www.jpct.net

Bones - Skeletal and Pose Animations for jPCT/jPCT-AE => Bones => Topic started by: aeroxr1 on June 05, 2014, 10:14:22 pm

Title: Animate rigged model according to given commands
Post by: aeroxr1 on June 05, 2014, 10:14:22 pm
Hello to everyone :)
I'm trying to animate a human's rigged model for an Android Application ( Real-time Motion Capture ).
Is possible to do this using jPCT-AE and Bones ?
Something like this https://www.youtube.com/watch?v=NYT-nx533nM

I have the library that gives me the position of the sensor in a quaternion.
I thought to set the quaternion on the relative bones.
But I don't know which function I have to use to identify bones and joints of my rigged model and which function I have to use to set its position in quaternion format.

Have you any suggestion for me ? 

Thanks all :)
Title: Re: Animate rigged model according to given commands
Post by: raft on June 06, 2014, 10:02:37 am
yes, sure it's possible. you have to set position/rotation of joints of skeleton. that is done via SkeletonPose. as its name suggests it's a pose of Skeleton. later that pose is applied to target object's mesh via Animated3D.applySkeletonPose().

have a look at ProceduralAnimationSample which programatically changes SkeletonPose and applies it.

however, calculating poses based on some input is not trivial and to tell the truth i'm not fluent with writing equations for it.
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on June 06, 2014, 11:15:38 am
Thank you so much :)

I'll download jpct-ae and bones and I'll look the proceduralanimationsample :)
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on June 12, 2014, 09:36:00 pm
Sorry,
I downloaded bones-android-ninja, I imported it in eclipse , but
5 errors appeared :

Code: [Select]
import raft.jpct.bones.Animated3D;
import raft.jpct.bones.AnimatedGroup;
import raft.jpct.bones.BonesIO;
import raft.jpct.bones.SkeletonPose;
import raft.jpct.bones.SkinClip;

(import raft cannot be resolved)

And I have another question :

bones is included in jpct-ae ?
or I have to import some library ? I ask that because I'm downloaded jpct and bone , but I don't find bones's libs :/
Title: Re: Animate rigged model according to given commands
Post by: raft on June 13, 2014, 08:43:35 am
Bones is not included in ninja demo app. you should download it separately and import to Eclipse. by default, Ninja demo app looks for Bones project in its classpath.

for your own projects, either add Bones the same way to your classpath or add its jar, which is in Bones/build directory.

Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on June 13, 2014, 09:11:48 pm
I don't find its jar :/
Title: Re: Animate rigged model according to given commands
Post by: raft on June 13, 2014, 09:33:59 pm
it is in Bones.zip/build directory
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on June 13, 2014, 09:43:31 pm
sorry i'm burned out  :'(

(tired and stupid -.-")

Before to read your post I compiled and built all files included in Bone.zip ahahah
Title: Re: Animate rigged model according to given commands
Post by: raft on June 13, 2014, 09:44:49 pm
np ;)
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on August 19, 2014, 02:47:11 pm
can you suggest me a rigged model that is easy to export to bones ?
I downloaded this model http://www.blendswap.com/blends/view/21948 (http://www.blendswap.com/blends/view/21948) and I'm trying to follow this tutorial http://www.jpct.net/wiki/index.php/Exporting_from_Blender_to_Bones (http://www.jpct.net/wiki/index.php/Exporting_from_Blender_to_Bones) to export in bones format, but for now I'm failing  :'(
Title: Re: Animate rigged model according to given commands
Post by: raft on August 19, 2014, 03:06:01 pm
not really, sorry :/ i've never exported from Blender myself. maybe contacting a Blender user may help?
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on August 19, 2014, 03:34:35 pm
Which extension of model do you usually use ?
Title: Re: Animate rigged model according to given commands
Post by: raft on August 19, 2014, 03:49:31 pm
in the past i've used 3dsMax + OgreMax exporter to export to Ogre3D format. it was quite stable and usable. AFAIK there is an OgreMax for Maya too.
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on August 19, 2014, 08:01:26 pm
I want to develop Android app but if I want to see if the conversion is done well can I import bones project in eclipse and use LoadBonesFormatSample ?

I did :
1- exported from blender to collada
2- used collada script exporter (in rotation what I have to put ? O.o )
3- I changed the LoadBonesFormatSample's code line from
Code: [Select]
FileInputStream fis = new FileInputStream("./samples/data/ninja/ninja.group.bones");to
Code: [Select]
FileInputStream fis = new FileInputStream("./samples/data/ninja/scheletro.group.bones");4- imported all the folder in eclipse and run LoadBonesFormatSample

But sadly It doesn't work, I see only one ninja's leg -.-" During the conversion the warning say me "WARNING : max of 4 joints .."

last question : when I export in ogree different files are being created , but how I have to use jmeOgre2Bones ?

For example in the last conversion I had this file :
- Sphere.000.mesh
- Sphere.000.mesh.xml
-Sphere.004.mesh
-Sphere.004.mesh.xml
-Sphere.004.skeleton
-Sphere.004.skeleton.xml

p.s : now I'm downloading 3dmax student version .. I have to find the way to import a rigged model in bones :(
Title: Re: Animate rigged model according to given commands
Post by: raft on August 20, 2014, 09:41:08 am
1- exported from blender to collada
why not export to Ogre format as mentioned in wiki page? i found Ogre a much usable format
2- used collada script exporter (in rotation what I have to put ? O.o )
Code: [Select]
-rotation x180

last question : when I export in ogree different files are being created , but how I have to use jmeOgre2Bones ?
Code: [Select]
jmeOgre2Bones -rotation x180 -out sphere.group.bones -in Sphere.000.mesh.xml
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on August 20, 2014, 03:54:56 pm
i'm trying to export this :
http://www.turbosquid.com/FullPreview/Index.cfm/ID/535459 (http://www.turbosquid.com/FullPreview/Index.cfm/ID/535459)

the export generated seems ok infact has generated stacy.group.bones.
After I put the generated file into C:\Bones\samples\data\ninja, I edit the line codes but the java compiler says me that he doesn't found Cube.group.bones -.-"

 :o
Title: Re: Animate rigged model according to given commands
Post by: raft on August 20, 2014, 04:02:58 pm
is it the compiler or do you get an error at runtime? it's possibly caused by a typo
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on August 20, 2014, 04:35:54 pm
Code: [Select]
Exception in thread "main" java.io.FileNotFoundException: .\samples\data\ninja\stacy.group.bones (Impossibile trovare il file specificato)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at bones.samples.LoadBonesFormatSample.loadNinja(LoadBonesFormatSample.java:46)
at bones.samples.LoadBonesFormatSample.createAnimatedGroup(LoadBonesFormatSample.java:42)
at bones.samples.AbstractSkinSample.initialize(AbstractSkinSample.java:79)
at bones.samples.LoadBonesFormatSample.initialize(LoadBonesFormatSample.java:85)
at bones.samples.AbstractSample.loop(AbstractSample.java:91)
at bones.samples.LoadBonesFormatSample.main(LoadBonesFormatSample.java:97)


 :)

