major changes to upgrade to 3JS 1.2.5 -- deprecated THREE.Geometry -- breakage may ensue

This commit is contained in:
Stewart Allen 2021-03-01 22:41:29 -05:00
commit 6aa78d2a6a
8 changed files with 83 additions and 85 deletions

View file

@ -5,9 +5,18 @@
(function() {
var MP = THREE.Mesh.prototype,
GP = THREE.Geometry.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;
};
MP.getBoundingBox = function(update) {
return this.geometry.getBoundingBox(update);
};
@ -46,7 +55,7 @@
};
// center geometry on x,y,z coordinates (defaults to 0,0,0)
GP.center = function(x,y,z) {
BP.center = function(x,y,z) {
var box = this.getBoundingBox(),
mid = box.dim.clone().multiplyScalar(0.5),
dif = mid.clone().add(box.min),
@ -69,7 +78,7 @@
};
// return cached or refreshed (when update = true) bounding box
GP.getBoundingBox = function(update) {
BP.getBoundingBox = function(update) {
if (update || !this.boundingBox) {
this.boundingBox = null;
this.computeBoundingBox();
@ -79,7 +88,7 @@
};
// uniformly scale any mesh to a max x/y/z dim of 'unit' (defaults to 1)
GP.unitScale = function(unit) {
BP.unitScale = function(unit) {
var bbox = this.getBoundingBox().clone(),
scale = (unit || 1) / Math.max(
bbox.max.x - bbox.min.x,
@ -92,20 +101,21 @@
return this;
};
BP.center = GP.center;
BP.getBoundingBox = GP.getBoundingBox;
BP.unitScale = GP.unitScale;
BP.fixNormals = function() {
this.computeVertexNormals();
return this;
};
THREE.Geometry.fromVertices = function(vertices) {
var geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
return geometry;
};
// may be faster than the equivalent matrix transform. to be tested
// BP.translate = function(x,y,z) {
// let off = [x,y,z],
// arr = this.attributes.position.array,
// len = arr.length;
// for (let i=0; i<len; i++) {
// arr[i] += off[i%3];
// }
// return this;
// }
THREE.Object3D.prototype.newGroup = function() {
var group = new THREE.Group();