Hi,
I have mesh on scene - this is a plane, and i need to put Spheres at each point of this plane.
I do following:
initialize: function () {
var i = 0, meshInstance = null;
for( ; meshInstance = this.entity.model.model.meshInstances[i++]; ) {
if (0 === meshInstance.node.name.indexOf('Plane_')) {
this.plane = meshInstance;
break;
}
}
if (null === this.plane) { // i pass this always with no error
console.error('Could found Plane mesh of model:' + entity.name);
return;
}
if (this.plane.mesh.vertexBuffer.numVertices < 4) { // i pass this always with no error
console.error('Plane mesh has unexpected count of vertices. There gotta be at least 4 vertices.');
return;
}
var vertexBuffer = this.plane.mesh.vertexBuffer;
var vertices = new Float32Array(vertexBuffer.storage);
var size = vertexBuffer.format.size / 4; // bytes -> float32
for(var vertexIndex = 0; vertexIndex < 4; vertexIndex++) {
var point = new pc.fw.Entity();
var pos = new pc.Vec3(
vertices[vertexIndex * size],
vertices[vertexIndex * size + 1],
vertices[vertexIndex * size + 2]);
point.setName('point_' + vertexIndex);
context.systems.model.addComponent(point, { type: 'sphere' });
this.entity.addChild(point)
point.setScale(0.5, 0.5, 0.5);
point.setPosition(pos);
}
// ....
The problem is that method setScale, setLocalScale, setPosition, setLocalPosition, translate does not make any effect on point - why?
point and Sphere attached to the point always stay at ceneter of scene. what I do wrong.