From 973f104704e8cd001c76efe11392e430273e7a5c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 8 May 2008 12:36:07 +0000 Subject: [PATCH] From Garrett Potts and Robert Osfield, changes to build against Collada DOM 2.x --- CMakeModules/FindCOLLADA.cmake | 8 +++-- src/osgPlugins/dae/CMakeLists.txt | 4 +-- src/osgPlugins/dae/daeRGeometry.cpp | 3 +- src/osgPlugins/dae/daeRMaterials.cpp | 44 +++++++++++++--------------- src/osgPlugins/dae/daeWMaterials.cpp | 2 +- src/osgPlugins/dae/daeWriter.cpp | 1 + 6 files changed, 32 insertions(+), 30 deletions(-) diff --git a/CMakeModules/FindCOLLADA.cmake b/CMakeModules/FindCOLLADA.cmake index fa10e2269..ef37403e6 100644 --- a/CMakeModules/FindCOLLADA.cmake +++ b/CMakeModules/FindCOLLADA.cmake @@ -18,7 +18,9 @@ FIND_PATH(COLLADA_INCLUDE_DIR dae.h ~/Library/Frameworks /Library/Frameworks /usr/local/include - /usr/include + /usr/local/include/colladadom + /usr/include/ + /usr/include/colladadom /sw/include # Fink /opt/local/include # DarwinPorts /opt/csw/include # Blastwave @@ -28,7 +30,7 @@ FIND_PATH(COLLADA_INCLUDE_DIR dae.h ) FIND_LIBRARY(COLLADA_LIBRARY - NAMES collada_dom + NAMES collada_dom collada14dom PATHS $ENV{COLLADA_DIR}/lib $ENV{COLLADA_DIR}/lib-dbg @@ -39,7 +41,9 @@ FIND_LIBRARY(COLLADA_LIBRARY ~/Library/Frameworks /Library/Frameworks /usr/local/lib + /usr/local/lib64 /usr/lib + /usr/lib64 /sw/lib /opt/local/lib /opt/csw/lib diff --git a/src/osgPlugins/dae/CMakeLists.txt b/src/osgPlugins/dae/CMakeLists.txt index fc50f7fa7..bd61a9977 100644 --- a/src/osgPlugins/dae/CMakeLists.txt +++ b/src/osgPlugins/dae/CMakeLists.txt @@ -45,9 +45,9 @@ ELSE (WIN32) # # ...so what we need is a conditional way to properly SET() the right one. IF(COLLADA_USE_STATIC) - SET(TARGET_EXTERNAL_LIBRARIES collada_dom collada_dae xml2 pcrecpp) + SET(TARGET_EXTERNAL_LIBRARIES collada14dom xml2 pcrecpp) ELSE(COLLADA_USE_STATIC) - SET(TARGET_EXTERNAL_LIBRARIES collada_dom_shared collada_dae_shared xml2) + SET(TARGET_EXTERNAL_LIBRARIES collada14dom xml2) ENDIF(COLLADA_USE_STATIC) ENDIF(WIN32) diff --git a/src/osgPlugins/dae/daeRGeometry.cpp b/src/osgPlugins/dae/daeRGeometry.cpp index ba210231d..cd63d0705 100644 --- a/src/osgPlugins/dae/daeRGeometry.cpp +++ b/src/osgPlugins/dae/daeRGeometry.cpp @@ -311,7 +311,8 @@ osg::Node* daeReader::processPolylist( domPolylist *group, SourceMap &sources ) osg::DrawArrayLengths* dal = new osg::DrawArrayLengths( GL_POLYGON ); - domPRef p = (domP*)(daeElement*)domP::_Meta->create(); //I don't condone creating elements like this but I don't care + //domPRef p = (domP*)(daeElement*)domP::_Meta->create(); //I don't condone creating elements like this but I don't care + domPRef p = (domP*)domP::registerElement(*dae)->create().cast(); //if it created properly because I never want it as part of the document. Its just a temporary //element to trick the importer into loading polylists easier. unsigned int maxOffset = 0; diff --git a/src/osgPlugins/dae/daeRMaterials.cpp b/src/osgPlugins/dae/daeRMaterials.cpp index 600cf2f84..ac00caf01 100644 --- a/src/osgPlugins/dae/daeRMaterials.cpp +++ b/src/osgPlugins/dae/daeRMaterials.cpp @@ -615,43 +615,39 @@ osg::StateAttribute *daeReader::processTexture( domCommon_color_or_texture_type_ osg::Image *img = NULL; if ( dImg->getInit_from() != NULL ) { + // daeURI uri = dImg->getInit_from()->getValue(); dImg->getInit_from()->getValue().validate(); - if ( std::string( dImg->getInit_from()->getValue().getProtocol() ) == std::string( "file" ) ) { - unsigned int bufSize = 1; //for the null char - if ( dImg->getInit_from()->getValue().getFilepath() != NULL ) - { - bufSize += strlen( dImg->getInit_from()->getValue().getFilepath() ); - } - if ( dImg->getInit_from()->getValue().getFile() != NULL ) - { - bufSize += strlen( dImg->getInit_from()->getValue().getFile() ); - } - char *path = new char[bufSize+1]; - if ( !dImg->getInit_from()->getValue().getPath( path, bufSize ) ) - { - osg::notify( osg::WARN ) << "Unable to get path from URI." << std::endl; - return NULL; - } - + //unsigned int bufSize = 1; //for the null char + //bufSize += dImg->getInit_from()->getValue().pathDir().size(); + //bufSize += dImg->getInit_from()->getValue().pathFile().size(); + std::string path = dImg->getInit_from()->getValue().pathDir()+ + dImg->getInit_from()->getValue().pathFile(); + // remove space encodings + // + path = cdom::uriToNativePath(path); + if(path.empty()) + { + osg::notify( osg::WARN ) << "Unable to get path from URI." << std::endl; + return NULL; + } #ifdef WIN32 // If the path has a drive specifier or a UNC name then strip the leading / - char* filename; + const char* filename =path.c_str(); if ((path[2] == ':') || ((path[1] == '/') && (path[2] == '/'))) - filename = path+1; - else - filename = path; + ++filename;// = path+1; +// else +// filename = path; #else - char* filename = path; + const char* filename = path.c_str(); #endif - img = osgDB::readImageFile( filename ); osg::notify(osg::INFO)<<" processTexture(..) - readImage("<getImage( 0 ); domImage::domInit_from *imgif = daeSafeCast< domImage::domInit_from >( img->createAndPlace( "init_from" ) ); std::string fileURI = ReaderWriterDAE::ConvertFilePathToColladaCompatibleURI(osgDB::findDataFile(osgimg->getFileName())); - daeURI dd( fileURI.c_str() ); + daeURI dd(*dae, fileURI);//fileURI.c_str() ); imgif->setValue( dd ); // The document URI should contain the canonical path it was created with imgif->getValue().makeRelativeTo(doc->getDocumentURI()); diff --git a/src/osgPlugins/dae/daeWriter.cpp b/src/osgPlugins/dae/daeWriter.cpp index 7c18e1b0d..810a7cbf3 100644 --- a/src/osgPlugins/dae/daeWriter.cpp +++ b/src/osgPlugins/dae/daeWriter.cpp @@ -24,6 +24,7 @@ using namespace osgdae; daeWriter::daeWriter( DAE *dae_, const std::string &fileURI, bool _usePolygons, bool GoogleMode ) : osg::NodeVisitor( TRAVERSE_ALL_CHILDREN ), dae(dae_), + rootName(*dae_), usePolygons (_usePolygons), m_GoogleMode(GoogleMode) {