lythreeframe 1.0.19 → 1.0.21

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.
@@ -1080,6 +1080,22 @@ const DefaultPostProcessParam = {
1080
1080
  }
1081
1081
  };
1082
1082
 
1083
+ class ThreeObjectLibrary {
1084
+ static disposeMeshMaterial(mesh) {
1085
+ let mats = Array.isArray(mesh.material) ? mesh.material : [mesh.material];
1086
+ mats.forEach((elem) => {
1087
+ elem.dispose();
1088
+ });
1089
+ }
1090
+ static disposeMeshGeometry(mesh) {
1091
+ mesh.geometry.dispose();
1092
+ }
1093
+ static disposeMeshResource(mesh) {
1094
+ ThreeObjectLibrary.disposeMeshMaterial(mesh);
1095
+ ThreeObjectLibrary.disposeMeshGeometry(mesh);
1096
+ }
1097
+ }
1098
+
1083
1099
  class World {
1084
1100
  get scene() {
1085
1101
  return this._scene;
@@ -1102,6 +1118,18 @@ class World {
1102
1118
  elem.tick(deltaTime);
1103
1119
  });
1104
1120
  }
1121
+ destroy() {
1122
+ this.actors.forEach((elem) => {
1123
+ elem.destroy();
1124
+ });
1125
+ this.actors.clear();
1126
+ this.scene.traverse((child) => {
1127
+ if (child instanceof three.Mesh) {
1128
+ ThreeObjectLibrary.disposeMeshResource(child);
1129
+ }
1130
+ });
1131
+ this.scene.clear();
1132
+ }
1105
1133
  addActor(actor) {
1106
1134
  if (!actor.rootComponent.threeObject) {
1107
1135
  throw Error("actor.threeObject is null");
@@ -1112,8 +1140,6 @@ class World {
1112
1140
  actor.onAddedToWorld(this);
1113
1141
  this.viewport.markRenderStateDirty();
1114
1142
  }
1115
- destroy() {
1116
- }
1117
1143
  }
1118
1144
 
1119
1145
  const DefaultToneMappingParams = {
@@ -2098,6 +2124,12 @@ class ThreeJsApp {
2098
2124
  this.world.tick(delta);
2099
2125
  this.viewport.render();
2100
2126
  }
2127
+ destroy() {
2128
+ this.onCameraChangedDelegate.clear();
2129
+ this.world.destroy();
2130
+ this.controller.destroy();
2131
+ this.viewport.destroy();
2132
+ }
2101
2133
  updateCamera(param) {
2102
2134
  const previousCam = this.camera;
2103
2135
  this._camera = CameraFactory.updataCamera(param, this.camera);
@@ -2116,12 +2148,6 @@ class ThreeJsApp {
2116
2148
  // }
2117
2149
  this.camera.updateProjectionMatrix();
2118
2150
  }
2119
- destroy() {
2120
- this.onCameraChangedDelegate.clear();
2121
- this.world.destroy();
2122
- this.controller.destroy();
2123
- this.viewport.destroy();
2124
- }
2125
2151
  }
2126
2152
 
2127
2153
  class Actor extends BaseObject {
@@ -2904,6 +2930,7 @@ exports.PlaneComponent = PlaneComponent;
2904
2930
  exports.SceneComponent = SceneComponent;
2905
2931
  exports.SphereComponent = SphereComponent;
2906
2932
  exports.ThreeJsApp = ThreeJsApp;
2933
+ exports.ThreeObjectLibrary = ThreeObjectLibrary;
2907
2934
  exports.ToneMappingOptions = ToneMappingOptions;
2908
2935
  exports.TransformGizmo = TransformGizmo;
2909
2936
  exports.Viewport = Viewport;
@@ -1078,6 +1078,22 @@ const DefaultPostProcessParam = {
1078
1078
  }
1079
1079
  };
1080
1080
 
1081
+ class ThreeObjectLibrary {
1082
+ static disposeMeshMaterial(mesh) {
1083
+ let mats = Array.isArray(mesh.material) ? mesh.material : [mesh.material];
1084
+ mats.forEach((elem) => {
1085
+ elem.dispose();
1086
+ });
1087
+ }
1088
+ static disposeMeshGeometry(mesh) {
1089
+ mesh.geometry.dispose();
1090
+ }
1091
+ static disposeMeshResource(mesh) {
1092
+ ThreeObjectLibrary.disposeMeshMaterial(mesh);
1093
+ ThreeObjectLibrary.disposeMeshGeometry(mesh);
1094
+ }
1095
+ }
1096
+
1081
1097
  class World {
1082
1098
  get scene() {
1083
1099
  return this._scene;
@@ -1100,6 +1116,18 @@ class World {
1100
1116
  elem.tick(deltaTime);
1101
1117
  });
1102
1118
  }
1119
+ destroy() {
1120
+ this.actors.forEach((elem) => {
1121
+ elem.destroy();
1122
+ });
1123
+ this.actors.clear();
1124
+ this.scene.traverse((child) => {
1125
+ if (child instanceof Mesh) {
1126
+ ThreeObjectLibrary.disposeMeshResource(child);
1127
+ }
1128
+ });
1129
+ this.scene.clear();
1130
+ }
1103
1131
  addActor(actor) {
1104
1132
  if (!actor.rootComponent.threeObject) {
1105
1133
  throw Error("actor.threeObject is null");
@@ -1110,8 +1138,6 @@ class World {
1110
1138
  actor.onAddedToWorld(this);
1111
1139
  this.viewport.markRenderStateDirty();
1112
1140
  }
1113
- destroy() {
1114
- }
1115
1141
  }
1116
1142
 
1117
1143
  const DefaultToneMappingParams = {
@@ -2096,6 +2122,12 @@ class ThreeJsApp {
2096
2122
  this.world.tick(delta);
2097
2123
  this.viewport.render();
2098
2124
  }
2125
+ destroy() {
2126
+ this.onCameraChangedDelegate.clear();
2127
+ this.world.destroy();
2128
+ this.controller.destroy();
2129
+ this.viewport.destroy();
2130
+ }
2099
2131
  updateCamera(param) {
2100
2132
  const previousCam = this.camera;
2101
2133
  this._camera = CameraFactory.updataCamera(param, this.camera);
@@ -2114,12 +2146,6 @@ class ThreeJsApp {
2114
2146
  // }
2115
2147
  this.camera.updateProjectionMatrix();
2116
2148
  }
2117
- destroy() {
2118
- this.onCameraChangedDelegate.clear();
2119
- this.world.destroy();
2120
- this.controller.destroy();
2121
- this.viewport.destroy();
2122
- }
2123
2149
  }
2124
2150
 
2125
2151
  class Actor extends BaseObject {
@@ -2873,4 +2899,4 @@ class TransformGizmo extends Pawn {
2873
2899
  }
2874
2900
  }
2875
2901
 
2876
- export { Actor, AttachmentRules, BoxActor, BoxComponent, Controller, DefaultAppParam, DefaultBloomParam, DefaultCameraParam, DefaultDOFParam, DefaultDenoiseParam, DefaultGTAOParam, DefaultOutlineParams, DefaultPostProcessParam, DefaultRenderParam, DefaultSSRParam, DefaultToneMappingParams, Delegate, DirectionalLightActor, DirectionalLightComponent, FirstPerson, LYAssetManager, LYLoadTask, LabelComponent, MeshComponent, Orbital, PlaneActor, PlaneComponent, SceneComponent, SphereComponent, ThreeJsApp, ToneMappingOptions, TransformGizmo, Viewport, WebGPUPostProcessFactory, World };
2902
+ export { Actor, AttachmentRules, BoxActor, BoxComponent, Controller, DefaultAppParam, DefaultBloomParam, DefaultCameraParam, DefaultDOFParam, DefaultDenoiseParam, DefaultGTAOParam, DefaultOutlineParams, DefaultPostProcessParam, DefaultRenderParam, DefaultSSRParam, DefaultToneMappingParams, Delegate, DirectionalLightActor, DirectionalLightComponent, FirstPerson, LYAssetManager, LYLoadTask, LabelComponent, MeshComponent, Orbital, PlaneActor, PlaneComponent, SceneComponent, SphereComponent, ThreeJsApp, ThreeObjectLibrary, ToneMappingOptions, TransformGizmo, Viewport, WebGPUPostProcessFactory, World };
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export type { AppParam } from "./lythreeframe/ThreeJsApp";
7
7
  export { Controller } from "./lythreeframe/Frame/Controller";
8
8
  export { Viewport } from "./lythreeframe/Frame/Viewport";
9
9
  export { World } from "./lythreeframe/Frame/World";
10
+ export type { CameraParam } from "./lythreeframe/Factory/CameraFactory";
10
11
  export { Actor } from "./lythreeframe/Object/Actor";
11
12
  export { DirectionalLightActor } from "./lythreeframe/Object/Actors/Light/DirectionalLightActor";
12
13
  export { BoxActor } from "./lythreeframe/Object/Actors/Shape/BoxActor";
@@ -40,3 +41,4 @@ export { FirstPerson } from "./lythreeframe/Object/PawnV2/FirstPerson";
40
41
  export type { ITransforming } from "./lythreeframe/Object/PawnV2/TransformControl";
41
42
  export { TransformType } from "./lythreeframe/Object/PawnV2/TransformControl";
42
43
  export { TransformGizmo } from "./lythreeframe/Object/PawnV2/TransformControl";
44
+ export { ThreeObjectLibrary } from "./lythreeframe/Library/ResourceLibrary";
@@ -13,6 +13,6 @@ export declare class World {
13
13
  constructor(app: ThreeJsApp);
14
14
  init(): void;
15
15
  tick(deltaTime: number): void;
16
- addActor(actor: Actor): void;
17
16
  destroy(): void;
17
+ addActor(actor: Actor): void;
18
18
  }
@@ -1,5 +1,5 @@
1
1
  import { Mesh } from "three";
2
- export declare class ResourceLibrary {
2
+ export declare class ThreeObjectLibrary {
3
3
  static disposeMeshMaterial(mesh: Mesh): void;
4
4
  static disposeMeshGeometry(mesh: Mesh): void;
5
5
  static disposeMeshResource(mesh: Mesh): void;
@@ -35,7 +35,7 @@ export declare class ThreeJsApp {
35
35
  constructor(elementId: string, appParam?: AppParam);
36
36
  init(): void;
37
37
  tick(): void;
38
+ destroy(): void;
38
39
  updateCamera(param: CameraParam): void;
39
40
  onWindowResize(width: number, height: number): void;
40
- destroy(): void;
41
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lythreeframe",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "Three.js 封装",
5
5
  "main": "dist/bundle.cjs.js",
6
6
  "module": "dist/bundle.esm.js",