add cleanup of geometries and textures
This commit is contained in:
parent
3fd79573e6
commit
c48a3fb147
4 changed files with 42 additions and 7 deletions
|
|
@ -23,6 +23,23 @@
|
|||
return cb;
|
||||
};
|
||||
|
||||
THREE.dispose = function(obj) {
|
||||
if (!obj) {
|
||||
return;
|
||||
}
|
||||
if (obj.geometry) {
|
||||
obj.geometry.dispose();
|
||||
}
|
||||
if (obj.material && obj.material.map && obj.material.map.dispose) {
|
||||
obj.material.map.dispose();
|
||||
}
|
||||
if (obj.children && obj.children.length) {
|
||||
for (let c of obj.children) {
|
||||
THREE.dispose(c);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// add .dim and .mid getters to Box3
|
||||
Object.defineProperties(XP, {
|
||||
dim: {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
destroy() {
|
||||
this._view.remove(this.view);
|
||||
THREE.dispose(this.view);
|
||||
this.view = this.slices = this.meshes = null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -112,9 +112,11 @@
|
|||
},
|
||||
remove: function() {
|
||||
view.remove(stack.obj.view);
|
||||
THREE.dispose(stack.obj.view);
|
||||
},
|
||||
clear: function() {
|
||||
view.remove(stack.obj.view);
|
||||
THREE.dispose(stack.obj.view);
|
||||
},
|
||||
button: function(label, action) {
|
||||
UC.newRow([ UC.newButton(label, action) ]);
|
||||
|
|
|
|||
|
|
@ -685,6 +685,7 @@
|
|||
|
||||
SCENE.remove(current);
|
||||
SCENE.add(platform);
|
||||
THREE.dispose(current);
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
|
|
@ -1049,13 +1050,27 @@
|
|||
},
|
||||
|
||||
remove: function (o) {
|
||||
THREE.dispose(o);
|
||||
return SCENE.remove(o);
|
||||
},
|
||||
|
||||
active: updateLastAction
|
||||
},
|
||||
|
||||
world: WORLD,
|
||||
world: {
|
||||
add: function(o) {
|
||||
return WORLD.add(o);
|
||||
},
|
||||
|
||||
remove: function(o) {
|
||||
THREE.dispose(o);
|
||||
return WORLD.remove(o);
|
||||
},
|
||||
|
||||
newGroup: function() {
|
||||
return WORLD.newGroup();
|
||||
}
|
||||
},
|
||||
|
||||
platform: {
|
||||
set: setPlatform,
|
||||
|
|
@ -1159,15 +1174,16 @@
|
|||
setDelay: (d) => { tweenDelay = d || 20 }
|
||||
},
|
||||
|
||||
useDefaultKeys: (b) => { defaultKeys = b },
|
||||
selectRecurse: (b) => { selectRecurse = b },
|
||||
objects: () => { return WORLD.children },
|
||||
useDefaultKeys (b) { defaultKeys = b },
|
||||
selectRecurse (b) { selectRecurse = b },
|
||||
renderInfo () { return renderer.info },
|
||||
objects () { return WORLD.children },
|
||||
|
||||
screenshot: (format, options) => {
|
||||
screenshot(format, options) {
|
||||
return renderer.domElement.toDataURL(format || "image/png", options);
|
||||
},
|
||||
|
||||
screenshot2: (param = {}) => {
|
||||
screenshot2(param = {}) {
|
||||
let oco = renderer.domElement;
|
||||
let oWidth = oco.offsetWidth;
|
||||
let oHeight = oco.offsetHeight;
|
||||
|
|
@ -1203,7 +1219,6 @@
|
|||
preserveDrawingBuffer: true,
|
||||
logarithmicDepthBuffer: true
|
||||
});
|
||||
console.log({renderer});
|
||||
camera = ortho ?
|
||||
new THREE.OrthographicCamera(-100 * aspect(), 100 * aspect(), 100, -100, 0.1, 100000) :
|
||||
new THREE.PerspectiveCamera(perspective, aspect(), 0.1, 100000);
|
||||
|
|
|
|||
Loading…
Reference in a new issue