getAttachmentNode() attach multiple spatials to a skeleton

@navycougar said: zarch

yes they work :confused: but i’m not sure if my bone hierarchy is right, or if I really understand what nehon said,

in blender do we have to make 1 .blend with ALL the geometries attached to the rig? or can we use different.blend files?

u’ll find a screen of my screen composer at bottom.

t0neg0d nehon said you can, and I am following what he said:

I think you are misinterpreting what he said.

You are destroying the animation control (containing the animation info). The vertex groups are gone when you do this, reattaching them to the rig in JME will do nothing if the vertex groups are gone.

Actually… I am… not u… but this will not work, because what he said is wrong lol

Seriously… I’m fairly sure this is not possible… unless each of these geometries are only attached to a single bone in the rig:

Maybe @nehon can confirm this?

EDIT: The reason I say this is… a mesh has absolutely ZERO information pertaining to keyframed bone animations associated with it. It knows NOTHING about vertex groups… so if the geom was attached to multiple bones and you destroy the anim control… how could it possibly know what to associate itself with?

@t0neg0d

I Don’t understand what he means for each model Torn it to j3M

someone made it work with @nehon help here is the topic :
http://hub.jmonkeyengine.org/forum/topic/animations-for-same-skeleton-different-objects-blender-question/#post-236738

nehon implies that he made a fix in the nightly build…(i’m using RC2)

@navycougar said: @t0neg0d someone made it work with @nehon help here is the topic : http://hub.jmonkeyengine.org/forum/topic/animations-for-same-skeleton-different-objects-blender-question/#post-236738

nehon implies that he made a fix in the nightly build…(i’m using RC2)

This line from the OP makes me think the clothing is attached to single bones:

“Now I can create a file have single Armature and parent to it the character and all the clothes…”

@t0neg0d said: This line from the OP makes me think the clothing is attached to single bones:

“Now I can create a file have single Armature and parent to it the character and all the clothes…”

but nehon says attach to the root bone :confused:

Um… ok… wait one second… the rig might contain a list of meshes… soooo… have you checked the rig to make sure that removing the geometries didn’t destroy these references (if there are these references)?

@t0neg0d said: Um... ok... wait one second... the rig might contain a list of meshes... soooo... have you checked the rig to make sure that removing the geometries didn't destroy these references (if there are these references)?

well actually there is something weird in what @nehon says, he said :
remove the geometrie and save the file : this is you rig file.

  • export every single model
  • for each model torn it to j3M, remove the AnimControl and SkeletonControl from them and only keep the geoms.

this is the weird part, he says turn the model to j3M? (maybe he means keep only the material)

I don’t see any references in my rig that’s why I started the thread I wish someone could shed light on this ,
:confused: I posted a screenshot of my scene editors with the rig, and my original spatial.

What happens if you combine them in the scene composer and select the anim control then select one of the animations from the drop down?

Does it work there?

@t0neg0d said: What happens if you combine them in the scene composer and select the anim control then select one of the animations from the drop down?

Does it work there?

yeah, well, in order to see the actually generated j3o, I used the binary exporter to save it to a j3o:

[java]
BinaryExporter exporter = BinaryExporter.getInstance();
File file = new File(“C:/game/assets/Models/”+“MyModel.j3o”);
try {
exporter.save(rig, file);
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, “Error: Failed to save game!”, ex);
}
[/java]

and opened the generated file in the scene editor, and the animations don’t work there…
meaning that the references have been lost??

look at the image I posted earlier, I show the result rig

The thing that I found strange is, why would you have to export anything other than the original mesh with the armatures/animations, if you are going to remove this after the fact.

I would think as long as they were attached when the first model was exported, the reference in the rig to that mesh would be there… (I really don’t think these references are store there though). Then you could just export the model - animations and save a TON of time exorting crap you dont need.

Anyways… I hope to god I am wrong. I wanted to do this as well, and couldn’t find a way that worked.

EDIT: I keep looking at the image (I mean I have been multiple times making sure I saw what I thought I saw).

I see the compined output contains the anim control with the two animations listed. But the meshes don’t recognize the rig, because there animation controls were destoryed in the process.

Hopefully @nehon can explain how this can work (if it can)…

@t0neg0d said: The thing that I found strange is, why would you have to export anything other than the original mesh with the armatures/animations, if you are going to remove this after the fact.

I would think as long as they were attached when the first model was exported, the reference in the rig to that mesh would be there… (I really don’t think these references are store there though). Then you could just export the model - animations and save a TON of time exorting crap you dont need.

Anyways… I hope to god I am wrong. I wanted to do this as well, and couldn’t find a way that worked.

EDIT: I keep looking at the image (I mean I have been multiple times making sure I saw what I thought I saw).

I see the compined output contains the anim control with the two animations listed. But the meshes don’t recognize the rig, because there animation controls were destoryed in the process.

Hopefully @nehon can explain how this can work (if it can)…

tonegod, I made it work, by moving the model by hand and saving the generated file again.

so it means that it really works, I rmemeber the other guy said something about resetting the rig in order to make it work, i’ll try that. (but I just made it work by resaving the j3o by hand)

1 Like

Yess i confirm that it works when I move the materials out of those root_attachnode folder and save the j3oby hand

