three-base 2.0.61 → 2.0.62
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/ThreeBase.js +1 -0
- package/ThreeBase.ts +1 -0
- package/package.json +1 -1
- package/threeUtils.d.ts +1 -0
- package/threeUtils.js +18 -1
- package/threeUtils.ts +19 -2
package/ThreeBase.js
CHANGED
|
@@ -133,6 +133,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
133
133
|
if (this.rendererLost) {
|
|
134
134
|
this.renderer.forceContextRestore();
|
|
135
135
|
this.renderer.domElement.style.opacity = "1";
|
|
136
|
+
this.needRender = true;
|
|
136
137
|
}
|
|
137
138
|
this.setSize(div.clientWidth, div.clientHeight);
|
|
138
139
|
// 开启时时渲染
|
package/ThreeBase.ts
CHANGED
|
@@ -152,6 +152,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
152
152
|
if (this.rendererLost) {
|
|
153
153
|
this.renderer.forceContextRestore();
|
|
154
154
|
this.renderer.domElement.style.opacity = "1";
|
|
155
|
+
this.needRender = true;
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
this.setSize(div.clientWidth, div.clientHeight);
|
package/package.json
CHANGED
package/threeUtils.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ declare class ThreeUtils extends EventDispatcher {
|
|
|
41
41
|
exportUsdz(): void;
|
|
42
42
|
getVolume(geometry: BufferGeometry): number;
|
|
43
43
|
signedVolumeOfTriangle(p1: Vector3, p2: Vector3, p3: Vector3): number;
|
|
44
|
+
dipose(object3d: Object3D): void;
|
|
44
45
|
}
|
|
45
46
|
declare const threeUtils: ThreeUtils;
|
|
46
47
|
export default threeUtils;
|
package/threeUtils.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
5
|
* @Last Modified time: 2023-05-03 00:36:18
|
|
6
6
|
*/
|
|
7
|
-
import { Box3, Clock, EventDispatcher, Vector3 } from "three";
|
|
7
|
+
import { Box3, Clock, EventDispatcher, Material, Vector3 } from "three";
|
|
8
8
|
import { GLTFExporter } from 'three/examples/jsm/exporters/GLTFExporter';
|
|
9
9
|
class ThreeUtils extends EventDispatcher {
|
|
10
10
|
constructor() {
|
|
@@ -244,6 +244,23 @@ class ThreeUtils extends EventDispatcher {
|
|
|
244
244
|
signedVolumeOfTriangle(p1, p2, p3) {
|
|
245
245
|
return p1.dot(p2.cross(p3)) / 6.0;
|
|
246
246
|
}
|
|
247
|
+
//清理对象的网格和材质的缓存
|
|
248
|
+
dipose(object3d) {
|
|
249
|
+
object3d.traverse(obj => {
|
|
250
|
+
const mesh = obj;
|
|
251
|
+
if (mesh.isMesh) {
|
|
252
|
+
mesh.geometry.dispose();
|
|
253
|
+
if (mesh.material instanceof Material) {
|
|
254
|
+
mesh.material.dispose();
|
|
255
|
+
}
|
|
256
|
+
else if (mesh.material instanceof Array) {
|
|
257
|
+
mesh.material.map(m => {
|
|
258
|
+
m.dispose();
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
247
264
|
}
|
|
248
265
|
const threeUtils = new ThreeUtils();
|
|
249
266
|
export default threeUtils;
|
package/threeUtils.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @Last Modified time: 2023-05-03 00:36:18
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { Box3, BufferAttribute, BufferGeometry, Clock, EventDispatcher, Mesh, MeshStandardMaterial, Object3D, Vector3 } from "three";
|
|
8
|
+
import { Box3, BufferAttribute, BufferGeometry, Clock, EventDispatcher, Material, Mesh, MeshStandardMaterial, Object3D, Vector3 } from "three";
|
|
9
9
|
import { GLTFExporter } from 'three/examples/jsm/exporters/GLTFExporter';
|
|
10
10
|
|
|
11
11
|
class ThreeUtils extends EventDispatcher {
|
|
@@ -242,7 +242,7 @@ class ThreeUtils extends EventDispatcher {
|
|
|
242
242
|
|
|
243
243
|
//导出usdz
|
|
244
244
|
exportUsdz() {
|
|
245
|
-
|
|
245
|
+
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
// 计算网格的体积
|
|
@@ -283,6 +283,23 @@ class ThreeUtils extends EventDispatcher {
|
|
|
283
283
|
return p1.dot(p2.cross(p3)) / 6.0;
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
+
//清理对象的网格和材质的缓存
|
|
287
|
+
dipose(object3d: Object3D) {
|
|
288
|
+
object3d.traverse(obj => {
|
|
289
|
+
const mesh = obj as Mesh;
|
|
290
|
+
if (mesh.isMesh) {
|
|
291
|
+
mesh.geometry.dispose();
|
|
292
|
+
if (mesh.material instanceof Material) {
|
|
293
|
+
mesh.material.dispose();
|
|
294
|
+
} else if (mesh.material instanceof Array) {
|
|
295
|
+
mesh.material.map(m => {
|
|
296
|
+
m.dispose();
|
|
297
|
+
})
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
286
303
|
}
|
|
287
304
|
|
|
288
305
|
const threeUtils = new ThreeUtils();
|