LoadAnimMesh()

Blitz3D Forums/Blitz3D Programming/LoadAnimMesh()

_PJ_(Posted 2016) [#1]
I really find the animation of 3D meshes in blitz to be extremely cumbersome, counter-intuitive and difficult to implement in any reasonably useful means.

In this particular case, the mesh loaded is loaded with apparently no surface. This makes no sense to my understanding, since there is clearly visible geometry.


Function InitalisePlayer()
MESH_PLAYER=LoadAnimMesh(VisualDir()+"p.x")

Local Surfaces=CountSurfaces(MESH_PLAYER)
DebugLog("Surface count: "+Str(Surfaces))

LoadAnimSeq(MESH_PLAYER,VisualDir()+"p_walk.x")
LoadAnimSeq(MESH_PLAYER,VisualDir()+"p_attack.x")

End Function



In the function, 'Surfaces' is returned as ZERO despite the animation and mesh geometry being visible later.

If the Surfaces are not accessible, how can one texture the mesh or identify the vertices programmatically?


Floyd(Posted 2016) [#2]
I would guess there is a "dummy" root and the real geometry is in children of the root, and perhaps children of children etc.


Bobysait(Posted 2016) [#3]
Depending on the modelisation software the mesh come from, the root is mostly a "fake" pivot (so it's actually a real mesh, but empty)
Check the root name, if it's something like "scene_root" (or a very long name if it's exported from Gile[s])

If you know the name of the mesh you're looking for, use FindChild("name of the mesh") (/!\ case sensitive) then you can get the recursivity of this mesh just looping GetParent() until the parent is the root
; Get the hierarchy to find an entity
Function FindInHierarchy(root, ent, ids%[100])
  ; put a marker on the child
  Local CheckParent = ent
  ; initialize number of parents to reach the root
  Local CountParent = 0
  ; marker on current entity
  Local CheckFrom = CheckParent
  ; loop until you reach the root
  While (CheckParent<>Root)
     ; increase parent count
     CountParents = CountParents + 1
     ; set the new parent
     CheckParent = GetParent(CheckFrom)
     ; initialize child ids for this branch
     ids[CountParents] = 0
     ; find the current entity in the direct parent hierarchy
     For i = 1 To CountChildren(CheckParent)
        If GetChild(CheckParent,i) = CheckFrom
            ; found it
            ids[CountParents] = i
            Exit
        EndIf
     Next
     ; update marker
     CheckFrom = CheckParent
  Wend
  ; finally return parent count to reach the root
  Return CountParents
End Function


Graphics3D 800,600,0,2

; create some hierarchy (replace all this scope with your LoadAnimMesh)
Local Root = CreatePivot()
  NameEntity Root, "root"
  For i = 0 To 2
    Local child1 = CreatePivot(Root)
    NameEntity child1, "child "+i
    For j = 0 To 1
      Local child2 = CreatePivot(child1)
      NameEntity child2, "child "+i+" "+j
      For k = 0 To 2
        Local child3 = CreatePivot(child2)
        NameEntity child3, "child "+i+" "+j+" "+k
      Next
    Next
  next

; find one of the children by its name (replace with the real name of the mesh you're looking for)
Local mesh = FindChild(root, "child 1 0 2")

; dump the hierarchy from the mesh to the root
Local ChildIds%[100]
Local nb = FindInHierarchy(root,mesh,ChildIds)
Local ex$ = "th" : Select nb:Case 1:ex="st":Case 2:ex="nd":Case 3:ex="rd":End Select
Print "The mesh is located on the "+nb+ex+" branch of the root"

; now you can debug the hierarchy from root to the mesh :
CheckParent = Root
Print "Hierarchy to get the mesh :"
For j = 1 To nb
    ; reverse the id (else it will show results from the mesh to the root)
    i = nb-j+1
    ex = "th" : Select ChildIds[i]:Case 1:ex="st":Case 2:ex="nd":Case 3:ex="rd":End Select
    Print "   * "+ChildIds[i]+ex+"' child of entity '"+EntityName(CheckParent)+"'"
    CheckParent = GetChild(CheckParent, ChildIds[i])
Next
WaitKey()
End



RemiD(Posted 2016) [#4]

I really find the animation of 3D meshes in blitz to be extremely cumbersome, counter-intuitive and difficult to implement in any reasonably useful means.


it works really well on my side, the problem must be on your side...


to export your rigged skinned animated mesh, i suggest to use Fragmotion, the b3d exporter works well.


you can analyze the joints/bones of your rigged skinned animated mesh using this code : http://www.blitzbasic.com/codearcs/codearcs.php?code=3264


(if you need a simple rigged skinned animated mesh (b3d) which is clean and works well (to do some tests), let me know, i can send one to you.)


RemiD(Posted 2016) [#5]
Note that you can animate your entity either with animate() (using an animation speed) or with setanimtime() (using the pose number, similar to using the frame number of an "animated image/texture")


_PJ_(Posted 2016) [#6]


I would guess there is a "dummy" root and the real geometry is in children of the root, and perhaps children of children etc.



[/quote]Depending on the modelisation software the mesh come from, the root is mostly a "fake" pivot (so it's actually a real mesh, but empty)[/quote]

This sounds likely and with hindsight, kinda logical.
I apprecaite the FindChild() suggestion too.

At least I am convinced that if this is what's happening, there are only Pivot and Mesh entities involved, so iterating the children of the loaded AnimMesh and some EntityClass() checks ought to be sufficient.

Thanks :)


RemiD(Posted 2016) [#7]
@_PJ_>>something to be aware of if you use fragmotion to create/save your b3d meshes :
each time you export a b3d mesh, it adds a root pivot.
So if you save your progress in a ugh file (the fragmotion file format) the hierarchy of the pivts/joints/bones stays the same and when you export in b3d, a root pivot is added. No problem.
However if you save your progress in a b3d file and then open your b3d file and then export again in b3d, each time you export, a root pivot is added. So your pivots/joints/bones hierarchy can quickly become a mess ! (so don't do that, save your progress in a ugh file)


_PJ_(Posted 2016) [#8]
I don't use any 3D modelling softwares at all. I am no 3D artist whatsover, but thanks for the tips.
It sounds like something similar has occurred in this case, that the meshes I am loading return a 'root' Pivot parent.


RemiD(Posted 2016) [#9]
if you analyze the hierarchy of the pivots/joints/bones of some b3d meshes often used in examples (because they are free), you will see a similar problem (several pivots were added at the root, probably one each time the mesh was exported...)


_PJ_(Posted 2016) [#10]
Seems the mesh indeed is a hierarchy based on a root pivot with the geometry of parts of the mesh as children of that pivot or other children.


_PJ_(Posted 2016) [#11]
Function PaintChildren(Parent,Texture)
	Local Children
	Local Iter
	Local Child
	
	Children=CountChildren(Parent)
	If (Children)
		For Iter=1 To Children
			Child=GetChild(Parent,Iter)
			If EntityClass(Child)="Mesh"
				EntityTexture Child,Texture
				PaintChildren(Child,Texture)
			End If
		Next
	End If
End Function


Fortunately the UV are all correct so a single texture map image is applied to the children meshes.