As for the details of how to build a skeleton:
The "NoHe" element contains information about the bone name and its local transformation (matrix 4x4) relative to its parent.
And so for the "Piston_FR" bone the parent is "D_Main".
For the bone "D_Main" the parent is "Root". And so on.
The Mesh element has the "NoHe" element transformation and can be composed of more than one "Geom" type element.
"Mesh" and "Geom" have the name of their "NoHe".
Here is an example of using a recursive function to load a tree of bones (python).
Code: Select all
def recurse(parent,g,n):
bone=None
tag=g.word(4)
len=g.i(1)[0]
n+=4
tm=g.tell()
if tag in ['RIFF','LIST']:
node=Node()
node.data=parent.data.copy()
parent.children.append(node)
chunk=g.word(4)
node.chunk=chunk
node.off=g.tell()
write(txt,[tag,':',len,chunk,tm],n)
while(True):
pos=recurse(node,g,n)
if pos==tm+len:break
else:
write(txt,[tag,len,tm],n)
if tag=='NoHe':
a=g.H(1)[0]
b=g.word(g.i(1)[0])[-25:]
c=g.H(1)[0]
d=g.f(16)
e=g.B(12)
matrix=Matrix4x4(d)
write(txt,[a,b,c,d,e],n)
#parent.matrix=parent.data['matrix'].copy()
#write(txt,parent.matrix[0],n)
#write(txt,parent.matrix[1],n)
#write(txt,parent.matrix[2],n)
#write(txt,parent.matrix[3],n)
#parent.data['matrix']=matrix.invert()
bone=Bone()
bone.name=b
skeleton.boneList.append(bone)
bone.matrix=matrix#.invert()#.transpose()
if parent.data['name']:bone.parentName=parent.data['name']
parent.data['name']=b
if tag=='Mesh':
model=Model()
modelList.append(model)
model.boneName=parent.data['name']
parent.data['model']=model
#model.matrix=parent.matrix
if tag=='Geom':
mesh=Mesh()
#mesh.matrix=parent.matrix
mesh.info=None
#if parent.model:
parent.data['model'].meshList.append(mesh)
if tag=='SuGe':
info=g.H(1)+g.i(2)+g.H(1)
mesh=parent.data['model'].meshList[-1]
mesh.info=info
write(txt,info,n+4)
if tag=='vpos':
mesh=parent.data['model'].meshList[-1]
vertCount=mesh.info[1]
for m in range(vertCount):
mesh.vertPosList.append(g.f(3))
if tag=='vuvs':
mesh=parent.data['model'].meshList[-1]
vertCount=mesh.info[1]
for m in range(vertCount):
mesh.vertUVList.append(g.short(2))
if tag=='vcol':
mesh=parent.data['model'].meshList[-1]
vertCount=mesh.info[1]
for m in range(vertCount):
mesh.vertColList.append(g.B(4))
#print mesh.vertColList[-1]
if tag=='indx':
mesh=parent.data['model'].meshList[-1]
#print mesh.info
faceCount=mesh.info[2]
for m in range(faceCount):
mesh.faceList.append(g.H(3))
#mesh.draw()
#model=parent.data['model']
#mesh.object.setMatrix(parent.data['matrix'])
g.seek(tm+len)
return g.tell()
def setBoneMatrix(object,skeletonObject,boneName):
bones=skeletonObject.getData().bones
if boneName in bones.keys():
matrix=bones[boneName].matrix['ARMATURESPACE']
object.setMatrix(matrix)
def p3dParser(filename,g):
global modelList,skeleton
skeleton=Skeleton()
#skeleton.ARMATURESPACE=True
#skeleton.SORT=True
skeleton.BONESPACE=True
modelList=[]
n=0
root=Node()
recurse(root,g,n)
Updated:2018-11-26
Blender importer for p3d files.
You need:
http://download.blender.org/release/Ble ... indows.exeand
https://www.python.org/ftp/python/2.6.6 ... -2.6.6.msiUnpack archive, doubleclick on file "Blender249.blend" , press alt+p in Blender Text Window and
1
- import car "*.p3d"
2.
- select skeleton in Blender 3D view
3.
- import wheel "*.p3d"
http://www.mediafire.com/file/1s4fr6uuj ... 1-24%5D.7z