major changes to upgrade to 3JS 1.2.5 -- deprecated THREE.Geometry -- breakage may ensue
This commit is contained in:
parent
d230f1e473
commit
6aa78d2a6a
8 changed files with 83 additions and 85 deletions
1
app.js
1
app.js
|
|
@ -241,6 +241,7 @@ const script = {
|
||||||
kiri : [
|
kiri : [
|
||||||
"kiri",
|
"kiri",
|
||||||
"ext/three",
|
"ext/three",
|
||||||
|
"ext/three-bgu",
|
||||||
"license",
|
"license",
|
||||||
"ext/clip2", // work.test
|
"ext/clip2", // work.test
|
||||||
"ext/tween",
|
"ext/tween",
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@
|
||||||
"moment": "^2.24.0",
|
"moment": "^2.24.0",
|
||||||
"pixi.js": "^4.8.9",
|
"pixi.js": "^4.8.9",
|
||||||
"serve-static": "^1.14.1",
|
"serve-static": "^1.14.1",
|
||||||
"three": "^0.122.0",
|
"three": "^0.125.0",
|
||||||
"tween.js": "^0.14.0",
|
"tween.js": "^0.14.0",
|
||||||
"uglify-es": "3.3.9",
|
"uglify-es": "3.3.9",
|
||||||
"validator": "^8.2.0",
|
"validator": "^8.2.0",
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,18 @@
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
var MP = THREE.Mesh.prototype,
|
var MP = THREE.Mesh.prototype,
|
||||||
GP = THREE.Geometry.prototype,
|
|
||||||
BP = THREE.BufferGeometry.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) {
|
MP.getBoundingBox = function(update) {
|
||||||
return this.geometry.getBoundingBox(update);
|
return this.geometry.getBoundingBox(update);
|
||||||
};
|
};
|
||||||
|
|
@ -46,7 +55,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
// center geometry on x,y,z coordinates (defaults to 0,0,0)
|
// 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(),
|
var box = this.getBoundingBox(),
|
||||||
mid = box.dim.clone().multiplyScalar(0.5),
|
mid = box.dim.clone().multiplyScalar(0.5),
|
||||||
dif = mid.clone().add(box.min),
|
dif = mid.clone().add(box.min),
|
||||||
|
|
@ -69,7 +78,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
// return cached or refreshed (when update = true) bounding box
|
// return cached or refreshed (when update = true) bounding box
|
||||||
GP.getBoundingBox = function(update) {
|
BP.getBoundingBox = function(update) {
|
||||||
if (update || !this.boundingBox) {
|
if (update || !this.boundingBox) {
|
||||||
this.boundingBox = null;
|
this.boundingBox = null;
|
||||||
this.computeBoundingBox();
|
this.computeBoundingBox();
|
||||||
|
|
@ -79,7 +88,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
// uniformly scale any mesh to a max x/y/z dim of 'unit' (defaults to 1)
|
// 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(),
|
var bbox = this.getBoundingBox().clone(),
|
||||||
scale = (unit || 1) / Math.max(
|
scale = (unit || 1) / Math.max(
|
||||||
bbox.max.x - bbox.min.x,
|
bbox.max.x - bbox.min.x,
|
||||||
|
|
@ -92,20 +101,21 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
BP.center = GP.center;
|
|
||||||
BP.getBoundingBox = GP.getBoundingBox;
|
|
||||||
BP.unitScale = GP.unitScale;
|
|
||||||
|
|
||||||
BP.fixNormals = function() {
|
BP.fixNormals = function() {
|
||||||
this.computeVertexNormals();
|
this.computeVertexNormals();
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
THREE.Geometry.fromVertices = function(vertices) {
|
// may be faster than the equivalent matrix transform. to be tested
|
||||||
var geometry = new THREE.BufferGeometry();
|
// BP.translate = function(x,y,z) {
|
||||||
geometry.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
|
// let off = [x,y,z],
|
||||||
return geometry;
|
// 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() {
|
THREE.Object3D.prototype.newGroup = function() {
|
||||||
var group = new THREE.Group();
|
var group = new THREE.Group();
|
||||||
|
|
|
||||||
|
|
@ -1504,51 +1504,22 @@
|
||||||
widgets.forEach(widget => {
|
widgets.forEach(widget => {
|
||||||
let mesh = widget.mesh;
|
let mesh = widget.mesh;
|
||||||
let geo = mesh.geometry;
|
let geo = mesh.geometry;
|
||||||
// let geo = new THREE.Geometry().fromBufferGeometry(mesh.geometry);
|
|
||||||
outs.push({geo, widget});
|
outs.push({geo, widget});
|
||||||
facets += geo.attributes.position.count;
|
facets += geo.attributes.position.count;
|
||||||
// facets += geo.faces.length;
|
|
||||||
});
|
});
|
||||||
let stl = new Uint8Array(80 + 4 + facets * 50);
|
let stl = new Uint8Array(80 + 4 + facets * 50);
|
||||||
let dat = new DataView(stl.buffer);
|
let dat = new DataView(stl.buffer);
|
||||||
let pos = 84;
|
let pos = 84;
|
||||||
dat.setInt32(80, facets, true);
|
dat.setInt32(80, facets, true);
|
||||||
// outs.forEach(out => {
|
|
||||||
// let { faces, vertices } = out.geo;
|
|
||||||
// for (let i=0, il=faces.length; i<il; i++) {
|
|
||||||
// let {a, b, c, normal} = faces[i];
|
|
||||||
// let xo = 0, yo = 0, zo = 0;
|
|
||||||
// if (outs.length > 1) {
|
|
||||||
// let {x, y, z} = out.widget.track.pos;
|
|
||||||
// xo = x;
|
|
||||||
// yo = y;
|
|
||||||
// zo = z;
|
|
||||||
// }
|
|
||||||
// dat.setFloat32(pos + 0, normal.x, true);
|
|
||||||
// dat.setFloat32(pos + 4, normal.y, true);
|
|
||||||
// dat.setFloat32(pos + 8, normal.z, true);
|
|
||||||
// dat.setFloat32(pos + 12, vertices[a].x + xo, true);
|
|
||||||
// dat.setFloat32(pos + 16, vertices[a].y + yo, true);
|
|
||||||
// dat.setFloat32(pos + 20, vertices[a].z + zo, true);
|
|
||||||
// dat.setFloat32(pos + 24, vertices[b].x + xo, true);
|
|
||||||
// dat.setFloat32(pos + 28, vertices[b].y + yo, true);
|
|
||||||
// dat.setFloat32(pos + 32, vertices[b].z + zo, true);
|
|
||||||
// dat.setFloat32(pos + 36, vertices[c].x + xo, true);
|
|
||||||
// dat.setFloat32(pos + 40, vertices[c].y + yo, true);
|
|
||||||
// dat.setFloat32(pos + 44, vertices[c].z + zo, true);
|
|
||||||
// pos += 50;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
for (let out of outs) {
|
for (let out of outs) {
|
||||||
let { normal, position } = out.geo.attributes;
|
let { position } = out.geo.attributes;
|
||||||
let nvals = normal.array;
|
|
||||||
let pvals = position.array;
|
let pvals = position.array;
|
||||||
for (let i=0, il=position.count; i<il; i += 3) {
|
for (let i=0, il=position.count; i<il; i += 3) {
|
||||||
let pi = i * position.itemSize;
|
let pi = i * position.itemSize;
|
||||||
// average vertex normals to produce a face normal
|
let p0 = new THREE.Vector3(pvals[pi++], pvals[pi++], pvals[pi++]);
|
||||||
let nx = (nvals[pi + 0] + nvals[pi + 3] + nvals[pi + 6]) / 3;
|
let p1 = new THREE.Vector3(pvals[pi++], pvals[pi++], pvals[pi++]);
|
||||||
let ny = (nvals[pi + 1] + nvals[pi + 4] + nvals[pi + 7]) / 3;
|
let p2 = new THREE.Vector3(pvals[pi++], pvals[pi++], pvals[pi++]);
|
||||||
let nz = (nvals[pi + 2] + nvals[pi + 5] + nvals[pi + 8]) / 3;
|
let norm = THREE.computeFaceNormal(p0, p1, p2);
|
||||||
let xo = 0, yo = 0, zo = 0;
|
let xo = 0, yo = 0, zo = 0;
|
||||||
if (outs.length > 1) {
|
if (outs.length > 1) {
|
||||||
let {x, y, z} = out.widget.track.pos;
|
let {x, y, z} = out.widget.track.pos;
|
||||||
|
|
@ -1556,18 +1527,18 @@
|
||||||
yo = y;
|
yo = y;
|
||||||
zo = z;
|
zo = z;
|
||||||
}
|
}
|
||||||
dat.setFloat32(pos + 0, nx, true);
|
dat.setFloat32(pos + 0, norm.x, true);
|
||||||
dat.setFloat32(pos + 4, ny, true);
|
dat.setFloat32(pos + 4, norm.y, true);
|
||||||
dat.setFloat32(pos + 8, nz, true);
|
dat.setFloat32(pos + 8, norm.z, true);
|
||||||
dat.setFloat32(pos + 12, pvals[pi + 0] + xo, true);
|
dat.setFloat32(pos + 12, p0.x + xo, true);
|
||||||
dat.setFloat32(pos + 16, pvals[pi + 1] + yo, true);
|
dat.setFloat32(pos + 16, p0.y + yo, true);
|
||||||
dat.setFloat32(pos + 20, pvals[pi + 2] + zo, true);
|
dat.setFloat32(pos + 20, p0.z + zo, true);
|
||||||
dat.setFloat32(pos + 24, pvals[pi + 3] + xo, true);
|
dat.setFloat32(pos + 24, p1.x + xo, true);
|
||||||
dat.setFloat32(pos + 28, pvals[pi + 4] + yo, true);
|
dat.setFloat32(pos + 28, p1.y + yo, true);
|
||||||
dat.setFloat32(pos + 32, pvals[pi + 5] + zo, true);
|
dat.setFloat32(pos + 32, p1.z + zo, true);
|
||||||
dat.setFloat32(pos + 36, pvals[pi + 6] + xo, true);
|
dat.setFloat32(pos + 36, p2.x + xo, true);
|
||||||
dat.setFloat32(pos + 40, pvals[pi + 7] + yo, true);
|
dat.setFloat32(pos + 40, p2.y + yo, true);
|
||||||
dat.setFloat32(pos + 44, pvals[pi + 8] + zo, true);
|
dat.setFloat32(pos + 44, p2.z + zo, true);
|
||||||
pos += 50;
|
pos += 50;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -557,7 +557,24 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
PRO.getGeoVertices = function() {
|
PRO.getGeoVertices = function() {
|
||||||
return this.mesh.geometry.getAttribute('position').array;
|
let geo = this.mesh.geometry;
|
||||||
|
let pos = geo.getAttribute('position').array;
|
||||||
|
if (geo.index) {
|
||||||
|
let idx = geo.index.array;
|
||||||
|
let len = idx.length;
|
||||||
|
let p2 = new Float32Array(len * 3);
|
||||||
|
let inc = 0;
|
||||||
|
for (let i=0; i<len; i++) {
|
||||||
|
let iv = idx[i];
|
||||||
|
let ip = iv * 3;
|
||||||
|
p2[inc++] = pos[ip++];
|
||||||
|
p2[inc++] = pos[ip++];
|
||||||
|
p2[inc++] = pos[ip];
|
||||||
|
}
|
||||||
|
return p2;
|
||||||
|
} else {
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
PRO.getPoints = function() {
|
PRO.getPoints = function() {
|
||||||
|
|
|
||||||
|
|
@ -207,20 +207,12 @@
|
||||||
// synth support widget for each widget group
|
// synth support widget for each widget group
|
||||||
let synth = [];
|
let synth = [];
|
||||||
for (let group of kiri.Widget.Groups.list()) {
|
for (let group of kiri.Widget.Groups.list()) {
|
||||||
let count = 0;
|
let merge = group.filter(w => w.sups).map(w => Object.values(w.sups)).flat();
|
||||||
let merged = new THREE.Geometry();
|
if (!merge.length) {
|
||||||
for (let widget of group) {
|
|
||||||
if (widget.sups) {
|
|
||||||
for (let sup of Object.values(widget.sups)) {
|
|
||||||
merged.merge(sup.box.geometry, sup.box.matrix);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!count) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let bbg = new THREE.BufferGeometry().fromGeometry(merged);
|
let boxen = merge.map(m => m.box.geometry.clone().translate(m.x, m.y, m.z));
|
||||||
|
let bbg = THREE.BufferGeometryUtils.mergeBufferGeometries(boxen);
|
||||||
let sw = kiri.newWidget(null, group);
|
let sw = kiri.newWidget(null, group);
|
||||||
let fwp = group[0].track.pos;
|
let fwp = group[0].track.pos;
|
||||||
sw.loadGeometry(bbg);
|
sw.loadGeometry(bbg);
|
||||||
|
|
|
||||||
|
|
@ -1323,19 +1323,25 @@
|
||||||
point.added = true;
|
point.added = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let filter = isBelt ? (f) => {
|
let filter = isBelt ? (norm) => {
|
||||||
return f.normal.z < thresh && f.normal.y < -0.001;
|
return norm.z < thresh && norm.y < -0.001;
|
||||||
} : (f) => {
|
} : (norm) => {
|
||||||
return f.normal.z < thresh;
|
return norm.z < thresh;
|
||||||
};
|
};
|
||||||
let position = geo.attributes.position;
|
let { position } = geo.attributes;
|
||||||
let { itemSize, count, array } = position;
|
let { itemSize, count, array } = position;
|
||||||
for (let i = 0; i<count; i += 3) {
|
for (let i = 0; i<count; i += 3) {
|
||||||
let ip = i * itemSize;
|
let ip = i * itemSize;
|
||||||
let a = new THREE.Vector3(array[ip++], array[ip++], array[ip++]);
|
let a = new THREE.Vector3(array[ip++], array[ip++], array[ip++]);
|
||||||
let b = new THREE.Vector3(array[ip++], array[ip++], array[ip++]);
|
let b = new THREE.Vector3(array[ip++], array[ip++], array[ip++]);
|
||||||
let c = new THREE.Vector3(array[ip++], array[ip++], array[ip++]);
|
let c = new THREE.Vector3(array[ip++], array[ip++], array[ip++]);
|
||||||
|
let norm = THREE.computeFaceNormal(a,b,c);
|
||||||
|
// limit to downward faces
|
||||||
|
if (!filter(norm)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// skip tiny faces
|
// skip tiny faces
|
||||||
|
let area = BASE.newPolygon().addPoints([a,b,c]).area();
|
||||||
if (BASE.newPolygon().addPoints([a,b,c]).area() < min) {
|
if (BASE.newPolygon().addPoints([a,b,c]).area() < min) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -682,14 +682,15 @@
|
||||||
if (points.length % 2 != 0) {
|
if (points.length % 2 != 0) {
|
||||||
throw "invalid line : "+points.length;
|
throw "invalid line : "+points.length;
|
||||||
}
|
}
|
||||||
const geo = new THREE.Geometry();
|
const geo = new THREE.BufferGeometry();
|
||||||
for (let i=0; i < points.length; ) {
|
const vrt = new Float32Array(points.length * 3);
|
||||||
const p1 = points[i++];
|
let vi = 0;
|
||||||
const p2 = points[i++];
|
for (let p of points) {
|
||||||
geo.vertices.push(new THREE.Vector3(p1.x, p1.y, p1.z));
|
vrt[vi++] = p.x;
|
||||||
geo.vertices.push(new THREE.Vector3(p2.x, p2.y, p2.z));
|
vrt[vi++] = p.y;
|
||||||
|
vrt[vi++] = p.z;
|
||||||
}
|
}
|
||||||
geo.verticesNeedUpdate = true;
|
geo.setAttribute('position', new THREE.BufferAttribute(vrt, 3));
|
||||||
return new THREE.LineSegments(geo, new THREE.LineBasicMaterial({
|
return new THREE.LineSegments(geo, new THREE.LineBasicMaterial({
|
||||||
color: color,
|
color: color,
|
||||||
opacity: opacity || 1,
|
opacity: opacity || 1,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue