Changed handling of ambientIntensity; change of major version in SG* lib

This commit is contained in:
Cirilo Bernardo 2016-02-07 08:41:27 +11:00
parent 67832dbc74
commit 99aba8f261
12 changed files with 106 additions and 29 deletions

View File

@ -56,15 +56,18 @@ static void formatMaterial( SMATERIAL& mat, SGAPPEARANCE const* app )
{ {
float v0, v1, v2; float v0, v1, v2;
v0 = app->ambient; app->ambient.GetColor( v0, v1, v2 );
mat.m_Ambient.x = v0; mat.m_Ambient.x = v0;
mat.m_Ambient.y = v0; mat.m_Ambient.y = v1;
mat.m_Ambient.z = v0; mat.m_Ambient.z = v2;
app->diffuse.GetColor( v0, v1, v2 ); app->diffuse.GetColor( v0, v1, v2 );
mat.m_Diffuse.x = v0; mat.m_Diffuse.x = v0;
mat.m_Diffuse.y = v1; mat.m_Diffuse.y = v1;
mat.m_Diffuse.z = v2; mat.m_Diffuse.z = v2;
mat.m_Ambient.x *= v0;
mat.m_Ambient.y *= v1;
mat.m_Ambient.z *= v2;
app->emissive.GetColor( v0, v1, v2 ); app->emissive.GetColor( v0, v1, v2 );
mat.m_Emissive.x = v0; mat.m_Emissive.x = v0;
@ -459,7 +462,7 @@ S3DMODEL* S3D::GetModel( SCENEGRAPH* aNode )
// also typical of MCAD applications. When a model has no associated // also typical of MCAD applications. When a model has no associated
// material color it shall be assigned the index 0. // material color it shall be assigned the index 0.
SGAPPEARANCE app( NULL ); SGAPPEARANCE app( NULL );
app.ambient = 0.9; app.ambient = SGCOLOR( 0.6, 0.6, 0.6 );
app.diffuse = SGCOLOR( 0.6, 0.6, 0.6 ); app.diffuse = SGCOLOR( 0.6, 0.6, 0.6 );
app.specular = app.diffuse; app.specular = app.diffuse;
app.shininess = 0.05; app.shininess = 0.05;

View File

@ -322,7 +322,7 @@ bool IFSG_APPEARANCE::SetSpecular( const SGCOLOR& aRGBColor )
} }
bool IFSG_APPEARANCE::SetAmbient( float aAmbientLight ) bool IFSG_APPEARANCE::SetAmbient( float aRVal, float aGVal, float aBVal )
{ {
if( NULL == m_node ) if( NULL == m_node )
{ {
@ -334,21 +334,42 @@ bool IFSG_APPEARANCE::SetAmbient( float aAmbientLight )
return false; return false;
} }
if( aAmbientLight < 0 || aAmbientLight > 1.0 ) return ((SGAPPEARANCE*)m_node)->SetAmbient( aRVal, aGVal, aBVal );
}
bool IFSG_APPEARANCE::SetAmbient( const SGCOLOR* aRGBColor )
{
if( NULL == m_node )
{ {
#ifdef DEBUG #ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] ambient intensity out of range [0..1]\n"; std::cerr << BadObject << "\n";
#endif #endif
return false; return false;
} }
((SGAPPEARANCE*)m_node)->ambient = aAmbientLight; return ((SGAPPEARANCE*)m_node)->SetAmbient( aRGBColor );
return true;
} }
bool IFSG_APPEARANCE::SetAmbient( const SGCOLOR& aRGBColor )
{
if( NULL == m_node )
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << BadObject << "\n";
#endif
return false;
}
return ((SGAPPEARANCE*)m_node)->SetAmbient( aRGBColor );
}
bool IFSG_APPEARANCE::SetShininess( float aShininess ) bool IFSG_APPEARANCE::SetShininess( float aShininess )
{ {
if( NULL == m_node ) if( NULL == m_node )

View File

@ -32,7 +32,7 @@ SGAPPEARANCE::SGAPPEARANCE( SGNODE* aParent ) : SGNODE( aParent)
m_SGtype = S3D::SGTYPE_APPEARANCE; m_SGtype = S3D::SGTYPE_APPEARANCE;
// defaults in accord with VRML2.0 spec // defaults in accord with VRML2.0 spec
ambient = 0.2; ambient.SetColor( 0.05317, 0.17879, 0.01804 );
shininess = 0.2; shininess = 0.2;
transparency = 0.0; transparency = 0.0;
diffuse.SetColor( 0.8, 0.8, 0.8 ); diffuse.SetColor( 0.8, 0.8, 0.8 );
@ -175,6 +175,34 @@ bool SGAPPEARANCE::SetSpecular( const SGCOLOR& aRGBColor )
} }
bool SGAPPEARANCE::SetAmbient( float aRVal, float aGVal, float aBVal )
{
return ambient.SetColor( aRVal, aGVal, aBVal );
}
bool SGAPPEARANCE::SetAmbient( const SGCOLOR* aRGBColor )
{
if( NULL == aRGBColor )
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [BUG] NULL pointer passed for aRGBColor\n";
#endif
return false;
}
return ambient.SetColor( aRGBColor );
}
bool SGAPPEARANCE::SetAmbient( const SGCOLOR& aRGBColor )
{
return ambient.SetColor( aRGBColor );
}
SGNODE* SGAPPEARANCE::FindNode(const char *aNodeName, const SGNODE *aCaller) SGNODE* SGAPPEARANCE::FindNode(const char *aNodeName, const SGNODE *aCaller)
{ {
if( NULL == aNodeName || 0 == aNodeName[0] ) if( NULL == aNodeName || 0 == aNodeName[0] )
@ -264,7 +292,21 @@ bool SGAPPEARANCE::WriteVRML( std::ofstream& aFile, bool aReuseFlag )
aFile << " material Material {\n"; aFile << " material Material {\n";
std::string tmp; std::string tmp;
S3D::FormatFloat( tmp, ambient ); float ambr, ambg, ambb;
ambient.GetColor( ambr, ambg, ambb );
float amb = ( 0.212671 * ambr + 0.71516 * ambg + 0.072169 * ambb );
diffuse.GetColor( ambr, ambg, ambb );
float den = ( 0.212671 * ambr + 0.71516 * ambg + 0.072169 * ambb );
if( den < 0.004 )
den = 0.004;
amb /= den;
if( amb > 1.0 )
amb = 1.0;
S3D::FormatFloat( tmp, amb );
aFile << " ambientIntensity " << tmp << "\n"; aFile << " ambientIntensity " << tmp << "\n";
float red, green, blue; float red, green, blue;

View File

@ -34,9 +34,9 @@
class SGAPPEARANCE : public SGNODE class SGAPPEARANCE : public SGNODE
{ {
public: public:
float ambient; // default 0.2
float shininess; // default 0.2 float shininess; // default 0.2
float transparency; // default 0.0 float transparency; // default 0.0
SGCOLOR ambient; // default 0.05317 0.17879 0.01804
SGCOLOR diffuse; // default 0.8 0.8 0.8 SGCOLOR diffuse; // default 0.8 0.8 0.8
SGCOLOR emissive; // default 0.0 0.0 0.0 SGCOLOR emissive; // default 0.0 0.0 0.0
SGCOLOR specular; // default 0.0 0.0 0.0 SGCOLOR specular; // default 0.0 0.0 0.0
@ -62,6 +62,10 @@ public:
bool SetSpecular( const SGCOLOR* aRGBColor ); bool SetSpecular( const SGCOLOR* aRGBColor );
bool SetSpecular( const SGCOLOR& aRGBColor ); bool SetSpecular( const SGCOLOR& aRGBColor );
bool SetAmbient( float aRVal, float aGVal, float aBVal );
bool SetAmbient( const SGCOLOR* aRGBColor );
bool SetAmbient( const SGCOLOR& aRGBColor );
SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller); SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller);
bool AddRefNode( SGNODE* aNode ); bool AddRefNode( SGNODE* aNode );
bool AddChildNode( SGNODE* aNode ); bool AddChildNode( SGNODE* aNode );

View File

@ -54,7 +54,10 @@ public:
bool SetSpecular( const SGCOLOR* aRGBColor ); bool SetSpecular( const SGCOLOR* aRGBColor );
bool SetSpecular( const SGCOLOR& aRGBColor ); bool SetSpecular( const SGCOLOR& aRGBColor );
bool SetAmbient( float aAmbientLight ); bool SetAmbient( float aRVal, float aGVal, float aBVal );
bool SetAmbient( const SGCOLOR* aRGBColor );
bool SetAmbient( const SGCOLOR& aRGBColor );
bool SetShininess( float aShininess ); bool SetShininess( float aShininess );
bool SetTransparency( float aTransparency ); bool SetTransparency( float aTransparency );
}; };

View File

@ -30,7 +30,7 @@
#ifndef SG_VERSION_H #ifndef SG_VERSION_H
#define SG_VERSION_H #define SG_VERSION_H
#define KICADSG_VERSION_MAJOR 1 #define KICADSG_VERSION_MAJOR 2
#define KICADSG_VERSION_MINOR 0 #define KICADSG_VERSION_MINOR 0
#define KICADSG_VERSION_PATCH 0 #define KICADSG_VERSION_PATCH 0
#define KICADSG_VERSION_REVISION 0 #define KICADSG_VERSION_REVISION 0

View File

@ -98,7 +98,7 @@ static SGNODE* getColor( IFSG_SHAPE& shape, int colorIdx )
// green for PCB // green for PCB
material.SetSpecular( 0.13, 0.81, 0.22 ); material.SetSpecular( 0.13, 0.81, 0.22 );
material.SetDiffuse( 0.13, 0.81, 0.22 ); material.SetDiffuse( 0.13, 0.81, 0.22 );
material.SetAmbient( 0.9 ); // default ambient intensity
material.SetShininess( 0.3 ); material.SetShininess( 0.3 );
break; break;
@ -107,7 +107,7 @@ static SGNODE* getColor( IFSG_SHAPE& shape, int colorIdx )
// magenta // magenta
material.SetSpecular( 0.8, 0.0, 0.8 ); material.SetSpecular( 0.8, 0.0, 0.8 );
material.SetDiffuse( 0.6, 0.0, 0.6 ); material.SetDiffuse( 0.6, 0.0, 0.6 );
material.SetAmbient( 0.9 ); // default ambient intensity
material.SetShininess( 0.3 ); material.SetShininess( 0.3 );
break; break;
@ -116,7 +116,7 @@ static SGNODE* getColor( IFSG_SHAPE& shape, int colorIdx )
// red // red
material.SetSpecular( 0.69, 0.14, 0.14 ); material.SetSpecular( 0.69, 0.14, 0.14 );
material.SetDiffuse( 0.69, 0.14, 0.14 ); material.SetDiffuse( 0.69, 0.14, 0.14 );
material.SetAmbient( 0.9 ); // default ambient intensity
material.SetShininess( 0.3 ); material.SetShininess( 0.3 );
break; break;
@ -125,7 +125,7 @@ static SGNODE* getColor( IFSG_SHAPE& shape, int colorIdx )
// orange // orange
material.SetSpecular( 1.0, 0.44, 0.0 ); material.SetSpecular( 1.0, 0.44, 0.0 );
material.SetDiffuse( 1.0, 0.44, 0.0 ); material.SetDiffuse( 1.0, 0.44, 0.0 );
material.SetAmbient( 0.9 ); // default ambient intensity
material.SetShininess( 0.3 ); material.SetShininess( 0.3 );
break; break;
@ -134,7 +134,7 @@ static SGNODE* getColor( IFSG_SHAPE& shape, int colorIdx )
// yellow // yellow
material.SetSpecular( 0.93, 0.94, 0.16 ); material.SetSpecular( 0.93, 0.94, 0.16 );
material.SetDiffuse( 0.93, 0.94, 0.16 ); material.SetDiffuse( 0.93, 0.94, 0.16 );
material.SetAmbient( 0.9 ); // default ambient intensity
material.SetShininess( 0.3 ); material.SetShininess( 0.3 );
break; break;
@ -143,7 +143,7 @@ static SGNODE* getColor( IFSG_SHAPE& shape, int colorIdx )
// blue // blue
material.SetSpecular( 0.1, 0.11, 0.88 ); material.SetSpecular( 0.1, 0.11, 0.88 );
material.SetDiffuse( 0.1, 0.11, 0.88 ); material.SetDiffuse( 0.1, 0.11, 0.88 );
material.SetAmbient( 0.9 ); // default ambient intensity
material.SetShininess( 0.3 ); material.SetShininess( 0.3 );
break; break;
@ -152,7 +152,7 @@ static SGNODE* getColor( IFSG_SHAPE& shape, int colorIdx )
// violet // violet
material.SetSpecular( 0.32, 0.07, 0.64 ); material.SetSpecular( 0.32, 0.07, 0.64 );
material.SetDiffuse( 0.32, 0.07, 0.64 ); material.SetDiffuse( 0.32, 0.07, 0.64 );
material.SetAmbient( 0.9 ); // default ambient intensity
material.SetShininess( 0.3 ); material.SetShininess( 0.3 );
break; break;

View File

@ -349,8 +349,7 @@ SGNODE* WRL1MATERIAL::GetAppearance( int aIndex )
checkRange( red ); checkRange( red );
checkRange( green ); checkRange( green );
checkRange( blue ); checkRange( blue );
val = (red + green + blue)/3.0; app.SetAmbient( red, green, blue );
app.SetAmbient( val );
if( aIndex == 0 || diffuseColor.empty() ) if( aIndex == 0 || diffuseColor.empty() )
{ {

View File

@ -410,7 +410,7 @@ SGNODE* WRL2APPEARANCE::TranslateToSG( SGNODE* aParent )
matNode.SetEmissive( 0.0, 0.0, 0.0 ); matNode.SetEmissive( 0.0, 0.0, 0.0 );
matNode.SetSpecular( 0.65, 0.65, 0.65 ); matNode.SetSpecular( 0.65, 0.65, 0.65 );
matNode.SetDiffuse( 0.65, 0.65, 0.65 ); matNode.SetDiffuse( 0.65, 0.65, 0.65 );
matNode.SetAmbient( 0.99 ); // default ambient
matNode.SetShininess( 0.2 ); matNode.SetShininess( 0.2 );
matNode.SetTransparency( 0.0 ); matNode.SetTransparency( 0.0 );
m_sgNode = matNode.GetRawPtr(); m_sgNode = matNode.GetRawPtr();

View File

@ -340,7 +340,10 @@ SGNODE* WRL2MATERIAL::TranslateToSG( SGNODE* aParent )
matNode.SetEmissive( emissiveColor.x, emissiveColor.y, emissiveColor.z ); matNode.SetEmissive( emissiveColor.x, emissiveColor.y, emissiveColor.z );
matNode.SetSpecular( specularColor.x, specularColor.y, specularColor.z ); matNode.SetSpecular( specularColor.x, specularColor.y, specularColor.z );
matNode.SetDiffuse( diffuseColor.x, diffuseColor.y, diffuseColor.z ); matNode.SetDiffuse( diffuseColor.x, diffuseColor.y, diffuseColor.z );
matNode.SetAmbient( ambientIntensity ); float ambr = ambientIntensity * diffuseColor.x;
float ambg = ambientIntensity * diffuseColor.y;
float ambb = ambientIntensity * diffuseColor.z;
matNode.SetAmbient( ambr, ambb, ambg );
matNode.SetShininess( shininess ); matNode.SetShininess( shininess );
matNode.SetTransparency( transparency ); matNode.SetTransparency( transparency );
m_sgNode = matNode.GetRawPtr(); m_sgNode = matNode.GetRawPtr();

View File

@ -218,7 +218,7 @@ bool X3DAPP::SetParent( X3DNODE* aParent, bool doUnlink )
} }
bool X3DAPP::AddChildNode( X3DNODE* aNode ) bool X3DAPP::AddChildNode( X3DNODE* aNode )
{ {
return false; return false;
} }
@ -274,7 +274,10 @@ SGNODE* X3DAPP::TranslateToSG( SGNODE* aParent )
matNode.SetEmissive( emissiveColor.x, emissiveColor.y, emissiveColor.z ); matNode.SetEmissive( emissiveColor.x, emissiveColor.y, emissiveColor.z );
matNode.SetSpecular( specularColor.x, specularColor.y, specularColor.z ); matNode.SetSpecular( specularColor.x, specularColor.y, specularColor.z );
matNode.SetDiffuse( diffuseColor.x, diffuseColor.y, diffuseColor.z ); matNode.SetDiffuse( diffuseColor.x, diffuseColor.y, diffuseColor.z );
matNode.SetAmbient( ambientIntensity ); float ambr = ambientIntensity * diffuseColor.x;
float ambg = ambientIntensity * diffuseColor.y;
float ambb = ambientIntensity * diffuseColor.z;
matNode.SetAmbient( ambr, ambg, ambb );
matNode.SetShininess( shininess ); matNode.SetShininess( shininess );
matNode.SetTransparency( transparency ); matNode.SetTransparency( transparency );
m_sgNode = matNode.GetRawPtr(); m_sgNode = matNode.GetRawPtr();

View File

@ -139,7 +139,6 @@ bool X3DTRANSFORM::Read( wxXmlNode* aNode, X3DNODE* aTopNode, X3D_DICT& aDict )
{ {
if( NULL == aTopNode || NULL == aNode ) if( NULL == aTopNode || NULL == aNode )
return false; return false;
std::cerr << "XXX: Reading Transform\n";
m_Dict = &aDict; m_Dict = &aDict;
readFields( aNode ); readFields( aNode );