Je poste cette explication que j'ai fait il y a peu de temps, je suis désolé elle est en anglais et j'ai pas eu le temps de la traduire .....
J'ai mis ce code sous vb car je donne les differents type en vb a la fin du tuto.
Source / Exemple :
First, I'm going to describe variables which will be used along explanation, then I will explain how the file is structured.
Bytes / Visual basic / C ++
1 byte / Byte / Byte
2 bytes / Integer / Word
4 bytes / Long / DWord
4 bytes floating / Single Float
8 bytes floating / Double Double
Multiple text size / String / Char
A vector is in fact a compound of three compononents : x = 4 bytes floating, y = 4 bytes floating and z = 4 bytes floating.
MilkShape 3d File structure :
Now, I shall say you how a ms3d is writen, or how you can read it.
The firts bytes in a ms3d file describes the header
10 bytes are reserved for identification, the value is = MS3D000000
in vb it's Dim Id as String * 10 and in c++ char Id[10]
2 bytes are used for the file's version, here the value is = 8
Then you can get the vertices :
2 bytes are reserved for an uknown use (in the most case the value is 0)
First 2 bytes decribe the vertices' numbers
Then, for each vertices :
a flag As Byte
x As Single
y As Single
z As Single
Bone As Byte
reference As Byte
After vertices you can retrieve the triangles :
Firsts 2 bytes are use for the number of vertices
Then, for each vertices :
flag As Integer
IndiceVertex0 As Integer
IndiceVertex1 As Integer
IndiceVertex2 As Integer
a little sophisticated, you can put in order the next bytes in a table :
NormalVertex_0_X NormalVertex_0_Y NormalVertex_0_Z
NormalVertex_1_X NormalVertex_1_Y NormalVertex_1_Z
NormalVertex_2_X NormalVertex_2_Y NormalVertex_2_Z
In fact it's 3 vectors for the normal of the triangle, with Single property
tu1 As Single
tu2 As Single
tv1 As Single
tv2 As Single
SmoothingGroup As Byte
IndexGroup As Byte
You have got the triangles, now groups :
Like other parts, the number of groups is reffered on 2 bytes
Then for each vertex :
Flag As Integer
Name as string (32 bytes max)
NumberTriangles As Integer
TrianglesIndices as Integer, it's also a large table he have the dimension of NumberTriangles - 1
MaterialIndex as byte, if is equal to -1 then no material
Now material "chunk" :
Number of Material As Integer
Only if the number is > 1 then for each vertices :
Name As String (32 bytes max)
AmbientX As Single
AmbientY As Single
AmbientZ As Single
DiffusX As Single
DiffusY As Single
DiffusZ As Single
SpeculaireX As Single
SpeculaireY As Single
SpeculaireZ As Single
EmetteurX As Single
EmetteurY As Single
EmetteurZ As Single
Glow As Single
Transparency As Single
Mode As String
Texture As String (128 bytes max)
MapAlpha As String (128 bytes max)
You have got the material, you have few information about animation :
Frame per Seconde As Single
Current Time for the animation (the frame selected ??) As Single
Frame's Number As Long '<-- Before i have make a mistake (Integer)
You ARE almost finished, remains the bones :
Number of Bone in the scene As Integer
Flag As Byte
Name As String (32 byte max)
Parent's Name As String (32 byte max)
RotationX As Single
RotationY As Single
RotationZ As Single
PositionX As Single
PositionY As Single
PositionZ As Single
Number of key frame for rotation As Integer
Number of key frame for translation As Integer
KeyFrame for rotation :
Time as Single
RotationX as Single
RotationY as Single
RotationZ as Single
KeyFrame for transformation :
Time as Single
PositionX as Single
PositionY as Single
PositionZ as Single
A last accuracy, for all flags, in fact it's an information about selected or hidden.
I hope you have succeeded in your project and that my english is not too bad or weird ...
Here you can find the variable of my explanation:
Voiçi donc les différentes variables correspondant à mon explication :
Public Type ms3D_header
ID As String * 10
version As Integer
End Type
Public Type ms3D_vertex
drapeau As Byte
X As Single '<--- Ou Coordonée as D3DVECTOR
Y As Single
Z As Single
Bone As Byte
reference As Byte
End Type
Public Type ms3d_Triangle
drapeau As Integer
IndiceVertex(2) As Integer
NormalVertex(2, 2) As Single
Tu(2) As Single
Tv(2) As Single
GroupeLissage As Byte
IndexGroup As Byte
End Type
Public Type ms3d_edge
IndiceEdge(1) As Integer
End Type
Public Type ms3d_group
Flag As Byte 'Selectionné/caché Select/Hide
name As String * 32
nbTriangle As Integer
triangleIndices() As Integer
materialIndex As Byte '-1 pas de materiel -1 = No material
End Type
Public Type ms3d_material
Nom As String * 32
Ambient(3) As Single
Diffus(3) As Single
Speculaire(3) As Single
Emetteur(3) As Single
Brillant As Single
Transparence As Single
Mode As String
Texture As String * 128
MapAlpha As String * 128
End Type
Public Type ms3d_framecle_rot
Durée As Single
Rotation As D3DVECTOR
End Type
Public Type ms3d_framecle_trans
Durée As Single
Rotation As D3DVECTOR
End Type
Public Type ms3d_Struct
Flag As Byte ' Sélectionné ou non
Nom As String * 32
NomParrent As String * 32
RotationX As Single
RotationY As Single
RotationZ As Single
PositionX As Single
PositionY As Single
PositionZ As Single
NbrFrameCléRotation As Integer
NbrFrameCléTranslation As Integer
FrameCleRotation() As ms3d_framecle_rot
FrameCleTranslation() As ms3d_framecle_trans
End Type
Public Entete As ms3D_header
Public Vertices() As ms3D_vertex
Public Triangles() As ms3d_Triangle
Public Edge() As ms3d_edge
Public Group() As ms3d_group
Public Materiaux() As ms3d_material
Public Structure() As ms3d_Struct
Public NbrVertices As Integer
Public NbrTriangles As Integer
Public NbrGroup As Integer
Public NbrMateriaux As Integer
Public NbrStructure As Integer
Public FPS As Single
Public TempsCourrant As Single
Public NbrFrame As Long '<--- Before i have make a mistake (Integer)
Conclusion :
Je sais pas si il y a de bug dans mes explications, si vous en voyez faite moi le savoir.
J'ai couvert l'ensemble du fichier il me semble.
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.