WRC 7 .P3D models

Skeletons, animations, shaders, texturing, converting, fixing and anything else related to read game models
huckleberrypie
Posts: 37
Joined: Sun Nov 11, 2018 2:27 am

WRC 7 .P3D models

Post by huckleberrypie »

I attempted to use Ninja Ripper on the game in vain, but it turns out that aluigi wrote a script for WRC 7's PKG file formats and that using it reveals a surprisingly good amount of content, all conveniently labelled.

That being said, the .P3D and .PTX files use RIFF as a container, but I figured there's more to it than just that. Maybe some of you 3D experts could figure out how to break this down so that we could port these cars to some other game easily.

Here are sample files I extracted using the BMS scripts mentioned above:
https://www73.zippyshare.com/v/vcUnAAjj/file.html
https://www73.zippyshare.com/v/AauPpLjC/file.html

EDIT: I opened the P3D and PTX files using Riffpad and the nodes seem neatly laid out and labelled (vertex positions, vertex normals, tangents, vertex uvs, indices...). Then again I'm not an expert with deciphering them floats and vert positions so I'll leave those to whoever can understand them:
Image
h3x3r
Posts: 165
Joined: Wed Jun 01, 2016 5:53 pm

Re: WRC 7 .P3D models

Post by h3x3r »

As I expect. Puzzle. Just few parts are on correct position + no wheels. +1 LOD inside which make mess.
Image

All floats.
Struct from string vpos

Code: Select all

uint vpos;
uint VTBSize;
VertexCount=VTBSize/12;
struct VERTICES {
for (i=0;i<VertexCount;i++)
struct Vertex {
        float VTX;
        float VTY;
        float VTZ;
        Printf("%s %f %f %f\n", s0, VTX*50, VTY*50, VTZ*50);
        }vt;
}vertices;

uint vnor;
uint VNBSize;
VertexCount=VNBSize/8;
struct NORMALS {
for (i=0;i<VertexCount;i++)
struct VNormals {
        hfloat VNX;
        hfloat VNY;
        hfloat VNZ;
        hfloat VNW;
        Printf("%s %f %f %f\n", s1, VNX, VNY, VNZ);
        }vtn;
}normals;

uint vtan;
uint VTGBSize;
FSkip(VTGBSize);

uint vuvs;
uint UVBSize;
VertexCount=UVBSize/4;
struct UV {
for (i=0;i<VertexCount;i++)
struct UVs {
        hfloat VTU;
        hfloat VTV;
        Printf("%s %f %f\n", s2, VTU*2000, -VTV*2000+1); not sure if position is really correct
        }uv;
}unitvector;

uint indx;
uint FBSize;
FaceCount=FBSize/2;
struct FACES {
for (i=0;i<FaceCount/3;i++)
struct Face {
        ushort FX;
        ushort FY;
        ushort FZ;
        Printf("%s %u/%u/%u %u/%u/%u %u/%u/%u\n", s3, FX+1,FX+1,FX+1, FY+1,FY+1,FY+1, FZ+1,FZ+1,FZ+1);
        }face;
}faces;
Szkaradek123
Posts: 124
Joined: Sat Aug 29, 2015 1:13 pm

Re: WRC 7 .P3D models

Post by Szkaradek123 »

To build a model, a skeleton is necessary. Each part of the car is associated with a specific bone. It's not difficult to see that the structure of the riff file is similar to the parent-child pattern.

Build a skeleton and then you can attach the wheels to the matching bone.
Last edited by Szkaradek123 on Fri Nov 23, 2018 2:53 pm, edited 1 time in total.
huckleberrypie
Posts: 37
Joined: Sun Nov 11, 2018 2:27 am

Re: WRC 7 .P3D models

Post by huckleberrypie »

Szkaradek123 wrote:To build a model, a skeleton is necessary. Each part of the car is associated with a specific bone. It's not difficult to see that the structure of the riff file is similar to the parent-child pattern.

Build a skeleton and then you can attach the wheels to the matching bone.

I presume this one has the UVs intact, right? Also, is it possible to get the skeleton data from the model itself or do I have to look elsewhere?
Szkaradek123
Posts: 124
Joined: Sat Aug 29, 2015 1:13 pm

