@nice2dev/ui-3d 1.3.15 → 1.3.16

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.
Files changed (108) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/collaborative/collaborativeScene.js +160 -206
  3. package/dist/cjs/core/editorAsk.js +51 -41
  4. package/dist/cjs/core/i18n.js +13 -14
  5. package/dist/cjs/core/threeCompat.js +29 -42
  6. package/dist/cjs/dance/DanceBridge.js +148 -177
  7. package/dist/cjs/dance/DanceScoreEngine.js +209 -221
  8. package/dist/cjs/dance/PoseDetector.js +302 -275
  9. package/dist/cjs/index.js +110 -113
  10. package/dist/cjs/material/MaterialEditor.module.css.js +242 -5
  11. package/dist/cjs/material/NiceMaterialEditor.js +1213 -757
  12. package/dist/cjs/material/materialEditorTypes.js +35 -49
  13. package/dist/cjs/material/materialEditorUtils.js +684 -747
  14. package/dist/cjs/material/materialNodeDefinitions.js +1411 -1459
  15. package/dist/cjs/model/ModelEditor.js +90 -40
  16. package/dist/cjs/model/ModelEditor.module.css.js +257 -5
  17. package/dist/cjs/model/ModelEditorLeftPanel.js +126 -47
  18. package/dist/cjs/model/ModelEditorMenuBar.js +359 -32
  19. package/dist/cjs/model/ModelEditorRightPanel.js +647 -131
  20. package/dist/cjs/model/ModelEditorSubComponents.js +277 -112
  21. package/dist/cjs/model/ModelEditorTimeline.js +232 -34
  22. package/dist/cjs/model/ModelEditorToolbar.js +170 -14
  23. package/dist/cjs/model/ModelEditorViewport.js +231 -39
  24. package/dist/cjs/model/ModelViewer.js +388 -63
  25. package/dist/cjs/model/ModelViewer.module.css.js +77 -5
  26. package/dist/cjs/model/NiceArmatureEditor.js +473 -274
  27. package/dist/cjs/model/NiceMorphTargetEditor.js +333 -227
  28. package/dist/cjs/model/NiceOctree.js +372 -320
  29. package/dist/cjs/model/NicePhysicsSimulation.js +528 -298
  30. package/dist/cjs/model/NiceProceduralGeometry.js +673 -300
  31. package/dist/cjs/model/NiceTerrainEditor.js +595 -385
  32. package/dist/cjs/model/NiceWeightPainter.js +384 -261
  33. package/dist/cjs/model/NiceXRPreview.js +385 -308
  34. package/dist/cjs/model/cadModeUtils.js +103 -106
  35. package/dist/cjs/model/editorShortcuts.js +171 -194
  36. package/dist/cjs/model/modelEditorTypes.js +100 -118
  37. package/dist/cjs/model/modelEditorUtils.js +1061 -1146
  38. package/dist/cjs/model/simsModeUtils.js +1023 -1053
  39. package/dist/cjs/model/useModelEditor.js +1977 -1933
  40. package/dist/cjs/model/useModelViewer.js +633 -665
  41. package/dist/cjs/nice2dev-ui-3d.css +1 -1
  42. package/dist/cjs/particle/NiceParticleEditor.js +1186 -571
  43. package/dist/cjs/particle/ParticleEditor.module.css.js +122 -5
  44. package/dist/cjs/particle/particleEditorTypes.js +62 -70
  45. package/dist/cjs/particle/particleEditorUtils.js +998 -1013
  46. package/dist/cjs/rendering/NiceCascadedShadows.js +381 -259
  47. package/dist/cjs/rendering/NiceRenderExport.js +424 -337
  48. package/dist/cjs/rendering/NiceSSAO.js +454 -337
  49. package/dist/cjs/rendering/NiceSSR.js +387 -261
  50. package/dist/cjs/rendering/NiceWebGPURenderer.js +359 -230
  51. package/dist/cjs/uv/NiceUVEditor.js +787 -550
  52. package/dist/cjs/uv/UVEditor.module.css.js +53 -5
  53. package/dist/cjs/uv/uvEditorTypes.js +59 -76
  54. package/dist/cjs/uv/uvEditorUtils.js +501 -575
  55. package/dist/esm/collaborative/collaborativeScene.js +163 -205
  56. package/dist/esm/core/editorAsk.js +53 -40
  57. package/dist/esm/core/i18n.js +15 -13
  58. package/dist/esm/core/threeCompat.js +18 -26
  59. package/dist/esm/dance/DanceBridge.js +151 -176
  60. package/dist/esm/dance/DanceScoreEngine.js +211 -220
  61. package/dist/esm/dance/PoseDetector.js +304 -274
  62. package/dist/esm/index.js +258 -36
  63. package/dist/esm/material/MaterialEditor.module.css.js +242 -3
  64. package/dist/esm/material/NiceMaterialEditor.js +1215 -756
  65. package/dist/esm/material/materialEditorTypes.js +45 -48
  66. package/dist/esm/material/materialEditorUtils.js +713 -746
  67. package/dist/esm/material/materialNodeDefinitions.js +1415 -1458
  68. package/dist/esm/model/ModelEditor.js +91 -39
  69. package/dist/esm/model/ModelEditor.module.css.js +257 -3
  70. package/dist/esm/model/ModelEditorLeftPanel.js +126 -45
  71. package/dist/esm/model/ModelEditorMenuBar.js +359 -30
  72. package/dist/esm/model/ModelEditorRightPanel.js +634 -114
  73. package/dist/esm/model/ModelEditorSubComponents.js +265 -94
  74. package/dist/esm/model/ModelEditorTimeline.js +232 -32
  75. package/dist/esm/model/ModelEditorToolbar.js +170 -12
  76. package/dist/esm/model/ModelEditorViewport.js +231 -37
  77. package/dist/esm/model/ModelViewer.js +389 -62
  78. package/dist/esm/model/ModelViewer.module.css.js +77 -3
  79. package/dist/esm/model/NiceArmatureEditor.js +462 -258
  80. package/dist/esm/model/NiceMorphTargetEditor.js +322 -211
  81. package/dist/esm/model/NiceOctree.js +361 -304
  82. package/dist/esm/model/NicePhysicsSimulation.js +517 -282
  83. package/dist/esm/model/NiceProceduralGeometry.js +667 -284
  84. package/dist/esm/model/NiceTerrainEditor.js +584 -369
  85. package/dist/esm/model/NiceWeightPainter.js +373 -245
  86. package/dist/esm/model/NiceXRPreview.js +374 -292
  87. package/dist/esm/model/cadModeUtils.js +95 -88
  88. package/dist/esm/model/editorShortcuts.js +172 -193
  89. package/dist/esm/model/modelEditorTypes.js +90 -100
  90. package/dist/esm/model/modelEditorUtils.js +1056 -1128
  91. package/dist/esm/model/simsModeUtils.js +1021 -1035
  92. package/dist/esm/model/useModelEditor.js +1946 -1920
  93. package/dist/esm/model/useModelViewer.js +619 -647
  94. package/dist/esm/nice2dev-ui-3d.css +1 -1
  95. package/dist/esm/particle/NiceParticleEditor.js +1188 -570
  96. package/dist/esm/particle/ParticleEditor.module.css.js +122 -3
  97. package/dist/esm/particle/particleEditorTypes.js +69 -69
  98. package/dist/esm/particle/particleEditorUtils.js +1027 -1012
  99. package/dist/esm/rendering/NiceCascadedShadows.js +370 -243
  100. package/dist/esm/rendering/NiceRenderExport.js +413 -321
  101. package/dist/esm/rendering/NiceSSAO.js +450 -328
  102. package/dist/esm/rendering/NiceSSR.js +383 -252
  103. package/dist/esm/rendering/NiceWebGPURenderer.js +326 -214
  104. package/dist/esm/uv/NiceUVEditor.js +788 -549
  105. package/dist/esm/uv/UVEditor.module.css.js +53 -3
  106. package/dist/esm/uv/uvEditorTypes.js +68 -75
  107. package/dist/esm/uv/uvEditorUtils.js +515 -557
  108. package/package.json +7 -12
