diff --git a/src/osgPlugins/dae/daeRGeometry.cpp b/src/osgPlugins/dae/daeRGeometry.cpp index 9d457f0fd..257f9d301 100644 --- a/src/osgPlugins/dae/daeRGeometry.cpp +++ b/src/osgPlugins/dae/daeRGeometry.cpp @@ -462,7 +462,7 @@ void daeReader::processSinglePPrimitive(osg::Geode* geode, osg::Geometry *geometry = new osg::Geometry(); if (NULL != group->getMaterial()) geometry->setName(group->getMaterial()); - geode->addDrawable( geometry ); + osg::DrawElementsUInt* pDrawElements = new osg::DrawElementsUInt(mode); geometry->addPrimitiveSet(pDrawElements); @@ -472,7 +472,11 @@ void daeReader::processSinglePPrimitive(osg::Geode* geode, std::vector > indexLists; resolveMeshArrays(domPArray, group->getInput_array(), pDomMesh, geometry, sources, indexLists); - pDrawElements->asVector().swap(indexLists.front()); + if (indexLists.front().size()) + { + pDrawElements->asVector().swap(indexLists.front()); + geode->addDrawable( geometry ); + } } template< typename T > @@ -945,6 +949,9 @@ void daeReader::resolveMeshArrays(const domP_Array& domPArray, { if (daeElement* texcoord_source = texcoord_sources[texcoord_set]) { + std::string id = std::string("#") + texcoord_source->getID(); + //We keep somewhere the mapping between daeElement id and created arrays + _texCoordIdMap.insert(std::pair(id,texcoord_set)); // 2D Texcoords osg::Geometry::ArrayData arrayData( createGeometryData(sources[texcoord_source], vertexIndicesIndexMap, readDoubleTexcoords, texcoord_set) ); if (arrayData.array.valid()) diff --git a/src/osgPlugins/dae/daeRMaterials.cpp b/src/osgPlugins/dae/daeRMaterials.cpp index a5efa8201..5e73fdf9e 100644 --- a/src/osgPlugins/dae/daeRMaterials.cpp +++ b/src/osgPlugins/dae/daeRMaterials.cpp @@ -584,7 +584,7 @@ bool daeReader::processColorOrTextureType(const osg::StateSet* ss, if (cot->getColor() != NULL ) { domFloat4 &f4 = cot->getColor()->getValue(); - mat->setEmission( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) ); + mat->setEmission( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], (f4.getCount()==4)? f4[3] : 1.0 ) ); retVal = true; } else if (cot->getParam() != NULL) @@ -616,7 +616,7 @@ bool daeReader::processColorOrTextureType(const osg::StateSet* ss, if (cot->getColor() != NULL ) { domFloat4 &f4 = cot->getColor()->getValue(); - mat->setAmbient( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) ); + mat->setAmbient( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], (f4.getCount()==4)? f4[3] : 1.0 ) ); retVal = true; } else if (cot->getParam() != NULL) @@ -646,10 +646,10 @@ bool daeReader::processColorOrTextureType(const osg::StateSet* ss, } else if (channel == osg::Material::DIFFUSE ) { - if (cot->getColor() != NULL ) + if (cot->getColor() != NULL) { domFloat4 &f4 = cot->getColor()->getValue(); - mat->setDiffuse( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) ); + mat->setDiffuse( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], (f4.getCount()==4)? f4[3] : 1.0 ) ); retVal = true; } else if (cot->getTexture() != NULL) @@ -700,7 +700,7 @@ bool daeReader::processColorOrTextureType(const osg::StateSet* ss, if (cot->getColor() != NULL ) { domFloat4 &f4 = cot->getColor()->getValue(); - mat->setSpecular( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) ); + mat->setSpecular( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], (f4.getCount()==4)? f4[3] : 1.0 ) ); retVal = true; } else if (cot->getParam() != NULL) @@ -1305,9 +1305,31 @@ bool daeReader::copyTextureCoordinateSet(const osg::StateSet* ss, const osg::Geo if (k == bvia.getCount()) { OSG_WARN << "Failed to find matching for " << texCoordSetName << std::endl; - if (cachedGeometry->getNumTexCoordArrays()) + + //bind_vertex_input failed, we try bind + const domInstance_material::domBind_Array &ba = im->getBind_array(); + for (k = 0; k < ba.getCount(); k++) { - clonedGeometry->setTexCoordData(localTextureUnit, cachedGeometry->getTexCoordData(0)); + if (!strcmp(ba[k]->getSemantic(), texCoordSetName.c_str()) ) + { + IdToCoordIndexMap::const_iterator it = _texCoordIdMap.find(ba[k]->getTarget()); + if (it!=_texCoordIdMap.end()&& (cachedGeometry->getNumTexCoordArrays()>it->second)) + { + clonedGeometry->setTexCoordData(localTextureUnit, cachedGeometry->getTexCoordData(it->second)); + } + else + { + OSG_WARN << "Texture coordinate set " << ba[k]->getTarget() << " not found." << std::endl; + } + break; + } + } + if (k == ba.getCount()) + { + if (cachedGeometry->getNumTexCoordArrays()) + { + clonedGeometry->setTexCoordData(localTextureUnit, cachedGeometry->getTexCoordData(0)); + } } } return true; diff --git a/src/osgPlugins/dae/daeReader.h b/src/osgPlugins/dae/daeReader.h index 10d043907..7acd498ae 100644 --- a/src/osgPlugins/dae/daeReader.h +++ b/src/osgPlugins/dae/daeReader.h @@ -245,6 +245,7 @@ public: typedef std::map > domNodeOsgSkeletonMap; typedef std::map > TextureParametersMap; typedef std::map, std::string> TextureToCoordSetMap; + typedef std::map IdToCoordIndexMap; typedef std::map< daeElement*, domSourceReader > SourceMap; typedef std::map< int, osg::IntArray*, std::less > IndexMap; @@ -403,6 +404,7 @@ private: MaterialStateSetMap _materialMap2; TextureParametersMap _textureParamMap; TextureToCoordSetMap _texCoordSetMap; + IdToCoordIndexMap _texCoordIdMap; domInstance_controllerList _skinInstanceControllers; OldToNewIndexMap _oldToNewIndexMap;