diff --git a/collada_parser/src/collada_parser.cpp b/collada_parser/src/collada_parser.cpp index f242094..76faeab 100644 --- a/collada_parser/src/collada_parser.cpp +++ b/collada_parser/src/collada_parser.cpp @@ -174,7 +174,7 @@ namespace urdf{ ///< for sphere it is radius ///< for cylinder, first 2 values are radius and height ///< for trimesh, none - Color diffuseColor, ambientColor; ///< hints for how to color the meshes + Color emissionColor, diffuseColor, ambientColor, specularColor; ///< hints for how to color the meshes std::vector vertices; std::vector indices; @@ -769,6 +769,13 @@ namespace urdf{ plink.reset(new Link()); plink->name = linkname; plink->visual.reset(new Visual()); + plink->visual->material_name = ""; + plink->visual->material.reset(new Material()); + plink->visual->material->name = "Red"; + plink->visual->material->color.r = 0.0; + plink->visual->material->color.g = 1.0; + plink->visual->material->color.b = 0.0; + plink->visual->material->color.a = 1.0; _model->links_.insert(std::make_pair(linkname,plink)); } @@ -1026,18 +1033,34 @@ namespace urdf{ geometry->scale.y = 1; geometry->scale.z = 1; - std::vector vertices; - std::vector indices; + std::vector > vertices; + std::vector > indices; + std::vector emission; + std::vector ambients; + std::vector diffuses; + std::vector specular; + unsigned int index; + vertices.resize(listGeomProperties.size()); + indices.resize(listGeomProperties.size()); + emission.resize(listGeomProperties.size()); + ambients.resize(listGeomProperties.size()); + diffuses.resize(listGeomProperties.size()); + specular.resize(listGeomProperties.size()); + index = 0; FOREACHC(it, listGeomProperties) { - int voffset = vertices.size(), ioffset = indices.size(); - vertices.resize(vertices.size()+it->vertices.size()); + vertices[index].resize(it->vertices.size()); for(size_t i = 0; i < it->vertices.size(); ++i) { - vertices[voffset+i] = _poseMult(it->_t, it->vertices[i]); + vertices[index][i] = _poseMult(it->_t, it->vertices[i]); } - indices.resize(indices.size()+it->indices.size()); + indices[index].resize(it->indices.size()); for(size_t i = 0; i < it->indices.size(); ++i) { - indices[ioffset+i] = voffset+it->indices[i]; + indices[index][i] = it->indices[i]; } + emission[index] = it->emissionColor; + ambients[index] = it->ambientColor; + diffuses[index] = it->diffuseColor; + specular[index] = it->specularColor; + index++; } // have to save the geometry into individual collada 1.4 files since URDF does not allow triangle meshes to be specified @@ -1054,37 +1077,68 @@ namespace urdf{ \n\ Z_UP\n\ \n\ - \n\ - \n\ - \n\ - \n\ + \n")); + for(unsigned int i=0; i < index; i++){ + daedata << str(boost::format("\ + \n\ + \n\ + \n")%i%i%i); + } + daedata << "\ \n\ - \n\ - \n\ + \n"; + for(unsigned int i=0; i < index; i++){ + daedata << str(boost::format("\ + \n\ \n\ \n\ \n\ + \n\ + %f %f %f %f\n\ + \n\ \n\ - 0.0 0.0 0.1 1\n\ + %f %f %f %f\n\ \n\ \n\ - 0.8 0.8 0.8 1\n\ + %f %f %f %f\n\ \n\ + \n\ + %f %f %f %f\n\ + \n\ \n\ \n\ \n\ - \n\ + \n")%i%emission[i].r%emission[i].g%emission[i].b%emission[i].a%ambients[i].r%ambients[i].g%ambients[i].b%ambients[i].a%diffuses[i].r%diffuses[i].g%diffuses[i].b%diffuses[i].a%specular[i].r%specular[i].g%specular[i].b%specular[i].a); + std::cout << str(boost::format("\ +%d\n\ + \n\ + %f %f %f %f\n\ + \n\ + \n\ + %f %f %f %f\n\ + \n\ + \n\ + %f %f %f %f\n\ + \n\ + \n\ + %f %f %f %f\n\ + \n\ +")%i%emission[i].r%emission[i].g%emission[i].b%emission[i].a%ambients[i].r%ambients[i].g%ambients[i].b%ambients[i].a%diffuses[i].r%diffuses[i].g%diffuses[i].b%diffuses[i].a%specular[i].r%specular[i].g%specular[i].b%specular[i].a); + } + daedata << str(boost::format("\ \n\ - \n\ - \n\ + \n")); + // fill with vertices + for(unsigned int i=0; i < index; i++){ + daedata << str(boost::format("\ + \n\ \n\ \n\ - ")%(vertices.size()*3)); - // fill with vertices - FOREACH(it,vertices) { - daedata << it->x << " " << it->y << " " << it->z << " "; - } - daedata << str(boost::format("\n\ + ")%i%i%(vertices[i].size()*3)); + FOREACH(it,vertices[i]) { + daedata << it->x << " " << it->y << " " << it->z << " "; + } + daedata << str(boost::format("\n\ \n\ \n\ \n\ @@ -1099,33 +1153,39 @@ namespace urdf{ \n\ \n\ \n\ -

")%vertices.size()%(indices.size()/3)); - // fill with indices - FOREACH(it,indices) { - daedata << *it << " "; - } - daedata << str(boost::format("

\n\ +

")%vertices[i].size()%(indices[i].size()/3)); + // fill with indices + FOREACH(it,indices[i]) { + daedata << *it << " "; + } + daedata << str(boost::format("

\n\
\n\
\n\ -
\n\ +
\n")); + } + daedata << str(boost::format("\
\n\ \n\ \n\ - \n\ - \n\ + \n")%name%name); + for(unsigned int i=0; i < index; i++){ + daedata << str(boost::format("\ + \n\ \n\ \n\ - \n\ + \n\ \n\ \n\ - \n\ + \n")%i%i); + } + daedata << str(boost::format("\ \n\ \n\ \n\ \n\ \n\ \n\ -")%name%name); +")); #ifdef HAVE_MKSTEMPS geometry->filename = str(boost::format("/tmp/collada_model_reader_%s_XXXXXX.dae")%name); @@ -1271,6 +1331,13 @@ namespace urdf{ if( !!peffect ) { domProfile_common::domTechnique::domPhongRef pphong = daeSafeCast(peffect->getDescendant(daeElement::matchType(domProfile_common::domTechnique::domPhong::ID()))); if( !!pphong ) { + if( !!pphong->getEmission() && !!pphong->getEmission()->getColor() ) { + domFx_color c = pphong->getEmission()->getColor()->getValue(); + geom.emissionColor.r = c[0]; + geom.emissionColor.g = c[1]; + geom.emissionColor.b = c[2]; + geom.emissionColor.a = c[3]; + } if( !!pphong->getAmbient() && !!pphong->getAmbient()->getColor() ) { domFx_color c = pphong->getAmbient()->getColor()->getValue(); geom.ambientColor.r = c[0]; @@ -1285,6 +1352,13 @@ namespace urdf{ geom.diffuseColor.b = c[2]; geom.diffuseColor.a = c[3]; } + if( !!pphong->getSpecular() && !!pphong->getSpecular()->getColor() ) { + domFx_color c = pphong->getSpecular()->getColor()->getValue(); + geom.specularColor.r = c[0]; + geom.specularColor.g = c[1]; + geom.specularColor.b = c[2]; + geom.specularColor.a = c[3]; + } } } }