@krate/3d 0.0.0-stage → 0.5.0-rc.13

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 (43) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +9 -0
  3. package/README.md +45 -2
  4. package/materials/VERSION +1 -0
  5. package/materials/build.mjs +59 -0
  6. package/materials/physical.filamat +0 -0
  7. package/materials/physical_transparent.filamat +0 -0
  8. package/materials/src/physical.mat +90 -0
  9. package/materials/src/standard.mat +77 -0
  10. package/materials/src/unlit.mat +28 -0
  11. package/materials/standard.filamat +0 -0
  12. package/materials/standard_transparent.filamat +0 -0
  13. package/materials/unlit.filamat +0 -0
  14. package/materials/unlit_transparent.filamat +0 -0
  15. package/package.json +66 -3
  16. package/src/index.ts +3 -0
  17. package/src/runtime/aim.ts +40 -0
  18. package/src/runtime/calibration.ts +29 -0
  19. package/src/runtime/canvas.tsx +18 -0
  20. package/src/runtime/canvas_style.ts +11 -0
  21. package/src/runtime/color.ts +183 -0
  22. package/src/runtime/compiled.ts +39 -0
  23. package/src/runtime/compiled_canvas.tsx +37 -0
  24. package/src/runtime/context.ts +14 -0
  25. package/src/runtime/controls.ts +146 -0
  26. package/src/runtime/entities.ts +50 -0
  27. package/src/runtime/environment.ts +50 -0
  28. package/src/runtime/filament.ts +309 -0
  29. package/src/runtime/geometry.ts +195 -0
  30. package/src/runtime/gltf.ts +77 -0
  31. package/src/runtime/hooks.ts +10 -0
  32. package/src/runtime/index.ts +18 -0
  33. package/src/runtime/lights.ts +75 -0
  34. package/src/runtime/materials.ts +267 -0
  35. package/src/runtime/mount.ts +52 -0
  36. package/src/runtime/picking.ts +123 -0
  37. package/src/runtime/renderables.ts +62 -0
  38. package/src/runtime/rt.ts +33 -0
  39. package/src/runtime/scene.ts +484 -0
  40. package/src/runtime/transforms.ts +182 -0
  41. package/src/runtime/tree.ts +283 -0
  42. package/src/runtime/view.ts +121 -0
  43. package/src/types.ts +205 -0
