@aura3d/react 1.3.3 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +25 -0
  2. package/package.json +34 -3
  3. package/src/index.ts +0 -173
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # @aura3d/react
2
+
3
+ `@aura3d/react` owns React components and helpers for mounting Aura3D scenes
4
+ with typed assets, cameras, lights, effects, and product-viewer scene builders.
5
+
6
+ ## Public API
7
+
8
+ - `AuraCanvas`: React canvas component that mounts `createAuraApp`, forwards
9
+ diagnostics/options, and disposes the app on unmount.
10
+ - `Scene`: declarative scene wrapper for background, camera, timeline, and
11
+ diagnostics options.
12
+ - `Model`: typed model node declaration using an `AuraAssetRef<"model">`.
13
+ - `Camera`: orbit, dolly, follow, or perspective camera declaration.
14
+ - `Lights`: studio, ambient, directional, and point light declaration.
15
+ - `Effect`: fog, bloom, and rain effect declaration.
16
+ - `buildSceneFromChildren`: converts supported React children into an
17
+ `AuraSceneBuilder`.
18
+ - `productViewerScene`: convenience builder for a typed-asset product viewer
19
+ scene.
20
+
21
+ ## Package Boundary
22
+
23
+ This package wraps the root `@aura3d/engine` public API for React apps. It does
24
+ not replace the typed asset pipeline: model props should use generated
25
+ `assets.name` references, not raw GLB URLs or guessed asset IDs.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aura3d/react",
3
- "version": "1.3.3",
3
+ "version": "1.4.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -15,6 +15,37 @@
15
15
  "react": "^19.0.0 || ^18.0.0"
16
16
  },
17
17
  "devDependencies": {
18
- "@aura3d/engine": "1.3.3"
19
- }
18
+ "@aura3d/engine": "1.4.1"
19
+ },
20
+ "description": "React components and helpers for mounting Aura3D scenes with typed assets, cameras, lights, effects, and product-viewer scene builders.",
21
+ "keywords": [
22
+ "aura3d",
23
+ "3d",
24
+ "browser-3d",
25
+ "web-3d",
26
+ "typescript",
27
+ "react",
28
+ "react-components",
29
+ "react-3d",
30
+ "aura-canvas",
31
+ "typed-assets",
32
+ "product-viewer"
33
+ ],
34
+ "homepage": "https://aura3d.auraone.ai",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/auraoneai/aura3d.git",
38
+ "directory": "packages/react"
39
+ },
40
+ "bugs": {
41
+ "url": "https://github.com/auraoneai/aura3d/issues"
42
+ },
43
+ "license": "MIT",
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "files": [
48
+ "README.md",
49
+ "dist"
50
+ ]
20
51
  }
