remove unworkable indexed mesh code

This commit is contained in:
Stewart Allen 2022-05-15 15:20:39 -04:00
commit 1ac95d785b
2 changed files with 9 additions and 32 deletions

View file

@ -164,7 +164,6 @@ class Stack {
} else { } else {
geo.setAttribute('position', new THREE.BufferAttribute(faces, 3)); geo.setAttribute('position', new THREE.BufferAttribute(faces, 3));
} }
// geo.computeFaceNormals();
geo.computeVertexNormals(); geo.computeVertexNormals();
if (cface) { if (cface) {
cface.forEach((c, i) => geo.addGroup(c.start, c.count, i)); cface.forEach((c, i) => geo.addGroup(c.start, c.count, i));
@ -192,7 +191,6 @@ class Stack {
const geo = new THREE.BufferGeometry(); const geo = new THREE.BufferGeometry();
geo.setAttribute('position', new THREE.BufferAttribute(faces, 3)); geo.setAttribute('position', new THREE.BufferAttribute(faces, 3));
geo.setIndex(index); geo.setIndex(index);
// geo.computeFaceNormals();
geo.computeVertexNormals(); geo.computeVertexNormals();
if (cpath) { if (cpath) {
cpath.forEach((c, i) => geo.addGroup(c.start, c.count, i)); cpath.forEach((c, i) => geo.addGroup(c.start, c.count, i));

View file

@ -127,7 +127,6 @@ class Widget {
const widget = this; const widget = this;
index().put('ws-save-'+this.id, { index().put('ws-save-'+this.id, {
geo: widget.getGeoVertices(false), geo: widget.getGeoVertices(false),
ind: widget.getGeoIndices(),
track: widget.track, track: widget.track,
group: this.group.id, group: this.group.id,
meta: this.meta, meta: this.meta,
@ -156,14 +155,19 @@ class Widget {
*/ */
loadVertices(data, options = { index: false }) { loadVertices(data, options = { index: false }) {
let vertices, let vertices,
indices,
autoscale = false; autoscale = false;
if (ArrayBuffer.isView(data) || typeof(data) != 'object') { if (ArrayBuffer.isView(data) || typeof(data) != 'object') {
vertices = data; vertices = data;
} else { } else {
vertices = data.vertices; vertices = data.vertices;
indices = data.indices; throw "deprecated vertex data format";
} }
// will not serialize into indexeddb -- need a performance sensitive workaround
// if (window.SharedArrayBuffer) {
// let newvert = new Float32Array(new SharedArrayBuffer(vertices.buffer.byteLength));
// newvert.set(vertices);
// vertices = newvert;
// }
switch (typeof(autoscale)) { switch (typeof(autoscale)) {
case 'boolean': case 'boolean':
autoscale = options; autoscale = options;
@ -188,25 +192,17 @@ class Widget {
} }
} }
} }
if (options.index && !indices) {
let mesh = new Mesh({vertices});
vertices = mesh.vertices.toFloat32();
indices = Uint32Array.from(mesh.faces.map(v => v/3));
}
if (this.mesh) { if (this.mesh) {
let geo = this.mesh.geometry; let geo = this.mesh.geometry;
if (indices) geo.setIndex(new THREE.BufferAttribute(indices, 1));
geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3)); geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
geo.setAttribute('normal', undefined); geo.setAttribute('normal', undefined);
geo.attributes.position.needsUpdate = true; geo.attributes.position.needsUpdate = true;
// geo.computeFaceNormals();
geo.computeVertexNormals(); geo.computeVertexNormals();
this.meta.vertices = vertices.length / 3; this.meta.vertices = vertices.length / 3;
this.points = null; this.points = null;
return this; return this;
} else { } else {
let geo = new THREE.BufferGeometry(); let geo = new THREE.BufferGeometry();
if (indices) geo.setIndex(new THREE.BufferAttribute(indices, 1));
geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3)); geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
geo.setAttribute('normal', undefined); geo.setAttribute('normal', undefined);
this.meta.vertices = vertices.length / 3; this.meta.vertices = vertices.length / 3;
@ -227,16 +223,6 @@ class Widget {
} }
} }
indexGeo() {
let indices = this.getGeoIndices();
if (!indices) {
let mesh = new Mesh({vertices: this.getGeoVertices()});
vertices = mesh.vertices.toFloat32();
indices = Uint32Array.from(mesh.faces.map(v => v/3));
this.loadData({vertices, indices});
}
}
heal(debug, refresh) { heal(debug, refresh) {
if (debug) { if (debug) {
let mesh = this.debugMesh().heal(); let mesh = this.debugMesh().heal();
@ -633,7 +619,6 @@ class Widget {
arr[i*3+8] = z; arr[i*3+8] = z;
} }
pos.needsUpdate = true; pos.needsUpdate = true;
// geo.computeFaceNormals();
geo.computeVertexNormals(); geo.computeVertexNormals();
ot.mirror = !ot.mirror; ot.mirror = !ot.mirror;
this.setModified(); this.setModified();
@ -661,11 +646,6 @@ class Widget {
} }
} }
getGeoIndices() {
let indices = this.mesh.geometry.index;
return indices ? indices.array : undefined;
}
iterPoints() { iterPoints() {
let verts = this.getGeoVertices(); let verts = this.getGeoVertices();
let index = 0; let index = 0;
@ -979,13 +959,12 @@ Widget.loadFromState = function(id, ondone, move) {
index().get('ws-save-'+id, function(data) { index().get('ws-save-'+id, function(data) {
if (data) { if (data) {
let vertices = data.geo || data, let vertices = data.geo || data,
indices = data.ind || undefined,
track = data.track || undefined, track = data.track || undefined,
group = data.group || id, group = data.group || id,
anno = data.anno || undefined, anno = data.anno || undefined,
widget = newWidget(id, Group.forid(group)), widget = newWidget(id, Group.forid(group)),
meta = data.meta || widget.meta, meta = data.meta || widget.meta,
ptr = widget.loadVertices({vertices, indices}); ptr = widget.loadVertices(vertices);
widget.meta = meta; widget.meta = meta;
widget.anno = anno || widget.anno; widget.anno = anno || widget.anno;
// restore widget position if specified // restore widget position if specified