--- ray/src/rt/m_alias.c 2003/09/09 03:28:43 2.3 +++ ray/src/rt/m_alias.c 2006/07/12 05:47:05 2.6 @@ -1,13 +1,15 @@ #ifndef lint -static const char RCSid[] = "$Id: m_alias.c,v 2.3 2003/09/09 03:28:43 greg Exp $"; +static const char RCSid[] = "$Id: m_alias.c,v 2.6 2006/07/12 05:47:05 greg Exp $"; #endif /* * Handler for modifier alias */ #include "copyright.h" + #include "ray.h" #include "otypes.h" +#include "rtotypes.h" #include "otspecial.h" /* @@ -21,23 +23,35 @@ static const char RCSid[] = "$Id: m_alias.c,v 2.3 2003 * chain at all. */ -int -m_alias(m, r) /* transfer shading to alias target */ -OBJREC *m; -RAY *r; +extern int +m_alias( /* transfer shading to alias target */ + OBJREC *m, + RAY *r +) { OBJECT aobj; + OBJREC *aop; OBJREC arec; + int rval; /* straight replacement? */ if (!m->oargs.nsargs) return(rayshade(r, m->omod)); /* else replace alias */ if (m->oargs.nsargs != 1) objerror(m, INTERNAL, "bad # string arguments"); - aobj = lastmod(objndx(m), m->oargs.sarg[0]); - if (aobj < 0) - objerror(m, USER, "bad reference"); - arec = *objptr(aobj); + aop = m; + aobj = objndx(aop); + do { /* follow alias trail */ + if (aop->oargs.nsargs == 1) + aobj = lastmod(aobj, aop->oargs.sarg[0]); + else + aobj = aop->omod; + if (aobj < 0) + objerror(aop, USER, "bad reference"); + aop = objptr(aobj); + } while (aop->otype == MOD_ALIAS); + /* copy struct */ + arec = *aop; /* irradiance hack */ if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS)) && m->otype != MAT_CLIP && @@ -52,5 +66,12 @@ RAY *r; /* substitute modifier */ arec.omod = m->omod; /* replacement shader */ - return((*ofun[arec.otype].funp)(&arec, r)); + rval = (*ofun[arec.otype].funp)(&arec, r); + /* save allocated struct */ + if (arec.os != aop->os) { + if (aop->os != NULL) /* should never happen */ + free_os(aop); + aop->os = arec.os; + } + return(rval); }