react-three-game 0.0.92 → 0.0.94
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 +81 -88
- package/dist/helpers/index.d.ts +0 -3
- package/dist/helpers/index.js +1 -8
- package/dist/index.d.ts +10 -10
- package/dist/index.js +7 -6
- package/dist/tools/prefabeditor/EditorTree.js +10 -14
- package/dist/tools/prefabeditor/EditorUI.js +4 -4
- package/dist/tools/prefabeditor/GameEvents.d.ts +6 -12
- package/dist/tools/prefabeditor/GameEvents.js +0 -8
- package/dist/tools/prefabeditor/InstanceProvider.d.ts +6 -4
- package/dist/tools/prefabeditor/InstanceProvider.js +84 -199
- package/dist/tools/prefabeditor/PrefabEditor.d.ts +12 -21
- package/dist/tools/prefabeditor/PrefabEditor.js +138 -146
- package/dist/tools/prefabeditor/PrefabRoot.d.ts +30 -11
- package/dist/tools/prefabeditor/PrefabRoot.js +182 -139
- package/dist/tools/prefabeditor/assetRuntime.d.ts +9 -13
- package/dist/tools/prefabeditor/assetRuntime.js +13 -13
- package/dist/tools/prefabeditor/components/BufferGeometryComponent.js +1 -1
- package/dist/tools/prefabeditor/components/CameraComponent.js +2 -2
- package/dist/tools/prefabeditor/components/ComponentRegistry.d.ts +3 -3
- package/dist/tools/prefabeditor/components/DirectionalLightComponent.js +2 -2
- package/dist/tools/prefabeditor/components/Input.js +5 -9
- package/dist/tools/prefabeditor/components/ModelComponent.js +4 -6
- package/dist/tools/prefabeditor/components/PointLightComponent.js +2 -2
- package/dist/tools/prefabeditor/components/SoundComponent.js +2 -2
- package/dist/tools/prefabeditor/components/SpotLightComponent.js +2 -2
- package/dist/tools/prefabeditor/components/index.js +0 -2
- package/dist/tools/prefabeditor/prefab.d.ts +1 -2
- package/dist/tools/prefabeditor/prefab.js +2 -3
- package/dist/tools/prefabeditor/prefabStore.d.ts +0 -6
- package/dist/tools/prefabeditor/prefabStore.js +1 -33
- package/dist/tools/prefabeditor/types.d.ts +1 -0
- package/dist/tools/prefabeditor/usePointerEvents.d.ts +3 -3
- package/dist/tools/prefabeditor/usePointerEvents.js +5 -5
- package/package.json +49 -51
- package/dist/tools/prefabeditor/components/PhysicsComponent.d.ts +0 -26
- package/dist/tools/prefabeditor/components/PhysicsComponent.js +0 -302
- package/dist/tools/prefabeditor/scene.d.ts +0 -70
- package/dist/tools/prefabeditor/scene.js +0 -237
|
@@ -10,11 +10,11 @@ export interface ComponentViewProps<P = Record<string, any>> {
|
|
|
10
10
|
properties: P;
|
|
11
11
|
/** Children to render for components that wrap the current subtree. */
|
|
12
12
|
children?: React.ReactNode;
|
|
13
|
-
/**
|
|
13
|
+
/** Current node local position for wrapper components. */
|
|
14
14
|
position?: [number, number, number];
|
|
15
|
-
/**
|
|
15
|
+
/** Current node local rotation in radians for wrapper components. */
|
|
16
16
|
rotation?: [number, number, number];
|
|
17
|
-
/**
|
|
17
|
+
/** Current node local scale for wrapper components. */
|
|
18
18
|
scale?: [number, number, number];
|
|
19
19
|
}
|
|
20
20
|
export interface Component {
|
|
@@ -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 } from "three";
|
|
6
|
-
import {
|
|
6
|
+
import { useNode } from "../assetRuntime";
|
|
7
7
|
import { BooleanField, ColorField, NumberField, NumberInput, Vector3Input } from "./Input";
|
|
8
8
|
import { LightSection, ShadowBiasField, mergeWithDefaults } from "./lightUtils";
|
|
9
9
|
import { colors } from "../styles";
|
|
@@ -102,7 +102,7 @@ function DirectionalLightComponentEditor({ component, onUpdate }) {
|
|
|
102
102
|
return (_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 8 }, children: [_jsxs(LightSection, { title: "Light", children: [_jsx(ColorField, { name: "color", label: "Color", values: values, onChange: onUpdate }), _jsx(NumberField, { name: "intensity", label: "Intensity", values: values, onChange: onUpdate, min: 0, step: 0.1, fallback: 1 }), _jsx(Vector3Input, { label: "Target Offset", value: values.targetOffset, onChange: targetOffset => onUpdate({ targetOffset }), snap: 0.5 })] }), _jsxs(LightSection, { title: "Shadow", children: [_jsx(BooleanField, { name: "castShadow", label: "Cast Shadow", values: values, onChange: onUpdate, fallback: false }), values.castShadow ? (_jsxs(_Fragment, { children: [_jsx(BooleanField, { name: "shadowAutoUpdate", label: "Auto Update", values: values, onChange: onUpdate, fallback: true }), _jsx(NumberField, { name: "shadowMapSize", label: "Map Size", values: values, onChange: onUpdate, min: 128, step: 128, fallback: 512 }), _jsx(ShadowBiasField, { name: "shadowBias", label: "Bias", values: values, onChange: onUpdate, fallback: 0 }), _jsx(ShadowBiasField, { name: "shadowNormalBias", label: "Normal Bias", values: values, onChange: onUpdate, fallback: 0 }), _jsx(NumberField, { name: "shadowCameraNear", label: "Near", values: values, onChange: onUpdate, min: 0.001, step: 0.1, fallback: 0.5 }), _jsx(NumberField, { name: "shadowCameraFar", label: "Far", values: values, onChange: onUpdate, min: 0.1, step: 1, fallback: 500 }), _jsx(ShadowFrustumField, { values: values, onChange: onUpdate })] })) : null] })] }));
|
|
103
103
|
}
|
|
104
104
|
function DirectionalLightView({ properties, children }) {
|
|
105
|
-
const { editMode, isSelected } =
|
|
105
|
+
const { editMode, isSelected } = useNode();
|
|
106
106
|
const merged = mergeWithDefaults(directionalLightDefaults, properties);
|
|
107
107
|
const color = merged.color;
|
|
108
108
|
const intensity = merged.intensity;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { colors, ui } from '../styles';
|
|
4
|
-
import {
|
|
4
|
+
import { usePrefabStoreApi } from '../prefabStore';
|
|
5
5
|
// ============================================================================
|
|
6
6
|
// Shared Styles (derived from shared color tokens)
|
|
7
7
|
// ============================================================================
|
|
@@ -278,14 +278,10 @@ export function ColorInput({ label, value, onChange }) {
|
|
|
278
278
|
export function StringInput({ label, value, onChange, placeholder }) {
|
|
279
279
|
return (_jsxs("div", { children: [label && _jsx(Label, { children: label }), _jsx("input", { type: "text", style: styles.input, value: value, onChange: e => onChange(e.target.value), placeholder: placeholder })] }));
|
|
280
280
|
}
|
|
281
|
-
function
|
|
282
|
-
const store =
|
|
283
|
-
const [state, setState] = useState(() =>
|
|
281
|
+
function usePrefabSnapshot() {
|
|
282
|
+
const store = usePrefabStoreApi();
|
|
283
|
+
const [state, setState] = useState(() => store.getState());
|
|
284
284
|
useEffect(() => {
|
|
285
|
-
if (!store) {
|
|
286
|
-
setState(null);
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
285
|
setState(store.getState());
|
|
290
286
|
return store.subscribe(nextState => setState(nextState));
|
|
291
287
|
}, [store]);
|
|
@@ -323,7 +319,7 @@ function SearchSuggestionList({ query, options, onSelect, emptyMessage, }) {
|
|
|
323
319
|
}, children: [_jsx("span", { style: { fontSize: 11, fontWeight: 500 }, children: option.label }), option.description ? (_jsx("span", { style: { fontSize: 10, color: colors.textMuted, fontFamily: 'monospace' }, children: option.description })) : null] }, option.value))) })] }));
|
|
324
320
|
}
|
|
325
321
|
export function NodeInput({ label, value, onChange, placeholder, includeRoot = true, }) {
|
|
326
|
-
const prefabState =
|
|
322
|
+
const prefabState = usePrefabSnapshot();
|
|
327
323
|
const [query, setQuery] = useState('');
|
|
328
324
|
const options = useMemo(() => {
|
|
329
325
|
var _a;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { ModelPicker } from '../../assetviewer/page';
|
|
3
|
-
import {
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
4
|
import { BooleanField, FieldGroup, Label, ListEditor, NumberInput, SelectInput, StringField } from './Input';
|
|
5
5
|
import { useAssetRuntime } from '../assetRuntime';
|
|
6
|
-
import {
|
|
6
|
+
import { useEditorContext } from '../PrefabEditor';
|
|
7
7
|
import { getRepeatAxesFromModelProperties, normalizeRepeatAxes } from '../InstanceProvider';
|
|
8
8
|
import { colors, ui } from '../styles';
|
|
9
9
|
const AXIS_OPTIONS = [
|
|
@@ -39,11 +39,9 @@ function RepeatAxisEditor({ axes, onChange, positionSnap, }) {
|
|
|
39
39
|
} }));
|
|
40
40
|
}
|
|
41
41
|
function ModelComponentEditor({ component, node, onUpdate, basePath = "" }) {
|
|
42
|
-
|
|
43
|
-
const editorContext = useContext(EditorContext);
|
|
44
|
-
const positionSnap = (_a = editorContext === null || editorContext === void 0 ? void 0 : editorContext.positionSnap) !== null && _a !== void 0 ? _a : 0.5;
|
|
42
|
+
const { positionSnap } = useEditorContext();
|
|
45
43
|
const repeatAxes = getRepeatAxesFromModelProperties(component.properties);
|
|
46
|
-
return (_jsxs(FieldGroup, { children: [_jsx(ModelPicker, { value: component.properties.filename, onChange: (filename) => onUpdate({ filename }), basePath: basePath, pickerKey: node === null || node === void 0 ? void 0 : node.id }), _jsx(BooleanField, { name: "instanced", label: "Instanced", values: component.properties, onChange: onUpdate, fallback: false }), !component.properties.instanced ? (_jsxs(_Fragment, { children: [_jsx(BooleanField, { name: "emitClickEvent", label: "Emit Click Event", values: component.properties, onChange: onUpdate, fallback: false }), component.properties.emitClickEvent ? (_jsx(StringField, { name: "clickEventName", label: "Click Event Name", values: component.properties, onChange: onUpdate, placeholder: "
|
|
44
|
+
return (_jsxs(FieldGroup, { children: [_jsx(ModelPicker, { value: component.properties.filename, onChange: (filename) => onUpdate({ filename }), basePath: basePath, pickerKey: node === null || node === void 0 ? void 0 : node.id }), _jsx(BooleanField, { name: "instanced", label: "Instanced", values: component.properties, onChange: onUpdate, fallback: false }), !component.properties.instanced ? (_jsxs(_Fragment, { children: [_jsx(BooleanField, { name: "emitClickEvent", label: "Emit Click Event", values: component.properties, onChange: onUpdate, fallback: false }), component.properties.emitClickEvent ? (_jsx(StringField, { name: "clickEventName", label: "Click Event Name", values: component.properties, onChange: onUpdate, placeholder: "node:click" })) : null] })) : null, component.properties.instanced && (_jsxs(_Fragment, { children: [_jsx(BooleanField, { name: "repeat", label: "Repeat", values: component.properties, onChange: onUpdate, fallback: false }), component.properties.repeat && (_jsx(RepeatAxisEditor, { axes: repeatAxes, onChange: (nextAxes) => onUpdate({ repeatAxes: nextAxes }), positionSnap: positionSnap }))] }))] }));
|
|
47
45
|
}
|
|
48
46
|
// View for Model component
|
|
49
47
|
function ModelComponentView({ properties, children }) {
|
|
@@ -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 {
|
|
5
|
+
import { useNode } from '../assetRuntime';
|
|
6
6
|
import { BooleanField, ColorField, NumberField } from './Input';
|
|
7
7
|
import { LightSection, ShadowBiasField, mergeWithDefaults } from './lightUtils';
|
|
8
8
|
const pointLightDefaults = {
|
|
@@ -23,7 +23,7 @@ function PointLightComponentEditor({ component, onUpdate }) {
|
|
|
23
23
|
return (_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 8 }, children: [_jsxs(LightSection, { title: "Light", children: [_jsx(ColorField, { name: "color", label: "Color", values: values, onChange: onUpdate }), _jsx(NumberField, { name: "intensity", label: "Intensity", values: values, onChange: onUpdate, min: 0, step: 0.1, fallback: 1 }), _jsx(NumberField, { name: "distance", label: "Distance", values: values, onChange: onUpdate, min: 0, step: 1, fallback: 0 }), _jsx(NumberField, { name: "decay", label: "Decay", values: values, onChange: onUpdate, min: 0, step: 0.1, fallback: 2 })] }), _jsxs(LightSection, { title: "Shadow", children: [_jsx(BooleanField, { name: "castShadow", label: "Cast Shadow", values: values, onChange: onUpdate, fallback: false }), values.castShadow ? (_jsxs(_Fragment, { children: [_jsx(BooleanField, { name: "shadowAutoUpdate", label: "Auto Update", values: values, onChange: onUpdate, fallback: true }), _jsx(NumberField, { name: "shadowMapSize", label: "Map Size", values: values, onChange: onUpdate, min: 128, step: 128, fallback: 512 }), _jsx(ShadowBiasField, { name: "shadowBias", label: "Bias", values: values, onChange: onUpdate, fallback: 0 }), _jsx(ShadowBiasField, { name: "shadowNormalBias", label: "Normal Bias", values: values, onChange: onUpdate, fallback: 0 }), _jsx(NumberField, { name: "shadowCameraNear", label: "Near", values: values, onChange: onUpdate, min: 0.001, step: 0.1, fallback: 0.5 }), _jsx(NumberField, { name: "shadowCameraFar", label: "Far", values: values, onChange: onUpdate, min: 0.1, step: 1, fallback: 500 })] })) : null] })] }));
|
|
24
24
|
}
|
|
25
25
|
function PointLightView({ properties, children }) {
|
|
26
|
-
const { editMode, isSelected } =
|
|
26
|
+
const { editMode, isSelected } = useNode();
|
|
27
27
|
const merged = mergeWithDefaults(pointLightDefaults, properties);
|
|
28
28
|
const color = merged.color;
|
|
29
29
|
const intensity = merged.intensity;
|
|
@@ -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 { useThree } from '@react-three/fiber';
|
|
4
4
|
import { SoundPicker } from '../../assetviewer/page';
|
|
5
|
-
import { useAssetRuntime,
|
|
5
|
+
import { useAssetRuntime, useNode } from '../assetRuntime';
|
|
6
6
|
import { gameEvents } from '../GameEvents';
|
|
7
7
|
import { BooleanField, FieldGroup, FieldRenderer, ListEditor, NumberField, SelectField, StringField } from './Input';
|
|
8
8
|
import { colors, ui } from '../styles';
|
|
@@ -124,7 +124,7 @@ function SoundComponentEditor({ component, onUpdate, basePath = '' }) {
|
|
|
124
124
|
}
|
|
125
125
|
function SoundComponentView({ properties, children }) {
|
|
126
126
|
const { getSound } = useAssetRuntime();
|
|
127
|
-
const { editMode, nodeId } =
|
|
127
|
+
const { editMode, nodeId } = useNode();
|
|
128
128
|
const { camera } = useThree();
|
|
129
129
|
const { eventName, autoplay = false, positional = false, refDistance = 1, maxDistance = 24, rolloffFactor = 1, distanceModel = 'inverse' } = properties;
|
|
130
130
|
const sequenceIndexRef = useRef(0);
|
|
@@ -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,
|
|
6
|
+
import { useAssetRuntime, useNode } from "../assetRuntime";
|
|
7
7
|
import { useFrame } from "@react-three/fiber";
|
|
8
8
|
import { TexturePicker } from "../../assetviewer/page";
|
|
9
9
|
import { LightSection, ShadowBiasField, mergeWithDefaults } from "./lightUtils";
|
|
@@ -31,7 +31,7 @@ function SpotLightComponentEditor({ component, onUpdate, basePath = "" }) {
|
|
|
31
31
|
function SpotLightView({ properties, children }) {
|
|
32
32
|
var _a;
|
|
33
33
|
const { getTexture } = useAssetRuntime();
|
|
34
|
-
const { editMode, isSelected } =
|
|
34
|
+
const { editMode, isSelected } = useNode();
|
|
35
35
|
const merged = mergeWithDefaults(spotLightDefaults, properties);
|
|
36
36
|
const color = merged.color;
|
|
37
37
|
const intensity = merged.intensity;
|
|
@@ -4,7 +4,6 @@ import BufferGeometryComponent from './BufferGeometryComponent';
|
|
|
4
4
|
import ModelComponent from './ModelComponent';
|
|
5
5
|
import TextComponent from './TextComponent';
|
|
6
6
|
import MaterialComponent from './MaterialComponent';
|
|
7
|
-
import PhysicsComponent from './PhysicsComponent';
|
|
8
7
|
import SpotLightComponent from './SpotLightComponent';
|
|
9
8
|
import PointLightComponent from './PointLightComponent';
|
|
10
9
|
import DirectionalLightComponent from './DirectionalLightComponent';
|
|
@@ -20,7 +19,6 @@ export const builtinComponents = [
|
|
|
20
19
|
ModelComponent,
|
|
21
20
|
TextComponent,
|
|
22
21
|
MaterialComponent,
|
|
23
|
-
PhysicsComponent,
|
|
24
22
|
SpotLightComponent,
|
|
25
23
|
PointLightComponent,
|
|
26
24
|
DirectionalLightComponent,
|
|
@@ -8,7 +8,6 @@ export interface PrefabState {
|
|
|
8
8
|
nodesById: Record<string, PrefabNodeRecord>;
|
|
9
9
|
childIdsById: Record<string, string[]>;
|
|
10
10
|
parentIdById: Record<string, string | null>;
|
|
11
|
-
revision: number;
|
|
12
11
|
assetManifestKey: string;
|
|
13
12
|
assetRefCounts: PrefabAssetRefCounts;
|
|
14
13
|
}
|
|
@@ -25,7 +24,7 @@ export declare function createEmptyNode(name?: string): GameObject;
|
|
|
25
24
|
export declare function createEmptyPrefab(): Prefab;
|
|
26
25
|
export declare function createModelNode(filename: string, name?: string): GameObject;
|
|
27
26
|
export declare function createImageNode(texturePath: string, name?: string): GameObject;
|
|
28
|
-
export declare function normalizePrefab(prefab: Prefab
|
|
27
|
+
export declare function normalizePrefab(prefab: Prefab): PrefabState;
|
|
29
28
|
export declare function createPrefabPatch(state: PrefabState, patch: Partial<PrefabState>, nextAssetRefCounts?: PrefabAssetRefCounts): Partial<PrefabState>;
|
|
30
29
|
export declare function denormalizePrefab(state: Pick<PrefabState, 'prefabId' | 'prefabName' | 'rootId' | 'nodesById' | 'childIdsById'>): Prefab;
|
|
31
30
|
export declare function collectSubtreeIds(id: string, childIdsById: Record<string, string[]>): string[];
|
|
@@ -132,7 +132,7 @@ export function createImageNode(texturePath, name) {
|
|
|
132
132
|
},
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
|
-
export function normalizePrefab(prefab
|
|
135
|
+
export function normalizePrefab(prefab) {
|
|
136
136
|
const nodesById = {};
|
|
137
137
|
const childIdsById = {};
|
|
138
138
|
const parentIdById = {};
|
|
@@ -145,14 +145,13 @@ export function normalizePrefab(prefab, revision = 0) {
|
|
|
145
145
|
nodesById,
|
|
146
146
|
childIdsById,
|
|
147
147
|
parentIdById,
|
|
148
|
-
revision,
|
|
149
148
|
assetManifestKey: getAssetManifestKey(assetRefCounts),
|
|
150
149
|
assetRefCounts,
|
|
151
150
|
};
|
|
152
151
|
}
|
|
153
152
|
export function createPrefabPatch(state, patch, nextAssetRefCounts = state.assetRefCounts) {
|
|
154
153
|
const assetRefsChanged = nextAssetRefCounts !== state.assetRefCounts;
|
|
155
|
-
return Object.assign(Object.assign(
|
|
154
|
+
return Object.assign(Object.assign({}, patch), (assetRefsChanged ? {
|
|
156
155
|
assetRefCounts: nextAssetRefCounts,
|
|
157
156
|
assetManifestKey: getAssetManifestKey(nextAssetRefCounts),
|
|
158
157
|
} : null));
|
|
@@ -5,14 +5,9 @@ import { denormalizePrefab, PrefabState, PrefabNodeRecord } from "./prefab";
|
|
|
5
5
|
export interface PrefabStoreState extends PrefabState {
|
|
6
6
|
replacePrefab: (prefab: Prefab) => void;
|
|
7
7
|
updateNode: (id: string, update: (node: PrefabNodeRecord) => PrefabNodeRecord) => void;
|
|
8
|
-
updateNodes: (updates: Array<{
|
|
9
|
-
id: string;
|
|
10
|
-
update: (node: PrefabNodeRecord) => PrefabNodeRecord;
|
|
11
|
-
}>) => void;
|
|
12
8
|
addChild: (parentId: string, node: GameObject) => void;
|
|
13
9
|
deleteNode: (id: string) => void;
|
|
14
10
|
duplicateNode: (id: string) => string | null;
|
|
15
|
-
toggleNodeFlag: (id: string, key: "disabled" | "locked") => void;
|
|
16
11
|
moveNode: (draggedId: string, targetId: string, position: "before" | "inside") => void;
|
|
17
12
|
}
|
|
18
13
|
export type PrefabStoreApi = StoreApi<PrefabStoreState>;
|
|
@@ -21,7 +16,6 @@ export declare function PrefabStoreProvider({ store, children, }: {
|
|
|
21
16
|
children: ReactNode;
|
|
22
17
|
}): import("react").FunctionComponentElement<import("react").ProviderProps<PrefabStoreApi | null>>;
|
|
23
18
|
export declare function usePrefabStoreApi(): PrefabStoreApi;
|
|
24
|
-
export declare function useOptionalPrefabStoreApi(): PrefabStoreApi | null;
|
|
25
19
|
export declare function usePrefabStore<T>(selector: (state: PrefabStoreState) => T): T;
|
|
26
20
|
export declare function usePrefabRootId(): string;
|
|
27
21
|
export declare function usePrefabNode(nodeId: string | null | undefined): PrefabNodeRecord | null;
|
|
@@ -15,9 +15,6 @@ export function usePrefabStoreApi() {
|
|
|
15
15
|
}
|
|
16
16
|
return store;
|
|
17
17
|
}
|
|
18
|
-
export function useOptionalPrefabStoreApi() {
|
|
19
|
-
return useContext(PrefabStoreContext);
|
|
20
|
-
}
|
|
21
18
|
export function usePrefabStore(selector) {
|
|
22
19
|
return useStore(usePrefabStoreApi(), selector);
|
|
23
20
|
}
|
|
@@ -32,7 +29,7 @@ export function usePrefabChildIds(nodeId) {
|
|
|
32
29
|
}
|
|
33
30
|
export function createPrefabStore(prefab) {
|
|
34
31
|
return createStore()(subscribeWithSelector((set, get) => (Object.assign(Object.assign({}, normalizePrefab(prefab)), { replacePrefab: (nextPrefab) => {
|
|
35
|
-
set(normalizePrefab(nextPrefab
|
|
32
|
+
set(normalizePrefab(nextPrefab));
|
|
36
33
|
}, updateNode: (id, update) => {
|
|
37
34
|
const state = get();
|
|
38
35
|
const node = state.nodesById[id];
|
|
@@ -45,26 +42,6 @@ export function createPrefabStore(prefab) {
|
|
|
45
42
|
set(createPrefabPatch(state, {
|
|
46
43
|
nodesById: Object.assign(Object.assign({}, state.nodesById), { [id]: nextNode }),
|
|
47
44
|
}, nextAssetRefCounts));
|
|
48
|
-
}, updateNodes: (updates) => {
|
|
49
|
-
if (updates.length === 0)
|
|
50
|
-
return;
|
|
51
|
-
const state = get();
|
|
52
|
-
let nextNodesById = null;
|
|
53
|
-
let nextAssetRefCounts = state.assetRefCounts;
|
|
54
|
-
for (const { id, update } of updates) {
|
|
55
|
-
const currentNode = (nextNodesById !== null && nextNodesById !== void 0 ? nextNodesById : state.nodesById)[id];
|
|
56
|
-
if (!currentNode)
|
|
57
|
-
continue;
|
|
58
|
-
const nextNode = update(currentNode);
|
|
59
|
-
if (nextNode === currentNode)
|
|
60
|
-
continue;
|
|
61
|
-
nextNodesById !== null && nextNodesById !== void 0 ? nextNodesById : (nextNodesById = Object.assign({}, state.nodesById));
|
|
62
|
-
nextNodesById[id] = nextNode;
|
|
63
|
-
nextAssetRefCounts = updateAssetRefsForNodeChange(nextAssetRefCounts, currentNode, nextNode);
|
|
64
|
-
}
|
|
65
|
-
if (!nextNodesById)
|
|
66
|
-
return;
|
|
67
|
-
set(createPrefabPatch(state, { nodesById: nextNodesById }, nextAssetRefCounts));
|
|
68
45
|
}, addChild: (parentId, node) => {
|
|
69
46
|
var _a;
|
|
70
47
|
const state = get();
|
|
@@ -152,15 +129,6 @@ export function createPrefabStore(prefab) {
|
|
|
152
129
|
parentIdById: nextParentIdById,
|
|
153
130
|
}, nextAssetRefCounts));
|
|
154
131
|
return duplicatedRootId;
|
|
155
|
-
}, toggleNodeFlag: (id, key) => {
|
|
156
|
-
const state = get();
|
|
157
|
-
const node = state.nodesById[id];
|
|
158
|
-
if (!node)
|
|
159
|
-
return;
|
|
160
|
-
const nextNode = Object.assign(Object.assign({}, node), { [key]: !node[key] });
|
|
161
|
-
set(createPrefabPatch(state, {
|
|
162
|
-
nodesById: Object.assign(Object.assign({}, state.nodesById), { [id]: nextNode }),
|
|
163
|
-
}));
|
|
164
132
|
}, moveNode: (draggedId, targetId, position) => {
|
|
165
133
|
var _a, _b, _c;
|
|
166
134
|
const state = get();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ThreeEvent } from "@react-three/fiber";
|
|
2
|
-
export type PointerHandler<T> = (event: ThreeEvent<PointerEvent>,
|
|
2
|
+
export type PointerHandler<T> = (event: ThreeEvent<PointerEvent>, node: T) => void;
|
|
3
3
|
export interface PointerEventHandlers<T> {
|
|
4
4
|
onClick?: PointerHandler<T>;
|
|
5
5
|
onPointerDown?: PointerHandler<T>;
|
|
@@ -12,10 +12,10 @@ export interface PointerEventHandlers<T> {
|
|
|
12
12
|
}
|
|
13
13
|
export interface UsePointerEventsOptions<T> extends PointerEventHandlers<T> {
|
|
14
14
|
enabled: boolean;
|
|
15
|
-
|
|
15
|
+
node: T | null | undefined;
|
|
16
16
|
}
|
|
17
17
|
export declare function hasPointerEventHandlers<T>(handlers: PointerEventHandlers<T>): boolean;
|
|
18
|
-
export declare function usePointerEvents<T>({ enabled,
|
|
18
|
+
export declare function usePointerEvents<T>({ enabled, node, onClick, onPointerDown, onPointerUp, onPointerMove, onPointerEnter, onPointerLeave, onPointerOver, onPointerOut, }: UsePointerEventsOptions<T>): {
|
|
19
19
|
onClick: ((event: ThreeEvent<PointerEvent>) => void) | undefined;
|
|
20
20
|
onPointerDown: ((event: ThreeEvent<PointerEvent>) => void) | undefined;
|
|
21
21
|
onPointerMove: ((event: ThreeEvent<PointerEvent>) => void) | undefined;
|
|
@@ -8,7 +8,7 @@ export function hasPointerEventHandlers(handlers) {
|
|
|
8
8
|
|| handlers.onPointerOver
|
|
9
9
|
|| handlers.onPointerOut);
|
|
10
10
|
}
|
|
11
|
-
export function usePointerEvents({ enabled,
|
|
11
|
+
export function usePointerEvents({ enabled, node, onClick, onPointerDown, onPointerUp, onPointerMove, onPointerEnter, onPointerLeave, onPointerOver, onPointerOut, }) {
|
|
12
12
|
if (!enabled) {
|
|
13
13
|
return {
|
|
14
14
|
onClick: undefined,
|
|
@@ -26,17 +26,17 @@ export function usePointerEvents({ enabled, entity, onClick, onPointerDown, onPo
|
|
|
26
26
|
return undefined;
|
|
27
27
|
return (event) => {
|
|
28
28
|
event.stopPropagation();
|
|
29
|
-
if (!
|
|
29
|
+
if (!node)
|
|
30
30
|
return;
|
|
31
|
-
handler(event,
|
|
31
|
+
handler(event, node);
|
|
32
32
|
};
|
|
33
33
|
};
|
|
34
34
|
const forwardMove = onPointerMove
|
|
35
35
|
? (event) => {
|
|
36
36
|
event.stopPropagation();
|
|
37
|
-
if (!
|
|
37
|
+
if (!node)
|
|
38
38
|
return;
|
|
39
|
-
onPointerMove(event,
|
|
39
|
+
onPointerMove(event, node);
|
|
40
40
|
}
|
|
41
41
|
: undefined;
|
|
42
42
|
return {
|
package/package.json
CHANGED
|
@@ -1,53 +1,51 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
"zustand": "^5.0.12"
|
|
52
|
-
}
|
|
2
|
+
"name": "react-three-game",
|
|
3
|
+
"version": "0.0.94",
|
|
4
|
+
"description": "high performance 3D game engine built in React",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md",
|
|
11
|
+
"LICENSE"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"clean": "rm -rf dist",
|
|
15
|
+
"watch": "npm run clean && tsc --watch",
|
|
16
|
+
"dev": "concurrently \"npm run watch\" \"cd docs && npm run dev\"",
|
|
17
|
+
"build": "npm run clean && tsc",
|
|
18
|
+
"release": "npm run build && npm publish --access public"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [],
|
|
21
|
+
"author": "prnth",
|
|
22
|
+
"license": "VPL",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"workspaces": [
|
|
25
|
+
"docs"
|
|
26
|
+
],
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@react-three/drei": ">=10.0.0",
|
|
29
|
+
"@react-three/fiber": ">=9.0.0",
|
|
30
|
+
"react": ">=18.0.0",
|
|
31
|
+
"react-dom": ">=18.0.0",
|
|
32
|
+
"three": ">=0.182.0",
|
|
33
|
+
"three-text": ">=0.4.4"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@react-three/drei": "^10.7.7",
|
|
37
|
+
"@react-three/fiber": "^9.5.0",
|
|
38
|
+
"@types/react": "^19.2.9",
|
|
39
|
+
"@types/react-dom": "^19.2.3",
|
|
40
|
+
"@types/three": "^0.182.0",
|
|
41
|
+
"concurrently": "^9.2.1",
|
|
42
|
+
"react": "^19.2.4",
|
|
43
|
+
"react-dom": "^19.2.4",
|
|
44
|
+
"three": "^0.184.0",
|
|
45
|
+
"typescript": "^5.9.3",
|
|
46
|
+
"vite": "^7.3.1"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"zustand": "^5.0.12"
|
|
50
|
+
}
|
|
53
51
|
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { RigidBodyOptions } from "@react-three/rapier";
|
|
2
|
-
import { Component } from "./ComponentRegistry";
|
|
3
|
-
type PhysicsColliderType = NonNullable<RigidBodyOptions['colliders']> | 'capsule';
|
|
4
|
-
type ManualColliderShape = 'cuboid' | 'ball' | 'capsule';
|
|
5
|
-
export type PhysicsProps = Omit<RigidBodyOptions, 'colliders'> & {
|
|
6
|
-
colliders?: PhysicsColliderType;
|
|
7
|
-
manualColliderShape?: ManualColliderShape;
|
|
8
|
-
activeCollisionTypes?: 'all' | undefined;
|
|
9
|
-
linearVelocity?: [number, number, number];
|
|
10
|
-
angularVelocity?: [number, number, number];
|
|
11
|
-
colliderSize?: [number, number, number];
|
|
12
|
-
colliderRadius?: number;
|
|
13
|
-
capsuleRadius?: number;
|
|
14
|
-
capsuleHalfHeight?: number;
|
|
15
|
-
emitSensorEnterEvent?: boolean;
|
|
16
|
-
sensorEnterEventName?: string;
|
|
17
|
-
emitSensorExitEvent?: boolean;
|
|
18
|
-
sensorExitEventName?: string;
|
|
19
|
-
emitCollisionEnterEvent?: boolean;
|
|
20
|
-
collisionEnterEventName?: string;
|
|
21
|
-
emitCollisionExitEvent?: boolean;
|
|
22
|
-
collisionExitEventName?: string;
|
|
23
|
-
};
|
|
24
|
-
export declare function isPhysicsProps(v: any): v is PhysicsProps;
|
|
25
|
-
declare const PhysicsComponent: Component;
|
|
26
|
-
export default PhysicsComponent;
|