Wavefront .obj file: Difference between revisions
m Reverted edits by 188.4.151.137 (talk) to last version by Glrx |
|||
Line 31: | Line 31: | ||
The OBJ file format is a simple data-format that represents 3D geometry alone — namely, the position of each vertex, the UV position of each texture coordinate vertex, vertex normals, and the faces that make each polygon defined as a list of vertices, and texture vertices. Vertices are stored in a counter-clockwise order by default, making explicit declaration of face normals unnecessary. OBJ coordinates have no units, but OBJ files can contain scale information in a human readable comment line. |
The OBJ file format is a simple data-format that represents 3D geometry alone — namely, the position of each vertex, the UV position of each texture coordinate vertex, vertex normals, and the faces that make each polygon defined as a list of vertices, and texture vertices. Vertices are stored in a counter-clockwise order by default, making explicit declaration of face normals unnecessary. OBJ coordinates have no units, but OBJ files can contain scale information in a human readable comment line. |
||
== File format == |
|||
class 1 gk_global : teleporter |
|||
Lines beginning with a hash character (#) are comments. |
|||
property_define_begin |
|||
telposlist_begin Position |
|||
{"Coliseum"; 146440; 46723; -3400; 0; 0 } |
|||
{"Giran Arena"; 73579; 142709; -3768; 0; 0 } |
|||
{"Gludin Arena"; -87297; 142365; -3648; 0; 0 } |
|||
telposlist_end |
|||
telposlist_begin PositionNoblessNoItemTown |
|||
{"Talking Island Village"; -84141; 244623; -3729; 0; 0 } |
|||
{"Elven Village"; 46951; 51550; -2976; 0; 0 } |
|||
{"Dark Elven Village"; 9709; 15566; -4500; 0; 0 } |
|||
{"Orc Village"; -45158; -112583; -236; 0; 0 } |
|||
{"Dwarven Village"; 115120; -178224; -917; 0; 0 } |
|||
{"Gludin Village"; -80826; 149775; -3043; 0; 0 } |
|||
{"Gludio Castle Town"; -12694; 122776; -3114; 0; 0 } |
|||
{"Town of Dion"; 15671; 142994; -2704; 0; 0 } |
|||
{"Giran Castle Town"; 83382; 147983; -3400; 0; 0 } |
|||
{"Giran Harbor"; 47935; 186810; -3420; 0; 0 } |
|||
{"Heine"; 111455; 219400; -3546; 0; 0 } |
|||
{"Hunters Village"; 117088; 76931; -2670; 0; 0 } |
|||
{"Town of Oren"; 83011; 53207; -1470; 0; 0 } |
|||
{"Ivory Tower"; 85343; 16267; -3640; 0; 0 } |
|||
{"Town of Aden"; 146783; 25808; -2000; 0; 0 } |
|||
{"Town of Goddard"; 147978; -55408; -2728; 0; 0 } |
|||
{"Rune Township"; 43826; -47688; -792; 0; 0 } |
|||
{"Town of Schuttgart"; 87093; -143329; -1288; 0; 0 } |
|||
telposlist_end |
|||
telposlist_begin PositionNoblessNoItemField |
|||
{"Elven Ruins [Lv 10-20]"; 48586; 248459; -6160; 0; 0 } |
|||
{"Elven Fortess [Lv 10-20]"; 27630; 74962; -3808; 0; 0 } |
|||
{"Execution Grounds [Lv 20-40]"; 44589; 148484; -3696; 0; 0 } |
|||
{"Fortress Resistance [Lv 25-35]"; 48651; 111342; -2128; 0; 0 } |
|||
{"Aligator Island [Lv 35-45]"; 115309; 190650; -3584; 0; 0 } |
|||
{"Death Pass [Lv 40-50]"; 71411; 118056; -3672; 0; 0 } |
|||
{"Cruma Tower [Lv 35-45]"; 17209; 114182; -3440; 0; 0 } |
|||
{"Hardin's Private Academic [Lv 35-50]"; 105918; 109759; -3208; 0; 0 } |
|||
{"Enchanted Valley [Lv 45-55]"; 124904; 61992; -3920; 0; 0 } |
|||
{"Frozen Labyrinth [Lv 50-60]"; 111584; -111996; -1320; 0; 0 } |
|||
{"The Forbidden Gateway [Lv 54-65]"; 185319; 20218; -3264; 0; 0 } |
|||
{"Antharas Lair [Lv 50-75]"; 131152; 114471; -3720; 0; 0 } |
|||
{"Blazing Swamp [Lv 65-75]"; 159455; -12931; -2872; 0; 0 } |
|||
{"Silent Valley [Lv 65-75]"; 170866; 55794; -5240; 0; 0 } |
|||
{"Swamp of Scream [Lv 70-75]"; 70479; -49999; -3272; 0; 0 } |
|||
{"Valley of Saints [Lv 65-70]"; 81278; -75070; -3728; 0; 0 } |
|||
{"Primeval Isle [Lv 70-75]"; 6993; -22078; -3336; 0; 0 } |
|||
telposlist_end |
|||
telposlist_begin PositionNoblessNoItemSSQ |
|||
{"Giants Cave [Lv 79-85]"; 183505; 47449; 4368; 0; 0 } |
|||
telposlist_end |
|||
property_define_end |
|||
class_end |
|||
# this is a comment |
|||
class 1 gk_global : teleporter |
|||
property_define_begin |
|||
telposlist_begin Position |
|||
{"Coliseum"; 146440; 46723; -3400; 0; 0 } |
|||
{"Giran Arena"; 73579; 142709; -3768; 0; 0 } |
|||
{"Gludin Arena"; -87297; 142365; -3648; 0; 0 } |
|||
telposlist_end |
|||
telposlist_begin PositionNoblessNoItemTown |
|||
{"Talking Island Village"; -84141; 244623; -3729; 0; 0 } |
|||
{"Elven Village"; 46951; 51550; -2976; 0; 0 } |
|||
{"Dark Elven Village"; 9709; 15566; -4500; 0; 0 } |
|||
{"Orc Village"; -45158; -112583; -236; 0; 0 } |
|||
{"Dwarven Village"; 115120; -178224; -917; 0; 0 } |
|||
{"Gludin Village"; -80826; 149775; -3043; 0; 0 } |
|||
{"Gludio Castle Town"; -12694; 122776; -3114; 0; 0 } |
|||
{"Town of Dion"; 15671; 142994; -2704; 0; 0 } |
|||
{"Giran Castle Town"; 83382; 147983; -3400; 0; 0 } |
|||
{"Giran Harbor"; 47935; 186810; -3420; 0; 0 } |
|||
{"Heine"; 111455; 219400; -3546; 0; 0 } |
|||
{"Hunters Village"; 117088; 76931; -2670; 0; 0 } |
|||
{"Town of Oren"; 83011; 53207; -1470; 0; 0 } |
|||
{"Ivory Tower"; 85343; 16267; -3640; 0; 0 } |
|||
{"Town of Aden"; 146783; 25808; -2000; 0; 0 } |
|||
{"Town of Goddard"; 147978; -55408; -2728; 0; 0 } |
|||
{"Rune Township"; 43826; -47688; -792; 0; 0 } |
|||
{"Town of Schuttgart"; 87093; -143329; -1288; 0; 0 } |
|||
telposlist_end |
|||
telposlist_begin PositionNoblessNoItemField |
|||
{"Elven Ruins [Lv 10-20]"; 48586; 248459; -6160; 0; 0 } |
|||
{"Elven Fortess [Lv 10-20]"; 27630; 74962; -3808; 0; 0 } |
|||
{"Execution Grounds [Lv 20-40]"; 44589; 148484; -3696; 0; 0 } |
|||
{"Fortress Resistance [Lv 25-35]"; 48651; 111342; -2128; 0; 0 } |
|||
{"Aligator Island [Lv 35-45]"; 115309; 190650; -3584; 0; 0 } |
|||
{"Death Pass [Lv 40-50]"; 71411; 118056; -3672; 0; 0 } |
|||
{"Cruma Tower [Lv 35-45]"; 17209; 114182; -3440; 0; 0 } |
|||
{"Hardin's Private Academic [Lv 35-50]"; 105918; 109759; -3208; 0; 0 } |
|||
{"Enchanted Valley [Lv 45-55]"; 124904; 61992; -3920; 0; 0 } |
|||
{"Frozen Labyrinth [Lv 50-60]"; 111584; -111996; -1320; 0; 0 } |
|||
{"The Forbidden Gateway [Lv 54-65]"; 185319; 20218; -3264; 0; 0 } |
|||
{"Antharas Lair [Lv 50-75]"; 131152; 114471; -3720; 0; 0 } |
|||
{"Blazing Swamp [Lv 65-75]"; 159455; -12931; -2872; 0; 0 } |
|||
{"Silent Valley [Lv 65-75]"; 170866; 55794; -5240; 0; 0 } |
|||
{"Swamp of Scream [Lv 70-75]"; 70479; -49999; -3272; 0; 0 } |
|||
{"Valley of Saints [Lv 65-70]"; 81278; -75070; -3728; 0; 0 } |
|||
{"Primeval Isle [Lv 70-75]"; 6993; -22078; -3336; 0; 0 } |
|||
telposlist_end |
|||
telposlist_begin PositionNoblessNoItemSSQ |
|||
{"Giants Cave [Lv 79-85]"; 183505; 47449; 4368; 0; 0 } |
|||
telposlist_end |
|||
property_define_end |
|||
class_end |
|||
An OBJ file contains several types of definitions: |
|||
class 1 gk_global : teleporter |
|||
property_define_begin |
|||
# List of Vertices, with (x,y,z[,w]) coordinates, w is optional and defaults to 1.0. |
|||
telposlist_begin Position |
|||
v 0.123 0.234 0.345 1.0 |
|||
{"Coliseum"; 146440; 46723; -3400; 0; 0 } |
|||
v ... |
|||
{"Giran Arena"; 73579; 142709; -3768; 0; 0 } |
|||
... |
|||
{"Gludin Arena"; -87297; 142365; -3648; 0; 0 } |
|||
# Texture coordinates, in (u ,v [,w]) coordinates, these will vary between 0 and 1, w is optional and default to 0. |
|||
telposlist_end |
|||
vt 0.500 1 [0] |
|||
telposlist_begin PositionNoblessNoItemTown |
|||
vt ... |
|||
{"Talking Island Village"; -84141; 244623; -3729; 0; 0 } |
|||
... |
|||
{"Elven Village"; 46951; 51550; -2976; 0; 0 } |
|||
# Normals in (x,y,z) form; normals might not be [[Unit normal|unit]]. |
|||
{"Dark Elven Village"; 9709; 15566; -4500; 0; 0 } |
|||
{"Orc Village"; -45158; -112583; -236; 0; 0 } |
|||
vn 0.707 0.000 0.707 |
|||
{"Dwarven Village"; 115120; -178224; -917; 0; 0 } |
|||
vn ... |
|||
{"Gludin Village"; -80826; 149775; -3043; 0; 0 } |
|||
... |
|||
{"Gludio Castle Town"; -12694; 122776; -3114; 0; 0 } |
|||
# Parameter space vertices in ( u [,v] [,w] ) form; free form geometry statement ( see below ) |
|||
{"Town of Dion"; 15671; 142994; -2704; 0; 0 } |
|||
vp 0.310000 3.210000 2.100000 |
|||
{"Giran Castle Town"; 83382; 147983; -3400; 0; 0 } |
|||
vp ... |
|||
{"Giran Harbor"; 47935; 186810; -3420; 0; 0 } |
|||
... |
|||
{"Heine"; 111455; 219400; -3546; 0; 0 } |
|||
# Face Definitions (see below) |
|||
{"Hunters Village"; 117088; 76931; -2670; 0; 0 } |
|||
f 1 2 3 |
|||
{"Town of Oren"; 83011; 53207; -1470; 0; 0 } |
|||
f 3/1 4/2 5/3 |
|||
{"Ivory Tower"; 85343; 16267; -3640; 0; 0 } |
|||
f 6/4/1 3/5/3 7/6/5 |
|||
{"Town of Aden"; 146783; 25808; -2000; 0; 0 } |
|||
f ... |
|||
{"Town of Goddard"; 147978; -55408; -2728; 0; 0 } |
|||
... |
|||
{"Rune Township"; 43826; -47688; -792; 0; 0 } |
|||
{"Town of Schuttgart"; 87093; -143329; -1288; 0; 0 } |
|||
=== Vertex positions (parameter space vertices) === |
|||
telposlist_end |
|||
Define points in parameter space of curve or surface. "u" only is required for curve points, "u" and "v" for surface points and control points of non-rational trimming curves, and "u", "v" and "w" (weight) for control points of rational trimming curves. |
|||
telposlist_begin PositionNoblessNoItemField |
|||
{"Elven Ruins [Lv 10-20]"; 48586; 248459; -6160; 0; 0 } |
|||
=== Face definitions === |
|||
{"Elven Fortess [Lv 10-20]"; 27630; 74962; -3808; 0; 0 } |
|||
Faces are defined using lists of vertex, texture and normal indices. Polygons such as quadrilaterals can be defined by using more than three vertex/texture/normal indices. |
|||
{"Execution Grounds [Lv 20-40]"; 44589; 148484; -3696; 0; 0 } |
|||
{"Fortress Resistance [Lv 25-35]"; 48651; 111342; -2128; 0; 0 } |
|||
OBJ files also support free form curved surface objects, such as [[NURBS]] surfaces. |
|||
{"Aligator Island [Lv 35-45]"; 115309; 190650; -3584; 0; 0 } |
|||
{"Death Pass [Lv 40-50]"; 71411; 118056; -3672; 0; 0 } |
|||
==== Vertex ==== |
|||
{"Cruma Tower [Lv 35-45]"; 17209; 114182; -3440; 0; 0 } |
|||
A valid vertex index starts from 1 and matches the corresponding vertex elements of a previously |
|||
{"Hardin's Private Academic [Lv 35-50]"; 105918; 109759; -3208; 0; 0 } |
|||
defined vertex list. Each face can contain three or more vertices. |
|||
{"Enchanted Valley [Lv 45-55]"; 124904; 61992; -3920; 0; 0 } |
|||
{"Frozen Labyrinth [Lv 50-60]"; 111584; -111996; -1320; 0; 0 } |
|||
f v1 v2 v3 v4 .... |
|||
{"The Forbidden Gateway [Lv 54-65]"; 185319; 20218; -3264; 0; 0 } |
|||
{"Antharas Lair [Lv 50-75]"; 131152; 114471; -3720; 0; 0 } |
|||
==== Vertex/texture-coordinate ==== |
|||
{"Blazing Swamp [Lv 65-75]"; 159455; -12931; -2872; 0; 0 } |
|||
Optionally, texture coordinate indices can be used to specify texture coordinates when defining a face. |
|||
{"Silent Valley [Lv 65-75]"; 170866; 55794; -5240; 0; 0 } |
|||
To add a texture coordinate index to a vertex index when defining a face, |
|||
{"Swamp of Scream [Lv 70-75]"; 70479; -49999; -3272; 0; 0 } |
|||
one must put a slash immediately after the vertex index and then put the |
|||
{"Valley of Saints [Lv 65-70]"; 81278; -75070; -3728; 0; 0 } |
|||
texture coordinate index. No spaces are permitted before or after the slash. |
|||
{"Primeval Isle [Lv 70-75]"; 6993; -22078; -3336; 0; 0 } |
|||
A valid texture coordinate index starts from 1 and matches the corresponding |
|||
telposlist_end |
|||
element in the previously defined list of texture coordinates. |
|||
telposlist_begin PositionNoblessNoItemSSQ |
|||
Each face can contain more than three elements. |
|||
{"Giants Cave [Lv 79-85]"; 183505; 47449; 4368; 0; 0 } |
|||
telposlist_end |
|||
f v1/vt1 v2/vt2 v3/vt3 ... |
|||
property_define_end |
|||
class_end |
|||
==== Vertex/texture-coordinate/normal ==== |
|||
Optionally, normal indices can be used to specify normal vectors for vertices when defining a face. |
|||
To add a normal index to a vertex index when defining a face, |
|||
one must put a second slash after the texture coordinate index and then put |
|||
the normal index. |
|||
A valid normal index starts from 1 and matches the corresponding element |
|||
in the previously defined list of normals. |
|||
Each face can contain more than three elements. |
|||
f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 .... |
|||
==== Vertex/normal ==== |
|||
As texture coordinates are optional, one can define geometry without them, but |
|||
one must put two slashes after the vertex index before putting the normal index. |
|||
<nowiki>f v1//vn1 v2//vn2 v3//vn3 ...</nowiki> |
|||
=== Other geometry formats === |
|||
Obj files support higher-order surfaces using several different kinds of interpolation, such as Taylor and B-splines, although support for those features in third party file readers is far from universal. Obj files also do not support mesh hierarchies or any kind of animation or deformation, such as vertex skinning or mesh morphing. |
|||
=== Referencing materials === |
|||
Materials that describe the visual aspects of the polygons are stored in |
|||
external .mtl files. More than one external MTL material file may be referenced from within the OBJ file. The .mtl file may contain one or more named material definitions. |
|||
mtllib [external .mtl file name] |
|||
... |
|||
This tag specifies the material name for the element following it. The material name matches a named material definition in an external .mtl file. |
|||
usemtl [material name] |
|||
... |
|||
Named objects and polygon groups are specified via the following tags. |
|||
o [object name] |
|||
... |
|||
g [group name] |
|||
... |
|||
Smooth shading across polygons is enabled by smoothing groups. |
|||
s 1 |
|||
... |
|||
# Smooth shading can be disabled as well. |
|||
s off |
|||
... |
|||
=== Relative and absolute indices === |
|||
OBJ files, due to their list structure, are able to reference vertices, normals, etc. either by their absolute position (1 represents the first defined vertex, N representing the Nth defined vertex), or by their relative position (-1 represents the latest defined vertex). |
|||
However, not all software supports the latter approach, and conversely some software inherently writes only the latter form (due to the convenience of appending elements without needing to recalculate vertex offsets, etc.), leading to occasional incompatibilities. |
|||
==Material template library== |
|||
{{Infobox file format |
|||
| name = MTL material format |
|||
| icon = |
|||
| logo = |
|||
| screenshot = |
|||
| caption = |
|||
| extension = <tt>.mtl</tt> |
|||
| mime = |
|||
| type code = |
|||
| uniform type = |
|||
| magic = |
|||
| owner = [[Wavefront Technologies]] |
|||
| released = <!-- {{Start date|YYYY|mm|dd|df=yes}} --> |
|||
| latest release version = |
|||
| latest release date = <!-- {{Start date and age|YYYY|mm|dd|df=yes}} --> |
|||
| genre = 3D texture format |
|||
| container for = |
|||
| contained by = |
|||
| extended from = |
|||
| extended to = |
|||
| standard = |
|||
| free = |
|||
| url = |
|||
}} |
|||
=== Synopsis === |
|||
In 3D [[Computer Graphics]], one of the most common geometry interchange file formats is the OBJ. The .MTL File Format is a companion file format that describes surface shading (material) properties of objects within one or more .OBJ files. A .OBJ file references one or more .MTL files (called "material libraries"), and from there, references one or more material descriptions by name. |
|||
=== Introduction === |
|||
The '''Material Template Library''' format (MTL) is a standard defined by [[Wavefront Technologies]] for [[ASCII]] files that define the light reflecting properties of a surface for the purposes of [[computer rendering]], and according to the [[Phong reflection model]]. The standard has widespread support among different computer software packages, making it a useful format for interchange of materials. |
|||
MTL files are commonly accompanied by and referenced from OBJ files that define geometry upon which the materials of the MTL file are mapped. |
|||
The MTL format, although still widely used, is outdated and does not fully support later technologies such as specular maps and [[parallax mapping|parallax maps]]. However due to the open and intuitive nature of the format, these can easily be added with a custom MTL file generator. |
|||
The MTL format defines a number of formats.<ref>{{cite web|url=http://people.sc.fsu.edu/~burkardt/data/mtl/mtl.html |title=MTL Files - Material Definitions for OBJ Files |publisher=People.sc.fsu.edu |date=2004-06-14 |accessdate=2010-11-26}}</ref><ref>{{cite web|author=Author |url=http://nendowingsmirai.yuku.com/forum/viewtopic/id/1723 |title=Wavefront .mtl file format info - GRIPES and GRUMBLES - Wings - Wings3D - Official Development Forum - Message Board |publisher=Nendowingsmirai.yuku.com |date= |accessdate=2010-11-26}}</ref> |
|||
==== Basic materials ==== |
|||
A single <tt>.mtl</tt> file may define multiple materials. Materials are defined one after another in the file, each starting with the <tt>newmtl</tt> command: |
|||
# define a material named 'Colored' |
|||
newmtl Colored |
|||
The [[Shading#Ambient lighting|ambient]] color of the material is declared using <tt>Ka</tt>. Color definitions are in RGB where each channel's value is between 0 and 1. |
|||
Ka 1.000 1.000 1.000 # white |
|||
Similarly, the [[diffuse reflection|diffuse]] color is declared using <tt>Kd</tt>. |
|||
Kd 1.000 1.000 1.000 # white |
|||
The [[specular reflection|specular]] color is declared using <tt>Ks</tt>, and weighted using the specular coefficient <tt>Ns</tt>. |
|||
Ks 0.000 0.000 0.000 # black (off) |
|||
Ns 10.000 # ranges between 0 and 1000 |
|||
Materials can be [[transparency and translucency|transparent]]. This is referred to as being ''dissolved''. Unlike real transparency, the result does not depend upon the thickness of the object. |
|||
d 0.9 # some implementations use 'd' |
|||
Tr 0.9 # others use 'Tr' |
|||
Multiple [[illumination model]]s are available, per material. These are enumerated as follows: |
|||
<pre>0. Color on and Ambient off |
|||
1. Color on and Ambient on |
|||
2. Highlight on |
|||
3. Reflection on and Ray trace on |
|||
4. Transparency: Glass on, Reflection: Ray trace on |
|||
5. Reflection: Fresnel on and Ray trace on |
|||
6. Transparency: Refraction on, Reflection: Fresnel off and Ray trace on |
|||
7. Transparency: Refraction on, Reflection: Fresnel on and Ray trace on |
|||
8. Reflection on and Ray trace off |
|||
9. Transparency: Glass on, Reflection: Ray trace off |
|||
10. Casts shadows onto invisible surfaces</pre> |
|||
illum 2 |
|||
==== Texture maps ==== |
|||
Textured materials use the same properties as above, and additionally define [[texture mapping|texture maps]]. Below is an example of a common material file. See the full wavefront file format reference for more details. |
|||
newmtl Textured |
|||
Ka 1.000 1.000 1.000 |
|||
Kd 1.000 1.000 1.000 |
|||
Ks 0.000 0.000 0.000 |
|||
d 1.0 |
|||
illum 2 |
|||
map_Ka lenna.tga # the ambient texture map |
|||
map_Kd lenna.tga # the diffuse texture map (most of the time, it will |
|||
# be the same as the ambient texture map) |
|||
map_Ks lenna.tga # specular color texture map |
|||
map_Ns lenna_spec.tga # specular highlight component |
|||
map_d lenna_alpha.tga # the alpha texture map |
|||
map_bump lenna_bump.tga # some implementations use 'map_bump' instead of 'bump' below |
|||
bump lenna_bump.tga # bump map (which by default uses luminance channel of the image) |
|||
disp lenna_disp.tga # displacement map |
|||
decal lenna_stencil.tga # stencil decal texture (defaults to 'matte' channel of the image) |
|||
Texture map statements may also have option parameters (see [http://paulbourke.net/dataformats/mtl/ full spec]). |
|||
map_Ka -o 1 1 1 ambient.tga # texture origin (1,1,1) |
|||
refl -type sphere clouds.tga # spherical reflection map |
|||
==== Texture options ==== |
|||
<code> |
|||
-blendu on | off # set horizontal texture blending (default on) |
|||
-blendv on | off # set vertical texture blending (default on) |
|||
-boost float_value # boost mip-map sharpness |
|||
-mm base_value gain_value # modify texture map values (default 0 1) |
|||
# base_value = brightness, gain_value = contrast |
|||
-o u [v [w]] # Origin offset (default 0 0 0) |
|||
-s u [v [w]] # Scale (default 1 1 1) |
|||
-t u [v [w]] # Turbulence (default 0 0 0) |
|||
-texres resolution # texture resolution to create |
|||
-clamp on | off # only render texels in the clamped 0-1 range (default off) |
|||
# When unclamped, textures are repeated across a surface, |
|||
# when clamped, only texels which fall within the 0-1 |
|||
# range are rendered. |
|||
-bm mult_value # bump multiplier (for bump maps only) |
|||
-imfchan r | g | b | m | l | z # specifies which channel of the file is used to |
|||
# create a scalar or bump texture. r:red, g:green, |
|||
# b:blue, m:matte, l:luminance, z:z-depth.. |
|||
# (the default for bump is 'l' and for decal is 'm') |
|||
bump -imfchan r bumpmap.tga # says to use the red channel of bumpmap.tga as the bumpmap |
|||
</code> |
|||
For reflection maps... |
|||
<code> |
|||
-type sphere # specifies a sphere for a "refl" reflection map |
|||
-type cube_top | cube_bottom | # when using a cube map, the texture file for each |
|||
cube_front | cube_back | # side of the cube is specified separately |
|||
cube_left | cube_right |
|||
</code> |
|||
==== Vendor specific alterations ==== |
|||
Because of the ease in parsing the files, and the unofficial spreading of the file-format, files may contain vendor specific alterations. |
|||
According to the spec, options are supposed to precede the texture filename. However, at least one vendor generates files with options at the end. |
|||
<code>bump texbump.tga -bm 0.2 # bump multiplier of 0.2</code> |
|||
==See also== |
|||
* [[3DMLW]] is a markup language that shows OBJ files through common web browsers ([[Internet Explorer]], [[Mozilla Firefox]], [[Opera (web browser)|Opera]]) |
|||
* [[STL (file format)]] |
|||
* [[PLY (file format)]] is an alternative file format offering more flexibility than most [[stereolithography]] applications. |
|||
==References== |
==References== |
Revision as of 01:59, 4 May 2014
Filename extension |
.obj |
---|---|
Internet media type |
text/plain |
Developed by | Wavefront Technologies |
Type of format | 3D model format |
OBJ (or .OBJ) is a geometry definition file format first developed by Wavefront Technologies for its Advanced Visualizer animation package. The file format is open and has been adopted by other 3D graphics application vendors. For the most part it is a universally accepted format.
The OBJ file format is a simple data-format that represents 3D geometry alone — namely, the position of each vertex, the UV position of each texture coordinate vertex, vertex normals, and the faces that make each polygon defined as a list of vertices, and texture vertices. Vertices are stored in a counter-clockwise order by default, making explicit declaration of face normals unnecessary. OBJ coordinates have no units, but OBJ files can contain scale information in a human readable comment line.
File format
Lines beginning with a hash character (#) are comments.
# this is a comment
An OBJ file contains several types of definitions:
# List of Vertices, with (x,y,z[,w]) coordinates, w is optional and defaults to 1.0. v 0.123 0.234 0.345 1.0 v ... ... # Texture coordinates, in (u ,v [,w]) coordinates, these will vary between 0 and 1, w is optional and default to 0. vt 0.500 1 [0] vt ... ... # Normals in (x,y,z) form; normals might not be unit. vn 0.707 0.000 0.707 vn ... ... # Parameter space vertices in ( u [,v] [,w] ) form; free form geometry statement ( see below ) vp 0.310000 3.210000 2.100000 vp ... ... # Face Definitions (see below) f 1 2 3 f 3/1 4/2 5/3 f 6/4/1 3/5/3 7/6/5 f ... ...
Vertex positions (parameter space vertices)
Define points in parameter space of curve or surface. "u" only is required for curve points, "u" and "v" for surface points and control points of non-rational trimming curves, and "u", "v" and "w" (weight) for control points of rational trimming curves.
Face definitions
Faces are defined using lists of vertex, texture and normal indices. Polygons such as quadrilaterals can be defined by using more than three vertex/texture/normal indices.
OBJ files also support free form curved surface objects, such as NURBS surfaces.
Vertex
A valid vertex index starts from 1 and matches the corresponding vertex elements of a previously defined vertex list. Each face can contain three or more vertices.
f v1 v2 v3 v4 ....
Vertex/texture-coordinate
Optionally, texture coordinate indices can be used to specify texture coordinates when defining a face. To add a texture coordinate index to a vertex index when defining a face, one must put a slash immediately after the vertex index and then put the texture coordinate index. No spaces are permitted before or after the slash. A valid texture coordinate index starts from 1 and matches the corresponding element in the previously defined list of texture coordinates. Each face can contain more than three elements.
f v1/vt1 v2/vt2 v3/vt3 ...
Vertex/texture-coordinate/normal
Optionally, normal indices can be used to specify normal vectors for vertices when defining a face. To add a normal index to a vertex index when defining a face, one must put a second slash after the texture coordinate index and then put the normal index. A valid normal index starts from 1 and matches the corresponding element in the previously defined list of normals. Each face can contain more than three elements.
f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 ....
Vertex/normal
As texture coordinates are optional, one can define geometry without them, but one must put two slashes after the vertex index before putting the normal index.
f v1//vn1 v2//vn2 v3//vn3 ...
Other geometry formats
Obj files support higher-order surfaces using several different kinds of interpolation, such as Taylor and B-splines, although support for those features in third party file readers is far from universal. Obj files also do not support mesh hierarchies or any kind of animation or deformation, such as vertex skinning or mesh morphing.
Referencing materials
Materials that describe the visual aspects of the polygons are stored in external .mtl files. More than one external MTL material file may be referenced from within the OBJ file. The .mtl file may contain one or more named material definitions.
mtllib [external .mtl file name] ...
This tag specifies the material name for the element following it. The material name matches a named material definition in an external .mtl file.
usemtl [material name] ...
Named objects and polygon groups are specified via the following tags.
o [object name] ... g [group name] ...
Smooth shading across polygons is enabled by smoothing groups.
s 1 ... # Smooth shading can be disabled as well. s off ...
Relative and absolute indices
OBJ files, due to their list structure, are able to reference vertices, normals, etc. either by their absolute position (1 represents the first defined vertex, N representing the Nth defined vertex), or by their relative position (-1 represents the latest defined vertex). However, not all software supports the latter approach, and conversely some software inherently writes only the latter form (due to the convenience of appending elements without needing to recalculate vertex offsets, etc.), leading to occasional incompatibilities.
Material template library
Filename extension |
.mtl |
---|---|
Internet media type | text/plain, model/obj |
Developed by | Wavefront Technologies |
Type of format | 3D texture format |
Synopsis
In 3D Computer Graphics, one of the most common geometry interchange file formats is the OBJ. The .MTL File Format is a companion file format that describes surface shading (material) properties of objects within one or more .OBJ files. A .OBJ file references one or more .MTL files (called "material libraries"), and from there, references one or more material descriptions by name.
Introduction
The Material Template Library format (MTL) is a standard defined by Wavefront Technologies for ASCII files that define the light reflecting properties of a surface for the purposes of computer rendering, and according to the Phong reflection model. The standard has widespread support among different computer software packages, making it a useful format for interchange of materials.
MTL files are commonly accompanied by and referenced from OBJ files that define geometry upon which the materials of the MTL file are mapped.
The MTL format, although still widely used, is outdated and does not fully support later technologies such as specular maps and parallax maps. However due to the open and intuitive nature of the format, these can easily be added with a custom MTL file generator.
The MTL format defines a number of formats.[1][2]
Basic materials
A single .mtl file may define multiple materials. Materials are defined one after another in the file, each starting with the newmtl command:
# define a material named 'Colored' newmtl Colored
The ambient color of the material is declared using Ka. Color definitions are in RGB where each channel's value is between 0 and 1.
Ka 1.000 1.000 1.000 # white
Similarly, the diffuse color is declared using Kd.
Kd 1.000 1.000 1.000 # white
The specular color is declared using Ks, and weighted using the specular coefficient Ns.
Ks 0.000 0.000 0.000 # black (off) Ns 10.000 # ranges between 0 and 1000
Materials can be transparent. This is referred to as being dissolved. Unlike real transparency, the result does not depend upon the thickness of the object.
d 0.9 # some implementations use 'd' Tr 0.9 # others use 'Tr'
Multiple illumination models are available, per material. These are enumerated as follows:
0. Color on and Ambient off 1. Color on and Ambient on 2. Highlight on 3. Reflection on and Ray trace on 4. Transparency: Glass on, Reflection: Ray trace on 5. Reflection: Fresnel on and Ray trace on 6. Transparency: Refraction on, Reflection: Fresnel off and Ray trace on 7. Transparency: Refraction on, Reflection: Fresnel on and Ray trace on 8. Reflection on and Ray trace off 9. Transparency: Glass on, Reflection: Ray trace off 10. Casts shadows onto invisible surfaces
illum 2
Texture maps
Textured materials use the same properties as above, and additionally define texture maps. Below is an example of a common material file. See the full wavefront file format reference for more details.
newmtl Textured Ka 1.000 1.000 1.000 Kd 1.000 1.000 1.000 Ks 0.000 0.000 0.000 d 1.0 illum 2 map_Ka lenna.tga # the ambient texture map map_Kd lenna.tga # the diffuse texture map (most of the time, it will # be the same as the ambient texture map) map_Ks lenna.tga # specular color texture map map_Ns lenna_spec.tga # specular highlight component map_d lenna_alpha.tga # the alpha texture map map_bump lenna_bump.tga # some implementations use 'map_bump' instead of 'bump' below
bump lenna_bump.tga # bump map (which by default uses luminance channel of the image) disp lenna_disp.tga # displacement map decal lenna_stencil.tga # stencil decal texture (defaults to 'matte' channel of the image)
Texture map statements may also have option parameters (see full spec).
map_Ka -o 1 1 1 ambient.tga # texture origin (1,1,1) refl -type sphere clouds.tga # spherical reflection map
Texture options
-blendu on | off # set horizontal texture blending (default on)
-blendv on | off # set vertical texture blending (default on)
-boost float_value # boost mip-map sharpness
-mm base_value gain_value # modify texture map values (default 0 1)
# base_value = brightness, gain_value = contrast
-o u [v [w]] # Origin offset (default 0 0 0)
-s u [v [w]] # Scale (default 1 1 1)
-t u [v [w]] # Turbulence (default 0 0 0)
-texres resolution # texture resolution to create
-clamp on | off # only render texels in the clamped 0-1 range (default off)
# When unclamped, textures are repeated across a surface,
# when clamped, only texels which fall within the 0-1
# range are rendered.
-bm mult_value # bump multiplier (for bump maps only)
-imfchan r | g | b | m | l | z # specifies which channel of the file is used to
# create a scalar or bump texture. r:red, g:green,
# b:blue, m:matte, l:luminance, z:z-depth..
# (the default for bump is 'l' and for decal is 'm')
bump -imfchan r bumpmap.tga # says to use the red channel of bumpmap.tga as the bumpmap
For reflection maps...
-type sphere # specifies a sphere for a "refl" reflection map
-type cube_top | cube_bottom | # when using a cube map, the texture file for each
cube_front | cube_back | # side of the cube is specified separately
cube_left | cube_right
Vendor specific alterations
Because of the ease in parsing the files, and the unofficial spreading of the file-format, files may contain vendor specific alterations.
According to the spec, options are supposed to precede the texture filename. However, at least one vendor generates files with options at the end.
bump texbump.tga -bm 0.2 # bump multiplier of 0.2
See also
- 3DMLW is a markup language that shows OBJ files through common web browsers (Internet Explorer, Mozilla Firefox, Opera)
- STL (file format)
- PLY (file format) is an alternative file format offering more flexibility than most stereolithography applications.
References
- ^ "MTL Files - Material Definitions for OBJ Files". People.sc.fsu.edu. 2004-06-14. Retrieved 2010-11-26.
- ^ Author. "Wavefront .mtl file format info - GRIPES and GRUMBLES - Wings - Wings3D - Official Development Forum - Message Board". Nendowingsmirai.yuku.com. Retrieved 2010-11-26.
{{cite web}}
:|author=
has generic name (help)