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