@headless-three/renderer 0.0.0 → 0.1.0

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 (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +201 -1
  3. package/dist/attributes.d.ts +8 -0
  4. package/dist/attributes.d.ts.map +1 -0
  5. package/dist/attributes.js +91 -0
  6. package/dist/attributes.js.map +1 -0
  7. package/dist/camera.d.ts +8 -0
  8. package/dist/camera.d.ts.map +1 -0
  9. package/dist/camera.js +53 -0
  10. package/dist/camera.js.map +1 -0
  11. package/dist/color.d.ts +5 -0
  12. package/dist/color.d.ts.map +1 -0
  13. package/dist/color.js +36 -0
  14. package/dist/color.js.map +1 -0
  15. package/dist/index.d.ts +9 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +72 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/lights.d.ts +5 -0
  20. package/dist/lights.d.ts.map +1 -0
  21. package/dist/lights.js +186 -0
  22. package/dist/lights.js.map +1 -0
  23. package/dist/materials.d.ts +18 -0
  24. package/dist/materials.d.ts.map +1 -0
  25. package/dist/materials.js +268 -0
  26. package/dist/materials.js.map +1 -0
  27. package/dist/math.d.ts +14 -0
  28. package/dist/math.d.ts.map +1 -0
  29. package/dist/math.js +137 -0
  30. package/dist/math.js.map +1 -0
  31. package/dist/morphs.d.ts +22 -0
  32. package/dist/morphs.d.ts.map +1 -0
  33. package/dist/morphs.js +108 -0
  34. package/dist/morphs.js.map +1 -0
  35. package/dist/scene.d.ts +3 -0
  36. package/dist/scene.d.ts.map +1 -0
  37. package/dist/scene.js +220 -0
  38. package/dist/scene.js.map +1 -0
  39. package/dist/skinning.d.ts +15 -0
  40. package/dist/skinning.d.ts.map +1 -0
  41. package/dist/skinning.js +88 -0
  42. package/dist/skinning.js.map +1 -0
  43. package/dist/types.d.ts +313 -0
  44. package/dist/types.d.ts.map +1 -0
  45. package/dist/types.js +4 -0
  46. package/dist/types.js.map +1 -0
  47. package/native.d.ts +178 -0
  48. package/native.js +580 -0
  49. package/package.json +83 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PortWatcher
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1 +1,201 @@
1
- placeholder
1
+ # @headless-three/renderer
2
+
3
+ Headless `wgpu` renderer for Three.js scenes in Node.js.
4
+
5
+ This package exists for Node.js environments where WebGL is not available. You build or load a normal Three.js scene, pass the `THREE.Scene` and `THREE.Camera` to this package, and the native addon renders it with `wgpu`.
6
+
7
+ ```bash
8
+ npm install @headless-three/renderer three
9
+ ```
10
+
11
+ ```js
12
+ import fs from 'node:fs'
13
+ import * as THREE from 'three'
14
+ import { render } from '@headless-three/renderer'
15
+
16
+ const scene = new THREE.Scene()
17
+ scene.background = new THREE.Color(0.04, 0.045, 0.05)
18
+
19
+ const geometry = new THREE.BoxGeometry(1, 1, 1)
20
+ const material = new THREE.MeshBasicMaterial({ color: 0xe84d3d })
21
+ scene.add(new THREE.Mesh(geometry, material))
22
+
23
+ const camera = new THREE.PerspectiveCamera(45, 1, 0.01, 100)
24
+ camera.position.set(2.5, 1.8, 3.2)
25
+ camera.lookAt(0, 0, 0)
26
+
27
+ const imageBuffer = render(scene, camera, {
28
+ width: 512,
29
+ height: 512,
30
+ })
31
+
32
+ fs.writeFileSync('render.png', imageBuffer)
33
+ ```
34
+
35
+ With `GLTFLoader`, render the loaded Three.js scene directly:
36
+
37
+ ```js
38
+ import fs from 'node:fs'
39
+ import * as THREE from 'three'
40
+ import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
41
+ import { render } from '@headless-three/renderer'
42
+
43
+ const gltf = await new GLTFLoader().loadAsync('./model.glb')
44
+
45
+ const camera = new THREE.PerspectiveCamera(45, 1, 0.01, 100)
46
+ camera.position.set(2, 1.5, 4)
47
+ camera.lookAt(0, 0, 0)
48
+
49
+ const imageBuffer = render(gltf.scene, camera, {
50
+ width: 1024,
51
+ height: 1024,
52
+ })
53
+
54
+ fs.writeFileSync('render.png', imageBuffer)
55
+ ```
56
+
57
+ The module exports a convenience `render(scene, camera, options)` function and a reusable `Renderer` class:
58
+
59
+ ```js
60
+ import { Renderer } from '@headless-three/renderer'
61
+ const renderer = new Renderer()
62
+ const imageBuffer = renderer.render(scene, camera, { width: 512, height: 512 })
63
+ ```
64
+
65
+ ## Supported Three.js Surface
66
+
67
+ The public API accepts only Three.js-like objects:
68
+
69
+ - `scene`: a `THREE.Scene`.
70
+ - `camera`: a `THREE.Camera`, including perspective and orthographic cameras.
71
+ - `options.width` and `options.height`: output pixel size. Defaults to `512 x 512`.
72
+ - `options.background`: `[r, g, b]`, `[r, g, b, a]`, or a `THREE.Color`. Defaults to `scene.background` when it is a color.
73
+ - `options.format`: `'png'` by default, or `'rgba'` for raw RGBA8 bytes.
74
+
75
+ ### Geometry & Scene
76
+
77
+ - `THREE.Mesh` and `THREE.SkinnedMesh`
78
+ - `THREE.BufferGeometry` positions, indices, normals, and UV coordinates
79
+ - geometry groups with material arrays
80
+ - mesh world transforms
81
+ - vertex colors
82
+ - scene background color
83
+ - perspective, orthographic, and custom projection matrices
84
+
85
+ ### Materials & Textures
86
+
87
+ - material base color and opacity
88
+ - `material.map` (base color texture) — PNG, JPEG, WebP, and raw RGBA8 DataTexture
89
+ - PBR metallic/roughness via `MeshStandardMaterial` and `MeshPhysicalMaterial`
90
+ - metallic/roughness map (`material.metalnessMap` / `material.roughnessMap`)
91
+ - normal map with configurable `normalScale`
92
+ - emissive color, intensity, and emissive map
93
+ - occlusion map (`material.aoMap`) applied to indirect lighting
94
+ - `MeshStandardMaterial`, `MeshPhysicalMaterial` (PBR), `MeshLambertMaterial` (diffuse-only), and `MeshBasicMaterial` (unlit)
95
+ - `material.side`: `FrontSide`, `BackSide`, `DoubleSide`
96
+ - alpha test (`material.alphaTest`) with fragment discard
97
+ - transparency sorting (back-to-front) with separate no-depth-write pipeline
98
+ - texture wrap modes: repeat, mirror, clamp-to-edge
99
+
100
+ Texture image data can be:
101
+
102
+ - Raw RGBA8 pixels via `THREE.DataTexture` (or any image with `.data`, `.width`, `.height`)
103
+ - Encoded PNG, JPEG, or WebP image buffers (auto-decoded on the native side)
104
+
105
+ ### Lights
106
+
107
+ - `THREE.AmbientLight` — uniform ambient illumination
108
+ - `THREE.DirectionalLight` — sun-like parallel light with position/target
109
+ - `THREE.PointLight` — omnidirectional light with distance/decay attenuation
110
+ - `THREE.SpotLight` — cone light with angle, penumbra, distance, and decay
111
+ - `THREE.HemisphereLight` — sky/ground gradient ambient light
112
+
113
+ Lights are automatically extracted from the scene. The shader uses a Cook-Torrance PBR BRDF (GGX/Trowbridge-Reitz distribution, Schlick-GGX geometry, Schlick Fresnel) with Three.js-compatible physically-based attenuation. Up to 16 lights per scene. When no lights are present, meshes render with a hemispherical ambient fallback.
114
+
115
+ ### Image-Based Lighting (IBL)
116
+
117
+ Environment maps set on `scene.environment` are supported for image-based lighting. The renderer CPU-precomputes:
118
+
119
+ - **Diffuse irradiance cubemap** — cosine-weighted hemisphere convolution
120
+ - **Prefiltered specular cubemap** — GGX importance-sampled at multiple roughness mip levels
121
+ - **BRDF integration LUT** — split-sum approximation lookup table
122
+
123
+ Supported input formats: equirectangular images in RGBA8, Float16 (`HalfFloatType`), or Float32 (`FloatType`). `scene.environmentIntensity` is respected.
124
+
125
+ ### Skinning / Skeletal Animation
126
+
127
+ `THREE.SkinnedMesh` objects are automatically detected and skinned on the CPU. The renderer reads `skinIndex` and `skinWeight` attributes, computes bone matrices from `skeleton.bones` and `skeleton.boneInverses`, and transforms vertex positions and normals before sending them to the GPU.
128
+
129
+ Compatible with:
130
+
131
+ - **Three.js** `SkinnedMesh` + `Skeleton` + `AnimationMixer`
132
+ - **@pixiv/three-vrm** — VRM humanoid avatars
133
+ - **VRMA** — VRM Animation files via `VRMAnimationLoaderPlugin` + `createVRMAnimationClip`
134
+
135
+ Call `mixer.update(dt)` and `scene.updateMatrixWorld(true)` before `render()` to bake the current pose:
136
+
137
+ ```js
138
+ import * as THREE from 'three'
139
+ import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
140
+ import { VRMLoaderPlugin, VRMUtils } from '@pixiv/three-vrm'
141
+ import { VRMAnimationLoaderPlugin, createVRMAnimationClip } from '@pixiv/three-vrm-animation'
142
+ import { render } from '@headless-three/renderer'
143
+
144
+ const gltfLoader = new GLTFLoader()
145
+ gltfLoader.register((parser) => new VRMLoaderPlugin(parser))
146
+ gltfLoader.register((parser) => new VRMAnimationLoaderPlugin(parser))
147
+
148
+ // Load VRM model
149
+ const modelGltf = await gltfLoader.loadAsync('./avatar.vrm')
150
+ const vrm = modelGltf.userData.vrm
151
+ VRMUtils.removeUnnecessaryVertices(vrm.scene)
152
+ VRMUtils.removeUnnecessaryJoints(vrm.scene)
153
+ vrm.scene.rotation.y = Math.PI
154
+
155
+ // Load VRMA animation
156
+ const animGltf = await gltfLoader.loadAsync('./dance.vrma')
157
+ const vrmAnimation = animGltf.userData.vrmAnimations[0]
158
+ const clip = createVRMAnimationClip(vrmAnimation, vrm)
159
+
160
+ // Animate to a specific time
161
+ const mixer = new THREE.AnimationMixer(vrm.scene)
162
+ mixer.clipAction(clip).play()
163
+ mixer.update(1.5) // seek to 1.5 seconds
164
+
165
+ // Update world matrices then render
166
+ vrm.update(0)
167
+ vrm.scene.updateMatrixWorld(true)
168
+
169
+ const camera = new THREE.PerspectiveCamera(30, 1, 0.1, 20)
170
+ camera.position.set(0, 1.2, 3)
171
+ camera.lookAt(0, 1, 0)
172
+
173
+ const imageBuffer = render(vrm.scene, camera, {
174
+ width: 1024,
175
+ height: 1024,
176
+ })
177
+ ```
178
+
179
+ ### Morph Targets / Blend Shapes
180
+
181
+ Morph targets are applied on the CPU before rendering. Both **relative** (glTF default) and **absolute** (legacy Three.js) modes are supported. Position and normal morphs are applied based on `mesh.morphTargetInfluences`. This is compatible with:
182
+
183
+ - glTF morph targets via `GLTFLoader`
184
+ - VRM blend shapes / expressions from `@pixiv/three-vrm`
185
+ - Blender shape keys exported to glTF
186
+
187
+ ### Shadows
188
+
189
+ Directional shadow maps are supported. Set `light.castShadow = true` on a `THREE.DirectionalLight`, configure `light.shadow.camera` (orthographic bounds), and mark meshes with `mesh.castShadow = true` / `mesh.receiveShadow = true`. The renderer picks the first shadow-casting directional light, renders a depth-only pass, and samples it with 3×3 PCF and a normal-offset bias.
190
+
191
+ ### Tone Mapping
192
+
193
+ Output uses the Narkowicz ACES Filmic tone mapping fit with a three.js-compatible `1/0.6` exposure pre-scale, matching `THREE.ACESFilmicToneMapping`.
194
+
195
+ ### Lines and Points
196
+
197
+ `THREE.Line`, `THREE.LineSegments`, `THREE.LineLoop`, and `THREE.Points` are supported. Lines and points render as unlit (basic) primitives and ignore lighting / normals.
198
+
199
+ ### Not Yet Implemented
200
+
201
+ Custom shaders, render targets, point/spot-light shadows, cascaded shadow maps, reflection probes, transmission / refraction, clearcoat / sheen, anisotropy, and post-processing effects.
@@ -0,0 +1,8 @@
1
+ import type { ThreeBufferAttributeLike, ThreeBufferGeometryLike, Color4 } from './types';
2
+ export declare function getAttribute(geometry: ThreeBufferGeometryLike, name: string): ThreeBufferAttributeLike | undefined;
3
+ export declare function readVec3Attribute(attribute: ThreeBufferAttributeLike): number[];
4
+ export declare function readVec2Attribute(attribute: ThreeBufferAttributeLike): number[];
5
+ export declare function readColorAttribute(attribute: ThreeBufferAttributeLike, materialColor: Color4): number[];
6
+ export declare function readIndexAttribute(attribute: ThreeBufferAttributeLike): number[];
7
+ export declare function attributeComponent(attribute: ThreeBufferAttributeLike, index: number, component: number): number;
8
+ //# sourceMappingURL=attributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../api/attributes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAGxF,wBAAgB,YAAY,CAAC,QAAQ,EAAE,uBAAuB,EAAE,IAAI,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,CAKlH;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,wBAAwB,GAAG,MAAM,EAAE,CAW/E;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,wBAAwB,GAAG,MAAM,EAAE,CAU/E;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,CAUvG;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,wBAAwB,GAAG,MAAM,EAAE,CAMhF;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,wBAAwB,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAoBhH"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAttribute = getAttribute;
4
+ exports.readVec3Attribute = readVec3Attribute;
5
+ exports.readVec2Attribute = readVec2Attribute;
6
+ exports.readColorAttribute = readColorAttribute;
7
+ exports.readIndexAttribute = readIndexAttribute;
8
+ exports.attributeComponent = attributeComponent;
9
+ const math_1 = require("./math");
10
+ function getAttribute(geometry, name) {
11
+ if (typeof geometry.getAttribute === 'function') {
12
+ return geometry.getAttribute(name);
13
+ }
14
+ return geometry.attributes?.[name];
15
+ }
16
+ function readVec3Attribute(attribute) {
17
+ if (attribute.count == null) {
18
+ throw new TypeError('THREE.BufferGeometry position attribute must have count');
19
+ }
20
+ const values = new Array(attribute.count * 3);
21
+ for (let i = 0; i < attribute.count; i += 1) {
22
+ values[i * 3] = attributeComponent(attribute, i, 0);
23
+ values[i * 3 + 1] = attributeComponent(attribute, i, 1);
24
+ values[i * 3 + 2] = attributeComponent(attribute, i, 2);
25
+ }
26
+ return values;
27
+ }
28
+ function readVec2Attribute(attribute) {
29
+ if (attribute.count == null) {
30
+ throw new TypeError('THREE.BufferGeometry UV attribute must have count');
31
+ }
32
+ const values = new Array(attribute.count * 2);
33
+ for (let i = 0; i < attribute.count; i += 1) {
34
+ values[i * 2] = attributeComponent(attribute, i, 0);
35
+ values[i * 2 + 1] = attributeComponent(attribute, i, 1);
36
+ }
37
+ return values;
38
+ }
39
+ function readColorAttribute(attribute, materialColor) {
40
+ const itemSize = attribute.itemSize ?? 3;
41
+ const values = new Array(attribute.count * 4);
42
+ for (let i = 0; i < attribute.count; i += 1) {
43
+ values[i * 4] = (0, math_1.clamp01)(attributeComponent(attribute, i, 0) * materialColor[0]);
44
+ values[i * 4 + 1] = (0, math_1.clamp01)(attributeComponent(attribute, i, 1) * materialColor[1]);
45
+ values[i * 4 + 2] = (0, math_1.clamp01)(attributeComponent(attribute, i, 2) * materialColor[2]);
46
+ values[i * 4 + 3] = (0, math_1.clamp01)((itemSize >= 4 ? attributeComponent(attribute, i, 3) : 1) * materialColor[3]);
47
+ }
48
+ return values;
49
+ }
50
+ function readIndexAttribute(attribute) {
51
+ const values = new Array(attribute.count);
52
+ for (let i = 0; i < attribute.count; i += 1) {
53
+ values[i] = attributeComponent(attribute, i, 0);
54
+ }
55
+ return values;
56
+ }
57
+ function attributeComponent(attribute, index, component) {
58
+ if (component >= (attribute.itemSize ?? 1))
59
+ return 0;
60
+ let value;
61
+ if (component === 0 && typeof attribute.getX === 'function')
62
+ value = attribute.getX(index);
63
+ else if (component === 1 && typeof attribute.getY === 'function')
64
+ value = attribute.getY(index);
65
+ else if (component === 2 && typeof attribute.getZ === 'function')
66
+ value = attribute.getZ(index);
67
+ else if (component === 3 && typeof attribute.getW === 'function')
68
+ value = attribute.getW(index);
69
+ else {
70
+ const array = attribute.array ?? attribute.data?.array;
71
+ const stride = attribute.data?.stride ?? attribute.itemSize ?? 1;
72
+ const offset = attribute.offset ?? 0;
73
+ value = array?.[index * stride + offset + component];
74
+ }
75
+ if (!Number.isFinite(value)) {
76
+ throw new TypeError('THREE.BufferAttribute contains a non-finite value');
77
+ }
78
+ return attribute.normalized ? normalizeAttributeValue(value, attribute.array ?? attribute.data?.array) : value;
79
+ }
80
+ function normalizeAttributeValue(value, array) {
81
+ if (array instanceof Uint8Array || array instanceof Uint8ClampedArray)
82
+ return value / 255;
83
+ if (array instanceof Uint16Array)
84
+ return value / 65535;
85
+ if (array instanceof Int8Array)
86
+ return Math.max(value / 127, -1);
87
+ if (array instanceof Int16Array)
88
+ return Math.max(value / 32767, -1);
89
+ return value;
90
+ }
91
+ //# sourceMappingURL=attributes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.js","sourceRoot":"","sources":["../api/attributes.ts"],"names":[],"mappings":";;AAGA,oCAKC;AAED,8CAWC;AAED,8CAUC;AAED,gDAUC;AAED,gDAMC;AAED,gDAoBC;AA1ED,iCAAgC;AAEhC,SAAgB,YAAY,CAAC,QAAiC,EAAE,IAAY;IAC1E,IAAI,OAAO,QAAQ,CAAC,YAAY,K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AAG,SAAS,CAAC,KAAK,IAAI,SAAS,CAAC,IAAI,EAAE,KAAK,CAAA;QACtD,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE,MAAM,IAAI,SAAS,CAAC,QAAQ,IAAI,CAAC,CAAA;QAChE,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,IAAI,CAAC,CAAA;QACpC,KAAK,GAAG,KAAK,EAAE,CAAC,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAAA;IACtD,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,SAAS,CAAC,mDAAmD,CAAC,CAAA;IAC1E,CAAC;IAED,OAAO,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,uBAAuB,CAAC,KAAM,EAAE,SAAS,CAAC,KAAK,IAAI,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAM,CAAA;AAClH,CAAC;AAED,SAAS,uBAAuB,CAAC,KAAa,EAAE,KAAoC;IAClF,IAAI,KAAK,YAAY,UAAU,IAAI,KAAK,YAAY,iBAAiB;QAAE,OAAO,KAAK,GAAG,GAAG,CAAA;IACzF,IAAI,KAAK,YAAY,WAAW;QAAE,OAAO,KAAK,GAAG,KAAK,CAAA;IACtD,IAAI,KAAK,YAAY,SAAS;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;IAChE,IAAI,KAAK,YAAY,UAAU;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;IACnE,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { ThreeCameraLike, RenderOptions, Mat4 } from './types';
2
+ export declare function resolveSize(camera: ThreeCameraLike, options: RenderOptions): {
3
+ width: number;
4
+ height: number;
5
+ };
6
+ export declare function cameraViewProjection(camera: ThreeCameraLike): Mat4;
7
+ export declare function cameraWorldPosition(camera: ThreeCameraLike): number[];
8
+ //# sourceMappingURL=camera.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"camera.d.ts","sourceRoot":"","sources":["../api/camera.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAMnE,wBAAgB,WAAW,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CA0B9G;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAIlE;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,EAAE,CAerE"}
package/dist/camera.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveSize = resolveSize;
4
+ exports.cameraViewProjection = cameraViewProjection;
5
+ exports.cameraWorldPosition = cameraWorldPosition;
6
+ const math_1 = require("./math");
7
+ const DEFAULT_WIDTH = 512;
8
+ const DEFAULT_HEIGHT = 512;
9
+ function resolveSize(camera, options) {
10
+ let width = (0, math_1.numberOrUndefined)(options.width);
11
+ let height = (0, math_1.numberOrUndefined)(options.height);
12
+ if (width == null && height == null) {
13
+ width = (0, math_1.numberOrUndefined)(camera.userData?.width) ?? DEFAULT_WIDTH;
14
+ height = (0, math_1.numberOrUndefined)(camera.userData?.height);
15
+ }
16
+ if (height == null && width != null && (0, math_1.isFinitePositive)(camera.aspect)) {
17
+ height = Math.round(width / camera.aspect);
18
+ }
19
+ if (width == null && height != null && (0, math_1.isFinitePositive)(camera.aspect)) {
20
+ width = Math.round(height * camera.aspect);
21
+ }
22
+ width ?? (width = DEFAULT_WIDTH);
23
+ height ?? (height = DEFAULT_HEIGHT);
24
+ if (!Number.isInteger(width) || width <= 0) {
25
+ throw new TypeError('render options width must be a positive integer');
26
+ }
27
+ if (!Number.isInteger(height) || height <= 0) {
28
+ throw new TypeError('render options height must be a positive integer');
29
+ }
30
+ return { width, height };
31
+ }
32
+ function cameraViewProjection(camera) {
33
+ const projection = (0, math_1.matrixElements)(camera.projectionMatrix, 'camera.projectionMatrix');
34
+ const view = (0, math_1.matrixElements)(camera.matrixWorldInverse, 'camera.matrixWorldInverse');
35
+ return (0, math_1.multiplyMatrices)(math_1.OPENGL_TO_WGPU_CLIP, (0, math_1.multiplyMatrices)(projection, view));
36
+ }
37
+ function cameraWorldPosition(camera) {
38
+ if (camera.matrixWorld?.elements) {
39
+ const e = camera.matrixWorld.elements;
40
+ return [e[12], e[13], e[14]];
41
+ }
42
+ if (camera.matrixWorldInverse?.elements) {
43
+ const e = camera.matrixWorldInverse.elements;
44
+ const tx = e[12], ty = e[13], tz = e[14];
45
+ return [
46
+ -(e[0] * tx + e[1] * ty + e[2] * tz),
47
+ -(e[4] * tx + e[5] * ty + e[6] * tz),
48
+ -(e[8] * tx + e[9] * ty + e[10] * tz),
49
+ ];
50
+ }
51
+ return [0, 0, 0];
52
+ }
53
+ //# sourceMappingURL=camera.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"camera.js","sourceRoot":"","sources":["../api/camera.ts"],"names":[],"mappings":";;AAMA,kCA0BC;AAED,oDAIC;AAED,kDAeC;AAtDD,iCAAmH;AAEnH,MAAM,aAAa,GAAG,GAAG,CAAA;AACzB,MAAM,cAAc,GAAG,GAAG,CAAA;AAE1B,SAAgB,WAAW,CAAC,MAAuB,EAAE,OAAsB;IACzE,IAAI,KAAK,GAAG,IAAA,wBAAiB,EAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC5C,IAAI,MAAM,GAAG,IAAA,wBAAiB,EAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAE9C,IAAI,KAAK,IAAI,IAAI,IA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AAC,EAAE,CAAC,CAAC,CAAA;AAClB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Color4, ThreeSceneLike, RenderOptions } from './types';
2
+ export declare function colorLikeToArray(value: unknown): Color4 | null;
3
+ export declare function normalizeColorArray(values: number[]): Color4;
4
+ export declare function resolveBackground(scene: ThreeSceneLike, options: RenderOptions): Color4;
5
+ //# sourceMappingURL=color.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../api/color.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkB,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAGpF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAQ9D;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAU5D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAOvF"}
package/dist/color.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.colorLikeToArray = colorLikeToArray;
4
+ exports.normalizeColorArray = normalizeColorArray;
5
+ exports.resolveBackground = resolveBackground;
6
+ const math_1 = require("./math");
7
+ function colorLikeToArray(value) {
8
+ if (!value)
9
+ return null;
10
+ if (Array.isArray(value))
11
+ return normalizeColorArray(value);
12
+ const v = value;
13
+ if (v.isColor === true || (0, math_1.areFiniteNumbers)(v.r, v.g, v.b)) {
14
+ return [(0, math_1.clamp01)(v.r), (0, math_1.clamp01)(v.g), (0, math_1.clamp01)(v.b), 1];
15
+ }
16
+ return null;
17
+ }
18
+ function normalizeColorArray(values) {
19
+ if (values.length !== 3 && values.length !== 4) {
20
+ throw new TypeError('Color arrays must be [r, g, b] or [r, g, b, a]');
21
+ }
22
+ return [
23
+ (0, math_1.clamp01)((0, math_1.assertFinite)(values[0], 'color r')),
24
+ (0, math_1.clamp01)((0, math_1.assertFinite)(values[1], 'color g')),
25
+ (0, math_1.clamp01)((0, math_1.assertFinite)(values[2], 'color b')),
26
+ (0, math_1.clamp01)(values.length === 4 ? (0, math_1.assertFinite)(values[3], 'color a') : 1),
27
+ ];
28
+ }
29
+ function resolveBackground(scene, options) {
30
+ if (Array.isArray(options.background)) {
31
+ return normalizeColorArray(options.background);
32
+ }
33
+ const color = colorLikeToArray(options.background) ?? colorLikeToArray(scene.background);
34
+ return color ?? [0.04, 0.045, 0.05, 1];
35
+ }
36
+ //# sourceMappingURL=color.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color.js","sourceRoot":"","sources":["../api/color.ts"],"names":[],"mappings":";;AAGA,4CAQC;AAED,kDAUC;AAED,8CAOC;AA/BD,iCAAgE;AAEhE,SAAgB,gBAAgB,CAAC,KAAc;IAC7C,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAA;IACvB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAA;IAC3D,MAAM,CAAC,GAAG,KAAgC,CAAA;IAC1C,IAAI,CAAC,CAAC,OAAO,KAAK,IAAI,IAAI,IAAA,uBAAgB,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1D,OAAO,CAAC,IAAA,cAAO,EAAC,CAAC,CAAC,CAAE,CAAC,EAAE,IAAA,cAAO,EAAC,CAAC,CAAC,CAAE,CAAC,EAAE,IAAA,cAAO,EAAC,CAAC,CAAC,CAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IACzD,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAgB,mBAAmB,CAAC,MAAgB;IAClD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAA;IACvE,CAAC;IACD,OAAO;QACL,IAAA,cAAO,EAAC,IAAA,mBAAY,EAAC,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;QAC3C,IAAA,cAAO,EAAC,IAAA,mBAAY,EAAC,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;QAC3C,IAAA,cAAO,EAAC,IAAA,mBAAY,EAAC,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;QAC3C,IAAA,cAAO,EAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAA,mBAAY,EAAC,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KACtE,CAAA;AACH,CAAC;AAED,SAAgB,iBAAiB,CAAC,KAAqB,EAAE,OAAsB;IAC7E,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACtC,OAAO,mBAAmB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IAChD,CAAC;IAED,MAAM,KAAK,GAAG,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;IACxF,OAAO,KAAK,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AACxC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { ThreeSceneLike, ThreeCameraLike, RenderOptions } from './types';
2
+ export type { RenderOutputFormat, ThreeColorLike, ThreeMatrix4Like, ThreeBufferAttributeLike, ThreeBufferGeometryLike, ThreeTextureLike, ThreeMaterialLike, ThreeBoneLike, ThreeSkeletonLike, ThreeObject3DLike, ThreeSceneLike, ThreeCameraLike, RenderOptions, } from './types';
3
+ export declare class Renderer {
4
+ private native;
5
+ constructor();
6
+ render(scene: ThreeSceneLike, camera: ThreeCameraLike, options?: RenderOptions): Buffer;
7
+ }
8
+ export declare function render(scene: ThreeSceneLike, camera: ThreeCameraLike, options?: RenderOptions): Buffer;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../api/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,aAAa,EAGd,MAAM,SAAS,CAAA;AAWhB,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,wBAAwB,EACxB,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,aAAa,GACd,MAAM,SAAS,CAAA;AAEhB,qBAAa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAA4C;;IAM1D,MAAM,CAAC,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM;CAI5F;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAG1G"}
package/dist/index.js ADDED
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Renderer = void 0;
4
+ exports.render = render;
5
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
6
+ const native = require('../native.js');
7
+ const camera_1 = require("./camera");
8
+ const color_1 = require("./color");
9
+ const scene_1 = require("./scene");
10
+ const lights_1 = require("./lights");
11
+ const materials_1 = require("./materials");
12
+ class Renderer {
13
+ constructor() {
14
+ this.native = new native.NativeRenderer();
15
+ }
16
+ render(scene, camera, options = {}) {
17
+ const { nativeScene, nativeCamera } = toNativeInput(scene, camera, options);
18
+ return this.native.render(nativeScene, nativeCamera);
19
+ }
20
+ }
21
+ exports.Renderer = Renderer;
22
+ function render(scene, camera, options = {}) {
23
+ const { nativeScene, nativeCamera } = toNativeInput(scene, camera, options);
24
+ return native.renderNative(nativeScene, nativeCamera);
25
+ }
26
+ function toNativeInput(scene, camera, options) {
27
+ validateThreeScene(scene);
28
+ validateThreeCamera(camera);
29
+ if (typeof scene.updateMatrixWorld === 'function') {
30
+ scene.updateMatrixWorld(true);
31
+ }
32
+ if (typeof camera.updateMatrixWorld === 'function') {
33
+ camera.updateMatrixWorld(true);
34
+ }
35
+ const size = (0, camera_1.resolveSize)(camera, options);
36
+ const envMap = (0, materials_1.extractEnvironmentMap)(scene);
37
+ const nativeScene = {
38
+ width: size.width,
39
+ height: size.height,
40
+ background: (0, color_1.resolveBackground)(scene, options),
41
+ format: options.format ?? 'png',
42
+ meshes: (0, scene_1.flattenScene)(scene),
43
+ lights: (0, lights_1.extractLights)(scene),
44
+ ambientLight: (0, lights_1.extractAmbientLight)(scene) ?? undefined,
45
+ ambientIntensity: (0, lights_1.extractAmbientIntensity)(scene) ?? undefined,
46
+ environmentMap: envMap?.data,
47
+ environmentMapWidth: envMap?.width,
48
+ environmentMapHeight: envMap?.height,
49
+ environmentMapIntensity: envMap?.intensity,
50
+ };
51
+ const nativeCamera = {
52
+ width: size.width,
53
+ height: size.height,
54
+ viewProjection: (0, camera_1.cameraViewProjection)(camera),
55
+ cameraPosition: (0, camera_1.cameraWorldPosition)(camera),
56
+ };
57
+ return { nativeScene, nativeCamera };
58
+ }
59
+ function validateThreeScene(scene) {
60
+ if (!scene || scene.isScene !== true) {
61
+ throw new TypeError('render(scene, camera) expects scene to be a THREE.Scene');
62
+ }
63
+ }
64
+ function validateThreeCamera(camera) {
65
+ if (!camera || camera.isCamera !== true) {
66
+ throw new TypeError('render(scene, camera) expects camera to be a THREE.Camera');
67
+ }
68
+ if (!camera.projectionMatrix || !camera.matrixWorldInverse) {
69
+ throw new TypeError('THREE.Camera must have projectionMatrix and matrixWorldInverse');
70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C;AACH,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAe;IAC1C,IAAI,CAAC,MAAM,IAAK,MAAc,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QACjD,MAAM,IAAI,SAAS,CAAC,2DAA2D,CAAC,CAAA;IAClF,CAAC;IACD,IAAI,CAAE,MAAc,CAAC,gBAAgB,IAAI,CAAE,MAAc,CAAC,kBAAkB,EAAE,CAAC;QAC7E,MAAM,IAAI,SAAS,CAAC,gEAAgE,CAAC,CAAA;IACvF,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { ThreeObject3DLike, NativeSceneLight } from './types';
2
+ export declare function extractLights(scene: ThreeObject3DLike): NativeSceneLight[] | undefined;
3
+ export declare function extractAmbientLight(scene: ThreeObject3DLike): number[] | null;
4
+ export declare function extractAmbientIntensity(scene: ThreeObject3DLike): number | undefined;
5
+ //# sourceMappingURL=lights.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lights.d.ts","sourceRoot":"","sources":["../api/lights.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAGlE,wBAAgB,aAAa,CAAC,KAAK,EAAE,iBAAiB,GAAG,gBAAgB,EAAE,GAAG,SAAS,CAItF;AA+ID,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,EAAE,GAAG,IAAI,CAa7E;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAMpF"}