Back to index

radiance  4R0+20100331
m_alias.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char RCSid[] = "$Id: m_alias.c,v 2.6 2006/07/12 05:47:05 greg Exp $";
00003 #endif
00004 /*
00005  * Handler for modifier alias
00006  */
00007 
00008 #include "copyright.h"
00009 
00010 #include "ray.h"
00011 #include "otypes.h"
00012 #include "rtotypes.h"
00013 #include "otspecial.h"
00014 
00015 /*
00016  *     If the alias has a single string argument, it's the
00017  *  name of the target modifier, and we must substitute the
00018  *  target and its arguments in place of this alias.  The
00019  *  only difference is that we use our modifier rather than
00020  *  theirs.
00021  *     If the alias has no string arguments, then we simply
00022  *  pass through to our modifier as if we weren't in the
00023  *  chain at all.
00024  */
00025 
00026 extern int
00027 m_alias(                    /* transfer shading to alias target */
00028        OBJREC *m,
00029        RAY    *r
00030 )
00031 {
00032        OBJECT aobj;
00033        OBJREC *aop;
00034        OBJREC arec;
00035        int    rval;
00036                                    /* straight replacement? */
00037        if (!m->oargs.nsargs)
00038               return(rayshade(r, m->omod));
00039                                    /* else replace alias */
00040        if (m->oargs.nsargs != 1)
00041               objerror(m, INTERNAL, "bad # string arguments");
00042        aop = m;
00043        aobj = objndx(aop);
00044        do {                        /* follow alias trail */
00045               if (aop->oargs.nsargs == 1)
00046                      aobj = lastmod(aobj, aop->oargs.sarg[0]);
00047               else
00048                      aobj = aop->omod;
00049               if (aobj < 0)
00050                      objerror(aop, USER, "bad reference");
00051               aop = objptr(aobj);
00052        } while (aop->otype == MOD_ALIAS);
00053                                    /* copy struct */
00054        arec = *aop;
00055                                    /* irradiance hack */
00056        if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS)) &&
00057                      m->otype != MAT_CLIP &&
00058                      (ofun[arec.otype].flags & (T_M|T_X))) {
00059               if (irr_ignore(arec.otype)) {
00060                      raytrans(r);
00061                      return(1);
00062               }
00063               if (!islight(arec.otype))
00064                      return((*ofun[Lamb.otype].funp)(&Lamb, r));
00065        }
00066                                    /* substitute modifier */
00067        arec.omod = m->omod;
00068                                    /* replacement shader */
00069        rval = (*ofun[arec.otype].funp)(&arec, r);
00070                                    /* save allocated struct */
00071        if (arec.os != aop->os) {
00072               if (aop->os != NULL) /* should never happen */
00073                      free_os(aop);
00074               aop->os = arec.os;
00075        }
00076        return(rval);
00077 }