We are trying to convert a in-memory object to PlayCanvas’s old (pre-.glb) json format.
We’re able to get the vertex positions, uvs, and normals ok. Having trouble getting the associated indicies per meshinstance in the way the json format expects. When we try to get the indices from a meshinstance.mesh it returns ALL the indices, not just the indices associated with this meshinstance.
Here’s our current code:
for(meshCount = 0; meshCount < meshInstances.length; meshCount++){
var mi = meshInstances[meshCount];
.
.
.
//get indices
var iBuffer = mi.mesh.indexBuffer[0];
var int16view = new Uint16Array(iBuffer.storage);
mesh.indices = Array.prototype.slice.call(int16view); //create javascript array from uint16 array
}
Any thoughts? Thanks,
Joe Hinrichs
Hi @jhinrichs,
Not sure what’s the case here, but what happens if you try getting the indices using the following method, and passing your array to populate to it:
https://developer.playcanvas.com/en/api/pc.Mesh.html#getIndices
L,
Thanks for the reply. Right, I tried this the other day, same deal. each meshinstance is returning all the indicies.
Code looks like:
for(meshCount = 0; meshCount < meshInstances.length; meshCount++){
var mi = meshInstances[meshCount];
.
.
.
//get indices
var indices = [];
mi.mesh.getIndices(indices);
mesh.indices = indices;
}
P.S. the model in question has three meshinstances, so my code is creating the PlayCanvas json format ok with three entries at the bottom for the three mesh instances, but I am expecting the indicies to be different but all three are identical.
meshes can share index buffer … which seems to be the case here if you get the same indices for all of them.
mesh contains this, which specifies which part of the index buffer it uses (or which part of vertex buffer, if index buffer is not used)
this.primitive = [{
type: 0,
base: 0,
count: 0
}];
1 Like
Ah…ok yeah. If I understand this correctly, the indices are consecutive so looking at the three meshinstances, the first mesh instance starts at 0 and goes to 1583, second starts at 1584 and goes to 1613, the third is the rest of the indices.
Am I safe to always use the primitive to determine the range even if the meshinstances don’t share the same buffer?
yes, primitive would in that case contain the whole range of the index buffer it owns. The primitive data is what used for rendering, so always correct.