From 1642af2b54f44d4fff3ad3271f8aa318af5ffad2 Mon Sep 17 00:00:00 2001 From: tfield Date: Tue, 9 Mar 2010 06:52:07 +0000 Subject: [PATCH] collada_urdf: fixed position_array --- collada_urdf/src/urdf_to_collada.cpp | 78 ++++++++++++++-------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/collada_urdf/src/urdf_to_collada.cpp b/collada_urdf/src/urdf_to_collada.cpp index 3b20da6..02c69f8 100644 --- a/collada_urdf/src/urdf_to_collada.cpp +++ b/collada_urdf/src/urdf_to_collada.cpp @@ -36,11 +36,6 @@ // urdf_to_collada.cpp -/* -Issues: - - triangles material hard-coded to "mat0" -*/ - #include #include #include @@ -349,7 +344,7 @@ public: unsigned int num_vertices = stl_mesh->vertices.size(); unsigned int num_indices = stl_mesh->indices.size(); unsigned int num_faces = num_indices / 3; - + // domSourceRef positions_source = daeSafeCast(mesh->createAndPlace(COLLADA_ELEMENT_SOURCE)); positions_source->setId((geometry_id + string(".positions")).c_str()); @@ -357,62 +352,67 @@ public: // domFloat_arrayRef positions_array = daeSafeCast(positions_source->createAndPlace(COLLADA_ELEMENT_FLOAT_ARRAY)); 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->getValue().setCount(num_vertices); - + positions_array->getValue().setCount(num_vertices * 3); for (unsigned int j = 0; j < num_vertices; j++) { - positions_array->getValue()[j] = stl_mesh->vertices[j].x; - positions_array->getValue()[j] = stl_mesh->vertices[j].y; - positions_array->getValue()[j] = stl_mesh->vertices[j].z; + positions_array->getValue()[j * 3 ] = stl_mesh->vertices[j].x; + positions_array->getValue()[j * 3 + 1] = stl_mesh->vertices[j].y; + positions_array->getValue()[j * 3 + 2] = stl_mesh->vertices[j].z; } + // // domSource::domTechnique_commonRef source_tech = daeSafeCast(positions_source->createAndPlace(COLLADA_ELEMENT_TECHNIQUE_COMMON)); - - // - domAccessorRef accessor = daeSafeCast(source_tech->createAndPlace(COLLADA_ELEMENT_ACCESSOR)); - accessor->setCount(num_vertices); - accessor->setSource(xsAnyURI(*positions_array, string("#") + geometry_id + string(".positions-array"))); - accessor->setStride(3); - - // - // - // - domParamRef px = daeSafeCast(accessor->createAndPlace(COLLADA_ELEMENT_PARAM)); px->setName("X"); px->setType("float"); - domParamRef py = daeSafeCast(accessor->createAndPlace(COLLADA_ELEMENT_PARAM)); py->setName("Y"); py->setType("float"); - domParamRef pz = daeSafeCast(accessor->createAndPlace(COLLADA_ELEMENT_PARAM)); pz->setName("Z"); pz->setType("float"); + { + // + domAccessorRef accessor = daeSafeCast(source_tech->createAndPlace(COLLADA_ELEMENT_ACCESSOR)); + accessor->setCount(num_vertices / 3); + accessor->setSource(xsAnyURI(*positions_array, string("#") + geometry_id + string(".positions-array"))); + accessor->setStride(3); + { + // + // + // + domParamRef px = daeSafeCast(accessor->createAndPlace(COLLADA_ELEMENT_PARAM)); px->setName("X"); px->setType("float"); + domParamRef py = daeSafeCast(accessor->createAndPlace(COLLADA_ELEMENT_PARAM)); py->setName("Y"); py->setType("float"); + domParamRef pz = daeSafeCast(accessor->createAndPlace(COLLADA_ELEMENT_PARAM)); pz->setName("Z"); pz->setType("float"); + } + // + } + // } // domVerticesRef vertices = daeSafeCast(mesh->createAndPlace(COLLADA_ELEMENT_VERTICES)); - vertices->setId("vertices"); + string vertices_id = geometry_id + string(".vertices"); + vertices->setId(vertices_id.c_str()); { // domInput_localRef vertices_input = daeSafeCast(vertices->createAndPlace(COLLADA_ELEMENT_INPUT)); 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()))); } // - + // domTrianglesRef triangles = daeSafeCast(mesh->createAndPlace(COLLADA_ELEMENT_TRIANGLES)); + triangles->setCount(num_faces); + triangles->setMaterial("mat0"); { - triangles->setCount(num_faces); - triangles->setMaterial("mat0"); - // domInput_local_offsetRef vertex_offset = daeSafeCast(triangles->createAndPlace(COLLADA_ELEMENT_INPUT)); vertex_offset->setSemantic("VERTEX"); vertex_offset->setOffset(0); - vertex_offset->setSource(domUrifragment(*positions_source, string("#") + geometry_id + string("/vertices"))); - - //

0 1 2 3 ... - domPRef indices = daeSafeCast(triangles->createAndPlace(COLLADA_ELEMENT_P)); - indices->getValue().setCount(num_indices); - for (unsigned int i = 0; i < num_indices; i++) - indices->getValue()[i] = stl_mesh->indices[i]; - //

+ vertex_offset->setSource(domUrifragment(*positions_source, string("#") + vertices_id)); + { + //

0 1 2 3 ... + domPRef indices = daeSafeCast(triangles->createAndPlace(COLLADA_ELEMENT_P)); + indices->getValue().setCount(num_indices); + for (unsigned int i = 0; i < num_indices; i++) + indices->getValue()[i] = stl_mesh->indices[i]; + //

+ } } //
}