我要发帖 回复

中级会员

7

主题

494

积分

0

专家分

:

私信
发表时间 : 2014-5-14 09:30:25 | 浏览 : 1040    评论 : 0
void statsTestApp::createSceneGraph()
{
    vsApp::createSceneGraph();
        vpScene *m_myScene;


        vsNode *pmound;
        //vsChildNode

    vsNodeFactory *pNodeFactory = new vsNodeFactory();
    vsNodeLoader  *loader = pNodeFactory->getLoader("flt", true);
    vsNode *pNode = NULL;
        //m_children

    //
    // Nothing was passed on the command-line... just load town.flt
    // instead.
    //

    vuSearchPath *pSearchPath = NULL;
    char fullPath[256];
    char *resourcePath = getenv("PRESAGIS_VEGA_PRIME_RESOURCE_6");

    sprintf( fullPath, "%s/resources/data/databases/camp_pendleton", resourcePath );

    pSearchPath = vuImageFactory::getDefaultSearchPath();
    pSearchPath->set( fullPath );

    pSearchPath = vrTextureFactory::getDefaultSearchPath();
    pSearchPath->set( fullPath );

    pSearchPath = vsNodeFactory::getDefaultSearchPath();
    pSearchPath->set( fullPath );

    vsNodeLoader::Data data;

    pNode = static_cast<vsNode*>(pNodeFactory->read( "camp_pendleton.flt", data ));
            
    if( pNode != NULL )
    {
       vsFlatten( pNode );
        vsClean( pNode );
        m_root->push_back_child( pNode );//if this line is worked, my white sphere  can't rending;
        }

    pNodeFactory->unref();
                       
                vrLight *pLight = vrLight::obtain(-1);
                pLight->setType( vrLight::TYPE_DIRECTIONAL );
                pLight->setDirection( 0.0f, 1.0f, -1.0f );

                vsLight *pLightNode = new vsLight;
                pLightNode->setLight( pLight );
                pLightNode->setName( "Light" );
                pLightNode->setColor( vrLight::COLOR_AMBIENT, 0.2f, 0.2f, 0.2f, 1.0f );
                pLightNode->setColor( vrLight::COLOR_DIFFUSE, 1.0f, 1.0f, 1.0f, 1.0f );
                pLightNode->setColor( vrLight::COLOR_SPECULAR, 1.0f, 1.0f, 1.0f, 1.0f );
                pLightNode->setEnable( true );
                m_root->push_back_child( pLightNode );


                //bulid my own geometry, and add it to scene.but why the line 205 and line 230 can't work together?
        m_geometry = new vrGeometry();
        buildGeometry(20);
        m_geometry->ref();
        vsGeometry *geometry = new vsGeometry();
        geometry->setGeometry(m_geometry);
                m_root->push_back_child(geometry);
                 

}
void statsTestApp::buildGeometry(int subdivisions)
    {

        // create a new sphere w/ the given number of subdivisions
        vrSphere *sphere = new vrSphere(vuVec3<float>(0.0f, 0.0f, 0.0f), 1.0f,
            subdivisions);

        // make our geometry a copy of the sphere
        vrGeometryBase::Binding binding;
        m_geometry->setPrimitive(sphere->getPrimitive());
        m_geometry->setNumPrimitives(sphere->getNumPrimitives());

        if (m_geometry->getColors(&binding) == NULL) {
            vuVec4<float> *color = vuAllocArray<vuVec4<float> >::malloc(1);
            color->set(1.0f, 1.0f, 1.0f, 1.0f);
            m_geometry->setColors(color, vrGeometryBase::BINDING_OVERALL);
        }

        int *length = vuAllocArray<int>::malloc(sphere->getNumPrimitives());
        crt::memcpy(length, sphere->getPrimitiveLengths(), vuGetSizeRequested(length));
        m_geometry->setPrimitiveLengths(length);

        vuVec3<float> *tmp = sphere->getNormals(&binding);
        vuVec3<float> *normal = vuAllocArray<vuVec3<float> >::malloc(
            sphere->getNumNormals());
        crt::memcpy(normal, tmp, vuGetSizeRequested(normal));
        m_geometry->setNormals(normal, binding);

        vuVec3<float> *vertex = vuAllocArray<vuVec3<float> >::malloc(
            sphere->getNumVertices());
        crt::memcpy(vertex, sphere->getVertices(), vuGetSizeRequested(vertex));
        m_geometry->setVertices(vertex);

        ushort *pIndices = NULL;
        if ( sphere->getNumIndices() > 0 )
        {
            pIndices = vuAllocArray<ushort>::malloc( sphere->getNumIndices());
            crt::memcpy(pIndices, sphere->getIndices< ushort >(), vuGetSizeRequested(pIndices));
            m_geometry->setIndices(pIndices);
        }

    sphere->unref();

    }


上面两个函数,一个是重载的 vsApp::createSceneGraph();这个里面我调用了camp_pendleton.flt,同时,我在这个函数里面调用自己动态创建模型的函数buildGeometry(int subdivisions),并渲染。但是问题是,camp_pendleton场景和我 自己创建的模型不可以同时渲染,二则只可以渲染一个,不知道为何?

请高手指点!!非常感谢




评分

参与人数 1积分 +50 VR币 +10 收起 理由
obuil + 50 + 10 赞一个!

查看全部评分

最近VR访客

手机版|VR开发网 ( 津ICP备18009691号 ) 统计 网安备12019202000257

GMT+8, 2020-11-26 03:36 PM

返回顶部