Skip to content
Snippets Groups Projects
Commit 869de4ce authored by Kevin Lee's avatar Kevin Lee
Browse files

cleanup sharedbuffergeometry

parent 35e962a6
No related branches found
No related tags found
No related merge requests found
...@@ -20,15 +20,14 @@ export default class SharedBufferGeometry { ...@@ -20,15 +20,14 @@ export default class SharedBufferGeometry {
this.idx.color++; this.idx.color++;
this.idx.normal++; this.idx.normal++;
this.idx.uv++;
} }
} }
remove(prevIdx, idx) { remove(prevIdx, idx) {
// Loop through all the attributes: position, color, uv, normal,... // Loop through all the attributes: position, color, normal,...
if (this.idx.position > idx.position) { if (this.idx.position > idx.position) {
for (let key in this.idx) { for (const key in this.idx) {
const componentSize = key === "uv" ? 2 : 3; const componentSize = 3;
let pos = prevIdx[key] * componentSize; let pos = prevIdx[key] * componentSize;
const start = (idx[key] + 1) * componentSize; const start = (idx[key] + 1) * componentSize;
const end = this.idx[key] * componentSize; const end = this.idx[key] * componentSize;
...@@ -39,7 +38,7 @@ export default class SharedBufferGeometry { ...@@ -39,7 +38,7 @@ export default class SharedBufferGeometry {
this.idx[key] -= diff; this.idx[key] -= diff;
} }
} else { } else {
for (let key in this.idx) { for (const key in this.idx) {
const diff = idx[key] - prevIdx[key]; const diff = idx[key] - prevIdx[key];
this.idx[key] -= diff; this.idx[key] -= diff;
} }
...@@ -54,12 +53,10 @@ export default class SharedBufferGeometry { ...@@ -54,12 +53,10 @@ export default class SharedBufferGeometry {
} }
addBuffer(copyLast) { addBuffer(copyLast) {
console.log("addBuffer", copyLast);
const geometry = new THREE.BufferGeometry(); const geometry = new THREE.BufferGeometry();
const vertices = new Float32Array(this.maxBufferSize * 3); const vertices = new Float32Array(this.maxBufferSize * 3);
const normals = new Float32Array(this.maxBufferSize * 3); const normals = new Float32Array(this.maxBufferSize * 3);
const uvs = new Float32Array(this.maxBufferSize * 2);
const colors = new Float32Array(this.maxBufferSize * 3); const colors = new Float32Array(this.maxBufferSize * 3);
const mesh = new THREE.Mesh(geometry, this.material); const mesh = new THREE.Mesh(geometry, this.material);
...@@ -75,7 +72,6 @@ export default class SharedBufferGeometry { ...@@ -75,7 +72,6 @@ export default class SharedBufferGeometry {
geometry.setDrawRange(0, 0); geometry.setDrawRange(0, 0);
geometry.addAttribute("position", new THREE.BufferAttribute(vertices, 3).setDynamic(true)); geometry.addAttribute("position", new THREE.BufferAttribute(vertices, 3).setDynamic(true));
geometry.addAttribute("uv", new THREE.BufferAttribute(uvs, 2).setDynamic(true));
geometry.addAttribute("normal", new THREE.BufferAttribute(normals, 3).setDynamic(true)); geometry.addAttribute("normal", new THREE.BufferAttribute(normals, 3).setDynamic(true));
geometry.addAttribute("color", new THREE.BufferAttribute(colors, 3).setDynamic(true)); geometry.addAttribute("color", new THREE.BufferAttribute(colors, 3).setDynamic(true));
...@@ -86,7 +82,6 @@ export default class SharedBufferGeometry { ...@@ -86,7 +82,6 @@ export default class SharedBufferGeometry {
this.idx = { this.idx = {
position: 0, position: 0,
uv: 0,
normal: 0, normal: 0,
color: 0 color: 0
}; };
...@@ -97,7 +92,6 @@ export default class SharedBufferGeometry { ...@@ -97,7 +92,6 @@ export default class SharedBufferGeometry {
if (this.previous && copyLast) { if (this.previous && copyLast) {
let prev = (this.maxBufferSize - 2) * 3; let prev = (this.maxBufferSize - 2) * 3;
let col = (this.maxBufferSize - 2) * 3; let col = (this.maxBufferSize - 2) * 3;
const uv = (this.maxBufferSize - 2) * 2;
let norm = (this.maxBufferSize - 2) * 3; let norm = (this.maxBufferSize - 2) * 3;
const position = this.previous.attributes.position.array; const position = this.previous.attributes.position.array;
...@@ -111,8 +105,6 @@ export default class SharedBufferGeometry { ...@@ -111,8 +105,6 @@ export default class SharedBufferGeometry {
const color = this.previous.attributes.color.array; const color = this.previous.attributes.color.array;
this.addColor(color[col++], color[col++], color[col++]); this.addColor(color[col++], color[col++], color[col++]);
this.addColor(color[col++], color[col++], color[col++]); this.addColor(color[col++], color[col++], color[col++]);
const uvs = this.previous.attributes.uv.array;
} }
} }
...@@ -133,16 +125,11 @@ export default class SharedBufferGeometry { ...@@ -133,16 +125,11 @@ export default class SharedBufferGeometry {
buffer.setXYZ(this.idx.position++, x, y, z); buffer.setXYZ(this.idx.position++, x, y, z);
} }
addUV(u, v) {
this.current.attributes.uv.setXY(this.idx.uv++, u, v);
}
update() { update() {
this.current.setDrawRange(0, this.idx.position); this.current.setDrawRange(0, this.idx.position);
this.current.attributes.color.needsUpdate = true; this.current.attributes.color.needsUpdate = true;
this.current.attributes.normal.needsUpdate = true; this.current.attributes.normal.needsUpdate = true;
this.current.attributes.position.needsUpdate = true; this.current.attributes.position.needsUpdate = true;
this.current.attributes.uv.needsUpdate = true;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment