You can see that the spheres dont match where the edges of the mesh meet
Image above is the result of spawning a sphere at each vertex, like so:
var mesh = this.entity.children[0].model.meshInstances[0].mesh;
var it = new pc.VertexIterator(mesh.vertexBuffer);
for (var i = 0; i < mesh.vertexBuffer.getNumVertices(); i++) {
var semPos = it.element[pc.SEMANTIC_POSITION];
var pos = {
x: semPos.array[semPos.index],
y: semPos.array[semPos.index + 1],
z: semPos.array[semPos.index + 2]
};
var b = this.cube.clone();
b.enabled = true;
b.reparent(this.entity);
b.setLocalPosition(pos.x, pos.y, pos.z);
it.next();
}
it.end();
The mesh has not been scaled, moved or rotated so I’m not sure what the issue here is!
Ok, cool the issue is that you are missing a base transform that the renderer does on the vertices, multiplying them by the model matrix:
Here is your corrected code:
PlanetSpikeTest.prototype.generate = function() {
var mesh = this.entity.children[0].model.meshInstances[0].mesh;
var it = new pc.VertexIterator(mesh.vertexBuffer);
// get matrix beforehand, don't need to call it for every vertex
var matrix = this.entity.children[0].model.meshInstances[0].node.getWorldTransform();
var pos = new pc.Vec3();
// none working code..
for (var i = 0; i < mesh.vertexBuffer.getNumVertices(); i++) {
var semPos = it.element[pc.SEMANTIC_POSITION];
pos.set(semPos.array[semPos.index], semPos.array[semPos.index + 1], semPos.array[semPos.index + 2]);
matrix.transformPoint(pos, pos);
var b = this.cube.clone();
b.enabled = true;
b.reparent(this.entity);
b.setPosition(pos);
it.next();
}
it.end();
};