Changeset 9228

Show
Ignore:
Timestamp:
11/24/08 15:26:04 (3 years ago)
Author:
robert
Message:

From Roland Smeenk, "Overview of the Collada/dae plugin changes


New features
+Read and write of osg::LOD, osg::Switch, osgSim::Sequence, osgim::MultiSwitch? and osgSim::DOFTransform data in <extra>
+Read and write of osg::Node description data in <extra>
+Plugin option "NoExtras?" to prevent writing of <extra> data and only traverse the active children when saving


Changes/additions
+instanced_geometry and instanced_controller are now loaded in a single Geode with multiple Geometries instead of multiple geodes with a single Geometry
+Changed all calls to the deprecated createAndPlace() to the new add() methods
+All transformation elements <scale>, <rotate>, <translate>, <lookat>, <matrix>, <skew> are now concatenated properly in to a single MatrixTransform?.

Previously this was not done in order as required by Collada and and not all elements were included.

+Complete skew matrix creation
+Automatically add GL_RESCALE_NORMAL if scale is non-identity
+Blinn shininess remapping to [0,128] when in range [0,1]
+Changes to CMake file to make it compile on Windows
+Coding style and code documentation


Bug fixes
+Transparent texture writing fixed
+Fixed bug in using osg node name as collada node ID
+Fixed usage of double sided faces in GOOGLEEARTH extra
+Not adding blendfunc and blendcolor when opaque


TODO/Wishlist
-solve differences in drawables, DAE reader should place multiple collation elements into multiple primitivesets in a single geometry where possible (only when same material)
-solve differences in matrices
-multitexture support
-skinned mesh and generic animations using osgAnimation
-profile_GLSL based on COLLADA OpenGL Effects Viewer http://ati.amd.com/developer/rendermonkey/downloads.html
-handling more <extra> to more closely mimic the intended lighting"

