+ Fixed calculation of overall transform in SCENEGRAPH
+ Fixed NULL dereference bug in VRML2 nodes
This commit is contained in:
parent
62c6cba2a1
commit
59cf4c5ed0
|
@ -36,6 +36,8 @@ SCENEGRAPH::SCENEGRAPH( SGNODE* aParent ) : SGNODE( aParent )
|
|||
{
|
||||
m_SGtype = S3D::SGTYPE_TRANSFORM;
|
||||
rotation_angle = 0.0;
|
||||
scale_angle = 0.0;
|
||||
|
||||
scale.x = 1.0;
|
||||
scale.y = 1.0;
|
||||
scale.z = 1.0;
|
||||
|
@ -580,15 +582,31 @@ bool SCENEGRAPH::Prepare( const glm::dmat4* aTransform,
|
|||
{
|
||||
// calculate the accumulated transform
|
||||
double rX, rY, rZ;
|
||||
// rotation
|
||||
rotation_axis.GetVector( rX, rY, rZ );
|
||||
glm::dmat4 rM = glm::rotate( rotation_angle, glm::dvec3( rX, rY, rZ ) );
|
||||
// translation
|
||||
glm::dmat4 tM = glm::translate( glm::dvec3( translation.x, translation.y, translation.z ) );
|
||||
// center
|
||||
glm::dmat4 cM = glm::translate( glm::dvec3( center.x, center.y, center.z ) );
|
||||
glm::dmat4 ncM = glm::translate( glm::dvec3( -center.x, -center.y, -center.z ) );
|
||||
// scale
|
||||
glm::dmat4 sM = glm::scale( glm::dmat4( 1.0 ), glm::dvec3( scale.x, scale.y, scale.z ) );
|
||||
// scaleOrientation
|
||||
scale_axis.GetVector( rX, rY, rZ );
|
||||
glm::dmat4 srM = glm::rotate( scale_angle, glm::dvec3( rX, rY, rZ ) );
|
||||
glm::dmat4 nsrM = glm::rotate( -scale_angle, glm::dvec3( rX, rY, rZ ) );
|
||||
|
||||
// resultant point:
|
||||
// P' = T x C x R x SR x S x -SR x -C x P
|
||||
// resultant transform:
|
||||
// tx0 = tM * cM * rM * srM * sM * nsrM * ncM
|
||||
glm::dmat4 tx0;
|
||||
|
||||
if( NULL != aTransform )
|
||||
tx0 = (*aTransform) * tM * rM;
|
||||
tx0 = (*aTransform) * tM * cM * rM * srM * sM * nsrM * ncM;
|
||||
else
|
||||
tx0 = tM * rM;
|
||||
tx0 = tM * cM * rM * srM * sM * nsrM * ncM;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/v2
|
||||
)
|
||||
|
||||
#add_definitions( -DDEBUG_VRML2=3 )
|
||||
#add_definitions( -DDEBUG_VRML1=3 )
|
||||
|
||||
add_library( s3d_plugin_vrml MODULE
|
||||
vrml.cpp
|
||||
wrlproc.cpp
|
||||
v2/vrml2_node.cpp
|
||||
v2/vrml2_base.cpp
|
||||
v2/vrml2_transform.cpp
|
||||
v2/vrml2_shape.cpp
|
||||
v2/vrml2_appearance.cpp
|
||||
v2/vrml2_material.cpp
|
||||
v2/vrml2_faceset.cpp
|
||||
v2/vrml2_coords.cpp
|
||||
v2/vrml2_norms.cpp
|
||||
v2/vrml2_color.cpp
|
||||
)
|
||||
|
||||
target_link_libraries( s3d_plugin_vrml kicad_3dsg ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} )
|
||||
|
||||
install( TARGETS
|
||||
s3d_plugin_vrml
|
||||
DESTINATION ${KICAD_USER_PLUGIN}/3d
|
||||
COMPONENT binary
|
||||
)
|
|
@ -397,3 +397,45 @@ SGNODE* WRL2APPEARANCE::TranslateToSG( SGNODE* aParent, bool calcNormals )
|
|||
|
||||
return m_sgNode;
|
||||
}
|
||||
|
||||
|
||||
void WRL2APPEARANCE::unlinkChildNode( const WRL2NODE* aNode )
|
||||
{
|
||||
if( NULL == aNode )
|
||||
return;
|
||||
|
||||
if( aNode->GetParent() == this )
|
||||
{
|
||||
if( aNode == material )
|
||||
material = NULL;
|
||||
else if( aNode == texture )
|
||||
texture = NULL;
|
||||
else if( aNode == textureTransform )
|
||||
textureTransform = NULL;
|
||||
|
||||
}
|
||||
|
||||
WRL2NODE::unlinkChildNode( aNode );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void WRL2APPEARANCE::unlinkRefNode( const WRL2NODE* aNode )
|
||||
{
|
||||
if( NULL == aNode )
|
||||
return;
|
||||
|
||||
if( aNode->GetParent() != this )
|
||||
{
|
||||
if( aNode == material )
|
||||
material = NULL;
|
||||
else if( aNode == texture )
|
||||
texture = NULL;
|
||||
else if( aNode == textureTransform )
|
||||
textureTransform = NULL;
|
||||
|
||||
}
|
||||
|
||||
WRL2NODE::unlinkRefNode( aNode );
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -50,6 +50,10 @@ private:
|
|||
*/
|
||||
bool checkNodeType( WRL2NODES aType );
|
||||
|
||||
// overloads
|
||||
void unlinkChildNode( const WRL2NODE* aNode );
|
||||
void unlinkRefNode( const WRL2NODE* aNode );
|
||||
|
||||
public:
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
|
|
|
@ -751,3 +751,49 @@ SGNODE* WRL2FACESET::TranslateToSG( SGNODE* aParent, bool calcNormals )
|
|||
|
||||
return m_sgNode;
|
||||
}
|
||||
|
||||
|
||||
void WRL2FACESET::unlinkChildNode( const WRL2NODE* aNode )
|
||||
{
|
||||
if( NULL == aNode )
|
||||
return;
|
||||
|
||||
if( aNode->GetParent() == this )
|
||||
{
|
||||
if( aNode == color )
|
||||
color = NULL;
|
||||
else if( aNode == coord )
|
||||
coord = NULL;
|
||||
else if( aNode == normal )
|
||||
normal = NULL;
|
||||
else if( aNode == texCoord )
|
||||
texCoord = NULL;
|
||||
|
||||
}
|
||||
|
||||
WRL2NODE::unlinkChildNode( aNode );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void WRL2FACESET::unlinkRefNode( const WRL2NODE* aNode )
|
||||
{
|
||||
if( NULL == aNode )
|
||||
return;
|
||||
|
||||
if( aNode->GetParent() != this )
|
||||
{
|
||||
if( aNode == color )
|
||||
color = NULL;
|
||||
else if( aNode == coord )
|
||||
coord = NULL;
|
||||
else if( aNode == normal )
|
||||
normal = NULL;
|
||||
else if( aNode == texCoord )
|
||||
texCoord = NULL;
|
||||
|
||||
}
|
||||
|
||||
WRL2NODE::unlinkRefNode( aNode );
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -73,6 +73,11 @@ public:
|
|||
// functions inherited from WRL2NODE
|
||||
bool isDangling( void );
|
||||
|
||||
|
||||
// overloads
|
||||
void unlinkChildNode( const WRL2NODE* aNode );
|
||||
void unlinkRefNode( const WRL2NODE* aNode );
|
||||
|
||||
public:
|
||||
WRL2FACESET();
|
||||
WRL2FACESET( WRL2NODE* aParent );
|
||||
|
|
|
@ -200,7 +200,7 @@ WRL2NODES WRL2NODE::GetNodeType( void ) const
|
|||
}
|
||||
|
||||
|
||||
WRL2NODE* WRL2NODE::GetParent( void )
|
||||
WRL2NODE* WRL2NODE::GetParent( void ) const
|
||||
{
|
||||
return m_Parent;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ public:
|
|||
*
|
||||
* @param aNode is the child which is being deleted
|
||||
*/
|
||||
void unlinkChildNode( const WRL2NODE* aNode );
|
||||
virtual void unlinkChildNode( const WRL2NODE* aNode );
|
||||
|
||||
/**
|
||||
* Function unlinkRef
|
||||
|
@ -94,7 +94,7 @@ public:
|
|||
*
|
||||
* @param aNode is the node which is being deleted
|
||||
*/
|
||||
void unlinkRefNode( const WRL2NODE* aNode );
|
||||
virtual void unlinkRefNode( const WRL2NODE* aNode );
|
||||
|
||||
/**
|
||||
* Function addNodeRef
|
||||
|
@ -141,7 +141,7 @@ public:
|
|||
* returns a pointer to the parent SGNODE of this object
|
||||
* or NULL if the object has no parent (ie. top level transform)
|
||||
*/
|
||||
WRL2NODE* GetParent( void );
|
||||
WRL2NODE* GetParent( void ) const;
|
||||
|
||||
/**
|
||||
* Function SetParent
|
||||
|
|
|
@ -371,3 +371,41 @@ SGNODE* WRL2SHAPE::TranslateToSG( SGNODE* aParent, bool calcNormals )
|
|||
|
||||
return m_sgNode;
|
||||
}
|
||||
|
||||
|
||||
void WRL2SHAPE::unlinkChildNode( const WRL2NODE* aNode )
|
||||
{
|
||||
if( NULL == aNode )
|
||||
return;
|
||||
|
||||
if( aNode->GetParent() == this )
|
||||
{
|
||||
if( aNode == appearance )
|
||||
appearance = NULL;
|
||||
else if( aNode == geometry )
|
||||
geometry = NULL;
|
||||
|
||||
}
|
||||
|
||||
WRL2NODE::unlinkChildNode( aNode );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void WRL2SHAPE::unlinkRefNode( const WRL2NODE* aNode )
|
||||
{
|
||||
if( NULL == aNode )
|
||||
return;
|
||||
|
||||
if( aNode->GetParent() != this )
|
||||
{
|
||||
if( aNode == appearance )
|
||||
appearance = NULL;
|
||||
else if( aNode == geometry )
|
||||
geometry = NULL;
|
||||
|
||||
}
|
||||
|
||||
WRL2NODE::unlinkRefNode( aNode );
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -49,6 +49,10 @@ private:
|
|||
*/
|
||||
bool checkNodeType( WRL2NODES aType );
|
||||
|
||||
// overloads
|
||||
void unlinkChildNode( const WRL2NODE* aNode );
|
||||
void unlinkRefNode( const WRL2NODE* aNode );
|
||||
|
||||
public:
|
||||
|
||||
// functions inherited from WRL2NODE
|
||||
|
|
Loading…
Reference in New Issue