collada_urdf: fixed position_array
This commit is contained in:
parent
642c69eabb
commit
1642af2b54
|
@ -36,11 +36,6 @@
|
||||||
|
|
||||||
// urdf_to_collada.cpp
|
// urdf_to_collada.cpp
|
||||||
|
|
||||||
/*
|
|
||||||
Issues:
|
|
||||||
- triangles material hard-coded to "mat0"
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <dae.h>
|
#include <dae.h>
|
||||||
#include <dae/daeErrorHandler.h>
|
#include <dae/daeErrorHandler.h>
|
||||||
#include <dom/domCOLLADA.h>
|
#include <dom/domCOLLADA.h>
|
||||||
|
@ -357,25 +352,25 @@ public:
|
||||||
// <float_array id="g1.link0.geom0.positions-array" count="4533" digits="6">
|
// <float_array id="g1.link0.geom0.positions-array" count="4533" digits="6">
|
||||||
domFloat_arrayRef positions_array = daeSafeCast<domFloat_array>(positions_source->createAndPlace(COLLADA_ELEMENT_FLOAT_ARRAY));
|
domFloat_arrayRef positions_array = daeSafeCast<domFloat_array>(positions_source->createAndPlace(COLLADA_ELEMENT_FLOAT_ARRAY));
|
||||||
positions_array->setId((geometry_id + string(".positions-array")).c_str());
|
positions_array->setId((geometry_id + string(".positions-array")).c_str());
|
||||||
positions_array->setCount(num_vertices);
|
positions_array->setCount(num_vertices * 3);
|
||||||
positions_array->setDigits(6); // 6 decimal places
|
positions_array->setDigits(6); // 6 decimal places
|
||||||
positions_array->getValue().setCount(num_vertices);
|
positions_array->getValue().setCount(num_vertices * 3);
|
||||||
|
|
||||||
for (unsigned int j = 0; j < num_vertices; j++) {
|
for (unsigned int j = 0; j < num_vertices; j++) {
|
||||||
positions_array->getValue()[j] = stl_mesh->vertices[j].x;
|
positions_array->getValue()[j * 3 ] = stl_mesh->vertices[j].x;
|
||||||
positions_array->getValue()[j] = stl_mesh->vertices[j].y;
|
positions_array->getValue()[j * 3 + 1] = stl_mesh->vertices[j].y;
|
||||||
positions_array->getValue()[j] = stl_mesh->vertices[j].z;
|
positions_array->getValue()[j * 3 + 2] = stl_mesh->vertices[j].z;
|
||||||
}
|
}
|
||||||
|
// </float_array>
|
||||||
|
|
||||||
// <technique_common>
|
// <technique_common>
|
||||||
domSource::domTechnique_commonRef source_tech = daeSafeCast<domSource::domTechnique_common>(positions_source->createAndPlace(COLLADA_ELEMENT_TECHNIQUE_COMMON));
|
domSource::domTechnique_commonRef source_tech = daeSafeCast<domSource::domTechnique_common>(positions_source->createAndPlace(COLLADA_ELEMENT_TECHNIQUE_COMMON));
|
||||||
|
{
|
||||||
// <accessor count="4533" source="#g1.link0.geom0.positions-array" stride="3">
|
// <accessor count="4533" source="#g1.link0.geom0.positions-array" stride="3">
|
||||||
domAccessorRef accessor = daeSafeCast<domAccessor>(source_tech->createAndPlace(COLLADA_ELEMENT_ACCESSOR));
|
domAccessorRef accessor = daeSafeCast<domAccessor>(source_tech->createAndPlace(COLLADA_ELEMENT_ACCESSOR));
|
||||||
accessor->setCount(num_vertices);
|
accessor->setCount(num_vertices / 3);
|
||||||
accessor->setSource(xsAnyURI(*positions_array, string("#") + geometry_id + string(".positions-array")));
|
accessor->setSource(xsAnyURI(*positions_array, string("#") + geometry_id + string(".positions-array")));
|
||||||
accessor->setStride(3);
|
accessor->setStride(3);
|
||||||
|
{
|
||||||
// <param name="X" type="float"/>
|
// <param name="X" type="float"/>
|
||||||
// <param name="Y" type="float"/>
|
// <param name="Y" type="float"/>
|
||||||
// <param name="Z" type="float"/>
|
// <param name="Z" type="float"/>
|
||||||
|
@ -383,30 +378,34 @@ public:
|
||||||
domParamRef py = daeSafeCast<domParam>(accessor->createAndPlace(COLLADA_ELEMENT_PARAM)); py->setName("Y"); py->setType("float");
|
domParamRef py = daeSafeCast<domParam>(accessor->createAndPlace(COLLADA_ELEMENT_PARAM)); py->setName("Y"); py->setType("float");
|
||||||
domParamRef pz = daeSafeCast<domParam>(accessor->createAndPlace(COLLADA_ELEMENT_PARAM)); pz->setName("Z"); pz->setType("float");
|
domParamRef pz = daeSafeCast<domParam>(accessor->createAndPlace(COLLADA_ELEMENT_PARAM)); pz->setName("Z"); pz->setType("float");
|
||||||
}
|
}
|
||||||
|
// </accessor>
|
||||||
|
}
|
||||||
|
// </technique_common>
|
||||||
|
}
|
||||||
|
|
||||||
// <vertices id="vertices">
|
// <vertices id="vertices">
|
||||||
domVerticesRef vertices = daeSafeCast<domVertices>(mesh->createAndPlace(COLLADA_ELEMENT_VERTICES));
|
domVerticesRef vertices = daeSafeCast<domVertices>(mesh->createAndPlace(COLLADA_ELEMENT_VERTICES));
|
||||||
vertices->setId("vertices");
|
string vertices_id = geometry_id + string(".vertices");
|
||||||
|
vertices->setId(vertices_id.c_str());
|
||||||
{
|
{
|
||||||
// <input semantic="POSITION" source="#g1.link0.geom0.positions"/>
|
// <input semantic="POSITION" source="#g1.link0.geom0.positions"/>
|
||||||
domInput_localRef vertices_input = daeSafeCast<domInput_local>(vertices->createAndPlace(COLLADA_ELEMENT_INPUT));
|
domInput_localRef vertices_input = daeSafeCast<domInput_local>(vertices->createAndPlace(COLLADA_ELEMENT_INPUT));
|
||||||
vertices_input->setSemantic("POSITION");
|
vertices_input->setSemantic("POSITION");
|
||||||
vertices_input->setSource(domUrifragment(*positions_source, string("#") + geometry_id + string(".positions")));
|
vertices_input->setSource(domUrifragment(*positions_source, string("#") + string(positions_source->getId())));
|
||||||
}
|
}
|
||||||
// </vertices>
|
// </vertices>
|
||||||
|
|
||||||
// <triangles count="1511" material="mat0">
|
// <triangles count="1511" material="mat0">
|
||||||
domTrianglesRef triangles = daeSafeCast<domTriangles>(mesh->createAndPlace(COLLADA_ELEMENT_TRIANGLES));
|
domTrianglesRef triangles = daeSafeCast<domTriangles>(mesh->createAndPlace(COLLADA_ELEMENT_TRIANGLES));
|
||||||
{
|
|
||||||
triangles->setCount(num_faces);
|
triangles->setCount(num_faces);
|
||||||
triangles->setMaterial("mat0");
|
triangles->setMaterial("mat0");
|
||||||
|
{
|
||||||
// <input offset="0" semantic="VERTEX" source="#g1.link0.geom0/vertices" set="0"/>
|
// <input offset="0" semantic="VERTEX" source="#g1.link0.geom0/vertices" set="0"/>
|
||||||
domInput_local_offsetRef vertex_offset = daeSafeCast<domInput_local_offset>(triangles->createAndPlace(COLLADA_ELEMENT_INPUT));
|
domInput_local_offsetRef vertex_offset = daeSafeCast<domInput_local_offset>(triangles->createAndPlace(COLLADA_ELEMENT_INPUT));
|
||||||
vertex_offset->setSemantic("VERTEX");
|
vertex_offset->setSemantic("VERTEX");
|
||||||
vertex_offset->setOffset(0);
|
vertex_offset->setOffset(0);
|
||||||
vertex_offset->setSource(domUrifragment(*positions_source, string("#") + geometry_id + string("/vertices")));
|
vertex_offset->setSource(domUrifragment(*positions_source, string("#") + vertices_id));
|
||||||
|
{
|
||||||
// <p>0 1 2 3 ...
|
// <p>0 1 2 3 ...
|
||||||
domPRef indices = daeSafeCast<domP>(triangles->createAndPlace(COLLADA_ELEMENT_P));
|
domPRef indices = daeSafeCast<domP>(triangles->createAndPlace(COLLADA_ELEMENT_P));
|
||||||
indices->getValue().setCount(num_indices);
|
indices->getValue().setCount(num_indices);
|
||||||
|
@ -414,6 +413,7 @@ public:
|
||||||
indices->getValue()[i] = stl_mesh->indices[i];
|
indices->getValue()[i] = stl_mesh->indices[i];
|
||||||
// </p>
|
// </p>
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// </triangles>
|
// </triangles>
|
||||||
}
|
}
|
||||||
// </mesh>
|
// </mesh>
|
||||||
|
|
Loading…
Reference in New Issue