Actually what I did in 2015, was PR a change to Mesh, so that the source of the clone & cloning was done in the constructor. This enabled Mesh sub-classing much like the rest of the language planet. Many languages allow multiple constructors (JS is crap). A clone() function outside the constructor is hostile to sub-classing.
I realize that I am strangely the edge case?? If you did anything, putting a source arg in Skeleton, & Bone constructors would be it.
Here is Mesh constructor code I currently generate
class HumanMale extends QI_MH.Automaton {
constructor(name, scene, source) {
super(name, scene, null, source, true);
const cloning = source && source !== null;
this.skeleton = skel_reference(name, scene);
this.numBoneInfluencers = 6;
this.id = this.name;
this.isPickable = false;
if (!cloning){
// Assign copies of donor VertexData, not donor.applyToMesh(), so dispose will not affect the donor.
// Also, appyToMesh() has a updatable arg. Only want it true for positions & normals, and only when shapekeys for mesh.
let donor = RefMale.VertexData["HumanMale"];
this.setVerticesData(BABYLON.VertexBuffer.PositionKind, donor.positions.slice(), true);
this.setIndices(donor.indices.slice());
this.setVerticesData(BABYLON.VertexBuffer.NormalKind, donor.normals.slice(), true);
this.setVerticesData(BABYLON.VertexBuffer.UVKind, donor.uvs.slice(), false);
this.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, donor.matricesWeights.slice(), false);
this.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, QI.UNPACK(donor.matricesIndices), false);
this.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind, donor.matricesWeightsExtra.slice(), false);
this.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, QI.UNPACK(donor.matricesIndicesExtra), false);
this.setMaterialByID("RefMale.Multimaterial#0");
this.subMeshes = [];
new BABYLON.SubMesh(0, 0, 15850, 0, 75036, this);
new BABYLON.SubMesh(1, 15850, 590, 75036, 2826, this);
new BABYLON.SubMesh(2, 16440, 609, 77862, 2406, this);
new BABYLON.SubMesh(3, 17049, 96, 80268, 516, this);
new BABYLON.SubMesh(4, 17145, 5516, 80784, 21360, this);
new BABYLON.SubMesh(5, 22661, 303, 102144, 1344, this);
// assign shape key data
this.assignShapeKeyDict(RefMale.MorphData["HumanMale"]);
}
if (this.postConstruction) this.postConstruction();
this.makeVisible(false);
this.onMeshReadyObservable.add(() => {
// an indirect test for being a QI.Mesh subclass
if (typeof this.grandEntrance === "function") this.grandEntrance();
else this.isVisible = true;
});
}
dispose(doNotRecurse) {
super.dispose(doNotRecurse);
if (this.skeleton) this.skeleton.dispose();
}
}
RefMale.HumanMale = HumanMale;
I can just put a if(this.skeleton) this.skeleton.dispose;
on a line before I assign it on the next line. I am just glad I caught it. I am probably going to need hours to go through all lines in changes.md when 5.0 comes out.