Example #1
0
        private static Material CreateMaterial(this Link.Visual.Material urdfMaterial)
        {
            if (urdfMaterial.name == "")
            {
                urdfMaterial.name = GenerateMaterialName(urdfMaterial);
            }

            var material = AssetDatabase.LoadAssetAtPath <Material>(UrdfAssetPathHandler.GetMaterialAssetPath(urdfMaterial.name));

            if (material != null) //material already exists
            {
                return(material);
            }

            material = InitializeMaterial();

            if (urdfMaterial.color != null)
            {
                material.color = CreateColor(urdfMaterial.color);
            }
            else if (urdfMaterial.texture != null)
            {
                material.mainTexture = LoadTexture(urdfMaterial.texture.filename);
            }

            AssetDatabase.CreateAsset(material, UrdfAssetPathHandler.GetMaterialAssetPath(urdfMaterial.name));
            return(material);
        }
        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));
        }
Example #3
0
 public static void SetUrdfMaterial(GameObject gameObject, Link.Visual.Material urdfMaterial)
 {
     if (urdfMaterial != null)
     {
         var material = CreateMaterial(urdfMaterial);
         SetMaterial(gameObject, material);
     }
     else
     {
         //If the URDF material is not defined, and the renderer is missing
         //a material, assign the default material.
         Renderer renderer = gameObject.GetComponentInChildren <Renderer>();
         if (renderer != null && renderer.sharedMaterial == null)
         {
             var defaultMaterial = AssetDatabase.LoadAssetAtPath <Material>(UrdfAssetPathHandler.GetMaterialAssetPath(DefaultMaterialName));
             SetMaterial(gameObject, defaultMaterial);
         }
     }
 }
Example #4
0
        private static string GenerateMaterialName(Link.Visual.Material urdfMaterial)
        {
            var materialName = "";

            if (urdfMaterial.color != null)
            {
                materialName = "rgba-";
                for (var i = 0; i < urdfMaterial.color.rgba.Length; i++)
                {
                    materialName += urdfMaterial.color.rgba[i];
                    if (i != urdfMaterial.color.rgba.Length - 1)
                    {
                        materialName += "-";
                    }
                }
            }
            else if (urdfMaterial.texture != null)
            {
                materialName = "texture-" + Path.GetFileName(urdfMaterial.texture.filename);
            }

            return(materialName);
        }