@ringozz/react-godot 1.0.0-4 → 1.0.0-5

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,280 +1,268 @@
1
- # `@ringozz/react-godot`
2
-
3
- Declarative, component-driven **Godot 4** scene graph management in React. Built for high-performance applications using `@ringozz/godot`.
4
-
5
- ---
6
-
7
- ## Overview
8
-
9
- `@ringozz/react-godot` brings a **React Three Fiber (R3F)**-like developer experience to Godot. It provides a custom React reconciler that renders React components directly into Godot's live engine scene tree (`SceneTree`).
10
-
11
- If you are familiar with React Three Fiber, the core paradigms will feel instantly recognizable:
12
- - **Declarative Nodes**: Godot 3D/2D nodes (e.g., `<RigidBody3D>`, `<Camera3D>`, `<DirectionalLight3D>`) map directly to JSX components.
13
- - **Resource Attachment**: Use the `attach` prop to assign nested Godot resources (materials, shapes, meshes, environments) directly to parent properties.
14
- - **Reactive Engine Loop**: Use hooks like `useSignal` to hook into Godot signals (`processFrame`, `windowInput`) without triggering React state re-renders.
15
-
16
- ---
17
-
18
- ## Installation & Setup
19
-
20
- ### 1. Dependencies
21
-
22
- ```bash
23
- npm install @ringozz/react-godot react
24
- ```
25
-
26
- ### 2. TypeScript Configuration (`tsconfig.json`)
27
-
28
- To enable custom JSX element resolution for Godot nodes, configure `jsxImportSource` and module settings in `tsconfig.json`:
29
-
30
- ```json
31
- {
32
- "compilerOptions": {
33
- "module": "esnext",
34
- "target": "es2025",
35
- "jsx": "react-jsx",
36
- "jsxImportSource": "@ringozz/react-godot",
37
- "rewriteRelativeImportExtensions": true,
38
- "verbatimModuleSyntax": true
39
- }
40
- }
41
- ```
42
-
43
- ---
44
-
45
- ## Application Entry & Portal Rendering
46
-
47
- ### 1. Mounting with `createRoot(parent: Node)`
48
- `createRoot` is the primary entry point for mounting a React component tree into a Godot target `Node` (typically `SceneTree.root`).
49
-
50
- ```tsx
51
- import { Engine } from '@ringozz/godot/Engine';
52
- import { SceneTree } from '@ringozz/godot/SceneTree';
53
- import { createRoot } from '@ringozz/react-godot';
54
- import { App } from './App';
55
-
56
- const tree = Engine.getMainLoop() as SceneTree;
57
- const { render } = createRoot(tree.root);
58
-
59
- render(<App />);
60
- ```
61
-
62
- - Returns `{ render, unmount }`.
63
- - Enables React `StrictMode` automatically in development (`NODE_ENV === 'development'`).
64
-
65
- ### 2. Render Portals with `createPortal(children, container)`
66
- `createPortal` allows rendering a React sub-tree into a different Godot `Node` in the hierarchy—such as a `CanvasLayer` for 2D UI overlays, a `SubViewport`, or an isolated container node.
67
-
68
- ```tsx
69
- import { createPortal } from '@ringozz/react-godot';
70
- import { Label } from '@ringozz/godot/Label';
71
-
72
- function Overlay({ overlayNode }: { overlayNode: Node }) {
73
- return createPortal(
74
- <Label text="HUD Overlay" position={[20, 20]} />,
75
- overlayNode
76
- );
77
- }
78
- ```
79
-
80
- - **Container Constraint**: The target `container` must be a Godot `Node` (it cannot target `Resource` instances).
81
- - **Cleanup**: Unmounting the portal safely disposes of and frees its child Godot nodes.
82
-
83
- ---
84
-
85
- ## Core Concepts & Patterns
86
-
87
- ### 1. Existing Objects with `object` Prop
88
-
89
- If you already have a pre-existing Godot `Node` or `Resource` instance (e.g. instantiated from C++ or loaded from disk), pass it via the `object` prop to adopt it into the React component tree instead of letting the reconciler instantiate a new object:
90
-
91
- ```tsx
92
- <Node object={myExistingGodotNode}>
93
- {/* Children attached to existing node */}
94
- </Node>
95
- ```
96
-
97
- ### 2. Resource Nesting with `attach`
98
-
99
- In Godot, nodes often hold references to `Resource` objects (such as shapes, meshes, materials, or environments). Use the `attach` prop to automatically assign a child resource to a specific property on its parent:
100
-
101
- ```tsx
102
- /* Attaching a shape to CollisionShape3D */
103
- <CollisionShape3D>
104
- <BoxShape3D attach="shape" size={[1, 1, 1]} />
105
- </CollisionShape3D>
106
-
107
- /* Attaching a material override to MeshInstance3D */
108
- <MeshInstance3D>
109
- <BoxMesh attach="mesh" />
110
- <StandardMaterial3D attach="materialOverride" albedoColor={[1, 0, 0]} />
111
- </MeshInstance3D>
112
-
113
- /* Attaching physics material to RigidBody3D */
114
- <RigidBody3D>
115
- <PhysicsMaterial attach="physicsMaterialOverride" bounce={0.8} />
116
- </RigidBody3D>
117
-
118
- /* Attaching environment to WorldEnvironment */
119
- <WorldEnvironment>
120
- <Environment attach="environment" backgroundColor={[0.1, 0.1, 0.2]} />
121
- </WorldEnvironment>
122
- ```
123
-
124
- ### 2. Properties & Helper Types
125
-
126
- Props map directly to Godot node setters and properties. Helper arrays are automatically cast to Godot types:
127
-
128
- - **Vectors**: `position={[0, 1, 0]}`, `scale={[2, 2, 2]}`
129
- - **Colors**: `albedoColor={[1, 0.2, 0.2]}` or `Color` objects
130
- - **Sub-properties / Dash props**: Set individual vector/color components directly using dash syntax:
131
- ```tsx
132
- <BoxMesh attach="mesh" size-x={0.5} size-y={1.0} size-z={0.5} />
133
- ```
134
-
135
- ### 3. Engine Signals & Event Subscription (`useSignal`)
136
-
137
- Subscribe to Godot engine signals cleanly with `useSignal`.
138
-
139
- ```tsx
140
- import { Engine } from '@ringozz/godot';
141
- import { SceneTree } from '@ringozz/godot/SceneTree';
142
- import { useSignal } from '@ringozz/react-godot';
143
-
144
- const tree = Engine.getMainLoop() as SceneTree;
145
- const root = tree.root;
146
-
147
- // Subscribe to frame updates (process loop)
148
- useSignal(tree.processFrame, () => {
149
- // Update animations, camera matrix, physics targets, etc.
150
- });
151
-
152
- // Subscribe to window input events
153
- useSignal(root.windowInput, (event) => {
154
- if (event instanceof InputEventMouseMotion) {
155
- // Handle mouse motion
156
- }
157
- // IMPORTANT: Always free transient input event objects
158
- event.free();
159
- });
160
- ```
161
-
162
- > **Memory Tip**: Godot input events should be explicitly freed by calling `event.free()` inside your signal handler.
163
-
164
- ---
165
-
166
- ## Full Example
167
-
168
- Below is a complete interactive 3D physics scene with custom camera controls and physics bodies:
169
-
170
- ```tsx
171
- import { Color, Key, MouseButton, Vector3, Engine } from '@ringozz/godot';
172
- import { BoxMesh } from '@ringozz/godot/BoxMesh';
173
- import { BoxShape3D } from '@ringozz/godot/BoxShape3D';
174
- import { Camera3D } from '@ringozz/godot/Camera3D';
175
- import { CollisionShape3D } from '@ringozz/godot/CollisionShape3D';
176
- import { DirectionalLight3D } from '@ringozz/godot/DirectionalLight3D';
177
- import { BGMode, Environment, ToneMapper } from '@ringozz/godot/Environment';
178
- import { InputEventMouseButton } from '@ringozz/godot/InputEventMouseButton';
179
- import { InputEventMouseMotion } from '@ringozz/godot/InputEventMouseMotion';
180
- import { MeshInstance3D } from '@ringozz/godot/MeshInstance3D';
181
- import { PhysicsMaterial } from '@ringozz/godot/PhysicsMaterial';
182
- import { RigidBody3D } from '@ringozz/godot/RigidBody3D';
183
- import { SceneTree } from '@ringozz/godot/SceneTree';
184
- import { SphereMesh } from '@ringozz/godot/SphereMesh';
185
- import { SphereShape3D } from '@ringozz/godot/SphereShape3D';
186
- import { StandardMaterial3D } from '@ringozz/godot/StandardMaterial3D';
187
- import { StaticBody3D } from '@ringozz/godot/StaticBody3D';
188
- import { WorldEnvironment } from '@ringozz/godot/WorldEnvironment';
189
- import { useSignal, type ComponentProps } from '@ringozz/react-godot';
190
- import { useRef, type ReactElement } from 'react';
191
-
192
- const tree = Engine.getMainLoop() as SceneTree;
193
- const root = tree.root;
194
-
195
- function PhysBody({ color, shape, children, ...rest }: {
196
- color: Color | number[];
197
- shape: ReactElement;
198
- } & ComponentProps<typeof RigidBody3D>) {
199
- return (
200
- <RigidBody3D {...rest}>
201
- <MeshInstance3D>
202
- {children}
203
- <StandardMaterial3D attach="materialOverride" albedoColor={color} />
204
- </MeshInstance3D>
205
- <CollisionShape3D>{shape}</CollisionShape3D>
206
- </RigidBody3D>
207
- );
208
- }
209
-
210
- export function App() {
211
- const cameraRef = useRef<Camera3D>(null);
212
- const isDragging = useRef(false);
213
- const yaw = useRef(0.7);
214
- const pitch = useRef(0.3);
215
- const zoom = useRef(7);
216
-
217
- useSignal(root.windowInput, (event) => {
218
- if (event instanceof InputEventMouseMotion && isDragging.current) {
219
- yaw.current -= event.relative.x * 0.005;
220
- pitch.current = Math.max(-1.4, Math.min(1.4, pitch.current + event.relative.y * 0.005));
221
- } else if (event instanceof InputEventMouseButton) {
222
- if (event.buttonIndex === MouseButton.MOUSE_BUTTON_LEFT) {
223
- isDragging.current = event.pressed;
224
- }
225
- }
226
- event.free();
227
- });
228
-
229
- useSignal(tree.processFrame, () => {
230
- const camera = cameraRef.current;
231
- if (!camera) return;
232
-
233
- const cx = zoom.current * Math.cos(pitch.current) * Math.sin(yaw.current);
234
- const cy = zoom.current * Math.sin(pitch.current) + 1;
235
- const cz = zoom.current * Math.cos(pitch.current) * Math.cos(yaw.current);
236
- camera.position = new Vector3(cx, cy, cz);
237
- camera.lookAt(new Vector3(0, 1, 0), new Vector3(0, 1, 0));
238
- });
239
-
240
- return (
241
- <>
242
- <WorldEnvironment>
243
- <Environment attach="environment" tonemapMode={ToneMapper.TONE_MAPPER_AGX} backgroundMode={BGMode.BG_COLOR} backgroundColor={[0.05, 0.1, 0.25]} />
244
- </WorldEnvironment>
245
- <DirectionalLight3D name="Sun" rotation={[-0.8, 0.5, 0]} />
246
- <Camera3D name="Camera" ref={cameraRef} />
247
-
248
- {/* Physics Sphere */}
249
- <PhysBody name="BouncySphere" position={[0, 4, 0]} color={[0.2, 1, 0.2]}
250
- shape={<SphereShape3D attach="shape" radius={0.5} />}>
251
- <SphereMesh attach="mesh" radius={0.5} height={1} />
252
- <PhysicsMaterial attach="physicsMaterialOverride" bounce={0.8} />
253
- </PhysBody>
254
-
255
- {/* Ground Plane */}
256
- <StaticBody3D name="Ground">
257
- <CollisionShape3D>
258
- <BoxShape3D attach="shape" size={[10, 0.1, 10]} />
259
- </CollisionShape3D>
260
- <MeshInstance3D>
261
- <BoxMesh attach="mesh" size-x={10} size-y={0.1} size-z={10} />
262
- <StandardMaterial3D attach="materialOverride" albedoColor={[0.2, 0.2, 0.25]} />
263
- </MeshInstance3D>
264
- </StaticBody3D>
265
- </>
266
- );
267
- }
268
- ```
269
-
270
- ---
271
-
272
- ## API Summary
273
-
274
- | Export | Type | Description |
275
- | :--- | :--- | :--- |
276
- | `createRoot(parent)` | Function | Mounts a React component tree into a target Godot `Node` (e.g. `tree.root`). Returns `{ render, unmount }`. |
277
- | `createPortal(children, container)` | Function | Renders children into a target Godot `Node` (e.g. `CanvasLayer` or `SubViewport`). |
278
- | `useSignal(signal, callback)` | Hook | Connects a callback to a Godot object signal (e.g. `tree.processFrame`, `node.treeEntered`). Disconnects on unmount. |
279
- | `useMutableCallback(fn)` | Hook | Returns a `RefObject` whose `.current` always points to the latest callback implementation. |
280
- | `ComponentProps<T>` | Type | Utility type to infer valid React JSX props for any Godot node class `T`. |
1
+ # `@ringozz/react-godot`
2
+
3
+ Declarative, component-driven **Godot 4** scene graph management in React. Built for high-performance applications using `@ringozz/godot`.
4
+
5
+ ## Overview
6
+
7
+ `@ringozz/react-godot` brings a **React Three Fiber (R3F)**-like developer experience to Godot. It provides a custom React reconciler that renders React components directly into Godot's live engine scene tree (`SceneTree`).
8
+
9
+ If you are familiar with React Three Fiber, the core paradigms will feel instantly recognizable:
10
+ - **Declarative Nodes**: Godot 3D/2D nodes (e.g., `<RigidBody3D>`, `<Camera3D>`, `<DirectionalLight3D>`) map directly to JSX components.
11
+ - **Resource Attachment**: Use the `attach` prop to assign nested Godot resources (materials, shapes, meshes, environments) directly to parent properties.
12
+ - **Reactive Engine Loop**: Use hooks like `useSignal` to hook into Godot signals (`processFrame`, `windowInput`) without triggering React state re-renders.
13
+
14
+ ## Installation & Setup
15
+
16
+ ### 1. Dependencies
17
+
18
+ ```bash
19
+ npm install @ringozz/react-godot react
20
+ ```
21
+
22
+ ### 2. TypeScript Configuration (`tsconfig.json`)
23
+
24
+ To enable custom JSX element resolution for Godot nodes, configure `jsxImportSource` and module settings in `tsconfig.json`:
25
+
26
+ ```json
27
+ {
28
+ "compilerOptions": {
29
+ "module": "esnext",
30
+ "target": "es2025",
31
+ "jsx": "react-jsx",
32
+ "jsxImportSource": "@ringozz/react-godot",
33
+ "rewriteRelativeImportExtensions": true,
34
+ "verbatimModuleSyntax": true
35
+ }
36
+ }
37
+ ```
38
+
39
+ ## Application Entry & Portal Rendering
40
+
41
+ ### 1. Mounting with `createRoot(parent: Node)`
42
+ `createRoot` is the primary entry point for mounting a React component tree into a Godot target `Node` (typically `SceneTree.root`).
43
+
44
+ ```tsx
45
+ import { Engine } from '@ringozz/godot/Engine';
46
+ import { SceneTree } from '@ringozz/godot/SceneTree';
47
+ import { createRoot } from '@ringozz/react-godot';
48
+ import { App } from './App';
49
+
50
+ const tree = Engine.getMainLoop() as SceneTree;
51
+ const { render } = createRoot(tree.root);
52
+
53
+ render(<App />);
54
+ ```
55
+
56
+ - Returns `{ render, unmount }`.
57
+ - Enables React `StrictMode` automatically in development (`NODE_ENV === 'development'`).
58
+
59
+ ### 2. Render Portals with `createPortal(children, container)`
60
+ `createPortal` allows rendering a React sub-tree into a different Godot `Node` in the hierarchy—such as a `CanvasLayer` for 2D UI overlays, a `SubViewport`, or an isolated container node.
61
+
62
+ ```tsx
63
+ import { createPortal } from '@ringozz/react-godot';
64
+ import { Label } from '@ringozz/godot/Label';
65
+
66
+ function Overlay({ overlayNode }: { overlayNode: Node }) {
67
+ return createPortal(
68
+ <Label text="HUD Overlay" position={[20, 20]} />,
69
+ overlayNode
70
+ );
71
+ }
72
+ ```
73
+
74
+ - **Container Constraint**: The target `container` must be a Godot `Node` (it cannot target `Resource` instances).
75
+ - **Cleanup**: Unmounting the portal safely disposes of and frees its child Godot nodes.
76
+
77
+ ## Core Concepts & Patterns
78
+
79
+ ### 1. Existing Objects with `object` Prop
80
+
81
+ If you already have a pre-existing Godot `Node`, `Resource`, or `PackedScene` instance (e.g. instantiated from C++ or loaded from disk), pass it via the `object` prop to adopt it into the React component tree instead of letting the reconciler instantiate a new object:
82
+
83
+ ```tsx
84
+ <Node object={myExistingGodotNode}>
85
+ {/* Children attached to existing node */}
86
+ </Node>
87
+ ```
88
+
89
+ - **`object` is immutable on a mounted instance.** It selects the host instance once, at creation. A re-render that changes `object` on an existing element throws (`Cannot change the \`object\` of a mounted instance`) because React cannot swap a fiber's Godot node remount with a new `key` instead.
90
+ - **A `PackedScene` `object` is instantiated once per host mount** — each element gets a fresh node tree; the result is a plain `Node` (not `.reference()`'d) freed on unmount. The same `PackedScene` can feed multiple elements; give same-type siblings stable `key`s.
91
+ - **Dynamic same-type sibling lists need stable `key`s.** Godot host nodes are identity, not content: React reconciles keyless siblings by position, so deleting the *first* of two same-type siblings reuses its Godot node for the survivor (a plain state re-render does this too; the web dev server's React Fast Refresh makes it especially likely). Add `key="..."` to each dynamically toggled same-type sibling to keep nodes pinned to the right elements.
92
+
93
+ ### 2. Resource Nesting with `attach`
94
+
95
+ In Godot, nodes often hold references to `Resource` objects (such as shapes, meshes, materials, or environments). Use the `attach` prop to automatically assign a child resource to a specific property on its parent:
96
+
97
+ ```tsx
98
+ /* Attaching a shape to CollisionShape3D */
99
+ <CollisionShape3D>
100
+ <BoxShape3D attach="shape" size={[1, 1, 1]} />
101
+ </CollisionShape3D>
102
+
103
+ /* Attaching a material override to MeshInstance3D */
104
+ <MeshInstance3D>
105
+ <BoxMesh attach="mesh" />
106
+ <StandardMaterial3D attach="materialOverride" albedoColor={[1, 0, 0]} />
107
+ </MeshInstance3D>
108
+
109
+ /* Attaching physics material to RigidBody3D */
110
+ <RigidBody3D>
111
+ <PhysicsMaterial attach="physicsMaterialOverride" bounce={0.8} />
112
+ </RigidBody3D>
113
+
114
+ /* Attaching environment to WorldEnvironment */
115
+ <WorldEnvironment>
116
+ <Environment attach="environment" backgroundColor={[0.1, 0.1, 0.2]} />
117
+ </WorldEnvironment>
118
+ ```
119
+
120
+ ### 2. Properties & Helper Types
121
+
122
+ Props map directly to Godot node setters and properties. Helper arrays are automatically cast to Godot types:
123
+
124
+ - **Vectors**: `position={[0, 1, 0]}`, `scale={[2, 2, 2]}`
125
+ - **Colors**: `albedoColor={[1, 0.2, 0.2]}` or `Color` objects
126
+ - **Sub-properties / Dash props**: Set individual vector/color components directly using dash syntax:
127
+ ```tsx
128
+ <BoxMesh attach="mesh" size-x={0.5} size-y={1.0} size-z={0.5} />
129
+ ```
130
+
131
+ ### 3. Engine Signals & Event Subscription (`useSignal`)
132
+
133
+ Subscribe to Godot engine signals cleanly with `useSignal`.
134
+
135
+ ```tsx
136
+ import { Engine } from '@ringozz/godot';
137
+ import { SceneTree } from '@ringozz/godot/SceneTree';
138
+ import { useSignal } from '@ringozz/react-godot';
139
+
140
+ const tree = Engine.getMainLoop() as SceneTree;
141
+ const root = tree.root;
142
+
143
+ // Subscribe to frame updates (process loop)
144
+ useSignal(tree.processFrame, () => {
145
+ // Update animations, camera matrix, physics targets, etc.
146
+ });
147
+
148
+ // Subscribe to window input events
149
+ useSignal(root.windowInput, (event) => {
150
+ if (event instanceof InputEventMouseMotion) {
151
+ // Handle mouse motion
152
+ }
153
+ });
154
+ ```
155
+
156
+ ## Full Example
157
+
158
+ Below is a complete interactive 3D physics scene with custom camera controls and physics bodies:
159
+
160
+ ```tsx
161
+ import { Color, Key, MouseButton, Vector3, Engine } from '@ringozz/godot';
162
+ import { BoxMesh } from '@ringozz/godot/BoxMesh';
163
+ import { BoxShape3D } from '@ringozz/godot/BoxShape3D';
164
+ import { Camera3D } from '@ringozz/godot/Camera3D';
165
+ import { CollisionShape3D } from '@ringozz/godot/CollisionShape3D';
166
+ import { DirectionalLight3D } from '@ringozz/godot/DirectionalLight3D';
167
+ import { BGMode, Environment, ToneMapper } from '@ringozz/godot/Environment';
168
+ import { InputEventMouseButton } from '@ringozz/godot/InputEventMouseButton';
169
+ import { InputEventMouseMotion } from '@ringozz/godot/InputEventMouseMotion';
170
+ import { MeshInstance3D } from '@ringozz/godot/MeshInstance3D';
171
+ import { PhysicsMaterial } from '@ringozz/godot/PhysicsMaterial';
172
+ import { RigidBody3D } from '@ringozz/godot/RigidBody3D';
173
+ import { SceneTree } from '@ringozz/godot/SceneTree';
174
+ import { SphereMesh } from '@ringozz/godot/SphereMesh';
175
+ import { SphereShape3D } from '@ringozz/godot/SphereShape3D';
176
+ import { StandardMaterial3D } from '@ringozz/godot/StandardMaterial3D';
177
+ import { StaticBody3D } from '@ringozz/godot/StaticBody3D';
178
+ import { WorldEnvironment } from '@ringozz/godot/WorldEnvironment';
179
+ import { useSignal, type ComponentProps } from '@ringozz/react-godot';
180
+ import { useRef, type ReactElement } from 'react';
181
+
182
+ const tree = Engine.getMainLoop() as SceneTree;
183
+ const root = tree.root;
184
+
185
+ function PhysBody({ color, shape, children, ...rest }: {
186
+ color: Color | number[];
187
+ shape: ReactElement;
188
+ } & ComponentProps<typeof RigidBody3D>) {
189
+ return (
190
+ <RigidBody3D {...rest}>
191
+ <MeshInstance3D>
192
+ {children}
193
+ <StandardMaterial3D attach="materialOverride" albedoColor={color} />
194
+ </MeshInstance3D>
195
+ <CollisionShape3D>{shape}</CollisionShape3D>
196
+ </RigidBody3D>
197
+ );
198
+ }
199
+
200
+ export function App() {
201
+ const cameraRef = useRef<Camera3D>(null);
202
+ const isDragging = useRef(false);
203
+ const yaw = useRef(0.7);
204
+ const pitch = useRef(0.3);
205
+ const zoom = useRef(7);
206
+
207
+ useSignal(root.windowInput, (event) => {
208
+ if (event instanceof InputEventMouseMotion && isDragging.current) {
209
+ yaw.current -= event.relative.x * 0.005;
210
+ pitch.current = Math.max(-1.4, Math.min(1.4, pitch.current + event.relative.y * 0.005));
211
+ } else if (event instanceof InputEventMouseButton) {
212
+ if (event.buttonIndex === MouseButton.MOUSE_BUTTON_LEFT) {
213
+ isDragging.current = event.pressed;
214
+ }
215
+ }
216
+ event.free();
217
+ });
218
+
219
+ useSignal(tree.processFrame, () => {
220
+ const camera = cameraRef.current;
221
+ if (!camera) return;
222
+
223
+ const cx = zoom.current * Math.cos(pitch.current) * Math.sin(yaw.current);
224
+ const cy = zoom.current * Math.sin(pitch.current) + 1;
225
+ const cz = zoom.current * Math.cos(pitch.current) * Math.cos(yaw.current);
226
+ camera.position = new Vector3(cx, cy, cz);
227
+ camera.lookAt(new Vector3(0, 1, 0), new Vector3(0, 1, 0));
228
+ });
229
+
230
+ return (
231
+ <>
232
+ <WorldEnvironment>
233
+ <Environment attach="environment" tonemapMode={ToneMapper.TONE_MAPPER_AGX} backgroundMode={BGMode.BG_COLOR} backgroundColor={[0.05, 0.1, 0.25]} />
234
+ </WorldEnvironment>
235
+ <DirectionalLight3D name="Sun" rotation={[-0.8, 0.5, 0]} />
236
+ <Camera3D name="Camera" ref={cameraRef} />
237
+
238
+ {/* Physics Sphere */}
239
+ <PhysBody name="BouncySphere" position={[0, 4, 0]} color={[0.2, 1, 0.2]}
240
+ shape={<SphereShape3D attach="shape" radius={0.5} />}>
241
+ <SphereMesh attach="mesh" radius={0.5} height={1} />
242
+ <PhysicsMaterial attach="physicsMaterialOverride" bounce={0.8} />
243
+ </PhysBody>
244
+
245
+ {/* Ground Plane */}
246
+ <StaticBody3D name="Ground">
247
+ <CollisionShape3D>
248
+ <BoxShape3D attach="shape" size={[10, 0.1, 10]} />
249
+ </CollisionShape3D>
250
+ <MeshInstance3D>
251
+ <BoxMesh attach="mesh" size-x={10} size-y={0.1} size-z={10} />
252
+ <StandardMaterial3D attach="materialOverride" albedoColor={[0.2, 0.2, 0.25]} />
253
+ </MeshInstance3D>
254
+ </StaticBody3D>
255
+ </>
256
+ );
257
+ }
258
+ ```
259
+
260
+ ## API Summary
261
+
262
+ | Export | Type | Description |
263
+ | :--- | :--- | :--- |
264
+ | `createRoot(parent)` | Function | Mounts a React component tree into a target Godot `Node` (e.g. `tree.root`). Returns `{ render, unmount }`. |
265
+ | `createPortal(children, container)` | Function | Renders children into a target Godot `Node` (e.g. `CanvasLayer` or `SubViewport`). |
266
+ | `useSignal(signal, callback)` | Hook | Connects a callback to a Godot object signal (e.g. `tree.processFrame`, `node.treeEntered`). Disconnects on unmount. |
267
+ | `useMutableCallback(fn)` | Hook | Returns a `RefObject` whose `.current` always points to the latest callback implementation. |
268
+ | `ComponentProps<T>` | Type | Utility type to infer valid React JSX props for any Godot node class `T`. |
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@ringozz/react-godot",
3
3
  "author": "Vladimir Davidovich",
4
- "version": "1.0.0-4",
4
+ "version": "1.0.0-5",
5
5
  "description": "A React renderer for Godot Engine via @ringozz/godot",
6
+ "keywords": [
7
+ "react",
8
+ "godot"
9
+ ],
6
10
  "type": "module",
7
11
  "main": "./src/index.ts",
8
12
  "types": "./src/index.ts",
@@ -16,7 +20,7 @@
16
20
  "*.md"
17
21
  ],
18
22
  "dependencies": {
19
- "@ringozz/godot": "^4.7.1-7",
23
+ "@ringozz/godot": "^4.7.1-8",
20
24
  "@types/react-reconciler": "^0.33.0",
21
25
  "react-reconciler": "^0.33.0"
22
26
  },