We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Loading / Cloning same Object with Children into Scene multiple times

Home Forums General Questions Loading / Cloning same Object with Children into Scene multiple times

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #80904
    Thomas Fabini
    Customer

    I’ve hit a wall when trying to dynamically clone (or append) objects to an existing scene:

    As far as I understand, when cloning, none of the parent – child relationship are retained in the cloned objects as they always reference the former children.
    Un- or re-parenting the clones isn’t even remotely an option because I am using a complex structure of parent-child relationships (and a rig) so I would assume that rebuilding of the structure would go down to every last bone in that rig.

    When appending that structure as a scene, with an unique id in the “as” slot, does that mean that for each appended scene individual objects are created? If so, how can the individual elements be referenced through puzzles?

    On API-level this shouldn’t be a problem at all, since many apps load complete rigs and reference them (or elements, properties within) individually. But on the puzzle level using getObjectByName won’t really do, since there might be different uuids for the object but identical names.

    I really hope there is a solution to this, else last resort would be to loading objects through the API and passing the references to the puzzles which I personally don’t feel would be best approach.

    As always – any insights hints or solutions are greatly appreciated…

    #80905
    kdv
    Participant

    If so, how can the individual elements be referenced through puzzles?

    you should rename all objects in appended scenes. every object should have a unique name if you want to interact with it via puzzles.

    Puzzles and JS coding. Fast and expensive.

    If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.

    #80906
    Thomas Fabini
    Customer

    you should rename all objects in appended scenes

    Hi kdv, thanks for your reply.
    Do you mean renaming objects in the original files which are loaded (which would defeat the purpose of dynamically loading and reusing a scene) – or – do you mean dynamically renaming objects when loading a scene?

    #80907
    kdv
    Participant

    dynamically renaming objects when loading a scene?

    yeap. append/clone -> rename.

    Puzzles and JS coding. Fast and expensive.

    If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.

    #80908
    Thomas Fabini
    Customer

    yeap. append/clone -> rename.

    Is there a ‘rename’ puzzle I don’t know about?
    I maybe could feed “all objects” from the loaded scene to a method, parse through for each and add an index to (the name property of) each element and return the references back in an object, dictionary. This is the only thing that comes to mind right now. (Don’t know it that works).

    #80910
    kdv
    Participant

    Is there a ‘rename’ puzzle I don’t know about?

    Yes and yes :yes:

    Puzzles and JS coding. Fast and expensive.

    If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.

    #80912
    Thomas Fabini
    Customer

    That explains why I haven’t found it yet… I was going for something like (profoundly un-tested) …and profoundly wrong, too. here’s the update:

    /// Built-in variables: app, v3d, puzzles, VARS, PROC
    const objects = VARS.scene_objects;
    const index = VARS.scene_index;
    const scene_objs_renamed = [];
    
    for ( const object of objects ) {
        
        obj = app.scene.getObjectByName(object);
        obj.name = obj.name+"_"+index;
        scene_objs_renamed.push(obj.name);
    }
    VARS.scene_objs_renamed = scene_objs_renamed;
    #80916
    Thomas Fabini
    Customer

    Thanks very much for explaining this and for the solution kdv :good:

    so it means when appending a scene several times all object id’s are unique, but the names still remain the same, thus getObjectByName() would return always only the first instance it finds when traversing the scene children. So they can’t be manipulated by the classical puzzle selector.

    When renaming all children in an appended scene it seems to work, the parenting and structure remains intact and individual elements can be manipulated through puzzles then.

    #80917
    kdv
    Participant

    all object id’s are unique, but the names still remain the same, thus getObjectByName() would return always only the first instance it finds when traversing the scene children. So they can’t be manipulated by the classical puzzle selector.

    yeap, that’s how it works. in puzzles you can find some object only by its unique name.

    Puzzles and JS coding. Fast and expensive.

    If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.

    #80930
    Thomas Fabini
    Customer

    Hi kdv,

    one more question if I may:
    Before you said loading _and_ cloning. When loading, the parent-child structure or the rig remains intact, all I have to do is to rename all objects within the loaded scene.

    But when cloning I am only able to clone a single object (without its children). If I’m not mistaken here.
    Even if I would iterate through all objects when cloning (and renaming), would the parent-child relations of the clones be correct?
    From other posts I understood that clones always reference back to their original children.

    Do you think it is possible to clone a complex parent-child structure or a rig with parent-child dependencies intact?

    #80932
    kdv
    Participant

    Do you think it is possible to clone a complex parent-child structure

    why not? easy.

    Puzzles and JS coding. Fast and expensive.

    If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.

    #80934
    Thomas Fabini
    Customer

    why not? easy.

    Thank you, then at least there’s hope it will work with cloning instead of loading, too.
    But in that specific example you are cloning the whole scene… doesn’t this dramatically change when cloning a particular rig?

    Btw., I found your thread regarding cloning animations, it helped me rename the animation clips on the cloned, and renamed, rigs – without, there wasn’t any animation available for the new rigs which could be played – thanks for those examples, too.

    #80935
    kdv
    Participant

    But in that specific example you are cloning the whole scene

    because that’s the most complex object. the left farmer is rigged, the animation of the right one is based on shape keys.

    Puzzles and JS coding. Fast and expensive.

    If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.

    #80936
    Thomas Fabini
    Customer

    Does this mean it would work, too if the rig is parented to an empty which you clone?

    #80937
    kdv
    Participant

    Scene is an empty object.

    Puzzles and JS coding. Fast and expensive.

    If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.

Viewing 15 posts - 1 through 15 (of 19 total)
  • You must be logged in to reply to this topic.