From f779a8e5f7889e5c398cde751b74f1993fd1ef98 Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Fri, 26 Jan 2024 11:19:59 +0100 Subject: [PATCH] Avoid crash when cloning Troika text --- src/utils/three-utils.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/utils/three-utils.js b/src/utils/three-utils.js index dffc35bd50..d9808919b5 100644 --- a/src/utils/three-utils.js +++ b/src/utils/three-utils.js @@ -365,9 +365,10 @@ export function createPlaneBufferGeometry(width, height, widthSegments, heightSe } import { Layers } from "../camera-layers"; -import { Box3, DoubleSide, Mesh, MeshBasicMaterial, Object3D, Vector3 } from "three"; +import { Box3, DoubleSide, Group, Mesh, MeshBasicMaterial, Object3D, Vector3 } from "three"; import { TEXTURES_FLIP_Y } from "../loaders/HubsTextureLoader"; import { MediaVideo } from "../bit-components"; +import { Text } from "troika-three-text"; // This code is from three-vrm. We will likely be using that in the future and this inlined code can go away function excludeTriangles(triangles, bws, skinIndex, exclude) { @@ -595,6 +596,19 @@ THREE.Object3D.prototype.clone = (function () { } return videoMesh; + } else if (this.type === "Group") { + const group = new Group().copy(this, false); + for (let i = 0; i < this.children.length; i++) { + const child = this.children[i]; + // Troika text material crashes when cloning: https://github.com/protectwise/troika/issues/248 + // Ignoring for now... + if (child instanceof Text) { + group.add(new Object3D()); + } else { + group.add(child.clone()); + } + } + return group; } else { return this._clone(); }