From 026d5b6878f067bd7e30dcca2dc6e1c78056e1b5 Mon Sep 17 00:00:00 2001 From: Michael Schlachter Date: Mon, 12 Jul 2021 10:53:40 -0700 Subject: [PATCH] fix: Add checks for missing UVs. (#34) Co-authored-by: Sam Alexander --- src/CSG.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/CSG.ts b/src/CSG.ts index 38bb0c9..9e2c030 100644 --- a/src/CSG.ts +++ b/src/CSG.ts @@ -119,9 +119,12 @@ export class CSG { normals.write(pvs[0].normal); normals.write(pvs[j - 2].normal); normals.write(pvs[j - 1].normal); - uvs.write(pvs[0].uv); - uvs.write(pvs[j - 2].uv); - uvs.write(pvs[j - 1].uv); + if (uvs) { + uvs.write(pvs[0].uv); + uvs.write(pvs[j - 2].uv); + uvs.write(pvs[j - 1].uv); + } + if (colors) { colors.write(pvs[0].color); colors.write(pvs[j - 2].color); @@ -131,7 +134,7 @@ export class CSG { } geom.setAttribute('position', new BufferAttribute(vertices.array, 3)); geom.setAttribute('normal', new BufferAttribute(normals.array, 3)); - geom.setAttribute('uv', new BufferAttribute(uvs.array, 2)); + uvs && geom.setAttribute('uv', new BufferAttribute(uvs.array, 2)); colors && geom.setAttribute('color', new BufferAttribute(colors.array, 3)); for (let gi = 0; gi < grps.length; gi++) { if (grps[gi] === undefined) {