Changeset 10234
- Timestamp:
- 05/18/09 17:21:57 (4 years ago)
- Location:
- OpenSceneGraph/trunk/src/osgPlugins/dae
- Files:
-
- 8 modified
-
CMakeLists.txt (modified) (2 diffs)
-
daeRSceneObjects.cpp (modified) (12 diffs)
-
daeReader.cpp (modified) (2 diffs)
-
daeReader.h (modified) (1 diff)
-
daeWGeometry.cpp (modified) (9 diffs)
-
daeWMaterials.cpp (modified) (19 diffs)
-
daeWSceneObjects.cpp (modified) (5 diffs)
-
daeWriter.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/dae/CMakeLists.txt
r9998 r10234 53 53 COLLADA_LIBXML_LIBRARY 54 54 COLLADA_PCRECPP_LIBRARY 55 COLLADA_PCRE_LIBRARY 55 56 COLLADA_BOOST_FILESYSTEM_LIBRARY 56 57 COLLADA_BOOST_SYSTEM_LIBRARY) … … 64 65 ELSE() 65 66 SET(TARGET_LIBRARIES_VARS 66 COLLADA_DYNAMIC_LIBRARY) 67 COLLADA_PCRECPP_LIBRARY 68 COLLADA_PCRE_LIBRARY 69 COLLADA_DYNAMIC_LIBRARY 70 COLLADA_BOOST_FILESYSTEM_LIBRARY 71 COLLADA_BOOST_SYSTEM_LIBRARY) 67 72 ENDIF() 68 73 ENDIF() -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeRSceneObjects.cpp
r9481 r10234 26 26 #include <osg/Sequence> 27 27 #include <osg/CameraView> 28 #include <osg/LightModel> 28 29 29 30 using namespace osgdae; … … 323 324 osg::Node* daeReader::processLight( domLight *dlight ) 324 325 { 325 osg::Node *node = new osg::Switch(); 326 if (m_numlights >= 7) 327 { 328 osg::notify( osg::WARN ) << "More than 8 lights may not be supported by OpenGL driver." << std::endl; 329 } 326 330 327 331 //do light processing here. … … 332 336 333 337 if ( dlight->getTechnique_common() == NULL || 334 dlight->getTechnique_common()->getContents().getCount() == 0 )338 dlight->getTechnique_common()->getContents().getCount() == 0 ) 335 339 { 336 340 osg::notify( osg::WARN ) << "Invalid content for light" << std::endl; … … 339 343 340 344 osg::Light* light = new osg::Light(); 345 light->setPosition(osg::Vec4(0,0,0,1)); 346 light->setLightNum(m_numlights); 347 348 // Enable OpenGL lighting 349 _rootStateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON); 350 // Enable this OpenGL light 351 _rootStateSet->setMode(GL_LIGHT0 + m_numlights++, osg::StateAttribute::ON); 352 353 // Set ambient of lightmodel to zero 354 // Ambient lights are added as separate lights with only an ambient term 355 osg::LightModel* lightmodel = new osg::LightModel; 356 lightmodel->setAmbientIntensity(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); 357 _rootStateSet->setAttributeAndModes(lightmodel, osg::StateAttribute::ON); 341 358 342 359 osg::LightSource* lightsource = new osg::LightSource(); 343 344 lightsource->setLight( light ); 345 light->setPosition(osg::Vec4(0,0,0,1)); 346 light->setLightNum( m_numlights ); 360 lightsource->setLight(light); 361 lightsource->setName(dlight->getId()); 347 362 348 363 daeElement *el = dlight->getTechnique_common()->getContents()[0]; … … 358 373 return NULL; 359 374 } 360 light->setAmbient( osg::Vec4( ambient->getColor()->getValue()[0], ambient->getColor()->getValue()[1], 361 ambient->getColor()->getValue()[2], 1.0f ) ); 375 376 light->setAmbient( osg::Vec4( ambient->getColor()->getValue()[0], 377 ambient->getColor()->getValue()[1], 378 ambient->getColor()->getValue()[2], 1.0f ) ); 379 light->setDiffuse( osg::Vec4( 0, 0, 0, 0)); 380 light->setSpecular( osg::Vec4( 0, 0, 0, 0)); 381 382 // Tell OpenGL to make it a directional light (w=0) 383 light->setPosition( osg::Vec4(0,0,0,0)); 362 384 } 363 385 else if ( directional != NULL ) … … 365 387 if ( directional->getColor() == NULL ) 366 388 { 367 osg::notify( osg::WARN ) << "Invalid content for ambientlight" << std::endl;389 osg::notify( osg::WARN ) << "Invalid content for directional light" << std::endl; 368 390 return NULL; 369 391 } 370 light->setDiffuse( osg::Vec4( directional->getColor()->getValue()[0], directional->getColor()->getValue()[1], 371 directional->getColor()->getValue()[2], 1.0f ) ); 372 light->setSpecular( osg::Vec4( directional->getColor()->getValue()[0], directional->getColor()->getValue()[1], 373 directional->getColor()->getValue()[2], 1.0f ) ); 392 light->setAmbient( osg::Vec4( 0, 0, 0, 0)); 393 light->setDiffuse( osg::Vec4( directional->getColor()->getValue()[0], 394 directional->getColor()->getValue()[1], 395 directional->getColor()->getValue()[2], 1.0f ) ); 396 light->setSpecular( osg::Vec4( directional->getColor()->getValue()[0], 397 directional->getColor()->getValue()[1], 398 directional->getColor()->getValue()[2], 1.0f ) ); 374 399 375 light->setDirection( osg::Vec3( 0, 0, -1 ) ); 400 light->setDirection(osg::Vec3(0,0,-1)); 401 402 // Tell OpenGL it is a directional light (w=0) 403 light->setPosition( osg::Vec4(0,0,1,0)); 376 404 } 377 405 else if ( point != NULL ) … … 379 407 if ( point->getColor() == NULL ) 380 408 { 381 osg::notify( osg::WARN ) << "Invalid content for ambient light" << std::endl;409 osg::notify( osg::WARN ) << "Invalid content for point light" << std::endl; 382 410 return NULL; 383 411 } 384 light->setDiffuse( osg::Vec4( point->getColor()->getValue()[0], point->getColor()->getValue()[1], 385 point->getColor()->getValue()[2], 1.0f ) ); 386 light->setSpecular( osg::Vec4( point->getColor()->getValue()[0], point->getColor()->getValue()[1], 387 point->getColor()->getValue()[2], 1.0f ) ); 412 light->setAmbient( osg::Vec4( 0, 0, 0, 0)); 413 light->setDiffuse( osg::Vec4( point->getColor()->getValue()[0], 414 point->getColor()->getValue()[1], 415 point->getColor()->getValue()[2], 1.0f ) ); 416 light->setSpecular( osg::Vec4( point->getColor()->getValue()[0], 417 point->getColor()->getValue()[1], 418 point->getColor()->getValue()[2], 1.0f ) ); 388 419 389 420 if ( point->getConstant_attenuation() != NULL ) … … 412 443 } 413 444 445 // Tell OpenGL this is an omni directional light 446 light->setDirection(osg::Vec3(0, 0, 0)); 414 447 } 415 448 else if ( spot != NULL ) … … 417 450 if ( spot->getColor() == NULL ) 418 451 { 419 osg::notify( osg::WARN ) << "Invalid content for ambient light" << std::endl;452 osg::notify( osg::WARN ) << "Invalid content for spot light" << std::endl; 420 453 return NULL; 421 454 } 422 light->setDiffuse( osg::Vec4( spot->getColor()->getValue()[0], spot->getColor()->getValue()[1], 423 spot->getColor()->getValue()[2], 1.0f ) ); 424 light->setSpecular( osg::Vec4( spot->getColor()->getValue()[0], spot->getColor()->getValue()[1], 425 spot->getColor()->getValue()[2], 1.0f ) ); 455 light->setAmbient( osg::Vec4( 0, 0, 0, 0)); 456 light->setDiffuse( osg::Vec4( spot->getColor()->getValue()[0], 457 spot->getColor()->getValue()[1], 458 spot->getColor()->getValue()[2], 1.0f ) ); 459 light->setSpecular( osg::Vec4( spot->getColor()->getValue()[0], 460 spot->getColor()->getValue()[1], 461 spot->getColor()->getValue()[2], 1.0f ) ); 426 462 427 463 if ( spot->getConstant_attenuation() != NULL ) … … 449 485 light->setQuadraticAttenuation( 0.0f ); 450 486 } 451 487 // OpenGL range [0, 90] (degrees) or 180 (omni) 452 488 if ( spot->getFalloff_angle() != NULL ) 453 489 { 454 light->setSpotCutoff( spot->getFalloff_angle()->getValue() ); 490 float falloffAngle = spot->getFalloff_angle()->getValue(); 491 if (falloffAngle != 180) 492 { 493 falloffAngle = osg::clampTo<float>(falloffAngle, 0, 90); 494 } 495 light->setSpotCutoff(falloffAngle); 455 496 } 456 497 else … … 458 499 light->setSpotCutoff( 180.0f ); 459 500 } 460 501 // OpenGL range [0, 128], where 0 means hard edge, and 128 means soft edge 461 502 if ( spot->getFalloff_exponent() != NULL ) 462 503 { 463 light->setSpotExponent( spot->getFalloff_exponent()->getValue() ); 504 float falloffExponent = spot->getFalloff_exponent()->getValue(); 505 falloffExponent = osg::clampTo<float>(falloffExponent, 0, 128); 506 light->setSpotExponent(falloffExponent); 464 507 } 465 508 else … … 467 510 light->setSpotExponent( 0.0f ); 468 511 } 469 470 } 471 472 osg::Switch* svitch = static_cast<osg::Switch*>(node); 473 474 // Switched of by default to avoid excessively large scene bound 475 svitch->addChild(lightsource,false); 476 477 m_numlights++; 478 479 return node; 512 light->setDirection(osg::Vec3(0, 0, -1)); 513 } 514 515 return lightsource; 480 516 } 481 517 -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeReader.cpp
r9529 r10234 129 129 { 130 130 osg::Node *retVal; 131 _rootStateSet = new osg::StateSet(); 131 132 132 133 unsigned int nbVisualSceneGroup=scene->getNode_array().getCount(); … … 161 162 } 162 163 } 164 retVal->setStateSet(_rootStateSet); 165 163 166 return retVal; 164 167 } -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeReader.h
r9956 r10234 225 225 DAE *dae; 226 226 osg::Node* rootNode; 227 osg::ref_ptr<osg::StateSet> _rootStateSet; 227 228 228 229 std::map<std::string,bool> _targetMap; -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeWGeometry.cpp
r9481 r10234 51 51 if ( iter != geometryMap.end() ) 52 52 { 53 domInstance_geometry *ig = daeSafeCast< domInstance_geometry >( currentNode->add( "instance_geometry") );53 domInstance_geometry *ig = daeSafeCast< domInstance_geometry >( currentNode->add( COLLADA_ELEMENT_INSTANCE_GEOMETRY ) ); 54 54 55 55 std::string url = "#" + std::string( iter->second->getId() ); … … 77 77 } 78 78 79 domInstance_geometry *ig = daeSafeCast< domInstance_geometry >( currentNode->add( "instance_geometry") );79 domInstance_geometry *ig = daeSafeCast< domInstance_geometry >( currentNode->add( COLLADA_ELEMENT_INSTANCE_GEOMETRY ) ); 80 80 81 81 std::string url = "#" + name; … … 219 219 220 220 //make a POSITION input in it 221 domInputLocal *il = daeSafeCast< domInputLocal >( vertices->add( "input") );222 il->setSemantic( "POSITION");221 domInputLocal *il = daeSafeCast< domInputLocal >( vertices->add( COLLADA_ELEMENT_INPUT) ); 222 il->setSemantic(COMMON_PROFILE_INPUT_POSITION); 223 223 std::string url = "#" + std::string( pos->getId() ); 224 224 il->setSource( url.c_str() ); … … 273 273 //if NORMAL shares same indices as POSITION put it in the vertices 274 274 /*if ( normalInds == vertInds && vertInds != NULL ) { 275 il = daeSafeCast< domInputLocal >( vertices->add( "input") );276 il->setSemantic( "NORMAL");275 il = daeSafeCast< domInputLocal >( vertices->add( COLLADA_ELEMENT_INPUT) ); 276 il->setSemantic(COMMON_PROFILE_INPUT_NORMAL); 277 277 url = "#" + std::string(md->norm->getId()); 278 278 il->setSource( url.c_str() ); … … 324 324 //if COLOR shares same indices as POSITION put it in the vertices 325 325 /*if ( colorInds == vertInds && vertInds != NULL ) { 326 il = daeSafeCast< domInputLocal >( vertices->add( "input") );327 il->setSemantic( "COLOR");326 il = daeSafeCast< domInputLocal >( vertices->add( COLLADA_ELEMENT_INPUT) ); 327 il->setSemantic(COMMON_PROFILE_INPUT_COLOR); 328 328 url = "#" + std::string(md->color->getId()); 329 329 il->setSource( url.c_str() ); … … 1057 1057 fa->setId( fName.c_str() ); 1058 1058 1059 domSource::domTechnique_common *teq = daeSafeCast< domSource::domTechnique_common >( src->add( "technique_common") );1059 domSource::domTechnique_common *teq = daeSafeCast< domSource::domTechnique_common >( src->add( COLLADA_ELEMENT_TECHNIQUE_COMMON ) ); 1060 1060 domAccessor *acc = daeSafeCast< domAccessor >( teq->add( COLLADA_ELEMENT_ACCESSOR ) ); 1061 1061 std::string url = "#" + fName; … … 1136 1136 unsigned int offset = 0; 1137 1137 Ty *retVal = daeSafeCast< Ty >( mesh->add( type ) ); 1138 domInputLocalOffset *ilo = daeSafeCast< domInputLocalOffset >( retVal->add( "input" ));1138 domInputLocalOffset *ilo = daeSafeCast< domInputLocalOffset >(retVal->add( COLLADA_ELEMENT_INPUT)); 1139 1139 ilo->setOffset( offset++ ); 1140 ilo->setSemantic( "VERTEX");1140 ilo->setSemantic(COMMON_PROFILE_INPUT_VERTEX); 1141 1141 std::string url = "#" + std::string(mesh->getVertices()->getId()); 1142 1142 ilo->setSource( url.c_str() ); 1143 1143 if ( norm != NULL ) 1144 1144 { 1145 ilo = daeSafeCast< domInputLocalOffset >( retVal->add( "input" ));1145 ilo = daeSafeCast< domInputLocalOffset >( retVal->add(COLLADA_ELEMENT_INPUT)); 1146 1146 ilo->setOffset( offset++ ); 1147 ilo->setSemantic( "NORMAL");1147 ilo->setSemantic( COMMON_PROFILE_INPUT_NORMAL); 1148 1148 url = "#" + std::string( norm->getId() ); 1149 1149 ilo->setSource( url.c_str() ); … … 1151 1151 if ( color != NULL ) 1152 1152 { 1153 ilo = daeSafeCast< domInputLocalOffset >( retVal->add( "input" ));1153 ilo = daeSafeCast< domInputLocalOffset >( retVal->add(COLLADA_ELEMENT_INPUT)); 1154 1154 ilo->setOffset( offset++ ); 1155 ilo->setSemantic( "COLOR");1155 ilo->setSemantic(COMMON_PROFILE_INPUT_COLOR); 1156 1156 url = "#" + std::string( color->getId() ); 1157 1157 ilo->setSource( url.c_str() ); … … 1159 1159 for ( unsigned int i = 0; i < texcoord.size(); i++ ) 1160 1160 { 1161 ilo = daeSafeCast< domInputLocalOffset >( retVal->add( "input" ));1161 ilo = daeSafeCast< domInputLocalOffset >( retVal->add(COLLADA_ELEMENT_INPUT)); 1162 1162 ilo->setOffset( offset++ ); 1163 ilo->setSemantic( "TEXCOORD");1163 ilo->setSemantic(COMMON_PROFILE_INPUT_TEXCOORD); 1164 1164 ilo->setSet( i ); 1165 1165 url = "#" + std::string( texcoord[i]->getId() ); -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeWMaterials.cpp
r9228 r10234 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 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" ));37 domBind_material::domTechnique_common *tc = daeSafeCast< domBind_material::domTechnique_common >( bm->add(COLLADA_ELEMENT_TECHNIQUE_COMMON)); 38 38 domInstance_material *im = daeSafeCast< domInstance_material >( tc->add( COLLADA_ELEMENT_INSTANCE_MATERIAL ) ); 39 39 std::string symbol = geoName + "_material"; … … 66 66 im->setTarget( url.c_str() ); 67 67 68 domInstance_effect *ie = daeSafeCast<domInstance_effect>( mat->add( "instance_effect") );68 domInstance_effect *ie = daeSafeCast<domInstance_effect>( mat->add( COLLADA_ELEMENT_INSTANCE_EFFECT ) ); 69 69 70 70 if ( lib_effects == NULL ) … … 81 81 82 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") );83 domProfile_COMMON::domTechnique *pc_teq = daeSafeCast< domProfile_COMMON::domTechnique >( pc->add( COLLADA_ELEMENT_TECHNIQUE ) ); 84 84 pc_teq->setSid( "t0" ); 85 domProfile_COMMON::domTechnique::domPhong *phong = daeSafeCast< domProfile_COMMON::domTechnique::domPhong >( pc_teq->add( "phong" ));85 domProfile_COMMON::domTechnique::domPhong *phong = daeSafeCast< domProfile_COMMON::domTechnique::domPhong >( pc_teq->add(COLLADA_ELEMENT_PHONG)); 86 86 87 87 osg::Texture *tex = static_cast<osg::Texture*>(ssClean->getTextureAttribute( 0, osg::StateAttribute::TEXTURE )); … … 98 98 99 99 osg::Image *osgimg = tex->getImage( 0 ); 100 domImage::domInit_from *imgif = daeSafeCast< domImage::domInit_from >( img->add( "init_from" ));100 domImage::domInit_from *imgif = daeSafeCast< domImage::domInit_from >( img->add(COLLADA_ELEMENT_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->add( "newparam" ));108 domCommon_newparam_type *np = daeSafeCast< domCommon_newparam_type >(pc->add(COLLADA_ELEMENT_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->add( "surface" ));112 domFx_surface_init_from_common *sif = daeSafeCast< domFx_surface_init_from_common >( surface->add( "init_from"));111 domFx_surface_common *surface = daeSafeCast< domFx_surface_common >(np->add(COLLADA_ELEMENT_SURFACE)); 112 domFx_surface_init_from_common *sif = daeSafeCast< domFx_surface_init_from_common >( surface->add(COLLADA_ELEMENT_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->add( "newparam" ));116 np = daeSafeCast< domCommon_newparam_type >( pc->add(COLLADA_ELEMENT_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->add( "sampler2D") );120 domFx_sampler2D_common_complexType::domSource *source = daeSafeCast< domFx_sampler2D_common_complexType::domSource >( sampler->add( "source" ));119 domFx_sampler2D_common *sampler = daeSafeCast< domFx_sampler2D_common >( np->add(COLLADA_ELEMENT_SAMPLER2D) ); 120 domFx_sampler2D_common_complexType::domSource *source = daeSafeCast< domFx_sampler2D_common_complexType::domSource >(sampler->add(COLLADA_ELEMENT_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->add( "wrap_s" ));124 domFx_sampler2D_common_complexType::domWrap_s *wrap_s = daeSafeCast< domFx_sampler2D_common_complexType::domWrap_s >(sampler->add(COLLADA_ELEMENT_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->add( "wrap_t" ));146 domFx_sampler2D_common_complexType::domWrap_t *wrap_t = daeSafeCast< domFx_sampler2D_common_complexType::domWrap_t >(sampler->add( COLLADA_ELEMENT_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->add( "border_color" ));169 domFx_sampler2D_common_complexType::domBorder_color *dbcol = daeSafeCast< domFx_sampler2D_common_complexType::domBorder_color >(sampler->add(COLLADA_ELEMENT_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->add( "minfilter" ));175 domFx_sampler2D_common_complexType::domMinfilter *minfilter = daeSafeCast< domFx_sampler2D_common_complexType::domMinfilter >(sampler->add(COLLADA_ELEMENT_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->add( "magfilter" ));199 domFx_sampler2D_common_complexType::domMagfilter *magfilter = daeSafeCast< domFx_sampler2D_common_complexType::domMagfilter >(sampler->add(COLLADA_ELEMENT_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->add( "diffuse") );225 domCommon_color_or_texture_type_complexType::domTexture *dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >( cot->add( "texture" ));224 domCommon_color_or_texture_type *cot = daeSafeCast< domCommon_color_or_texture_type >( phong->add(COLLADA_ELEMENT_DIFFUSE) ); 225 domCommon_color_or_texture_type_complexType::domTexture *dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >(cot->add(COLLADA_ELEMENT_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->add( "diffuse") );230 domCommon_color_or_texture_type_complexType::domTexture *dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >( cot->add( "texture" ));229 domCommon_color_or_texture_type *cot = daeSafeCast< domCommon_color_or_texture_type >( phong->add(COLLADA_ELEMENT_DIFFUSE) ); 230 domCommon_color_or_texture_type_complexType::domTexture *dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >( cot->add(COLLADA_ELEMENT_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->add( "bind_vertex_input" ));235 domInstance_material::domBind_vertex_input *bvi = daeSafeCast< domInstance_material::domBind_vertex_input >(im->add(COLLADA_ELEMENT_BIND_VERTEX_INPUT)); 236 236 bvi->setSemantic( "texcoord0" ); 237 237 bvi->setInput_semantic( "TEXCOORD" ); … … 247 247 float shininess = osgmat->getShininessFrontAndBack()?osgmat->getShininess( osg::Material::FRONT_AND_BACK ):osgmat->getShininess( osg::Material::FRONT ); 248 248 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" ));249 domCommon_color_or_texture_type *cot = daeSafeCast< domCommon_color_or_texture_type >( phong->add(COLLADA_ELEMENT_EMISSION)); 250 domCommon_color_or_texture_type_complexType::domColor *col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->add(COLLADA_ELEMENT_COLOR)); 251 251 col->getValue().append( eCol.r() ); 252 252 col->getValue().append( eCol.g() ); … … 254 254 col->getValue().append( eCol.a() ); 255 255 256 cot = daeSafeCast< domCommon_color_or_texture_type >( phong->add( "ambient" ));257 col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->add( "color" ));256 cot = daeSafeCast< domCommon_color_or_texture_type >( phong->add(COLLADA_ELEMENT_AMBIENT)); 257 col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >(cot->add(COLLADA_ELEMENT_COLOR)); 258 258 col->getValue().append( aCol.r() ); 259 259 col->getValue().append( aCol.g() ); … … 265 265 if ( phong->getDiffuse() == NULL ) 266 266 { 267 cot = daeSafeCast< domCommon_color_or_texture_type >( phong->add( "diffuse" ));268 col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->add( "color" ));267 cot = daeSafeCast< domCommon_color_or_texture_type >( phong->add(COLLADA_ELEMENT_DIFFUSE)); 268 col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->add(COLLADA_ELEMENT_COLOR)); 269 269 col->getValue().append( dCol.r() ); 270 270 col->getValue().append( dCol.g() ); … … 291 291 domTechnique *teq = daeSafeCast< domTechnique >( extra->add( COLLADA_ELEMENT_TECHNIQUE ) ); 292 292 teq->setProfile( "SCEI" ); 293 domAny *any = (domAny*)(daeElement*)teq->add( "color");293 domAny *any = (domAny*)(daeElement*)teq->add(COLLADA_ELEMENT_COLOR); 294 294 295 295 std::ostringstream colVal; … … 299 299 } 300 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" ));301 cot = daeSafeCast< domCommon_color_or_texture_type >( phong->add(COLLADA_ELEMENT_SPECULAR)); 302 col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->add(COLLADA_ELEMENT_COLOR)); 303 303 col->getValue().append( sCol.r() ); 304 304 col->getValue().append( sCol.g() ); … … 306 306 col->getValue().append( sCol.a() ); 307 307 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" ));308 domCommon_float_or_param_type *fop = daeSafeCast< domCommon_float_or_param_type >( phong->add(COLLADA_ELEMENT_SHININESS)); 309 domCommon_float_or_param_type_complexType::domFloat *f = daeSafeCast< domCommon_float_or_param_type_complexType::domFloat >( fop->add(COLLADA_ELEMENT_FLOAT)); 310 310 f->setValue( shininess ); 311 311 } … … 324 324 { 325 325 // A_ONE opaque mode 326 domCommon_transparent_type *pTransparent = daeSafeCast<domCommon_transparent_type>(phong->add( "transparent"));326 domCommon_transparent_type *pTransparent = daeSafeCast<domCommon_transparent_type>(phong->add(COLLADA_ELEMENT_TRANSPARENT)); 327 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"));328 domCommon_color_or_texture_type_complexType::domColor *pColor = daeSafeCast<domCommon_color_or_texture_type_complexType::domColor>(pTransparent->add(COLLADA_ELEMENT_COLOR)); 329 domCommon_float_or_param_type *pFop = daeSafeCast<domCommon_float_or_param_type>(phong->add(COLLADA_ELEMENT_TRANSPARENCY)); 330 domCommon_float_or_param_type_complexType::domFloat *pTransparency = daeSafeCast<domCommon_float_or_param_type_complexType::domFloat>(pFop->add(COLLADA_ELEMENT_FLOAT)); 331 331 if (m_GoogleMode) 332 332 { … … 349 349 { 350 350 // RGB_ZERO opaque mode 351 domCommon_transparent_type *pTransparent = daeSafeCast<domCommon_transparent_type>(phong->add( "transparent"));351 domCommon_transparent_type *pTransparent = daeSafeCast<domCommon_transparent_type>(phong->add(COLLADA_ELEMENT_TRANSPARENT)); 352 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"));353 domCommon_color_or_texture_type_complexType::domColor *pColor = daeSafeCast<domCommon_color_or_texture_type_complexType::domColor>(pTransparent->add(COLLADA_ELEMENT_COLOR)); 354 354 pColor->getValue().append(pBlendColor->getConstantColor().r()); 355 355 pColor->getValue().append(pBlendColor->getConstantColor().g()); 356 356 pColor->getValue().append(pBlendColor->getConstantColor().b()); 357 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"));358 domCommon_float_or_param_type *pFop = daeSafeCast<domCommon_float_or_param_type>(phong->add(COLLADA_ELEMENT_TRANSPARENCY)); 359 domCommon_float_or_param_type_complexType::domFloat *pTransparency = daeSafeCast<domCommon_float_or_param_type_complexType::domFloat>(pFop->add(COLLADA_ELEMENT_FLOAT)); 360 360 pTransparency->setValue(1.0); 361 361 } … … 365 365 else if (tex != NULL && tex->getImage( 0 ) != NULL) 366 366 { 367 domCommon_transparent_type *ctt = daeSafeCast< domCommon_transparent_type >( phong->add( "transparent" ));367 domCommon_transparent_type *ctt = daeSafeCast< domCommon_transparent_type >( phong->add(COLLADA_ELEMENT_TRANSPARENT)); 368 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" ));369 domCommon_color_or_texture_type_complexType::domTexture * dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >( ctt->add(COLLADA_ELEMENT_TEXTURE)); 370 370 371 371 #ifndef EARTH_TEX -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeWSceneObjects.cpp
r9441 r10234 354 354 debugPrint( node ); 355 355 356 domInstance_light * il = daeSafeCast< domInstance_light >( currentNode->add( "instance_light" ));356 domInstance_light *pDomInstanceLight = daeSafeCast< domInstance_light >( currentNode->add(COLLADA_ELEMENT_INSTANCE_LIGHT)); 357 357 std::string name = node.getName(); 358 358 if ( name.empty() ) … … 361 361 } 362 362 std::string url = "#" + name; 363 il->setUrl( url.c_str() );363 pDomInstanceLight->setUrl( url.c_str() ); 364 364 365 365 if ( lib_lights == NULL ) … … 367 367 lib_lights = daeSafeCast< domLibrary_lights >( dom->add( COLLADA_ELEMENT_LIBRARY_LIGHTS ) ); 368 368 } 369 domLight *light = daeSafeCast< domLight >( lib_lights->add( COLLADA_ELEMENT_LIGHT ) );370 light->setId( name.c_str() );371 369 370 osg::Light* pOsgLight = node.getLight(); 371 372 domLight *pDomLight = daeSafeCast< domLight >( lib_lights->add( COLLADA_ELEMENT_LIGHT ) ); 373 pDomLight->setId( name.c_str() ); 374 375 domLight::domTechnique_common *domTechniqueCommon = daeSafeCast<domLight::domTechnique_common>(pDomLight->add(COLLADA_ELEMENT_TECHNIQUE_COMMON)); 376 377 osg::Vec4 position = pOsgLight->getPosition(); 378 osg::Vec3 direction = pOsgLight->getDirection(); 379 osg::Vec4 ambientColor = pOsgLight->getAmbient(); 380 osg::Vec4 diffuseColor = pOsgLight->getDiffuse(); 381 osg::Vec4 specularColor = pOsgLight->getSpecular(); 382 383 if (position.w() == 0) 384 { 385 // Directional light 386 domLight::domTechnique_common::domDirectional *domDirectional = daeSafeCast<domLight::domTechnique_common::domDirectional>(domTechniqueCommon->add(COLLADA_ELEMENT_DIRECTIONAL)); 387 388 if ((position.x() != 0) || (position.y() != 0) || (position.z() != 0)) 389 { 390 osg::Vec3 dir(-position.x(), -position.y(), -position.z()); 391 // TODO wrap instance_light in a rotating node to translate default light [0,0,-1] into proper direction 392 } 393 394 domFloat3 color; 395 color.append3(diffuseColor.r(), diffuseColor.g(), diffuseColor.b()); 396 domDirectional->add(COLLADA_ELEMENT_COLOR); 397 domDirectional->getColor()->setValue(color); 398 } 399 else if (direction.length() == 0) 400 { 401 // Omni/point light 402 domLight::domTechnique_common::domPoint *domPoint = daeSafeCast<domLight::domTechnique_common::domPoint>(domTechniqueCommon->add(COLLADA_ELEMENT_POINT)); 403 domPoint->add(COLLADA_ELEMENT_CONSTANT_ATTENUATION); 404 domPoint->getConstant_attenuation()->setValue(pOsgLight->getConstantAttenuation()); 405 domPoint->add(COLLADA_ELEMENT_LINEAR_ATTENUATION); 406 domPoint->getLinear_attenuation()->setValue(pOsgLight->getLinearAttenuation()); 407 domPoint->add(COLLADA_ELEMENT_QUADRATIC_ATTENUATION); 408 domPoint->getQuadratic_attenuation()->setValue(pOsgLight->getQuadraticAttenuation()); 409 410 if ((position.x() != 0) || (position.y() != 0) || (position.z() != 0)) 411 { 412 // TODO wrap instance_light in a transforming node to translate default light [0,0,0] into proper position 413 } 414 415 domFloat3 color; 416 color.append3(diffuseColor.r(), diffuseColor.g(), diffuseColor.b()); 417 domPoint->add(COLLADA_ELEMENT_COLOR); 418 domPoint->getColor()->setValue(color); 419 } 420 else 421 { 422 // Spot light 423 domLight::domTechnique_common::domSpot *domSpot = daeSafeCast<domLight::domTechnique_common::domSpot>(domTechniqueCommon->add(COLLADA_ELEMENT_SPOT)); 424 domSpot->add(COLLADA_ELEMENT_CONSTANT_ATTENUATION); 425 domSpot->getConstant_attenuation()->setValue(pOsgLight->getConstantAttenuation()); 426 domSpot->add(COLLADA_ELEMENT_LINEAR_ATTENUATION); 427 domSpot->getLinear_attenuation()->setValue(pOsgLight->getLinearAttenuation()); 428 domSpot->add(COLLADA_ELEMENT_QUADRATIC_ATTENUATION); 429 domSpot->getQuadratic_attenuation()->setValue(pOsgLight->getQuadraticAttenuation()); 430 431 if ((position.x() != 0) || (position.y() != 0) || (position.z() != 0)) 432 { 433 // TODO wrap instance_light in a transforming node to translate default light [0,0,0] into proper position 434 // and rotate default direction [0,0,-1] into proper dir 435 } 436 437 domFloat3 color; 438 color.append3(diffuseColor.r(), diffuseColor.g(), diffuseColor.b()); 439 domSpot->add(COLLADA_ELEMENT_COLOR); 440 domSpot->getColor()->setValue(color); 441 442 domSpot->add(COLLADA_ELEMENT_FALLOFF_ANGLE); 443 domSpot->getFalloff_angle()->setValue(pOsgLight->getSpotCutoff()); 444 445 domSpot->add(COLLADA_ELEMENT_FALLOFF_EXPONENT); 446 domSpot->getFalloff_exponent()->setValue(pOsgLight->getSpotExponent()); 447 } 448 449 // Write ambient as a separate Collada <ambient> light 450 if ((ambientColor.r() != 0) || (ambientColor.g() != 0) || (ambientColor.b() != 0)) 451 { 452 domInstance_light *ambientDomInstanceLight = daeSafeCast< domInstance_light >(currentNode->add( COLLADA_ELEMENT_INSTANCE_LIGHT )); 453 std::string name = node.getName(); 454 if (name.empty()) 455 { 456 name = uniquify( "light-ambient" ); 457 } 458 else 459 { 460 name += "-ambient"; 461 } 462 std::string url = "#" + name; 463 ambientDomInstanceLight->setUrl( url.c_str() ); 464 465 domLight *ambientDomLight = daeSafeCast< domLight >( lib_lights->add( COLLADA_ELEMENT_LIGHT ) ); 466 ambientDomLight->setId(name.c_str()); 467 468 domLight::domTechnique_common *ambientDomTechniqueCommon = daeSafeCast<domLight::domTechnique_common>(ambientDomLight->add(COLLADA_ELEMENT_TECHNIQUE_COMMON)); 469 470 // Ambient light 471 domLight::domTechnique_common::domAmbient *domAmbient = daeSafeCast<domLight::domTechnique_common::domAmbient>(ambientDomTechniqueCommon->add(COLLADA_ELEMENT_AMBIENT)); 472 473 domFloat3 color; 474 color.append3(ambientColor.r(), ambientColor.g(), ambientColor.b()); 475 domAmbient->add(COLLADA_ELEMENT_COLOR); 476 domAmbient->getColor()->setValue(color); 477 } 478 372 479 traverse( node ); 373 480 } … … 377 484 debugPrint( node ); 378 485 379 domInstance_camera *ic = daeSafeCast< domInstance_camera >( currentNode->add( "instance_camera") );486 domInstance_camera *ic = daeSafeCast< domInstance_camera >( currentNode->add( COLLADA_ELEMENT_INSTANCE_CAMERA ) ); 380 487 std::string name = node.getName(); 381 488 if ( name.empty() ) … … 400 507 debugPrint( node ); 401 508 402 domInstance_camera *ic = daeSafeCast< domInstance_camera >( currentNode->add( "instance_camera" ));509 domInstance_camera *ic = daeSafeCast< domInstance_camera >( currentNode->add(COLLADA_ELEMENT_INSTANCE_CAMERA)); 403 510 std::string name = node.getName(); 404 511 if ( name.empty() ) -
OpenSceneGraph/trunk/src/osgPlugins/dae/daeWriter.cpp
r9481 r10234 58 58 dom = (domCOLLADA*)doc->getDomRoot(); 59 59 //create scene and instance visual scene 60 domCOLLADA::domScene *scene = daeSafeCast< domCOLLADA::domScene >( dom->add( COLLADA_ELEMENT_SCENE ));61 domInstanceWithExtra *ivs = daeSafeCast< domInstanceWithExtra >( scene->add( "instance_visual_scene" ));60 domCOLLADA::domScene *scene = daeSafeCast< domCOLLADA::domScene >( dom->add(COLLADA_ELEMENT_SCENE)); 61 domInstanceWithExtra *ivs = daeSafeCast< domInstanceWithExtra >( scene->add(COLLADA_ELEMENT_INSTANCE_VISUAL_SCENE)); 62 62 ivs->setUrl( "#defaultScene" ); 63 63 //create library visual scenes and a visual scene and the root node 64 lib_vis_scenes = daeSafeCast<domLibrary_visual_scenes>( dom->add( COLLADA_ELEMENT_LIBRARY_VISUAL_SCENES ));65 vs = daeSafeCast< domVisual_scene >( lib_vis_scenes->add( COLLADA_ELEMENT_VISUAL_SCENE ));64 lib_vis_scenes = daeSafeCast<domLibrary_visual_scenes>( dom->add(COLLADA_ELEMENT_LIBRARY_VISUAL_SCENES)); 65 vs = daeSafeCast< domVisual_scene >( lib_vis_scenes->add(COLLADA_ELEMENT_VISUAL_SCENE)); 66 66 vs->setId( "defaultScene" ); 67 67 currentNode = daeSafeCast< domNode >( vs->add( COLLADA_ELEMENT_NODE ) ); … … 157 157 { 158 158 domAsset *asset = daeSafeCast< domAsset >(dom->add( COLLADA_ELEMENT_ASSET ) ); 159 domAsset::domCreated *c = daeSafeCast< domAsset::domCreated >(asset->add( "created"));160 domAsset::domModified *m = daeSafeCast< domAsset::domModified >(asset->add( "modified"));161 domAsset::domUnit *u = daeSafeCast< domAsset::domUnit >(asset->add( "unit"));159 domAsset::domCreated *c = daeSafeCast< domAsset::domCreated >(asset->add(COLLADA_ELEMENT_CREATED)); 160 domAsset::domModified *m = daeSafeCast< domAsset::domModified >(asset->add(COLLADA_ELEMENT_MODIFIED)); 161 domAsset::domUnit *u = daeSafeCast< domAsset::domUnit >(asset->add(COLLADA_ELEMENT_UNIT)); 162 162 163 163 //TODO : set date and time
