changing a model's color at runtime

New Message Reply Date view Thread view Subject view Author view

From: Paul Duncan (paulduncan++at++thehfegroup.com)
Date: 02/19/2001 12:49:15


Hi,

I'm reposting this since I didn't get any responses last time and I haven't
found a solution yet.

I'm modifying the color of models at runtime by traversing through the model
tree until I get to a node (ofGeodeClassType) and then setting the
node(Geode) to the color I want.
This works fine for simple models, but for more complex ones with multiple
LOD's and such the behavior is odd. Some models have one LOD of many
modified, others all but one and others cause it to crash.

The code looks like this:

void modifyModelColor(pfNode *node, float brightLevel)
{
        int i, k, j;

        if (pfIsOfType(node, pfGetGroupClassType()))
        {
                for ( i=0; i<(pfGetNumChildren(node)); ++i)
                {
                        modifyModelColor(pfGetChild((pfGroup *)node,i), brightLevel);
                }
        }

        if (pfIsOfType(node, pfGetGeodeClassType()))
        {
                for ( j=0; j < pfGetNumGSets(node); ++j)
                {
                        pfGeoSet *gset;
                        pfVec4 *colors;
                        ushort *icolors;
                        int numcolors = pfGetSize(colors)/sizeof(pfVec4);

                        gset = pfGetGSet((pfGeode *)node, j);
                        pfGetGSetAttrLists(gset, PFGS_COLOR4, (void **)&colors, &icolors);

                        for (k=0; k<numcolors; ++k)
                        {
                                /* Here we modify the color element of each
                                         vertex that we encounter */

                                colors[k][0] = brightLevel;
                                colors[k][1] = brightLevel;
                                colors[k][2] = brightLevel;

                        }
                }
        }
}

Is this a feasible way of doing this?
Do I have to set the traversal mode?
What am I doing wrong?

Any help would be appreciated.

Thanks Paul

Paul Duncan
The HFE Group
220 Laurier Ave. W, Suite 350
(613) 230-8226
paulduncan++at++thehfegroup.com


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Mon Feb 19 2001 - 12:54:23 PST

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