コード例 #1
0
        private static Material CreateMaterialAsset(this Link.Visual.Material urdfMaterial)
        {
            if (urdfMaterial.name == "")
            {
                urdfMaterial.name = GenerateMaterialName(urdfMaterial);
            }

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

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

            material = InitializeMaterial();

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

            AssetDatabase.CreateAsset(material, GetMaterialAssetPath(urdfMaterial.name));
            return(material);
        }
コード例 #2
0
        private static Material createMaterialAsset(this Link.Visual.Material urdfMaterial)
        {
            Material material = initializeMaterial();

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

            AssetDatabase.CreateAsset(material, getMaterialAssetPath(urdfMaterial.name));
            return(material);
        }
コード例 #3
0
 public static void SetUrdfMaterial(GameObject gameObject, Link.Visual.Material urdfMaterial)
 {
     if (urdfMaterial != null)
     {
         var material = CreateMaterialAsset(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)
         {
             SetDefaultMaterial(gameObject);
         }
     }
 }
コード例 #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);
        }