# Drawing Vertices of GLB Model from Float32Array

Im trying to draw the vertices of a glb model in my three js scene. The problem is, different models appear to have different vertice orientations.
Im getting the vertices via geometry.attributes.position.array:

``````scene.traverse(n => {
if (n.isMesh) {
let allVertices = n.geometry.attributes.position.array;
for (let i = 0; i < allVertices.length; i = i + 3) {
modelVertices.push(new THREE.Vector3(allVertices[i], allVertices[i+1], allVertices[i+2]))
}
}
});
``````

Here are 2 examples of 2 different models, one of a bag, and the other being a keyboard.

The keyboard is in the right orientation, but the bag isnâ€™t ( I got the models from different websites ). I figured that if I write the bag coordinates with

``````modelVertices.push(new THREE.Vector3(allVertices[i], -allVertices[i + 2], allVertices[i + 1])
``````

It would work, but there are more models that this other orientation wouldnâ€™t work either. I want to know how could I know in which direction draw the coordinate of the vertices, according to each model.

2 Likes

Try using translateZ

Do you add the object of points to `scene`?
Try to add it to the object of the bag.

1 Like

What do you mean? Iâ€™m already adding the points to scene, thatâ€™s why I can see them. The problem is not in the visualization (that is already working), but in the vertices that I get from the array.

1 Like

I mean, add these points to the object, whose geometry to use for the object of points.

``````scene.traverse(n => {
if (n.isMesh) {
let points = new THREE.Points(n.geometry, _your_points_material);
}
});
``````
1 Like
``````        scene.traverse(n => {
if (n.isMesh) {
let points = new THREE.Points(n.geometry, new THREE.MeshBasicMaterial({ color: 0xff0000 }));
}});
``````

Drawing the little red cubes from points.geometry.attributes.position.array, I got the same result. The vertices are sometimes rotated in an axis, deppending on which model Iâ€™m using.

1 Like

That wouldnâ€™t work on itself, because there are models that the correct orientation sits on another axis, like so:

So the problem isnâ€™t on just one misaligned orientation ( donâ€™t mind the y offset of the drawn vertices, it isnâ€™t relevant ).
I think there is a solution to this because the GLTF Loader itself loads the object in the correct orientation, but if I access only its vertices via geometry.attributes.position.array, sometimes they will be misaligned, and sometimes they will be in the correct orientation.

The coordinates in the geometry are the so called â€ślocal coordinatesâ€ť. If you want to find the actual global position of a vertex, you need its â€śworld coordinatesâ€ť. They are calculated by Object3D.localToWorld.

2 Likes