diff --git a/collada_urdf/src/urdf_to_collada.cpp b/collada_urdf/src/urdf_to_collada.cpp index fe1b4f6..2afc41b 100644 --- a/collada_urdf/src/urdf_to_collada.cpp +++ b/collada_urdf/src/urdf_to_collada.cpp @@ -103,6 +103,9 @@ public: domLibrary_effectsRef effectsLib_; //domLibrary_articulated_systemsRef articulatedSystemsLib_; + map geometry_ids_; // link.name -> geometry.id + map joint_ids_; // joint.name -> joint.sid + public: ColladaWriter(urdf::Model* robot) : robot_(robot) { daeErrorHandler::setErrorHandler(this); @@ -291,6 +294,7 @@ public: { loadMesh(filename, geometry, geometry_id); } + geometry_ids_[urdf_link->name] = geometry_id; // link_num++; @@ -528,79 +532,109 @@ public: for (map >::const_iterator i = robot_->joints_.begin(); i != robot_->joints_.end(); i++) { boost::shared_ptr urdf_joint = i->second; - // Create COLLADA joint + // domJointRef joint = daeSafeCast(jointsLib_->createAndPlace(COLLADA_ELEMENT_JOINT)); - joint->setId(urdf_joint->name.c_str()); joint->setName(urdf_joint->name.c_str()); - switch (urdf_joint->type) { case urdf::Joint::REVOLUTE: { - // joint.axis - vector axes(1); - axes[0] = daeSafeCast(joint->createAndPlace(COLLADA_ELEMENT_REVOLUTE)); - axes[0]->setSid("axis0"); - domAxisRef axis = daeSafeCast(axes[0]->createAndPlace(COLLADA_ELEMENT_AXIS)); - axis->getValue().setCount(3); - axis->getValue()[0] = urdf_joint->axis.x; - axis->getValue()[1] = urdf_joint->axis.y; - axis->getValue()[2] = urdf_joint->axis.z; + // + domAxis_constraintRef revolute = daeSafeCast(joint->createAndPlace(COLLADA_ELEMENT_REVOLUTE)); + revolute->setSid("axis0"); + { + // + domAxisRef axis = daeSafeCast(revolute->createAndPlace(COLLADA_ELEMENT_AXIS)); + { + axis->getValue().setCount(3); + axis->getValue()[0] = urdf_joint->axis.x; + axis->getValue()[1] = urdf_joint->axis.y; + axis->getValue()[2] = urdf_joint->axis.z; + } + // - // joint.limits - domJoint_limitsRef limits = daeSafeCast(axes[0]->createAndPlace(COLLADA_TYPE_LIMITS)); - daeSafeCast(limits->createAndPlace(COLLADA_ELEMENT_MIN))->getValue() = urdf_joint->limits->lower; - daeSafeCast(limits->createAndPlace(COLLADA_ELEMENT_MAX))->getValue() = urdf_joint->limits->upper; + // + domJoint_limitsRef limits = daeSafeCast(revolute->createAndPlace(COLLADA_TYPE_LIMITS)); + { + daeSafeCast(limits->createAndPlace(COLLADA_ELEMENT_MIN))->getValue() = urdf_joint->limits->lower; + daeSafeCast(limits->createAndPlace(COLLADA_ELEMENT_MAX))->getValue() = urdf_joint->limits->upper; + } + // + } + // break; } case urdf::Joint::CONTINUOUS: { // Model as a REVOLUTE joint without limits - // joint.axis - vector axes(1); - axes[0] = daeSafeCast(joint->createAndPlace(COLLADA_ELEMENT_REVOLUTE)); - axes[0]->setSid("axis0"); - domAxisRef axis = daeSafeCast(axes[0]->createAndPlace(COLLADA_ELEMENT_AXIS)); - axis->getValue().setCount(3); - axis->getValue()[0] = urdf_joint->axis.x; - axis->getValue()[1] = urdf_joint->axis.y; - axis->getValue()[2] = urdf_joint->axis.z; + // + domAxis_constraintRef revolute = daeSafeCast(joint->createAndPlace(COLLADA_ELEMENT_REVOLUTE)); + revolute->setSid("axis0"); + { + // + domAxisRef axis = daeSafeCast(revolute->createAndPlace(COLLADA_ELEMENT_AXIS)); + { + axis->getValue().setCount(3); + axis->getValue()[0] = urdf_joint->axis.x; + axis->getValue()[1] = urdf_joint->axis.y; + axis->getValue()[2] = urdf_joint->axis.z; + } + // + } + // break; } case urdf::Joint::PRISMATIC: { - // joint.axis - vector axes(1); - axes[0] = daeSafeCast(joint->createAndPlace(COLLADA_ELEMENT_PRISMATIC)); - axes[0]->setSid("axis0"); - domAxisRef axis = daeSafeCast(axes[0]->createAndPlace(COLLADA_ELEMENT_AXIS)); - axis->getValue().setCount(3); - axis->getValue()[0] = urdf_joint->axis.x; - axis->getValue()[1] = urdf_joint->axis.y; - axis->getValue()[2] = urdf_joint->axis.z; - - // joint.limits - domJoint_limitsRef limits = daeSafeCast(axes[0]->createAndPlace(COLLADA_TYPE_LIMITS)); - daeSafeCast(limits->createAndPlace(COLLADA_ELEMENT_MIN))->getValue() = urdf_joint->limits->lower; - daeSafeCast(limits->createAndPlace(COLLADA_ELEMENT_MAX))->getValue() = urdf_joint->limits->upper; + // + domAxis_constraintRef prismatic = daeSafeCast(joint->createAndPlace(COLLADA_ELEMENT_PRISMATIC)); + prismatic->setSid("axis0"); + { + // + domAxisRef axis = daeSafeCast(prismatic->createAndPlace(COLLADA_ELEMENT_AXIS)); + { + axis->getValue().setCount(3); + axis->getValue()[0] = urdf_joint->axis.x; + axis->getValue()[1] = urdf_joint->axis.y; + axis->getValue()[2] = urdf_joint->axis.z; + } + // + + // + domJoint_limitsRef limits = daeSafeCast(prismatic->createAndPlace(COLLADA_TYPE_LIMITS)); + { + daeSafeCast(limits->createAndPlace(COLLADA_ELEMENT_MIN))->getValue() = urdf_joint->limits->lower; + daeSafeCast(limits->createAndPlace(COLLADA_ELEMENT_MAX))->getValue() = urdf_joint->limits->upper; + } + // + } + // break; } case urdf::Joint::FIXED: { // Model as a REVOLUTE joint with no leeway - // joint.axis - vector axes(1); - axes[0] = daeSafeCast(joint->createAndPlace(COLLADA_ELEMENT_REVOLUTE)); - axes[0]->setSid("axis0"); - domAxisRef axis = daeSafeCast(axes[0]->createAndPlace(COLLADA_ELEMENT_AXIS)); - axis->getValue().setCount(3); - axis->getValue()[0] = urdf_joint->axis.x; - axis->getValue()[1] = urdf_joint->axis.y; - axis->getValue()[2] = urdf_joint->axis.z; - - // joint.limits - domJoint_limitsRef limits = daeSafeCast(axes[0]->createAndPlace(COLLADA_TYPE_LIMITS)); - daeSafeCast(limits->createAndPlace(COLLADA_ELEMENT_MIN))->getValue() = 0.0; - daeSafeCast(limits->createAndPlace(COLLADA_ELEMENT_MAX))->getValue() = 0.0; + domAxis_constraintRef revolute = daeSafeCast(joint->createAndPlace(COLLADA_ELEMENT_REVOLUTE)); + revolute->setSid("axis0"); + { + // + domAxisRef axis = daeSafeCast(revolute->createAndPlace(COLLADA_ELEMENT_AXIS)); + { + axis->getValue().setCount(3); + axis->getValue()[0] = urdf_joint->axis.x; + axis->getValue()[1] = urdf_joint->axis.y; + axis->getValue()[2] = urdf_joint->axis.z; + } + // + + // + domJoint_limitsRef limits = daeSafeCast(revolute->createAndPlace(COLLADA_TYPE_LIMITS)); + { + daeSafeCast(limits->createAndPlace(COLLADA_ELEMENT_MIN))->getValue() = 0.0; + daeSafeCast(limits->createAndPlace(COLLADA_ELEMENT_MAX))->getValue() = 0.0; + } + // + } + // break; } case urdf::Joint::UNKNOWN: { @@ -699,14 +733,22 @@ public: // x y z angle domRotateRef joint_rotate = addRotate(node, urdf_link->parent_joint->parent_to_joint_origin_transform.rotation); - joint_rotate->setSid("node_joint0_axis0"); + joint_rotate->setSid("node_joint0_axis0"); // @todo use joint_num } - - for (vector >::const_iterator i = urdf_link->child_links.begin(); i != urdf_link->child_links.end(); i++) { - boost::shared_ptr urdf_child_link = *i; - addVisualLink(urdf_child_link, node, link_num); + // + domInstance_geometryRef instance_geometry = daeSafeCast(node->createAndPlace(COLLADA_ELEMENT_INSTANCE_GEOMETRY)); + instance_geometry->setUrl("#g1.link0.geom"); // @todo use link_num + { + // @todo + // @todo + // @todo } + + // + for (vector >::const_iterator i = urdf_link->child_links.begin(); i != urdf_link->child_links.end(); i++) + addVisualLink(*i, node, link_num); + // } // }