Exemple #1
0
        public RenderMaterial(Direct3D.Device device, GameCache cache, TagTool.Geometry.RenderMaterial material)
        {
            if (material.RenderMethod == null)
            {
                return;
            }

            using (var cacheStream = cache.OpenCacheRead())
            {
                var renderMethod = cache.Deserialize <RenderMethod>(cacheStream, material.RenderMethod);

                var template = cache.Deserialize <RenderMethodTemplate>(cacheStream, renderMethod.ShaderProperties[0].Template);

                Textures = new Dictionary <string, RenderTexture>();

                for (var shaderMapIndex = 0; shaderMapIndex < renderMethod.ShaderProperties[0].TextureConstants.Count; shaderMapIndex++)
                {
                    var shaderMapName = cache.StringTable.GetString(template.TextureParameterNames[shaderMapIndex].Name);

                    if (Textures.ContainsKey(shaderMapName))
                    {
                        continue;
                    }

                    var shaderMap           = renderMethod.ShaderProperties[0].TextureConstants[shaderMapIndex];
                    var shaderMapDefinition = cache.Deserialize <Bitmap>(cacheStream, shaderMap.Bitmap);

                    Textures[shaderMapName] = new RenderTexture(device, cache, shaderMapDefinition, shaderMap.BitmapIndex);
                }
            }
        }
Exemple #2
0
        public RenderMaterial(Direct3D.Device device, HaloOnlineCacheContext cacheContext, TagTool.Geometry.RenderMaterial material)
        {
            if (material.RenderMethod == null)
            {
                return;
            }

            using (var cacheStream = cacheContext.OpenTagCacheRead())
            {
                var renderMethod = (RenderMethod)cacheContext.Deserialize(
                    new TagSerializationContext(cacheStream, cacheContext, material.RenderMethod),
                    TagDefinition.Find(material.RenderMethod.Group));

                var template = cacheContext.Deserialize <RenderMethodTemplate>(
                    new TagSerializationContext(cacheStream, cacheContext, renderMethod.ShaderProperties[0].Template));

                Textures = new Dictionary <string, RenderTexture>();

                for (var shaderMapIndex = 0; shaderMapIndex < renderMethod.ShaderProperties[0].ShaderMaps.Count; shaderMapIndex++)
                {
                    var shaderMapName = cacheContext.GetString(template.SamplerArguments[shaderMapIndex].Name);

                    if (Textures.ContainsKey(shaderMapName))
                    {
                        continue;
                    }

                    var shaderMap           = renderMethod.ShaderProperties[0].ShaderMaps[shaderMapIndex];
                    var shaderMapDefinition = cacheContext.Deserialize <Bitmap>(new TagSerializationContext(cacheStream, cacheContext, shaderMap.Bitmap));

                    Textures[shaderMapName] = new RenderTexture(device, cacheContext, shaderMapDefinition, shaderMap.BitmapIndex);
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Adds a material to the model.
 /// </summary>
 /// <param name="material">The material.</param>
 /// <returns>The material index.</returns>
 public short AddMaterial(RenderMaterial material)
 {
     _model.Materials.Add(material);
     return((short)(_model.Materials.Count - 1));
 }