Changeset 9228
- Timestamp:
- 11/24/08 15:26:04 (3 years ago)
- Location:
- OpenSceneGraph/trunk/src/osgPlugins/dae
- Files:
-
- 14 modified
-
CMakeLists.txt (modified) (2 diffs)
-
ReaderWriterDAE.cpp (modified) (4 diffs)
-
daeRGeometry.cpp (modified) (17 diffs)
-
daeRMaterials.cpp (modified) (22 diffs)
-
daeRSceneObjects.cpp (modified) (4 diffs)
-
daeRTransforms.cpp (modified) (1 diff)
-
daeReader.cpp (modified) (4 diffs)
-
daeReader.h (modified) (5 diffs)
-
daeWGeometry.cpp (modified) (43 diffs)
-
daeWMaterials.cpp (modified) (18 diffs)
-
daeWSceneObjects.cpp (modified) (6 diffs)
-
daeWTransforms.cpp (modified) (9 diffs)
-
daeWriter.cpp (modified) (8 diffs)
-
daeWriter.h (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/dae/CMakeLists.txt
r8282 r9228 28 28 29 29 IF (COLLADA_USE_STATIC) 30 SET(TARGET_EXTERNAL_LIBRARIES lib collada_dom libcollada_dae libcollada_STLDatabase libcollada_LIBXMLPlugin libcollada_stdErrPlugin libxml2)30 SET(TARGET_EXTERNAL_LIBRARIES libxml2 pcrecpp-d pcre-d) 31 31 ELSE (COLLADA_USE_STATIC) 32 ADD_DEFINITIONS(-DDOM_DYNAMIC) 32 # ADD_DEFINITIONS(-DDOM_DYNAMIC) 33 SET(TARGET_EXTERNAL_LIBRARIES libxml2 pcrecpp-d pcre-d) 33 34 ENDIF(COLLADA_USE_STATIC) 34 35 … … 54 55 55 56 SET(TARGET_LIBRARIES_VARS COLLADA_LIBRARY) 57 SET(TARGET_ADDED_LIBRARIES osgSim ) 56 58 57 59 #### end var setup ### -
OpenSceneGraph/trunk/src/osgPlugins/dae/ReaderWriterDAE.cpp
r8314 r9228 15 15 16 16 #include <osg/Notify> 17 #include <osg/NodeVisitor> 17 18 #include <osgDB/ReaderWriter> 18 19 #include <osgDB/FileNameUtils> … … 41 42 42 43 if ( options ) 43 pDAE = (DAE*) options->getPluginData("DAE");44 pDAE = (DAE*)options->getPluginData("DAE"); 44 45 45 46 std::string ext( osgDB::getLowerCaseFileExtension(fname) ); … … 104 105 105 106 // Process options 106 bool usePolygon(false); 107 bool GoogleMode(false); 107 bool usePolygon(false); // Use plugin option "polygon" to enable 108 bool GoogleMode(false); // Use plugin option "GoogleMode" to enable 109 bool writeExtras(true); // Use plugin option "NoExtras" to disable 108 110 if( options ) 109 111 { 110 pDAE = (DAE*) options->getPluginData("DAE");112 pDAE = (DAE*)options->getPluginData("DAE"); 111 113 std::istringstream iss( options->getOptionString() ); 112 114 std::string opt; 113 115 114 while( std::getline( iss, opt, ',' ) ) 115 { 116 if( opt == "polygon") usePolygon = true; 117 else if (opt == "GoogleMode") GoogleMode = true; 118 else 116 while( std::getline( iss, opt, ',' ) ) 119 117 { 120 osg::notify(osg::WARN) 121 << "\n" "COLLADA dae plugin: unrecognized option \"" << opt << "\"\n" 122 << "comma-delimited options:\n" 123 << "\tpolygon = use polygons instead of polylists for element\n" 124 << "\tGoogleMode = write files suitable for use by Google products\n" 125 << "example: osgviewer -O polygon bar.dae" "\n" 126 << std::endl; 118 if( opt == "polygon") usePolygon = true; 119 else if (opt == "GoogleMode") GoogleMode = true; 120 else if (opt == "NoExtras") writeExtras = false; 121 else 122 { 123 osg::notify(osg::WARN) 124 << std::endl << "COLLADA dae plugin: unrecognized option \"" << opt << std::endl 125 << "comma-delimited options:" << std::endl << std::endl 126 << "\tpolygon = use polygons instead of polylists for element" << std::endl 127 << "\tGoogleMode = write files suitable for use by Google products" << std::endl 128 << "example: osgviewer -O polygon bar.dae" << std::endl << std::endl; 129 } 127 130 } 128 }129 131 } 130 132 131 133 if (NULL == pDAE) 132 134 { … … 138 140 std::string fileURI = ConvertFilePathToColladaCompatibleURI(fname); 139 141 140 osgdae::daeWriter daeWriter(pDAE, fileURI, usePolygon, GoogleMode ); 142 osg::NodeVisitor::TraversalMode traversalMode = writeExtras ? osg::NodeVisitor::TRAVERSE_ALL_CHILDREN : osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN; 143 144 osgdae::daeWriter daeWriter(pDAE, fileURI, usePolygon, GoogleMode, traversalMode, writeExtras); 141 145 daeWriter.setRootNode( node ); 142 146 const_cast<osg::Node*>(&node)->accept( daeWriter ); -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeRGeometry.cpp
r8282 r9228 19 19 #include <dom/domInstance_controller.h> 20 20 #include <dom/domController.h> 21 #include <osg/StateSet> 21 22 22 23 #include <osg/Geometry> … … 24 25 using namespace osgdae; 25 26 26 osg::Node* daeReader::processInstance_geometry( domInstance_geometry *ig ) 27 { 28 //TODO: cache geometries so they don't get processed mulitple times. 29 //TODO: after cached need to check geometries and materials. both have to be the same for it 30 // to be the same instance. 31 27 osg::Geode* daeReader::processInstanceGeometry( domInstance_geometry *ig ) 28 { 32 29 daeElement *el = getElementFromURI( ig->getUrl() ); 33 30 domGeometry *geom = daeSafeCast< domGeometry >( el ); … … 37 34 return NULL; 38 35 } 39 //check cache if geometry already exists 40 osg::Node *geo; 41 42 std::map< domGeometry*, osg::Node* >::iterator iter = geometryMap.find( geom ); 36 37 // Check cache if geometry already exists 38 osg::Geode *geode; 39 40 domGeometryGeodeMap::iterator iter = geometryMap.find( geom ); 43 41 if ( iter != geometryMap.end() ) 44 42 { 45 geo = iter->second; 43 osg::Geode* cachedGeode = iter->second; 44 45 // Create a copy of the cached Geode with a copy of the drawables, 46 // because the may be using a different material. 47 // TODO Cloning is not necessary if the material layouts are exactly the same. 48 // To check this we need to compare the material bindings used by the cached Geode 49 // and this new instance_geometry material bindings. 50 geode = static_cast<osg::Geode*>(cachedGeode->clone(osg::CopyOp::DEEP_COPY_DRAWABLES)); 46 51 } 47 52 else 48 53 { 49 geo = processGeometry( geom ); 50 geometryMap.insert( std::make_pair( geom, geo ) ); 51 } 52 if ( geo == NULL ) 54 geode = processGeometry( geom ); 55 geometryMap.insert( std::make_pair( geom, geode ) ); 56 } 57 58 if ( geode == NULL ) 53 59 { 54 60 osg::notify( osg::WARN ) << "Failed to load geometry " << ig->getUrl().getURI() << std::endl; 55 61 return NULL; 56 62 } 57 //process material bindings 63 64 // process material bindings 58 65 if ( ig->getBind_material() != NULL ) 59 66 { 60 processBindMaterial( ig->getBind_material(), geo ); 61 } 62 63 return geo; 64 } 65 66 osg::Node* daeReader::processInstance_controller( domInstance_controller *ictrl ) 67 { 68 //TODO: cache geometries so they don't get processed mulitple times. 69 //TODO: after cached need to check geometries and materials. both have to be the same for it 70 // to be the same instance. 67 processBindMaterial( ig->getBind_material(), geom, geode ); 68 } 69 70 return geode; 71 } 72 73 // <controller> 74 // attributes: 75 // id, name 76 // elements: 77 // 0..1 <asset> 78 // 1 <skin>, <morph> 79 // 0..* <extra> 80 osg::Geode* daeReader::processInstanceController( domInstance_controller *ictrl ) 81 { 71 82 //TODO: support skinning 72 73 osg::notify( osg::WARN ) << "Processing <instance_controller>. There is not skinning support but will display the base mesh." << std::endl; 74 daeElement *el = getElementFromURI( ictrl->getUrl() ); 83 daeElement *el = getElementFromURI( ictrl->getUrl()); 75 84 domController *ctrl = daeSafeCast< domController >( el ); 76 85 if ( ctrl == NULL ) 77 86 { 78 osg::notify( osg::WARN ) << "Failed to locate controller " << ictrl->getUrl().getURI() << std::endl; 79 return NULL; 80 } 87 osg::notify( osg::WARN ) << "Failed to locate conroller " << ictrl->getUrl().getURI() << std::endl; 88 return NULL; 89 } 90 91 osg::notify( osg::WARN ) << "Processing <controller>. There is not skinning support but will display the base mesh." << std::endl; 92 81 93 el = NULL; 82 //## non init94 //## non init 83 95 daeURI *src=NULL; 84 96 if ( ctrl->getSkin() != NULL ) … … 92 104 el = getElementFromURI( ctrl->getMorph()->getSource() ); 93 105 } 94 //non init case 95 if ( !src ) 96 { 97 osg::notify( osg::WARN ) << "Failed to locate geometry : URI is NULL" << std::endl; 98 return NULL; 99 } 106 107 //non init case 108 if ( !src ) 109 { 110 osg::notify( osg::WARN ) << "Failed to locate geometry : URI is NULL" << std::endl; 111 return NULL; 112 } 100 113 101 114 domGeometry *geom = daeSafeCast< domGeometry >( el ); … … 105 118 return NULL; 106 119 } 107 osg::Node *geo; 108 109 std::map< domGeometry*, osg::Node* >::iterator iter = geometryMap.find( geom ); 120 121 // Check cache if geometry already exists 122 osg::Geode *geode; 123 124 domGeometryGeodeMap::iterator iter = geometryMap.find( geom ); 110 125 if ( iter != geometryMap.end() ) 111 126 { 112 geo = iter->second; 127 osg::Geode* cachedGeode = iter->second; 128 129 // Create a copy of the cached Geode with a copy of the drawables, 130 // because the may be using a different material. 131 // TODO Cloning is not necessary if the material layouts are exactly the same. 132 // To check this we need to compare the material bindings used by the cached Geode 133 // and this new instance_geometry material bindings. 134 geode = static_cast<osg::Geode*>(cachedGeode->clone(osg::CopyOp::DEEP_COPY_DRAWABLES)); 113 135 } 114 136 else 115 137 { 116 geo = processGeometry( geom ); 117 geometryMap.insert( std::make_pair( geom, geo ) ); 118 } 119 if ( geo == NULL ) 138 geode = processGeometry( geom ); 139 geometryMap.insert( std::make_pair( geom, geode ) ); 140 } 141 142 if ( geode == NULL ) 120 143 { 121 144 osg::notify( osg::WARN ) << "Failed to load geometry " << src->getURI() << std::endl; … … 125 148 if ( ictrl->getBind_material() != NULL ) 126 149 { 127 processBindMaterial( ictrl->getBind_material(), geo ); 128 } 129 130 return geo; 131 } 132 133 osg::Node *daeReader::processGeometry( domGeometry *geo ) 150 processBindMaterial( ictrl->getBind_material(), geom, geode ); 151 } 152 153 return geode; 154 } 155 156 // <geometry> 157 // attributes: 158 // id, name 159 // elements: 160 // 0..1 <asset> 161 // 1 <convex_mesh>, <mesh>, <spline> 162 // 0..* <extra> 163 osg::Geode *daeReader::processGeometry( domGeometry *geo ) 134 164 { 135 165 domMesh *mesh = geo->getMesh(); … … 139 169 return NULL; 140 170 } 141 osg::Node *node = new osg::Group(); 142 143 if ( geo->getId() != NULL ) 144 { 145 node->setName( geo->getId() ); 146 } 147 171 172 osg::Geode* geode = new osg::Geode; 173 if (geo->getId() != NULL ) 174 { 175 geode->setName( geo->getId() ); 176 } 177 178 // <mesh> 179 // elements: 180 // 1..* <source> 181 // 1 <vertices> 182 // 0..* <lines>, <linestrips>, <polygons>, <polylist>, <triangles>, <trifans>, <tristrips> 183 // 0..* <extra> 184 size_t count = mesh->getContents().getCount(); 185 186 // 1..* <source> 148 187 SourceMap sources; 149 150 size_t count = mesh->getContents().getCount(); 151 for ( size_t i = 0; i < count; i++ ) 152 { 153 if ( daeSafeCast< domVertices >( mesh->getContents()[i] ) != NULL ) continue; 154 155 domSource *s = daeSafeCast< domSource >( mesh->getContents()[i] ); 156 if ( s != NULL ) 157 { 158 sources.insert( std::make_pair( (daeElement*)mesh->getContents()[i], 159 domSourceReader( s ) ) ); 160 continue; 161 } 162 163 osg::Node *n = NULL; 164 165 domTriangles *t = daeSafeCast< domTriangles >( mesh->getContents()[i] ); 166 if ( t != NULL ) 167 { 168 n = processSinglePPrimitive( t, sources, GL_TRIANGLES ); 169 if ( n != NULL ) 170 { 171 node->asGroup()->addChild( n ); 172 } 173 continue; 174 } 175 176 domTristrips *ts = daeSafeCast< domTristrips >( mesh->getContents()[i] ); 177 if ( ts != NULL ) 178 { 179 n = processMultiPPrimitive( ts, sources, GL_TRIANGLE_STRIP ); 180 if ( n != NULL ) 181 { 182 node->asGroup()->addChild( n ); 183 } 184 continue; 185 } 186 187 domTrifans *tf = daeSafeCast< domTrifans >( mesh->getContents()[i] ); 188 if ( tf != NULL ) 189 { 190 n = processMultiPPrimitive( tf, sources, GL_TRIANGLE_FAN ); 191 if ( n != NULL ) 192 { 193 node->asGroup()->addChild( n ); 194 } 195 continue; 196 } 197 198 domLines *l = daeSafeCast< domLines >( mesh->getContents()[i] ); 199 if ( l != NULL ) 200 { 201 n = processSinglePPrimitive( l, sources, GL_LINES ); 202 if ( n != NULL ) 203 { 204 node->asGroup()->addChild( n ); 205 } 206 continue; 207 } 208 209 domLinestrips *ls = daeSafeCast< domLinestrips >( mesh->getContents()[i] ); 210 if ( ls != NULL ) 211 { 212 n = processMultiPPrimitive( ls, sources, GL_LINE_STRIP ); 213 if ( n != NULL ) 214 { 215 node->asGroup()->addChild( n ); 216 } 217 continue; 218 } 219 220 domPolygons *p = daeSafeCast< domPolygons >( mesh->getContents()[i] ); 221 if ( p != NULL ) 222 { 223 n = processMultiPPrimitive( p, sources, GL_POLYGON ); 224 if ( n != NULL ) 225 { 226 node->asGroup()->addChild( n ); 227 } 228 continue; 229 } 230 231 domPolylist *pl = daeSafeCast< domPolylist >( mesh->getContents()[i] ); 232 if ( pl != NULL ) 233 { 234 n = processPolylist( pl, sources ); 235 if ( n != NULL ) 236 { 237 node->asGroup()->addChild( n ); 238 } 239 continue; 240 } 241 242 osg::notify( osg::WARN ) << "Unsupported primitive type " << mesh->getContents()[i]->getTypeName() << " in geometry " << geo->getId() << std::endl; 243 } 244 245 return node; 246 } 188 domSource_Array sourceArray = mesh->getSource_array(); 189 for ( size_t i = 0; i < sourceArray.getCount(); i++) 190 { 191 sources.insert( std::make_pair((daeElement*)sourceArray[i], domSourceReader( sourceArray[i] ) ) ); 192 } 193 194 // 0..* <lines> 195 domLines_Array linesArray = mesh->getLines_array(); 196 for ( size_t i = 0; i < linesArray.getCount(); i++) 197 { 198 processSinglePPrimitive<domLines>(geode, linesArray[i], sources, GL_LINES ); 199 } 200 201 // 0..* <linestrips> 202 domLinestrips_Array linestripsArray = mesh->getLinestrips_array(); 203 for ( size_t i = 0; i < linestripsArray.getCount(); i++) 204 { 205 processMultiPPrimitive<domLinestrips>(geode, linestripsArray[i], sources, GL_LINE_STRIP ); 206 } 207 208 // 0..* <polygons> 209 domPolygons_Array polygonsArray = mesh->getPolygons_array(); 210 for ( size_t i = 0; i < polygonsArray.getCount(); i++) 211 { 212 processMultiPPrimitive<domPolygons>(geode, polygonsArray[i], sources, GL_POLYGON ); 213 } 214 215 // 0..* <polylist> 216 domPolylist_Array polylistArray = mesh->getPolylist_array(); 217 for ( size_t i = 0; i < polylistArray.getCount(); i++) 218 { 219 processPolylist(geode, polylistArray[i], sources ); 220 } 221 222 // 0..* <triangles> 223 domTriangles_Array trianglesArray = mesh->getTriangles_array(); 224 for ( size_t i = 0; i < trianglesArray.getCount(); i++) 225 { 226 processSinglePPrimitive<domTriangles>(geode, trianglesArray[i], sources, GL_TRIANGLES ); 227 } 228 229 // 0..* <trifans> 230 domTrifans_Array trifansArray = mesh->getTrifans_array(); 231 for ( size_t i = 0; i < trifansArray.getCount(); i++) 232 { 233 processMultiPPrimitive<domTrifans>(geode, trifansArray[i], sources, GL_TRIANGLE_FAN ); 234 } 235 236 // 0..* <tristrips> 237 domTristrips_Array tristripsArray = mesh->getTristrips_array(); 238 for ( size_t i = 0; i < tristripsArray.getCount(); i++) 239 { 240 processMultiPPrimitive<domTristrips>(geode, tristripsArray[i], sources, GL_TRIANGLE_STRIP ); 241 } 242 243 return geode; 244 } 245 247 246 248 247 template< typename T > 249 osg::Node* daeReader::processSinglePPrimitive( T *group, SourceMap &sources, GLenum mode ) 250 { 251 osg::Geode* geode = new osg::Geode(); 248 void daeReader::processSinglePPrimitive(osg::Geode* geode, T *group, SourceMap &sources, GLenum mode ) 249 { 252 250 osg::Geometry *geometry = new osg::Geometry(); 253 254 //Setting the name of the geode to the material symbol for easy binding later 255 if ( group->getMaterial() != NULL ) 256 { 257 geode->setName( group->getMaterial() ); 258 } 251 geometry->setName(group->getMaterial()); 259 252 260 253 IndexMap index_map; … … 266 259 267 260 geode->addDrawable( geometry ); 268 return geode;269 261 } 270 262 271 263 template< typename T > 272 osg::Node* daeReader::processMultiPPrimitive( T *group, SourceMap &sources, GLenum mode ) 273 { 274 osg::Geode* geode = new osg::Geode(); 264 void daeReader::processMultiPPrimitive(osg::Geode* geode, T *group, SourceMap &sources, GLenum mode ) 265 { 275 266 osg::Geometry *geometry = new osg::Geometry(); 276 277 //Setting the name of the geode to the material symbol for easy binding later 278 if ( group->getMaterial() != NULL ) 279 { 280 geode->setName( group->getMaterial() ); 281 } 267 geometry->setName(group->getMaterial()); 282 268 283 269 IndexMap index_map; … … 293 279 294 280 geode->addDrawable( geometry ); 295 return geode; 296 } 297 298 osg::Node* daeReader::processPolylist( domPolylist *group, SourceMap &sources ) 299 { 300 osg::Geode* geode = new osg::Geode(); 281 } 282 283 void daeReader::processPolylist(osg::Geode* geode, domPolylist *group, SourceMap &sources ) 284 { 301 285 osg::Geometry *geometry = new osg::Geometry(); 302 303 //Setting the name of the geode to the material symbol for easy binding later 304 if ( group->getMaterial() != NULL ) 305 { 306 geode->setName( group->getMaterial() ); 307 } 286 geometry->setName(group->getMaterial()); 308 287 309 288 IndexMap index_map; … … 343 322 344 323 geode->addDrawable( geometry ); 345 return geode;346 324 } 347 325 348 326 void daeReader::processP( domP *p, osg::Geometry *&/*geom*/, IndexMap &index_map, osg::DrawArrayLengths* dal /*GLenum mode*/ ) 349 327 { 350 //osg::DrawArrayLengths* dal = new osg::DrawArrayLengths( mode );351 328 int idxcount = index_map.size(); 352 329 int count = p->getValue().getCount(); … … 361 338 } 362 339 } 363 //geom->addPrimitiveSet( dal );364 340 } 365 341 … … 378 354 domInputLocalOffset *tmp_input; 379 355 380 if ( findInputSourceBySemantic( inputs, "VERTEX", tmp_el, &tmp_input ) ) { 356 if ( findInputSourceBySemantic( inputs, "VERTEX", tmp_el, &tmp_input ) ) 357 { 381 358 vertices = daeSafeCast< domVertices >( tmp_el ); 382 if ( vertices == NULL ) { 359 if ( vertices == NULL ) 360 { 383 361 osg::notify( osg::WARN )<<"Could not get vertices"<<std::endl; 384 362 return; … … 394 372 findInputSourceBySemantic( vertices->getInput_array(), "TEXCOORD", texcoord_source, &tmp ); 395 373 396 if ( index_map[offset] == NULL ) { 374 if ( index_map[offset] == NULL ) 375 { 397 376 index_map[offset] = new osg::IntArray(); 398 377 } … … 437 416 } 438 417 439 440 if ( findInputSourceBySemantic( inputs, "COLOR", color_source, &tmp_input ) ) { 441 418 if ( findInputSourceBySemantic( inputs, "COLOR", color_source, &tmp_input )) 419 { 442 420 offset = tmp_input->getOffset(); 443 421 if ( index_map[offset] == NULL ) { … … 447 425 } 448 426 449 if ( color_source != NULL ) { 427 if ( color_source != NULL ) 428 { 450 429 geom->setColorArray( sources[color_source].getVec4Array() ); 451 430 geom->setColorBinding( osg::Geometry::BIND_PER_VERTEX ); 452 431 } 453 432 454 if ( findInputSourceBySemantic( inputs, "NORMAL", normal_source, &tmp_input ) ) {455 433 if ( findInputSourceBySemantic( inputs, "NORMAL", normal_source, &tmp_input ) ) 434 { 456 435 offset = tmp_input->getOffset(); 457 if ( index_map[offset] == NULL ) { 436 if ( index_map[offset] == NULL ) 437 { 458 438 index_map[offset] = new osg::IntArray(); 459 439 } … … 461 441 } 462 442 463 if ( normal_source ) { 443 if ( normal_source ) 444 { 464 445 geom->setNormalArray( sources[normal_source].getVec3Array() ); 465 446 geom->setNormalBinding( osg::Geometry::BIND_PER_VERTEX ); … … 467 448 468 449 int unit = 0; 469 while ( findInputSourceBySemantic( inputs, "TEXCOORD", texcoord_source, &tmp_input, unit ) ) {470 450 while ( findInputSourceBySemantic( inputs, "TEXCOORD", texcoord_source, &tmp_input, unit ) ) 451 { 471 452 offset = tmp_input->getOffset(); 472 453 set = tmp_input->getSet(); 473 454 474 if ( index_map[offset] == NULL ) { 455 if ( index_map[offset] == NULL ) 456 { 475 457 index_map[offset] = new osg::IntArray(); 476 458 } -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeRMaterials.cpp
r8353 r9228 30 30 using namespace osgdae; 31 31 32 void daeReader::processBindMaterial( domBind_material *bm, osg::Node *geo ) 32 33 // <bind_material> 34 // elements: 35 // 0..* <param> 36 // name 37 // sid 38 // semantic 39 // type 40 // 1 <technique_common> 41 // 0..* <instance_material> 42 // symbol 43 // target 44 // sid 45 // name 46 // 0..* <technique> 47 // profile 48 // 0..* <extra> 49 // id 50 // name 51 // type 52 void daeReader::processBindMaterial( domBind_material *bm, domGeometry *geom, osg::Geode *geode ) 33 53 { 34 if ( bm->getTechnique_common() == NULL )54 if (bm->getTechnique_common() == NULL ) 35 55 { 36 56 osg::notify( osg::WARN ) << "No COMMON technique for bind_material" << std::endl; 37 57 return; 38 58 } 39 osg::Group *group = geo->asGroup(); 40 if ( group == NULL ) 41 { 42 //this shouldn't happen unless something is terribly wrong 43 return; 44 } 45 domInstance_material_Array &ima = bm->getTechnique_common()->getInstance_material_array(); 46 size_t count = ima.getCount(); 47 for ( size_t i = 0; i < count; i++ ) 48 { 49 std::string symbol = ima[i]->getSymbol(); 50 domMaterial *mat = daeSafeCast< domMaterial >( getElementFromURI( ima[i]->getTarget() ) ); 51 if ( mat == NULL ) 52 { 53 osg::notify( osg::WARN ) << "Failed to locate material " << ima[i]->getTarget().getURI() << std::endl; 54 continue; 55 } 56 osg::StateSet *ss; 57 //check material cache if this material already exists 58 std::map< domMaterial*, osg::StateSet*>::iterator iter = materialMap.find( mat ); 59 if ( iter != materialMap.end() ) 60 { 61 ss = iter->second; 62 } 63 else 64 { 65 ss = processMaterial( mat ); 66 materialMap.insert( std::make_pair( mat, ss ) ); 67 } 68 if ( ss == NULL ) 69 { 70 continue; 71 } 72 //TODO: process all of the <bind>s and <bind_vertex_input>s that are here in the instance_material. 73 74 for ( unsigned int x = 0; x < group->getNumChildren(); x++ ) 75 { 76 //I named the geode with the material symbol so I can do this check for binding 77 if ( group->getChild( x )->getName() == symbol ) 78 { 79 /*if ( group->getChild( x )->getStateSet() != NULL ) 59 60 for (size_t i =0; i < geode->getNumDrawables(); i++) 61 { 62 osg::Drawable* drawable = geode->getDrawable(i); 63 std::string materialName = drawable->getName(); 64 65 domInstance_material_Array &ima = bm->getTechnique_common()->getInstance_material_array(); 66 std::string symbol; 67 bool found = false; 68 for ( size_t j = 0; j < ima.getCount(); j++) 69 { 70 symbol = ima[j]->getSymbol(); 71 if (symbol.compare(materialName) == 0) 72 { 73 found = true; 74 domMaterial *mat = daeSafeCast< domMaterial >(getElementFromURI( ima[j]->getTarget())); 75 if (mat) 80 76 { 81 //already have a stateSet this means I am an instance so clone me. 82 group->replaceChild( group->getChild( x ), (osg::Node*)group->getChild( x )->cloneType() ); 83 }*/ 84 group->getChild( x )->setStateSet( ss ); 85 } 77 // Check material cache if this material already exists 78 domMaterialStateSetMap::iterator iter = materialMap.find( mat ); 79 if ( iter != materialMap.end() ) 80 { 81 // Reuse material 82 drawable->setStateSet(iter->second); 83 } 84 else 85 { 86 // Create new material 87 osg::StateSet* ss = new osg::StateSet; 88 processMaterial(ss, mat); 89 drawable->setStateSet(ss); 90 materialMap.insert(std::make_pair(mat, ss)); 91 } 92 } 93 else 94 { 95 osg::notify( osg::WARN ) << "Failed to locate <material> wit id " << ima[i]->getTarget().getURI() << std::endl; 96 } 97 98 break; 99 } 100 } 101 if (!found) 102 { 103 osg::notify( osg::WARN ) << "Failed to locate <instance_material> with symbol " << materialName << std::endl; 86 104 } 87 105 } 88 106 } 89 107 90 osg::StateSet *daeReader::processMaterial( domMaterial *mat ) 108 // <material> 109 // attributes: 110 // 0..1 id 111 // 0..1 name 112 // elements: 113 // 0..1 <asset> 114 // 1 <instance_effect> 115 // 0..* <extra> 116 void daeReader::processMaterial(osg::StateSet *ss, domMaterial *mat ) 91 117 { 92 118 currentInstance_effect = mat->getInstance_effect(); 93 119 domEffect *effect = daeSafeCast< domEffect >( getElementFromURI( currentInstance_effect->getUrl() ) ); 94 if ( effect == NULL ) 120 if (effect) 121 { 122 processEffect(ss, effect); 123 124 //TODO: process all of the setParams that could happen here in the material. ESP. the textures 125 } 126 else 95 127 { 96 128 osg::notify( osg::WARN ) << "Failed to locate effect " << mat->getInstance_effect()->getUrl().getURI() << std::endl; 97 return NULL; 98 } 99 osg::StateSet *ss = processEffect( effect ); 100 101 //TODO: process all of the setParams that could happen here in the material. ESP. the textures 102 103 return ss; 129 } 104 130 } 105 131 106 osg::StateSet *daeReader::processEffect( domEffect *effect ) 132 // <effect> 133 // attributes: 134 // 1 id 135 // 0..1 name 136 // elements: 137 // 0..1 <asset> 138 // 0..* <annotate> 139 // 0..* <image> 140 // 0..* <newparam> 141 // 1..* <fx_profile_abstract> 142 // 0..* <extra> 143 void daeReader::processEffect(osg::StateSet *ss, domEffect *effect ) 107 144 { 108 145 bool hasCOMMON = false; 109 osg::StateSet *ss = NULL;110 146 111 147 for ( size_t i = 0; i < effect->getFx_profile_abstract_array().getCount(); i++ ) … … 120 156 } 121 157 currentEffect = effect; 122 ss = processProfileCOMMON( pc);158 processProfileCOMMON(ss, pc); 123 159 hasCOMMON = true; 124 160 continue; … … 127 163 osg::notify( osg::WARN ) << "unsupported effect profile " << effect->getFx_profile_abstract_array()[i]->getTypeName() << std::endl; 128 164 } 129 130 return ss;131 165 } 132 166 133 osg::StateSet *daeReader::processProfileCOMMON( domProfile_COMMON *pc ) 167 // <profile_COMMON> 168 // elements: 169 // 0..* <image>, <newparam> 170 // 1 <technique> 171 // attributes: 172 // elements: 173 // 0..1 <asset> 174 // 0..* <image>, <newparam> 175 // 1 <constant>, <lambert>, <phong>, <blinn> 176 // 0..* <extra> 177 // 0..* <extra> 178 void daeReader::processProfileCOMMON(osg::StateSet *ss, domProfile_COMMON *pc ) 134 179 { 135 osg::StateSet *ss = new osg::StateSet();136 137 180 domProfile_COMMON::domTechnique *teq = pc->getTechnique(); 138 181 … … 144 187 ss->setMode( GL_CULL_FACE, GL_TRUE ); 145 188 146 if (m_AuthoringTool == GOOGLE_SKETCHUP) 147 { 148 const domExtra_Array& ExtraArray = pc->getExtra_array(); 149 size_t NumberOfExtras = ExtraArray.getCount(); 150 size_t CurrentExtra; 151 for (CurrentExtra = 0; CurrentExtra < NumberOfExtras; CurrentExtra++) 152 { 153 const domTechnique_Array& TechniqueArray = ExtraArray[CurrentExtra]->getTechnique_array(); 154 size_t NumberOfTechniques = TechniqueArray.getCount(); 155 size_t CurrentTechnique; 156 for (CurrentTechnique = 0; CurrentTechnique < NumberOfTechniques; CurrentTechnique++) 157 { 158 if (strcmp(TechniqueArray[CurrentTechnique]->getProfile(), "GOOGLEEARTH") == 0) 189 // See if there are any extra's that are supported by OpenSceneGraph 190 const domExtra_Array& ExtraArray = pc->getExtra_array(); 191 size_t NumberOfExtras = ExtraArray.getCount(); 192 size_t CurrentExtra; 193 for (CurrentExtra = 0; CurrentExtra < NumberOfExtras; CurrentExtra++) 194 { 195 const domTechnique_Array& TechniqueArray = ExtraArray[CurrentExtra]->getTechnique_array(); 196 size_t NumberOfTechniques = TechniqueArray.getCount(); 197 size_t CurrentTechnique; 198 for (CurrentTechnique = 0; CurrentTechnique < NumberOfTechniques; CurrentTechnique++) 199 { 200 // <technique profile="GOOGLEEARTH"> 201 // <double_sided>0</double_sided> 202 // </technique> 203 if (strcmp(TechniqueArray[CurrentTechnique]->getProfile(), "GOOGLEEARTH") == 0) 204 { 205 const daeElementRefArray& ElementArray = TechniqueArray[CurrentTechnique]->getContents(); 206 size_t NumberOfElements = ElementArray.getCount(); 207 size_t CurrentElement; 208 for (CurrentElement = 0; CurrentElement < NumberOfElements; CurrentElement++) 159 209 { 160 const daeElementRefArray& ElementArray = TechniqueArray[CurrentTechnique]->getContents(); 161 size_t NumberOfElements = ElementArray.getCount(); 162 size_t CurrentElement; 163 for (CurrentElement = 0; CurrentElement < NumberOfElements; CurrentElement++) 210 domAny* pAny = (domAny*)ElementArray[CurrentElement].cast(); 211 if (strcmp(pAny->getElementName(), "double_sided") == 0) 164 212 { 165 domAny* pAny = (domAny*)ElementArray[CurrentElement].cast(); 166 if (strcmp(pAny->getElementName(), "double_sided") == 0) 167 { 168 daeString Value = pAny->getValue(); 169 if (strcmp(Value, "1") == 0) 170 ss->setMode( GL_CULL_FACE, GL_FALSE ); 171 } 213 daeString Value = pAny->getValue(); 214 if (strcmp(Value, "1") == 0) 215 ss->setMode( GL_CULL_FACE, GL_FALSE ); 172 216 } 173 217 } … … 176 220 } 177 221 178 //ss->setMode( GL_LIGHTING, GL_FALSE );179 180 222 osg::ref_ptr< osg::Material > mat = new osg::Material(); 181 223 bool insertMat = false; 224 // <blinn> 225 // elements: 226 // 0..1 <emission> 227 // 0..1 <ambient> 228 // 0..1 <diffuse> 229 // 0..1 <specular> 230 // 0..1 <shininess> 231 // 0..1 <reflective> 232 // 0..1 <reflectivity> 233 // 0..1 <transparent> 234 // 0..1 <transparency> 235 // 0..1 <index_of_refraction> 182 236 if ( b != NULL ) 183 237 { … … 198 252 } 199 253 200 tmp = processColorOrTextureType( b->getSpecular(), osg::Material::SPECULAR, mat.get(), b->getShininess() );254 tmp = processColorOrTextureType( b->getSpecular(), osg::Material::SPECULAR, mat.get(), b->getShininess(), NULL, true ); 201 255 insertMat = insertMat || tmp; 202 256 … … 215 269 } 216 270 } 217 218 } 271 } 272 // <phong> 273 // elements: 274 // 0..1 <emission> 275 // 0..1 <ambient> 276 // 0..1 <diffuse> 277 // 0..1 <specular> 278 // 0..1 <shininess> 279 // 0..1 <reflective> 280 // 0..1 <reflectivity> 281 // 0..1 <transparent> 282 // 0..1 <transparency> 283 // 0..1 <index_of_refraction> 219 284 else if ( p != NULL ) 220 285 { … … 223 288 insertMat = insertMat || tmp; 224 289 225 tmp = processColorOrTextureType( p->getAmbient(), osg::Material::AMBIENT, mat.get() ); 290 osg::StateAttribute *sa1 = NULL; 291 tmp = processColorOrTextureType( p->getAmbient(), osg::Material::AMBIENT, mat.get(), NULL, &sa1 ); 226 292 insertMat = insertMat || tmp; 293 if ( sa1 != NULL ) 294 { 295 ss->setTextureMode( 1, GL_TEXTURE_2D, GL_TRUE ); 296 ss->setTextureAttribute( 0, sa1 ); 297 } 227 298 228 299 osg::StateAttribute *sa = NULL; … … 254 325 255 326 } 327 // <lambert> 328 // elements: 329 // 0..1 <emission> 330 // 0..1 <ambient> 331 // 0..1 <diffuse> 332 // 0..1 <reflective> 333 // 0..1 <reflectivity> 334 // 0..1 <transparent> 335 // 0..1 <transparency> 336 // 0..1 <index_of_refraction> 256 337 else if ( l != NULL ) 257 338 { … … 288 369 289 370 } 371 // <constant> 372 // elements: 373 // 0..1 <emission> 374 // 0..1 <reflective> 375 // 0..1 <reflectivity> 376 // 0..1 <transparent> 377 // 0..1 <transparency> 378 // 0..1 <index_of_refraction> 290 379 else if ( c != NULL ) 291 380 { … … 304 393 ss->setAttribute( mat.get() ); 305 394 } 306 307 return ss;308 395 } 309 396 310 bool daeReader::processColorOrTextureType( domCommon_color_or_texture_type *cot, 311 osg::Material::ColorMode channel, 312 osg::Material *mat, 313 domCommon_float_or_param_type *fop, 314 osg::StateAttribute **sa ) 397 // colorOrTexture 398 // 1 of 399 // <color> 400 // <param> 401 // attributes: 402 // 1 ref 403 // <texture> 404 // attributes: 405 // 1 texture 406 // 1 texcoord 407 // 0..* extra 408 bool daeReader::processColorOrTextureType( domCommon_color_or_texture_type *cot, 409 osg::Material::ColorMode channel, 410 osg::Material *mat, 411 domCommon_float_or_param_type *fop, 412 osg::StateAttribute **sa, 413 bool blinn) 315 414 { 316 415 if ( cot == NULL ) … … 319 418 } 320 419 bool retVal = false; 420 321 421 //osg::StateAttribute *sa = NULL; 322 422 //TODO: Make all channels process <param ref=""> type of value … … 329 429 retVal = true; 330 430 } 331 332 431 else if (cot->getParam() != NULL) 333 432 { … … 339 438 } 340 439 } 341 else 440 else if (cot->getTexture() != NULL) 342 441 { 343 442 osg::notify( osg::WARN ) << "Currently no support for <texture> in Emission channel " << std::endl; 344 443 } 444 else 445 { 446 osg::notify( osg::WARN ) << "Missing <color>, <param> or <texture> in Emission channel " << std::endl; 447 } 345 448 } 346 449 else if ( channel == osg::Material::AMBIENT ) … … 361 464 } 362 465 } 466 else if (cot->getTexture() != NULL && sa != NULL) 467 { 468 *sa = processTexture( cot->getTexture() ); 469 //osg::notify( osg::WARN ) << "Currently no support for <texture> in Ambient channel " << std::endl; 470 } 363 471 else 364 472 { 365 osg::notify( osg::WARN ) << " Currently no support for <texture> in Ambient channel " << std::endl;473 osg::notify( osg::WARN ) << "Missing <color>, <param> or <texture> in Ambient channel " << std::endl; 366 474 } 367 475 } … … 378 486 *sa = processTexture( cot->getTexture() ); 379 487 domExtra *extra = cot->getTexture()->getExtra(); 380 if ( extra != NULL && extra->getType() != NULL && 381 strcmp( extra->getType(), "color" ) == 0 ) 488 if ( extra != NULL && extra->getType() != NULL && strcmp( extra->getType(), "color" ) == 0 ) 382 489 { 383 490 //the extra data for osg. Diffuse color can happen with a texture. … … 407 514 } 408 515 } 516 else 517 { 518 osg::notify( osg::WARN ) << "Missing <color>, <param> or <texture> in Diffuse channel " << std::endl; 519 } 409 520 } 410 521 else if ( channel == osg::Material::SPECULAR ) … … 416 527 retVal = true; 417 528 } 418 else if (cot->getParam() != NULL)529 else if (cot->getParam() != NULL) 419 530 { 420 531 domFloat4 f4; … … 425 536 } 426 537 } 427 else538 else if (cot->getTexture() != NULL) 428 539 { 429 540 osg::notify( osg::WARN ) << "Currently no support for <texture> in Specular channel " << std::endl; 430 541 } 542 else 543 { 544 osg::notify( osg::WARN ) << "Missing <color>, <param> or <texture> in Specular channel " << std::endl; 545 } 546 431 547 if ( fop != NULL && fop->getFloat() != NULL ) 432 548 { 433 mat->setShininess( osg::Material::FRONT_AND_BACK, fop->getFloat()->getValue() ); 549 float shininess = fop->getFloat()->getValue(); 550 if (blinn) 551 { 552 // If the blinn mode is in the range [0,1] rescale it to [0,128] 553 if (shininess < 1) 554 shininess *= 128.0f; 555 } 556 mat->setShininess( osg::Material::FRONT_AND_BACK, shininess ); 434 557 retVal = true; 435 558 } … … 809 932 } 810 933 934 935 /* 936 Collada 1.4.1 Specification (2nd Edition) Patch Release Notes: Revision C Release notes 937 938 In <blinn>, <constant>, <lambert>, and <phong>, the child element <transparent> now has an 939 optional opaque attribute whose valid values are: 940 A_ONE (the default): Takes the transparency information from the colors alpha channel, where the value 1.0 is opaque. 941 RGB_ZERO: Takes the transparency information from the colors red, green, and blue channels, where the value 0.0 is opaque, 942 with each channel modulated independently. 943 In the Specification, this is described in the FX Reference chapter in the 944 common_color_or_texture_type entry, along with a description of how transparency works in the 945 Getting Started with COLLADA FX chapter in the Determining Transparency section. 946 947 948 Collada Digital Asset Schema Release 1.5.0 Release Notes 949 950 The <transparent> elements opaque attribute now allows, in addition to A_ONE and RGB_ZERO, the following values: 951 A_ZERO (the default): Takes the transparency information from the colors alpha channel, where the value 0.0 is opaque. 952 RGB_ONE: Takes the transparency information from the colors red, green, and blue channels, where the value 1.0 is opaque, 953 with each channel modulated independently. 954 */ 955 811 956 osg::StateAttribute *daeReader::processTransparencySettings( domCommon_transparent_type *ctt, domCommon_float_or_param_type *pTransparency, osg::StateSet *ss ) 812 957 { … … 882 1027 } 883 1028 1029 if (FX_OPAQUE_ENUM_A_ONE == Opaque) 1030 { 1031 if (Transparency * f4[3] > 0.99f) 1032 // Material is really opaque so dont put it in the transparent bin 1033 return NULL; 1034 } 1035 else 1036 { 1037 if ((Transparency * f4[0] < 0.01f) && 1038 (Transparency * f4[1] < 0.01f) && 1039 (Transparency * f4[2] < 0.01f) && 1040 (Transparency * f4[3] < 0.01f)) 1041 // Material is really opaque so dont put it in the transparent bin 1042 return NULL; 1043 } 1044 884 1045 osg::BlendColor *bc = new osg::BlendColor(); 885 1046 bc->setConstantColor(osg::Vec4( f4[0] * Transparency, f4[1] * Transparency, f4[2] * Transparency, f4[3] * Transparency )); … … 893 1054 ss->setMode( GL_BLEND, GL_TRUE ); 894 1055 895 if (FX_OPAQUE_ENUM_A_ONE == Opaque)896 {897 if (Transparency * f4[3] > 0.99f)898 // Material is really opaque so dont put it in the transparent bin899 return NULL;900 }901 else902 {903 if ((Transparency * f4[0] < 0.01f) &&904 (Transparency * f4[1] < 0.01f) &&905 (Transparency * f4[2] < 0.01f) &&906 (Transparency * f4[3] < 0.01f))907 // Material is really opaque so dont put it in the transparent bin908 return NULL;909 }910 911 1056 ss->setRenderingHint( osg::StateSet::TRANSPARENT_BIN ); 912 1057 ss->setRenderBinDetails( 10, "DepthSortedBin" ); 913 1058 return NULL; 914 1059 } 1060 1061 // 0..* <extra> -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeRSceneObjects.cpp
r5465 r9228 14 14 #include "daeReader.h" 15 15 #include <dae.h> 16 #include <dae/domAny.h> 16 17 #include <dom/domCOLLADA.h> 17 18 … … 19 20 #include <osg/LightSource> 20 21 #include <osg/Geode> 21 #include <osg/Switch>22 22 #include <osg/ShapeDrawable> 23 #include <osg/LOD> 24 #include <osg/Billboard> 25 #include <osgSim/MultiSwitch> 26 #include <osg/Sequence> 23 27 24 28 using namespace osgdae; 25 29 30 osg::Node* daeReader::processOsgMultiSwitch(domTechnique* teq) 31 { 32 osgSim::MultiSwitch* msw = new osgSim::MultiSwitch; 33 34 domAny* any = daeSafeCast<domAny>(teq->getChild("ActiveSwitchSet")); 35 if (any) 36 { 37 msw->setActiveSwitchSet(parseString<unsigned int>(any->getValue())); 38 } 39 else 40 { 41 osg::notify(osg::WARN) << "Expected element 'ActiveSwitchSet' not found" << std::endl; 42 } 43 44 any = daeSafeCast<domAny>(teq->getChild("ValueLists")); 45 if (any) 46 { 47 unsigned int numChildren = any->getChildren().getCount(); 48 for (unsigned int currChild = 0; currChild < numChildren; currChild++) 49 { 50 domAny* child = daeSafeCast<domAny>(any->getChildren()[currChild]); 51 if (child) 52 { 53 if (strcmp(child->getElementName(), "ValueList" ) == 0 ) 54 { 55 std::list<std::string> stringValues; 56 osgSim::MultiSwitch::ValueList values; 57 58 cdom::tokenize(child->getValue(), " ", stringValues); 59 cdom::tokenIter iter = stringValues.begin(); 60 61 while (iter != stringValues.end()) 62 { 63 values.push_back(parseString<bool>(*iter)); 64 ++iter; 65 } 66 67 msw->setValueList(currChild, values); 68 } 69 else 70 { 71 osg::notify(osg::WARN) << "Child of element 'ValueLists' is not of type 'ValueList'" << std::endl; 72 } 73 } 74 else 75 { 76 osg::notify(osg::WARN) << "Element 'ValueLists' does not contain expected elements." << std::endl; 77 } 78 } 79 } 80 else 81 { 82 osg::notify(osg::WARN) << "Expected element 'ValueLists' not found" << std::endl; 83 } 84 return msw; 85 } 86 87 osg::Node* daeReader::processOsgSwitch(domTechnique* teq) 88 { 89 osg::Switch* sw = new osg::Switch; 90 91 domAny* any = daeSafeCast< domAny >(teq->getChild("ValueList")); 92 if (any) 93 { 94 std::list<std::string> stringValues; 95 96 cdom::tokenize(any->getValue(), " ", stringValues); 97 cdom::tokenIter iter = stringValues.begin(); 98 99 int pos = 0; 100 while (iter != stringValues.end()) 101 { 102 sw->setValue(pos++, parseString<bool>(*iter)); 103 ++iter; 104 } 105 } 106 else 107 { 108 osg::notify(osg::WARN) << "Expected element 'ValueList' not found" << std::endl; 109 } 110 return sw; 111 } 112 113 osg::Node* daeReader::processOsgSequence(domTechnique* teq) 114 { 115 osg::Sequence* sq = new osg::Sequence; 116 117 domAny* any = daeSafeCast< domAny >(teq->getChild("FrameTime")); 118 if (any) 119 { 120 std::list<std::string> stringValues; 121 122 cdom::tokenize(any->getValue(), " ", stringValues); 123 cdom::tokenIter iter = stringValues.begin(); 124 125 int frame = 0; 126 while (iter != stringValues.end()) 127 { 128 sq->setTime(frame++, parseString<double>(*iter)); 129 ++iter; 130 } 131 } 132 else 133 { 134 osg::notify(osg::WARN) << "Expected element 'FrameTime' not found" << std::endl; 135 } 136 137 any = daeSafeCast< domAny >(teq->getChild("LastFrameTime")); 138 if (any) 139 { 140 sq->setLastFrameTime(parseString<double>(any->getValue())); 141 } 142 else 143 { 144 osg::notify(osg::WARN) << "Expected element 'LastFrameTime' not found" << std::endl; 145 } 146 147 osg::Sequence::LoopMode loopmode; 148 any = daeSafeCast< domAny >(teq->getChild("LoopMode")); 149 if (any) 150 { 151 loopmode = (osg::Sequence::LoopMode)parseString<int>(any->getValue()); 152 } 153 else 154 { 155 osg::notify(osg::WARN) << "Expected element 'LoopMode' not found" << std::endl; 156 } 157 158 int begin=0; 159 any = daeSafeCast< domAny >(teq->getChild("IntervalBegin")); 160 if (any) 161 { 162 begin = parseString<int>(any->getValue()); 163 } 164 else 165 { 166 osg::notify(osg::WARN) << "Expected element 'IntervalBegin' not found" << std::endl; 167 } 168 169 int end=-1; 170 any = daeSafeCast< domAny >(teq->getChild("IntervalEnd")); 171 if (any) 172 { 173 end = parseString<int>(any->getValue()); 174 } 175 else 176 { 177 osg::notify(osg::WARN) << "Expected element 'IntervalEnd' not found" << std::endl; 178 } 179 180 sq->setInterval(loopmode, begin, end); 181 182 float speed = 0; 183 any = daeSafeCast< domAny >(teq->getChild("DurationSpeed")); 184 if (any) 185 { 186 speed = parseString<float>(any->getValue()); 187 } 188 else 189 { 190 osg::notify(osg::WARN) << "Expected element 'DurationSpeed' not found" << std::endl; 191 } 192 193 int nreps = -1; 194 any = daeSafeCast< domAny >(teq->getChild("DurationNReps")); 195 if (any) 196 { 197 nreps = parseString<int>(any->getValue()); 198 } 199 else 200 { 201 osg::notify(osg::WARN) << "Expected element 'DurationNReps' not found" << std::endl; 202 } 203 204 sq->setDuration(speed, nreps); 205 206 any = daeSafeCast< domAny >(teq->getChild("SequenceMode")); 207 if (any) 208 { 209 sq->setMode((osg::Sequence::SequenceMode)parseString<int>(any->getValue())); 210 } 211 else 212 { 213 osg::notify(osg::WARN) << "Expected element 'SequenceMode' not found" << std::endl; 214 } 215 216 return sq; 217 } 218 219 220 osg::Node* daeReader::processOsgLOD(domTechnique* teq) 221 { 222 osg::LOD* lod = new osg::LOD; 223 224 domAny* any = daeSafeCast< domAny >(teq->getChild("Center")); 225 if (any) 226 { 227 // If a center is specified 228 lod->setCenterMode(osg::LOD::USER_DEFINED_CENTER); 229 lod->setCenter(parseVec3String(any->getValue())); 230 231 any = daeSafeCast< domAny >(teq->getChild("Radius")); 232 if (any) 233 { 234 lod->setRadius(parseString<osg::LOD::value_type>(any->getValue())); 235 } 236 else 237 { 238 osg::notify(osg::WARN) << "Expected element 'Radius' not found" << std::endl; 239 } 240 } 241 242 any = daeSafeCast< domAny >(teq->getChild("RangeMode")); 243 if (any) 244 { 245 lod->setRangeMode((osg::LOD::RangeMode)parseString<int>(any->getValue())); 246 } 247 else 248 { 249 osg::notify(osg::WARN) << "Expected element 'RangeMode' not found" << std::endl; 250 } 251 252 any = daeSafeCast< domAny >(teq->getChild("RangeList")); 253 if (any) 254 { 255 osg::LOD::RangeList rangelist; 256 257 unsigned int numChildren = any->getChildren().getCount(); 258 for (unsigned int currChild = 0; currChild < numChildren; currChild++) 259 { 260 domAny* child = daeSafeCast<domAny>(any->getChildren()[currChild]); 261 if (child) 262 { 263 if (strcmp(child->getElementName(), "MinMax" ) == 0 ) 264 { 265 std::list<std::string> stringValues; 266 osg::LOD::MinMaxPair minMaxPair; 267 268 cdom::tokenize(child->getValue(), " ", stringValues); 269 cdom::tokenIter iter = stringValues.begin(); 270 271 if (iter != stringValues.end()) 272 { 273 minMaxPair.first = parseString<float>(*iter); 274 ++iter; 275 } 276 else 277 { 278 osg::notify(osg::WARN) << "'MinMax' does not contain a valid minimum value" << std::endl; 279 } 280 281 if (iter != stringValues.end()) 282 { 283 minMaxPair.second = parseString<float>(*iter); 284 } 285 else 286 { 287 osg::notify(osg::WARN) << "'MinMax' does not contain a valid maximum value" << std::endl; 288 } 289 290 rangelist.push_back(minMaxPair); 291 } 292 else 293 { 294 osg::notify(osg::WARN) << "Child of element 'RangeList' is not of type 'MinMax'" << std::endl; 295 } 296 } 297 else 298 { 299 osg::notify(osg::WARN) << "Element 'RangeList' does not contain expected elements." << std::endl; 300 } 301 } 302 303 lod->setRangeList(rangelist); 304 } 305 else 306 { 307 osg::notify(osg::WARN) << "Expected element 'RangeList' not found" << std::endl; 308 } 309 310 return lod; 311 } 312 313 // <light> 314 // attributes: 315 // id, name 316 // elements: 317 // 0..1 <asset> 318 // 1 <technique_common> 319 // 1 <ambient>, <directional>, <point>, <spot> 320 // 0..* <technique> 321 // 0..* <extra> 26 322 osg::Node* daeReader::processLight( domLight *dlight ) 27 323 { 324 osg::Node *node = new osg::Switch(); 325 28 326 //do light processing here. 29 327 domLight::domTechnique_common::domAmbient *ambient; … … 38 336 return NULL; 39 337 } 40 41 osg::Node* node = new osg::Switch();42 338 43 339 osg::Light* light = new osg::Light(); … … 183 479 } 184 480 185 osg::Node* daeReader::processCamera( domCamera* /*dcamera*/ ) 481 // <camera> 482 // attributes: 483 // id, name 484 // elements: 485 // 0..1 <asset> 486 // 1 <optics> 487 // 1 <technique_common> 488 // 1 <orthographic>, <perspective> 489 // 0..* <technique> 490 // 0..* <extra> 491 // 0..* <imager> 492 // 1 <technique> 493 // 0..* <extra> 494 // 0..* <extra> 495 osg::Node* daeReader::processCamera( domCamera * dcamera ) 186 496 { 497 osg::Node *node = new osg::Switch(); 498 187 499 //TODO: Make the camera actually make a camera to view from. Not just draw a cone. 188 osg::Node *node = new osg::Switch();189 190 500 osg::Cone* cone = new osg::Cone(); 191 501 -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeRTransforms.cpp
r5465 r9228 14 14 #include "daeReader.h" 15 15 #include <dae.h> 16 #include <dae/domAny.h> 16 17 #include <dom/domCOLLADA.h> 17 18 18 #include <osg/PositionAttitudeTransform>19 19 #include <osg/MatrixTransform> 20 #include <osgSim/DOFTransform> 20 21 21 22 using namespace osgdae; 22 23 23 osg::Transform* daeReader::processMatrix( domMatrix *mat ) 24 // Note <lookat>, <matrix>, <rotate>, <scale>, <skew> and <translate> may appear in any order 25 // These transformations can be combined in any number and ordering to produce the desired 26 // coordinate systemfor the parent <node> element. The COLLADA specificatin requires that the 27 // transformation elements are processed in order and accumulate the result as if they were 28 // converted to column-order matrices and concatenated using matrix post-multiplication. 29 osg::Node* daeReader::processOsgMatrixTransform( domNode *node ) 24 30 { 25 osg::Transform* xform = new osg::MatrixTransform(); 26 xform->setDataVariance(osg::Object::STATIC); 27 28 xform->setName( mat->getSid() ? mat->getSid() : "" ); 29 30 osg::Matrix m; 31 32 if (mat->getValue().getCount() != 16 ) { 33 osg::notify(osg::WARN)<<"Data is wrong size for matrix"<<std::endl; 34 return NULL; 35 } 36 37 //m.set((daeDouble*)mat->getValue().getRawData()); 38 m.set( mat->getValue()[0], mat->getValue()[4], mat->getValue()[8], mat->getValue()[12], 39 mat->getValue()[1], mat->getValue()[5], mat->getValue()[9], mat->getValue()[13], 40 mat->getValue()[2], mat->getValue()[6], mat->getValue()[10], mat->getValue()[14], 41 mat->getValue()[3], mat->getValue()[7], mat->getValue()[11], mat->getValue()[15] ); 42 43 xform->asMatrixTransform()->setMatrix(m); 44 45 return xform; 31 osg::MatrixTransform* matNode = new osg::MatrixTransform; 32 osg::Matrix matrix; 33 34 // Process all coordinate system contributing elements in order! 35 size_t count = node->getContents().getCount(); 36 for (size_t i = 0; i < count; i++ ) 37 { 38 domRotate * rot = daeSafeCast< domRotate >( node->getContents()[i] ); 39 if (rot) 40 { 41 domFloat4& r = rot->getValue(); 42 if (r.getCount() != 4 ) 43 { 44 osg::notify(osg::WARN)<<"Data is wrong size for rotate"<<std::endl; 45 continue; 46 } 47 48 // Build rotation matrix 49 osg::Matrix rotMat; 50 rotMat.makeRotate(osg::DegreesToRadians(r[3]), r[0], r[1], r[2]); 51 52 matrix = rotMat * matrix; 53 continue; 54 } 55 56 domTranslate * trans = daeSafeCast< domTranslate >( node->getContents()[i] ); 57 if (trans != NULL) 58 { 59 domFloat3& t = trans->getValue(); 60 if (t.getCount() != 3 ) 61 { 62 osg::notify(osg::WARN)<<"Data is wrong size for translate"<<std::endl; 63 continue; 64 } 65 66 // Build translation matrix 67 osg::Matrix transMat; 68 transMat.makeTranslate(t[0], t[1], t[2]); 69 70 matrix = transMat * matrix; 71 continue; 72 } 73 74 domScale * scale = daeSafeCast< domScale >( node->getContents()[i] ); 75 if (scale != NULL) 76 { 77 domFloat3& s = scale->getValue(); 78 if (s.getCount() != 3 ) 79 { 80 osg::notify(osg::WARN)<<"Data is wrong size for scale"<<std::endl; 81 continue; 82 } 83 84 // Build scale matrix 85 osg::Matrix scaleMat; 86 scaleMat.makeScale(s[0], s[1], s[2]); 87 88 matrix = scaleMat * matrix; 89 continue; 90 } 91 92 domMatrix * mat = daeSafeCast< domMatrix >( node->getContents()[i] ); 93 if (mat != NULL) 94 { 95 if (mat->getValue().getCount() != 16 ) 96 { 97 osg::notify(osg::WARN)<<"Data is wrong size for matrix"<<std::endl; 98 continue; 99 } 100 101 // Build matrix 102 osg::Matrix mMat( mat->getValue()[0], mat->getValue()[4], mat->getValue()[8], mat->getValue()[12], 103 mat->getValue()[1], mat->getValue()[5], mat->getValue()[9], mat->getValue()[13], 104 mat->getValue()[2], mat->getValue()[6], mat->getValue()[10], mat->getValue()[14], 105 mat->getValue()[3], mat->getValue()[7], mat->getValue()[11], mat->getValue()[15] ); 106 107 matrix = mMat * matrix; 108 continue; 109 } 110 111 domLookat * la = daeSafeCast< domLookat >( node->getContents()[i] ); 112 if (la != NULL) 113 { 114 if (la->getValue().getCount() != 9 ) 115 { 116 osg::notify(osg::WARN)<<"Data is wrong size for lookat"<<std::endl; 117 continue; 118 } 119 120 // Build lookat matrix 121 osg::Matrix lookatMat; 122 osg::Vec3 eye(la->getValue()[0], la->getValue()[1], la->getValue()[2]); 123 osg::Vec3 center(la->getValue()[3], la->getValue()[4], la->getValue()[5] ); 124 osg::Vec3 up( la->getValue()[6], la->getValue()[7], la->getValue()[8] ); 125 lookatMat.makeLookAt( eye, center, up ); 126 127 matrix = lookatMat * matrix; 128 continue; 129 } 130 131 domSkew * skew = daeSafeCast< domSkew >( node->getContents()[i] ); 132 if (skew != NULL) 133 { 134 if (skew->getValue().getCount() != 7 ) 135 { 136 osg::notify(osg::WARN)<<"Data is wrong size for skew"<<std::endl; 137 continue; 138 } 139 140 // Skew matrix building derived from GNURealistic ShaderMan GMANMatrix4 (LGPL) matrix class 141 142 // Build skew matrix 143 domFloat7& s = skew->getValue(); 144 145 float shear = sin(osg::DegreesToRadians(s[0])); 146 // axis of rotation 147 osg::Vec3f around(s[1],s[2],s[3]); 148 // axis of translation 149 osg::Vec3f along(s[4],s[5],s[6]); 150 151 along.normalize(); 152 osg::Vec3f a = around - (along * (around * along)); 153 a.normalize(); 154 155 float an1 = around * a; 156 float an2 = around * along; 157 158 float rx = an1 * cos(shear) - an2 * sin(shear); 159 float ry = an1 * sin(shear) + an2 * cos(shear); 160 161 if (rx <= 0.0) 162 { 163 osg::notify(osg::WARN)<<"skew angle too large"<<std::endl; 164 continue; 165 } 166 167 float alpha; 168 // A parallel to B?? 169 if (an1==0) 170 { 171 alpha=0; 172 } 173 else 174 { 175 alpha=ry/rx-an2/an1; 176 } 177 178 179 osg::Matrix skewMat(a.x()*along.x()*alpha+1.0, a.x()*along.y()*alpha, a.x()*along.z()*alpha, 0, 180 a.y()*along.x()*alpha, a.y()*along.y()*alpha+1.0, a.y()*along.z()*alpha, 0, 181 a.z()*along.x()*alpha, a.z()*along.y()*alpha, a.z()*along.z()*alpha+1.0, 0, 182 0, 0, 0, 1); 183 184 185 matrix = skewMat * matrix; 186 continue; 187 } 188 } 189 190 matNode->setMatrix(matrix); 191 192 osg::Vec3 scale = matrix.getScale(); 193 if ((scale.x() != 1) || (scale.y() != 1) || (scale.z() != 1)) 194 { 195 osg::StateSet* ss = matNode->getOrCreateStateSet(); 196 ss->setMode(GL_RESCALE_NORMAL, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); 197 } 198 199 return matNode; 46 200 } 47 201 48 osg:: Transform* daeReader::processTranslate( domTranslate *trans)202 osg::Node* daeReader::processOsgDOFTransform(domTechnique* teq) 49 203 { 50 osg::Transform* xform = new osg::PositionAttitudeTransform(); 51 //xform->setDataVariance(osg::Object::STATIC); 52 53 xform->setName( trans->getSid() ? trans->getSid() : "" ); 54 55 if (trans->getValue().getCount() != 3 ) { 56 osg::notify(osg::WARN)<<"Data is wrong size for translate"<<std::endl; 57 return NULL; 58 } 59 60 domFloat3& t = trans->getValue(); 61 62 xform->asPositionAttitudeTransform()->setPosition( 63 osg::Vec3(t[0],t[1],t[2])); 64 65 return xform; 204 osgSim::DOFTransform* dof = new osgSim::DOFTransform; 205 206 domAny* any = daeSafeCast< domAny >(teq->getChild("MinHPR")); 207 if (any) 208 { 209 dof->setMinHPR(parseVec3String(any->getValue())); 210 } 211 else 212 { 213 osg::notify(osg::WARN) << "Expected element 'MinHPR' not found" << std::endl; 214 } 215 216 any = daeSafeCast< domAny >(teq->getChild("MaxHPR")); 217 if (any) 218 { 219 dof->setMaxHPR(parseVec3String(any->getValue())); 220 } 221 else 222 { 223 osg::notify(osg::WARN) << "Expected element 'MaxHPR' not found" << std::endl; 224 } 225 226 any = daeSafeCast< domAny >(teq->getChild("IncrementHPR")); 227 if (any) 228 { 229 dof->setIncrementHPR(parseVec3String(any->getValue())); 230 } 231 else 232 { 233 osg::notify(osg::WARN) << "Expected element 'IncrementHPR' not found" << std::endl; 234 } 235 236 any = daeSafeCast< domAny >(teq->getChild("CurrentHPR")); 237 if (any) 238 { 239 dof->setCurrentHPR(parseVec3String(any->getValue())); 240 } 241 else 242 { 243 osg::notify(osg::WARN) << "Expected element 'CurrentHPR' not found" << std::endl; 244 } 245 246 any = daeSafeCast< domAny >(teq->getChild("MinTranslate")); 247 if (any) 248 { 249 dof->setMinTranslate(parseVec3String(any->getValue())); 250 } 251 else 252 { 253 osg::notify(osg::WARN) << "Expected element 'MinTranslate' not found" << std::endl; 254 } 255 256 any = daeSafeCast< domAny >(teq->getChild("MaxTranslate")); 257 if (any) 258 { 259 dof->setMaxTranslate(parseVec3String(any->getValue())); 260 } 261 else 262 { 263 osg::notify(osg::WARN) << "Expected element 'MaxTranslate' not found" << std::endl; 264 } 265 266 any = daeSafeCast< domAny >(teq->getChild("IncrementTranslate")); 267 if (any) 268 { 269 dof->setIncrementTranslate(parseVec3String(any->getValue())); 270 } 271 else 272 { 273 osg::notify(osg::WARN) << "Expected element 'IncrementTranslate' not found" << std::endl; 274 } 275 276 any = daeSafeCast< domAny >(teq->getChild("CurrentTranslate")); 277 if (any) 278 { 279 dof->setCurrentTranslate(parseVec3String(any->getValue())); 280 } 281 else 282 { 283 osg::notify(osg::WARN) << "Expected element 'CurrentTranslate' not found" << std::endl; 284 } 285 286 any = daeSafeCast< domAny >(teq->getChild("MinScale")); 287 if (any) 288 { 289 dof->setMinScale(parseVec3String(any->getValue())); 290 } 291 else 292 { 293 osg::notify(osg::WARN) << "Expected element 'MinScale' not found" << std::endl; 294 } 295 296 any = daeSafeCast< domAny >(teq->getChild("MaxScale")); 297 if (any) 298 { 299 dof->setMaxScale(parseVec3String(any->getValue())); 300 } 301 else 302 { 303 osg::notify(osg::WARN) << "Expected element 'MaxScale' not found" << std::endl; 304 } 305 306 any = daeSafeCast< domAny >(teq->getChild("IncrementScale")); 307 if (any) 308 { 309 dof->setIncrementScale(parseVec3String(any->getValue())); 310 } 311 else 312 { 313 osg::notify(osg::WARN) << "Expected element 'IncrementScale' not found" << std::endl; 314 } 315 316 any = daeSafeCast< domAny >(teq->getChild("CurrentScale")); 317 if (any) 318 { 319 dof->setCurrentScale(parseVec3String(any->getValue())); 320 } 321 else 322 { 323 osg::notify(osg::WARN) << "Expected element 'CurrentScale' not found" << std::endl; 324 } 325 326 any = daeSafeCast< domAny >(teq->getChild("MultOrder")); 327 if (any) 328 { 329 dof->setHPRMultOrder((osgSim::DOFTransform::MultOrder)parseString<int>(any->getValue())); 330 } 331 else 332 { 333 osg::notify(osg::WARN) << "Expected element 'MultOrder' not found" << std::endl; 334 } 335 336 any = daeSafeCast< domAny >(teq->getChild("LimitationFlags")); 337 if (any) 338 { 339 dof->setLimitationFlags(parseString<unsigned long>(any->getValue())); 340 } 341 else 342 { 343 osg::notify(osg::WARN) << "Expected element 'LimitationFlags' not found" << std::endl; 344 } 345 346 any = daeSafeCast< domAny >(teq->getChild("AnimationOn")); 347 if (any) 348 { 349 dof->setAnimationOn(parseString<bool>(any->getValue())); 350 } 351 else 352 { 353 osg::notify(osg::WARN) << "Expected element 'AnimationOn' not found" << std::endl; 354 } 355 356 any = daeSafeCast< domAny >(teq->getChild("PutMatrix")); 357 if (any) 358 { 359 osg::Matrix mat = parseMatrixString(any->getValue()); 360 dof->setPutMatrix(mat); 361 dof->setInversePutMatrix( osg::Matrixd::inverse( mat ) ); 362 } 363 else 364 { 365 osg::notify(osg::WARN) << "Expected element 'PutMatrix' not found" << std::endl; 366 } 367 368 return dof; 66 369 } 67 68 osg::Transform* daeReader::processRotate( domRotate *rot )69 {70 osg::Transform* xform = new osg::PositionAttitudeTransform();71 //xform->setDataVariance(osg::Object::STATIC);72 73 xform->setName( rot->getSid() ? rot->getSid() : "" );74 75 if (rot->getValue().getCount() != 4 ) {76 osg::notify(osg::WARN)<<"Data is wrong size for rotate"<<std::endl;77 return NULL;78 }79 domFloat4& r = rot->getValue();80 81 osg::Vec3 axis;82 axis.set(r[0],r[1],r[2]);83 xform->asPositionAttitudeTransform()->setAttitude(84 osg::Quat(osg::DegreesToRadians(r[3]),axis));85 86 return xform;87 }88 89 osg::Transform* daeReader::processScale( domScale *scale )90 {91 osg::Transform* xform = new osg::PositionAttitudeTransform();92 //xform->setDataVariance(osg::Object::STATIC);93 94 xform->setName( scale->getSid() ? scale->getSid() : "" );95 96 if (scale->getValue().getCount() != 3 ) {97 osg::notify(osg::WARN)<<"Data is wrong size for scale"<<std::endl;98 return NULL;99 }100 domFloat3& s = scale->getValue();101 102 xform->asPositionAttitudeTransform()->setScale(103 osg::Vec3(s[0],s[1],s[2]));104 105 return xform;106 }107 108 osg::Transform* daeReader::processLookat( domLookat *la )109 {110 osg::Transform* xform = new osg::MatrixTransform();111 xform->setDataVariance(osg::Object::STATIC);112 113 xform->setName( la->getSid() ? la->getSid() : "" );114 115 if (la->getValue().getCount() != 9 ) {116 osg::notify(osg::WARN)<<"Data is wrong size for lookat"<<std::endl;117 return NULL;118 }119 120 osg::Matrix m;121 122 osg::Vec3 eye;123 osg::Vec3 center;124 osg::Vec3 up;125 126 eye.set( la->getValue()[0], la->getValue()[1], la->getValue()[2] );127 center.set( la->getValue()[3], la->getValue()[4], la->getValue()[5] );128 up.set( la->getValue()[6], la->getValue()[7], la->getValue()[8] );129 130 m.makeLookAt( eye, center, up );131 132 xform->asMatrixTransform()->setMatrix(m);133 134 return xform;135 }136 137 osg::Transform* daeReader::processSkew( domSkew *skew )138 {139 osg::Transform* xform = new osg::MatrixTransform();140 xform->setDataVariance(osg::Object::STATIC);141 142 xform->setName( skew->getSid() ? skew->getSid() : "" );143 144 if (skew->getValue().getCount() != 9 ) {145 osg::notify(osg::WARN)<<"Data is wrong size for skew"<<std::endl;146 return NULL;147 }148 domFloat7& s = skew->getValue();149 150 float angle = s[0];151 float shear = sin(osg::DegreesToRadians(angle));152 osg::Vec3 around(s[1],s[2],s[3]);153 osg::Vec3 along(s[4],s[5],s[6]);154 155 osg::Vec3 const x(1,0,0);156 osg::Vec3 const y(0,1,0);157 osg::Vec3 const z(0,0,1);158 159 osg::Matrix m;160 161 if ( along == x ) {162 if ( around == y ) {163 m(2,0) = shear;164 } else if ( around == z ) {165 m(1,0) = -shear;166 } else {167 //osg::notify(osg::WARN)<<"Unsupported skew around "<<around<<std::endl;168 }169 } else if ( along == y ) {170 if ( around == x ) {171 m(2,1) = -shear;172 } else if ( around == z ) {173 m(0,1) = shear;174 } else {175 //osg::notify(osg::WARN)<<"Unsupported skew around "<<around<<std::endl;176 }177 } else if ( along == z ) {178 if ( around == x ) {179 m(1,2) = shear;180 } else if ( around == y ) {181 m(0,2) = -shear;182 } else {183 //osg::notify(osg::WARN)<<"Unsupported skew around "<<around<<std::endl;184 }185 } else {186 //osg::notify(osg::WARN)<<"Unsupported skew along "<<along<<std::endl;187 }188 189 190 if (angle > 0) {191 //osg::notify(osg::NOTICE)<<"Skew: angle("<<angle<<") around("<<around<<") along("<<along<<")"<<std::endl;192 }193 194 xform->asMatrixTransform()->setMatrix(m);195 196 return xform;197 } -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeReader.cpp
r7664 r9228 14 14 #include "daeReader.h" 15 15 #include <dae.h> 16 #include <dae/domAny.h> 16 17 #include <dom/domCOLLADA.h> 17 18 #include <dom/domInstanceWithExtra.h> 18 19 #include <dom/domConstants.h> 20 #include <osg/MatrixTransform> 19 21 20 22 using namespace osgdae; … … 87 89 } 88 90 89 if (dae->getDatabase()) { 91 if (dae->getDatabase()) 92 { 90 93 count = dae->getDatabase()->getElementCount(NULL, COLLADA_TYPE_INSTANCE_RIGID_BODY, NULL); 91 94 92 95 // build a std::map for lookup if Group or PositionAttitudeTransform should be created, 93 96 // i.e, make it easy to check if a instance_rigid_body targets a visual node 94 for (int i=0; i<count; i++) { 97 for (int i=0; i<count; i++) 98 { 95 99 result = dae->getDatabase()->getElement(&colladaElement, i, NULL, COLLADA_TYPE_INSTANCE_RIGID_BODY); 96 100 97 if (result == DAE_OK) { 101 if (result == DAE_OK) 102 { 98 103 irb = daeSafeCast<domInstance_rigid_body>(colladaElement); 99 if (irb) { 100 domNode *node = daeSafeCast<domNode>(irb->getTarget().getElement()); 101 if (node && node->getId()) { 104 if (irb) 105 { 106 domNode *node = daeSafeCast<domNode>(irb->getTarget().getElement()); 107 if (node && node->getId()) 108 { 102 109 _targetMap[ std::string(node->getId()) ] = true; 103 110 } … … 122 129 { 123 130 osg::Node *retVal; 124 //### do not add an empty group if there is only one 131 125 132 unsigned int nbVisualSceneGroup=scene->getNode_array().getCount(); 126 133 if (nbVisualSceneGroup==0) … … 155 162 } 156 163 return retVal; 157 158 } 159 164 } 165 166 osg::Node* daeReader::processExtras(domNode *node) 167 { 168 // See if one of the extras contains OpenSceneGraph specific information 169 unsigned int numExtras = node->getExtra_array().getCount(); 170 for (unsigned int currExtra=0; currExtra < numExtras; currExtra++) 171 { 172 domExtra* extra = node->getExtra_array()[currExtra]; 173 domTechnique* teq = NULL; 174 175 daeString extraType = extra->getType(); 176 if (extraType) 177 { 178 if (strcmp(extraType, "Switch") == 0) 179 { 180 teq = getOpenSceneGraphProfile(extra); 181 if (teq) 182 { 183 return processOsgSwitch(teq); 184 } 185 } 186 else if (strcmp(extraType, "MultiSwitch") == 0) 187 { 188 teq = getOpenSceneGraphProfile(extra); 189 if (teq) 190 { 191 return processOsgMultiSwitch(teq); 192 } 193 } 194 else if (strcmp(extraType, "LOD") == 0) 195 { 196 teq = getOpenSceneGraphProfile(extra); 197 if (teq) 198 { 199 return processOsgLOD(teq); 200 } 201 } 202 else if (strcmp(extraType, "DOFTransform") == 0) 203 { 204 teq = getOpenSceneGraphProfile(extra); 205 if (teq) 206 { 207 return processOsgDOFTransform(teq); 208 } 209 } 210 else if (strcmp(extraType, "Sequence") == 0) 211 { 212 teq = getOpenSceneGraphProfile(extra); 213 if (teq) 214 { 215 return processOsgSequence(teq); 216 } 217 } 218 } 219 } 220 return new osg::Group; 221 } 222 223 void daeReader::processNodeExtra(osg::Node* osgNode, domNode *node) 224 { 225 // See if one of the extras contains OpenSceneGraph specific information 226 unsigned int numExtras = node->getExtra_array().getCount(); 227 228 for (unsigned int currExtra=0; currExtra < numExtras; currExtra++) 229 { 230 domExtra* extra = node->getExtra_array()[currExtra]; 231 232 daeString extraType = extra->getType(); 233 if (extraType && (strcmp(extraType, "Node") == 0)) 234 { 235 domTechnique* teq = getOpenSceneGraphProfile(extra); 236 if (teq) 237 { 238 domAny* any = daeSafeCast< domAny >(teq->getChild("Descriptions")); 239 if (any) 240 { 241 osg::Node::DescriptionList descriptions; 242 unsigned int numChildren = any->getChildren().getCount(); 243 for (unsigned int currChild = 0; currChild < numChildren; currChild++) 244 { 245 domAny* child = daeSafeCast<domAny>(any->getChildren()[currChild]); 246 if (child) 247 { 248 if (strcmp(child->getElementName(), "Description" ) == 0 ) 249 { 250 std::string value = child->getValue(); 251 descriptions.push_back(value); 252 } 253 else 254 { 255 osg::notify(osg::WARN) << "Child of element 'Descriptions' is not of type 'Description'" << std::endl; 256 } 257 } 258 else 259 { 260 osg::notify(osg::WARN) << "Element 'Descriptions' does not contain expected elements." << std::endl; 261 } 262 } 263 osgNode->setDescriptions(descriptions); 264 } 265 else 266 { 267 osg::notify(osg::WARN) << "Expected element 'Descriptions' not found" << std::endl; 268 } 269 } 270 } 271 } 272 } 273 274 domTechnique* daeReader::getOpenSceneGraphProfile(domExtra* extra) 275 { 276 unsigned int numTeqs = extra->getTechnique_array().getCount(); 277 278 for ( unsigned int currTeq = 0; currTeq < numTeqs; ++currTeq ) 279 { 280 // Only interested in OpenSceneGraph technique 281 if (strcmp( extra->getTechnique_array()[currTeq]->getProfile(), "OpenSceneGraph" ) == 0 ) 282 { 283 return extra->getTechnique_array()[currTeq]; 284 } 285 } 286 return NULL; 287 } 288 289 290 // <node> 291 // attributes: 292 // id, name, sid, type, layer 293 // child elements: 294 // 0..1 <asset> 295 // 0..* <lookat>, <matrix>, <rotate>, <scale>, <skew>, <translate> 296 // 0..* <instance_camera> 297 // 0..* <instance_controller> 298 // 0..* <instance_geometry> 299 // 0..* <instance_light> 300 // 0..* <instance_node> 301 // 0..* <node> 302 // 0..* <extra> 160 303 osg::Node* daeReader::processNode( domNode *node ) 161 304 { 162 osg::Node *retVal; 163 osg::PositionAttitudeTransform *pat; 164 165 int patcount = node->getRotate_array().getCount() + 166 node->getScale_array().getCount() + 167 node->getTranslate_array().getCount(); 168 305 // First we need to determine what kind of OSG node we need 306 // If there exist any of the <lookat>, <matrix>, <rotate>, <scale>, <skew>, <translate> elements 307 // or if a COLLADA_TYPE_INSTANCE_RIGID_BODY targets this node we need a MatrixTransform 308 int coordcount = node->getRotate_array().getCount() + 309 node->getScale_array().getCount() + 310 node->getTranslate_array().getCount() + 311 node->getLookat_array().getCount() + 312 node->getMatrix_array().getCount() + 313 node->getSkew_array().getCount(); 314 315 // See if it is targeted 169 316 bool targeted = false; 170 171 if (node->getId()){317 if (node->getId()) 318 { 172 319 targeted = _targetMap[std::string(node->getId())]; 173 320 } 174 321 175 176 if (patcount > 0 || targeted ) 177 { 178 pat = new osg::PositionAttitudeTransform(); 179 retVal = pat; 180 } 181 else 182 { 183 retVal = new osg::Group(); 184 } 185 186 osg::Node *current = retVal; 187 188 retVal->setName( node->getId() ? node->getId() : "" ); 189 190 191 // Handle rotate, translate and scale first.. 192 // will make the hierarchy less deep 193 194 // <rotate> 195 osg::Quat osgRot; 196 for (unsigned int i=0; i<node->getRotate_array().getCount(); i++) 197 { 198 daeSmartRef<domRotate> rot = node->getRotate_array().get(i); 199 if (rot->getValue().getCount() != 4 ) { 200 osg::notify(osg::WARN)<<"Data is wrong size for rotate"<<std::endl; 201 continue; 202 } 203 204 domFloat4& r = rot->getValue(); 205 206 osg::Vec3 axis; 207 axis.set(r[0],r[1],r[2]); 208 osgRot = osg::Quat(osg::DegreesToRadians(r[3]),axis) * osgRot; 209 pat->setAttitude(osgRot); 210 } 211 212 // <scale> 213 osg::Vec3 osgScale = osg::Vec3(1.0, 1.0, 1.0); 214 for (unsigned int i=0; i<node->getScale_array().getCount(); i++) 215 { 216 daeSmartRef<domScale> scale = node->getScale_array().get(i); 217 218 if (scale->getValue().getCount() != 3 ) { 219 osg::notify(osg::WARN)<<"Data is wrong size for scale"<<std::endl; 220 continue; 221 } 222 domFloat3& s = scale->getValue(); 223 224 osgScale[0] *= s[0]; 225 osgScale[1] *= s[1]; 226 osgScale[2] *= s[2]; 227 pat->setScale(osgScale); 228 } 229 230 // <translate> 231 osg::Vec3 osgTrans = osg::Vec3(0.0, 0.0, 0.0); 232 for (unsigned int i=0; i<node->getTranslate_array().getCount(); i++) 233 { 234 daeSmartRef<domTranslate> trans = node->getTranslate_array().get(i); 235 236 if (trans->getValue().getCount() != 3 ) { 237 osg::notify(osg::WARN)<<"Data is wrong size for translate"<<std::endl; 238 continue; 239 } 240 241 domFloat3& t = trans->getValue(); 242 osgTrans += osg::Vec3(t[0],t[1],t[2]); 243 pat->setPosition(osgTrans); 244 } 245 246 247 248 size_t count = node->getContents().getCount(); 249 for ( size_t i = 0; i < count; i++ ) 250 { 251 osg::Node *trans = NULL; 252 253 //I'm using daeSafeCast to check type because the pointer comparisons are a lot faster 254 //than a strcmp 255 domTranslate * t = daeSafeCast< domTranslate >( node->getContents()[i] ); 256 if ( t != NULL ) 257 { 258 continue; 259 } 260 261 domRotate * r = daeSafeCast< domRotate >( node->getContents()[i] ); 262 if ( r != NULL ) { 263 continue; 264 } 265 266 domScale * s = daeSafeCast< domScale >( node->getContents()[i] ); 267 if ( s != NULL ) { 268 continue; 269 } 270 271 domMatrix * m = daeSafeCast< domMatrix >( node->getContents()[i] ); 272 if ( m != NULL ) { 273 trans = processMatrix( m ); 274 if ( trans != NULL ) 275 { 276 current->asGroup()->addChild( trans ); 277 current = trans; 278 } 279 continue; 280 } 281 282 domSkew *sk = daeSafeCast< domSkew >( node->getContents()[i] ); 283 if ( sk != NULL ) { 284 trans = processSkew( sk ); 285 if ( trans != NULL ) 286 { 287 current->asGroup()->addChild( trans ); 288 current = trans; 289 } 290 continue; 291 } 292 293 domInstance_geometry *ig = daeSafeCast< domInstance_geometry >( node->getContents()[i] ); 294 if ( ig != NULL ) 295 { 296 trans = processInstance_geometry( ig ); 297 if ( trans != NULL ) 298 { 299 current->asGroup()->addChild( trans ); 300 } 301 continue; 302 } 303 304 domInstance_controller *ictrl = daeSafeCast< domInstance_controller >( node->getContents()[i] ); 305 if ( ictrl != NULL ) 306 { 307 trans = processInstance_controller( ictrl ); 308 if ( trans != NULL ) 309 { 310 current->asGroup()->addChild( trans ); 311 } 312 continue; 313 } 314 315 domInstance_camera *ic = daeSafeCast< domInstance_camera >( node->getContents()[i] ); 316 if ( ic != NULL ) 317 { 318 daeElement *el = getElementFromURI( ic->getUrl() ); 322 osg::Node *resultNode; 323 if (coordcount > 0 || targeted ) 324 { 325 resultNode = processOsgMatrixTransform(node); 326 } 327 else 328 { 329 // No transform data, determine node type based on it's available extra data 330 resultNode = processExtras(node); 331 } 332 333 // See if there is generic node info attached as extra 334 processNodeExtra(resultNode, node); 335 336 resultNode->setName( node->getId() ? node->getId() : "" ); 337 338 osg::Group* groupNode = resultNode->asGroup(); 339 340 if (groupNode) 341 { 342 // 0..* <instance_camera> 343 domInstance_camera_Array cameraInstanceArray = node->getInstance_camera_array(); 344 for ( size_t i = 0; i < cameraInstanceArray.getCount(); i++ ) 345 { 346 daeElement *el = getElementFromURI( cameraInstanceArray[i]->getUrl()); 319 347 domCamera *c = daeSafeCast< domCamera >( el ); 320 if ( c == NULL ) 321 { 322 osg::notify( osg::WARN ) << "Failed to locate camera " << ic->getUrl().getURI() << std::endl; 323 } 324 trans = processCamera( c ); 325 if ( trans != NULL ) 326 { 327 current->asGroup()->addChild( trans ); 328 } 329 continue; 330 } 331 332 domInstance_light *il = daeSafeCast< domInstance_light >( node->getContents()[i] ); 333 if ( il != NULL ) 334 { 335 daeElement *el = getElementFromURI( il->getUrl() ); 348 349 if (c) 350 groupNode->addChild( processCamera( c )); 351 else 352 osg::notify( osg::WARN ) << "Failed to locate camera " << cameraInstanceArray[i]->getUrl().getURI() << std::endl; 353 } 354 355 // 0..* <instance_controller> 356 domInstance_controller_Array controllerInstanceArray = node->getInstance_controller_array(); 357 for ( size_t i = 0; i < controllerInstanceArray.getCount(); i++ ) 358 { 359 groupNode->addChild( processInstanceController( controllerInstanceArray[i] )); 360 } 361 362 // 0..* <instance_geometry> 363 domInstance_geometry_Array geometryInstanceArray = node->getInstance_geometry_array(); 364 for ( size_t i = 0; i < geometryInstanceArray.getCount(); i++ ) 365 { 366 groupNode->addChild( processInstanceGeometry( geometryInstanceArray[i] )); 367 } 368 369 // 0..* <instance_light> 370 domInstance_light_Array lightInstanceArray = node->getInstance_light_array(); 371 for ( size_t i = 0; i < lightInstanceArray.getCount(); i++ ) 372 { 373 daeElement *el = getElementFromURI( lightInstanceArray[i]->getUrl()); 336 374 domLight *l = daeSafeCast< domLight >( el ); 337 if ( l == NULL ) 338 { 339 osg::notify( osg::WARN ) << "Failed to locate light " << il->getUrl().getURI() << std::endl; 340 } 341 trans = processLight( l ); 342 if ( trans != NULL ) 343 { 344 current->asGroup()->addChild( trans ); 345 } 346 continue; 347 } 348 349 domInstance_node *instn = daeSafeCast< domInstance_node >( node->getContents()[i] ); 350 if ( instn != NULL ) 351 { 352 daeElement *el = getElementFromURI( instn->getUrl() ); 375 376 if (l) 377 groupNode->addChild( processLight( l )); 378 else 379 osg::notify( osg::WARN ) << "Failed to locate light " << lightInstanceArray[i]->getUrl().getURI() << std::endl; 380 } 381 382 // 0..* <instance_node> 383 domInstance_node_Array nodeInstanceArray = node->getInstance_node_array(); 384 for ( size_t i = 0; i < nodeInstanceArray.getCount(); i++ ) 385 { 386 daeElement *el = getElementFromURI( nodeInstanceArray[i]->getUrl()); 353 387 domNode *n = daeSafeCast< domNode >( el ); 354 if ( n == NULL ) 355 { 356 osg::notify( osg::WARN ) << "Failed to locate camera " << ic->getUrl().getURI() << std::endl; 357 } 358 trans = processNode( n ); 359 if ( trans != NULL ) 360 { 361 current->asGroup()->addChild( trans ); 362 } 363 continue; 364 } 365 366 domNode *n = daeSafeCast< domNode >( node->getContents()[i] ); 367 if ( n != NULL ) 368 { 369 trans = processNode( n ); 370 if ( trans != NULL ) 371 { 372 current->asGroup()->addChild( trans ); 373 } 374 continue; 375 } 376 377 const char *name = node->getContents()[i]->getElementName(); 378 if ( name == NULL ) name = node->getContents()[i]->getTypeName(); 379 osg::notify( osg::WARN ) << "Unsupported element type: " << name << " in COLLADA scene!" << std::endl; 380 381 } 382 383 return retVal; 384 } 388 389 if (n) 390 // Recursive call 391 groupNode->addChild( processNode( n )); 392 else 393 osg::notify( osg::WARN ) << "Failed to locate node " << nodeInstanceArray[i]->getUrl().getURI() << std::endl; 394 } 395 396 // 0..* <node> 397 domNode_Array nodeArray = node->getNode_array(); 398 for ( size_t i = 0; i < nodeArray.getCount(); i++ ) 399 { 400 // Recursive call 401 groupNode->addChild( processNode( nodeArray[i] )); 402 } 403 } 404 405 return resultNode; 406 } -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeReader.h
r7664 r9228 94 94 } 95 95 96 /// Convert string to value using it's stream operator 97 template <typename T> 98 T parseString(const std::string& valueAsString) { 99 std::stringstream str; 100 str << valueAsString; 101 T result; 102 str >> result; 103 return result; 104 } 105 106 inline osg::Vec3 parseVec3String(const std::string& valueAsString) 107 { 108 std::stringstream str; 109 str << valueAsString; 110 osg::Vec3 result; 111 str >> result.x() >> result.y() >> result.z(); 112 return result; 113 } 114 115 inline osg::Matrix parseMatrixString(const std::string& valueAsString) 116 { 117 std::stringstream str; 118 str << valueAsString; 119 osg::Matrix result; 120 str >> result(0,0) >> result(1,0) >> result(2,0) >> result(3,0) 121 >> result(0,1) >> result(1,1) >> result(2,1) >> result(3,1) 122 >> result(0,2) >> result(1,2) >> result(2,2) >> result(3,2) 123 >> result(0,3) >> result(1,3) >> result(2,3) >> result(3,3); 124 return result; 125 } 126 127 96 128 /** 97 129 @class daeReader … … 114 146 protected: 115 147 //scene processing 116 osg::Node* processVisualScene( domVisual_scene *scene ); 117 osg::Node* processNode( domNode *node ); 148 osg::Node* processVisualScene( domVisual_scene *scene ); 149 osg::Node* processNode( domNode *node ); 150 osg::Node* processOsgMatrixTransform( domNode *node ); 118 151 //osg::Node* processInstance( domInstanceWithExtra *iwe ); 119 152 120 //transform processing 121 osg::Transform* processMatrix( domMatrix *mat ); 122 osg::Transform* processTranslate( domTranslate *trans ); 123 osg::Transform* processRotate( domRotate *rot ); 124 osg::Transform* processScale( domScale *scale ); 125 osg::Transform* processLookat( domLookat *la ); 126 osg::Transform* processSkew( domSkew *skew ); 153 // Processing of OSG specific info stored in node extras 154 osg::Node* processExtras(domNode *node); 155 void processNodeExtra(osg::Node* osgNode, domNode *node); 156 domTechnique* getOpenSceneGraphProfile(domExtra* extra); 157 void processAsset( domAsset *node ); 158 159 osg::Node* processOsgSwitch(domTechnique* teq); 160 osg::Node* processOsgMultiSwitch(domTechnique* teq); 161 osg::Node* processOsgLOD(domTechnique* teq); 162 osg::Node* processOsgDOFTransform(domTechnique* teq); 163 osg::Node* processOsgSequence(domTechnique* teq); 127 164 128 165 //geometry processing 129 osg:: Node* processInstance_geometry( domInstance_geometry *ig );130 osg:: Node* processGeometry( domGeometry *geo );131 osg:: Node* processInstance_controller( domInstance_controller *ictrl );166 osg::Geode* processInstanceGeometry( domInstance_geometry *ig ); 167 osg::Geode* processGeometry( domGeometry *geo ); 168 osg::Geode* processInstanceController( domInstance_controller *ictrl ); 132 169 133 170 typedef std::map< daeElement*, domSourceReader > SourceMap; … … 135 172 136 173 template< typename T > 137 osg::Node* processSinglePPrimitive(T *group, SourceMap &sources, GLenum mode );174 void processSinglePPrimitive(osg::Geode* geode, T *group, SourceMap &sources, GLenum mode ); 138 175 139 176 template< typename T > 140 osg::Node* processMultiPPrimitive(T *group, SourceMap &sources, GLenum mode );141 142 osg::Node* processPolylist(domPolylist *group, SourceMap &sources );177 void processMultiPPrimitive(osg::Geode* geode, T *group, SourceMap &sources, GLenum mode ); 178 179 void processPolylist(osg::Geode* geode, domPolylist *group, SourceMap &sources ); 143 180 144 181 void resolveArrays( domInputLocalOffset_Array &inputs, osg::Geometry *&geom, … … 148 185 149 186 //material/effect processing 150 void processBindMaterial( domBind_material *bm, osg::Node *geo);151 osg::StateSet *processMaterial(domMaterial *mat );152 osg::StateSet *processEffect(domEffect *effect );153 osg::StateSet *processProfileCOMMON(domProfile_COMMON *pc );187 void processBindMaterial( domBind_material *bm, domGeometry *geom, osg::Geode *geode ); 188 void processMaterial(osg::StateSet *ss, domMaterial *mat ); 189 void processEffect(osg::StateSet *ss, domEffect *effect ); 190 void processProfileCOMMON(osg::StateSet *ss, domProfile_COMMON *pc ); 154 191 bool processColorOrTextureType( domCommon_color_or_texture_type *cot, 155 osg::Material::ColorMode channel, osg::Material *mat, domCommon_float_or_param_type *fop = NULL, osg::StateAttribute **sa = NULL ); 192 osg::Material::ColorMode channel, 193 osg::Material *mat, 194 domCommon_float_or_param_type *fop = NULL, 195 osg::StateAttribute **sa = NULL, 196 bool normalizeShininess=false); 156 197 osg::StateAttribute *processTransparencySettings( domCommon_transparent_type *ctt, domCommon_float_or_param_type *pTransparency, osg::StateSet *ss ); 157 198 bool GetFloat4Param(xsNCName Reference, domFloat4 &f4); … … 175 216 domEffect *currentEffect; 176 217 177 std::map< domGeometry*, osg::Node* > geometryMap; 178 std::map< domMaterial*, osg::StateSet* > materialMap; 218 typedef std::map< domGeometry*, osg::Geode*> domGeometryGeodeMap; 219 typedef std::map< domMaterial*, osg::StateSet*> domMaterialStateSetMap; 220 typedef std::map< std::string, osg::StateSet*> MaterialStateSetMap; 221 222 /// Maps geometry to a Geode 223 domGeometryGeodeMap geometryMap; 224 // Maps material target to stateset 225 domMaterialStateSetMap materialMap; 226 // Maps material symbol to stateset 227 MaterialStateSetMap materialMap2; 228 179 229 enum AuthoringTool 180 230 { -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeWGeometry.cpp
r8357 r9228 25 25 using namespace osgdae; 26 26 27 //GEODE28 27 void daeWriter::apply( osg::Geode &node ) 29 28 { 30 #ifdef _DEBUG31 29 debugPrint( node ); 32 #endif33 30 34 31 pushStateSet(node.getStateSet()); … … 36 33 m_CurrentRenderingHint = node.getStateSet()->getRenderingHint(); 37 34 35 // TODO 36 // Write a Geode as a single instance_geometry if all drawables use the same vertex streams 37 // Reuse an existing Geode if only statesets differ 38 38 unsigned int count = node.getNumDrawables(); 39 39 for ( unsigned int i = 0; i < count; i++ ) 40 40 { 41 41 osg::Geometry *g = node.getDrawable( i )->asGeometry(); 42 42 43 if ( g != NULL ) 43 44 { 45 // Transparency at drawable level 46 if (NULL != g->getStateSet()) 47 m_CurrentRenderingHint = g->getStateSet()->getRenderingHint(); 48 44 49 pushStateSet(g->getStateSet()); 45 50 std::map< osg::Geometry*, domGeometry *>::iterator iter = geometryMap.find( g ); 46 51 if ( iter != geometryMap.end() ) 47 52 { 48 domInstance_geometry *ig = daeSafeCast< domInstance_geometry >( currentNode-> createAndPlace( "instance_geometry" ) );53 domInstance_geometry *ig = daeSafeCast< domInstance_geometry >( currentNode->add( "instance_geometry" ) ); 49 54 50 55 std::string url = "#" + std::string( iter->second->getId() ); … … 57 62 if ( lib_geoms == NULL ) 58 63 { 59 lib_geoms = daeSafeCast< domLibrary_geometries >( dom-> createAndPlace( COLLADA_ELEMENT_LIBRARY_GEOMETRIES ) );64 lib_geoms = daeSafeCast< domLibrary_geometries >( dom->add( COLLADA_ELEMENT_LIBRARY_GEOMETRIES ) ); 60 65 } 61 66 std::string name = node.getName(); … … 63 68 name = uniquify( name ); 64 69 65 domGeometryRef geo = daeSafeCast< domGeometry >( lib_geoms-> createAndPlace( COLLADA_ELEMENT_GEOMETRY ) );70 domGeometryRef geo = daeSafeCast< domGeometry >( lib_geoms->add( COLLADA_ELEMENT_GEOMETRY ) ); 66 71 geo->setId( name.c_str() ); 67 72 … … 72 77 } 73 78 74 domInstance_geometry *ig = daeSafeCast< domInstance_geometry >( currentNode-> createAndPlace( "instance_geometry" ) );79 domInstance_geometry *ig = daeSafeCast< domInstance_geometry >( currentNode->add( "instance_geometry" ) ); 75 80 76 81 std::string url = "#" + name; … … 87 92 } 88 93 } 89 90 lastVisited = GEODE;91 94 92 95 popStateSet(node.getStateSet()); … … 131 134 bool daeWriter::processGeometry( osg::Geometry *geom, domGeometry *geo, const std::string &name ) 132 135 { 133 domMesh *mesh = daeSafeCast< domMesh >( geo-> createAndPlace( COLLADA_ELEMENT_MESH ) );136 domMesh *mesh = daeSafeCast< domMesh >( geo->add( COLLADA_ELEMENT_MESH ) ); 134 137 domSource *pos = NULL; 135 138 domSource *norm = NULL; … … 207 210 208 211 //create a vertices element 209 domVertices *vertices = daeSafeCast< domVertices >( mesh-> createAndPlace( COLLADA_ELEMENT_VERTICES ) );212 domVertices *vertices = daeSafeCast< domVertices >( mesh->add( COLLADA_ELEMENT_VERTICES ) ); 210 213 std::string vName = name + "-vertices"; 211 214 vertices->setId( vName.c_str() ); 212 215 213 216 //make a POSITION input in it 214 domInputLocal *il = daeSafeCast< domInputLocal >( vertices-> createAndPlace( "input" ) );217 domInputLocal *il = daeSafeCast< domInputLocal >( vertices->add( "input" ) ); 215 218 il->setSemantic( "POSITION" ); 216 219 std::string url = "#" + std::string( pos->getId() ); … … 266 269 //if NORMAL shares same indices as POSITION put it in the vertices 267 270 /*if ( normalInds == vertInds && vertInds != NULL ) { 268 il = daeSafeCast< domInputLocal >( vertices-> createAndPlace( "input" ) );271 il = daeSafeCast< domInputLocal >( vertices->add( "input" ) ); 269 272 il->setSemantic( "NORMAL" ); 270 273 url = "#" + std::string(md->norm->getId()); … … 317 320 //if COLOR shares same indices as POSITION put it in the vertices 318 321 /*if ( colorInds == vertInds && vertInds != NULL ) { 319 il = daeSafeCast< domInputLocal >( vertices-> createAndPlace( "input" ) );322 il = daeSafeCast< domInputLocal >( vertices->add( "input" ) ); 320 323 il->setSemantic( "COLOR" ); 321 324 url = "#" + std::string(md->color->getId()); … … 404 407 { 405 408 lines = createPrimGroup<domLines>( COLLADA_ELEMENT_LINES, mesh, norm, color, texcoord ); 406 lines-> createAndPlace( COLLADA_ELEMENT_P );409 lines->add( COLLADA_ELEMENT_P ); 407 410 std::string mat = name + "_material"; 408 411 lines->setMaterial( mat.c_str() ); … … 417 420 { 418 421 tris = createPrimGroup<domTriangles>( COLLADA_ELEMENT_TRIANGLES, mesh, norm, color, texcoord ); 419 tris-> createAndPlace( COLLADA_ELEMENT_P );422 tris->add( COLLADA_ELEMENT_P ); 420 423 std::string mat = name + "_material"; 421 424 tris->setMaterial( mat.c_str() ); … … 432 435 { 433 436 polys = createPrimGroup<domPolygons>( COLLADA_ELEMENT_POLYGONS, mesh, norm, color, texcoord ); 434 polys-> createAndPlace( COLLADA_ELEMENT_P );437 polys->add( COLLADA_ELEMENT_P ); 435 438 std::string mat = name + "_material"; 436 439 polys->setMaterial( mat.c_str() ); … … 440 443 polylist = createPrimGroup<domPolylist>( COLLADA_ELEMENT_POLYLIST, mesh, norm, color, texcoord ); 441 444 442 polylist-> createAndPlace( COLLADA_ELEMENT_VCOUNT );443 polylist-> createAndPlace( COLLADA_ELEMENT_P );445 polylist->add( COLLADA_ELEMENT_VCOUNT ); 446 polylist->add( COLLADA_ELEMENT_P ); 444 447 std::string mat = name + "_material"; 445 448 polylist->setMaterial( mat.c_str() ); … … 493 496 { 494 497 polys = createPrimGroup<domPolygons>( COLLADA_ELEMENT_POLYGONS, mesh, norm, color, texcoord ); 495 polys-> createAndPlace( COLLADA_ELEMENT_P );498 polys->add( COLLADA_ELEMENT_P ); 496 499 std::string mat = name + "_material"; 497 500 polys->setMaterial( mat.c_str() ); … … 501 504 polylist = createPrimGroup<domPolylist>( COLLADA_ELEMENT_POLYLIST, mesh, norm, color, texcoord ); 502 505 503 polylist-> createAndPlace( COLLADA_ELEMENT_VCOUNT );504 polylist-> createAndPlace( COLLADA_ELEMENT_P );506 polylist->add( COLLADA_ELEMENT_VCOUNT ); 507 polylist->add( COLLADA_ELEMENT_P ); 505 508 std::string mat = name + "_material"; 506 509 polylist->setMaterial( mat.c_str() ); … … 550 553 case GL_LINE_STRIP: 551 554 { 552 p.push_back(daeSafeCast<domP>( linestrips-> createAndPlace( COLLADA_ELEMENT_P ) ));555 p.push_back(daeSafeCast<domP>( linestrips->add( COLLADA_ELEMENT_P ) )); 553 556 linestrips->setCount( linestrips->getCount() + 1 ); 554 557 break; … … 556 559 case GL_TRIANGLE_STRIP: 557 560 { 558 p.push_back(daeSafeCast<domP>( tristrips-> createAndPlace( COLLADA_ELEMENT_P ) ));561 p.push_back(daeSafeCast<domP>( tristrips->add( COLLADA_ELEMENT_P ) )); 559 562 tristrips->setCount( tristrips->getCount() + 1 ); 560 563 break; … … 562 565 case GL_TRIANGLE_FAN: 563 566 { 564 p.push_back(daeSafeCast<domP>( trifans-> createAndPlace( COLLADA_ELEMENT_P ) ));567 p.push_back(daeSafeCast<domP>( trifans->add( COLLADA_ELEMENT_P ) )); 565 568 trifans->setCount( trifans->getCount() + 1 ); 566 569 break; … … 651 654 case GL_LINE_STRIP: 652 655 { 653 p.push_back(daeSafeCast<domP>( linestrips-> createAndPlace( COLLADA_ELEMENT_P ) ));656 p.push_back(daeSafeCast<domP>( linestrips->add( COLLADA_ELEMENT_P ) )); 654 657 linestrips->setCount( linestrips->getCount() + 1 ); 655 658 break; … … 657 660 case GL_TRIANGLE_STRIP: 658 661 { 659 p.push_back(daeSafeCast<domP>( tristrips-> createAndPlace( COLLADA_ELEMENT_P ) ));662 p.push_back(daeSafeCast<domP>( tristrips->add( COLLADA_ELEMENT_P ) )); 660 663 tristrips->setCount( tristrips->getCount() + 1 ); 661 664 break; … … 663 666 case GL_TRIANGLE_FAN: 664 667 { 665 p.push_back(daeSafeCast<domP>( trifans-> createAndPlace( COLLADA_ELEMENT_P ) ));668 p.push_back(daeSafeCast<domP>( trifans->add( COLLADA_ELEMENT_P ) )); 666 669 trifans->setCount( trifans->getCount() + 1 ); 667 670 break; … … 745 748 case GL_LINE_STRIP: 746 749 { 747 p.push_back(daeSafeCast<domP>( linestrips-> createAndPlace( COLLADA_ELEMENT_P ) ));750 p.push_back(daeSafeCast<domP>( linestrips->add( COLLADA_ELEMENT_P ) )); 748 751 linestrips->setCount( linestrips->getCount() + 1 ); 749 752 break; … … 751 754 case GL_TRIANGLE_STRIP: 752 755 { 753 p.push_back(daeSafeCast<domP>( tristrips-> createAndPlace( COLLADA_ELEMENT_P ) ));756 p.push_back(daeSafeCast<domP>( tristrips->add( COLLADA_ELEMENT_P ) )); 754 757 tristrips->setCount( tristrips->getCount() + 1 ); 755 758 break; … … 757 760 case GL_TRIANGLE_FAN: 758 761 { 759 p.push_back(daeSafeCast<domP>( trifans-> createAndPlace( COLLADA_ELEMENT_P ) ));762 p.push_back(daeSafeCast<domP>( trifans->add( COLLADA_ELEMENT_P ) )); 760 763 trifans->setCount( trifans->getCount() + 1 ); 761 764 break; … … 844 847 case GL_LINE_STRIP: 845 848 { 846 p.push_back(daeSafeCast<domP>( linestrips-> createAndPlace( COLLADA_ELEMENT_P ) ));849 p.push_back(daeSafeCast<domP>( linestrips->add( COLLADA_ELEMENT_P ) )); 847 850 linestrips->setCount( linestrips->getCount() + 1 ); 848 851 break; … … 850 853 case GL_TRIANGLE_STRIP: 851 854 { 852 p.push_back(daeSafeCast<domP>( tristrips-> createAndPlace( COLLADA_ELEMENT_P ) ));855 p.push_back(daeSafeCast<domP>( tristrips->add( COLLADA_ELEMENT_P ) )); 853 856 tristrips->setCount( tristrips->getCount() + 1 ); 854 857 break; … … 856 859 case GL_TRIANGLE_FAN: 857 860 { 858 p.push_back(daeSafeCast<domP>( trifans-> createAndPlace( COLLADA_ELEMENT_P ) ));861 p.push_back(daeSafeCast<domP>( trifans->add( COLLADA_ELEMENT_P ) )); 859 862 trifans->setCount( trifans->getCount() + 1 ); 860 863 break; … … 945 948 case GL_LINE_STRIP: 946 949 { 947 p.push_back(daeSafeCast<domP>( linestrips-> createAndPlace( COLLADA_ELEMENT_P ) ));950 p.push_back(daeSafeCast<domP>( linestrips->add( COLLADA_ELEMENT_P ) )); 948 951 linestrips->setCount( linestrips->getCount() + 1 ); 949 952 break; … … 951 954 case GL_TRIANGLE_STRIP: 952 955 { 953 p.push_back(daeSafeCast<domP>( tristrips-> createAndPlace( COLLADA_ELEMENT_P ) ));956 p.push_back(daeSafeCast<domP>( tristrips->add( COLLADA_ELEMENT_P ) )); 954 957 tristrips->setCount( tristrips->getCount() + 1 ); 955 958 break; … … 957 960 case GL_TRIANGLE_FAN: 958 961 { 959 p.push_back(daeSafeCast<domP>( trifans-> createAndPlace( COLLADA_ELEMENT_P ) ));962 p.push_back(daeSafeCast<domP>( trifans->add( COLLADA_ELEMENT_P ) )); 960 963 trifans->setCount( trifans->getCount() + 1 ); 961 964 break; … … 1039 1042 domSource *daeWriter::createSource( daeElement *parent, const std::string &baseName, int size, bool color, bool uv ) 1040 1043 { 1041 domSource *src = daeSafeCast< domSource >( parent-> createAndPlace( COLLADA_ELEMENT_SOURCE ) );1044 domSource *src = daeSafeCast< domSource >( parent->add( COLLADA_ELEMENT_SOURCE ) ); 1042 1045 if ( src == NULL ) 1043 1046 { … … 1046 1049 src->setId( baseName.c_str() ); 1047 1050 1048 domFloat_array *fa = daeSafeCast< domFloat_array >( src-> createAndPlace( COLLADA_ELEMENT_FLOAT_ARRAY ) );1051 domFloat_array *fa = daeSafeCast< domFloat_array >( src->add( COLLADA_ELEMENT_FLOAT_ARRAY ) ); 1049 1052 std::string fName = baseName + "-array"; 1050 1053 fa->setId( fName.c_str() ); 1051 1054 1052 domSource::domTechnique_common *teq = daeSafeCast< domSource::domTechnique_common >( src-> createAndPlace( "technique_common" ) );1053 domAccessor *acc = daeSafeCast< domAccessor >( teq-> createAndPlace( COLLADA_ELEMENT_ACCESSOR ) );1055 domSource::domTechnique_common *teq = daeSafeCast< domSource::domTechnique_common >( src->add( "technique_common" ) ); 1056 domAccessor *acc = daeSafeCast< domAccessor >( teq->add( COLLADA_ELEMENT_ACCESSOR ) ); 1054 1057 std::string url = "#" + fName; 1055 1058 acc->setSource( url.c_str() ); … … 1058 1061 { 1059 1062 acc->setStride( size ); 1060 param = daeSafeCast< domParam >( acc-> createAndPlace( COLLADA_ELEMENT_PARAM ) );1063 param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 1061 1064 param->setName( "R" ); 1062 1065 param->setType( "float" ); 1063 1066 1064 param = daeSafeCast< domParam >( acc-> createAndPlace( COLLADA_ELEMENT_PARAM ) );1067 param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 1065 1068 param->setName( "G" ); 1066 1069 param->setType( "float" ); 1067 1070 1068 param = daeSafeCast< domParam >( acc-> createAndPlace( COLLADA_ELEMENT_PARAM ) );1071 param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 1069 1072 param->setName( "B" ); 1070 1073 param->setType( "float" ); 1071 1074 1072 1075 if ( size == 4 ) { 1073 param = daeSafeCast< domParam >( acc-> createAndPlace( COLLADA_ELEMENT_PARAM ) );1076 param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 1074 1077 param->setName( "A" ); 1075 1078 param->setType( "float" ); … … 1080 1083 { 1081 1084 acc->setStride( size ); 1082 param = daeSafeCast< domParam >( acc-> createAndPlace( COLLADA_ELEMENT_PARAM ) );1085 param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 1083 1086 param->setName( "S" ); 1084 1087 param->setType( "float" ); 1085 1088 1086 param = daeSafeCast< domParam >( acc-> createAndPlace( COLLADA_ELEMENT_PARAM ) );1089 param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 1087 1090 param->setName( "T" ); 1088 1091 param->setType( "float" ); … … 1090 1093 if ( size >=3 ) 1091 1094 { 1092 param = daeSafeCast< domParam >( acc-> createAndPlace( COLLADA_ELEMENT_PARAM ) );1095 param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 1093 1096 param->setName( "P" ); 1094 1097 param->setType( "float" ); … … 1098 1101 { 1099 1102 acc->setStride( size ); 1100 param = daeSafeCast< domParam >( acc-> createAndPlace( COLLADA_ELEMENT_PARAM ) );1103 param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 1101 1104 param->setName( "X" ); 1102 1105 param->setType( "float" ); 1103 1106 1104 param = daeSafeCast< domParam >( acc-> createAndPlace( COLLADA_ELEMENT_PARAM ) );1107 param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 1105 1108 param->setName( "Y" ); 1106 1109 param->setType( "float" ); … … 1108 1111 if ( size >=3 ) 1109 1112 { 1110 param = daeSafeCast< domParam >( acc-> createAndPlace( COLLADA_ELEMENT_PARAM ) );1113 param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 1111 1114 param->setName( "Z" ); 1112 1115 param->setType( "float" ); … … 1114 1117 if ( size == 4 ) 1115 1118 { 1116 param = daeSafeCast< domParam >( acc-> createAndPlace( COLLADA_ELEMENT_PARAM ) );1119 param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 1117 1120 param->setName( "W" ); 1118 1121 param->setType( "float" ); … … 1128 1131 { 1129 1132 unsigned int offset = 0; 1130 Ty *retVal = daeSafeCast< Ty >( mesh-> createAndPlace( type ) );1131 domInputLocalOffset *ilo = daeSafeCast< domInputLocalOffset >( retVal-> createAndPlace( "input" ) );1133 Ty *retVal = daeSafeCast< Ty >( mesh->add( type ) ); 1134 domInputLocalOffset *ilo = daeSafeCast< domInputLocalOffset >( retVal->add( "input" ) ); 1132 1135 ilo->setOffset( offset++ ); 1133 1136 ilo->setSemantic( "VERTEX" ); … … 1136 1139 if ( norm != NULL ) 1137 1140 { 1138 ilo = daeSafeCast< domInputLocalOffset >( retVal-> createAndPlace( "input" ) );1141 ilo = daeSafeCast< domInputLocalOffset >( retVal->add( "input" ) ); 1139 1142 ilo->setOffset( offset++ ); 1140 1143 ilo->setSemantic( "NORMAL" ); … … 1144 1147 if ( color != NULL ) 1145 1148 { 1146 ilo = daeSafeCast< domInputLocalOffset >( retVal-> createAndPlace( "input" ) );1149 ilo = daeSafeCast< domInputLocalOffset >( retVal->add( "input" ) ); 1147 1150 ilo->setOffset( offset++ ); 1148 1151 ilo->setSemantic( "COLOR" ); … … 1152 1155 for ( unsigned int i = 0; i < texcoord.size(); i++ ) 1153 1156 { 1154 ilo = daeSafeCast< domInputLocalOffset >( retVal-> createAndPlace( "input" ) );1157 ilo = daeSafeCast< domInputLocalOffset >( retVal->add( "input" ) ); 1155 1158 ilo->setOffset( offset++ ); 1156 1159 ilo->setSemantic( "TEXCOORD" ); -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeWMaterials.cpp
r8353 r9228 34 34 { 35 35 osg::ref_ptr<osg::StateSet> ssClean = CleanStateSet(ss); // Need to hold a ref to this or the materialMap.find() will delete it 36 domBind_material *bm = daeSafeCast< domBind_material >( ig-> createAndPlace( COLLADA_ELEMENT_BIND_MATERIAL ) );37 domBind_material::domTechnique_common *tc = daeSafeCast< domBind_material::domTechnique_common >( bm-> createAndPlace( "technique_common" ) );38 domInstance_material *im = daeSafeCast< domInstance_material >( tc-> createAndPlace( COLLADA_ELEMENT_INSTANCE_MATERIAL ) );36 domBind_material *bm = daeSafeCast< domBind_material >( ig->add( COLLADA_ELEMENT_BIND_MATERIAL ) ); 37 domBind_material::domTechnique_common *tc = daeSafeCast< domBind_material::domTechnique_common >( bm->add( "technique_common" ) ); 38 domInstance_material *im = daeSafeCast< domInstance_material >( tc->add( COLLADA_ELEMENT_INSTANCE_MATERIAL ) ); 39 39 std::string symbol = geoName + "_material"; 40 40 im->setSymbol( symbol.c_str() ); … … 50 50 if ( lib_mats == NULL ) 51 51 { 52 lib_mats = daeSafeCast< domLibrary_materials >( dom-> createAndPlace( COLLADA_ELEMENT_LIBRARY_MATERIALS ) );53 } 54 55 domMaterial *mat = daeSafeCast< domMaterial >( lib_mats-> createAndPlace( COLLADA_ELEMENT_MATERIAL ) );52 lib_mats = daeSafeCast< domLibrary_materials >( dom->add( COLLADA_ELEMENT_LIBRARY_MATERIALS ) ); 53 } 54 55 domMaterial *mat = daeSafeCast< domMaterial >( lib_mats->add( COLLADA_ELEMENT_MATERIAL ) ); 56 56 std::string name = ssClean->getName(); 57 57 if ( name.empty() ) … … 66 66 im->setTarget( url.c_str() ); 67 67 68 domInstance_effect *ie = daeSafeCast<domInstance_effect>( mat-> createAndPlace( "instance_effect" ) );68 domInstance_effect *ie = daeSafeCast<domInstance_effect>( mat->add( "instance_effect" ) ); 69 69 70 70 if ( lib_effects == NULL ) 71 71 { 72 lib_effects = daeSafeCast< domLibrary_effects >( dom-> createAndPlace( COLLADA_ELEMENT_LIBRARY_EFFECTS ) );73 } 74 domEffect *effect = daeSafeCast< domEffect >( lib_effects-> createAndPlace( COLLADA_ELEMENT_EFFECT ) );72 lib_effects = daeSafeCast< domLibrary_effects >( dom->add( COLLADA_ELEMENT_LIBRARY_EFFECTS ) ); 73 } 74 domEffect *effect = daeSafeCast< domEffect >( lib_effects->add( COLLADA_ELEMENT_EFFECT ) ); 75 75 std::string efName = name + "_effect"; 76 76 … … 80 80 ie->setUrl( url.c_str() ); 81 81 82 domProfile_COMMON *pc = daeSafeCast< domProfile_COMMON >( effect-> createAndPlace( COLLADA_ELEMENT_PROFILE_COMMON ) );83 domProfile_COMMON::domTechnique *pc_teq = daeSafeCast< domProfile_COMMON::domTechnique >( pc-> createAndPlace( "technique" ) );82 domProfile_COMMON *pc = daeSafeCast< domProfile_COMMON >( effect->add( COLLADA_ELEMENT_PROFILE_COMMON ) ); 83 domProfile_COMMON::domTechnique *pc_teq = daeSafeCast< domProfile_COMMON::domTechnique >( pc->add( "technique" ) ); 84 84 pc_teq->setSid( "t0" ); 85 domProfile_COMMON::domTechnique::domPhong *phong = daeSafeCast< domProfile_COMMON::domTechnique::domPhong >( pc_teq-> createAndPlace( "phong" ) );85 domProfile_COMMON::domTechnique::domPhong *phong = daeSafeCast< domProfile_COMMON::domTechnique::domPhong >( pc_teq->add( "phong" ) ); 86 86 87 87 osg::Texture *tex = static_cast<osg::Texture*>(ssClean->getTextureAttribute( 0, osg::StateAttribute::TEXTURE )); … … 93 93 { 94 94 //TODO: Export all of the texture Attributes like wrap mode and all that jazz 95 domImage *img = daeSafeCast< domImage >( pc-> createAndPlace( COLLADA_ELEMENT_IMAGE ) );95 domImage *img = daeSafeCast< domImage >( pc->add( COLLADA_ELEMENT_IMAGE ) ); 96 96 std::string iName = efName + "-image"; 97 97 img->setId( iName.c_str() ); 98 98 99 99 osg::Image *osgimg = tex->getImage( 0 ); 100 domImage::domInit_from *imgif = daeSafeCast< domImage::domInit_from >( img-> createAndPlace( "init_from" ) );100 domImage::domInit_from *imgif = daeSafeCast< domImage::domInit_from >( img->add( "init_from" ) ); 101 101 std::string fileURI = ReaderWriterDAE::ConvertFilePathToColladaCompatibleURI(osgDB::findDataFile(osgimg->getFileName())); 102 102 daeURI dd(*dae, fileURI);//fileURI.c_str() ); … … 106 106 107 107 #ifndef EARTH_TEX 108 domCommon_newparam_type *np = daeSafeCast< domCommon_newparam_type >( pc-> createAndPlace( "newparam" ) );108 domCommon_newparam_type *np = daeSafeCast< domCommon_newparam_type >( pc->add( "newparam" ) ); 109 109 std::string surfName = efName + "-surface"; 110 110 np->setSid( surfName.c_str() ); 111 domFx_surface_common *surface = daeSafeCast< domFx_surface_common >( np-> createAndPlace( "surface" ) );112 domFx_surface_init_from_common *sif = daeSafeCast< domFx_surface_init_from_common >( surface-> createAndPlace("init_from") );111 domFx_surface_common *surface = daeSafeCast< domFx_surface_common >( np->add( "surface" ) ); 112 domFx_surface_init_from_common *sif = daeSafeCast< domFx_surface_init_from_common >( surface->add("init_from") ); 113 113 sif->setValue( iName.c_str() ); 114 114 surface->setType( FX_SURFACE_TYPE_ENUM_2D ); 115 115 116 np = daeSafeCast< domCommon_newparam_type >( pc-> createAndPlace( "newparam" ) );116 np = daeSafeCast< domCommon_newparam_type >( pc->add( "newparam" ) ); 117 117 std::string sampName = efName + "-sampler"; 118 118 np->setSid( sampName.c_str() ); 119 domFx_sampler2D_common *sampler = daeSafeCast< domFx_sampler2D_common >( np-> createAndPlace( "sampler2D" ) );120 domFx_sampler2D_common_complexType::domSource *source = daeSafeCast< domFx_sampler2D_common_complexType::domSource >( sampler-> createAndPlace( "source" ) );119 domFx_sampler2D_common *sampler = daeSafeCast< domFx_sampler2D_common >( np->add( "sampler2D" ) ); 120 domFx_sampler2D_common_complexType::domSource *source = daeSafeCast< domFx_sampler2D_common_complexType::domSource >( sampler->add( "source" ) ); 121 121 source->setValue( surfName.c_str() ); 122 122 123 123 //set sampler state 124 domFx_sampler2D_common_complexType::domWrap_s *wrap_s = daeSafeCast< domFx_sampler2D_common_complexType::domWrap_s >( sampler-> createAndPlace( "wrap_s" ) );124 domFx_sampler2D_common_complexType::domWrap_s *wrap_s = daeSafeCast< domFx_sampler2D_common_complexType::domWrap_s >( sampler->add( "wrap_s" ) ); 125 125 osg::Texture::WrapMode wrap = tex->getWrap( osg::Texture::WRAP_S ); 126 126 switch( wrap ) … … 144 144 } 145 145 146 domFx_sampler2D_common_complexType::domWrap_t *wrap_t = daeSafeCast< domFx_sampler2D_common_complexType::domWrap_t >( sampler-> createAndPlace( "wrap_t" ) );146 domFx_sampler2D_common_complexType::domWrap_t *wrap_t = daeSafeCast< domFx_sampler2D_common_complexType::domWrap_t >( sampler->add( "wrap_t" ) ); 147 147 wrap = tex->getWrap( osg::Texture::WRAP_T ); 148 148 switch( wrap ) … … 167 167 168 168 const osg::Vec4 &bcol = tex->getBorderColor(); 169 domFx_sampler2D_common_complexType::domBorder_color *dbcol = daeSafeCast< domFx_sampler2D_common_complexType::domBorder_color >( sampler-> createAndPlace( "border_color" ) );169 domFx_sampler2D_common_complexType::domBorder_color *dbcol = daeSafeCast< domFx_sampler2D_common_complexType::domBorder_color >( sampler->add( "border_color" ) ); 170 170 dbcol->getValue().append( bcol.r() ); 171 171 dbcol->getValue().append( bcol.g() ); … … 173 173 dbcol->getValue().append( bcol.a() ); 174 174 175 domFx_sampler2D_common_complexType::domMinfilter *minfilter = daeSafeCast< domFx_sampler2D_common_complexType::domMinfilter >( sampler-> createAndPlace( "minfilter" ) );175 domFx_sampler2D_common_complexType::domMinfilter *minfilter = daeSafeCast< domFx_sampler2D_common_complexType::domMinfilter >( sampler->add( "minfilter" ) ); 176 176 osg::Texture::FilterMode mode = tex->getFilter( osg::Texture::MIN_FILTER ); 177 177 switch( mode ) … … 197 197 } 198 198 199 domFx_sampler2D_common_complexType::domMagfilter *magfilter = daeSafeCast< domFx_sampler2D_common_complexType::domMagfilter >( sampler-> createAndPlace( "magfilter" ) );199 domFx_sampler2D_common_complexType::domMagfilter *magfilter = daeSafeCast< domFx_sampler2D_common_complexType::domMagfilter >( sampler->add( "magfilter" ) ); 200 200 mode = tex->getFilter( osg::Texture::MAG_FILTER ); 201 201 switch( mode ) … … 222 222 223 223 224 domCommon_color_or_texture_type *cot = daeSafeCast< domCommon_color_or_texture_type >( phong-> createAndPlace( "diffuse" ) );225 domCommon_color_or_texture_type_complexType::domTexture *dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >( cot-> createAndPlace( "texture" ) );224 domCommon_color_or_texture_type *cot = daeSafeCast< domCommon_color_or_texture_type >( phong->add( "diffuse" ) ); 225 domCommon_color_or_texture_type_complexType::domTexture *dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >( cot->add( "texture" ) ); 226 226 dtex->setTexture( sampName.c_str() ); 227 227 dtex->setTexcoord( "texcoord0" ); 228 228 #else 229 domCommon_color_or_texture_type *cot = daeSafeCast< domCommon_color_or_texture_type >( phong-> createAndPlace( "diffuse" ) );230 domCommon_color_or_texture_type_complexType::domTexture *dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >( cot-> createAndPlace( "texture" ) );229 domCommon_color_or_texture_type *cot = daeSafeCast< domCommon_color_or_texture_type >( phong->add( "diffuse" ) ); 230 domCommon_color_or_texture_type_complexType::domTexture *dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >( cot->add( "texture" ) ); 231 231 dtex->setTexture( iName.c_str() ); 232 232 dtex->setTexcoord( "texcoord0" ); 233 233 #endif 234 234 235 domInstance_material::domBind_vertex_input *bvi = daeSafeCast< domInstance_material::domBind_vertex_input >( im-> createAndPlace( "bind_vertex_input" ) );235 domInstance_material::domBind_vertex_input *bvi = daeSafeCast< domInstance_material::domBind_vertex_input >( im->add( "bind_vertex_input" ) ); 236 236 bvi->setSemantic( "texcoord0" ); 237 237 bvi->setInput_semantic( "TEXCOORD" ); 238 238 bvi->setInput_set( 0 ); 239 240 /* I dont think this belongs here RFJ241 //take care of blending if any242 osg::BlendFunc *bf = static_cast< osg::BlendFunc * >( ssClean->getAttribute( osg::StateAttribute::BLENDFUNC ) );243 osg::BlendColor *bc = static_cast< osg::BlendColor * >( ssClean->getAttribute( osg::StateAttribute::BLENDCOLOR ) );244 if ( bc != NULL )245 {246 domCommon_transparent_type *ctt = daeSafeCast< domCommon_transparent_type >( phong->createAndPlace( "transparent" ) );247 ctt->setOpaque( FX_OPAQUE_ENUM_RGB_ZERO );248 domCommon_color_or_texture_type_complexType::domColor *tcol = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( ctt->createAndPlace( "color" ) );249 tcol->getValue().append( bc->getConstantColor().r() );250 tcol->getValue().append( bc->getConstantColor().r() );251 tcol->getValue().append( bc->getConstantColor().r() );252 tcol->getValue().append( bc->getConstantColor().r() );253 }254 else if ( bf != NULL )255 {256 domCommon_transparent_type *ctt = daeSafeCast< domCommon_transparent_type >( phong->createAndPlace( "transparent" ) );257 ctt->setOpaque( FX_OPAQUE_ENUM_A_ONE );258 dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >( ctt->createAndPlace( "texture" ) );259 #ifndef EARTH_TEX260 dtex->setTexture( sampName.c_str() );261 #else262 dtex->setTexture( iName.c_str() );263 #endif264 dtex->setTexcoord( "texcoord0" );265 }266 */267 239 } 268 240 osg::Material *osgmat = static_cast<osg::Material*>(ssClean->getAttribute( osg::StateAttribute::MATERIAL )); … … 275 247 float shininess = osgmat->getShininessFrontAndBack()?osgmat->getShininess( osg::Material::FRONT_AND_BACK ):osgmat->getShininess( osg::Material::FRONT ); 276 248 277 domCommon_color_or_texture_type *cot = daeSafeCast< domCommon_color_or_texture_type >( phong-> createAndPlace( "emission" ) );278 domCommon_color_or_texture_type_complexType::domColor *col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot-> createAndPlace( "color" ) );249 domCommon_color_or_texture_type *cot = daeSafeCast< domCommon_color_or_texture_type >( phong->add( "emission" ) ); 250 domCommon_color_or_texture_type_complexType::domColor *col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->add( "color" ) ); 279 251 col->getValue().append( eCol.r() ); 280 252 col->getValue().append( eCol.g() ); … … 282 254 col->getValue().append( eCol.a() ); 283 255 284 cot = daeSafeCast< domCommon_color_or_texture_type >( phong-> createAndPlace( "ambient" ) );285 col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot-> createAndPlace( "color" ) );256 cot = daeSafeCast< domCommon_color_or_texture_type >( phong->add( "ambient" ) ); 257 col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->add( "color" ) ); 286 258 col->getValue().append( aCol.r() ); 287 259 col->getValue().append( aCol.g() ); … … 293 265 if ( phong->getDiffuse() == NULL ) 294 266 { 295 cot = daeSafeCast< domCommon_color_or_texture_type >( phong-> createAndPlace( "diffuse" ) );296 col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot-> createAndPlace( "color" ) );267 cot = daeSafeCast< domCommon_color_or_texture_type >( phong->add( "diffuse" ) ); 268 col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->add( "color" ) ); 297 269 col->getValue().append( dCol.r() ); 298 270 col->getValue().append( dCol.g() ); … … 304 276 cot = phong->getDiffuse(); 305 277 306 domCommon_color_or_texture_type_complexType::domTexture *dtex = cot->getTexture(); 307 domExtra *extra = daeSafeCast< domExtra >( dtex->createAndPlace( COLLADA_ELEMENT_EXTRA ) ); 308 extra->setType( "color" ); 309 domTechnique *teq = daeSafeCast< domTechnique >( extra->createAndPlace( COLLADA_ELEMENT_TECHNIQUE ) ); 310 teq->setProfile( "SCEI" ); 311 domAny *any = (domAny*)(daeElement*)teq->createAndPlace( "color" ); 312 313 std::ostringstream colVal; 314 colVal << dCol.r() << " " << dCol.g() << " " << dCol.b() << " " << dCol.a(); 315 any->setValue( colVal.str().c_str() ); 316 } 317 318 cot = daeSafeCast< domCommon_color_or_texture_type >( phong->createAndPlace( "specular" ) ); 319 col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->createAndPlace( "color" ) ); 278 if (writeExtras) 279 { 280 // Adds the following to a texture element 281 282 //<extra type="color"> 283 // <technique profile="SCEI"> 284 // <color>1.0 1.0 1.0 1.0</color> 285 // </technique> 286 //</extra> 287 288 domCommon_color_or_texture_type_complexType::domTexture *dtex = cot->getTexture(); 289 domExtra *extra = daeSafeCast< domExtra >( dtex->add( COLLADA_ELEMENT_EXTRA ) ); 290 extra->setType( "color" ); 291 domTechnique *teq = daeSafeCast< domTechnique >( extra->add( COLLADA_ELEMENT_TECHNIQUE ) ); 292 teq->setProfile( "SCEI" ); 293 domAny *any = (domAny*)(daeElement*)teq->add( "color" ); 294 295 std::ostringstream colVal; 296 colVal << dCol.r() << " " << dCol.g() << " " << dCol.b() << " " << dCol.a(); 297 any->setValue( colVal.str().c_str() ); 298 } 299 } 300 301 cot = daeSafeCast< domCommon_color_or_texture_type >( phong->add( "specular" ) ); 302 col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->add( "color" ) ); 320 303 col->getValue().append( sCol.r() ); 321 304 col->getValue().append( sCol.g() ); … … 323 306 col->getValue().append( sCol.a() ); 324 307 325 domCommon_float_or_param_type *fop = daeSafeCast< domCommon_float_or_param_type >( phong-> createAndPlace( "shininess" ) );326 domCommon_float_or_param_type_complexType::domFloat *f = daeSafeCast< domCommon_float_or_param_type_complexType::domFloat >( fop-> createAndPlace( "float" ) );308 domCommon_float_or_param_type *fop = daeSafeCast< domCommon_float_or_param_type >( phong->add( "shininess" ) ); 309 domCommon_float_or_param_type_complexType::domFloat *f = daeSafeCast< domCommon_float_or_param_type_complexType::domFloat >( fop->add( "float" ) ); 327 310 f->setValue( shininess ); 328 311 } … … 334 317 osg::BlendFunc *pBlendFunc = static_cast< osg::BlendFunc * >( ssClean->getAttribute( osg::StateAttribute::BLENDFUNC ) ); 335 318 osg::BlendColor *pBlendColor = static_cast< osg::BlendColor * >( ssClean->getAttribute( osg::StateAttribute::BLENDCOLOR ) ); 336 if ( (NULL != pBlendFunc) && (NULL != pBlendColor))337 { 338 if ( (GL_CONSTANT_ALPHA == pBlendFunc->getSource()) && (GL_ONE_MINUS_CONSTANT_ALPHA == pBlendFunc->getDestination()))319 if (pBlendFunc != NULL) 320 { 321 if (pBlendColor != NULL) 339 322 { 340 // A_ONE opaque mode 341 domCommon_transparent_type *pTransparent = daeSafeCast<domCommon_transparent_type>(phong->createAndPlace("transparent")); 342 pTransparent->setOpaque(FX_OPAQUE_ENUM_A_ONE); 343 domCommon_color_or_texture_type_complexType::domColor *pColor = daeSafeCast<domCommon_color_or_texture_type_complexType::domColor>(pTransparent->createAndPlace("color")); 344 domCommon_float_or_param_type *pFop = daeSafeCast<domCommon_float_or_param_type>(phong->createAndPlace( "transparency")); 345 domCommon_float_or_param_type_complexType::domFloat *pTransparency = daeSafeCast<domCommon_float_or_param_type_complexType::domFloat>(pFop->createAndPlace("float")); 346 if (m_GoogleMode) 323 if ((GL_CONSTANT_ALPHA == pBlendFunc->getSource()) && (GL_ONE_MINUS_CONSTANT_ALPHA == pBlendFunc->getDestination())) 347 324 { 348 pColor->getValue().append(1.0); 349 pColor->getValue().append(1.0); 350 pColor->getValue().append(1.0); 351 pColor->getValue().append(1.0); 352 pTransparency->setValue(1.0 - pBlendColor->getConstantColor().a()); 325 // A_ONE opaque mode 326 domCommon_transparent_type *pTransparent = daeSafeCast<domCommon_transparent_type>(phong->add("transparent")); 327 pTransparent->setOpaque(FX_OPAQUE_ENUM_A_ONE); 328 domCommon_color_or_texture_type_complexType::domColor *pColor = daeSafeCast<domCommon_color_or_texture_type_complexType::domColor>(pTransparent->add("color")); 329 domCommon_float_or_param_type *pFop = daeSafeCast<domCommon_float_or_param_type>(phong->add( "transparency")); 330 domCommon_float_or_param_type_complexType::domFloat *pTransparency = daeSafeCast<domCommon_float_or_param_type_complexType::domFloat>(pFop->add("float")); 331 if (m_GoogleMode) 332 { 333 pColor->getValue().append(1.0); 334 pColor->getValue().append(1.0); 335 pColor->getValue().append(1.0); 336 pColor->getValue().append(1.0); 337 pTransparency->setValue(1.0 - pBlendColor->getConstantColor().a()); 338 } 339 else 340 { 341 pColor->getValue().append(pBlendColor->getConstantColor().r()); 342 pColor->getValue().append(pBlendColor->getConstantColor().g()); 343 pColor->getValue().append(pBlendColor->getConstantColor().b()); 344 pColor->getValue().append(pBlendColor->getConstantColor().a()); 345 pTransparency->setValue(1.0); 346 } 353 347 } 354 else 348 else if ((GL_ONE_MINUS_CONSTANT_COLOR == pBlendFunc->getSource()) && (GL_CONSTANT_COLOR == pBlendFunc->getDestination())) 355 349 { 350 // RGB_ZERO opaque mode 351 domCommon_transparent_type *pTransparent = daeSafeCast<domCommon_transparent_type>(phong->add("transparent")); 352 pTransparent->setOpaque(FX_OPAQUE_ENUM_RGB_ZERO); 353 domCommon_color_or_texture_type_complexType::domColor *pColor = daeSafeCast<domCommon_color_or_texture_type_complexType::domColor>(pTransparent->add("color")); 356 354 pColor->getValue().append(pBlendColor->getConstantColor().r()); 357 355 pColor->getValue().append(pBlendColor->getConstantColor().g()); 358 356 pColor->getValue().append(pBlendColor->getConstantColor().b()); 359 357 pColor->getValue().append(pBlendColor->getConstantColor().a()); 358 domCommon_float_or_param_type *pFop = daeSafeCast<domCommon_float_or_param_type>(phong->add( "transparency")); 359 domCommon_float_or_param_type_complexType::domFloat *pTransparency = daeSafeCast<domCommon_float_or_param_type_complexType::domFloat>(pFop->add("float")); 360 360 pTransparency->setValue(1.0); 361 361 } 362 else 363 osg::notify( osg::WARN ) << "Unsupported BlendFunction parameters in transparency processing." << std::endl; 362 364 } 363 else if ( (GL_ONE_MINUS_CONSTANT_COLOR == pBlendFunc->getSource()) && (GL_CONSTANT_COLOR == pBlendFunc->getDestination()))365 else if (tex != NULL && tex->getImage( 0 ) != NULL) 364 366 { 365 // RGB_ZERO opaque mode 366 domCommon_transparent_type *pTransparent = daeSafeCast<domCommon_transparent_type>(phong->createAndPlace("transparent")); 367 pTransparent->setOpaque(FX_OPAQUE_ENUM_RGB_ZERO); 368 domCommon_color_or_texture_type_complexType::domColor *pColor = daeSafeCast<domCommon_color_or_texture_type_complexType::domColor>(pTransparent->createAndPlace("color")); 369 pColor->getValue().append(pBlendColor->getConstantColor().r()); 370 pColor->getValue().append(pBlendColor->getConstantColor().g()); 371 pColor->getValue().append(pBlendColor->getConstantColor().b()); 372 pColor->getValue().append(pBlendColor->getConstantColor().a()); 373 domCommon_float_or_param_type *pFop = daeSafeCast<domCommon_float_or_param_type>(phong->createAndPlace( "transparency")); 374 domCommon_float_or_param_type_complexType::domFloat *pTransparency = daeSafeCast<domCommon_float_or_param_type_complexType::domFloat>(pFop->createAndPlace("float")); 375 pTransparency->setValue(1.0); 367 domCommon_transparent_type *ctt = daeSafeCast< domCommon_transparent_type >( phong->add( "transparent" ) ); 368 ctt->setOpaque( FX_OPAQUE_ENUM_A_ONE ); 369 domCommon_color_or_texture_type_complexType::domTexture * dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >( ctt->add( "texture" ) ); 370 371 #ifndef EARTH_TEX 372 std::string sampName = efName + "-sampler"; 373 dtex->setTexture( sampName.c_str() ); 374 #else 375 std::string iName = efName + "-image"; 376 dtex->setTexture( iName.c_str() ); 377 #endif 378 dtex->setTexcoord( "texcoord0" ); 376 379 } 377 380 else 378 osg::notify( osg::WARN ) << "Unsupported BlendFunction parameters in transparency processing." << std::endl; 381 { 382 osg::notify( osg::WARN ) << "Transparency processing - No texture or BlendColor." << std::endl; 383 } 379 384 } 380 385 else 381 osg::notify( osg::WARN ) << "Transparency processing - BlendFunction or BlendColor not found." << std::endl; 382 } 383 384 // Process GOOGLE one sided stuff here 385 if (osg::StateAttribute::INHERIT != ssClean->getMode(GL_CULL_FACE)) 386 { 387 domExtra *pExtra = daeSafeCast<domExtra>(pc->createAndPlace(COLLADA_ELEMENT_EXTRA)); 388 domTechnique *pTechnique = daeSafeCast<domTechnique>(pExtra->createAndPlace( COLLADA_ELEMENT_TECHNIQUE ) ); 389 pTechnique->setProfile("GOOGLEEARTH"); 390 domAny *pAny = (domAny*)(daeElement*)pTechnique->createAndPlace("double_sided"); 391 if (GL_FALSE == ssClean->getMode(GL_CULL_FACE)) 392 pAny->setValue("1"); 393 else 394 pAny->setValue("0"); 386 { 387 osg::notify( osg::WARN ) << "Transparency processing - BlendFunction not found." << std::endl; 388 } 389 } 390 391 if (writeExtras) 392 { 393 // Adds the following to a Profile_COMMON element 394 395 //<extra> 396 // <technique profile="GOOGLEEARTH"> 397 // <double_sided>0</double_sided> 398 // </technique> 399 //</extra> 400 401 // Process GOOGLE one sided stuff here 402 if (osg::StateAttribute::INHERIT != ssClean->getMode(GL_CULL_FACE)) 403 { 404 domExtra *pExtra = daeSafeCast<domExtra>(pc->add(COLLADA_ELEMENT_EXTRA)); 405 domTechnique *pTechnique = daeSafeCast<domTechnique>(pExtra->add( COLLADA_ELEMENT_TECHNIQUE ) ); 406 pTechnique->setProfile("GOOGLEEARTH"); 407 domAny *pAny = (domAny*)(daeElement*)pTechnique->add("double_sided"); 408 if (GL_FALSE == ssClean->getMode(GL_CULL_FACE)) 409 pAny->setValue("1"); 410 else 411 pAny->setValue("0"); 412 } 395 413 } 396 414 … … 410 428 pCleanedStateSet->setAttribute(pStateSet->getAttribute(osg::StateAttribute::MATERIAL)); 411 429 // pCleanedStateSet->setRenderingHint(pStateSet->getRenderingHint()); does not work at the moment due to stateSet::merge 412 if (osg::StateAttribute:: INHERIT!= pStateSet->getMode(GL_CULL_FACE))430 if (osg::StateAttribute::ON != pStateSet->getMode(GL_CULL_FACE)) 413 431 pCleanedStateSet->setMode(GL_CULL_FACE, pStateSet->getMode(GL_CULL_FACE)); 414 432 return pCleanedStateSet; -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeWSceneObjects.cpp
r5757 r9228 20 20 #include <dom/domLibrary_cameras.h> 21 21 #include <dom/domLibrary_lights.h> 22 22 #include <dae/domAny.h> 23 23 //#include <dom/domVisual_scene.h> 24 24 //#include <dom/domLibrary_visual_scenes.h> 25 25 26 #include <osgSim/MultiSwitch> 27 #include <osg/Sequence> 28 #include <osg/Billboard> 29 26 30 using namespace osgdae; 27 31 28 29 //GROUP 32 // Write non-standard node data as extra of type "Node" with "OpenSceneGraph" technique 33 void daeWriter::writeNodeExtra(osg::Node &node) 34 { 35 unsigned int numDesc = node.getDescriptions().size(); 36 // Only create extra if descriptions are filled in 37 if (writeExtras && (numDesc > 0)) 38 { 39 // Adds the following to a node 40 41 //<extra type="Node"> 42 // <technique profile="OpenSceneGraph"> 43 // <Descriptions> 44 // <Description>Some info</Description> 45 // </Descriptions> 46 // </technique> 47 //</extra> 48 49 domExtra *extra = daeSafeCast<domExtra>(currentNode->add( COLLADA_ELEMENT_EXTRA )); 50 extra->setType("Node"); 51 domTechnique *teq = daeSafeCast<domTechnique>(extra->add( COLLADA_ELEMENT_TECHNIQUE ) ); 52 teq->setProfile( "OpenSceneGraph" ); 53 domAny *descriptions = (domAny*)teq->add( "Descriptions" ); 54 55 for (unsigned int currDesc = 0; currDesc < numDesc; currDesc++) 56 { 57 std::string value = node.getDescription(currDesc); 58 if (!value.empty()) 59 { 60 domAny *description = (domAny*)descriptions->add( "Description" ); 61 description->setValue(value.c_str()); 62 } 63 } 64 } 65 } 66 30 67 void daeWriter::apply( osg::Group &node ) 31 68 { 32 #ifdef _DEBUG 33 debugPrint( node ); 34 #endif 69 debugPrint( node ); 35 70 36 71 while ( lastDepth >= _nodePath.size() ) … … 40 75 lastDepth--; 41 76 } 42 currentNode = daeSafeCast< domNode >(currentNode->createAndPlace( COLLADA_ELEMENT_NODE ) ); 77 currentNode = daeSafeCast< domNode >(currentNode->add( COLLADA_ELEMENT_NODE ) ); 78 79 // If a multiswitch node, store it's data as extra "MultiSwitch" data in the "OpenSceneGraph" technique 80 osgSim::MultiSwitch* multiswitch = dynamic_cast<osgSim::MultiSwitch*>(&node); 81 if (writeExtras && multiswitch) 82 { 83 // Adds the following to a node 84 85 //<extra type="MultiSwitch"> 86 // <technique profile="OpenSceneGraph"> 87 // <ActiveSwitchSet>0</ActiveSwitchSet> 88 // <ValueLists> 89 // <ValueList>1 0</ValueList> 90 // <ValueList>0 1</ValueList> 91 // </ValueLists> 92 // </technique> 93 //</extra> 94 95 domExtra *extra = daeSafeCast<domExtra>(currentNode->add( COLLADA_ELEMENT_EXTRA )); 96 extra->setType("MultiSwitch"); 97 domTechnique *teq = daeSafeCast<domTechnique>(extra->add( COLLADA_ELEMENT_TECHNIQUE ) ); 98 teq->setProfile( "OpenSceneGraph" ); 99 100 domAny *activeSwitchSet = (domAny*)teq->add("ActiveSwitchSet" ); 101 activeSwitchSet->setValue(toString<unsigned int>(multiswitch->getActiveSwitchSet()).c_str()); 102 103 domAny *valueLists = (domAny*)teq->add( "ValueLists" ); 104 105 unsigned int pos = 0; 106 const osgSim::MultiSwitch::SwitchSetList& switchset = multiswitch->getSwitchSetList(); 107 for(osgSim::MultiSwitch::SwitchSetList::const_iterator sitr=switchset.begin(); 108 sitr!=switchset.end(); 109 ++sitr,++pos) 110 { 111 domAny *valueList = (domAny*)valueLists->add( "ValueList" ); 112 std::stringstream fw; 113 const osgSim::MultiSwitch::ValueList& values = *sitr; 114 for(osgSim::MultiSwitch::ValueList::const_iterator itr=values.begin(); 115 itr!=values.end(); 116 ++itr) 117 { 118 if (itr != values.begin()) 119 { 120 fw << " "; 121 } 122 fw << *itr; 123 } 124 valueList->setValue(fw.str().c_str()); 125 } 126 currentNode->setId(getNodeName(node,"multiswitch").c_str()); 127 } 128 else 129 { 43 130 currentNode->setId(getNodeName(node,"group").c_str()); 131 } 132 133 writeNodeExtra(node); 44 134 45 135 lastDepth = _nodePath.size(); 46 136 47 lastVisited = GROUP; 48 49 traverse( node ); 50 } 51 52 53 //SWITCH 137 traverse( node ); 138 } 139 140 54 141 void daeWriter::apply( osg::Switch &node ) 55 142 { 56 #ifdef _DEBUG 57 debugPrint( node ); 58 #endif 143 debugPrint( node ); 59 144 60 145 while ( lastDepth >= _nodePath.size() ) … … 64 149 lastDepth--; 65 150 } 66 currentNode = daeSafeCast< domNode >(currentNode-> createAndPlace( COLLADA_ELEMENT_NODE ) );151 currentNode = daeSafeCast< domNode >(currentNode->add( COLLADA_ELEMENT_NODE ) ); 67 152 currentNode->setId(getNodeName(node,"switch").c_str()); 153 154 if (writeExtras) 155 { 156 // Adds the following to a node 157 158 //<extra type="Switch"> 159 // <technique profile="OpenSceneGraph"> 160 // <ValueList>1 0</ValueList> 161 // </technique> 162 //</extra> 163 164 domExtra *extra = daeSafeCast<domExtra>(currentNode->add( COLLADA_ELEMENT_EXTRA )); 165 extra->setType("Switch"); 166 domTechnique *teq = daeSafeCast<domTechnique>(extra->add( COLLADA_ELEMENT_TECHNIQUE ) ); 167 teq->setProfile( "OpenSceneGraph" ); 168 169 domAny *valueList = (domAny*)teq->add( "ValueList" ); 170 171 std::stringstream fw; 172 const osg::Switch::ValueList& values = node.getValueList(); 173 for(osg::Switch::ValueList::const_iterator itr=values.begin(); 174 itr!=values.end(); 175 ++itr) 176 { 177 if (itr != values.begin()) 178 { 179 fw << " "; 180 } 181 fw << *itr; 182 } 183 valueList->setValue(fw.str().c_str()); 184 } 185 186 writeNodeExtra(node); 68 187 69 188 lastDepth = _nodePath.size(); 70 189 71 lastVisited = SWITCH; 72 73 unsigned int cnt = node.getNumChildren(); 74 for ( unsigned int i = 0; i < cnt; i++ ) 75 { 76 if ( node.getValue( i ) ) 77 { 78 node.getChild( i )->accept( *this ); 79 } 80 } 81 } 82 83 //LOD 84 void daeWriter::apply( osg::LOD &node ) 85 { 86 #ifdef _DEBUG 87 debugPrint( node ); 88 #endif 190 // Process all children 191 traverse( node ); 192 } 193 194 void daeWriter::apply( osg::Sequence &node ) 195 { 196 debugPrint( node ); 89 197 90 198 while ( lastDepth >= _nodePath.size() ) … … 94 202 lastDepth--; 95 203 } 96 currentNode = daeSafeCast< domNode >(currentNode->createAndPlace( COLLADA_ELEMENT_NODE ) ); 204 currentNode = daeSafeCast< domNode >(currentNode->add( COLLADA_ELEMENT_NODE ) ); 205 currentNode->setId(getNodeName(node,"sequence").c_str()); 206 207 // If a sequence node, store it's data as extra "Sequence" data in the "OpenSceneGraph" technique 208 if (writeExtras) 209 { 210 // Adds the following to a node 211 212 //<extra type="Sequence"> 213 // <technique profile="OpenSceneGraph"> 214 // <FrameTime>0 0</FrameTime> 215 // <LastFrameTime>0</LastFrameTime> 216 // <LoopMode>0</LoopMode> 217 // <IntervalBegin>0</IntervalBegin> 218 // <IntervalEnd>-1</IntervalEnd> 219 // <DurationSpeed>1</DurationSpeed> 220 // <DurationNReps>-1</DurationNReps> 221 // <SequenceMode>0</SequenceMode> 222 // </technique> 223 //</extra> 224 225 domExtra *extra = daeSafeCast<domExtra>(currentNode->add( COLLADA_ELEMENT_EXTRA )); 226 extra->setType("Sequence"); 227 domTechnique *teq = daeSafeCast<domTechnique>(extra->add( COLLADA_ELEMENT_TECHNIQUE ) ); 228 teq->setProfile( "OpenSceneGraph" ); 229 230 domAny *frameTime = (domAny*)teq->add("FrameTime"); 231 std::stringstream fw; 232 for (unsigned int i = 0; i < node.getNumChildren(); i++) 233 { 234 if (i > 0) 235 { 236 fw << " "; 237 } 238 fw << node.getTime(i); 239 } 240 frameTime->setValue(fw.str().c_str()); 241 242 domAny *lastFrameTime = (domAny*)teq->add("LastFrameTime"); 243 lastFrameTime->setValue(toString<double>(node.getLastFrameTime()).c_str()); 244 245 // loop mode & interval 246 osg::Sequence::LoopMode mode; 247 int begin, end; 248 node.getInterval(mode, begin, end); 249 domAny *loopMode = (domAny*)teq->add("LoopMode"); 250 loopMode->setValue(toString<osg::Sequence::LoopMode>(mode).c_str()); 251 domAny *intervalBegin = (domAny*)teq->add("IntervalBegin"); 252 intervalBegin->setValue(toString<int>(begin).c_str()); 253 domAny *intervalEnd = (domAny*)teq->add("IntervalEnd"); 254 intervalEnd->setValue(toString<int>(end).c_str()); 255 256 // duration 257 float speed; 258 int nreps; 259 node.getDuration(speed, nreps); 260 domAny *durationSpeed = (domAny*)teq->add("DurationSpeed"); 261 durationSpeed->setValue(toString<float>(speed).c_str()); 262 domAny *durationNReps = (domAny*)teq->add("DurationNReps"); 263 durationNReps->setValue(toString<int>(nreps).c_str()); 264 265 // sequence mode 266 domAny *sequenceMode = (domAny*)teq->add("SequenceMode"); 267 sequenceMode->setValue(toString<osg::Sequence::SequenceMode>(node.getMode()).c_str()); 268 } 269 270 writeNodeExtra(node); 271 272 lastDepth = _nodePath.size(); 273 274 traverse( node ); 275 } 276 277 void daeWriter::apply( osg::LOD &node ) 278 { 279 debugPrint( node ); 280 281 while ( lastDepth >= _nodePath.size() ) 282 { 283 //We are not a child of previous node 284 currentNode = daeSafeCast< domNode >( currentNode->getParentElement() ); 285 lastDepth--; 286 } 287 currentNode = daeSafeCast< domNode >(currentNode->add( COLLADA_ELEMENT_NODE ) ); 97 288 lastDepth = _nodePath.size(); 98 289 currentNode->setId(getNodeName(node,"LOD").c_str()); 99 lastVisited = LOD; 100 101 //TODO : get the most or less detailed node, not only the first one 102 103 /*for ( unsigned int i = 0; i < node.getNumChildren(); i++ ) 104 { 105 if ( node.getChild( i ) != NULL ) 106 { 107 node.getChild( i )->accept( *this ); 108 break; 109 } 110 }*/ 111 //unsigned int cnt = node.getNumChildren(); 112 node.getChild( 0 )->accept( *this ); 290 291 if (writeExtras) 292 { 293 // Store LOD data as extra "LOD" data in the "OpenSceneGraph" technique 294 // Adds the following to a node 295 296 //<extra type="LOD"> 297 // <technique profile="OpenSceneGraph"> 298 // <Center>1 2 3</Center> (optional ) 299 // <Radius>-1</Radius> (required if Center is available) 300 // <RangeMode>0</RangeMode> 301 // <RangeList> 302 // <MinMax>0 300</MinMax> 303 // <MinMax>300 600</MinMax> 304 // </RangeList> 305 // </technique> 306 //</extra> 307 308 domExtra *extra = daeSafeCast<domExtra>(currentNode->add( COLLADA_ELEMENT_EXTRA )); 309 extra->setType("LOD"); 310 domTechnique *teq = daeSafeCast<domTechnique>(extra->add( COLLADA_ELEMENT_TECHNIQUE ) ); 311 teq->setProfile( "OpenSceneGraph" ); 312 313 if (node.getCenterMode()==osg::LOD::USER_DEFINED_CENTER) 314 { 315 domAny *center = (domAny*)teq->add("Center"); 316 center->setValue(toString(node.getCenter()).c_str()); 317 318 domAny *radius = (domAny*)teq->add("Radius"); 319 radius->setValue(toString<osg::LOD::value_type>(node.getRadius()).c_str()); 320 } 321 322 domAny *rangeMode = (domAny*)teq->add("RangeMode"); 323 rangeMode->setValue(toString<osg::LOD::RangeMode>(node.getRangeMode()).c_str()); 324 325 domAny *valueLists = (domAny*)teq->add("RangeList"); 326 327 unsigned int pos = 0; 328 const osg::LOD::RangeList& rangelist = node.getRangeList(); 329 for(osg::LOD::RangeList::const_iterator sitr=rangelist.begin(); 330 sitr!=rangelist.end(); 331 ++sitr,++pos) 332 { 333 domAny *valueList = (domAny*)valueLists->add("MinMax"); 334 std::stringstream fw; 335 fw << sitr->first << " " << sitr->second; 336 valueList->setValue(fw.str().c_str()); 337 } 338 } 339 340 writeNodeExtra(node); 341 342 // Process all children 343 traverse( node ); 113 344 } 114 345 115 346 void daeWriter::apply( osg::ProxyNode &node ) 116 347 { 117 osg::notify( osg::WARN ) << "ProxyNode. Missing " << node.getNumChildren() << " children\n"; 118 } 119 120 121 122 //LIGHT 348 osg::notify( osg::WARN ) << "ProxyNode. Missing " << node.getNumChildren() << " children" << std::endl; 349 } 350 123 351 void daeWriter::apply( osg::LightSource &node ) 124 352 { 125 #ifdef _DEBUG 126 debugPrint( node ); 127 #endif 128 129 domInstance_light *il = daeSafeCast< domInstance_light >( currentNode->createAndPlace( "instance_light" ) ); 353 debugPrint( node ); 354 355 domInstance_light *il = daeSafeCast< domInstance_light >( currentNode->add( "instance_light" ) ); 130 356 std::string name = node.getName(); 131 357 if ( name.empty() ) … … 138 364 if ( lib_lights == NULL ) 139 365 { 140 lib_lights = daeSafeCast< domLibrary_lights >( dom-> createAndPlace( COLLADA_ELEMENT_LIBRARY_LIGHTS ) );141 } 142 domLight *light = daeSafeCast< domLight >( lib_lights-> createAndPlace( COLLADA_ELEMENT_LIGHT ) );366 lib_lights = daeSafeCast< domLibrary_lights >( dom->add( COLLADA_ELEMENT_LIBRARY_LIGHTS ) ); 367 } 368 domLight *light = daeSafeCast< domLight >( lib_lights->add( COLLADA_ELEMENT_LIGHT ) ); 143 369 light->setId( name.c_str() ); 144 370 145 lastVisited = LIGHT; 146 147 traverse( node ); 148 } 149 150 //CAMERA 371 traverse( node ); 372 } 373 151 374 void daeWriter::apply( osg::Camera &node ) 152 375 { 153 #ifdef _DEBUG 154 debugPrint( node ); 155 #endif 156 157 domInstance_camera *ic = daeSafeCast< domInstance_camera >( currentNode->createAndPlace( "instance_camera" ) ); 376 debugPrint( node ); 377 378 domInstance_camera *ic = daeSafeCast< domInstance_camera >( currentNode->add( "instance_camera" ) ); 158 379 std::string name = node.getName(); 159 380 if ( name.empty() ) … … 166 387 if ( lib_cameras == NULL ) 167 388 { 168 lib_cameras = daeSafeCast< domLibrary_cameras >( dom-> createAndPlace( COLLADA_ELEMENT_LIBRARY_CAMERAS ) );169 } 170 domCamera *cam = daeSafeCast< domCamera >( lib_cameras-> createAndPlace( COLLADA_ELEMENT_CAMERA ) );389 lib_cameras = daeSafeCast< domLibrary_cameras >( dom->add( COLLADA_ELEMENT_LIBRARY_CAMERAS ) ); 390 } 391 domCamera *cam = daeSafeCast< domCamera >( lib_cameras->add( COLLADA_ELEMENT_CAMERA ) ); 171 392 cam->setId( name.c_str() ); 172 393 173 lastVisited = CAMERA; 174 175 traverse( node ); 176 } 394 traverse( node ); 395 } -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeWTransforms.cpp
r9045 r9228 18 18 #include <dom/domNode.h> 19 19 #include <dom/domConstants.h> 20 #include <dae/domAny.h> 21 22 #include <osgSim/DOFTransform> 20 23 21 24 using namespace osgdae; … … 35 38 } 36 39 37 currentNode = daeSafeCast< domNode >(currentNode-> createAndPlace( COLLADA_ELEMENT_NODE ) );40 currentNode = daeSafeCast< domNode >(currentNode->add( COLLADA_ELEMENT_NODE ) ); 38 41 currentNode->setId(getNodeName(node,"matrixTransform").c_str()); 39 42 40 domMatrix *mat = daeSafeCast< domMatrix >(currentNode-> createAndPlace( COLLADA_ELEMENT_MATRIX ) );43 domMatrix *mat = daeSafeCast< domMatrix >(currentNode->add( COLLADA_ELEMENT_MATRIX ) ); 41 44 const osg::Matrix::value_type *mat_vals = node.getMatrix().ptr(); 42 45 //for ( int i = 0; i < 16; i++ ) … … 61 64 mat->getValue().append( mat_vals[15] ); 62 65 63 lastVisited = MATRIX;64 66 lastDepth = _nodePath.size(); 67 68 writeNodeExtra(node); 65 69 66 70 traverse( node ); … … 80 84 lastDepth--; 81 85 } 82 currentNode = daeSafeCast< domNode >(currentNode-> createAndPlace( COLLADA_ELEMENT_NODE ) );86 currentNode = daeSafeCast< domNode >(currentNode->add( COLLADA_ELEMENT_NODE ) ); 83 87 currentNode->setId(getNodeName(node,"positionAttitudeTransform").c_str()); 84 88 … … 90 94 { 91 95 //make a scale 92 domScale *scale = daeSafeCast< domScale >( currentNode-> createAndPlace( COLLADA_ELEMENT_SCALE ) );96 domScale *scale = daeSafeCast< domScale >( currentNode->add( COLLADA_ELEMENT_SCALE ) ); 93 97 scale->getValue().append( s.x() ); 94 98 scale->getValue().append( s.y() ); … … 102 106 { 103 107 //make a rotate 104 domRotate *rot = daeSafeCast< domRotate >( currentNode-> createAndPlace( COLLADA_ELEMENT_ROTATE ) );108 domRotate *rot = daeSafeCast< domRotate >( currentNode->add( COLLADA_ELEMENT_ROTATE ) ); 105 109 rot->getValue().append( axis.x() ); 106 110 rot->getValue().append( axis.y() ); … … 112 116 { 113 117 //make a translate 114 domTranslate *trans = daeSafeCast< domTranslate >( currentNode-> createAndPlace( COLLADA_ELEMENT_TRANSLATE ) );118 domTranslate *trans = daeSafeCast< domTranslate >( currentNode->add( COLLADA_ELEMENT_TRANSLATE ) ); 115 119 trans->getValue().append( pos.x() ); 116 120 trans->getValue().append( pos.y() ); … … 118 122 } 119 123 120 lastVisited = POSATT; 124 writeNodeExtra(node); 125 121 126 lastDepth = _nodePath.size(); 122 127 … … 126 131 void daeWriter::apply( osg::Transform &node ) 127 132 { 128 osg::notify( osg::WARN ) << "some other transform type. Missing " << node.getNumChildren() << " children\n"; 133 debugPrint( node ); 134 135 while ( lastDepth >= _nodePath.size() ) 136 { 137 // We are not a child of previous node 138 currentNode = daeSafeCast< domNode >( currentNode->getParentElement() ); 139 lastDepth--; 140 } 141 currentNode = daeSafeCast< domNode >(currentNode->add( COLLADA_ELEMENT_NODE ) ); 142 143 // If a DOFTransform node store it's data as extra "DOFTransform" data in the "OpenSceneGraph" technique 144 osgSim::DOFTransform* dof = dynamic_cast<osgSim::DOFTransform*>(&node); 145 if (writeExtras && dof) 146 { 147 // Adds the following to a node 148 149 //<extra type="DOFTransform"> 150 // <technique profile="OpenSceneGraph"> 151 // <MinHPR>0 -0.174533 0</MinHPR> 152 // <MaxHPR>0 0.872665 0</MaxHPR> 153 // <IncrementHPR>0 0.0174533 0</IncrementHPR> 154 // <CurrentHPR>0 0 0</CurrentHPR> 155 // <MinTranslate>0 0 0</MinTranslate> 156 // <MaxTranslate>0 0 0</MaxTranslate> 157 // <IncrementTranslate>0 0 0</IncrementTranslate> 158 // <CurrentTranslate>0 0 0</CurrentTranslate> 159 // <MinScale>0 0 0</MinScale> 160 // <MaxScale>1 1 1</MaxScale> 161 // <IncrementScale>0 0 0</IncrementScale> 162 // <CurrentScale>1 1 1</CurrentScale> 163 // <MultOrder>0</MultOrder> 164 // <LimitationFlags>269964960</LimitationFlags> 165 // <AnimationOn>0</AnimationOn> 166 // <PutMatrix> 167 // 1 0 0 0 168 // 0 1 0 0 169 // 0 0 1 0 170 // 0 0 0 1 171 // </PutMatrix> 172 // </technique> 173 //</extra> 174 175 domExtra *extra = daeSafeCast<domExtra>(currentNode->add( COLLADA_ELEMENT_EXTRA )); 176 extra->setType("DOFTransform"); 177 domTechnique *teq = daeSafeCast<domTechnique>(extra->add( COLLADA_ELEMENT_TECHNIQUE ) ); 178 teq->setProfile( "OpenSceneGraph" ); 179 180 domAny *minHPR = (domAny*)teq->add("MinHPR" ); 181 minHPR->setValue(toString(dof->getMinHPR()).c_str()); 182 183 domAny *maxHPR = (domAny*)teq->add("MaxHPR" ); 184 maxHPR->setValue(toString(dof->getMaxHPR()).c_str()); 185 186 domAny *incrementHPR = (domAny*)teq->add("IncrementHPR" ); 187 incrementHPR->setValue(toString(dof->getIncrementHPR()).c_str()); 188 189 domAny *currentHPR = (domAny*)teq->add("CurrentHPR" ); 190 currentHPR->setValue(toString(dof->getCurrentHPR()).c_str()); 191 192 domAny *minTranslate = (domAny*)teq->add("MinTranslate" ); 193 minTranslate->setValue(toString(dof->getMinTranslate()).c_str()); 194 195 domAny *maxTranslate = (domAny*)teq->add("MaxTranslate" ); 196 maxTranslate->setValue(toString(dof->getMaxTranslate()).c_str()); 197 198 domAny *incrementTranslate = (domAny*)teq->add("IncrementTranslate" ); 199 incrementTranslate->setValue(toString(dof->getIncrementTranslate()).c_str()); 200 201 domAny *currentTranslate = (domAny*)teq->add("CurrentTranslate" ); 202 currentTranslate->setValue(toString(dof->getCurrentTranslate()).c_str()); 203 204 domAny *minScale = (domAny*)teq->add("MinScale" ); 205 minScale->setValue(toString(dof->getMinScale()).c_str()); 206 207 domAny *maxScale = (domAny*)teq->add("MaxScale" ); 208 maxScale->setValue(toString(dof->getMaxScale()).c_str()); 209 210 domAny *incrementScale = (domAny*)teq->add("IncrementScale" ); 211 incrementScale->setValue(toString(dof->getIncrementScale()).c_str()); 212 213 domAny *currentScale = (domAny*)teq->add("CurrentScale" ); 214 currentScale->setValue(toString(dof->getCurrentScale()).c_str()); 215 216 domAny *multOrder = (domAny*)teq->add("MultOrder" ); 217 multOrder->setValue(toString<int>(dof->getHPRMultOrder()).c_str()); 218 219 domAny *limitationFlags = (domAny*)teq->add("LimitationFlags" ); 220 limitationFlags->setValue(toString<unsigned long>(dof->getLimitationFlags()).c_str()); 221 222 domAny *animationOn = (domAny*)teq->add("AnimationOn" ); 223 animationOn->setValue(toString<bool>(dof->getAnimationOn()).c_str()); 224 225 domAny *putMatrix = (domAny*)teq->add("PutMatrix" ); 226 putMatrix->setValue(toString(dof->getPutMatrix()).c_str()); 227 228 currentNode->setId(getNodeName(node, "doftransform").c_str()); 229 } 230 else 231 { 232 currentNode->setId(getNodeName(node, "transform").c_str()); 233 osg::notify( osg::WARN ) << "some other transform type. Missing " << node.getNumChildren() << " children" << std::endl; 234 } 235 236 writeNodeExtra(node); 237 238 lastDepth = _nodePath.size(); 239 240 traverse( node ); 129 241 } 130 242 131 243 void daeWriter::apply( osg::CoordinateSystemNode &node ) 132 244 { 133 osg::notify( osg::WARN ) << "CoordinateSystemNode. Missing " << node.getNumChildren() << " children \n";134 } 245 osg::notify( osg::WARN ) << "CoordinateSystemNode. Missing " << node.getNumChildren() << " children" << std::endl; 246 } -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeWriter.cpp
r8282 r9228 21 21 #include <sstream> 22 22 23 using namespace osgdae; 24 25 daeWriter::daeWriter( DAE *dae_, const std::string &fileURI, bool _usePolygons, bool GoogleMode ) : osg::NodeVisitor( TRAVERSE_ALL_CHILDREN ), 23 24 namespace osgdae { 25 26 std::string toString(osg::Vec3 value) 27 { 28 std::stringstream str; 29 str << value.x() << " " << value.y() << " " << value.z(); 30 return str.str(); 31 } 32 33 std::string toString(osg::Matrix value) 34 { 35 std::stringstream str; 36 str << value(0,0) << " " << value(1,0) << " " << value(2,0) << " " << value(3,0) << " " 37 << value(0,1) << " " << value(1,1) << " " << value(2,1) << " " << value(3,1) << " " 38 << value(0,2) << " " << value(1,2) << " " << value(2,2) << " " << value(3,2) << " " 39 << value(0,3) << " " << value(1,3) << " " << value(2,3) << " " << value(3,3); 40 return str.str(); 41 } 42 43 44 daeWriter::daeWriter( DAE *dae_, const std::string &fileURI, bool _usePolygons, bool GoogleMode, TraversalMode tm, bool _writeExtras) : osg::NodeVisitor( tm ), 26 45 dae(dae_), 27 46 rootName(*dae_), 28 47 usePolygons (_usePolygons), 29 m_GoogleMode(GoogleMode) 48 m_GoogleMode(GoogleMode), 49 writeExtras(_writeExtras) 30 50 { 31 51 success = true; … … 37 57 dom = (domCOLLADA*)doc->getDomRoot(); 38 58 //create scene and instance visual scene 39 domCOLLADA::domScene *scene = daeSafeCast< domCOLLADA::domScene >( dom-> createAndPlace( COLLADA_ELEMENT_SCENE ) );40 domInstanceWithExtra *ivs = daeSafeCast< domInstanceWithExtra >( scene-> createAndPlace( "instance_visual_scene" ) );59 domCOLLADA::domScene *scene = daeSafeCast< domCOLLADA::domScene >( dom->add( COLLADA_ELEMENT_SCENE ) ); 60 domInstanceWithExtra *ivs = daeSafeCast< domInstanceWithExtra >( scene->add( "instance_visual_scene" ) ); 41 61 ivs->setUrl( "#defaultScene" ); 42 62 //create library visual scenes and a visual scene and the root node 43 lib_vis_scenes = daeSafeCast<domLibrary_visual_scenes>( dom-> createAndPlace( COLLADA_ELEMENT_LIBRARY_VISUAL_SCENES ) );44 vs = daeSafeCast< domVisual_scene >( lib_vis_scenes-> createAndPlace( COLLADA_ELEMENT_VISUAL_SCENE ) );63 lib_vis_scenes = daeSafeCast<domLibrary_visual_scenes>( dom->add( COLLADA_ELEMENT_LIBRARY_VISUAL_SCENES ) ); 64 vs = daeSafeCast< domVisual_scene >( lib_vis_scenes->add( COLLADA_ELEMENT_VISUAL_SCENE ) ); 45 65 vs->setId( "defaultScene" ); 46 currentNode = daeSafeCast< domNode >( vs-> createAndPlace( COLLADA_ELEMENT_NODE ) );66 currentNode = daeSafeCast< domNode >( vs->add( COLLADA_ELEMENT_NODE ) ); 47 67 currentNode->setId( "sceneRoot" ); 48 68 … … 67 87 void daeWriter::debugPrint( osg::Node &node ) 68 88 { 89 #ifdef _DEBUG 69 90 std::string indent = ""; 70 91 for ( unsigned int i = 0; i < _nodePath.size(); i++ ) … … 73 94 } 74 95 osg::notify( osg::INFO ) << indent << node.className() << std::endl; 96 #endif 75 97 } 76 98 … … 95 117 { 96 118 std::string nodeName; 97 if ( (node.getName().empty()) || (node.getName()!=""))119 if (node.getName().empty()) 98 120 nodeName=uniquify(defaultName); 99 121 else … … 105 127 void daeWriter::apply( osg::Node &node ) 106 128 { 107 #ifdef _DEBUG108 129 debugPrint( node ); 109 #endif 110 111 osg::notify( osg::INFO ) << "generic node\n"; 112 lastVisited = NODE; 130 131 writeNodeExtra(node); 113 132 114 133 traverse( node ); … … 136 155 void daeWriter::createAssetTag() 137 156 { 138 domAsset *asset = daeSafeCast< domAsset >(dom-> createAndPlace( COLLADA_ELEMENT_ASSET ) );139 domAsset::domCreated *c = daeSafeCast< domAsset::domCreated >( asset->createAndPlace( "created" ));140 domAsset::domModified *m = daeSafeCast< domAsset::domModified >( asset->createAndPlace( "modified" ));141 domAsset::domUnit *u = daeSafeCast< domAsset::domUnit >( asset->createAndPlace( "unit" ));157 domAsset *asset = daeSafeCast< domAsset >(dom->add( COLLADA_ELEMENT_ASSET ) ); 158 domAsset::domCreated *c = daeSafeCast< domAsset::domCreated >(asset->add("created" )); 159 domAsset::domModified *m = daeSafeCast< domAsset::domModified >(asset->add("modified" )); 160 domAsset::domUnit *u = daeSafeCast< domAsset::domUnit >(asset->add("unit")); 142 161 143 162 //TODO : set date and time … … 180 199 } 181 200 201 } // namespace osgdae -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeWriter.h
r7664 r9228 40 40 #include <osgDB/FileUtils> 41 41 #include <osgDB/Registry> 42 #include <osgSim/MultiSwitch> 42 43 43 44 #include <dae.h> … … 62 63 63 64 namespace osgdae { 65 66 /// Convert value to string using it's stream operator 67 template <typename T> 68 std::string toString(T value) { 69 std::stringstream str; 70 str << value; 71 return str.str(); 72 } 73 74 std::string toString(osg::Vec3 value); 75 std::string toString(osg::Matrix value); 64 76 65 77 /** … … 72 84 class ArrayNIndices; 73 85 public: 74 enum NodeType { NODE, GEODE, GROUP, LIGHT, CAMERA, MATRIX, POSATT, SWITCH, LOD }; 75 76 daeWriter( DAE *dae_, const std::string &fileURI, bool usePolygons=false, bool GoogleMode = false ); 86 daeWriter( DAE *dae_, const std::string &fileURI, bool usePolygons=false, bool GoogleMode = false,TraversalMode tm=TRAVERSE_ALL_CHILDREN, bool writeExtras = true); 77 87 virtual ~daeWriter(); 78 88 … … 91 101 virtual void apply( osg::PositionAttitudeTransform &node ); 92 102 virtual void apply( osg::Switch &node ); 103 virtual void apply( osg::Sequence &node ); 93 104 virtual void apply( osg::LOD &node ); 94 105 95 //virtual void apply( osg::Billboard &node);106 //virtual void apply( osg::Billboard &node); 96 107 virtual void apply( osg::ProxyNode &node ); 97 108 //virtual void apply( osg::Projection &node) … … 101 112 virtual void apply( osg::Transform &node ); 102 113 //virtual void apply( osg::CameraView &node) 103 //virtual void apply( osg::Sequence &node)104 114 //virtual void apply( osg::PagedLOD &node) 105 115 //virtual void apply( osg::ClearNode &node) 106 116 //virtual void apply( osg::OccluderNode &node) 117 118 void writeNodeExtra(osg::Node &node); 119 120 107 121 108 122 void traverse (osg::Node &node); … … 149 163 domVisual_scene *vs; 150 164 165 /// Write OSG specific data as extra data 166 bool writeExtras; 151 167 bool success; 152 NodeType lastVisited;153 168 unsigned int lastDepth; 154 169
