@glyx-dev/three 0.1.0 → 0.2.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/CHANGELOG.md +11 -0
- package/README.md +54 -0
- package/package.json +2 -2
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @glyx-dev/three
|
|
2
|
+
|
|
3
|
+
Declarative React-Three-Fiber-style 3D API for Glyx Canvas3D.
|
|
4
|
+
|
|
5
|
+
Full docs: [glyx.dev](https://glyx.dev)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
bun add @glyx-dev/three
|
|
11
|
+
# or npm install @glyx-dev/three
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```jsx
|
|
17
|
+
import { Canvas3D } from '@glyx-dev/react';
|
|
18
|
+
import { Scene, PerspectiveCamera, AmbientLight, DirectionalLight, Mesh } from '@glyx-dev/three';
|
|
19
|
+
|
|
20
|
+
function My3DScene() {
|
|
21
|
+
const c3dRef = React.useRef(null);
|
|
22
|
+
const [angle, setAngle] = React.useState(0);
|
|
23
|
+
|
|
24
|
+
React.useEffect(() => {
|
|
25
|
+
const id = setInterval(() => setAngle((a) => a + 0.02), 16);
|
|
26
|
+
return () => clearInterval(id);
|
|
27
|
+
}, []);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<Canvas3D ref={c3dRef} width={640} height={400} style={{ borderRadius: 8 }}>
|
|
31
|
+
<Scene canvasRef={c3dRef}>
|
|
32
|
+
<PerspectiveCamera position={[0, 2, 5]} target={[0, 0, 0]} />
|
|
33
|
+
<AmbientLight intensity={0.3} />
|
|
34
|
+
<DirectionalLight />
|
|
35
|
+
<Mesh geometry={{ type: 'box' }} transform={/* ... */ null} color={[1, 0, 0, 1]} />
|
|
36
|
+
</Scene>
|
|
37
|
+
</Canvas3D>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Architecture: `<Scene>` owns a React context that child components register into. On each render, `Scene` resets an internal accumulator, children fill it synchronously (Glyx uses synchronous `LegacyRoot` rendering), then a `useLayoutEffect` commits the assembled scene to the native `Canvas3D` via `ctx.updateScene(scene)`. There's no custom reconciler — it's plain React hooks + context, producing a JSON scene description matching glyx-3d's Rust `Scene3D` struct exactly.
|
|
43
|
+
|
|
44
|
+
## API
|
|
45
|
+
|
|
46
|
+
- `Scene({ canvasRef, background, children })` — root 3D scene container; commits the accumulated scene to the given `Canvas3D` ref.
|
|
47
|
+
- `PerspectiveCamera({ position, target, up, fovDeg, near, far })` — sets the scene's camera.
|
|
48
|
+
- `AmbientLight({ color, intensity })` — adds an ambient light.
|
|
49
|
+
- `DirectionalLight({ ... })` — adds a directional light.
|
|
50
|
+
- `PointLight({ ... })` — adds a point light.
|
|
51
|
+
- `SpotLight({ ... })` — adds a spot light.
|
|
52
|
+
- `Group({ position, rotation, scale, transform, children })` — groups child meshes under one composed transform.
|
|
53
|
+
- `Mesh({ geometry, transform, color, ... })` — a single mesh (`geometry.type`: `'box' | 'sphere' | 'plane' | 'gltf'`).
|
|
54
|
+
- `Model({ ... })` — loads a GLTF model as a mesh, including animation clips.
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glyx-dev/three",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"description": "Declarative React-Three-Fiber-style 3D API for Glyx Canvas3D.",
|
|
7
7
|
"peerDependencies": {
|
|
8
8
|
"react": "^18.2.0",
|
|
9
|
-
"@glyx-dev/react": "0.
|
|
9
|
+
"@glyx-dev/react": "^0.2.0"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"test": "bun test"
|