Position of instaces when I rotate the model

Hi all, I’m new in playcanvas I’m having some problems.

I’m using harware instancing similar to this example:
https://playcanvas.github.io/#/graphics/hardware-instancing

But instead of using a random postion for each object, like in the example, I am using the position of each vertex of a model, i.e. on each vertex of the model there is an intance.


I get the position of each vertex by iterating, similar to this:

let iterator = new pc.VertexIterator(buffer);
for(let i = 0; i < buffer.getNumVertices(); i++) {

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

   let posX = posSem.array[posSem.index];
   let posY = posSem.array[posSem.index + 1];
   let posZ = posSem.array[posSem.index + 2];
   pos.set(posX,posY,posZ);

The problem is when I rotate the figure with the vertexs, for example over y axis, the position of each vertex I get are without considering the rotation.
There is any way to get the position of each vertex taken into account the rotation?

Thanks in advance.

Hey, according to the information you provided, it seems like you are setting the vertex buffer positions each time you rotate the main model. If not, you can change the vertex buffer type of instancing meshInstance from pc.BUFFER_STATIC to pc.BUFFER_DYNAMIC. And then get the vertex position each time and simply set the latest positions to the vertex buffer.

If you are already doing it and vertex positions are not correct then try using a different method to get vertex positions provided in this thread Vertex World Positions

2 Likes