Archive 19/01/2023.

Puting a model on a bone

rogerdv

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?

Mike

Use a node for each model and parent them using:

rogerdv

[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.

szamq

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

rogerdv

Negative. Next guess?

codingmonkey
  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)
rogerdv

Still cant see it.

Mike

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)?

rogerdv

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

Mike

Create childNode + StaticModel component before parenting to parentNode.

rogerdv

Found the problem.

doesnt works, the correct way is this: