wamr3d 0.0.0-stage → 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.
package/README.md CHANGED
@@ -1,3 +1,120 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # wamr3d
2
+
3
+ A 3D engine in Rust and WebAssembly that draws with WebGPU. Scene graph, transforms, cameras, geometry processing, culling and draw ordering run inside a WebAssembly module; you drive it from JavaScript through three.js-style classes or through batched low-level calls.
4
+
5
+ Behaviour is checked against three.js r186. The engine is **unfinished**: no shadows, environment reflections, points, sprites or render targets yet. See [Not available yet](https://github.com/aymen94/wamr3d/blob/main/MIGRATION.md#not-available-yet).
6
+
7
+ ## Install
8
+
9
+ ```
10
+ npm install wamr3d
11
+ ```
12
+
13
+ Requirements: a browser with WebGPU (current Chrome or Edge) for rendering; Node.js 18 or newer for the math and scene graph without a renderer. In a browser, pages must be served over HTTP, not opened from `file://`. A bundler or an import map is needed to resolve the `wamr3d` package name.
14
+
15
+ ## Quick start (object API)
16
+
17
+ ```js
18
+ import * as WAMR3D from 'wamr3d/compat';
19
+
20
+ await WAMR3D.init();
21
+
22
+ const scene = new WAMR3D.Scene();
23
+ const camera = new WAMR3D.PerspectiveCamera( 50, innerWidth / innerHeight, 0.1, 100 );
24
+ camera.position.set( 3, 2, 5 );
25
+ camera.lookAt( 0, 0, 0 );
26
+
27
+ const cube = new WAMR3D.Mesh( new WAMR3D.BoxGeometry(), new WAMR3D.MeshLambertMaterial( { color: 0x4f8cff } ) );
28
+ scene.add( cube, new WAMR3D.DirectionalLight( 0xffffff, 2 ), new WAMR3D.HemisphereLight( 0xbfd4ff, 0x30281e, 1 ) );
29
+
30
+ const renderer = new WAMR3D.WebGPURenderer( { antialias: true } );
31
+ await renderer.init();
32
+ renderer.setSize( innerWidth, innerHeight );
33
+ document.body.appendChild( renderer.domElement );
34
+
35
+ renderer.setAnimationLoop( ( time ) => {
36
+
37
+ cube.rotation.y = time / 1000;
38
+ renderer.render( scene, camera );
39
+
40
+ } );
41
+ ```
42
+
43
+ ## Low-level API
44
+
45
+ Handle-based and batched; use it when thousands of objects change every frame.
46
+
47
+ ```js
48
+ import { init, World } from 'wamr3d';
49
+
50
+ await init();
51
+
52
+ const world = new World();
53
+ const scene = world.createObject();
54
+ const arm = world.createObject();
55
+ const hand = world.createObject();
56
+ world.add( scene, arm );
57
+ world.add( arm, hand );
58
+
59
+ world.setPosition( arm, 10, 0, 0 );
60
+ world.setRotation( arm, 0, 0, Math.PI / 2, 'XYZ' );
61
+ world.setPosition( hand, 1, 0, 0 );
62
+
63
+ world.updateMatrixWorld( scene, false );
64
+ console.log( world.matrixWorld( hand ) ); // Float32Array(16), column-major
65
+ ```
66
+
67
+ Things to know:
68
+
69
+ - Objects, geometries and materials are handles (`bigint`). Math values, `Timer` and `World` are classes; call `.free()` when done.
70
+ - Methods change values in place and return nothing, so calls do not chain.
71
+ - There are no default arguments: rotation order, segment counts and the like are always written out.
72
+ - Values are stored as 32-bit floats; results agree with three.js to about `1e-6`.
73
+ - A view from `attributeView()` stops working when the module's memory grows. Create it right before use.
74
+
75
+ ## Migrating from three.js
76
+
77
+ For the classes WAMR3D has, change the import, initialize once, and use the WebGPU renderer:
78
+
79
+ ```diff
80
+ - import * as THREE from 'three';
81
+ + import * as THREE from 'wamr3d/compat';
82
+ + await THREE.init();
83
+
84
+ - const renderer = new THREE.WebGLRenderer( { antialias: true } );
85
+ + const renderer = new THREE.WebGPURenderer( { antialias: true } );
86
+ + await renderer.init();
87
+ ```
88
+
89
+ `scene.add( mesh )`, `mesh.position.set( 1, 2, 3 )`, `mesh.rotation.y += 0.01`, `camera.lookAt( 0, 0, 0 )`, `raycaster.intersectObjects( scene.children )` and chained math keep working as written.
90
+
91
+ Differences to watch for:
92
+
93
+ | In three.js | In `wamr3d/compat` |
94
+ |---|---|
95
+ | Works without setup | `await init()` once, and `await renderer.init()` before the first `render` (`setAnimationLoop` waits for you) |
96
+ | `WebGLRenderer` | `WebGPURenderer` only |
97
+ | `MeshStandardMaterial` with environment and many maps | `color`, `map`, `roughness`, `metalness`, `side`, `transparent`, `opacity`, `depthTest`, `depthWrite`, `vertexColors`. No environment reflections. Unsupported parameters are stored, have no effect and log one warning |
98
+ | A missing class is `undefined` | Missing classes (`Points`, `Sprite`, `SkinnedMesh`, `MeshPhongMaterial`, `WebGLRenderer`, ...) throw "not available yet" |
99
+ | Any number of lights | Up to 8 directional, point and spot lights, plus ambient and hemisphere lights. No shadows |
100
+ | `object.matrix.elements[ 12 ] = 5` | `matrixWorld`, `matrix.elements`, `box.min` and similar are copies. Use `position`, `rotation`, `scale` or the value's methods |
101
+ | `attribute.array` is the data | Set `attribute.needsUpdate = true` after changing it, as in three.js |
102
+ | Garbage collected | Also here; `dispose()` releases engine objects at once |
103
+
104
+ Available classes include `Scene`, `Group`, `Object3D`, `Mesh`, `InstancedMesh`, `Line`, `LineSegments`, `PerspectiveCamera`, `OrthographicCamera`, `BufferGeometry`, eight shape geometries, `MeshBasicMaterial`, `MeshLambertMaterial`, `MeshStandardMaterial`, `LineBasicMaterial`, textures, five lights, `Fog`, `FogExp2`, `Raycaster`, `Clock`, `GridHelper`, `AxesHelper` and the math types (`Vector2/3/4`, `Quaternion`, `Euler`, `Matrix3/4`, `Color`, `Box3`, `Sphere`, `Plane`, `Ray`, `Frustum`, `MathUtils`).
105
+
106
+ **Full guide:** [MIGRATION.md](https://github.com/aymen94/wamr3d/blob/main/MIGRATION.md): the complete class list, the low-level API mapping, batching patterns and what is not available yet.
107
+
108
+ ## TypeScript
109
+
110
+ Typings ship with the package (`index.d.ts`, `compat.d.ts`). Set `"lib": [ "esnext", "dom" ]` in `tsconfig.json`.
111
+
112
+ ## Links
113
+
114
+ - Repository and examples: <https://github.com/aymen94/wamr3d>
115
+ - Status and measurements: [STATUS.md](https://github.com/aymen94/wamr3d/blob/main/STATUS.md)
116
+ - Design decisions: [DECISIONS.md](https://github.com/aymen94/wamr3d/blob/main/DECISIONS.md)
117
+
118
+ ## License
119
+
120
+ MIT license; see [THIRD_PARTY.md](https://github.com/aymen94/wamr3d/blob/main/THIRD_PARTY.md).