sa2kit 1.0.4 → 1.0.6
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 +142 -18
- package/dist/mmd/index.js.map +1 -1
- package/dist/mmd/index.mjs +142 -18
- package/dist/mmd/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/mmd/index.js
CHANGED
|
@@ -516,7 +516,7 @@ var MMDPlayerEnhanced = ({
|
|
|
516
516
|
};
|
|
517
517
|
}, [stage]);
|
|
518
518
|
const clearOldResources = () => {
|
|
519
|
-
console.log("\u{1F9F9} [MMDPlayerEnhanced] \u5F00\u59CB\u6E05\u9664\u65E7\u8D44\u6E90");
|
|
519
|
+
console.log("\u{1F9F9} [MMDPlayerEnhanced] \u5F00\u59CB\u6E05\u9664\u65E7\u8D44\u6E90\uFF08\u589E\u5F3A\u6E05\u7406\uFF09");
|
|
520
520
|
if (!sceneRef.current) return;
|
|
521
521
|
if (isPlayingRef.current) {
|
|
522
522
|
isPlayingRef.current = false;
|
|
@@ -525,10 +525,61 @@ var MMDPlayerEnhanced = ({
|
|
|
525
525
|
if (audioRef.current) {
|
|
526
526
|
audioRef.current.pause();
|
|
527
527
|
audioRef.current.currentTime = 0;
|
|
528
|
+
audioRef.current.onended = null;
|
|
528
529
|
audioRef.current = null;
|
|
529
530
|
}
|
|
530
531
|
if (helperRef.current) {
|
|
532
|
+
console.log("\u{1F9F9} \u5F00\u59CB\u6E05\u7406 MMDAnimationHelper");
|
|
533
|
+
try {
|
|
534
|
+
helperRef.current.enable("animation", false);
|
|
535
|
+
helperRef.current.enable("ik", false);
|
|
536
|
+
helperRef.current.enable("grant", false);
|
|
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
|
+
const helperObjects = helperRef.current.objects;
|
|
544
|
+
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
|
+
helperObjects.forEach((obj) => {
|
|
547
|
+
if (obj.physics) {
|
|
548
|
+
console.log("\u{1F527} \u6E05\u7406\u7269\u7406\u7CFB\u7EDF:", obj.mesh?.name || "unnamed");
|
|
549
|
+
try {
|
|
550
|
+
if (obj.physics.reset) {
|
|
551
|
+
obj.physics.reset();
|
|
552
|
+
}
|
|
553
|
+
if (obj.physics.world) {
|
|
554
|
+
const world = obj.physics.world;
|
|
555
|
+
while (world.getNumCollisionObjects() > 0) {
|
|
556
|
+
const body = world.getCollisionObjectArray().at(0);
|
|
557
|
+
world.removeCollisionObject(body);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
obj.physics = null;
|
|
561
|
+
} catch (physicsError) {
|
|
562
|
+
console.warn("\u26A0\uFE0F \u6E05\u7406\u7269\u7406\u7CFB\u7EDF\u5931\u8D25:", physicsError);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
helperObjects.length = 0;
|
|
567
|
+
}
|
|
568
|
+
} catch (error2) {
|
|
569
|
+
console.warn("\u26A0\uFE0F \u65E0\u6CD5\u8BBF\u95EE helper.objects:", error2);
|
|
570
|
+
}
|
|
531
571
|
helperRef.current = null;
|
|
572
|
+
console.log("\u2705 MMDAnimationHelper \u6E05\u7406\u5B8C\u6210");
|
|
573
|
+
}
|
|
574
|
+
if (sceneRef.current.background && sceneRef.current.background.isTexture) {
|
|
575
|
+
console.log("\u{1F9F9} \u6E05\u9664\u573A\u666F\u80CC\u666F\u8D34\u56FE");
|
|
576
|
+
sceneRef.current.background.dispose();
|
|
577
|
+
sceneRef.current.background = null;
|
|
578
|
+
}
|
|
579
|
+
if (sceneRef.current.environment && sceneRef.current.environment.isTexture) {
|
|
580
|
+
console.log("\u{1F9F9} \u6E05\u9664\u573A\u666F\u73AF\u5883\u8D34\u56FE");
|
|
581
|
+
sceneRef.current.environment.dispose();
|
|
582
|
+
sceneRef.current.environment = null;
|
|
532
583
|
}
|
|
533
584
|
const objectsToRemove = [];
|
|
534
585
|
sceneRef.current.traverse((child) => {
|
|
@@ -547,16 +598,34 @@ var MMDPlayerEnhanced = ({
|
|
|
547
598
|
obj.geometry.dispose();
|
|
548
599
|
}
|
|
549
600
|
if (obj.material) {
|
|
550
|
-
|
|
551
|
-
|
|
601
|
+
const material = obj.material;
|
|
602
|
+
const disposeMaterial = (m) => {
|
|
603
|
+
if (m.map) m.map.dispose();
|
|
604
|
+
if (m.emissiveMap) m.emissiveMap.dispose();
|
|
605
|
+
if (m.normalMap) m.normalMap.dispose();
|
|
606
|
+
if (m.bumpMap) m.bumpMap.dispose();
|
|
607
|
+
if (m.specularMap) m.specularMap.dispose();
|
|
608
|
+
if (m.envMap) m.envMap.dispose();
|
|
609
|
+
if (m.lightMap) m.lightMap.dispose();
|
|
610
|
+
if (m.aoMap) m.aoMap.dispose();
|
|
611
|
+
if (m.alphaMap) m.alphaMap.dispose();
|
|
612
|
+
m.dispose();
|
|
613
|
+
};
|
|
614
|
+
if (Array.isArray(material)) {
|
|
615
|
+
material.forEach(disposeMaterial);
|
|
552
616
|
} else {
|
|
553
|
-
|
|
617
|
+
disposeMaterial(material);
|
|
554
618
|
}
|
|
555
619
|
}
|
|
620
|
+
if (obj.skeleton) {
|
|
621
|
+
console.log("\u{1F9F9} \u6E05\u7406\u9AA8\u9ABC\u6570\u636E");
|
|
622
|
+
obj.skeleton = null;
|
|
623
|
+
}
|
|
556
624
|
});
|
|
557
625
|
clockRef.current = new THREE2__namespace.Clock();
|
|
558
626
|
vmdDataRef.current = null;
|
|
559
|
-
|
|
627
|
+
setNeedReset(false);
|
|
628
|
+
console.log(`\u2705 [MMDPlayerEnhanced] \u5DF2\u6E05\u9664 ${objectsToRemove.length} \u4E2A\u5BF9\u8C61\uFF08\u589E\u5F3A\u6E05\u7406\u5B8C\u6210\uFF09`);
|
|
560
629
|
};
|
|
561
630
|
React2.useEffect(() => {
|
|
562
631
|
console.log("\u{1F4E6} [MMDPlayerEnhanced] \u8D44\u6E90\u52A0\u8F7D useEffect \u89E6\u53D1");
|
|
@@ -617,22 +686,30 @@ var MMDPlayerEnhanced = ({
|
|
|
617
686
|
const helper = new threeStdlib.MMDAnimationHelper();
|
|
618
687
|
helperRef.current = helper;
|
|
619
688
|
setLoadingProgress(20);
|
|
689
|
+
const modelStartTime = performance.now();
|
|
620
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());
|
|
621
692
|
const mesh = await new Promise((resolve, reject) => {
|
|
622
693
|
loader.load(
|
|
623
694
|
currentResources.modelPath,
|
|
624
695
|
(object) => {
|
|
625
|
-
|
|
696
|
+
const modelEndTime = performance.now();
|
|
697
|
+
const modelLoadTime = ((modelEndTime - modelStartTime) / 1e3).toFixed(2);
|
|
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`);
|
|
626
700
|
resolve(object);
|
|
627
701
|
},
|
|
628
702
|
(progress) => {
|
|
629
703
|
if (progress.total > 0) {
|
|
630
704
|
const percent = progress.loaded / progress.total * 30 + 20;
|
|
631
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)`);
|
|
632
707
|
}
|
|
633
708
|
},
|
|
634
709
|
(error2) => {
|
|
635
|
-
|
|
710
|
+
const modelEndTime = performance.now();
|
|
711
|
+
const modelLoadTime = ((modelEndTime - modelStartTime) / 1e3).toFixed(2);
|
|
712
|
+
console.error(`\u274C \u6A21\u578B\u52A0\u8F7D\u5931\u8D25 (\u8017\u65F6: ${modelLoadTime}\u79D2):`, error2);
|
|
636
713
|
reject(error2);
|
|
637
714
|
}
|
|
638
715
|
);
|
|
@@ -660,14 +737,25 @@ var MMDPlayerEnhanced = ({
|
|
|
660
737
|
sceneRef.current.add(stageMesh);
|
|
661
738
|
}
|
|
662
739
|
if (currentResources.backgroundPath && sceneRef.current) {
|
|
740
|
+
const bgStartTime = performance.now();
|
|
663
741
|
console.log("\u{1F5BC}\uFE0F \u5F00\u59CB\u52A0\u8F7D\u80CC\u666F\u56FE\u7247:", currentResources.backgroundPath);
|
|
664
742
|
const textureLoader = new THREE2__namespace.TextureLoader();
|
|
665
743
|
const backgroundTexture = await new Promise((resolve, reject) => {
|
|
666
744
|
textureLoader.load(
|
|
667
745
|
currentResources.backgroundPath,
|
|
668
|
-
(texture) =>
|
|
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
|
+
},
|
|
669
752
|
void 0,
|
|
670
|
-
(err) =>
|
|
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
|
+
}
|
|
671
759
|
);
|
|
672
760
|
});
|
|
673
761
|
backgroundTexture.colorSpace = THREE2__namespace.SRGBColorSpace;
|
|
@@ -680,29 +768,34 @@ var MMDPlayerEnhanced = ({
|
|
|
680
768
|
} else {
|
|
681
769
|
sceneRef.current.background = backgroundTexture;
|
|
682
770
|
}
|
|
683
|
-
console.log("\u2705 \u80CC\u666F\u56FE\u7247\u52A0\u8F7D\u6210\u529F");
|
|
684
771
|
}
|
|
685
772
|
let vmd = null;
|
|
686
773
|
let cameraVmd = null;
|
|
687
774
|
if (currentResources.motionPath) {
|
|
688
775
|
setLoadingProgress(60);
|
|
776
|
+
const motionStartTime = performance.now();
|
|
689
777
|
console.log("\u{1F483} \u5F00\u59CB\u52A0\u8F7D\u52A8\u4F5C:", currentResources.motionPath);
|
|
690
778
|
vmd = await new Promise((resolve, reject) => {
|
|
691
779
|
loader.loadAnimation(
|
|
692
780
|
currentResources.motionPath,
|
|
693
781
|
mesh,
|
|
694
782
|
(vmdObject) => {
|
|
695
|
-
|
|
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)`);
|
|
696
786
|
resolve(vmdObject);
|
|
697
787
|
},
|
|
698
788
|
(progress) => {
|
|
699
789
|
if (progress.total > 0) {
|
|
700
790
|
const percent = progress.loaded / progress.total * 20 + 60;
|
|
701
791
|
setLoadingProgress(Math.min(percent, 80));
|
|
792
|
+
console.log(`\u{1F4E5} \u52A8\u4F5C\u52A0\u8F7D\u8FDB\u5EA6: ${(progress.loaded / progress.total * 100).toFixed(1)}%`);
|
|
702
793
|
}
|
|
703
794
|
},
|
|
704
795
|
(error2) => {
|
|
705
|
-
|
|
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);
|
|
706
799
|
reject(error2);
|
|
707
800
|
}
|
|
708
801
|
);
|
|
@@ -753,12 +846,18 @@ var MMDPlayerEnhanced = ({
|
|
|
753
846
|
}
|
|
754
847
|
if (currentResources.audioPath) {
|
|
755
848
|
setLoadingProgress(90);
|
|
849
|
+
const audioStartTime = performance.now();
|
|
756
850
|
console.log("\u{1F3B5} \u5F00\u59CB\u52A0\u8F7D\u97F3\u9891:", currentResources.audioPath);
|
|
757
851
|
const audio = new Audio(currentResources.audioPath);
|
|
758
852
|
audio.volume = 0.5;
|
|
759
853
|
audio.loop = loop;
|
|
760
854
|
audioRef.current = audio;
|
|
761
855
|
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
|
+
};
|
|
762
861
|
audio.onended = () => {
|
|
763
862
|
if (!loop) {
|
|
764
863
|
setIsPlaying(false);
|
|
@@ -773,7 +872,6 @@ var MMDPlayerEnhanced = ({
|
|
|
773
872
|
}
|
|
774
873
|
onAudioEnded?.();
|
|
775
874
|
};
|
|
776
|
-
console.log("\u2705 \u97F3\u9891\u52A0\u8F7D\u6210\u529F");
|
|
777
875
|
}
|
|
778
876
|
setLoadingProgress(100);
|
|
779
877
|
setLoading(false);
|
|
@@ -802,32 +900,54 @@ var MMDPlayerEnhanced = ({
|
|
|
802
900
|
}, [currentResources, stage?.enablePhysics, autoPlay, loop, onLoad, onError, reloadTrigger]);
|
|
803
901
|
const play = () => {
|
|
804
902
|
console.log("\u{1F3AC} [play] \u51FD\u6570\u88AB\u8C03\u7528\uFF0CneedReset =", needReset);
|
|
805
|
-
if (!helperRef.current) return;
|
|
903
|
+
if (!helperRef.current && !needReset) return;
|
|
806
904
|
if (needReset && vmdDataRef.current && sceneRef.current && cameraRef.current) {
|
|
807
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");
|
|
808
906
|
const { mesh, vmd, cameraVmd } = vmdDataRef.current;
|
|
907
|
+
if (helperRef.current) {
|
|
908
|
+
try {
|
|
909
|
+
const helperObjects = helperRef.current.objects;
|
|
910
|
+
if (helperObjects && Array.isArray(helperObjects)) {
|
|
911
|
+
helperObjects.length = 0;
|
|
912
|
+
console.log("\u{1F9F9} \u6E05\u7A7A\u4E86\u65E7 helper \u7684 objects \u6570\u7EC4");
|
|
913
|
+
}
|
|
914
|
+
} catch (error2) {
|
|
915
|
+
console.warn("\u26A0\uFE0F \u65E0\u6CD5\u6E05\u7A7A\u65E7 helper.objects:", error2);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
809
918
|
const newHelper = new threeStdlib.MMDAnimationHelper();
|
|
810
919
|
helperRef.current = newHelper;
|
|
811
920
|
clockRef.current = new THREE2__namespace.Clock();
|
|
812
921
|
if (vmd && typeof vmd === "object") {
|
|
813
|
-
console.log("\u{1F4E6} \u91CD\u65B0\u6DFB\u52A0\u6A21\u578B\u52A8\u753B
|
|
922
|
+
console.log("\u{1F4E6} \u91CD\u65B0\u6DFB\u52A0\u6A21\u578B\u52A8\u753B");
|
|
814
923
|
try {
|
|
815
924
|
newHelper.add(mesh, {
|
|
816
925
|
animation: vmd,
|
|
817
926
|
physics: stage?.enablePhysics !== false
|
|
818
927
|
});
|
|
928
|
+
console.log("\u2705 \u6A21\u578B\u52A8\u753B\u6DFB\u52A0\u6210\u529F");
|
|
819
929
|
} catch (error2) {
|
|
820
930
|
console.error("\u274C \u91CD\u65B0\u6DFB\u52A0\u6A21\u578B\u52A8\u753B\u5931\u8D25:", error2);
|
|
821
|
-
|
|
822
|
-
|
|
931
|
+
try {
|
|
932
|
+
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
|
+
} catch (innerError) {
|
|
935
|
+
console.error("\u274C \u6DFB\u52A0\u6A21\u578B\u4E5F\u5931\u8D25\u4E86:", innerError);
|
|
936
|
+
}
|
|
823
937
|
}
|
|
824
938
|
} else {
|
|
825
|
-
|
|
939
|
+
try {
|
|
940
|
+
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
|
+
} catch (error2) {
|
|
943
|
+
console.error("\u274C \u6DFB\u52A0\u6A21\u578B\u5931\u8D25:", error2);
|
|
944
|
+
}
|
|
826
945
|
}
|
|
827
946
|
if (cameraVmd && typeof cameraVmd === "object") {
|
|
828
947
|
console.log("\u{1F4F7} \u91CD\u65B0\u6DFB\u52A0\u76F8\u673A\u52A8\u753B");
|
|
829
948
|
try {
|
|
830
949
|
newHelper.add(cameraRef.current, { animation: cameraVmd });
|
|
950
|
+
console.log("\u2705 \u76F8\u673A\u52A8\u753B\u6DFB\u52A0\u6210\u529F");
|
|
831
951
|
} catch (error2) {
|
|
832
952
|
console.error("\u274C \u91CD\u65B0\u6DFB\u52A0\u76F8\u673A\u52A8\u753B\u5931\u8D25:", error2);
|
|
833
953
|
}
|
|
@@ -838,6 +958,10 @@ var MMDPlayerEnhanced = ({
|
|
|
838
958
|
setNeedReset(false);
|
|
839
959
|
console.log("\u2705 Helper \u91CD\u65B0\u521D\u59CB\u5316\u5B8C\u6210\uFF0C\u51C6\u5907\u4ECE\u7B2C\u4E00\u5E27\u64AD\u653E");
|
|
840
960
|
}
|
|
961
|
+
if (!helperRef.current) {
|
|
962
|
+
console.error("\u274C [play] helper \u4E0D\u5B58\u5728\uFF0C\u65E0\u6CD5\u64AD\u653E");
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
841
965
|
if (audioRef.current) {
|
|
842
966
|
audioRef.current.play();
|
|
843
967
|
}
|