1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: m_alias.c,v 2.4 2004/01/20 22:16:53 greg Exp $"; |
3 |
#endif |
4 |
/* |
5 |
* Handler for modifier alias |
6 |
*/ |
7 |
|
8 |
#include "copyright.h" |
9 |
|
10 |
#include "ray.h" |
11 |
#include "otypes.h" |
12 |
#include "rtotypes.h" |
13 |
#include "otspecial.h" |
14 |
|
15 |
/* |
16 |
* If the alias has a single string argument, it's the |
17 |
* name of the target modifier, and we must substitute the |
18 |
* target and its arguments in place of this alias. The |
19 |
* only difference is that we use our modifier rather than |
20 |
* theirs. |
21 |
* If the alias has no string arguments, then we simply |
22 |
* pass through to our modifier as if we weren't in the |
23 |
* chain at all. |
24 |
*/ |
25 |
|
26 |
extern int |
27 |
m_alias( /* transfer shading to alias target */ |
28 |
OBJREC *m, |
29 |
RAY *r |
30 |
) |
31 |
{ |
32 |
OBJECT aobj; |
33 |
OBJREC *aop; |
34 |
OBJREC arec; |
35 |
int rval; |
36 |
/* straight replacement? */ |
37 |
if (!m->oargs.nsargs) |
38 |
return(rayshade(r, m->omod)); |
39 |
/* else replace alias */ |
40 |
if (m->oargs.nsargs != 1) |
41 |
objerror(m, INTERNAL, "bad # string arguments"); |
42 |
aobj = lastmod(objndx(m), m->oargs.sarg[0]); |
43 |
if (aobj < 0) |
44 |
objerror(m, USER, "bad reference"); |
45 |
aop = objptr(aobj); |
46 |
arec = *aop; |
47 |
/* irradiance hack */ |
48 |
if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS)) && |
49 |
m->otype != MAT_CLIP && |
50 |
(ofun[arec.otype].flags & (T_M|T_X))) { |
51 |
if (irr_ignore(arec.otype)) { |
52 |
raytrans(r); |
53 |
return(1); |
54 |
} |
55 |
if (!islight(arec.otype)) |
56 |
return((*ofun[Lamb.otype].funp)(&Lamb, r)); |
57 |
} |
58 |
/* substitute modifier */ |
59 |
arec.omod = m->omod; |
60 |
/* replacement shader */ |
61 |
rval = (*ofun[arec.otype].funp)(&arec, r); |
62 |
/* save allocated struct */ |
63 |
if (arec.os != aop->os) { |
64 |
if (aop->os != NULL) /* should never happen */ |
65 |
free_os(aop); |
66 |
aop->os = arec.os; |
67 |
} |
68 |
return(rval); |
69 |
} |