react-three-game 0.0.69 → 0.0.71
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/helpers/SoundManager.d.ts +2 -0
- package/dist/helpers/SoundManager.js +6 -0
- package/dist/index.d.ts +20 -13
- package/dist/index.js +14 -7
- package/dist/shared/GameCanvas.js +0 -2
- package/dist/tools/assetviewer/page.d.ts +5 -0
- package/dist/tools/assetviewer/page.js +3 -0
- package/dist/tools/dragdrop/DragDropLoader.d.ts +3 -2
- package/dist/tools/dragdrop/DragDropLoader.js +18 -3
- package/dist/tools/dragdrop/index.d.ts +2 -2
- package/dist/tools/dragdrop/index.js +1 -1
- package/dist/tools/dragdrop/modelLoader.d.ts +10 -0
- package/dist/tools/dragdrop/modelLoader.js +60 -0
- package/dist/tools/prefabeditor/EditorTree.js +6 -40
- package/dist/tools/prefabeditor/EditorTreeMenus.js +2 -20
- package/dist/tools/prefabeditor/EditorUI.js +8 -5
- package/dist/tools/prefabeditor/InstanceProvider.d.ts +2 -0
- package/dist/tools/prefabeditor/InstanceProvider.js +54 -52
- package/dist/tools/prefabeditor/PrefabEditor.d.ts +23 -1
- package/dist/tools/prefabeditor/PrefabEditor.js +79 -47
- package/dist/tools/prefabeditor/PrefabRoot.d.ts +26 -9
- package/dist/tools/prefabeditor/PrefabRoot.js +195 -159
- package/dist/tools/prefabeditor/RefBridge.d.ts +24 -0
- package/dist/tools/prefabeditor/RefBridge.js +44 -0
- package/dist/tools/prefabeditor/components/AmbientLightComponent.js +10 -7
- package/dist/tools/prefabeditor/components/CameraComponent.js +8 -14
- package/dist/tools/prefabeditor/components/ClickComponent.js +12 -7
- package/dist/tools/prefabeditor/components/ComponentRegistry.d.ts +31 -5
- package/dist/tools/prefabeditor/components/ComponentRegistry.js +6 -6
- package/dist/tools/prefabeditor/components/DirectionalLightComponent.js +124 -52
- package/dist/tools/prefabeditor/components/EnvironmentComponent.js +5 -3
- package/dist/tools/prefabeditor/components/GeometryComponent.js +1 -1
- package/dist/tools/prefabeditor/components/Input.d.ts +16 -0
- package/dist/tools/prefabeditor/components/Input.js +33 -0
- package/dist/tools/prefabeditor/components/MaterialComponent.js +19 -8
- package/dist/tools/prefabeditor/components/ModelComponent.js +39 -45
- package/dist/tools/prefabeditor/components/PhysicsComponent.d.ts +10 -1
- package/dist/tools/prefabeditor/components/PhysicsComponent.js +127 -31
- package/dist/tools/prefabeditor/components/PointLightComponent.d.ts +3 -0
- package/dist/tools/prefabeditor/components/PointLightComponent.js +55 -0
- package/dist/tools/prefabeditor/components/SoundComponent.d.ts +3 -0
- package/dist/tools/prefabeditor/components/SoundComponent.js +244 -0
- package/dist/tools/prefabeditor/components/SpotLightComponent.js +53 -24
- package/dist/tools/prefabeditor/components/TransformComponent.js +2 -2
- package/dist/tools/prefabeditor/components/index.js +4 -0
- package/dist/tools/prefabeditor/components/lightUtils.d.ts +13 -0
- package/dist/tools/prefabeditor/components/lightUtils.js +64 -0
- package/dist/tools/prefabeditor/prefab.d.ts +37 -0
- package/dist/tools/prefabeditor/prefab.js +229 -0
- package/dist/tools/prefabeditor/prefabStore.d.ts +4 -16
- package/dist/tools/prefabeditor/prefabStore.js +32 -173
- package/dist/tools/prefabeditor/{sceneApi.d.ts → scene.d.ts} +15 -1
- package/dist/tools/prefabeditor/{sceneApi.js → scene.js} +66 -32
- package/dist/tools/prefabeditor/styles.d.ts +1 -0
- package/dist/tools/prefabeditor/styles.js +9 -0
- package/dist/tools/prefabeditor/types.d.ts +13 -0
- package/dist/tools/prefabeditor/types.js +28 -1
- package/dist/tools/prefabeditor/useClickValid.d.ts +13 -0
- package/dist/tools/prefabeditor/useClickValid.js +21 -0
- package/dist/tools/prefabeditor/utils.d.ts +2 -4
- package/dist/tools/prefabeditor/utils.js +8 -46
- package/package.json +1 -1
- package/dist/tools/prefabeditor/EditorContext.d.ts +0 -16
- package/dist/tools/prefabeditor/EditorContext.js +0 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { PerspectiveCamera } from '@react-three/drei';
|
|
3
|
-
import {
|
|
2
|
+
import { PerspectiveCamera, useHelper } from '@react-three/drei';
|
|
3
|
+
import { useRef } from 'react';
|
|
4
4
|
import { CameraHelper } from 'three';
|
|
5
5
|
import { useFrame } from '@react-three/fiber';
|
|
6
6
|
import { FieldGroup, NumberField } from './Input';
|
|
@@ -20,21 +20,15 @@ function CameraComponentView({ properties, children, editMode, isSelected }) {
|
|
|
20
20
|
const near = merged.near;
|
|
21
21
|
const zoom = merged.zoom;
|
|
22
22
|
const far = merged.far;
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
return () => {
|
|
27
|
-
cameraHelper === null || cameraHelper === void 0 ? void 0 : cameraHelper.dispose();
|
|
28
|
-
};
|
|
29
|
-
}, [cameraHelper]);
|
|
23
|
+
const cameraRef = useRef(null);
|
|
24
|
+
useHelper(editMode && isSelected ? cameraRef : null, CameraHelper);
|
|
30
25
|
useFrame(() => {
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
cameraHelper.update();
|
|
26
|
+
if (cameraRef.current && editMode && isSelected) {
|
|
27
|
+
cameraRef.current.updateProjectionMatrix();
|
|
28
|
+
cameraRef.current.updateMatrixWorld();
|
|
35
29
|
}
|
|
36
30
|
});
|
|
37
|
-
return (_jsxs(_Fragment, { children: [_jsx(PerspectiveCamera, { ref:
|
|
31
|
+
return (_jsxs(_Fragment, { children: [_jsx(PerspectiveCamera, { ref: cameraRef, makeDefault: !editMode, fov: fov, near: near, zoom: zoom, far: far }), editMode ? (_jsxs("group", { children: [_jsxs("mesh", { children: [_jsx("boxGeometry", { args: [0.3, 0.3, 0.5] }), _jsx("meshBasicMaterial", { color: '#22d3ee', wireframe: true })] }), _jsxs("mesh", { position: [0, 0, -0.25], rotation: [Math.PI / 2, 0, 0], children: [_jsx("coneGeometry", { args: [0.08, 0.16, 16] }), _jsx("meshBasicMaterial", { color: '#22d3ee', wireframe: true })] })] })) : null, children] }));
|
|
38
32
|
}
|
|
39
33
|
const CameraComponent = {
|
|
40
34
|
name: 'Camera',
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
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 { FieldGroup } from './Input';
|
|
5
|
-
function ClickComponentEditor() {
|
|
6
|
-
return (
|
|
4
|
+
import { FieldGroup, StringField } from './Input';
|
|
5
|
+
function ClickComponentEditor({ component, onUpdate }) {
|
|
6
|
+
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" })] }));
|
|
7
7
|
}
|
|
8
|
-
function ClickComponentView({ children, editMode, nodeId }) {
|
|
8
|
+
function ClickComponentView({ children, editMode, nodeId, properties }) {
|
|
9
9
|
const clickValid = useRef(false);
|
|
10
|
+
const eventName = (properties === null || properties === void 0 ? void 0 : properties.eventName) || 'click';
|
|
10
11
|
const emitClick = (event) => {
|
|
11
12
|
if (!nodeId)
|
|
12
13
|
return;
|
|
13
|
-
gameEvents.emit(
|
|
14
|
+
gameEvents.emit(eventName, {
|
|
14
15
|
sourceEntityId: nodeId,
|
|
15
16
|
point: [event.point.x, event.point.y, event.point.z],
|
|
16
17
|
button: event.button,
|
|
@@ -26,6 +27,8 @@ function ClickComponentView({ children, editMode, nodeId }) {
|
|
|
26
27
|
return (_jsx("group", { onPointerDown: (event) => {
|
|
27
28
|
event.stopPropagation();
|
|
28
29
|
clickValid.current = true;
|
|
30
|
+
}, onClick: (event) => {
|
|
31
|
+
event.stopPropagation();
|
|
29
32
|
}, onPointerMove: () => {
|
|
30
33
|
clickValid.current = false;
|
|
31
34
|
}, onPointerUp: (event) => {
|
|
@@ -40,6 +43,8 @@ const ClickComponent = {
|
|
|
40
43
|
name: 'Click',
|
|
41
44
|
Editor: ClickComponentEditor,
|
|
42
45
|
View: ClickComponentView,
|
|
43
|
-
defaultProperties: {
|
|
46
|
+
defaultProperties: {
|
|
47
|
+
eventName: 'click',
|
|
48
|
+
},
|
|
44
49
|
};
|
|
45
50
|
export default ClickComponent;
|
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
import { FC } from "react";
|
|
2
2
|
import { ComponentData, GameObject } from "../types";
|
|
3
|
+
export type AssetRef = {
|
|
4
|
+
type: "model" | "texture" | "sound";
|
|
5
|
+
path: string;
|
|
6
|
+
};
|
|
7
|
+
/** Props every component View receives from the renderer. */
|
|
8
|
+
export interface ComponentViewProps<P = Record<string, any>> {
|
|
9
|
+
/** This component's own data from the prefab JSON. */
|
|
10
|
+
properties: P;
|
|
11
|
+
/** Children to render (for wrapper / child-host components). */
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
/** The entity ID this component belongs to. */
|
|
14
|
+
nodeId?: string;
|
|
15
|
+
/** True when the editor is in edit mode. */
|
|
16
|
+
editMode?: boolean;
|
|
17
|
+
/** True when this entity is selected in the editor. */
|
|
18
|
+
isSelected?: boolean;
|
|
19
|
+
/** Entity local position (passed to wrapper components like Physics). */
|
|
20
|
+
position?: [number, number, number];
|
|
21
|
+
/** Entity local rotation in radians (passed to wrapper components like Physics). */
|
|
22
|
+
rotation?: [number, number, number];
|
|
23
|
+
/** Entity local scale (passed to wrapper components like Physics). */
|
|
24
|
+
scale?: [number, number, number];
|
|
25
|
+
}
|
|
3
26
|
export interface Component {
|
|
4
27
|
name: string;
|
|
5
28
|
Editor: FC<{
|
|
@@ -9,10 +32,13 @@ export interface Component {
|
|
|
9
32
|
basePath?: string;
|
|
10
33
|
}>;
|
|
11
34
|
defaultProperties: any;
|
|
12
|
-
View?: FC<
|
|
13
|
-
|
|
35
|
+
View?: FC<ComponentViewProps>;
|
|
36
|
+
/** When true, this component wraps child entities (e.g. Physics wraps children in RigidBody). */
|
|
37
|
+
isWrapper?: boolean;
|
|
38
|
+
/** Declare which asset paths this component references (for asset loading). */
|
|
39
|
+
getAssetRefs?: (properties: Record<string, any>) => AssetRef[];
|
|
14
40
|
}
|
|
15
41
|
export declare function registerComponent(component: Component): void;
|
|
16
|
-
export declare function
|
|
17
|
-
export declare function
|
|
18
|
-
export declare function
|
|
42
|
+
export declare function getComponentDef(name: string): Component | undefined;
|
|
43
|
+
export declare function getAllComponentDefs(): Record<string, Component>;
|
|
44
|
+
export declare function getComponentAssetRefs(componentType: string, properties: Record<string, any>): AssetRef[];
|
|
@@ -2,14 +2,14 @@ const REGISTRY = {};
|
|
|
2
2
|
export function registerComponent(component) {
|
|
3
3
|
REGISTRY[component.name] = component;
|
|
4
4
|
}
|
|
5
|
-
export function
|
|
5
|
+
export function getComponentDef(name) {
|
|
6
6
|
return REGISTRY[name];
|
|
7
7
|
}
|
|
8
|
-
export function
|
|
8
|
+
export function getAllComponentDefs() {
|
|
9
9
|
return Object.assign({}, REGISTRY);
|
|
10
10
|
}
|
|
11
|
-
export function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
export function getComponentAssetRefs(componentType, properties) {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
const component = REGISTRY[componentType];
|
|
14
|
+
return (_b = (_a = component === null || component === void 0 ? void 0 : component.getAssetRefs) === null || _a === void 0 ? void 0 : _a.call(component, properties)) !== null && _b !== void 0 ? _b : [];
|
|
15
15
|
}
|
|
@@ -1,59 +1,114 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useHelper } from "@react-three/drei";
|
|
3
|
+
import { useRef, useEffect, useState } from "react";
|
|
3
4
|
import { useFrame } from "@react-three/fiber";
|
|
4
5
|
import { CameraHelper, Vector3 } from "three";
|
|
5
|
-
import {
|
|
6
|
-
|
|
6
|
+
import { BooleanField, ColorField, NumberField, NumberInput, Vector3Input } from "./Input";
|
|
7
|
+
import { LightSection, ShadowBiasField, mergeWithDefaults } from "./lightUtils";
|
|
8
|
+
import { colors } from "../styles";
|
|
7
9
|
const directionalLightDefaults = {
|
|
8
10
|
color: '#ffffff',
|
|
9
11
|
intensity: 1,
|
|
10
|
-
castShadow:
|
|
11
|
-
shadowMapSize:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
castShadow: false,
|
|
13
|
+
shadowMapSize: 512,
|
|
14
|
+
shadowBias: 0,
|
|
15
|
+
shadowNormalBias: 0,
|
|
16
|
+
shadowAutoUpdate: true,
|
|
17
|
+
shadowCameraNear: 0.5,
|
|
18
|
+
shadowCameraFar: 500,
|
|
19
|
+
shadowCameraTop: 5,
|
|
20
|
+
shadowCameraBottom: -5,
|
|
21
|
+
shadowCameraLeft: -5,
|
|
22
|
+
shadowCameraRight: 5,
|
|
18
23
|
targetOffset: [0, -5, 0],
|
|
19
24
|
};
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
25
|
+
const frustumLabelStyle = {
|
|
26
|
+
fontSize: 10,
|
|
27
|
+
textTransform: 'uppercase',
|
|
28
|
+
letterSpacing: '0.06em',
|
|
29
|
+
color: colors.textMuted,
|
|
30
|
+
textAlign: 'center',
|
|
31
|
+
};
|
|
32
|
+
const frustumCellStyle = {
|
|
33
|
+
display: 'flex',
|
|
34
|
+
alignItems: 'center',
|
|
35
|
+
justifyContent: 'center',
|
|
36
|
+
};
|
|
37
|
+
const frustumInputStyle = {
|
|
38
|
+
width: 62,
|
|
39
|
+
minWidth: 62,
|
|
40
|
+
textAlign: 'center',
|
|
41
|
+
};
|
|
42
|
+
const centerLockButtonStyle = {
|
|
43
|
+
width: 34,
|
|
44
|
+
height: 34,
|
|
45
|
+
borderRadius: 999,
|
|
46
|
+
border: `1px solid ${colors.border}`,
|
|
47
|
+
background: colors.bgInput,
|
|
48
|
+
color: colors.textMuted,
|
|
49
|
+
cursor: 'pointer',
|
|
50
|
+
fontSize: 14,
|
|
51
|
+
lineHeight: 1,
|
|
52
|
+
padding: 0,
|
|
53
|
+
};
|
|
54
|
+
function areFrustumSidesLocked(values) {
|
|
55
|
+
const top = Math.abs(values.shadowCameraTop);
|
|
56
|
+
const bottom = Math.abs(values.shadowCameraBottom);
|
|
57
|
+
const left = Math.abs(values.shadowCameraLeft);
|
|
58
|
+
const right = Math.abs(values.shadowCameraRight);
|
|
59
|
+
return top === bottom && top === left && top === right;
|
|
60
|
+
}
|
|
61
|
+
function ShadowFrustumField({ values, onChange, }) {
|
|
62
|
+
const [locked, setLocked] = useState(() => areFrustumSidesLocked(values));
|
|
63
|
+
const updateSide = (side, nextValue) => {
|
|
64
|
+
if (!locked) {
|
|
65
|
+
onChange({ [side]: nextValue });
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const magnitude = Math.abs(nextValue);
|
|
69
|
+
onChange({
|
|
70
|
+
shadowCameraTop: magnitude,
|
|
71
|
+
shadowCameraBottom: -magnitude,
|
|
72
|
+
shadowCameraLeft: -magnitude,
|
|
73
|
+
shadowCameraRight: magnitude,
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
const toggleLocked = () => {
|
|
77
|
+
setLocked(current => {
|
|
78
|
+
const nextLocked = !current;
|
|
79
|
+
if (nextLocked) {
|
|
80
|
+
const magnitude = Math.max(Math.abs(values.shadowCameraTop), Math.abs(values.shadowCameraBottom), Math.abs(values.shadowCameraLeft), Math.abs(values.shadowCameraRight));
|
|
81
|
+
onChange({
|
|
82
|
+
shadowCameraTop: magnitude,
|
|
83
|
+
shadowCameraBottom: -magnitude,
|
|
84
|
+
shadowCameraLeft: -magnitude,
|
|
85
|
+
shadowCameraRight: magnitude,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return nextLocked;
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
return (_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 6 }, children: [_jsx("div", { style: Object.assign(Object.assign({}, frustumLabelStyle), { textAlign: 'left' }), children: "Shadow Frustum" }), _jsxs("div", { style: {
|
|
92
|
+
display: 'grid',
|
|
93
|
+
gridTemplateColumns: '1fr auto 1fr',
|
|
94
|
+
gridTemplateRows: 'auto auto auto',
|
|
95
|
+
gap: 8,
|
|
96
|
+
alignItems: 'center',
|
|
97
|
+
}, children: [_jsx("div", {}), _jsx("div", { style: frustumCellStyle, children: _jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 4, alignItems: 'center' }, children: [_jsx("div", { style: frustumLabelStyle, children: "Top" }), _jsx(NumberInput, { value: values.shadowCameraTop, onChange: nextValue => updateSide('shadowCameraTop', nextValue), step: 0.5, style: frustumInputStyle })] }) }), _jsx("div", {}), _jsx("div", { style: frustumCellStyle, children: _jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 4, alignItems: 'center' }, children: [_jsx("div", { style: frustumLabelStyle, children: "Left" }), _jsx(NumberInput, { value: values.shadowCameraLeft, onChange: nextValue => updateSide('shadowCameraLeft', nextValue), step: 0.5, style: frustumInputStyle })] }) }), _jsx("div", { style: frustumCellStyle, children: _jsx("button", { type: "button", onClick: toggleLocked, style: Object.assign(Object.assign({}, centerLockButtonStyle), { color: locked ? colors.accent : colors.textMuted, borderColor: locked ? colors.accentBorder : colors.border, background: locked ? colors.accentBg : colors.bgInput }), title: locked ? 'Frustum sides locked' : 'Frustum sides unlocked', children: locked ? '🔒' : '🔓' }) }), _jsx("div", { style: frustumCellStyle, children: _jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 4, alignItems: 'center' }, children: [_jsx("div", { style: frustumLabelStyle, children: "Right" }), _jsx(NumberInput, { value: values.shadowCameraRight, onChange: nextValue => updateSide('shadowCameraRight', nextValue), step: 0.5, style: frustumInputStyle })] }) }), _jsx("div", {}), _jsx("div", { style: frustumCellStyle, children: _jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 4, alignItems: 'center' }, children: [_jsx("div", { style: frustumLabelStyle, children: "Bottom" }), _jsx(NumberInput, { value: values.shadowCameraBottom, onChange: nextValue => updateSide('shadowCameraBottom', nextValue), step: 0.5, style: frustumInputStyle })] }) }), _jsx("div", {})] })] }));
|
|
98
|
+
}
|
|
44
99
|
function DirectionalLightComponentEditor({ component, onUpdate }) {
|
|
45
|
-
const values =
|
|
46
|
-
|
|
47
|
-
? directionalLightFields
|
|
48
|
-
: directionalLightFields.filter(field => field.name !== '_shadowCamera');
|
|
49
|
-
return (_jsx(FieldRenderer, { fields: fields, values: values, onChange: onUpdate }));
|
|
100
|
+
const values = mergeWithDefaults(directionalLightDefaults, component.properties);
|
|
101
|
+
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] })] }));
|
|
50
102
|
}
|
|
51
103
|
function DirectionalLightView({ properties, children, editMode, isSelected }) {
|
|
52
|
-
const merged =
|
|
104
|
+
const merged = mergeWithDefaults(directionalLightDefaults, properties);
|
|
53
105
|
const color = merged.color;
|
|
54
106
|
const intensity = merged.intensity;
|
|
55
107
|
const castShadow = merged.castShadow;
|
|
56
108
|
const shadowMapSize = merged.shadowMapSize;
|
|
109
|
+
const shadowBias = merged.shadowBias;
|
|
110
|
+
const shadowNormalBias = merged.shadowNormalBias;
|
|
111
|
+
const shadowAutoUpdate = merged.shadowAutoUpdate;
|
|
57
112
|
const shadowCameraNear = merged.shadowCameraNear;
|
|
58
113
|
const shadowCameraFar = merged.shadowCameraFar;
|
|
59
114
|
const shadowCameraTop = merged.shadowCameraTop;
|
|
@@ -63,31 +118,48 @@ function DirectionalLightView({ properties, children, editMode, isSelected }) {
|
|
|
63
118
|
const targetOffset = merged.targetOffset;
|
|
64
119
|
const directionalLightRef = useRef(null);
|
|
65
120
|
const targetRef = useRef(null);
|
|
121
|
+
const shadowCameraRef = useRef(null);
|
|
66
122
|
const [shadowCamera, setShadowCamera] = useState(null);
|
|
67
|
-
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
return () => {
|
|
70
|
-
shadowCameraHelper === null || shadowCameraHelper === void 0 ? void 0 : shadowCameraHelper.dispose();
|
|
71
|
-
};
|
|
72
|
-
}, [shadowCameraHelper]);
|
|
123
|
+
useHelper(editMode && isSelected && castShadow ? shadowCameraRef : null, CameraHelper);
|
|
73
124
|
// Use a local target object so node transforms rotate the light direction naturally.
|
|
74
125
|
useEffect(() => {
|
|
75
126
|
if (directionalLightRef.current && targetRef.current) {
|
|
76
127
|
directionalLightRef.current.target = targetRef.current;
|
|
77
|
-
|
|
128
|
+
const nextShadowCamera = directionalLightRef.current.shadow.camera;
|
|
129
|
+
shadowCameraRef.current = nextShadowCamera;
|
|
130
|
+
setShadowCamera(nextShadowCamera);
|
|
78
131
|
}
|
|
79
132
|
}, []);
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
var _a;
|
|
135
|
+
const shadow = (_a = directionalLightRef.current) === null || _a === void 0 ? void 0 : _a.shadow;
|
|
136
|
+
if (!shadow)
|
|
137
|
+
return;
|
|
138
|
+
shadow.needsUpdate = true;
|
|
139
|
+
shadow.camera.updateProjectionMatrix();
|
|
140
|
+
}, [
|
|
141
|
+
castShadow,
|
|
142
|
+
shadowMapSize,
|
|
143
|
+
shadowBias,
|
|
144
|
+
shadowNormalBias,
|
|
145
|
+
shadowAutoUpdate,
|
|
146
|
+
shadowCameraNear,
|
|
147
|
+
shadowCameraFar,
|
|
148
|
+
shadowCameraTop,
|
|
149
|
+
shadowCameraBottom,
|
|
150
|
+
shadowCameraLeft,
|
|
151
|
+
shadowCameraRight,
|
|
152
|
+
]);
|
|
80
153
|
useFrame(() => {
|
|
81
154
|
if (!directionalLightRef.current || !targetRef.current)
|
|
82
155
|
return;
|
|
83
156
|
directionalLightRef.current.target.updateMatrixWorld();
|
|
84
|
-
if (shadowCamera &&
|
|
157
|
+
if (shadowCamera && castShadow) {
|
|
85
158
|
shadowCamera.updateProjectionMatrix();
|
|
86
159
|
shadowCamera.updateMatrixWorld();
|
|
87
|
-
shadowCameraHelper.update();
|
|
88
160
|
}
|
|
89
161
|
});
|
|
90
|
-
return (_jsxs(_Fragment, { children: [_jsx("directionalLight", { ref: directionalLightRef, color: color, intensity: intensity, castShadow: castShadow, "shadow-mapSize-width": shadowMapSize, "shadow-mapSize-height": shadowMapSize, "shadow-camera-near": shadowCameraNear, "shadow-camera-far": shadowCameraFar, "shadow-camera-top": shadowCameraTop, "shadow-camera-bottom": shadowCameraBottom, "shadow-camera-left": shadowCameraLeft, "shadow-camera-right": shadowCameraRight, "shadow-bias":
|
|
162
|
+
return (_jsxs(_Fragment, { children: [_jsx("directionalLight", { ref: directionalLightRef, color: color, intensity: intensity, castShadow: castShadow, "shadow-mapSize-width": shadowMapSize, "shadow-mapSize-height": shadowMapSize, "shadow-camera-near": shadowCameraNear, "shadow-camera-far": shadowCameraFar, "shadow-camera-top": shadowCameraTop, "shadow-camera-bottom": shadowCameraBottom, "shadow-camera-left": shadowCameraLeft, "shadow-camera-right": shadowCameraRight, "shadow-bias": shadowBias, "shadow-normalBias": shadowNormalBias, "shadow-autoUpdate": shadowAutoUpdate }), _jsx("object3D", { ref: targetRef, position: targetOffset }), editMode && isSelected && (_jsxs(_Fragment, { children: [_jsxs("mesh", { children: [_jsx("sphereGeometry", { args: [0.3, 8, 6] }), _jsx("meshBasicMaterial", { color: color, wireframe: true })] }), _jsxs("mesh", { position: targetOffset, children: [_jsx("sphereGeometry", { args: [0.2, 8, 6] }), _jsx("meshBasicMaterial", { color: color, wireframe: true, opacity: 0.5, transparent: true })] }), _jsxs("line", { children: [_jsx("bufferGeometry", { onUpdate: (geo) => {
|
|
91
163
|
const points = [
|
|
92
164
|
new Vector3(0, 0, 0),
|
|
93
165
|
new Vector3(targetOffset[0], targetOffset[1], targetOffset[2])
|
|
@@ -99,6 +171,6 @@ const DirectionalLightComponent = {
|
|
|
99
171
|
name: 'DirectionalLight',
|
|
100
172
|
Editor: DirectionalLightComponentEditor,
|
|
101
173
|
View: DirectionalLightView,
|
|
102
|
-
defaultProperties:
|
|
174
|
+
defaultProperties: {}
|
|
103
175
|
};
|
|
104
176
|
export default DirectionalLightComponent;
|
|
@@ -1,10 +1,12 @@
|
|
|
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
|
-
|
|
4
|
+
import { useSceneRuntime } from '../PrefabRoot';
|
|
5
|
+
function EnvironmentView({ properties, children, }) {
|
|
6
|
+
const { getAssetRevision } = useSceneRuntime();
|
|
5
7
|
const { intensity = 1, resolution = 256 } = properties;
|
|
6
|
-
const
|
|
7
|
-
return (_jsx(Environment, { background: true, environmentIntensity: intensity, resolution: resolution, frames:
|
|
8
|
+
const environmentRevision = `${getAssetRevision()}::${intensity}::${resolution}`;
|
|
9
|
+
return (_jsx(Environment, { background: true, environmentIntensity: intensity, resolution: resolution, frames: 1, children: children }, environmentRevision));
|
|
8
10
|
}
|
|
9
11
|
const EnvironmentComponent = {
|
|
10
12
|
name: 'Environment',
|
|
@@ -136,6 +136,22 @@ interface BoundVector3FieldProps extends BoundFieldProps {
|
|
|
136
136
|
export declare function FieldGroup({ children }: {
|
|
137
137
|
children: React.ReactNode;
|
|
138
138
|
}): import("react/jsx-runtime").JSX.Element;
|
|
139
|
+
interface ListEditorOption {
|
|
140
|
+
value: string;
|
|
141
|
+
label: string;
|
|
142
|
+
}
|
|
143
|
+
interface ListEditorProps<T> {
|
|
144
|
+
label: string;
|
|
145
|
+
items: T[];
|
|
146
|
+
renderItem: (item: T, index: number) => React.ReactNode;
|
|
147
|
+
onAdd: (value: string) => void;
|
|
148
|
+
addOptions?: ListEditorOption[];
|
|
149
|
+
emptyMessage?: string;
|
|
150
|
+
canAdd?: boolean;
|
|
151
|
+
addButtonTitle?: string;
|
|
152
|
+
addDisabledTitle?: string;
|
|
153
|
+
}
|
|
154
|
+
export declare function ListEditor<T>({ label, items, renderItem, onAdd, addOptions, emptyMessage, canAdd, addButtonTitle, addDisabledTitle, }: ListEditorProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
139
155
|
export declare function NumberField({ name, label, values, onChange, fallback, step, min, max, style, }: BoundNumberFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
140
156
|
export declare function StringField({ name, label, values, onChange, fallback, placeholder, }: BoundStringFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
141
157
|
export declare function ColorField({ name, label, values, onChange, fallback, }: BoundColorFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -294,6 +294,39 @@ function bindFieldChange(name, onChange) {
|
|
|
294
294
|
export function FieldGroup({ children }) {
|
|
295
295
|
return _jsx("div", { style: { display: 'flex', flexDirection: 'column', gap: 8 }, children: children });
|
|
296
296
|
}
|
|
297
|
+
export function ListEditor({ label, items, renderItem, onAdd, addOptions = [], emptyMessage = 'No items added.', canAdd = true, addButtonTitle = 'Add item', addDisabledTitle = 'No more items available', }) {
|
|
298
|
+
var _a;
|
|
299
|
+
const [selectedAddValue, setSelectedAddValue] = useState('');
|
|
300
|
+
const hasAddSelector = addOptions.length > 0;
|
|
301
|
+
const resolvedAddValue = hasAddSelector ? (selectedAddValue || ((_a = addOptions[0]) === null || _a === void 0 ? void 0 : _a.value) || '') : '';
|
|
302
|
+
const canAddItem = canAdd && (!hasAddSelector || resolvedAddValue !== '');
|
|
303
|
+
useEffect(() => {
|
|
304
|
+
var _a, _b;
|
|
305
|
+
if (!hasAddSelector) {
|
|
306
|
+
if (selectedAddValue !== '') {
|
|
307
|
+
setSelectedAddValue('');
|
|
308
|
+
}
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const stillAvailable = addOptions.some(option => option.value === selectedAddValue);
|
|
312
|
+
if (!stillAvailable) {
|
|
313
|
+
setSelectedAddValue((_b = (_a = addOptions[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '');
|
|
314
|
+
}
|
|
315
|
+
}, [addOptions, hasAddSelector, selectedAddValue]);
|
|
316
|
+
return (_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 8 }, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between' }, children: [_jsx(Label, { children: label }), _jsxs("div", { style: { display: 'flex', gap: 6, alignItems: 'center' }, children: [hasAddSelector ? (_jsx("div", { style: { minWidth: 140 }, children: _jsx(SelectInput, { value: resolvedAddValue, onChange: setSelectedAddValue, options: canAdd ? addOptions : [{ value: '', label: 'All items added' }] }) })) : null, _jsx("button", { type: "button", onClick: () => onAdd(resolvedAddValue), disabled: !canAddItem, style: {
|
|
317
|
+
width: 22,
|
|
318
|
+
height: 22,
|
|
319
|
+
borderRadius: 3,
|
|
320
|
+
border: `1px solid ${canAddItem ? colors.accentBorder : colors.border}`,
|
|
321
|
+
background: canAddItem ? colors.accentBg : colors.bgSurface,
|
|
322
|
+
color: canAddItem ? colors.accent : colors.textMuted,
|
|
323
|
+
cursor: canAddItem ? 'pointer' : 'not-allowed',
|
|
324
|
+
fontSize: 14,
|
|
325
|
+
lineHeight: 1,
|
|
326
|
+
padding: 0,
|
|
327
|
+
flexShrink: 0,
|
|
328
|
+
}, title: canAddItem ? addButtonTitle : addDisabledTitle, children: "+" })] })] }), items.length === 0 ? (_jsx("div", { style: { fontSize: 11, color: colors.textMuted }, children: emptyMessage })) : null, items.map(renderItem)] }));
|
|
329
|
+
}
|
|
297
330
|
export function NumberField({ name, label, values, onChange, fallback = 0, step, min, max, style, }) {
|
|
298
331
|
var _a;
|
|
299
332
|
return (_jsx(FieldRow, { label: label, children: _jsx(NumberInput, { value: (_a = values[name]) !== null && _a !== void 0 ? _a : fallback, onChange: bindFieldChange(name, onChange), step: step, min: min, max: max, style: style }) }));
|
|
@@ -12,6 +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 { useSceneRuntime } from '../PrefabRoot';
|
|
15
16
|
import { useMemo } from 'react';
|
|
16
17
|
import { MeshBasicNodeMaterial, MeshStandardNodeMaterial } from 'three/webgpu';
|
|
17
18
|
import { TexturePicker } from '../../assetviewer/page';
|
|
@@ -119,8 +120,10 @@ function MaterialComponentEditor({ component, onUpdate, basePath = "" }) {
|
|
|
119
120
|
return (_jsx(FieldRenderer, { fields: fields, values: component.properties, onChange: onUpdate }));
|
|
120
121
|
}
|
|
121
122
|
// View for Material component
|
|
122
|
-
function MaterialComponentView({ properties
|
|
123
|
-
var _a, _b, _c;
|
|
123
|
+
function MaterialComponentView({ properties: rawProps }) {
|
|
124
|
+
var _a, _b, _c, _d, _e;
|
|
125
|
+
const { getTexture } = useSceneRuntime();
|
|
126
|
+
const properties = rawProps;
|
|
124
127
|
const materialType = (_a = properties === null || properties === void 0 ? void 0 : properties.materialType) !== null && _a !== void 0 ? _a : 'standard';
|
|
125
128
|
const textureName = properties === null || properties === void 0 ? void 0 : properties.texture;
|
|
126
129
|
const repeat = properties === null || properties === void 0 ? void 0 : properties.repeat;
|
|
@@ -128,15 +131,15 @@ function MaterialComponentView({ properties, loadedTextures }) {
|
|
|
128
131
|
const generateMipmaps = (properties === null || properties === void 0 ? void 0 : properties.generateMipmaps) !== false;
|
|
129
132
|
const minFilter = (properties === null || properties === void 0 ? void 0 : properties.minFilter) || 'LinearMipmapLinearFilter';
|
|
130
133
|
const magFilter = (properties === null || properties === void 0 ? void 0 : properties.magFilter) || 'LinearFilter';
|
|
131
|
-
const texture = textureName &&
|
|
134
|
+
const texture = textureName ? (_b = getTexture(textureName)) !== null && _b !== void 0 ? _b : undefined : undefined;
|
|
132
135
|
const normalMapTextureName = properties === null || properties === void 0 ? void 0 : properties.normalMapTexture;
|
|
133
136
|
const normalScaleProp = properties === null || properties === void 0 ? void 0 : properties.normalScale;
|
|
134
|
-
const normalMapTexture = normalMapTextureName &&
|
|
137
|
+
const normalMapTexture = normalMapTextureName ? (_c = getTexture(normalMapTextureName)) !== null && _c !== void 0 ? _c : undefined : undefined;
|
|
135
138
|
const materialSource = properties !== null && properties !== void 0 ? properties : {};
|
|
136
139
|
// Destructure all material props and separate custom texture handling props
|
|
137
140
|
const { texture: _texture, repeat: _repeat, repeatCount: _repeatCount, generateMipmaps: _generateMipmaps, minFilter: _minFilter, magFilter: _magFilter, map: _map, materialType: _materialType, normalMapTexture: _normalMapTexture, normalScale: _normalScale, normalMap: _normalMap, side: sideProp } = materialSource, materialProps = __rest(materialSource, ["texture", "repeat", "repeatCount", "generateMipmaps", "minFilter", "magFilter", "map", "materialType", "normalMapTexture", "normalScale", "normalMap", "side"]);
|
|
138
141
|
const sideMap = { FrontSide, BackSide, DoubleSide };
|
|
139
|
-
const resolvedSide = sideProp ? ((
|
|
142
|
+
const resolvedSide = sideProp ? ((_d = sideMap[sideProp]) !== null && _d !== void 0 ? _d : FrontSide) : FrontSide;
|
|
140
143
|
const minFilterMap = {
|
|
141
144
|
NearestFilter,
|
|
142
145
|
LinearFilter,
|
|
@@ -187,7 +190,7 @@ function MaterialComponentView({ properties, loadedTextures }) {
|
|
|
187
190
|
if (!properties) {
|
|
188
191
|
return _jsx("meshStandardNodeMaterial", { color: "red", wireframe: true });
|
|
189
192
|
}
|
|
190
|
-
const materialKey = `${(
|
|
193
|
+
const materialKey = `${(_e = finalTexture === null || finalTexture === void 0 ? void 0 : finalTexture.uuid) !== null && _e !== void 0 ? _e : 'no-texture'}:${materialProps.transparent ? 'transparent' : 'opaque'}`;
|
|
191
194
|
const sharedProps = Object.assign({ map: finalTexture, side: resolvedSide }, materialProps);
|
|
192
195
|
if (materialType === 'basic') {
|
|
193
196
|
return _jsx("meshBasicNodeMaterial", Object.assign({}, sharedProps), materialKey);
|
|
@@ -198,7 +201,7 @@ const MaterialComponent = {
|
|
|
198
201
|
name: 'Material',
|
|
199
202
|
Editor: MaterialComponentEditor,
|
|
200
203
|
View: MaterialComponentView,
|
|
201
|
-
|
|
204
|
+
isWrapper: true,
|
|
202
205
|
defaultProperties: {
|
|
203
206
|
materialType: 'standard',
|
|
204
207
|
color: '#ffffff',
|
|
@@ -208,6 +211,14 @@ const MaterialComponent = {
|
|
|
208
211
|
opacity: 1,
|
|
209
212
|
metalness: 0,
|
|
210
213
|
roughness: 1
|
|
211
|
-
}
|
|
214
|
+
},
|
|
215
|
+
getAssetRefs: (properties) => {
|
|
216
|
+
const refs = [];
|
|
217
|
+
if (properties.texture)
|
|
218
|
+
refs.push({ type: 'texture', path: properties.texture });
|
|
219
|
+
if (properties.normalMapTexture)
|
|
220
|
+
refs.push({ type: 'texture', path: properties.normalMapTexture });
|
|
221
|
+
return refs;
|
|
222
|
+
},
|
|
212
223
|
};
|
|
213
224
|
export default MaterialComponent;
|