@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 +268 -280
- package/package.json +6 -2
- package/src/index.ts +58 -58
- package/src/react-fiber.ts +312 -307
- package/src/react-hooks.ts +25 -22
- package/src/react-jsx.ts +45 -41
- package/src/react-types.ts +39 -36
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- **
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
import {
|
|
172
|
-
import {
|
|
173
|
-
import {
|
|
174
|
-
import {
|
|
175
|
-
import {
|
|
176
|
-
import {
|
|
177
|
-
import {
|
|
178
|
-
import {
|
|
179
|
-
import {
|
|
180
|
-
import {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
)
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
<
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
+
"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-
|
|
23
|
+
"@ringozz/godot": "^4.7.1-8",
|
|
20
24
|
"@types/react-reconciler": "^0.33.0",
|
|
21
25
|
"react-reconciler": "^0.33.0"
|
|
22
26
|
},
|