How to translate object by using it's name


(Shaderbytes) #21

Great glad you found your issue. Thanks for the usage which lead to me adding another useful function.


(SRF Studio) #22

Thank you for this great utility, it’s extremely useful and very user-friendly :slight_smile:

Also if anyone else stumbles onto this topic, apart from highly recommending this utility, I would also suggest that, if you use utility, you keep the SketchFab official viewer to version 1.1.0. in your script. The official version 1.2.1. has it’s own ‘click’ that doesn’t distinguish between click, rotate or drag. So if a user is holding down the mouse button in any mode, once the mouse button is released the object behind the cursor will receive a ‘click’ event.

This doesn’t happens with utility. The object will be ‘clicked’ only if it’s clicked, not if rotation or drag ends up on object :+1:

(SRF Studio) #23

I’m so sorry, I seem to be stuck with translate again :frowning_face:

The click-to-translate code is working great for animated & non-animated models alike but I also needed to make objects move without clicking on them so I used a button to try it out. Didn’t get anywhere.

Button is still working great for non-animated objects but it’s doing nothing for animated, rigged models.

These are the code variations I tried and they work but, as I mentioned, only on static objects:

var currentObjectKey = "";
var objectref = sketchfabAPIUtilityInstance.getNodeObject("objectXYZ",null,sketchfabAPIUtilityInstance.nodeTypeMatrixTransform);
currentObjectKey =;
var x = -1;
var y = -0.7;
var z = 1.19;
newPosition = [x,y,z];

…and version that combines utility & api:

var currentObjectKey = "";    
var currentNode;
    sketchfabAPIUtilityInstance.api.getNodeMap( function ( err, nodes ) {        
            for (var id in nodes) {
              currentNode = nodes[id];
              if ( === 'objectXYZ' && currentNode.type === 'MatrixTransform') {
     			currentObjectKey =; } } } );
        var x = -1;
        var y = -0.7;
        var z = 1.19;
        newPosition = [x,y,z];

I know that the objects I’m trying to move with a button can be moved because I was able to move them with your click-to-translate code :frowning_face:

(Shaderbytes) #24

could you send you model id again , and if you have a page with code i can look at? set up a code pen with what you are trying to achieve… that would be the easiest manner to debug it for you

Im not sure what is going on maybe the click version finds a parent matrix transform that is not the name expected, not sure need to investigate the model. Normally in a CG engine you can not move vertices that are bound by bone weights because the vertex position gets calculated every frame and so moving that would just get overridden and you wont see any effect. You need to move a parent container of the said vertices which is not bound to any bone weights to see any effect.

chat soon

(SRF Studio) #25

Thanks for taking a look, again, for the 100th time :slightly_smiling_face:

This is my model for the game that I’m trying to consolidate :no_mouth: It’s going to be iframed onto a game layout in Construct 2. The local storage variables are there for communication between iframe and game. (655.7 KB)

If you don’t want to download zip model link is: 3ec89af998134521842ca3c2c84f7cdb

…I must warn you, if you download zip, that my coding is extremely terrible so keep an open mind :smile:

/////////////// EDIT:
I gave up on rotation of player model so you will see 3 models facing different directions and one with walking animation. Because I decided to keep the share option on each of the levels in game, I left only one player model with 100 opacity for SketchFab version and others will be shown/hidden during the game.

(Shaderbytes) #26

it is as i suspected , the name of the matrix transform moved by the click example is not the same as the group name.

Remember i mentioned earlier that on rigged models thre is a matrix transform and a group with the same name… the matrix transform with the expected name is useless because it has no children. So for rigged models you filter by group. Now take into account what i also said earlier about moving the parent. For rigged models the parent of the expected name group is a matrix transform, but not one with any name you can use… in fact it is un named and will be given some undefined name by the tool. Thankfully you dont have to care what the name is as you can just get a reference to it via the “parent” property my tool generates when it builds the internal storage.

anyway long story short here is an example :

So i list all the groups and then when moving i reference the group parent. if you select a button scroll the buttons to the top and there is a textfield showing the group and matrix transform names used.

here is an inspector for your model , you ccan see the entire scene graph :

(SRF Studio) #27

Thank you, this is much more than I expected, it’s not a reply, it’s really an analysis of a model, objects and it’s structure :open_mouth:

The information you wrote is a bit overwhelming, I did notice, using your other code pen examples, that when I click on object and object moves, the object’s name is different from what I use for show/hide. I suppose that’s the difference between my model’s matrix and group.

For rigged models the parent of the expected name group is a matrix transform, but not one with any name you can use” which explains your code for click-to-move:; So that’s the reason why click-to-move was working? Because when I click on object, the object is not being searched for by it’s group-name but manually being selected by user and then, from there, you parse it’s MT parent’s name?

I’m gonna go try to get my head around the ‘Set Position via button example’ code. I really appreciate all you’ve done.

(Shaderbytes) #28

yup , the click was finding the first parent of type matrix transform , regardless of it name. The click functionality actually does not directly reference the immediate parent , it will transverse the object graph backwards until it finds a parent of the type. Thankfully when inspecting the model i saw the groups immediate parent was a matrix transform and so in my new code example im just referencing the stored parent property of the node ( which is the immediate parent)

Take not this functionality only exists in my utility code the raw api nodes do not store their parents as reference.

So im listing all the groups as buttons and then when they are clicked i get a reference to that group node and then reference its parent, i then move the parent. ( the parent has a undefined name ) This is not your fault but rather just the means in which rigged objects are built internally on sketchfab.

(Jumpjack) #29

How can I apply these methods to model f66ecf2b03b54553a969b4d5aa81d99c ?
It looks like it does not contain “objects” but just “geometries”.
How do I create objects in a model before uploading? I uploaded an .obj file created with Meshmixer.