|
MGFE: Materials and Geometry Format Extended |
|
MGFE Basics
The basic idea is to define all the entities in a scene with MGFE files, i.e. to include the part related to geometry (volumes and surfaces), materials, textures, participating media, animation, and others in scene using the same file formats. We think that this format could be extended for new entities in the future.
unsigned char* buffer = new unsigned char [sizeX*sizeY*sizeZ];
unsigned char* t=buffer;
for (int k=0; k < sizeZ; ++k) {
read(fd,(char*)t,sizeX*sizeY*sizeof(unsigned char));
t += sizeX*sizeY;
}
Keyword Arguments Interpretation
===============================================================================
# [anything ...] a comment
{ [anything ...] begin block comment
} [anything ...] end block comment
o [name] begin/end object context
xf [xform] begin/end transformation context
i pathname [xform] include file (with transformation)
ies pathname [-m f][xform] include IES luminaire (with transformation)
-------------------------------------------------------------------------------
m [id [= [template]]] get/set material context
sides {1|2} set number of sides for current material
rd rho_d set diffuse reflectance for current material
td tau_d set diffuse transmittance for current material
ed epsilon_d set diffuse emittance for current material
rs rho_s alpha_r set specular reflectance for current material
ts tau_s alpha_t set specular transmittance for current material
ir n_real n_imag set index of refraction for current material
-------------------------------------------------------------------------------
c [id [= [template]]] get/set color context
cxy x y set CIE (x,y) chromaticity for current color
cspec l_min l_max v1 v2 ... set relative spectrum for current color
cct temperature set spectrum based on black body temperature
cmix w1 c1 w2 c2 ... mix named colors to make current color
-------------------------------------------------------------------------------
phf [id [= [template]]] get/set phase function context
type Isotropic|Schlick| set the type for current phase function
Schlick2|
Henyey-Greenstein
k value set the k parameter value for the current
phase function
l value set the l parameter value for the current
phase function
r value set the r parameter value for the current
phase function
-------------------------------------------------------------------------------
mpm [id [= [template]]] get/set material context for participating
medium
albedo omega set albedo for current material
em epsilon set emittance for current material
kt kappa_t set extinction for current material
ktgridfile filename set the grid file to modulate kappa_t for
current material
albedogridfile filename set the grid file to modulate Omega for
current material
-------------------------------------------------------------------------------
v [id [= [template]]] get/set vertex context
p x y z set point position for current vertex
n dx dy dz set surface normal for current vertex
-------------------------------------------------------------------------------
cv x y z w point 3d
pv x y tantype ix iy tantype
ox oy keyframe:
x: Input y: Output
ix, iy: Input tangent
ox, oy:Output tangent
-------------------------------------------------------------------------------
cam [id [= [template]]] camera
eye x y z eye point in world space
center x y z center of interest point in world space
up u w t up vector in world space
view alfa beta horizontal and vertical aperture respectively
-------------------------------------------------------------------------------
pcurve [id [= [template]]] parametrical curve (animation curve with
keyframes)
in preInfinity controls how the curve is evaluated before
the first keyframe
out postInfinity controls how the curve is evaluated before
the first keyframe
cvs pv1 ... list of keyframes
-------------------------------------------------------------------------------
curve [id [= [template]]] nurbs curve
deg value curve degree
knt value ... knot values
cvs cv1 ... control points
-------------------------------------------------------------------------------
f v1 v2 v3 ... polygon using current material,
spec. vertices
sph vc radius sphere
cyl v1 radius v2 truncated right cylinder (closed solid)
[Note that in MGF the cyl entity refers to an
open ended cylinder.]
cone v1 rad1 v2 rad2 truncated right cone (closed solid)
[Note that in MGF the mySrc{cone} entity
refers to an open ended cone.]
prism v1 v2 v3 ... length truncated right prism (closed solid)
ring vc rmin rmax circular ring with inner and outer radii
torus vc rmin rmax circular torus with inner and outer radii
rectprism pmin pmax rectangular prism
fullspace full space
-------------------------------------------------------------------------------
texture pathname sizeU sizeV texture with relative dimensions
channel obj type [curve] coord
actions function with one input and one output.
obj: Object to which the channel is applied
type: Indicates the transformation to be
applied to a certain axis. Valid values
are: XTranslate, YTranslate, ZTranslate,
XRotate, YRotate, ZRotate, XScale, YScale,
ZScale.
curve: Optional nurbs curve (motion path)
coord: Exit coordinate from curve
actions: List of animation curves (keyframes)
-------------------------------------------------------------------------------
Table 1. MGFE entities and their arguments. Arguments in brackets are optional. Arguments in curly braces mean one of the given choices must appear. Ellipsis (...) mean that any number of arguments may be given.A context describes the current state of the interpreter, and affects or is affected by certain entities as they are read in. MGF contexts can be divided into two types, hierarchical contexts and named contexts.
Hierarchical contexts are manipulated by a single entity and have an associated "stack" onto which new contexts are "pushed" using the entity. The last context may be "popped" by giving the entity again with no arguments. The two hierarchical contexts in MGF are the current transformation, manipulated with the xf entity, and the current object, manipulated with the o entity.
Context Cntl. Entity Default Value Field Entities Affects
===============================================================================
Object o - - -
-------------------------------------------------------------------------------
Transform xf - - f, sph, cyl,
cone, ring,
prism, torus,
rectprism
-------------------------------------------------------------------------------
Material m 2-sided black sides, rd, td, f, sph, cyl,
ed, rs, ts cone, ring,
torus, prism
-------------------------------------------------------------------------------
Phase phf isotropic type, k, l, r sph, cyl, cone,
function prism, torus,
rectprism,
fullspace
-------------------------------------------------------------------------------
Material for mpm black albedo, em, sph, cyl, cone,
participating kt, ktgridfile, prism, torus,
media albedogridfile rectprism,
fullspace
-------------------------------------------------------------------------------
Color c neutral grey cxy, cspec, albedo, em,
cct, cmix kt, ktgridfile,
albedogridfile
-------------------------------------------------------------------------------
Vertex v (0,0,0) p, n sph, cyl, cone,
no normal prism, torus,
rectprism
-------------------------------------------------------------------------------
Table 2. MGFE contexts and their related entities and default values.
# Establish a new phf context called "cloudyPhF"
phf cloudyPhF =
type Schlick2
k 0.3
l -0.4
r 0.5
# We're done, the current phf context is now "cloudyPhF"
# Create new named material for participating media context
mpm matPsicoCloud =
# Set a certain albedo
c
# Spectrum measured in 10 nm increments from 400 to 700 nm
cspec 400 700 35.29 44.87 47.25 47.03 46.87 47.00 47.09 \
47.15 46.80 46.17 46.26 48.74 51.08 51.31 51.10 \
51.11 50.52 50.36 51.72 53.61 53.95 52.08 49.49 \
48.30 48.75 49.99 51.35 52.75 54.44 56.34 58.00
albedo 0.97
# Set neutral color
c
# Set extinction coefficient
kt .04
# Modulate with a file of our own
ktgridfile myGridFileApart
# The cloud corner vertices:
v corner.xyz =
p 0 0 0
v corner.XYZ =
p 48 24 48
# The cloud:
# Push object name
o cloud
# Get previously defined matPsicoCloud material
m matPsicoCloud
# Get previously defined cloudyPhF phase function
phf cloudyPhF
# Polygonal face using defined vertices
rectprism corner.xyz corner.XYZ
# Pop object name
o
# To define the object geometry use this file...
o car
i jaguar.mgfe
o
# Motion path:
# The controls points for the curve.
cv cv0 = -54.358292 -95.225906 0.000000 1.000000
cv cv1 = -33.192841 -62.570728 0.000000 1.000000
cv cv2 = -16.306379 -37.387878 0.000000 1.000000
cv cv3 = 4.540790 -34.844360 0.000000 1.000000
cv cv4 = 18.002951 -32.068100 0.000000 1.000000
cv cv5 = 32.955528 -17.635670 0.000000 1.000000
cv cv6 = 45.697121 -7.263900 0.000000 1.000000
cv cv7 = 69.370010 -7.424020 0.000000 1.000000
cv cv8 = 126.772240 -5.515900 0.000000 1.000000
# Curve carCurve with the last controls points (motion path).
curve carCurve =
deg 3
knt 0.000000 0.000000 0.000000 0.000000 1.000000 2.000000 3.000000 4.000000 5.000000 \
6.000000 6.000000 6.000000 6.000000
cvs cv0 cv1 cv2 cv3 cv4 cv5 cv6 cv7 cv8
# Key frame: Initial and final steps.
pv pv0 = 0.000000 1.000000 TAN_LINEAR -1.000000 0.000000 TAN_LINEAR 0.278520 0.960430
pv pv1 = 1.000000 30.000000 TAN_LINEAR -0.278520 -0.960430 TAN_LINEAR 1.000000 0.000000
# The time curve (keyframe).
pcurve timing =
in PRE_LINEAR
out POST_LINEAR
cvs pv0 pv1
# Channels that define the car animation.
# Each channel is associated to each coordinate.
channel car XTranslate carCurve [X] timing
channel car YTranslate carCurve [Y] timing
channel car ZTranslate carCurve [Z] timing
phf [id [= [template]]] get/set phase function context type {Isotropic|Schlick| ...} specify the type of phase function k value specify the first parameter of a phase function l value specify the second parameter of a phase function r value specify the third parameter of a phase function mpm [id [= [template]]] get/set material for participating media context albedo omega specify the albedo of a participating medium em epsilon specify the emittance of a participating medium kt kappa_t specify the kt of a participating medium ktgridfile filename specify a factor file for the extinction of a participating medium albedogridfile filename specify a factor file for the albedo of a participating medium rectprism v1 v2 closed rectangular prism fullspace set the partipating medium everywhere
curve id = (curveform)+ NURBS curve cv id = X Y Z W control vertex pv id = x y input_tanget ... parametric vertex pcurve id = (in|out|cvs)+ hermite curve channel obj type curve coord (pcurve)* animation channel cam [id [=]] (cform)+ camera
texture [id [=tform]] | tform get/set texture context
Entity Parent entity =============================== MG_E_COMMENT - MG_E_CCT MG_E_COLOR MG_E_CXY MG_E_COLOR MG_E_CMIX MG_E_COLOR MG_E_CSPEC MG_E_COLOR MG_E_POINT MG_E_VERTEX MG_E_NORMAL MG_E_VERTEX MG_E_ED MG_E_MATERIAL MG_E_IR MG_E_MATERIAL MG_E_RD MG_E_MATERIAL MG_E_RS MG_E_MATERIAL MG_E_TD MG_E_MATERIAL MG_E_TS MG_E_MATERIAL MG_E_SIDES MG_E_MATERIAL ---------------------------------------------------------------
Table 3. MGFE entities with no associate functions in the library.New format MGFE presents the information through the associate functions different way than MGF. This format presents the information through a set of variable called mgfe_current_X_, where X is the name of the entity in course. This variable is a structure that shows all the information of the entity. To see the structure for each entity you can take a look at `mgparser.h' file. We record in MGF format library the functions to access other information. Many these functions don't exist in MGFE format library because the new information's presentation is more direct (you can access the information directly through mgfe_current_X_, you don't need other functions). The functions and variables you can use are shown in the Table 5.
Function or variable Comment
================================================================================
mgfe_init First function that you should use.
It opens a MGFE file and initializes the parser environment.
mgfe_parse Once you assigned the associate functions this function
generates the entities in the last file read in mgfe_init.
xf_xfmpoint The xf_xfmpoint routine applies the current transformation
to a point, scaling, rotating and moving it to its proper
location.
xf_xfmvect The xf_xfmvect routine applies the current transformation to
a vector, scaling and rotating it to its proper location. The
only difference between xf_xfmpoint and xf_xfmvect is that
in the latter, the final translation is not applied.
xf_xfrotvect The xf_rotvect routine rotates a vector using the current
transformation. No translation or scaling is applied, which
is the appropriate action for surface normal vectors for
example.
xf_scale The xf_scale function takes a scalar argument and applies
the current scale factor, returning the result.
mgfe_ehand mgfe_ehand is a array of associate functions that can be
initilized. You can use mgfe_ehand in the same way than
mg_ehand in MGF format library.
mgfe_current_material_ The current material. This material is the same than in
MGF format library.
mgfe_current_matpm_ The current material for participating medium.
mgfe_current_vertex_ The current vertex. This variable is global to keep
compatiblity with the MGF library.
mgfe_current_phf_ The current phase function context.
--------------------------------------------------------------------------------
Table 5. MGFE functions and variables you can use.