コード例 #1
0
        // TODO
        /// <summary>
        /// <para>CreateVisualGeometry</para>
        /// Parses a ROS link and creates a MeshInstance for the visual
        /// geometry specified in that link.
        /// </summary>
        /// <param name="visuals">List of visuals stored in the Urdf link.</param>
        /// <returns>
        /// <para>
        /// A mesh containing the accurate visual geometry of the link if no error.
        /// <para>
        /// <para>
        /// Null if there was an error.
        /// </para></returns>
        public Godot.Mesh CreateVisualGeometry(List <Link.Visual> visuals)
        {
            // The union of the geometries defined in the list define
            // the end visual of the link, but for now we will just use
            // the first one
            if (visuals.Count < 1)
            {
                return(null);
            }

            Link.Visual workingVis = visuals[0];

            // Create the material if it exists
            SpatialMaterial linkMat = CreateMaterial(workingVis.material);

            // Create the meshs
            if (workingVis.geometry.box != null)
            {
                return(CreateBox(workingVis.geometry.box, linkMat));
            }
            if (workingVis.geometry.cylinder != null)
            {
                return(CreateCylinder(workingVis.geometry.cylinder, linkMat));
            }
            if (workingVis.geometry.sphere != null)
            {
                return(CreateSphere(workingVis.geometry.sphere, linkMat));
            }
            if (workingVis.geometry.mesh != null)
            {
                return(CreateMesh(workingVis.geometry.mesh).Mesh);
            }
            return(null);
        }
コード例 #2
0
ファイル: ParseUrdfTests.cs プロジェクト: b2220333/unity_ros2
        public void _Reads_Visual_Origins()
        {
            robot.ConstructFromString(urdfString);

            Link sensorLink = robot.links.Find(link => link.name == "sensor_link");

            Link.Visual visual = sensorLink.visuals[0];
            Origin      origin = visual.origin;

            Assert.That(origin.Xyz, Is.EqualTo(new[] { 0.1d, 0.2d, 0.3d }));
            Assert.That(origin.Rpy, Is.EqualTo(new[] { 0.4d, 0.5d, 0.6d }));
        }
コード例 #3
0
        public static void Create(Transform parent, Link.Visual visual)
        {
            GameObject visualObject = new GameObject(visual.name ?? "unnamed");

            visualObject.transform.SetParentAndAlign(parent);
            UrdfVisual urdfVisual = visualObject.AddComponent <UrdfVisual>();

            urdfVisual.GeometryType = UrdfGeometry.GetGeometryType(visual.geometry);
            UrdfGeometryVisual.Create(visualObject.transform, urdfVisual.GeometryType, visual.geometry);

            UrdfMaterial.SetUrdfMaterial(visualObject, visual.material);
            UrdfOrigin.ImportOriginData(visualObject.transform, visual.origin);
        }
コード例 #4
0
        /// <summary>
        /// Compares visual information of two links
        /// </summary>
        /// <param name="source">First link's visual information to be compared</param>
        /// <param name="exported">Second link's visual information to be compared</param>
        /// <param name="indent">Indent level in the log file</param>
        /// <returns></returns>
        private bool CompareVisual(Link.Visual source, Link.Visual exported, int indent)
        {
            bool visualNameEqual = (source.name == exported.name);

            linkLog.AppendLine(String.Format("{0}Visual Component Name : {1,6}", Indent(indent + 1), visualNameEqual));
            if (!visualNameEqual)
            {
                return(false);
            }

            if (!CompareOrigin(source.origin, exported.origin, indent))
            {
                return(false);
            }

            linkLog.AppendLine(String.Format("{0}Geometry Checks", Indent(indent)));
            if (!CompareGeometry(source.geometry, exported.geometry, indent + 1))
            {
                return(false);
            }

            linkLog.AppendLine(String.Format("{0}Material Checks", Indent(indent)));
            if (source.material == null && exported.material == null)
            {
                linkLog.AppendLine(String.Format("{0}Material Nullity Check: {1,6}", Indent(indent), "True"));
                return(true);
            }
            else if (source.material != null && exported.material != null)
            {
                linkLog.AppendLine(String.Format("{0}Material Nullity Check: {1,6}", Indent(indent), "True"));
                if (!CompareMaterial(source.material, exported.material, indent + 1))
                {
                    return(false);
                }
            }
            else if ((source.material == null && exported.material.name == "Default-Material") || (exported.material == null && source.material?.name == "Default-Material"))
            {
                linkLog.AppendLine(String.Format("{0}Material Nullity Check: {1,6}", Indent(indent), "True"));
                return(true);
            }
            else
            {
                linkLog.AppendLine(String.Format("{0}Material Nullity Check: {1,6}", Indent(indent), "False"));
                return(false);
            }

            return(true);
        }
コード例 #5
0
        public static void Create(Transform parent, Link.Visual visual)
        {
            if (String.IsNullOrEmpty(visual.name))
            {
                visual.name = visual.GenerateNonReferenceID();
            }

            if (parent.FindChildOrCreateWithComponent <UrdfVisual>(visual.name, out GameObject visualObject, out UrdfVisual urdfVisual))
            {
                //only create these visuals if the gameobject had to be created itself
                urdfVisual.GeometryType = UrdfGeometry.GetGeometryType(visual.geometry);
                UrdfGeometryVisual.Create(visualObject.transform, urdfVisual.GeometryType, visual.geometry);
            }

            //update these values every time
            UrdfMaterial.SetUrdfMaterial(visualObject, visual.material);
            UrdfOrigin.ImportOriginData(visualObject.transform, visual.origin);
        }