Can i clone object by api

(Vr Go) #1

as the topic, i wonder can i clone object by api in my frame.
i don’t see any information of it.

(Klaasnienhuis) #2

Hi @vr-go,
it’s currently not possible to make clones of objects through the API. The workaround I’ve used before is to predict the maximum number of objects of a certain kind I’ll need, hide them and then unhide and transform them when needed.
If your objects aren’t too heavy and you don’t need hundreds of them, you should be fine.

(Vr Go) #3

hi, how about clone material,such as i have one Tetragonal with 8 material for each face.
i clone one of them then put it above the tetragonal.

(Klaasnienhuis) #4

I’m afraid cloning materials isn’t possible. You can change materials, but you can’t change material assignments (to which objects a material has been applied) and you can’t create materials with the API.
What you can do is in your 3d software create 8 different materials with meaningful names as placeholders and assign them to the relevant faces. With the API you can then change each material individually.
Make sure the placeholder materials have unique names and preferably one unique property (such as a different diffuse color). Otherwise the compression by sketchfab might decide the materials are the same.
If you have many materials (I believe over 100) sketchfab compression will kick in anyway and merge materials together (@james correct me if I’m wrong here. Not sure of the exact numbers)


Correct; if we detect more than 100 unique materials, we attempt to merge identical materials. If there are still more than 100, we merge everything together into 1 material.

The viewer also merges identical materials at runtime, but not by default in the Viewer API.