AnimControl – one for many objects

Hey oxplay2. Strange that I wasn’t told about the mention. But anyway, I’ll use an AnimControl for each part. I don’t know whether or not it’s possible to use just one AnimControl since all the different parts will be different models (spatials).



That’s as far as I can help - but I hope someone can help you more. Sorry.

1 Like

@memonick: i afraid i will need to do the same.



every part can be assigned to 2-3 bones, so assign them to one bone will result in ugly animations.



BTW about one bone assign(weapons/shields):

i never assigned object to a bone, if someone could tell me how to exacly do it, it would be greatful.

otherwise, i will look alone.

What do you use? 3DS Max? If yes, I can help. If not, maybe try this: Animation Workflow.pdf - Google Drive



Good luck buddy :slight_smile:

1 Like

thank you



blender

i know how to export

BTW this document is obsolete imo.

Actually this works fine if you attach the AnimControl and the SkeletonControl to the parent node.

The SkeletonControl has an array of target meshes and is able to gather them when you attach it to the parent node.



Sinbad model works like that, it has 7 different geometries working with the same animControl and the same SkeletonControl.

try to transform it to j3o and inspect the model.



From blender it’s pretty easy, your objects only have to share the same armature.

1 Like

nehon:



when i export via ogreMesh, i have many separate models with their own AnimControl.(and it work but only when i have one AnimControl for one element)



When i try to get all Nodes under one AnimControl, then it dont work(i tried in SceneComposer - do i need do it in code?).



Maybe you say about blend2j3o(directly from blender), but i have exception:

java.lang.IllegalStateException: Cannot find track for: belt bone
at com.jme3.scene.plugins.blender.constraints.Constraint.getTrack(Constraint.java:109)

so i will need to remove constrains from skeleton, and see how JMP export it directly from blender.

edit:
and to be clear:
i don't want to have Geometries with one shared AnimControl
i want to have many Nodes(with their Geometries) sharing one AnimControl.
@oxplay2 said:
and to be clear:
i don't want to have Geometries with one shared AnimControl
i want to have many Nodes(with their Geometries) sharing one AnimControl.

oh....why?
1 Like

nehon:



becouse i want to be able for example to “cut arms” / “cut legs” / “cut head” AND sometimes head can have a helmet, or arm can have ring or something. and its not all. arms/head/legs/torso is splitted into 2 materials, where one is texture and second is “flesh”(where flesh material is used for all cutted parts).



i think this 2 main reasons is enough :wink:



edit: there is a good reason too:

its very bad to have 999(example) materials in one blender file with one object. i know i can hide material elements, but its not handy.



i need to have some of heads, some of arms/arm armors, some of torso/armors, some of hairs/helmets, etc…

its very not handy to have it all in one object in blender.



and it’s hard to change parts with working AnimControl in Character Creator i am making.



that is why i need Nodes with their Geometries.

How about using a UEBER shader and a textureatlas + uv mapping in blender?

One material for everythig.

1 Like

there is UV mapping, ofc…

i think textureatlas can’t contain 999(again example) textures…



BTW: then still other reasons are unchanged.

@oxplay2 said:
nehon:

becouse i want to be able for example to "cut arms" / "cut legs" / "cut head" AND sometimes head can have a helmet, or arm can have ring or something. and its not all. arms/head/legs/torso is splitted into 2 materials, where one is texture and second is "flesh"(where flesh material is used for all cutted parts).

i think this 2 main reasons is enough ;)

Actually....what would prevent your to do all of that with geometries only? i mean you can have the character node and all the geometries below it, (head geom, helmet geom, ring geom , w/e geom ...) all attached to the character node...
What makes you think it's gonna be easier if you have nodes?

Really look at Sinbad's model it works just fine and it's built like that.
1 Like

@nehon:



yes, but simbad don’t have multi versions of his hands/armor/head/legs/torso AND i have. he have only one version of hands/head/etc.



if i make as you say, then in blender i will have no possibility of using layers/etc… and it will be hard to modify/add more elements.

Ok i get that you want to switch parts of the model.

So I made a small test case to demonstrate what I mean.

I think you are over complicating something that is already fairly complicated…



[java]

package mygame;



import com.jme3.animation.AnimChannel;

import com.jme3.animation.AnimControl;

import com.jme3.animation.LoopMode;

import com.jme3.animation.SkeletonControl;

import com.jme3.app.SimpleApplication;

import com.jme3.input.KeyInput;

import com.jme3.input.controls.ActionListener;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.scene.Geometry;

import com.jme3.scene.Node;