@@ -1,220 +1,331 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { NiceTutorialButton, resolveTutorial, NiceIcon } from '@nice2dev/ui';
3
- import { useState, useRef, useEffect, useCallback } from 'react';
4
- import * as THREE from 'three';
5
- import { useNiceTranslation } from '../core/i18n.js';
6
-
7
- /** Built-in guided tour (EN inline + i18n keys → PL and other locales). */
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { NiceTutorialButton, resolveTutorial, NiceIcon } from "@nice2dev/ui";
3
+ import { useState, useRef, useEffect, useCallback } from "react";
4
+ import * as THREE from "three";
5
+ import { useNiceTranslation } from "../core/i18n.js";
8
6
  const MORPH_TARGET_EDITOR_TOUR = [
9
- {
10
- target: '.nice-morph-target-editor',
11
- titleKey: 'tutorial.morphTargetEditor.intro.title',
12
- title: 'Morph target editor',
13
- contentKey: 'tutorial.morphTargetEditor.intro.content',
14
- content: 'Blend the mesh’s morph targets with the per-target influence sliders, create or delete targets, and preview the interpolation.',
15
- placement: 'auto',
16
- },
7
+ {
8
+ target: ".nice-morph-target-editor",
9
+ titleKey: "tutorial.morphTargetEditor.intro.title",
10
+ title: "Morph target editor",
11
+ contentKey: "tutorial.morphTargetEditor.intro.content",
12
+ content: "Blend the mesh’s morph targets with the per-target influence sliders, create or delete targets, and preview the interpolation.",
13
+ placement: "auto"
14
+ }
17
15
  ];
