Importing an animation using a binary file

Hello,

I am writing a plugin which needs 2 functions one to export an animation in a binary file and another to import the modified animation in Daz.

After the exportation, this mesh animation is modified by another program.

The two functions work perfectly and the vertices are correctly imported in the interface.

My problem is the normals of the mesh are not modified during the importation.

It is like if the normals was defined in the first frame and stay the sames during all the animation, even if the vertices positions move correctly.

For the exportation and the importation, I use this function to get the geometry : "DzVertexMesh * mesh =  obj->getCachedGeom();"

I suppose this method is fine for the exportation but it does not work properly for the importation.

I tried several methods to update the mesh but the normals stay always bad.

I hope someone can help me to resolve this issue.

I thank you by advance.

       Gérald

Comments

  • Hello Again,

    I tried to use this function "DzVertexMesh * mesh = obj->getCurrentShape()->getModifiableGeom(true);" to modify the vertices.

    Using this line, the program does not modify any vertices. Nothing happens.

    I tried to use a call as close as possible to the one I used in a script I wrote and which modified correctly the vertices.

    If someone can help, This would be great. Thanks!

  • Hello,

    I will ask my question in another way.

    Someone could tell me how I could access to the vertices of a geometry.

    I would like to access to the "setVertex" function of a geometry but I do not find a way to do so.

    Thank you by advance.

  • rbtwhizrbtwhiz Posts: 2,267
    edited December 2018

    Rather than trying to edit the cached mesh, subclass DzModifier and store the adjusted positions of vertices in the base mesh (for a given time)... and then in your apply() implementation, adjust the position of the vertices (based on the current time), so that when the mesh is finalized (after the modifier stack has been processed) the normals are automatically recalculated (once) through the normal operation of the geometry pipeline.

    Another (much less efficient) option is to use DzShape::getModifiableGeom(), call it meshA. Then, use meshA->makeCopy() to create a second copy of meshA, call it meshB. Then, for each time/frame of the animation data, call meshB->copyFrom( meshA ) followed by modifing the vertex positions in meshB to reflect the animation data and then calling meshB->getNormalsPtr(). This works because it marks the normals in meshB as being invalid so that when meshB is next asked for normals, the normals are recalculated.

    This obviously doesn't help you at the moment, with the current SDK, but an invalidateNormals() member function has recently been added to DzFacetMesh for a pending SDK update.

    -Rob

    Post edited by rbtwhiz on
  • Hello Rob,

    Thank you for your very precise reply.

    Thanks to your help, I found another way to play the animation with good normals.
    I never tried to write a modifier and I looked at the BlackHole sample.
    This sample modifies directly the vertices defined by the "getVerticesPtr" function.
    This pointer can be found in the DzGeometry class. For me this solution seemed better.
    I got the DzGeometry using a "myGeom = node->getCurrentShape()->getGeometry();" line.
    Then I got the pointer using "verts = myGeom->getVerticesPtr();".
    And I just needed to modify directly the vertices by using a correct pointer to each vertex.
    It is necessary to use "myGeom->beginEdit();" before the modifications and "myGeom->finishEdit();" after the modifications.
    These 2 functions update the vertices but update also the normals.

    I hope this solution could help some developers.

    Thank you very much for your help.

           Gérald

Sign In or Register to comment.