Coloring Models in Performer

New Message Reply Date view Thread view Subject view Author view

Curtis L. Goodhart (goodhart++at++cod.nosc.mil)
Wed, 15 Jun 94 14:28:26 PDT


I am using perfly to implement a specific type of object selection
algorithm. I want to be able to change the color of some model
dynamically. For example at some given time I want to change the
color of the geometry under node X to red. Currently I think that
node X is a DCS.

The data files that I've tried this with are flt format files,
obj files, and iv files.

When I do what follows below all that happens is that the model turns
grey instead of the desired color.

1) Let's say I load 4 data files (4 separate objects) such as
   4 enterprise.flt files.
   ie:
    
   perfly enterprise.flt enterprise.flt enterprise.flt enterprise.flt

c) My SW selects one of those objects (models) and attempts to change
   its color. I do this in a node call back function during
   the draw traversal.

   So I execute the following when I am reading in the model files.
   ptrToNode is a pointer to the node that gets set up when perfly
   loads a file.

   int mydata;
   pfNodeTravFuncs(ptrToNode, PFTRAV_DRAW, clgpreDraw, clgpostDraw);
   pfNodeTravData(ptrToNode, PFTRAV_DRAW, &mydata);

   In the preDraw function I intend to color the object red
   when test is set:

   long
   clgpreDraw(pfTraverser *trav, void *data)
{
   int test;
   static int firsttime = 0;
   static pfMaterial *ahaPreselectMtl;

   /* Please forgive this hack of setting the material here
    * I intend to move it to an initialization file when I
    * get things working.
    */
   if (!firsttime)
   {
      firsttime = 1;
      ahaPreselectMtl = pfNewMtl(NULL);
   }

   test = *(int *) data;
   if (test)
   {
      pfPushState();
      pfMtlColorMode(ahaPreselectMtl, PFMTL_BOTH, LMC_CMODE_COLOR);

/* I also tried it with the following statement included - nodifference
 * pfMtlColorMode(ahaPreselectMtl, PFMTL_BOTH, LMC_AD);
 */
      pfMtlColor(ahaPreselectMtl, PFMTL_DIFFUSE, 1.0, 0.0, 0.0);
      pfOverride(PFSTATE_FRONTMTL | PFSTATE_BACKMTL, PF_ON);
      pfApplyMtl(ahaPreselectMtl);
   }
   return PFTRAV_CONT;
}

The postDraw function to restore the state is:

long
clgpostDraw(pfTraverser *trav, void *data)
{
   int test;

   test = *(int *)data;

   if (test)
   {
      pfOverride(PFSTATE_FRONTMTL | PFSTATE_BACKMTL, PF_OFF);
      pfPopState();
   }
   return PFTRAV_CONT;
}

The idea is that whenever test is 1 I want to change the color
of that object to red.

When I use what I show you above the material of the selected
object becomes gray rather than red.

This code seems to work ok when I change the selected object to
wireframe rather than coloring the object red (ie I just do a
pfEnable(PFEN_WIREFRAME) in the preDraw, and a
pfDisable(PFEN_WIREFRAME) in the postDraw.

3) We are running on an Onyx running IRIX 5.2 and using
Performer 1.2.

Thank you,

     Curt Goodhart


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:50:20 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.