Example #1
0
Action::ResultE changeGeo(NodePtr& node)
{   
    GeometryPtr geo = GeometryPtr::dcast(node->getCore());
    
    if(geo == NullFC)
        return Action::Continue;


    GeoColors3fPtr colors = GeoColors3fPtr::dcast(geo->getColors());
    if(colors == NullFC)
    {
        colors = GeoColors3f::create();

        colors->resize(geo->getPositions()->getSize());
        
        // Change the geometry to use the new colors
        beginEditCP(geo, Geometry::ColorsFieldMask);
            geo->setColors(colors);
            // If multi-indexed, make the colors use the same index as
            // the geometry
            if(geo->getMFIndexMapping()->size() > 0)
            {
                Int16 pind = geo->calcMappingIndex(Geometry::MapPosition);
                
                if(pind < 0)
                {
                    FFATAL(("Multi-indexed, but no positions index???\n"));
                    return Action::Continue; 
                }
                
                // This makes the colors use the same indices as the positions
                geo->editIndexMapping(pind) |= Geometry::MapColor;
            }
        endEditCP  (geo, Geometry::ColorsFieldMask);
    }
    

    beginEditCP(geo, Geometry::ColorsFieldMask);
    beginEditCP(colors);
    Real32 size = colors->getSize();
    for(UInt32 i=0;i<size;++i)
    {
        Color3f c;
        c[0] = ((Real32) i) / size;
        c[1] = 0.0f;
        c[2] = 0.0f;
        colors->setValue(c, i);
    }
    endEditCP(colors);
    endEditCP(geo, Geometry::ColorsFieldMask);
    
    return Action::Continue; 
}