Location:
OpenSceneGraph/trunk/src/osgPlugins/dae
Files:
14 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/dae/CMakeLists.txt

    r8282 r9228  
    2828 
    2929  IF   (COLLADA_USE_STATIC) 
    30     SET(TARGET_EXTERNAL_LIBRARIES libcollada_dom libcollada_dae libcollada_STLDatabase libcollada_LIBXMLPlugin libcollada_stdErrPlugin libxml2 ) 
     30    SET(TARGET_EXTERNAL_LIBRARIES libxml2 pcrecpp-d pcre-d) 
    3131  ELSE (COLLADA_USE_STATIC) 
    32     ADD_DEFINITIONS(-DDOM_DYNAMIC) 
     32#    ADD_DEFINITIONS(-DDOM_DYNAMIC) 
     33    SET(TARGET_EXTERNAL_LIBRARIES libxml2 pcrecpp-d pcre-d) 
    3334  ENDIF(COLLADA_USE_STATIC) 
    3435 
     
    5455 
    5556SET(TARGET_LIBRARIES_VARS COLLADA_LIBRARY) 
     57SET(TARGET_ADDED_LIBRARIES osgSim )  
    5658 
    5759#### end var setup  ### 
  • OpenSceneGraph/trunk/src/osgPlugins/dae/ReaderWriterDAE.cpp

    r8314 r9228  
    1515 
    1616#include <osg/Notify> 
     17#include <osg/NodeVisitor> 
    1718#include <osgDB/ReaderWriter> 
    1819#include <osgDB/FileNameUtils> 
     
    4142    
    4243    if ( options ) 
    43         pDAE = (DAE*) options->getPluginData("DAE");         
     44        pDAE = (DAE*)options->getPluginData("DAE"); 
    4445     
    4546    std::string ext( osgDB::getLowerCaseFileExtension(fname) ); 
     
    104105 
    105106    // 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 
    108110    if( options ) 
    109111    { 
    110         pDAE = (DAE*) options->getPluginData("DAE");         
     112        pDAE = (DAE*)options->getPluginData("DAE"); 
    111113        std::istringstream iss( options->getOptionString() ); 
    112114        std::string opt; 
    113115 
    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, ',' ) ) 
    119117        { 
    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            } 
    127130        } 
    128       } 
    129131    } 
    130      
     132 
    131133    if (NULL == pDAE) 
    132134    { 
     
    138140    std::string fileURI = ConvertFilePathToColladaCompatibleURI(fname); 
    139141 
    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); 
    141145    daeWriter.setRootNode( node ); 
    142146    const_cast<osg::Node*>(&node)->accept( daeWriter ); 
  • OpenSceneGraph/trunk/src/osgPlugins/dae/daeRGeometry.cpp

    r8282 r9228  
    1919#include <dom/domInstance_controller.h> 
    2020#include <dom/domController.h> 
     21#include <osg/StateSet> 
    2122 
    2223#include <osg/Geometry> 
     
    2425using namespace osgdae; 
    2526 
    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  
     27osg::Geode* daeReader::processInstanceGeometry( domInstance_geometry *ig ) 
     28{ 
    3229    daeElement *el = getElementFromURI( ig->getUrl() ); 
    3330    domGeometry *geom = daeSafeCast< domGeometry >( el ); 
     
    3734        return NULL; 
    3835    } 
    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 ); 
    4341    if ( iter != geometryMap.end() ) 
    4442    { 
    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)); 
    4651    } 
    4752    else 
    4853    { 
    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 ) 
    5359    { 
    5460        osg::notify( osg::WARN ) << "Failed to load geometry " << ig->getUrl().getURI() << std::endl; 
    5561        return NULL; 
    5662    } 
    57     //process material bindings 
     63 
     64    // process material bindings 
    5865    if ( ig->getBind_material() != NULL ) 
    5966    { 
    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> 
     80osg::Geode* daeReader::processInstanceController( domInstance_controller *ictrl ) 
     81{ 
    7182    //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()); 
    7584    domController *ctrl = daeSafeCast< domController >( el ); 
    7685    if ( ctrl == NULL ) 
    7786    { 
    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 
    8193    el = NULL; 
    82         //## non init 
     94    //## non init 
    8395    daeURI *src=NULL; 
    8496    if ( ctrl->getSkin() != NULL ) 
     
    92104        el = getElementFromURI( ctrl->getMorph()->getSource() ); 
    93105    } 
    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    } 
    100113         
    101114    domGeometry *geom = daeSafeCast< domGeometry >( el ); 
     
    105118        return NULL; 
    106119    } 
    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 ); 
    110125    if ( iter != geometryMap.end() ) 
    111126    { 
    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)); 
    113135    } 
    114136    else 
    115137    { 
    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 ) 
    120143    { 
    121144        osg::notify( osg::WARN ) << "Failed to load geometry " << src->getURI() << std::endl; 
     
    125148    if ( ictrl->getBind_material() != NULL ) 
    126149    { 
    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> 
     163osg::Geode *daeReader::processGeometry( domGeometry *geo ) 
    134164{ 
    135165    domMesh *mesh = geo->getMesh(); 
     
    139169        return NULL; 
    140170    } 
    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> 
    148187    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 
    247246 
    248247template< typename T > 
    249 osg::Node* daeReader::processSinglePPrimitive( T *group, SourceMap &sources, GLenum mode ) 
    250 { 
    251     osg::Geode* geode = new osg::Geode(); 
     248void daeReader::processSinglePPrimitive(osg::Geode* geode, T *group, SourceMap &sources, GLenum mode ) 
     249{ 
    252250    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()); 
    259252 
    260253    IndexMap index_map; 
     
    266259     
    267260    geode->addDrawable( geometry ); 
    268     return geode; 
    269261} 
    270262 
    271263template< typename T > 
    272     osg::Node* daeReader::processMultiPPrimitive( T *group, SourceMap &sources, GLenum mode ) 
    273 { 
    274     osg::Geode* geode = new osg::Geode(); 
     264void daeReader::processMultiPPrimitive(osg::Geode* geode, T *group, SourceMap &sources, GLenum mode ) 
     265{ 
    275266    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()); 
    282268 
    283269    IndexMap index_map; 
     
    293279 
    294280    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 
     283void daeReader::processPolylist(osg::Geode* geode, domPolylist *group, SourceMap &sources ) 
     284{ 
    301285    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()); 
    308287 
    309288    IndexMap index_map; 
     
    343322     
    344323    geode->addDrawable( geometry ); 
    345     return geode; 
    346324} 
    347325 
    348326void daeReader::processP( domP *p, osg::Geometry *&/*geom*/, IndexMap &index_map, osg::DrawArrayLengths* dal /*GLenum mode*/ ) 
    349327{ 
    350     //osg::DrawArrayLengths* dal = new osg::DrawArrayLengths( mode ); 
    351328    int idxcount = index_map.size(); 
    352329    int count = p->getValue().getCount(); 
     
    361338        } 
    362339    } 
    363     //geom->addPrimitiveSet( dal ); 
    364340} 
    365341 
     
    378354    domInputLocalOffset *tmp_input; 
    379355 
    380     if ( findInputSourceBySemantic( inputs, "VERTEX", tmp_el, &tmp_input ) ) { 
     356    if ( findInputSourceBySemantic( inputs, "VERTEX", tmp_el, &tmp_input ) )  
     357    { 
    381358        vertices = daeSafeCast< domVertices >( tmp_el ); 
    382         if ( vertices == NULL ) { 
     359        if ( vertices == NULL )  
     360        { 
    383361            osg::notify( osg::WARN )<<"Could not get vertices"<<std::endl; 
    384362            return; 
     
    394372        findInputSourceBySemantic( vertices->getInput_array(), "TEXCOORD", texcoord_source, &tmp ); 
    395373         
    396         if ( index_map[offset] == NULL ) { 
     374        if ( index_map[offset] == NULL )  
     375        { 
    397376            index_map[offset] = new osg::IntArray(); 
    398377        } 
     
    437416    } 
    438417 
    439      
    440     if ( findInputSourceBySemantic( inputs, "COLOR", color_source, &tmp_input ) ) { 
    441          
     418    if ( findInputSourceBySemantic( inputs, "COLOR", color_source, &tmp_input ))  
     419    { 
    442420        offset = tmp_input->getOffset(); 
    443421        if ( index_map[offset] == NULL ) { 
     
    447425    } 
    448426 
    449     if ( color_source != NULL ) { 
     427    if ( color_source != NULL )  
     428    { 
    450429        geom->setColorArray( sources[color_source].getVec4Array() ); 
    451430        geom->setColorBinding( osg::Geometry::BIND_PER_VERTEX ); 
    452431    } 
    453432 
    454     if ( findInputSourceBySemantic( inputs, "NORMAL", normal_source, &tmp_input ) ) { 
    455          
     433    if ( findInputSourceBySemantic( inputs, "NORMAL", normal_source, &tmp_input ) )  
     434    { 
    456435        offset = tmp_input->getOffset(); 
    457         if ( index_map[offset] == NULL ) { 
     436        if ( index_map[offset] == NULL )  
     437        { 
    458438            index_map[offset] = new osg::IntArray(); 
    459439        } 
     
    461441    } 
    462442 
    463     if ( normal_source ) { 
     443    if ( normal_source )  
     444    { 
    464445        geom->setNormalArray( sources[normal_source].getVec3Array() ); 
    465446        geom->setNormalBinding( osg::Geometry::BIND_PER_VERTEX ); 
     
    467448 
    468449    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    { 
    471452        offset = tmp_input->getOffset(); 
    472453        set = tmp_input->getSet(); 
    473454 
    474         if ( index_map[offset] == NULL ) { 
     455        if ( index_map[offset] == NULL )  
     456        { 
    475457            index_map[offset] = new osg::IntArray(); 
    476458        } 
  • OpenSceneGraph/trunk/src/osgPlugins/dae/daeRMaterials.cpp

    r8353 r9228  
    3030using namespace osgdae; 
    3131 
    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 
     52void daeReader::processBindMaterial( domBind_material *bm, domGeometry *geom, osg::Geode *geode ) 
    3353{ 
    34     if ( bm->getTechnique_common() == NULL ) 
     54    if (bm->getTechnique_common() == NULL ) 
    3555    { 
    3656        osg::notify( osg::WARN ) << "No COMMON technique for bind_material" << std::endl; 
    3757        return; 
    3858    } 
    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) 
    8076                { 
    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; 
    86104        } 
    87105    } 
    88106} 
    89107 
    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> 
     116void    daeReader::processMaterial(osg::StateSet *ss, domMaterial *mat ) 
    91117{ 
    92118    currentInstance_effect = mat->getInstance_effect(); 
    93119    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 
    95127    { 
    96128        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    } 
    104130} 
    105131 
    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> 
     143void daeReader::processEffect(osg::StateSet *ss, domEffect *effect ) 
    107144{ 
    108145    bool hasCOMMON = false; 
    109     osg::StateSet *ss = NULL; 
    110146 
    111147    for ( size_t i = 0; i < effect->getFx_profile_abstract_array().getCount(); i++ ) 
     
    120156            } 
    121157            currentEffect = effect; 
    122             ss = processProfileCOMMON( pc ); 
     158            processProfileCOMMON(ss, pc); 
    123159            hasCOMMON = true; 
    124160            continue; 
     
    127163        osg::notify( osg::WARN ) << "unsupported effect profile " << effect->getFx_profile_abstract_array()[i]->getTypeName() << std::endl; 
    128164    } 
    129  
    130     return ss; 
    131165} 
    132166 
    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> 
     178void daeReader::processProfileCOMMON(osg::StateSet *ss, domProfile_COMMON *pc ) 
    134179{ 
    135     osg::StateSet *ss = new osg::StateSet(); 
    136      
    137180    domProfile_COMMON::domTechnique *teq = pc->getTechnique(); 
    138181 
     
    144187    ss->setMode( GL_CULL_FACE, GL_TRUE ); 
    145188 
    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++) 
    159209                { 
    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) 
    164212                    { 
    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 ); 
    172216                    } 
    173217                } 
     
    176220    } 
    177221 
    178     //ss->setMode( GL_LIGHTING, GL_FALSE ); 
    179  
    180222    osg::ref_ptr< osg::Material > mat = new osg::Material(); 
    181223    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> 
    182236    if ( b != NULL ) 
    183237    { 
     
    198252        } 
    199253 
    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 ); 
    201255        insertMat = insertMat || tmp; 
    202256 
     
    215269            } 
    216270        } 
    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> 
    219284    else if ( p != NULL ) 
    220285    { 
     
    223288        insertMat = insertMat || tmp; 
    224289         
    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 ); 
    226292        insertMat = insertMat || tmp; 
     293        if ( sa1 != NULL )  
     294        { 
     295            ss->setTextureMode( 1, GL_TEXTURE_2D, GL_TRUE ); 
     296            ss->setTextureAttribute( 0, sa1 ); 
     297        } 
    227298         
    228299        osg::StateAttribute *sa = NULL; 
     
    254325 
    255326    } 
     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> 
    256337    else if ( l != NULL ) 
    257338    { 
     
    288369         
    289370    } 
     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> 
    290379    else if ( c != NULL ) 
    291380    { 
     
    304393        ss->setAttribute( mat.get() ); 
    305394    } 
    306  
    307     return ss; 
    308395} 
    309396 
    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 
     408bool 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) 
    315414{ 
    316415    if ( cot == NULL ) 
     
    319418    } 
    320419    bool retVal = false; 
     420 
    321421    //osg::StateAttribute *sa = NULL; 
    322422    //TODO: Make all channels process <param ref=""> type of value 
     
    329429            retVal = true; 
    330430        } 
    331  
    332431        else if (cot->getParam() != NULL) 
    333432        { 
     
    339438            } 
    340439        } 
    341         else 
     440        else if (cot->getTexture() != NULL) 
    342441        { 
    343442            osg::notify( osg::WARN ) << "Currently no support for <texture> in Emission channel " << std::endl; 
    344443        }        
     444        else 
     445        { 
     446            osg::notify( osg::WARN ) << "Missing <color>, <param> or <texture> in Emission channel " << std::endl; 
     447        } 
    345448    } 
    346449    else if ( channel == osg::Material::AMBIENT ) 
     
    361464            } 
    362465        } 
     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        } 
    363471        else 
    364472        { 
    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; 
    366474        } 
    367475    } 
     
    378486            *sa = processTexture( cot->getTexture() ); 
    379487            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 ) 
    382489            { 
    383490                //the extra data for osg. Diffuse color can happen with a texture. 
     
    407514            } 
    408515        } 
     516        else 
     517        { 
     518            osg::notify( osg::WARN ) << "Missing <color>, <param> or <texture> in Diffuse channel " << std::endl; 
     519        } 
    409520    } 
    410521    else if ( channel == osg::Material::SPECULAR ) 
     
    416527            retVal = true; 
    417528        } 
    418          else if (cot->getParam() != NULL) 
     529        else if (cot->getParam() != NULL) 
    419530        { 
    420531            domFloat4 f4; 
     
    425536            } 
    426537        } 
    427        else 
     538        else if (cot->getTexture() != NULL) 
    428539        { 
    429540            osg::notify( osg::WARN ) << "Currently no support for <texture> in Specular channel " << std::endl; 
    430541        } 
     542        else 
     543        { 
     544            osg::notify( osg::WARN ) << "Missing <color>, <param> or <texture> in Specular channel " << std::endl; 
     545        } 
     546 
    431547        if ( fop != NULL && fop->getFloat() != NULL ) 
    432548        { 
    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 ); 
    434557            retVal = true; 
    435558        } 
     
    809932} 
    810933 
     934 
     935/* 
     936Collada 1.4.1 Specification (2nd Edition) Patch Release Notes: Revision C Release notes 
     937 
     938In <blinn>, <constant>, <lambert>, and <phong>, the child element <transparent> now has an 
     939optional opaque attribute whose valid values are: 
     940• A_ONE (the default): Takes the transparency information from the color’s alpha channel, where the value 1.0 is opaque. 
     941• RGB_ZERO: Takes the transparency information from the color’s red, green, and blue channels, where the value 0.0 is opaque, 
     942with each channel modulated independently. 
     943In the Specification, this is described in the “FX Reference” chapter in the 
     944common_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 
     948Collada Digital Asset Schema Release 1.5.0 Release Notes 
     949 
     950The <transparent> element’s 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 color’s alpha channel, where the value 0.0 is opaque. 
     952• RGB_ONE: Takes the transparency information from the color’s red, green, and blue channels, where the value 1.0 is opaque, 
     953with each channel modulated independently. 
     954*/ 
     955 
    811956osg::StateAttribute *daeReader::processTransparencySettings( domCommon_transparent_type *ctt,  domCommon_float_or_param_type *pTransparency, osg::StateSet *ss ) 
    812957{ 
     
    8821027    } 
    8831028 
     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 
    8841045    osg::BlendColor *bc = new osg::BlendColor(); 
    8851046    bc->setConstantColor(osg::Vec4( f4[0] * Transparency, f4[1] * Transparency, f4[2] * Transparency, f4[3] * Transparency )); 
     
    8931054    ss->setMode( GL_BLEND, GL_TRUE ); 
    8941055 
    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 bin 
    899             return NULL; 
    900     } 
    901     else 
    902     { 
    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 bin 
    908             return NULL; 
    909     } 
    910  
    9111056    ss->setRenderingHint( osg::StateSet::TRANSPARENT_BIN ); 
    9121057    ss->setRenderBinDetails( 10, "DepthSortedBin" ); 
    9131058    return NULL; 
    9141059} 
     1060 
     1061// 0..* <extra> 
  • OpenSceneGraph/trunk/src/osgPlugins/dae/daeRSceneObjects.cpp

    r5465 r9228  
    1414#include "daeReader.h" 
    1515#include <dae.h> 
     16#include <dae/domAny.h> 
    1617#include <dom/domCOLLADA.h> 
    1718 
     
    1920#include <osg/LightSource> 
    2021#include <osg/Geode> 
    21 #include <osg/Switch> 
    2222#include <osg/ShapeDrawable> 
     23#include <osg/LOD> 
     24#include <osg/Billboard> 
     25#include <osgSim/MultiSwitch> 
     26#include <osg/Sequence> 
    2327 
    2428using namespace osgdae; 
    2529 
     30osg::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 
     87osg::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 
     113osg::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 
     220osg::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> 
    26322osg::Node* daeReader::processLight( domLight *dlight ) 
    27323{ 
     324    osg::Node *node = new osg::Switch(); 
     325 
    28326    //do light processing here. 
    29327    domLight::domTechnique_common::domAmbient *ambient; 
     
    38336        return NULL; 
    39337    } 
    40  
    41     osg::Node* node = new osg::Switch(); 
    42338 
    43339    osg::Light* light = new osg::Light(); 
     
    183479} 
    184480 
    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> 
     495osg::Node* daeReader::processCamera( domCamera * dcamera ) 
    186496{ 
     497    osg::Node *node = new osg::Switch(); 
     498 
    187499    //TODO: Make the camera actually make a camera to view from. Not just draw a cone. 
    188     osg::Node *node = new osg::Switch(); 
    189  
    190500    osg::Cone* cone = new osg::Cone(); 
    191501 
  • OpenSceneGraph/trunk/src/osgPlugins/dae/daeRTransforms.cpp

    r5465 r9228  
    1414#include "daeReader.h" 
    1515#include <dae.h> 
     16#include <dae/domAny.h> 
    1617#include <dom/domCOLLADA.h> 
    1718 
    18 #include <osg/PositionAttitudeTransform> 
    1919#include <osg/MatrixTransform> 
     20#include <osgSim/DOFTransform> 
    2021 
    2122using namespace osgdae; 
    2223 
    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. 
     29osg::Node* daeReader::processOsgMatrixTransform( domNode *node ) 
    2430{ 
    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; 
    46200} 
    47201 
    48 osg::Transform* daeReader::processTranslate( domTranslate *trans ) 
     202osg::Node* daeReader::processOsgDOFTransform(domTechnique* teq) 
    49203{ 
    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; 
    66369} 
    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  
    1414#include "daeReader.h" 
    1515#include <dae.h> 
     16#include <dae/domAny.h> 
    1617#include <dom/domCOLLADA.h> 
    1718#include <dom/domInstanceWithExtra.h> 
    1819#include <dom/domConstants.h> 
     20#include <osg/MatrixTransform> 
    1921 
    2022using namespace osgdae; 
     
    8789    } 
    8890 
    89     if (dae->getDatabase()) { 
     91    if (dae->getDatabase())  
     92    { 
    9093        count = dae->getDatabase()->getElementCount(NULL, COLLADA_TYPE_INSTANCE_RIGID_BODY, NULL); 
    9194 
    9295        // build a std::map for lookup if Group or PositionAttitudeTransform should be created,  
    9396        // 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        { 
    9599            result = dae->getDatabase()->getElement(&colladaElement, i, NULL, COLLADA_TYPE_INSTANCE_RIGID_BODY); 
    96100 
    97             if (result == DAE_OK) { 
     101            if (result == DAE_OK)  
     102            { 
    98103                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                    { 
    102109                        _targetMap[ std::string(node->getId()) ] = true;           
    103110                    } 
     
    122129{ 
    123130    osg::Node *retVal;  
    124     //### do not add an empty group if there is only one 
     131 
    125132    unsigned int nbVisualSceneGroup=scene->getNode_array().getCount(); 
    126133    if (nbVisualSceneGroup==0) 
     
    155162    } 
    156163    return retVal; 
    157      
    158 } 
    159  
     164} 
     165 
     166osg::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 
     223void 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 
     274domTechnique* 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> 
    160303osg::Node* daeReader::processNode( domNode *node ) 
    161304{ 
    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 
    169316    bool targeted = false; 
    170  
    171     if (node->getId()) { 
     317    if (node->getId())  
     318    { 
    172319        targeted = _targetMap[std::string(node->getId())]; 
    173320    } 
    174321 
    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()); 
    319347            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()); 
    336374            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()); 
    353387            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  
    9494} 
    9595 
     96/// Convert string to value using it's stream operator 
     97template <typename T> 
     98T parseString(const std::string& valueAsString) { 
     99    std::stringstream str; 
     100    str << valueAsString; 
     101    T result; 
     102    str >> result; 
     103    return result; 
     104} 
     105 
     106inline 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 
     115inline 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 
    96128/** 
    97129@class daeReader 
     
    114146protected: 
    115147    //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 ); 
    118151    //osg::Node* processInstance( domInstanceWithExtra *iwe ); 
    119152 
    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); 
    127164 
    128165    //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 ); 
    132169 
    133170    typedef std::map< daeElement*, domSourceReader > SourceMap; 
     
    135172 
    136173    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 ); 
    138175     
    139176    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 ); 
    143180 
    144181    void resolveArrays( domInputLocalOffset_Array &inputs, osg::Geometry *&geom,  
     
    148185 
    149186    //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 ); 
    154191    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); 
    156197    osg::StateAttribute *processTransparencySettings( domCommon_transparent_type *ctt, domCommon_float_or_param_type *pTransparency, osg::StateSet *ss ); 
    157198    bool GetFloat4Param(xsNCName Reference, domFloat4 &f4); 
     
    175216    domEffect *currentEffect; 
    176217 
    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 
    179229    enum AuthoringTool 
    180230    { 
  • OpenSceneGraph/trunk/src/osgPlugins/dae/daeWGeometry.cpp

    r8357 r9228  
    2525using namespace osgdae; 
    2626 
    27 //GEODE 
    2827void daeWriter::apply( osg::Geode &node ) 
    2928{ 
    30 #ifdef _DEBUG 
    3129    debugPrint( node ); 
    32 #endif 
    3330 
    3431    pushStateSet(node.getStateSet()); 
     
    3633        m_CurrentRenderingHint = node.getStateSet()->getRenderingHint(); 
    3734 
     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 
    3838    unsigned int count = node.getNumDrawables(); 
    3939    for ( unsigned int i = 0; i < count; i++ ) 
    4040    { 
    4141        osg::Geometry *g = node.getDrawable( i )->asGeometry(); 
     42         
    4243        if ( g != NULL ) 
    4344        { 
     45            // Transparency at drawable level 
     46            if (NULL != g->getStateSet()) 
     47                m_CurrentRenderingHint = g->getStateSet()->getRenderingHint(); 
     48 
    4449            pushStateSet(g->getStateSet()); 
    4550            std::map< osg::Geometry*, domGeometry *>::iterator iter = geometryMap.find( g ); 
    4651            if ( iter != geometryMap.end() ) 
    4752            { 
    48                 domInstance_geometry *ig = daeSafeCast< domInstance_geometry >( currentNode->createAndPlace( "instance_geometry" ) ); 
     53                domInstance_geometry *ig = daeSafeCast< domInstance_geometry >( currentNode->add( "instance_geometry" ) ); 
    4954                     
    5055                std::string url = "#" + std::string( iter->second->getId() ); 
     
    5762                if ( lib_geoms == NULL ) 
    5863                { 
    59                     lib_geoms = daeSafeCast< domLibrary_geometries >( dom->createAndPlace( COLLADA_ELEMENT_LIBRARY_GEOMETRIES ) ); 
     64                    lib_geoms = daeSafeCast< domLibrary_geometries >( dom->add( COLLADA_ELEMENT_LIBRARY_GEOMETRIES ) ); 
    6065                } 
    6166                std::string name = node.getName(); 
     
    6368                name = uniquify( name ); 
    6469 
    65                 domGeometryRef geo = daeSafeCast< domGeometry >( lib_geoms->createAndPlace( COLLADA_ELEMENT_GEOMETRY ) ); 
     70                domGeometryRef geo = daeSafeCast< domGeometry >( lib_geoms->add( COLLADA_ELEMENT_GEOMETRY ) ); 
    6671                geo->setId( name.c_str() ); 
    6772 
     
    7277                } 
    7378 
    74                 domInstance_geometry *ig = daeSafeCast< domInstance_geometry >( currentNode->createAndPlace( "instance_geometry" ) ); 
     79                domInstance_geometry *ig = daeSafeCast< domInstance_geometry >( currentNode->add( "instance_geometry" ) ); 
    7580                     
    7681                std::string url = "#" + name; 
     
    8792        } 
    8893    } 
    89  
    90     lastVisited = GEODE; 
    9194 
    9295    popStateSet(node.getStateSet()); 
     
    131134bool daeWriter::processGeometry( osg::Geometry *geom, domGeometry *geo, const std::string &name ) 
    132135{    
    133     domMesh *mesh = daeSafeCast< domMesh >( geo->createAndPlace( COLLADA_ELEMENT_MESH ) ); 
     136    domMesh *mesh = daeSafeCast< domMesh >( geo->add( COLLADA_ELEMENT_MESH ) ); 
    134137    domSource *pos = NULL; 
    135138    domSource *norm = NULL; 
     
    207210 
    208211    //create a vertices element 
    209     domVertices *vertices = daeSafeCast< domVertices >( mesh->createAndPlace( COLLADA_ELEMENT_VERTICES ) ); 
     212    domVertices *vertices = daeSafeCast< domVertices >( mesh->add( COLLADA_ELEMENT_VERTICES ) ); 
    210213    std::string vName = name + "-vertices"; 
    211214    vertices->setId( vName.c_str() ); 
    212215 
    213216    //make a POSITION input in it 
    214     domInputLocal *il = daeSafeCast< domInputLocal >( vertices->createAndPlace( "input" ) ); 
     217    domInputLocal *il = daeSafeCast< domInputLocal >( vertices->add( "input" ) ); 
    215218    il->setSemantic( "POSITION" ); 
    216219    std::string url = "#" + std::string( pos->getId() ); 
     
    266269        //if NORMAL shares same indices as POSITION put it in the vertices 
    267270        /*if ( normalInds == vertInds && vertInds != NULL ) { 
    268             il = daeSafeCast< domInputLocal >( vertices->createAndPlace( "input" ) ); 
     271            il = daeSafeCast< domInputLocal >( vertices->add( "input" ) ); 
    269272            il->setSemantic( "NORMAL" ); 
    270273            url = "#" + std::string(md->norm->getId()); 
     
    317320        //if COLOR shares same indices as POSITION put it in the vertices 
    318321        /*if ( colorInds == vertInds && vertInds != NULL ) { 
    319             il = daeSafeCast< domInputLocal >( vertices->createAndPlace( "input" ) ); 
     322            il = daeSafeCast< domInputLocal >( vertices->add( "input" ) ); 
    320323            il->setSemantic( "COLOR" ); 
    321324            url = "#" + std::string(md->color->getId()); 
     
    404407                { 
    405408                    lines = createPrimGroup<domLines>( COLLADA_ELEMENT_LINES, mesh, norm, color, texcoord ); 
    406                     lines->createAndPlace( COLLADA_ELEMENT_P ); 
     409                    lines->add( COLLADA_ELEMENT_P ); 
    407410                    std::string mat = name + "_material"; 
    408411                    lines->setMaterial( mat.c_str() ); 
     
    417420                { 
    418421                    tris = createPrimGroup<domTriangles>( COLLADA_ELEMENT_TRIANGLES, mesh, norm, color, texcoord ); 
    419                     tris->createAndPlace( COLLADA_ELEMENT_P ); 
     422                    tris->add( COLLADA_ELEMENT_P ); 
    420423                    std::string mat = name + "_material"; 
    421424                    tris->setMaterial( mat.c_str() ); 
     
    432435                    { 
    433436                          polys = createPrimGroup<domPolygons>( COLLADA_ELEMENT_POLYGONS, mesh, norm, color, texcoord ); 
    434                           polys->createAndPlace( COLLADA_ELEMENT_P ); 
     437                          polys->add( COLLADA_ELEMENT_P ); 
    435438                          std::string mat = name + "_material"; 
    436439                          polys->setMaterial( mat.c_str() ); 
     
    440443                          polylist = createPrimGroup<domPolylist>( COLLADA_ELEMENT_POLYLIST, mesh, norm, color, texcoord ); 
    441444                             
    442                           polylist->createAndPlace( COLLADA_ELEMENT_VCOUNT ); 
    443                           polylist->createAndPlace( COLLADA_ELEMENT_P ); 
     445                          polylist->add( COLLADA_ELEMENT_VCOUNT ); 
     446                          polylist->add( COLLADA_ELEMENT_P ); 
    444447                          std::string mat = name + "_material"; 
    445448                          polylist->setMaterial( mat.c_str() ); 
     
    493496                    { 
    494497                        polys = createPrimGroup<domPolygons>( COLLADA_ELEMENT_POLYGONS, mesh, norm, color, texcoord ); 
    495                         polys->createAndPlace( COLLADA_ELEMENT_P ); 
     498                        polys->add( COLLADA_ELEMENT_P ); 
    496499                        std::string mat = name + "_material"; 
    497500                        polys->setMaterial( mat.c_str() ); 
     
    501504                        polylist = createPrimGroup<domPolylist>( COLLADA_ELEMENT_POLYLIST, mesh, norm, color, texcoord ); 
    502505 
    503                         polylist->createAndPlace( COLLADA_ELEMENT_VCOUNT ); 
    504                         polylist->createAndPlace( COLLADA_ELEMENT_P ); 
     506                        polylist->add( COLLADA_ELEMENT_VCOUNT ); 
     507                        polylist->add( COLLADA_ELEMENT_P ); 
    505508                        std::string mat = name + "_material"; 
    506509                        polylist->setMaterial( mat.c_str() ); 
     
    550553                    case GL_LINE_STRIP: 
    551554                    { 
    552                                                 p.push_back(daeSafeCast<domP>( linestrips->createAndPlace( COLLADA_ELEMENT_P ) )); 
     555                                                p.push_back(daeSafeCast<domP>( linestrips->add( COLLADA_ELEMENT_P ) )); 
    553556                        linestrips->setCount( linestrips->getCount() + 1 ); 
    554557                        break; 
     
    556559                    case GL_TRIANGLE_STRIP: 
    557560                    { 
    558                                                 p.push_back(daeSafeCast<domP>( tristrips->createAndPlace( COLLADA_ELEMENT_P ) )); 
     561                                                p.push_back(daeSafeCast<domP>( tristrips->add( COLLADA_ELEMENT_P ) )); 
    559562                        tristrips->setCount( tristrips->getCount() + 1 ); 
    560563                        break; 
     
    562565                    case GL_TRIANGLE_FAN: 
    563566                    { 
    564                                                 p.push_back(daeSafeCast<domP>( trifans->createAndPlace( COLLADA_ELEMENT_P ) )); 
     567                                                p.push_back(daeSafeCast<domP>( trifans->add( COLLADA_ELEMENT_P ) )); 
    565568                        trifans->setCount( trifans->getCount() + 1 ); 
    566569                        break; 
     
    651654                        case GL_LINE_STRIP: 
    652655                        { 
    653                             p.push_back(daeSafeCast<domP>( linestrips->createAndPlace( COLLADA_ELEMENT_P ) )); 
     656                            p.push_back(daeSafeCast<domP>( linestrips->add( COLLADA_ELEMENT_P ) )); 
    654657                            linestrips->setCount( linestrips->getCount() + 1 ); 
    655658                            break; 
     
    657660                        case GL_TRIANGLE_STRIP: 
    658661                        { 
    659                             p.push_back(daeSafeCast<domP>( tristrips->createAndPlace( COLLADA_ELEMENT_P ) )); 
     662                            p.push_back(daeSafeCast<domP>( tristrips->add( COLLADA_ELEMENT_P ) )); 
    660663                            tristrips->setCount( tristrips->getCount() + 1 ); 
    661664                            break; 
     
    663666                        case GL_TRIANGLE_FAN: 
    664667                        { 
    665                             p.push_back(daeSafeCast<domP>( trifans->createAndPlace( COLLADA_ELEMENT_P ) )); 
     668                            p.push_back(daeSafeCast<domP>( trifans->add( COLLADA_ELEMENT_P ) )); 
    666669                            trifans->setCount( trifans->getCount() + 1 ); 
    667670                            break; 
     
    745748                    case GL_LINE_STRIP: 
    746749                    { 
    747                         p.push_back(daeSafeCast<domP>( linestrips->createAndPlace( COLLADA_ELEMENT_P ) )); 
     750                        p.push_back(daeSafeCast<domP>( linestrips->add( COLLADA_ELEMENT_P ) )); 
    748751                        linestrips->setCount( linestrips->getCount() + 1 ); 
    749752                        break; 
     
    751754                    case GL_TRIANGLE_STRIP: 
    752755                    { 
    753                         p.push_back(daeSafeCast<domP>( tristrips->createAndPlace( COLLADA_ELEMENT_P ) )); 
     756                        p.push_back(daeSafeCast<domP>( tristrips->add( COLLADA_ELEMENT_P ) )); 
    754757                        tristrips->setCount( tristrips->getCount() + 1 ); 
    755758                        break; 
     
    757760                    case GL_TRIANGLE_FAN: 
    758761                    { 
    759                         p.push_back(daeSafeCast<domP>( trifans->createAndPlace( COLLADA_ELEMENT_P ) )); 
     762                        p.push_back(daeSafeCast<domP>( trifans->add( COLLADA_ELEMENT_P ) )); 
    760763                        trifans->setCount( trifans->getCount() + 1 ); 
    761764                        break; 
     
    844847                    case GL_LINE_STRIP: 
    845848                    { 
    846                         p.push_back(daeSafeCast<domP>( linestrips->createAndPlace( COLLADA_ELEMENT_P ) )); 
     849                        p.push_back(daeSafeCast<domP>( linestrips->add( COLLADA_ELEMENT_P ) )); 
    847850                        linestrips->setCount( linestrips->getCount() + 1 ); 
    848851                        break; 
     
    850853                    case GL_TRIANGLE_STRIP: 
    851854                    { 
    852                         p.push_back(daeSafeCast<domP>( tristrips->createAndPlace( COLLADA_ELEMENT_P ) )); 
     855                        p.push_back(daeSafeCast<domP>( tristrips->add( COLLADA_ELEMENT_P ) )); 
    853856                        tristrips->setCount( tristrips->getCount() + 1 ); 
    854857                        break; 
     
    856859                    case GL_TRIANGLE_FAN: 
    857860                    { 
    858                         p.push_back(daeSafeCast<domP>( trifans->createAndPlace( COLLADA_ELEMENT_P ) )); 
     861                        p.push_back(daeSafeCast<domP>( trifans->add( COLLADA_ELEMENT_P ) )); 
    859862                        trifans->setCount( trifans->getCount() + 1 ); 
    860863                        break; 
     
    945948                    case GL_LINE_STRIP: 
    946949                    { 
    947                         p.push_back(daeSafeCast<domP>( linestrips->createAndPlace( COLLADA_ELEMENT_P ) )); 
     950                        p.push_back(daeSafeCast<domP>( linestrips->add( COLLADA_ELEMENT_P ) )); 
    948951                        linestrips->setCount( linestrips->getCount() + 1 ); 
    949952                        break; 
     
    951954                    case GL_TRIANGLE_STRIP: 
    952955                    { 
    953                         p.push_back(daeSafeCast<domP>( tristrips->createAndPlace( COLLADA_ELEMENT_P ) )); 
     956                        p.push_back(daeSafeCast<domP>( tristrips->add( COLLADA_ELEMENT_P ) )); 
    954957                        tristrips->setCount( tristrips->getCount() + 1 ); 
    955958                        break; 
     
    957960                    case GL_TRIANGLE_FAN: 
    958961                    { 
    959                         p.push_back(daeSafeCast<domP>( trifans->createAndPlace( COLLADA_ELEMENT_P ) )); 
     962                        p.push_back(daeSafeCast<domP>( trifans->add( COLLADA_ELEMENT_P ) )); 
    960963                        trifans->setCount( trifans->getCount() + 1 ); 
    961964                        break; 
     
    10391042domSource *daeWriter::createSource( daeElement *parent, const std::string &baseName, int size, bool color, bool uv ) 
    10401043{ 
    1041     domSource *src = daeSafeCast< domSource >( parent->createAndPlace( COLLADA_ELEMENT_SOURCE ) ); 
     1044    domSource *src = daeSafeCast< domSource >( parent->add( COLLADA_ELEMENT_SOURCE ) ); 
    10421045    if ( src == NULL ) 
    10431046    { 
     
    10461049    src->setId( baseName.c_str() ); 
    10471050 
    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 ) ); 
    10491052    std::string fName = baseName + "-array"; 
    10501053    fa->setId( fName.c_str() ); 
    10511054 
    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 ) ); 
    10541057    std::string url = "#" + fName; 
    10551058    acc->setSource( url.c_str() ); 
     
    10581061    { 
    10591062        acc->setStride( size ); 
    1060         param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); 
     1063        param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 
    10611064        param->setName( "R" ); 
    10621065        param->setType( "float" ); 
    10631066         
    1064         param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); 
     1067        param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 
    10651068        param->setName( "G" ); 
    10661069        param->setType( "float" ); 
    10671070 
    1068         param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); 
     1071        param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 
    10691072        param->setName( "B" ); 
    10701073        param->setType( "float" ); 
    10711074 
    10721075        if ( size == 4 ) { 
    1073             param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); 
     1076            param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 
    10741077            param->setName( "A" ); 
    10751078            param->setType( "float" ); 
     
    10801083    { 
    10811084        acc->setStride( size ); 
    1082         param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); 
     1085        param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 
    10831086        param->setName( "S" ); 
    10841087        param->setType( "float" ); 
    10851088 
    1086         param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); 
     1089        param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 
    10871090        param->setName( "T" ); 
    10881091        param->setType( "float" ); 
     
    10901093        if ( size >=3 ) 
    10911094        { 
    1092             param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); 
     1095            param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 
    10931096            param->setName( "P" ); 
    10941097            param->setType( "float" ); 
     
    10981101    { 
    10991102        acc->setStride( size ); 
    1100         param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); 
     1103        param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 
    11011104        param->setName( "X" ); 
    11021105        param->setType( "float" ); 
    11031106 
    1104         param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); 
     1107        param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 
    11051108        param->setName( "Y" ); 
    11061109        param->setType( "float" ); 
     
    11081111        if ( size >=3 ) 
    11091112        { 
    1110             param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); 
     1113            param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 
    11111114            param->setName( "Z" ); 
    11121115            param->setType( "float" ); 
     
    11141117            if ( size == 4 ) 
    11151118            { 
    1116                 param = daeSafeCast< domParam >( acc->createAndPlace( COLLADA_ELEMENT_PARAM ) ); 
     1119                param = daeSafeCast< domParam >( acc->add( COLLADA_ELEMENT_PARAM ) ); 
    11171120                param->setName( "W" ); 
    11181121                param->setType( "float" ); 
     
    11281131{ 
    11291132    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" ) ); 
    11321135    ilo->setOffset( offset++ ); 
    11331136    ilo->setSemantic( "VERTEX" ); 
     
    11361139    if ( norm != NULL ) 
    11371140    { 
    1138         ilo = daeSafeCast< domInputLocalOffset >( retVal->createAndPlace( "input" ) ); 
     1141        ilo = daeSafeCast< domInputLocalOffset >( retVal->add( "input" ) ); 
    11391142        ilo->setOffset( offset++ ); 
    11401143        ilo->setSemantic( "NORMAL" ); 
     
    11441147    if ( color != NULL ) 
    11451148    { 
    1146         ilo = daeSafeCast< domInputLocalOffset >( retVal->createAndPlace( "input" ) ); 
     1149        ilo = daeSafeCast< domInputLocalOffset >( retVal->add( "input" ) ); 
    11471150        ilo->setOffset( offset++ ); 
    11481151        ilo->setSemantic( "COLOR" ); 
     
    11521155    for ( unsigned int i = 0; i < texcoord.size(); i++ ) 
    11531156    { 
    1154         ilo = daeSafeCast< domInputLocalOffset >( retVal->createAndPlace( "input" ) ); 
     1157        ilo = daeSafeCast< domInputLocalOffset >( retVal->add( "input" ) ); 
    11551158        ilo->setOffset( offset++ ); 
    11561159        ilo->setSemantic( "TEXCOORD" ); 
  • OpenSceneGraph/trunk/src/osgPlugins/dae/daeWMaterials.cpp

    r8353 r9228  
    3434{ 
    3535    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 ) ); 
    3939    std::string symbol = geoName + "_material"; 
    4040    im->setSymbol( symbol.c_str() ); 
     
    5050    if ( lib_mats == NULL ) 
    5151    { 
    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 ) ); 
    5656    std::string name = ssClean->getName(); 
    5757    if ( name.empty() ) 
     
    6666    im->setTarget( url.c_str() ); 
    6767 
    68     domInstance_effect *ie = daeSafeCast<domInstance_effect>( mat->createAndPlace( "instance_effect" ) ); 
     68    domInstance_effect *ie = daeSafeCast<domInstance_effect>( mat->add( "instance_effect" ) ); 
    6969 
    7070    if ( lib_effects == NULL ) 
    7171    { 
    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 ) ); 
    7575    std::string efName = name + "_effect"; 
    7676     
     
    8080    ie->setUrl( url.c_str() ); 
    8181 
    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" ) ); 
    8484    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" ) ); 
    8686 
    8787    osg::Texture *tex = static_cast<osg::Texture*>(ssClean->getTextureAttribute( 0, osg::StateAttribute::TEXTURE )); 
     
    9393    { 
    9494        //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 ) ); 
    9696        std::string iName = efName + "-image"; 
    9797        img->setId( iName.c_str() ); 
    9898 
    9999        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" ) ); 
    101101        std::string fileURI = ReaderWriterDAE::ConvertFilePathToColladaCompatibleURI(osgDB::findDataFile(osgimg->getFileName())); 
    102102       daeURI dd(*dae, fileURI);//fileURI.c_str() ); 
     
    106106 
    107107#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" ) ); 
    109109        std::string surfName = efName + "-surface"; 
    110110        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") ); 
    113113        sif->setValue( iName.c_str() ); 
    114114        surface->setType( FX_SURFACE_TYPE_ENUM_2D ); 
    115115 
    116         np = daeSafeCast< domCommon_newparam_type >( pc->createAndPlace( "newparam" ) ); 
     116        np = daeSafeCast< domCommon_newparam_type >( pc->add( "newparam" ) ); 
    117117        std::string sampName = efName + "-sampler"; 
    118118        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" ) ); 
    121121        source->setValue( surfName.c_str() );  
    122122 
    123123        //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" ) ); 
    125125        osg::Texture::WrapMode wrap = tex->getWrap( osg::Texture::WRAP_S ); 
    126126        switch( wrap )  
     
    144144        } 
    145145 
    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" ) ); 
    147147        wrap = tex->getWrap( osg::Texture::WRAP_T ); 
    148148        switch( wrap )  
     
    167167 
    168168        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" ) ); 
    170170        dbcol->getValue().append( bcol.r() ); 
    171171        dbcol->getValue().append( bcol.g() ); 
     
    173173        dbcol->getValue().append( bcol.a() ); 
    174174 
    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" ) ); 
    176176        osg::Texture::FilterMode mode = tex->getFilter( osg::Texture::MIN_FILTER ); 
    177177        switch( mode ) 
     
    197197        } 
    198198 
    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" ) ); 
    200200        mode = tex->getFilter( osg::Texture::MAG_FILTER ); 
    201201        switch( mode ) 
     
    222222 
    223223 
    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" ) ); 
    226226        dtex->setTexture( sampName.c_str() ); 
    227227        dtex->setTexcoord( "texcoord0" ); 
    228228#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" ) ); 
    231231        dtex->setTexture( iName.c_str() ); 
    232232        dtex->setTexcoord( "texcoord0" ); 
    233233#endif 
    234234 
    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" ) ); 
    236236        bvi->setSemantic( "texcoord0" ); 
    237237        bvi->setInput_semantic( "TEXCOORD" ); 
    238238        bvi->setInput_set( 0 ); 
    239  
    240 /*  I dont think this belongs here RFJ 
    241         //take care of blending if any 
    242         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_TEX 
    260             dtex->setTexture( sampName.c_str() ); 
    261 #else 
    262             dtex->setTexture( iName.c_str() ); 
    263 #endif 
    264             dtex->setTexcoord( "texcoord0" );            
    265         } 
    266 */        
    267239    } 
    268240    osg::Material *osgmat = static_cast<osg::Material*>(ssClean->getAttribute( osg::StateAttribute::MATERIAL )); 
     
    275247        float shininess = osgmat->getShininessFrontAndBack()?osgmat->getShininess( osg::Material::FRONT_AND_BACK ):osgmat->getShininess( osg::Material::FRONT ); 
    276248         
    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" ) ); 
    279251        col->getValue().append( eCol.r() ); 
    280252        col->getValue().append( eCol.g() ); 
     
    282254        col->getValue().append( eCol.a() ); 
    283255 
    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" ) ); 
    286258        col->getValue().append( aCol.r() ); 
    287259        col->getValue().append( aCol.g() ); 
     
    293265        if ( phong->getDiffuse() == NULL ) 
    294266        { 
    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" ) ); 
    297269            col->getValue().append( dCol.r() ); 
    298270            col->getValue().append( dCol.g() ); 
     
    304276            cot = phong->getDiffuse(); 
    305277             
    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" ) ); 
    320303        col->getValue().append( sCol.r() ); 
    321304        col->getValue().append( sCol.g() ); 
     
    323306        col->getValue().append( sCol.a() ); 
    324307 
    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" ) ); 
    327310        f->setValue( shininess ); 
    328311    } 
     
    334317        osg::BlendFunc *pBlendFunc = static_cast< osg::BlendFunc * >( ssClean->getAttribute( osg::StateAttribute::BLENDFUNC ) ); 
    335318        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) 
    339322            { 
    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())) 
    347324                { 
    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                    } 
    353347                } 
    354                 else 
     348                else if ((GL_ONE_MINUS_CONSTANT_COLOR == pBlendFunc->getSource()) && (GL_CONSTANT_COLOR == pBlendFunc->getDestination())) 
    355349                { 
     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")); 
    356354                    pColor->getValue().append(pBlendColor->getConstantColor().r()); 
    357355                    pColor->getValue().append(pBlendColor->getConstantColor().g()); 
    358356                    pColor->getValue().append(pBlendColor->getConstantColor().b()); 
    359357                    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")); 
    360360                    pTransparency->setValue(1.0); 
    361361                } 
     362                else 
     363                    osg::notify( osg::WARN ) << "Unsupported BlendFunction parameters in transparency processing." << std::endl; 
    362364            } 
    363             else if ((GL_ONE_MINUS_CONSTANT_COLOR == pBlendFunc->getSource()) && (GL_CONSTANT_COLOR == pBlendFunc->getDestination())) 
     365            else if (tex != NULL && tex->getImage( 0 ) != NULL) 
    364366            { 
    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" );            
    376379            } 
    377380            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            } 
    379384        } 
    380385        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        } 
    395413    } 
    396414 
     
    410428        pCleanedStateSet->setAttribute(pStateSet->getAttribute(osg::StateAttribute::MATERIAL)); 
    411429    // 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)) 
    413431        pCleanedStateSet->setMode(GL_CULL_FACE, pStateSet->getMode(GL_CULL_FACE)); 
    414432    return pCleanedStateSet; 
  • OpenSceneGraph/trunk/src/osgPlugins/dae/daeWSceneObjects.cpp

    r5757 r9228  
    2020#include <dom/domLibrary_cameras.h> 
    2121#include <dom/domLibrary_lights.h> 
    22  
     22#include <dae/domAny.h> 
    2323//#include <dom/domVisual_scene.h> 
    2424//#include <dom/domLibrary_visual_scenes.h> 
    2525 
     26#include <osgSim/MultiSwitch> 
     27#include <osg/Sequence> 
     28#include <osg/Billboard> 
     29 
    2630using namespace osgdae; 
    2731 
    28  
    29 //GROUP 
     32// Write non-standard node data as extra of type "Node" with "OpenSceneGraph" technique 
     33void 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 
    3067void daeWriter::apply( osg::Group &node ) 
    3168{ 
    32 #ifdef _DEBUG 
    33     debugPrint( node ); 
    34 #endif 
     69    debugPrint( node ); 
    3570 
    3671    while ( lastDepth >= _nodePath.size() ) 
     
    4075        lastDepth--; 
    4176    } 
    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    { 
    43130        currentNode->setId(getNodeName(node,"group").c_str()); 
     131    } 
     132 
     133    writeNodeExtra(node); 
    44134     
    45135    lastDepth = _nodePath.size(); 
    46136 
    47     lastVisited = GROUP; 
    48      
    49     traverse( node ); 
    50 } 
    51  
    52  
    53 //SWITCH 
     137    traverse( node ); 
     138} 
     139 
     140 
    54141void daeWriter::apply( osg::Switch &node ) 
    55142{ 
    56 #ifdef _DEBUG 
    57     debugPrint( node ); 
    58 #endif 
     143    debugPrint( node ); 
    59144 
    60145    while ( lastDepth >= _nodePath.size() ) 
     
    64149        lastDepth--; 
    65150    } 
    66     currentNode = daeSafeCast< domNode >(currentNode->createAndPlace( COLLADA_ELEMENT_NODE ) ); 
     151    currentNode = daeSafeCast< domNode >(currentNode->add( COLLADA_ELEMENT_NODE ) ); 
    67152    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); 
    68187     
    69188    lastDepth = _nodePath.size(); 
    70189 
    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 
     194void daeWriter::apply( osg::Sequence &node ) 
     195{ 
     196    debugPrint( node ); 
    89197 
    90198    while ( lastDepth >= _nodePath.size() ) 
     
    94202        lastDepth--; 
    95203    } 
    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 
     277void 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 ) ); 
    97288    lastDepth = _nodePath.size(); 
    98289    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 ); 
    113344} 
    114345 
    115346void daeWriter::apply( osg::ProxyNode &node )  
    116347{ 
    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 
    123351void daeWriter::apply( osg::LightSource &node ) 
    124352{ 
    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" ) ); 
    130356    std::string name = node.getName(); 
    131357    if ( name.empty() ) 
     
    138364    if ( lib_lights == NULL ) 
    139365    { 
    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 ) ); 
    143369    light->setId( name.c_str() ); 
    144370     
    145     lastVisited = LIGHT; 
    146  
    147     traverse( node ); 
    148 } 
    149  
    150 //CAMERA 
     371    traverse( node ); 
     372} 
     373 
    151374void daeWriter::apply( osg::Camera &node ) 
    152375{ 
    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" ) ); 
    158379    std::string name = node.getName(); 
    159380    if ( name.empty() ) 
     
    166387    if ( lib_cameras == NULL ) 
    167388    { 
    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 ) ); 
    171392    cam->setId( name.c_str() ); 
    172393 
    173     lastVisited = CAMERA; 
    174  
    175     traverse( node ); 
    176 } 
     394    traverse( node ); 
     395} 
  • OpenSceneGraph/trunk/src/osgPlugins/dae/daeWTransforms.cpp

    r9045 r9228  
    1818#include <dom/domNode.h> 
    1919#include <dom/domConstants.h> 
     20#include <dae/domAny.h> 
     21 
     22#include <osgSim/DOFTransform> 
    2023 
    2124using namespace osgdae; 
     
    3538    } 
    3639 
    37     currentNode = daeSafeCast< domNode >(currentNode->createAndPlace( COLLADA_ELEMENT_NODE ) ); 
     40    currentNode = daeSafeCast< domNode >(currentNode->add( COLLADA_ELEMENT_NODE ) ); 
    3841    currentNode->setId(getNodeName(node,"matrixTransform").c_str()); 
    3942     
    40     domMatrix *mat = daeSafeCast< domMatrix >(currentNode->createAndPlace( COLLADA_ELEMENT_MATRIX ) ); 
     43    domMatrix *mat = daeSafeCast< domMatrix >(currentNode->add( COLLADA_ELEMENT_MATRIX ) ); 
    4144    const osg::Matrix::value_type *mat_vals = node.getMatrix().ptr(); 
    4245    //for ( int i = 0; i < 16; i++ ) 
     
    6164    mat->getValue().append( mat_vals[15] ); 
    6265 
    63     lastVisited = MATRIX; 
    6466    lastDepth = _nodePath.size(); 
     67 
     68    writeNodeExtra(node); 
    6569 
    6670    traverse( node ); 
     
    8084        lastDepth--; 
    8185    } 
    82     currentNode = daeSafeCast< domNode >(currentNode->createAndPlace( COLLADA_ELEMENT_NODE ) ); 
     86    currentNode = daeSafeCast< domNode >(currentNode->add( COLLADA_ELEMENT_NODE ) ); 
    8387    currentNode->setId(getNodeName(node,"positionAttitudeTransform").c_str()); 
    8488     
     
    9094    { 
    9195        //make a scale 
    92         domScale *scale = daeSafeCast< domScale >( currentNode->createAndPlace( COLLADA_ELEMENT_SCALE ) ); 
     96        domScale *scale = daeSafeCast< domScale >( currentNode->add( COLLADA_ELEMENT_SCALE ) ); 
    9397        scale->getValue().append( s.x() ); 
    9498        scale->getValue().append( s.y() ); 
     
    102106    { 
    103107        //make a rotate 
    104         domRotate *rot = daeSafeCast< domRotate >( currentNode->createAndPlace( COLLADA_ELEMENT_ROTATE ) ); 
     108        domRotate *rot = daeSafeCast< domRotate >( currentNode->add( COLLADA_ELEMENT_ROTATE ) ); 
    105109        rot->getValue().append( axis.x() ); 
    106110        rot->getValue().append( axis.y() ); 
     
    112116    { 
    113117        //make a translate 
    114         domTranslate *trans = daeSafeCast< domTranslate >( currentNode->createAndPlace( COLLADA_ELEMENT_TRANSLATE ) ); 
     118        domTranslate *trans = daeSafeCast< domTranslate >( currentNode->add( COLLADA_ELEMENT_TRANSLATE ) ); 
    115119        trans->getValue().append( pos.x() ); 
    116120        trans->getValue().append( pos.y() ); 
     
    118122    } 
    119123 
    120     lastVisited = POSATT; 
     124    writeNodeExtra(node); 
     125 
    121126    lastDepth = _nodePath.size(); 
    122127 
     
    126131void daeWriter::apply( osg::Transform &node )  
    127132{ 
    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 ); 
    129241} 
    130242 
    131243void daeWriter::apply( osg::CoordinateSystemNode &node )  
    132244{ 
    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  
    2121#include <sstream> 
    2222 
    23 using namespace osgdae; 
    24  
    25 daeWriter::daeWriter( DAE *dae_, const std::string &fileURI, bool _usePolygons,  bool GoogleMode ) : osg::NodeVisitor( TRAVERSE_ALL_CHILDREN ), 
     23 
     24namespace osgdae { 
     25 
     26std::string toString(osg::Vec3 value) 
     27{ 
     28    std::stringstream str; 
     29    str << value.x() << " " << value.y() << " " << value.z(); 
     30    return str.str(); 
     31} 
     32 
     33std::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 
     44daeWriter::daeWriter( DAE *dae_, const std::string &fileURI, bool _usePolygons,  bool GoogleMode, TraversalMode tm, bool _writeExtras) : osg::NodeVisitor( tm ), 
    2645                                        dae(dae_), 
    2746                                        rootName(*dae_), 
    2847                                        usePolygons (_usePolygons), 
    29                                         m_GoogleMode(GoogleMode) 
     48                                        m_GoogleMode(GoogleMode), 
     49                                        writeExtras(_writeExtras) 
    3050{ 
    3151    success = true; 
     
    3757    dom = (domCOLLADA*)doc->getDomRoot(); 
    3858    //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" ) ); 
    4161    ivs->setUrl( "#defaultScene" ); 
    4262    //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 ) ); 
    4565    vs->setId( "defaultScene" ); 
    46     currentNode = daeSafeCast< domNode >( vs->createAndPlace( COLLADA_ELEMENT_NODE ) ); 
     66    currentNode = daeSafeCast< domNode >( vs->add( COLLADA_ELEMENT_NODE ) ); 
    4767    currentNode->setId( "sceneRoot" ); 
    4868 
     
    6787void daeWriter::debugPrint( osg::Node &node ) 
    6888{ 
     89#ifdef _DEBUG 
    6990    std::string indent = ""; 
    7091    for ( unsigned int i = 0; i < _nodePath.size(); i++ ) 
     
    7394    } 
    7495    osg::notify( osg::INFO ) << indent << node.className() << std::endl; 
     96#endif 
    7597} 
    7698 
     
    95117{ 
    96118    std::string nodeName; 
    97     if ((node.getName().empty()) || (node.getName()!="")) 
     119    if (node.getName().empty()) 
    98120        nodeName=uniquify(defaultName); 
    99121    else 
     
    105127void daeWriter::apply( osg::Node &node ) 
    106128{ 
    107 #ifdef _DEBUG 
    108129    debugPrint( node ); 
    109 #endif 
    110  
    111     osg::notify( osg::INFO ) << "generic node\n"; 
    112     lastVisited = NODE; 
     130 
     131    writeNodeExtra(node); 
    113132 
    114133    traverse( node ); 
     
    136155void daeWriter::createAssetTag() 
    137156{ 
    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")); 
    142161 
    143162    //TODO : set date and time 
     
    180199} 
    181200 
     201} // namespace osgdae 
  • OpenSceneGraph/trunk/src/osgPlugins/dae/daeWriter.h

    r7664 r9228  
    4040#include <osgDB/FileUtils> 
    4141#include <osgDB/Registry> 
     42#include <osgSim/MultiSwitch> 
    4243 
    4344#include <dae.h> 
     
    6263 
    6364namespace osgdae { 
     65 
     66/// Convert value to string using it's stream operator 
     67template <typename T> 
     68std::string toString(T value) { 
     69    std::stringstream str; 
     70    str << value; 
     71    return str.str(); 
     72} 
     73 
     74std::string toString(osg::Vec3 value); 
     75std::string toString(osg::Matrix value); 
    6476   
    6577/** 
     
    7284    class ArrayNIndices; 
    7385public: 
    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); 
    7787    virtual ~daeWriter(); 
    7888 
     
    91101    virtual void    apply( osg::PositionAttitudeTransform &node ); 
    92102    virtual void    apply( osg::Switch &node ); 
     103    virtual void    apply( osg::Sequence &node ); 
    93104    virtual void    apply( osg::LOD &node ); 
    94105 
    95     //virtual void  apply( osg::Billboard &node); 
     106    //virtual void    apply( osg::Billboard &node); 
    96107    virtual void    apply( osg::ProxyNode &node ); 
    97108    //virtual void  apply( osg::Projection &node) 
     
    101112    virtual void    apply( osg::Transform &node ); 
    102113    //virtual void  apply( osg::CameraView &node) 
    103     //virtual void  apply( osg::Sequence &node) 
    104114    //virtual void  apply( osg::PagedLOD &node) 
    105115    //virtual void  apply( osg::ClearNode &node) 
    106116    //virtual void  apply( osg::OccluderNode &node) 
     117 
     118    void writeNodeExtra(osg::Node &node); 
     119 
     120 
    107121 
    108122    void traverse (osg::Node &node); 
     
    149163    domVisual_scene *vs; 
    150164 
     165    /// Write OSG specific data as extra data 
     166    bool writeExtras; 
    151167    bool success; 
    152     NodeType lastVisited; 
    153168    unsigned int lastDepth; 
    154169