XeNTaX Forum Index
Forum MultiEx Commander Tools Tools Home
It is currently Thu Nov 23, 2017 1:22 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Very Basic model format conversion (Shaiya).
PostPosted: Sun Sep 27, 2009 1:45 am 
Offline
Moderator
User avatar

Joined: Sun May 18, 2008 3:01 pm
Posts: 2444
Has thanked: 56 times
Have thanks: 1192 times














You can make the ads go away by registering

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
Image

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
Image
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
Image
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.
Image
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
Image
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
Image
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 :)
Image


Attachments:


You do not have the required permissions to view the files attached to this post. Register to gain access.



Last edited by chrrox on Thu Oct 01, 2009 1:03 am, edited 4 times in total.

Top
 Profile  
 
 Post subject: Re: Very Basic model format conversion (Shaiya).
PostPosted: Sun Sep 27, 2009 1:47 am 
Offline
n00b
User avatar

Joined: Sun Sep 27, 2009 12:54 am
Posts: 16
Has thanked: 5 times
Have thanks: 0 time
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.


Top
 Profile  
 
 Post subject: Re: Very Basic model format conversion (Shaiya).
PostPosted: Sun Sep 27, 2009 2:20 am 
Offline
Moderator
User avatar

Joined: Sun May 18, 2008 3:01 pm
Posts: 2444
Has thanked: 56 times
Have thanks: 1192 times
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.


Top
 Profile  
 
 Post subject: Re: Very Basic model format conversion (Shaiya).
PostPosted: Mon Sep 28, 2009 3:38 pm 
Offline
ultra-veteran
ultra-veteran

Joined: Mon Aug 11, 2008 11:30 pm
Posts: 421
Has thanked: 23 times
Have thanks: 13 times
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 :)


Top
 Profile  
 
 Post subject: Re: Very Basic model format conversion (Shaiya).
PostPosted: Fri Oct 02, 2009 2:55 am 
Offline
Moderator
User avatar

Joined: Sun May 18, 2008 3:01 pm
Posts: 2444
Has thanked: 56 times
Have thanks: 1192 times
I will write a max script import tutorial soon for shaiya so you can see how it is done.
Image


Top
 Profile  
 
 Post subject: Re: Very Basic model format conversion (Shaiya).
PostPosted: Wed Oct 14, 2009 10:43 pm 
Offline
ultra-n00b

Joined: Wed Oct 14, 2009 9:57 pm
Posts: 1
Has thanked: 1 time
Have thanks: 0 time
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:
Image
Image


Top
 Profile  
 
 Post subject: Re: Very Basic model format conversion (Shaiya).
PostPosted: Sun Oct 18, 2009 5:29 am 
Offline
beginner
User avatar

Joined: Mon Sep 28, 2009 7:52 pm
Posts: 21
Location: Amber
Has thanked: 11 times
Have thanks: 5 times
Thanks for tutorial. :keke:
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 :]

_________________
All your packages is belong to us!


Top
 Profile  
 
 Post subject: Re: Very Basic model format conversion (Shaiya).
PostPosted: Tue Oct 20, 2009 5:01 pm 
Offline
mega-veteran
mega-veteran
User avatar

Joined: Sun Jan 18, 2009 1:45 pm
Posts: 205
Location: Sagittarius
Has thanked: 201 times
Have thanks: 12 times
DEAR chrrox please insert the images in full size , because for saving the tutorials , for offline reading !

_________________
ILLUSORY VIDEO GAMES ARE MORE IMPORTANT THAN PRECIOUS INTERNATIONAL FOOTBALLs


Top
 Profile  
 
 Post subject: Re: Very Basic model format conversion (Shaiya).
PostPosted: Fri Oct 30, 2009 4:14 am 
Offline
beginner

Joined: Sun Mar 01, 2009 7:11 am
Posts: 24
Has thanked: 3 times
Have thanks: 0 time
Any word on a maxscript for this?


Top
 Profile  
 
 Post subject: Re: Very Basic model format conversion (Shaiya).
PostPosted: Sun Dec 06, 2009 3:34 am 
Offline
Moderator
User avatar

Joined: Sun May 18, 2008 3:01 pm
Posts: 2444
Has thanked: 56 times
Have thanks: 1192 times
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]


Top
 Profile  
 
 Post subject: Re: Very Basic model format conversion (Shaiya).
PostPosted: Sun Dec 06, 2009 10:01 am 
Offline
mega-veteran
mega-veteran
User avatar

Joined: Sun Jan 18, 2009 1:45 pm
Posts: 205
Location: Sagittarius
Has thanked: 201 times
Have thanks: 12 times
is there any script or MEL for maya that works in similar way ?
:wv: thanks

_________________
ILLUSORY VIDEO GAMES ARE MORE IMPORTANT THAN PRECIOUS INTERNATIONAL FOOTBALLs


Top
 Profile  
 
 Post subject: Re: Very Basic model format conversion (Shaiya).
PostPosted: Sat Mar 20, 2010 2:02 pm 
Offline
beginner

Joined: Thu Dec 17, 2009 9:59 am
Posts: 30
Has thanked: 0 time
Have thanks: 0 time
Wow thanks a lot of this!

What I would also love is a nice tutorial on writing an import maxscript for 3d models :)


Top
 Profile  
 
 Post subject: Re: Very Basic model format conversion (Shaiya).
PostPosted: Mon Aug 02, 2010 11:36 pm 
Offline
mega-veteran
mega-veteran

Joined: Mon Apr 26, 2010 6:51 am
Posts: 250
Has thanked: 61 times
Have thanks: 12 times
This can also apply to any 3D format once you know its structure, right?


Top
 Profile  
 
 Post subject: Re: Very Basic model format conversion (Shaiya).
PostPosted: Thu Feb 24, 2011 9:43 pm 
Offline
veteran
User avatar

Joined: Sun Jan 23, 2011 5:31 am
Posts: 97
Has thanked: 2 times
Have thanks: 2 times
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. :)


Top
 Profile  
 
 Post subject: Re: Very Basic model format conversion (Shaiya).
PostPosted: Thu Jul 21, 2011 7:09 am 
Offline
ultra-n00b

Joined: Thu Jul 21, 2011 6:37 am
Posts: 1
Has thanked: 0 time
Have thanks: 0 time
i dont understand how you know 2C meens 44 bones, i have 3C an i dont see anywhere a number or i dont know


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group