react-three-game 0.0.56 → 0.0.57
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 +1 -1
- package/dist/index.js +1 -1
- package/dist/shared/GameCanvas.js +1 -3
- package/dist/tools/assetviewer/page.js +35 -14
- package/dist/tools/prefabeditor/Dropdown.d.ts +15 -0
- package/dist/tools/prefabeditor/Dropdown.js +82 -0
- package/dist/tools/prefabeditor/EditorContext.d.ts +5 -0
- package/dist/tools/prefabeditor/EditorTree.js +138 -56
- package/dist/tools/prefabeditor/EditorUI.js +1 -1
- package/dist/tools/prefabeditor/PrefabEditor.d.ts +1 -0
- package/dist/tools/prefabeditor/PrefabEditor.js +13 -2
- package/dist/tools/prefabeditor/PrefabRoot.d.ts +1 -0
- package/dist/tools/prefabeditor/PrefabRoot.js +120 -34
- package/dist/tools/prefabeditor/components/AmbientLightComponent.js +3 -7
- package/dist/tools/prefabeditor/components/CameraComponent.d.ts +3 -0
- package/dist/tools/prefabeditor/components/CameraComponent.js +25 -0
- package/dist/tools/prefabeditor/components/DirectionalLightComponent.js +2 -2
- package/dist/tools/prefabeditor/components/EnvironmentComponent.d.ts +3 -0
- package/dist/tools/prefabeditor/components/EnvironmentComponent.js +15 -0
- package/dist/tools/prefabeditor/components/GeometryComponent.js +46 -46
- package/dist/tools/prefabeditor/components/Input.d.ts +51 -1
- package/dist/tools/prefabeditor/components/Input.js +73 -21
- package/dist/tools/prefabeditor/components/MaterialComponent.d.ts +8 -2
- package/dist/tools/prefabeditor/components/MaterialComponent.js +122 -14
- package/dist/tools/prefabeditor/components/ModelComponent.js +44 -3
- package/dist/tools/prefabeditor/components/PhysicsComponent.js +16 -81
- package/dist/tools/prefabeditor/components/SpotLightComponent.js +4 -12
- package/dist/tools/prefabeditor/components/TextComponent.js +7 -53
- package/dist/tools/prefabeditor/components/TransformComponent.js +18 -8
- package/dist/tools/prefabeditor/components/index.js +5 -1
- package/dist/tools/prefabeditor/styles.d.ts +5 -2
- package/dist/tools/prefabeditor/styles.js +7 -3
- package/dist/tools/prefabeditor/utils.d.ts +4 -3
- package/dist/tools/prefabeditor/utils.js +53 -5
- package/package.json +1 -1
- package/src/index.ts +7 -0
- package/src/shared/GameCanvas.tsx +0 -3
- package/src/tools/assetviewer/page.tsx +77 -45
- package/src/tools/prefabeditor/Dropdown.tsx +112 -0
- package/src/tools/prefabeditor/EditorContext.tsx +5 -0
- package/src/tools/prefabeditor/EditorTree.tsx +234 -101
- package/src/tools/prefabeditor/EditorUI.tsx +1 -1
- package/src/tools/prefabeditor/PrefabEditor.tsx +17 -4
- package/src/tools/prefabeditor/PrefabRoot.tsx +208 -58
- package/src/tools/prefabeditor/components/AmbientLightComponent.tsx +5 -11
- package/src/tools/prefabeditor/components/CameraComponent.tsx +80 -0
- package/src/tools/prefabeditor/components/DirectionalLightComponent.tsx +2 -2
- package/src/tools/prefabeditor/components/EnvironmentComponent.tsx +47 -0
- package/src/tools/prefabeditor/components/GeometryComponent.tsx +69 -63
- package/src/tools/prefabeditor/components/Input.tsx +220 -27
- package/src/tools/prefabeditor/components/MaterialComponent.tsx +178 -16
- package/src/tools/prefabeditor/components/ModelComponent.tsx +51 -4
- package/src/tools/prefabeditor/components/PhysicsComponent.tsx +44 -85
- package/src/tools/prefabeditor/components/SpotLightComponent.tsx +11 -17
- package/src/tools/prefabeditor/components/TextComponent.tsx +58 -57
- package/src/tools/prefabeditor/components/TransformComponent.tsx +61 -9
- package/src/tools/prefabeditor/components/index.ts +5 -1
- package/src/tools/prefabeditor/styles.ts +7 -3
- package/src/tools/prefabeditor/utils.ts +55 -4
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useRef, useEffect } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { BooleanField, ColorField, FieldGroup, NumberField } from "./Input";
|
|
4
4
|
import { useHelper } from "@react-three/drei";
|
|
5
5
|
import { SpotLightHelper } from "three";
|
|
6
|
-
const spotLightFields = [
|
|
7
|
-
{ name: 'color', type: 'color', label: 'Color' },
|
|
8
|
-
{ name: 'intensity', type: 'number', label: 'Intensity', step: 0.1, min: 0 },
|
|
9
|
-
{ name: 'angle', type: 'number', label: 'Angle', step: 0.1, min: 0, max: Math.PI },
|
|
10
|
-
{ name: 'penumbra', type: 'number', label: 'Penumbra', step: 0.1, min: 0, max: 1 },
|
|
11
|
-
{ name: 'distance', type: 'number', label: 'Distance', step: 1, min: 0 },
|
|
12
|
-
{ name: 'castShadow', type: 'boolean', label: 'Cast Shadow' },
|
|
13
|
-
];
|
|
14
6
|
function SpotLightComponentEditor({ component, onUpdate }) {
|
|
15
|
-
return (_jsx(
|
|
7
|
+
return (_jsxs(FieldGroup, { children: [_jsx(ColorField, { name: "color", label: "Color", values: component.properties, onChange: onUpdate }), _jsx(NumberField, { name: "intensity", label: "Intensity", values: component.properties, onChange: onUpdate, min: 0, step: 0.1, fallback: 1 }), _jsx(NumberField, { name: "angle", label: "Angle", values: component.properties, onChange: onUpdate, min: 0, max: Math.PI, step: 0.05, fallback: Math.PI / 6 }), _jsx(NumberField, { name: "penumbra", label: "Penumbra", values: component.properties, onChange: onUpdate, min: 0, max: 1, step: 0.05, fallback: 0.5 }), _jsx(NumberField, { name: "distance", label: "Distance", values: component.properties, onChange: onUpdate, min: 0, step: 1, fallback: 100 }), _jsx(BooleanField, { name: "castShadow", label: "Cast Shadow", values: component.properties, onChange: onUpdate, fallback: true })] }));
|
|
16
8
|
}
|
|
17
|
-
function SpotLightView({ properties, editMode }) {
|
|
9
|
+
function SpotLightView({ properties, editMode, isSelected }) {
|
|
18
10
|
var _a, _b, _c, _d, _e, _f;
|
|
19
11
|
const color = (_a = properties.color) !== null && _a !== void 0 ? _a : '#ffffff';
|
|
20
12
|
const intensity = (_b = properties.intensity) !== null && _b !== void 0 ? _b : 1.0;
|
|
@@ -24,7 +16,7 @@ function SpotLightView({ properties, editMode }) {
|
|
|
24
16
|
const castShadow = (_f = properties.castShadow) !== null && _f !== void 0 ? _f : true;
|
|
25
17
|
const spotLightRef = useRef(null);
|
|
26
18
|
const targetRef = useRef(null);
|
|
27
|
-
useHelper(editMode ? spotLightRef : null, SpotLightHelper, color);
|
|
19
|
+
useHelper(editMode && isSelected ? spotLightRef : null, SpotLightHelper, color);
|
|
28
20
|
useEffect(() => {
|
|
29
21
|
if (spotLightRef.current && targetRef.current) {
|
|
30
22
|
spotLightRef.current.target = targetRef.current;
|
|
@@ -1,61 +1,15 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ColorField, FieldGroup, NumberField, SelectField, StringField } from "./Input";
|
|
3
3
|
import { Text } from 'three-text/three/react';
|
|
4
4
|
import { useRef, useState, useCallback } from 'react';
|
|
5
5
|
// Initialize HarfBuzz path for font shaping
|
|
6
6
|
Text.setHarfBuzzPath('/fonts/hb.wasm');
|
|
7
7
|
function TextComponentEditor({ component, onUpdate, }) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
placeholder: 'Enter text...',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
name: 'color',
|
|
17
|
-
type: 'color',
|
|
18
|
-
label: 'Color',
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
name: 'font',
|
|
22
|
-
type: 'string',
|
|
23
|
-
label: 'Font',
|
|
24
|
-
placeholder: '/fonts/NotoSans-Regular.ttf',
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: 'size',
|
|
28
|
-
type: 'number',
|
|
29
|
-
label: 'Size',
|
|
30
|
-
min: 0.01,
|
|
31
|
-
step: 0.1,
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
name: 'depth',
|
|
35
|
-
type: 'number',
|
|
36
|
-
label: 'Depth',
|
|
37
|
-
min: 0,
|
|
38
|
-
step: 0.1,
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: 'width',
|
|
42
|
-
type: 'number',
|
|
43
|
-
label: 'Width',
|
|
44
|
-
min: 0,
|
|
45
|
-
step: 0.5,
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: 'align',
|
|
49
|
-
type: 'select',
|
|
50
|
-
label: 'Align',
|
|
51
|
-
options: [
|
|
52
|
-
{ value: 'left', label: 'Left' },
|
|
53
|
-
{ value: 'center', label: 'Center' },
|
|
54
|
-
{ value: 'right', label: 'Right' },
|
|
55
|
-
],
|
|
56
|
-
},
|
|
57
|
-
];
|
|
58
|
-
return (_jsx(FieldRenderer, { fields: fields, values: component.properties, onChange: onUpdate }));
|
|
8
|
+
return (_jsxs(FieldGroup, { children: [_jsx(StringField, { name: "text", label: "Text", values: component.properties, onChange: onUpdate, placeholder: "Enter text..." }), _jsx(ColorField, { name: "color", label: "Color", values: component.properties, onChange: onUpdate }), _jsx(StringField, { name: "font", label: "Font", values: component.properties, onChange: onUpdate, placeholder: "/fonts/NotoSans-Regular.ttf" }), _jsx(NumberField, { name: "size", label: "Size", values: component.properties, onChange: onUpdate, min: 0.01, step: 0.1 }), _jsx(NumberField, { name: "depth", label: "Depth", values: component.properties, onChange: onUpdate, min: 0, step: 0.1 }), _jsx(NumberField, { name: "width", label: "Width", values: component.properties, onChange: onUpdate, min: 0, step: 0.5 }), _jsx(SelectField, { name: "align", label: "Align", values: component.properties, onChange: onUpdate, options: [
|
|
9
|
+
{ value: 'left', label: 'Left' },
|
|
10
|
+
{ value: 'center', label: 'Center' },
|
|
11
|
+
{ value: 'right', label: 'Right' },
|
|
12
|
+
] })] }));
|
|
59
13
|
}
|
|
60
14
|
function TextComponentView({ properties }) {
|
|
61
15
|
const { text = '', font, size, depth, width, align, color } = properties;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { Label, Vector3Field, Vector3Input } from "./Input";
|
|
3
3
|
import { useEditorContext } from "../EditorContext";
|
|
4
4
|
import { colors } from "../styles";
|
|
5
5
|
const buttonStyle = {
|
|
@@ -31,14 +31,24 @@ function TransformModeSelector({ transformMode, setTransformMode, snapResolution
|
|
|
31
31
|
e.currentTarget.style.background = colors.bgSurface;
|
|
32
32
|
}, children: ["Snap: ", snapResolution > 0 ? `ON (${snapResolution})` : 'OFF'] }) })] }));
|
|
33
33
|
}
|
|
34
|
+
const snapLockBtnStyle = {
|
|
35
|
+
background: 'none',
|
|
36
|
+
border: 'none',
|
|
37
|
+
cursor: 'pointer',
|
|
38
|
+
padding: '0 2px',
|
|
39
|
+
fontSize: 12,
|
|
40
|
+
lineHeight: 1,
|
|
41
|
+
color: colors.textMuted,
|
|
42
|
+
};
|
|
43
|
+
function SnapLockButton({ locked, onToggle, title }) {
|
|
44
|
+
return (_jsx("button", { style: snapLockBtnStyle, onClick: onToggle, title: title, children: locked ? '🔒' : '🔓' }));
|
|
45
|
+
}
|
|
34
46
|
function TransformComponentEditor({ component, onUpdate }) {
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
];
|
|
41
|
-
return (_jsxs("div", { style: { display: 'flex', flexDirection: 'column' }, children: [_jsx(TransformModeSelector, { transformMode: transformMode, setTransformMode: setTransformMode, snapResolution: snapResolution, setSnapResolution: setSnapResolution }), _jsx(FieldRenderer, { fields: fields, values: component.properties, onChange: onUpdate })] }));
|
|
47
|
+
var _a, _b;
|
|
48
|
+
const { transformMode, setTransformMode, snapResolution, setSnapResolution, positionSnap, setPositionSnap, rotationSnap, setRotationSnap } = useEditorContext();
|
|
49
|
+
const positionSnapped = positionSnap > 0;
|
|
50
|
+
const rotationSnapped = rotationSnap > 0;
|
|
51
|
+
return (_jsxs("div", { style: { display: 'flex', flexDirection: 'column' }, children: [_jsx(TransformModeSelector, { transformMode: transformMode, setTransformMode: setTransformMode, snapResolution: snapResolution, setSnapResolution: setSnapResolution }), _jsx(Vector3Input, { label: "Position", value: (_a = component.properties.position) !== null && _a !== void 0 ? _a : [0, 0, 0], onChange: v => onUpdate({ position: v }), snap: positionSnap, labelExtra: _jsx(SnapLockButton, { locked: positionSnapped, onToggle: () => setPositionSnap(positionSnapped ? 0 : 0.5), title: positionSnapped ? `Snap ON (0.5) — click to disable` : `Snap OFF — click to enable (0.5)` }) }), _jsx(Vector3Input, { label: "Rotation", value: (_b = component.properties.rotation) !== null && _b !== void 0 ? _b : [0, 0, 0], onChange: v => onUpdate({ rotation: v }), snap: rotationSnap, labelExtra: _jsx(SnapLockButton, { locked: rotationSnapped, onToggle: () => setRotationSnap(rotationSnapped ? 0 : Math.PI / 4), title: rotationSnapped ? `Snap ON (π/4) — click to disable` : `Snap OFF — click to enable (π/4)` }) }), _jsx(Vector3Field, { name: "scale", label: "Scale", values: component.properties, onChange: onUpdate, fallback: [1, 1, 1] })] }));
|
|
42
52
|
}
|
|
43
53
|
const TransformComponent = {
|
|
44
54
|
name: 'Transform',
|
|
@@ -7,6 +7,8 @@ import DirectionalLightComponent from './DirectionalLightComponent';
|
|
|
7
7
|
import AmbientLightComponent from './AmbientLightComponent';
|
|
8
8
|
import ModelComponent from './ModelComponent';
|
|
9
9
|
import TextComponent from './TextComponent';
|
|
10
|
+
import EnvironmentComponent from './EnvironmentComponent';
|
|
11
|
+
import CameraComponent from './CameraComponent';
|
|
10
12
|
export default [
|
|
11
13
|
GeometryComponent,
|
|
12
14
|
TransformComponent,
|
|
@@ -16,5 +18,7 @@ export default [
|
|
|
16
18
|
DirectionalLightComponent,
|
|
17
19
|
AmbientLightComponent,
|
|
18
20
|
ModelComponent,
|
|
19
|
-
TextComponent
|
|
21
|
+
TextComponent,
|
|
22
|
+
EnvironmentComponent,
|
|
23
|
+
CameraComponent,
|
|
20
24
|
];
|
|
@@ -896,6 +896,8 @@ export declare const inspector: {
|
|
|
896
896
|
padding: number;
|
|
897
897
|
maxHeight: string;
|
|
898
898
|
overflowY: "auto";
|
|
899
|
+
overflowX: "hidden";
|
|
900
|
+
boxSizing: "border-box";
|
|
899
901
|
display: string;
|
|
900
902
|
flexDirection: "column";
|
|
901
903
|
gap: number;
|
|
@@ -1772,7 +1774,9 @@ export declare const menu: {
|
|
|
1772
1774
|
container: {
|
|
1773
1775
|
position: "fixed";
|
|
1774
1776
|
zIndex: number;
|
|
1775
|
-
minWidth:
|
|
1777
|
+
minWidth: string;
|
|
1778
|
+
width: string;
|
|
1779
|
+
maxWidth: string;
|
|
1776
1780
|
background: string;
|
|
1777
1781
|
border: string;
|
|
1778
1782
|
borderRadius: number;
|
|
@@ -1789,7 +1793,6 @@ export declare const toolbar: {
|
|
|
1789
1793
|
position: "absolute";
|
|
1790
1794
|
top: number;
|
|
1791
1795
|
left: string;
|
|
1792
|
-
transform: string;
|
|
1793
1796
|
display: string;
|
|
1794
1797
|
gap: number;
|
|
1795
1798
|
padding: string;
|
|
@@ -97,6 +97,8 @@ export const inspector = {
|
|
|
97
97
|
padding: 8,
|
|
98
98
|
maxHeight: '80vh',
|
|
99
99
|
overflowY: 'auto',
|
|
100
|
+
overflowX: 'hidden',
|
|
101
|
+
boxSizing: 'border-box',
|
|
100
102
|
display: 'flex',
|
|
101
103
|
flexDirection: 'column',
|
|
102
104
|
gap: 8,
|
|
@@ -130,7 +132,9 @@ export const menu = {
|
|
|
130
132
|
container: {
|
|
131
133
|
position: 'fixed',
|
|
132
134
|
zIndex: 50,
|
|
133
|
-
minWidth:
|
|
135
|
+
minWidth: 'auto',
|
|
136
|
+
width: 'max-content',
|
|
137
|
+
maxWidth: 'min(240px, calc(100vw - 16px))',
|
|
134
138
|
background: colors.bgSurface,
|
|
135
139
|
border: `1px solid ${colors.border}`,
|
|
136
140
|
borderRadius: 4,
|
|
@@ -145,6 +149,7 @@ export const menu = {
|
|
|
145
149
|
border: 'none',
|
|
146
150
|
color: colors.text,
|
|
147
151
|
fontSize: fonts.size,
|
|
152
|
+
whiteSpace: 'nowrap',
|
|
148
153
|
cursor: 'pointer',
|
|
149
154
|
outline: 'none',
|
|
150
155
|
},
|
|
@@ -156,8 +161,7 @@ export const toolbar = {
|
|
|
156
161
|
panel: {
|
|
157
162
|
position: 'absolute',
|
|
158
163
|
top: 8,
|
|
159
|
-
left: '
|
|
160
|
-
transform: 'translateX(-50%)',
|
|
164
|
+
left: '240px',
|
|
161
165
|
display: 'flex',
|
|
162
166
|
gap: 6,
|
|
163
167
|
padding: '4px 6px',
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { GameObject, Prefab } from "./types";
|
|
2
|
-
import { Object3D } from 'three';
|
|
2
|
+
import { Object3D, Vector3 } from 'three';
|
|
3
3
|
export interface ExportGLBOptions {
|
|
4
4
|
filename?: string;
|
|
5
5
|
binary?: boolean;
|
|
6
6
|
onComplete?: (result: ArrayBuffer | object) => void;
|
|
7
7
|
onError?: (error: any) => void;
|
|
8
8
|
}
|
|
9
|
-
/** Save a prefab as JSON file */
|
|
10
|
-
export declare function saveJson(data: Prefab, filename: string): void
|
|
9
|
+
/** Save a prefab as JSON file, showing a Save As dialog when supported */
|
|
10
|
+
export declare function saveJson(data: Prefab, filename: string): Promise<void>;
|
|
11
11
|
/** Load a prefab from JSON file */
|
|
12
12
|
export declare function loadJson(): Promise<Prefab | undefined>;
|
|
13
13
|
/**
|
|
@@ -23,6 +23,7 @@ export declare function exportGLB(sceneRoot: Object3D, options?: ExportGLBOption
|
|
|
23
23
|
* @returns Promise that resolves with the GLB data as ArrayBuffer
|
|
24
24
|
*/
|
|
25
25
|
export declare function exportGLBData(sceneRoot: Object3D): Promise<ArrayBuffer>;
|
|
26
|
+
export declare function focusCameraOnObject(object: Object3D, camera: Object3D, target: Vector3, update?: () => void): void;
|
|
26
27
|
/** Find a node by ID in the tree */
|
|
27
28
|
export declare function findNode(root: GameObject, id: string): GameObject | null;
|
|
28
29
|
/** Find the parent of a node by ID */
|
|
@@ -8,12 +8,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { GLTFExporter } from 'three/examples/jsm/exporters/GLTFExporter.js';
|
|
11
|
-
|
|
11
|
+
import { Box3, PerspectiveCamera, Quaternion, Vector3 } from 'three';
|
|
12
|
+
/** Save a prefab as JSON file, showing a Save As dialog when supported */
|
|
12
13
|
export function saveJson(data, filename) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const json = JSON.stringify(data, null, 2);
|
|
16
|
+
if ('showSaveFilePicker' in window) {
|
|
17
|
+
try {
|
|
18
|
+
const handle = yield window.showSaveFilePicker({
|
|
19
|
+
suggestedName: `${filename || 'prefab'}.json`,
|
|
20
|
+
types: [{ description: 'JSON', accept: { 'application/json': ['.json'] } }],
|
|
21
|
+
});
|
|
22
|
+
const writable = yield handle.createWritable();
|
|
23
|
+
yield writable.write(json);
|
|
24
|
+
yield writable.close();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
if ((e === null || e === void 0 ? void 0 : e.name) === 'AbortError')
|
|
29
|
+
return; // user cancelled
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Fallback for browsers without File System Access API
|
|
33
|
+
const a = document.createElement('a');
|
|
34
|
+
a.href = "data:text/json;charset=utf-8," + encodeURIComponent(json);
|
|
35
|
+
a.download = `${filename || 'prefab'}.json`;
|
|
36
|
+
a.click();
|
|
37
|
+
});
|
|
17
38
|
}
|
|
18
39
|
/** Load a prefab from JSON file */
|
|
19
40
|
export function loadJson() {
|
|
@@ -85,6 +106,33 @@ export function exportGLBData(sceneRoot) {
|
|
|
85
106
|
return result;
|
|
86
107
|
});
|
|
87
108
|
}
|
|
109
|
+
export function focusCameraOnObject(object, camera, target, update) {
|
|
110
|
+
const bounds = new Box3().setFromObject(object);
|
|
111
|
+
const center = new Vector3();
|
|
112
|
+
const size = new Vector3();
|
|
113
|
+
const quaternion = new Quaternion();
|
|
114
|
+
object.getWorldQuaternion(quaternion);
|
|
115
|
+
if (bounds.isEmpty()) {
|
|
116
|
+
object.getWorldPosition(center);
|
|
117
|
+
size.setScalar(1);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
bounds.getCenter(center);
|
|
121
|
+
bounds.getSize(size);
|
|
122
|
+
}
|
|
123
|
+
const radius = Math.max(size.length() * 0.5, 1);
|
|
124
|
+
const forward = new Vector3(0, 0, 1).applyQuaternion(quaternion).normalize();
|
|
125
|
+
const worldUp = new Vector3(0, 1, 0);
|
|
126
|
+
const elevatedDirection = forward.clone().addScaledVector(worldUp, 0.65).normalize();
|
|
127
|
+
const distance = camera instanceof PerspectiveCamera
|
|
128
|
+
? Math.max(radius / Math.tan((camera.fov * Math.PI) / 360) * 1.8, radius * 3.5)
|
|
129
|
+
: radius * 4.5;
|
|
130
|
+
const nextPosition = center.clone().add(elevatedDirection.multiplyScalar(distance));
|
|
131
|
+
camera.position.copy(nextPosition);
|
|
132
|
+
camera.lookAt(center);
|
|
133
|
+
target.copy(center);
|
|
134
|
+
update === null || update === void 0 ? void 0 : update();
|
|
135
|
+
}
|
|
88
136
|
/** Find a node by ID in the tree */
|
|
89
137
|
export function findNode(root, id) {
|
|
90
138
|
var _a;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -15,13 +15,20 @@ export { registerComponent } from './tools/prefabeditor/components/ComponentRegi
|
|
|
15
15
|
// Prefab Editor - Input Components
|
|
16
16
|
export {
|
|
17
17
|
FieldRenderer,
|
|
18
|
+
FieldGroup,
|
|
18
19
|
Input,
|
|
19
20
|
Label,
|
|
20
21
|
Vector3Input,
|
|
22
|
+
Vector3Field,
|
|
23
|
+
NumberField,
|
|
21
24
|
ColorInput,
|
|
25
|
+
ColorField,
|
|
22
26
|
StringInput,
|
|
27
|
+
StringField,
|
|
23
28
|
BooleanInput,
|
|
29
|
+
BooleanField,
|
|
24
30
|
SelectInput,
|
|
31
|
+
SelectField,
|
|
25
32
|
} from './tools/prefabeditor/components/Input';
|
|
26
33
|
|
|
27
34
|
// Prefab Editor - Styles & Utils
|
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
import { Canvas
|
|
1
|
+
import { Canvas } from "@react-three/fiber";
|
|
2
2
|
import { OrbitControls, Stage, View, PerspectiveCamera } from "@react-three/drei";
|
|
3
|
-
import { Suspense, useEffect, useState, useRef } from "react";
|
|
3
|
+
import { Component as ReactComponent, Suspense, useEffect, useState, useRef } from "react";
|
|
4
4
|
import { TextureLoader } from "three";
|
|
5
5
|
import { loadModel } from "../dragdrop/modelLoader";
|
|
6
6
|
|
|
7
|
+
class ErrorBoundary extends ReactComponent<{ onError?: () => void; children: React.ReactNode }, { hasError: boolean }> {
|
|
8
|
+
constructor(props: any) {
|
|
9
|
+
super(props);
|
|
10
|
+
this.state = { hasError: false };
|
|
11
|
+
}
|
|
12
|
+
static getDerivedStateFromError() { return { hasError: true }; }
|
|
13
|
+
componentDidCatch() { this.props.onError?.(); }
|
|
14
|
+
render() { return this.state.hasError ? null : this.props.children; }
|
|
15
|
+
}
|
|
16
|
+
|
|
7
17
|
// view models and textures in manifest, onselect callback
|
|
8
18
|
|
|
9
19
|
const styles: Record<string, any> = {
|
|
10
20
|
errorIcon: { color: '#fca5a5', fontSize: 12 }, // text-red-400 text-xs
|
|
11
21
|
flexFillRelative: { flex: 1, position: 'relative' },
|
|
12
|
-
bottomLabel: { backgroundColor: 'rgba(0,0,0,0.6)', fontSize: 10, padding: '0 4px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', textAlign: 'center' },
|
|
22
|
+
bottomLabel: { backgroundColor: 'rgba(0,0,0,0.6)', color: '#f9fafb', fontSize: 10, padding: '0 4px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', textAlign: 'center' },
|
|
23
|
+
textLight: { color: '#f9fafb' },
|
|
13
24
|
iconLarge: { fontSize: 20 }
|
|
14
25
|
};
|
|
15
26
|
|
|
@@ -49,6 +60,7 @@ function FolderTile({ name, onClick }: { name: string; onClick: () => void }) {
|
|
|
49
60
|
maxWidth: 60,
|
|
50
61
|
aspectRatio: '1 / 1',
|
|
51
62
|
backgroundColor: '#1f2937', /* gray-800 */
|
|
63
|
+
color: '#f9fafb',
|
|
52
64
|
cursor: 'pointer',
|
|
53
65
|
display: 'flex',
|
|
54
66
|
flexDirection: 'column',
|
|
@@ -100,7 +112,7 @@ function AssetListViewer({ files, selected, onSelect, renderCard }: AssetListVie
|
|
|
100
112
|
const { folders, filesInCurrentPath } = getItemsInPath(files, currentPath);
|
|
101
113
|
|
|
102
114
|
return (
|
|
103
|
-
<div>
|
|
115
|
+
<div style={styles.textLight}>
|
|
104
116
|
{currentPath && (
|
|
105
117
|
<button
|
|
106
118
|
onClick={() => {
|
|
@@ -140,17 +152,19 @@ interface TextureListViewerProps {
|
|
|
140
152
|
|
|
141
153
|
export function TextureListViewer({ files, selected, onSelect, basePath = "" }: TextureListViewerProps) {
|
|
142
154
|
return (
|
|
143
|
-
|
|
144
|
-
<
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
155
|
+
<div style={{ position: 'relative', width: '100%', height: '100%' }}>
|
|
156
|
+
<div style={{ width: '100%', height: '100%', overflowY: 'auto', overflowX: 'hidden', paddingRight: 4 }}>
|
|
157
|
+
<AssetListViewer
|
|
158
|
+
files={files}
|
|
159
|
+
selected={selected}
|
|
160
|
+
onSelect={onSelect}
|
|
161
|
+
renderCard={(file, onSelectHandler) => (
|
|
162
|
+
<TextureCard file={file} basePath={basePath} onSelect={onSelectHandler} />
|
|
163
|
+
)}
|
|
164
|
+
/>
|
|
165
|
+
</div>
|
|
152
166
|
<SharedCanvas />
|
|
153
|
-
|
|
167
|
+
</div>
|
|
154
168
|
);
|
|
155
169
|
}
|
|
156
170
|
|
|
@@ -175,7 +189,7 @@ function TextureCard({ file, onSelect, basePath = "" }: { file: string; onSelect
|
|
|
175
189
|
return (
|
|
176
190
|
<div
|
|
177
191
|
ref={ref}
|
|
178
|
-
style={{ maxWidth: 60, aspectRatio: '1 / 1', backgroundColor: '#1f2937', cursor: 'pointer', display: 'flex', flexDirection: 'column' }}
|
|
192
|
+
style={{ maxWidth: 60, aspectRatio: '1 / 1', backgroundColor: '#1f2937', color: '#f9fafb', cursor: 'pointer', display: 'flex', flexDirection: 'column' }}
|
|
179
193
|
onClick={() => onSelect(file)}
|
|
180
194
|
onMouseEnter={() => setIsHovered(true)}
|
|
181
195
|
onMouseLeave={() => setIsHovered(false)}
|
|
@@ -184,21 +198,19 @@ function TextureCard({ file, onSelect, basePath = "" }: { file: string; onSelect
|
|
|
184
198
|
{isInView ? (
|
|
185
199
|
<View style={{ width: '100%', height: '100%' }}>
|
|
186
200
|
<PerspectiveCamera makeDefault position={[0, 0, 2.5]} fov={50} />
|
|
187
|
-
<
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
/>
|
|
197
|
-
</Suspense>
|
|
201
|
+
<ambientLight intensity={0.8} />
|
|
202
|
+
<pointLight position={[5, 5, 5]} intensity={0.5} />
|
|
203
|
+
<TextureSphere url={fullPath} onError={() => setError(true)} />
|
|
204
|
+
<OrbitControls
|
|
205
|
+
enableZoom={false}
|
|
206
|
+
enablePan={false}
|
|
207
|
+
autoRotate={isHovered}
|
|
208
|
+
autoRotateSpeed={2}
|
|
209
|
+
/>
|
|
198
210
|
</View>
|
|
199
211
|
) : null}
|
|
200
212
|
</div>
|
|
201
|
-
<div style={
|
|
213
|
+
<div style={styles.bottomLabel}>
|
|
202
214
|
{file.split('/').pop()}
|
|
203
215
|
</div>
|
|
204
216
|
</div>
|
|
@@ -206,10 +218,23 @@ function TextureCard({ file, onSelect, basePath = "" }: { file: string; onSelect
|
|
|
206
218
|
}
|
|
207
219
|
|
|
208
220
|
function TextureSphere({ url, onError }: { url: string; onError?: () => void }) {
|
|
209
|
-
const texture
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
221
|
+
const [texture, setTexture] = useState<any>(null);
|
|
222
|
+
|
|
223
|
+
useEffect(() => {
|
|
224
|
+
setTexture(null);
|
|
225
|
+
const loader = new TextureLoader();
|
|
226
|
+
loader.load(
|
|
227
|
+
url,
|
|
228
|
+
(tex) => setTexture(tex),
|
|
229
|
+
undefined,
|
|
230
|
+
(err) => {
|
|
231
|
+
console.warn('Failed to load texture:', url, err);
|
|
232
|
+
onError?.();
|
|
233
|
+
}
|
|
234
|
+
);
|
|
235
|
+
}, [url]);
|
|
236
|
+
|
|
237
|
+
if (!texture) return null;
|
|
213
238
|
return (
|
|
214
239
|
<mesh position={[0, 0, 0]}>
|
|
215
240
|
<sphereGeometry args={[1, 32, 32]} />
|
|
@@ -227,17 +252,19 @@ interface ModelListViewerProps {
|
|
|
227
252
|
|
|
228
253
|
export function ModelListViewer({ files, selected, onSelect, basePath = "" }: ModelListViewerProps) {
|
|
229
254
|
return (
|
|
230
|
-
|
|
231
|
-
<
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
255
|
+
<div style={{ position: 'relative', width: '100%', height: '100%' }}>
|
|
256
|
+
<div style={{ width: '100%', height: '100%', overflowY: 'auto', overflowX: 'hidden', paddingRight: 4 }}>
|
|
257
|
+
<AssetListViewer
|
|
258
|
+
files={files}
|
|
259
|
+
selected={selected}
|
|
260
|
+
onSelect={onSelect}
|
|
261
|
+
renderCard={(file, onSelectHandler) => (
|
|
262
|
+
<ModelCard file={file} basePath={basePath} onSelect={onSelectHandler} />
|
|
263
|
+
)}
|
|
264
|
+
/>
|
|
265
|
+
</div>
|
|
239
266
|
<SharedCanvas />
|
|
240
|
-
|
|
267
|
+
</div>
|
|
241
268
|
);
|
|
242
269
|
}
|
|
243
270
|
|
|
@@ -261,7 +288,7 @@ function ModelCard({ file, onSelect, basePath = "" }: { file: string; onSelect:
|
|
|
261
288
|
return (
|
|
262
289
|
<div
|
|
263
290
|
ref={ref}
|
|
264
|
-
style={{ maxWidth: 60, aspectRatio: '1 / 1', backgroundColor: '#111827', cursor: 'pointer', display: 'flex', flexDirection: 'column' }}
|
|
291
|
+
style={{ maxWidth: 60, aspectRatio: '1 / 1', backgroundColor: '#111827', color: '#f9fafb', cursor: 'pointer', display: 'flex', flexDirection: 'column' }}
|
|
265
292
|
onClick={() => onSelect(file)}
|
|
266
293
|
>
|
|
267
294
|
<div style={styles.flexFillRelative}>
|
|
@@ -277,7 +304,7 @@ function ModelCard({ file, onSelect, basePath = "" }: { file: string; onSelect:
|
|
|
277
304
|
</View>
|
|
278
305
|
) : null}
|
|
279
306
|
</div>
|
|
280
|
-
<div style={
|
|
307
|
+
<div style={styles.bottomLabel}>
|
|
281
308
|
{file.split('/').pop()}
|
|
282
309
|
</div>
|
|
283
310
|
</div>
|
|
@@ -335,10 +362,10 @@ function SoundCard({ file, onSelect, basePath = "" }: { file: string; onSelect:
|
|
|
335
362
|
return (
|
|
336
363
|
<div
|
|
337
364
|
onClick={() => onSelect(file)}
|
|
338
|
-
style={{ aspectRatio: '1 / 1', backgroundColor: '#374151', cursor: 'pointer', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}
|
|
365
|
+
style={{ aspectRatio: '1 / 1', backgroundColor: '#374151', color: '#f9fafb', cursor: 'pointer', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}
|
|
339
366
|
>
|
|
340
367
|
<div style={styles.iconLarge}>🔊</div>
|
|
341
|
-
<div style={{ fontSize: 12, padding: '0 4px', marginTop: 4, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', textAlign: 'center', width: '100%' }}>{fileName}</div>
|
|
368
|
+
<div style={{ color: '#f9fafb', fontSize: 12, padding: '0 4px', marginTop: 4, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', textAlign: 'center', width: '100%' }}>{fileName}</div>
|
|
342
369
|
</div>
|
|
343
370
|
);
|
|
344
371
|
}
|
|
@@ -375,7 +402,11 @@ export function SharedCanvas() {
|
|
|
375
402
|
<Canvas
|
|
376
403
|
shadows
|
|
377
404
|
dpr={[1, 1.5]}
|
|
405
|
+
gl={{ alpha: true }}
|
|
378
406
|
camera={{ position: [0, 0, 3], fov: 45, near: 0.1, far: 1000 }}
|
|
407
|
+
onCreated={({ gl }) => {
|
|
408
|
+
gl.setClearAlpha(0);
|
|
409
|
+
}}
|
|
379
410
|
style={{
|
|
380
411
|
position: 'fixed',
|
|
381
412
|
top: 0,
|
|
@@ -383,6 +414,7 @@ export function SharedCanvas() {
|
|
|
383
414
|
width: '100vw',
|
|
384
415
|
height: '100vh',
|
|
385
416
|
pointerEvents: 'none',
|
|
417
|
+
background: 'transparent',
|
|
386
418
|
}}
|
|
387
419
|
eventSource={typeof document !== 'undefined' ? document.getElementById('root') || undefined : undefined}
|
|
388
420
|
eventPrefix="client"
|