Store/Cache BaseArray of vectors



  • On 15/05/2015 at 00:23, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   14,15,16 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hi,
    This is a long shot, but here it is anyway.

    I am trying to store some BaseArray vectors to be used later in the code.
    I am writing an object plugin. This plugin gets the points of a link polygon object in the scene and does some noise calculations on those. The problem is that when the link object is animation-deformed, like in the case of a formula deformer, my noise results change.
    What I would like to do is get the points from the link object at the start frame and cache them. I should then be able to access that cached array of vectors from GetVirtualObjects at any frame and process them.

    Any hint on the simplest way to do that ?



  • On 15/05/2015 at 08:12, xxxxxxxx wrote:

    Hi,

    actually we are not quite sure, what's the actual problem. Are you having problems storing Vectors in a BaseArray? Or is it a problem, how to get the undeformed data of an object? Or perhaps something completely different?



  • On 15/05/2015 at 09:49, xxxxxxxx wrote:

    I guess he/she wants to know how to store the initial state of the input polygon object to have constant vertex coordinates unaffected by animated deformations to allow for equivalent world space shader sampling (what a freakin long sentence.. :D )

    Just store a copy of it in your class. Make sure to delete the cached polygon object whenever necesarry (::Free() method e.g.). You could equivalently do the same with just the vertices if you want..it's all up to you

    class YourObjectPlugin  
    {  
    private:  
    PolygonObject* m_cached_initial_state;  
    }  
      
    //Then in your code (probably even in GVO() method)  
    if(frame==0){  
    if(m_cached_initial_state) PolygonObject::Free(m_cached_initial_state);  
    m_cached_initial_state = static_cast<PolygonObject*>(original_polygon_obj->GetClone());  
    }
    


  • On 15/05/2015 at 12:58, xxxxxxxx wrote:

    Thanks for the reply Katachi. (I'm a He btw).

    I already tried it that way with a BaseArray of vectors. It works in the viewport, but I get a crash when I render. I think the crash is normal because that BaseArray is not cached.

    The code I used is this:

    if (cF == startFrame) staticGridPoints.CopyFrom(gridPoints);
    

    where gridPoints is a BaseArray of vectors created procedurally at every frame in GVO and staticGridPoints is a class level variable BaseArray.

    If I try to access staticGridPoints at a later frame than the start frame, I get a crash.

    It works in the viewport since I am usually starting the playback from the start frame. But if I save the file with the playback at say frame 50 and reopen I get a crash. I also get a crash when I render.

    My question is how to store that staticGridPoints BaseArray (obtained from the start frame) so that it is accessible (to the renderer) at any frame.

    @Andreas, yes I am trying to get the undeformed data of an object.



  • On 16/05/2015 at 08:31, xxxxxxxx wrote:

    As I am doing exactly this in one of my objects myself I cannot really confirm a crash (though I am not using BaseArray but STL which however shouldn't matter).

    You must post more code to know what might be the problem (make sure you overload Read(), Write(), CopyTo() virtual functions to allow loading and saving from scene file and for picture viewer rendering respectively). Did you debug your code to know where the crash actually happens?

    If not that's the first objective.


Log in to reply