react-three-game 0.0.72 → 0.0.74

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/dist/index.d.ts CHANGED
@@ -19,9 +19,9 @@ export type { ExportGLBOptions } from './tools/prefabeditor/utils';
19
19
  export { createModelNode, createImageNode, } from './tools/prefabeditor/prefab';
20
20
  export type { PrefabEditorProps, PrefabEditorRef, } from './tools/prefabeditor/PrefabEditor';
21
21
  export type { SpawnOptions, Scene, Entity, EntityComponent, EntityData, EntityUpdate, PropertyPath, SceneUpdates, } from './tools/prefabeditor/scene';
22
- export type { PrefabRootProps, AssetRuntime } from './tools/prefabeditor/PrefabRoot';
23
- export type { EntityRuntime, LiveObjectRef, LiveRigidBodyRef } from './tools/prefabeditor/PrefabRoot';
24
- export { useAssetRuntime, useEntityRuntime, useEntityObjectRef, useEntityRigidBodyRef } from './tools/prefabeditor/PrefabRoot';
22
+ export type { PrefabRootProps } from './tools/prefabeditor/PrefabRoot';
23
+ export type { AssetRuntime, EntityRuntime, LiveObjectRef, LiveRigidBodyRef } from './tools/prefabeditor/runtimeContext';
24
+ export { useAssetRuntime, useEntityRuntime, useEntityObjectRef, useEntityRigidBodyRef } from './tools/prefabeditor/runtimeContext';
25
25
  export type { Component, ComponentViewProps } from './tools/prefabeditor/components/ComponentRegistry';
26
26
  export type { FieldDefinition, FieldType } from './tools/prefabeditor/components/Input';
