Re: Material tables with .fl

New Message Reply Date view Thread view Subject view Author view

Eric S. Hirschorn (erich++at++pike.cecer.army.mil)
Sat, 12 Aug 1995 12:44:52 -0500 (CDT)


Marcus,

Thank you for responding to my previous post.

> >3) Grab pointers to pfMaterials from a *pfGeode , i.e.
> >
> > mtl = pfNewMtl(NULL);
>
> Creating a new material here is unneccesary. This code snippet
> is actually a memory leak.

Why is this a memory leak? Would the leak be prevented if the
material is created in shared memory using pfGetSharedArena?

[...much deleted...]
> In order for
> you to do what you want, you'll need to create and reference
> unique materials for each polygon in the database. As a
> run-time hack you must traverse each geoset of interest
> and create a copy of its geostate, bind a new material to the
> copy, and then bind the new (copied) geostate to the geoset.
>
> Having done all this ... you will gain control of materials on
> a per geoset level at the expense of draw performance.

Ok, I'll try this out. Can pfCopy be used to make a copy of the geostate?
I wonder if pfCopy will not make a true copy but will keep references to
the original material.

My second stab at this problem, using pre- and post- draw callbacks,
turns out not to work as well as I reported previously. The EMISSION
properties are changed for the one object without changing other
objects. However, there is no affect on the other material properties
AMBIENT, DIFFUSE, and SPECULAR. This behavior is also the same for
Inventor objects.

------------------------------------

            /* read in file */
            root = (pfGroup *)LoadFile(DatabaseFiles[i], NULL);

            /* grab pointer to shared memory */
            arena = pfGetSharedArena();
            /* define new material in shared memory */
            planeMtl = pfNewMtl(arena);

            /* modify material */
            pfMtlColor(planeMtl, PFMTL_EMISSION, 0.0f, 0.1f, 0.0f);
            pfMtlColor(planeMtl, PFMTL_AMBIENT, 0.3f, 0.0f, 0.3f);
            pfMtlColor(planeMtl, PFMTL_DIFFUSE, 0.6f, 0.0f, 0.6f);
            pfMtlColor(planeMtl, PFMTL_SPECULAR, 0.2f, 0.2f, 0.2f);

            /* set up pre- and post- draw callbacks */
            pfNodeTravFuncs((pfNode *)root, PFTRAV_DRAW,
                            planePreCallback, planePostCallback);
            /* pass material planeMtl into the draw callbacks */
            pfNodeTravData((pfNode *)root, PFTRAV_DRAW, (void *)planeMtl);

------------------------------------

and the draw callbacks:

/* Change material properties just before drawing */
long
planePreCallback(pfTraverser *trav, void *data)
{

  pfPushState();

  pfApplyMtl((pfMaterial *)data);
  pfOverride(PFSTATE_FRONTMTL, PF_ON);
   
  return PFTRAV_CONT;
}

/*
   Reset material properties after the draw
   so no other object is affected
*/
long
planePostCallback(pfTraverser *trav, void *data)
{
  pfOverride(PFSTATE_FRONTMTL, PF_OFF);

  pfPopState();

  return PFTRAV_CONT;
}

-----------------------------------------

Comments on this (by anyone) would be appreciated.

Eric
____________________________________________________________________
Eric S. Hirschorn, USACERL VE Group EMAIL: erich++at++pike.cecer.army.mil
TEL: (800) USA-CERL ext. 6363 or 7528, FAX: (217) 373-6724


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:51:47 PDT

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