Thank you for your fast and helpful reply!
It would be sufficient for me at first when i transform an object with a scaling operation called by a keystroke. For example if i press ‘Y’ the object would get stretched in y-direction by a certain factor.
My first approach was to change the data inside the buffer just like in SimpleAnimationScene::updateGeometry(). But i can only scale once and then if I press the button, I see no change.
Here is my edited function:
void SimpleAnimationScene::compressX()
{
//We know that we have (only) one group in this example
GeometryInstance geometryInstance = m_geometry_group->getChild( 0 );
Geometry geometry = geometryInstance->getGeometry();
/*
All we want to do here is to compress all vertices y-position by the 10% .
*/
Buffer vertexBuffer = geometry["vertex_buffer"]->getBuffer();
float3* new_vertices = (float3*)vertexBuffer->map();
RTsize numVertices;
vertexBuffer->getSize( numVertices );
//We don't have to set x and z here in this example
for(unsigned int v = 0; v < numVertices; v++)
{
new_vertices[v].x = m_vertices[v].x * 0.9f;
}
vertexBuffer->unmap();
/*
Vertices are changed now; we have to tell the
corresponding acceleration structure that it
has to be rebuild.
Mark the accel structure and geometry as dirty.
*/
geometry->markDirty();
m_geometry_group->getAcceleration()->markDirty();
}
My second approach is setting the matrices inside a Transform node, like you said. But i get an error like OptiX Error: Invalid value (Details: Function “RTresult _rtGroupGetChild(RTgroup, unsigned int, void**)” caught exception: Child index out of range, [2228283]). Can somebody tell me why?
Here is my second approach.
void SimpleAnimationScene::compressY()
{
//We know that we have (only) one group in this example
Group maingroup = m_context->createGroup();
// we have only one group - the main group whose childs are instances of Transform
// mainGroup is an instance of Group
Transform transform = maingroup->getChild<Transform>(0);
//transform->setChild(m_geometry_group);
//float m[16];
const float matrix[4*4] = { 1, 0, 0, 0,
0, 1.1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
transform->setMatrix(false, matrix, NULL);
// mark dirty so that the acceleration structure gets rebuilt
m_geometry_group->getAcceleration()->markDirty();
}
Thanks in advance!
Regards, Daniel