27
27
  export type { Prefab, GameObject, ComponentData } from './tools/prefabeditor/types';
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ export { FieldRenderer, FieldGroup, ListEditor, Label, Vector3Input, Vector3Fiel
19
19
  // Prefab Editor - Utils
20
20
  export { loadJson, saveJson, exportGLB, exportGLBData, regenerateIds, computeParentWorldMatrix, } from './tools/prefabeditor/utils';
21
21
  export { createModelNode, createImageNode, } from './tools/prefabeditor/prefab';
22
- export { useAssetRuntime, useEntityRuntime, useEntityObjectRef, useEntityRigidBodyRef } from './tools/prefabeditor/PrefabRoot';
22
+ export { useAssetRuntime, useEntityRuntime, useEntityObjectRef, useEntityRigidBodyRef } from './tools/prefabeditor/runtimeContext';
23
23
  export { findComponent, findComponentEntry, hasComponent } from './tools/prefabeditor/types';
24
24
  // Game Events (physics + custom events)
25
25
  export { gameEvents, useGameEvent, getEntityIdFromRigidBody } from './tools/prefabeditor/GameEvents';
@@ -28,6 +28,13 @@ extend({
28
28
  MeshStandardNodeMaterial: MeshStandardNodeMaterial,
29
29
  SpriteNodeMaterial: SpriteNodeMaterial,
30
30
  });
31
+ function applyCanvasInteractionGuards(canvas) {
32
+ canvas.style.touchAction = 'none';
33
+ canvas.style.userSelect = 'none';
34
+ canvas.style.setProperty('-webkit-touch-callout', 'none');
35
+ canvas.style.setProperty('-webkit-user-drag', 'none');
36
+ canvas.style.setProperty('-webkit-tap-highlight-color', 'transparent');
37
+ }
31
38
  export default function GameCanvas(_a) {
32
39
  var { loader = false, children, glConfig, canvasRef, onCreated, style } = _a, props = __rest(_a, ["loader", "children", "glConfig", "canvasRef", "onCreated", "style"]);
33
40
  const [frameloop, setFrameloop] = useState("never");
@@ -40,6 +47,7 @@ export default function GameCanvas(_a) {
40
47
  });
41
48
  return renderer;
42
49
  }), onCreated: (state) => {
50
+ applyCanvasInteractionGuards(state.gl.domElement);
43
51
  if (canvasRef) {
44
52
  canvasRef.current = state.gl.domElement;
45
53
  }
@@ -4,7 +4,7 @@ import { OrbitControls, View, PerspectiveCamera } from "@react-three/drei";
4
4
  import { Component as ReactComponent, Suspense, useEffect, useLayoutEffect, useState, useRef } from "react";
5
5
  import { createPortal } from 'react-dom';
6
6
  import { TextureLoader } from "three";
7
- import { loadModel } from "../dragdrop";
7
+ import { loadModel } from "../dragdrop/modelLoader";
8
8
  class ErrorBoundary extends ReactComponent {
9
9
  constructor(props) {
10
10
  super(props);
@@ -366,7 +366,7 @@ const PrefabEditor = forwardRef(({ basePath, initialPrefab, physics = true, mode
366
366
  }
367
367
  (_d = canvasProps === null || canvasProps === void 0 ? void 0 : canvasProps.onPointerMissed) === null || _d === void 0 ? void 0 : _d.call(canvasProps, event);
368
368
  }
369
- : canvasProps === null || canvasProps === void 0 ? void 0 : canvasProps.onPointerMissed, children: [physics ? (_jsx(Physics, { debug: isEditMode, paused: isEditMode, children: content })) : content, isEditMode && (_jsxs(_Fragment, { children: [_jsx(MapControls, { ref: controlsRef, makeDefault: true }), selectedObject && (_jsx(TransformControls, { object: selectedObject, mode: transformMode, space: "local", onObjectChange: handleTransformChange, translationSnap: positionSnap > 0 ? positionSnap : undefined, rotationSnap: rotationSnap > 0 ? rotationSnap : undefined, scaleSnap: scaleSnap > 0 ? scaleSnap : undefined }, `transform-${transformMode}-${positionSnap}-${rotationSnap}-${scaleSnap}`))] }))] })), showUI && (_jsxs(_Fragment, { children: [_jsxs("div", { style: toolbar.panel, children: [_jsx("button", { style: base.btn, onClick: toggleMode, children: isEditMode ? "▶" : "⏸" }), uiPlugins] }), isEditMode && (_jsx(EditorUI, { selectedId: selectedId, setSelectedId: setSelection, getPrefab: getPrefab, onReplacePrefab: (prefab) => loadPrefab(prefab, { resetHistory: true }), onImportPrefab: importPrefab, basePath: basePath, onUndo: undo, onRedo: redo, canUndo: historyIndex > 0, canRedo: historyIndex < history.length - 1 }))] }))] }) });
369
+ : canvasProps === null || canvasProps === void 0 ? void 0 : canvasProps.onPointerMissed, children: [physics ? (_jsx(Physics, { debug: isEditMode, paused: isEditMode, children: content })) : content, isEditMode && (_jsxs(_Fragment, { children: [_jsx(MapControls, { ref: controlsRef, enableDamping: false, makeDefault: true }), selectedObject && (_jsx(TransformControls, { object: selectedObject, mode: transformMode, space: "local", onObjectChange: handleTransformChange, translationSnap: positionSnap > 0 ? positionSnap : undefined, rotationSnap: rotationSnap > 0 ? rotationSnap : undefined, scaleSnap: scaleSnap > 0 ? scaleSnap : undefined }, `transform-${transformMode}-${positionSnap}-${rotationSnap}-${scaleSnap}`))] }))] })), showUI && (_jsxs(_Fragment, { children: [_jsxs("div", { style: toolbar.panel, children: [_jsx("button", { style: base.btn, onClick: toggleMode, children: isEditMode ? "▶" : "⏸" }), uiPlugins] }), isEditMode && (_jsx(EditorUI, { selectedId: selectedId, setSelectedId: setSelection, getPrefab: getPrefab, onReplacePrefab: (prefab) => loadPrefab(prefab, { resetHistory: true }), onImportPrefab: importPrefab, basePath: basePath, onUndo: undo, onRedo: redo, canUndo: historyIndex > 0, canRedo: historyIndex < history.length - 1 }))] }))] }) });
370
370
  });
371
371
  PrefabEditor.displayName = "PrefabEditor";
372
372
  export default PrefabEditor;
@@ -3,40 +3,6 @@ import { ThreeEvent } from "@react-three/fiber";
3
3
  import { GameObject as GameObjectType, Prefab } from "./types";
4
4
  import { LoadedModels } from "../dragdrop";
5
5
  import { PrefabStoreApi } from "./prefabStore";