@@ -0,0 +1,283 @@
1
+ // Fallback path: mounts the element descriptors a renderer-tier <Canvas>
2
+ // receives (`{ __k3: 1, type, props, children }`, the same shape @krate/three
3
+ // consumes) onto a scene through the same API compiled code uses. There is no
4
+ // compile-time flattening: every mesh gets a dynamic slot, and groups are
5
+ // folded into a static parent matrix when mounted.
6
+
7
+ import type { PointerHandler } from '../types.js';
8
+ import { lightIntensity } from './calibration.js';
9
+ import { colorToLinear } from './color.js';
10
+ import type { GeometryKind } from './geometry.js';
11
+ import type { LightKind, LightProps } from './lights.js';
12
+ import type { MaterialKind, MaterialParams, ParamValue } from './materials.js';
13
+ import type { PointerEventName } from './picking.js';
14
+ import { rt } from './rt.js';
15
+ import type { Scene3D } from './scene.js';
16
+ import { composeTRS, eulerToQuat, mulMat4 } from './transforms.js';
17
+
18
+ type Props = Record<string, unknown>;
19
+
20
+ interface Element {
21
+ __k3?: number;
22
+ __kv?: number;
23
+ __ka?: number;
24
+ type?: unknown;
25
+ tag?: string;
26
+ props?: Props | null;
27
+ children?: unknown;
28
+ items?: () => unknown;
29
+ render?: (item: unknown, index: unknown) => unknown;
30
+ }
31
+
32
+ const IDENTITY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
33
+ const GEOMETRIES: Record<string, GeometryKind> = { boxGeometry: 'box', sphereGeometry: 'sphere', planeGeometry: 'plane' };
34
+ const MATERIALS: Record<string, MaterialKind> = {
35
+ meshStandardMaterial: 'standard',
36
+ meshPhysicalMaterial: 'physical',
37
+ meshBasicMaterial: 'unlit',
38
+ };
39
+ const LIGHTS: Record<string, LightKind> = {
40
+ directionalLight: 'directional',
41
+ pointLight: 'point',
42
+ spotLight: 'spot',
43
+ ambientLight: 'ambient',
44
+ };
45
+ const EVENTS: Record<string, PointerEventName> = {
46
+ onClick: 'click',
47
+ onPointerOver: 'pointerover',
48
+ onPointerOut: 'pointerout',
49
+ onPointerMove: 'pointermove',
50
+ onPointerDown: 'pointerdown',
51
+ onPointerUp: 'pointerup',
52
+ };
53
+ // Three.js-style material prop to uber-material parameter.
54
+ const MATERIAL_PROPS: Record<string, string> = {
55
+ roughness: 'roughness',
56
+ metallic: 'metallic',
57
+ metalness: 'metallic',
58
+ emissiveIntensity: 'emissiveIntensity',
59
+ opacity: 'opacity',
60
+ transparent: 'transparent',
61
+ map: 'baseColorMap',
62
+ normalMap: 'normalMap',
63
+ aoMap: 'aoMap',
64
+ roughnessMap: 'roughnessMap',
65
+ metalnessMap: 'metallicMap',
66
+ emissiveMap: 'emissiveMap',
67
+ normalScale: 'normalScale',
68
+ aoMapIntensity: 'aoMapIntensity',
69
+ clearcoat: 'clearcoat',
70
+ clearcoatRoughness: 'clearcoatRoughness',
71
+ sheenRoughness: 'sheenRoughness',
72
+ transmission: 'transmission',
73
+ ior: 'ior',
74
+ };
75
+
76
+ function isThunk(key: string, v: unknown): v is () => unknown {
77
+ return typeof v === 'function' && (v as Function).length === 0 && !(key in EVENTS) && key !== 'ref';
78
+ }
79
+
80
+ /** A Three.js-style material prop as a uber-material parameter value. */
81
+ export function materialParam(key: string, value: unknown): [string, ParamValue] | undefined {
82
+ if (key === 'color') {
83
+ const [r, g, b] = colorToLinear(value as string | number);
84
+ return ['baseColor', [r, g, b, 1]];
85
+ }
86
+ if (key === 'emissive' || key === 'sheenColor') return [key, colorToLinear(value as string | number)];
87
+ const name = MATERIAL_PROPS[key];
88
+ return name ? [name, value as ParamValue] : undefined;
89
+ }
90
+
91
+ export function materialParams(props: Props, read: (key: string) => unknown = (k) => props[k]): MaterialParams {
92
+ const out: MaterialParams = {};
93
+ for (const key of Object.keys(props)) {
94
+ const p = materialParam(key, read(key));
95
+ if (p) out[p[0]] = p[1];
96
+ }
97
+ return out;
98
+ }
99
+
100
+ function trsMatrix(pos?: readonly number[], rot?: readonly number[], scale?: readonly number[] | number): number[] {
101
+ const data = new Float32Array(10);
102
+ data[6] = 1;
103
+ data[7] = data[8] = data[9] = 1;
104
+ if (pos) data.set(pos.slice(0, 3), 0);
105
+ if (rot) eulerToQuat(data, 3, rot[0], rot[1], rot[2]);
106
+ if (typeof scale === 'number') data.fill(scale, 7, 10);
107
+ else if (scale) data.set(scale.slice(0, 3), 7);
108
+ const m = new Float32Array(16);
109
+ composeTRS(m, data, 0);
110
+ return Array.from(m);
111
+ }
112
+
113
+ function multiply(a: number[], b: number[]): number[] {
114
+ const out = new Float32Array(16);
115
+ mulMat4(out, Float32Array.from(a), 0, Float32Array.from(b));
116
+ return Array.from(out);
117
+ }
118
+
119
+ function transformPoint(m: number[], p: readonly number[]): number[] {
120
+ const [x, y, z] = p;
121
+ return [m[0] * x + m[4] * y + m[8] * z + m[12], m[1] * x + m[5] * y + m[9] * z + m[13], m[2] * x + m[6] * y + m[10] * z + m[14]];
122
+ }
123
+
124
+ function normalize(v: number[]): number[] {
125
+ const l = Math.hypot(v[0], v[1], v[2]) || 1;
126
+ return [v[0] / l, v[1] / l, v[2] / l];
127
+ }
128
+
129
+ interface Ctx {
130
+ scene: Scene3D;
131
+ parent: number[];
132
+ disposers: Array<() => void>;
133
+ }
134
+
135
+ /** Mounts scene children; returns a function that stops their reactive effects. */
136
+ export function mountSceneTree(scene: Scene3D, children: unknown): () => void {
137
+ const ctx: Ctx = { scene, parent: IDENTITY, disposers: [] };
138
+ mountValue(children, ctx);
139
+ return () => {
140
+ for (const d of ctx.disposers.splice(0)) d();
141
+ };
142
+ }
143
+
144
+ function mountValue(value: unknown, ctx: Ctx): void {
145
+ if (value == null || typeof value === 'boolean' || typeof value === 'string' || typeof value === 'number') return;
146
+ if (Array.isArray(value)) {
147
+ for (const v of value) mountValue(v, ctx);
148
+ return;
149
+ }
150
+ if (typeof value === 'function') {
151
+ // Regions are evaluated once; the fallback does not diff scene children.
152
+ mountValue(rt().untrack(value as () => unknown), ctx);
153
+ return;
154
+ }
155
+ const el = value as Element;
156
+ if (el.__ka === 1 && el.items && el.render) {
157
+ const items = rt().untrack(el.items);
158
+ if (Array.isArray(items)) items.forEach((item, i) => mountValue(el.render!(item, i), ctx));
159
+ return;
160
+ }
161
+ if (el.__k3 === 2 && typeof el.type === 'function') {
162
+ mountValue(rt().untrack(() => (el.type as (p: Props) => unknown)(el.props ?? {})), ctx);
163
+ return;
164
+ }
165
+ if (el.__k3 === 1 && typeof el.type === 'string') return mountElement(el.type, el.props ?? {}, el.children, ctx);
166
+ if (el.__kv === 1 && el.tag) return mountElement(el.tag, el.props ?? {}, el.children, ctx);
167
+ console.warn('@krate/3d: unsupported scene child ignored', value);
168
+ }
169
+
170
+ function read(props: Props, key: string): unknown {
171
+ const v = props[key];
172
+ return isThunk(key, v) ? rt().untrack(v) : v;
173
+ }
174
+
175
+ /** Calls apply now and again whenever the (possibly reactive) prop changes. */
176
+ function track(ctx: Ctx, props: Props, key: string, apply: (v: unknown) => void): void {
177
+ const v = props[key];
178
+ if (isThunk(key, v)) ctx.disposers.push(rt().createEffect(() => apply(v())));
179
+ }
180
+
181
+ function childList(children: unknown): unknown[] {
182
+ const out: unknown[] = [];
183
+ const walk = (c: unknown): void => {
184
+ if (Array.isArray(c)) c.forEach(walk);
185
+ else if (c != null && typeof c === 'object') out.push(c);
186
+ };
187
+ walk(children);
188
+ return out;
189
+ }
190
+
191
+ function mountElement(type: string, props: Props, children: unknown, ctx: Ctx): void {
192
+ if (type === 'group') return mountGroup(props, children, ctx);
193
+ if (type === 'mesh') return mountMesh(props, children, ctx);
194
+ const kind = LIGHTS[type];
195
+ if (kind) return mountLight(kind, props, ctx);
196
+ console.warn(`@krate/3d: unknown scene element <${type}> ignored`);
197
+ }
198
+
199
+ function mountGroup(props: Props, children: unknown, ctx: Ctx): void {
200
+ const m = trsMatrix(read(props, 'position') as number[], read(props, 'rotation') as number[], read(props, 'scale') as number[]);
201
+ mountValue(children, { ...ctx, parent: multiply(ctx.parent, m) });
202
+ }
203
+
204
+ function elementOf(list: unknown[], names: Record<string, unknown>): { type: string; props: Props } | undefined {
205
+ for (const c of list) {
206
+ const e = c as Element;
207
+ const t = e.type ?? e.tag;
208
+ if (typeof t === 'string' && t in names) return { type: t, props: e.props ?? {} };
209
+ }
210
+ return undefined;
211
+ }
212
+
213
+ function mountMesh(props: Props, children: unknown, ctx: Ctx): void {
214
+ const { scene } = ctx;
215
+ const list = childList(children);
216
+ const geo = elementOf(list, GEOMETRIES);
217
+ const mat = elementOf(list, MATERIALS);
218
+ if (!geo || !mat) {
219
+ console.warn('@krate/3d: <mesh> needs a geometry and a material child');
220
+ return;
221
+ }
222
+ const g = scene.geometry(GEOMETRIES[geo.type], (read(geo.props, 'args') as number[]) ?? []);
223
+ const m = scene.material(MATERIALS[mat.type], materialParams(mat.props, (k) => read(mat.props, k)));
224
+ for (const key of Object.keys(mat.props)) {
225
+ track(ctx, mat.props, key, (v) => {
226
+ const p = materialParam(key, v);
227
+ if (p) scene.setMaterialParam(m, p[0], p[1]);
228
+ });
229
+ }
230
+ const slot = scene.allocSlot();
231
+ const pos = (read(props, 'position') as number[]) ?? [0, 0, 0];
232
+ const rot = (read(props, 'rotation') as number[]) ?? [0, 0, 0];
233
+ const sc = read(props, 'scale');
234
+ const scale = typeof sc === 'number' ? [sc, sc, sc] : ((sc as number[]) ?? [1, 1, 1]);
235
+ const q = new Float32Array(4);
236
+ eulerToQuat(q, 0, rot[0], rot[1], rot[2]);
237
+ const mesh = scene.dynamicMesh(slot, g, m, ctx.parent, { pos, quat: Array.from(q), scale }, {
238
+ castShadow: !!read(props, 'castShadow'),
239
+ receiveShadow: !!read(props, 'receiveShadow'),
240
+ });
241
+ track(ctx, props, 'position', (v) => scene.pos(slot, ...(v as [number, number, number])));
242
+ track(ctx, props, 'rotation', (v) => scene.rot(slot, ...(v as [number, number, number])));
243
+ track(ctx, props, 'scale', (v) => {
244
+ const s = typeof v === 'number' ? [v, v, v] : (v as number[]);
245
+ scene.scale(slot, s[0], s[1], s[2]);
246
+ });
247
+ for (const key of Object.keys(EVENTS)) {
248
+ const h = props[key];
249
+ if (typeof h === 'function') scene.on(mesh, EVENTS[key], h as PointerHandler);
250
+ }
251
+ // Nested meshes and lights are placed relative to this mesh's initial transform.
252
+ const nested = list.filter((c) => {
253
+ const t = (c as Element).type ?? (c as Element).tag;
254
+ return typeof t !== 'string' || !(t in GEOMETRIES || t in MATERIALS);
255
+ });
256
+ if (nested.length) mountValue(nested, { ...ctx, parent: multiply(ctx.parent, trsMatrix(pos, rot, scale)) });
257
+ }
258
+
259
+ function mountLight(kind: LightKind, props: Props, ctx: Ctx): void {
260
+ const { scene } = ctx;
261
+ const position = transformPoint(ctx.parent, (read(props, 'position') as number[]) ?? [0, 0, 0]);
262
+ const color = read(props, 'color') as string | number | undefined;
263
+ const intensity = (read(props, 'intensity') as number | undefined) ?? 1;
264
+ const lp: LightProps = { intensity: lightIntensity(kind, intensity), color, castShadows: !!read(props, 'castShadow') };
265
+ if (kind === 'directional') {
266
+ lp.position = position;
267
+ lp.direction = normalize(position.map((c) => -c));
268
+ } else if (kind !== 'ambient') {
269
+ lp.position = position;
270
+ const distance = read(props, 'distance') as number | undefined;
271
+ if (distance) lp.falloff = distance;
272
+ if (kind === 'spot') {
273
+ const target = transformPoint(ctx.parent, (read(props, 'target') as number[]) ?? [0, 0, 0]);
274
+ lp.direction = normalize(target.map((c, i) => c - position[i]));
275
+ const angle = (read(props, 'angle') as number | undefined) ?? Math.PI / 3;
276
+ const penumbra = (read(props, 'penumbra') as number | undefined) ?? 0;
277
+ lp.outer = angle;
278
+ lp.inner = angle * (1 - penumbra);
279
+ }
280
+ }
281
+ const h = scene.light(kind, lp);
282
+ track(ctx, props, 'intensity', (v) => scene.setLight(h, 'intensity', lightIntensity(kind, v as number)));
283
+ }
@@ -0,0 +1,121 @@
1
+ // Canvas props to Filament View, ColorGrading and Camera.
2
+
3
+ import type { Antialias, BloomOptions, CameraProps, SsaoOptions, ToneMapping } from '../types.js';
4
+ import { DEFAULT_CAMERA, DEFAULT_EXPOSURE } from './calibration.js';
5
+ import type { FCamera, FColorGrading, FEngine, FView, FilamentModule } from './filament.js';
6
+
7
+ export interface ViewOptions {
8
+ shadows?: boolean;
9
+ bloom?: boolean | BloomOptions;
10
+ ssao?: boolean | SsaoOptions;
11
+ antialias?: Antialias;
12
+ toneMapping?: ToneMapping;
13
+ }
14
+
15
+ export interface SceneCameraOptions extends CameraProps {
16
+ aperture?: number;
17
+ shutter?: number;
18
+ iso?: number;
19
+ /** Exposure compensation in EV stops. */
20
+ exposure?: number;
21
+ }
22
+
23
+ export const DEFAULT_VIEW = { antialias: 'fxaa', toneMapping: 'aces' } as const;
24
+
25
+ export function bloomOptions(F: FilamentModule, bloom: ViewOptions['bloom']): Record<string, unknown> {
26
+ if (!bloom) return { enabled: false };
27
+ const o = bloom === true ? {} : bloom;
28
+ return {
29
+ enabled: true,
30
+ strength: o.strength ?? 0.1,
31
+ levels: o.levels ?? 6,
32
+ threshold: o.threshold ?? true,
33
+ blendMode: F.View$BloomOptions$BlendMode?.ADD ?? 0,
34
+ };
35
+ }
36
+
37
+ export function ssaoOptions(F: FilamentModule, ssao: ViewOptions['ssao']): Record<string, unknown> {
38
+ if (!ssao) return { enabled: false };
39
+ const o = ssao === true ? {} : ssao;
40
+ return {
41
+ enabled: true,
42
+ radius: o.radius ?? 0.3,
43
+ intensity: o.intensity ?? 1,
44
+ bias: o.bias ?? 0.0005,
45
+ quality: F.View$QualityLevel?.HIGH ?? 2,
46
+ };
47
+ }
48
+
49
+ /** Filament enum name for a tone mapper; AGX exists only in newer bindings, so it falls back to FILMIC. */
50
+ export function toneMapperValue(F: FilamentModule, tm: ToneMapping): number {
51
+ const E = F.ColorGrading$ToneMapping;
52
+ switch (tm) {
53
+ case 'linear':
54
+ return E.LINEAR;
55
+ case 'filmic':
56
+ return E.FILMIC;
57
+ case 'agx':
58
+ return E.AGX ?? E.FILMIC;
59
+ default:
60
+ return E.ACES;
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Applies the options to the view. Shadows need no View call (Filament shadows
66
+ * follow light and renderable flags); fog, SSR, VSM and stereo stay off because
67
+ * the compiled materials exclude those variants. Returns the new color grading.
68
+ */
69
+ export function applyView(
70
+ F: FilamentModule,
71
+ engine: FEngine,
72
+ view: FView,
73
+ opts: ViewOptions,
74
+ previous?: FColorGrading
75
+ ): FColorGrading {
76
+ view.setBloomOptions(bloomOptions(F, opts.bloom));
77
+ view.setAmbientOcclusionOptions(ssaoOptions(F, opts.ssao));
78
+ const aa = opts.antialias ?? DEFAULT_VIEW.antialias;
79
+ const A = F.View$AntiAliasing;
80
+ view.setAntiAliasing(aa === 'fxaa' ? A.FXAA : A.NONE);
81
+ view.setTemporalAntiAliasingOptions({ enabled: aa === 'taa' });
82
+ view.setMultiSampleAntiAliasingOptions(aa === 'msaa' ? { enabled: true, sampleCount: 4 } : { enabled: false });
83
+ const grading = F.ColorGrading.Builder()
84
+ .toneMapping(toneMapperValue(F, opts.toneMapping ?? DEFAULT_VIEW.toneMapping))
85
+ .build(engine);
86
+ view.setColorGrading(grading);
87
+ if (previous) engine.destroyColorGrading(previous);
88
+ return grading;
89
+ }
90
+
91
+ export interface CameraState {
92
+ position: number[];
93
+ target: number[];
94
+ fov: number;
95
+ near: number;
96
+ far: number;
97
+ }
98
+
99
+ export function cameraState(o: SceneCameraOptions = {}): CameraState {
100
+ return {
101
+ position: [...(o.position ?? DEFAULT_CAMERA.position)],
102
+ target: [...(o.target ?? DEFAULT_CAMERA.target)],
103
+ fov: o.fov ?? DEFAULT_CAMERA.fov,
104
+ near: o.near ?? DEFAULT_CAMERA.near,
105
+ far: o.far ?? DEFAULT_CAMERA.far,
106
+ };
107
+ }
108
+
109
+ /** Exposure: default f/16, 1/125 s, ISO 100, with compensation applied as ISO stops. */
110
+ export function applyExposure(camera: FCamera, o: SceneCameraOptions = {}): void {
111
+ const iso = (o.iso ?? DEFAULT_EXPOSURE.iso) * 2 ** (o.exposure ?? 0);
112
+ camera.setExposure(o.aperture ?? DEFAULT_EXPOSURE.aperture, o.shutter ?? DEFAULT_EXPOSURE.shutter, iso);
113
+ }
114
+
115
+ export function applyProjection(F: FilamentModule, camera: FCamera, s: CameraState, width: number, height: number): void {
116
+ camera.setProjectionFov(s.fov, width / Math.max(1, height), s.near, s.far, F.Camera$Fov.VERTICAL);
117
+ }
118
+
119
+ export function applyLookAt(camera: FCamera, s: CameraState): void {
120
+ camera.lookAt(s.position, s.target, [0, 1, 0]);
121
+ }
package/src/types.ts ADDED
@@ -0,0 +1,205 @@
1
+ // JSX typings for @krate/3d scene elements and component props.
2
+
3
+ export type Vec3 = [number, number, number];
4
+ export type Vec2 = [number, number];
5
+ /** A CSS color string or a 0xRRGGBB number. */
6
+ export type ColorRepresentation = string | number;
7
+ /** URL of an image used as a texture. */
8
+ export type TextureSource = string;
9
+
10
+ export interface Pointer3DEvent {
11
+ /** Entity id of the picked mesh. */
12
+ entity: number;
13
+ /** Pointer position in canvas pixels. */
14
+ x: number;
15
+ y: number;
16
+ nativeEvent: PointerEvent | MouseEvent;
17
+ }
18
+ export type PointerHandler = (event: Pointer3DEvent) => void;
19
+
20
+ export interface EventProps {
21
+ onClick?: PointerHandler;
22
+ onPointerOver?: PointerHandler;
23
+ onPointerOut?: PointerHandler;
24
+ onPointerMove?: PointerHandler;
25
+ onPointerDown?: PointerHandler;
26
+ onPointerUp?: PointerHandler;
27
+ }
28
+
29
+ export interface TransformProps {
30
+ position?: Vec3;
31
+ /** Euler angles in radians, XYZ order. */
32
+ rotation?: Vec3;
33
+ scale?: Vec3 | number;
34
+ }
35
+
36
+ export interface NodeProps extends TransformProps {
37
+ key?: string | number;
38
+ name?: string;
39
+ visible?: boolean;
40
+ children?: unknown;
41
+ }
42
+
43
+ export interface MeshProps extends NodeProps, EventProps {
44
+ castShadow?: boolean;
45
+ receiveShadow?: boolean;
46
+ }
47
+ export type GroupProps = NodeProps;
48
+
49
+ export interface GeometryProps<A extends unknown[]> {
50
+ args?: A;
51
+ }
52
+ export type BoxGeometryProps = GeometryProps<[width?: number, height?: number, depth?: number]>;
53
+ export type SphereGeometryProps = GeometryProps<
54
+ [radius?: number, widthSegments?: number, heightSegments?: number]
55
+ >;
56
+ export type PlaneGeometryProps = GeometryProps<
57
+ [width?: number, height?: number, widthSegments?: number, heightSegments?: number]
58
+ >;
59
+
60
+ export interface MaterialMaps {
61
+ map?: TextureSource;
62
+ normalMap?: TextureSource;
63
+ aoMap?: TextureSource;
64
+ roughnessMap?: TextureSource;
65
+ metalnessMap?: TextureSource;
66
+ emissiveMap?: TextureSource;
67
+ normalScale?: number;
68
+ aoMapIntensity?: number;
69
+ }
70
+
71
+ export interface MeshBasicMaterialProps {
72
+ color?: ColorRepresentation;
73
+ map?: TextureSource;
74
+ opacity?: number;
75
+ transparent?: boolean;
76
+ }
77
+
78
+ export interface MeshStandardMaterialProps extends MeshBasicMaterialProps, MaterialMaps {
79
+ roughness?: number;
80
+ metallic?: number;
81
+ emissive?: ColorRepresentation;
82
+ emissiveIntensity?: number;
83
+ }
84
+
85
+ export interface MeshPhysicalMaterialProps extends MeshStandardMaterialProps {
86
+ clearcoat?: number;
87
+ clearcoatRoughness?: number;
88
+ sheenColor?: ColorRepresentation;
89
+ sheenRoughness?: number;
90
+ transmission?: number;
91
+ ior?: number;
92
+ }
93
+
94
+ export interface ShaderMaterialProps {
95
+ /** GLSL body of the Filament `material(inout MaterialInputs)` function. */
96
+ fragmentShader?: string;
97
+ /** Extra material parameters, name to type (`float`, `float3`, `float4`, `sampler2d`). */
98
+ uniforms?: Record<string, number | Vec3 | [number, number, number, number] | TextureSource>;
99
+ transparent?: boolean;
100
+ opacity?: number;
101
+ }
102
+
103
+ export interface LightProps {
104
+ color?: ColorRepresentation;
105
+ /** Three.js-scale intensity; the compiler converts it to Filament units. */
106
+ intensity?: number;
107
+ position?: Vec3;
108
+ castShadow?: boolean;
109
+ }
110
+ export type DirectionalLightProps = LightProps;
111
+ export interface PointLightProps extends LightProps {
112
+ /** Falloff radius in world units. */
113
+ distance?: number;
114
+ }
115
+ export interface SpotLightProps extends PointLightProps {
116
+ /** Target the light points at. */
117
+ target?: Vec3;
118
+ /** Outer cone angle in radians. */
119
+ angle?: number;
120
+ /** Inner-to-outer cone softness, 0 to 1. */
121
+ penumbra?: number;
122
+ }
123
+ export interface AmbientLightProps {
124
+ color?: ColorRepresentation;
125
+ intensity?: number;
126
+ }
127
+
128
+ export type ToneMapping = 'aces' | 'filmic' | 'agx' | 'linear';
129
+ export type Antialias = 'taa' | 'fxaa' | 'msaa' | 'none';
130
+
131
+ export interface BloomOptions {
132
+ strength?: number;
133
+ levels?: number;
134
+ threshold?: boolean;
135
+ }
136
+ export interface SsaoOptions {
137
+ radius?: number;
138
+ intensity?: number;
139
+ bias?: number;
140
+ }
141
+ export interface CameraProps {
142
+ position?: Vec3;
143
+ /** Point the camera looks at. */
144
+ target?: Vec3;
145
+ /** Vertical field of view in degrees. */
146
+ fov?: number;
147
+ near?: number;
148
+ far?: number;
149
+ }
150
+
151
+ export interface CanvasProps {
152
+ class?: string;
153
+ style?: string | Record<string, string | number>;
154
+ shadows?: boolean;
155
+ bloom?: boolean | BloomOptions;
156
+ ssao?: boolean | SsaoOptions;
157
+ antialias?: Antialias;
158
+ toneMapping?: ToneMapping;
159
+ camera?: CameraProps;
160
+ /** Exposure compensation in EV stops added to the default f/16, 1/125 s, ISO 100 camera. */
161
+ exposure?: number;
162
+ children?: unknown;
163
+ }
164
+
165
+ export interface OrbitControlsProps {
166
+ target?: Vec3;
167
+ enableZoom?: boolean;
168
+ enablePan?: boolean;
169
+ enableRotate?: boolean;
170
+ autoRotate?: boolean;
171
+ autoRotateSpeed?: number;
172
+ minDistance?: number;
173
+ maxDistance?: number;
174
+ }
175
+
176
+ export interface EnvironmentProps {
177
+ /** Built-in preset name, or a URL to a KTX image-based light. */
178
+ preset?: 'studio' | 'sunset' | 'dawn' | 'night' | 'warehouse' | 'forest' | 'city';
179
+ files?: string;
180
+ /** Show the environment as the scene background. */
181
+ background?: boolean;
182
+ intensity?: number;
183
+ }
184
+
185
+ export interface SceneElements {
186
+ mesh: MeshProps;
187
+ group: GroupProps;
188
+ boxGeometry: BoxGeometryProps;
189
+ sphereGeometry: SphereGeometryProps;
190
+ planeGeometry: PlaneGeometryProps;
191
+ meshStandardMaterial: MeshStandardMaterialProps;
192
+ meshPhysicalMaterial: MeshPhysicalMaterialProps;
193
+ meshBasicMaterial: MeshBasicMaterialProps;
194
+ shaderMaterial: ShaderMaterialProps;
195
+ directionalLight: DirectionalLightProps;
196
+ pointLight: PointLightProps;
197
+ spotLight: SpotLightProps;
198
+ ambientLight: AmbientLightProps;
199
+ }
200
+
201
+ declare global {
202
+ namespace JSX {
203
+ interface IntrinsicElements extends SceneElements {}
204
+ }
205
+ }