Animated & non Animated meshes

Blitz3D Forums/Blitz3D Beginners Area/Animated & non Animated meshes

How I can check before if a mesh is animated or not animated in order to use LoadMesh or LoadANimMesh respectively

Thanks!

Ok, I found a solution.
If I load a static mesh with the LoadAnimMesh function then its width, height or depth are negatives

Problem is, LoadAnimMesh, is used for groups of meshes too, not just animated meshes.

Try using the animate command. I'm sure this will return a 0 value from the animating() function is the mesh isn't animating.

I tried but not worked. Take a look here just for your info:
http://www.blitzbasic.com/Community/posts.php?topic=77956

Thats odd. If it's an animating mesh, it should animate. And if it animates, it should return true on the animating flag. As long as you ghot it working though :o)

Yap, try this:
Graphics3D 640,480 
SetBuffer BackBuffer() 

camera=CreateCamera() 

light=CreateLight() 
RotateEntity light,90,0,0 

arialfont = LoadFont("Arial", 16)
SetFont arialfont

model% = LoadMesh("the_static_model")
If model <> 0 Then PositionEntity model,0,0,MeshDepth(model)*2

; Load mesh 
animmodel% = LoadAnimMesh("the_static_model")

If animmodel <> 0
	Animate animmodel
	anim_length% = AnimLength(animmodel) 
	animate_ing% = Animating(animmodel)
EndIf

While Not KeyDown( 1 ) 

	RenderWorld
	UpdateWorld
	If animmodel <> 0
		Text 0,0,"Model is valid"
		Text 0,20, "Width = "+MeshWidth(animmodel)
		Text 0,40, "Height = "+MeshHeight(animmodel)
		Text 0,60, "Depth = "+MeshDepth(animmodel)
		Text 0,80, "Anim length = "+anim_length
		Text 0,100, "Animating = "+animate_ing
	Else
		Text 0,0,"Model is not valid"
	EndIf
	Flip 

Wend

End


I dont think you can do this line:
If animmodel <> 0
;code
endif

You have to do this:
If animmodel < 0
If animmodel > 0
;code
endif
endif

also,NEVER load a model as floating point

NEVER load a model as floating point

Where did I do this?

You can use <>, it means unequal to.
The command AnimLength(), if it is zero, the mesh is most likely not animated.
Usually, .b3d files have a root which is not animated. In that case, you'll need to use GetChild to obtain the child that contains the animation.
If you load the mesh using LoadAnimMesh, and decide that it isn't animated, you can collapse the mesh instead of freeing it and loading it again using LoadMesh. I've written a routine 'CopyMeshAt' which could come in handy for that. It copies a mesh, and applies the original entities rotation/scaling/position to the copied mesh.
Usage: mesh2 = CopyMeshAt(mesh) instead of mesh2 = CopyMesh(mesh) or mesh2 = CopyEntity(mesh)
Function CopyMeshAt(mesh)

	mesh2 = CopyMesh(mesh)
	ScaleMesh mesh2, EntityWidth(mesh), EntityHeight(mesh), EntityDepth(mesh)
	RotateMesh mesh2, GlobalEntityPitch(mesh), GlobalEntityYaw(mesh), GlobalEntityRoll(mesh)
	PositionMesh mesh2, EntityX(mesh,1), EntityY(mesh,1), EntityZ(mesh,1)
	
	Return mesh2
	
End Function


Function EntityWidth#( mesh )
	
	If EntityClass$(mesh) <> "Mesh" Then Return 1
	If MeshWidth(mesh) = 0 Then Return 1

	TFormPoint MeshWidth(mesh), 0, 0, mesh, 0	
	xx# = TFormedX()
	yy# = TFormedY()
	zz# = TFormedZ()
	TFormPoint 0, 0, 0, mesh, 0	
	xx# = TFormedX()-xx
	yy# = TFormedY()-yy
	zz# = TFormedZ()-zz	
	ll# = Sqr(xx * xx + yy * yy + zz * zz) / MeshWidth(mesh)
	
	If ll = 0 Then ll = 1
	Return ll
	
End Function

Function EntityHeight#( mesh )

	If EntityClass$(mesh) <> "Mesh" Then Return 1
	If MeshHeight(mesh) = 0 Then Return 1
	
	TFormPoint 0, MeshHeight(mesh), 0, mesh, 0
	xx# = TFormedX()
	yy# = TFormedY()
	zz# = TFormedZ()
	TFormPoint 0, 0, 0, mesh, 0
	xx# = TFormedX()-xx
	yy# = TFormedY()-yy
	zz# = TFormedZ()-zz
	ll# = Sqr(xx * xx + yy * yy + zz * zz) / MeshHeight(mesh)
	
	If ll = 0 Then ll = 1
	Return ll
	
End Function

Function EntityDepth#( mesh )

	If EntityClass$(mesh) <> "Mesh" Then Return 1
	If MeshDepth(mesh) = 0 Then Return 1
	
	TFormPoint 0, 0, MeshDepth(mesh), mesh, 0	
	xx# = TFormedX()
	yy# = TFormedY()
	zz# = TFormedZ()
	TFormPoint 0, 0, 0, mesh, 0
	xx# = TFormedX()-xx
	yy# = TFormedY()-yy
	zz# = TFormedZ()-zz
	
	ll# = Sqr(xx * xx + yy * yy + zz * zz) / MeshDepth(mesh)
	
	If ll = 0 Then ll = 1
	Return ll
		
End Function

Function GlobalEntityPitch#(entity)

	pit# = Int(EntityPitch(entity)*1000)/1000.0
	
	Return pit

End Function
Function GlobalEntityYaw#(entity)
	
	pit# = Int(EntityPitch(entity)*1000)/1000.0
	yaw# = Int(EntityYaw(entity)*1000)/1000.0
	
	If Abs(pit)>GIMBAL_LIMIT
		temp = CreatePivot(entity)
		EntityParent temp, GetParent(entity)
		TurnEntity temp,Sgn(pit)*-90.0,0,0
		yaw# = Int(EntityYaw(temp)*1000)/1000.0
		FreeEntity temp
	EndIf

	Return yaw
	
End Function

Function GlobalEntityRoll#(entity)

	pit# = Int(EntityPitch(entity)*1000)/1000.0
	rol# = Int(EntityRoll(entity)*1000)/1000.0

	If Abs(pit)>GIMBAL_LIMIT
		temp = CreatePivot(entity)
		EntityParent temp, GetParent(entity)
		TurnEntity temp,Sgn(pit)*-90.0,0,0
		rol# = Int(EntityRoll(temp)*1000)/1000.0
		FreeEntity temp
	EndIf

	Return rol

End Function


I dont think you can do this line:

Yes you can.

also,NEVER load a model as floating point

% is the symbol for an integer, floats are designated with #.

My bad.