コード例 #1
0
        /// <summary>
        /// Add a new generic parameter.
        /// </summary>
        /// <typeparam name="T">The type of the generic.</typeparam>
        /// <param name="keyName">The name of the generic.</param>
        /// <param name="generics">The target GenericDictionary.</param>
        private void AddKey <T>(string keyName, GenericDictionary generics)
        {
            INodeParameter nodeParameter;
            var            typeT = typeof(T);

            if (typeT == typeof(string))
            {
                nodeParameter = new NodeParameter();
            }
            else if (typeT == typeof(Texture2D))
            {
                nodeParameter = new NodeParameterTexture();
            }
            else if (typeT == typeof(float))
            {
                nodeParameter = new NodeParameterFloat();
            }
            else if (typeT == typeof(int))
            {
                nodeParameter = new NodeParameterInt();
            }
            else if (typeT == typeof(Vector2))
            {
                nodeParameter = new NodeParameterFloat2();
            }
            else if (typeT == typeof(Vector3))
            {
                nodeParameter = new NodeParameterFloat3();
            }
            else if (typeT == typeof(Vector4))
            {
                nodeParameter = new NodeParameterFloat4();
            }
            else if (typeT == typeof(SamplerState))
            {
                nodeParameter = new NodeParameterSampler();
            }
            else
            {
                throw new Exception("Unsupported generic format");
            }

            if (Generics.ContainsKey(keyName))
            {
                var gen = Generics[keyName];
                if (gen == null || gen.GetType() != nodeParameter.GetType())
                {
                    generics[keyName] = nodeParameter;
                }
                else
                {
                    generics[keyName] = gen;
                }
            }
            else
            {
                generics.Add(keyName, nodeParameter);
            }
        }
コード例 #2
0
 private void AddSampler(NodeParameterSampler sampler)
 {
     if (sampler != null && sampler.SamplerParameterKey != null)
     {
         var samplerStateDescr = new SamplerStateDescription(sampler.Filtering, sampler.AddressModeU)
         {
             AddressV = sampler.AddressModeV,
             AddressW = TextureAddressMode.Wrap
         };
         var samplerState = new FakeSamplerState(samplerStateDescr);
         Parameters.Set(sampler.SamplerParameterKey, ContentReference.Create((SamplerState)samplerState));
     }
 }
コード例 #3
0
        /// <summary>
        /// Get the sampler key, a new one or an existing one.
        /// </summary>
        /// <param name="sampler">The sampler.</param>
        /// <param name="samplerKeys">The already defined keys.</param>
        /// <param name="samplerIndex">The current index of the sampler.</param>
        /// <returns>The ParameterKey.</returns>
        private void SetSamplerKey(NodeParameterSampler sampler, Dictionary <SamplerDescription, ParameterKey <SamplerState> > samplerKeys, ref int samplerIndex)
        {
            var state = new SamplerDescription {
                Filtering = sampler.Filtering, AddressModeU = sampler.AddressModeU, AddressModeV = sampler.AddressModeV, AddressModeW = TextureAddressMode.Wrap
            };
            ParameterKey <SamplerState> samplerParameterKey;

            if (!samplerKeys.TryGetValue(state, out samplerParameterKey))
            {
                samplerParameterKey = GetDefaultSamplerKey(samplerIndex);
                ++samplerIndex;
                samplerKeys.Add(state, samplerParameterKey);
            }
            sampler.SamplerParameterKey = samplerParameterKey;
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MaterialTextureNode"/> class.
        /// </summary>
        /// <param name="texturePath">Name of the texture.</param>
        /// <param name="texcoordIndex">Index of the texcoord.</param>
        /// <param name="scale">The scale.</param>
        /// <param name="offset">The offset.</param>
        public MaterialTextureNode(string texturePath, TextureCoordinate texcoordIndex, Vector2 scale, Vector2 offset)
        {
            if (texturePath == null)
            {
                throw new ArgumentNullException("texturePath");
            }

            TextureReference = new AssetReference <TextureAsset>(Guid.Empty, new UFile(texturePath));
            TexcoordIndex    = texcoordIndex;
            Sampler          = new NodeParameterSampler();
            Scale            = scale;
            Offset           = offset;
            AutoAssignKey    = true;
            Key = null;
            UsedParameterKey = null;
        }
コード例 #5
0
        /// <summary>
        /// Add a new member.
        /// </summary>
        /// <typeparam name="T">The type of the member.</typeparam>
        /// <param name="linkName">The name of the parameter key.</param>
        /// <param name="members">The target parameter collection.</param>
        private void AddMember <T>(string linkName, Dictionary <ParameterKey, object> members)
        {
            var pk = GetTypedParameterKey <T>(linkName);

            if (pk != null)
            {
                Type   expectedType = null;
                object defaultValue;
                if (pk.PropertyType == typeof(Graphics.Texture))
                {
                    expectedType = typeof(NodeParameterTexture);
                    defaultValue = new NodeParameterTexture();
                }
                else if (pk.PropertyType == typeof(Graphics.SamplerState))
                {
                    expectedType = typeof(NodeParameterSampler);
                    defaultValue = new NodeParameterSampler();
                }
                else
                {
                    expectedType = pk.PropertyType;
                    defaultValue = pk.DefaultMetadataT.DefaultValue;
                }

                if (Members.ContainsKey(pk))
                {
                    var value = Members[pk];
                    if (value.GetType() == expectedType)
                    {
                        members.Add(pk, value);
                    }
                }
                else
                {
                    members.Add(pk, defaultValue);
                }
            }
        }