lythreeframe 1.0.32 → 1.0.34
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/bundle.cjs.js +280 -185
- package/dist/bundle.esm.js +281 -185
- package/dist/index.d.ts +3 -4
- package/dist/lythreeframe/AssetManagement/AssetManager.d.ts +13 -9
- package/dist/lythreeframe/Frame/Parameters/AppParameter.d.ts +11 -0
- package/dist/lythreeframe/Frame/Viewport.d.ts +1 -1
- package/dist/lythreeframe/Object/Actor.d.ts +3 -1
- package/dist/lythreeframe/Object/Actors/Light/DirectionalLightActor.d.ts +2 -1
- package/dist/lythreeframe/Object/Actors/Shape/BoxActor.d.ts +2 -1
- package/dist/lythreeframe/Object/Actors/Shape/PlaneActor.d.ts +2 -1
- package/dist/lythreeframe/Object/Actors/Sky/SkyActor.d.ts +2 -1
- package/dist/lythreeframe/Object/Components/2D/2DComponent.d.ts +2 -1
- package/dist/lythreeframe/Object/Components/Light/DirectionalLight/DirectionalLightComponent.d.ts +2 -1
- package/dist/lythreeframe/Object/Components/Light/LightComponent.d.ts +2 -1
- package/dist/lythreeframe/Object/Components/Mesh/MeshComponent.d.ts +16 -9
- package/dist/lythreeframe/Object/Components/Mesh/Shape/BoxComponent.d.ts +2 -1
- package/dist/lythreeframe/Object/Components/Mesh/Shape/PlaneComponent.d.ts +2 -1
- package/dist/lythreeframe/Object/Components/Mesh/Shape/SphereComponent.d.ts +2 -1
- package/dist/lythreeframe/Object/Components/Mesh/Sprite/SpriteComponent.d.ts +2 -1
- package/dist/lythreeframe/Object/Components/SceneComponent.d.ts +4 -2
- package/dist/lythreeframe/Object/Components/Sky/SkyComponent.d.ts +3 -1
- package/dist/lythreeframe/ThreeJsApp.d.ts +4 -4
- package/package.json +1 -1
package/dist/bundle.cjs.js
CHANGED
|
@@ -19,21 +19,6 @@ var CSS2DRenderer_js = require('three/examples/jsm/renderers/CSS2DRenderer.js');
|
|
|
19
19
|
var PointerLockControls = require('three/examples/jsm/controls/PointerLockControls');
|
|
20
20
|
var TransformControls_js = require('three/examples/jsm/controls/TransformControls.js');
|
|
21
21
|
|
|
22
|
-
class LYLoadTask {
|
|
23
|
-
constructor(paths, onLoaded) {
|
|
24
|
-
this.paths = paths;
|
|
25
|
-
this.onLoaded = onLoaded;
|
|
26
|
-
}
|
|
27
|
-
get Paths() {
|
|
28
|
-
return this.paths;
|
|
29
|
-
}
|
|
30
|
-
onLoadingFinished(loaded) {
|
|
31
|
-
if (this.onLoaded) {
|
|
32
|
-
this.onLoaded(loaded);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
22
|
/*
|
|
38
23
|
* virtual class of 3D Object, should not be use directly.
|
|
39
24
|
*/
|
|
@@ -124,11 +109,14 @@ class SceneComponent extends Component {
|
|
|
124
109
|
// 通过 _parentActor 私有字段访问父级 Actor
|
|
125
110
|
return this._parentActor;
|
|
126
111
|
}
|
|
127
|
-
|
|
112
|
+
get world() {
|
|
113
|
+
return this.app.world;
|
|
114
|
+
}
|
|
115
|
+
constructor(app, newThreeObject) {
|
|
128
116
|
super(newThreeObject);
|
|
129
117
|
this.bCanHover = false;
|
|
130
118
|
this.bCanClick = false;
|
|
131
|
-
this.
|
|
119
|
+
this.app = app;
|
|
132
120
|
this._name = "SceneComponent";
|
|
133
121
|
}
|
|
134
122
|
createDefaultThreeObject() {
|
|
@@ -223,10 +211,9 @@ class SceneComponent extends Component {
|
|
|
223
211
|
return childrens;
|
|
224
212
|
}
|
|
225
213
|
onAddedToWorld(world) {
|
|
226
|
-
this.world = world;
|
|
227
214
|
let childrens = this.childrenComponents;
|
|
228
215
|
for (let i = 0; i < childrens.length; ++i) {
|
|
229
|
-
childrens[i].onAddedToWorld(
|
|
216
|
+
childrens[i].onAddedToWorld(world);
|
|
230
217
|
}
|
|
231
218
|
}
|
|
232
219
|
destroy() {
|
|
@@ -678,6 +665,8 @@ class SceneComponent extends Component {
|
|
|
678
665
|
}
|
|
679
666
|
}
|
|
680
667
|
|
|
668
|
+
// import {BufferGeometry, Material, Mesh, Texture} from "three/webgpu";
|
|
669
|
+
// import {Vector3} from "three/webgpu";
|
|
681
670
|
class MeshComponent extends SceneComponent {
|
|
682
671
|
get threeObject() {
|
|
683
672
|
return this.obj;
|
|
@@ -689,43 +678,86 @@ class MeshComponent extends SceneComponent {
|
|
|
689
678
|
}
|
|
690
679
|
}
|
|
691
680
|
get geometry() {
|
|
692
|
-
|
|
681
|
+
if (!this._geometryPtr) {
|
|
682
|
+
throw new Error("geometryPtr is null");
|
|
683
|
+
}
|
|
684
|
+
return this._geometryPtr.getValue();
|
|
693
685
|
}
|
|
694
686
|
set geometry(geo) {
|
|
695
|
-
|
|
696
|
-
|
|
687
|
+
let geoPtr = this.app.assetManager.addGeometryAsset(geo);
|
|
688
|
+
this.geometryPtr = geoPtr;
|
|
689
|
+
}
|
|
690
|
+
get geometryPtr() {
|
|
691
|
+
if (!this._geometryPtr) {
|
|
692
|
+
throw new Error("geometryPtr is null");
|
|
693
|
+
}
|
|
694
|
+
return this._geometryPtr;
|
|
695
|
+
}
|
|
696
|
+
set geometryPtr(geo) {
|
|
697
|
+
if (this._geometryPtr) {
|
|
698
|
+
this._geometryPtr.release();
|
|
699
|
+
this._geometryPtr = null;
|
|
700
|
+
}
|
|
701
|
+
this._geometryPtr = geo;
|
|
702
|
+
if (this.threeObject) {
|
|
703
|
+
this.threeObject.geometry = geo.getValue();
|
|
697
704
|
}
|
|
698
|
-
this.threeObject.geometry = geo;
|
|
699
705
|
}
|
|
700
706
|
get material() {
|
|
701
|
-
|
|
707
|
+
let mats = [];
|
|
708
|
+
this._materialPtr.forEach((elem) => {
|
|
709
|
+
mats.push(elem.getValue());
|
|
710
|
+
});
|
|
711
|
+
return mats;
|
|
712
|
+
}
|
|
713
|
+
get materialPtr() {
|
|
714
|
+
return this.materialPtr;
|
|
702
715
|
}
|
|
703
716
|
set material(newMat) {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
}
|
|
717
|
+
let mats = Array.isArray(newMat) ? newMat : [newMat];
|
|
718
|
+
let matPtrs = [];
|
|
719
|
+
mats.forEach((elem) => {
|
|
720
|
+
let ptr = this.app.assetManager.addMaterialAsset(elem);
|
|
721
|
+
if (ptr)
|
|
722
|
+
matPtrs.push(ptr);
|
|
723
|
+
});
|
|
724
|
+
this.materialPtr = matPtrs;
|
|
711
725
|
}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
726
|
+
set materialPtr(newMat) {
|
|
727
|
+
if (this._materialPtr) {
|
|
728
|
+
this._materialPtr.forEach((elem) => {
|
|
729
|
+
elem.release();
|
|
730
|
+
});
|
|
731
|
+
this._materialPtr = [];
|
|
716
732
|
}
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
733
|
+
let matPtrs = Array.isArray(newMat) ? newMat : [newMat];
|
|
734
|
+
let mats = Array.isArray(newMat) ? newMat : [newMat];
|
|
735
|
+
matPtrs.forEach((elem) => {
|
|
736
|
+
mats.push(elem.getValue());
|
|
737
|
+
elem.addRef();
|
|
738
|
+
});
|
|
739
|
+
if (this.threeObject) {
|
|
740
|
+
this.threeObject.material = mats;
|
|
724
741
|
}
|
|
725
|
-
|
|
742
|
+
this._materialPtr = matPtrs;
|
|
743
|
+
}
|
|
744
|
+
constructor(app, geometry, material) {
|
|
745
|
+
let matPtrs = [];
|
|
746
|
+
let mats = Array.isArray(material) ? material : [material];
|
|
747
|
+
mats.forEach((elem) => {
|
|
748
|
+
let ptr = app.assetManager.addMaterialAsset(elem);
|
|
749
|
+
if (ptr)
|
|
750
|
+
matPtrs.push(ptr);
|
|
751
|
+
});
|
|
752
|
+
let newMesh = new webgpu.Mesh(geometry, mats);
|
|
753
|
+
super(app, newMesh);
|
|
726
754
|
this.obj = null;
|
|
755
|
+
this._geometryPtr = app.assetManager.addGeometryAsset(geometry);
|
|
756
|
+
this._materialPtr = matPtrs;
|
|
757
|
+
matPtrs.forEach((elem) => {
|
|
758
|
+
elem.addRef();
|
|
759
|
+
});
|
|
727
760
|
this.threeObject = newMesh;
|
|
728
|
-
LYAssetManager.Get().checkMeshResource(newMesh);
|
|
729
761
|
}
|
|
730
762
|
set castShadow(bCast) {
|
|
731
763
|
if (this.threeObject)
|
|
@@ -763,27 +795,15 @@ class MeshComponent extends SceneComponent {
|
|
|
763
795
|
return ret;
|
|
764
796
|
}
|
|
765
797
|
destroyObject() {
|
|
766
|
-
if (this.
|
|
767
|
-
this.
|
|
768
|
-
}
|
|
769
|
-
let assetManager = LYAssetManager.Get();
|
|
770
|
-
const mats = Array.isArray(this.material) ? this.material : [this.material];
|
|
771
|
-
mats.forEach((material) => {
|
|
772
|
-
if (material instanceof webgpu.Material) {
|
|
773
|
-
Object.entries(material).forEach(([key, value]) => {
|
|
774
|
-
if (value instanceof webgpu.Texture) {
|
|
775
|
-
assetManager.releaseAsset(value);
|
|
776
|
-
value = null;
|
|
777
|
-
}
|
|
778
|
-
});
|
|
779
|
-
assetManager.releaseAsset(material);
|
|
780
|
-
}
|
|
781
|
-
});
|
|
782
|
-
this.material = [];
|
|
783
|
-
if (this.geometry instanceof webgpu.BufferGeometry) {
|
|
784
|
-
assetManager.releaseAsset(this.geometry);
|
|
785
|
-
this.geometry = null;
|
|
798
|
+
if (this.threeObject) {
|
|
799
|
+
this.threeObject.removeFromParent();
|
|
786
800
|
}
|
|
801
|
+
this._geometryPtr.release();
|
|
802
|
+
let matPtrs = Array.isArray(this._materialPtr) ? this._materialPtr : [this._materialPtr];
|
|
803
|
+
matPtrs.forEach((elem) => {
|
|
804
|
+
elem.release();
|
|
805
|
+
});
|
|
806
|
+
super.destroyObject();
|
|
787
807
|
}
|
|
788
808
|
}
|
|
789
809
|
|
|
@@ -849,29 +869,30 @@ class TAssetPointer extends TSmartPointer {
|
|
|
849
869
|
}
|
|
850
870
|
}
|
|
851
871
|
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
this.
|
|
872
|
+
class AssetManager {
|
|
873
|
+
constructor(app) {
|
|
874
|
+
this.geometryAssets = new Map();
|
|
875
|
+
this.textureAssets = new Map();
|
|
876
|
+
this.materialAssets = new Map();
|
|
856
877
|
this.dracoLoader = null;
|
|
857
878
|
this.loadingManager = new webgpu.LoadingManager();
|
|
858
879
|
this.gltfLoader = new Addons_js.GLTFLoader(this.loadingManager);
|
|
880
|
+
this.app = app;
|
|
859
881
|
}
|
|
860
882
|
get LoadingManager() {
|
|
861
883
|
return this.loadingManager;
|
|
862
884
|
}
|
|
863
|
-
static Get() {
|
|
864
|
-
return assetManager;
|
|
865
|
-
}
|
|
866
|
-
static ClearAssets() {
|
|
867
|
-
assetManager.clearAssets();
|
|
868
|
-
}
|
|
869
885
|
setupDracoLoader(dracoPath) {
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
886
|
+
if (!this.dracoLoader) {
|
|
887
|
+
this.dracoLoader = new Addons_js.DRACOLoader(this.loadingManager);
|
|
888
|
+
this.dracoLoader.setDecoderPath(dracoPath);
|
|
889
|
+
this.dracoLoader.setDecoderConfig({ type: "js" });
|
|
890
|
+
this.dracoLoader.preload();
|
|
891
|
+
this.gltfLoader.setDRACOLoader(this.dracoLoader);
|
|
892
|
+
}
|
|
893
|
+
else {
|
|
894
|
+
console.error("DracoLoader already setup");
|
|
895
|
+
}
|
|
875
896
|
}
|
|
876
897
|
convertThreeObjectToLYObject(parentLYComponent, threejsObject) {
|
|
877
898
|
let location = threejsObject.position.clone();
|
|
@@ -907,7 +928,7 @@ class LYAssetManager {
|
|
|
907
928
|
}
|
|
908
929
|
return threejsObject.userData.LYObject;
|
|
909
930
|
}
|
|
910
|
-
collectResourcesAndReferences(
|
|
931
|
+
collectResourcesAndReferences(object) {
|
|
911
932
|
function countResource(map, resource) {
|
|
912
933
|
if (!map.has(resource)) {
|
|
913
934
|
map.set(resource, 1);
|
|
@@ -921,7 +942,7 @@ class LYAssetManager {
|
|
|
921
942
|
materials: new Map(),
|
|
922
943
|
textures: new Map()
|
|
923
944
|
};
|
|
924
|
-
|
|
945
|
+
object.traverse((child) => {
|
|
925
946
|
if (child.geometry && child.geometry instanceof webgpu.BufferGeometry) {
|
|
926
947
|
countResource(resources.geometries, child.geometry);
|
|
927
948
|
}
|
|
@@ -967,7 +988,7 @@ class LYAssetManager {
|
|
|
967
988
|
}
|
|
968
989
|
Object.entries(material).forEach(([key, value]) => {
|
|
969
990
|
if (value instanceof webgpu.Texture) {
|
|
970
|
-
if (!value.userData["assetPointer"]) {
|
|
991
|
+
if (!(value.userData["assetPointer"])) {
|
|
971
992
|
this.addAsset(value);
|
|
972
993
|
}
|
|
973
994
|
}
|
|
@@ -976,36 +997,51 @@ class LYAssetManager {
|
|
|
976
997
|
});
|
|
977
998
|
}
|
|
978
999
|
}
|
|
979
|
-
loadMultiGLTFAsGroup(tasks, onProgress = null, onAllFinished = null)
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1000
|
+
// loadMultiGLTFAsGroup(tasks:LoadTask[], onProgress:((url:string, loaded:number, total:number) => void) | null = null, onAllFinished:(() => void) | null = null)
|
|
1001
|
+
// {
|
|
1002
|
+
// this.loadingManager.onLoad = onAllFinished ? () =>
|
|
1003
|
+
// {
|
|
1004
|
+
// this.loadingManager.onLoad = () =>
|
|
1005
|
+
// {
|
|
1006
|
+
// };
|
|
1007
|
+
// onAllFinished();
|
|
1008
|
+
// } : () =>
|
|
1009
|
+
// {
|
|
1010
|
+
// this.loadingManager.onLoad = () =>
|
|
1011
|
+
// {
|
|
1012
|
+
// };
|
|
1013
|
+
// };
|
|
1014
|
+
// this.loadingManager.onProgress = onProgress ? (url, loaded, total) =>
|
|
1015
|
+
// {
|
|
1016
|
+
// onProgress(url, loaded, total);
|
|
1017
|
+
// } : () =>
|
|
1018
|
+
// {
|
|
1019
|
+
// };
|
|
1020
|
+
// tasks.forEach(
|
|
1021
|
+
// (task) =>
|
|
1022
|
+
// {
|
|
1023
|
+
// task.Paths.forEach(
|
|
1024
|
+
// (path) =>
|
|
1025
|
+
// {
|
|
1026
|
+
// const onGlbLoaded = (glb:GLTF) =>
|
|
1027
|
+
// {
|
|
1028
|
+
// task.onLoadingFinished(glb);
|
|
1029
|
+
// this.collectResourcesAndReferences(glb.scene);
|
|
1030
|
+
// };
|
|
1031
|
+
// try
|
|
1032
|
+
// {
|
|
1033
|
+
// this.gltfLoader.load(path, (glb:GLTF) =>
|
|
1034
|
+
// {
|
|
1035
|
+
// onGlbLoaded(glb);
|
|
1036
|
+
// });
|
|
1037
|
+
// } catch (e)
|
|
1038
|
+
// {
|
|
1039
|
+
// console.error(e, path);
|
|
1040
|
+
// }
|
|
1041
|
+
// });
|
|
1042
|
+
// }
|
|
1043
|
+
// );
|
|
1044
|
+
// }
|
|
1009
1045
|
loadGltfFromBuffer(data, path, onLoadFinished) {
|
|
1010
1046
|
this.gltfLoader.parse(data, path, onLoadFinished);
|
|
1011
1047
|
}
|
|
@@ -1016,18 +1052,49 @@ class LYAssetManager {
|
|
|
1016
1052
|
});
|
|
1017
1053
|
}
|
|
1018
1054
|
addAsset(asset, referenceCount = 1) {
|
|
1019
|
-
|
|
1020
|
-
|
|
1055
|
+
if (asset instanceof webgpu.BufferGeometry) {
|
|
1056
|
+
return this.addGeometryAsset(asset, referenceCount);
|
|
1057
|
+
}
|
|
1058
|
+
else if (asset instanceof webgpu.Material) {
|
|
1059
|
+
return this.addMaterialAsset(asset, referenceCount);
|
|
1060
|
+
}
|
|
1061
|
+
else if (asset instanceof webgpu.Texture) {
|
|
1062
|
+
return this.addTextureAsset(asset, referenceCount);
|
|
1063
|
+
}
|
|
1064
|
+
return undefined;
|
|
1065
|
+
}
|
|
1066
|
+
addMaterialAsset(asset, referenceCount = 1) {
|
|
1067
|
+
let pointer = (asset.userData["assetPointer"]);
|
|
1068
|
+
if (!pointer) {
|
|
1069
|
+
pointer = new TAssetPointer(asset, referenceCount);
|
|
1070
|
+
}
|
|
1071
|
+
else {
|
|
1072
|
+
pointer = asset.userData["assetPointer"];
|
|
1073
|
+
pointer.addRef(referenceCount);
|
|
1074
|
+
}
|
|
1075
|
+
return pointer;
|
|
1076
|
+
}
|
|
1077
|
+
addTextureAsset(asset, referenceCount = 1) {
|
|
1078
|
+
let pointer = (asset.userData["assetPointer"]);
|
|
1079
|
+
if (!pointer) {
|
|
1021
1080
|
pointer = new TAssetPointer(asset, referenceCount);
|
|
1022
|
-
asset.userData["assetPointer"] = pointer;
|
|
1023
1081
|
}
|
|
1024
1082
|
else {
|
|
1025
1083
|
pointer = asset.userData["assetPointer"];
|
|
1026
1084
|
pointer.addRef(referenceCount);
|
|
1027
1085
|
}
|
|
1028
|
-
|
|
1029
|
-
|
|
1086
|
+
return pointer;
|
|
1087
|
+
}
|
|
1088
|
+
addGeometryAsset(asset, referenceCount = 1) {
|
|
1089
|
+
let pointer = (asset.userData["assetPointer"]);
|
|
1090
|
+
if (!pointer) {
|
|
1091
|
+
pointer = new TAssetPointer(asset, referenceCount);
|
|
1092
|
+
}
|
|
1093
|
+
else {
|
|
1094
|
+
pointer = asset.userData["assetPointer"];
|
|
1095
|
+
pointer.addRef(referenceCount);
|
|
1030
1096
|
}
|
|
1097
|
+
return pointer;
|
|
1031
1098
|
}
|
|
1032
1099
|
releaseAsset(asset) {
|
|
1033
1100
|
// let uuid = asset.uuid
|
|
@@ -1040,14 +1107,26 @@ class LYAssetManager {
|
|
|
1040
1107
|
}
|
|
1041
1108
|
}
|
|
1042
1109
|
clearAssets() {
|
|
1043
|
-
|
|
1044
|
-
|
|
1110
|
+
this.geometryAssets.forEach((p) => {
|
|
1111
|
+
p.forceRelease();
|
|
1112
|
+
});
|
|
1113
|
+
this.geometryAssets.clear();
|
|
1114
|
+
this.materialAssets.forEach((p) => {
|
|
1045
1115
|
p.forceRelease();
|
|
1046
1116
|
});
|
|
1047
|
-
this.
|
|
1117
|
+
this.materialAssets.clear();
|
|
1118
|
+
this.textureAssets.forEach((p) => {
|
|
1119
|
+
p.forceRelease();
|
|
1120
|
+
});
|
|
1121
|
+
this.textureAssets.clear();
|
|
1122
|
+
// let pointers = Array.from(this.assetPointer.values());
|
|
1123
|
+
// pointers.forEach((p) =>
|
|
1124
|
+
// {
|
|
1125
|
+
// p.forceRelease();
|
|
1126
|
+
// });
|
|
1127
|
+
// this.assetPointer.clear();
|
|
1048
1128
|
}
|
|
1049
1129
|
}
|
|
1050
|
-
const assetManager = new LYAssetManager();
|
|
1051
1130
|
|
|
1052
1131
|
class Delegate {
|
|
1053
1132
|
constructor() {
|
|
@@ -1664,26 +1743,31 @@ class Viewport {
|
|
|
1664
1743
|
}
|
|
1665
1744
|
this.isRenderStateDirty = false;
|
|
1666
1745
|
}
|
|
1667
|
-
renderAsImage(width = 1024, height = 1024) {
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1746
|
+
async renderAsImage(width = 1024, height = 1024) {
|
|
1747
|
+
return new Promise((resolve, reject) => {
|
|
1748
|
+
try {
|
|
1749
|
+
if (this.postProcessing) {
|
|
1750
|
+
this.postProcessing.render();
|
|
1751
|
+
}
|
|
1752
|
+
else {
|
|
1753
|
+
this.renderer.render(this.app.world.scene, this.app.camera);
|
|
1754
|
+
}
|
|
1755
|
+
const offscreenCanvas = document.createElement('canvas');
|
|
1756
|
+
offscreenCanvas.width = width;
|
|
1757
|
+
offscreenCanvas.height = height;
|
|
1758
|
+
const context = offscreenCanvas.getContext('2d');
|
|
1759
|
+
if (!context) {
|
|
1760
|
+
throw Error("Can not create context");
|
|
1761
|
+
}
|
|
1762
|
+
context.drawImage(this.renderer.domElement, 0, 0, width, height);
|
|
1763
|
+
const ret = offscreenCanvas.toDataURL('image/jpeg');
|
|
1764
|
+
offscreenCanvas.remove();
|
|
1765
|
+
resolve(ret);
|
|
1766
|
+
}
|
|
1767
|
+
catch (error) {
|
|
1768
|
+
reject(error);
|
|
1769
|
+
}
|
|
1770
|
+
});
|
|
1687
1771
|
}
|
|
1688
1772
|
destroy() {
|
|
1689
1773
|
var _a;
|
|
@@ -2087,6 +2171,12 @@ const DefaultAppParam = {
|
|
|
2087
2171
|
renderParam: DefaultRenderParam,
|
|
2088
2172
|
cameraParam: DefaultCameraParam,
|
|
2089
2173
|
postProcessParam: DefaultPostProcessParam,
|
|
2174
|
+
classes: {
|
|
2175
|
+
assetManagerClass: AssetManager,
|
|
2176
|
+
controllerClass: Controller,
|
|
2177
|
+
worldClass: World,
|
|
2178
|
+
viewportClass: Viewport,
|
|
2179
|
+
}
|
|
2090
2180
|
};
|
|
2091
2181
|
|
|
2092
2182
|
class ThreeJsApp {
|
|
@@ -2105,14 +2195,8 @@ class ThreeJsApp {
|
|
|
2105
2195
|
get controller() {
|
|
2106
2196
|
return this._controller;
|
|
2107
2197
|
}
|
|
2108
|
-
get
|
|
2109
|
-
return
|
|
2110
|
-
}
|
|
2111
|
-
get viewportClass() {
|
|
2112
|
-
return Viewport;
|
|
2113
|
-
}
|
|
2114
|
-
get controllerClass() {
|
|
2115
|
-
return Controller;
|
|
2198
|
+
get assetManager() {
|
|
2199
|
+
return this._assetManager;
|
|
2116
2200
|
}
|
|
2117
2201
|
get appParam() {
|
|
2118
2202
|
return this._appParam;
|
|
@@ -2126,11 +2210,18 @@ class ThreeJsApp {
|
|
|
2126
2210
|
this._appParam.cameraParam = appParam.cameraParam ? appParam.cameraParam : DefaultCameraParam;
|
|
2127
2211
|
this._appParam.renderParam = appParam.renderParam ? appParam.renderParam : DefaultRenderParam;
|
|
2128
2212
|
this._appParam.postProcessParam = appParam.postProcessParam ? appParam.postProcessParam : DefaultPostProcessParam;
|
|
2213
|
+
this._appParam.classes = appParam.classes ? appParam.classes : {
|
|
2214
|
+
assetManagerClass: AssetManager,
|
|
2215
|
+
controllerClass: Controller,
|
|
2216
|
+
worldClass: World,
|
|
2217
|
+
viewportClass: Viewport,
|
|
2218
|
+
};
|
|
2129
2219
|
this._clock = new webgpu.Clock();
|
|
2130
2220
|
this._camera = CameraFactory.createCamera(this._appParam.cameraParam);
|
|
2131
|
-
this._world = new this.worldClass(this);
|
|
2132
|
-
this._viewport = new this.viewportClass(this, elementId, this._appParam.renderParam, this._appParam.postProcessParam);
|
|
2133
|
-
this._controller = new this.controllerClass(this);
|
|
2221
|
+
this._world = new this._appParam.classes.worldClass(this);
|
|
2222
|
+
this._viewport = new this._appParam.classes.viewportClass(this, elementId, this._appParam.renderParam, this._appParam.postProcessParam);
|
|
2223
|
+
this._controller = new this._appParam.classes.controllerClass(this);
|
|
2224
|
+
this._assetManager = new this._appParam.classes.assetManagerClass(this);
|
|
2134
2225
|
this.viewport.renderer.setAnimationLoop(() => {
|
|
2135
2226
|
this.tick();
|
|
2136
2227
|
});
|
|
@@ -2152,6 +2243,7 @@ class ThreeJsApp {
|
|
|
2152
2243
|
this.world.destroy();
|
|
2153
2244
|
this.controller.destroy();
|
|
2154
2245
|
this.viewport.destroy();
|
|
2246
|
+
this._assetManager.clearAssets();
|
|
2155
2247
|
}
|
|
2156
2248
|
updateCamera(param) {
|
|
2157
2249
|
const previousCam = this.camera;
|
|
@@ -2172,8 +2264,8 @@ class ThreeJsApp {
|
|
|
2172
2264
|
// }
|
|
2173
2265
|
this.camera.updateProjectionMatrix();
|
|
2174
2266
|
}
|
|
2175
|
-
renderAsImage(width = 1024, height = 1024) {
|
|
2176
|
-
return this.viewport.renderAsImage(width, height);
|
|
2267
|
+
async renderAsImage(width = 1024, height = 1024) {
|
|
2268
|
+
return await this.viewport.renderAsImage(width, height);
|
|
2177
2269
|
}
|
|
2178
2270
|
}
|
|
2179
2271
|
|
|
@@ -2229,7 +2321,7 @@ class Actor extends BaseObject {
|
|
|
2229
2321
|
get isVisible() {
|
|
2230
2322
|
return this.rootComponent ? this.rootComponent.isVisible : false;
|
|
2231
2323
|
}
|
|
2232
|
-
constructor(myThreeObject = null) {
|
|
2324
|
+
constructor(app, myThreeObject = null) {
|
|
2233
2325
|
super();
|
|
2234
2326
|
this._name = "Actor";
|
|
2235
2327
|
this._rootComponent = null;
|
|
@@ -2238,17 +2330,18 @@ class Actor extends BaseObject {
|
|
|
2238
2330
|
this.onDoubleClickedEvent = [];
|
|
2239
2331
|
this.onHoverBeginEvent = [];
|
|
2240
2332
|
this.onHoverEndEvent = [];
|
|
2333
|
+
this.app = app;
|
|
2241
2334
|
this.constructRootComponent(myThreeObject);
|
|
2242
2335
|
}
|
|
2243
2336
|
constructRootComponent(myThreeObject = null) {
|
|
2244
2337
|
let tObject = myThreeObject ? myThreeObject : new webgpu.Group();
|
|
2245
2338
|
if (tObject.isMesh) {
|
|
2246
2339
|
let mesh = tObject;
|
|
2247
|
-
this._rootComponent = new MeshComponent(mesh);
|
|
2340
|
+
this._rootComponent = new MeshComponent(this.app, mesh.geometry, mesh.material);
|
|
2248
2341
|
this.rootComponent.parentActor = this;
|
|
2249
2342
|
}
|
|
2250
2343
|
else {
|
|
2251
|
-
this._rootComponent = new SceneComponent(tObject);
|
|
2344
|
+
this._rootComponent = new SceneComponent(this.app, tObject);
|
|
2252
2345
|
this.rootComponent.parentActor = this;
|
|
2253
2346
|
}
|
|
2254
2347
|
}
|
|
@@ -2581,8 +2674,8 @@ class LightComponent extends SceneComponent {
|
|
|
2581
2674
|
set intensity(intensity) {
|
|
2582
2675
|
this.threeObject.intensity = intensity;
|
|
2583
2676
|
}
|
|
2584
|
-
constructor(light) {
|
|
2585
|
-
super(light);
|
|
2677
|
+
constructor(app, light) {
|
|
2678
|
+
super(app, light);
|
|
2586
2679
|
this.obj = light;
|
|
2587
2680
|
}
|
|
2588
2681
|
}
|
|
@@ -2606,9 +2699,9 @@ class DirectionalLightComponent extends LightComponent {
|
|
|
2606
2699
|
set castShadow(value) {
|
|
2607
2700
|
this.threeObject.castShadow = value;
|
|
2608
2701
|
}
|
|
2609
|
-
constructor(color = 0xffffff, intensity = 10) {
|
|
2702
|
+
constructor(app, color = 0xffffff, intensity = 10) {
|
|
2610
2703
|
let obj = new webgpu.DirectionalLight(color, intensity);
|
|
2611
|
-
super(obj);
|
|
2704
|
+
super(app, obj);
|
|
2612
2705
|
this.obj = obj;
|
|
2613
2706
|
obj.castShadow = true;
|
|
2614
2707
|
}
|
|
@@ -2637,8 +2730,8 @@ class DirectionalLightComponent extends LightComponent {
|
|
|
2637
2730
|
}
|
|
2638
2731
|
|
|
2639
2732
|
class DirectionalLightActor extends Actor {
|
|
2640
|
-
constructor(color = 0xffffff, intensity = 1) {
|
|
2641
|
-
super();
|
|
2733
|
+
constructor(app, color = 0xffffff, intensity = 1) {
|
|
2734
|
+
super(app);
|
|
2642
2735
|
this.lightComponent = null;
|
|
2643
2736
|
this.lightComponent = this.rootComponent;
|
|
2644
2737
|
if (this.lightComponent) {
|
|
@@ -2648,7 +2741,7 @@ class DirectionalLightActor extends Actor {
|
|
|
2648
2741
|
this.lightComponent.castShadow = true;
|
|
2649
2742
|
}
|
|
2650
2743
|
constructRootComponent() {
|
|
2651
|
-
this.lightComponent = new DirectionalLightComponent();
|
|
2744
|
+
this.lightComponent = new DirectionalLightComponent(this.app);
|
|
2652
2745
|
this.rootComponent = this.lightComponent;
|
|
2653
2746
|
this.lightComponent.castShadow = true;
|
|
2654
2747
|
this.rootComponent.parentActor = this;
|
|
@@ -2656,15 +2749,15 @@ class DirectionalLightActor extends Actor {
|
|
|
2656
2749
|
}
|
|
2657
2750
|
|
|
2658
2751
|
class BoxComponent extends MeshComponent {
|
|
2659
|
-
constructor(width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1, material = new webgpu.MeshStandardMaterial()) {
|
|
2660
|
-
super(new webgpu.BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments), material);
|
|
2752
|
+
constructor(app, width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1, material = new webgpu.MeshStandardMaterial()) {
|
|
2753
|
+
super(app, new webgpu.BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments), material);
|
|
2661
2754
|
}
|
|
2662
2755
|
}
|
|
2663
2756
|
|
|
2664
2757
|
class BoxActor extends Actor {
|
|
2665
|
-
constructor(width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1, material = new webgpu.MeshBasicMaterial()) {
|
|
2666
|
-
super();
|
|
2667
|
-
this.addComponent(new BoxComponent(width, height, depth, widthSegments, heightSegments, depthSegments, material));
|
|
2758
|
+
constructor(app, width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1, material = new webgpu.MeshBasicMaterial()) {
|
|
2759
|
+
super(app);
|
|
2760
|
+
this.addComponent(new BoxComponent(this.app, width, height, depth, widthSegments, heightSegments, depthSegments, material));
|
|
2668
2761
|
}
|
|
2669
2762
|
}
|
|
2670
2763
|
|
|
@@ -2689,9 +2782,9 @@ class SkyComponent extends SceneComponent {
|
|
|
2689
2782
|
this.obj.userData["LYObject"] = this;
|
|
2690
2783
|
}
|
|
2691
2784
|
}
|
|
2692
|
-
constructor(skyparam) {
|
|
2785
|
+
constructor(app, skyparam) {
|
|
2693
2786
|
let obj = new SkyMesh_js.SkyMesh();
|
|
2694
|
-
super(obj);
|
|
2787
|
+
super(app, obj);
|
|
2695
2788
|
this.skyParam = DefaultSkyParam;
|
|
2696
2789
|
this.sunPosition = new webgpu.Vector3();
|
|
2697
2790
|
this.obj = obj;
|
|
@@ -2713,11 +2806,14 @@ class SkyComponent extends SceneComponent {
|
|
|
2713
2806
|
this.threeObject.sunPosition.value.copy(this.sunPosition);
|
|
2714
2807
|
(_b = (_a = this.world) === null || _a === void 0 ? void 0 : _a.viewport) === null || _b === void 0 ? void 0 : _b.markRenderStateDirty();
|
|
2715
2808
|
}
|
|
2809
|
+
destroyObject() {
|
|
2810
|
+
ThreeObjectLibrary.disposeMeshResource(this.obj);
|
|
2811
|
+
}
|
|
2716
2812
|
}
|
|
2717
2813
|
|
|
2718
2814
|
class SkyActor extends Actor {
|
|
2719
|
-
constructor() {
|
|
2720
|
-
super();
|
|
2815
|
+
constructor(app) {
|
|
2816
|
+
super(app);
|
|
2721
2817
|
this._name = "SkyActor";
|
|
2722
2818
|
this.skyComponent = null;
|
|
2723
2819
|
this.name = "DirectionalLightActor";
|
|
@@ -2726,15 +2822,15 @@ class SkyActor extends Actor {
|
|
|
2726
2822
|
this.setScale(45000, 45000, 45000);
|
|
2727
2823
|
}
|
|
2728
2824
|
constructRootComponent() {
|
|
2729
|
-
this.skyComponent = new SkyComponent();
|
|
2825
|
+
this.skyComponent = new SkyComponent(this.app);
|
|
2730
2826
|
this.rootComponent = this.skyComponent;
|
|
2731
2827
|
this.rootComponent.parentActor = this;
|
|
2732
2828
|
}
|
|
2733
2829
|
}
|
|
2734
2830
|
|
|
2735
2831
|
class PlaneComponent extends MeshComponent {
|
|
2736
|
-
constructor(width, height, material, widthSegments = 1, heightSegments = 1) {
|
|
2737
|
-
super(new webgpu.PlaneGeometry(width, height, widthSegments, heightSegments), material);
|
|
2832
|
+
constructor(app, width, height, material, widthSegments = 1, heightSegments = 1) {
|
|
2833
|
+
super(app, new webgpu.PlaneGeometry(width, height, widthSegments, heightSegments), material);
|
|
2738
2834
|
}
|
|
2739
2835
|
}
|
|
2740
2836
|
|
|
@@ -2742,9 +2838,9 @@ class PlaneActor extends Actor {
|
|
|
2742
2838
|
get planeComponent() {
|
|
2743
2839
|
return this._planeComponent;
|
|
2744
2840
|
}
|
|
2745
|
-
constructor(width, height, material = new webgpu.MeshBasicMaterial(), widthSegments = 1, heightSegments = 1) {
|
|
2746
|
-
super();
|
|
2747
|
-
this._planeComponent = new PlaneComponent(width, height, material, widthSegments, heightSegments);
|
|
2841
|
+
constructor(app, width, height, material = new webgpu.MeshBasicMaterial(), widthSegments = 1, heightSegments = 1) {
|
|
2842
|
+
super(app);
|
|
2843
|
+
this._planeComponent = new PlaneComponent(this.app, width, height, material, widthSegments, heightSegments);
|
|
2748
2844
|
this._planeComponent.setRotation(Math.PI * 0.5 * -1, 0, 0);
|
|
2749
2845
|
this.addComponent(this._planeComponent);
|
|
2750
2846
|
this._planeComponent.receiveShadow = true;
|
|
@@ -2758,8 +2854,8 @@ class PlaneActor extends Actor {
|
|
|
2758
2854
|
}
|
|
2759
2855
|
|
|
2760
2856
|
class SphereComponent extends MeshComponent {
|
|
2761
|
-
constructor(radius, material = new webgpu.MeshBasicMaterial(), widthSegments = 32, heightSegments = 16) {
|
|
2762
|
-
super(new webgpu.SphereGeometry(radius, widthSegments, heightSegments), material);
|
|
2857
|
+
constructor(app, radius, material = new webgpu.MeshBasicMaterial(), widthSegments = 32, heightSegments = 16) {
|
|
2858
|
+
super(app, new webgpu.SphereGeometry(radius, widthSegments, heightSegments), material);
|
|
2763
2859
|
}
|
|
2764
2860
|
}
|
|
2765
2861
|
|
|
@@ -2773,9 +2869,9 @@ class LabelComponent extends SceneComponent {
|
|
|
2773
2869
|
this.obj.userData["LYObject"] = this;
|
|
2774
2870
|
}
|
|
2775
2871
|
}
|
|
2776
|
-
constructor(domElement, center = new webgpu.Vector2(0.5, 1)) {
|
|
2872
|
+
constructor(app, domElement, center = new webgpu.Vector2(0.5, 1)) {
|
|
2777
2873
|
let obj = new CSS2DRenderer_js.CSS2DObject(domElement);
|
|
2778
|
-
super(obj);
|
|
2874
|
+
super(app, obj);
|
|
2779
2875
|
this.obj = obj;
|
|
2780
2876
|
obj.center = center;
|
|
2781
2877
|
}
|
|
@@ -3003,6 +3099,7 @@ class TransformGizmo extends Pawn {
|
|
|
3003
3099
|
}
|
|
3004
3100
|
|
|
3005
3101
|
exports.Actor = Actor;
|
|
3102
|
+
exports.AssetManager = AssetManager;
|
|
3006
3103
|
exports.BoxActor = BoxActor;
|
|
3007
3104
|
exports.BoxComponent = BoxComponent;
|
|
3008
3105
|
exports.Controller = Controller;
|
|
@@ -3021,8 +3118,6 @@ exports.Delegate = Delegate;
|
|
|
3021
3118
|
exports.DirectionalLightActor = DirectionalLightActor;
|
|
3022
3119
|
exports.DirectionalLightComponent = DirectionalLightComponent;
|
|
3023
3120
|
exports.FirstPerson = FirstPerson;
|
|
3024
|
-
exports.LYAssetManager = LYAssetManager;
|
|
3025
|
-
exports.LYLoadTask = LYLoadTask;
|
|
3026
3121
|
exports.LabelComponent = LabelComponent;
|
|
3027
3122
|
exports.MeshComponent = MeshComponent;
|
|
3028
3123
|
exports.Orbital = Orbital;
|