⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 daergeometry.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2006 Sony Computer Entertainment Inc. * * Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this  * file except in compliance with the License. You may obtain a copy of the License at: * http://research.scea.com/scea_shared_source_license.html * * Unless required by applicable law or agreed to in writing, software distributed under the License  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or  * implied. See the License for the specific language governing permissions and limitations under the  * License.  */#include "daeReader.h"#include "domSourceReader.h"#include <dae.h>#include <dom/domCOLLADA.h>#include <dom/domInstance_geometry.h>#include <dom/domInstance_controller.h>#include <dom/domController.h>#include <osg/Geometry>using namespace osgdae;osg::Node* daeReader::processInstance_geometry( domInstance_geometry *ig ){    //TODO: cache geometries so they don't get processed mulitple times.    //TODO: after cached need to check geometries and materials. both have to be the same for it    //      to be the same instance.    daeElement *el = getElementFromURI( ig->getUrl() );    domGeometry *geom = daeSafeCast< domGeometry >( el );    if ( geom == NULL )    {        osg::notify( osg::WARN ) << "Failed to locate geometry " << ig->getUrl().getURI() << std::endl;        return NULL;    }    //check cache if geometry already exists    osg::Node *geo;    std::map< domGeometry*, osg::Node* >::iterator iter = geometryMap.find( geom );    if ( iter != geometryMap.end() )    {        geo = iter->second;    }    else    {        geo = processGeometry( geom );        geometryMap.insert( std::make_pair( geom, geo ) );    }    if ( geo == NULL )    {        osg::notify( osg::WARN ) << "Failed to load geometry " << ig->getUrl().getURI() << std::endl;        return NULL;    }    //process material bindings    if ( ig->getBind_material() != NULL )    {        processBindMaterial( ig->getBind_material(), geo );    }    return geo;}osg::Node* daeReader::processInstance_controller( domInstance_controller *ictrl ){    //TODO: cache geometries so they don't get processed mulitple times.    //TODO: after cached need to check geometries and materials. both have to be the same for it    //      to be the same instance.    //TODO: support skinning    osg::notify( osg::WARN ) << "Processing <instance_controller>. There is not skinning support but will display the base mesh." << std::endl;    daeElement *el = getElementFromURI( ictrl->getUrl() );    domController *ctrl = daeSafeCast< domController >( el );    if ( ctrl == NULL )    {        osg::notify( osg::WARN ) << "Failed to locate controller " << ictrl->getUrl().getURI() << std::endl;        return NULL;    }    el = NULL;        //## non init    daeURI *src=NULL;    if ( ctrl->getSkin() != NULL )    {        src = &ctrl->getSkin()->getSource();        el = getElementFromURI( ctrl->getSkin()->getSource() );    }    else if ( ctrl->getMorph() != NULL )    {        src = &ctrl->getSkin()->getSource();        el = getElementFromURI( ctrl->getMorph()->getSource() );    }        //non init case        if ( !src )        {            osg::notify( osg::WARN ) << "Failed to locate geometry : URI is NULL" << std::endl;            return NULL;        }            domGeometry *geom = daeSafeCast< domGeometry >( el );    if ( geom == NULL )    {        osg::notify( osg::WARN ) << "Failed to locate geometry " << src->getURI() << std::endl;        return NULL;    }    osg::Node *geo;    std::map< domGeometry*, osg::Node* >::iterator iter = geometryMap.find( geom );    if ( iter != geometryMap.end() )    {        geo = iter->second;    }    else    {        geo = processGeometry( geom );        geometryMap.insert( std::make_pair( geom, geo ) );    }    if ( geo == NULL )    {        osg::notify( osg::WARN ) << "Failed to load geometry " << src->getURI() << std::endl;        return NULL;    }    //process material bindings    if ( ictrl->getBind_material() != NULL )    {        processBindMaterial( ictrl->getBind_material(), geo );    }    return geo;}osg::Node *daeReader::processGeometry( domGeometry *geo ){    domMesh *mesh = geo->getMesh();    if ( mesh == NULL )    {        osg::notify( osg::WARN ) << "Unsupported Geometry type loading " << geo->getId() << std::endl;        return NULL;    }    osg::Node *node = new osg::Group();    if ( geo->getId() != NULL )    {        node->setName( geo->getId() );    }    SourceMap sources;        size_t count = mesh->getContents().getCount();    for ( size_t i = 0; i < count; i++ )    {        if ( daeSafeCast< domVertices >( mesh->getContents()[i] ) != NULL ) continue;        domSource *s = daeSafeCast< domSource >( mesh->getContents()[i] );        if ( s != NULL )        {            sources.insert( std::make_pair( (daeElement*)mesh->getContents()[i],                 domSourceReader( s ) ) );             continue;        }        osg::Node *n = NULL;        domTriangles *t = daeSafeCast< domTriangles >( mesh->getContents()[i] );        if ( t != NULL )        {            n = processSinglePPrimitive( t, sources, GL_TRIANGLES );            if ( n != NULL )            {                node->asGroup()->addChild( n );            }            continue;        }        domTristrips *ts = daeSafeCast< domTristrips >( mesh->getContents()[i] );        if ( ts != NULL )        {            n = processMultiPPrimitive( ts, sources, GL_TRIANGLE_STRIP );            if ( n != NULL )            {                node->asGroup()->addChild( n );            }            continue;        }        domTrifans *tf = daeSafeCast< domTrifans >( mesh->getContents()[i] );        if ( tf != NULL )        {            n = processMultiPPrimitive( tf, sources, GL_TRIANGLE_FAN );            if ( n != NULL )            {                node->asGroup()->addChild( n );            }            continue;        }        domLines *l = daeSafeCast< domLines >( mesh->getContents()[i] );        if ( l != NULL )        {            n = processSinglePPrimitive( l, sources, GL_LINES );            if ( n != NULL )            {                node->asGroup()->addChild( n );            }            continue;        }        domLinestrips *ls = daeSafeCast< domLinestrips >( mesh->getContents()[i] );        if ( ls != NULL )        {            n = processMultiPPrimitive( ls, sources, GL_LINE_STRIP );            if ( n != NULL )            {                node->asGroup()->addChild( n );            }            continue;        }        domPolygons *p = daeSafeCast< domPolygons >( mesh->getContents()[i] );        if ( p != NULL )        {            n = processMultiPPrimitive( p, sources, GL_POLYGON );            if ( n != NULL )            {                node->asGroup()->addChild( n );            }            continue;        }        domPolylist *pl = daeSafeCast< domPolylist >( mesh->getContents()[i] );        if ( pl != NULL )        {            n = processPolylist( pl, sources );            if ( n != NULL )            {                node->asGroup()->addChild( n );            }            continue;        }        osg::notify( osg::WARN ) << "Unsupported primitive type " << mesh->getContents()[i]->getTypeName() << " in geometry " << geo->getId() << std::endl;    }    return node;}template< typename T >osg::Node* daeReader::processSinglePPrimitive( T *group, SourceMap &sources, GLenum mode ){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -