Implemented per-vertex colors for VRML2 and SGNODE

This commit is contained in:
Cirilo Bernardo 2016-01-06 16:15:54 +11:00
parent 6b873ed46b
commit 6f309a46c9
5 changed files with 13 additions and 7 deletions

View File

@ -131,7 +131,7 @@ bool SGCOLORS::AddChildNode( SGNODE* aNode )
bool SGCOLORS::GetColorList( size_t& aListSize, SGCOLOR*& aColorList )
{
if( colors.size() )
if( colors.empty() )
{
aListSize = 0;
aColorList = NULL;
@ -144,7 +144,7 @@ bool SGCOLORS::GetColorList( size_t& aListSize, SGCOLOR*& aColorList )
}
void SGCOLORS::SetColorList( size_t& aListSize, const SGCOLOR* aColorList )
void SGCOLORS::SetColorList( size_t aListSize, const SGCOLOR* aColorList )
{
colors.clear();
@ -154,6 +154,8 @@ void SGCOLORS::SetColorList( size_t& aListSize, const SGCOLOR* aColorList )
for( size_t i = 0; i < aListSize; ++i )
colors.push_back( aColorList[i] );
std::cerr << "XXX: ncolors: " << colors.size() << "\n";
return;
}
@ -212,6 +214,8 @@ bool SGCOLORS::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
for( size_t i = 0; i < n; )
{
S3D::FormatColor( tmp, colors[i] );
float r,g,b;
colors[i].GetColor(r, g, b);
aFile << tmp ;
++i;

View File

@ -51,7 +51,7 @@ public:
bool AddChildNode( SGNODE* aNode );
bool GetColorList( size_t& aListSize, SGCOLOR*& aColorList );
void SetColorList( size_t& aListSize, const SGCOLOR* aColorList );
void SetColorList( size_t aListSize, const SGCOLOR* aColorList );
void AddColor( double aRedValue, double aGreenValue, double aBlueValue );
void AddColor( const SGCOLOR& aColor );

View File

@ -654,7 +654,8 @@ bool SGSHAPE::Prepare( const glm::dmat4* aTransform,
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] bad model; not enough colors per vertex\n";
std::cerr << " * [INFO] bad model; not enough colors per vertex (";
std::cerr << nColors << " vs " << nCoords << ")\n";
#endif
return true;
}
@ -698,7 +699,7 @@ bool SGSHAPE::Prepare( const glm::dmat4* aTransform,
if( pc )
{
SFVEC3F* lColors = new SFVEC3F[vertices.size()];
lColors = new SFVEC3F[vertices.size()];
m.m_Color = lColors;
}

View File

@ -216,8 +216,8 @@ void WRL2COLOR::GetColor( int aIndex, float& red, float& green, float& blue )
}
red = colors[aIndex].x;
green = colors[aIndex].x;
blue = colors[aIndex].x;
green = colors[aIndex].y;
blue = colors[aIndex].z;
return;
}

View File

@ -855,6 +855,7 @@ SGNODE* WRL2FACESET::TranslateToSG( SGNODE* aParent, bool calcNormals )
{
IFSG_COLORS nmColor( fsNode );
nmColor.SetColorList( lColors.size(), &lColors[0] );
std::cerr << "XXX: colors: " << lColors.size() << "\n";
}
m_sgNode = fsNode.GetRawPtr();