Re: WRC 7 .P3D models

Post by Szkaradek123 »

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.exe
and
https://www.python.org/ftp/python/2.6.6 ... -2.6.6.msi

Unpack 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
huckleberrypie
Posts: 37
Joined: Sun Nov 11, 2018 2:27 am

Re: WRC 7 .P3D models

Post by huckleberrypie »

How's the UVW maps on this though?
Szkaradek123
Posts: 124
Joined: Sat Aug 29, 2015 1:13 pm

Re: WRC 7 .P3D models

Post by Szkaradek123 »

I do not understand.
For me meshes have uv mapping. And for you don't ?
huckleberrypie
Posts: 37
Joined: Sun Nov 11, 2018 2:27 am

Re: WRC 7 .P3D models

Post by huckleberrypie »

Szkaradek123 wrote:I do not understand.
For me meshes have uv mapping. And for you don't ?

Yeah, it does check out fine. I just had to make sure that I chose the right export options for converting them to Wavefront OBJ, as it would end up being a spaghetti-esque mess otherwise.

Image

I had to manually rename the objects too, but that may have to be merged and renamed in case I convert this to let's say GTA San Andreas or some other racing game.
huckleberrypie
Posts: 37
Joined: Sun Nov 11, 2018 2:27 am

Re: WRC 7 .P3D models

Post by huckleberrypie »

Also, the script doesn't seem to take LOD models into account. I know there are (obviously) LODs used throughout the game, and I'd like to know as there are some games which don't seem to like higher-poly cars and such.
huckleberrypie
Posts: 37
Joined: Sun Nov 11, 2018 2:27 am

Re: WRC 7 .P3D models

Post by huckleberrypie »

Sorry for the bump, but I'd like to know if the script could be amended to parse LOD models as well as the main mesh.
huckleberrypie
Posts: 37
Joined: Sun Nov 11, 2018 2:27 am

Re: WRC 7 .P3D models

Post by huckleberrypie »

Anyone?
Ha3aP
Posts: 5
Joined: Sun Sep 29, 2019 1:44 pm

Re: WRC 7 .P3D models

Post by Ha3aP »

WRC8 it's medot work?
Help pls!

update:
Work, but how extract texture?
Mrbig155
Posts: 2
Joined: Mon Feb 03, 2020 2:29 pm

Re: WRC 7 .P3D models

Post by Mrbig155 »

I'm having troubles exporting to obj file format from WRC8. I've extracted pkg packs to p3d files, but I can convert p3d files to a proper file format to use in 3ds max like obj.
Anyone can help me?
Thanks in advance.
@huckleberrypie I saw your screenshot of the Yaris from 3ds max in a previous post, how have you imported?
huckleberrypie
Posts: 37
Joined: Sun Nov 11, 2018 2:27 am

Re: WRC 7 .P3D models

Post by huckleberrypie »

Mrbig155 wrote:I'm having troubles exporting to obj file format from WRC8. I've extracted pkg packs to p3d files, but I can convert p3d files to a proper file format to use in 3ds max like obj.
Anyone can help me?
Thanks in advance.
@huckleberrypie I saw your screenshot of the Yaris from 3ds max in a previous post, how have you imported?

I used the Blender 2.45 script after extracting them archives.
Mrbig155
Posts: 2
Joined: Mon Feb 03, 2020 2:29 pm

Re: WRC 7 .P3D models

Post by Mrbig155 »

I've tried also with blender but it seems there's a problem with phyton.
Possibly a version mismatch problem?
I've installed latest blender version + phyton 2.6.6.
Thanks
Ha3aP
Posts: 5
Joined: Sun Sep 29, 2019 1:44 pm

Re: WRC 7 .P3D models

Post by Ha3aP »

Pls help open archive WRC Generations, wrc7.bms don't work ((
https://drive.google.com/file/d/1oABy5s ... share_link
the_keane
Posts: 3
Joined: Sun Nov 27, 2022 2:34 pm

Re: WRC 7 .P3D models

Post by the_keane »

I keep getting this error when importing the models from Generations, it works with no problem with WRC10.. any idea why this happens please?

Thank you!