protected static void SetScale(Transform transform, Link.Geometry geometry, GeometryTypes geometryType)
        {
            switch (geometryType)
            {
            case GeometryTypes.Box:
                transform.localScale =
                    new Vector3((float)geometry.box.size[1], (float)geometry.box.size[2], (float)geometry.box.size[0]);
                break;

            case GeometryTypes.Cylinder:
                transform.localScale = new Vector3(
                    (float)geometry.cylinder.radius * 2,
                    (float)geometry.cylinder.length / 2,
                    (float)geometry.cylinder.radius * 2);
                break;

            case GeometryTypes.Sphere:
                transform.localScale = new Vector3(
                    (float)geometry.sphere.radius * 2,
                    (float)geometry.sphere.radius * 2,
                    (float)geometry.sphere.radius * 2);
                break;

            case GeometryTypes.Mesh:
                if (geometry?.mesh?.scale != null)
                {
                    Vector3 scale = geometry.mesh.scale.ToVector3().Ros2UnityScale();

                    transform.localScale    = Vector3.Scale(transform.localScale, scale);
                    transform.localPosition = Vector3.Scale(transform.localPosition, scale);
                }
                break;
            }
        }
        public static Link.Geometry ExportGeometryData(GeometryTypes geometryType, Transform transform, bool isCollisionGeometry = false)
        {
            Link.Geometry geometry = null;
            switch (geometryType)
            {
            case GeometryTypes.Box:
                geometry = new Link.Geometry(new Link.Geometry.Box(ExportUrdfSize(transform)));
                break;

            case GeometryTypes.Cylinder:
                geometry = new Link.Geometry(
                    null,
                    new Link.Geometry.Cylinder(ExportUrdfRadius(transform), ExportCylinderHeight(transform)));
                break;

            case GeometryTypes.Sphere:
                geometry = new Link.Geometry(null, null, new Link.Geometry.Sphere(ExportUrdfRadius(transform)));
                break;

            case GeometryTypes.Mesh:
                geometry = ExportGeometryMeshData(transform.GetChild(0).gameObject, ExportUrdfSize(transform), isCollisionGeometry);
                break;
            }

            return(geometry);
        }
Beispiel #3
0
        public Link.Collision ExportCollisionData()
        {
            CheckForUrdfCompatibility();

            Link.Geometry geometry      = UrdfGeometry.ExportGeometryData(geometryType, transform, true);
            string        collisionName = gameObject.name == "unnamed" ? null : gameObject.name;

            return(new Link.Collision(geometry, collisionName, UrdfOrigin.ExportOriginData(transform)));
        }
        public Link.Visual ExportVisualData()
        {
            CheckForUrdfCompatibility();

            Link.Geometry geometry = UrdfGeometry.ExportGeometryData(geometryType, transform);

            Link.Visual.Material material = null;
            if (!(geometry.mesh != null && geometry.mesh.filename.ToLower().EndsWith(".dae"))) //Collada files contain their own materials
            {
                material = UrdfMaterial.ExportMaterialData(gameObject.GetComponentInChildren <MeshRenderer>().sharedMaterial);
            }

            string visualName = gameObject.name == "unnamed" ? null : gameObject.name;

            return(new Link.Visual(geometry, visualName, UrdfOrigin.ExportOriginData(transform), material));
        }
        public static GeometryTypes GetGeometryType(Link.Geometry geometry)
        {
            if (geometry.box != null)
            {
                return(GeometryTypes.Box);
            }
            if (geometry.cylinder != null)
            {
                return(GeometryTypes.Cylinder);
            }
            if (geometry.sphere != null)
            {
                return(GeometryTypes.Sphere);
            }

            return(GeometryTypes.Mesh);
        }
        public static void Create(Transform parent, GeometryTypes geometryType, Link.Geometry geometry = null)
        {
            GameObject geometryGameObject = null;

            switch (geometryType)
            {
            case GeometryTypes.Box:
                geometryGameObject = new GameObject(geometryType.ToString());
                geometryGameObject.AddComponent <BoxCollider>();
                break;

            case GeometryTypes.Cylinder:
                geometryGameObject = CreateCylinderCollider();
                break;

            case GeometryTypes.Sphere:
                geometryGameObject = new GameObject(geometryType.ToString());
                geometryGameObject.AddComponent <SphereCollider>();
                break;

            case GeometryTypes.Mesh:
                if (geometry != null)
                {
                    geometryGameObject = CreateMeshCollider(geometry.mesh);
                }
                else
                {
                    geometryGameObject = new GameObject(geometryType.ToString());
                    geometryGameObject.AddComponent <MeshCollider>();
                }
                break;
            }

            if (geometryGameObject != null)
            {
                geometryGameObject.transform.SetParentAndAlign(parent);
                if (geometry != null)
                {
                    SetScale(parent, geometry, geometryType);
                }
            }
        }
Beispiel #7
0
        public static void Create(Transform parent, GeometryTypes geometryType, Link.Geometry geometry = null)
        {
            GameObject geometryGameObject = null;

            switch (geometryType)
            {
            case GeometryTypes.Box:
                geometryGameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
                geometryGameObject.transform.DestroyImmediateIfExists <BoxCollider>();
                break;

            case GeometryTypes.Cylinder:
                geometryGameObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
                geometryGameObject.transform.DestroyImmediateIfExists <CapsuleCollider>();
                break;

            case GeometryTypes.Sphere:
                geometryGameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                geometryGameObject.transform.DestroyImmediateIfExists <SphereCollider>();
                break;

            case GeometryTypes.Mesh:
                if (geometry != null)
                {
                    geometryGameObject = CreateMeshVisual(geometry.mesh);
                }
                //else, let user add their own mesh gameObject
                break;
            }

            if (geometryGameObject != null)
            {
                geometryGameObject.transform.SetParentAndAlign(parent);
                if (geometry != null)
                {
                    SetScale(parent, geometry, geometryType);
                }
            }
        }