react-three-game 0.0.13 → 0.0.14

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.
Binary file
Binary file
@@ -75,17 +75,14 @@ export const PrefabRoot = forwardRef(({ editMode, data, onPrefabChange, selected
75
75
  localMatrix.decompose(lp, lq, ls);
76
76
  const le = new Euler().setFromQuaternion(lq);
77
77
  // 4. Write back LOCAL transform into the prefab node
78
- const newRoot = updatePrefabNode(data.root, selectedId, (node) => {
79
- var _a, _b, _c;
80
- return (Object.assign(Object.assign({}, node), { components: Object.assign(Object.assign({}, node === null || node === void 0 ? void 0 : node.components), { transform: {
81
- type: "Transform",
82
- properties: {
83
- position: [lp.x, lp.y, lp.z],
84
- rotation: [le.x, le.y, le.z],
85
- scale: [ls.x, ls.y, ls.z],
86
- },
87
- }, geometry: (_a = node.components) === null || _a === void 0 ? void 0 : _a.geometry, material: (_b = node.components) === null || _b === void 0 ? void 0 : _b.material, model: (_c = node.components) === null || _c === void 0 ? void 0 : _c.model }) }));
88
- });
78
+ const newRoot = updatePrefabNode(data.root, selectedId, (node) => (Object.assign(Object.assign({}, node), { components: Object.assign(Object.assign({}, node === null || node === void 0 ? void 0 : node.components), { transform: {
79
+ type: "Transform",
80
+ properties: {
81
+ position: [lp.x, lp.y, lp.z],
82
+ rotation: [le.x, le.y, le.z],
83
+ scale: [ls.x, ls.y, ls.z],
84
+ },
85
+ } }) })));
89
86
  onPrefabChange(Object.assign(Object.assign({}, data), { root: newRoot }));
90
87
  };
91
88
  useEffect(() => {
@@ -173,11 +170,11 @@ function GameObjectRenderer({ gameObject, selectedId, onSelect, registerRef, loa
173
170
  // --- 5. Render children (always relative transforms) ---
174
171
  const children = ((_d = gameObject.children) !== null && _d !== void 0 ? _d : []).map((child) => (_jsx(GameObjectRenderer, { gameObject: child, selectedId: selectedId, onSelect: onSelect, registerRef: registerRef, loadedModels: loadedModels, loadedTextures: loadedTextures, editMode: editMode, parentMatrix: worldMatrix }, child.id)));
175
172
  // --- 4. Wrap with physics if needed ---
176
- // Combine core and children so they both get wrapped by physics (if present)
177
- const content = (_jsxs(_Fragment, { children: [core, children] }));
178
- const physicsWrapped = wrapPhysicsIfNeeded(gameObject, content, ctx);
173
+ // Only wrap the core content (geometry/model), not children
174
+ // Children should be siblings, not inside the physics body
175
+ const physicsWrapped = wrapPhysicsIfNeeded(gameObject, core, ctx);
179
176
  // --- 6. Final group wrapper ---
180
- return (_jsx("group", { ref: (el) => registerRef(gameObject.id, el), position: transformProps.position, rotation: transformProps.rotation, scale: transformProps.scale, onPointerDown: handlePointerDown, onPointerMove: handlePointerMove, onPointerUp: handlePointerUp, children: physicsWrapped }));
177
+ return (_jsxs("group", { ref: (el) => registerRef(gameObject.id, el), position: transformProps.position, rotation: transformProps.rotation, scale: transformProps.scale, onPointerDown: handlePointerDown, onPointerMove: handlePointerMove, onPointerUp: handlePointerUp, children: [physicsWrapped, children] }));
181
178
  }
182
179
  // Helper: render an instanced GameInstance (terminal node)
183
180
  function renderInstancedNode(gameObject, worldMatrix, ctx) {
@@ -242,7 +239,7 @@ function wrapPhysicsIfNeeded(gameObject, content, ctx) {
242
239
  const physicsDef = getComponent('Physics');
243
240
  if (!physicsDef || !physicsDef.View)
244
241
  return content;
245
- return (_jsx(physicsDef.View, { properties: Object.assign(Object.assign({}, physics.properties), { id: gameObject.id }), registerRef: ctx.registerRef, editMode: ctx.editMode, children: content }));
242
+ return (_jsx(physicsDef.View, { properties: Object.assign(Object.assign({}, physics.properties), { id: gameObject.id }), editMode: ctx.editMode, children: content }));
246
243
  }
247
244
  export default PrefabRoot;
248
245
  function getNodeTransformProps(node) {
@@ -3,10 +3,10 @@ function PhysicsComponentEditor({ component, onUpdate }) {
3
3
  return _jsxs("div", { children: [_jsx("label", { className: "block text-[9px] text-cyan-400/60 uppercase tracking-wider mb-0.5", children: "Type" }), _jsxs("select", { className: "w-full bg-black/40 border border-cyan-500/30 px-1 py-0.5 text-[10px] text-cyan-300 font-mono focus:outline-none focus:border-cyan-400/50", value: component.properties.type, onChange: e => onUpdate({ type: e.target.value }), children: [_jsx("option", { value: "dynamic", children: "Dynamic" }), _jsx("option", { value: "fixed", children: "Fixed" })] })] });
4
4
  }
5
5
  import { RigidBody } from "@react-three/rapier";
6
- function PhysicsComponentView({ properties, children, registerRef, transform, editMode }) {
6
+ function PhysicsComponentView({ properties, children, editMode }) {
7
7
  if (editMode)
8
8
  return children;
9
- return (_jsx(RigidBody, { ref: el => registerRef && registerRef(properties.id, el), position: transform === null || transform === void 0 ? void 0 : transform.position, rotation: transform === null || transform === void 0 ? void 0 : transform.rotation, scale: transform === null || transform === void 0 ? void 0 : transform.scale, type: properties.type, colliders: "cuboid", children: children }));
9
+ return (_jsx(RigidBody, { type: properties.type, colliders: "cuboid", children: children }));
10
10
  }
11
11
  const PhysicsComponent = {
12
12
  name: 'Physics',
@@ -22,7 +22,7 @@ function SpotLightView({ properties }) {
22
22
  const penumbra = (_d = properties.penumbra) !== null && _d !== void 0 ? _d : 0.5;
23
23
  const distance = (_e = properties.distance) !== null && _e !== void 0 ? _e : 100;
24
24
  const castShadow = (_f = properties.castShadow) !== null && _f !== void 0 ? _f : true;
25
- return (_jsx(_Fragment, { children: _jsx("spotLight", { color: color, intensity: intensity, angle: angle, penumbra: penumbra, distance: distance, castShadow: castShadow, "target-position": [0, 0, 0], position: [0, 0, 0] }) }));
25
+ return (_jsx(_Fragment, { children: _jsx("spotLight", { color: color, intensity: intensity, angle: angle, penumbra: penumbra, distance: distance, castShadow: castShadow }) }));
26
26
  }
27
27
  const SpotLightComponent = {
28
28
  name: 'SpotLight',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-three-game",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "Batteries included React Three Fiber game engine",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -103,9 +103,6 @@ export const PrefabRoot = forwardRef<Group, {
103
103
  scale: [ls.x, ls.y, ls.z] as [number, number, number],
104
104
  },
105
105
  },
106
- geometry: node.components?.geometry,
107
- material: node.components?.material,
108
- model: node.components?.model,
109
106
  },
110
107
  }));
111
108
 
@@ -272,14 +269,9 @@ function GameObjectRenderer({
272
269
  ));
273
270
 
274
271
  // --- 4. Wrap with physics if needed ---
275
- // Combine core and children so they both get wrapped by physics (if present)
276
- const content = (
277
- <>
278
- {core}
279
- {children}
280
- </>
281
- );
282
- const physicsWrapped = wrapPhysicsIfNeeded(gameObject, content, ctx);
272
+ // Only wrap the core content (geometry/model), not children
273
+ // Children should be siblings, not inside the physics body
274
+ const physicsWrapped = wrapPhysicsIfNeeded(gameObject, core, ctx);
283
275
 
284
276
  // --- 6. Final group wrapper ---
285
277
  return (
@@ -293,6 +285,7 @@ function GameObjectRenderer({
293
285
  onPointerUp={handlePointerUp}
294
286
  >
295
287
  {physicsWrapped}
288
+ {children}
296
289
  </group>
297
290
  );
298
291
  }
@@ -404,7 +397,6 @@ function wrapPhysicsIfNeeded(gameObject: GameObjectType, content: React.ReactNod
404
397
  return (
405
398
  <physicsDef.View
406
399
  properties={{ ...physics.properties, id: gameObject.id }}
407
- registerRef={ctx.registerRef}
408
400
  editMode={ctx.editMode}
409
401
  >
410
402
  {content}
@@ -16,17 +16,11 @@ function PhysicsComponentEditor({ component, onUpdate }: { component: any; onUpd
16
16
 
17
17
 
18
18
  import { RigidBody } from "@react-three/rapier";
19
- import { Object3D } from "three";
20
- import { useRef } from "react";
21
19
 
22
- function PhysicsComponentView({ properties, children, registerRef, transform, editMode }: any) {
20
+ function PhysicsComponentView({ properties, children, editMode }: any) {
23
21
  if (editMode) return children;
24
22
  return (
25
23
  <RigidBody
26
- ref={el => registerRef && registerRef(properties.id, el as unknown as Object3D)}
27
- position={transform?.position}
28
- rotation={transform?.rotation}
29
- scale={transform?.scale}
30
24
  type={properties.type}
31
25
  colliders="cuboid"
32
26
  >
@@ -108,8 +108,6 @@ function SpotLightView({ properties }: { properties: any }) {
108
108
  penumbra={penumbra}
109
109
  distance={distance}
110
110
  castShadow={castShadow}
111
- target-position={[0, 0, 0]}
112
- position={[0, 0, 0]}
113
111
  />
114
112
  </>
115
113
  );