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.mjs
CHANGED
|
@@ -491,7 +491,7 @@ var MMDPlayerEnhanced = ({
|
|
|
491
491
|
};
|
|
492
492
|
}, [stage]);
|
|
493
493
|
const clearOldResources = () => {
|
|
494
|
-
console.log("\u{1F9F9} [MMDPlayerEnhanced] \u5F00\u59CB\u6E05\u9664\u65E7\u8D44\u6E90");
|
|
494
|
+
console.log("\u{1F9F9} [MMDPlayerEnhanced] \u5F00\u59CB\u6E05\u9664\u65E7\u8D44\u6E90\uFF08\u589E\u5F3A\u6E05\u7406\uFF09");
|
|
495
495
|
if (!sceneRef.current) return;
|
|
496
496
|
if (isPlayingRef.current) {
|
|
497
497
|
isPlayingRef.current = false;
|
|
@@ -500,10 +500,61 @@ var MMDPlayerEnhanced = ({
|
|
|
500
500
|
if (audioRef.current) {
|
|
501
501
|
audioRef.current.pause();
|
|
502
502
|
audioRef.current.currentTime = 0;
|
|
503
|
+
audioRef.current.onended = null;
|
|
503
504
|
audioRef.current = null;
|
|
504
505
|
}
|
|
505
506
|
if (helperRef.current) {
|
|
507
|
+
console.log("\u{1F9F9} \u5F00\u59CB\u6E05\u7406 MMDAnimationHelper");
|
|
508
|
+
try {
|
|
509
|
+
helperRef.current.enable("animation", false);
|
|
510
|
+
helperRef.current.enable("ik", false);
|
|
511
|
+
helperRef.current.enable("grant", false);
|
|
512
|
+
helperRef.current.enable("physics", false);
|
|
513
|
+
console.log("\u2705 \u5DF2\u505C\u7528\u6240\u6709 helper \u7CFB\u7EDF");
|
|
514
|
+
} catch (error2) {
|
|
515
|
+
console.warn("\u26A0\uFE0F \u505C\u7528 helper \u7CFB\u7EDF\u5931\u8D25:", error2);
|
|
516
|
+
}
|
|
517
|
+
try {
|
|
518
|
+
const helperObjects = helperRef.current.objects;
|
|
519
|
+
if (helperObjects && Array.isArray(helperObjects)) {
|
|
520
|
+
console.log(`\u{1F9F9} \u6E05\u9664 helper \u4E2D\u7684 ${helperObjects.length} \u4E2A\u5BF9\u8C61\uFF08\u5305\u62EC\u7269\u7406\u7CFB\u7EDF\uFF09`);
|
|
521
|
+
helperObjects.forEach((obj) => {
|
|
522
|
+
if (obj.physics) {
|
|
523
|
+
console.log("\u{1F527} \u6E05\u7406\u7269\u7406\u7CFB\u7EDF:", obj.mesh?.name || "unnamed");
|
|
524
|
+
try {
|
|
525
|
+
if (obj.physics.reset) {
|
|
526
|
+
obj.physics.reset();
|
|
527
|
+
}
|
|
528
|
+
if (obj.physics.world) {
|
|
529
|
+
const world = obj.physics.world;
|
|
530
|
+
while (world.getNumCollisionObjects() > 0) {
|
|
531
|
+
const body = world.getCollisionObjectArray().at(0);
|
|
532
|
+
world.removeCollisionObject(body);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
obj.physics = null;
|
|
536
|
+
} catch (physicsError) {
|
|
537
|
+
console.warn("\u26A0\uFE0F \u6E05\u7406\u7269\u7406\u7CFB\u7EDF\u5931\u8D25:", physicsError);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
helperObjects.length = 0;
|
|
542
|
+
}
|
|
543
|
+
} catch (error2) {
|
|
544
|
+
console.warn("\u26A0\uFE0F \u65E0\u6CD5\u8BBF\u95EE helper.objects:", error2);
|
|
545
|
+
}
|
|
506
546
|
helperRef.current = null;
|
|
547
|
+
console.log("\u2705 MMDAnimationHelper \u6E05\u7406\u5B8C\u6210");
|
|
548
|
+
}
|
|
549
|
+
if (sceneRef.current.background && sceneRef.current.background.isTexture) {
|
|
550
|
+
console.log("\u{1F9F9} \u6E05\u9664\u573A\u666F\u80CC\u666F\u8D34\u56FE");
|
|
551
|
+
sceneRef.current.background.dispose();
|
|
552
|
+
sceneRef.current.background = null;
|
|
553
|
+
}
|
|
554
|
+
if (sceneRef.current.environment && sceneRef.current.environment.isTexture) {
|
|
555
|
+
console.log("\u{1F9F9} \u6E05\u9664\u573A\u666F\u73AF\u5883\u8D34\u56FE");
|
|
556
|
+
sceneRef.current.environment.dispose();
|
|
557
|
+
sceneRef.current.environment = null;
|
|
507
558
|
}
|
|
508
559
|
const objectsToRemove = [];
|
|
509
560
|
sceneRef.current.traverse((child) => {
|
|
@@ -522,16 +573,34 @@ var MMDPlayerEnhanced = ({
|
|
|
522
573
|
obj.geometry.dispose();
|
|
523
574
|
}
|
|
524
575
|
if (obj.material) {
|
|
525
|
-
|
|
526
|
-
|
|
576
|
+
const material = obj.material;
|
|
577
|
+
const disposeMaterial = (m) => {
|
|
578
|
+
if (m.map) m.map.dispose();
|
|
579
|
+
if (m.emissiveMap) m.emissiveMap.dispose();
|
|
580
|
+
if (m.normalMap) m.normalMap.dispose();
|
|
581
|
+
if (m.bumpMap) m.bumpMap.dispose();
|
|
582
|
+
if (m.specularMap) m.specularMap.dispose();
|
|
583
|
+
if (m.envMap) m.envMap.dispose();
|
|
584
|
+
if (m.lightMap) m.lightMap.dispose();
|
|
585
|
+
if (m.aoMap) m.aoMap.dispose();
|
|
586
|
+
if (m.alphaMap) m.alphaMap.dispose();
|
|
587
|
+
m.dispose();
|
|
588
|
+
};
|
|
589
|
+
if (Array.isArray(material)) {
|
|
590
|
+
material.forEach(disposeMaterial);
|
|
527
591
|
} else {
|
|
528
|
-
|
|
592
|
+
disposeMaterial(material);
|
|
529
593
|
}
|
|
530
594
|
}
|
|
595
|
+
if (obj.skeleton) {
|
|
596
|
+
console.log("\u{1F9F9} \u6E05\u7406\u9AA8\u9ABC\u6570\u636E");
|
|
597
|
+
obj.skeleton = null;
|
|
598
|
+
}
|
|
531
599
|
});
|
|
532
600
|
clockRef.current = new THREE2.Clock();
|
|
533
601
|
vmdDataRef.current = null;
|
|
534
|
-
|
|
602
|
+
setNeedReset(false);
|
|
603
|
+
console.log(`\u2705 [MMDPlayerEnhanced] \u5DF2\u6E05\u9664 ${objectsToRemove.length} \u4E2A\u5BF9\u8C61\uFF08\u589E\u5F3A\u6E05\u7406\u5B8C\u6210\uFF09`);
|
|
535
604
|
};
|
|
536
605
|
useEffect(() => {
|
|
537
606
|
console.log("\u{1F4E6} [MMDPlayerEnhanced] \u8D44\u6E90\u52A0\u8F7D useEffect \u89E6\u53D1");
|
|
@@ -592,22 +661,30 @@ var MMDPlayerEnhanced = ({
|
|
|
592
661
|
const helper = new MMDAnimationHelper();
|
|
593
662
|
helperRef.current = helper;
|
|
594
663
|
setLoadingProgress(20);
|
|
664
|
+
const modelStartTime = performance.now();
|
|
595
665
|
console.log("\u{1F3AD} \u5F00\u59CB\u52A0\u8F7D\u6A21\u578B:", currentResources.modelPath);
|
|
666
|
+
console.log("\u{1F4CA} [\u6027\u80FD] \u6A21\u578B\u52A0\u8F7D\u5F00\u59CB\u65F6\u95F4:", (/* @__PURE__ */ new Date()).toISOString());
|
|
596
667
|
const mesh = await new Promise((resolve, reject) => {
|
|
597
668
|
loader.load(
|
|
598
669
|
currentResources.modelPath,
|
|
599
670
|
(object) => {
|
|
600
|
-
|
|
671
|
+
const modelEndTime = performance.now();
|
|
672
|
+
const modelLoadTime = ((modelEndTime - modelStartTime) / 1e3).toFixed(2);
|
|
673
|
+
console.log(`\u2705 \u6A21\u578B\u52A0\u8F7D\u6210\u529F (\u8017\u65F6: ${modelLoadTime}\u79D2)`);
|
|
674
|
+
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`);
|
|
601
675
|
resolve(object);
|
|
602
676
|
},
|
|
603
677
|
(progress) => {
|
|
604
678
|
if (progress.total > 0) {
|
|
605
679
|
const percent = progress.loaded / progress.total * 30 + 20;
|
|
606
680
|
setLoadingProgress(Math.min(percent, 50));
|
|
681
|
+
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)`);
|
|
607
682
|
}
|
|
608
683
|
},
|
|
609
684
|
(error2) => {
|
|
610
|
-
|
|
685
|
+
const modelEndTime = performance.now();
|
|
686
|
+
const modelLoadTime = ((modelEndTime - modelStartTime) / 1e3).toFixed(2);
|
|
687
|
+
console.error(`\u274C \u6A21\u578B\u52A0\u8F7D\u5931\u8D25 (\u8017\u65F6: ${modelLoadTime}\u79D2):`, error2);
|
|
611
688
|
reject(error2);
|
|
612
689
|
}
|
|
613
690
|
);
|
|
@@ -635,14 +712,25 @@ var MMDPlayerEnhanced = ({
|
|
|
635
712
|
sceneRef.current.add(stageMesh);
|
|
636
713
|
}
|
|
637
714
|
if (currentResources.backgroundPath && sceneRef.current) {
|
|
715
|
+
const bgStartTime = performance.now();
|
|
638
716
|
console.log("\u{1F5BC}\uFE0F \u5F00\u59CB\u52A0\u8F7D\u80CC\u666F\u56FE\u7247:", currentResources.backgroundPath);
|
|
639
717
|
const textureLoader = new THREE2.TextureLoader();
|
|
640
718
|
const backgroundTexture = await new Promise((resolve, reject) => {
|
|
641
719
|
textureLoader.load(
|
|
642
720
|
currentResources.backgroundPath,
|
|
643
|
-
(texture) =>
|
|
721
|
+
(texture) => {
|
|
722
|
+
const bgEndTime = performance.now();
|
|
723
|
+
const bgLoadTime = ((bgEndTime - bgStartTime) / 1e3).toFixed(2);
|
|
724
|
+
console.log(`\u2705 \u80CC\u666F\u56FE\u7247\u52A0\u8F7D\u6210\u529F (\u8017\u65F6: ${bgLoadTime}\u79D2, \u5C3A\u5BF8: ${texture.image.width}x${texture.image.height})`);
|
|
725
|
+
resolve(texture);
|
|
726
|
+
},
|
|
644
727
|
void 0,
|
|
645
|
-
(err) =>
|
|
728
|
+
(err) => {
|
|
729
|
+
const bgEndTime = performance.now();
|
|
730
|
+
const bgLoadTime = ((bgEndTime - bgStartTime) / 1e3).toFixed(2);
|
|
731
|
+
console.error(`\u274C \u80CC\u666F\u56FE\u7247\u52A0\u8F7D\u5931\u8D25 (\u8017\u65F6: ${bgLoadTime}\u79D2):`, err);
|
|
732
|
+
reject(err);
|
|
733
|
+
}
|
|
646
734
|
);
|
|
647
735
|
});
|
|
648
736
|
backgroundTexture.colorSpace = THREE2.SRGBColorSpace;
|
|
@@ -655,29 +743,34 @@ var MMDPlayerEnhanced = ({
|
|
|
655
743
|
} else {
|
|
656
744
|
sceneRef.current.background = backgroundTexture;
|
|
657
745
|
}
|
|
658
|
-
console.log("\u2705 \u80CC\u666F\u56FE\u7247\u52A0\u8F7D\u6210\u529F");
|
|
659
746
|
}
|
|
660
747
|
let vmd = null;
|
|
661
748
|
let cameraVmd = null;
|
|
662
749
|
if (currentResources.motionPath) {
|
|
663
750
|
setLoadingProgress(60);
|
|
751
|
+
const motionStartTime = performance.now();
|
|
664
752
|
console.log("\u{1F483} \u5F00\u59CB\u52A0\u8F7D\u52A8\u4F5C:", currentResources.motionPath);
|
|
665
753
|
vmd = await new Promise((resolve, reject) => {
|
|
666
754
|
loader.loadAnimation(
|
|
667
755
|
currentResources.motionPath,
|
|
668
756
|
mesh,
|
|
669
757
|
(vmdObject) => {
|
|
670
|
-
|
|
758
|
+
const motionEndTime = performance.now();
|
|
759
|
+
const motionLoadTime = ((motionEndTime - motionStartTime) / 1e3).toFixed(2);
|
|
760
|
+
console.log(`\u2705 \u52A8\u4F5C\u52A0\u8F7D\u6210\u529F (\u8017\u65F6: ${motionLoadTime}\u79D2)`);
|
|
671
761
|
resolve(vmdObject);
|
|
672
762
|
},
|
|
673
763
|
(progress) => {
|
|
674
764
|
if (progress.total > 0) {
|
|
675
765
|
const percent = progress.loaded / progress.total * 20 + 60;
|
|
676
766
|
setLoadingProgress(Math.min(percent, 80));
|
|
767
|
+
console.log(`\u{1F4E5} \u52A8\u4F5C\u52A0\u8F7D\u8FDB\u5EA6: ${(progress.loaded / progress.total * 100).toFixed(1)}%`);
|
|
677
768
|
}
|
|
678
769
|
},
|
|
679
770
|
(error2) => {
|
|
680
|
-
|
|
771
|
+
const motionEndTime = performance.now();
|
|
772
|
+
const motionLoadTime = ((motionEndTime - motionStartTime) / 1e3).toFixed(2);
|
|
773
|
+
console.error(`\u274C \u52A8\u4F5C\u52A0\u8F7D\u5931\u8D25 (\u8017\u65F6: ${motionLoadTime}\u79D2):`, error2);
|
|
681
774
|
reject(error2);
|
|
682
775
|
}
|
|
683
776
|
);
|
|
@@ -728,12 +821,18 @@ var MMDPlayerEnhanced = ({
|
|
|
728
821
|
}
|
|
729
822
|
if (currentResources.audioPath) {
|
|
730
823
|
setLoadingProgress(90);
|
|
824
|
+
const audioStartTime = performance.now();
|
|
731
825
|
console.log("\u{1F3B5} \u5F00\u59CB\u52A0\u8F7D\u97F3\u9891:", currentResources.audioPath);
|
|
732
826
|
const audio = new Audio(currentResources.audioPath);
|
|
733
827
|
audio.volume = 0.5;
|
|
734
828
|
audio.loop = loop;
|
|
735
829
|
audioRef.current = audio;
|
|
736
830
|
hasAudioRef.current = true;
|
|
831
|
+
audio.onloadedmetadata = () => {
|
|
832
|
+
const audioEndTime = performance.now();
|
|
833
|
+
const audioLoadTime = ((audioEndTime - audioStartTime) / 1e3).toFixed(2);
|
|
834
|
+
console.log(`\u2705 \u97F3\u9891\u52A0\u8F7D\u6210\u529F (\u8017\u65F6: ${audioLoadTime}\u79D2, \u65F6\u957F: ${audio.duration.toFixed(2)}\u79D2)`);
|
|
835
|
+
};
|
|
737
836
|
audio.onended = () => {
|
|
738
837
|
if (!loop) {
|
|
739
838
|
setIsPlaying(false);
|
|
@@ -748,7 +847,6 @@ var MMDPlayerEnhanced = ({
|
|
|
748
847
|
}
|
|
749
848
|
onAudioEnded?.();
|
|
750
849
|
};
|
|
751
|
-
console.log("\u2705 \u97F3\u9891\u52A0\u8F7D\u6210\u529F");
|
|
752
850
|
}
|
|
753
851
|
setLoadingProgress(100);
|
|
754
852
|
setLoading(false);
|
|
@@ -777,32 +875,54 @@ var MMDPlayerEnhanced = ({
|
|
|
777
875
|
}, [currentResources, stage?.enablePhysics, autoPlay, loop, onLoad, onError, reloadTrigger]);
|
|
778
876
|
const play = () => {
|
|
779
877
|
console.log("\u{1F3AC} [play] \u51FD\u6570\u88AB\u8C03\u7528\uFF0CneedReset =", needReset);
|
|
780
|
-
if (!helperRef.current) return;
|
|
878
|
+
if (!helperRef.current && !needReset) return;
|
|
781
879
|
if (needReset && vmdDataRef.current && sceneRef.current && cameraRef.current) {
|
|
782
880
|
console.log("\u{1F504} \u68C0\u6D4B\u5230\u9700\u8981\u91CD\u7F6E\uFF0C\u91CD\u65B0\u521D\u59CB\u5316 helper\uFF08\u4FDD\u7559\u6A21\u578B\uFF09");
|
|
783
881
|
const { mesh, vmd, cameraVmd } = vmdDataRef.current;
|
|
882
|
+
if (helperRef.current) {
|
|
883
|
+
try {
|
|
884
|
+
const helperObjects = helperRef.current.objects;
|
|
885
|
+
if (helperObjects && Array.isArray(helperObjects)) {
|
|
886
|
+
helperObjects.length = 0;
|
|
887
|
+
console.log("\u{1F9F9} \u6E05\u7A7A\u4E86\u65E7 helper \u7684 objects \u6570\u7EC4");
|
|
888
|
+
}
|
|
889
|
+
} catch (error2) {
|
|
890
|
+
console.warn("\u26A0\uFE0F \u65E0\u6CD5\u6E05\u7A7A\u65E7 helper.objects:", error2);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
784
893
|
const newHelper = new MMDAnimationHelper();
|
|
785
894
|
helperRef.current = newHelper;
|
|
786
895
|
clockRef.current = new THREE2.Clock();
|
|
787
896
|
if (vmd && typeof vmd === "object") {
|
|
788
|
-
console.log("\u{1F4E6} \u91CD\u65B0\u6DFB\u52A0\u6A21\u578B\u52A8\u753B
|
|
897
|
+
console.log("\u{1F4E6} \u91CD\u65B0\u6DFB\u52A0\u6A21\u578B\u52A8\u753B");
|
|
789
898
|
try {
|
|
790
899
|
newHelper.add(mesh, {
|
|
791
900
|
animation: vmd,
|
|
792
901
|
physics: stage?.enablePhysics !== false
|
|
793
902
|
});
|
|
903
|
+
console.log("\u2705 \u6A21\u578B\u52A8\u753B\u6DFB\u52A0\u6210\u529F");
|
|
794
904
|
} catch (error2) {
|
|
795
905
|
console.error("\u274C \u91CD\u65B0\u6DFB\u52A0\u6A21\u578B\u52A8\u753B\u5931\u8D25:", error2);
|
|
796
|
-
|
|
797
|
-
|
|
906
|
+
try {
|
|
907
|
+
newHelper.add(mesh, { physics: stage?.enablePhysics !== false });
|
|
908
|
+
console.log("\u2705 \u4EC5\u6DFB\u52A0\u6A21\u578B\u548C\u7269\u7406\uFF08\u65E0\u52A8\u753B\uFF09");
|
|
909
|
+
} catch (innerError) {
|
|
910
|
+
console.error("\u274C \u6DFB\u52A0\u6A21\u578B\u4E5F\u5931\u8D25\u4E86:", innerError);
|
|
911
|
+
}
|
|
798
912
|
}
|
|
799
913
|
} else {
|
|
800
|
-
|
|
914
|
+
try {
|
|
915
|
+
newHelper.add(mesh, { physics: stage?.enablePhysics !== false });
|
|
916
|
+
console.log("\u2705 \u4EC5\u6DFB\u52A0\u6A21\u578B\u548C\u7269\u7406\uFF08\u65E0\u52A8\u753B\u6570\u636E\uFF09");
|
|
917
|
+
} catch (error2) {
|
|
918
|
+
console.error("\u274C \u6DFB\u52A0\u6A21\u578B\u5931\u8D25:", error2);
|
|
919
|
+
}
|
|
801
920
|
}
|
|
802
921
|
if (cameraVmd && typeof cameraVmd === "object") {
|
|
803
922
|
console.log("\u{1F4F7} \u91CD\u65B0\u6DFB\u52A0\u76F8\u673A\u52A8\u753B");
|
|
804
923
|
try {
|
|
805
924
|
newHelper.add(cameraRef.current, { animation: cameraVmd });
|
|
925
|
+
console.log("\u2705 \u76F8\u673A\u52A8\u753B\u6DFB\u52A0\u6210\u529F");
|
|
806
926
|
} catch (error2) {
|
|
807
927
|
console.error("\u274C \u91CD\u65B0\u6DFB\u52A0\u76F8\u673A\u52A8\u753B\u5931\u8D25:", error2);
|
|
808
928
|
}
|
|
@@ -813,6 +933,10 @@ var MMDPlayerEnhanced = ({
|
|
|
813
933
|
setNeedReset(false);
|
|
814
934
|
console.log("\u2705 Helper \u91CD\u65B0\u521D\u59CB\u5316\u5B8C\u6210\uFF0C\u51C6\u5907\u4ECE\u7B2C\u4E00\u5E27\u64AD\u653E");
|
|
815
935
|
}
|
|
936
|
+
if (!helperRef.current) {
|
|
937
|
+
console.error("\u274C [play] helper \u4E0D\u5B58\u5728\uFF0C\u65E0\u6CD5\u64AD\u653E");
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
816
940
|
if (audioRef.current) {
|
|
817
941
|
audioRef.current.play();
|
|
818
942
|
}
|