In this rar file there are the ogre's resulting files :
https://mega.co.nz/#!Hc1GmLKB!xMFyrr3cenXpBsPxyy7oj_0uUrLqQG3QAlldN4mla-I (https://mega.co.nz/#!Hc1GmLKB!xMFyrr3cenXpBsPxyy7oj_0uUrLqQG3QAlldN4mla-I)
Title: Re: Animate rigged model according to given commands
Post by: raft on August 20, 2014, 04:47:06 pm
is it stacy.group.bones or Cube.group.bones? ;)
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on August 20, 2014, 05:07:04 pm
Stacy stacy :D

I tryed to use OgreSample but there is the same error :(
I tryed to use OgreMaxViewer and it correctly loads the model  :o

Now I want to try to use 3dmax 2015. You have a model to suggest me that you know that it works ? :)

thanks to everythings :)

In this archive https://mega.co.nz/#!Hc1GmLKB!xMFyrr3cenXpBsPxyy7oj_0uUrLqQG3QAlldN4mla-I (https://mega.co.nz/#!Hc1GmLKB!xMFyrr3cenXpBsPxyy7oj_0uUrLqQG3QAlldN4mla-I) there are this files :
- ogre file
- bones file
Title: Re: Animate rigged model according to given commands
Post by: raft on August 21, 2014, 08:43:06 am
as i said in your other post, the exception is clear, java io cannot find your file. double check file name and location.
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on August 21, 2014, 11:46:10 am
Thanks :)
I have put the stacy.bones.group in the ninja's folder, but java finds ninja's files and not stacy's files ...  ;) :)
Title: Re: Animate rigged model according to given commands
Post by: raft on August 21, 2014, 12:55:13 pm
maybe java cannaot read because of file permissions? btw java file names are case sensitive
Title: Re: Animate rigged model according to given commands
Post by: AGP on August 21, 2014, 01:50:22 pm
I think that your problem is that you're not exporting XMLs. If you can open the file with the OgreMax Viewer, you're probably just exporting the binary version of the file. Go to OgreMax's scene settings and click on "Export XML".

To answer your PM, most rigged models work fine. When they don't, I usually complain here (I have found Derek, the creator of OgreMax, to be less than helpful). Hope this solves your problem.
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on August 21, 2014, 04:05:19 pm
THanks :)
For now I  always used blender and for exporting use this : https://code.google.com/p/blender2ogre/  (https://code.google.com/p/blender2ogre/) .

If you tell me that also you (as raft) use 3dmax , I will try to use 3dmax :)

p.s : During the installation of ogreMaxSceneexporter the software ask me to select or ogre 1.8.x or ogre 1.7.x , I selected 1.8 . I did well ? ( I suppose yes :D )

EDIT :
http://www.ogremax.com/Documents/OgreMaxSceneExporter-3DSMax/scene-settings-dialog-page-meshes.html (http://www.ogremax.com/Documents/OgreMaxSceneExporter-3DSMax/scene-settings-dialog-page-meshes.html)

I have selected export xml files, are there any options that I have to select or to edit ? 

Now jmeOgre2Bones give me this error :
Code: [Select]
C:\Bones\scripts>jmeOgre2Bones -rotation x180 -out vincent.bones.group -in vince
nt_Mesh.mesh.xml

C:\Bones\scripts>echo off
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
ago 21, 2014 6:19:46 PM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized
Exception in thread "main" java.lang.IllegalArgumentException: No controller fou
nd in OgreEntityNode. Means there is no skeleton or pose animation!
        at raft.jpct.bones.BonesImporter.importOgre(BonesImporter.java:135)
        at raft.jpct.bones.util.JMEOgreImporter.loadGroup(JMEOgreImporter.java:1
12)
        at raft.jpct.bones.util.JMEOgreImporter.loadGroup(JMEOgreImporter.java:8
8)
        at raft.jpct.bones.util.JMEOgreImporter.run(JMEOgreImporter.java:69)
        at raft.jpct.bones.util.JMEOgreImporter.main(JMEOgreImporter.java:170)

-.-"

 :'(

This is the model that I'm trying to export :) 
https://mega.co.nz/#!LY1lSKaT!D5uHWcQunQcstXDhrZ1bgHkQycjjrXKOxZBW2RDLEWo (https://mega.co.nz/#!LY1lSKaT!D5uHWcQunQcstXDhrZ1bgHkQycjjrXKOxZBW2RDLEWo)
Title: Re: Animate rigged model according to given commands
Post by: AGP on August 21, 2014, 06:37:18 pm
1.8 works. I've never seen a difference (although, since the Ogre format changed last year, there may well be one). Go with 1.8 to avoid confusion. And  http://tf3dm.com/3d-model/robocop-52409.html is an example of a model that probably works. This site has a whole lot of free game models (though you won't be able to use them commercially because they tend to be stolen from existing games). I haven't tried the linked model because usually I only use Character Studio rigs (in order to be able to use the Mixer). But you can try the models on that site. I'm sure that most of them (get the .daes, not the OBJs, obviously) will be usable.

That's the only setting that you need to change for Scene. Now select your character and go to "Object Settings." Under "Mesh Animations," add your animations. Then, export scene (and be sure to select ".mesh"). Voil.
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on August 21, 2014, 06:50:28 pm
AH ok,
now i'm trying to export this :
https://mega.co.nz/#!LY1lSKaT!D5uHWcQunQcstXDhrZ1bgHkQycjjrXKOxZBW2RDLEWo (https://mega.co.nz/#!LY1lSKaT!D5uHWcQunQcstXDhrZ1bgHkQycjjrXKOxZBW2RDLEWo)

And the jmeogre2bones give me some errors that I wrote in precedent post , but I think there were errors because I selected .scene file !

Now I'm retrying :D

Thanks :)

Title: Re: Animate rigged model according to given commands
Post by: AGP on August 21, 2014, 07:03:29 pm
If you have no animations listed under "Object Settings>Mesh Animations" there won't be a skeleton (or there will, but it won't describe any animations) and Bones won't load your model.

Personally, I think that it should load any model with a .seleton.xml file, whether or not there are animations, so that you could animate your models programmatically...
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on August 21, 2014, 07:20:16 pm
In my project I want to animate programmatically my model .
But If I want to use my model in bones and animate it after by code programming what I have to do ?
Infact the model that I try to export has not animation :/ It's only rigged..

What I have to do to export it in bones and use it  ???

I generated ogre files, but if I use jmeogre2bones gives me the posted error. Can I import the model in bones without the conversion ogre to bones ?

Title: Re: Animate rigged model according to given commands
Post by: AGP on August 21, 2014, 07:24:55 pm
You have to put an animation in. You don't have to use it, though.
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on August 21, 2014, 07:32:52 pm
The conversion is done. Now I try to put it in LoadBonesFormatSample :)
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on August 21, 2014, 07:51:19 pm
THANKS TO EVERYONE :)

Now it work  ;)
Skeleton is correctly loaded :)
I also have finded the errors that I did with blender -.-""" It's my fault and not exporter's fault  ::)
I had added the .bones file in wrong folder because eclipse had copied all the bones folder in its workspace  :-[
I'm very stupid .. sorry -.-"
I have an other question , my model has .tga texture. I try to import it by editing this following code lines :

Code: [Select]
Texture texture = new Texture("./samples/data/ninja/Vincent_new_UV.tga");
TextureManager.getInstance().addTexture("ninja", texture);

for (Animated3D o : skinnedGroup) {
o.setTexture("ninja");
o.build();
o.discardMeshData();
}

but it not works. There are some rules to set the texture ? dimension , extension ecc ecc ? :)
Title: Re: Animate rigged model according to given commands
Post by: AGP on August 21, 2014, 08:00:14 pm
It will only open a format that Java opens. Export your texture as a PNG. That's the best format for it (and the file will be smaller, to boot).
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on August 21, 2014, 08:07:18 pm
THANKS !!!!

it works !!!!!!!!  ;D
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 02, 2014, 03:49:58 pm
If you have no animations listed under "Object Settings>Mesh Animations" there won't be a skeleton (or there will, but it won't describe any animations) and Bones won't load your model.

Personally, I think that it should load any model with a .seleton.xml file, whether or not there are animations, so that you could animate your models programmatically...

Hi it's me again :)
I correctly exported the 3ds rigged model to bones format , but now I want to programmatically animate it.
Which bones's functions do I have to look at ?
Which are the steps that I have to follow ?
( I have to move the leg of the human model )
Title: Re: Animate rigged model according to given commands
Post by: raft on September 02, 2014, 03:55:20 pm
have a look at ProceduralAnimationSample. it does something similar
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 02, 2014, 04:12:29 pm
yes but in procedural example it imports collada model while I have model in bones format .
If I import the file .bones, the bones and joints are automattically imported ?
If I want to refer to determinated joint or bone what do I have to do ?

Title: Re: Animate rigged model according to given commands
Post by: raft on September 02, 2014, 04:21:03 pm
either way they are converted into same java objects :)

you can find a joint by index (if you now) or by name (again if you now)

Code: [Select]
Skeleton.getJoint(int)
Skeleton.findJointByName(String)
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 02, 2014, 04:47:32 pm
I use this function to load my models :
Code: [Select]
private AnimatedGroup loadNinja() throws Exception {
FileInputStream fis = new FileInputStream("./samples/data/ninja/vincent.group.bones");
try {
AnimatedGroup skinnedGroup = BonesIO.loadGroup(fis);

Texture texture = new Texture("./samples/data/ninja/Vincent_new_UV.png");
TextureManager.getInstance().addTexture("ninja", texture);

for (Animated3D o : skinnedGroup) {
o.setTexture("ninja");
o.build();
o.discardMeshData();
}
return skinnedGroup;
} finally {
fis.close();
}
}

After I have imported it, do I have to use this following functions to refer to index ?

Code: [Select]
SkeletonPose currentPose=animatedGroup.get(0).getSkeletonPose();
currentPose.getSkeleton().getJoint(index);
Title: Re: Animate rigged model according to given commands
Post by: raft on September 02, 2014, 04:53:19 pm
yes, that's one way of accesing the skeleton. you can also access it by:

Code: [Select]
Animated3D.getSkeleton
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 02, 2014, 06:35:15 pm
thanks :D
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 03, 2014, 02:56:33 pm
Another question  ;D

Where I have to put the .bones file in an Android project ?

In the asset folder right ? :)
Title: Re: Animate rigged model according to given commands
Post by: raft on September 03, 2014, 03:08:10 pm
i prefer putting them into /res/raw folder
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 03, 2014, 03:23:26 pm
and you refer to it using R.raw.yourfile . Perfect :)
Title: Re: Animate rigged model according to given commands
Post by: raft on September 03, 2014, 03:24:38 pm
yes, right :)
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 03, 2014, 05:51:40 pm
Where do you suggest to create the model ?

in the onSurfaceCreated function ? Or is better if I create the model in an other function ? :)
Title: Re: Animate rigged model according to given commands
Post by: raft on September 03, 2014, 06:13:50 pm
doesnt really matter at this stage of the project. you can load them in any thread and anytime
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 03, 2014, 07:32:57 pm
 8)
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 04, 2014, 08:10:12 pm
Hi :)
why I have to put the bones file in the animatedgroup and not in animate3d ?

(i watched ninja bones android demo)

Quote
masterNinja = BonesIO.loadGroup(res.openRawResource(R.raw.ninja));

And why the texture is applicate in this for function ?
Code: [Select]
for (Animated3D a : masterNinja)
a.setTexture("ninja");

If I have only one bones file with only one 3d model , do I have to do  same thing ?
Title: Re: Animate rigged model according to given commands
Post by: raft on September 05, 2014, 10:08:25 am
yes, you should do the same thing.

if you will always have one object in your group, you can use BonesIO methods to save a single object. but personally I dont see any point in that
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 05, 2014, 07:17:59 pm
I set the camera in this way :

Code: [Select]
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
cam.lookAt(new SimpleVector(0, -box_h/2, box_h));

protected float[] calcBoundingBox() {
float[] box = null;

for (Animated3D skin : modello) {
float[] skinBB = skin.getMesh().getBoundingBox();

if (box == null) {
box = skinBB;
} else {
// x
box[0] = Math.min(box[0], skinBB[0]);
box[1] = Math.max(box[1], skinBB[1]);
// y
box[2] = Math.min(box[2], skinBB[2]);
box[3] = Math.max(box[3], skinBB[3]);
// z
box[4] = Math.min(box[4], skinBB[4]);
box[5] = Math.max(box[5], skinBB[5]);
}
}
return box;
}

and the result is :
(http://imagizer.imageshack.us/v2/150x100q90/910/LNhpJA.png) (http://imageshack.com/f/paLNhpJAp)

it isn't as I wanted  :(

I would set the camera in front of the model :( Where did I wrong ?

And I have seen helloworld and other jpct-ae's examples and in all of those the world is created in onSurfaceChange; it works but how ? Does Onsurfacechange runs only when the display is rotated ?

And another things, is there a function to scale the model in landscape mode ? I mean when I rotate the display from portrait to landscape mode the human model has to become little :D
Title: Re: Animate rigged model according to given commands
Post by: raft on September 06, 2014, 06:51:53 pm
just move the camera to other part of model. or rotate the model.

you can move camera closer to make the model look bigger. or you can scale the model.

onSurfaceChanged is called every time the surface is created. just read the docs:)
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 06, 2014, 08:38:59 pm
just move the camera to other part of model. or rotate the model.

you can move camera closer to make the model look bigger. or you can scale the model.

onSurfaceChanged is called every time the surface is created. just read the docs:)


Quote
Called when the surface changed size.

Called after the surface is created and whenever the OpenGL ES surface size changes.

Typically you will set your viewport here. If your camera is fixed then you could also set your projection matrix here

I didn't see this line -.-"""" sorry  ::)

Another stupid question :
when I import a new model, in what position will be place ? 0,0,0 ? :D
I imagine is very stupid question, but I know little of 3d graphics -.-"


Title: Re: Animate rigged model according to given commands
Post by: raft on September 06, 2014, 08:43:10 pm
yes, it will be in origin (0,0,0) in world space.

but that does not necessarily means you will see your model in origin. that depends on the model position when it's exported
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 06, 2014, 09:45:21 pm
All the object after the inserting is positionated in 0,0,0 ?

For example when I use getcamera() the camera initially is in 0,0,0 ?

I try to ask :D :
Is there an example where the model is scaled when the smartphone is rotated from portrait to landscape view ? :D

Now I'm trying to experiment with direction,simplevector and rotation matrix  ;D
Title: Re: Animate rigged model according to given commands
Post by: raft on September 06, 2014, 09:51:40 pm
yes everything is initially at origin until you move them to somewhere

Is there an example where the model is scaled when the smartphone is rotated from portrait to landscape view ? :D

possibly there is somewhere in the forum. just try different scaling values.

it's also possible to make the model occupy same height of the screen by adjusting camera distance. have a look at AbstractSkinSample.autoAdjustCamera method
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 07, 2014, 09:45:18 am
off-topic : bones's website is down
Title: Re: Animate rigged model according to given commands
Post by: raft on September 07, 2014, 11:47:26 am
yes, i know, thx. my hosting company says my server is DDOS attacked ???
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 07, 2014, 01:12:46 pm
Do Hacker wants to obtain your private images ? xD
Now I'm trying to understand the rotation matrix to applied it to the arms , I want they lies along the body :)
( I want to set the position of model's arms via programmatically )
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 08, 2014, 08:08:42 pm
I searched into the web, but I didn't found an explanation of the use of matrix bindpose , matrix inverse bind pose and the relation between them.

EDIT : I found this explanation http://www.gamedev.net/topic/571044-skeletal-animation-bonespace/ . It is wrong ?

But remain this doubts :

Code: [Select]
        final Matrix jointInverseBindPose = pose.getSkeleton().getJoint(jointIndex).getInverseBindPose();
        final Matrix jointBindPose = jointInverseBindPose.invert();

jointInverseBindPose ok, now , maybe I understand whats is it.
But why do we do this :
Code: [Select]
jointBindPose =  jointBindPose = jointInverseBindPose.invert(); ?
in the precedent link this thing there isn't .. :(


Other parts of code that I don't really understand are :
Code: [Select]
        // Get a vector representing forward direction in neck space, use inverse to take from world -> neck space.
        SimpleVector forwardDirection = new SimpleVector(bindPoseDirection);
        forwardDirection.rotate(jointInverseBindPose);

        // Get a vector representing a direction to target point in neck space.
        SimpleVector targetDirection = targetPos.calcSub(pose.getGlobal(jointIndex).getTranslation()).normalize();
        targetDirection.rotate(jointInverseBindPose);


in particular why do we use jointinversebindpose to rotate the forwarDirection and the targetdirection ? to take from world to neck space don't we need to multiply vector to jointinversebindpose ?

And I don't understand this :
Code: [Select]
pose.getGlobal(jointIndex).getTranslation()
Can you give me a hand ?
Title: Re: Animate rigged model according to given commands
Post by: raft on September 09, 2014, 09:29:20 am
well, to tell the truth I'm not proficient in those calculations too :-[

a few points:

* each joint's transform is in its parent's space.
* as the name suggests invertBindPose is the invert of bindPose of joint. we use it in calculations, so instead of inverting bindPose each time, we keep a reference to its invert.

have a look at SkeletonPose updateTransforms and setToBindPose methods, they may give some clue.
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 09, 2014, 04:03:05 pm
Code: [Select]
private void targetJoint(SkeletonPose pose, int jointIndex, SimpleVector bindPoseDirection,
    SimpleVector targetPos, final float targetStrength) {
   
        final int parentIndex = pose.getSkeleton().getJoint(jointIndex).getParentIndex();

        // neckBindGlobalTransform is the neck bone -> model space transform. essentially, it is the world transform of
        // the neck bone in bind pose.
   1-     final Matrix jointInverseBindPose = pose.getSkeleton().getJoint(jointIndex).getInverseBindPose();
        final Matrix jointBindPose = jointInverseBindPose.invert();

      .........................
       
        // now remove the global/world transform of the neck's parent bone, leaving us with just the local transform of
        // neck + rotation.
        subGlobal.matMul(jointBindPose);
     2-   subGlobal.matMul(pose.getSkeleton().getJoint(parentIndex).getInverseBindPose());

      .........................
    }

But the inverseBindPose matrix is not the same for all the bones ?

In 2 can I use the inverseBindPose calculated in 1 ? No ? why ?

Title: Re: Animate rigged model according to given commands
Post by: raft on September 09, 2014, 04:23:03 pm
But the inverseBindPose matrix is not the same for all the bones ?
of course not, why should it be?
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 09, 2014, 05:30:51 pm
Boh, I thought I read this  :-[

I'm trying to positionate the left arm close to the model's body but I can't :(

This is the code that I used :

Code: [Select]
Logger.log("rotazione");
Tpose = modello.get(0).getSkeletonPose();
Tpose.setToBindPose(); //setto la posa iniziale del modello
final Joint LUpperArm  = Tpose.getSkeleton().getJoint(17);
final Joint parentJoint = Tpose.getSkeleton().getJoint(LUpperArm.getParentIndex());
skeletonDebugger=new SkeletonDebugger(Tpose);
skeletonDebugger.addToWorld(world);
rotation=new Matrix(LUpperArm.getBindPose());
rotation.rotateX(90); //ruoto il braccio dalla bindPose di 90gradi
rotation.matMul(parentJoint.getInverseBindPose());
        Tpose.getLocal(17).setTo(rotation);
        Tpose.updateTransforms();
        skeletonDebugger.update(Tpose);
        modello.applySkeletonPose();
        modello.applyAnimation();

What did I do wrong ?

I have this problems because I don't know the math behind bind matrices,inverse bind matrices and local trasformation ecc ecc :( Could you suggest me some guides ?

Title: Re: Animate rigged model according to given commands
Post by: raft on September 09, 2014, 06:45:07 pm
well, not really sorry. as i said i'm not proficient in those calculations. i never did such kinnd of programatic positioning before.
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 09, 2014, 09:17:17 pm
thanks anyway  :)
Title: Re: Animate rigged model according to given commands
Post by: EgonOlsen on September 10, 2014, 08:19:10 am
I'm not sure about this either, but this is obviously wrong:

Code: [Select]
rotation.rotateX(90);

All methods in jPCT that want an angle use radians, not degrees. I should make this more clear in the docs...
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 10, 2014, 09:52:15 am
I edit the code from degree to radiant and I will try :)
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 10, 2014, 12:12:27 pm
In this post I attach the model's skeleton xml files.

I posted it, because I did in this way.

In public void onSurfaceChanged(GL10 gl, int width, int height) :
Code: [Select]
protected void rotazionebraccio()
{
Logger.log("rotazionebraccio");

final Joint LUpperArm  = currentPose.getSkeleton().getJoint(17);
final Joint parentJoint = currentPose.getSkeleton().getJoint(LUpperArm.getParentIndex());
final Matrix global= new Matrix(LUpperArm.getBindPose());
float angle=(float)Math.toRadians(90);
global.rotateZ(angle);
global.matMul(parentJoint.getInverseBindPose());
currentPose.getLocal(17).setTo(global);

currentPose.updateTransforms();
skeletonDebugger.update(currentPose);
modello.applySkeletonPose();
modello.applyAnimation();

}


and

Code: [Select]
public void onDrawFrame(GL10 gl)
{
if (frameBuffer == null)
return;

frameBuffer.clear(back); //ripulisco il frameBuffer e lo setto con il colore di sfondo voluto
world.renderScene(frameBuffer);
world.draw(frameBuffer);
frameBuffer.display();

}

I want to rotate the left arm, that in skeleton xml file is :
<bone id="17" name="Vincent L UpperArm">

I run the application and the left foot rotated and not the arm... do you know what did I do wrong  ?
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 11, 2014, 10:53:58 am
I think that the ids present in skeleton.xml file are wrong. I think, because I have tried to move the left arm and it has moved but in wrong way -.-"

I try to move the model's Left Thigh and the result is :
(http://imagizer.imageshack.us/v2/280x200q90/902/WImtAY.png) (http://imageshack.com/f/p2WImtAYp)

 >:(

The code that I have used is :
Code: [Select]
protected void rotazionebraccio()
{
Logger.log("rotazionebraccio");

final Joint LUpperArm  = currentPose.getSkeleton().getJoint(3);
final Joint parentJoint = currentPose.getSkeleton().getJoint(LUpperArm.getParentIndex());
final Matrix global= new Matrix(LUpperArm.getBindPose());
float angle=(float)Math.toRadians(-90);
global.rotateX(angle);
global.matMul(parentJoint.getInverseBindPose());
currentPose.getLocal(3).setTo(global);

currentPose.updateTransforms();
skeletonDebugger.update(currentPose);
modello.applySkeletonPose();
modello.applyAnimation();

}

I have committed an error in the code or maybe is ogre's exporter fault ?   


EDIT :now I have replaced in code but the right thigh has moved .. I take the id from this file :

Code: [Select]
         <bone id="2" name="Vincent Spine">
            <position x="4.90153" y="5.88984e-006" z="-0.624106"/>
            <rotation angle="0">
                <axis x="-0.82569" y="-0.0201387" z="0.563765"/>
            </rotation>
        </bone>
        <bone id="3" name="Vincent L Thigh">
            <position x="-4.90153" y="3.78952" z="0.624106"/>
            <rotation angle="3.14159">
                <axis x="0.0181571" y="1.91597e-007" z="0.999835"/>
            </rotation>
        </bone>
        <bone id="4" name="Vincent L Calf">
            <position x="18.4395" y="0" z="-1.19209e-007"/>
            <rotation angle="0.00851348">
                <axis x="-3.32428e-012" y="1" z="-4.37102e-008"/>
            </rotation>
        </bone>
        <bone id="5" name="Vincent L Foot">
            <position x="13.4731" y="0" z="-1.19209e-007"/>
            <rotation angle="0.0277679">
                <axis x="-2.55262e-005" y="1" z="-7.32838e-006"/>
            </rotation>
        </bone>

Did I do wrong ? :(

I hope you can help me  :D
Title: Re: Animate rigged model according to given commands
Post by: raft on September 11, 2014, 11:04:39 am
the index of joints in skeleton.xml file is not related to id's in Bones. indeed joints in Bones has no id's but zero based indices. such that first joint in skeleton is at index zero, the second one is at index one, and so on. the ordering may be totally different from skeleton.xml file.

but assuming joint names are unique, you can retrieve a joint by its name:

Code: [Select]
Skeleton.findJointByName(jointName)
once a joint is found you can later retrieve it by its index.
Title: Re: Animate rigged model according to given commands
Post by: raft on September 11, 2014, 11:09:36 am
btw, i will suggest you making yout trials at desktop jPCT not on Android. it will be much easier to do so. and using Bones' samples as a starting point may also save you some time.
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 11, 2014, 11:10:26 am
the index of joints in skeleton.xml file is not related to id's in Bones. indeed joints in Bones has no id's but zero based indices. such that first joint in skeleton is at index zero, the second one is at index one, and so on. the ordering may be totally different from skeleton.xml file.

but assuming joint names are unique, you can retrieve a joint by its name:

Code: [Select]
Skeleton.findJointByName(jointName)
once a joint is found you can later retrieve it by its index.

Thank you a lot !!!!!!!!!!!!!!!!!!!!!1  ;D
Title: Re: Animate rigged model according to given commands
Post by: raft on September 11, 2014, 11:13:34 am
the ordering may be totally different from skeleton.xml file.
this is worth mentioning, the joints are ordered such that, parent of a joint always comes before the joint itself.
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 11, 2014, 11:25:56 am
yes yes I had supposed this :D
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 12, 2014, 11:05:45 pm
ooooh :D
I have two last aspect to improve :
- camera : to handle smartphone rotate, zoom and pan
- undestand if we can to edit bone's weight

:)
Title: Re: Animate rigged model according to given commands
Post by: raft on September 13, 2014, 01:37:21 pm
- undestand if we can to edit bone's weight
i guess you cannot do that at the moment without changing Bones's source code
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 13, 2014, 01:45:50 pm
ah ok :)

@AGP :

do you know why we do this ?   
                mulMatrixByInverse(getJoint(joint.getParentIndex()), bind);
      pose.getLocal(getJointIndex(joint)).setTo(bind);
Author of skeletonhelper doesn't remember why he use this function XD

Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 22, 2014, 08:25:54 pm
you can move camera closer to make the model look bigger. or you can scale the model.

Is the Fov angle the setting we have to change to obtain a correctly zoom ?

I would want a camera that rotate around my model then I have used this camera :
http://www.jpct.net/wiki/index.php/MultiTouch_camera_controls (http://www.jpct.net/wiki/index.php/MultiTouch_camera_controls)

In vertical it correctly works, but when I rotate to landscape it's too zoomed. I have to set the fov depending of resolution but I don't know how :/
Title: Re: Animate rigged model according to given commands
Post by: raft on September 23, 2014, 09:07:35 am
changing FOV for zoom is like looking through a telescope. you see a narrow region zoomed.

for landscape, you can try different FOV values
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 23, 2014, 11:34:59 am
I'm trying but the results is wrong :(

I have searched in the web and the result is that I have to do in this way :

Code: [Select]
cameraDistance = ( modelHeight / 2 ) / tan( fovy / 2 )
Then place your camera:
cameraPos.z = modelPos.z - cameraDistance


I try to merge this math function in http://www.jpct.net/wiki/index.php/MultiTouch_camera_controls but it isn't simple because the camera's code isn't mine :/
Title: Re: Animate rigged model according to given commands
Post by: raft on September 23, 2014, 12:33:38 pm
i havent done it myself. did you have a look at AbstractSkinSample.autoAdjustCamera method?
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 24, 2014, 01:03:09 am
raft another question :
I would implement a ghost of my first model, I want it in the same position of first model but it have to move in different way.  Then I want they will be in different color, for example draw the ghost with drawWireframe .

Is it possible ? Any suggestion ? :)