/**

  • test
  • @author Nehon

    */

    public class Main extends SimpleApplication {



    public static void main(String[] args) {

    Main app = new Main();

    app.start();

    }



    @Override

    public void simpleInitApp() {



    viewPort.setBackgroundColor(ColorRGBA.DarkGray);

    flyCam.setMoveSpeed(100);



    //loading the model

    final Node model = (Node) assetManager.loadModel(“Models/Sinbad/Sinbad.j3o”);

    rootNode.attachChild(model);



    //keeping the pants geometry in a variable

    final Geometry origPants = (Geometry) model.getChild(“Sinbad-geom-7”);



    //creating a clone (just for conveniance of the example, but this can be someting else

    //imported from blender that has bone index and bone weight for this skeleton

    final Geometry newPants = (Geometry) model.getChild(“Sinbad-geom-7”).clone(false);

    //setting a basic lighting material

    newPants.setMaterial(new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”));



    //fetching the skeleton control on the model

    final SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);

    //removing it

    model.removeControl(skeletonControl);



    //removing the original pants from the model

    origPants.removeFromParent();

    //attaching the new pants to the model

    model.attachChild(newPants);



    //re-adding the control so that it gathers the geoms

    model.addControl(skeletonControl);



    //setting an animation to demostrate that the anim is not messed up…

    AnimChannel channel = model.getControl(AnimControl.class).createChannel();

    channel.setAnim(“Dance”);

    channel.setLoopMode(LoopMode.Loop);





    //even adding a key binding to switch pants at runtime

    inputManager.addListener(new ActionListener() {



    public void onAction(String name, boolean isPressed, float tpf) {

    if (name.equals(“switchPants”) && isPressed) {

    model.removeControl(skeletonControl);

    if (origPants.getParent() != null) {

    origPants.removeFromParent();

    model.attachChild(newPants);

    } else {

    newPants.removeFromParent();

    model.attachChild(origPants);

    }

    model.addControl(skeletonControl);

    }

    }

    }, “switchPants”);



    inputManager.addMapping(“switchPants”, new KeyTrigger(KeyInput.KEY_SPACE));



    }



    }



    [/java]



    Screenshot :

    http://i.imgur.com/aHlsX.png

    Now if you want to change the pants with another model, it just have to fit to the same skeleton. So you can have plenty different blender files (one for each armor set for example) has long as you use the same skeleton in those files.
5 Likes

@nehon, performance-wise, is it better to use this method?

indeed it is, why not? it contain much less data, and update loops are merged. even onAnimationCycleDone/etc will no need ingerence since its only one AnimControl.



I really don’t know that it’s so easy.



and indeed, it is good idea. (if there will be not problem in appending/importing skeleton to other blend files).

i hope it’s true it will work for more “sets”.



the problem of 2 materials i will solve by merging flesh texture and element texture.(like Empire Phoenix said)

also i will need to name geometries, but as i good remember: material name → geometry name(so there should not be problem of manual changing names in SceneComposer)



@memonick:

don’t know if you will make one control now, but i think we should really thank nehon guru :slight_smile:

Better than what? having nodes for each part? I think it does not make any difference…

It’s just a lot more convenient and allow you to have only one AniCcontrol



Edit : I was answering to memonick

3 Likes

i just wanted to thank you so much nehon. you shared your time to make solution + example :slight_smile:



edit: even if many AnimControls worked, one AnimControl is much better.

1 Like
@oxplay2 said:
i just wanted to thank you so much nehon. you shared your time to make solution + example :)

You're welcome ;)
1 Like

Yeah – thanks nehon! Will definitely use this.



If I create two different chest armour, I will still have to give it a skeleton, and import the .skeleton.xml file, right?



EDIT: What if I want to attack (animation 1) while running (animation 2)? Wouldn’t I have to have two AnimControls?

AD skeleton:

you use 3D Max? or Blender?

in blender propably it need only Vertex Groups, but its not hard to import skeleton :slight_smile:





AD edit:

you have AnimChannels to split it(it don’t need more animChannels - i tested)



i have actually:

[java] Set<String> torso = new HashSet<String>();

torso.add(“torso”);

Set<String> head = new HashSet<String>();

torso.add(“head”);

Set<String> topBones = new HashSet<String>();

topBones.add(“neck”);

topBones.add(“shoulder_left”);

topBones.add(“arm_left”);

topBones.add(“armend_left”);

topBones.add(“thumb_left”);

topBones.add(“thumbend_left”);

topBones.add(“hand_left”);

topBones.add(“finger_left”);

topBones.add(“shoulder_right”);

topBones.add(“arm_right”);

topBones.add(“armend_right”);

topBones.add(“thumb_right”);

topBones.add(“thumbend_right”);

topBones.add(“hand_right”);

topBones.add(“finger_right”);

Set<String> bottomBones = new HashSet<String>();

bottomBones.add(“Parent”);

bottomBones.add(“belt”);

bottomBones.add(“leg_left”);

bottomBones.add(“leg_right”);

bottomBones.add(“legend_left”);

bottomBones.add(“legend_right”);

bottomBones.add(“feetfront_left”);

bottomBones.add(“feetfront_right”);

bottomBones.add(“feetback_left”);

bottomBones.add(“feetback_right”);

setChannelBones(topBones, 0);

setChannelBones(bottomBones, 1);

setChannelBones(torso, 2);

setChannelBones(head, 3);

setAnim(“idle0”, LoopMode.Loop, 0, idleSpeed, 0);

setAnim(“idle0”, LoopMode.Loop, 1, idleSpeed, 0);

setAnim(“idle0”, LoopMode.Loop, 0, idleSpeed, 0);

setAnim(“idle0”, LoopMode.Loop, 1, idleSpeed, 0);[/java]



each set is other AnimChannel. - and it work perfect.



you can set time(not speed) of animation, so it will be synchronized(when you want change animation to runTop after attackTop and to be synchronized with runBottom) :slight_smile:

1 Like