sa2kit 1.0.6 → 1.0.7
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 +65 -177
- package/dist/mmd/index.js.map +1 -1
- package/dist/mmd/index.mjs +65 -177
- package/dist/mmd/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/mmd/index.js
CHANGED
|
@@ -516,7 +516,6 @@ var MMDPlayerEnhanced = ({
|
|
|
516
516
|
};
|
|
517
517
|
}, [stage]);
|
|
518
518
|
const clearOldResources = () => {
|
|
519
|
-
console.log("\u{1F9F9} [MMDPlayerEnhanced] \u5F00\u59CB\u6E05\u9664\u65E7\u8D44\u6E90\uFF08\u589E\u5F3A\u6E05\u7406\uFF09");
|
|
520
519
|
if (!sceneRef.current) return;
|
|
521
520
|
if (isPlayingRef.current) {
|
|
522
521
|
isPlayingRef.current = false;
|
|
@@ -526,58 +525,64 @@ var MMDPlayerEnhanced = ({
|
|
|
526
525
|
audioRef.current.pause();
|
|
527
526
|
audioRef.current.currentTime = 0;
|
|
528
527
|
audioRef.current.onended = null;
|
|
528
|
+
audioRef.current.src = "";
|
|
529
|
+
audioRef.current.load();
|
|
529
530
|
audioRef.current = null;
|
|
530
531
|
}
|
|
531
532
|
if (helperRef.current) {
|
|
532
|
-
console.log("\u{1F9F9} \u5F00\u59CB\u6E05\u7406 MMDAnimationHelper");
|
|
533
533
|
try {
|
|
534
534
|
helperRef.current.enable("animation", false);
|
|
535
535
|
helperRef.current.enable("ik", false);
|
|
536
536
|
helperRef.current.enable("grant", false);
|
|
537
537
|
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
538
|
const helperObjects = helperRef.current.objects;
|
|
544
539
|
if (helperObjects && Array.isArray(helperObjects)) {
|
|
545
|
-
console.log(`\u{1F9F9} \u6E05\u9664 helper \u4E2D\u7684 ${helperObjects.length} \u4E2A\u5BF9\u8C61\uFF08\u5305\u62EC\u7269\u7406\u7CFB\u7EDF\uFF09`);
|
|
546
540
|
helperObjects.forEach((obj) => {
|
|
547
541
|
if (obj.physics) {
|
|
548
|
-
console.log("\u{1F527} \u6E05\u7406\u7269\u7406\u7CFB\u7EDF:", obj.mesh?.name || "unnamed");
|
|
549
542
|
try {
|
|
550
|
-
|
|
551
|
-
|
|
543
|
+
const physics = obj.physics;
|
|
544
|
+
if (physics.bodies && Array.isArray(physics.bodies)) {
|
|
545
|
+
physics.bodies.forEach((body) => {
|
|
546
|
+
if (physics.world && body) {
|
|
547
|
+
physics.world.removeRigidBody(body);
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
physics.bodies.length = 0;
|
|
552
551
|
}
|
|
553
|
-
if (
|
|
554
|
-
|
|
552
|
+
if (physics.constraints && Array.isArray(physics.constraints)) {
|
|
553
|
+
physics.constraints.forEach((constraint) => {
|
|
554
|
+
if (physics.world && constraint) {
|
|
555
|
+
physics.world.removeConstraint(constraint);
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
physics.constraints.length = 0;
|
|
559
|
+
}
|
|
560
|
+
if (physics.world) {
|
|
561
|
+
const world = physics.world;
|
|
555
562
|
while (world.getNumCollisionObjects() > 0) {
|
|
556
563
|
const body = world.getCollisionObjectArray().at(0);
|
|
557
564
|
world.removeCollisionObject(body);
|
|
558
565
|
}
|
|
559
566
|
}
|
|
567
|
+
if (physics.reset) physics.reset();
|
|
560
568
|
obj.physics = null;
|
|
561
|
-
} catch (
|
|
562
|
-
console.warn("\
|
|
569
|
+
} catch (e) {
|
|
570
|
+
console.warn("\u6E05\u7406\u7269\u7406\u7CFB\u7EDF\u5931\u8D25:", e);
|
|
563
571
|
}
|
|
564
572
|
}
|
|
565
573
|
});
|
|
566
574
|
helperObjects.length = 0;
|
|
567
575
|
}
|
|
568
576
|
} catch (error2) {
|
|
569
|
-
console.warn("\
|
|
577
|
+
console.warn("\u6E05\u7406 helper \u5931\u8D25:", error2);
|
|
570
578
|
}
|
|
571
579
|
helperRef.current = null;
|
|
572
|
-
console.log("\u2705 MMDAnimationHelper \u6E05\u7406\u5B8C\u6210");
|
|
573
580
|
}
|
|
574
581
|
if (sceneRef.current.background && sceneRef.current.background.isTexture) {
|
|
575
|
-
console.log("\u{1F9F9} \u6E05\u9664\u573A\u666F\u80CC\u666F\u8D34\u56FE");
|
|
576
582
|
sceneRef.current.background.dispose();
|
|
577
583
|
sceneRef.current.background = null;
|
|
578
584
|
}
|
|
579
585
|
if (sceneRef.current.environment && sceneRef.current.environment.isTexture) {
|
|
580
|
-
console.log("\u{1F9F9} \u6E05\u9664\u573A\u666F\u73AF\u5883\u8D34\u56FE");
|
|
581
586
|
sceneRef.current.environment.dispose();
|
|
582
587
|
sceneRef.current.environment = null;
|
|
583
588
|
}
|
|
@@ -591,26 +596,28 @@ var MMDPlayerEnhanced = ({
|
|
|
591
596
|
}
|
|
592
597
|
});
|
|
593
598
|
objectsToRemove.forEach((obj) => {
|
|
594
|
-
if (obj.parent)
|
|
595
|
-
obj.parent.remove(obj);
|
|
596
|
-
}
|
|
599
|
+
if (obj.parent) obj.parent.remove(obj);
|
|
597
600
|
if (obj.geometry) {
|
|
598
601
|
obj.geometry.dispose();
|
|
599
602
|
}
|
|
600
603
|
if (obj.material) {
|
|
601
|
-
const material = obj.material;
|
|
602
604
|
const disposeMaterial = (m) => {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
605
|
+
[
|
|
606
|
+
"map",
|
|
607
|
+
"emissiveMap",
|
|
608
|
+
"normalMap",
|
|
609
|
+
"bumpMap",
|
|
610
|
+
"specularMap",
|
|
611
|
+
"envMap",
|
|
612
|
+
"lightMap",
|
|
613
|
+
"aoMap",
|
|
614
|
+
"alphaMap"
|
|
615
|
+
].forEach((prop) => {
|
|
616
|
+
if (m[prop]) m[prop].dispose();
|
|
617
|
+
});
|
|
612
618
|
m.dispose();
|
|
613
619
|
};
|
|
620
|
+
const material = obj.material;
|
|
614
621
|
if (Array.isArray(material)) {
|
|
615
622
|
material.forEach(disposeMaterial);
|
|
616
623
|
} else {
|
|
@@ -618,29 +625,23 @@ var MMDPlayerEnhanced = ({
|
|
|
618
625
|
}
|
|
619
626
|
}
|
|
620
627
|
if (obj.skeleton) {
|
|
621
|
-
console.log("\u{1F9F9} \u6E05\u7406\u9AA8\u9ABC\u6570\u636E");
|
|
622
628
|
obj.skeleton = null;
|
|
623
629
|
}
|
|
624
630
|
});
|
|
625
631
|
clockRef.current = new THREE2__namespace.Clock();
|
|
626
632
|
vmdDataRef.current = null;
|
|
627
633
|
setNeedReset(false);
|
|
628
|
-
|
|
634
|
+
if (window.gc) {
|
|
635
|
+
try {
|
|
636
|
+
window.gc();
|
|
637
|
+
} catch (e) {
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
console.log(`\u2705 \u8D44\u6E90\u6E05\u7406\u5B8C\u6210 (${objectsToRemove.length} \u4E2A\u5BF9\u8C61)`);
|
|
629
641
|
};
|
|
630
642
|
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");
|
|
643
|
+
if (!sceneRef.current || !cameraRef.current) return;
|
|
644
|
+
if (isLoadedRef.current) return;
|
|
644
645
|
clearOldResources();
|
|
645
646
|
isLoadedRef.current = true;
|
|
646
647
|
const loadMMD = async () => {
|
|
@@ -653,63 +654,39 @@ var MMDPlayerEnhanced = ({
|
|
|
653
654
|
lastAnimationTimeRef.current = 0;
|
|
654
655
|
animationStoppedCountRef.current = 0;
|
|
655
656
|
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
657
|
setLoadingProgress(5);
|
|
662
658
|
await loadAmmo({
|
|
663
|
-
scriptPath:
|
|
664
|
-
wasmBasePath: ammoWasmPath
|
|
659
|
+
scriptPath: stage?.ammoPath || "/mikutalking/libs/ammo.wasm.js",
|
|
660
|
+
wasmBasePath: stage?.ammoWasmPath || "/mikutalking/libs/"
|
|
665
661
|
});
|
|
666
|
-
console.log("\u2705 [MMDPlayerEnhanced] Ammo.js \u52A0\u8F7D\u5B8C\u6210");
|
|
667
662
|
}
|
|
668
663
|
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);
|
|
664
|
+
const basePath = currentResources.modelPath.substring(0, currentResources.modelPath.lastIndexOf("/") + 1);
|
|
672
665
|
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;
|
|
666
|
+
if (url.startsWith("http://") || url.startsWith("https://")) return url;
|
|
667
|
+
if (url.startsWith("/")) return url;
|
|
668
|
+
return basePath + url;
|
|
684
669
|
});
|
|
685
670
|
const loader = new threeStdlib.MMDLoader(manager);
|
|
686
671
|
const helper = new threeStdlib.MMDAnimationHelper();
|
|
687
672
|
helperRef.current = helper;
|
|
688
673
|
setLoadingProgress(20);
|
|
689
674
|
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
675
|
const mesh = await new Promise((resolve, reject) => {
|
|
693
676
|
loader.load(
|
|
694
677
|
currentResources.modelPath,
|
|
695
678
|
(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`);
|
|
679
|
+
const loadTime = ((performance.now() - modelStartTime) / 1e3).toFixed(2);
|
|
680
|
+
console.log(`\u2705 \u6A21\u578B\u52A0\u8F7D\u5B8C\u6210 (${loadTime}s)`);
|
|
700
681
|
resolve(object);
|
|
701
682
|
},
|
|
702
683
|
(progress) => {
|
|
703
684
|
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)`);
|
|
685
|
+
setLoadingProgress(Math.min(progress.loaded / progress.total * 30 + 20, 50));
|
|
707
686
|
}
|
|
708
687
|
},
|
|
709
688
|
(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);
|
|
689
|
+
console.error("\u274C \u6A21\u578B\u52A0\u8F7D\u5931\u8D25:", error2);
|
|
713
690
|
reject(error2);
|
|
714
691
|
}
|
|
715
692
|
);
|
|
@@ -719,52 +696,21 @@ var MMDPlayerEnhanced = ({
|
|
|
719
696
|
}
|
|
720
697
|
sceneRef.current.add(mesh);
|
|
721
698
|
if (currentResources.stageModelPath) {
|
|
722
|
-
console.log("\u{1F3F0} \u5F00\u59CB\u52A0\u8F7D\u573A\u666F\u6A21\u578B:", currentResources.stageModelPath);
|
|
723
699
|
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
|
-
);
|
|
700
|
+
loader.load(currentResources.stageModelPath, resolve, void 0, reject);
|
|
736
701
|
});
|
|
737
702
|
sceneRef.current.add(stageMesh);
|
|
738
703
|
}
|
|
739
704
|
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
705
|
const textureLoader = new THREE2__namespace.TextureLoader();
|
|
743
706
|
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
|
-
);
|
|
707
|
+
textureLoader.load(currentResources.backgroundPath, resolve, void 0, reject);
|
|
760
708
|
});
|
|
761
709
|
backgroundTexture.colorSpace = THREE2__namespace.SRGBColorSpace;
|
|
762
710
|
if (stage?.backgroundType === "skybox") {
|
|
763
711
|
backgroundTexture.mapping = THREE2__namespace.EquirectangularReflectionMapping;
|
|
764
712
|
sceneRef.current.background = backgroundTexture;
|
|
765
713
|
sceneRef.current.environment = backgroundTexture;
|
|
766
|
-
} else if (stage?.backgroundType === "image") {
|
|
767
|
-
sceneRef.current.background = backgroundTexture;
|
|
768
714
|
} else {
|
|
769
715
|
sceneRef.current.background = backgroundTexture;
|
|
770
716
|
}
|
|
@@ -773,31 +719,17 @@ var MMDPlayerEnhanced = ({
|
|
|
773
719
|
let cameraVmd = null;
|
|
774
720
|
if (currentResources.motionPath) {
|
|
775
721
|
setLoadingProgress(60);
|
|
776
|
-
const motionStartTime = performance.now();
|
|
777
|
-
console.log("\u{1F483} \u5F00\u59CB\u52A0\u8F7D\u52A8\u4F5C:", currentResources.motionPath);
|
|
778
722
|
vmd = await new Promise((resolve, reject) => {
|
|
779
723
|
loader.loadAnimation(
|
|
780
724
|
currentResources.motionPath,
|
|
781
725
|
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
|
-
},
|
|
726
|
+
resolve,
|
|
788
727
|
(progress) => {
|
|
789
728
|
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)}%`);
|
|
729
|
+
setLoadingProgress(Math.min(progress.loaded / progress.total * 20 + 60, 80));
|
|
793
730
|
}
|
|
794
731
|
},
|
|
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
|
-
}
|
|
732
|
+
reject
|
|
801
733
|
);
|
|
802
734
|
});
|
|
803
735
|
helper.add(mesh, {
|
|
@@ -815,10 +747,6 @@ var MMDPlayerEnhanced = ({
|
|
|
815
747
|
}
|
|
816
748
|
if (maxDuration > 0) {
|
|
817
749
|
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
750
|
}
|
|
823
751
|
}
|
|
824
752
|
} else {
|
|
@@ -826,38 +754,18 @@ var MMDPlayerEnhanced = ({
|
|
|
826
754
|
}
|
|
827
755
|
if (currentResources.cameraPath && cameraRef.current) {
|
|
828
756
|
setLoadingProgress(80);
|
|
829
|
-
console.log("\u{1F4F7} \u5F00\u59CB\u52A0\u8F7D\u955C\u5934:", currentResources.cameraPath);
|
|
830
757
|
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
|
-
);
|
|
758
|
+
loader.loadAnimation(currentResources.cameraPath, cameraRef.current, resolve, void 0, reject);
|
|
844
759
|
});
|
|
845
760
|
helper.add(cameraRef.current, { animation: cameraVmd });
|
|
846
761
|
}
|
|
847
762
|
if (currentResources.audioPath) {
|
|
848
763
|
setLoadingProgress(90);
|
|
849
|
-
const audioStartTime = performance.now();
|
|
850
|
-
console.log("\u{1F3B5} \u5F00\u59CB\u52A0\u8F7D\u97F3\u9891:", currentResources.audioPath);
|
|
851
764
|
const audio = new Audio(currentResources.audioPath);
|
|
852
765
|
audio.volume = 0.5;
|
|
853
766
|
audio.loop = loop;
|
|
854
767
|
audioRef.current = audio;
|
|
855
768
|
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
769
|
audio.onended = () => {
|
|
862
770
|
if (!loop) {
|
|
863
771
|
setIsPlaying(false);
|
|
@@ -875,12 +783,7 @@ var MMDPlayerEnhanced = ({
|
|
|
875
783
|
}
|
|
876
784
|
setLoadingProgress(100);
|
|
877
785
|
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");
|
|
786
|
+
vmdDataRef.current = { mesh, vmd, cameraVmd };
|
|
884
787
|
if (shouldAutoPlayAfterReloadRef.current) {
|
|
885
788
|
shouldAutoPlayAfterReloadRef.current = false;
|
|
886
789
|
setTimeout(() => play(), 500);
|
|
@@ -899,64 +802,49 @@ var MMDPlayerEnhanced = ({
|
|
|
899
802
|
loadMMD();
|
|
900
803
|
}, [currentResources, stage?.enablePhysics, autoPlay, loop, onLoad, onError, reloadTrigger]);
|
|
901
804
|
const play = () => {
|
|
902
|
-
console.log("\u{1F3AC} [play] \u51FD\u6570\u88AB\u8C03\u7528\uFF0CneedReset =", needReset);
|
|
903
805
|
if (!helperRef.current && !needReset) return;
|
|
904
806
|
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
807
|
const { mesh, vmd, cameraVmd } = vmdDataRef.current;
|
|
907
808
|
if (helperRef.current) {
|
|
908
809
|
try {
|
|
909
810
|
const helperObjects = helperRef.current.objects;
|
|
910
811
|
if (helperObjects && Array.isArray(helperObjects)) {
|
|
911
812
|
helperObjects.length = 0;
|
|
912
|
-
console.log("\u{1F9F9} \u6E05\u7A7A\u4E86\u65E7 helper \u7684 objects \u6570\u7EC4");
|
|
913
813
|
}
|
|
914
814
|
} catch (error2) {
|
|
915
|
-
console.warn("\u26A0\uFE0F \u65E0\u6CD5\u6E05\u7A7A\u65E7 helper.objects:", error2);
|
|
916
815
|
}
|
|
917
816
|
}
|
|
918
817
|
const newHelper = new threeStdlib.MMDAnimationHelper();
|
|
919
818
|
helperRef.current = newHelper;
|
|
920
819
|
clockRef.current = new THREE2__namespace.Clock();
|
|
921
820
|
if (vmd && typeof vmd === "object") {
|
|
922
|
-
console.log("\u{1F4E6} \u91CD\u65B0\u6DFB\u52A0\u6A21\u578B\u52A8\u753B");
|
|
923
821
|
try {
|
|
924
822
|
newHelper.add(mesh, {
|
|
925
823
|
animation: vmd,
|
|
926
824
|
physics: stage?.enablePhysics !== false
|
|
927
825
|
});
|
|
928
|
-
console.log("\u2705 \u6A21\u578B\u52A8\u753B\u6DFB\u52A0\u6210\u529F");
|
|
929
826
|
} catch (error2) {
|
|
930
|
-
console.error("\u274C \u91CD\u65B0\u6DFB\u52A0\u6A21\u578B\u52A8\u753B\u5931\u8D25:", error2);
|
|
931
827
|
try {
|
|
932
828
|
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
829
|
} catch (innerError) {
|
|
935
|
-
console.error("\u274C \u6DFB\u52A0\u6A21\u578B\u4E5F\u5931\u8D25\u4E86:", innerError);
|
|
936
830
|
}
|
|
937
831
|
}
|
|
938
832
|
} else {
|
|
939
833
|
try {
|
|
940
834
|
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
835
|
} catch (error2) {
|
|
943
|
-
console.error("\u274C \u6DFB\u52A0\u6A21\u578B\u5931\u8D25:", error2);
|
|
944
836
|
}
|
|
945
837
|
}
|
|
946
838
|
if (cameraVmd && typeof cameraVmd === "object") {
|
|
947
|
-
console.log("\u{1F4F7} \u91CD\u65B0\u6DFB\u52A0\u76F8\u673A\u52A8\u753B");
|
|
948
839
|
try {
|
|
949
840
|
newHelper.add(cameraRef.current, { animation: cameraVmd });
|
|
950
|
-
console.log("\u2705 \u76F8\u673A\u52A8\u753B\u6DFB\u52A0\u6210\u529F");
|
|
951
841
|
} catch (error2) {
|
|
952
|
-
console.error("\u274C \u91CD\u65B0\u6DFB\u52A0\u76F8\u673A\u52A8\u753B\u5931\u8D25:", error2);
|
|
953
842
|
}
|
|
954
843
|
}
|
|
955
844
|
if (audioRef.current) {
|
|
956
845
|
audioRef.current.currentTime = 0;
|
|
957
846
|
}
|
|
958
847
|
setNeedReset(false);
|
|
959
|
-
console.log("\u2705 Helper \u91CD\u65B0\u521D\u59CB\u5316\u5B8C\u6210\uFF0C\u51C6\u5907\u4ECE\u7B2C\u4E00\u5E27\u64AD\u653E");
|
|
960
848
|
}
|
|
961
849
|
if (!helperRef.current) {
|
|
962
850
|
console.error("\u274C [play] helper \u4E0D\u5B58\u5728\uFF0C\u65E0\u6CD5\u64AD\u653E");
|