public RobotLink(string link_name, UrdfJoint urdf_joint, JointStateWriter joint_writer, JointStateReader joint_reader, Dictionary <UrdfVisual, bool> visuals_gameObject = null, Dictionary <UrdfCollision, bool> collisions_gameObject = null, bool is_base_link = false, float scale = 1f) { LinkName = link_name; UrdfJoint = urdf_joint; jointWriter = joint_writer; jointReader = joint_reader; Visuals = visuals_gameObject ?? new Dictionary <UrdfVisual, bool>(); Collisions = collisions_gameObject ?? new Dictionary <UrdfCollision, bool>(); IsBaseLink = is_base_link; LinkScale = scale; }
/// <summary> /// Initializes RobotLinks and sets a boolean to its Visuals dictionary, /// telling whether the model of individual visual was already imported (is type of box, cylinder, capsule) /// or not yet (is mesh - is going to be continually imported from UrdfAssetImporterRuntime). /// </summary> /// <param name="copyOfRobotModel">If set to true, robotModel is being copied from another robotModel, it assumed, that Visuals of every Link are already imported.</param> public void LoadLinks(bool copyOfRobotModel = false) { // Get all UrdfLink components in builded Robot foreach (UrdfLink link in RobotModelGameObject.GetComponentsInChildren <UrdfLink>()) { // Get all UrdfVisuals of each UrdfLink GameObject visualsGameObject = link.gameObject.GetComponentInChildren <UrdfVisuals>().gameObject; Dictionary <UrdfVisual, bool> visuals = new Dictionary <UrdfVisual, bool>(); float scale = 1f; // Traverse each UrdfVisual and set a boolean indicating whether its visual is already loaded (is of some basic type - box, cylinder, capsule) // or is going to be loaded by ColladaImporter (in case its type of mesh) foreach (UrdfVisual visual in visualsGameObject.GetComponentsInChildren <UrdfVisual>()) { visuals.Add(visual, copyOfRobotModel ? true : (visual.GeometryType == GeometryTypes.Mesh ? false : true)); // hide visual if it is mesh.. mesh will be displayed when fully loaded visual.gameObject.SetActive(copyOfRobotModel ? true : (visual.GeometryType == GeometryTypes.Mesh ? false : true)); // get scale of urdfVisual and each of its child foreach (Transform child in visual.GetComponentsInChildren <Transform>()) { scale *= child.localScale.x; } } UrdfJoint urdfJoint = link.GetComponent <UrdfJoint>(); JointStateWriter jointWriter = null; JointStateReader jointReader = null; if (urdfJoint != null) { if (urdfJoint.JointType != UrdfJoint.JointTypes.Fixed) { jointWriter = urdfJoint.transform.AddComponentIfNotExists <JointStateWriter>(); Joints.Add(urdfJoint.JointName, link.gameObject.name); } jointReader = urdfJoint.transform.AddComponentIfNotExists <JointStateReader>(); } Links.Add(link.gameObject.name, new RobotLink(link.gameObject.name, urdfJoint, jointWriter, jointReader, visuals_gameObject: visuals, is_base_link: link.IsBaseLink, scale: scale)); } }