void FltExportVisitor::apply( osg::PositionAttitudeTransform& node ) { _firstNode = false; ScopedStatePushPop guard( this, node.getStateSet() ); osg::ref_ptr<osg::RefMatrix> m = new osg::RefMatrix( osg::Matrix::translate( -node.getPivotPoint() ) * osg::Matrix::scale( node.getScale() ) * osg::Matrix::rotate( node.getAttitude() ) * osg::Matrix::translate( node.getPosition() ) ); typedef std::vector< osg::ref_ptr< osg::Referenced > > UserDataList; UserDataList saveUserDataList( node.getNumChildren() ); unsigned int idx; for( idx=0; idx<node.getNumChildren(); ++idx ) { saveUserDataList[ idx ] = node.getChild( idx )->getUserData(); node.getChild( idx )->setUserData( m.get() ); } traverse( (osg::Node&)node ); // Restore saved UserData. for( idx=0; idx<node.getNumChildren(); ++idx ) { node.getChild( idx )->setUserData( saveUserDataList[ idx ].get() ); } }
//POSATT void daeWriter::apply( osg::PositionAttitudeTransform &node ) { #ifdef _DEBUG debugPrint( node ); #endif while ( lastDepth >= _nodePath.size() ) { //We are not a child of previous node currentNode = daeSafeCast< domNode >( currentNode->getParentElement() ); lastDepth--; } currentNode = daeSafeCast< domNode >(currentNode->createAndPlace( COLLADA_ELEMENT_NODE ) ); currentNode->setId(getNodeName(node,"positionAttitudeTransform").c_str()); const osg::Vec3 &pos = node.getPosition(); const osg::Quat &q = node.getAttitude(); const osg::Vec3 &s = node.getScale(); if ( s.x() != 1 || s.y() != 1 || s.z() != 1 ) { //make a scale domScale *scale = daeSafeCast< domScale >( currentNode->createAndPlace( COLLADA_ELEMENT_SCALE ) ); scale->getValue().append( s.x() ); scale->getValue().append( s.y() ); scale->getValue().append( s.z() ); } double angle; osg::Vec3 axis; q.getRotate( angle, axis ); if ( angle != 0 ) { //make a rotate domRotate *rot = daeSafeCast< domRotate >( currentNode->createAndPlace( COLLADA_ELEMENT_ROTATE ) ); rot->getValue().append( axis.x() ); rot->getValue().append( axis.y() ); rot->getValue().append( axis.z() ); rot->getValue().append( angle ); } if ( pos.x() != 0 || pos.y() != 0 || pos.z() != 0 ) { //make a translate domTranslate *trans = daeSafeCast< domTranslate >( currentNode->createAndPlace( COLLADA_ELEMENT_TRANSLATE ) ); trans->getValue().append( pos.x() ); trans->getValue().append( pos.y() ); trans->getValue().append( pos.z() ); } lastVisited = POSATT; lastDepth = _nodePath.size(); traverse( node ); }
//POSATT void daeWriter::apply( osg::PositionAttitudeTransform &node ) { #ifdef _DEBUG debugPrint( node ); #endif updateCurrentDaeNode(); currentNode = daeSafeCast< domNode >(currentNode->add( COLLADA_ELEMENT_NODE ) ); std::string nodeName = getNodeName(node,"positionAttitudeTransform"); currentNode->setId(nodeName.c_str()); const osg::Vec3 &pos = node.getPosition(); const osg::Quat &q = node.getAttitude(); const osg::Vec3 &s = node.getScale(); osg::Callback* ncb = node.getUpdateCallback(); bool handled = false; if (ncb) { osgAnimation::UpdateMatrixTransform* ut = dynamic_cast<osgAnimation::UpdateMatrixTransform*>(ncb); // If targeted by an animation we split up the matrix into multiple place element so they can be targeted individually if (ut) { handled = true; writeUpdateTransformElements(pos, q, s); } } // If not targeted by an animation simply add the elements that actually contribute to placement if (!handled) { if ( s.x() != 1 || s.y() != 1 || s.z() != 1 ) { // Make a scale place element domScale *scale = daeSafeCast< domScale >( currentNode->add( COLLADA_ELEMENT_SCALE ) ); scale->setSid("scale"); scale->getValue().append3( s.x(), s.y(), s.z() ); } double angle; osg::Vec3 axis; q.getRotate( angle, axis ); if ( angle != 0 ) { // Make a rotate place element domRotate *rot = daeSafeCast< domRotate >( currentNode->add( COLLADA_ELEMENT_ROTATE ) ); rot->setSid("rotate"); rot->getValue().append4( axis.x(), axis.y(), axis.z(), osg::RadiansToDegrees(angle) ); } if ( s.x() != 1 || s.y() != 1 || s.z() != 1 ) { // Make a translate place element domTranslate *trans = daeSafeCast< domTranslate >( currentNode->add( COLLADA_ELEMENT_TRANSLATE ) ); trans->setSid("translate"); trans->getValue().append3( pos.x(), pos.y(), pos.z() ); } } writeNodeExtra(node); lastDepth = _nodePath.size(); traverse( node ); }