# Problem with vertexBuffer

Hello.

I’m trying to get vertexes’ position from vertexBuffer and render lines between em.

Get vertexes:

``````
this.points = [];
var buffer = this.entity.model.model.meshInstances.mesh.vertexBuffer;
var iterator = new pc.VertexIterator(buffer);

for(i = 0; i < buffer.getNumVertices(); i++) {

var posSem = iterator.element[pc.SEMANTIC_POSITION];

posX = posSem.array[posSem.index];
posY = posSem.array[posSem.index + 1];
posZ = posSem.array[posSem.index + 2];

var pos = new pc.Vec3(posX, posY, posZ);
this.points.push(pos);
iterator.next();

}

iterator.end();
``````

Render lines:

``````for (i = 0; i <  this.points.length-1; i++) {
var pointA =  this.points[i];

for (j = i+1; j <  this.points.length; j++) {
var pointB =  this.points[j];

var dx = pointA.x - pointB.x;
var dy = pointA.y - pointB.y;
var dz = pointA.z - pointB.z;

var dist = Math.sqrt(dx*dx + dy*dy + dz*dz);

if (dist < 15) {
this.app.renderLine(pointA, pointB, new pc.Color(1,1,1));
}
}

}
``````

And the problems is that my vertexes’ positions are not correct and much more than actual geometry.

I think I probably have to multiply my pos vector by viewProject matrix, but i’m not quite sure how to do that.

Before adding a point to your points array, multiply it by the model matrix, that’ll apply translation/rotation/scaling to your vertices ``````// get matrix beforehand, don't need to call it for every vertex
var matrix = this.entity.model.meshInstances.node.getWorldTransform();

// in your loop, multiply the pos
matrix.transformPoint(pos, pos);
``````
2 Likes