home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / mg / ri / mgrimesh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-06  |  3.0 KB  |  131 lines

  1. #include "mgP.h"
  2. #include "mgriP.h"
  3.  
  4. int
  5. mgri_mesh( wrap, nu, nv, P, N, C)
  6.     int wrap;
  7.     int nu, nv;
  8.     HPoint3 *P;
  9.     Point3 *N;
  10.     ColorA *C;
  11. {
  12.     register Appearance *ap;
  13.     ColorA    *c;
  14.     Color   *c3;
  15.     Point3  *n;
  16.     void    mgri_submesh();
  17.     int u,v;
  18.  
  19.     ap = &_mgc->astk->ap;
  20.  
  21.     if(ap->flag & APF_FACEDRAW) {
  22.     mgri_submesh( wrap, nu, nv, P, N, C);
  23.     }
  24.     
  25.     if(ap->flag & APF_EDGEDRAW) {
  26.         RiAttributeBegin();
  27.     RiGeometricRepresentation("lines");
  28.     mgri_closer();
  29.     c3 = &ap->mat->edgecolor;
  30.     RiColor((float *)c3);
  31.     mgri_submesh( wrap, nu, nv, P, N, C);
  32.     RiAttributeEnd();
  33.     }
  34.     
  35.     if((ap->flag & APF_NORMALDRAW) && N!=NULL) {
  36.     Color *color = &_mgc->astk->mat.normalcolor;
  37.     n = N;
  38.     RiAttributeBegin();
  39.     RiSurface(RI_CONSTANT, RI_NULL);
  40.     RiColor((float *)color);
  41.     for(u=0; u<nu; u++) {
  42.         for(v=0; v<nv; v++) {
  43.             mgri_drawnormal(&P[u + v * nu], &N[u + v * nu], color);
  44.         }
  45.     }
  46.     RiAttributeEnd();
  47.     }
  48.     
  49.     return 1;
  50. }
  51.  
  52. void
  53. mgri_submesh( wrap, nu, nv, P, N, C)
  54.     int wrap;
  55.     int nu, nv;
  56.     HPoint3 *P;
  57.     Point3 *N;
  58.     ColorA *C;
  59. {
  60.     register Appearance *ap;
  61.     char    *uwrap,*vwrap;
  62.     int     shading;
  63.     int     i;
  64.     register HPoint3 *p;
  65.     register Point3  *n;
  66.     register ColorA    *c;
  67.     int     nunv;
  68.     float   alpha;
  69.     int colorsdefined;
  70.     int normalsdefined;
  71.  
  72.     /* Ignore colors if overridden */
  73.     if((_mgc->astk->mat.override & MTF_DIFFUSE) && !_mgc->astk->useshader)
  74.     C = NULL;
  75.  
  76.     nunv = nu * nv;
  77.     p = P;
  78.     n = N;
  79.     c = C;
  80.         
  81.     ap = &_mgc->astk->ap;
  82.     
  83.     if(wrap & MM_UWRAP) uwrap = RI_PERIODIC;
  84.     else uwrap = RI_NONPERIODIC;
  85.     
  86.     if(wrap & MM_VWRAP) vwrap = RI_PERIODIC;
  87.     else vwrap = RI_NONPERIODIC;
  88.     
  89.     RiAttributeBegin(); // IS THIS NECESSARY!?
  90.  
  91.     /* Points */
  92.     /* NOTES: Check to see if we can use Pw here!! */
  93.     for(i=0; i<nunv; i++, p++) {
  94.         mgri_normalize(p, ript[i]);
  95.     }
  96.     
  97.     /* use normals if supplied */
  98.     if(N!=NULL) {
  99.     for(i=0; i<nunv; i++, n++) {
  100.         bcopy((char *)n, (char *)rinormal[i], sizeof(float)*3);
  101.     }
  102.     normalsdefined=1;
  103.     } else normalsdefined=0;
  104.     
  105.     /* use colors if supplied */
  106.     if(C!=NULL) {
  107.     for(i=0; i<nunv; i++, c++) {
  108.         //bcopy((char *)c, (char *)ricolor[i], sizeof(float)*3);
  109.         *(Color *)&ricolor[i] = *(Color *)c;
  110.     }
  111.     colorsdefined=1;
  112.     } else colorsdefined=0;
  113.     
  114.     /* No Opacity in QuickRenderman */
  115.  
  116.     /* Define mesh via the renderman interface */
  117.     if(!colorsdefined && normalsdefined)
  118.     RiPatchMesh( RI_BILINEAR, nu, uwrap, nv, vwrap, RI_P, (RtPointer)ript,
  119.         RI_N, (RtPointer)rinormal, RI_NULL);
  120.     else if(colorsdefined && !normalsdefined)
  121.     RiPatchMesh( RI_BILINEAR, nu, uwrap, nv, vwrap, RI_P, (RtPointer)ript,
  122.         RI_CS, (RtPointer)ricolor, RI_NULL);
  123.     else if(!colorsdefined && !normalsdefined)
  124.     RiPatchMesh( RI_BILINEAR, nu, uwrap, nv, vwrap, RI_P, (RtPointer)ript,
  125.         RI_NULL);
  126.     else RiPatchMesh( RI_BILINEAR, nu, uwrap, nv, vwrap, RI_P, (RtPointer)ript,
  127.             RI_CS, (RtPointer)ricolor, RI_N, (RtPointer)rinormal, RI_NULL);
  128.  
  129.     RiAttributeEnd();
  130. }
  131.