Esempio n. 1
0
 /// <summary>
 /// Adds a new geometry resource.
 /// </summary>
 internal static GeometryResource AddGeometry(this ResourceDictionary resourceDictionary, NamedOrGenericKey resourceKey, GeometryFactory objectType)
 {
     return(resourceDictionary.AddResource(resourceKey, new GeometryResource(objectType)));
 }
Esempio n. 2
0
 /// <summary>
 /// Adds a new texture resource pointing to the given texture file name.
 /// </summary>
 internal static StandardTextureResource AddTexture(this ResourceDictionary resourceDictionary, NamedOrGenericKey resourceKey, string textureFileName)
 {
     return(resourceDictionary.AddResource(resourceKey, new StandardTextureResource(textureFileName)));
 }
Esempio n. 3
0
 /// <summary>
 /// Adds a new geometry resource.
 /// </summary>
 internal static GeometryResource AddGeometry(this ResourceDictionary resourceDictionary, NamedOrGenericKey resourceKey, Geometry geometry)
 {
     return(resourceDictionary.AddResource(resourceKey, new GeometryResource(geometry)));
 }
Esempio n. 4
0
 /// <summary>
 /// Adds a new geometry resource.
 /// </summary>
 internal static GeometryResource AddGeometry(this ResourceDictionary resourceDictionary, GeometryFactory objectType)
 {
     return(resourceDictionary.AddResource(new GeometryResource(objectType)));
 }
        /// <summary>
        /// Gets or creates the material resource for the given VertexStructure object.
        /// </summary>
        internal static MaterialResource GetOrCreateMaterialResource(this ResourceDictionary resourceDict, VertexStructureSurface targetSurface)
        {
            NamedOrGenericKey materialKey = targetSurface.Material;
            NamedOrGenericKey textureKey  = targetSurface.TextureKey;

            // Get the material if it is already created
            if ((!materialKey.IsEmpty) && (resourceDict.ContainsResource(materialKey)))
            {
                return(resourceDict.GetResource <MaterialResource>(materialKey));
            }

            // Generate a dynamic material key
            if (materialKey.IsEmpty)
            {
                materialKey = new NamedOrGenericKey(targetSurface.MaterialProperties.GetDynamicResourceKey());
            }

            // Get the material if it is already created
            if (resourceDict.ContainsResource(materialKey))
            {
                return(resourceDict.GetResource <MaterialResource>(materialKey));
            }

            if (textureKey.IsEmpty)
            {
                // Create a default material without any texture
                SimpleColoredMaterialResource result = resourceDict.AddResource <SimpleColoredMaterialResource>(materialKey, new SimpleColoredMaterialResource());
                result.MaterialDiffuseColor = targetSurface.MaterialProperties.DiffuseColor;
                return(result);
            }
            else
            {
                // Create texture resource if needed
                try
                {
                    if ((!resourceDict.ContainsResource(textureKey)) &&
                        (!string.IsNullOrEmpty(textureKey.NameKey)))
                    {
                        // Try to find and create the texture resource by its name
                        if (targetSurface.ResourceLink != null)
                        {
                            var textureResourceLink = targetSurface.ResourceLink.GetForAnotherFile(textureKey.NameKey);

                            resourceDict.AddResource <StandardTextureResource>(
                                textureKey,
                                new StandardTextureResource(
                                    targetSurface.ResourceLink.GetForAnotherFile(textureKey.NameKey)));
                        }
                        else if (targetSurface.ResourceSourceAssembly != null)
                        {
                            var textureResourceLink = new AssemblyResourceLink(
                                targetSurface.ResourceSourceAssembly,
                                targetSurface.ResourceSourceAssembly.GetName().Name + ".Resources.Textures",
                                textureKey.NameKey);
                            if (textureResourceLink.IsValid())
                            {
                                resourceDict.AddResource <StandardTextureResource>(
                                    textureKey,
                                    new StandardTextureResource(textureResourceLink));
                            }
                            else
                            {
                                // Unable to resolve texture
                                textureKey = NamedOrGenericKey.Empty;
                            }
                        }
                        else
                        {
                            // Unable to resolve texture
                            textureKey = NamedOrGenericKey.Empty;
                        }
                    }
                }
                catch { }

                // Create a default textured material
                if (!textureKey.IsEmpty)
                {
                    SimpleColoredMaterialResource result = resourceDict.AddResource <SimpleColoredMaterialResource>(
                        materialKey,
                        new SimpleColoredMaterialResource(textureKey));
                    result.MaterialDiffuseColor = targetSurface.MaterialProperties.DiffuseColor;
                    return(result);
                }
                else
                {
                    SimpleColoredMaterialResource result = resourceDict.AddResource <SimpleColoredMaterialResource>(
                        materialKey,
                        new SimpleColoredMaterialResource());
                    result.MaterialDiffuseColor = targetSurface.MaterialProperties.DiffuseColor;
                    return(result);
                }
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Adds a new geometry resource.
 /// </summary>
 internal static GeometryResource AddGeometry(this ResourceDictionary resourceDictionary, Geometry geometry)
 {
     return(resourceDictionary.AddResource(new GeometryResource(geometry)));
 }
 /// <summary>
 /// Adds a new texture resource pointing to the given texture file name.
 /// </summary>
 internal static StandardTextureResource AddTexture(this ResourceDictionary resourceDiciontary, NamedOrGenericKey resourceKey, Uri textureResourceUri)
 {
     return(resourceDiciontary.AddResource(resourceKey, new StandardTextureResource(textureResourceUri)));
 }
 /// <summary>
 /// Adds a new texture resource pointing to the given texture file name.
 /// </summary>
 internal static StandardTextureResource AddTexture(this ResourceDictionary resourceDiciontary, Uri textureResourceUri)
 {
     return(resourceDiciontary.AddResource(new StandardTextureResource(textureResourceUri)));
 }
 /// <summary>
 /// Adds a new texture resource pointing to the given texture file name.
 /// </summary>
 internal static StandardTextureResource AddTexture(this ResourceDictionary resourceDiciontary, string textureFileName)
 {
     return(resourceDiciontary.AddResource(new StandardTextureResource(textureFileName)));
 }
 /// <summary>
 /// Adds a new geometry resource.
 /// </summary>
 internal static GeometryResource AddGeometry(this ResourceDictionary resourceDiciontary, NamedOrGenericKey resourceKey, VertexStructure structure)
 {
     return(resourceDiciontary.AddResource(resourceKey, new GeometryResource(structure)));
 }
 /// <summary>
 /// Adds a new geometry resource.
 /// </summary>
 internal static GeometryResource AddGeometry(this ResourceDictionary resourceDiciontary, VertexStructure structure)
 {
     return(resourceDiciontary.AddResource(new GeometryResource(structure)));
 }