Esempio n. 1
0
        /// <summary>
        /// Compares the value behind a key in two ParameterCollectionData.
        /// </summary>
        /// <param name="parameters0">The first ParameterCollectionData.</param>
        /// <param name="parameters1">The second ParameterCollectionData.</param>
        /// <param name="key">The ParameterKey.</param>
        /// <returns>True</returns>
        private static bool CompareKeyValue <T>(ParameterCollectionData parameters0, ParameterCollectionData parameters1, ParameterKey <T> key)
        {
            var value0 = parameters0.ContainsKey(key) ? parameters0[key] : key.DefaultMetadataT.DefaultValue;
            var value1 = parameters1.ContainsKey(key) ? parameters1[key] : key.DefaultMetadataT.DefaultValue;

            return(value0 == value1);
        }
 /// <summary>
 /// Get the parameters from the lighting configurations.
 /// </summary>
 /// <param name="meshData">The mesh.</param>
 /// <returns>The lighting configurations.</returns>
 private List <ParameterCollectionData> GetLightingParameters(MeshData meshData)
 {
     if (meshData != null && meshData.Parameters != null && meshData.Parameters.ContainsKey(LightingKeys.LightingConfigurations))
     {
         var lightingDescContent = meshData.Parameters[LightingKeys.LightingConfigurations];
         if (lightingDescContent != null && lightingDescContent is ContentReference <LightingConfigurationsSetData> )
         {
             var lightingDesc = ((ContentReference <LightingConfigurationsSetData>)lightingDescContent).Value;
             if (lightingDesc != null)
             {
                 var collection = new List <ParameterCollectionData>();
                 foreach (var config in lightingDesc.Configs)
                 {
                     var parameters = config.GetCollection();
                     SetShadowCasterReceiverConfiguration(meshData.Parameters, parameters, shadowKeys);
                     collection.Add(parameters);
                 }
                 return(collection);
             }
         }
         var defaultParameters = new ParameterCollectionData();
         SetShadowCasterReceiverConfiguration(meshData.Parameters, defaultParameters, shadowKeys);
         return(new List <ParameterCollectionData> {
             defaultParameters
         });
     }
     return(null);
 }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MaterialDescription"/> class.
 /// </summary>
 public MaterialDescription()
 {
     //MaterialTrees = new Dictionary<string, MaterialTree>();
     Nodes      = new Dictionary <string, IMaterialNode>();
     ColorNodes = new Dictionary <ParameterKey <ShaderMixinSource>, string>();
     Parameters = new ParameterCollectionData();
 }
        /// <summary>
        /// Add the parameter to the collection.
        /// </summary>
        /// <typeparam name="T">The type of the parameter.</typeparam>
        /// <param name="key">The key of the variable.</param>
        /// <param name="value"></param>
        /// <param name="collection"></param>
        private void AddToCollection <T>(ParameterKey key, object value, ParameterCollectionData collection)
        {
            var pk = key as ParameterKey <T>;

            if (pk != null)
            {
                collection.Set(pk, value);
            }
        }
 private static void SetShadowCasterReceiverConfiguration(ParameterCollectionData sourceParameters, ParameterCollectionData targetParameters, params ParameterKey[] keys)
 {
     if (sourceParameters != null)
     {
         foreach (var key in keys)
         {
             if (sourceParameters.ContainsKey(key))
             {
                 targetParameters.Set(key, sourceParameters[key]);
             }
         }
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Test if two ParameterCollectionData are equal
        /// </summary>
        /// <param name="parameters0">The first ParameterCollectionData.</param>
        /// <param name="parameters1">The second ParameterCollectionData.</param>
        /// <returns>True if the collections are the same, false otherwise.</returns>
        private static bool AreCollectionsEqual(ParameterCollectionData parameters0, ParameterCollectionData parameters1)
        {
            bool result = true;

            foreach (var paramKey in parameters0)
            {
                result &= parameters1.ContainsKey(paramKey.Key) && parameters1[paramKey.Key].Equals(paramKey.Value);
            }
            foreach (var paramKey in parameters1)
            {
                result &= parameters0.ContainsKey(paramKey.Key) && parameters0[paramKey.Key].Equals(paramKey.Value);
            }
            return(result);
        }
Esempio n. 7
0
        public ParameterCollectionData GetParameters()
        {
            var parameters = new ParameterCollectionData();

            foreach (var startNodeName in Material.ColorNodes)
            {
                var startNode = Material.FindNode(startNodeName.Value);
                if (startNode != null)
                {
                    GetParametersFromNode(startNode, parameters);
                }
            }
            return(parameters);
        }
Esempio n. 8
0
 /// <summary>
 /// Adds the parameters from the ParameterCollectionData to the destination ParameterCollection. Excludes GraphicsResourceBase parameters.
 /// </summary>
 /// <param name="sourceParameters">The source ParameterCollectionData.</param>
 /// <param name="destParameters">The destination ParameterCollection.</param>
 protected static void AddToParameters(ParameterCollectionData sourceParameters, ParameterCollection destParameters)
 {
     if (sourceParameters != null)
     {
         foreach (var keyValue in sourceParameters)
         {
             // only keep what can be assigned
             if (keyValue.Value.GetType().IsAssignableFrom(keyValue.Key.PropertyType))
             {
                 destParameters.SetObject(keyValue.Key, keyValue.Key.ConvertValue(keyValue.Value));
             }
         }
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Gather all the parameters in the node hierarchy.
        /// </summary>
        /// <param name="node">The node to look into.</param>
        /// <param name="parameters">The parameter collection to fill.</param>
        private void GetParametersFromNode(IMaterialNode node, ParameterCollectionData parameters)
        {
            if (node == null)
            {
                return;
            }

            node.VisitNodes((context, nodeEntry) =>
            {
                var shaderNode = nodeEntry.Node as MaterialShaderClassNode;
                if (shaderNode != null)
                {
                    //foreach (var member in shaderNode.Members)
                    foreach (var member in shaderNode.GetParameters(context))
                    {
                        parameters.Set(member.Key, member.Value);
                    }
                }
            }, new MaterialContext {
                Material = Material, ExploreGenerics = false
            });
        }
Esempio n. 10
0
 public ModelComponentData()
 {
     Parameters = new ParameterCollectionData();
 }
        public ParameterCollectionData GetParameters(object context)
        {
            var collection = new ParameterCollectionData();

            if (MixinReference != null)
            {
                foreach (var keyValue in Members)
                {
                    var expectedType = keyValue.Value.GetType();
                    if (expectedType == typeof(Color4))
                    {
                        AddToCollection <Color4>(keyValue.Key, (Color4)keyValue.Value, collection);
                    }
                    else if (expectedType == typeof(float))
                    {
                        AddToCollection <float>(keyValue.Key, (float)keyValue.Value, collection);
                    }
                    else if (expectedType == typeof(double))
                    {
                        AddToCollection <double>(keyValue.Key, (double)keyValue.Value, collection);
                    }
                    else if (expectedType == typeof(int))
                    {
                        AddToCollection <int>(keyValue.Key, (int)keyValue.Value, collection);
                    }
                    else if (expectedType == typeof(uint))
                    {
                        AddToCollection <uint>(keyValue.Key, (uint)keyValue.Value, collection);
                    }
                    else if (expectedType == typeof(bool))
                    {
                        AddToCollection <bool>(keyValue.Key, (bool)keyValue.Value, collection);
                    }
                    else if (expectedType == typeof(Vector2))
                    {
                        AddToCollection <Vector2>(keyValue.Key, (Vector2)keyValue.Value, collection);
                    }
                    else if (expectedType == typeof(Vector3))
                    {
                        AddToCollection <Vector3>(keyValue.Key, (Vector3)keyValue.Value, collection);
                    }
                    else if (expectedType == typeof(Vector4))
                    {
                        AddToCollection <Vector4>(keyValue.Key, (Vector4)keyValue.Value, collection);
                    }
                    else if (expectedType == typeof(NodeParameterTexture))
                    {
                        var matContext = context as MaterialContext;
                        if (matContext != null)
                        {
                            var textureNode = matContext.Material.FindNode(((NodeParameterTexture)keyValue.Value).Reference);
                            if (textureNode != null)
                            {
                                AddToCollection <Graphics.Texture>(keyValue.Key, textureNode, collection);
                            }
                        }
                    }
                    else if (expectedType == typeof(NodeParameterSampler))
                    {
                        AddToCollection <Graphics.SamplerState>(keyValue.Key, keyValue.Value, collection);
                    }
                }
            }
            return(collection);
        }
 public MaterialParametersCreator(MaterialDescription mat, string assetUrl) : base(mat)
 {
     Parameters  = new ParameterCollectionData();
     materialUrl = assetUrl;
 }
Esempio n. 13
0
 public MeshMaterialParameters()
 {
     Parameters = new ParameterCollectionData();
 }