From 80690b0dad0edcc7f227323a001c183afa9436dd Mon Sep 17 00:00:00 2001 From: Daniel Adams Date: Sun, 27 Feb 2022 02:53:45 -0500 Subject: [PATCH 1/8] Fix triangle rendering for line brushes. This removes the remaining references to TriangleStripDrawMode. In its place is a vertex index buffer that seems to be working. Still currently an issue with strokes made after an undo action. --- src/brushes/line.js | 12 ++++++------ src/sharedbuffergeometry.js | 22 +++++++++++++--------- src/sharedbuffergeometrymanager.js | 4 ++-- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/brushes/line.js b/src/brushes/line.js index e1ad39ad2..b4819cfd9 100644 --- a/src/brushes/line.js +++ b/src/brushes/line.js @@ -30,9 +30,9 @@ var onLoaded = require('../onloaded.js'); alphaTest: 0.5 }; - sharedBufferGeometryManager.addSharedBuffer('strip-flat', new THREE.MeshBasicMaterial(optionsBasic), THREE.TriangleStripDrawMode); - sharedBufferGeometryManager.addSharedBuffer('strip-shaded', new THREE.MeshStandardMaterial(optionsStandard), THREE.TriangleStripDrawMode); - sharedBufferGeometryManager.addSharedBuffer('strip-textured', new THREE.MeshStandardMaterial(optionTextured), THREE.TriangleStripDrawMode); + sharedBufferGeometryManager.addSharedBuffer('strip-flat', new THREE.MeshBasicMaterial(optionsBasic)); + sharedBufferGeometryManager.addSharedBuffer('strip-shaded', new THREE.MeshStandardMaterial(optionsStandard)); + sharedBufferGeometryManager.addSharedBuffer('strip-textured', new THREE.MeshStandardMaterial(optionTextured)); }); var line = { @@ -113,12 +113,12 @@ var onLoaded = require('../onloaded.js'); this.idx = Object.assign({}, this.sharedBuffer.idx); this.sharedBuffer.update(); - this.computeStripVertexNormals(); + this.computeVertexNormals(); return true; }; })(), - computeStripVertexNormals: (function () { + computeVertexNormals: (function () { var pA = new THREE.Vector3(); var pB = new THREE.Vector3(); var pC = new THREE.Vector3(); @@ -167,7 +167,7 @@ var onLoaded = require('../onloaded.js'); } /* - first and last vertice (0 and 8) belongs just to one triangle + first and last vertices (0 and 8) belongs just to one triangle second and penultimate (1 and 7) belongs to two triangles the rest of the vertices belongs to three triangles diff --git a/src/sharedbuffergeometry.js b/src/sharedbuffergeometry.js index de8184063..4daa73f2d 100644 --- a/src/sharedbuffergeometry.js +++ b/src/sharedbuffergeometry.js @@ -1,6 +1,5 @@ -function SharedBufferGeometry (material, primitiveMode) { +function SharedBufferGeometry (material) { this.material = material; - this.primitiveMode = primitiveMode; this.maxBufferSize = 1000000; this.geometries = []; @@ -56,14 +55,13 @@ SharedBufferGeometry.prototype = { var geometry = new THREE.BufferGeometry(); var vertices = new Float32Array(this.maxBufferSize * 3); + var indices = new Uint32Array(this.maxBufferSize * 1.5); var normals = new Float32Array(this.maxBufferSize * 3); var uvs = new Float32Array(this.maxBufferSize * 2); var colors = new Float32Array(this.maxBufferSize * 3); var mesh = new THREE.Mesh(geometry, this.material); - mesh.drawMode = this.primitiveMode; - mesh.frustumCulled = false; mesh.vertices = vertices; @@ -79,10 +77,11 @@ SharedBufferGeometry.prototype = { this.object3D.add(mesh); geometry.setDrawRange(0, 0); - 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('color', new THREE.BufferAttribute(colors, 3).setDynamic(true)); + geometry.setAttribute('position', new THREE.BufferAttribute(vertices, 3).setUsage(THREE.DynamicDrawUsage)); + geometry.setIndex(new THREE.BufferAttribute(indices, 3).setUsage(THREE.DynamicDrawUsage)); + geometry.setAttribute('uv', new THREE.BufferAttribute(uvs, 2).setUsage(THREE.DynamicDrawUsage)); + geometry.setAttribute('normal', new THREE.BufferAttribute(normals, 3).setUsage(THREE.DynamicDrawUsage)); + geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3).setUsage(THREE.DynamicDrawUsage)); this.previous = null; @@ -138,6 +137,10 @@ SharedBufferGeometry.prototype = { buffer = this.current.attributes.position; } buffer.setXYZ(this.idx.position++, x, y, z); + if ((this.idx.position + 1) % 2 == 0 && this.idx.position > 1) { + this.current.index.setXYZ(this.idx.position - 3, this.idx.position - 3, this.idx.position - 2, this.idx.position - 1); + this.current.index.setXYZ(this.idx.position - 2, this.idx.position - 1, this.idx.position - 2, this.idx.position); + } }, addUV: function (u, v) { @@ -145,12 +148,13 @@ SharedBufferGeometry.prototype = { }, update: function () { - this.current.setDrawRange(0, this.idx.position); + this.current.setDrawRange(0, this.idx.position * 3); this.current.attributes.color.needsUpdate = true; this.current.attributes.normal.needsUpdate = true; this.current.attributes.position.needsUpdate = true; this.current.attributes.uv.needsUpdate = true; + this.current.index.needsUpdate = true; } }; diff --git a/src/sharedbuffergeometrymanager.js b/src/sharedbuffergeometrymanager.js index 2f8866195..4e5d26fcb 100644 --- a/src/sharedbuffergeometrymanager.js +++ b/src/sharedbuffergeometrymanager.js @@ -5,8 +5,8 @@ function SharedBufferGeometryManager () { } SharedBufferGeometryManager.prototype = { - addSharedBuffer: function (name, material, primitiveMode) { - var bufferGeometry = new SharedBufferGeometry(material, primitiveMode); + addSharedBuffer: function (name, material) { + var bufferGeometry = new SharedBufferGeometry(material); this.sharedBuffers[name] = bufferGeometry; }, From 98bd28ef980818dad6e2789917ad0453fb3da4f5 Mon Sep 17 00:00:00 2001 From: Daniel Adams Date: Sun, 27 Feb 2022 12:40:13 -0500 Subject: [PATCH 2/8] Clear vertex+index buffers to prevent "replaying" Undoing a stroke and then drawing again would cause it to read old data. Now vertex/index buffers are cleared back to the prevIdx on undo/clear. --- src/sharedbuffergeometry.js | 4 ++++ src/systems/brush.js | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sharedbuffergeometry.js b/src/sharedbuffergeometry.js index 4daa73f2d..28f239a36 100644 --- a/src/sharedbuffergeometry.js +++ b/src/sharedbuffergeometry.js @@ -47,6 +47,10 @@ SharedBufferGeometry.prototype = { }, undo: function (prevIdx) { + for (let i = prevIdx.position; i < this.idx.position; i++) { + this.current.attributes.position.setXYZ(i, 0, 0, 0); + this.current.index.setXYZ(i, 0, 0, 0); + } this.idx = prevIdx; this.update(); }, diff --git a/src/systems/brush.js b/src/systems/brush.js index e39ba4cb0..b25df43fa 100644 --- a/src/systems/brush.js +++ b/src/systems/brush.js @@ -185,7 +185,6 @@ AFRAME.registerSystem('brush', { }, clear: function () { // Remove all the stroke entities - //for (var i = 0; i < this.strokes.length; i++) { for (var i = this.strokes.length - 1; i >= 0; i--) { if(this.strokes[i].data.owner !== 'local') continue; var stroke = this.strokes[i]; From 41fa49167c61ea176b4ad5041393f25931ebae31 Mon Sep 17 00:00:00 2001 From: Daniel Adams Date: Sun, 27 Feb 2022 13:29:14 -0500 Subject: [PATCH 3/8] Silence more three.js warnings on brushes For whatever reason they still aren't rendering though. --- src/brushes/cubes.js | 4 ++-- src/brushes/rainbow.js | 7 +++---- src/brushes/single-sphere.js | 2 +- src/brushes/spheres.js | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/brushes/cubes.js b/src/brushes/cubes.js index 591259811..d41a1d00f 100644 --- a/src/brushes/cubes.js +++ b/src/brushes/cubes.js @@ -7,7 +7,7 @@ AFRAME.registerBrush('cubes', roughness: 0.5, metalness: 0.5, side: THREE.DoubleSide, - shading: THREE.FlatShading + flatShading: true }); this.geometry = new THREE.BoxGeometry(1, 1, 1); }, @@ -17,7 +17,7 @@ AFRAME.registerBrush('cubes', var sca = pressure * this.data.size * Math.random(); box.scale.set(sca, sca, sca); box.position.copy(pointerPosition); - box.rotation.copy(orientation); + box.quaternion.copy(orientation); this.object3D.add(box); diff --git a/src/brushes/rainbow.js b/src/brushes/rainbow.js index 595e18a92..829554284 100644 --- a/src/brushes/rainbow.js +++ b/src/brushes/rainbow.js @@ -42,13 +42,12 @@ this.linepositions = new Float32Array(this.options.maxPoints); this.geometry.setDrawRange(0, 0); - this.geometry.addAttribute('position', new THREE.BufferAttribute(this.vertices, 3).setDynamic(true)); - this.geometry.addAttribute('uv', new THREE.BufferAttribute(this.uvs, 2).setDynamic(true)); - this.geometry.addAttribute('lineposition', new THREE.BufferAttribute(this.linepositions, 1).setDynamic(true)); + this.geometry.setAttribute('position', new THREE.BufferAttribute(this.vertices, 3).setUsage(THREE.DynamicDrawUsage)); + this.geometry.setAttribute('uv', new THREE.BufferAttribute(this.uvs, 2).setUsage(THREE.DynamicDrawUsage)); + this.geometry.setAttribute('lineposition', new THREE.BufferAttribute(this.linepositions, 1).setUsage(THREE.DynamicDrawUsage)); this.material = material; var mesh = new THREE.Mesh(this.geometry, this.material); - mesh.drawMode = THREE.TriangleStripDrawMode; mesh.frustumCulled = false; mesh.vertices = this.vertices; diff --git a/src/brushes/single-sphere.js b/src/brushes/single-sphere.js index 09a49e70a..338c16da1 100644 --- a/src/brushes/single-sphere.js +++ b/src/brushes/single-sphere.js @@ -7,7 +7,7 @@ AFRAME.registerBrush('single-sphere', roughness: 0.6, metalness: 0.2, side: THREE.FrontSide, - shading: THREE.SmoothShading + flatShading: true }); this.geometry = new THREE.IcosahedronGeometry(1, 2); this.mesh = new THREE.Mesh(this.geometry, this.material); diff --git a/src/brushes/spheres.js b/src/brushes/spheres.js index 05b18c926..b97c6ff59 100644 --- a/src/brushes/spheres.js +++ b/src/brushes/spheres.js @@ -8,7 +8,7 @@ AFRAME.registerBrush('spheres', roughness: 0.5, metalness: 0.5, side: THREE.DoubleSide, - shading: THREE.FlatShading + flatShading: true }); this.geometry = new THREE.IcosahedronGeometry(1, 0); }, @@ -28,7 +28,7 @@ AFRAME.registerBrush('spheres', // Set the position of the sphere to match the controller positoin sphere.position.copy(pointerPosition); - sphere.rotation.copy(orientation); + sphere.quaternion.copy(orientation); // Add the sphere to the object3D this.object3D.add(sphere); From 0280dc0da41275c302eb413307843fb717aa48f9 Mon Sep 17 00:00:00 2001 From: Daniel Adams Date: Sun, 27 Feb 2022 21:50:07 -0500 Subject: [PATCH 4/8] Fix stamp-based brushes This modifies the way indices are sent to the index buffer. If the brush is strip-based, we know verts are being sent 2 at a time. If it's stamp based, we know verts are being sent 3 at a time. SharedBufferGeometry now has a strip flag and sets indices accordingly. --- src/brushes/line.js | 1 + src/brushes/stamp.js | 6 +++--- src/sharedbuffergeometry.js | 26 +++++++++++++++++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/brushes/line.js b/src/brushes/line.js index b4819cfd9..caca21daf 100644 --- a/src/brushes/line.js +++ b/src/brushes/line.js @@ -40,6 +40,7 @@ var onLoaded = require('../onloaded.js'); init: function (color, brushSize) { this.sharedBuffer = sharedBufferGeometryManager.getSharedBuffer('strip-' + this.materialOptions.type); this.sharedBuffer.restartPrimitive(); + this.sharedBuffer.strip = true; this.prevIdx = Object.assign({}, this.sharedBuffer.idx); this.idx = Object.assign({}, this.sharedBuffer.idx); diff --git a/src/brushes/stamp.js b/src/brushes/stamp.js index d204cfab3..957a04b46 100644 --- a/src/brushes/stamp.js +++ b/src/brushes/stamp.js @@ -22,8 +22,8 @@ var onLoaded = require('../onloaded.js'); alphaTest: 0.5 }); - sharedBufferGeometryManager.addSharedBuffer('tris-flat', flat, THREE.TrianglesDrawMode); - sharedBufferGeometryManager.addSharedBuffer('tris-shaded', shaded, THREE.TrianglesDrawMode); + sharedBufferGeometryManager.addSharedBuffer('tris-flat', flat); + sharedBufferGeometryManager.addSharedBuffer('tris-shaded', shaded); }); var stamp = { @@ -32,7 +32,7 @@ var onLoaded = require('../onloaded.js'); this.sharedBuffer = sharedBufferGeometryManager.getSharedBuffer('tris-' + this.materialOptions.type); this.prevIdx = Object.assign({}, this.sharedBuffer.idx); this.idx = Object.assign({}, this.sharedBuffer.idx); - + this.sharedBuffer.strip = false; this.currAngle = 0; this.subTextures = 1; diff --git a/src/sharedbuffergeometry.js b/src/sharedbuffergeometry.js index 28f239a36..3f8f0a799 100644 --- a/src/sharedbuffergeometry.js +++ b/src/sharedbuffergeometry.js @@ -4,6 +4,7 @@ function SharedBufferGeometry (material) { this.maxBufferSize = 1000000; this.geometries = []; this.current = null; + this.strip = true; this.addBuffer(false); } @@ -141,9 +142,28 @@ SharedBufferGeometry.prototype = { buffer = this.current.attributes.position; } buffer.setXYZ(this.idx.position++, x, y, z); - if ((this.idx.position + 1) % 2 == 0 && this.idx.position > 1) { - this.current.index.setXYZ(this.idx.position - 3, this.idx.position - 3, this.idx.position - 2, this.idx.position - 1); - this.current.index.setXYZ(this.idx.position - 2, this.idx.position - 1, this.idx.position - 2, this.idx.position); + if (this.strip) { + if ((this.idx.position + 1) % 2 == 0 && this.idx.position > 1) { + /* Line brushes + 2---3 + | \ | + 0---1 + {0, 1, 2}, {2, 1, 3} + */ + this.current.index.setXYZ(this.idx.position - 3, this.idx.position - 3, this.idx.position - 2, this.idx.position - 1); + this.current.index.setXYZ(this.idx.position - 2, this.idx.position - 1, this.idx.position - 2, this.idx.position); + } + } + else { + if ((this.idx.position + 1) % 3 == 0) { + /* Stamp brushes + 0---1 0 + \ | | \ + 2 3---2 + {0, 1, 2}, {2, 3, 0} + */ + this.current.index.setXYZ(this.idx.position, this.idx.position - 2, this.idx.position - 1, this.idx.position); + } } }, From 00c91291cf3930ef2a8cb24883a2d7c65b2532cd Mon Sep 17 00:00:00 2001 From: Daniel Adams Date: Mon, 28 Feb 2022 00:21:46 -0500 Subject: [PATCH 5/8] Restore cube/sphere/rainbow brushes These brushes were not being added to the a-drawing entity. They were also missing an undo function, which is now implemented. Rainbow brush was adjusted to use indexed BufferGeometry. Increased index buffer size for sharedbuffergeometry. --- src/brushes/cubes.js | 5 +++++ src/brushes/rainbow.js | 16 +++++++++++++++- src/brushes/single-sphere.js | 7 ++++++- src/brushes/spheres.js | 5 +++++ src/sharedbuffergeometry.js | 2 +- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/brushes/cubes.js b/src/brushes/cubes.js index d41a1d00f..c1215e5ed 100644 --- a/src/brushes/cubes.js +++ b/src/brushes/cubes.js @@ -10,6 +10,8 @@ AFRAME.registerBrush('cubes', flatShading: true }); this.geometry = new THREE.BoxGeometry(1, 1, 1); + this.drawing = document.querySelector('.a-drawing'); + this.drawing.object3D.add(this.object3D); }, addPoint: function (position, orientation, pointerPosition, pressure, timestamp) { var box = new THREE.Mesh(this.geometry, this.material); @@ -22,6 +24,9 @@ AFRAME.registerBrush('cubes', this.object3D.add(box); return true; + }, + undo: function () { + this.drawing.object3D.children.pop(); } }, {thumbnail: 'brushes/thumb_cubes.gif', spacing: 0.01} diff --git a/src/brushes/rainbow.js b/src/brushes/rainbow.js index 829554284..0090d7d51 100644 --- a/src/brushes/rainbow.js +++ b/src/brushes/rainbow.js @@ -38,11 +38,13 @@ this.idx = 0; this.geometry = new THREE.BufferGeometry(); this.vertices = new Float32Array(this.options.maxPoints * 3 * 3); + this.indices = new Uint32Array(this.options.maxPoints * 4.5 * 4.5) this.uvs = new Float32Array(this.options.maxPoints * 2 * 2); this.linepositions = new Float32Array(this.options.maxPoints); this.geometry.setDrawRange(0, 0); this.geometry.setAttribute('position', new THREE.BufferAttribute(this.vertices, 3).setUsage(THREE.DynamicDrawUsage)); + this.geometry.setIndex(new THREE.BufferAttribute(this.indices, 3).setUsage(THREE.DynamicDrawUsage)); this.geometry.setAttribute('uv', new THREE.BufferAttribute(this.uvs, 2).setUsage(THREE.DynamicDrawUsage)); this.geometry.setAttribute('lineposition', new THREE.BufferAttribute(this.linepositions, 1).setUsage(THREE.DynamicDrawUsage)); @@ -53,6 +55,8 @@ mesh.vertices = this.vertices; this.object3D.add(mesh); + this.drawing = document.querySelector('.a-drawing'); + this.drawing.object3D.add(this.object3D); }, addPoint: (function () { var direction = new THREE.Vector3(); @@ -88,11 +92,18 @@ this.vertices[this.idx++] = posB.x; this.vertices[this.idx++] = posB.y; this.vertices[this.idx++] = posB.z; + + // Same principle as line brush strips + if (this.idx > 6) { + this.geometry.index.setXYZ(this.idx / 3 - 4, this.idx / 3 - 4, this.idx / 3 - 3, this.idx / 3 - 2); + this.geometry.index.setXYZ(this.idx / 3 - 3, this.idx / 3 - 2, this.idx / 3 - 3, this.idx / 3 - 1); + } this.geometry.attributes.position.needsUpdate = true; + this.geometry.index.needsUpdate = true; this.geometry.attributes.uv.needsUpdate = true; - this.geometry.setDrawRange(0, this.data.numPoints * 2); + this.geometry.setDrawRange(0, this.data.numPoints * 2 * 6); return true; } @@ -100,6 +111,9 @@ tick: function(timeOffset, delta) { this.material.uniforms.time.value = timeOffset; }, + undo: function () { + this.drawing.object3D.children.pop(); + } }, {thumbnail:'brushes/thumb_rainbow.png', maxPoints: 3000} ); diff --git a/src/brushes/single-sphere.js b/src/brushes/single-sphere.js index 338c16da1..66ee01ff7 100644 --- a/src/brushes/single-sphere.js +++ b/src/brushes/single-sphere.js @@ -12,7 +12,9 @@ AFRAME.registerBrush('single-sphere', this.geometry = new THREE.IcosahedronGeometry(1, 2); this.mesh = new THREE.Mesh(this.geometry, this.material); this.object3D.add(this.mesh); - this.mesh.visible = false + this.mesh.visible = false; + this.drawing = document.querySelector('.a-drawing'); + this.drawing.object3D.add(this.object3D); }, addPoint: function (position, orientation, pointerPosition, pressure, timestamp) { if (!this.firstPoint) { @@ -23,6 +25,9 @@ AFRAME.registerBrush('single-sphere', var distance = this.firstPoint.distanceTo(pointerPosition); this.mesh.scale.set(distance, distance, distance); return true; + }, + undo: function () { + this.drawing.object3D.children.pop(); } }, {thumbnail: 'brushes/thumb_single_sphere.png', spacing: 0.0} diff --git a/src/brushes/spheres.js b/src/brushes/spheres.js index b97c6ff59..90f00177e 100644 --- a/src/brushes/spheres.js +++ b/src/brushes/spheres.js @@ -11,6 +11,8 @@ AFRAME.registerBrush('spheres', flatShading: true }); this.geometry = new THREE.IcosahedronGeometry(1, 0); + this.drawing = document.querySelector('.a-drawing'); + this.drawing.object3D.add(this.object3D); }, // This function is called every time we need to add a point to our stroke // It should returns true if the point is added correctly, false otherwise. @@ -45,6 +47,9 @@ AFRAME.registerBrush('spheres', var sin = (Math.sin(sphere.phase + time / 500.0) + 1) / 2 + 0.1; sphere.scale.copy(sphere.initialScale).multiplyScalar(sin); } + }, + undo: function () { + this.drawing.object3D.children.pop(); } }, // Define extra options for this brush diff --git a/src/sharedbuffergeometry.js b/src/sharedbuffergeometry.js index 3f8f0a799..cf874715e 100644 --- a/src/sharedbuffergeometry.js +++ b/src/sharedbuffergeometry.js @@ -60,7 +60,7 @@ SharedBufferGeometry.prototype = { var geometry = new THREE.BufferGeometry(); var vertices = new Float32Array(this.maxBufferSize * 3); - var indices = new Uint32Array(this.maxBufferSize * 1.5); + var indices = new Uint32Array(this.maxBufferSize * 4.5); var normals = new Float32Array(this.maxBufferSize * 3); var uvs = new Float32Array(this.maxBufferSize * 2); var colors = new Float32Array(this.maxBufferSize * 3); From 8f96318f9373ef20cebc4e98e5798b81c8cc7cdc Mon Sep 17 00:00:00 2001 From: Daniel Adams Date: Thu, 3 Mar 2022 22:35:15 -0500 Subject: [PATCH 6/8] Fix indexing into empty position data on even undo --- src/sharedbuffergeometry.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sharedbuffergeometry.js b/src/sharedbuffergeometry.js index cf874715e..cec8659de 100644 --- a/src/sharedbuffergeometry.js +++ b/src/sharedbuffergeometry.js @@ -172,7 +172,9 @@ SharedBufferGeometry.prototype = { }, update: function () { - this.current.setDrawRange(0, this.idx.position * 3); + // Draw one less triangle to prevent indexing into blank positions + // on an even-number-positioned undo + this.current.setDrawRange(0, (this.idx.position * 3) - 4); this.current.attributes.color.needsUpdate = true; this.current.attributes.normal.needsUpdate = true; From 65422cda72ef3fd6333f3833b6f0a014d9959356 Mon Sep 17 00:00:00 2001 From: Daniel Adams Date: Fri, 4 Mar 2022 18:32:54 -0500 Subject: [PATCH 7/8] Adjust bufferattribute updateRanges --- src/sharedbuffergeometry.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/sharedbuffergeometry.js b/src/sharedbuffergeometry.js index cec8659de..767b72eae 100644 --- a/src/sharedbuffergeometry.js +++ b/src/sharedbuffergeometry.js @@ -83,10 +83,15 @@ SharedBufferGeometry.prototype = { geometry.setDrawRange(0, 0); geometry.setAttribute('position', new THREE.BufferAttribute(vertices, 3).setUsage(THREE.DynamicDrawUsage)); + geometry.attributes.position.updateRange.count = 0; geometry.setIndex(new THREE.BufferAttribute(indices, 3).setUsage(THREE.DynamicDrawUsage)); + geometry.index.updateRange.count = 0; geometry.setAttribute('uv', new THREE.BufferAttribute(uvs, 2).setUsage(THREE.DynamicDrawUsage)); + geometry.attributes.uv.updateRange.count = 0; geometry.setAttribute('normal', new THREE.BufferAttribute(normals, 3).setUsage(THREE.DynamicDrawUsage)); + geometry.attributes.normal.updateRange.count = 0; geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3).setUsage(THREE.DynamicDrawUsage)); + geometry.attributes.color.updateRange.count = 0; this.previous = null; @@ -176,10 +181,15 @@ SharedBufferGeometry.prototype = { // on an even-number-positioned undo this.current.setDrawRange(0, (this.idx.position * 3) - 4); + this.current.attributes.color.updateRange.count = this.idx.position * 3; this.current.attributes.color.needsUpdate = true; + this.current.attributes.normal.updateRange.count = this.idx.position * 3; this.current.attributes.normal.needsUpdate = true; + this.current.attributes.position.updateRange.count = this.idx.position * 3; this.current.attributes.position.needsUpdate = true; + this.current.attributes.uv.updateRange.count = this.idx.position * 2; this.current.attributes.uv.needsUpdate = true; + this.current.index.updateRange.count = this.idx.position * 3; this.current.index.needsUpdate = true; } }; From a31c781ee36109c3e5c2568267b30c19c8a07f6b Mon Sep 17 00:00:00 2001 From: Daniel Adams Date: Mon, 7 Mar 2022 01:24:38 -0500 Subject: [PATCH 8/8] drawing -> drawingEl --- src/brushes/cubes.js | 6 +++--- src/brushes/single-sphere.js | 6 +++--- src/brushes/spheres.js | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/brushes/cubes.js b/src/brushes/cubes.js index c1215e5ed..0e82c6668 100644 --- a/src/brushes/cubes.js +++ b/src/brushes/cubes.js @@ -10,8 +10,8 @@ AFRAME.registerBrush('cubes', flatShading: true }); this.geometry = new THREE.BoxGeometry(1, 1, 1); - this.drawing = document.querySelector('.a-drawing'); - this.drawing.object3D.add(this.object3D); + this.drawingEl = document.querySelector('.a-drawing'); + this.drawingEl.object3D.add(this.object3D); }, addPoint: function (position, orientation, pointerPosition, pressure, timestamp) { var box = new THREE.Mesh(this.geometry, this.material); @@ -26,7 +26,7 @@ AFRAME.registerBrush('cubes', return true; }, undo: function () { - this.drawing.object3D.children.pop(); + this.drawingEl.object3D.children.pop(); } }, {thumbnail: 'brushes/thumb_cubes.gif', spacing: 0.01} diff --git a/src/brushes/single-sphere.js b/src/brushes/single-sphere.js index 66ee01ff7..9ff627ddc 100644 --- a/src/brushes/single-sphere.js +++ b/src/brushes/single-sphere.js @@ -13,8 +13,8 @@ AFRAME.registerBrush('single-sphere', this.mesh = new THREE.Mesh(this.geometry, this.material); this.object3D.add(this.mesh); this.mesh.visible = false; - this.drawing = document.querySelector('.a-drawing'); - this.drawing.object3D.add(this.object3D); + this.drawingEl = document.querySelector('.a-drawing'); + this.drawingEl.object3D.add(this.object3D); }, addPoint: function (position, orientation, pointerPosition, pressure, timestamp) { if (!this.firstPoint) { @@ -27,7 +27,7 @@ AFRAME.registerBrush('single-sphere', return true; }, undo: function () { - this.drawing.object3D.children.pop(); + this.drawingEl.object3D.children.pop(); } }, {thumbnail: 'brushes/thumb_single_sphere.png', spacing: 0.0} diff --git a/src/brushes/spheres.js b/src/brushes/spheres.js index 90f00177e..e6b0bc648 100644 --- a/src/brushes/spheres.js +++ b/src/brushes/spheres.js @@ -11,8 +11,8 @@ AFRAME.registerBrush('spheres', flatShading: true }); this.geometry = new THREE.IcosahedronGeometry(1, 0); - this.drawing = document.querySelector('.a-drawing'); - this.drawing.object3D.add(this.object3D); + this.drawingEl = document.querySelector('.a-drawing'); + this.drawingEl.object3D.add(this.object3D); }, // This function is called every time we need to add a point to our stroke // It should returns true if the point is added correctly, false otherwise. @@ -49,7 +49,7 @@ AFRAME.registerBrush('spheres', } }, undo: function () { - this.drawing.object3D.children.pop(); + this.drawingEl.object3D.children.pop(); } }, // Define extra options for this brush