예제 #1
0
        private static TextureType GetTextureType(uint parameterHash)
        {
            uint baseDiffuseHash = Jenkins.OneAtATime("baseDiffuse");
            uint BaseDiffuseHash = Jenkins.OneAtATime("BaseDiffuse");
            uint basediffuseHash = Jenkins.OneAtATime("basediffuse");

            uint SpecHash = Jenkins.OneAtATime("Spec");
            uint specHash = Jenkins.OneAtATime("spec");

            uint BumpHash    = Jenkins.OneAtATime("Bump");
            uint BumpMapHash = Jenkins.OneAtATime("BumpMap");

            if (parameterHash == baseDiffuseHash || parameterHash == BaseDiffuseHash || parameterHash == basediffuseHash)
            {
                return(TextureType.Diffuse);
            }

            if (parameterHash == SpecHash || parameterHash == specHash)
            {
                return(TextureType.Spec);
            }

            if (parameterHash == BumpHash || parameterHash == BumpMapHash)
            {
                return(TextureType.Bump);
            }

            return(TextureType.Invalid);
        }
예제 #2
0
        public static MaterialDefinition LoadFromXPathNavigator(XPathNavigator navigator)
        {
            if (navigator == null)
            {
                return(null);
            }

            MaterialDefinition materialDefinition = new MaterialDefinition();

            //name
            materialDefinition.Name     = navigator.GetAttribute("Name", string.Empty);
            materialDefinition.NameHash = Jenkins.OneAtATime(materialDefinition.Name);

            //type
            materialDefinition.Type     = navigator.GetAttribute("Type", string.Empty);
            materialDefinition.TypeHash = Jenkins.OneAtATime(materialDefinition.Type);

            //draw styles
            XPathNodeIterator entries = navigator.Select("./Array[@Name='DrawStyles']/Object[@Class='DrawStyle']");

            while (entries.MoveNext())
            {
                DrawStyle drawStyle = DrawStyle.LoadFromXPathNavigator(entries.Current);

                if (drawStyle != null)
                {
                    materialDefinition.DrawStyles.Add(drawStyle);
                }
            }

            return(materialDefinition);
        }
예제 #3
0
        public static VertexLayout LoadFromXPathNavigator(XPathNavigator navigator)
        {
            if (navigator == null)
            {
                return(null);
            }

            VertexLayout vertexLayout = new VertexLayout();

            //name
            vertexLayout.Name = navigator.GetAttribute("Name", String.Empty);

            //name hash
            vertexLayout.NameHash = Jenkins.OneAtATime(vertexLayout.Name);

            //entries
            XPathNodeIterator entries = navigator.Select("./Array[@Name='Entries']/Object[@Class='LayoutEntry']");

            while (entries.MoveNext())
            {
                navigator = entries.Current;

                VertexLayout.Entry entry = new Entry();

                //stream
                entry.Stream = UInt32.Parse(navigator.GetAttribute("Stream", String.Empty));

                //data type
                String dataTypeString = navigator.GetAttribute("Type", String.Empty);
                Entry.GetDataTypeFromString(dataTypeString, out entry.DataType);

                //data usage
                String dataUsageString = navigator.GetAttribute("Usage", String.Empty);
                Entry.GetDataUsageFromString(dataUsageString, out entry.DataUsage);

                //data usage index
                entry.DataUsageIndex = UInt32.Parse(navigator.GetAttribute("UsageIndex", String.Empty));

                vertexLayout.Entries.Add(entry);
            }

            return(vertexLayout);
        }
예제 #4
0
        /// <summary>
        /// Finds the correct diffuse, specular and packed normal maps for the given mesh.
        /// </summary>
        /// <param name="mesh">The origin mesh.</param>
        /// <param name="parameter">The material parameter containing the hashed texture name, or some other parameter.</param>
        /// <param name="textureStrings">A list of available textures for this mesh.</param>
        private static void LookupTextures(Mesh mesh, Material.Parameter parameter, List <string> textureStrings)
        {
            if (parameter.Data.Length != 4 && parameter.Type != Material.Parameter.D3DXParameterType.Texture || parameter.Class != Material.Parameter.D3DXParameterClass.Object)
            {
                return;
            }

            TextureType textureType = GetTextureType(parameter.NameHash);

            if (textureType == TextureType.Invalid)
            {
                return;
            }

            uint textureHash = BitConverter.ToUInt32(parameter.Data, 0);

            foreach (string textureString in textureStrings)
            {
                if (Jenkins.OneAtATime(textureString.ToUpper()) == textureHash)
                {
                    switch (textureType)
                    {
                    case TextureType.Diffuse:
                        mesh.BaseDiffuse = textureString;
                        break;

                    case TextureType.Bump:
                        mesh.BumpMap = textureString;
                        break;

                    case TextureType.Spec:
                        mesh.SpecMap = textureString;
                        break;
                    }

                    return;
                }
            }
        }
        public static DrawStyle LoadFromXPathNavigator(XPathNavigator navigator)
        {
            if (navigator == null)
            {
                return(null);
            }

            DrawStyle drawStyle = new DrawStyle();

            //name
            drawStyle.Name     = navigator.GetAttribute("Name", string.Empty);
            drawStyle.NameHash = Jenkins.OneAtATime(drawStyle.Name);

            //effect
            drawStyle.Effect = navigator.GetAttribute("Effect", string.Empty);

            //input layout
            string vertexLayout = navigator.GetAttribute("InputLayout", string.Empty);

            drawStyle.VertexLayoutNameHash = Jenkins.OneAtATime(vertexLayout);

            return(drawStyle);
        }