Puting a model on a bone

I tried to test the method to attach a model to a bone. First I tried this:

StaticModel@ item = player.model.skeleton.GetBone("Bip01_R_Hand").node.CreateComponent("StaticModel"); if (item.Load(cache.GetFile("Models/longsword.mdl"))) Print("model loaded ok");

The model is beign loaded, but it is not visible. I also tried creating a child noide, and then creating the model component there instead of the bone node, but the result is the same. Whats the correct method to do this?

Use a node for each model and parent them using:

[code]Node@ itn = player.model.skeleton.GetBone(“Bip01_R_Hand”).node.CreateChild(“item”);
itn.parent = player.model.skeleton.GetBone(“Bip01_R_Hand”).node;

StaticModel@ item = itn.CreateComponent("StaticModel");
if (item.Load(cache.GetFile("Models/longsword.mdl")))
  Print("model loaded ok");[/code]

Negative, the model is not displayed. Tried adding position and scale:

    itn.position = Vector3(0,0,0);
    itn.scale = Vector3(0.08,0.08,0.08);

But doesnt works neither.

I’m guessing that you also need to set Material to the StaticModel

Negative. Next guess?

  1. new child node depends on parent scale, maybe you need to make - upscale or downscale your new node for several times to see it.
  2. new node.setEnable(true)
1 Like

Still cant see it.

To get the bone node, you don’t need to access the skeleton, you can use:

Did you check in the Editor the result to help you debug (saving your scene and loading it in the Editor)?

SAved the scene and checked with editor. The child node is created, but the StaticModel component is empty, no mesh is loaded on it.

Create childNode + StaticModel component before parenting to parentNode.

Found the problem.

doesnt works, the correct way is this: