Blitz3D Animation bug? (loadAnimSeq+multiple anim)

Blitz3D Forums/Blitz3D Programming/Blitz3D Animation bug? (loadAnimSeq+multiple anim)

gameproducer(Posted 2007) [#1]
I have a character files that contain 2 separate animations. Here's the code I use (that works) for the first animation:
	temp =  LoadAnimMesh("assassin_death.b3d")
	ScaleEntity mesh, 15, 15, 15

	tempbody = FindChild(temp, "body")
	tempsword = FindChild(temp, "Knife")
	tempholster = FindChild(temp, "Knife_holder")

	tex = LoadTexture("assassin5.png")
	EntityTexture tempbody, tex
	EntityTexture tempsword, tex
	EntityTexture tempholster, tex

	Animate temp, 		1, .42, 0, 5
	Animate tempbody, 	1, .42, 0, 5


That works okay, but when I try to add an additional animation it will animate only "temp", not "tempbody"
	temp =  LoadAnimMesh("assassin_death.b3d")
	ScaleEntity mesh, 15, 15, 15

	tempbody = FindChild(temp, "body")
	tempsword = FindChild(temp, "Knife")
	tempholster = FindChild(temp, "Knife_holder")

	tex = LoadTexture("assassin5.png")
	EntityTexture tempbody, tex
	EntityTexture tempsword, tex
	EntityTexture tempholster, tex
	
	LoadAnimSeq(temp, "assassin_sneak.b3d")
	LoadAnimSeq(tempbody, "assassin_sneak.b3d")

	Animate temp, 		1, .42, 1, 5
	Animate tempbody, 	1, .42, 1, 5


I've checked the files (load "sneak" first, and then animSeq "death") I see the same problem: only the first loaded "loadAnimMesh" gets animated properly.

The "tempbody" won't animate more sequences.

Is this a blitz3d bug, or is there some certain way how the animations should be added?

Should I try to create separarate files for animations (for both the "temp" and for the "tempbody")?


IPete2(Posted 2007) [#2]
Hiya there,

Don't know if this will help as it is loading 2 animations but not to 2 spearate boned/mesh models. But this works:

b\entitypivot = CreatePivot()

b\entitymesh = LoadAnimMesh("Boned_Mesh.b3d",b\entitypivot) ; attach my boned mesh to the pivot

b\NPC_name = FindChild(b\entitymesh,"ROOT_UU3D") ; find the animatable root bone so I can call it to animate it 
b\npc_Idle  =   LoadAnimSeq(b\entitymesh,"idle_1.b3d") ; load sequence idle 1
b\npc_Idle2 =  LoadAnimSeq(b\entitymesh,"idle_2.b3d") ; load sequence idle 2 

Animate b\NPC_name,1,0.5,b\npc_Idle,5 ; animate this npc with the first Idle


- as the mesh was exported from Ultimate Unwrap its root bone for animating is by default called "ROOT_UU3D" - and this is case sensitive btw.


I load multiple anim-Seq's using this method and just animate the b\NPC_name with whichever is more apporpriate based on user input.

I have also found that by testing for the animation sequence, sometimes it doesn't load on the end of a particular sequence , so I move that one earlier in the load sequence, for example, if I load 10 animations and nothing works beyond the 6th one, I would move the load sequences around making sure that 8 9 and 10 load before 7 (if 7 is the problem file).

I haven't found out why this happens sometimes, but it does, and by moving it to an earlier or later load position it sorts it out somehow?! (don't ask me how!)

IPete2.


gameproducer(Posted 2007) [#3]
I tried doing the findchild, but it didn't work. We finally got it working by having ALL animations in one file - and then using extractAnimSeq to separate them... after that I could animate child meshes.


IPete2(Posted 2007) [#4]
Is that solution okay for you now then or would you still like to find out what went wrong with the previous set up?

If you want me to take a look at a mesh and a single animation, you can e-mail me and I'll see if I can see anything odd about it.

Best regards,

IPete2.


gameproducer(Posted 2007) [#5]
This is fine for me (for now)... but actually I run into another problem. For some reason I cannot get shadows to appear for my .b3d file (I can texture it fine - so the child "body" must be a proper mesh - but for some reason it won't show shadows)... talking about this here:
http://blitzbasic.com/Community/posts.php?topic=72345


Bobysait(Posted 2009) [#6]
This is an old topic, but a question that is often posed.

The real thing with the animations and export format, is about the hierarchy of the scene.
It depends on "how many" meshes are skinned in the scene.

for eg with 3dsmax and b3d pipeline :
if we use a mesh skinned using a biped or bones, if this mesh is single in the scene ( expect the bones "inside" ) we'll have to export the scene using "Meshes" , "Export Bones" and eventually "Export Animation"
+> but not the "Scene Root"

Then to export individual animations, we need to export the "Export Bones" and "Export Animation"

+> in blitz3d, we'll have to animate directly the AnimMesh
MyB3d=LoadAnimMesh("Myb3dFile.b3d")
SeqAddOn=LoadAnimSeq(MyB3d,"MyAnimFile.b3d")
; we can subdivise the animation using ExtractAnimSeq.
Seq1=ExtractAnimSeq(MyB3d,1,20 , SeqAddOn )
Animate MyB3d , 1 , 1 , Seq1



Now if we have a mesh and multiples items attached to bones or else, we'll have to export using "Scene Root"
in blitz3d , we'll have to find the skinned Mesh to happen animation.
To export extra animations in other b3d files, we 'll have to delete everything that does not happen in the skinned mesh hierarchy, else, the hierarchy won't be paste in blitz3d due to irelevant bones id.

ps :
I can provide screens from the b3d pipeline setup for people who wants to know exactly how I do in the detail.


RemiD(Posted 2016) [#7]
@Bobysait>>So this means that i can do something like that :
;load the skeleton+skinnedmesh
SkeletonAndSkinnedMesh = loadanimmesh("skeletonandskinnedmesh.b3d") 

;add the animation "idle" to the skeleton+skinnedmesh
SkeletonAndAnimation_Idle = loadanimseq(SkeletonAndSkinnedMesh,"skeletonandanimation_idle.b3d") ;let's say that the frames are 1,40
;add the animation "walkforward" to the skeleton+skinnedmesh
SkeletonAndAnimation_WalkForward = loadanimseq(SkeletonAndSkinnedMesh,"skeletonandanimation_walkforward.b3d") ;let's say that the frames are 1,60
;add the animation "walkbackward" to the skeleton+skinnedmesh
SkeletonAndAnimation_WalkBackward = loadanimseq(SkeletonAndSkinnedMesh,"skeletonandanimation_walkbackward.b3d") ;let's say that the frames are 1,60

;get the animation "idle" from the skeleton+skinnedmesh
IdleAnimation = extractanimseq(SkeletonAndSkinnedMesh,1,40)
;get the animation "walkforward" from the skeleton+skinnedmesh
WalkForwardAnimation = extractanimseq(SkeletonAndSkinnedMesh,40+1,40+60)
;get the animation "walkbackward" from the skeleton+skinnedmesh
WalkBackward = extractanimseq(SkeletonAndSkinnedMesh,40+60+1,40+60+60)

yes ? no ?

Thanks,


Bobysait(Posted 2016) [#8]
I've got an headacke just reading the names of your entities :)

To anwer your question :
Yes, No ... it depends on the files you exported and what do they contain.

The hierarchy must match at some level, and depending on the software you use, and optimization made on the model, some software remove or add some pivots from the scene if unused.

For example, if you have a mesh rigged with bones, the first file you export will be the one containing the mesh and its hierarchy.

Then you want to export the animations :
-> if you export only the animation (without the mesh), it will fail unless you add the animation to the matching root of the hierarchy in the animation file and not to the mesh itself. But then, the animated entity will be the pivot, not the mesh.

To prevent any kind of bad stuff, one thing you can consider doing (it will also optimize the size of your animations drastically) :
- export everything from your software (fragmotion isn't it ?) with the mesh and its bones for the "static" model
export the mesh, its bones and the animations keys for the animation files

Load the b3d animation files using readfile and use the "b3d file utils" (from the "Specs and Utils" section > "Sample Blitz code") to read the b3d chunks extract the "BONE", "ANIM", and "KEYS" chunk
Then export the chunk to a binary format that contains only those data.
if you then want to happen an animation, read the binary file and use SetAnimKey/AddAnimSeq to create the animations directly on the entity you want to be animated.


RemiD(Posted 2016) [#9]
@Bobysait>>Thanks for the suggestions.


I have found the answer here : http://www.blitzbasic.com/Community/posts.php?topic=56947 post#3

If i understand correctly, it would be more like (not tested) :


Now i have to test!


RemiD(Posted 2016) [#10]

Then you want to export the animations :
-> if you export only the animation (without the mesh), it will fail unless you add the animation to the matching root of the hierarchy in the animation file and not to the mesh itself. But then, the animated entity will be the pivot, not the mesh.

To prevent any kind of bad stuff, one thing you can consider doing (it will also optimize the size of your animations drastically) :
- export everything from your software (fragmotion isn't it ?) with the mesh and its bones for the "static" model
export the mesh, its bones and the animations keys for the animation files



Well, i see what you mean now...



Load the b3d animation files using readfile and use the "b3d file utils" (from the "Specs and Utils" section > "Sample Blitz code") to read the b3d chunks extract the "BONE", "ANIM", and "KEYS" chunk
Then export the chunk to a binary format that contains only those data.
if you then want to happen an animation, read the binary file and use SetAnimKey/AddAnimSeq to create the animations directly on the entity you want to be animated.


Another way would be to load the rigged skinned animated mesh with the animation, then play the animation with 1.0 speed, and for each frame get each joint/bone position/orientation and store these values somewhere.
Then recreate the animation by using positionentity/rotateentity on each joint/bone of the skeletonandskinnedmesh, then setanimkey(), then at the end of the animation addanimsed().

I will try that...


RemiD(Posted 2016) [#11]
Ok, after some tests, what i have explained in post #9 works well but you have to remove the empty frames at the end of the animation or they will be added to the animation... So the skeletonandskinnedmesh.b3d file must contains the skeleton and the skinned mesh, and the skeletonandanimation_x.b3d file must contains the skeleton and the animation that you want (startframe to endframe).
No need to use extractanimseq() in this case...

Good ! It simplifies things.


Bobysait(Posted 2016) [#12]

Another way would be to load the rigged skinned animated mesh with the animation, then play the animation with 1.0 speed, and for each frame get each joint/bone position/orientation and store these values somewhere.
Then recreate the animation by using positionentity/rotateentity on each joint/bone of the skeletonandskinnedmesh, then setanimkey(), then at the end of the animation addanimsed().



Well ... you can ... but do you really want ?
I explain :
Any animation software (the good ones, not the crappy ones ^^) only export usefull keys, it already makes files as big as the hierarchy is deep and the animation is long.
If you do what you told, you'll store a key per bone per frame.
This will give you a very huge file.
It will work, but it will consume lot of ram, lot of disk space and can also make decrease the framerate (keys are often stored as linked list > the more the keys, the longer time you get the last key)

So, if you want to do something like this, at least, use an optimization routine that removes interpolated keys.


RemiD(Posted 2016) [#13]
Yes the best approach is to read the b3d file, as you have explained. But for the moment i don't need to do that because loadanimseq() on a skeleton+animation works well.