SMD file format: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
m (Fixing double redirect. This action was performed by a bot.)
Tag: Redirect target changed
 
(10 intermediate revisions by 6 users not shown)
Line 1: Line 1:
ricreleltli
#REDIRECT [[SMD]]
The '''SMD''' ('''S'''tudio '''M'''odel '''D'''ata) file format is a text-based format for storing model information. SMD files are carriage return sensitive &mdash; each line must end with a carriage return. The file should also include at least one carriage return after the final end statement. White space is the only delimiter; any combination of tabs and spaces can be used to separate values, and for this reason multiword names should be enclosed in quotation marks (<code>"</code>).
 
==Two versions of SMD and VTA==
SMD files come in two flavors, Reference and Animation files. Although one file can contain both.
 
The '''Reference SMD''' file is a complete snapshot of the model, including its geometry, its skeletal structure, one animation frame to describe the position of the skeletal bones, its texture, and the links between its mesh vertices and its skeleton. Reference SMDs do not contain any animation data &mdash; they produce only a static image of the complete model at one point in time.
 
The '''Animation SMD''' omits the triangle and texture map data and contains only animation and skeletal data.
 
In addition, [[VTA]] files (facial animation) use a similar format to SMD, but contains only vertex animation data.
 
==SMD file sections==
Here are the sections of an SMD file, considered in order:
 
===Header data===
The only header data required is the tag <code>version 1</code> in the first line of the file. This is compatible with both [[HL1]] and [[HL2]].
 
===Node tree data===
Builds a list of all the bones in the skeleton. Each bone has a unique ID number, a unique text name and a pointer to the ID number of its parent. Children of the world use <code>–1</code> as their parent ID. ID numbers are integers (starting from 0). Names are text, enclosed in quotes. Names may contain spaces.
 
*<code>nodes</code>
:Starts the node tree data block.
*<code>''<ID>'' "''Bone Name''" ''<parent ID>''</code>
:<code>''<ID>''</code> is a the ID number for this bone. <code>"''Bone Name''"</code> is a text name for the bone, enclosed in quotes. <code>''<parent ID>''</code> is the ID number of the bone’s parent. Children of the world (unparented objects) have a parent ID of <code>-1</code>.
*<code>end</code>
:Ends the node tree data block.
 
===Skeleton Pose data===
This block contains the position and rotation data for every bone in the skeleton. In an animation SMD there will be a "time" block for every frame in the animation. In reference SMDs there will only be one time block.
 
The skeleton block is begun by the <code>skeleton</code> tag and ended by an <code>end</code> tag. A time block begins with <code>time ''<frame>''</code> and end when a new "time" tag is encountered.
 
Each frame is defined by a line telling the frame number, eg <code>time 0</code>, followed by the bone's new position and rotations. The frame will end when a new one is defined or the end of the skeleton tree is reached. The frames doesn't have to start at 0 (it can also be negative), but they have to increase in numbers. Frames may be skiped, they will then be lineary interpolated instead.
 
*<code>Skeleton</code>
:Begins the skeleton pose block.
*<code>Time 0</code>
:Begins this time block
*<code>''<ID>'' ''<PosX>'' ''<PosY>'' ''<PosZ>'' ''<RotX>'' ''<RotY>'' ''<RotZ>''</code>
:<code>''<ID>''</code> is the bone ID. <code>''<PosX>'' ''<PosY>'' ''<PosZ>''</code> is the position in world units (good to 6 significant digits). <code>''<RotX>'' ''<RotY>'' ''<RotZ>''</code> are local Euler rotations in radians. Bones which are not children of the world report their position and rotations in their parent's local space.
*<code>Time 1</code>
:Begins the next time block. Any bone without changes from the last frame doesn't have to be entered, but will be lineary interpolated if a new position is later defined.
*<code>end</code>
:Ends skeleton pose block.
 
===Triangle block===
The triangle block contains a list of triangles. Each triangle is preceded by a texture file name (filename only &mdash; path data is supplied in the QC file as <code>$cdmaterials</code>). Each vertex of the triangle then reports its parent bone’s ID (Bone with the hightes weights value), the vertex's position, the vertex's texture coordinates, its normals, and bone weights (bone weights can be ommited per vertex).
 
The Triangle block is begun with the <code>triangles</code> tag and ends with the <code>end</code> tag.
 
*<code>Triangles</code>
:Begins the triangle block
*<code>''texturename''.*</code>
:Name of the texture file for the texture assigned to this face, including the file suffix like <code>.tga</code>. Do not enclose in quotes.
*<code>''<Parent>'' ''<PosX>'' ''<PosY>'' ''<PosZ>'' ''<NormX>'' ''<NormY>'' ''<NormZ>'' ''<TexU>'' ''<TexV>'' ''<# of links>'' ''<bone ID>'' ''<weight>'' ''[...]''</code>
:<code>''<Parent>''</code> is the ID number of the vertex's parent bone. <code>''<PosX>'' ''<PosY>'' ''<PosZ>''</code> is the position of the vertex in world space. <code>''<NormX>'' ''<NormY>'' ''<NormZ>''</code> are the components of the vertex's normal vector (used for smoothing the suface). <code>''<TexU>''</code> and <code>''<TexV>''</code> are the texture coordinates for this vertex.
:<code>''<bone ID>'' ''<weight>''</code> will be looped at the end of each vertex ''<# of links>'' times.
:If the weights don't add up to 1.0 the rest will be assigned to the ''<Parent>'' bone. Same if no ''<# of links>'' is defined or if it is 0.
:Each triangle contains 3 vertex records.
*<code>''nextTextureName''.tga</code>
:new texture file begins a new triangle listing
*<code>end</code>
:ends triangle block.
 
===Vertex Animation Files===
Theas files (.VTA) contains the position and normal data for every vertex in the model. There will be a "time" block for every frame in the vertex animation.
 
The vertex animation is begun by the <code>vertexanimation</code> tag and ended by an <code>end</code> tag. Time block begin with <code>time ''<frame>''</code> and end when a new "time" tag is encountered or the end of the vertex animation block is reached.
 
*<code>vertexanimation</code>
:Begins the vertex animation block
*<code>Time 0</code>
:Begins this time block. Time 0 serves as vertex index, so it should have all verts of the model giving a index number for each.
*<code>''<ID>'' ''<PosX>'' ''<PosY>'' ''<PosZ>'' ''<NormX>'' ''<NormY>'' ''<NormZ>''</code>
:<code>''<ID>''</code> is the vertex ID. <code>''<PosX>'' ''<PosY>'' ''<PosZ>''</code> is the position in world units (good to 6 significant digits). <code>''<NormX>'' ''<NormY>'' ''<NormZ>''</code> are the components of the vertex's normal vector
 
*<code>Time 1</code>
:Begins next time block.
*<code>end</code>
:Ends vertex animation block
 
[[Category:Modeling]]

Latest revision as of 15:28, 21 January 2024

Redirect to: