[bb] Attach Body Parts by Leon Drake [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:40

Previous topic - Next topic

BlitzBot

Title : Attach Body Parts
Author : Leon Drake
Posted : 1+ years ago

Description : I am working on a game where i have a base skeleton that will have all my characters animations but i wanted to keep the body parts seperate in case i may want to replace the mesh with like clothing or armor. Here is a good set of functions to do this without the trouble of manually lining parts up. Provided the Part your attaching has bones that have the same name as the skeletons.

Code :
Code (blitzbasic) Select
Graphics3D 800,600,16,2





SetBuffer BackBuffer()


global skeleton,part

Type child

Field child,childcount,parentmesh

End Type

lit = createlight()
cam = createcamer()
skeleton = LoadAnimMesh(tbodyfile$)
addtoskeleton(tpartfile$,ttextfile$)

Repeat
Cls


UpdateWorld()
RenderWorld()
Flip

Until KeyHit(1)


End

Function addtoskeleton(tpartfile$,ttextfile$)


part = LoadAnimMesh(tpartfile$)
parttex = LoadTexture(ttextfile$,1)
EntityTexture part,parttex

PositionEntity part,EntityX(skeleton),EntityY(skeleton),EntityZ(skeleton)
getchildren(part)
getchildren(skeleton)
For c.child = Each child
If cparentmesh = part Then
For x.child = Each child
If xparentmesh = skeleton Then
If EntityName(xchild) = EntityName(cchild) Then
DebugLog "Attaching "+EntityName(cchild)+" to "+EntityName(xchild)

EntityParent(cchild,0)

PositionEntity cchild,EntityX(xchild,True),EntityY(xchild,True),EntityZ(xchild,True)


RotateEntity cchild,EntityPitch(xchild,True),EntityYaw(xchild,True),EntityRoll(xchild,True)

EntityParent(cchild,xchild)


Exit
EndIf
EndIf
Next
EndIf

Next





For c.child = Each child
Delete c
Next
End Function





Function getchildren(ent)
entp = ent
While ent
c.child = New child
cchild = ent
cparentmesh = entp
ent = NextChild(ent)
Wend

End Function

;NextChild() function by Beaker
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


Comments :


Leon Drake(Posted 1+ years ago)

 woops forgot to change the type over to a regular varPositionEntity ppartmesh,EntityX(pselfmesh),EntityY(pselfmesh),EntityZ(pselfmesh)should bePositionEntity part,EntityX(skeleton),EntityY(skeleton),EntityZ(skeleton)


Wings(Posted 1+ years ago)

 This is a good idea indeed.Curently i am having to create multible animations. ang if i want to change the animation i will have to Reexport all entitys.this seams like a good sollution.