SkinWeightsToVertColsPrimFunc.cpp

Go to the documentation of this file.
00001 // Copyright (C) 2005 Dave Griffiths
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 
00017 #include "SkinWeightsToVertColsPrimFunc.h"
00018 #include "Primitive.h"
00019 #include "SceneGraph.h"
00020 
00021 using namespace Fluxus;
00022 
00023 SkinWeightsToVertColsPrimFunc::SkinWeightsToVertColsPrimFunc()
00024 {
00025 }
00026 
00027 SkinWeightsToVertColsPrimFunc::~SkinWeightsToVertColsPrimFunc()
00028 {
00029 }
00030 
00031 void SkinWeightsToVertColsPrimFunc::Run(Primitive &prim, const SceneGraph &world)
00032 {
00033     // find out how many sets of weights there are
00034     bool found=true;
00035     unsigned int numbones=0;
00036     unsigned int size=0;
00037     char wname[256];
00038     char type=0;
00039     
00040     while(found)
00041     {
00042         snprintf(wname,256,"w%d",numbones);
00043         found=prim.GetDataInfo(wname, type, size);
00044         if (found) numbones++;
00045     }
00046     
00047     // make some random colours
00048     vector<dColour> colours;
00049     for (unsigned int bone=0; bone<numbones; bone++)
00050     {
00051         colours.push_back(dColour(RandFloat(),RandFloat(),RandFloat()));
00052     }
00053     
00054     // get pointers to all the weights
00055     vector<vector<float>*> weights;
00056     for (unsigned int bone=0; bone<numbones; bone++)
00057     {
00058         snprintf(wname,256,"w%d",bone);
00059         weights.push_back(prim.GetDataVec<float>(wname));
00060     }
00061     
00062     for (unsigned int n=0; n<prim.Size(); n++)
00063     {
00064         dColour col;
00065         for (unsigned int bone=0; bone<numbones; bone++)
00066         {
00067             col+=colours[bone]*(*weights[bone])[n];
00068         }
00070         prim.SetData("c", n, col);
00071     }
00072     
00073 }

Generated on Tue Sep 4 23:22:18 2007 for The Fluxus Renderer (libfluxus) by  doxygen 1.5.1