sa2kit 1.0.6 → 1.0.8
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 +109 -182
- package/dist/mmd/index.js.map +1 -1
- package/dist/mmd/index.mjs +109 -182
- package/dist/mmd/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/mmd/index.js
CHANGED
|
@@ -461,7 +461,18 @@ var MMDPlayerEnhanced = ({
|
|
|
461
461
|
animationIdRef.current = requestAnimationFrame(animate);
|
|
462
462
|
if (helperRef.current && isPlayingRef.current) {
|
|
463
463
|
const delta = clockRef.current.getDelta();
|
|
464
|
-
|
|
464
|
+
try {
|
|
465
|
+
helperRef.current.update(delta);
|
|
466
|
+
} catch (error2) {
|
|
467
|
+
if (error2.message && error2.message.includes("OOM")) {
|
|
468
|
+
console.error("\u274C \u7269\u7406\u5F15\u64CE\u5185\u5B58\u6EA2\u51FA\uFF0C\u505C\u6B62\u64AD\u653E");
|
|
469
|
+
isPlayingRef.current = false;
|
|
470
|
+
setIsPlaying(false);
|
|
471
|
+
onError?.(new Error("\u7269\u7406\u5F15\u64CE\u5185\u5B58\u6EA2\u51FA"));
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
throw error2;
|
|
475
|
+
}
|
|
465
476
|
if (!hasAudioRef.current && !loop && !animationEndedFiredRef.current) {
|
|
466
477
|
const currentTime = clockRef.current.getElapsedTime();
|
|
467
478
|
if (animationDurationRef.current > 0) {
|
|
@@ -516,7 +527,6 @@ var MMDPlayerEnhanced = ({
|
|
|
516
527
|
};
|
|
517
528
|
}, [stage]);
|
|
518
529
|
const clearOldResources = () => {
|
|
519
|
-
console.log("\u{1F9F9} [MMDPlayerEnhanced] \u5F00\u59CB\u6E05\u9664\u65E7\u8D44\u6E90\uFF08\u589E\u5F3A\u6E05\u7406\uFF09");
|
|
520
530
|
if (!sceneRef.current) return;
|
|
521
531
|
if (isPlayingRef.current) {
|
|
522
532
|
isPlayingRef.current = false;
|
|
@@ -526,58 +536,92 @@ var MMDPlayerEnhanced = ({
|
|
|
526
536
|
audioRef.current.pause();
|
|
527
537
|
audioRef.current.currentTime = 0;
|
|
528
538
|
audioRef.current.onended = null;
|
|
539
|
+
audioRef.current.src = "";
|
|
540
|
+
audioRef.current.load();
|
|
529
541
|
audioRef.current = null;
|
|
530
542
|
}
|
|
531
543
|
if (helperRef.current) {
|
|
532
|
-
console.log("\u{1F9F9} \u5F00\u59CB\u6E05\u7406 MMDAnimationHelper");
|
|
533
544
|
try {
|
|
534
545
|
helperRef.current.enable("animation", false);
|
|
535
546
|
helperRef.current.enable("ik", false);
|
|
536
547
|
helperRef.current.enable("grant", false);
|
|
537
548
|
helperRef.current.enable("physics", false);
|
|
538
|
-
console.log("\u2705 \u5DF2\u505C\u7528\u6240\u6709 helper \u7CFB\u7EDF");
|
|
539
|
-
} catch (error2) {
|
|
540
|
-
console.warn("\u26A0\uFE0F \u505C\u7528 helper \u7CFB\u7EDF\u5931\u8D25:", error2);
|
|
541
|
-
}
|
|
542
|
-
try {
|
|
543
549
|
const helperObjects = helperRef.current.objects;
|
|
544
550
|
if (helperObjects && Array.isArray(helperObjects)) {
|
|
545
|
-
|
|
551
|
+
const physicsWorldsToDestroy = /* @__PURE__ */ new Set();
|
|
546
552
|
helperObjects.forEach((obj) => {
|
|
547
553
|
if (obj.physics) {
|
|
548
|
-
console.log("\u{1F527} \u6E05\u7406\u7269\u7406\u7CFB\u7EDF:", obj.mesh?.name || "unnamed");
|
|
549
554
|
try {
|
|
550
|
-
|
|
551
|
-
|
|
555
|
+
const physics = obj.physics;
|
|
556
|
+
if (physics.world) {
|
|
557
|
+
physicsWorldsToDestroy.add(physics.world);
|
|
558
|
+
}
|
|
559
|
+
if (physics.bodies && Array.isArray(physics.bodies)) {
|
|
560
|
+
physics.bodies.forEach((body) => {
|
|
561
|
+
if (physics.world && body) {
|
|
562
|
+
try {
|
|
563
|
+
physics.world.removeRigidBody(body);
|
|
564
|
+
if (window.Ammo && body.destroy) {
|
|
565
|
+
body.destroy();
|
|
566
|
+
}
|
|
567
|
+
} catch (e) {
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
physics.bodies.length = 0;
|
|
572
|
+
physics.bodies = null;
|
|
552
573
|
}
|
|
553
|
-
if (
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
574
|
+
if (physics.constraints && Array.isArray(physics.constraints)) {
|
|
575
|
+
physics.constraints.forEach((constraint) => {
|
|
576
|
+
if (physics.world && constraint) {
|
|
577
|
+
try {
|
|
578
|
+
physics.world.removeConstraint(constraint);
|
|
579
|
+
if (window.Ammo && constraint.destroy) {
|
|
580
|
+
constraint.destroy();
|
|
581
|
+
}
|
|
582
|
+
} catch (e) {
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
physics.constraints.length = 0;
|
|
587
|
+
physics.constraints = null;
|
|
559
588
|
}
|
|
589
|
+
if (physics.reset) physics.reset();
|
|
590
|
+
physics.world = null;
|
|
560
591
|
obj.physics = null;
|
|
561
|
-
} catch (
|
|
562
|
-
console.warn("\
|
|
592
|
+
} catch (e) {
|
|
593
|
+
console.warn("\u6E05\u7406\u7269\u7406\u7CFB\u7EDF\u5931\u8D25:", e);
|
|
563
594
|
}
|
|
564
595
|
}
|
|
565
596
|
});
|
|
597
|
+
physicsWorldsToDestroy.forEach((world) => {
|
|
598
|
+
try {
|
|
599
|
+
while (world.getNumCollisionObjects() > 0) {
|
|
600
|
+
const obj = world.getCollisionObjectArray().at(0);
|
|
601
|
+
world.removeCollisionObject(obj);
|
|
602
|
+
if (obj && obj.destroy) {
|
|
603
|
+
obj.destroy();
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
if (world.destroy) {
|
|
607
|
+
world.destroy();
|
|
608
|
+
}
|
|
609
|
+
} catch (e) {
|
|
610
|
+
console.warn("\u9500\u6BC1\u7269\u7406\u4E16\u754C\u5931\u8D25:", e);
|
|
611
|
+
}
|
|
612
|
+
});
|
|
566
613
|
helperObjects.length = 0;
|
|
567
614
|
}
|
|
568
615
|
} catch (error2) {
|
|
569
|
-
console.warn("\
|
|
616
|
+
console.warn("\u6E05\u7406 helper \u5931\u8D25:", error2);
|
|
570
617
|
}
|
|
571
618
|
helperRef.current = null;
|
|
572
|
-
console.log("\u2705 MMDAnimationHelper \u6E05\u7406\u5B8C\u6210");
|
|
573
619
|
}
|
|
574
620
|
if (sceneRef.current.background && sceneRef.current.background.isTexture) {
|
|
575
|
-
console.log("\u{1F9F9} \u6E05\u9664\u573A\u666F\u80CC\u666F\u8D34\u56FE");
|
|
576
621
|
sceneRef.current.background.dispose();
|
|
577
622
|
sceneRef.current.background = null;
|
|
578
623
|
}
|
|
579
624
|
if (sceneRef.current.environment && sceneRef.current.environment.isTexture) {
|
|
580
|
-
console.log("\u{1F9F9} \u6E05\u9664\u573A\u666F\u73AF\u5883\u8D34\u56FE");
|
|
581
625
|
sceneRef.current.environment.dispose();
|
|
582
626
|
sceneRef.current.environment = null;
|
|
583
627
|
}
|
|
@@ -591,26 +635,28 @@ var MMDPlayerEnhanced = ({
|
|
|
591
635
|
}
|
|
592
636
|
});
|
|
593
637
|
objectsToRemove.forEach((obj) => {
|
|
594
|
-
if (obj.parent)
|
|
595
|
-
obj.parent.remove(obj);
|
|
596
|
-
}
|
|
638
|
+
if (obj.parent) obj.parent.remove(obj);
|
|
597
639
|
if (obj.geometry) {
|
|
598
640
|
obj.geometry.dispose();
|
|
599
641
|
}
|
|
600
642
|
if (obj.material) {
|
|
601
|
-
const material = obj.material;
|
|
602
643
|
const disposeMaterial = (m) => {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
644
|
+
[
|
|
645
|
+
"map",
|
|
646
|
+
"emissiveMap",
|
|
647
|
+
"normalMap",
|
|
648
|
+
"bumpMap",
|
|
649
|
+
"specularMap",
|
|
650
|
+
"envMap",
|
|
651
|
+
"lightMap",
|
|
652
|
+
"aoMap",
|
|
653
|
+
"alphaMap"
|
|
654
|
+
].forEach((prop) => {
|
|
655
|
+
if (m[prop]) m[prop].dispose();
|
|
656
|
+
});
|
|
612
657
|
m.dispose();
|
|
613
658
|
};
|
|
659
|
+
const material = obj.material;
|
|
614
660
|
if (Array.isArray(material)) {
|
|
615
661
|
material.forEach(disposeMaterial);
|
|
616
662
|
} else {
|
|
@@ -618,29 +664,23 @@ var MMDPlayerEnhanced = ({
|
|
|
618
664
|
}
|
|
619
665
|
}
|
|
620
666
|
if (obj.skeleton) {
|
|
621
|
-
console.log("\u{1F9F9} \u6E05\u7406\u9AA8\u9ABC\u6570\u636E");
|
|
622
667
|
obj.skeleton = null;
|
|
623
668
|
}
|
|
624
669
|
});
|
|
625
670
|
clockRef.current = new THREE2__namespace.Clock();
|
|
626
671
|
vmdDataRef.current = null;
|
|
627
672
|
setNeedReset(false);
|
|
628
|
-
|
|
673
|
+
if (window.gc) {
|
|
674
|
+
try {
|
|
675
|
+
window.gc();
|
|
676
|
+
} catch (e) {
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
console.log(`\u2705 \u8D44\u6E90\u6E05\u7406\u5B8C\u6210 (${objectsToRemove.length} \u4E2A\u5BF9\u8C61)`);
|
|
629
680
|
};
|
|
630
681
|
React2.useEffect(() => {
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
console.log("\u{1F50D} [MMDPlayerEnhanced] cameraRef.current:", cameraRef.current);
|
|
634
|
-
console.log("\u{1F50D} [MMDPlayerEnhanced] isLoadedRef.current:", isLoadedRef.current);
|
|
635
|
-
if (!sceneRef.current || !cameraRef.current) {
|
|
636
|
-
console.warn("\u26A0\uFE0F [MMDPlayerEnhanced] \u573A\u666F\u6216\u76F8\u673A\u672A\u521D\u59CB\u5316\uFF0C\u8DF3\u8FC7\u8D44\u6E90\u52A0\u8F7D");
|
|
637
|
-
return;
|
|
638
|
-
}
|
|
639
|
-
if (isLoadedRef.current) {
|
|
640
|
-
console.log("\u26A0\uFE0F [MMDPlayerEnhanced] \u8D44\u6E90\u5DF2\u52A0\u8F7D\uFF0C\u8DF3\u8FC7\u91CD\u590D\u52A0\u8F7D");
|
|
641
|
-
return;
|
|
642
|
-
}
|
|
643
|
-
console.log("\u2705 [MMDPlayerEnhanced] \u573A\u666F\u548C\u76F8\u673A\u5DF2\u5C31\u7EEA\uFF0C\u5F00\u59CB\u52A0\u8F7D\u8D44\u6E90");
|
|
682
|
+
if (!sceneRef.current || !cameraRef.current) return;
|
|
683
|
+
if (isLoadedRef.current) return;
|
|
644
684
|
clearOldResources();
|
|
645
685
|
isLoadedRef.current = true;
|
|
646
686
|
const loadMMD = async () => {
|
|
@@ -653,63 +693,39 @@ var MMDPlayerEnhanced = ({
|
|
|
653
693
|
lastAnimationTimeRef.current = 0;
|
|
654
694
|
animationStoppedCountRef.current = 0;
|
|
655
695
|
if (stage?.enablePhysics !== false) {
|
|
656
|
-
const ammoScriptPath = stage?.ammoPath || "/mikutalking/libs/ammo.wasm.js";
|
|
657
|
-
const ammoWasmPath = stage?.ammoWasmPath || "/mikutalking/libs/";
|
|
658
|
-
console.log("\u{1F527} [MMDPlayerEnhanced] \u68C0\u6D4B\u5230\u542F\u7528\u7269\u7406\uFF0C\u5F00\u59CB\u52A0\u8F7D Ammo.js");
|
|
659
|
-
console.log("\u{1F4C2} [MMDPlayerEnhanced] Ammo \u811A\u672C\u8DEF\u5F84:", ammoScriptPath);
|
|
660
|
-
console.log("\u{1F4C2} [MMDPlayerEnhanced] Ammo WASM \u8DEF\u5F84:", ammoWasmPath);
|
|
661
696
|
setLoadingProgress(5);
|
|
662
697
|
await loadAmmo({
|
|
663
|
-
scriptPath:
|
|
664
|
-
wasmBasePath: ammoWasmPath
|
|
698
|
+
scriptPath: stage?.ammoPath || "/mikutalking/libs/ammo.wasm.js",
|
|
699
|
+
wasmBasePath: stage?.ammoWasmPath || "/mikutalking/libs/"
|
|
665
700
|
});
|
|
666
|
-
console.log("\u2705 [MMDPlayerEnhanced] Ammo.js \u52A0\u8F7D\u5B8C\u6210");
|
|
667
701
|
}
|
|
668
702
|
const manager = new THREE2__namespace.LoadingManager();
|
|
669
|
-
const
|
|
670
|
-
const basePath = modelUrl.substring(0, modelUrl.lastIndexOf("/") + 1);
|
|
671
|
-
console.log("\u{1F4C2} [MMDPlayerEnhanced] \u6A21\u578B\u57FA\u7840\u8DEF\u5F84:", basePath);
|
|
703
|
+
const basePath = currentResources.modelPath.substring(0, currentResources.modelPath.lastIndexOf("/") + 1);
|
|
672
704
|
manager.setURLModifier((url) => {
|
|
673
|
-
if (url.startsWith("http://") || url.startsWith("https://"))
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
}
|
|
677
|
-
if (url.startsWith("/")) {
|
|
678
|
-
console.log("\u{1F517} [MMDPlayerEnhanced] \u4F7F\u7528\u7EDD\u5BF9\u8DEF\u5F84:", url);
|
|
679
|
-
return url;
|
|
680
|
-
}
|
|
681
|
-
const fullUrl = basePath + url;
|
|
682
|
-
console.log("\u{1F517} [MMDPlayerEnhanced] \u76F8\u5BF9\u8DEF\u5F84\u8F6C\u6362:", url, "->", fullUrl);
|
|
683
|
-
return fullUrl;
|
|
705
|
+
if (url.startsWith("http://") || url.startsWith("https://")) return url;
|
|
706
|
+
if (url.startsWith("/")) return url;
|
|
707
|
+
return basePath + url;
|
|
684
708
|
});
|
|
685
709
|
const loader = new threeStdlib.MMDLoader(manager);
|
|
686
710
|
const helper = new threeStdlib.MMDAnimationHelper();
|
|
687
711
|
helperRef.current = helper;
|
|
688
712
|
setLoadingProgress(20);
|
|
689
713
|
const modelStartTime = performance.now();
|
|
690
|
-
console.log("\u{1F3AD} \u5F00\u59CB\u52A0\u8F7D\u6A21\u578B:", currentResources.modelPath);
|
|
691
|
-
console.log("\u{1F4CA} [\u6027\u80FD] \u6A21\u578B\u52A0\u8F7D\u5F00\u59CB\u65F6\u95F4:", (/* @__PURE__ */ new Date()).toISOString());
|
|
692
714
|
const mesh = await new Promise((resolve, reject) => {
|
|
693
715
|
loader.load(
|
|
694
716
|
currentResources.modelPath,
|
|
695
717
|
(object) => {
|
|
696
|
-
const
|
|
697
|
-
|
|
698
|
-
console.log(`\u2705 \u6A21\u578B\u52A0\u8F7D\u6210\u529F (\u8017\u65F6: ${modelLoadTime}\u79D2)`);
|
|
699
|
-
console.log(`\u{1F4CA} [\u6027\u80FD] \u6A21\u578B\u5927\u5C0F: ${object.geometry ? (object.geometry.attributes.position.count * 3 * 4 / 1024 / 1024).toFixed(2) : "N/A"} MB`);
|
|
718
|
+
const loadTime = ((performance.now() - modelStartTime) / 1e3).toFixed(2);
|
|
719
|
+
console.log(`\u2705 \u6A21\u578B\u52A0\u8F7D\u5B8C\u6210 (${loadTime}s)`);
|
|
700
720
|
resolve(object);
|
|
701
721
|
},
|
|
702
722
|
(progress) => {
|
|
703
723
|
if (progress.total > 0) {
|
|
704
|
-
|
|
705
|
-
setLoadingProgress(Math.min(percent, 50));
|
|
706
|
-
console.log(`\u{1F4E5} \u6A21\u578B\u52A0\u8F7D\u8FDB\u5EA6: ${(progress.loaded / progress.total * 100).toFixed(1)}% (${(progress.loaded / 1024 / 1024).toFixed(2)}MB / ${(progress.total / 1024 / 1024).toFixed(2)}MB)`);
|
|
724
|
+
setLoadingProgress(Math.min(progress.loaded / progress.total * 30 + 20, 50));
|
|
707
725
|
}
|
|
708
726
|
},
|
|
709
727
|
(error2) => {
|
|
710
|
-
|
|
711
|
-
const modelLoadTime = ((modelEndTime - modelStartTime) / 1e3).toFixed(2);
|
|
712
|
-
console.error(`\u274C \u6A21\u578B\u52A0\u8F7D\u5931\u8D25 (\u8017\u65F6: ${modelLoadTime}\u79D2):`, error2);
|
|
728
|
+
console.error("\u274C \u6A21\u578B\u52A0\u8F7D\u5931\u8D25:", error2);
|
|
713
729
|
reject(error2);
|
|
714
730
|
}
|
|
715
731
|
);
|
|
@@ -719,52 +735,21 @@ var MMDPlayerEnhanced = ({
|
|
|
719
735
|
}
|
|
720
736
|
sceneRef.current.add(mesh);
|
|
721
737
|
if (currentResources.stageModelPath) {
|
|
722
|
-
console.log("\u{1F3F0} \u5F00\u59CB\u52A0\u8F7D\u573A\u666F\u6A21\u578B:", currentResources.stageModelPath);
|
|
723
738
|
const stageMesh = await new Promise((resolve, reject) => {
|
|
724
|
-
loader.load(
|
|
725
|
-
currentResources.stageModelPath,
|
|
726
|
-
(object) => {
|
|
727
|
-
console.log("\u2705 \u573A\u666F\u6A21\u578B\u52A0\u8F7D\u6210\u529F");
|
|
728
|
-
resolve(object);
|
|
729
|
-
},
|
|
730
|
-
void 0,
|
|
731
|
-
(error2) => {
|
|
732
|
-
console.error("\u274C \u573A\u666F\u6A21\u578B\u52A0\u8F7D\u5931\u8D25:", error2);
|
|
733
|
-
reject(error2);
|
|
734
|
-
}
|
|
735
|
-
);
|
|
739
|
+
loader.load(currentResources.stageModelPath, resolve, void 0, reject);
|
|
736
740
|
});
|
|
737
741
|
sceneRef.current.add(stageMesh);
|
|
738
742
|
}
|
|
739
743
|
if (currentResources.backgroundPath && sceneRef.current) {
|
|
740
|
-
const bgStartTime = performance.now();
|
|
741
|
-
console.log("\u{1F5BC}\uFE0F \u5F00\u59CB\u52A0\u8F7D\u80CC\u666F\u56FE\u7247:", currentResources.backgroundPath);
|
|
742
744
|
const textureLoader = new THREE2__namespace.TextureLoader();
|
|
743
745
|
const backgroundTexture = await new Promise((resolve, reject) => {
|
|
744
|
-
textureLoader.load(
|
|
745
|
-
currentResources.backgroundPath,
|
|
746
|
-
(texture) => {
|
|
747
|
-
const bgEndTime = performance.now();
|
|
748
|
-
const bgLoadTime = ((bgEndTime - bgStartTime) / 1e3).toFixed(2);
|
|
749
|
-
console.log(`\u2705 \u80CC\u666F\u56FE\u7247\u52A0\u8F7D\u6210\u529F (\u8017\u65F6: ${bgLoadTime}\u79D2, \u5C3A\u5BF8: ${texture.image.width}x${texture.image.height})`);
|
|
750
|
-
resolve(texture);
|
|
751
|
-
},
|
|
752
|
-
void 0,
|
|
753
|
-
(err) => {
|
|
754
|
-
const bgEndTime = performance.now();
|
|
755
|
-
const bgLoadTime = ((bgEndTime - bgStartTime) / 1e3).toFixed(2);
|
|
756
|
-
console.error(`\u274C \u80CC\u666F\u56FE\u7247\u52A0\u8F7D\u5931\u8D25 (\u8017\u65F6: ${bgLoadTime}\u79D2):`, err);
|
|
757
|
-
reject(err);
|
|
758
|
-
}
|
|
759
|
-
);
|
|
746
|
+
textureLoader.load(currentResources.backgroundPath, resolve, void 0, reject);
|
|
760
747
|
});
|
|
761
748
|
backgroundTexture.colorSpace = THREE2__namespace.SRGBColorSpace;
|
|
762
749
|
if (stage?.backgroundType === "skybox") {
|
|
763
750
|
backgroundTexture.mapping = THREE2__namespace.EquirectangularReflectionMapping;
|
|
764
751
|
sceneRef.current.background = backgroundTexture;
|
|
765
752
|
sceneRef.current.environment = backgroundTexture;
|
|
766
|
-
} else if (stage?.backgroundType === "image") {
|
|
767
|
-
sceneRef.current.background = backgroundTexture;
|
|
768
753
|
} else {
|
|
769
754
|
sceneRef.current.background = backgroundTexture;
|
|
770
755
|
}
|
|
@@ -773,31 +758,17 @@ var MMDPlayerEnhanced = ({
|
|
|
773
758
|
let cameraVmd = null;
|
|
774
759
|
if (currentResources.motionPath) {
|
|
775
760
|
setLoadingProgress(60);
|
|
776
|
-
const motionStartTime = performance.now();
|
|
777
|
-
console.log("\u{1F483} \u5F00\u59CB\u52A0\u8F7D\u52A8\u4F5C:", currentResources.motionPath);
|
|
778
761
|
vmd = await new Promise((resolve, reject) => {
|
|
779
762
|
loader.loadAnimation(
|
|
780
763
|
currentResources.motionPath,
|
|
781
764
|
mesh,
|
|
782
|
-
|
|
783
|
-
const motionEndTime = performance.now();
|
|
784
|
-
const motionLoadTime = ((motionEndTime - motionStartTime) / 1e3).toFixed(2);
|
|
785
|
-
console.log(`\u2705 \u52A8\u4F5C\u52A0\u8F7D\u6210\u529F (\u8017\u65F6: ${motionLoadTime}\u79D2)`);
|
|
786
|
-
resolve(vmdObject);
|
|
787
|
-
},
|
|
765
|
+
resolve,
|
|
788
766
|
(progress) => {
|
|
789
767
|
if (progress.total > 0) {
|
|
790
|
-
|
|
791
|
-
setLoadingProgress(Math.min(percent, 80));
|
|
792
|
-
console.log(`\u{1F4E5} \u52A8\u4F5C\u52A0\u8F7D\u8FDB\u5EA6: ${(progress.loaded / progress.total * 100).toFixed(1)}%`);
|
|
768
|
+
setLoadingProgress(Math.min(progress.loaded / progress.total * 20 + 60, 80));
|
|
793
769
|
}
|
|
794
770
|
},
|
|
795
|
-
|
|
796
|
-
const motionEndTime = performance.now();
|
|
797
|
-
const motionLoadTime = ((motionEndTime - motionStartTime) / 1e3).toFixed(2);
|
|
798
|
-
console.error(`\u274C \u52A8\u4F5C\u52A0\u8F7D\u5931\u8D25 (\u8017\u65F6: ${motionLoadTime}\u79D2):`, error2);
|
|
799
|
-
reject(error2);
|
|
800
|
-
}
|
|
771
|
+
reject
|
|
801
772
|
);
|
|
802
773
|
});
|
|
803
774
|
helper.add(mesh, {
|
|
@@ -815,10 +786,6 @@ var MMDPlayerEnhanced = ({
|
|
|
815
786
|
}
|
|
816
787
|
if (maxDuration > 0) {
|
|
817
788
|
animationDurationRef.current = maxDuration;
|
|
818
|
-
console.log("\u23F1\uFE0F \u52A8\u753B\u65F6\u957F:", maxDuration, "\u79D2");
|
|
819
|
-
} else {
|
|
820
|
-
console.warn("\u26A0\uFE0F \u65E0\u6CD5\u83B7\u53D6\u52A8\u753B\u65F6\u957F\uFF0C\u5C06\u65E0\u6CD5\u81EA\u52A8\u68C0\u6D4B\u52A8\u753B\u7ED3\u675F");
|
|
821
|
-
console.log("\u{1F4CB} VMD \u6570\u636E\u7ED3\u6784:", vmd);
|
|
822
789
|
}
|
|
823
790
|
}
|
|
824
791
|
} else {
|
|
@@ -826,38 +793,18 @@ var MMDPlayerEnhanced = ({
|
|
|
826
793
|
}
|
|
827
794
|
if (currentResources.cameraPath && cameraRef.current) {
|
|
828
795
|
setLoadingProgress(80);
|
|
829
|
-
console.log("\u{1F4F7} \u5F00\u59CB\u52A0\u8F7D\u955C\u5934:", currentResources.cameraPath);
|
|
830
796
|
cameraVmd = await new Promise((resolve, reject) => {
|
|
831
|
-
loader.loadAnimation(
|
|
832
|
-
currentResources.cameraPath,
|
|
833
|
-
cameraRef.current,
|
|
834
|
-
(vmdObject) => {
|
|
835
|
-
console.log("\u2705 \u955C\u5934\u52A0\u8F7D\u6210\u529F");
|
|
836
|
-
resolve(vmdObject);
|
|
837
|
-
},
|
|
838
|
-
void 0,
|
|
839
|
-
(error2) => {
|
|
840
|
-
console.error("\u274C \u955C\u5934\u52A0\u8F7D\u5931\u8D25:", error2);
|
|
841
|
-
reject(error2);
|
|
842
|
-
}
|
|
843
|
-
);
|
|
797
|
+
loader.loadAnimation(currentResources.cameraPath, cameraRef.current, resolve, void 0, reject);
|
|
844
798
|
});
|
|
845
799
|
helper.add(cameraRef.current, { animation: cameraVmd });
|
|
846
800
|
}
|
|
847
801
|
if (currentResources.audioPath) {
|
|
848
802
|
setLoadingProgress(90);
|
|
849
|
-
const audioStartTime = performance.now();
|
|
850
|
-
console.log("\u{1F3B5} \u5F00\u59CB\u52A0\u8F7D\u97F3\u9891:", currentResources.audioPath);
|
|
851
803
|
const audio = new Audio(currentResources.audioPath);
|
|
852
804
|
audio.volume = 0.5;
|
|
853
805
|
audio.loop = loop;
|
|
854
806
|
audioRef.current = audio;
|
|
855
807
|
hasAudioRef.current = true;
|
|
856
|
-
audio.onloadedmetadata = () => {
|
|
857
|
-
const audioEndTime = performance.now();
|
|
858
|
-
const audioLoadTime = ((audioEndTime - audioStartTime) / 1e3).toFixed(2);
|
|
859
|
-
console.log(`\u2705 \u97F3\u9891\u52A0\u8F7D\u6210\u529F (\u8017\u65F6: ${audioLoadTime}\u79D2, \u65F6\u957F: ${audio.duration.toFixed(2)}\u79D2)`);
|
|
860
|
-
};
|
|
861
808
|
audio.onended = () => {
|
|
862
809
|
if (!loop) {
|
|
863
810
|
setIsPlaying(false);
|
|
@@ -875,12 +822,7 @@ var MMDPlayerEnhanced = ({
|
|
|
875
822
|
}
|
|
876
823
|
setLoadingProgress(100);
|
|
877
824
|
setLoading(false);
|
|
878
|
-
vmdDataRef.current = {
|
|
879
|
-
mesh,
|
|
880
|
-
vmd,
|
|
881
|
-
cameraVmd
|
|
882
|
-
};
|
|
883
|
-
console.log("\u{1F389} \u6240\u6709\u8D44\u6E90\u52A0\u8F7D\u5B8C\u6210\uFF01");
|
|
825
|
+
vmdDataRef.current = { mesh, vmd, cameraVmd };
|
|
884
826
|
if (shouldAutoPlayAfterReloadRef.current) {
|
|
885
827
|
shouldAutoPlayAfterReloadRef.current = false;
|
|
886
828
|
setTimeout(() => play(), 500);
|
|
@@ -899,64 +841,49 @@ var MMDPlayerEnhanced = ({
|
|
|
899
841
|
loadMMD();
|
|
900
842
|
}, [currentResources, stage?.enablePhysics, autoPlay, loop, onLoad, onError, reloadTrigger]);
|
|
901
843
|
const play = () => {
|
|
902
|
-
console.log("\u{1F3AC} [play] \u51FD\u6570\u88AB\u8C03\u7528\uFF0CneedReset =", needReset);
|
|
903
844
|
if (!helperRef.current && !needReset) return;
|
|
904
845
|
if (needReset && vmdDataRef.current && sceneRef.current && cameraRef.current) {
|
|
905
|
-
console.log("\u{1F504} \u68C0\u6D4B\u5230\u9700\u8981\u91CD\u7F6E\uFF0C\u91CD\u65B0\u521D\u59CB\u5316 helper\uFF08\u4FDD\u7559\u6A21\u578B\uFF09");
|
|
906
846
|
const { mesh, vmd, cameraVmd } = vmdDataRef.current;
|
|
907
847
|
if (helperRef.current) {
|
|
908
848
|
try {
|
|
909
849
|
const helperObjects = helperRef.current.objects;
|
|
910
850
|
if (helperObjects && Array.isArray(helperObjects)) {
|
|
911
851
|
helperObjects.length = 0;
|
|
912
|
-
console.log("\u{1F9F9} \u6E05\u7A7A\u4E86\u65E7 helper \u7684 objects \u6570\u7EC4");
|
|
913
852
|
}
|
|
914
853
|
} catch (error2) {
|
|
915
|
-
console.warn("\u26A0\uFE0F \u65E0\u6CD5\u6E05\u7A7A\u65E7 helper.objects:", error2);
|
|
916
854
|
}
|
|
917
855
|
}
|
|
918
856
|
const newHelper = new threeStdlib.MMDAnimationHelper();
|
|
919
857
|
helperRef.current = newHelper;
|
|
920
858
|
clockRef.current = new THREE2__namespace.Clock();
|
|
921
859
|
if (vmd && typeof vmd === "object") {
|
|
922
|
-
console.log("\u{1F4E6} \u91CD\u65B0\u6DFB\u52A0\u6A21\u578B\u52A8\u753B");
|
|
923
860
|
try {
|
|
924
861
|
newHelper.add(mesh, {
|
|
925
862
|
animation: vmd,
|
|
926
863
|
physics: stage?.enablePhysics !== false
|
|
927
864
|
});
|
|
928
|
-
console.log("\u2705 \u6A21\u578B\u52A8\u753B\u6DFB\u52A0\u6210\u529F");
|
|
929
865
|
} catch (error2) {
|
|
930
|
-
console.error("\u274C \u91CD\u65B0\u6DFB\u52A0\u6A21\u578B\u52A8\u753B\u5931\u8D25:", error2);
|
|
931
866
|
try {
|
|
932
867
|
newHelper.add(mesh, { physics: stage?.enablePhysics !== false });
|
|
933
|
-
console.log("\u2705 \u4EC5\u6DFB\u52A0\u6A21\u578B\u548C\u7269\u7406\uFF08\u65E0\u52A8\u753B\uFF09");
|
|
934
868
|
} catch (innerError) {
|
|
935
|
-
console.error("\u274C \u6DFB\u52A0\u6A21\u578B\u4E5F\u5931\u8D25\u4E86:", innerError);
|
|
936
869
|
}
|
|
937
870
|
}
|
|
938
871
|
} else {
|
|
939
872
|
try {
|
|
940
873
|
newHelper.add(mesh, { physics: stage?.enablePhysics !== false });
|
|
941
|
-
console.log("\u2705 \u4EC5\u6DFB\u52A0\u6A21\u578B\u548C\u7269\u7406\uFF08\u65E0\u52A8\u753B\u6570\u636E\uFF09");
|
|
942
874
|
} catch (error2) {
|
|
943
|
-
console.error("\u274C \u6DFB\u52A0\u6A21\u578B\u5931\u8D25:", error2);
|
|
944
875
|
}
|
|
945
876
|
}
|
|
946
877
|
if (cameraVmd && typeof cameraVmd === "object") {
|
|
947
|
-
console.log("\u{1F4F7} \u91CD\u65B0\u6DFB\u52A0\u76F8\u673A\u52A8\u753B");
|
|
948
878
|
try {
|
|
949
879
|
newHelper.add(cameraRef.current, { animation: cameraVmd });
|
|
950
|
-
console.log("\u2705 \u76F8\u673A\u52A8\u753B\u6DFB\u52A0\u6210\u529F");
|
|
951
880
|
} catch (error2) {
|
|
952
|
-
console.error("\u274C \u91CD\u65B0\u6DFB\u52A0\u76F8\u673A\u52A8\u753B\u5931\u8D25:", error2);
|
|
953
881
|
}
|
|
954
882
|
}
|
|
955
883
|
if (audioRef.current) {
|
|
956
884
|
audioRef.current.currentTime = 0;
|
|
957
885
|
}
|
|
958
886
|
setNeedReset(false);
|
|
959
|
-
console.log("\u2705 Helper \u91CD\u65B0\u521D\u59CB\u5316\u5B8C\u6210\uFF0C\u51C6\u5907\u4ECE\u7B2C\u4E00\u5E27\u64AD\u653E");
|
|
960
887
|
}
|
|
961
888
|
if (!helperRef.current) {
|
|
962
889
|
console.error("\u274C [play] helper \u4E0D\u5B58\u5728\uFF0C\u65E0\u6CD5\u64AD\u653E");
|