I’m trying to work out how to instance an object to the face centres of another object.
I think I need to output the face centre positions to a structured buffer and then just batch that. But how do I do that? Or am I approaching this wrong?
// Snippet to get face centers from triangles
{
if (dtid.x > threadCount) { return; }
float3 avgPoint = 0;
for(uint i=0; i<3; i++) avgPoint += ( posBuffer[(dtid.x*3 + i) % bSize(posBuffer)][dtid.x*3 + i) % bSize(posBuffer)](https://vvvv.org/documentation/dtid.x*3-+-i)-%-bSize(posBuffer))/3;
output[dtid.x](dtid.x) = avgPoint;
}
bSize() is just a helper function to get the buffer count.
Getting the face centres is the easy bit, its the how to pass it to instance the other objects…
Basically I have a seating plan made up of a triangle per seat all combined into 1 object, in c4d I use that to instance the seats to these positions, I’m looking to do the same in v4
3D buffer?
quite few ways:
depends on an object, u can render geometry as buffer with gsfx, then u can use it as buffer
if u have some simple geometry u want to align (cube) u can write all the vertex data directly in the shader but (this is slow with more then 16 verts)
many options… store ur objects as buffers do sdf etc… here is code to read gsfx streamout as buffer in compute:
ByteAddressBuffer sobuffer;
void csBOX( uint3 DTid : SV_DispatchThreadID )
{
uint ii=(DTid.x+IndexOffset)%totalcount;
float x = asfloat(sobuffer.Load(ii * 36));
float y = asfloat(sobuffer.Load(ii * 36 + 4));
float z = asfloat(sobuffer.Load(ii * 36 + 8));
float3 center = float3(x,y,z);
float u = asfloat(sobuffer.Load(ii * 36 + 12));
float v = asfloat(sobuffer.Load(ii * 36 + 12 + 4));
float2 texcd = float2(u,v);
}
Thanks guys, it was the ByteAddressBuffer that had eluded me, here’s a solution that does what I need, maybe it should align to the normals, but this is all I needed for now!
geomFx to instance Objects from another objects faces (7.4 kB)