Beispiel #1
0
void replaceEffectDatas( SceneSharedPtr const& scene, ReplacementMapNames const& replacements )
{
    replaceEffectDatas( scene->getRootNode(), replacements );
}
Beispiel #2
0
void
XMLLoader::buildScene( GroupSharedPtr const& parent, TiXmlDocument & doc, TiXmlNode * node )
{
  if( !node )
  {
    return;
  }

  TiXmlElement * element = node->ToElement();
  const string value = node->Value();

  // skip everything that is not an element
  if( element )
  {
    if( value == "file" )
    {
      //cout << "XMLLoader: Adding File: " << element->GetText() << endl;
      SceneSharedPtr scene = lookupFile( element->GetText() );

      if( scene )
      {
        // see if they positioned it
        const char * pos = element->Attribute( "position" );
        const char * ori = element->Attribute( "orientation" );
        const char * note = element->Attribute( "annotation" );

        NodeSharedPtr root = scene->getRootNode();
        NodeSharedPtr theNode;

        if( pos || ori )
        {
          TransformSharedPtr transH( Transform::create() );
          transH->addChild(std::static_pointer_cast<dp::sg::core::Node>(root->clone()));
          Trafo trafo;

          if( pos )
          {
            stringstream ss( pos );
            float x, y, z;

            ss >> x;
            ss >> y;
            ss >> z;

            trafo.setTranslation( Vec3f( x, y, z ) );
          }

          if( ori )
          {
            stringstream ss( ori );
            float x, y, z, w;
            int args = 0;

            // read first value
            ss >> x;
            args++;

            if( ss.good() )
            {
              args+=2;
              ss >> y;
              ss >> z;

              if( ss.good() )
              {
                args++;
                ss >> w;
              }
            }

            if( args == 4 )
            {
              trafo.setOrientation( Quatf( x, y, z, w ) );
            }
          }

          transH->setTrafo( trafo );

          // reset 'theNode' here
          theNode = transH;
        }
Beispiel #3
0
void replaceEffectDatas( SceneSharedPtr const& scene, ReplacementMapEffectData const& replacements )
{
    ReplaceTraverser::replace( scene->getRootNode(), replacements );
}
bool CommandReplaceItem::doReplace( SceneTreeItem * oldChild, SceneTreeItem * newChild )
{
  switch( m_parent->getObject()->getObjectCode() )
  {
    case ObjectCode::GEO_NODE :
      DP_ASSERT(std::static_pointer_cast<GeoNode>(m_parent->getObject())->getMaterialPipeline() == std::static_pointer_cast<dp::sg::core::PipelineData>(oldChild->getObject()));
      if ( std::dynamic_pointer_cast<dp::sg::core::PipelineData>(newChild->getObject()) )
      {
        std::static_pointer_cast<GeoNode>(m_parent->getObject())->setMaterialPipeline(std::static_pointer_cast<dp::sg::core::PipelineData>(newChild->getObject()));
      }
      else
      {
        DP_ASSERT( std::dynamic_pointer_cast<Primitive>(m_newChild->getObject()) );
        std::static_pointer_cast<GeoNode>(m_parent->getObject())->setPrimitive(std::static_pointer_cast<Primitive>(newChild->getObject()));
      }
      break;
    case ObjectCode::GROUP :
    case ObjectCode::LOD :
    case ObjectCode::SWITCH :
    case ObjectCode::TRANSFORM :
    case ObjectCode::BILLBOARD :
      {
        GroupSharedPtr g = std::static_pointer_cast<Group>(m_parent->getObject());
        if ( std::dynamic_pointer_cast<Node>(newChild->getObject()) )
        {
          DP_ASSERT(g->findChild(g->beginChildren(), std::static_pointer_cast<Node>(oldChild->getObject())) != g->endChildren());
          g->replaceChild(std::static_pointer_cast<Node>(newChild->getObject()), std::static_pointer_cast<Node>(oldChild->getObject()));
        }
        else
        {
          DP_ASSERT( std::dynamic_pointer_cast<ClipPlane>(newChild->getObject()) );
          DP_ASSERT( g->findClipPlane( std::static_pointer_cast<ClipPlane>(oldChild->getObject()) ) != g->endClipPlanes() );
          g->removeClipPlane(std::static_pointer_cast<ClipPlane>(oldChild->getObject()));
          g->addClipPlane(std::static_pointer_cast<ClipPlane>(newChild->getObject()));
        }
      }
      break;
    case ObjectCode::PRIMITIVE :
      if ( std::dynamic_pointer_cast<IndexSet>(newChild->getObject()) )
      {
        std::static_pointer_cast<Primitive>(m_parent->getObject())->setIndexSet(std::static_pointer_cast<IndexSet>(newChild->getObject()));
      }
      else
      {
        DP_ASSERT( std::dynamic_pointer_cast<VertexAttributeSet>(newChild->getObject()) );
        std::static_pointer_cast<Primitive>(m_parent->getObject())->setVertexAttributeSet(std::static_pointer_cast<VertexAttributeSet>(newChild->getObject()));
      }
      break;
    case ObjectCode::PARAMETER_GROUP_DATA :
      DP_ASSERT( newChild->getObject()->getObjectCode() == ObjectCode::SAMPLER );
      {
        ParameterGroupDataSharedPtr pgd = std::static_pointer_cast<ParameterGroupData>(m_parent->getObject());
        const dp::fx::ParameterGroupSpecSharedPtr & pgs = pgd->getParameterGroupSpec();
        dp::fx::ParameterGroupSpec::iterator it = pgs->findParameterSpec(std::static_pointer_cast<Sampler>(newChild->getObject())->getName());
        DP_ASSERT( it != pgs->endParameterSpecs() );
        DP_ASSERT(pgs->findParameterSpec(std::static_pointer_cast<Sampler>(oldChild->getObject())->getName()) == it);
        pgd->setParameter(it, std::static_pointer_cast<Sampler>(newChild->getObject()));
      }
      break;
    case ObjectCode::PARALLEL_CAMERA :
    case ObjectCode::PERSPECTIVE_CAMERA :
    case ObjectCode::MATRIX_CAMERA :
      DP_ASSERT( m_newChild->getObject()->getObjectCode() == ObjectCode::LIGHT_SOURCE );
      std::static_pointer_cast<Camera>(m_parent->getObject())->replaceHeadLight(std::static_pointer_cast<LightSource>(newChild->getObject()), std::static_pointer_cast<LightSource>(oldChild->getObject()));
      break;
    case ObjectCode::PIPELINE_DATA :
      DP_ASSERT( std::dynamic_pointer_cast<ParameterGroupData>(newChild->getObject()) );
      DP_ASSERT(std::static_pointer_cast<ParameterGroupData>(newChild->getObject())->getParameterGroupSpec() == std::static_pointer_cast<ParameterGroupData>(oldChild->getObject())->getParameterGroupSpec());
      std::static_pointer_cast<dp::sg::core::PipelineData>(m_parent->getObject())->setParameterGroupData(std::static_pointer_cast<ParameterGroupData>(newChild->getObject()));
      break;
    case ObjectCode::SCENE :
      if ( std::dynamic_pointer_cast<Camera>(m_newChild->getObject()) )
      {
        SceneSharedPtr s = std::static_pointer_cast<Scene>(m_parent->getObject());
        s->removeCamera(std::static_pointer_cast<Camera>(oldChild->getObject()));
        s->addCamera(std::static_pointer_cast<Camera>(newChild->getObject()));
      }
      else
      {
        DP_ASSERT( std::dynamic_pointer_cast<Node>(newChild->getObject()) );
        std::static_pointer_cast<Scene>(m_parent->getObject())->setRootNode(std::static_pointer_cast<Node>(newChild->getObject()));
      }
      break;
    default :
      DP_ASSERT( false );
      break;
  }

  if ( m_parent->isExpanded() )
  {
    int index = m_parent->indexOfChild( oldChild );
    DP_ASSERT( 0 <= index );
    m_parent->takeChild( index );
    m_parent->insertChild( index, newChild );
    m_holdsOldChild = !m_holdsOldChild;
  }
  m_parent->setChildIndicatorPolicy();
  GetApp()->outputStatistics();

  ObjectSharedPtr s = std::static_pointer_cast<Object>(oldChild->getObject());
  if ( s->isAttached( m_observer ) )
  {
    s->detach( m_observer );
    std::static_pointer_cast<Object>(newChild->getObject())->attach(m_observer);
  }

  return true;
}