18
- /* ── Hook ── */
19
16
  function useMorphTargetEditor(mesh, onInfluenceChange) {
20
- const [targets, setTargets] = useState([]);
21
- const [animations, setAnimations] = useState([]);
22
- const [isAnimating, setIsAnimating] = useState(false);
23
- const animFrameRef = useRef(0);
24
- const animStartRef = useRef(0);
25
- const activeAnimRef = useRef(null);
26
- // Sync targets from mesh
27
- useEffect(() => {
28
- if (!mesh || !mesh.morphTargetDictionary || !mesh.morphTargetInfluences) {
29
- setTargets([]);
30
- return;
31
- }
32
- const dict = mesh.morphTargetDictionary;
33
- const influences = mesh.morphTargetInfluences;
34
- const list = Object.entries(dict).map(([name, index]) => {
35
- var _a;
36
- return ({
37
- name,
38
- index,
39
- influence: (_a = influences[index]) !== null && _a !== void 0 ? _a : 0,
40
- });
41
- });
42
- list.sort((a, b) => a.index - b.index);
43
- setTargets(list);
44
- }, [mesh]);
45
- const setInfluence = useCallback((index, value) => {
46
- if (!(mesh === null || mesh === void 0 ? void 0 : mesh.morphTargetInfluences)) {
47
- return;
48
- }
49
- mesh.morphTargetInfluences[index] = value;
50
- setTargets((prev) => prev.map((t) => (t.index === index ? { ...t, influence: value } : t)));
51
- onInfluenceChange === null || onInfluenceChange === void 0 ? void 0 : onInfluenceChange(mesh, index, value);
52
- }, [mesh, onInfluenceChange]);
53
- const createMorphTarget = useCallback((name) => {
54
- if (!mesh) {
55
- return;
56
- }
57
- const geometry = mesh.geometry;
58
- const posAttr = geometry.attributes.position;
59
- const count = posAttr.count;
60
- // Clone current position as new morph target
61
- const morphPositions = new Float32Array(count * 3);
62
- for (let i = 0; i < count * 3; i++) {
63
- morphPositions[i] = posAttr.array[i];
64
- }
65
- const morphAttr = new THREE.BufferAttribute(morphPositions, 3);
66
- morphAttr.name = name;
67
- // Add to morphAttributes
68
- if (!geometry.morphAttributes.position) {
69
- geometry.morphAttributes.position = [];
70
- }
71
- const morphArray = geometry.morphAttributes.position;
72
- morphArray.push(morphAttr);
73
- // Update dictionary and influences
74
- if (!mesh.morphTargetDictionary) {
75
- mesh.morphTargetDictionary = {};
76
- }
77
- if (!mesh.morphTargetInfluences) {
78
- mesh.morphTargetInfluences = [];
79
- }
80
- const newIndex = morphArray.length - 1;
81
- mesh.morphTargetDictionary[name] = newIndex;
82
- mesh.morphTargetInfluences[newIndex] = 0;
83
- mesh.updateMorphTargets();
84
- setTargets((prev) => [...prev, { name, index: newIndex, influence: 0 }]);
85
- }, [mesh]);
86
- const deleteMorphTarget = useCallback((index) => {
87
- if (!mesh) {
88
- return;
89
- }
90
- const geometry = mesh.geometry;
91
- const morphArray = geometry.morphAttributes.position;
92
- if (!morphArray || index >= morphArray.length) {
93
- return;
17
+ const [targets, setTargets] = useState([]);
18
+ const [animations, setAnimations] = useState([]);
19
+ const [isAnimating, setIsAnimating] = useState(false);
20
+ const animFrameRef = useRef(0);
21
+ const animStartRef = useRef(0);
22
+ const activeAnimRef = useRef(null);
23
+ useEffect(() => {
24
+ if (!mesh || !mesh.morphTargetDictionary || !mesh.morphTargetInfluences) {
25
+ setTargets([]);
26
+ return;
27
+ }
28
+ const dict = mesh.morphTargetDictionary;
29
+ const influences = mesh.morphTargetInfluences;
30
+ const list = Object.entries(dict).map(([name, index]) => ({
31
+ name,
32
+ index,
33
+ influence: influences[index] ?? 0
34
+ }));
35
+ list.sort((a, b) => a.index - b.index);
36
+ setTargets(list);
37
+ }, [mesh]);
38
+ const setInfluence = useCallback(
39
+ (index, value) => {
40
+ if (!mesh?.morphTargetInfluences) {
41
+ return;
42
+ }
43
+ mesh.morphTargetInfluences[index] = value;
44
+ setTargets((prev) => prev.map((t) => t.index === index ? { ...t, influence: value } : t));
45
+ onInfluenceChange?.(mesh, index, value);
46
+ },
47
+ [mesh, onInfluenceChange]
48
+ );
49
+ const createMorphTarget = useCallback(
50
+ (name) => {
51
+ if (!mesh) {
52
+ return;
53
+ }
54
+ const geometry = mesh.geometry;
55
+ const posAttr = geometry.attributes.position;
56
+ const count = posAttr.count;
57
+ const morphPositions = new Float32Array(count * 3);
58
+ for (let i = 0; i < count * 3; i++) {
59
+ morphPositions[i] = posAttr.array[i];
60
+ }
61
+ const morphAttr = new THREE.BufferAttribute(morphPositions, 3);
62
+ morphAttr.name = name;
63
+ if (!geometry.morphAttributes.position) {
64
+ geometry.morphAttributes.position = [];
65
+ }
66
+ const morphArray = geometry.morphAttributes.position;
67
+ morphArray.push(morphAttr);
68
+ if (!mesh.morphTargetDictionary) {
69
+ mesh.morphTargetDictionary = {};
70
+ }
71
+ if (!mesh.morphTargetInfluences) {
72
+ mesh.morphTargetInfluences = [];
73
+ }
74
+ const newIndex = morphArray.length - 1;
75
+ mesh.morphTargetDictionary[name] = newIndex;
76
+ mesh.morphTargetInfluences[newIndex] = 0;
77
+ mesh.updateMorphTargets();
78
+ setTargets((prev) => [...prev, { name, index: newIndex, influence: 0 }]);
79
+ },
80
+ [mesh]
81
+ );
82
+ const deleteMorphTarget = useCallback(
83
+ (index) => {
84
+ if (!mesh) {
85
+ return;
86
+ }
87
+ const geometry = mesh.geometry;
88
+ const morphArray = geometry.morphAttributes.position;
89
+ if (!morphArray || index >= morphArray.length) {
90
+ return;
91
+ }
92
+ morphArray.splice(index, 1);
93
+ const dict = {};
94
+ const influences = [];
95
+ morphArray.forEach((attr, i) => {
96
+ dict[attr.name || `morph_${i}`] = i;
97
+ influences[i] = mesh.morphTargetInfluences?.[i === index ? -1 : i >= index ? i + 1 : i] ?? 0;
98
+ });
99
+ mesh.morphTargetDictionary = dict;
100
+ mesh.morphTargetInfluences = influences;
101
+ setTargets(
102
+ Object.entries(dict).map(([name, idx]) => ({
103
+ name,
104
+ index: idx,
105
+ influence: influences[idx]
106
+ }))
107
+ );
108
+ },
109
+ [mesh]
110
+ );
111
+ const resetAllInfluences = useCallback(() => {
112
+ if (!mesh?.morphTargetInfluences) {
113
+ return;
114
+ }
115
+ mesh.morphTargetInfluences.fill(0);
116
+ setTargets((prev) => prev.map((t) => ({ ...t, influence: 0 })));
117
+ }, [mesh]);
118
+ const startAnimation = useCallback(
119
+ (animation) => {
120
+ if (!mesh?.morphTargetInfluences) {
121
+ return;
122
+ }
123
+ activeAnimRef.current = animation;
124
+ setIsAnimating(true);
125
+ animStartRef.current = performance.now();
126
+ const animate = (now) => {
127
+ const anim = activeAnimRef.current;
128
+ if (!anim || !mesh.morphTargetInfluences) {
129
+ return;
94
130
  }
95
- morphArray.splice(index, 1);
96
- // Rebuild dictionary
97
- const dict = {};
98
- const influences = [];
99
- morphArray.forEach((attr, i) => {
100
- var _a, _b;
101
- dict[attr.name || `morph_${i}`] = i;
102
- influences[i] =
103
- (_b = (_a = mesh.morphTargetInfluences) === null || _a === void 0 ? void 0 : _a[i === index ? -1 : i >= index ? i + 1 : i]) !== null && _b !== void 0 ? _b : 0;
104
- });
105
- mesh.morphTargetDictionary = dict;
106
- mesh.morphTargetInfluences = influences;
107
- setTargets(Object.entries(dict).map(([name, idx]) => ({
108
- name,
109
- index: idx,
110
- influence: influences[idx],
111
- })));
112
- }, [mesh]);
113
- const resetAllInfluences = useCallback(() => {
114
- if (!(mesh === null || mesh === void 0 ? void 0 : mesh.morphTargetInfluences)) {
115
- return;
131
+ const elapsed = (now - animStartRef.current) / 1e3;
132
+ const t = elapsed % anim.duration / anim.duration;
133
+ const kfs = anim.keyframes;
134
+ let prevKf = kfs[0];
135
+ let nextKf = kfs[kfs.length - 1];
136
+ for (let i = 0; i < kfs.length - 1; i++) {
137
+ if (t >= kfs[i].time / anim.duration && t < kfs[i + 1].time / anim.duration) {
138
+ prevKf = kfs[i];
139
+ nextKf = kfs[i + 1];
140
+ break;
141
+ }
116
142
  }
117
- mesh.morphTargetInfluences.fill(0);
118
- setTargets((prev) => prev.map((t) => ({ ...t, influence: 0 })));
119
- }, [mesh]);
120
- const startAnimation = useCallback((animation) => {
121
- if (!(mesh === null || mesh === void 0 ? void 0 : mesh.morphTargetInfluences)) {
122
- return;
143
+ const segDuration = (nextKf.time - prevKf.time) / anim.duration;
144
+ const segT = segDuration > 0 ? (t - prevKf.time / anim.duration) / segDuration : 0;
145
+ for (let i = 0; i < mesh.morphTargetInfluences.length; i++) {
146
+ const from = prevKf.influences[i] ?? 0;
147
+ const to = nextKf.influences[i] ?? 0;
148
+ mesh.morphTargetInfluences[i] = from + (to - from) * segT;
123
149
  }
124
- activeAnimRef.current = animation;
125
- setIsAnimating(true);
126
- animStartRef.current = performance.now();
127
- const animate = (now) => {
128
- var _a, _b;
129
- const anim = activeAnimRef.current;
130
- if (!anim || !mesh.morphTargetInfluences) {
131
- return;
132
- }
133
- const elapsed = (now - animStartRef.current) / 1000;
134
- const t = (elapsed % anim.duration) / anim.duration;
135
- // Interpolate between keyframes
136
- const kfs = anim.keyframes;
137
- let prevKf = kfs[0];
138
- let nextKf = kfs[kfs.length - 1];
139
- for (let i = 0; i < kfs.length - 1; i++) {
140
- if (t >= kfs[i].time / anim.duration && t < kfs[i + 1].time / anim.duration) {
141
- prevKf = kfs[i];
142
- nextKf = kfs[i + 1];
143
- break;
144
- }
145
- }
146
- const segDuration = (nextKf.time - prevKf.time) / anim.duration;
147
- const segT = segDuration > 0 ? (t - prevKf.time / anim.duration) / segDuration : 0;
148
- for (let i = 0; i < mesh.morphTargetInfluences.length; i++) {
149
- const from = (_a = prevKf.influences[i]) !== null && _a !== void 0 ? _a : 0;
150
- const to = (_b = nextKf.influences[i]) !== null && _b !== void 0 ? _b : 0;
151
- mesh.morphTargetInfluences[i] = from + (to - from) * segT;
152
- }
153
- setTargets((prev) => prev.map((tgt) => {
154
- var _a;
155
- return ({
156
- ...tgt,
157
- influence: (_a = mesh.morphTargetInfluences[tgt.index]) !== null && _a !== void 0 ? _a : 0,
158
- });
159
- }));
160
- animFrameRef.current = requestAnimationFrame(animate);
161
- };
150
+ setTargets(
151
+ (prev) => prev.map((tgt) => ({
152
+ ...tgt,
153
+ influence: mesh.morphTargetInfluences[tgt.index] ?? 0
154
+ }))
155
+ );
162
156
  animFrameRef.current = requestAnimationFrame(animate);
163
- }, [mesh]);
164
- const stopAnimation = useCallback(() => {
165
- activeAnimRef.current = null;
166
- setIsAnimating(false);
167
- cancelAnimationFrame(animFrameRef.current);
168
- }, []);
169
- useEffect(() => {
170
- return () => cancelAnimationFrame(animFrameRef.current);
171
- }, []);
172
- const addAnimation = useCallback((animation) => {
173
- setAnimations((prev) => [...prev, animation]);
174
- }, []);
175
- const removeAnimation = useCallback((name) => {
176
- setAnimations((prev) => prev.filter((a) => a.name !== name));
177
- }, []);
178
- return {
179
- targets,
180
- setInfluence,
181
- createMorphTarget,
182
- deleteMorphTarget,
183
- resetAllInfluences,
184
- isAnimating,
185
- startAnimation,
186
- stopAnimation,
187
- animations,
188
- addAnimation,
189
- removeAnimation,
190
- };
157
+ };
158
+ animFrameRef.current = requestAnimationFrame(animate);
159
+ },
160
+ [mesh]
161
+ );
162
+ const stopAnimation = useCallback(() => {
163
+ activeAnimRef.current = null;
164
+ setIsAnimating(false);
165
+ cancelAnimationFrame(animFrameRef.current);
166
+ }, []);
167
+ useEffect(() => {
168
+ return () => cancelAnimationFrame(animFrameRef.current);
169
+ }, []);
170
+ const addAnimation = useCallback((animation) => {
171
+ setAnimations((prev) => [...prev, animation]);
172
+ }, []);
173
+ const removeAnimation = useCallback((name) => {
174
+ setAnimations((prev) => prev.filter((a) => a.name !== name));
175
+ }, []);
176
+ return {
177
+ targets,
178
+ setInfluence,
179
+ createMorphTarget,
180
+ deleteMorphTarget,
181
+ resetAllInfluences,
182
+ isAnimating,
183
+ startAnimation,
184
+ stopAnimation,
185
+ animations,
186
+ addAnimation,
187
+ removeAnimation
188
+ };
191
189
  }
192
- /* ── Component ── */
193
- const NiceMorphTargetEditor = ({ mesh, onInfluenceChange, className = '', tutorial, }) => {
194
- const { t } = useNiceTranslation();
195
- const { targets, setInfluence, createMorphTarget, deleteMorphTarget, resetAllInfluences, isAnimating, startAnimation, stopAnimation, animations, addAnimation: _addAnimation, removeAnimation, } = useMorphTargetEditor(mesh, onInfluenceChange);
196
- const [newName, setNewName] = useState('');
197
- const handleCreate = () => {
198
- const name = newName.trim();
199
- if (!name) {
200
- return;
201
- }
202
- createMorphTarget(name);
203
- setNewName('');
204
- };
205
- return (jsxs("div", { className: `nice-morph-target-editor ${className}`, style: { position: 'relative', display: 'grid', gap: 8, fontSize: 13 }, children: [jsx("span", { style: { position: 'absolute', top: 0, right: 0, zIndex: 20 }, children: jsx(NiceTutorialButton, { steps: resolveTutorial(tutorial, MORPH_TARGET_EDITOR_TOUR) }) }), jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center' }, children: [jsx("strong", { children: t('morphTargetEditor.morphTargets', 'Morph Targets') }), jsx("button", { type: "button", onClick: resetAllInfluences, style: { fontSize: 11 }, children: t('morphTargetEditor.resetAll', 'Reset All') })] }), targets.length === 0 && (jsx("div", { style: { opacity: 0.6, fontStyle: 'italic' }, children: t('morphTargetEditor.noMorphTargetsFound', 'No morph targets found.') })), targets.map((target) => (jsxs("div", { style: {
206
- display: 'grid',
207
- gridTemplateColumns: '1fr 50px auto',
208
- alignItems: 'center',
209
- gap: 6,
210
- }, children: [jsxs("div", { children: [jsx("label", { style: { display: 'block', fontSize: 11, marginBottom: 2 }, children: target.name }), jsx("input", { type: "range", min: 0, max: 1, step: 0.01, value: target.influence, onChange: (e) => setInfluence(target.index, parseFloat(e.target.value)), style: { width: '100%' } })] }), jsx("span", { style: { fontSize: 11, textAlign: 'right' }, children: target.influence.toFixed(2) }), jsx("button", { type: "button", onClick: () => deleteMorphTarget(target.index), title: t('morphTargetEditor.delete', 'Delete'), "aria-label": t('morphTargetEditor.delete', 'Delete'), style: { background: 'none', border: 'none', cursor: 'pointer' }, children: jsx(NiceIcon, { name: "trash", size: 14 }) })] }, target.index))), jsxs("div", { style: { display: 'flex', gap: 4, marginTop: 4 }, children: [jsx("input", { type: "text", value: newName, onChange: (e) => setNewName(e.target.value), placeholder: t('morphTargetEditor.newMorphTargetName', 'New morph target name…'), onKeyDown: (e) => e.key === 'Enter' && handleCreate(), style: {
211
- flex: 1,
212
- padding: '4px 8px',
213
- border: '1px solid var(--nice-border, #e2e8f0)',
214
- borderRadius: 4,
215
- } }), jsx("button", { type: "button", onClick: handleCreate, children: t('morphTargetEditor.add', '+ Add') })] }), animations.length > 0 && (jsxs("div", { style: { marginTop: 8 }, children: [jsx("strong", { style: { fontSize: 12 }, children: t('morphTargetEditor.animations', 'Animations') }), animations.map((anim) => (jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 4, marginTop: 4 }, children: [jsx("span", { style: { flex: 1 }, children: anim.name }), jsx("button", { type: "button", onClick: () => (isAnimating ? stopAnimation() : startAnimation(anim)), style: { fontSize: 11 }, "aria-label": isAnimating
216
- ? t('morphTargetEditor.stop', 'Stop')
217
- : t('morphTargetEditor.play', 'Play'), children: jsx(NiceIcon, { name: isAnimating ? 'stop' : 'play', size: 14 }) }), jsx("button", { type: "button", onClick: () => removeAnimation(anim.name), style: { fontSize: 11 }, "aria-label": t('morphTargetEditor.removeAnimation', 'Remove animation'), children: jsx(NiceIcon, { name: "trash", size: 14 }) })] }, anim.name)))] }))] }));
190
+ const NiceMorphTargetEditor = ({
191
+ mesh,
192
+ onInfluenceChange,
193
+ className = "",
194
+ tutorial
195
+ }) => {
196
+ const { t } = useNiceTranslation();
197
+ const {
198
+ targets,
199
+ setInfluence,
200
+ createMorphTarget,
201
+ deleteMorphTarget,
202
+ resetAllInfluences,
203
+ isAnimating,
204
+ startAnimation,
205
+ stopAnimation,
206
+ animations,
207
+ addAnimation: _addAnimation,
208
+ removeAnimation
209
+ } = useMorphTargetEditor(mesh, onInfluenceChange);
210
+ const [newName, setNewName] = useState("");
211
+ const handleCreate = () => {
212
+ const name = newName.trim();
213
+ if (!name) {
214
+ return;
215
+ }
216
+ createMorphTarget(name);
217
+ setNewName("");
218
+ };
219
+ return /* @__PURE__ */ jsxs(
220
+ "div",
221
+ {
222
+ className: `nice-morph-target-editor ${className}`,
223
+ style: { position: "relative", display: "grid", gap: 8, fontSize: 13 },
224
+ children: [
225
+ /* @__PURE__ */ jsx("span", { style: { position: "absolute", top: 0, right: 0, zIndex: 20 }, children: /* @__PURE__ */ jsx(NiceTutorialButton, { steps: resolveTutorial(tutorial, MORPH_TARGET_EDITOR_TOUR) }) }),
226
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
227
+ /* @__PURE__ */ jsx("strong", { children: t("morphTargetEditor.morphTargets", "Morph Targets") }),
228
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: resetAllInfluences, style: { fontSize: 11 }, children: t("morphTargetEditor.resetAll", "Reset All") })
229
+ ] }),
230
+ targets.length === 0 && /* @__PURE__ */ jsx("div", { style: { opacity: 0.6, fontStyle: "italic" }, children: t("morphTargetEditor.noMorphTargetsFound", "No morph targets found.") }),
231
+ targets.map((target) => /* @__PURE__ */ jsxs(
232
+ "div",
233
+ {
234
+ style: {
235
+ display: "grid",
236
+ gridTemplateColumns: "1fr 50px auto",
237
+ alignItems: "center",
238
+ gap: 6
239
+ },
240
+ children: [
241
+ /* @__PURE__ */ jsxs("div", { children: [
242
+ /* @__PURE__ */ jsx("label", { style: { display: "block", fontSize: 11, marginBottom: 2 }, children: target.name }),
243
+ /* @__PURE__ */ jsx(
244
+ "input",
245
+ {
246
+ type: "range",
247
+ min: 0,
248
+ max: 1,
249
+ step: 0.01,
250
+ value: target.influence,
251
+ onChange: (e) => setInfluence(target.index, parseFloat(e.target.value)),
252
+ style: { width: "100%" }
253
+ }
254
+ )
255
+ ] }),
256
+ /* @__PURE__ */ jsx("span", { style: { fontSize: 11, textAlign: "right" }, children: target.influence.toFixed(2) }),
257
+ /* @__PURE__ */ jsx(
258
+ "button",
259
+ {
260
+ type: "button",
261
+ onClick: () => deleteMorphTarget(target.index),
262
+ title: t("morphTargetEditor.delete", "Delete"),
263
+ "aria-label": t("morphTargetEditor.delete", "Delete"),
264
+ style: { background: "none", border: "none", cursor: "pointer" },
265
+ children: /* @__PURE__ */ jsx(NiceIcon, { name: "trash", size: 14 })
266
+ }
267
+ )
268
+ ]
269
+ },
270
+ target.index
271
+ )),
272
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 4, marginTop: 4 }, children: [
273
+ /* @__PURE__ */ jsx(
274
+ "input",
275
+ {
276
+ type: "text",
277
+ value: newName,
278
+ onChange: (e) => setNewName(e.target.value),
279
+ placeholder: t("morphTargetEditor.newMorphTargetName", "New morph target name…"),
280
+ onKeyDown: (e) => e.key === "Enter" && handleCreate(),
281
+ style: {
282
+ flex: 1,
283
+ padding: "4px 8px",
284
+ border: "1px solid var(--nice-border, #e2e8f0)",
285
+ borderRadius: 4
286
+ }
287
+ }
288
+ ),
289
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: handleCreate, children: t("morphTargetEditor.add", "+ Add") })
290
+ ] }),
291
+ animations.length > 0 && /* @__PURE__ */ jsxs("div", { style: { marginTop: 8 }, children: [
292
+ /* @__PURE__ */ jsx("strong", { style: { fontSize: 12 }, children: t("morphTargetEditor.animations", "Animations") }),
293
+ animations.map((anim) => /* @__PURE__ */ jsxs(
294
+ "div",
295
+ {
296
+ style: { display: "flex", alignItems: "center", gap: 4, marginTop: 4 },
297
+ children: [
298
+ /* @__PURE__ */ jsx("span", { style: { flex: 1 }, children: anim.name }),
299
+ /* @__PURE__ */ jsx(
300
+ "button",
301
+ {
302
+ type: "button",
303
+ onClick: () => isAnimating ? stopAnimation() : startAnimation(anim),
304
+ style: { fontSize: 11 },
305
+ "aria-label": isAnimating ? t("morphTargetEditor.stop", "Stop") : t("morphTargetEditor.play", "Play"),
306
+ children: /* @__PURE__ */ jsx(NiceIcon, { name: isAnimating ? "stop" : "play", size: 14 })
307
+ }
308
+ ),
309
+ /* @__PURE__ */ jsx(
310
+ "button",
311
+ {
312
+ type: "button",
313
+ onClick: () => removeAnimation(anim.name),
314
+ style: { fontSize: 11 },
315
+ "aria-label": t("morphTargetEditor.removeAnimation", "Remove animation"),
316
+ children: /* @__PURE__ */ jsx(NiceIcon, { name: "trash", size: 14 })
317
+ }
318
+ )
319
+ ]
320
+ },
321
+ anim.name
322
+ ))
323
+ ] })
324
+ ]
325
+ }
326
+ );
327
+ };
328
+ export {
329
+ NiceMorphTargetEditor,
330
+ useMorphTargetEditor
218
331
  };
219
-
220
- export { NiceMorphTargetEditor, useMorphTargetEditor };