code style updates
This commit is contained in:
parent
f54e01e54f
commit
7c6a34c743
5 changed files with 670 additions and 688 deletions
234
src/add/three.js
234
src/add/three.js
|
|
@ -4,129 +4,129 @@
|
|||
|
||||
(function() {
|
||||
|
||||
// dep: ext.three
|
||||
// dep: ext.three-bgu
|
||||
// dep: ext.three-svg
|
||||
gapp.register('add.three');
|
||||
// dep: ext.three
|
||||
// dep: ext.three-bgu
|
||||
// dep: ext.three-svg
|
||||
gapp.register('add.three');
|
||||
|
||||
let MP = THREE.Mesh.prototype,
|
||||
XP = THREE.Box3.prototype,
|
||||
BP = THREE.BufferGeometry.prototype;
|
||||
let MP = THREE.Mesh.prototype,
|
||||
XP = THREE.Box3.prototype,
|
||||
BP = THREE.BufferGeometry.prototype;
|
||||
|
||||
THREE.computeFaceNormal = function(vA,vB,vC) {
|
||||
const ab = new THREE.Vector3();
|
||||
const cb = new THREE.Vector3();
|
||||
cb.subVectors( vC, vB );
|
||||
ab.subVectors( vA, vB );
|
||||
cb.cross( ab );
|
||||
cb.normalize();
|
||||
return cb;
|
||||
};
|
||||
THREE.computeFaceNormal = function(vA,vB,vC) {
|
||||
const ab = new THREE.Vector3();
|
||||
const cb = new THREE.Vector3();
|
||||
cb.subVectors( vC, vB );
|
||||
ab.subVectors( vA, vB );
|
||||
cb.cross( ab );
|
||||
cb.normalize();
|
||||
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: {
|
||||
get: function() {
|
||||
return this.max.clone().sub(this.min);
|
||||
}
|
||||
},
|
||||
mid: {
|
||||
get: function() {
|
||||
return this.dim.clone().multiplyScalar(0.5).add(this.min);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
MP.getBoundingBox = function(update) {
|
||||
return this.geometry.getBoundingBox(update);
|
||||
};
|
||||
|
||||
MP.mirrorX = function() {
|
||||
return this.mirror(0);
|
||||
};
|
||||
|
||||
MP.mirrorY = function() {
|
||||
return this.mirror(1);
|
||||
};
|
||||
|
||||
MP.mirrorZ = function() {
|
||||
return this.mirror(2);
|
||||
};
|
||||
|
||||
// fast mirror of vertices given axis array offset
|
||||
// array elements are repeating [x,y,z,x,y,z,...]
|
||||
MP.mirror = function(start) {
|
||||
let i,
|
||||
geo = this.geometry,
|
||||
at = geo.attributes,
|
||||
pa = at.position.array,
|
||||
nm = at.normal.array;
|
||||
for (i = start || 0 ; i < pa.length; i += 3) {
|
||||
pa[i] = -pa[i];
|
||||
nm[i] = -nm[i];
|
||||
}
|
||||
geo.computeVertexNormals();
|
||||
return this;
|
||||
};
|
||||
|
||||
// return cached or refreshed (when update = true) bounding box
|
||||
BP.getBoundingBox = function(update) {
|
||||
if (update || !this.boundingBox) {
|
||||
this.boundingBox = null;
|
||||
this.computeBoundingBox();
|
||||
}
|
||||
return this.boundingBox;
|
||||
};
|
||||
|
||||
BP.moveMesh = function(x = 0, y = 0, z = 0) {
|
||||
let gap = this.attributes.position,
|
||||
pa = gap.array;
|
||||
for (let i=0; i < pa.length; i += 3) {
|
||||
pa[i ] += x;
|
||||
pa[i + 1] += y;
|
||||
pa[i + 2] += z;
|
||||
}
|
||||
gap.needsUpdate = true;
|
||||
return this;
|
||||
THREE.dispose = function(obj) {
|
||||
if (!obj) {
|
||||
return;
|
||||
}
|
||||
|
||||
BP.shallowClone = function() {
|
||||
let geo = new THREE.BufferGeometry();
|
||||
for (let [k, v] of Object.entries(this.attributes)) {
|
||||
geo.setAttribute(k, new THREE.BufferAttribute(v.array, v.itemSize));
|
||||
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);
|
||||
}
|
||||
return geo;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
THREE.Object3D.prototype.newGroup = function() {
|
||||
let group = new THREE.Group();
|
||||
this.add(group);
|
||||
return group;
|
||||
};
|
||||
// add .dim and .mid getters to Box3
|
||||
Object.defineProperties(XP, {
|
||||
dim: {
|
||||
get: function() {
|
||||
return this.max.clone().sub(this.min);
|
||||
}
|
||||
},
|
||||
mid: {
|
||||
get: function() {
|
||||
return this.dim.clone().multiplyScalar(0.5).add(this.min);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
THREE.Object3D.prototype.removeAll = function() {
|
||||
this.children.slice().forEach(function (c) {
|
||||
c.parent = undefined;
|
||||
c.dispatchEvent( { type: 'removed' } );
|
||||
});
|
||||
this.children = [];
|
||||
};
|
||||
MP.getBoundingBox = function(update) {
|
||||
return this.geometry.getBoundingBox(update);
|
||||
};
|
||||
|
||||
MP.mirrorX = function() {
|
||||
return this.mirror(0);
|
||||
};
|
||||
|
||||
MP.mirrorY = function() {
|
||||
return this.mirror(1);
|
||||
};
|
||||
|
||||
MP.mirrorZ = function() {
|
||||
return this.mirror(2);
|
||||
};
|
||||
|
||||
// fast mirror of vertices given axis array offset
|
||||
// array elements are repeating [x,y,z,x,y,z,...]
|
||||
MP.mirror = function(start) {
|
||||
let i,
|
||||
geo = this.geometry,
|
||||
at = geo.attributes,
|
||||
pa = at.position.array,
|
||||
nm = at.normal.array;
|
||||
for (i = start || 0 ; i < pa.length; i += 3) {
|
||||
pa[i] = -pa[i];
|
||||
nm[i] = -nm[i];
|
||||
}
|
||||
geo.computeVertexNormals();
|
||||
return this;
|
||||
};
|
||||
|
||||
// return cached or refreshed (when update = true) bounding box
|
||||
BP.getBoundingBox = function(update) {
|
||||
if (update || !this.boundingBox) {
|
||||
this.boundingBox = null;
|
||||
this.computeBoundingBox();
|
||||
}
|
||||
return this.boundingBox;
|
||||
};
|
||||
|
||||
BP.moveMesh = function(x = 0, y = 0, z = 0) {
|
||||
let gap = this.attributes.position,
|
||||
pa = gap.array;
|
||||
for (let i=0; i < pa.length; i += 3) {
|
||||
pa[i ] += x;
|
||||
pa[i + 1] += y;
|
||||
pa[i + 2] += z;
|
||||
}
|
||||
gap.needsUpdate = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
BP.shallowClone = function() {
|
||||
let geo = new THREE.BufferGeometry();
|
||||
for (let [k, v] of Object.entries(this.attributes)) {
|
||||
geo.setAttribute(k, new THREE.BufferAttribute(v.array, v.itemSize));
|
||||
}
|
||||
return geo;
|
||||
};
|
||||
|
||||
THREE.Object3D.prototype.newGroup = function() {
|
||||
let group = new THREE.Group();
|
||||
this.add(group);
|
||||
return group;
|
||||
};
|
||||
|
||||
THREE.Object3D.prototype.removeAll = function() {
|
||||
this.children.slice().forEach(function (c) {
|
||||
c.parent = undefined;
|
||||
c.dispatchEvent( { type: 'removed' } );
|
||||
});
|
||||
this.children = [];
|
||||
};
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue