@nice2dev/ui-3d 1.0.3 → 1.0.5
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/cjs/core/i18n.js +3 -3
- package/dist/cjs/dance/DanceBridge.js +13 -13
- package/dist/cjs/dance/DanceScoreEngine.js +8 -8
- package/dist/cjs/dance/PoseDetector.js +20 -20
- package/dist/cjs/material/NiceMaterialEditor.js +19 -19
- package/dist/cjs/model/ModelEditorLeftPanel.js +3 -3
- package/dist/cjs/model/ModelEditorMenuBar.js +2 -2
- package/dist/cjs/model/ModelEditorRightPanel.js +2 -2
- package/dist/cjs/model/ModelEditorSubComponents.js +3 -3
- package/dist/cjs/model/ModelEditorTimeline.js +3 -3
- package/dist/cjs/model/ModelEditorToolbar.js +2 -2
- package/dist/cjs/model/ModelEditorViewport.js +2 -2
- package/dist/cjs/model/ModelViewer.js +8 -8
- package/dist/cjs/model/NiceArmatureEditor.js +18 -18
- package/dist/cjs/model/NiceMorphTargetEditor.js +18 -18
- package/dist/cjs/model/NiceOctree.js +16 -16
- package/dist/cjs/model/NicePhysicsSimulation.js +24 -24
- package/dist/cjs/model/NiceProceduralGeometry.js +8 -8
- package/dist/cjs/model/NiceTerrainEditor.js +19 -19
- package/dist/cjs/model/NiceWeightPainter.js +14 -14
- package/dist/cjs/model/NiceXRPreview.js +18 -18
- package/dist/cjs/model/useModelEditor.js +127 -127
- package/dist/cjs/model/useModelViewer.js +61 -61
- package/dist/cjs/particle/NiceParticleEditor.js +11 -11
- package/dist/cjs/rendering/NiceCascadedShadows.js +12 -12
- package/dist/cjs/rendering/NiceRenderExport.js +5 -5
- package/dist/cjs/rendering/NiceSSAO.js +18 -18
- package/dist/cjs/rendering/NiceSSR.js +14 -14
- package/dist/cjs/rendering/NiceWebGPURenderer.js +21 -21
- package/dist/cjs/ui/dist/index.js +47227 -31319
- package/dist/cjs/ui/dist/index.js.map +1 -1
- package/dist/cjs/uv/NiceUVEditor.js +24 -24
- package/dist/esm/model/ModelEditorLeftPanel.js +5 -5
- package/dist/esm/model/ModelEditorMenuBar.js +5 -5
- package/dist/esm/model/ModelEditorRightPanel.js +17 -17
- package/dist/esm/model/ModelEditorSubComponents.js +6 -6
- package/dist/esm/model/ModelEditorTimeline.js +5 -5
- package/dist/esm/model/ModelEditorToolbar.js +4 -4
- package/dist/esm/model/ModelEditorViewport.js +2 -2
- package/dist/esm/model/ModelViewer.js +5 -5
- package/dist/esm/ui/dist/index.js +36901 -21016
- package/dist/esm/ui/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var THREE = require('three');
|
|
5
|
-
var
|
|
5
|
+
var Ue = require('react');
|
|
6
6
|
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
8
8
|
var n = Object.create(null);
|
|
@@ -24,12 +24,12 @@ function _interopNamespaceDefault(e) {
|
|
|
24
24
|
var THREE__namespace = /*#__PURE__*/_interopNamespaceDefault(THREE);
|
|
25
25
|
|
|
26
26
|
function useArmatureEditor(skeleton, scene, onBoneSelect) {
|
|
27
|
-
const [bones, setBones] =
|
|
28
|
-
const [selectedBoneId, setSelectedBoneId] =
|
|
29
|
-
const [savedPoses, setSavedPoses] =
|
|
30
|
-
const helperRef =
|
|
27
|
+
const [bones, setBones] = Ue.useState([]);
|
|
28
|
+
const [selectedBoneId, setSelectedBoneId] = Ue.useState(null);
|
|
29
|
+
const [savedPoses, setSavedPoses] = Ue.useState([]);
|
|
30
|
+
const helperRef = Ue.useRef(null);
|
|
31
31
|
// Build bone info tree from skeleton
|
|
32
|
-
|
|
32
|
+
Ue.useEffect(() => {
|
|
33
33
|
if (!skeleton) {
|
|
34
34
|
setBones([]);
|
|
35
35
|
return;
|
|
@@ -52,7 +52,7 @@ function useArmatureEditor(skeleton, scene, onBoneSelect) {
|
|
|
52
52
|
setBones(boneInfos);
|
|
53
53
|
}, [skeleton]);
|
|
54
54
|
// Create skeleton helper for visualization
|
|
55
|
-
|
|
55
|
+
Ue.useEffect(() => {
|
|
56
56
|
var _a;
|
|
57
57
|
if (!skeleton || !scene)
|
|
58
58
|
return;
|
|
@@ -69,12 +69,12 @@ function useArmatureEditor(skeleton, scene, onBoneSelect) {
|
|
|
69
69
|
helperRef.current = null;
|
|
70
70
|
};
|
|
71
71
|
}, [skeleton, scene]);
|
|
72
|
-
const selectBone =
|
|
72
|
+
const selectBone = Ue.useCallback((id) => {
|
|
73
73
|
setSelectedBoneId(id);
|
|
74
74
|
const bone = id ? (skeleton === null || skeleton === void 0 ? void 0 : skeleton.bones.find((b) => b.uuid === id)) || null : null;
|
|
75
75
|
onBoneSelect === null || onBoneSelect === void 0 ? void 0 : onBoneSelect(bone);
|
|
76
76
|
}, [skeleton, onBoneSelect]);
|
|
77
|
-
const setBonePosition =
|
|
77
|
+
const setBonePosition = Ue.useCallback((id, pos) => {
|
|
78
78
|
const bone = skeleton === null || skeleton === void 0 ? void 0 : skeleton.bones.find((b) => b.uuid === id);
|
|
79
79
|
if (bone) {
|
|
80
80
|
bone.position.copy(pos);
|
|
@@ -82,7 +82,7 @@ function useArmatureEditor(skeleton, scene, onBoneSelect) {
|
|
|
82
82
|
setBones((prev) => prev.map((b) => (b.id === id ? { ...b, localPosition: pos.clone() } : b)));
|
|
83
83
|
}
|
|
84
84
|
}, [skeleton]);
|
|
85
|
-
const setBoneRotation =
|
|
85
|
+
const setBoneRotation = Ue.useCallback((id, rot) => {
|
|
86
86
|
const bone = skeleton === null || skeleton === void 0 ? void 0 : skeleton.bones.find((b) => b.uuid === id);
|
|
87
87
|
if (bone) {
|
|
88
88
|
bone.rotation.copy(rot);
|
|
@@ -90,7 +90,7 @@ function useArmatureEditor(skeleton, scene, onBoneSelect) {
|
|
|
90
90
|
setBones((prev) => prev.map((b) => (b.id === id ? { ...b, localRotation: rot.clone() } : b)));
|
|
91
91
|
}
|
|
92
92
|
}, [skeleton]);
|
|
93
|
-
const addBone =
|
|
93
|
+
const addBone = Ue.useCallback((parentId, name) => {
|
|
94
94
|
const parent = skeleton === null || skeleton === void 0 ? void 0 : skeleton.bones.find((b) => b.uuid === parentId);
|
|
95
95
|
const newBone = new THREE__namespace.Bone();
|
|
96
96
|
newBone.name = name;
|
|
@@ -119,7 +119,7 @@ function useArmatureEditor(skeleton, scene, onBoneSelect) {
|
|
|
119
119
|
]);
|
|
120
120
|
return newBone;
|
|
121
121
|
}, [skeleton]);
|
|
122
|
-
const removeBone =
|
|
122
|
+
const removeBone = Ue.useCallback((id) => {
|
|
123
123
|
const bone = skeleton === null || skeleton === void 0 ? void 0 : skeleton.bones.find((b) => b.uuid === id);
|
|
124
124
|
if (!bone)
|
|
125
125
|
return;
|
|
@@ -139,7 +139,7 @@ function useArmatureEditor(skeleton, scene, onBoneSelect) {
|
|
|
139
139
|
if (selectedBoneId === id)
|
|
140
140
|
setSelectedBoneId(null);
|
|
141
141
|
}, [skeleton, selectedBoneId]);
|
|
142
|
-
const savePose =
|
|
142
|
+
const savePose = Ue.useCallback((name) => {
|
|
143
143
|
const transforms = new Map();
|
|
144
144
|
if (skeleton) {
|
|
145
145
|
for (const bone of skeleton.bones) {
|
|
@@ -159,7 +159,7 @@ function useArmatureEditor(skeleton, scene, onBoneSelect) {
|
|
|
159
159
|
setSavedPoses((prev) => [...prev, pose]);
|
|
160
160
|
return pose;
|
|
161
161
|
}, [skeleton]);
|
|
162
|
-
const loadPose =
|
|
162
|
+
const loadPose = Ue.useCallback((pose) => {
|
|
163
163
|
if (!skeleton)
|
|
164
164
|
return;
|
|
165
165
|
for (const bone of skeleton.bones) {
|
|
@@ -178,7 +178,7 @@ function useArmatureEditor(skeleton, scene, onBoneSelect) {
|
|
|
178
178
|
localScale: b.bone.scale.clone(),
|
|
179
179
|
})));
|
|
180
180
|
}, [skeleton]);
|
|
181
|
-
const resetPose =
|
|
181
|
+
const resetPose = Ue.useCallback(() => {
|
|
182
182
|
if (!skeleton)
|
|
183
183
|
return;
|
|
184
184
|
for (const bone of skeleton.bones) {
|
|
@@ -216,9 +216,9 @@ function useArmatureEditor(skeleton, scene, onBoneSelect) {
|
|
|
216
216
|
/* ── Component ── */
|
|
217
217
|
const NiceArmatureEditor = ({ skeleton, skinnedMesh, scene, camera, onBoneSelect, onPoseChange, className = '', }) => {
|
|
218
218
|
const { bones, selectedBoneId, selectBone, setBonePosition, setBoneRotation, addBone, removeBone, savePose, loadPose, resetPose, savedPoses, skeletonHelper, } = useArmatureEditor(skeleton, scene, onBoneSelect);
|
|
219
|
-
const [newBoneName, setNewBoneName] =
|
|
220
|
-
const selectedBone =
|
|
221
|
-
const rootBones =
|
|
219
|
+
const [newBoneName, setNewBoneName] = Ue.useState('');
|
|
220
|
+
const selectedBone = Ue.useMemo(() => bones.find((b) => b.id === selectedBoneId), [bones, selectedBoneId]);
|
|
221
|
+
const rootBones = Ue.useMemo(() => bones.filter((b) => !b.parentId), [bones]);
|
|
222
222
|
const renderBoneTree = (boneInfo, depth = 0) => {
|
|
223
223
|
const isSelected = boneInfo.id === selectedBoneId;
|
|
224
224
|
const childBones = bones.filter((b) => b.parentId === boneInfo.id);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var THREE = require('three');
|
|
5
|
-
var
|
|
5
|
+
var Ue = require('react');
|
|
6
6
|
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
8
8
|
var n = Object.create(null);
|
|
@@ -25,14 +25,14 @@ var THREE__namespace = /*#__PURE__*/_interopNamespaceDefault(THREE);
|
|
|
25
25
|
|
|
26
26
|
/* ── Hook ── */
|
|
27
27
|
function useMorphTargetEditor(mesh, onInfluenceChange) {
|
|
28
|
-
const [targets, setTargets] =
|
|
29
|
-
const [animations, setAnimations] =
|
|
30
|
-
const [isAnimating, setIsAnimating] =
|
|
31
|
-
const animFrameRef =
|
|
32
|
-
const animStartRef =
|
|
33
|
-
const activeAnimRef =
|
|
28
|
+
const [targets, setTargets] = Ue.useState([]);
|
|
29
|
+
const [animations, setAnimations] = Ue.useState([]);
|
|
30
|
+
const [isAnimating, setIsAnimating] = Ue.useState(false);
|
|
31
|
+
const animFrameRef = Ue.useRef(0);
|
|
32
|
+
const animStartRef = Ue.useRef(0);
|
|
33
|
+
const activeAnimRef = Ue.useRef(null);
|
|
34
34
|
// Sync targets from mesh
|
|
35
|
-
|
|
35
|
+
Ue.useEffect(() => {
|
|
36
36
|
if (!mesh || !mesh.morphTargetDictionary || !mesh.morphTargetInfluences) {
|
|
37
37
|
setTargets([]);
|
|
38
38
|
return;
|
|
@@ -50,14 +50,14 @@ function useMorphTargetEditor(mesh, onInfluenceChange) {
|
|
|
50
50
|
list.sort((a, b) => a.index - b.index);
|
|
51
51
|
setTargets(list);
|
|
52
52
|
}, [mesh]);
|
|
53
|
-
const setInfluence =
|
|
53
|
+
const setInfluence = Ue.useCallback((index, value) => {
|
|
54
54
|
if (!(mesh === null || mesh === void 0 ? void 0 : mesh.morphTargetInfluences))
|
|
55
55
|
return;
|
|
56
56
|
mesh.morphTargetInfluences[index] = value;
|
|
57
57
|
setTargets((prev) => prev.map((t) => (t.index === index ? { ...t, influence: value } : t)));
|
|
58
58
|
onInfluenceChange === null || onInfluenceChange === void 0 ? void 0 : onInfluenceChange(mesh, index, value);
|
|
59
59
|
}, [mesh, onInfluenceChange]);
|
|
60
|
-
const createMorphTarget =
|
|
60
|
+
const createMorphTarget = Ue.useCallback((name) => {
|
|
61
61
|
if (!mesh)
|
|
62
62
|
return;
|
|
63
63
|
const geometry = mesh.geometry;
|
|
@@ -87,7 +87,7 @@ function useMorphTargetEditor(mesh, onInfluenceChange) {
|
|
|
87
87
|
mesh.updateMorphTargets();
|
|
88
88
|
setTargets((prev) => [...prev, { name, index: newIndex, influence: 0 }]);
|
|
89
89
|
}, [mesh]);
|
|
90
|
-
const deleteMorphTarget =
|
|
90
|
+
const deleteMorphTarget = Ue.useCallback((index) => {
|
|
91
91
|
if (!mesh)
|
|
92
92
|
return;
|
|
93
93
|
const geometry = mesh.geometry;
|
|
@@ -111,13 +111,13 @@ function useMorphTargetEditor(mesh, onInfluenceChange) {
|
|
|
111
111
|
influence: influences[idx],
|
|
112
112
|
})));
|
|
113
113
|
}, [mesh]);
|
|
114
|
-
const resetAllInfluences =
|
|
114
|
+
const resetAllInfluences = Ue.useCallback(() => {
|
|
115
115
|
if (!(mesh === null || mesh === void 0 ? void 0 : mesh.morphTargetInfluences))
|
|
116
116
|
return;
|
|
117
117
|
mesh.morphTargetInfluences.fill(0);
|
|
118
118
|
setTargets((prev) => prev.map((t) => ({ ...t, influence: 0 })));
|
|
119
119
|
}, [mesh]);
|
|
120
|
-
const startAnimation =
|
|
120
|
+
const startAnimation = Ue.useCallback((animation) => {
|
|
121
121
|
if (!(mesh === null || mesh === void 0 ? void 0 : mesh.morphTargetInfluences))
|
|
122
122
|
return;
|
|
123
123
|
activeAnimRef.current = animation;
|
|
@@ -159,18 +159,18 @@ function useMorphTargetEditor(mesh, onInfluenceChange) {
|
|
|
159
159
|
};
|
|
160
160
|
animFrameRef.current = requestAnimationFrame(animate);
|
|
161
161
|
}, [mesh]);
|
|
162
|
-
const stopAnimation =
|
|
162
|
+
const stopAnimation = Ue.useCallback(() => {
|
|
163
163
|
activeAnimRef.current = null;
|
|
164
164
|
setIsAnimating(false);
|
|
165
165
|
cancelAnimationFrame(animFrameRef.current);
|
|
166
166
|
}, []);
|
|
167
|
-
|
|
167
|
+
Ue.useEffect(() => {
|
|
168
168
|
return () => cancelAnimationFrame(animFrameRef.current);
|
|
169
169
|
}, []);
|
|
170
|
-
const addAnimation =
|
|
170
|
+
const addAnimation = Ue.useCallback((animation) => {
|
|
171
171
|
setAnimations((prev) => [...prev, animation]);
|
|
172
172
|
}, []);
|
|
173
|
-
const removeAnimation =
|
|
173
|
+
const removeAnimation = Ue.useCallback((name) => {
|
|
174
174
|
setAnimations((prev) => prev.filter((a) => a.name !== name));
|
|
175
175
|
}, []);
|
|
176
176
|
return {
|
|
@@ -190,7 +190,7 @@ function useMorphTargetEditor(mesh, onInfluenceChange) {
|
|
|
190
190
|
/* ── Component ── */
|
|
191
191
|
const NiceMorphTargetEditor = ({ mesh, onInfluenceChange, className = '', }) => {
|
|
192
192
|
const { targets, setInfluence, createMorphTarget, deleteMorphTarget, resetAllInfluences, isAnimating, startAnimation, stopAnimation, animations, addAnimation, removeAnimation, } = useMorphTargetEditor(mesh, onInfluenceChange);
|
|
193
|
-
const [newName, setNewName] =
|
|
193
|
+
const [newName, setNewName] = Ue.useState('');
|
|
194
194
|
const handleCreate = () => {
|
|
195
195
|
const name = newName.trim();
|
|
196
196
|
if (!name)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var THREE = require('three');
|
|
5
|
-
var
|
|
5
|
+
var Ue = require('react');
|
|
6
6
|
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
8
8
|
var n = Object.create(null);
|
|
@@ -208,12 +208,12 @@ function buildDebugVisualization(node, group, maxDepth) {
|
|
|
208
208
|
}
|
|
209
209
|
/* ── Hook ── */
|
|
210
210
|
function useOctree(scene, configOverride) {
|
|
211
|
-
const config =
|
|
212
|
-
const [root, setRoot] =
|
|
213
|
-
const [showDebug, setShowDebug] =
|
|
214
|
-
const [stats, setStats] =
|
|
215
|
-
const debugGroup =
|
|
216
|
-
|
|
211
|
+
const config = Ue.useMemo(() => ({ ...DEFAULT_CONFIG, ...configOverride }), [configOverride]);
|
|
212
|
+
const [root, setRoot] = Ue.useState(null);
|
|
213
|
+
const [showDebug, setShowDebug] = Ue.useState(false);
|
|
214
|
+
const [stats, setStats] = Ue.useState({ nodeCount: 0, objectCount: 0 });
|
|
215
|
+
const debugGroup = Ue.useRef(new THREE__namespace.Group());
|
|
216
|
+
Ue.useEffect(() => {
|
|
217
217
|
if (!scene)
|
|
218
218
|
return;
|
|
219
219
|
debugGroup.current.name = '__octree_debug__';
|
|
@@ -224,7 +224,7 @@ function useOctree(scene, configOverride) {
|
|
|
224
224
|
scene.remove(debugGroup.current);
|
|
225
225
|
};
|
|
226
226
|
}, [scene, showDebug]);
|
|
227
|
-
const refreshDebug =
|
|
227
|
+
const refreshDebug = Ue.useCallback((rootNode) => {
|
|
228
228
|
// Clear existing debug
|
|
229
229
|
while (debugGroup.current.children.length) {
|
|
230
230
|
const child = debugGroup.current.children[0];
|
|
@@ -234,7 +234,7 @@ function useOctree(scene, configOverride) {
|
|
|
234
234
|
buildDebugVisualization(rootNode, debugGroup.current, config.maxDepth);
|
|
235
235
|
}
|
|
236
236
|
}, [showDebug, config.maxDepth]);
|
|
237
|
-
const build =
|
|
237
|
+
const build = Ue.useCallback(() => {
|
|
238
238
|
if (!scene)
|
|
239
239
|
return;
|
|
240
240
|
// Compute scene bounds
|
|
@@ -264,26 +264,26 @@ function useOctree(scene, configOverride) {
|
|
|
264
264
|
setStats({ nodeCount: countNodes(rootNode), objectCount: countObjects(rootNode) });
|
|
265
265
|
refreshDebug(rootNode);
|
|
266
266
|
}, [scene, config, refreshDebug]);
|
|
267
|
-
const insert =
|
|
267
|
+
const insert = Ue.useCallback((object) => {
|
|
268
268
|
if (!root)
|
|
269
269
|
return;
|
|
270
270
|
insertObject(root, object, config);
|
|
271
271
|
setStats({ nodeCount: countNodes(root), objectCount: countObjects(root) });
|
|
272
272
|
refreshDebug(root);
|
|
273
273
|
}, [root, config, refreshDebug]);
|
|
274
|
-
const remove =
|
|
274
|
+
const remove = Ue.useCallback((object) => {
|
|
275
275
|
if (!root)
|
|
276
276
|
return;
|
|
277
277
|
removeObject(root, object);
|
|
278
278
|
setStats({ nodeCount: countNodes(root), objectCount: countObjects(root) });
|
|
279
279
|
}, [root]);
|
|
280
|
-
const update =
|
|
280
|
+
const update = Ue.useCallback((object) => {
|
|
281
281
|
if (!root)
|
|
282
282
|
return;
|
|
283
283
|
removeObject(root, object);
|
|
284
284
|
insertObject(root, object, config);
|
|
285
285
|
}, [root, config]);
|
|
286
|
-
const raycast =
|
|
286
|
+
const raycast = Ue.useCallback((raycaster) => {
|
|
287
287
|
if (!root)
|
|
288
288
|
return [];
|
|
289
289
|
const results = [];
|
|
@@ -291,7 +291,7 @@ function useOctree(scene, configOverride) {
|
|
|
291
291
|
results.sort((a, b) => a.distance - b.distance);
|
|
292
292
|
return results;
|
|
293
293
|
}, [root]);
|
|
294
|
-
const frustumCull =
|
|
294
|
+
const frustumCull = Ue.useCallback((camera) => {
|
|
295
295
|
if (!root)
|
|
296
296
|
return [];
|
|
297
297
|
const frustum = new THREE__namespace.Frustum();
|
|
@@ -302,7 +302,7 @@ function useOctree(scene, configOverride) {
|
|
|
302
302
|
frustumCullNode(root, frustum, results);
|
|
303
303
|
return results;
|
|
304
304
|
}, [root]);
|
|
305
|
-
const nearestNeighbor =
|
|
305
|
+
const nearestNeighbor = Ue.useCallback((point, maxDistance = Infinity) => {
|
|
306
306
|
if (!root)
|
|
307
307
|
return null;
|
|
308
308
|
const best = { object: null, dist: maxDistance };
|
|
@@ -327,7 +327,7 @@ function useOctree(scene, configOverride) {
|
|
|
327
327
|
/* ── Component ── */
|
|
328
328
|
const NiceOctree = ({ scene, config, showDebug: initialShowDebug, className = '', }) => {
|
|
329
329
|
const octree = useOctree(scene, config);
|
|
330
|
-
|
|
330
|
+
Ue.useEffect(() => {
|
|
331
331
|
if (initialShowDebug !== undefined)
|
|
332
332
|
octree.setShowDebug(initialShowDebug);
|
|
333
333
|
}, [initialShowDebug]);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var THREE = require('three');
|
|
5
|
-
var
|
|
5
|
+
var Ue = require('react');
|
|
6
6
|
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
8
8
|
var n = Object.create(null);
|
|
@@ -45,21 +45,21 @@ function computeAABB(object) {
|
|
|
45
45
|
let bodyIdCounter = 0;
|
|
46
46
|
let jointIdCounter = 0;
|
|
47
47
|
function usePhysicsSimulation(scene, onSimulationStep) {
|
|
48
|
-
const [worldConfig, setWorldConfigState] =
|
|
48
|
+
const [worldConfig, setWorldConfigState] = Ue.useState({
|
|
49
49
|
gravity: new THREE__namespace.Vector3(0, -9.81, 0),
|
|
50
50
|
timestep: 1 / 60,
|
|
51
51
|
maxSubsteps: 4,
|
|
52
52
|
});
|
|
53
|
-
const [bodies, setBodies] =
|
|
54
|
-
const [joints, setJoints] =
|
|
55
|
-
const [isRunning, setIsRunning] =
|
|
56
|
-
const [debugDraw, setDebugDraw] =
|
|
57
|
-
const internalBodies =
|
|
58
|
-
const debugGroup =
|
|
59
|
-
const animFrameId =
|
|
60
|
-
const lastTime =
|
|
53
|
+
const [bodies, setBodies] = Ue.useState([]);
|
|
54
|
+
const [joints, setJoints] = Ue.useState([]);
|
|
55
|
+
const [isRunning, setIsRunning] = Ue.useState(false);
|
|
56
|
+
const [debugDraw, setDebugDraw] = Ue.useState(false);
|
|
57
|
+
const internalBodies = Ue.useRef(new Map());
|
|
58
|
+
const debugGroup = Ue.useRef(new THREE__namespace.Group());
|
|
59
|
+
const animFrameId = Ue.useRef(0);
|
|
60
|
+
const lastTime = Ue.useRef(0);
|
|
61
61
|
// Debug wireframe colliders
|
|
62
|
-
|
|
62
|
+
Ue.useEffect(() => {
|
|
63
63
|
if (!scene)
|
|
64
64
|
return;
|
|
65
65
|
debugGroup.current.name = '__physics_debug__';
|
|
@@ -70,10 +70,10 @@ function usePhysicsSimulation(scene, onSimulationStep) {
|
|
|
70
70
|
scene.remove(debugGroup.current);
|
|
71
71
|
};
|
|
72
72
|
}, [scene, debugDraw]);
|
|
73
|
-
const setWorldConfig =
|
|
73
|
+
const setWorldConfig = Ue.useCallback((partial) => {
|
|
74
74
|
setWorldConfigState((prev) => ({ ...prev, ...partial }));
|
|
75
75
|
}, []);
|
|
76
|
-
const addBody =
|
|
76
|
+
const addBody = Ue.useCallback((object) => {
|
|
77
77
|
const id = `phys_${++bodyIdCounter}`;
|
|
78
78
|
const desc = {
|
|
79
79
|
id,
|
|
@@ -105,7 +105,7 @@ function usePhysicsSimulation(scene, onSimulationStep) {
|
|
|
105
105
|
}
|
|
106
106
|
return desc;
|
|
107
107
|
}, [debugDraw]);
|
|
108
|
-
const removeBody =
|
|
108
|
+
const removeBody = Ue.useCallback((id) => {
|
|
109
109
|
internalBodies.current.delete(id);
|
|
110
110
|
setBodies((prev) => prev.filter((b) => b.id !== id));
|
|
111
111
|
// Remove debug wireframe
|
|
@@ -113,23 +113,23 @@ function usePhysicsSimulation(scene, onSimulationStep) {
|
|
|
113
113
|
if (debugObj)
|
|
114
114
|
debugGroup.current.remove(debugObj);
|
|
115
115
|
}, []);
|
|
116
|
-
const updateBody =
|
|
116
|
+
const updateBody = Ue.useCallback((id, partial) => {
|
|
117
117
|
const internal = internalBodies.current.get(id);
|
|
118
118
|
if (internal) {
|
|
119
119
|
Object.assign(internal.desc, partial);
|
|
120
120
|
}
|
|
121
121
|
setBodies((prev) => prev.map((b) => (b.id === id ? { ...b, ...partial } : b)));
|
|
122
122
|
}, []);
|
|
123
|
-
const addJoint =
|
|
123
|
+
const addJoint = Ue.useCallback((joint) => {
|
|
124
124
|
const id = `joint_${++jointIdCounter}`;
|
|
125
125
|
setJoints((prev) => [...prev, { ...joint, id }]);
|
|
126
126
|
}, []);
|
|
127
|
-
const removeJoint =
|
|
127
|
+
const removeJoint = Ue.useCallback((id) => {
|
|
128
128
|
setJoints((prev) => prev.filter((j) => j.id !== id));
|
|
129
129
|
}, []);
|
|
130
|
-
const getBodyForObject =
|
|
130
|
+
const getBodyForObject = Ue.useCallback((objectName) => bodies.find((b) => b.objectName === objectName), [bodies]);
|
|
131
131
|
// Simplified physics step (Euler integration with collision detection)
|
|
132
|
-
const simulationStep =
|
|
132
|
+
const simulationStep = Ue.useCallback((dt) => {
|
|
133
133
|
const gravity = worldConfig.gravity;
|
|
134
134
|
internalBodies.current.forEach((body) => {
|
|
135
135
|
if (body.desc.bodyType !== 'dynamic')
|
|
@@ -196,7 +196,7 @@ function usePhysicsSimulation(scene, onSimulationStep) {
|
|
|
196
196
|
onSimulationStep === null || onSimulationStep === void 0 ? void 0 : onSimulationStep(dt);
|
|
197
197
|
}, [worldConfig.gravity, onSimulationStep]);
|
|
198
198
|
// Animation loop
|
|
199
|
-
|
|
199
|
+
Ue.useEffect(() => {
|
|
200
200
|
if (!isRunning)
|
|
201
201
|
return;
|
|
202
202
|
lastTime.current = performance.now();
|
|
@@ -213,12 +213,12 @@ function usePhysicsSimulation(scene, onSimulationStep) {
|
|
|
213
213
|
animFrameId.current = requestAnimationFrame(loop);
|
|
214
214
|
return () => cancelAnimationFrame(animFrameId.current);
|
|
215
215
|
}, [isRunning, simulationStep, worldConfig.timestep, worldConfig.maxSubsteps]);
|
|
216
|
-
const play =
|
|
217
|
-
const pause =
|
|
218
|
-
const step =
|
|
216
|
+
const play = Ue.useCallback(() => setIsRunning(true), []);
|
|
217
|
+
const pause = Ue.useCallback(() => setIsRunning(false), []);
|
|
218
|
+
const step = Ue.useCallback(() => {
|
|
219
219
|
simulationStep(worldConfig.timestep);
|
|
220
220
|
}, [simulationStep, worldConfig.timestep]);
|
|
221
|
-
const reset =
|
|
221
|
+
const reset = Ue.useCallback(() => {
|
|
222
222
|
setIsRunning(false);
|
|
223
223
|
internalBodies.current.forEach((body) => {
|
|
224
224
|
body.object.position.copy(body.initialPosition);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var THREE = require('three');
|
|
5
|
-
var
|
|
5
|
+
var Ue = require('react');
|
|
6
6
|
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
8
8
|
var n = Object.create(null);
|
|
@@ -213,13 +213,13 @@ const DEFAULT_PIPE = {
|
|
|
213
213
|
};
|
|
214
214
|
const DEFAULT_GEAR = { innerRadius: 0.5, outerRadius: 2, teeth: 12, toothDepth: 0.3, thickness: 0.4 };
|
|
215
215
|
function useProceduralGeometry(scene, onGenerated) {
|
|
216
|
-
const [type, setType] =
|
|
217
|
-
const [treeParams, setTreeParams] =
|
|
218
|
-
const [rockParams, setRockParams] =
|
|
219
|
-
const [buildingParams, setBuildingParams] =
|
|
220
|
-
const [pipeParams, setPipeParams] =
|
|
221
|
-
const [gearParams, setGearParams] =
|
|
222
|
-
const generate =
|
|
216
|
+
const [type, setType] = Ue.useState('tree');
|
|
217
|
+
const [treeParams, setTreeParams] = Ue.useState(DEFAULT_TREE);
|
|
218
|
+
const [rockParams, setRockParams] = Ue.useState(DEFAULT_ROCK);
|
|
219
|
+
const [buildingParams, setBuildingParams] = Ue.useState(DEFAULT_BUILDING);
|
|
220
|
+
const [pipeParams, setPipeParams] = Ue.useState(DEFAULT_PIPE);
|
|
221
|
+
const [gearParams, setGearParams] = Ue.useState(DEFAULT_GEAR);
|
|
222
|
+
const generate = Ue.useCallback(() => {
|
|
223
223
|
if (!scene)
|
|
224
224
|
return;
|
|
225
225
|
let result;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var THREE = require('three');
|
|
5
|
-
var
|
|
5
|
+
var Ue = require('react');
|
|
6
6
|
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
8
8
|
var n = Object.create(null);
|
|
@@ -42,25 +42,25 @@ function fractalNoise(x, z, octaves, persistence, lacunarity, rng) {
|
|
|
42
42
|
}
|
|
43
43
|
/* ── Hook ── */
|
|
44
44
|
function useTerrainEditor(scene, camera, canvas, config = { width: 100, depth: 100, segments: 128, maxHeight: 20 }, onTerrainChange) {
|
|
45
|
-
const [brush, setBrushState] =
|
|
45
|
+
const [brush, setBrushState] = Ue.useState({
|
|
46
46
|
mode: 'raise',
|
|
47
47
|
radius: 5,
|
|
48
48
|
strength: 0.3,
|
|
49
49
|
falloff: 'smooth',
|
|
50
50
|
});
|
|
51
|
-
const [isPainting, setIsPainting] =
|
|
52
|
-
const [textureLayers, setTextureLayers] =
|
|
51
|
+
const [isPainting, setIsPainting] = Ue.useState(false);
|
|
52
|
+
const [textureLayers, setTextureLayers] = Ue.useState([
|
|
53
53
|
{ name: 'Grass', texture: null, scale: 10 },
|
|
54
54
|
{ name: 'Rock', texture: null, scale: 8 },
|
|
55
55
|
{ name: 'Sand', texture: null, scale: 12 },
|
|
56
56
|
{ name: 'Snow', texture: null, scale: 10 },
|
|
57
57
|
]);
|
|
58
|
-
const [activeTextureLayer, setActiveTextureLayer] =
|
|
59
|
-
const terrainRef =
|
|
60
|
-
const splatMapRef =
|
|
61
|
-
const raycaster =
|
|
58
|
+
const [activeTextureLayer, setActiveTextureLayer] = Ue.useState(0);
|
|
59
|
+
const terrainRef = Ue.useRef(null);
|
|
60
|
+
const splatMapRef = Ue.useRef(null);
|
|
61
|
+
const raycaster = Ue.useRef(new THREE__namespace.Raycaster());
|
|
62
62
|
// Create terrain mesh
|
|
63
|
-
|
|
63
|
+
Ue.useEffect(() => {
|
|
64
64
|
if (!scene)
|
|
65
65
|
return;
|
|
66
66
|
const geometry = new THREE__namespace.PlaneGeometry(config.width, config.depth, config.segments, config.segments);
|
|
@@ -90,10 +90,10 @@ function useTerrainEditor(scene, camera, canvas, config = { width: 100, depth: 1
|
|
|
90
90
|
material.dispose();
|
|
91
91
|
};
|
|
92
92
|
}, [scene, config.width, config.depth, config.segments]);
|
|
93
|
-
const setBrush =
|
|
93
|
+
const setBrush = Ue.useCallback((partial) => {
|
|
94
94
|
setBrushState((prev) => ({ ...prev, ...partial }));
|
|
95
95
|
}, []);
|
|
96
|
-
const applyBrushAtPoint =
|
|
96
|
+
const applyBrushAtPoint = Ue.useCallback((point) => {
|
|
97
97
|
const mesh = terrainRef.current;
|
|
98
98
|
if (!mesh)
|
|
99
99
|
return;
|
|
@@ -185,7 +185,7 @@ function useTerrainEditor(scene, camera, canvas, config = { width: 100, depth: 1
|
|
|
185
185
|
onTerrainChange === null || onTerrainChange === void 0 ? void 0 : onTerrainChange(mesh);
|
|
186
186
|
}, [brush, config.segments, activeTextureLayer, onTerrainChange]);
|
|
187
187
|
// Mouse handling
|
|
188
|
-
|
|
188
|
+
Ue.useEffect(() => {
|
|
189
189
|
if (!canvas || !camera || !isPainting)
|
|
190
190
|
return;
|
|
191
191
|
const onPointerMove = (e) => {
|
|
@@ -203,7 +203,7 @@ function useTerrainEditor(scene, camera, canvas, config = { width: 100, depth: 1
|
|
|
203
203
|
canvas.addEventListener('pointermove', onPointerMove);
|
|
204
204
|
return () => canvas.removeEventListener('pointermove', onPointerMove);
|
|
205
205
|
}, [canvas, camera, isPainting, applyBrushAtPoint]);
|
|
206
|
-
const generateFlat =
|
|
206
|
+
const generateFlat = Ue.useCallback(() => {
|
|
207
207
|
const mesh = terrainRef.current;
|
|
208
208
|
if (!mesh)
|
|
209
209
|
return;
|
|
@@ -215,7 +215,7 @@ function useTerrainEditor(scene, camera, canvas, config = { width: 100, depth: 1
|
|
|
215
215
|
mesh.geometry.computeVertexNormals();
|
|
216
216
|
onTerrainChange === null || onTerrainChange === void 0 ? void 0 : onTerrainChange(mesh);
|
|
217
217
|
}, [onTerrainChange]);
|
|
218
|
-
const generateNoise =
|
|
218
|
+
const generateNoise = Ue.useCallback((octaves = 6, persistence = 0.5, lacunarity = 2.0) => {
|
|
219
219
|
const mesh = terrainRef.current;
|
|
220
220
|
if (!mesh)
|
|
221
221
|
return;
|
|
@@ -230,7 +230,7 @@ function useTerrainEditor(scene, camera, canvas, config = { width: 100, depth: 1
|
|
|
230
230
|
mesh.geometry.computeVertexNormals();
|
|
231
231
|
onTerrainChange === null || onTerrainChange === void 0 ? void 0 : onTerrainChange(mesh);
|
|
232
232
|
}, [config, onTerrainChange]);
|
|
233
|
-
const importHeightmap =
|
|
233
|
+
const importHeightmap = Ue.useCallback((image) => {
|
|
234
234
|
const mesh = terrainRef.current;
|
|
235
235
|
if (!mesh)
|
|
236
236
|
return;
|
|
@@ -257,7 +257,7 @@ function useTerrainEditor(scene, camera, canvas, config = { width: 100, depth: 1
|
|
|
257
257
|
mesh.geometry.computeVertexNormals();
|
|
258
258
|
onTerrainChange === null || onTerrainChange === void 0 ? void 0 : onTerrainChange(mesh);
|
|
259
259
|
}, [config, onTerrainChange]);
|
|
260
|
-
const exportHeightmap =
|
|
260
|
+
const exportHeightmap = Ue.useCallback(() => {
|
|
261
261
|
const mesh = terrainRef.current;
|
|
262
262
|
if (!mesh)
|
|
263
263
|
return null;
|
|
@@ -290,7 +290,7 @@ function useTerrainEditor(scene, camera, canvas, config = { width: 100, depth: 1
|
|
|
290
290
|
ctx.putImageData(imageData, 0, 0);
|
|
291
291
|
return exportCanvas;
|
|
292
292
|
}, [config.segments]);
|
|
293
|
-
const setTextureLayer =
|
|
293
|
+
const setTextureLayer = Ue.useCallback((index, partial) => {
|
|
294
294
|
setTextureLayers((prev) => prev.map((l, i) => (i === index ? { ...l, ...partial } : l)));
|
|
295
295
|
}, []);
|
|
296
296
|
return {
|
|
@@ -320,8 +320,8 @@ const NiceTerrainEditor = ({ scene, camera, canvas, config: configProp, onTerrai
|
|
|
320
320
|
...configProp,
|
|
321
321
|
};
|
|
322
322
|
const { brush, setBrush, isPainting, startPainting, stopPainting, generateFlat, generateNoise, exportHeightmap, textureLayers, setTextureLayer, activeTextureLayer, setActiveTextureLayer, } = useTerrainEditor(scene, camera, canvas, config, onTerrainChange);
|
|
323
|
-
const [noiseOctaves, setNoiseOctaves] =
|
|
324
|
-
const [noisePersistence, setNoisePersistence] =
|
|
323
|
+
const [noiseOctaves, setNoiseOctaves] = Ue.useState(6);
|
|
324
|
+
const [noisePersistence, setNoisePersistence] = Ue.useState(0.5);
|
|
325
325
|
return (jsxRuntime.jsxs("div", { className: `nice-terrain-editor ${className}`, style: { display: 'grid', gap: 8, fontSize: 13 }, children: [jsxRuntime.jsx("strong", { children: "Terrain Editor" }), jsxRuntime.jsxs("fieldset", { style: { border: '1px solid var(--border, #e2e8f0)', borderRadius: 6, padding: 4, display: 'flex', flexWrap: 'wrap', gap: 2 }, children: [jsxRuntime.jsx("legend", { style: { fontSize: 11 }, children: "Brush" }), ['raise', 'lower', 'flatten', 'smooth', 'noise', 'paint'].map((m) => (jsxRuntime.jsx("button", { type: "button", onClick: () => setBrush({ mode: m }), style: {
|
|
326
326
|
padding: '3px 6px', fontSize: 11, cursor: 'pointer', borderRadius: 4,
|
|
327
327
|
border: '1px solid var(--border, #e2e8f0)',
|