Now that I can properly edit vertices on a mesh, is there a way to duplicate a mesh so I can edit each mesh differently? Otherwise each model clone will just use the same vertex data
I couldn’t find a clone function for a pc.Mesh so I believe I need to take the data of the base mesh and construct a new one from that?
Yes, there isn’t any method named mesh.clone(). But the createMesh() available in the engine will always create new vertex/index buffers instances. So basically it will create a copy of all the params you are passing.
Yeah I tried doing something along the lines, however this provides pretty messed up results, check my code here:
DupeTest.prototype.dupeMesh = function(entity) {
var m = entity.model.meshInstances[0].mesh;
var it = new pc.VertexIterator(m.vertexBuffer);
var pos = it.element[pc.SEMANTIC_POSITION].array;
var uvs = it.element[pc.SEMANTIC_TEXCOORD0].array;
var indices = Array.from(new Uint8Array(m.indexBuffer[0].storage));
var normals = pc.calculateNormals(pos, indices);
var mesh = pc.createMesh(this.app.graphicsDevice, pos, {
normals: normals,
uvs: uvs,
indices: indices
});
var node = new pc.GraphNode();
var mat = entity.model.meshInstances[0].material;
var meshInstance = new pc.MeshInstance(node, mesh, mat);
var model = new pc.Model();
model.graph = node;
model.meshInstances.push(meshInstance);
return model;
};
Am I right how I’m getting the vertices/indices and uvs from the current mesh using SEMANTIC_POSITION, SEMANTIC_TEXCOORD and the indexBuffer?