I just combined the hair and the body saved the file by hand and the animation works.

but how to make it work in code???

@navycougar said: tonegod, I made it work, by moving the model by hand and saving the generated file again.

so it means that it really works, I rmemeber the other guy said something about resetting the rig in order to make it work, i’ll try that. (but I just made it work by resaving the j3o by hand)

O.o I am soooo going to have a go at this tomorrow! This has been the biggest bane of my gaming existence.

@navycougar said: Yess i confirm that it works when I move the materials out of those root_attachnode folder and save the j3oby hand

I just combined the hair and the body saved the file by hand and the animation works.

I wonder if it is possible to attach them differently (i.e. by code) That would be ideal, but if this means I can export all my equipment etc without animations… that will be good enough for me.

@t0neg0d

look!

I sabed the generated rig file with binary exporter, in the default setup it doesn’t work, but when I move the material_26 ad material_29 out of the root_attachmentnode folder, and resave the file, my hair and my model start MOVINg! OMG!!!
this proves that the references are still there, its just a matter of updaing the rig…
bbut how to refresh it in code??

the leo used this :

@The Leo said: mehehe thanks, finally got it to working. Inside the SkeletonControl the Mesh[] targets wasnt updated. So in the easiest way i needed to call just about this rig.getControl(SkeletonControl.class).setSpatial(null); rig.getControl(SkeletonControl.class).setSpatial(rig);

Now it works XD

but this doesnt work in my case because I have to move the material_26 and material_29 to the root of the rig…

do you know a way to do that?

There are 2 things to not mistake here.

you can attach a geometry to a bone by getting the attachement node on this bone and attach the geometry to it. The effect is that the geometry’s transforms will “copy” the bone transforms. That’s convenient for a sword attached to a hand or even a helmet to a head.

Now, for parts like legs and chest the rig has to deform the mesh not only transform it.
When you export from ogre a rigged character sub-graph is made of a node on which all the character geometries are attached. The AnimControl and the SkeletonControl are set on the Node and not on the sub geoms.

The skeleton control has to know what geometry to deform, so in RC2 when you set the SkeletonControl to the node (node.addControl(skeletonControl)) the geometries from the node sub graph are recursively gathered.

So in RC2, if you change a sub geometry you have to go
[java]
SkeletonControl ctrl = node.getControl(SkeletonControl.class);
node.removeControl(ctrl);
node.addControl(ctrl);
[/java]
Then the sub geoms will be refreshed.

In 3.0, geoms are refreshed on every frame, so you don’t need this and it just works.

When i said “trun your models to J3M”, I meant J3o yes, that was a mistake.

Hope that’s clear to you, and that I answered all your questions.

1 Like

hello @nehon thanks alot!

I have a question, when I do this :

[java] Spatial male1 = assetManager.loadModel(“Models/Male1/Male1.j3o”);
rig.getControl(SkeletonControl.class).getAttachmentsNode(“root”).attachChild(male1);

SkeletonControl ctrl = rig.getControl(SkeletonControl.class);
rig.removeControl(ctrl);
rig.addControl(ctrl);[/java]

the animations don’t work, because the geometry is added under a folder called root_attachnode,
is there a way to attach the geometry to the rig directly??
when I use getAttachmentsNode(“root”).attachChild, it automatically creates this kind of folder… :frowning:

look at this picture : on the left side the animations don’t work, but on the right they work (the only difference is that I moved them by hand in the scene editor and saved the j3o … :frowning:

Don’t use attachement node at all.
you just need to attach the geometries to the node, then remove and add again the skeleton control.
Attachement node is for another purpose.

1 Like
@nehon said: Don't use attachement node at all. you just need to attach the geometries to the node, then remove and add again the skeleton control. Attachement node is for another purpose.

i’ve got the same problem the geometries are now under a folder called Male1

the result is like this :

  • Male1
    ++Male1
    +++geometry <– i need to move this to the upper +Male1
    ++AnimCOntrol
    ++SkeletonControl

here is the code, I just attached my spatial to the rig like you suggested but the spatial is under a folder called Male1, maybe I don’t know how to retrieve only the geometries part of a spatial :blush:
[java] Node rig = (Node) assetManager.loadModel(“Models/Male1/rig.j3o”);
Spatial male1 = assetManager.loadModel(“Models/Male1/Male1.j3o”);
rig.attachChild(male1);

    SkeletonControl ctrl = rig.getControl(SkeletonControl.class);
    rig.removeControl(ctrl);
    rig.addControl(ctrl);[/java]

OK OK OK!! IT WOKS! OMFG! I’m soo happy THANKS ALOT NEHONN!
ok here is the solution for those who will in the future have the same problem as ME!

   [java] Node rig = (Node) assetManager.loadModel("Models/Male1/rig.j3o");
    Node male1 =  (Node)assetManager.loadModel("Models/Male1/Male1.j3o");
    male1.setMaterial(createPlayerMaterial(assetManager));
    rig.attachChild(male1.getChild(0));  &lt;------ here the magic happens, you just need to retrieve the geometry child of the loaded MESH OMFG!! and attach it to the rig and it works!
   
    SkeletonControl ctrl = rig.getControl(SkeletonControl.class);
    rig.removeControl(ctrl);
    rig.addControl(ctrl);[/java]
1 Like