CameraPick and animated .X files

Blitz3D Forums/Blitz3D Beginners Area/CameraPick and animated .X files

@Bill Stanbrook: I didn't try it but your solution looks very clever.

Edit:
I tried. CopyMesh does not copy all hierarchy.
Before your work flow, you must copy all meshes and then make a new one.
Graphics3D 640,480 
SetBuffer BackBuffer() 

camera=CreateCamera() 

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

modelname$ = "mak_running.3ds"
staticmesh% = LoadMesh(modelname$)
If staticmesh <> 0 Then PositionEntity camera,0,0,-MeshDepth(staticmesh)*3
FreeEntity staticmesh

; Load mesh 

animmesh% = LoadAnimMesh(modelname$)

staticmesh = CopyMesh(animmesh)

; alpha entity
ent = animmesh
While ent
	If EntityClass(ent)="Mesh"
		EntityAlpha ent, 0
	EndIf
	ent = NextChild(ent)
Wend

; pick entity
ent = animmesh
While ent
	If EntityClass(ent)="Mesh"
		EntityPickMode ent, 2
	EndIf
	ent = NextChild(ent)
Wend

Animate animmesh

While Not KeyDown( 1 ) 

	RenderWorld
	UpdateWorld
	If CameraPick(camera, MouseX(), MouseY()) Then Text 0,0, "Picked"
	Flip 

Wend

FreeEntity animmesh
FreeEntity staticmesh

End


Function NextChild(ent)
	Local siblingcnt
	If CountChildren(ent)>0
		Return GetChild(ent,1)
	EndIf

	Local foundunused=False
	Local foundent = 0, parent,sibling
	While foundunused=False And ent<>0
		parent = GetParent(ent)
		If parent<>0
			If CountChildren(parent)>1
				If GetChild(parent,CountChildren(parent))<>ent
					For siblingcnt = 1 To CountChildren(parent)
						sibling = GetChild(parent,siblingcnt)
						If sibling=ent
							foundunused = True
							foundent = GetChild(parent,siblingcnt+1)
						EndIf
					Next
				EndIf
			EndIf
		EndIf
		ent = parent
	Wend
	Return foundent
End Function


You will see nothing. This means that a simple copy mesh is not enough.

Note: You can locate mak_running.3ds (or mak_running.x) in sample\mak\anim\makbot folder of the Blitz3D installation