Hello,
I’m trying to create custom meshes, I have a problem related to cloning.
I created a javascript class that extends the Mesh class.
I redefined the clone method.
When I clone a custom mesh, it does not contain what the original source mesh contained.
Is there any alternative way to do this.
Cloned meshes must remain of the same original class.
I created an example here on playground:
Sample code:
const A = new CustomMeshA('A');
A.build();
const B = A.clone('B');
B.position.x = 1;
class CustomMeshA extends BABYLON.Mesh
{
constructor(name, scene) {
super(name, scene);
}
clone(name, newParent, doNotCloneChildren)
{
const newInstance = new CustomMeshA(name, this.getScene());
//super.clone(name, newInstance, doNotCloneChildren);
return newInstance;
}
build()
{
const positions = [-.5, .2, -.3, -.7, -.2, -.3, -.3, -.2, -.3, .5, .2, .3, .7, -.2, .3, .3, -.2, .3];
const indices = [0, 1, 2, 3, 4, 5];
const vertexData = new BABYLON.VertexData();
vertexData.positions = positions;
vertexData.indices = indices;
const normals = [];
BABYLON.VertexData.ComputeNormals(positions, indices, normals);
vertexData.applyToMesh(this);
}
}