package/src/index.ts DELETED
@@ -1,173 +0,0 @@
1
- import {
2
- Children,
3
- createElement,
4
- isValidElement,
5
- useEffect,
6
- useMemo,
7
- useRef,
8
- type CSSProperties,
9
- type ReactElement,
10
- type ReactNode
11
- } from "react";
12
- import {
13
- camera,
14
- createAuraApp,
15
- effects,
16
- lights,
17
- model,
18
- scene,
19
- type AuraApp,
20
- type AuraAssetRef,
21
- type AuraCameraSpec,
22
- type AuraColor,
23
- type AuraCreateAppOptions,
24
- type AuraEffectNode,
25
- type AuraLightNode,
26
- type AuraMaterialSpec,
27
- type AuraModelOptions,
28
- type AuraSceneBuilder,
29
- type AuraTimelineSpec
30
- } from "@aura3d/engine";
31
-
32
- export interface AuraCanvasProps {
33
- readonly children?: ReactNode;
34
- readonly diagnostics?: AuraCreateAppOptions["diagnostics"];
35
- readonly pixelRatio?: number;
36
- readonly autoStart?: boolean;
37
- readonly resize?: boolean;
38
- readonly className?: string;
39
- readonly style?: CSSProperties;
40
- readonly onReady?: (app: AuraApp) => void;
41
- }
42
-
43
- export interface SceneProps {
44
- readonly children?: ReactNode;
45
- readonly background?: AuraColor;
46
- readonly camera?: AuraCameraSpec;
47
- readonly timeline?: AuraTimelineSpec;
48
- readonly diagnostics?: boolean;
49
- }
50
-
51
- export interface ModelProps extends AuraModelOptions {
52
- readonly asset: AuraAssetRef<"model">;
53
- }
54
-
55
- export interface CameraProps extends Omit<AuraCameraSpec, "mode"> {
56
- readonly mode?: AuraCameraSpec["mode"];
57
- }
58
-
59
- export interface LightsProps {
60
- readonly preset?: "studio";
61
- readonly type?: AuraLightNode["light"];
62
- readonly intensity?: number;
63
- readonly color?: AuraColor;
64
- readonly position?: readonly [number, number, number];
65
- }
66
-
67
- export interface EffectProps extends Omit<AuraEffectNode, "kind" | "effect"> {
68
- readonly type: AuraEffectNode["effect"];
69
- }
70
-
71
- export function AuraCanvas(props: AuraCanvasProps): ReactElement {
72
- const ref = useRef<HTMLCanvasElement | null>(null);
73
- const builtScene = useMemo(() => buildSceneFromChildren(props.children), [props.children]);
74
- useEffect(() => {
75
- if (!ref.current) return undefined;
76
- const app = createAuraApp(ref.current, {
77
- scene: builtScene,
78
- diagnostics: props.diagnostics,
79
- pixelRatio: props.pixelRatio,
80
- autoStart: props.autoStart,
81
- resize: props.resize
82
- });
83
- props.onReady?.(app);
84
- return () => app.dispose();
85
- }, [builtScene, props.autoStart, props.diagnostics, props.onReady, props.pixelRatio, props.resize]);
86
- return createElement("canvas", {
87
- ref,
88
- className: props.className,
89
- style: {
90
- width: "100%",
91
- height: "100%",
92
- display: "block",
93
- ...(props.style ?? {})
94
- }
95
- });
96
- }
97
-
98
- export function Scene(_props: SceneProps): null {
99
- return null;
100
- }
101
-
102
- export function Model(_props: ModelProps): null {
103
- return null;
104
- }
105
-
106
- export function Camera(_props: CameraProps): null {
107
- return null;
108
- }
109
-
110
- export function Lights(_props: LightsProps): null {
111
- return null;
112
- }
113
-
114
- export function Effect(_props: EffectProps): null {
115
- return null;
116
- }
117
-
118
- export function buildSceneFromChildren(children: ReactNode): AuraSceneBuilder {
119
- let builder = scene();
120
- const sceneElement = findFirstElementOfType(children, Scene);
121
- const sceneProps = (sceneElement?.props ?? {}) as SceneProps;
122
- if (sceneProps.background) builder = builder.background(sceneProps.background);
123
- if (sceneProps.camera) builder = builder.camera(sceneProps.camera);
124
- if (sceneProps.timeline) builder = builder.timeline(sceneProps.timeline);
125
- if (sceneProps.diagnostics) builder = builder.diagnostics(sceneProps.diagnostics);
126
- const content = sceneElement ? sceneProps.children : children;
127
- Children.forEach(content, (child) => {
128
- if (!isValidElement(child)) return;
129
- if (child.type === Model) {
130
- const props = child.props as ModelProps;
131
- builder.add(model(props.asset, props));
132
- }
133
- if (child.type === Camera) {
134
- const props = child.props as CameraProps;
135
- const mode = props.mode ?? "orbit";
136
- if (mode === "dolly" && props.from && props.to) builder.camera(camera.dolly({ ...props, from: props.from, to: props.to }));
137
- else if (mode === "follow" && props.targetNode) builder.camera(camera.follow({ ...props, targetNode: props.targetNode }));
138
- else if (mode === "perspective") builder.camera(camera.perspective(props));
139
- else builder.camera(camera.orbit(props));
140
- }
141
- if (child.type === Lights) {
142
- const props = child.props as LightsProps;
143
- if (props.preset === "studio" || !props.type || props.type === "studio") builder.add(lights.studio({ intensity: props.intensity }));
144
- else if (props.type === "ambient") builder.add(lights.ambient(props));
145
- else if (props.type === "directional") builder.add(lights.directional(props));
146
- else builder.add(lights.point(props));
147
- }
148
- if (child.type === Effect) {
149
- const props = child.props as EffectProps;
150
- if (props.type === "fog") builder.add(effects.fog(props));
151
- if (props.type === "bloom") builder.add(effects.bloom(props));
152
- if (props.type === "rain") builder.add(effects.rain(props));
153
- }
154
- });
155
- return builder;
156
- }
157
-
158
- export function productViewerScene(asset: AuraAssetRef<"model">, material?: AuraMaterialSpec): AuraSceneBuilder {
159
- return scene()
160
- .background("#08111f")
161
- .add(model(asset, { material }).position(0, 0, 0).scale(1))
162
- .add(lights.studio({ intensity: 1.1 }))
163
- .camera(camera.orbit({ distance: 4 }))
164
- .diagnostics(true);
165
- }
166
-
167
- function findFirstElementOfType(children: ReactNode, type: (props: never) => null): ReactElement | undefined {
168
- let found: ReactElement | undefined;
169
- Children.forEach(children, (child) => {
170
- if (!found && isValidElement(child) && child.type === type) found = child;
171
- });
172
- return found;
173
- }