6
- /** Scene-wide shared services available to component Views inside a PrefabRoot. */
7
- export interface AssetRuntime {
8
- /** @internal Used by PhysicsComponent. */
9
- registerRigidBodyRef: (id: string, rb: any) => void;
10
- /** Get a loaded model by asset path. */
11
- getModel: (path: string) => Object3D | null;
12
- /** Get a loaded texture by asset path. */
13
- getTexture: (path: string) => Texture | null;
14
- /** Get a loaded sound buffer by asset path. */
15
- getSound: (path: string) => AudioBuffer | null;
16
- /** Get a revision string that changes when loaded assets change (for cache-busting keys). */
17
- getAssetRevision: () => string;
18
- }
19
- export interface EntityRuntime {
20
- nodeId: string;
21
- editMode?: boolean;
22
- isSelected?: boolean;
23
- getObject: <T extends Object3D = Object3D>() => T | null;
24
- getRigidBody: <T = any>() => T | null;
25
- }
26
- export interface LiveObjectRef<T extends Object3D = Object3D> {
27
- readonly current: T | null;
28
- }
29
- export interface LiveRigidBodyRef<T = any> {
30
- readonly current: T | null;
31
- }
32
- /** Access scene-wide shared services from within a component View. */
33
- export declare function useAssetRuntime(): AssetRuntime;
34
- /** Access the current node's runtime from within a component View. */
35
- export declare function useEntityRuntime(): EntityRuntime;
36
- /** Read the current component's Object3D through a live ref-like accessor. */
37
- export declare function useEntityObjectRef<T extends Object3D = Object3D>(): LiveObjectRef<T>;
38
- /** Read the current component's rigid body through a live ref-like accessor. */
39
- export declare function useEntityRigidBodyRef<T = any>(): LiveRigidBodyRef<T>;
40
6
  export interface PrefabRootRef {
41
7
  root: Group | null;
42
8
  getObject: (nodeId: string) => Object3D | null;
@@ -11,73 +11,26 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  };
12
12
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import { useHelper } from "@react-three/drei";
14
- import { forwardRef, createContext, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
14
+ import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
15
15
  import { BoxHelper, Euler, Matrix4, } from "three";
16
16
  import { useStore } from "zustand";
17
17
  import { useClickValid } from "./useClickValid";
18
18
  import { findComponent } from "./types";
19
19
  import { getComponentDef, getComponentAssetRefs, registerComponent } from "./components/ComponentRegistry";
20
- import components from "./components";
20
+ import { builtinComponents } from "./components";
21
21
  import { loadModel, loadSound, loadTexture } from "../dragdrop";
22
22
  import { GameInstance, GameInstanceProvider, getRepeatAxesFromModelProperties, useInstanceCheck } from "./InstanceProvider";
23
23
  import { composeTransform, decompose } from "./utils";
24
24
  import { isPhysicsProps } from "./components/PhysicsComponent";
25
25
  import { denormalizePrefab } from "./prefab";
26
26
  import { createPrefabStore, PrefabStoreProvider, useOptionalPrefabStoreApi, usePrefabChildIds, usePrefabNode, usePrefabRootId } from "./prefabStore";
27
+ import { AssetRuntimeContext, EntityRuntimeScope } from "./runtimeContext";
27
28
  import { sound as soundManager } from "../../helpers/SoundManager";
28
- components.forEach(registerComponent);
29
+ builtinComponents.forEach(registerComponent);
29
30
  const IDENTITY = new Matrix4();
30
31
  const EMPTY_MODELS = {};
31
32
  const EMPTY_TEXTURES = {};
32
33
  const EMPTY_SOUNDS = {};
33
- const AssetRuntimeContext = createContext(null);
34
- const EntityRuntimeContext = createContext(null);
35
- /** Access scene-wide shared services from within a component View. */
36
- export function useAssetRuntime() {
37
- const ctx = useContext(AssetRuntimeContext);
38
- if (!ctx)
39
- throw new Error("useAssetRuntime must be used inside <PrefabRoot>");
40
- return ctx;
41
- }
42
- /** Access the current node's runtime from within a component View. */
43
- export function useEntityRuntime() {
44
- const ctx = useContext(EntityRuntimeContext);
45
- if (!ctx)
46
- throw new Error("useEntityRuntime must be used inside a component View rendered by <PrefabRoot>");
47
- return ctx;
48
- }
49
- /** Read the current component's Object3D through a live ref-like accessor. */
50
- export function useEntityObjectRef() {
51
- const { getObject } = useEntityRuntime();
52
- return useMemo(() => ({
53
- get current() {
54
- return getObject();
55
- },
56
- }), [getObject]);
57
- }
58
- /** Read the current component's rigid body through a live ref-like accessor. */
59
- export function useEntityRigidBodyRef() {
60
- const { getRigidBody } = useEntityRuntime();
61
- return useMemo(() => ({
62
- get current() {
63
- return getRigidBody();
64
- },
65
- }), [getRigidBody]);
66
- }
67
- function EntityRuntimeScope({ nodeId, editMode, isSelected, children, }) {
68
- const assetRuntime = useContext(AssetRuntimeContext);
69
- if (!assetRuntime)
70
- throw new Error("EntityRuntimeScope must be used inside <PrefabRoot>");
71
- const { getObject, getRigidBody } = assetRuntime;
72
- const value = useMemo(() => ({
73
- nodeId,
74
- editMode,
75
- isSelected,
76
- getObject: () => getObject(nodeId),
77
- getRigidBody: () => getRigidBody(nodeId),
78
- }), [editMode, getObject, getRigidBody, isSelected, nodeId]);
79
- return _jsx(EntityRuntimeContext.Provider, { value: value, children: children });
80
- }
81
34
  /** Resolve a relative or absolute asset file path against a base path. */
82
35
  function resolveAssetPath(basePath, file) {
83
36
  if (file.startsWith("http://") || file.startsWith("https://"))
@@ -3,7 +3,7 @@ import { PerspectiveCamera, useHelper } from '@react-three/drei';
3
3
  import { useRef } from 'react';
4
4
  import { CameraHelper } from 'three';
5
5
  import { useFrame } from '@react-three/fiber';
6
- import { useEntityRuntime } from '../PrefabRoot';
6
+ import { useEntityRuntime } from '../runtimeContext';
7
7
  import { FieldGroup, NumberField } from './Input';
8
8
  const cameraDefaults = {
9
9
  fov: 50,
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useRef } from 'react';
3
3
  import { gameEvents } from '../GameEvents';
4
- import { useEntityRuntime } from '../PrefabRoot';
4
+ import { useEntityRuntime } from '../runtimeContext';
5
5
  import { FieldGroup, StringField } from './Input';
6
6
  function ClickComponentEditor({ component, onUpdate }) {
7
7
  return (_jsxs(FieldGroup, { children: [_jsx("div", { style: { fontSize: 12, opacity: 0.8 }, children: "Emits a game event in play mode when this entity is clicked." }), _jsx(StringField, { name: "eventName", label: "Emit Event", values: component.properties, onChange: onUpdate, placeholder: "click" })] }));
@@ -3,7 +3,7 @@ import { useHelper } from "@react-three/drei";
3
3
  import { useRef, useEffect, useState } from "react";
4
4
  import { useFrame } from "@react-three/fiber";
5
5
  import { CameraHelper, Vector3 } from "three";
6
- import { useEntityRuntime } from "../PrefabRoot";
6
+ import { useEntityRuntime } from "../runtimeContext";
7
7
  import { BooleanField, ColorField, NumberField, NumberInput, Vector3Input } from "./Input";
8
8
  import { LightSection, ShadowBiasField, mergeWithDefaults } from "./lightUtils";
9
9
  import { colors } from "../styles";
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Environment } from '@react-three/drei';
3
3
  import { FieldGroup, NumberField } from './Input';
4
- import { useAssetRuntime } from '../PrefabRoot';
4
+ import { useAssetRuntime } from '../runtimeContext';
5
5
  function EnvironmentView({ properties, children, }) {
6
6
  const { getAssetRevision } = useAssetRuntime();
7
7
  const { intensity = 1, resolution = 256 } = properties;
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import { extend } from '@react-three/fiber';
14
14
  import { FieldRenderer, Label, NumberInput } from './Input';
15
- import { useAssetRuntime } from '../PrefabRoot';
15
+ import { useAssetRuntime } from '../runtimeContext';
16
16
  import { useMemo } from 'react';
17
17
  import { MeshBasicNodeMaterial, MeshStandardNodeMaterial } from 'three/webgpu';
18
18
  import { TexturePicker } from '../../assetviewer/page';
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import { ModelPicker } from '../../assetviewer/page';
3
3
  import { useContext, useMemo } from 'react';
4
4
  import { BooleanField, FieldGroup, Label, ListEditor, NumberInput, SelectInput } from './Input';
5
- import { useAssetRuntime } from '../PrefabRoot';
5
+ import { useAssetRuntime } from '../runtimeContext';
6
6
  import { EditorContext } from '../PrefabEditor';
7
7
  import { DEFAULT_REPEAT_AXES, getRepeatAxesFromModelProperties, normalizeRepeatAxes } from '../InstanceProvider';
8
8
  import { colors } from '../styles';
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
13
13
  import { CapsuleCollider, RigidBody, useRapier } from "@react-three/rapier";
14
14
  import { useRef, useEffect, useCallback } from 'react';
15
- import { useAssetRuntime, useEntityRuntime } from "../PrefabRoot";
15
+ import { useAssetRuntime, useEntityRuntime } from "../runtimeContext";
16
16
  import { BooleanField, FieldGroup, ListEditor, NumberField, SelectField, SelectInput, StringInput, Vector3Field } from "./Input";
17
17
  import { gameEvents, getEntityIdFromRigidBody } from "../GameEvents";
18
18
  import { colors } from "../styles";
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import { useEffect, useRef } from 'react';
3
3
  import { useHelper } from '@react-three/drei';
4
4
  import { PointLightHelper } from 'three';
5
- import { useEntityRuntime } from '../PrefabRoot';
5
+ import { useEntityRuntime } from '../runtimeContext';
6
6
  import { BooleanField, ColorField, NumberField } from './Input';
7
7
  import { LightSection, ShadowBiasField, mergeWithDefaults } from './lightUtils';
8
8
  const pointLightDefaults = {
@@ -4,7 +4,7 @@ import { useThree } from '@react-three/fiber';
4
4
  import { SoundPicker } from '../../assetviewer/page';
5
5
  import { sound as soundManager } from '../../../helpers/SoundManager';
6
6
  import { gameEvents } from '../GameEvents';
7
- import { useAssetRuntime, useEntityRuntime } from '../PrefabRoot';
7
+ import { useAssetRuntime, useEntityRuntime } from '../runtimeContext';
8
8
  import { BooleanField, FieldGroup, FieldRenderer, ListEditor, NumberField, SelectField, StringField } from './Input';
9
9
  import { colors } from '../styles';
10
10
  import { AudioListener } from 'three';
@@ -3,7 +3,7 @@ import { useHelper } from "@react-three/drei";
3
3
  import { useRef, useEffect } from "react";
4
4
  import { BooleanField, ColorField, Label, NumberField, Vector3Input } from "./Input";
5
5
  import { SpotLightHelper } from "three";
6
- import { useAssetRuntime, useEntityRuntime } from "../PrefabRoot";
6
+ import { useAssetRuntime, useEntityRuntime } from "../runtimeContext";
7
7
  import { useFrame } from "@react-three/fiber";
8
8
  import { TexturePicker } from "../../assetviewer/page";
9
9
  import { LightSection, ShadowBiasField, mergeWithDefaults } from "./lightUtils";
@@ -1,2 +1 @@
1
- declare const _default: import("./ComponentRegistry").Component[];
2
- export default _default;
1
+ export declare const builtinComponents: import("./ComponentRegistry").Component[];
@@ -12,7 +12,7 @@ import EnvironmentComponent from './EnvironmentComponent';
12
12
  import CameraComponent from './CameraComponent';
13
13
  import ClickComponent from './ClickComponent';
14
14
  import SoundComponent from './SoundComponent';
15
- export default [
15
+ export const builtinComponents = [
16
16
  GeometryComponent,
17
17
  TransformComponent,
18
18
  MaterialComponent,
@@ -0,0 +1,40 @@
1
+ import { type ReactNode } from "react";
2
+ import { Object3D, Texture } from "three";
3
+ type RuntimeScopeProps = {
4
+ nodeId: string;
5
+ editMode?: boolean;
6
+ isSelected?: boolean;
7
+ children: ReactNode;
8
+ };
9
+ export interface AssetRuntime {
10
+ registerRigidBodyRef: (id: string, rb: any) => void;
11
+ getModel: (path: string) => Object3D | null;
12
+ getTexture: (path: string) => Texture | null;
13
+ getSound: (path: string) => AudioBuffer | null;
14
+ getAssetRevision: () => string;
15
+ }
16
+ export interface AssetRuntimeContextValue extends AssetRuntime {
17
+ getObject: (id: string) => Object3D | null;
18
+ getRigidBody: (id: string) => any;
19
+ }
20
+ export interface EntityRuntime {
21
+ nodeId: string;
22
+ editMode?: boolean;
23
+ isSelected?: boolean;
24
+ getObject: <T extends Object3D = Object3D>() => T | null;
25
+ getRigidBody: <T = any>() => T | null;
26
+ }
27
+ export interface LiveObjectRef<T extends Object3D = Object3D> {
28
+ readonly current: T | null;
29
+ }
30
+ export interface LiveRigidBodyRef<T = any> {
31
+ readonly current: T | null;
32
+ }
33
+ export declare const AssetRuntimeContext: import("react").Context<AssetRuntimeContextValue | null>;
34
+ export declare const EntityRuntimeContext: import("react").Context<EntityRuntime | null>;
35
+ export declare function useAssetRuntime(): AssetRuntime;
36
+ export declare function useEntityRuntime(): EntityRuntime;
37
+ export declare function useEntityObjectRef<T extends Object3D = Object3D>(): LiveObjectRef<T>;
38
+ export declare function useEntityRigidBodyRef<T = any>(): LiveRigidBodyRef<T>;
39
+ export declare function EntityRuntimeScope({ nodeId, editMode, isSelected, children, }: RuntimeScopeProps): import("react/jsx-runtime").JSX.Element;
40
+ export {};
@@ -0,0 +1,45 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useMemo } from "react";
3
+ function createLiveRef(getCurrent) {
4
+ return {
5
+ get current() {
6
+ return getCurrent();
7
+ },
8
+ };
9
+ }
10
+ export const AssetRuntimeContext = createContext(null);
11
+ export const EntityRuntimeContext = createContext(null);
12
+ export function useAssetRuntime() {
13
+ const ctx = useContext(AssetRuntimeContext);
14
+ if (!ctx)
15
+ throw new Error("useAssetRuntime must be used inside <PrefabRoot>");
16
+ return ctx;
17
+ }
18
+ export function useEntityRuntime() {
19
+ const ctx = useContext(EntityRuntimeContext);
20
+ if (!ctx)
21
+ throw new Error("useEntityRuntime must be used inside a component View rendered by <PrefabRoot>");
22
+ return ctx;
23
+ }
24
+ export function useEntityObjectRef() {
25
+ const { getObject } = useEntityRuntime();
26
+ return useMemo(() => createLiveRef(() => getObject()), [getObject]);
27
+ }
28
+ export function useEntityRigidBodyRef() {
29
+ const { getRigidBody } = useEntityRuntime();
30
+ return useMemo(() => createLiveRef(() => getRigidBody()), [getRigidBody]);
31
+ }
32
+ export function EntityRuntimeScope({ nodeId, editMode, isSelected, children, }) {
33
+ const assetRuntime = useContext(AssetRuntimeContext);
34
+ if (!assetRuntime)
35
+ throw new Error("EntityRuntimeScope must be used inside <PrefabRoot>");
36
+ const { getObject, getRigidBody } = assetRuntime;
37
+ const value = useMemo(() => ({
38
+ nodeId,
39
+ editMode,
40
+ isSelected,
41
+ getObject: () => getObject(nodeId),
42
+ getRigidBody: () => getRigidBody(nodeId),
43
+ }), [editMode, getObject, getRigidBody, isSelected, nodeId]);
44
+ return _jsx(EntityRuntimeContext.Provider, { value: value, children: children });
45
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-three-game",
3
- "version": "0.0.72",
3
+ "version": "0.0.74",
4
4
  "description": "high performance 3D game engine built in React",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",