ToString() public method

public ToString ( ) : string
return string
Example #1
0
 //-------------------------------------------------------------------------------
 internal static string Name(aiString name, string context)
 {
     if (name.Length == 0)
     {
         return("unnamed_" + context);
     }
     else
     {
         return(name.ToString());
     }
 }
Example #2
0
        private static void FromAssimpAlphaTexture(Module.Import.Assimp.Context context, Material material, aiMaterial material_data, aiScene scene, string unity_property, aiTextureType texture_type, Color default_color, Func <Color, float> op)
        {
            if (material_data.GetTextureCount(texture_type) > 0)
            {
                using (aiString texture_name = new aiString())
                {
                    if (material_data.GetTexturePath(texture_type, 0, texture_name))
                    {
                        Texture alpha    = new Texture(context, texture_name.ToString(), scene);
                        Texture base_tex = null;

                        Material.TextureParams param = material.GetTextureParams(unity_property);

                        if (param != null)
                        {
                            CLARTE.Backport.Tuple <Texture, uint> res = context.scene.GetAssimpTexture(param.index);

                            if (res != null)
                            {
                                base_tex = res.Item1;
                            }
                            else
                            {
                                Debug.LogErrorFormat("Invalid texture index. '{0}' was registered for material '{1}' as texture with index '{2}'. However no texture was found with this index.", unity_property, material.Name, param.index);
                            }
                        }
                        else
                        {
                            CLARTE.Backport.Tuple <Texture, uint> assimp_tex = context.scene.GetAssimpTexture(Guid.NewGuid().ToString(), () => new Texture("**E", alpha.width, alpha.height, default_color));

                            material.AddTextureParams(unity_property, new Material.TextureParams(assimp_tex.Item2));

                            base_tex = assimp_tex.Item1;
                        }

                        if (base_tex != null)
                        {
                            base_tex.AddToAlpha(alpha, op);

                            base_tex.filename = string.Format("**A{0}|{1}", base_tex.filename, texture_name.C_Str());
                        }
                    }
                }
            }
        }
Example #3
0
        private static Material FromAssimp(Module.Import.Assimp.Context context, aiScene scene, aiMaterial material_data)
        {
            Material material = new Material();

            // Initialize dictionaries before hand because we do not know in advance wich ones we will need
            material.floats   = new Dictionary <string, float>();
            material.colors   = new Dictionary <string, Color>();
            material.textures = new Dictionary <string, TextureParams>();

            // Name
            using (aiString material_name = new aiString())
            {
                if (material_data.GetName(material_name))
                {
                    material.name = material_name.ToString();
                }
            }

            // shader
            material.shader = Constants.defaultAssimpShader;

            // Shininess
            float shininess;

            if (material_data.GetShininess(out shininess))
            {
                aiShadingMode shading;

                if (material_data.GetShadingModel(out shading))
                {
                    if (shading != aiShadingMode.aiShadingMode_Blinn && shading != aiShadingMode.aiShadingMode_Phong)
                    {
                        // Unsupported shading model
                        Debug.LogWarningFormat("The shading model for material {0} is not supported. The value for the shininess is likely to be incorrect.", material.name);
                    }
                }

                const int factor = 128;                 // unity shader factor
                shininess /= factor;
            }

            // Gloss
            float gloss;

            if (material_data.GetShininessStrength(out gloss))
            {
                shininess *= gloss;
            }

            // Reflectivity
            float reflectivity;

            if (material_data.GetReflectivity(out reflectivity))
            {
                material.floats.Add(Assimp.Convert.unityMetallicValueName, reflectivity);
            }

            material.floats.Add(Assimp.Convert.unityGlossinessValueName, Smoothness(shininess, reflectivity));

            // Colors
            foreach (KeyValuePair <string, Assimp.Convert.GetColor> pair in Assimp.Convert.GetColors(material_data))
            {
                using (aiColor4D color = new aiColor4D())
                {
                    if (pair.Value(color))
                    {
                        Color unity_color = Assimp.Convert.AssimpToUnity.Color(color);

                        bool set_color = true;

                        switch (pair.Key)
                        {
                        case Assimp.Convert.unityDiffuseColorName:
                            // Global opacity
                            float opacity;

                            if (material_data.GetOpacity(out opacity) && opacity < 1.0f)
                            {
                                unity_color.a = opacity;

                                material.floats.Add(Assimp.Convert.unityRenderModeName, (float)CLARTE.Shaders.Standard.Utility.BlendMode.TRANSPARENT);
                            }

                            break;

                        case Assimp.Convert.unitySpecularColorName:
                            // Specular color must be very close to black
                            unity_color = 0.1f * unity_color;

                            break;

                        case Assimp.Convert.unityEmissiveColorName:
                            if (!CLARTE.Shaders.Standard.Utility.ShouldEmissionBeEnabled(unity_color))
                            {
                                set_color = false;
                            }

                            break;
                        }

                        if (set_color)
                        {
                            material.colors.Add(pair.Key, unity_color);
                        }
                    }
                }
            }

            // Textures
            foreach (KeyValuePair <string, aiTextureType> pair in Assimp.Convert.textureTypes)
            {
                // Make a copy to avoid problem of loop variable captured by reference by lambda expression
                string        texture_key  = pair.Key;
                aiTextureType texture_type = pair.Value;

                context.threads.AddTask(() => Texture.FromAssimp(context, material, scene, material_data, texture_key, texture_type, reflectivity));
            }

            // We must dispose of the given parameter to free unused memory. However other tasks may still be using this material (i.e. textures), so we will let the garbage collector do it's job.
            //material_data.Dispose();

            context.progress.Update(ASSIMP_PROGRESS_FACTOR);

            return(material);
        }