00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
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     
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     
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     
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 }