How to properly attach mesh into specific bones?

Blitz3D Forums/Blitz3D Programming/How to properly attach mesh into specific bones?

RustyKristi(Posted 2016) [#1]
I have 2 similar armature but different meshes and slightly differ in size. Attaching a mesh (ie a gun) in the hand should be easy with other engines but I'm having trouble with b3d. Maybe I'm not doing this properly?

What I'm doing is findchild the bone and entityparent the mesh to it. When I tweak the position and rotations, it only applies to a specifice mesh even though they have the same armature.


RemiD(Posted 2016) [#2]
Yes, i already did that several times :
RHandJoint = findchild(RiggedMesh,"RHand")
;position oriente the weapon like the joint :
PositionEntity(Weapon,entityx(RHandJoint,true),entityy(RHandJoint,true),entityz(RHandJoint,true),true)
RotateEntity(Weapon,entitypitch(RHandJoint,true),entityyaw(RHandJoint,true),entityroll(RHandJoint,true),true)
;tweak the position/orientation of the weapon :
MoveEntity(Weapon,0,0,0)
TurnEntity(Weapon,0,0,0)
;set the weapon as a child of the joint
EntityParent(Weapon,RHandJoint,true)


note that the weapon mesh must be positionned/oriented correctly (related to the origine/root) in your modeling program (in this case the origine/root should be near the handle of the weapon)


Bobysait(Posted 2016) [#3]
Blitz3d does not do the same thing as 3dsmax, because it doesn't use reference, but instanciation for bones.

A Copy will :
- instanciate the hierarchy (the entities)
- reference the inner material (animation, surfaces, brushes, bone handler)
A reference is just a pointer to the original source, so anything you happen on the source will happen on the copy
An instance is a replicant of the source, it owns its very unique stuff (for an entity, it has its own matrix and its own hierarchy)

The bone handler contains the bone informations (the "real" bones, not the entity that you can access via GetChild/FindChild)
The Bone (as entity) is just an entity (like a pivot), it doesn't contain any information related to the animation
-> only the root (the one you use "Animate" on) contains such infos in the bone/animation handler


So, you can't affect the position of anything you parented to a copy by modifying its alias in the source because they are totally different objects (entities) with their own matrix.

All you can do is use a dummy in your modelisation software to mark the position and rotation for your weapon (definitely)
Once loaded in blitz3d, attach the weapon to this dummy.
You won't be able to modify all copies of your model for the reasons specified above, but at least you can manipulate the dummy in your modelisation software so you don't have to repeat the operation any time you copy a hierarchy.

But, keep in mind this is only happening if you actually use "CopyEntity" (and then happen the small scale modifications)
If what you do is "LoadAnimMesh" anytime you want a "copy", what you do is create a full standalone hierarchy that is fully unrelated to an other, whether or not its hierarchy is the same in the file. (just like a car industry -> all the cars are the same, but they are all unique, they come from the same file, but in the end, if you paint one car, others won't be painted)


RustyKristi(Posted 2016) [#4]
note that the weapon mesh must be positionned/oriented correctly (related to the origine/root) in your modeling program (in this case the origine/root should be near the handle of the weapon)



Ok so I cannot reference and parent it to the bone, only the animesh origin?

@Bobysait

Interesting approach but I'm confused what to use because you are comparing them.

So do I use CopyEntity on LoadAnimMesh?

I have tried adding a dummy or bone with the exact position as the nearest bone, I'm still getting the same result. Do I have to use a dummy or like an empty pivot and not a bone? I'm using Fragmotion btw.


Bobysait(Posted 2016) [#5]
Add a dummy in your modelisation software (let's call it "dummy_weapon"

In blitz3D, use LoadAniMesh Once for the file, then hide it !
Local REF_Character = LoadAnimMesh("MyFile.b3d")
    HideEntity REF_Character
Local REF_Weapon = LoadMesh("Gun.b3d")
    HideEntity REF_Weapon


use CopyEntity for copies and attach weapons to the dummies
Local ent1 = CopyEntity(REF_Character)
Local weapon1 = CopyEntity(REF_Weapon, FindChild(ent1, "dummy_weapon"))
Local ent2 = CopyEntity(REF_Character)
Local weapon2 = CopyEntity(REF_Weapon, FindChild(ent2, "dummy_weapon"))
Local ent3 = CopyEntity(REF_Character)
Local weapon3 = CopyEntity(REF_Weapon, FindChild(ent3, "dummy_weapon"))


or ... if you want all copies to have the same weapon :
Local REF_Character = LoadAnimMesh("MyFile.b3d")
    HideEntity REF_Character
Local REF_Weapon = LoadMesh("Gun.b3d")
    HideEntity REF_Weapon
    ParentEntity REF_Weapon, FindChild(REF_Character,"dummy_weapon") ; attach the weapon to the reference dummy


Local ent1 = CopyEntity(REF_Character)
Local ent2 = CopyEntity(REF_Character)
Local ent3 = CopyEntity(REF_Character)

No need to copy the weapon, it's already copied from the reference.


And, anyway, I repeat : this won't let you modify the position/rotation of the dummy in blitz3d for all copies, you'll have to tweak them once at a time, here I just show you how to have them all already positioned/oriented without the need to do it in the code.


RustyKristi(Posted 2016) [#6]
Thanks! I will try it asap and post my results.


RemiD(Posted 2016) [#7]

Ok so I cannot reference and parent it to the bone, only the animesh origin?


It depends on the approach you choose...

Personally i have one rigged skinned mesh for each character (the hairs/clothes/armors are skinned too) and one not rigged not skinned mesh for each weapon
So these are separate meshes and the weapon has no joint (bone) and its vertices are not skinnedvertices

But you could have a weapon with a joint (bone) and skinned vertices (influences/weights of the joint (bone) over the vertices of the weapon) and then, when you attach the joint (bone) of the weapon to the joint (bone) of the hand, it should work...


RustyKristi(Posted 2016) [#8]
Thank you guys both! I will try anything as this has been bugging me for some time now :/


RustyKristi(Posted 2016) [#9]
@RemiD

I see in your sample code that you use global like in EntityX() etc, which is not the default. Could this possibly be the missing step as to why I'm getting those issues?


RemiD(Posted 2016) [#10]

that you use global like in EntityX() etc, which is not the default


@RustyKristi>>
yes you can notice this in my codes because i prefer to always be sure how the entity will be positionned/oriented in the 3dworld

also take a look at the entityparent() true or false differences


RustyKristi(Posted 2016) [#11]
Ok thanks. I will also try a solo test with just the 2 mesh and the attachment and apply this global flag.