Title: Re: Animate rigged model according to given commands
Post by: raft on September 24, 2014, 12:38:58 pm
i guess not. jPCT does not draw wireframe per object, it draws the whole scene or none.

buy you can try a hybrid solution, render two worlds on top of each other, one wireframe and contains only the ghost, over the other original world. or you can try giving similar effect with a special texture.
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 25, 2014, 07:38:59 pm
Is there a rapid way to add the same model but with a different physical appearance ? (without using 3d graphics programs)  ;D
Title: Re: Animate rigged model according to given commands
Post by: raft on September 26, 2014, 09:18:24 am
apply a fancy effect to texture in a simple image editor program ;)
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 27, 2014, 10:28:39 pm
thanks :D

A last question :

is there some kind of tricks to pre-load  3d models and the relative textures? because in the ninja-bones-demo the model is loaded immediatelly, instead in mine app it's load after 5-8 seconds   >:(
Title: Re: Animate rigged model according to given commands
Post by: raft on September 28, 2014, 11:44:47 am
loading them in surfaceCreated or surfaceChanged methods doesnt help?
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 28, 2014, 12:53:40 pm
I have imported the model in onSurfaceChanged in this way :

Code: [Select]
public MyGLRenderer(Context context,MovementHandler gestore) {
//impostiamo i settaggi del render
Config.maxPolysVisible = 500;
Config.farPlane = 1000;
ActivityContext=context;
this.gestore=gestore;
}


@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// TODO Auto-generated method stub
Logger.log("onSurfaceCreated");
}

@Override
public void onDrawFrame(GL10 gl)
{

if (frameBuffer == null)
return;

........

}


@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
// TODO Auto-generated method stub
Logger.log("onSurfaceChanged");
if (frameBuffer != null) {
frameBuffer.dispose();
}
frameBuffer = new FrameBuffer(width, height);

this.width=width;
this.height=height;

//in teoria .. potrebbe funzionare ..
if (world != null)
return;

world = new World();  //creiamo il mondo

//inseriamo il nostro modello nel mondo

Resources res = ActivityContext.getResources();
try {

modello = BonesIO.loadGroup(res.openRawResource(R.raw.vincent));
modello.addToWorld(world);
}
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}

world.setAmbientLight(127, 127, 127);
world.buildAllObjects();
helper=new JointRotation(modello);

TextureManager.getInstance().flush();
Texture texture = new Texture(res.openRawResource(R.raw.vincent_texture));
texture.keepPixelData(true);
TextureManager.getInstance().addTexture("vincent", texture);

for (Animated3D a : modello)
{
a.setTexture("vincent");
a.discardMeshData();
}

//calcoliamo le grandezze del boundingbox del nostro modello

float[] bb = calcBoundingBox();
box_h = (bb[3] - bb[2]); // model height



Camera camera = world.getCamera();
if(width < height)
{
camera.setPosition(0,-box_h/2,0);
camera.moveCamera(Camera.CAMERA_MOVEOUT, 70);  //la sposto indietro
camera.lookAt(new SimpleVector(0, -box_h/2, 0));
}
else
{
float fovy=camera.getYFOV();

double cameraDistance = ( box_h / 2 ) / Math.tan( fovy / 2 );

camera.setPosition(0,-box_h/2,(float)cameraDistance-100);

camera.lookAt(new SimpleVector(0, -box_h/2, 0));

}

//ora si crea un vettore per indirizzare il sole
new Light(world).setPosition(new SimpleVector(0, -box_h/2, box_h));

currentPose = modello.get(0).getSkeletonPose();

MemoryHelper.compact();  // dovrebbe liberare un p di memoria
}

In on SurfaceCreated I have done nothing :)

Did I do something wrong ?
Title: Re: Animate rigged model according to given commands
Post by: raft on September 28, 2014, 06:06:30 pm
not sure, it seems ok
Title: Re: Animate rigged model according to given commands
Post by: aeroxr1 on September 29, 2014, 09:42:40 am
thanks you for your time :)