コード例 #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)));
 }
コード例 #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)));
 }
コード例 #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)));
 }
コード例 #4
0
 /// <summary>
 /// Adds a new geometry resource.
 /// </summary>
 internal static GeometryResource AddGeometry(this ResourceDictionary resourceDictionary, GeometryFactory objectType)
 {
     return(resourceDictionary.AddResource(new GeometryResource(objectType)));
 }
コード例 #5
0
        /// <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);
                }
            }
        }
コード例 #6
0
 /// <summary>
 /// Adds a new geometry resource.
 /// </summary>
 internal static GeometryResource AddGeometry(this ResourceDictionary resourceDictionary, Geometry geometry)
 {
     return(resourceDictionary.AddResource(new GeometryResource(geometry)));
 }
コード例 #7
0
 /// <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)));
 }
コード例 #8
0
 /// <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)));
 }
コード例 #9
0
 /// <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)));
 }
コード例 #10
0
 /// <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)));
 }
コード例 #11
0
 /// <summary>
 /// Adds a new geometry resource.
 /// </summary>
 internal static GeometryResource AddGeometry(this ResourceDictionary resourceDiciontary, VertexStructure structure)
 {
     return(resourceDiciontary.AddResource(new GeometryResource(structure)));
 }