sa2kit 1.0.8 → 1.0.9
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/mmd/index.js +210 -3
- package/dist/mmd/index.js.map +1 -1
- package/dist/mmd/index.mjs +210 -3
- package/dist/mmd/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/mmd/index.js
CHANGED
|
@@ -317,6 +317,80 @@ var MMDPlayerEnhanced = ({
|
|
|
317
317
|
onAnimationEnded
|
|
318
318
|
}) => {
|
|
319
319
|
console.log("\u{1F3A8} [MMDPlayerEnhanced] \u7EC4\u4EF6\u521D\u59CB\u5316");
|
|
320
|
+
React2.useEffect(() => {
|
|
321
|
+
return () => {
|
|
322
|
+
console.log("\u{1F9F9} [MMDPlayerEnhanced] \u7EC4\u4EF6\u5378\u8F7D\uFF0C\u6267\u884C\u5B8C\u6574\u6E05\u7406");
|
|
323
|
+
if (animationIdRef.current) {
|
|
324
|
+
cancelAnimationFrame(animationIdRef.current);
|
|
325
|
+
animationIdRef.current = null;
|
|
326
|
+
}
|
|
327
|
+
if (audioRef.current) {
|
|
328
|
+
audioRef.current.pause();
|
|
329
|
+
audioRef.current.src = "";
|
|
330
|
+
audioRef.current.load();
|
|
331
|
+
audioRef.current = null;
|
|
332
|
+
}
|
|
333
|
+
if (helperRef.current) {
|
|
334
|
+
try {
|
|
335
|
+
helperRef.current.enable("animation", false);
|
|
336
|
+
helperRef.current.enable("ik", false);
|
|
337
|
+
helperRef.current.enable("grant", false);
|
|
338
|
+
helperRef.current.enable("physics", false);
|
|
339
|
+
const helperObjects = helperRef.current.objects;
|
|
340
|
+
if (helperObjects && Array.isArray(helperObjects)) {
|
|
341
|
+
const physicsWorldsToDestroy = /* @__PURE__ */ new Set();
|
|
342
|
+
helperObjects.forEach((obj) => {
|
|
343
|
+
if (obj.physics) {
|
|
344
|
+
const physics = obj.physics;
|
|
345
|
+
if (physics.world) physicsWorldsToDestroy.add(physics.world);
|
|
346
|
+
if (physics.bodies) physics.bodies.length = 0;
|
|
347
|
+
if (physics.constraints) physics.constraints.length = 0;
|
|
348
|
+
obj.physics = null;
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
physicsWorldsToDestroy.forEach((world) => {
|
|
352
|
+
try {
|
|
353
|
+
while (world.getNumCollisionObjects() > 0) {
|
|
354
|
+
const obj = world.getCollisionObjectArray().at(0);
|
|
355
|
+
world.removeCollisionObject(obj);
|
|
356
|
+
if (obj && obj.destroy) obj.destroy();
|
|
357
|
+
}
|
|
358
|
+
if (world.destroy) world.destroy();
|
|
359
|
+
} catch (e) {
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
helperObjects.length = 0;
|
|
363
|
+
}
|
|
364
|
+
} catch (e) {
|
|
365
|
+
}
|
|
366
|
+
helperRef.current = null;
|
|
367
|
+
}
|
|
368
|
+
if (sceneRef.current) {
|
|
369
|
+
sceneRef.current.clear();
|
|
370
|
+
sceneRef.current = null;
|
|
371
|
+
}
|
|
372
|
+
if (rendererRef.current) {
|
|
373
|
+
rendererRef.current.dispose();
|
|
374
|
+
rendererRef.current = null;
|
|
375
|
+
}
|
|
376
|
+
if (controlsRef.current) {
|
|
377
|
+
controlsRef.current.dispose();
|
|
378
|
+
controlsRef.current = null;
|
|
379
|
+
}
|
|
380
|
+
cameraRef.current = null;
|
|
381
|
+
if (clockRef.current) {
|
|
382
|
+
clockRef.current = new THREE2__namespace.Clock();
|
|
383
|
+
}
|
|
384
|
+
vmdDataRef.current = null;
|
|
385
|
+
if (window.gc) {
|
|
386
|
+
try {
|
|
387
|
+
window.gc();
|
|
388
|
+
} catch (e) {
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
console.log("\u2705 [MMDPlayerEnhanced] \u7EC4\u4EF6\u5378\u8F7D\u6E05\u7406\u5B8C\u6210");
|
|
392
|
+
};
|
|
393
|
+
}, []);
|
|
320
394
|
const [selectedResourceId, setSelectedResourceId] = React2.useState(
|
|
321
395
|
defaultResourceId || resourcesList?.[0]?.id || ""
|
|
322
396
|
);
|
|
@@ -673,6 +747,7 @@ var MMDPlayerEnhanced = ({
|
|
|
673
747
|
if (window.gc) {
|
|
674
748
|
try {
|
|
675
749
|
window.gc();
|
|
750
|
+
console.log("\u267B\uFE0F \u5DF2\u89E6\u53D1\u5783\u573E\u56DE\u6536");
|
|
676
751
|
} catch (e) {
|
|
677
752
|
}
|
|
678
753
|
}
|
|
@@ -841,13 +916,75 @@ var MMDPlayerEnhanced = ({
|
|
|
841
916
|
loadMMD();
|
|
842
917
|
}, [currentResources, stage?.enablePhysics, autoPlay, loop, onLoad, onError, reloadTrigger]);
|
|
843
918
|
const play = () => {
|
|
844
|
-
if (!helperRef.current && !needReset) return;
|
|
845
919
|
if (needReset && vmdDataRef.current && sceneRef.current && cameraRef.current) {
|
|
846
|
-
|
|
920
|
+
console.log("\u{1F504} \u68C0\u6D4B\u5230\u9700\u8981\u91CD\u7F6E\uFF0C\u5F00\u59CB\u5F3A\u5236\u6E05\u7406...");
|
|
921
|
+
if (animationIdRef.current) {
|
|
922
|
+
cancelAnimationFrame(animationIdRef.current);
|
|
923
|
+
animationIdRef.current = null;
|
|
924
|
+
}
|
|
847
925
|
if (helperRef.current) {
|
|
848
926
|
try {
|
|
927
|
+
helperRef.current.enable("animation", false);
|
|
928
|
+
helperRef.current.enable("ik", false);
|
|
929
|
+
helperRef.current.enable("grant", false);
|
|
930
|
+
helperRef.current.enable("physics", false);
|
|
849
931
|
const helperObjects = helperRef.current.objects;
|
|
850
932
|
if (helperObjects && Array.isArray(helperObjects)) {
|
|
933
|
+
const physicsWorldsToDestroy = /* @__PURE__ */ new Set();
|
|
934
|
+
helperObjects.forEach((obj) => {
|
|
935
|
+
if (obj.physics) {
|
|
936
|
+
try {
|
|
937
|
+
const physics = obj.physics;
|
|
938
|
+
if (physics.world) {
|
|
939
|
+
physicsWorldsToDestroy.add(physics.world);
|
|
940
|
+
}
|
|
941
|
+
if (physics.bodies && Array.isArray(physics.bodies)) {
|
|
942
|
+
physics.bodies.forEach((body) => {
|
|
943
|
+
if (physics.world && body) {
|
|
944
|
+
try {
|
|
945
|
+
physics.world.removeRigidBody(body);
|
|
946
|
+
if (window.Ammo && body.destroy) {
|
|
947
|
+
body.destroy();
|
|
948
|
+
}
|
|
949
|
+
} catch (e) {
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
physics.bodies.length = 0;
|
|
954
|
+
physics.bodies = null;
|
|
955
|
+
}
|
|
956
|
+
if (physics.constraints && Array.isArray(physics.constraints)) {
|
|
957
|
+
physics.constraints.forEach((constraint) => {
|
|
958
|
+
if (physics.world && constraint) {
|
|
959
|
+
try {
|
|
960
|
+
physics.world.removeConstraint(constraint);
|
|
961
|
+
if (window.Ammo && constraint.destroy) {
|
|
962
|
+
constraint.destroy();
|
|
963
|
+
}
|
|
964
|
+
} catch (e) {
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
physics.constraints.length = 0;
|
|
969
|
+
physics.constraints = null;
|
|
970
|
+
}
|
|
971
|
+
physics.world = null;
|
|
972
|
+
obj.physics = null;
|
|
973
|
+
} catch (e) {
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
});
|
|
977
|
+
physicsWorldsToDestroy.forEach((world) => {
|
|
978
|
+
try {
|
|
979
|
+
while (world.getNumCollisionObjects() > 0) {
|
|
980
|
+
const obj = world.getCollisionObjectArray().at(0);
|
|
981
|
+
world.removeCollisionObject(obj);
|
|
982
|
+
if (obj && obj.destroy) obj.destroy();
|
|
983
|
+
}
|
|
984
|
+
if (world.destroy) world.destroy();
|
|
985
|
+
} catch (e) {
|
|
986
|
+
}
|
|
987
|
+
});
|
|
851
988
|
helperObjects.length = 0;
|
|
852
989
|
}
|
|
853
990
|
} catch (error2) {
|
|
@@ -856,6 +993,7 @@ var MMDPlayerEnhanced = ({
|
|
|
856
993
|
const newHelper = new threeStdlib.MMDAnimationHelper();
|
|
857
994
|
helperRef.current = newHelper;
|
|
858
995
|
clockRef.current = new THREE2__namespace.Clock();
|
|
996
|
+
const { mesh, vmd, cameraVmd } = vmdDataRef.current;
|
|
859
997
|
if (vmd && typeof vmd === "object") {
|
|
860
998
|
try {
|
|
861
999
|
newHelper.add(mesh, {
|
|
@@ -884,6 +1022,7 @@ var MMDPlayerEnhanced = ({
|
|
|
884
1022
|
audioRef.current.currentTime = 0;
|
|
885
1023
|
}
|
|
886
1024
|
setNeedReset(false);
|
|
1025
|
+
console.log("\u2705 \u5F3A\u5236\u6E05\u7406\u5B8C\u6210\uFF0C\u5F00\u59CB\u64AD\u653E");
|
|
887
1026
|
}
|
|
888
1027
|
if (!helperRef.current) {
|
|
889
1028
|
console.error("\u274C [play] helper \u4E0D\u5B58\u5728\uFF0C\u65E0\u6CD5\u64AD\u653E");
|
|
@@ -918,6 +1057,7 @@ var MMDPlayerEnhanced = ({
|
|
|
918
1057
|
};
|
|
919
1058
|
const stop = () => {
|
|
920
1059
|
if (!helperRef.current || !sceneRef.current) return;
|
|
1060
|
+
console.log("\u23F9\uFE0F \u505C\u6B62\u64AD\u653E\uFF0C\u5F00\u59CB\u6E05\u7406\u7269\u7406\u7CFB\u7EDF...");
|
|
921
1061
|
isPlayingRef.current = false;
|
|
922
1062
|
setIsPlaying(false);
|
|
923
1063
|
if (audioRef.current) {
|
|
@@ -926,6 +1066,73 @@ var MMDPlayerEnhanced = ({
|
|
|
926
1066
|
}
|
|
927
1067
|
clockRef.current.stop();
|
|
928
1068
|
clockRef.current = new THREE2__namespace.Clock();
|
|
1069
|
+
try {
|
|
1070
|
+
helperRef.current.enable("animation", false);
|
|
1071
|
+
helperRef.current.enable("ik", false);
|
|
1072
|
+
helperRef.current.enable("grant", false);
|
|
1073
|
+
helperRef.current.enable("physics", false);
|
|
1074
|
+
const helperObjects = helperRef.current.objects;
|
|
1075
|
+
if (helperObjects && Array.isArray(helperObjects)) {
|
|
1076
|
+
const physicsWorldsToDestroy = /* @__PURE__ */ new Set();
|
|
1077
|
+
helperObjects.forEach((obj) => {
|
|
1078
|
+
if (obj.physics) {
|
|
1079
|
+
try {
|
|
1080
|
+
const physics = obj.physics;
|
|
1081
|
+
if (physics.world) {
|
|
1082
|
+
physicsWorldsToDestroy.add(physics.world);
|
|
1083
|
+
}
|
|
1084
|
+
if (physics.bodies && Array.isArray(physics.bodies)) {
|
|
1085
|
+
physics.bodies.forEach((body) => {
|
|
1086
|
+
if (physics.world && body) {
|
|
1087
|
+
try {
|
|
1088
|
+
physics.world.removeRigidBody(body);
|
|
1089
|
+
if (window.Ammo && body.destroy) {
|
|
1090
|
+
body.destroy();
|
|
1091
|
+
}
|
|
1092
|
+
} catch (e) {
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
physics.bodies.length = 0;
|
|
1097
|
+
physics.bodies = null;
|
|
1098
|
+
}
|
|
1099
|
+
if (physics.constraints && Array.isArray(physics.constraints)) {
|
|
1100
|
+
physics.constraints.forEach((constraint) => {
|
|
1101
|
+
if (physics.world && constraint) {
|
|
1102
|
+
try {
|
|
1103
|
+
physics.world.removeConstraint(constraint);
|
|
1104
|
+
if (window.Ammo && constraint.destroy) {
|
|
1105
|
+
constraint.destroy();
|
|
1106
|
+
}
|
|
1107
|
+
} catch (e) {
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
});
|
|
1111
|
+
physics.constraints.length = 0;
|
|
1112
|
+
physics.constraints = null;
|
|
1113
|
+
}
|
|
1114
|
+
physics.world = null;
|
|
1115
|
+
obj.physics = null;
|
|
1116
|
+
} catch (e) {
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
});
|
|
1120
|
+
physicsWorldsToDestroy.forEach((world) => {
|
|
1121
|
+
try {
|
|
1122
|
+
while (world.getNumCollisionObjects() > 0) {
|
|
1123
|
+
const obj = world.getCollisionObjectArray().at(0);
|
|
1124
|
+
world.removeCollisionObject(obj);
|
|
1125
|
+
if (obj && obj.destroy) obj.destroy();
|
|
1126
|
+
}
|
|
1127
|
+
if (world.destroy) world.destroy();
|
|
1128
|
+
} catch (e) {
|
|
1129
|
+
}
|
|
1130
|
+
});
|
|
1131
|
+
helperObjects.length = 0;
|
|
1132
|
+
}
|
|
1133
|
+
} catch (error2) {
|
|
1134
|
+
console.warn("\u505C\u6B62\u65F6\u6E05\u7406\u7269\u7406\u7CFB\u7EDF\u5931\u8D25:", error2);
|
|
1135
|
+
}
|
|
929
1136
|
const mesh = sceneRef.current.children.find(
|
|
930
1137
|
(child) => child.type === "SkinnedMesh" || child.isSkinnedMesh
|
|
931
1138
|
);
|
|
@@ -944,7 +1151,7 @@ var MMDPlayerEnhanced = ({
|
|
|
944
1151
|
}
|
|
945
1152
|
}
|
|
946
1153
|
setNeedReset(true);
|
|
947
|
-
console.log("\
|
|
1154
|
+
console.log("\u2705 \u505C\u6B62\u64AD\u653E\u5E76\u6E05\u7406\u5B8C\u6210\uFF0CneedReset = true");
|
|
948
1155
|
};
|
|
949
1156
|
const handleResourceChange = (resourceId) => {
|
|
950
1157
|
console.log("\u{1F504} [MMDPlayerEnhanced] \u5207\u6362\u8D44\u6E90:", resourceId);
|