XeNTaX http://forum.xentax.com/ 

Very Basic model format conversion (Shaiya). http://forum.xentax.com/viewtopic.php?f=29&t=3739 
Page 1 of 2 
Author:  chrrox [ Sun Sep 27, 2009 1:45 am ] 
Post subject:  Very Basic model format conversion (Shaiya). 
In this tutorial you will learn the VERY basic way to convert a 3d model into verts that can be loaded into a 3d application. I hope to expand on these tutorials and use better tools to automate the job and code it completely proper. for this tutorial you will need a few tools 1. Float 2 text download/file.php?id=1888 2. HxD (free hex editor) 3 excel (2007) 4 Deep exploration (program able to view an obj with just verts 5 some shaiya model files. download/file.php?id=2187 1) Ok so open the model folder after you extract them and open the file demf_boots001.3DC in the program HxD 2)Now if we know the model format lets see how to break it down Quote: #Provided from Fatduck dword constant00 dword numBones struct Bone { float_16 Matrix4X4 } dword numVerts struct Vert { float_3 CoordXYZ float Weight byte BoneID01 byte BoneID02 byte NULL1 byte NULL2 float_3 NormalXYZ float_2 TexCoordUV } dword numFaces struct Face { word_3 FaceIndices123 } 3) a dword is 4 bytes a 32 bit float (these are 32 bit floats) is equal to 4 bytes float_X is the number of floats in a row so float_2 would be 8 bytes and a byte is 1 byte a word is 2 bytes 4) So knowing this lets look at the first line dword constant00 this tells us our first 4 bytes are 00 and if we check this they are 5) The next line is dword numBones so the Number of bones is in the next 4 bytes which shows us 2C 00 00 00 so that converts into 00 00 00 2C and 2C in decimal is 44 so now we know we have 44 bones 6) The next part is struct Bone { float_16 Matrix4X4 } so this means we have a float which is 4 bytes then the underscore 16 means each bone has 16 floats so in decimal we do 4 x 16 = 64 then we convert this number to hex which is 0x40 we multiply 0x40 bye the number of bones 2C and we get B00 If you highlight this section you should get a screen looking just like mine 7) The next line is dword numVerts this means the next 4 bytes tell us how many verts we will have in our model so we take AE 01 00 00 and convert it to 00 00 01 AE and that equals 430 so there are 430 vertexes. 8 The next line is the most important for the tutorial float_3 CoordXYZ this means we have a float which is 4 bytes and we have 3 in a row representing x , y z coordinates. so our first set of cordiantes should look like this X)FE F8 A1 BE Y)00 00 C8 36 Z)4A CA BF BD 9) The next line float Weight means the next 4 bytes are the weighting information 00 00 80 3F 10) the next 4 lines tell us what bones our weighting information has influence on byte BoneID01 byte BoneID02 byte NULL1 byte NULL2 22 00 00 00 break these apart byte by byte so this vertex is effected bye bone 22 and 00 you can ignore the NULL parts 11)This next line tells us our normal coordinates float_3 NormalXYZ it is a float value so its 4 bytes and it is in a series of 3 so its 12 bytes total X)08 7D 7D BF Y)E2 5A 0D 3E Z)AC 99 B1 BC 12) The last line of the vertex definition tells us our UV coordinates. float_2 TexCoordUV U)BB DA 08 3F V)F2 60 7A 3F so it is again a float of 4 bytes and there are 2 in a row so it is 8 bytes total 13) The next line tells us how many faces we have dword numFaces so it is a dword of 4 bytes 98 01 00 00 so convert it to 00 00 01 98 and in decimal that is 408 so we have 408 Faces 14)The next 2 lines tell us the face structure struct Face { word_3 FaceIndices123 } so we have a word 2 bytes and 3 in a row so thats 6 bytes so 408 / 3 = 158 15) Now to the converting the vertex part highlight the whole vertex section and copy it into a new hxd file called vertex.dat start offset B0C end offset 4E3B length 4330 16)now we use float2txt on our dat file float2txt.exe vertex.dat vertex.txt 10 we take the arguments float2txt.exe input file output file number of floats we choose 10 because there are 10 groups of 4 bytes that make up our vertex structure. 17)now we open excel and it will ask is this a delimited file choose tab and space check boxes and hit import. you will end up with columns a  j 18)delete columns d  j so you are only left with a b and c inert a column before a and fill it with the letter v until you reach the end of your vertex list (line 430) 19) save the file as a csv file open the file in hxd do a replace and replace in hex 2C with 20 and save the file as testobj.txt 20)now open your file in wordpad and paste the following header Code: # 3ds Max Wavefront OBJ Exporter v0.94b  (c)2007 guruware # File Created: 26.09.2009 19:47:31 mtllib test.mtl # # object NET # and at the end of your file put Code: # 430 vertices ok now save your file as test.obj 21)Open your file in deep exploration and see the boots 
Author:  ResiHax [ Sun Sep 27, 2009 1:47 am ] 
Post subject:  Re: Very Basic model format conversion (Shaiya). 
Hope to see this completed. Now, converting models into a usable file is one thing, but how about converting them back to their original file? Then we'd be good. Unless there's a tutorial on this and I can't see it. 
Author:  chrrox [ Sun Sep 27, 2009 2:20 am ] 
Post subject:  Re: Very Basic model format conversion (Shaiya). 
I will attempt to make more tutorials this one is done for now. and I will try to teach people how to do this in max script or a simple model viewer code. 
Author:  pixellegolas [ Mon Sep 28, 2009 3:38 pm ] 
Post subject:  Re: Very Basic model format conversion (Shaiya). 
This is really great info. Probably easy to use because you showed all commands from fatduck but maybe hard to do by your own from scratch But still, impressive 
Author:  chrrox [ Fri Oct 02, 2009 2:55 am ] 
Post subject:  Re: Very Basic model format conversion (Shaiya). 
I will write a max script import tutorial soon for shaiya so you can see how it is done. 
Author:  ParsEmAll [ Wed Oct 14, 2009 10:43 pm ] 
Post subject:  Re: Very Basic model format conversion (Shaiya). 
Thanks you for this tutorial. chrrox wrote: 14)The next 2 lines tell us the face structure struct Face { word_3 FaceIndices123 } so we have a word 2 bytes and 3 in a row so thats 6 bytes so 408 / 3 = 158 looks like this should be: we have 408 faces, which have 408 * 3 = 1224 vertex index numbers in total of a length of 2 bytes each. Looking forward for your next tutorial about importing it to max, since I had some issues with the converter:  I had to trow away the first vertex (v), vertex uv's (vt) and vertex normal (vn) in order to get the mesh loaded visually correct.  I needed to flip the uv verticaly too Thank you again (and Fatduck of curse) Just for fun I made a command line tool to automate this. Here are some some results: 
Author:  Corwin [ Sun Oct 18, 2009 5:29 am ] 
Post subject:  Re: Very Basic model format conversion (Shaiya). 
Thanks for tutorial. As i understand, this method can be used for exploring file format. Right? I can check if some portion of data represents vertexes, but how about triangles, bones and normals? Then we'd be good. Also. Quote: 19) save the file as a csv file open the file in hxd do a replace and replace in hex 2C with 20 There is a better way to do this. Just choose space delimeter instead of comma when you save file as csv. P.S. Moar tutorials like this please 
Author:  shekofte [ Tue Oct 20, 2009 5:01 pm ] 
Post subject:  Re: Very Basic model format conversion (Shaiya). 
DEAR chrrox please insert the images in full size , because for saving the tutorials , for offline reading ! 
Author:  potemkis [ Fri Oct 30, 2009 4:14 am ] 
Post subject:  Re: Very Basic model format conversion (Shaiya). 
Any word on a maxscript for this? 
Author:  chrrox [ Sun Dec 06, 2009 3:34 am ] 
Post subject:  Re: Very Basic model format conversion (Shaiya). 
Here is a max script that will work on these files Code: fname = "C:\\temp\\test.3dc" file name f = fopen fname "rb" open file in read only format Vert_array = #() define arrays for verts, normals, UV and Faces Normal_array = #() UV_array = #() Face_array = #() Weight_array = #() Bone_array = #() fseek f 4 #seek_cur bray = readlong f for i = 1 to bray do ( * number of Bones b1 = readfloat f b2 = readfloat f b3 = readfloat f b4 = readfloat f b5 = readfloat f b6 = readfloat f b7 = readfloat f b8 = readfloat f b9 = readfloat f b10 = readfloat f b11 = readfloat f b12 = readfloat f b13 = readfloat f b14 = readfloat f b15 = readfloat f b16 = readfloat f ) vray = readlong f for i = 1 to vray do ( vx = readfloat f read xyz coordinates vy = readfloat f vz = readfloat f append Vert_array [vx,vy,vz] save verts to Vert_array w1 = readfloat f bo1 = readbyte f bo2 = readbyte f bo3 = readbyte f bo4 = readbyte f append Weight_array [w1,bo1,bo2,bo3,bo4] nx = readlong f read Normal ny = readlong f nz = readlong f append Normal_array [nx,ny,nz] save normals to Normal_array tu = (readfloat f) * 1 read UV float value tv = (readfloat f) * 1 append UV_array [tu,tv,0] save UVs to UV_array ) nray = readlong f for i = 1 to nray do ( f1 = (readshort f) + 1 read face indices, games are start form 0, but Max start from 1 f2 = (readshort f) + 1 so we add 1 to each index f3 = (readshort f) + 1 append Face_array [f1,f2,f3] save faces to Face_array ) fclose f close file msh = mesh vertices:Vert_array faces:Face_array build mesh msh.numTVerts = UV_array.count buildTVFaces msh for j = 1 to UV_array.count do setTVert msh j UV_array[j] for j = 1 to Face_array.count do setTVFace msh j Face_array[j] for j = 1 to Normal_array.count do setNormal msh j Normal_array[j] 
Author:  shekofte [ Sun Dec 06, 2009 10:01 am ] 
Post subject:  Re: Very Basic model format conversion (Shaiya). 
is there any script or MEL for maya that works in similar way ? thanks 
Author:  djoscar [ Sat Mar 20, 2010 2:02 pm ] 
Post subject:  Re: Very Basic model format conversion (Shaiya). 
Wow thanks a lot of this! What I would also love is a nice tutorial on writing an import maxscript for 3d models 
Author:  huckleberrypie [ Mon Aug 02, 2010 11:36 pm ] 
Post subject:  Re: Very Basic model format conversion (Shaiya). 
This can also apply to any 3D format once you know its structure, right? 
Author:  SoftIce [ Thu Feb 24, 2011 9:43 pm ] 
Post subject:  Re: Very Basic model format conversion (Shaiya). 
Thanks so much for the tutorial! You are awesome! I still suck at most of this, but having things spelled out with lots of pictures helps a whole lot. 
Author:  linpost [ Thu Jul 21, 2011 7:09 am ] 
Post subject:  Re: Very Basic model format conversion (Shaiya). 
i dont understand how you know 2C meens 44 bones, i have 3C an i dont see anywhere a number or i dont know 
Page 1 of 2  All times are UTC + 1 hour 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ 