lythreeframe 1.0.33 → 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.
@@ -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
- constructor(newThreeObject) {
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.world = null;
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(this.world);
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
- return this.threeObject ? this.threeObject.geometry : null;
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
- if (!this.threeObject) {
696
- return;
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
- return this.threeObject ? this.threeObject.material : null;
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
- if (!this.threeObject) {
705
- return;
706
- }
707
- this.threeObject.material = newMat;
708
- if (this.world) {
709
- this.world.viewport.markRenderStateDirty();
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
- constructor(...args) {
713
- let newMesh = null;
714
- if (args[0] instanceof webgpu.Mesh) {
715
- newMesh = args[0];
726
+ set materialPtr(newMat) {
727
+ if (this._materialPtr) {
728
+ this._materialPtr.forEach((elem) => {
729
+ elem.release();
730
+ });
731
+ this._materialPtr = [];
716
732
  }
717
- else {
718
- if (args[0] instanceof webgpu.BufferGeometry && (args[1] instanceof webgpu.Material || Array.isArray(args[1]))) {
719
- newMesh = new webgpu.Mesh(args[0], args[1]);
720
- }
721
- else {
722
- throw new Error('Invalid arguments for A constructor');
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
- super(newMesh);
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.world && this.world.scene && this.threeObject) {
767
- this.world.scene.remove(this.threeObject);
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
- // this class should be a singleton
853
- class LYAssetManager {
854
- constructor() {
855
- this.assetPointer = new Map();
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
- this.dracoLoader = new Addons_js.DRACOLoader(this.loadingManager);
871
- this.dracoLoader.setDecoderPath(dracoPath);
872
- this.dracoLoader.setDecoderConfig({ type: "js" });
873
- this.dracoLoader.preload();
874
- this.gltfLoader.setDRACOLoader(this.dracoLoader);
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(gltf) {
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
- gltf.scene.traverse((child) => {
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
- this.loadingManager.onLoad = onAllFinished ? () => {
981
- this.loadingManager.onLoad = () => {
982
- };
983
- onAllFinished();
984
- } : () => {
985
- this.loadingManager.onLoad = () => {
986
- };
987
- };
988
- this.loadingManager.onProgress = onProgress ? (url, loaded, total) => {
989
- onProgress(url, loaded, total);
990
- } : () => {
991
- };
992
- tasks.forEach((task) => {
993
- task.Paths.forEach((path) => {
994
- const onGlbLoaded = (glb) => {
995
- task.onLoadingFinished(glb);
996
- this.collectResourcesAndReferences(glb);
997
- };
998
- try {
999
- this.gltfLoader.load(path, (glb) => {
1000
- onGlbLoaded(glb);
1001
- });
1002
- }
1003
- catch (e) {
1004
- console.error(e, path);
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
- let pointer = null;
1020
- if (!asset.userData["assetPointer"]) {
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
- if (pointer) {
1029
- this.assetPointer.set(pointer.uuid, pointer);
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
- let pointers = Array.from(this.assetPointer.values());
1044
- pointers.forEach((p) => {
1110
+ this.geometryAssets.forEach((p) => {
1045
1111
  p.forceRelease();
1046
1112
  });
1047
- this.assetPointer.clear();
1113
+ this.geometryAssets.clear();
1114
+ this.materialAssets.forEach((p) => {
1115
+ p.forceRelease();
1116
+ });
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() {
@@ -2092,6 +2171,12 @@ const DefaultAppParam = {
2092
2171
  renderParam: DefaultRenderParam,
2093
2172
  cameraParam: DefaultCameraParam,
2094
2173
  postProcessParam: DefaultPostProcessParam,
2174
+ classes: {
2175
+ assetManagerClass: AssetManager,
2176
+ controllerClass: Controller,
2177
+ worldClass: World,
2178
+ viewportClass: Viewport,
2179
+ }
2095
2180
  };
2096
2181
 
2097
2182
  class ThreeJsApp {
@@ -2110,14 +2195,8 @@ class ThreeJsApp {
2110
2195
  get controller() {
2111
2196
  return this._controller;
2112
2197
  }
2113
- get worldClass() {
2114
- return World;
2115
- }
2116
- get viewportClass() {
2117
- return Viewport;
2118
- }
2119
- get controllerClass() {
2120
- return Controller;
2198
+ get assetManager() {
2199
+ return this._assetManager;
2121
2200
  }
2122
2201
  get appParam() {
2123
2202
  return this._appParam;
@@ -2131,11 +2210,18 @@ class ThreeJsApp {
2131
2210
  this._appParam.cameraParam = appParam.cameraParam ? appParam.cameraParam : DefaultCameraParam;
2132
2211
  this._appParam.renderParam = appParam.renderParam ? appParam.renderParam : DefaultRenderParam;
2133
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
+ };
2134
2219
  this._clock = new webgpu.Clock();
2135
2220
  this._camera = CameraFactory.createCamera(this._appParam.cameraParam);
2136
- this._world = new this.worldClass(this);
2137
- this._viewport = new this.viewportClass(this, elementId, this._appParam.renderParam, this._appParam.postProcessParam);
2138
- 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);
2139
2225
  this.viewport.renderer.setAnimationLoop(() => {
2140
2226
  this.tick();
2141
2227
  });
@@ -2157,6 +2243,7 @@ class ThreeJsApp {
2157
2243
  this.world.destroy();
2158
2244
  this.controller.destroy();
2159
2245
  this.viewport.destroy();
2246
+ this._assetManager.clearAssets();
2160
2247
  }
2161
2248
  updateCamera(param) {
2162
2249
  const previousCam = this.camera;
@@ -2234,7 +2321,7 @@ class Actor extends BaseObject {
2234
2321
  get isVisible() {
2235
2322
  return this.rootComponent ? this.rootComponent.isVisible : false;
2236
2323
  }
2237
- constructor(myThreeObject = null) {
2324
+ constructor(app, myThreeObject = null) {
2238
2325
  super();
2239
2326
  this._name = "Actor";
2240
2327
  this._rootComponent = null;
@@ -2243,17 +2330,18 @@ class Actor extends BaseObject {
2243
2330
  this.onDoubleClickedEvent = [];
2244
2331
  this.onHoverBeginEvent = [];
2245
2332
  this.onHoverEndEvent = [];
2333
+ this.app = app;
2246
2334
  this.constructRootComponent(myThreeObject);
2247
2335
  }
2248
2336
  constructRootComponent(myThreeObject = null) {
2249
2337
  let tObject = myThreeObject ? myThreeObject : new webgpu.Group();
2250
2338
  if (tObject.isMesh) {
2251
2339
  let mesh = tObject;
2252
- this._rootComponent = new MeshComponent(mesh);
2340
+ this._rootComponent = new MeshComponent(this.app, mesh.geometry, mesh.material);
2253
2341
  this.rootComponent.parentActor = this;
2254
2342
  }
2255
2343
  else {
2256
- this._rootComponent = new SceneComponent(tObject);
2344
+ this._rootComponent = new SceneComponent(this.app, tObject);
2257
2345
  this.rootComponent.parentActor = this;
2258
2346
  }
2259
2347
  }
@@ -2586,8 +2674,8 @@ class LightComponent extends SceneComponent {
2586
2674
  set intensity(intensity) {
2587
2675
  this.threeObject.intensity = intensity;
2588
2676
  }
2589
- constructor(light) {
2590
- super(light);
2677
+ constructor(app, light) {
2678
+ super(app, light);
2591
2679
  this.obj = light;
2592
2680
  }
2593
2681
  }
@@ -2611,9 +2699,9 @@ class DirectionalLightComponent extends LightComponent {
2611
2699
  set castShadow(value) {
2612
2700
  this.threeObject.castShadow = value;
2613
2701
  }
2614
- constructor(color = 0xffffff, intensity = 10) {
2702
+ constructor(app, color = 0xffffff, intensity = 10) {
2615
2703
  let obj = new webgpu.DirectionalLight(color, intensity);
2616
- super(obj);
2704
+ super(app, obj);
2617
2705
  this.obj = obj;
2618
2706
  obj.castShadow = true;
2619
2707
  }
@@ -2642,8 +2730,8 @@ class DirectionalLightComponent extends LightComponent {
2642
2730
  }
2643
2731
 
2644
2732
  class DirectionalLightActor extends Actor {
2645
- constructor(color = 0xffffff, intensity = 1) {
2646
- super();
2733
+ constructor(app, color = 0xffffff, intensity = 1) {
2734
+ super(app);
2647
2735
  this.lightComponent = null;
2648
2736
  this.lightComponent = this.rootComponent;
2649
2737
  if (this.lightComponent) {
@@ -2653,7 +2741,7 @@ class DirectionalLightActor extends Actor {
2653
2741
  this.lightComponent.castShadow = true;
2654
2742
  }
2655
2743
  constructRootComponent() {
2656
- this.lightComponent = new DirectionalLightComponent();
2744
+ this.lightComponent = new DirectionalLightComponent(this.app);
2657
2745
  this.rootComponent = this.lightComponent;
2658
2746
  this.lightComponent.castShadow = true;
2659
2747
  this.rootComponent.parentActor = this;
@@ -2661,15 +2749,15 @@ class DirectionalLightActor extends Actor {
2661
2749
  }
2662
2750
 
2663
2751
  class BoxComponent extends MeshComponent {
2664
- constructor(width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1, material = new webgpu.MeshStandardMaterial()) {
2665
- 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);
2666
2754
  }
2667
2755
  }
2668
2756
 
2669
2757
  class BoxActor extends Actor {
2670
- constructor(width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1, material = new webgpu.MeshBasicMaterial()) {
2671
- super();
2672
- 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));
2673
2761
  }
2674
2762
  }
2675
2763
 
@@ -2694,9 +2782,9 @@ class SkyComponent extends SceneComponent {
2694
2782
  this.obj.userData["LYObject"] = this;
2695
2783
  }
2696
2784
  }
2697
- constructor(skyparam) {
2785
+ constructor(app, skyparam) {
2698
2786
  let obj = new SkyMesh_js.SkyMesh();
2699
- super(obj);
2787
+ super(app, obj);
2700
2788
  this.skyParam = DefaultSkyParam;
2701
2789
  this.sunPosition = new webgpu.Vector3();
2702
2790
  this.obj = obj;
@@ -2718,11 +2806,14 @@ class SkyComponent extends SceneComponent {
2718
2806
  this.threeObject.sunPosition.value.copy(this.sunPosition);
2719
2807
  (_b = (_a = this.world) === null || _a === void 0 ? void 0 : _a.viewport) === null || _b === void 0 ? void 0 : _b.markRenderStateDirty();
2720
2808
  }
2809
+ destroyObject() {
2810
+ ThreeObjectLibrary.disposeMeshResource(this.obj);
2811
+ }
2721
2812
  }
2722
2813
 
2723
2814
  class SkyActor extends Actor {
2724
- constructor() {
2725
- super();
2815
+ constructor(app) {
2816
+ super(app);
2726
2817
  this._name = "SkyActor";
2727
2818
  this.skyComponent = null;
2728
2819
  this.name = "DirectionalLightActor";
@@ -2731,15 +2822,15 @@ class SkyActor extends Actor {
2731
2822
  this.setScale(45000, 45000, 45000);
2732
2823
  }
2733
2824
  constructRootComponent() {
2734
- this.skyComponent = new SkyComponent();
2825
+ this.skyComponent = new SkyComponent(this.app);
2735
2826
  this.rootComponent = this.skyComponent;
2736
2827
  this.rootComponent.parentActor = this;
2737
2828
  }
2738
2829
  }
2739
2830
 
2740
2831
  class PlaneComponent extends MeshComponent {
2741
- constructor(width, height, material, widthSegments = 1, heightSegments = 1) {
2742
- 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);
2743
2834
  }
2744
2835
  }
2745
2836
 
@@ -2747,9 +2838,9 @@ class PlaneActor extends Actor {
2747
2838
  get planeComponent() {
2748
2839
  return this._planeComponent;
2749
2840
  }
2750
- constructor(width, height, material = new webgpu.MeshBasicMaterial(), widthSegments = 1, heightSegments = 1) {
2751
- super();
2752
- 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);
2753
2844
  this._planeComponent.setRotation(Math.PI * 0.5 * -1, 0, 0);
2754
2845
  this.addComponent(this._planeComponent);
2755
2846
  this._planeComponent.receiveShadow = true;
@@ -2763,8 +2854,8 @@ class PlaneActor extends Actor {
2763
2854
  }
2764
2855
 
2765
2856
  class SphereComponent extends MeshComponent {
2766
- constructor(radius, material = new webgpu.MeshBasicMaterial(), widthSegments = 32, heightSegments = 16) {
2767
- 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);
2768
2859
  }
2769
2860
  }
2770
2861
 
@@ -2778,9 +2869,9 @@ class LabelComponent extends SceneComponent {
2778
2869
  this.obj.userData["LYObject"] = this;
2779
2870
  }
2780
2871
  }
2781
- constructor(domElement, center = new webgpu.Vector2(0.5, 1)) {
2872
+ constructor(app, domElement, center = new webgpu.Vector2(0.5, 1)) {
2782
2873
  let obj = new CSS2DRenderer_js.CSS2DObject(domElement);
2783
- super(obj);
2874
+ super(app, obj);
2784
2875
  this.obj = obj;
2785
2876
  obj.center = center;
2786
2877
  }
@@ -3008,6 +3099,7 @@ class TransformGizmo extends Pawn {
3008
3099
  }
3009
3100
 
3010
3101
  exports.Actor = Actor;
3102
+ exports.AssetManager = AssetManager;
3011
3103
  exports.BoxActor = BoxActor;
3012
3104
  exports.BoxComponent = BoxComponent;
3013
3105
  exports.Controller = Controller;
@@ -3026,8 +3118,6 @@ exports.Delegate = Delegate;
3026
3118
  exports.DirectionalLightActor = DirectionalLightActor;
3027
3119
  exports.DirectionalLightComponent = DirectionalLightComponent;
3028
3120
  exports.FirstPerson = FirstPerson;
3029
- exports.LYAssetManager = LYAssetManager;
3030
- exports.LYLoadTask = LYLoadTask;
3031
3121
  exports.LabelComponent = LabelComponent;
3032
3122
  exports.MeshComponent = MeshComponent;
3033
3123
  exports.Orbital = Orbital;