Manipulate a PolyMesh with a Model in an Asset with the API

I have a project where I am manipulating a complex asset with API calls (translate, scale, etc). The asset has many nulls and polymeshes. The script works as intended in this situation.

Now, I must create a 3D scene with several copies or instantiations of the original asset. I can think of two ways to do this. The dumb way: copy and paste all of the geometry within the same asset several times (this would create a lot of redundant geometry and code). Or, the smart way: instancing. I would rather do it smartly, but I don’t know how to manipulate a polyMesh with a model in an asset with the API. If this is possible, could you give a few pointers?

Here is a highly simplified version of my situation:
Let’s say that we have an asset called “generic_box_and_sphere”

Then we create a new asset and drag the “generic_box_and_sphere” in twice. Now we have an asset with two models. I’ve named and positioned them for clarity.

I want to reach into one of these models and manipulate one of its polymeshes. Let’s say the cube on the nearer model. I can’t get that to work. I can only set transforms on the whole model. Like this:
Screenshot 2023-08-16 161334

So, what is the correct strategy for this, and is it even possible to manipulate instances independently?
Thank you very much.

Hey @jem - I’m going to dig into this more but in the meantime can you try this out:

In your asset with the referenced models, can you run:

api.scene.getAll({from: instanceId, evalNode: true})

and see if this gives you some more details to work with? I have a feeling the node IDs might be tucked away in this object somewhere. Let me know if this does or doesn’t help at all.

Hi Will. Thanks for the quick response.
Your query will get the IDs of models in the asset. See the screenshot below. This is where the difficulty starts. The two instances are solidified “models” rather than a graph of polymeshes at this point, and I don’t see a way of manipulating those underlying polymeshes (and nulls).

The ids of the two models are highlighted in yellow. The id of the parent asset is in green. I expanded one of the models to show some detail. It has no child meshes to manipulate.

Thanks again.

Sorry @jem - I should have added a bit more clarity to my post! I set up an example similar to yours, I am reference an asset (cube base, sphere topper) two times in a standalone asset:

I will run

api.scene.getAll({from: instanceId, evalNode: true})

Notice that child object in our responses called sceneGraphnodes this is where the juice is.

With this information, you should be able to do exactly what you want (if I’m understanding correctly).

   from: instanceId, 
   id: "3688fa2a-9f9d-47d3-bb4b-872f88a45d14",  // ID of the node I want to adjust
   plug:  "Transform", 
   property: "scale"
   x: 1, 
   y: 1, 
   z: 2

Should get you something like this:

Can you let me know if this gets you where you need to be?

Yes. This is what I was looking for!
My mistake was that I was looking under the models for each of their scene graphs. There is no scene graph under a model. The graph is a child of the top-level asset. I was looking in the wrong place.
I should be able to make this all work now. Thank you very much!

1 Like