ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/mgfdoc.tr
Revision: 1.17
Committed: Tue Mar 18 12:57:07 1997 UTC (27 years, 1 month ago) by greg
Content type: application/x-troff
Branch: MAIN
Changes since 1.16: +4 -3 lines
Log Message:
added fh entity and general cleanup

File Contents

# Content
1 .\" SCCSid "$SunId$ LBL"
2 .nr PS 11
3 .ps 11
4 .nr VS 12
5 .vs 12
6 .nr PD .5v
7 .ds LF MGF
8 .ds RF Version 1.1
9 .\" !Remember to update date on each modification!
10 .DA February 1996
11 .TL
12 The Materials and Geometry Format
13 .AU
14 Greg Ward
15 .br
16 Lawrence Berkeley Laboratory
17 .NH
18 Introduction
19 .LP
20 The Materials and Geometry Format (referred to henceforth as MGF)
21 is a description language for 3-dimensional environments expressly
22 suited to visible light simulation and rendering.
23 The materials are physically-based and rely on standard and
24 well-accepted definitions of color, reflectance and transmittance
25 for good accuracy and reproducibility.
26 The geometry is based on boundary representation using simple
27 geometric primitives such as polygons, spheres and cones.
28 The file format itself is terse but human-readable ASCII text.
29 .NH 2
30 What makes MGF special?
31 .LP
32 There are three principal reasons to use MGF as an input language for
33 lighting simulation and physically-based rendering:
34 .RS
35 .IP 1.
36 It's the only existing format that describes materials physically.
37 .IP 2.
38 It is endorsed by the Illuminating Engineering Society of North
39 America (IESNA) as part of their LM-63-1995 standard for luminaire data.
40 .IP 3.
41 It's easy and fun to support since it comes with a standard parser
42 and sample scenes and objects at the web site,
43 "http://radsite.lbl.gov/mgf/HOME.html".
44 .RE
45 .LP
46 The standard parser provides both immediate and long-term
47 benefits, since it presents a programming interface that is more
48 stable even than the language itself.
49 Unlike AutoCAD DXF and other de facto standards, a change to the
50 language will not break existing programs.
51 This is because the parser gives the calling software only those
52 entities it can handle.
53 If the translator understands only polygons, it will be given only
54 polygons.
55 If a new geometric primitive is included in a later version of the
56 standard, the new parser that comes with it will still be able to
57 express this entity as polygons.
58 Thus, the urgency of modifying code to support a changing standard
59 is removed, and long-term stability is assured.
60 .LP
61 This notion of
62 .I extensibility
63 is a cornerstone of the format, and it goes well beyond the
64 extensibility of other languages because is guarantees that new
65 versions of the standard will not break existing programs, and the
66 new information will be used as much as possible.
67 Other languages either require that all translators stay up to date
68 with the latest standard, or allow forward compatibility by simply
69 .I ignoring
70 new entities.
71 In MGF, if NURBS are added at some point and the translator or
72 loader does not handle them directly, the new version of the parser
73 will automatically convert them to smoothed polygons without
74 changing a single line of the calling program.
75 It is merely necessary to link to the new library, and all the new
76 entities are supported\(dg.
77 .FS
78 \(dgIf an old version of the parser encounters new entities it does
79 not recognize, the default action is to ignore them, printing a warning
80 message.
81 This may be overridden to support custom entities, but such
82 practice is discouraged because it weakens the standard.
83 .FE
84 .NH 2
85 What does MGF look like?
86 .LP
87 MGF has a simple entity-per-line structure, with a similar
88 appearance to Wavefront's .OBJ format.
89 Each entity is specified by a short keyword, and
90 arguments are separated by white space (tabs and/or spaces).
91 A newline may be escaped with a backslash ('\\'), in which case it
92 counts as a space.
93 Lines and continued lines may have up to 4096 characters, including
94 newlines, tabs and spaces.
95 A comment is an ignored entity whose keyword is the pound sign ('#').
96 .LP
97 Here is an MGF file that describes a simple two-drawer file cabinet:
98 .DS
99 # Conversion from inches to meters
100 xf -s .0254
101 # Surface material
102 m burgundy_formica =
103 c
104 cxy .362 .283
105 rd .0402
106 c
107 rs .0284 .05
108 sides 1
109 # Cabinet vertices
110 v fc.xy =
111 p .05 0 0
112 v fc.xY =
113 p .05 18 0
114 v fc.XY =
115 p 35.95 18 0
116 v fc.Xy =
117 p 35.95 0 0
118 # Cabinet
119 prism fc.xy fc.xY fc.XY fc.Xy 24
120 # Drawer vertices
121 v fcd.Xz =
122 p 34 0 0
123 v fcd.XZ =
124 p 34 0 10
125 v fcd.xZ =
126 p 0 0 10
127 v fcd.xz =
128 p 0 0 0
129 # Two drawers
130 o drawer
131 xf -t 1 18.1 2 -a 2 -t 0 0 11
132 prism fcd.xz fcd.Xz fcd.XZ fcd.xZ .9
133 xf
134 o
135 # End of units conversion
136 xf
137 .DE
138 .NH 2
139 MGF's place in the world of standards
140 .LP
141 MGF was developed initially to support detailed geometric
142 description of light fixtures for the IESNA luminaire data standard,
143 publication LM-63\(dg.
144 .FS
145 \(dgTo obtain the latest version of this standard, write to:
146 Illuminating Engineering Society of North America,
147 345 East 47th St.,
148 New York, NY 10017.
149 .FE
150 Existing standards for geometric description were either too
151 cumbersome (e.g.
152 .I Radiance)
153 or did not include physical materials (e.g. IGES).
154 It was noted early on that a standard able to fully describe
155 luminaires would necessarily be
156 capable of describing other objects as well; indeed whole
157 environments could be defined this way.
158 Since the descriptions would be physical, they could serve as input
159 to both lighting simulation and rendering software.
160 A standard language for describing the appearance of physical
161 objects has been lacking for some time, and current efforts in this
162 direction (i.e. STEP) seem several years away from fruition.
163 (There are other languages for describing realistic scenes
164 that deserve mention here, such as VRML and the Manchester Scene
165 Description Language, but none give specific attention to physical
166 material properties and are thus unsuitable for lighting
167 simulation.)\0
168 .LP
169 In short, we saw this as an opportunity to offer the lighting and
170 rendering community a simple and easy-to-support standard for
171 describing environments in a physically valid way.
172 Our hope is that this will promote sharing color, material and object
173 libraries as well as complete scene descriptions.
174 Sharing libraries is of obvious benefit to users and software
175 developers alike.
176 Sharing scenes should also permit
177 comparisons between rendering systems and
178 intervalidation of lighting calculations.
179 As anyone who works in this field knows, modeling is the most
180 difficult step in creating any simulation or rendering, and there is
181 no excuse for this data being held prisoner by a proprietary data
182 format.
183 .NH
184 MGF Basics
185 .LP
186 The default coordinate system in MGF is right-handed with
187 distances given in meters, though this can be effectively changed
188 by specifying a global transformation.
189 The transformation context is affected by the
190 .UL xf
191 entity, and the whole of MGF can be understood in terms of entities
192 and contexts.
193 .NH 2
194 Entities and Contexts
195 .LP
196 An
197 .I entity
198 in MGF is any non-blank line, which must be one of a finite set of
199 command keywords followed by zero or more arguments.
200 (As mentioned previously, an entity may continue over multiple lines
201 by escaping the newline with a backslash.)\0
202 Table 1 gives a list of entities and their expected arguments.
203 Section 3 gives more detailed information on each entity.
204 .KF
205 .TS
206 expand, box;
207 l l l.
208 Keyword Arguments Interpretation
209 = = =
210 # [anything ...] a comment
211 o [name] begin/end object context
212 xf [xform] begin/end transformation context
213 i pathname [xform] include file (with transformation)
214 ies pathname [-m f][xform] include IES luminaire (with transformation)
215 _ _ _
216 c [id [= [template]]] get/set color context
217 cxy x y set CIE (x,y) chromaticity for current color
218 cspec l_min l_max v1 v2 ... set relative spectrum for current color
219 cct temperature set spectrum based on black body temperature
220 cmix w1 c1 w2 c2 ... mix named colors to make current color
221 _ _ _
222 m [id [= [template]]] get/set material context
223 sides {1|2} set number of sides for current material
224 rd rho_d set diffuse reflectance for current material
225 td tau_d set diffuse transmittance for current material
226 ed epsilon_d set diffuse emittance for current material
227 rs rho_s alpha_r set specular reflectance for current material
228 ts tau_s alpha_t set specular transmittance for current material
229 ir n_real n_imag set index of refraction for current material
230 _ _ _
231 v [id [= [template]]] get/set vertex context
232 p x y z set point position for current vertex
233 n dx dy dz set surface normal for current vertex
234 _ _ _
235 f v1 v2 v3 ... polygon using current material, spec. vertices
236 fh v1 v2 v3 - ... face with explicit holes
237 sph vc radius sphere
238 cyl v1 radius v2 truncated right cylinder (open-ended)
239 cone v1 rad1 v2 rad2 truncated right cone (open-ended)
240 prism v1 v2 v3 ... length truncated right prism (closed solid)
241 ring vc rmin rmax circular ring with inner and outer radii
242 torus vc rmin rmax circular torus with inner and outer radii
243 .TE
244 .QP
245 .B "Table 1".
246 MGF entities and their arguments.
247 Arguments in brackets are optional.
248 Arguments in curly braces mean one of the given choices must
249 appear.
250 Ellipsis (...) mean that any number of arguments may be given.
251 .sp
252 .KE
253 .LP
254 A
255 .I context
256 describes the current state of the interpreter, and affects or is
257 affected by certain entities as they are read in.
258 MGF contexts can be divided into two types,
259 .I "hierarchical contexts"
260 and
261 .I "named contexts".
262 .LP
263 Hierarchical contexts are manipulated by a single entity and
264 have an associated "stack" onto which new
265 contexts are "pushed" using the entity.
266 The last context may be "popped" by giving the entity again with no
267 arguments.
268 The two hierarchical contexts in MGF are the current transformation,
269 manipulated with the
270 .UL xf
271 entity, and the current object, manipulated with the
272 .UL o
273 entity.
274 .KF
275 .TS
276 expand, allbox;
277 l c l l l.
278 Context Cntl. Entity Default Value Field Entities Affects
279 = = = = =
280 Object o - - -
281 Transform xf - - T{
282 f, fh, sph, cyl, cone,
283 ring, torus, prism
284 T}
285 Material m 2-sided black T{
286 sides, rd, td,
287 ed, rs, ts, ir
288 T} T{
289 f, fh, sph, cyl, cone,
290 ring, torus, prism
291 T}
292 Color c neutral grey T{
293 cxy, cspec, cct, cmix
294 T} T{
295 rd, td, ed, rs, ts
296 T}
297 Vertex v T{
298 (0,0,0),
299 no normal
300 T} p, n T{
301 f, fh, sph, cyl, cone,
302 ring, torus, prism
303 T}
304 .TE
305 .QP
306 .B "Table 2".
307 MGF contexts and their related entities and default values.
308 .sp
309 .KE
310 .LP
311 Named contexts in contrast hold sets of values that are swapped
312 in and out one at a time.
313 There are three named contexts in MGF, the current material, the
314 current color and the current vertex.
315 Each one may be associated with an identifier (any non-white
316 sequence of printing ASCII characters beginning with a letter),
317 and one of each is in effect at any given time.
318 Initially, these contexts are unnamed, and invoking an unnamed
319 context always returns to the original (default) values.
320 (See Table 2 for a list of contexts, their related
321 entities and defaults.)\0
322 .LP
323 It is easiest to think of a context as a "scratch space" where
324 values are written by some entities and read by others.
325 Naming a context allows us to reestablish the same scratch space
326 later, usually for reference but it can be altered as well.
327 Let us say we wanted to create a smooth blue plastic material with a
328 diffuse reflectance of 20% and a specular reflectance of 4%:
329 .DS
330 # Establish a new material context called "blue_plastic"
331 m blue_plastic =
332 # Reestablish a previous color context called "blue"
333 c blue
334 # Set the diffuse reflectance, which uses the above color
335 rd .20
336 # Get the unnamed color context (always starts out grey)
337 c
338 # Set the specular reflectance, which is uncolored
339 rs .04 0
340 # We're done, the current material context is now "blue_plastic"
341 .DE
342 Note that the above assumes that we have previously defined a color
343 context named "blue".
344 If we forgot to do that, the above description would generate an
345 "undefined" error.
346 The color context affects the material context indirectly because it
347 is read by the specular and diffuse reflectance entities, which are
348 in turn written to the current material.
349 It is not necessary to indent the entities that affect the material
350 definition, but it improves readability.
351 Note also that there is no explicit end to the material definition.
352 As long as a context remains in effect, its contents may be altered
353 by its field entities.
354 This will not affect previous uses of the context, however.
355 For example, a surface entity following the above definition will
356 have the specified color and reflectance, and later changes to the
357 material "blue_plastic" will have no effect on it.
358 .LP
359 Each of the three named contexts has an associated entity that
360 controls it.
361 The material context is controlled by the
362 .UL m
363 entity, the color context is controlled by the
364 .UL c
365 entity, and the vertex context is controlled by the
366 .UL v
367 entity.
368 There are exactly four forms for each entity.
369 The first form is the keyword by itself, which establishes
370 an unnamed context with predetermined default values.
371 This is a useful way to set values without worrying about saving
372 them for recall later.
373 The second form is to give the keyword with a previously defined
374 name.
375 This reestablishes a prior context for reuse.
376 The third form is to give the keyword with a name followed by an
377 equals sign.
378 (There must be a space between the name and the equals sign, since
379 it is a separate argument.)\0
380 This establishes a new context and assigns it the same default
381 values as the unnamed context.
382 The fourth and final form gives the keyword followed by a name then
383 an equals then the name of a previous context definition.
384 This establishes a new context for the first name, assigning the
385 values from the second named context rather than the usual defaults.
386 This is a convenient way create an alias or
387 to modify a context under a new name (i.e. "save as").
388 .NH 2
389 Hierarchical Contexts and Transformations
390 .LP
391 As mentioned in the last subsection, there are two hierarchical
392 contexts in MGF, the current object and the current transformation.
393 We will start by discussing the current object, since it is
394 the simpler of the two.
395 .NH 3
396 Objects
397 .LP
398 There is no particular need in lighting simulation or rendering to
399 name objects, but it may help the user
400 to know what object a particular surface is associated with.
401 The
402 .UL o
403 entity provides a convenient mechanism for associating names with
404 surfaces.
405 The basic use of this entity is as follows:
406 .DS
407 o object_name
408 [object entities...]
409 o subobject_name
410 [subobject entities...]
411 o
412 [more object entities and subobjects...]
413 o
414 .DE
415 The
416 .UL o
417 keyword by itself marks the end of an object context.
418 Any number of hierarchical context levels are supported, and there are no
419 rules governing the choice of object names except that they begin
420 with a letter and be made up of printing, non-white ASCII characters.
421 Indentation is not necessary of course, but it does improve
422 readability.
423 .NH 3
424 Transformations
425 .LP
426 MGF supports only rigid-body (i.e. non-distorting) transformations
427 with uniform scaling.
428 Unlike the other contexts, transformations have no associated
429 name, only arguments.
430 Thus, there is no way to reestablish a previous transformation other
431 than to give the same arguments over again.
432 Since the arguments are concise and self-explanatory, this was thought
433 sufficient.
434 The following transformation flags and
435 parameters are defined:
436 .TS
437 center;
438 l l.
439 -t dx dy dz translate objects along the given vector
440 -rx degrees rotate objects about the X-axis
441 -ry degrees rotate objects about the Y-axis
442 -rz degrees rotate objects about the Z-axis
443 -s scalefactor scale objects by the given factor
444 -mx mirror objects about the Y-Z plane
445 -my mirror objects about the X-Z plane
446 -mz mirror objects about the X-Y plane
447 -i N repeat the following arguments N times
448 -a N make an array of N geometric instances
449 .TE
450 Transform arguments have a cumulative effect.
451 That is, a rotation
452 about X of 20 degrees followed by a rotation about X of -50 degrees
453 results in a total rotation of -30 degrees.
454 However, if the two
455 rotations are separated by some translation vector, the cumulative
456 effect is quite different.
457 It is best to think of each argument as
458 acting on the included geometric objects, and each subsequent transformation
459 argument affects the objects relative to their new position/orientation.
460 .LP
461 For example, rotating an object about its center is most easily done
462 by translating
463 the object back to the origin, applying the desired rotation, and translating
464 it again back to its original position, like so:
465 .DS
466 # rotate an included object 20 degrees clockwise looking down
467 # an axis parallel to Y and passing through the point (15,0,-35)
468 xf -t -15 0 35 -ry -20 -t 15 0 -35
469 i object.mgf
470 xf
471 .DE
472 Note that the include entity,
473 .UL i,
474 permits a transformation to be given with it, so the above could
475 have been written more compactly as:
476 .DS
477 i object.mgf -t -15 0 35 -ry -20 -t 15 0 -35
478 .DE
479 .LP
480 Rotations are given in degrees counter-clockwise about a principal axis.
481 That is, with the thumb of the right hand pointing in the direction
482 of the axis, rotation follows the curl of the fingers.
483 .LP
484 The transform entity itself is cumulative, but in the reverse
485 order to its arguments.
486 That is, later transformations (i.e. enclosed transformations)
487 are prepended to existing (i.e. enclosing) ones.
488 A transform command
489 with no arguments is used to return to the previous condition.
490 It is
491 necessary that transforms and their end statements ("xf" by itself) be
492 balanced in a file, so that later or enclosing files are not affected.
493 .LP
494 Transformations apply only to geometric types, e.g. polygons, spheres, etc.
495 Vertices and the components that go into geometry are not directly affected.
496 This is to avoid confusion and the inadvertent multiple application of a
497 given transformation.
498 For example:
499 .DS
500 xf -t 5 0 0
501 v v1 =
502 p 0 10 0
503 n 0 0 1
504 xf -rx 180
505 # Transform now in effect is "-rx 180 -t 5 0 0"
506 ring v1 0 2
507 xf
508 xf
509 .DE
510 The final ring center is (5,-10,0) -- note that the vertex itself is
511 not affected by the transformation, only the geometry that calls on
512 it.
513 The normal orientation is (0,0,-1) due to the rotation about X,
514 which also reversed the sign of the central Y coordinate.
515 .NH 3
516 Arrays
517 .LP
518 The -a N transform specification causes the following transform
519 arguments to be repeated along with the contents of the included
520 objects N times.
521 The first instance of the geometry will be in its
522 initial location; the second instance will be repositioned according
523 to the named transformation; the third instance will be repositioned by
524 applying this transformation twice, and so on up to N-1 applications.
525 .LP
526 Multi-dimensional arrays may be specified with a single include
527 entity by giving multiple array commands separated by their
528 corresponding transforms.
529 A final transformation may be given
530 by preceding it with a -i 1 specification.
531 In other words, the
532 scope of an array command continues until the next -i or -a option.
533 .LP
534 The following MGF description places 60 spheres at a one unit spacing
535 in a 3x4x5 array, then moves the whole thing to an origin of
536 (15,30,45):
537 .DS
538 v v0 =
539 p 0 0 0
540 xf -a 3 -t 1 0 0 -a 4 -t 0 1 0 -a 5 -t 0 0 1 -i 1 -t 15 30 45
541 sph v0 0.1
542 xf
543 .DE
544 Note the "-i 1" in the specification, which marks the end of the
545 third array arguments before the final translation.
546 .NH 2
547 Detailed MGF Example
548 .LP
549 The following example of a simple room with a single door
550 and six file cabinets shows MGF in action, with copious comments to
551 help explain what's going on.
552 .LP
553 .DS
554 # "ceiling_tile" is a diffuse white surface with 75% reflectance:
555 # Create new named material context and clear it
556 m ceiling_tile =
557 # Specify one-sided material so we can see through from above
558 sides 1
559 # Set neutral color
560 c
561 # Set diffuse reflectance
562 rd .75
563 # "stainless_steel" is a mostly specular surface with 70% reflectance:
564 m stainless_steel =
565 sides 1
566 c
567 # Set specular reflectance to 50%, .08 roughness
568 rs .5 .08
569 # Other 20% reflectance is diffuse
570 rd .2
571
572 # The following materials were measured with a spectrophotometer:
573 m beige_paint =
574 sides 1
575 # Set diffuse spectral reflectance
576 c
577 # Spectrum measured in 10 nm increments from 400 to 700 nm
578 cspec 400 700 35.29 44.87 47.25 47.03 46.87 47.00 47.09 \\\\
579 47.15 46.80 46.17 46.26 48.74 51.08 51.31 51.10 \\\\
580 51.11 50.52 50.36 51.72 53.61 53.95 52.08 49.49 \\\\
581 48.30 48.75 49.99 51.35 52.75 54.44 56.34 58.00
582 rd 0.5078
583 # Neutral (grey) specular component
584 c
585 rs 0.0099 0.08000
586 m mottled_carpet =
587 sides 1
588 c
589 cspec 400 700 11.23 11.28 11.39 11.49 11.61 11.73 11.88 \\\\
590 12.02 12.12 12.19 12.30 12.37 12.37 12.36 12.34 \\\\
591 12.28 12.22 12.29 12.45 12.59 12.70 12.77 12.82 \\\\
592 12.88 12.98 13.24 13.67 14.31 15.55 17.46 19.75
593 rd 0.1245
594 m reddish_cloth =
595 # 2-sided so we can observe it from behind
596 sides 2
597 c
598 cspec 400 700 28.62 27.96 27.86 28.28 29.28 30.49 31.61 \\\\
599 32.27 32.26 31.83 31.13 30.07 29.14 29.03 29.69 \\\\
600 30.79 32.30 33.90 34.56 34.32 33.85 33.51 33.30 \\\\
601 33.43 34.06 35.26 37.04 39.41 42.55 46.46 51.00
602 rd 0.3210
603 m burgundy_formica =
604 sides 1
605 c
606 cspec 400 700 3.86 3.74 3.63 3.51 3.34 3.21 3.14 \\\\
607 3.09 3.08 3.14 3.13 2.91 2.72 2.74 2.72 \\\\
608 2.60 2.68 3.40 4.76 6.05 6.65 6.75 6.68 \\\\
609 6.63 6.56 6.51 6.46 6.41 6.36 6.34 6.34
610 rd 0.0402
611 c
612 rs 0.0284 0.05000
613 m speckled_grey_formica =
614 sides 1
615 c
616 cspec 400 700 30.95 44.77 51.15 52.60 53.00 53.37 53.68 \\\\
617 54.07 54.33 54.57 54.85 55.20 55.42 55.51 55.54 \\\\
618 55.46 55.33 55.30 55.52 55.81 55.91 55.92 56.00 \\\\
619 56.22 56.45 56.66 56.72 56.58 56.44 56.39 56.39
620 rd 0.5550
621 c
622 rs 0.0149 0.15000
623
624 # 40' x 22' x 9' office space with no windows and one door
625
626 # All measurements are in inches, so enclose with a metric conversion:
627 xf -s .0254
628
629 # The room corner vertices:
630 v rc.xyz =
631 p 0 0 0
632 v rc.Xyz =
633 p 480 0 0
634 v rc.xYz =
635 p 0 264 0
636 v rc.xyZ =
637 p 0 0 108
638 v rc.XYz =
639 p 480 264 0
640 v rc.xYZ =
641 p 0 264 108
642 v rc.XyZ =
643 p 480 0 108
644 v rc.XYZ =
645 p 480 264 108
646
647 # The floor:
648 # Push object name
649 o floor
650 # Get previously defined carpet material
651 m mottled_carpet
652 # Polygonal face using defined vertices
653 f rc.xyz rc.Xyz rc.XYz rc.xYz
654 # Pop object name
655 o
656
657 # The ceiling:
658 o ceiling
659 m ceiling_tile
660 f rc.xyZ rc.xYZ rc.XYZ rc.XyZ
661 o
662
663 # The door outline vertices:
664 v do.xz =
665 p 216 0 0
666 v do.Xz =
667 p 264 0 0
668 v do.xZ =
669 p 216 0 84
670 v do.XZ =
671 p 264 0 84
672
673 # The walls:
674 o wall
675 m beige_paint
676 o x
677 f rc.xyz rc.xYz rc.xYZ rc.xyZ
678 o
679 o X
680 f rc.Xyz rc.XyZ rc.XYZ rc.XYz
681 o
682 o y
683 f rc.xyz rc.xyZ rc.XyZ rc.Xyz do.Xz do.XZ do.xZ do.xz
684 o
685 o Y
686 f rc.xYz rc.XYz rc.XYZ rc.xYZ
687 o
688 o
689
690 # The door and jam vertices:
691 v djo.xz =
692 p 216 .5 0
693 v djo.xZ =
694 p 216 .5 84
695 v djo.XZ =
696 p 264 .5 84
697 v djo.Xz =
698 p 264 .5 0
699 v dji.Xz =
700 p 262 .5 0
701 v dji.XZ =
702 p 262 .5 82
703 v dji.xZ =
704 p 218 .5 82
705 v dji.xz =
706 p 218 .5 0
707 v door.xz =
708 p 218 0 0
709 v door.xZ =
710 p 218 0 82
711 v door.XZ =
712 p 262 0 82
713 v door.Xz =
714 p 262 0 0
715
716 # The door, jam and knob
717 o door
718 m burgundy_formica
719 f door.xz door.xZ door.XZ door.Xz
720 o jam
721 m beige_paint
722 f djo.xz djo.xZ djo.XZ djo.Xz dji.Xz dji.XZ dji.xZ dji.xz
723 f djo.xz do.xz do.xZ djo.xZ
724 f djo.xZ do.xZ do.XZ djo.XZ
725 f djo.Xz djo.XZ do.XZ do.Xz
726 f dji.xz dji.xZ door.xZ door.xz
727 f dji.xZ dji.XZ door.XZ door.xZ
728 f dji.Xz door.Xz door.XZ dji.XZ
729 o
730 o knob
731 m stainless_steel
732 # Define vertices needed for curved geometry
733 v kb1 =
734 p 257 0 36
735 v kb2 =
736 p 257 .25 36
737 n 0 1 0
738 v kb3 =
739 p 257 2 36
740 # 1" diameter cylindrical base from kb1 to kb2
741 cyl kb1 1 kb2
742 # Ring at base of knob stem
743 ring kb2 .4 1
744 # Knob stem
745 cyl kb2 .4 kb3
746 # Spherical knob
747 sph kb3 .85
748 o
749 o
750
751 # Six file cabinets (36" wide each)
752 # ("filecab.inc" was given as an earlier example in Section 1.2)
753 o filecab.x
754 # include a file as an array of three 36" apart
755 i filecab.inc -t -36 0 0 -rz -90 -t 1 54 0 -a 3 -t 0 36 0
756 o
757 o filecab.X
758 # the other three cabinets
759 i filecab.inc -rz 90 -t 479 54 0 -a 3 -t 0 36 0
760 o
761
762 # End of transform from inches to meters:
763 xf
764
765 # The 10 recessed fluorescent ceiling fixtures
766 ies hlrs2gna.ies -t 1.2192 2.1336 2.74 -a 5 -t 2.4384 0 0 -a 2 -t 0 2.4384 0
767 .DE
768 .bp
769 .NH
770 MGF Entity Reference
771 .LP
772 There are currently 28 entities in the MGF specification.
773 For ease of reference we have broken these into five categories:
774 .IP 1.
775 General
776 .TS
777 lw(.75i) lw(1.75i) lw(3i).
778 # [anything ...] a comment
779 o [name] begin/end object context
780 xf [xform] begin/end transformation context
781 i pathname [xform] include file (with transformation)
782 ies pathname [-m f][xform] include IES luminaire (with transformation)
783 .TE
784 .IP 2.
785 Color
786 .TS
787 lw(.75i) lw(1.75i) lw(3i).
788 c [id [= [template]]] get/set color context
789 cxy x y set CIE (x,y) chromaticity for current color
790 cspec l_min l_max v1 v2 ... set relative spectrum for current color
791 cct temperature set spectrum based on black body temperature
792 cmix w1 c1 w2 c2 ... mix named colors to make current color
793 .TE
794 .IP 3.
795 Material
796 .TS
797 lw(.75i) lw(1.75i) lw(3i).
798 m [id [= [template]]] get/set material context
799 sides {1|2} set number of sides for current material
800 rd rho_d set diffuse reflectance for current material
801 td tau_d set diffuse transmittance for current material
802 ed epsilon_d set diffuse emittance for current material
803 rs rho_s alpha_r set specular reflectance for current material
804 ts tau_s alpha_t set specular transmittance for current material
805 ir n_real n_imag set index of refraction for current material
806 .TE
807 .IP 4.
808 Vertex
809 .TS
810 lw(.75i) lw(1.75i) lw(3i).
811 v [id [= [template]]] get/set vertex context
812 p x y z set point position for current vertex
813 n dx dy dz set surface normal for current vertex
814 .TE
815 .IP 5.
816 Geometry
817 .TS
818 lw(.75i) lw(1.75i) lw(3i).
819 f v1 v2 v3 ... polygon using current material, spec. vertices
820 fh v1 v2 v3 - ... face with explicit holes
821 sph vc radius sphere
822 cyl v1 radius v2 truncated right cylinder (open-ended)
823 cone v1 rad1 v2 rad2 truncated right cone (open-ended)
824 prism v1 v2 v3 ... length truncated right prism (closed solid)
825 ring vc rmin rmax circular ring with inner and outer radii
826 torus vc rmin rmax circular torus with inner and outer radii
827 .TE
828 .ds LH General Entities
829 .ds RH #
830 .bp
831 .SH
832 NAME
833 .LP
834 # - a comment
835 .SH
836 SYNOPSIS
837 .LP
838 .B #
839 [
840 .I anything
841 ]
842 .SH
843 DESCRIPTION
844 .LP
845 A comment is a bit of text explanation.
846 Since it is an entity like any other (except that it has no effect),
847 there must be at least one space between the keyword (which is a
848 pound sign) and the "arguments," and the end of line may be escaped
849 as usual with the backslash character ('\\').
850 .LP
851 A comment may actually be used to hold auxiliary information such as
852 view parameters, which may be interpreted by some destination program.
853 Care should be taken under such circumstances that the user does not
854 inadvertently mung or mimic this information in other comments, and
855 it is therefore advisable to use an additional set of identifying
856 characters to distinguish such data.
857 .SH
858 EXAMPLE
859 .DS
860 # The following include file is in inches, so convert to meters
861 i cubgeom.inc -s .0254
862 # Stuff we don't want to see at the moment:
863 # i person.mgf -t 3 2 0
864 # ies hlrs3gna.ies -rz 90 -t 1.524 1.8288 2.74 \\\\
865 -a 6 -t 1.8288 0 0 -a 2 -t 0 3.048 0
866 .DE
867 .ds RH O
868 .bp
869 .SH
870 NAME
871 .LP
872 o - begin or end object context
873 .SH
874 SYNOPSIS
875 .LP
876 .B o
877 [
878 .I name
879 ]
880 .SH
881 DESCRIPTION
882 .LP
883 If
884 .I name
885 is given, we push a new object context onto the stack, which is to
886 say that we begin a new subobject by this name\(dg.
887 .FS
888 \(dgA name is any sequence of printing, non-white ASCII characters
889 beginning with a letter.
890 .FE
891 If the
892 .UL o
893 keyword is given by itself, then we pop the last object context off
894 the stack, which means that we leave the current subobject.
895 .LP
896 All geometry between the start of an object context and its matching
897 end statement is associated with the given name.
898 This may be used in modeling software to help identify objects and
899 subobjects, or it may be ignored altogether.
900 .LP
901 Object begin and end statements should be balanced in a file, and
902 care should be taken not to overlap transform
903 .UL (xf)
904 contexts with object contexts, especially when arrays are involved.
905 This is because the standard parser will assign object contexts to
906 instanced geometry, which can get confused with other object
907 contexts if a clear enclosure is not maintained.
908 .SH
909 EXAMPLE
910 .DS
911 o body
912 o torso
913 i torso.mgf
914 o
915 o arm
916 o left
917 i leftarm.mgf
918 o
919 o right
920 i leftarm.mgf -mx
921 o
922 o
923 o
924 .DE
925 .SH
926 SEE ALSO
927 .LP
928 .UL xf
929 .ds RH XF
930 .bp
931 .SH
932 NAME
933 .LP
934 xf - begin or end transformation context
935 .SH
936 SYNOPSIS
937 .LP
938 .B xf
939 [
940 .I transform
941 ]
942 .SH
943 DESCRIPTION
944 .LP
945 If a set of
946 .I transform
947 arguments are given, we push a new transformation context onto the
948 stack.
949 If the
950 .UL xf
951 keyword is given by itself, then we pop the last transformation
952 context off the stack.
953 The total transformation in effect at any given time is
954 computed by prepending each set subcontext arguments onto those of
955 its enclosing context.
956 This and other details about transformation specifications
957 are explained in some detail in section 2.2.2.
958 .LP
959 The following transformation flags and
960 parameters are defined:
961 .TS
962 center;
963 l l.
964 -t dx dy dz translate objects along the given vector
965 -rx degrees rotate objects about the X-axis
966 -ry degrees rotate objects about the Y-axis
967 -rz degrees rotate objects about the Z-axis
968 -s scalefactor scale objects by the given factor
969 -mx mirror objects about the Y-Z plane
970 -my mirror objects about the X-Z plane
971 -mz mirror objects about the X-Y plane
972 -i N repeat the following arguments N times
973 -a N make an array of N geometric instances
974 .TE
975 .SH
976 EXAMPLE
977 .DS
978 # Create 3x5 array of evenly-spaced spheres (grid size = 3)
979 v vc =
980 p 0 0 0
981 xf -t 1 1 10 -a 3 -t 3 0 0 -a 5 -t 0 3 0
982 sph vc .5
983 xf
984 .DE
985 .SH
986 SEE ALSO
987 .LP
988 .UL i,
989 .UL ies,
990 .UL o
991 .ds RH I
992 .bp
993 .SH
994 NAME
995 .LP
996 i - include MGF data file
997 .SH
998 SYNOPSIS
999 .LP
1000 .B i
1001 .I pathname
1002 [
1003 .I transform
1004 ]
1005 .SH
1006 DESCRIPTION
1007 .LP
1008 Include the information contained in the file
1009 .I pathname.
1010 If a
1011 .I transform
1012 specification is given, then it will be applied as though the
1013 include statement were enclosed by beginning and ending
1014 .UL xf
1015 entities with this transformation.
1016 .LP
1017 The
1018 .I pathname
1019 will be interpreted relative to the enclosing MGF file.
1020 That is, if the file containing the include statement is in some
1021 parent or subdirectory, then the given pathname is appended to this
1022 directory.
1023 It is illegal to specify a
1024 .I pathname
1025 relative to the root directory, and the MGF standard requires that
1026 all filenames adhere to the ISO-9660 8.3 name format for maximum
1027 portability between systems.
1028 The directory separator is defined to be slash ('/'), and drive
1029 specifications (such as "c:") are not allowed.
1030 All pathnames should be given in lower case, and will be converted to
1031 upper case on systems that require it.
1032 (That way, there are no accidental name collisions.)\0
1033 .LP
1034 The suggested suffix for MGF-adherent files is ".mgf".
1035 Files that are not in metric units but are in MGF may be given any
1036 suffix, but we suggest using ".inc" as a convention.
1037 .SH
1038 EXAMPLE
1039 .DS
1040 # Define vertices for 62x30" partition
1041 i pv62x30.inc
1042 # Insert 2 62x30" partitions
1043 o cpart1
1044 i partn.inc -t 75 130.5 0
1045 o
1046 o cpart3
1047 i partn.inc -t 186 130.5 0
1048 o
1049 # Define vertices for 62x36" partition
1050 i pv62x36.inc
1051 # Insert 62x36" partition
1052 o cpart2
1053 i partn.inc -t 105 130.5 0
1054 o
1055 .DE
1056 .SH
1057 SEE ALSO
1058 .LP
1059 .UL ies,
1060 .UL o,
1061 .UL xf
1062 .ds RH IES
1063 .bp
1064 .SH
1065 NAME
1066 .LP
1067 ies - include IESNA luminaire file
1068 .SH
1069 SYNOPSIS
1070 .LP
1071 .B ies
1072 .I pathname
1073 [
1074 .B \-m
1075 .I multiplier
1076 ]
1077 [
1078 .I transform
1079 ]
1080 .SH
1081 DESCRIPTION
1082 .LP
1083 Load the IES standard luminaire information contained in the file
1084 .I pathname.
1085 If a
1086 .I multiplier
1087 is given, all candela values will be multiplied by this factor.
1088 (This option must appear first if present.)\0
1089 If a
1090 .I transform
1091 specification is given, then it will be applied as though the
1092 statement were enclosed by beginning and ending
1093 .UL xf
1094 entities with this transformation.
1095 .LP
1096 The
1097 .I pathname
1098 will be interpreted relative to the enclosing MGF file, and all
1099 restrictions discussed under the
1100 .UL i
1101 entity also apply to the IES file name.
1102 The suggested suffix is ".ies", but this has not been followed
1103 consistently by lighting manufacturers.
1104 .SH
1105 EXAMPLE
1106 .DS
1107 # Insert 10 2x4' fluorescent troffers in two groups
1108 ies cf9pr240.ies -t 3.6576 2.1336 2.74 -a 3 -t 2.4384 0 0 -a 2 -t 0 2.4384 0
1109 ies cf9pr240.ies -rz 90 -t 1.2192 1.8288 2.74 \\\\
1110 -a 2 -t 9.7536 0 0 -a 2 -t 0 3.048 0
1111 .DE
1112 .SH
1113 SEE ALSO
1114 .LP
1115 .UL i,
1116 .UL o,
1117 .UL xf
1118 .ds LH Color Entities
1119 .ds RH C
1120 .bp
1121 .SH
1122 NAME
1123 .LP
1124 c - get or set the current color context
1125 .SH
1126 SYNOPSIS
1127 .LP
1128 .B c
1129 [
1130 .I id
1131 [
1132 .B =
1133 [
1134 .I template
1135 ]
1136 ]
1137 ]
1138 .SH
1139 DESCRIPTION
1140 .LP
1141 If the
1142 .UL c
1143 keyword is given by itself, then it establishes the unnamed color
1144 context, which is neutral (i.e. equal-energy) grey.
1145 This context may be modified, but the changes will not be saved.
1146 .LP
1147 If the keyword is followed by an identifier
1148 .I id,
1149 then it reestablishes a previous context.
1150 If the specified context was never defined, an error will result.
1151 .LP
1152 If the entity is given with an identifier
1153 followed by an equals sign ('='), then a new context is established,
1154 and cleared to the default neutral grey.
1155 (Note that the equals sign must be separated from other
1156 arguments by white space to be properly recognized.)\0
1157 If the equals sign is followed by a second identifier
1158 .I template,
1159 then this previously defined color will be used as a source of
1160 default values rather than grey.
1161 This is most useful for establishing a color alias.
1162 .SH
1163 EXAMPLE
1164 .DS
1165 # Define the color "red32"
1166 c red32 =
1167 cxy .42 .15
1168 # Make "cabinet_color" an alias for "red32"
1169 c cabinet_color = red32
1170
1171 # Later in another part of the description...
1172
1173 # Get our cabinet color
1174 c cabinet_color
1175 # Get the geometry
1176 i cabgeom.mgf
1177 .DE
1178 .SH
1179 SEE ALSO
1180 .LP
1181 .UL cct,
1182 .UL cmix,
1183 .UL cspec,
1184 .UL cxy,
1185 .UL m
1186 .ds RH CXY
1187 .bp
1188 .SH
1189 NAME
1190 .LP
1191 cxy - set the CIE (x,y) chromaticity for the current color
1192 .SH
1193 SYNOPSIS
1194 .LP
1195 .B cxy
1196 .I "x y"
1197 .SH
1198 DESCRIPTION
1199 .LP
1200 This entity sets the current color using (x,y) chromaticity
1201 coordinates for the 1931 CIE standard 2 degree observer.
1202 Legal values for
1203 .I x
1204 and
1205 .I y
1206 are greater than zero and sum to less than one, and more
1207 specifically they must fit within the curve of the visible spectrum.
1208 The
1209 .I x
1210 coordinate roughly corresponds to the red part of the spectrum and
1211 the
1212 .I y
1213 coordinate corresponds to the green.
1214 The CIE z coordinate is implicit, since it is equal to (1-x-y).
1215 .LP
1216 All colors in MGF are absolute, thus colorimeter measurements should
1217 be conducted the same for surfaces as for light sources.
1218 Applying a standard illuminant calculation is redundant and
1219 introduces inaccuracies, and should therefore be avoided if
1220 possible.
1221 .LP
1222 Conversion between CIE colors and those more commonly used in
1223 computer graphics are described in the application notes section
1224 6.1.1.
1225 .SH
1226 EXAMPLE
1227 .DS
1228 # Set unnamed color context
1229 c
1230 # Set CIE chromaticity to a bluish hue
1231 cxy .15 .2
1232 # Apply color to diffuse reflectance of 15%
1233 rd .15
1234 .DE
1235 .SH
1236 SEE ALSO
1237 .LP
1238 .UL c,
1239 .UL cct,
1240 .UL cmix,
1241 .UL cspec
1242 .ds RH CSPEC
1243 .bp
1244 .SH
1245 NAME
1246 .LP
1247 cspec - set the relative spectrum for the current color
1248 .SH
1249 SYNOPSIS
1250 .LP
1251 .B cspec
1252 .I "l_min l_max o1 o2 ... oN"
1253 .SH
1254 DESCRIPTION
1255 .LP
1256 Assign a relative spectrum measured between
1257 .I l_min
1258 and
1259 .I l_max
1260 nanometers at evenly spaced intervals.
1261 The first value,
1262 .I o1
1263 corresponds to the measurement at
1264 .I l_min,
1265 and the last value,
1266 .I oN
1267 corresponds to the measurement at
1268 .I l_max.
1269 Values in between are separated by
1270 .I "(l_max-l_min)/(N-1)"
1271 nanometers.
1272 All values should be non-negative unless defining a component for
1273 complementary color mixing, and the spectrum outside of the
1274 specified range is assumed to be zero.
1275 (The visible range is 380 to 780 nm.)\0
1276 The actual units and scale of the measurements do not matter,
1277 since the total will be
1278 normalized according to whatever the color is modifying
1279 (e.g. photometric reflectance or emittance).
1280 .SH
1281 EXAMPLE
1282 .DS
1283 # Color measured at 10 nm increments from 400 to 700
1284 m reddish_cloth =
1285 c
1286 cspec 400 700 28.62 27.96 27.86 28.28 29.28 30.49 31.61 \\\\
1287 32.27 32.26 31.83 31.13 30.07 29.14 29.03 29.69 \\\\
1288 30.79 32.30 33.90 34.56 34.32 33.85 33.51 33.30 \\\\
1289 33.43 34.06 35.26 37.04 39.41 42.55 46.46 51.00
1290 rd 0.3210
1291 .DE
1292 .SH
1293 SEE ALSO
1294 .LP
1295 .UL c,
1296 .UL cct,
1297 .UL cmix,
1298 .UL cxy
1299 .ds RH CCT
1300 .bp
1301 .SH
1302 NAME
1303 .LP
1304 cct - set the current color to a black body spectrum
1305 .SH
1306 SYNOPSIS
1307 .LP
1308 .B cct
1309 .I temperature
1310 .SH
1311 DESCRIPTION
1312 .LP
1313 The
1314 .UL cct
1315 entity sets the current color to the spectrum of an ideal
1316 black body radiating at
1317 .I temperature
1318 degrees Kelvin.
1319 This is often the most convenient way to set the color of an
1320 incandescent light source, but it is not recommended for
1321 fluorescent lamps or other materials that do not fit a
1322 black body spectrum.
1323 .SH
1324 EXAMPLE
1325 .DS
1326 # Define an incandescent source material at 3000 degrees K
1327 m incand3000k =
1328 c
1329 cct 3000
1330 ed 1500
1331 .DE
1332 .SH
1333 SEE ALSO
1334 .LP
1335 .UL c,
1336 .UL cmix,
1337 .UL cspec,
1338 .UL cxy
1339 .ds RH CMIX
1340 .bp
1341 .SH
1342 NAME
1343 .LP
1344 cmix - mix two or more named colors to make the current color
1345 .SH
1346 SYNOPSIS
1347 .LP
1348 .B cmix
1349 .I "w1 c1 w2 c2 ..."
1350 .SH
1351 DESCRIPTION
1352 .LP
1353 The
1354 .UL cmix
1355 entity sums together two or more named colors using specified
1356 weighting coefficients, which correspond to the relative
1357 photometric brightness of each.
1358 As in all color specifications, the result is normalized so the
1359 absolute scale of the weights does not matter, only their relative
1360 values.
1361 .LP
1362 If any of the colors is a spectral quantity (i.e. from a
1363 .UL cspec
1364 or
1365 .UL cct
1366 entity), then all the colors are first converted to spectral
1367 quantities.
1368 This is done with an approximation for CIE (x,y) chromaticities,
1369 which may be problematic depending on their values.
1370 In general, it is safest to add together colors that are either
1371 all spectral quantities or all CIE quantities.
1372 .SH
1373 EXAMPLE
1374 .DS
1375 # Define RGB primaries for a standard color monitor
1376 c R =
1377 cxy 0.640 0.330
1378 c G =
1379 cxy 0.290 0.600
1380 c B =
1381 cxy 0.150 0.060
1382 # Mix them together in appropriate amounts for white
1383 c white =
1384 cmix 0.265 R 0.670 G 0.065 B
1385 .DE
1386 .SH
1387 SEE ALSO
1388 .LP
1389 .UL c,
1390 .UL cct,
1391 .UL cspec,
1392 .UL cxy
1393 .ds LH Material Entities
1394 .ds RH M
1395 .bp
1396 .SH
1397 NAME
1398 .LP
1399 m - get or set the current material context
1400 .SH
1401 SYNOPSIS
1402 .LP
1403 .B m
1404 [
1405 .I id
1406 [
1407 .B =
1408 [
1409 .I template
1410 ]
1411 ]
1412 ]
1413 .SH
1414 DESCRIPTION
1415 .LP
1416 If the
1417 .UL m
1418 keyword is given by itself, then it establishes
1419 the unnamed material context, which is a perfect two-sided black absorber.
1420 This context may be modified, but the changes will not be saved.
1421 .LP
1422 If the keyword is followed by an identifier
1423 .I id,
1424 then it reestablishes a previous context.
1425 If the specified context was never defined, an error will result.
1426 .LP
1427 If the entity is given with an identifier
1428 followed by an equals sign ('='), then a new context is established,
1429 and cleared to the default material.
1430 (Note that the equals sign must be separated from other
1431 arguments by white space to be properly recognized.)\0
1432 If the equals sign is followed by a second identifier
1433 .I template,
1434 then this previously defined material will be used as a source of
1435 default values instead.
1436 This may be used to establish a material alias, or to modify an
1437 existing material and give it a new name.
1438 .LP
1439 The sum of the diffuse and specular reflectances and transmittances
1440 must not be greater than one (with no negative values, obviously).
1441 These values are assumed to be measured at normal incidence.
1442 If an index of refraction is given, this may modify the balance between
1443 diffuse and specular reflectance at other incident angles.
1444 If the
1445 material is one-sided (see
1446 .UL sides
1447 entity), then it may be a dielectric interface.
1448 In this case, the specular transmittance given is that which would be
1449 measured at normal incidence for a pane of the material 5 mm thick.
1450 This is important for figuring the actual transmittance for non-planar
1451 geometries assuming a uniformly absorbing medium.
1452 (Diffuse transmittance will not be affected by thickness.)\0
1453 If the index of
1454 refraction has an imaginary part, then the surface is a metal and this
1455 implies other properties as well.
1456 The default index of refraction is that of a vacuum, i.e. (1,0).
1457 .SH
1458 EXAMPLE
1459 .DS
1460 # Define a blue enamel paint
1461 m blue_enamel =
1462 c
1463 cxy 0.2771 0.2975
1464 rd 0.5011
1465 c
1466 rs 0.0100 0.0350
1467 # Assign blue_enamel to be the color of the south wall
1468 m swall_mat = blue_enamel
1469 # ...
1470 # South wall face
1471 m swall_mat
1472 f sv1 sv2 sv3 sv4
1473 .DE
1474 .SH
1475 SEE ALSO
1476 .LP
1477 .UL ed,
1478 .UL ir,
1479 .UL rd,
1480 .UL rs,
1481 .UL sides,
1482 .UL td,
1483 .UL ts
1484 .ds RH SIDES
1485 .bp
1486 .SH
1487 NAME
1488 .LP
1489 sides - set the number of sides for the current material
1490 .SH
1491 SYNOPSIS
1492 .LP
1493 .B sides
1494 {
1495 .B 1
1496 |
1497 .B 2
1498 }
1499 .SH
1500 DESCRIPTION
1501 .LP
1502 The
1503 .UL sides
1504 entity is used to set the number of sides for the current material.
1505 If a surface is two-sided, then it will appear
1506 identical when viewed from either the front or the back.
1507 If a surface is one-sided,
1508 then it appears invisible when viewed from the back side.
1509 This means
1510 that a transmitting object will affect the light coming in through the
1511 front surface and ignore the characteristics of the back surface,
1512 unless the index of refraction is set.
1513 If the index of refraction is set, then the object will act as a
1514 solid piece of dielectric material.
1515 In either case, the transmission properties of the exiting surface
1516 should be the same as the incident surface for the model to be
1517 physically valid.
1518 .LP
1519 The default number of sides is two.
1520 .SH
1521 EXAMPLE
1522 .DS
1523 # Describe a blue crystal ball
1524 m blue_crystal =
1525 ir 1.650000 0
1526 # Solid dielectrics must use one-sided materials
1527 sides 1
1528 c
1529 rs 0.0602 0
1530 c
1531 cxy 0.3127 0.2881
1532 ts 0.6425 0
1533 v sc =
1534 p 10 15 1.5
1535 sph sc .02
1536 .DE
1537 .SH
1538 SEE ALSO
1539 .LP
1540 .UL ed,
1541 .UL ir,
1542 .UL m,
1543 .UL rd,
1544 .UL rs,
1545 .UL td,
1546 .UL ts
1547 .ds RH RD
1548 .bp
1549 .SH
1550 NAME
1551 .LP
1552 rd - set the diffuse reflectance for the current material
1553 .SH
1554 SYNOPSIS
1555 .LP
1556 .B rd
1557 .I rho_d
1558 .SH
1559 DESCRIPTION
1560 .LP
1561 Set the diffuse reflectance for the current material to
1562 .I rho_d
1563 using the current color to determine the spectral characteristics.
1564 This is the fraction of visible light that is reflected from a
1565 surface equally in all directions according to Lambert's law, and is
1566 often called the "Lambertian component."
1567 Photometric reflectance is measured according to v(lambda)
1568 response function of the 1931 CIE standard 2
1569 degree observer, and assumes an equal-energy white light source.
1570 The value must be between zero and one, and may be further
1571 restricted by the luminosity of the selected color.
1572 (I.e. it is impossible to have a violet material with a photometric
1573 reflectance close to one since the eye is less sensitive in this part
1574 of the spectrum.)\0
1575 .LP
1576 The default diffuse reflectance is zero.
1577 .SH
1578 EXAMPLE
1579 .DS
1580 # An off-white paint with 70% reflectance
1581 m flat_white70 =
1582 c
1583 cxy .3632 .3420
1584 rd .70
1585 .DE
1586 .SH
1587 SEE ALSO
1588 .LP
1589 .UL c,
1590 .UL ed,
1591 .UL ir,
1592 .UL m,
1593 .UL rs,
1594 .UL sides,
1595 .UL td,
1596 .UL ts
1597 .ds RH TD
1598 .bp
1599 .SH
1600 NAME
1601 .LP
1602 td - set the diffuse transmittance for the current material
1603 .SH
1604 SYNOPSIS
1605 .LP
1606 .B td
1607 .I tau_d
1608 .SH
1609 DESCRIPTION
1610 .LP
1611 Set the diffuse transmittance for the current material to
1612 .I tau_d
1613 using the current color to determine the spectral characteristics.
1614 This is the fraction of visible light that is transmitted through a
1615 surface equally in all (transmitted) directions.
1616 Like reflectance, transmittance is measured according to the
1617 standard v(lambda) curve, and assumes an equal-energy white light source.
1618 It is probably not possible to create a material with a diffuse
1619 transmittance above 50%, since well-diffused light will be reflected
1620 as well.
1621 .LP
1622 The default diffuse transmittance is zero.
1623 .SH
1624 EXAMPLE
1625 .DS
1626 # Model a perfect spherical diffuser, i.e. light hitting \
1627 either side will be scattered equally in all directions
1628 m wonderland_diffuser =
1629 c
1630 td .5
1631 rd .5
1632 .DE
1633 .SH
1634 SEE ALSO
1635 .LP
1636 .UL c,
1637 .UL ed,
1638 .UL ir,
1639 .UL m,
1640 .UL rd,
1641 .UL rs,
1642 .UL sides,
1643 .UL ts
1644 .ds RH ED
1645 .bp
1646 .SH
1647 NAME
1648 .LP
1649 ed - set the diffuse emittance for the current material
1650 .SH
1651 SYNOPSIS
1652 .LP
1653 .B ed
1654 .I epsilon_d
1655 .SH
1656 DESCRIPTION
1657 .LP
1658 Set the diffuse emittance for the current material to
1659 .I epsilon_d
1660 lumens per square meter using the current color to determine the
1661 spectral characteristics.
1662 Note that this is emittance rather than exitance, and therefore
1663 does not include reflected or transmitted light, which is a function
1664 of the other material settings and the illuminated environment.
1665 .LP
1666 The total lumen output of a convex emitting object
1667 is the radiating area of that object multiplied by its emittance.
1668 Therefore, one can compute the appropriate
1669 .I epsilon_d
1670 value for an emitter by dividing the total lumen output by the
1671 radiating area (in square meters).
1672 .LP
1673 The default emittance is zero.
1674 .SH
1675 EXAMPLE
1676 .DS
1677 # A 100-watt incandescent bulb (1600 lumens) modeled as a sphere
1678 m
1679 c
1680 cct 3000
1681 ed 87712
1682 v cent =
1683 p 0 0 0
1684 sph cent .0381
1685 .DE
1686 .SH
1687 SEE ALSO
1688 .LP
1689 .UL c,
1690 .UL ir,
1691 .UL m,
1692 .UL rd,
1693 .UL rs,
1694 .UL sides,
1695 .UL td,
1696 .UL ts
1697 .ds RH RS
1698 .bp
1699 .SH
1700 NAME
1701 .LP
1702 rs - set the specular reflectance for the current material
1703 .SH
1704 SYNOPSIS
1705 .LP
1706 .B rs
1707 .I "rho_s alpha_r"
1708 .SH
1709 DESCRIPTION
1710 .LP
1711 Set the specular reflectance for the current material to
1712 .I rho_s
1713 using the current color to determine the spectral characteristics.
1714 The surface roughness parameter is set to
1715 .I alpha_r,
1716 which is the RMS height of surface variations over the
1717 autocorrelation distance (equivalent to RMS facet slope).
1718 A roughness value of zero means a perfectly smooth surface, and
1719 values greater than 0.2 are unusual.
1720 (See application notes section 6.1.2 for a comparison between the
1721 roughness parameter and Phong specular power.)\0
1722 .LP
1723 The default specular reflectance is zero.
1724 .SH
1725 EXAMPLE
1726 .DS
1727 # Define a slightly rough brass metallic surface
1728 m rough_brass =
1729 c
1730 cxy .3820 .4035
1731 # 30% specular, 9% diffuse
1732 rs .30 .08
1733 rd .09
1734 .DE
1735 .SH
1736 SEE ALSO
1737 .LP
1738 .UL c,
1739 .UL ed,
1740 .UL ir,
1741 .UL m,
1742 .UL rd,
1743 .UL sides,
1744 .UL td,
1745 .UL ts
1746 .ds RH TS
1747 .bp
1748 .SH
1749 NAME
1750 .LP
1751 ts - set the specular transmittance for the current material
1752 .SH
1753 SYNOPSIS
1754 .LP
1755 .B ts
1756 .I "tau_s alpha_t"
1757 .SH
1758 DESCRIPTION
1759 .LP
1760 Set the specular transmittance for the current material to
1761 .I tau_s
1762 using the current color to determine the spectral characteristics.
1763 The effective surface roughness is set to
1764 .I alpha_t.
1765 Rays will be transmitted with the same distribution as they would
1766 have been reflected with if this roughness value were given to the
1767 .UL rs
1768 entity.
1769 .LP
1770 The default specular transmittance is zero.
1771 .SH
1772 EXAMPLE
1773 .DS
1774 # Define a green glass material (58% transmittance)
1775 m glass =
1776 sides 2
1777 ir 1.52 0
1778 c
1779 rs 0.0725 0
1780 c
1781 cxy .23 .38
1782 ts 0.5815 0
1783 # Define an uncolored translucent plastic (40% transmittance)
1784 m translucent =
1785 sides 2
1786 ir 1.4 0
1787 c
1788 rs .045 0
1789 ts .40 .05
1790 .DE
1791 .SH
1792 SEE ALSO
1793 .LP
1794 .UL c,
1795 .UL ed,
1796 .UL ir,
1797 .UL m,
1798 .UL rd,
1799 .UL rs,
1800 .UL sides,
1801 .UL td
1802 .ds RH IR
1803 .bp
1804 .SH
1805 NAME
1806 .LP
1807 ir - set the complex index of refraction for the current material
1808 .SH
1809 SYNOPSIS
1810 .LP
1811 .B ir
1812 .I "n_real n_imag"
1813 .SH
1814 DESCRIPTION
1815 .LP
1816 Set the index of refraction for the current material to
1817 .I (n_real,n_imag).
1818 If the material is a dielectric (as opposed to metallic), then
1819 .I n_imag
1820 should be zero.
1821 For solid dielectric objects, the material should be made one-sided.
1822 If it is being used for thin objects, then a two-sided
1823 material is appropriate.
1824 (See the
1825 .UL sides
1826 entity.)\0
1827 .LP
1828 The default index of refraction is that of a vacuum, (1,0).
1829 .SH
1830 EXAMPLE
1831 .DS
1832 # Define polished aluminum material
1833 m polished_aluminum =
1834 # Complex index of refraction (from physics table)
1835 ir .770058 6.08351
1836 c
1837 rs .75 0
1838 .DE
1839 .SH
1840 SEE ALSO
1841 .LP
1842 .UL c,
1843 .UL ed,
1844 .UL m,
1845 .UL rd,
1846 .UL rs,
1847 .UL sides,
1848 .UL td,
1849 .UL ts
1850 .ds LH Vertex Entities
1851 .ds RH V
1852 .bp
1853 .SH
1854 NAME
1855 .LP
1856 v - get or set the current vertex context
1857 .SH
1858 SYNOPSIS
1859 .LP
1860 .B v
1861 [
1862 .I id
1863 [
1864 .B =
1865 [
1866 .I template
1867 ]
1868 ]
1869 ]
1870 .SH
1871 DESCRIPTION
1872 .LP
1873 If the
1874 .UL v
1875 keyword is given by itself, then it establishes
1876 the unnamed vertex context, which is the origin with no normal.
1877 This context may be modified, but the changes will not be saved.
1878 (The unnamed vertex is never used except as a source of default
1879 values since all geometric entities call their vertices by name.)\0
1880 .LP
1881 If the keyword is followed by an identifier
1882 .I id,
1883 then it reestablishes a previous context.
1884 If the specified context was never defined, an error will result.
1885 .LP
1886 If the entity is given with an identifier
1887 followed by an equals sign ('='), then a new context is established,
1888 and cleared to the default vertex (the origin).
1889 (Note that the equals sign must be separated from other
1890 arguments by white space to be properly recognized.)\0
1891 If the equals sign is followed by a second identifier
1892 .I template,
1893 then this previously defined vertex will be used as a source of
1894 default values instead.
1895 This may be used to establish a vertex alias, or to modify an
1896 existing vertex and give it a new name.
1897 .LP
1898 A non-zero vertex normal must be given for
1899 certain entities, specifically
1900 .UL ring
1901 and
1902 .UL torus
1903 require a normal direction.
1904 An
1905 .UL f
1906 entity will interpolate vertex normals if given, and
1907 use the polygon plane normal otherwise.
1908 See the
1909 .UL prism
1910 entry for an explanation of how it interprets and uses vertex
1911 normals.
1912 The other entities ignore vertex normals if present.
1913 .LP
1914 The actual position and normal direction for a vertex is determined
1915 at the time of use by a geometric entity.
1916 Specifically, the transformation in effect at the time the vertex is
1917 defined is irrelevant.
1918 The only transformation that matters is the one that is applied to
1919 the geometry itself.
1920 This prevents double-transformation of vertices and allows one set
1921 of vertices to be used for multiple purposes, e.g. the front and
1922 back sides of a drawer.
1923 .SH
1924 EXAMPLE
1925 .DS
1926 # Make a capped cylinder
1927 v end1 =
1928 p 0 0 0
1929 n 0 0 -1
1930 v end2 =
1931 p 0 0 1
1932 cyl end1 1.2 end2
1933 # Forgot normal for end2
1934 v end2
1935 n 0 0 1
1936 ring end1 0 1.2
1937 ring end2 0 1.2
1938 .DE
1939 .SH
1940 SEE ALSO
1941 .LP
1942 .UL cone,
1943 .UL cyl,
1944 .UL f,
1945 .UL n,
1946 .UL p,
1947 .UL prism,
1948 .UL ring,
1949 .UL sph,
1950 .UL torus
1951 .ds RH P
1952 .bp
1953 .SH
1954 NAME
1955 .LP
1956 p - set the point location for the current vertex
1957 .SH
1958 SYNOPSIS
1959 .LP
1960 .B p
1961 .I "px py pz"
1962 .SH
1963 DESCRIPTION
1964 .LP
1965 Set the 3-dimensional position for the current vertex to
1966 .I (px,py,pz).
1967 The actual position of the vertex will be determined by the
1968 transformation in effect at the time the vertex is applied to a
1969 geometric surface entity.
1970 The transform current when the position is set is irrelevant.
1971 .LP
1972 The default vertex position is the origin, (0,0,0).
1973 .SH
1974 EXAMPLE
1975 .DS
1976 # Make a small circle of 6 spheres
1977 v scent =
1978 p 1 0 0
1979 xf -a 6 -rz 60
1980 sph scent .05
1981 xf
1982 .DE
1983 .SH
1984 SEE ALSO
1985 .LP
1986 .UL cone,
1987 .UL cyl,
1988 .UL f,
1989 .UL n,
1990 .UL prism,
1991 .UL ring,
1992 .UL sph,
1993 .UL torus,
1994 .UL v
1995 .ds RH N
1996 .bp
1997 .SH
1998 NAME
1999 .LP
2000 n - set the surface normal direction for the current vertex
2001 .SH
2002 SYNOPSIS
2003 .LP
2004 .B n
2005 .I "dx dy dz"
2006 .SH
2007 DESCRIPTION
2008 .LP
2009 Set the 3-dimensional surface normal for the current vertex to the
2010 normalized vector along
2011 .I (dx,dy,dz).
2012 If this vector is zero, then the surface normal is effectively
2013 unset.
2014 The actual surface normal orientation of the vertex will be determined
2015 by the transformation in effect at the time the vertex is applied to a
2016 geometric surface entity.
2017 The current transform when the normal is set is irrelevant.
2018 .LP
2019 The default vertex normal is the zero vector (i.e. no normal).
2020 .SH
2021 EXAMPLE
2022 .DS
2023 # Make a chain of 10 interlocking doughnuts
2024 v tcent =
2025 p 0 0 0
2026 n 0 1 0
2027 xf -a 10 -rx 90 -t .2 0 0
2028 torus tcent .1 .2
2029 xf
2030 .DE
2031 .SH
2032 SEE ALSO
2033 .LP
2034 .UL f,
2035 .UL p,
2036 .UL prism,
2037 .UL ring,
2038 .UL torus,
2039 .UL v
2040 .ds LH Geometric Entities
2041 .ds RH F
2042 .bp
2043 .SH
2044 NAME
2045 .LP
2046 f - create an N-sided polygonal face
2047 .SH
2048 SYNOPSIS
2049 .LP
2050 .B f
2051 .I "v1 v2 ... vN"
2052 .SH
2053 DESCRIPTION
2054 .LP
2055 Create a polygonal face made of the current material
2056 by connecting the named vertices in order, and connecting the last
2057 vertex to the first.
2058 There must be at least three vertices, and if any vertex is undefined,
2059 an error will result.
2060 .LP
2061 The surface orientation is determined by the right-hand rule; when
2062 the curl of the fingers follows the given order of the vertices, the
2063 surface normal points in the thumb direction.
2064 Face vertices should be coplanar, though this is difficult to guarantee
2065 in a 3-dimensional specification.
2066 .LP
2067 If any vertices have associated surface normals, they will be used
2068 instead of the average plane normal, though it is safest to specify
2069 either all normals or no normals, and to stick with triangles
2070 when normals are used.
2071 Also, specified normals should point in the general direction of the
2072 surface for best results.
2073 .LP
2074 There is no explicit representation of holes in this entity, but see
2075 the
2076 .UL fh
2077 entity for an alternative specification.
2078 .LP
2079 A hole may be represented implicitly in a face entity
2080 by connecting vertices to form "seams."
2081 For
2082 example, a wall with a window in it might look as shown in Figure 1.
2083 In many systems, the wall itself would be represented with the first
2084 list of vertices, (v1,v2,v3,v4) and the hole associated with that
2085 wall as a second set of vertices (v5,v6,v7,v8).
2086 Using the face entity, we must
2087 give the whole thing as a single polygon, connecting the vertices so
2088 as to create a "seam," as shown in Figure 2.
2089 This could be written as "f v1 v2 v3 v4 v5 v6 v7 v8 v5 v4".
2090 .LP
2091 It is very important that the order of the hole be opposite to the
2092 order of the outer perimeter, otherwise the polygon will be
2093 "twisted" on top of itself. Note also that the seam was traversed
2094 in both directions, once going from v4 to v5, and again returning
2095 from v5 to v4. This is a necessary condition for a proper seam.
2096 .LP
2097 The choice of vertices to make into a seam is somewhat arbitrary, but
2098 some rendering systems may not give sane results if you cross over a
2099 hole with part of your seam. If we had chosen to create the seam
2100 between v2 and v5 in the above example instead of v4 and v5, the seam
2101 would cross our hole and may not render correctly\(dg.
2102 .FS
2103 \(dgFor systems that
2104 are sensitive to this, it is probably safest for their MGF
2105 loader/translator to re-expresses seams in terms of holes again, which can
2106 be done easily so long as vertices are shared in the fashion shown.
2107 .FE
2108 .bp
2109 Replace this page with the first page from "figures.ps".
2110 .bp
2111 .SH
2112 EXAMPLE
2113 .DS
2114 # Make a pyramid
2115 v apex =
2116 p 1 1 1
2117 v base0 =
2118 p 0 0 0
2119 v base1 =
2120 p 0 2 0
2121 v base2 =
2122 p 2 2 0
2123 v base3 =
2124 p 2 0 0
2125 # Bottom
2126 f base0 base1 base2 base3
2127 # Sides
2128 f base0 apex base1
2129 f base1 apex base2
2130 f base2 apex base3
2131 f base3 apex base0
2132 .DE
2133 .SH
2134 SEE ALSO
2135 .LP
2136 .UL cone,
2137 .UL cyl,
2138 .UL fh,
2139 .UL m,
2140 .UL prism,
2141 .UL ring,
2142 .UL sph,
2143 .UL torus,
2144 .UL v
2145 .ds RH FH
2146 .bp
2147 .SH
2148 NAME
2149 .LP
2150 fh - create a polygonal face with explicit holes
2151 .SH
2152 SYNOPSIS
2153 .LP
2154 .B fh
2155 .I "p1 p2 ... - h1.1 h1.2 ... - h2.1 h2.2 ..."
2156 .SH
2157 DESCRIPTION
2158 .LP
2159 Create a polygonal face with optional holes made of the current material.
2160 The first contour is the outer perimeter, with vertices given in
2161 counter-clockwise order as seen from the front side (the same as the
2162 .UL f
2163 entity).
2164 A hole is indicated by a hyphen ('-') followed by the hole's
2165 vertices, given in clockwise order as seen from the front side.
2166 Multiple hole contours are separated by additional hyphens.
2167 There must be at least three vertices for each contour, and the
2168 last vertex is implicitly connected to the first.
2169 If any vertex is undefined, an error will result.
2170 .LP
2171 If any vertices have associated surface normals, they will be used
2172 instead of the average plane normal, though it is safest to specify
2173 either all normals or no normals, and to stick with triangles
2174 when normals are used.
2175 Also, specified normals should point in the general direction of the
2176 surface for best results.
2177 .SH
2178 EXAMPLE
2179 .DS
2180 # Make a wall with a window using an explicit hole.
2181 # (See Figures 1 and 2.)
2182 fh v1 v2 v3 v4 - v5 v6 v7 v8
2183 .DE
2184 .SH
2185 SEE ALSO
2186 .LP
2187 .UL cone,
2188 .UL cyl,
2189 .UL f,
2190 .UL m,
2191 .UL prism,
2192 .UL ring,
2193 .UL sph,
2194 .UL torus,
2195 .UL v
2196 .ds RH SPH
2197 .bp
2198 .SH
2199 NAME
2200 .LP
2201 sph - create a sphere
2202 .SH
2203 SYNOPSIS
2204 .LP
2205 .B sph
2206 .I "vc rad"
2207 .SH
2208 DESCRIPTION
2209 .LP
2210 Create a sphere made of the current material with its center at the
2211 named vertex
2212 .I vc
2213 and a radius of
2214 .I rad.
2215 If the vertex is undefined an error will result.
2216 .LP
2217 The surface normal is usually directed outward, but will be directed
2218 inward if the given radius is negative.
2219 (This typically matters only for one-sided materials.)\0
2220 A zero radius is illegal.
2221 .SH
2222 EXAMPLE
2223 .DS
2224 # Create a thick glass sphere with a hollow inside
2225 m glass =
2226 sides 1
2227 ir 1.52 0
2228 c
2229 rs .06 0
2230 ts .88 0
2231 v cent =
2232 p 0 0 1.1
2233 # The outer shell
2234 sph cent .1
2235 # The inner bubble
2236 sph cent -.08
2237 .DE
2238 .SH
2239 SEE ALSO
2240 .LP
2241 .UL cone,
2242 .UL cyl,
2243 .UL f,
2244 .UL m,
2245 .UL prism,
2246 .UL ring,
2247 .UL torus,
2248 .UL v
2249 .ds RH CYL
2250 .bp
2251 .SH
2252 NAME
2253 .LP
2254 cyl - create an open-ended, truncated right cylinder
2255 .SH
2256 SYNOPSIS
2257 .LP
2258 .B cyl
2259 .I "v1 rad v2"
2260 .SH
2261 DESCRIPTION
2262 .LP
2263 Create a truncated right cylinder of radius
2264 .I rad
2265 using the current material, starting at the named vertex
2266 .I v1
2267 and continuing to
2268 .I v2.
2269 The ends will be open, but may be capped using the
2270 .UL ring
2271 entity if desired.
2272 .LP
2273 The surface normal will usually be directed outward, but may be
2274 directed inward by giving a negative value for
2275 .I rad.
2276 A zero radius is illegal, and
2277 .I v1
2278 cannot equal
2279 .I v2.
2280 .SH
2281 EXAMPLE
2282 .DS
2283 # A stylus with one rounded and one pointed end
2284 o stylus
2285 v vtip0 =
2286 p 0 0 0
2287 v vtip1 =
2288 p 0 0 .005
2289 v vend =
2290 p 0 0 .05
2291 cyl vtip1 .0015 vend
2292 sph vend .0015
2293 cone vtip0 0 vtip1 .0015
2294 o
2295 .DE
2296 .SH
2297 SEE ALSO
2298 .LP
2299 .UL cone,
2300 .UL f,
2301 .UL m,
2302 .UL prism,
2303 .UL ring,
2304 .UL sph,
2305 .UL torus,
2306 .UL v
2307 .ds RH CONE
2308 .bp
2309 .SH
2310 NAME
2311 .LP
2312 cone - create an open-ended, truncated right cone
2313 .SH
2314 SYNOPSIS
2315 .LP
2316 .B cone
2317 .I "v1 rad1 v2 rad2"
2318 .SH
2319 DESCRIPTION
2320 .LP
2321 Create a truncated right cone using the current material.
2322 The starting radius is
2323 .I rad1
2324 at
2325 .I v1
2326 and the ending radius is
2327 is
2328 .I rad2
2329 at
2330 .I v2.
2331 The ends will be open, but may be capped using the
2332 .UL ring
2333 entity if desired.
2334 .LP
2335 The surface normal will usually be directed outward, but may be
2336 directed inward by giving negative values for both radii.
2337 (It is illegal for the signs of the two radii to disagree.)\0
2338 One but not both radii may be zero, indicating that the cone comes
2339 to a point.
2340 .LP
2341 Although it is not strictly forbidden to have equal cone radii, the
2342 .UL cyl
2343 entity should be used in such cases.
2344 Likewise, the
2345 .UL ring
2346 entity must be used if
2347 .I v1
2348 and
2349 .I v2
2350 are equal.
2351 .SH
2352 EXAMPLE
2353 .DS
2354 # A parasol
2355 o parasol
2356 v v1 =
2357 p 0 0 0
2358 v v2 =
2359 p 0 0 .75
2360 v v3 =
2361 p 0 0 .7
2362 m handle_mat
2363 cyl v1 .002 v2
2364 m parasol_paper
2365 cyl v2 0 v3 .33
2366 o
2367 .DE
2368 .SH
2369 SEE ALSO
2370 .LP
2371 .UL cyl,
2372 .UL f,
2373 .UL m,
2374 .UL prism,
2375 .UL ring,
2376 .UL sph,
2377 .UL torus,
2378 .UL v
2379 .ds RH PRISM
2380 .bp
2381 .SH
2382 NAME
2383 .LP
2384 prism - create a closed right prism
2385 .SH
2386 SYNOPSIS
2387 .LP
2388 .B prism
2389 .I "v1 v2 ... vN length"
2390 .SH
2391 DESCRIPTION
2392 .LP
2393 Create a closed right prism using the current material.
2394 One end face will be enclosed by the named vertices, and the
2395 opposite end face will be a mirror image at a distance
2396 .I length
2397 from the original.
2398 The edges will be extruded into N quadrilaterals connecting
2399 the two end faces.
2400 .LP
2401 The order of vertices determines the original face orientation
2402 according to the right-hand rule as explained for the
2403 .UL f
2404 entity.
2405 Normally, the prism is extruded in the direction opposite to the
2406 original surface normal, resulting in faces that all point outward.
2407 If the specified
2408 .I length
2409 is negative, the prism will be extruded above the original face
2410 and all surface normals will point inward.
2411 .LP
2412 If the vertices have associated normals, they are applied to the
2413 side faces only, and should generally point in the appropriate
2414 direction (i.e. in or out depending on whether
2415 .I length
2416 is negative or positive).
2417 .SH
2418 EXAMPLE
2419 .DS
2420 # Make a unit cube starting at the origin and \\\\
2421 extending to the positive octant
2422 v cv0 =
2423 p 0 0 0
2424 v cv1 =
2425 p 0 1 0
2426 v cv2 =
2427 p 1 1 0
2428 v cv3 =
2429 p 1 0 0
2430 # Right hand rule has original face looking in -Z direction
2431 prism cv0 cv1 cv2 cv3 1
2432 .DE
2433 .SH
2434 SEE ALSO
2435 .LP
2436 .UL cyl,
2437 .UL cone,
2438 .UL f,
2439 .UL m,
2440 .UL ring,
2441 .UL sph,
2442 .UL torus,
2443 .UL v
2444 .ds RH RING
2445 .bp
2446 .SH
2447 NAME
2448 .LP
2449 ring - create a circular ring with inner and outer radii
2450 .SH
2451 SYNOPSIS
2452 .LP
2453 .B ring
2454 .I "vc rmin rmax"
2455 .SH
2456 DESCRIPTION
2457 .LP
2458 Create a circular face of the current material centered on the named
2459 vertex
2460 .I vc
2461 with an inner radius of
2462 .I rmin
2463 and an outer radius of
2464 .I rmax.
2465 The surface orientation is determined by the normal vector
2466 associated with
2467 .I vc.
2468 If this vertex is undefined or has no normal, an error will result.
2469 The minimum radius may be equal to but not less than zero, and the
2470 maximum radius must be strictly greater than the minimum.
2471 .SH
2472 EXAMPLE
2473 .DS
2474 # The proverbial brass ring
2475 o brass_ring
2476 m brass
2477 v end1 =
2478 p 0 -.005 0
2479 n 0 -1 0
2480 v end2 =
2481 p 0 .005 0
2482 n 0 1 0
2483 ring end1 .02 .03
2484 cyl end1 .03 end2
2485 ring end2 .02 .03
2486 cyl end2 -.02 end1
2487 o
2488 .DE
2489 .SH
2490 SEE ALSO
2491 .LP
2492 .UL cyl,
2493 .UL cone,
2494 .UL f,
2495 .UL m,
2496 .UL prism,
2497 .UL sph,
2498 .UL torus,
2499 .UL v
2500 .ds RH TORUS
2501 .bp
2502 .SH
2503 NAME
2504 .LP
2505 torus - create a regular torus
2506 .SH
2507 SYNOPSIS
2508 .LP
2509 .B torus
2510 .I "vc rmin rmax"
2511 .SH
2512 DESCRIPTION
2513 .LP
2514 Create a torus of the current material centered on the named vertex
2515 .I vc
2516 with an inner radius of
2517 .I rmin
2518 and an outer radius of
2519 .I rmax.
2520 The plane of the torus will be perpendicular to the normal vector
2521 associated with
2522 .I vc.
2523 If this vertex is undefined or has no normal, an error will result.
2524 .LP
2525 If a torus with an inward facing surface normal is desired,
2526 .I rmin
2527 and
2528 .I rmax
2529 may be negative.
2530 The minimum radius may be zero, but may not be negative when
2531 .I rmax
2532 is positive or vice versa.
2533 The magnitude or
2534 .I rmax
2535 must always be strictly greater than that of
2536 .I rmin.
2537 .SH
2538 EXAMPLE
2539 .DS
2540 # The proverbial brass ring -- easy grip version
2541 o brass_ring
2542 m brass
2543 v center =
2544 p 0 0 0
2545 n 0 1 0
2546 torus center .02 .03
2547 o
2548 .DE
2549 .SH
2550 SEE ALSO
2551 .LP
2552 .UL cyl,
2553 .UL cone,
2554 .UL f,
2555 .UL m,
2556 .UL prism,
2557 .UL ring,
2558 .UL sph,
2559 .UL v
2560 .ds RH
2561 .ds LH
2562 .bp
2563 .NH
2564 MGF Translators
2565 .LP
2566 Initially, there are six translators for MGF data, and
2567 three of these are distributed with the MGF parser itself,
2568 .I mgfilt,
2569 .I mgf2inv
2570 and
2571 .I 3ds2mgf.
2572 Two of the other translators,
2573 .I mgf2rad
2574 and
2575 .I rad2mgf
2576 convert between MGF and the Radiance scene description language,
2577 and are distributed for free with the rest of the Radiance
2578 package\(dg.
2579 .FS
2580 \(dgRadiance is available by anonymous ftp from hobbes.lbl.gov and
2581 nestor.epfl.ch, or by WWW from
2582 "http://radsite.lbl.gov/radiance/HOME.html"
2583 .FE
2584 The sixth translator,
2585 .I mgf2meta,
2586 converts to a 2-dimensional line plot, and is also
2587 distributed with Radiance.
2588 .LP
2589 Mgfilt is a simple but useful utility that takes MGF on its input
2590 and produces MGF on its output.
2591 It uses the parser to convert entities that are not wanted or
2592 understood, and produces only the requested ones.
2593 This is useful for seeing what exactly a program must understand
2594 when it supports a given set of entities, and may serve as a
2595 substitute for linking to the parser library for programmers who
2596 wish to interpret the ASCII input directly but without all the
2597 unwanted entities.
2598 In future releases of MGF, this utility will also be handy for
2599 taking new entities and producing older versions of MGF for
2600 translators that have not yet been updated properly.
2601 .LP
2602 Mgf2inv converts from MGF to Inventor or VRML format.
2603 Some information is lost, because these formats do not support
2604 physical light sources or materials.
2605 .LP
2606 3ds2mgf converts from 3D Studio binary format to MGF.
2607 Care must be taken to correct for errors in the material descriptions,
2608 since 3D Studio is completely non-physical.
2609 .ds LH Translators
2610 .ds RH MGFILT
2611 .bp
2612 .SH
2613 NAME
2614 .LP
2615 mgfilt - get usable MGF entities from input
2616 .SH
2617 SYNOPSIS
2618 .LP
2619 .B mgfilt
2620 .B version
2621 [
2622 .B input ..
2623 ]
2624 .br
2625 or
2626 .br
2627 .B mgfilt
2628 .B "e1,e2,.."
2629 [
2630 .B input ..
2631 ]
2632 .SH
2633 DESCRIPTION
2634 .LP
2635 .I Mgfilt
2636 takes one or more MGF input files and converts all the entities to
2637 the types listed.
2638 In the first form, a single integer is given for the
2639 .I version
2640 of MGF that is to be produced.
2641 Since MGF is in its first major release, this is not yet a useful
2642 form, but it will be when the second major release comes out.
2643 This has the necessary side-effect of expanding all included files.
2644 (See the
2645 .UL i
2646 entity.)\0
2647 .LP
2648 In the second form,
2649 .I mgfilt
2650 produces only the entities listed in the first argument, which must
2651 be comma-separated.
2652 The listed entity order is not important, but all entities given
2653 must be defined in the current version of MGF.
2654 Unknown entities will be summarily discarded on the input, and a
2655 warning message will be printed to the standard error.
2656 .SH
2657 EXAMPLES
2658 .LP
2659 To take an MGF version 3 file and send it to a version 2
2660 translator:
2661 .IP
2662 mgfilt 2 input.mgf | mgf2rad > input.rad
2663 .LP
2664 To take an MGF file and produce only flat polygonal faces
2665 with no materials:
2666 .IP
2667 mgfilt f,v,p,xf input.mgf > flatpoly.mgf
2668 .SH
2669 SEE ALSO
2670 .LP
2671 i, mgf2inv, mgf2rad, rad2mgf
2672 .ds RH MGF2INV
2673 .bp
2674 .SH
2675 NAME
2676 .LP
2677 mgf2inv - convert from MGF to Inventor or VRML format
2678 .SH
2679 SYNOPSIS
2680 .LP
2681 .B mgf2inv
2682 [
2683 .B "-1|-2|-vrml"
2684 ]
2685 [
2686 .B input ..
2687 ]
2688 .SH
2689 DESCRIPTION
2690 .LP
2691 .I Mgf2inv
2692 takes one or more MGF input files and converts it to
2693 Inventor or VRML format.
2694 If the
2695 .I \-1
2696 option is used, then Inventor 1.0 ASCII output is produced.
2697 If the
2698 .I \-2
2699 option is used, then Inventor 2.0 ASCII output is produced.
2700 (This is the default.)\0
2701 If the
2702 .I \-vrml
2703 option is used, then VRML 1.0 ASCII output is produced.
2704 .LP
2705 This converter does not work properly for light sources, since
2706 the output formats do not support IES-type luminaires with recorded
2707 distributions.
2708 Also, some material information may be lost because Inventor lacks
2709 a physically valid reflectance model.
2710 .SH
2711 EXAMPLES
2712 .LP
2713 To take an MGF file and convert it to VRML format:
2714 .IP
2715 mgf2inv -vrml myscene.mgf > myscene.iv
2716 .SH
2717 SEE ALSO
2718 .LP
2719 mgf2rad(1), mgfilt(1), 3ds2mgf(1), rad2mgf(1)
2720 .ds RH 3DS2MGF
2721 .bp
2722 .SH
2723 NAME
2724 .LP
2725 3ds2mgf - convert 3D Studio binary file to Materials and Geometry Format
2726 .SH
2727 SYNOPSIS
2728 .LP
2729 .B 3ds2mgf
2730 .B input
2731 [
2732 .B output
2733 ]
2734 [
2735 .B -lMatlib
2736 ][
2737 .B -xObjname
2738 ][
2739 .B -sAngle
2740 ][
2741 .B -aAnimfile
2742 ][
2743 .B -fN
2744 ]
2745 .SH
2746 DESCRIPTION
2747 .LP
2748 .I 3ds2mgf
2749 converts a 3D Studio binary scene description
2750 to the Materials and Geometry Format (MGF).
2751 If no output file name is given, the input root name
2752 will be taken as the output root, and an "mgf" extension
2753 will be added.
2754 This file will contain any light sources and materials, and an include
2755 statement for a similarly named file ending in "inc", which will contain
2756 the MGF geometry of all the translated 3DS meshes.
2757 .LP
2758 The MGF material names and properties
2759 for the surfaces will be those assigned in 3D Studio,
2760 unless they are named in one or more MGF material libraries given in a
2761 .I -l
2762 option.
2763 .LP
2764 The
2765 .I -x
2766 option may be used to exclude a named object from the output.
2767 .LP
2768 The
2769 .I -s
2770 option may be used to adjust automatic mesh smoothing such that adjacent
2771 triangle faces with less than the given angle between them (in degrees)
2772 will be smoothed.
2773 A value of zero turns smoothing off.
2774 The default value is 60 degrees.
2775 .LP
2776 The
2777 .I -a
2778 option may be used to specify a 3D Studio animation file, and together with the
2779 .I -f
2780 option,
2781 .I 3ds2mgf
2782 will generate a scene description for the specified frame.
2783 .LP
2784 Note that there are no spaces between the options and their arguments.
2785 .SH
2786 LIMITATIONS
2787 .LP
2788 Obviously, since 3D Studio has no notion of physical materials, the
2789 translation to MGF material descriptions is very ad hoc, and it will
2790 usually be necessary to edit the materials and light sources in
2791 the output file or replace materials with proper entries from a material
2792 library using the
2793 .I -l
2794 option.
2795 .LP
2796 With smoothing turned on (i.e., a non-zero value for the
2797 .I -s
2798 option), vertices in the MGF output will not be linked in a proper
2799 mesh for each object.
2800 This is due to the way the automatic smoothing code was originally
2801 written, and is too difficult to repair.
2802 If a good mesh is needed, then smoothing must be turned off.
2803 .SH
2804 EXAMPLES
2805 .LP
2806 To convert a 3D Studio robot model to MGF without smoothing.
2807 (Output will be put into "robot.mgf" and "robot.inc".)
2808 .IP
2809 3ds2mgf robot.3ds -s0
2810 .LP
2811 To convert a DC10 jet model to MGF using a hand-created material library:
2812 .IP
2813 3ds2mgf dc10.3ds -ldc10mat.mgf
2814 .SH
2815 AUTHORS
2816 .LP
2817 Steve Anger, Jeff Bowermaster and Greg Ward
2818 .br
2819 Extended from 3ds2pov 1.8.
2820 .SH
2821 SEE ALSO
2822 .LP
2823 mgf2inv(1), mgf2meta(1), mgf2rad(1)
2824 .ds RH MGF2RAD
2825 .bp
2826 .SH
2827 NAME
2828 .LP
2829 mgf2rad - convert Materials and Geometry Format file to RADIANCE description
2830 .SH
2831 SYNOPSIS
2832 .LP
2833 .B mgf2rad
2834 [
2835 .B "\-m matfile"
2836 ][
2837 .B "\-e mult"
2838 ][
2839 .B "\-g dist"
2840 ]
2841 [
2842 .B input ..
2843 ]
2844 .SH
2845 DESCRIPTION
2846 .LP
2847 .I Mgf2rad
2848 converts one or more Materials and Geometry Format (MGF)
2849 files to a RADIANCE scene description.
2850 By definition, all output dimensions are in meters.
2851 The material names and properties
2852 for the surfaces will be those assigned in MGF.
2853 Any materials not defined in MGF will result in an error during
2854 translation.
2855 Light sources are described inline as IES luminaire files, and
2856 .I mgf2rad
2857 calls the program
2858 .I ies2rad(1)
2859 to translate these files.
2860 If an IES file in turn contains an MGF description of the local
2861 fixture geometry, this may result in a recursive call to
2862 .I mgf2rad,
2863 which is normal and should be transparent.
2864 The only side-effect of this additional translation is the
2865 appearance of other RADIANCE scene and data files produced
2866 automatically by
2867 .I ies2rad.
2868 .LP
2869 The
2870 .I \-m
2871 option may be used to put all the translated materials into a separate
2872 RADIANCE file.
2873 This is not always advisable, as any given material name may be
2874 reused at different points in the MGF description, and writing them
2875 to a separate file loses the contextual association between
2876 materials and surfaces.
2877 As long as unique material names are used throughout the MGF
2878 description and material properties are not redefined, there
2879 will be no problem.
2880 Note that this is the only way to get all the translated materials
2881 into a single file, since no output is produced for unreferenced
2882 materials; i.e. translating just the MGF materials does not work.
2883 .LP
2884 The
2885 .I \-e
2886 option may be used to multiply all the emission values by the
2887 given
2888 .I mult
2889 factor.
2890 The
2891 .I \-g
2892 option may be used to establish a glow distance (in meters)
2893 for all emitting surfaces.
2894 These two options are employed principally by
2895 .I ies2rad,
2896 and are not generally useful to most users.
2897 .SH
2898 EXAMPLES
2899 .LP
2900 To translate two MGF files into one RADIANCE materials file and
2901 one geometry file:
2902 .IP
2903 mgf2rad -m materials.rad building1.mgf building2.mgf > building1+2.rad
2904 .LP
2905 To create an octree directly from two MGF files and one RADIANCE
2906 file:
2907 .IP
2908 oconv '\\!mgf2rad materials.mgf scene.mgf' source.rad > scene.oct
2909 .SH
2910 FILES
2911 .LP
2912 tmesh.cal Used to smooth polygonal geometry
2913 .br
2914 *.rad RADIANCE source descriptions created by ies2rad
2915 .br
2916 *.dat RADIANCE source data created by ies2rad
2917 .br
2918 source.cal Used for IES source coordinates
2919 .SH
2920 AUTHOR
2921 .LP
2922 Greg Ward
2923 .SH
2924 SEE ALSO
2925 .LP
2926 ies2rad(1), mgf2meta(1), obj2rad(1), oconv(1), rad2mgf(1), xform(1)
2927 .ds RH RAD2MGF
2928 .bp
2929 .SH
2930 NAME
2931 .LP
2932 rad2mgf - convert RADIANCE scene description to Materials and Geometry Format
2933 .SH
2934 SYNOPSIS
2935 .LP
2936 .B rad2mgf
2937 [
2938 .B \-dU
2939 ]
2940 [
2941 .B input ..
2942 ]
2943 .SH
2944 DESCRIPTION
2945 .LP
2946 .I Rad2mgf
2947 converts one or more RADIANCE scene files
2948 to the Materials and Geometry Format (MGF).
2949 Input units are specified with the
2950 .I \-mU
2951 option, where
2952 .I U
2953 is one of 'm' (meters), 'c' (centimeters), 'f' (feet) or 'i'
2954 (inches).
2955 The assumed unit is meters, which is the required output unit for
2956 MGF (thus the need to know).
2957 If the input dimensions are in none of these units, then the user
2958 should apply
2959 .I xform(1)
2960 with the
2961 .I \-s
2962 option to bring the units into line prior to translation.
2963 .LP
2964 The MGF material names and properties
2965 for the surfaces will be those assigned in RADIANCE.
2966 If a referenced material has not been defined, then its name will
2967 be invoked in the MGF output without definition, and the description
2968 will be incomplete.
2969 .SH
2970 LIMITATIONS
2971 .LP
2972 Although MGF supports all of the geometric types and the most
2973 common material types used in RADIANCE, there is currently no
2974 support for advanced BRDF materials, patterns, textures or mixtures.
2975 Also, the special types "source" and "antimatter" are not supported,
2976 and all light source materials are converted to simple diffuse emitters
2977 (except "illum" materials, which are converted to their alternates).
2978 These primitives are reproduced as comments in the output and
2979 must be replaced manually if necessary.
2980 .LP
2981 The RADIANCE "instance" type is treated specially.
2982 .I Rad2mgf
2983 converts each instance to an MGF include statement, using the corresponding
2984 transformation and a file name derived from the octree name.
2985 (The original octree suffix is replaced by ".mgf".)\0
2986 For this to work, the user must separately create the referenced
2987 MGF files from the original RADIANCE descriptions.
2988 The description file names can usually be determined using the
2989 .I getinfo(1)
2990 command run on the octrees in question.
2991 .SH
2992 EXAMPLES
2993 .LP
2994 To convert three RADIANCE files (in feet) to one MGF file:
2995 .IP
2996 mgf2rad -df file1.rad file2.rad file3.rad > scene.mgf
2997 .LP
2998 To translate a RADIANCE materials file to MGF:
2999 .IP
3000 mgf2rad materials.rad > materials.mgf
3001 .SH
3002 AUTHOR
3003 .LP
3004 Greg Ward
3005 .SH
3006 SEE ALSO
3007 .LP
3008 getinfo(1), ies2rad(1), mgf2meta(1), mgf2rad(1), obj2rad(1), oconv(1), xform(1)
3009 .ds RH MGF2META
3010 .bp
3011 .SH
3012 NAME
3013 .LP
3014 mgf2meta - convert Materials and Geometry Format file to Metafile graphics
3015 .SH
3016 SYNOPSIS
3017 .LP
3018 .B mgf2meta
3019 [
3020 .B "-t threshold"
3021 ]
3022 .B "{x|y|z} xmin xmax ymin ymax zmin zmax"
3023 [
3024 .B input ..
3025 ]
3026 .SH
3027 DESCRIPTION
3028 .LP
3029 .I Mgf2meta
3030 converts one or more Materials and Geometry Format (MGF)
3031 files to a 2-D orthographic projection along the selected axis in the
3032 .I metafile(1)
3033 graphics format.
3034 All geometry is clipped to the specified bounding box, and the
3035 resulting orientation is as follows:
3036 .sp .5
3037 .nf
3038 Projection Orientation
3039 ======= ========
3040 x Y-axis right, Z-axis up
3041 y Z-axis right, X-axis up
3042 z X-axis right, Z-axis up
3043 .fi
3044 .LP
3045 If multiple input files are given, the first file prints in black,
3046 the second prints in red, the third in green and the fourth in blue.
3047 If more than four input files are given, they cycle through the
3048 colors again in three other line types: dashed, dotted and
3049 dot-dashed.
3050 .LP
3051 The
3052 .I \-t
3053 option may be used to randomly throw out line segments that are
3054 shorter than the given
3055 .I threshold
3056 (given as a fraction of the plot width).
3057 Segments are included with a
3058 probability equal to the square of the line length over the square
3059 of the threshold.
3060 This can greatly reduce the number of lines in the drawing (and
3061 therefore improve the drawing speed) with only a modest loss in
3062 quality.
3063 A typical value for this parameter is 0.005.
3064 .LP
3065 All MGF material information is ignored on the input.
3066 .SH
3067 EXAMPLES
3068 .LP
3069 To project two MGF files along the Z-axis and display them under
3070 X11:
3071 .IP
3072 mgf2meta z 0 10 0 15 0 9 building1.mgf building2.mgf | x11meta
3073 .LP
3074 To convert a RADIANCE scene to a line drawing in RADIANCE picture
3075 format:
3076 .IP
3077 rad2mgf scene.rad | mgf2meta x `getbbox -h scene.rad` | meta2tga |
3078 ra_t8 -r > scene.pic
3079 .SH
3080 AUTHOR
3081 .LP
3082 Greg Ward
3083 .SH
3084 SEE ALSO
3085 .LP
3086 getbbox(1), meta2tga(1), metafile(5), mgf2rad(1), pflip(1),
3087 protate(1), psmeta(1), ra_t8(1), rad2mgf(1), t4014(1), x11meta(1)
3088 .ds RH
3089 .ds LH
3090 .bp
3091 .NH
3092 MGF Parser Library
3093 .LP
3094 The principal motivation for creating a standard parser library for
3095 MGF is to make it easy for software developers to offer some base
3096 level of compliance.
3097 The key to making MGF easy to support in fact is the parser, which
3098 has the ability to express higher order entities in terms of
3099 lower order ones.
3100 For example, tori are part of the MGF specification, but if a given
3101 program or translator does not support them, the parser will convert
3102 them to cones.
3103 If cones are not supported either, it will convert them further into
3104 smoothed polygons.
3105 If smoothing (vertex normal information) is not supported, it will
3106 be ignored and the program will just get flat polygons.
3107 This is done in such a way that future versions of the standard may
3108 include new entities that old software does not even have to know
3109 about, and they will be converted appropriately.
3110 Forward compatibility is thus built right into the parser loading
3111 mechanism itself -- the programmer simply links to the new code and
3112 the new standard is supported without any further changes.
3113 .SH
3114 Language
3115 .LP
3116 The provided MGF parser is written in ANSI-C.
3117 This language was chosen for reasons of portability and efficiency.
3118 Almost all systems support some form of ANSI-compatible C, and many
3119 languages can cross-link to C libraries without modification.
3120 Backward compatibility to Kernighan and Ritchie C is achieved by
3121 compiling with the -DNOPROTO flag.
3122 .LP
3123 All of the data structures and prototypes needed for the library
3124 are in the header file "parser.h".
3125 This file is the best resource for the parser and is updated with
3126 each MGF release.
3127 .SH
3128 Mechanism
3129 .LP
3130 The parser works by a simple callback mechanism to routines that
3131 actually interpret the individual entities.
3132 Some of these routines will belong to the calling program, and some
3133 will be entity support routines included in the library itself.
3134 There is a global array of function pointers, called
3135 .I mg_ehand.
3136 It is defined thus:
3137 .DS
3138 extern int (*mg_ehand[MG_NENTITIES])(int argc, char **argv);
3139 .DE
3140 Before parsing begins, this dispatch table is initialized to point to the
3141 routines that will handle each supported entity.
3142 Every entity handler has the same basic prototype, which is the
3143 same as the
3144 .I main
3145 function, i.e:
3146 .DS
3147 extern int \f2handler\f1(int argc, char **argv);
3148 .DE
3149 The first argument is the number of words in the MGF entity
3150 (counting the entity itself) and the second argument is an array of
3151 nul-terminated strings with the entity and its arguments.
3152 The function should return zero or one of the error
3153 codes defined in "parser.h".
3154 A non-zero return value causes the parser to abort, returning the
3155 error up through its call stack to the entry function, usually
3156 .I mg_load.
3157 .LP
3158 A special function pointer for undefined entities is
3159 defined as follows:
3160 .DS
3161 extern int (*mg_uhand)(int argc, char **argv);
3162 .DE
3163 By default, this points to the library function
3164 .I mg_defuhand,
3165 which prints an error message on the first unknown entity and keeps a
3166 count from then on, which is stored in the global unsigned integer
3167 .I mg_nunknown.
3168 If the
3169 .I mg_uhand
3170 pointer is assigned a value of NULL instead, parsing will abort at the
3171 first unrecognized entity.
3172 The reason this is not the default action is that ignoring unknown entities
3173 offers a certain base level of forward compatibility.
3174 Ignoring things one does not understand is not the best approach, but it
3175 is usually better than quitting with an error message if the input is
3176 in fact valid, but is a later version of the standard.
3177 The real solution is to update the interpreter by linking to a new version
3178 of the parser, or use a new version of the
3179 .I mgfilt
3180 command to convert the new MGF input to an older standard.
3181 .LP
3182 The
3183 .I mg_uhand
3184 pointer may also be used to customize the language for a particular
3185 application by adding entities, though this is discouraged because it
3186 tends to weaken the standard.
3187 .LP
3188 The skeletal framework for an MGF loader or translator is to assign
3189 function pointers to the
3190 .I mg_ehand
3191 array, call the parser initialization function
3192 .I mg_init,
3193 then call the file loader function
3194 .I mg_load
3195 once for each input file.
3196 This will in turn make calls back to the functions assigned to
3197 .I mg_ehand.
3198 To give a simple example, let us look at a
3199 translator that understands only flat polygonal faces, putting out
3200 vertex locations immediately after each "face" keyword:
3201 .DS
3202 #include <stdio.h>
3203 #include "parser.h"
3204
3205 int
3206 myfaceh(ac, av) /* face handling routine */
3207 int ac;
3208 char **av;
3209 {
3210 C_VERTEX *vp; /* vertex structure pointer */
3211 FVECT vert; /* vertex point location */
3212 int i;
3213
3214 if (ac < 4) /* check # arguments */
3215 return(MG_EARGC);
3216 printf("face\\\\n"); /* begin face output */
3217 for (i = 1; i < ac; i++) {
3218 if ((vp = c_getvert(av[i])) == NULL) /* vertex from name */
3219 return(MG_EUNDEF);
3220 xf_xfmpoint(vert, vp->p); /* apply transform */
3221 printf("%15.9f %15.9f %15.9f\\\\n",
3222 vert[0], vert[1], vert[2]); /* output vertex */
3223 }
3224 printf(";\\\\n"); /* end of face output */
3225 return(MG_OK); /* normal exit */
3226 }
3227
3228 main(argc, argv) /* translate MGF file(s) */
3229 int argc;
3230 char **argv;
3231 {
3232 int i;
3233 /* initialize dispatch table */
3234 mg_ehand[MG_E_FACE] = myfaceh; /* ours */
3235 mg_ehand[MG_E_VERTEX] = c_hvertex; /* parser lib */
3236 mg_ehand[MG_E_POINT] = c_hvertex; /* parser lib */
3237 mg_ehand[MG_E_XF] = xf_handler; /* parser lib */
3238 mg_init(); /* initialize parser */
3239 for (i = 1; i < argc; i++) /* load each file argument */
3240 if (mg_load(argv[i]) != MG_OK) /* and check for error */
3241 exit(1);
3242 exit(0); /* all done! */
3243 }
3244 .DE
3245 Hopefully, this example demonstrates just how easy it is to
3246 write an MGF translator.
3247 Of course, translators get more complicated the more entity
3248 types they support, but the point is that one does not
3249 .I have
3250 to support every entity -- the parser handles what the translator
3251 does not.
3252 Also, the library includes many general entity handlers,
3253 further reducing the burden on the programmer.
3254 This same principle means that it is not necessary to modify an
3255 existing program to accommodate a new version of MGF -- one need only
3256 link to the new parser library to comply with the new standard.
3257 .SH
3258 Division of Labor
3259 .LP
3260 As seen in the previous example, there are two parser routines that
3261 are normally called directly in an MGF translator or loader program.
3262 The first is
3263 .I mg_init,
3264 which takes no arguments but relies on the program having
3265 initialized those parts of the global
3266 .I mg_ehand
3267 array it cares about.
3268 The second routine is
3269 .I mg_load,
3270 which is called once on each input file.
3271 (A third routine,
3272 .I mg_clear,
3273 may be called to free the parser data structures after each file or
3274 after all files, if the program plans to continue rather than
3275 exit.)\0
3276 .LP
3277 The rest of the routines in a translator or loader program are
3278 called indirectly through the
3279 .I mg_ehand
3280 dispatch table, and they are the ones that do the real work of
3281 supporting the MGF entities.
3282 In addition to converting or discarding entities that the calling
3283 program does not know or care about, the parser library includes a
3284 set of context handlers that greatly simplify the translation
3285 process.
3286 There are three handlers for each of the three named contexts and
3287 their constituents, and two handlers for the two hierarchical
3288 context entities.
3289 To use these handlers, one simply sets the appropriate positions in the
3290 .I mg_ehand
3291 dispatch table to point to these functions.
3292 Additional functions and global data structures provide convenient
3293 access to the relevant contexts, and all of these are detailed in
3294 the following manual pages.
3295 .ds LH Basic Parser Routines
3296 .ds RH MG_INIT
3297 .bp
3298 .SH
3299 NAME
3300 .LP
3301 mg_init, mg_ehand, mg_uhand - initialize MGF entity handlers
3302 .SH
3303 SYNOPSIS
3304 .LP
3305 #include "parser.h"
3306 .LP
3307 .B void
3308 mg_init(
3309 .B void
3310 )
3311 .LP
3312 .B int
3313 mg_defuhand(
3314 .B int
3315 argc,
3316 .B char
3317 **argv )
3318 .LP
3319 .B "extern int"
3320 (*mg_ehand[MG_NENTITIES])(
3321 .B int
3322 argc,
3323 .B char
3324 **argv )
3325 .LP
3326 .B "extern int"
3327 (*mg_uhand)(
3328 .B int
3329 argc,
3330 .B char
3331 **argv )
3332 .LP
3333 .B "extern unsigned"
3334 mg_nunknown
3335 .SH
3336 DESCRIPTION
3337 .LP
3338 The parser dispatch table,
3339 .I mg_ehand
3340 is initially set to all NULL pointers, and it
3341 is the duty of the calling program to assign entity handler functions to
3342 each of the supported entity positions in the array.
3343 The entities are given in the include file "parser.h" as the
3344 following:
3345 .DS
3346 #define MG_E_COMMENT 0 /* # */
3347 #define MG_E_COLOR 1 /* c */
3348 #define MG_E_CCT 2 /* cct */
3349 #define MG_E_CONE 3 /* cone */
3350 #define MG_E_CMIX 4 /* cmix */
3351 #define MG_E_CSPEC 5 /* cspec */
3352 #define MG_E_CXY 6 /* cxy */
3353 #define MG_E_CYL 7 /* cyl */
3354 #define MG_E_ED 8 /* ed */
3355 #define MG_E_FACE 9 /* f */
3356 #define MG_E_INCLUDE 10 /* i */
3357 #define MG_E_IES 11 /* ies */
3358 #define MG_E_IR 12 /* ir */
3359 #define MG_E_MATERIAL 13 /* m */
3360 #define MG_E_NORMAL 14 /* n */
3361 #define MG_E_OBJECT 15 /* o */
3362 #define MG_E_POINT 16 /* p */
3363 #define MG_E_PRISM 17 /* prism */
3364 #define MG_E_RD 18 /* rd */
3365 #define MG_E_RING 19 /* ring */
3366 #define MG_E_RS 20 /* rs */
3367 #define MG_E_SIDES 21 /* sides */
3368 #define MG_E_SPH 22 /* sph */
3369 #define MG_E_TD 23 /* td */
3370 #define MG_E_TORUS 24 /* torus */
3371 #define MG_E_TS 25 /* ts */
3372 #define MG_E_VERTEX 26 /* v */
3373 #define MG_E_XF 27 /* xf */
3374
3375 #define MG_NENTITIES 28 /* total # entities */
3376 .DE
3377 .LP
3378 Once the
3379 .I mg_ehand
3380 array has been set by the program, the
3381 .I mg_init
3382 routine must be called to complete the initialization process.
3383 This should be done once and only once per invocation, before any other
3384 parser routines are called.
3385 .LP
3386 The
3387 .I mg_uhand
3388 variable points to the current handler for unknown entities
3389 encountered on the input.
3390 Its default value points to the
3391 .I mg_defuhand
3392 function, which simply increments the global variable
3393 .I mg_nunknown,
3394 printing a warning message on the standard error on the first
3395 offense.
3396 (This message may be avoided by incrementing
3397 .I mg_nunknown
3398 before processing begins.)\0
3399 If
3400 .I mg_uhand
3401 is assigned a value of NULL, then an unknown entity will return an
3402 .I MG_EUNK
3403 error, which will cause the parser to abort.
3404 (See the
3405 .I mg_load
3406 page for a list of errors.)\0
3407 If the
3408 .I mg_uhand
3409 pointer is assigned to another function, that function will receive
3410 any unknown entities and their arguments, and the parsing will
3411 abort if the new function returns a non-zero error value.
3412 This offers a convenient way to customize the language by adding
3413 non-standard entities.
3414 .SH
3415 DIAGNOSTICS
3416 .LP
3417 If an inconsistent set of entities has been set for support, the
3418 .I mg_init
3419 routine will print an informative message to standard error and abort
3420 the calling program with a call to
3421 .I exit.
3422 This is normally unacceptable behavior for a library routine, but since
3423 such an error indicates a fault with the calling program itself,
3424 recovery is impossible.
3425 .SH
3426 SEE ALSO
3427 .LP
3428 mg_load, mg_handle
3429 .ds RH MG_LOAD
3430 .bp
3431 .SH
3432 NAME
3433 .LP
3434 mg_load, mg_clear, mg_file, mg_err - load MGF file, clear data structures
3435 .SH
3436 SYNOPSIS
3437 .LP
3438 #include "parser.h"
3439 .LP
3440 .B int
3441 mg_load(
3442 .B char
3443 *filename )
3444 .LP
3445 .B void
3446 mg_clear(
3447 .B void
3448 )
3449 .LP
3450 .B extern
3451 MG_FCTXT *mg_file
3452 .LP
3453 .B "extern char"
3454 *mg_err[MG_NERRS]
3455 .SH
3456 DESCRIPTION
3457 .LP
3458 The
3459 .I mg_load
3460 function loads the named file, or standard input if
3461 .I filename
3462 is the NULL pointer.
3463 Calls back to the appropriate MGF handler routines are made through the
3464 .I mg_ehand
3465 dispatch table.
3466 .LP
3467 The global
3468 .I mg_file
3469 variable points to the current file context structure, which
3470 may be useful for the interpretation of certain entities, such as
3471 .UL ies,
3472 which must know the directory path of the enclosing file.
3473 This structure is of the defined type
3474 .I MG_FCTXT,
3475 given in "parser.h" as:
3476 .DS
3477 typedef struct mg_fctxt {
3478 char fname[96]; /* file name */
3479 FILE *fp; /* stream pointer */
3480 int fid; /* unique file context id */
3481 char inpline[4096]; /* input line */
3482 int lineno; /* line number */
3483 struct mg_fctxt *prev; /* previous context */
3484 } MG_FCTXT;
3485 .DE
3486 .SH
3487 DIAGNOSTICS
3488 .LP
3489 If an error is encountered during parsing,
3490 .I mg_load
3491 will print an appropriate error message to the standard error stream
3492 and return one of the non-zero values from "parser.h" listed below:
3493 .DS
3494 #define MG_OK 0 /* normal return value */
3495 #define MG_EUNK 1 /* unknown entity */
3496 #define MG_EARGC 2 /* wrong number of arguments */
3497 #define MG_ETYPE 3 /* argument type error */
3498 #define MG_EILL 4 /* illegal argument value */
3499 #define MG_EUNDEF 5 /* undefined reference */
3500 #define MG_ENOFILE 6 /* cannot open input file */
3501 #define MG_EINCL 7 /* error in included file */
3502 #define MG_EMEM 8 /* out of memory */
3503 #define MG_ESEEK 9 /* file seek error */
3504 #define MG_EBADMAT 10 /* bad material specification */
3505 #define MG_ELINE 11 /* input line too long */
3506 #define MG_ECNTXT 12 /* unmatched context close */
3507
3508 #define MG_NERRS 13
3509 .DE
3510 If it is inappropriate to send output to standard error, the calling
3511 program should use the routines listed under
3512 .I mg_open
3513 for better control over the parsing process.
3514 .LP
3515 The
3516 .I mg_err
3517 array contains error messages corresponding to each of the values
3518 listed above in the native country's language.
3519 .SH
3520 SEE ALSO
3521 .LP
3522 mg_fgetpos, mg_handle, mg_init, mg_open
3523 .ds RH MG_OPEN
3524 .bp
3525 .SH
3526 NAME
3527 .LP
3528 mg_open, mg_read, mg_parse, mg_close - MGF file loading subroutines
3529 .SH
3530 SYNOPSIS
3531 .LP
3532 #include "parser.h"
3533 .LP
3534 .B int
3535 mg_open( MG_FCTXT *fcp,
3536 .B char
3537 *filename )
3538 .LP
3539 .B int
3540 mg_read(
3541 .B void
3542 )
3543 .LP
3544 .B int
3545 mg_parse(
3546 .B void
3547 )
3548 .LP
3549 .B void
3550 mg_close(
3551 .B void
3552 )
3553 .SH
3554 DESCRIPTION
3555 .LP
3556 Most loaders and translators will call the
3557 .I mg_load
3558 routine to handle the above operations, but some programs or
3559 entity handlers require tighter control over the loading process.
3560 .LP
3561 The
3562 .I mg_open
3563 routine takes an uninitialized
3564 .I MG_FCTXT
3565 structure and a file name as its arguments.
3566 If
3567 .I filename
3568 is the NULL pointer, the standard input is "opened."
3569 The
3570 .I fcp
3571 structure will be set by
3572 .I mg_open
3573 prior to its return, and the global
3574 .I mg_file
3575 pointer will be assigned to point to it.
3576 This variable must not be destroyed until after the file is closed
3577 with a call to
3578 .I mg_close.
3579 (See the
3580 .I mg_load
3581 page for a definition of
3582 .I mg_file
3583 and the
3584 .I MG_FCTXT
3585 type.)\0
3586 .LP
3587 The
3588 .I mg_read
3589 function reads the next input line from the current file,
3590 returning the number of characters in the line, or zero if the
3591 end of file is reached or there is a file error.
3592 If the value returned equals MG_MAXLINE-1,
3593 then the input line was too long, and you
3594 should return an MG_ELINE error.
3595 The function keeps track of the
3596 line number in the current file context
3597 .I mg_file,
3598 which also contains the line that was read.
3599 .LP
3600 The
3601 .I mg_parse
3602 function breaks the current line in the
3603 .I mg_file
3604 structure into words and calls the appropriate handler routine, if
3605 any.
3606 Blank lines and unsupported entities cause a quick return.
3607 .LP
3608 The
3609 .I mg_close
3610 routine closes the current input file (unless it is the standard
3611 input) and returns to the previous file context (if any).
3612 .SH
3613 DIAGNOSTICS
3614 .LP
3615 The
3616 .I mg_open
3617 function returns
3618 .I MG_OK
3619 (0) normally, or
3620 .I MG_ENOFILE
3621 if the open fails for some reason.
3622 .LP
3623 The
3624 .I mg_parse
3625 function returns
3626 .I MG_OK
3627 if the current line was successfully interpreted, or one of the
3628 defined error values if there is a problem.
3629 (See the
3630 .I mg_load
3631 page for the defined error values.)\0
3632 .SH
3633 SEE ALSO
3634 .LP
3635 mg_fgetpos, mg_handle, mg_init, mg_load
3636 .ds RH MG_FGETPOS
3637 .bp
3638 .SH
3639 NAME
3640 .LP
3641 mg_fgetpos, mg_fgoto - get current file position and seek to pointer
3642 .SH
3643 SYNOPSIS
3644 .LP
3645 #include "parser.h"
3646 .LP
3647 .B void
3648 mg_fgetpos( MG_FPOS *pos )
3649 .LP
3650 .B int
3651 mg_fgoto( MG_FPOS *pos )
3652 .SH
3653 DESCRIPTION
3654 .LP
3655 The
3656 .I mg_fgetpos
3657 gets the current MGF file position and loads it into the passed
3658 .I MG_FPOS
3659 structure,
3660 .I pos.
3661 .LP
3662 The
3663 .I mg_fgoto
3664 function seeks to the position
3665 .I pos,
3666 taken from a previous call to
3667 .I mg_fgetpos.
3668 .SH
3669 DIAGNOSTICS
3670 .LP
3671 If
3672 .I mg_fgoto
3673 is passed an illegal pointer or one that does not correspond to the
3674 current
3675 .I mg_file
3676 context, it will return the
3677 .I MG_ESEEK
3678 error value.
3679 Normally, it returns
3680 .I MG_OK
3681 (0).
3682 .SH
3683 SEE ALSO
3684 .LP
3685 mg_load, mg_open
3686 .ds RH MG_HANDLE
3687 .bp
3688 .SH
3689 NAME
3690 .LP
3691 mg_handle, mg_entity, mg_ename, mg_nqcdivs - entity assistance and control
3692 .SH
3693 SYNOPSIS
3694 .LP
3695 .B int
3696 mg_handle(
3697 .B int
3698 en,
3699 .B int
3700 ac,
3701 .B char
3702 *av )
3703 .LP
3704 .B int
3705 mg_entity(
3706 .B char
3707 *name )
3708 .LP
3709 .B "extern char"
3710 mg_ename[MG_NENTITIES][MG_MAXELEN]
3711 .LP
3712 .B "extern int"
3713 mg_nqcdivs
3714 .SH
3715 DESCRIPTION
3716 .LP
3717 The
3718 .I mg_handle
3719 routine may be used to pass entities back to the parser
3720 to be redirected through the
3721 .I mg_ehand
3722 dispatch table.
3723 This method is recommended rather than calling through
3724 .I mg_ehand
3725 directly, since the parser sometimes has its own support routines
3726 that it needs to call for specific entities.
3727 The first argument,
3728 .I en,
3729 is the corresponding entity number, or -1 if
3730 .I mg_handle
3731 should figure it out from the first
3732 .I av
3733 argument.
3734 .LP
3735 The
3736 .I mg_entity
3737 function gets an entity number from its name, using a hash
3738 table on the
3739 .I mg_ename
3740 list.
3741 .LP
3742 The
3743 .I mg_ename
3744 table contains the string names corresponding to each MGF entity in
3745 the designated order.
3746 (See the
3747 .I mg_init
3748 page for the list of MGF entities.)\0
3749 .LP
3750 The global integer variable
3751 .I mg_nqcdivs
3752 tells the parser how many subdivisions to use per quarter circle (90
3753 degrees) when tesselating curved geometry.
3754 The default value is 5, and it may be reset at any time by the
3755 calling program.
3756 .SH
3757 DIAGNOSTICS
3758 .LP
3759 The
3760 .I mg_handle
3761 function returns
3762 .I MG_OK
3763 if the entity is handled correctly, or one of the predefined error
3764 values if there is a problem.
3765 (See the
3766 .I mg_load
3767 page for a list of error values.)\0
3768 .LP
3769 The
3770 .I mg_entity
3771 function returns -1 if the passed name does not appear in the
3772 .I mg_ename
3773 list.
3774 .SH
3775 SEE ALSO
3776 .LP
3777 mg_init, mg_load, mg_open
3778 .ds RH ISINT, ISFLT, ISNAME
3779 .bp
3780 .SH
3781 NAME
3782 .LP
3783 isint, isflt, isname - determine if string fits integer or real format,
3784 or is legal identifier
3785 .SH
3786 SYNOPSIS
3787 .LP
3788 .B int
3789 isint(
3790 .B char
3791 *str )
3792 .LP
3793 .B int
3794 isflt(
3795 .B char
3796 *str )
3797 .LP
3798 .B int
3799 isname(
3800 .B char
3801 *str )
3802 .SH
3803 DESCRIPTION
3804 .LP
3805 The
3806 .I isint
3807 function checks to see if the passed string
3808 .I str
3809 matches a decimal integer format (positive or negative),
3810 and returns 1 or 0 based on whether it does or does not.
3811 .LP
3812 The
3813 .I isflt
3814 function checks to see if the passed string
3815 .I str
3816 matches a floating point format (positive or negative with optional
3817 exponent), and returns 1 or 0 based on whether it does or does not.
3818 .LP
3819 The
3820 .I isname
3821 function checks to see if the passed string
3822 .I str
3823 is a legal identifier name.
3824 In MGF, a legal identifier must begin with a letter and contain only
3825 visible ASCII characters (those between decimal 33 and 127 inclusive).
3826 The one caveat to this is that names may begin with one or more
3827 underscores ('_'), but this is a trick employed by the parser to
3828 maintain a separate name space from the user, and is not legal usage
3829 otherwise.
3830 .LP
3831 Note that a string that matches an integer format is also a valid
3832 floating point value.
3833 Conversely, a string that is not a floating point number cannot be a
3834 valid integer.
3835 .LP
3836 These routines are useful for checking arguments passed to entity
3837 handlers that certain types in certain positions.
3838 If an invalid argument is passed, the handler should return an
3839 .I MG_ETYPE
3840 error.
3841 .SH
3842 SEE ALSO
3843 .LP
3844 mg_init, mg_load
3845 .ds LH Entity Support Routines
3846 .ds RH C_HVERTEX
3847 .bp
3848 .SH
3849 NAME
3850 .LP
3851 c_hvertex, c_getvert, c_cvname, c_cvertex - vertex entity support
3852 .SH
3853 SYNOPSIS
3854 .LP
3855 #include "parser.h"
3856 .LP
3857 .B int
3858 c_hvertex(
3859 .B int
3860 argc,
3861 .B char
3862 **argv )
3863 .LP
3864 C_VERTEX *c_getvert(
3865 .B char
3866 *name )
3867 .LP
3868 .B "extern char"
3869 *c_vname
3870 .LP
3871 .B extern
3872 C_VERTEX *c_cvertex
3873 .SH
3874 DESCRIPTION
3875 .LP
3876 The
3877 .I c_hvertex
3878 function handles the MGF vertex entities,
3879 .UL v,
3880 .UL p
3881 and
3882 .UL n.
3883 If either
3884 .UL p
3885 or
3886 .UL n
3887 is supported, then
3888 .UL v
3889 must be also.
3890 The assignments are normally made to the
3891 .I mg_ehand
3892 array prior to parser initialization, like so:
3893 .DS
3894 mg_ehand[MG_E_VERTEX] = c_hvertex; /* support "v" entity */
3895 mg_ehand[MG_E_POINT] = c_hvertex; /* support "p" entity */
3896 mg_ehand[MG_E_NORMAL] = c_hvertex; /* support "n" entity */
3897 /* other entity handler assignments... */
3898 mg_init(); /* initialize parser */
3899 .DE
3900 If vertex normals are not understood by any of the program-supported
3901 entities, then the
3902 .I MG_E_NORMAL
3903 entry may be left with its original NULL assignment.
3904 .LP
3905 The
3906 .I c_getvert
3907 call takes the name of a defined vertex and returns a pointer to its
3908 .I C_VERTEX
3909 structure, defined in "parser.h" as:
3910 .DS
3911 typedef FLOAT FVECT[3]; /* a 3-d real vector */
3912
3913 typedef struct {
3914 int clock; /* incremented each change -- resettable */
3915 FVECT p, n; /* point and normal */
3916 } C_VERTEX; /* vertex context */
3917 .DE
3918 The
3919 .I clock
3920 member will be incremented each time the value gets changed by a
3921 .UL p
3922 or
3923 .UL n
3924 entity, and may be reset by the controlling program if desired.
3925 This is a convenient way to keep track of whether or not a vertex has
3926 changed since its last use.
3927 To link identical vertices, one must also check that the current
3928 transform has not changed, which is uniquely identified by the
3929 global
3930 .I xf_context->xid
3931 variable, but only if one is using the parser library's transform
3932 handler.
3933 (See the
3934 .I xf_handler
3935 page.)\0
3936 .LP
3937 It is possible but not recommended to alter the contents of the
3938 vertex structure returned by
3939 .I c_getvert.
3940 Normally it is read during the
3941 interpretation of entities using named vertices.
3942 .LP
3943 The name of the current vertex is given by the global
3944 .I c_cvname
3945 variable, which is set to NULL if the unnamed vertex is current.
3946 The current vertex value is pointed to by the global variable
3947 .I c_cvertex,
3948 which should never be NULL.
3949 .SH
3950 DIAGNOSTICS
3951 .LP
3952 The
3953 .I c_hvertex
3954 function returns
3955 .I MG_OK
3956 (0) if the vertex is handled correctly, or one of the predefined
3957 error values if there is a problem.
3958 (See the
3959 .I mg_load
3960 page for a list of errors.)\0
3961 .LP
3962 The
3963 .I c_getvert
3964 function returns NULL if the specified vertex name is undefined, at
3965 which point the calling function should return an
3966 .I MG_EUNDEF
3967 error.
3968 .SH
3969 SEE ALSO
3970 .LP
3971 c_hcolor, c_hmaterial, mg_init, mg_load, xf_handler
3972 .ds RH C_HCOLOR
3973 .bp
3974 .SH
3975 NAME
3976 .LP
3977 c_hcolor, c_getcolor, c_ccname, c_ccolor, c_ccvt, c_isgrey -
3978 color entity support
3979 .SH
3980 SYNOPSIS
3981 .LP
3982 #include "parser.h"
3983 .LP
3984 .B int
3985 c_hcolor(
3986 .B int
3987 argc,
3988 .B char
3989 **argv )
3990 .LP
3991 C_COLOR *c_getcolor(
3992 .B char
3993 *name )
3994 .LP
3995 .B "extern char"
3996 *c_ccname
3997 .LP
3998 .B extern
3999 C_COLOR *c_ccolor
4000 .LP
4001 .B void
4002 c_ccvt( C_COLOR *cvp,
4003 .B int
4004 cflags )
4005 .LP
4006 .B int
4007 c_isgrey( C_COLOR *cvp )
4008 .SH
4009 DESCRIPTION
4010 .LP
4011 The
4012 .I c_hcolor
4013 function supports the MGF entities,
4014 .UL c,
4015 .UL cxy,
4016 .UL cspec,
4017 .UL cct
4018 and
4019 .UL cmix.
4020 It is an error to support any of the color field entities without
4021 supporting the
4022 .UL c
4023 entity itself.
4024 The assignments are normally made to the
4025 .I mg_ehand
4026 array prior to parser initialization, like so:
4027 .DS
4028 mg_ehand[MG_E_COLOR] = c_hcolor; /* support "c" entity */
4029 mg_ehand[MG_E_CXY] = c_hcolor; /* support "cxy" entity */
4030 mg_ehand[MG_E_CSPEC] = c_hcolor; /* support "cspec" entity */
4031 mg_ehand[MG_E_CCT] = c_hcolor; /* support "cct" entity */
4032 mg_ehand[MG_E_CMIX] = c_hcolor; /* support "cmix" entity */
4033 /* other entity handler assignments... */
4034 mg_init(); /* initialize parser */
4035 .DE
4036 If the loader/translator has no use for spectral data, the entries for
4037 .UL cspec
4038 and
4039 .UL cct
4040 may be left with their original NULL assignments and these entities will
4041 be re-expressed appropriately as tristimulus values.
4042 .LP
4043 The
4044 .I c_getcolor
4045 function takes the name of a defined color and returns a pointer to its
4046 .I C_COLOR
4047 structure, defined in "parser.h" as:
4048 .DS
4049 #define C_CMINWL 380 /* minimum wavelength */
4050 #define C_CMAXWL 780 /* maximum wavelength */
4051 #define C_CNSS 41 /* number of spectral samples */
4052 #define C_CWLI ((C_CMAXWL-C_CMINWL)/(C_CNSS-1))
4053 #define C_CMAXV 10000 /* nominal maximum sample value */
4054 #define C_CLPWM (683./C_CMAXV) /* peak lumens/watt multiplier */
4055
4056 typedef struct {
4057 int clock; /* incremented each change */
4058 short flags; /* what's been set */
4059 short ssamp[C_CNSS]; /* spectral samples, min wl to max */
4060 long ssum; /* straight sum of spectral values */
4061 float cx, cy; /* xy chromaticity value */
4062 float eff; /* efficacy (lumens/watt) */
4063 } C_COLOR; /* color context */
4064 .DE
4065 The
4066 .I clock
4067 member will be incremented each time the value gets changed by a
4068 color field entity, and may be reset by the calling program if
4069 desired.
4070 This is a convenient way to keep track of whether or not a color has
4071 changed since its last use.
4072 The
4073 .I flags
4074 member indicates which color representations have been assigned,
4075 and is an inclusive OR of one or more of the following:
4076 .DS
4077 #define C_CSSPEC 01 /* flag if spectrum is set */
4078 #define C_CDSPEC 02 /* flag if defined w/ spectrum */
4079 #define C_CSXY 04 /* flag if xy is set */
4080 #define C_CDXY 010 /* flag if defined w/ xy */
4081 #define C_CSEFF 020 /* flag if efficacy set */
4082 .DE
4083 .LP
4084 It is possible but not recommended to alter the contents of the
4085 color structure returned by
4086 .I c_getcolor.
4087 Normally, this routine is never called directly, since there are no
4088 entities that access colors by name other than
4089 .UL c.
4090 .LP
4091 The global variable
4092 .I c_ccname
4093 points to the name of the current color, or NULL if it is unnamed.
4094 The variable
4095 .I c_ccolor
4096 points to the current color value, which should never be NULL.
4097 .LP
4098 The
4099 .I c_ccvt
4100 routine takes a
4101 .I C_COLOR
4102 structure and a set of desired flag settings and computes the
4103 missing color representation(s).
4104 .LP
4105 The
4106 .I c_isgrey
4107 function returns 1 if the passed color is very close to neutral
4108 grey, or 0 otherwise.
4109 .SH
4110 DIAGNOSTICS
4111 .LP
4112 The
4113 .I c_hcolor
4114 function returns
4115 .I MG_OK
4116 (0) if the color is handled correctly, or one of the predefined
4117 error values if there is a problem.
4118 (See the
4119 .I mg_load
4120 page for a list of errors.)\0
4121 .LP
4122 The
4123 .I c_getcolor
4124 function returns NULL if the specified color name is undefined, at
4125 which point the calling function should return an
4126 .I MG_EUNDEF
4127 error.
4128 .SH
4129 SEE ALSO
4130 .LP
4131 c_hmaterial, c_hvertex, mg_init, mg_load
4132 .ds RH C_HMATERIAL
4133 .bp
4134 .SH
4135 NAME
4136 .LP
4137 c_hmaterial, c_getmaterial, c_cmname, c_cmaterial -
4138 material entity support
4139 .SH
4140 SYNOPSIS
4141 .LP
4142 #include "parser.h"
4143 .LP
4144 .B int
4145 c_hmaterial(
4146 .B int
4147 argc,
4148 .B char
4149 **argv )
4150 .LP
4151 C_MATERIAL *c_getmaterial(
4152 .B char
4153 *name )
4154 .LP
4155 .B "extern char"
4156 *c_cmname
4157 .LP
4158 .B extern
4159 C_MATERIAL *c_cmaterial
4160 .SH
4161 DESCRIPTION
4162 .LP
4163 The
4164 .I c_hmaterial
4165 function supports the MGF entities,
4166 .UL m,
4167 .UL ed,
4168 .UL ir,
4169 .UL rd,
4170 .UL rs,
4171 .UL sides,
4172 .UL td,
4173 and
4174 .UL ts.
4175 It is an error to support any of the material field entities without
4176 supporting the
4177 .UL m
4178 entity itself.
4179 The assignments are normally made to the
4180 .I mg_ehand
4181 array prior to parser initialization, like so:
4182 .DS
4183 mg_ehand[MG_E_MATERIAL] = c_hmaterial; /* support "m" entity */
4184 mg_ehand[MG_E_ED] = c_hmaterial; /* support "ed" entity */
4185 mg_ehand[MG_E_IR] = c_hmaterial; /* support "ir" entity */
4186 mg_ehand[MG_E_RD] = c_hmaterial; /* support "rd" entity */
4187 mg_ehand[MG_E_RS] = c_hmaterial; /* support "rs" entity */
4188 mg_ehand[MG_E_SIDES] = c_hmaterial; /* support "sides" entity */
4189 mg_ehand[MG_E_TD] = c_hmaterial; /* support "td" entity */
4190 mg_ehand[MG_E_TS] = c_hmaterial; /* support "ts" entity */
4191 /* other entity handler assignments... */
4192 mg_init(); /* initialize parser */
4193 .DE
4194 Any of the above entities besides
4195 .UL m
4196 may be unsupported, but the parser will not attempt to include their
4197 effect into other members, e.g. an unsupported
4198 .UL rs
4199 component will not be added back into the
4200 .UL rd
4201 member.
4202 It is therefore safer to support all of the relevant material
4203 entities and make final approximations from the complete
4204 .I C_MATERIAL
4205 structure.
4206 .LP
4207 The
4208 .I c_getmaterial
4209 function takes the name of a defined material and returns a pointer to its
4210 .I C_MATERIAL
4211 structure, defined in "parser.h" as:
4212 .DS
4213 #define C_1SIDEDTHICK 0.005 /* assumed thickness of 1-sided mat. */
4214
4215 typedef struct {
4216 int clock; /* incremented each change -- resettable */
4217 int sided; /* 1 if surface is 1-sided, 0 for 2-sided */
4218 float nr, ni; /* index of refraction, real and imaginary */
4219 float rd; /* diffuse reflectance */
4220 C_COLOR rd_c; /* diffuse reflectance color */
4221 float td; /* diffuse transmittance */
4222 C_COLOR td_c; /* diffuse transmittance color */
4223 float ed; /* diffuse emittance */
4224 C_COLOR ed_c; /* diffuse emittance color */
4225 float rs; /* specular reflectance */
4226 C_COLOR rs_c; /* specular reflectance color */
4227 float rs_a; /* specular reflectance roughness */
4228 float ts; /* specular transmittance */
4229 C_COLOR ts_c; /* specular transmittance color */
4230 float ts_a; /* specular transmittance roughness */
4231 } C_MATERIAL; /* material context */
4232 .DE
4233 The
4234 .I clock
4235 member will be incremented each time the value gets changed by a
4236 material field entity, and may be reset by the calling program if
4237 desired.
4238 This is a convenient way to keep track of whether or not a material has
4239 changed since its last use.
4240 .LP
4241 All reflectance and transmittance values correspond to normal
4242 incidence, and may vary as a function of angle depending on the
4243 index of refraction.
4244 A solid object is normally represented with a one-sided material.
4245 A two-sided material is most appropriate for thin surfaces, though
4246 it may be used also when the surface normal orientations in a model
4247 are unreliable.
4248 .LP
4249 If a transparent or translucent surface is one-sided, then the
4250 absorption will change as a function of distance through the
4251 material, and a single value for diffuse or specular transmittance is
4252 ambiguous.
4253 We therefore define a standard thickness,
4254 .I C_1SIDEDTHICK,
4255 which is the object thickness to which the given values correspond,
4256 so that one may compute the isotropic absorptance of the material.
4257 .LP
4258 It is possible but not recommended to alter the contents of the
4259 material structure returned by
4260 .I c_getmaterial.
4261 Normally, this routine is never called directly, since there are no
4262 entities that access materials by name other than
4263 .UL m.
4264 .LP
4265 The global variable
4266 .I c_cmname
4267 points to the name of the current material, or NULL if it is unnamed.
4268 The variable
4269 .I c_cmaterial
4270 points to the current material value, which should never be NULL.
4271 .SH
4272 DIAGNOSTICS
4273 .LP
4274 The
4275 .I c_hmaterial
4276 function returns
4277 .I MG_OK
4278 (0) if the color is handled correctly, or one of the predefined
4279 error values if there is a problem.
4280 (See the
4281 .I mg_load
4282 page for a list of errors.)\0
4283 .LP
4284 The
4285 .I c_getmaterial
4286 function returns NULL if the specified material name is undefined, at
4287 which point the calling function should return an
4288 .I MG_EUNDEF
4289 error.
4290 .SH
4291 SEE ALSO
4292 .LP
4293 c_hcolor, c_hvertex, mg_init, mg_load
4294 .ds RH OBJ_HANDLER
4295 .bp
4296 .SH
4297 NAME
4298 .LP
4299 obj_handler, obj_clear, obj_nnames, obj_name - object name support
4300 .SH
4301 SYNOPSIS
4302 .LP
4303 .B int
4304 obj_handler(
4305 .B int
4306 argc,
4307 .B char
4308 **argv )
4309 .LP
4310 .B void
4311 obj_clear(
4312 .B void
4313 )
4314 .LP
4315 .B "extern int"
4316 obj_nnames
4317 .LP
4318 .B "extern char"
4319 **obj_name
4320 .SH
4321 DESCRIPTION
4322 .LP
4323 The
4324 .I obj_handler
4325 routine should be assigned to the
4326 .I MG_E_OBJECT
4327 entry of the parser's
4328 .I mg_ehand
4329 array prior to calling
4330 .I mg_load
4331 if the loader/translator wishes to support hierarchical object
4332 names.
4333 .LP
4334 The
4335 .I obj_clear
4336 function may be used to clear the object name stack and free any
4337 associated memory, but this is usually not necessary since
4338 .UL o
4339 begin and end entities are normally balanced in the input.
4340 .LP
4341 The global
4342 .I obj_nnames
4343 variable indicates the number of names currently in the object
4344 stack, and the
4345 .I obj_name
4346 list contains the name strings in the same order as they were
4347 encountered on the input.
4348 (I.e. the most recently pushed name is last.)\0
4349 .SH
4350 DIAGNOSTICS
4351 .LP
4352 The
4353 .I obj_handler
4354 function returns
4355 .I MG_OK
4356 (0) if the color is handled correctly, or one of the predefined
4357 error values if there is a problem.
4358 (See the
4359 .I mg_load
4360 page for a list of errors.)\0
4361 .SH
4362 SEE ALSO
4363 .LP
4364 mg_init, mg_load, xf_handler
4365 .ds RH XF_HANDLER
4366 .bp
4367 .SH
4368 NAME
4369 .LP
4370 xf_handler, xf_clear, xf_context, xf_argend - transformation support
4371 .SH
4372 SYNOPSIS
4373 .LP
4374 .B int
4375 xf_handler(
4376 .B int
4377 argc,
4378 .B char
4379 **argv )
4380 .LP
4381 .B void
4382 xf_clear(
4383 .B void
4384 )
4385 .LP
4386 .B extern
4387 XF_SPEC *xf_context
4388 .LP
4389 .B "extern char"
4390 **xf_argend
4391 .SH
4392 DESCRIPTION
4393 .LP
4394 The
4395 .I xf_handler
4396 routine should be assigned to the
4397 .I MG_E_XF
4398 entry of the parser's
4399 .I mg_ehand
4400 array prior to calling
4401 .I mg_load
4402 if the loader/translator wishes to support hierarchical
4403 transformations.
4404 (Note that all MGF geometric entities require this support.)\0
4405 .LP
4406 The
4407 .I xf_clear
4408 function may be used to clear the transform stack and free any
4409 associated memory, but this is usually not necessary since
4410 .UL xf
4411 begin and end entities are normally balanced in the input.
4412 .LP
4413 The global
4414 .I xf_context
4415 variable points to the current transformation context, which is of
4416 the type
4417 .I XF_SPEC,
4418 described in "parser.h":
4419 .DS
4420 typedef struct xf_spec {
4421 long xid; /* unique transform id */
4422 short xac; /* context argument count */
4423 short rev; /* boolean true if vertices reversed */
4424 XF xf; /* cumulative transformation */
4425 struct xf_array *xarr; /* transformation array pointer */
4426 struct xf_spec *prev; /* previous transformation context */
4427 } XF_SPEC; /* followed by argument buffer */
4428 .DE
4429 The
4430 .I xid
4431 member is a identifier associated with this transformation,
4432 which should be the same for identical transformations, as an aid to
4433 vertex sharing.
4434 (See also the
4435 .I c_hvertex
4436 page.)\0
4437 The
4438 .I xac
4439 member indicates the total number of transform arguments, and is
4440 used to indicate the position of the first argument relative to the
4441 last one pointed to by the global
4442 .I xf_argend
4443 variable.
4444 .LP
4445 The first transform argument starts at
4446 .I xf_argv,
4447 which is a macro defined in "parser.h" as:
4448 .DS
4449 #define xf_argv (xf_argend - xf_context->xac)
4450 .DE
4451 Note that accessing this macro will result in a segmentation violation
4452 if the current context is NULL, so one should first test the second macro
4453 .I xf_argc
4454 against zero.
4455 This macro is defined as:
4456 .DS
4457 #define xf_argc (xf_context==NULL ? 0 : xf_context->xac)
4458 .DE
4459 .LP
4460 Normally, neither of these macros will be used, since there are
4461 routines for transforming points, vectors and scalars directly based
4462 on the current transformation context.
4463 (See the
4464 .I xf_xfmpoint
4465 page for details.)\0
4466 .LP
4467 The
4468 .I rev
4469 member of the
4470 .I XF_SPEC
4471 structure indicates whether or not this transform reverses the order
4472 of polygon vertices.
4473 This member will be 1 if the transformation mirrors about an odd
4474 number of coordinate axes, thus inverting faces.
4475 The usual thing to do in this circumstance is to interpret the
4476 vertex arguments in the reverse order, so as to bring the face back
4477 to its original orientation in the new position.
4478 .LP
4479 The
4480 .I xf
4481 member contains the transformation scalefactor (in xf.sca)
4482 and 4x4 homogeneous matrix (in xf.xfm), but these will usually not
4483 be accessed directly.
4484 Likewise, the
4485 .I xarr
4486 and
4487 .I prev
4488 members point to data that should not be needed by the calling
4489 program.
4490 .SH
4491 DIAGNOSTICS
4492 .LP
4493 The
4494 .I xf_handler
4495 function returns
4496 .I MG_OK
4497 (0) if the color is handled correctly, or one of the predefined
4498 error values if there is a problem.
4499 (See the
4500 .I mg_load
4501 page for a list of errors.)\0
4502 .SH
4503 SEE ALSO
4504 .LP
4505 mg_init, mg_load, obj_handler, xf_xfmpoint
4506 .ds RH XF_XFMPOINT
4507 .bp
4508 .SH
4509 NAME
4510 .LP
4511 xf_xfmpoint, xf_xfmvect, xf_rotvect, xf_scale - apply current
4512 transformation
4513 .SH
4514 SYNOPSIS
4515 .LP
4516 .B void
4517 xf_xfmpoint( FVECT pnew, FVECT pold )
4518 .LP
4519 .B void
4520 xf_xfmvect( FVECT vnew, FVECT vold )
4521 .LP
4522 .B void
4523 xf_rotvect( FVECT nnew, FVECT nold )
4524 .LP
4525 .B double
4526 xf_scale(
4527 .B double
4528 sold )
4529 .SH
4530 DESCRIPTION
4531 .LP
4532 The
4533 .I xf_xfmpoint
4534 routine applies the current transformation defined by
4535 .I xf_context
4536 to the point
4537 .I pold,
4538 scaling, rotating and moving it to its proper location, which is put in
4539 .I pnew.
4540 (As for
4541 .I xf_xfmvect
4542 and
4543 .I xf_rotvect,
4544 the two arguments may point to the same vector.)\0
4545 .LP
4546 The
4547 .I xf_xfmvect
4548 routine applies the current transformation to the vector
4549 .I vold,
4550 scaling and rotating it to its proper location, which is put in
4551 .I vnew.
4552 The only difference between
4553 .I xf_xfmpoint
4554 and
4555 .I xf_xfmvect
4556 is that in the latter, the final translation is not applied.
4557 .LP
4558 The
4559 .I xf_rotvect
4560 routine rotates the vector
4561 .I nold
4562 using the current transformation, and stores the result in
4563 .I nnew.
4564 No translation or scaling is applied, which is the appropriate
4565 action for surface normal vectors for example.
4566 .LP
4567 The
4568 .I xf_scale
4569 function takes a scalar argument
4570 .I sold
4571 and applies the current scale factor, returning the result.
4572 .SH
4573 SEE ALSO
4574 .LP
4575 xf_handler
4576 .ds LH
4577 .ds RH
4578 .bp
4579 .NH
4580 Application Notes
4581 .NH 2
4582 Relation to Standard Practices in Computer Graphics
4583 .LP
4584 For those coming from a computer graphics background, some of the
4585 choices in the material model may seem strange or even capricious.
4586 Why not simply stick with RGB colors and a Phong specular component
4587 like everyone else?
4588 What is the point in choosing the number of sides to a material?
4589 .LP
4590 In the real world, a surface can have only one side,
4591 defining the interface between one volume and another.
4592 Many object-space rendering packages (e.g. z-buffer algorithms) take
4593 advantage of this fact by culling back-facing polygons and thus saving
4594 as much as 50% of the preprocessing time.
4595 However, many models rely on an
4596 approximation whereby a single surface is used to represent a very thin
4597 volume, such as a pane of glass, and this also can provide significant
4598 calculational savings in an image-space algorithm (such as
4599 ray-tracing).
4600 Also, many models are created in such a way that the front vs. back
4601 information is lost or confused, so that the back side of one or
4602 more surfaces may have to serve as the front side during rendering.
4603 (AutoCAD is one easily identified culprit in this department.)\0
4604 Since both types of surface models are useful and any
4605 rendering algorithm may ultimately be applied, MGF provides a way
4606 to specify sidedness rather than picking one interpretation or the other.
4607 .LP
4608 The problem with RGB is that there is no accepted standard, and even
4609 if we were to set one it would either be impossible to realize (i.e.
4610 impossible to create phosphors with the chosen colors) or it would
4611 have a gamut that excludes many saturated colors.
4612 The CIE color system was very carefully conceived and developed,
4613 and is the standard to which all photometric measurements adhere.
4614 It is therefore the logical choice in any standard format, though it
4615 has been too often ignored by the computer graphics community.
4616 .LP
4617 Regarding Phong shading, this was never a physical model and making it
4618 behave basic laws of reciprocity and energy balance is difficult.
4619 More to the point, specular power has almost nothing to do with
4620 surface microstructure, and is difficult to set properly
4621 even if every physical characteristic of a material has
4622 been carefully measured.
4623 This is the ultimate indictment of any physical model -- that it
4624 is incapable of reproducing any measurement whatsoever.
4625 .LP
4626 Admittedly, the compliment of diffuse and specular component plus
4627 surface roughness and index of refraction used in MGF is less than a
4628 perfect model, but it is serviceable for most materials and
4629 relatively simple to incorporate into a rendering algorithm.
4630 In the long term, MGF shall probably include full spectral
4631 scattering functions, though the sheer quantity of data involved
4632 makes this burdensome from both the measurement side and the
4633 simulation side.
4634 .NH 3
4635 Converting between Phong Specular Power and Gaussian Roughness
4636 .LP
4637 So-called specular reflection and transmission are modeled using a
4638 Gaussian distribution of surface facets.
4639 The roughness parameters to the
4640 .UL rs
4641 and
4642 .UL ts
4643 entities specify
4644 the root-mean-squared (RMS) surface facet slope, which varies from 0
4645 for a perfectly smooth surface to around .2 for a fairly rough one.
4646 The effect this will have on the reflected component distribution is
4647 well-defined, but predicting the behavior of the transmitted
4648 component requires further assumptions.
4649 We assume that the surface
4650 scatters light passing through it just as much as it scatters
4651 reflected light.
4652 This assumption is approximately correct for a
4653 two-sided transparent material with an index of refraction of 1.5
4654 (like glass) and both sides having the given RMS facet slope.
4655 .LP
4656 Oftentimes, one is translating from a Phong exponent on the cosine
4657 of the half-vector-to-normal angle to the more physical but less
4658 familiar Gaussian model of MGF.
4659 The hardest part is translating the specular power to a roughness value.
4660 For this, we recommend the following approximation:
4661 .IP
4662 roughness = sqrt(2/specular_power)
4663 .LP
4664 It is not a perfect correlation, but it is about as close as one can get.
4665 .NH 3
4666 Converting between RGB and CIE Colors
4667 .LP
4668 Unlike most graphics languages, MGF does not use an RGB color model,
4669 simply because there is no recognized definition for this model.
4670 It is based on computer monitor phosphors, which vary from one
4671 CRT to the next.
4672 (There is an RGB standard defined in the TV
4673 industry, but this has a rather poor correlation to most computer
4674 monitors and it is impossible to express many real-world colors
4675 within its limited gamut.)\0
4676 .LP
4677 MGF uses two alternative, well-defined standards, spectral power
4678 distributions and the 1931 CIE 2 degree standard observer.
4679 With the CIE standard, any viewable
4680 color may be exactly represented as an (x,y) chromaticity value.
4681 Unfortunately, the interaction between
4682 colors (i.e. colored light sources and interreflections) cannot be
4683 specified exactly with any finite coordinate set, including CIE
4684 chromaticities.
4685 So, MGF offers the ability to give reflectance,
4686 transmittance or emittance as a function of wavelength over the visible
4687 spectrum.
4688 This function is still discretized, but at a user-selectable
4689 resolution.
4690 Furthermore, spectral colors may be mixed, providing (nearly)
4691 arbitrary basis functions, which can produce more accurate results in
4692 some cases and are merely a convenience for translation in others.
4693 .LP
4694 Conversion back and forth between CIE chromaticity coordinates and spectral
4695 samples is provided within the MGF parser.
4696 Unfortunately, conversion
4697 to and from RGB values depends on a particular RGB definition, and as we
4698 have said, there is no recognized standard.
4699 We therefore recommend that
4700 you decide yourself what chromaticity values to use for each RGB primary,
4701 and adopt the following code to convert between CIE and RGB coordinates.
4702 .LP
4703 .nf
4704 #ifdef NTSC
4705 #define CIE_x_r 0.670 /* standard NTSC primaries */
4706 #define CIE_y_r 0.330
4707 #define CIE_x_g 0.210
4708 #define CIE_y_g 0.710
4709 #define CIE_x_b 0.140
4710 #define CIE_y_b 0.080
4711 #define CIE_x_w 0.3333 /* monitor white point */
4712 #define CIE_y_w 0.3333
4713 #else
4714 #define CIE_x_r 0.640 /* nominal CRT primaries */
4715 #define CIE_y_r 0.330
4716 #define CIE_x_g 0.290
4717 #define CIE_y_g 0.600
4718 #define CIE_x_b 0.150
4719 #define CIE_y_b 0.060
4720 #define CIE_x_w 0.3333 /* monitor white point */
4721 #define CIE_y_w 0.3333
4722 #endif
4723
4724 #define CIE_D ( CIE_x_r*(CIE_y_g - CIE_y_b) + \\
4725 CIE_x_g*(CIE_y_b - CIE_y_r) + \\
4726 CIE_x_b*(CIE_y_r - CIE_y_g) )
4727 #define CIE_C_rD ( (1./CIE_y_w) * \\
4728 ( CIE_x_w*(CIE_y_g - CIE_y_b) - \\
4729 CIE_y_w*(CIE_x_g - CIE_x_b) + \\
4730 CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g ) )
4731 #define CIE_C_gD ( (1./CIE_y_w) * \\
4732 ( CIE_x_w*(CIE_y_b - CIE_y_r) - \\
4733 CIE_y_w*(CIE_x_b - CIE_x_r) - \\
4734 CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r ) )
4735 #define CIE_C_bD ( (1./CIE_y_w) * \\
4736 ( CIE_x_w*(CIE_y_r - CIE_y_g) - \\
4737 CIE_y_w*(CIE_x_r - CIE_x_g) + \\
4738 CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r ) )
4739
4740 #define CIE_rf (CIE_y_r*CIE_C_rD/CIE_D)
4741 #define CIE_gf (CIE_y_g*CIE_C_gD/CIE_D)
4742 #define CIE_bf (CIE_y_b*CIE_C_bD/CIE_D)
4743
4744 float xyz2rgbmat[3][3] = { /* XYZ to RGB */
4745 {(CIE_y_g - CIE_y_b - CIE_x_b*CIE_y_g + CIE_y_b*CIE_x_g)/CIE_C_rD,
4746 (CIE_x_b - CIE_x_g - CIE_x_b*CIE_y_g + CIE_x_g*CIE_y_b)/CIE_C_rD,
4747 (CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g)/CIE_C_rD},
4748 {(CIE_y_b - CIE_y_r - CIE_y_b*CIE_x_r + CIE_y_r*CIE_x_b)/CIE_C_gD,
4749 (CIE_x_r - CIE_x_b - CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r)/CIE_C_gD,
4750 (CIE_x_b*CIE_y_r - CIE_x_r*CIE_y_b)/CIE_C_gD},
4751 {(CIE_y_r - CIE_y_g - CIE_y_r*CIE_x_g + CIE_y_g*CIE_x_r)/CIE_C_bD,
4752 (CIE_x_g - CIE_x_r - CIE_x_g*CIE_y_r + CIE_x_r*CIE_y_g)/CIE_C_bD,
4753 (CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r)/CIE_C_bD}
4754 };
4755
4756 float rgb2xyzmat[3][3] = { /* RGB to XYZ */
4757 {CIE_x_r*CIE_C_rD/CIE_D,CIE_x_g*CIE_C_gD/CIE_D,CIE_x_b*CIE_C_bD/CIE_D},
4758 {CIE_y_r*CIE_C_rD/CIE_D,CIE_y_g*CIE_C_gD/CIE_D,CIE_y_b*CIE_C_bD/CIE_D},
4759 {(1.-CIE_x_r-CIE_y_r)*CIE_C_rD/CIE_D,
4760 (1.-CIE_x_g-CIE_y_g)*CIE_C_gD/CIE_D,
4761 (1.-CIE_x_b-CIE_y_b)*CIE_C_bD/CIE_D}
4762 };
4763
4764
4765 cie_rgb(rgbcolor, ciecolor) /* convert CIE to RGB */
4766 register float *rgbcolor, *ciecolor;
4767 {
4768 register int i;
4769
4770 for (i = 0; i < 3; i++) {
4771 rgbcolor[i] = xyz2rgbmat[i][0]*ciecolor[0] +
4772 xyz2rgbmat[i][1]*ciecolor[1] +
4773 xyz2rgbmat[i][2]*ciecolor[2] ;
4774 if (rgbcolor[i] < 0.0) /* watch for negative values */
4775 rgbcolor[i] = 0.0;
4776 }
4777 }
4778
4779
4780 rgb_cie(ciecolor, rgbcolor) /* convert RGB to CIE */
4781 register float *ciecolor, *rgbcolor;
4782 {
4783 register int i;
4784
4785 for (i = 0; i < 3; i++)
4786 ciecolor[i] = rgb2xyzmat[i][0]*rgbcolor[0] +
4787 rgb2xyzmat[i][1]*rgbcolor[1] +
4788 rgb2xyzmat[i][2]*rgbcolor[2] ;
4789 }
4790 .fi
4791 .LP
4792 An alternative to adopting the above code is to use the MGF "cmix"
4793 entity to convert from RGB directly by naming the three primaries in
4794 terms of their chromaticities, e.g:
4795 .DS
4796 c R =
4797 cxy 0.640 0.330
4798 c G =
4799 cxy 0.290 0.600
4800 c B =
4801 cxy 0.150 0.060
4802 .DE
4803 .LP
4804 Then, converting from RGB to MGF colors is as simple as multiplying each
4805 component by its relative luminance in a cmix statement, for instance:
4806 .DS
4807 c white =
4808 cmix 0.265 R 0.670 G 0.065 B
4809 .DE
4810 .LP
4811 For the chosen RGB standard, the above specification would result a pure
4812 white.
4813 The reason the coefficients are not all 1 as you might expect is
4814 that cmix uses relative luminance as the standard for its weights.
4815 Since
4816 blue is less luminous for the same energy than red, which is in turn
4817 less luminous than green, the weights cannot be the same to achieve an
4818 even spectral balance.
4819 Unfortunately, computing these relative weights
4820 is not straightforward, though it is given in the above macros as CIE_rf,
4821 CIE_gf and CIE_bf.
4822 (The common factors in these macros may of course
4823 be removed since
4824 .UL cmix
4825 weights are all relative.)\0
4826 Alternatively, one could measure the actual full scale luminance of
4827 the phosphors with a luminance probe and get the same relative
4828 values.
4829 .NH 2
4830 Relation to IESNA LM-63 and Luminaire Catalogs
4831 .LP
4832 Recently, the Illuminating Engineering Society of North America
4833 (IESNA) adopted MGF as the official standard for
4834 representing luminaire geometry and materials.
4835 The way this works in an IES luminaire data file is through the
4836 addition of a keyword called LUMINOUSGEOMETRY, which is given on a
4837 line in the header portion of a file (before the TILT specification)
4838 like so:
4839 .LP
4840 .B [LUMINOUSGEOMETRY]
4841 .I mgf_file
4842 .LP
4843 The given MGF file must exist relative to the directory containing
4844 the IES file (i.e. the same stipulations and restrictions on pathnames
4845 apply as for the MGF
4846 .UL i
4847 entity).
4848 Furthermore, the position of the MGF geometry must be
4849 such that the gross geometric specification of emitting surfaces
4850 in the IES file completely
4851 blocks or encloses the luminous portions of the MGF description.
4852 Specifically, any ray traced towards the MGF geometry must strike
4853 the IES gross geometry before it strikes any luminous surface in the
4854 MGF description.
4855 This provides a convenient way of preventing overcounting in the
4856 illumination calculation, while still allowing for accurate fixture
4857 appearance.
4858 .LP
4859 To give two examples, let us consider first a recessed can, followed
4860 by a hanging direct/indirect fluorescent fixture.
4861 .LP
4862 The most appropriate IES geometric specification for the emitting
4863 area of a can light would be a circular disk.
4864 Since the IES gross geometry gives only the diameter of the disk, the
4865 actual 3-dimensional placement is implicitly defined as having a
4866 center at the origin, with the radiating disk facing in the
4867 negative Z direction (nadir, downwards).
4868 The MGF geometry would then be placed such that any luminous portion
4869 was above this disk, and no portion of it would obstruct the IES
4870 geometry.
4871 The most sensible position therefore has the IES disk flush with the
4872 MGF can opening, as shown in Figure 3.
4873 .bp
4874 Replace this page with the second page from "figures.ps".
4875 .bp
4876 .LP
4877 In the case of a direct/indirect fluorescent fixture, light will
4878 exit both the top and the bottom sides, and the IES geometry must
4879 enclose the radiating portion of the fixture entirely.
4880 It is acceptable to have additional MGF geometry above the
4881 fixture so long as it does not radiate, which is what we must do if
4882 we wish to include the support rods, as shown in Figure 4.
4883 .LP
4884 Note that the origin is always in the exact center of the IES
4885 geometry.
4886 .LP
4887 Not all fixtures will fit the simple IES geometry specification so
4888 nicely.
4889 For odd-shaped fixtures, it may be necessary to use an IES geometry
4890 that does not match the radiating area terribly well in order that
4891 it completely block or enclose the required MGF specification.
4892 .LP
4893 The unit of length in the MGF file is always meters, regardless of
4894 the units specified in the enclosing IES file.
4895 However, any and all multipliers applied to the candlepower data in the
4896 IES file will also be applied to the emittance of surfaces in the
4897 MGF specification, so that one MGF file may serve similar
4898 luminaires that differ in their total output.
4899 .NH
4900 Credits
4901 .LP
4902 The MGF language grew out of a joint investigation into physical
4903 representations for rendering undertaken by the author
4904 (Greg Ward of LBL) and Holly Rushmeier of the National
4905 Institute of Standards and Technology.
4906 After deciding that a complete and robust specification was
4907 an extreme challenge, we shelved the project for another time.
4908 A few months later, the author spoke with Ian Ashdown and Robert
4909 Shakespeare, who are both members of the IES Computing Committee,
4910 about the need for extending the existing data standard to
4911 include luminaire geometry and near-field photometry.
4912 We then moved forward as a team towards a somewhat less ambitious
4913 approach to physical materials and geometry that had the advantage
4914 of simplicity and the possibility of support with a standard parser
4915 library.
4916 The author went to work over the next two months
4917 on the detailed design of the language
4918 and an ANSI-C parser, with regular feedback from the other three
4919 team members.
4920 Several months and several versions later, we arrived at release
4921 1.0, which is the occasion of this document's creation.
4922 .LP
4923 Funding for this work... would be nice.