| 1 |
greg |
2.1 |
#ifndef lint
|
| 2 |
greg |
2.9 |
static const char RCSid[] = "$Id: m_alias.c,v 2.8 2018/01/09 05:01:15 greg Exp $";
|
| 3 |
greg |
2.1 |
#endif
|
| 4 |
|
|
/*
|
| 5 |
|
|
* Handler for modifier alias
|
| 6 |
|
|
*/
|
| 7 |
|
|
|
| 8 |
|
|
#include "copyright.h"
|
| 9 |
schorsch |
2.5 |
|
| 10 |
greg |
2.1 |
#include "ray.h"
|
| 11 |
|
|
#include "otypes.h"
|
| 12 |
schorsch |
2.5 |
#include "rtotypes.h"
|
| 13 |
greg |
2.1 |
#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 |
greg |
2.7 |
int
|
| 27 |
schorsch |
2.5 |
m_alias( /* transfer shading to alias target */
|
| 28 |
|
|
OBJREC *m,
|
| 29 |
|
|
RAY *r
|
| 30 |
|
|
)
|
| 31 |
greg |
2.1 |
{
|
| 32 |
|
|
OBJECT aobj;
|
| 33 |
greg |
2.4 |
OBJREC *aop;
|
| 34 |
greg |
2.1 |
OBJREC arec;
|
| 35 |
greg |
2.4 |
int rval;
|
| 36 |
greg |
2.1 |
/* 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 |
greg |
2.6 |
aop = m;
|
| 43 |
|
|
aobj = objndx(aop);
|
| 44 |
|
|
do { /* follow alias trail */
|
| 45 |
|
|
if (aop->oargs.nsargs == 1)
|
| 46 |
|
|
aobj = lastmod(aobj, aop->oargs.sarg[0]);
|
| 47 |
|
|
else
|
| 48 |
|
|
aobj = aop->omod;
|
| 49 |
|
|
if (aobj < 0)
|
| 50 |
|
|
objerror(aop, USER, "bad reference");
|
| 51 |
|
|
aop = objptr(aobj);
|
| 52 |
|
|
} while (aop->otype == MOD_ALIAS);
|
| 53 |
|
|
/* copy struct */
|
| 54 |
greg |
2.4 |
arec = *aop;
|
| 55 |
greg |
2.1 |
/* irradiance hack */
|
| 56 |
|
|
if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS)) &&
|
| 57 |
greg |
2.9 |
(ofun[arec.otype].flags & (T_M|T_X)) &&
|
| 58 |
|
|
arec.otype != MAT_CLIP) {
|
| 59 |
|
|
if (istransp(arec.otype) || isBSDFproxy(&arec)) {
|
| 60 |
greg |
2.1 |
raytrans(r);
|
| 61 |
|
|
return(1);
|
| 62 |
|
|
}
|
| 63 |
|
|
if (!islight(arec.otype))
|
| 64 |
|
|
return((*ofun[Lamb.otype].funp)(&Lamb, r));
|
| 65 |
|
|
}
|
| 66 |
|
|
/* substitute modifier */
|
| 67 |
|
|
arec.omod = m->omod;
|
| 68 |
|
|
/* replacement shader */
|
| 69 |
greg |
2.4 |
rval = (*ofun[arec.otype].funp)(&arec, r);
|
| 70 |
|
|
/* save allocated struct */
|
| 71 |
|
|
if (arec.os != aop->os) {
|
| 72 |
|
|
if (aop->os != NULL) /* should never happen */
|
| 73 |
|
|
free_os(aop);
|
| 74 |
|
|
aop->os = arec.os;
|
| 75 |
|
|
}
|
| 76 |
|
|
return(rval);
|
| 77 |
greg |
2.1 |
}
|