Skip to content

Commit d5726d6

Browse files
Fixing issue when cloning LineMesh with CreationOptions (#16762)
When cloning a LineMesh, if the cloning is using MeshCloneOptions, LineMesh will not clone correctly because it will not update the source of the clone, and it will use the parent itself. This updates the function to handle MeshCloneOptions the same way that mesh.ts->clone does, where there are two code paths depending if parent is a Node or MeshCloneOptions.
1 parent a375175 commit d5726d6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/dev/core/src/Meshes/linesMesh.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Material } from "../Materials/material";
1010
import type { IShaderMaterialOptions } from "../Materials/shaderMaterial";
1111
import { ShaderMaterial } from "../Materials/shaderMaterial";
1212
import type { Effect } from "../Materials/effect";
13+
import type { MeshCreationOptions } from "./mesh";
1314
import { ShaderLanguage } from "core/Materials/shaderLanguage";
1415

1516
Mesh._LinesMeshParser = (parsedMesh: any, scene: Scene): Mesh => {
@@ -250,8 +251,15 @@ export class LinesMesh extends Mesh {
250251
* @param doNotCloneChildren if set to true, none of the mesh children are cloned (false by default)
251252
* @returns the new mesh
252253
*/
253-
public override clone(name: string, newParent: Nullable<Node> = null, doNotCloneChildren?: boolean): LinesMesh {
254-
return new LinesMesh(name, this.getScene(), newParent, this, doNotCloneChildren);
254+
public override clone(name: string, newParent: Nullable<Node> | MeshCreationOptions = null, doNotCloneChildren?: boolean): LinesMesh {
255+
if (newParent && (newParent as Node)._addToSceneRootNodes === undefined) {
256+
const createOptions = newParent as MeshCreationOptions;
257+
createOptions.source = this;
258+
259+
return new LinesMesh(name, this.getScene(), createOptions.parent, createOptions.source as Nullable<LinesMesh>, createOptions.doNotCloneChildren);
260+
}
261+
262+
return new LinesMesh(name, this.getScene(), newParent as Nullable<Node>, this, doNotCloneChildren);
255263
}
256264

257265
/**

0 commit comments

Comments
 (0)