Exemplo n.º 1
0
        private ScenarioLightmapBspData ConvertScenarioLightmapBspData(ScenarioLightmapBspData Lbsp)
        {
            var lightmapResourceDefinition = BlamCache.ResourceCache.GetRenderGeometryApiResourceDefinition(Lbsp.Geometry.Resource);

            if (lightmapResourceDefinition == null)
            {
                return(Lbsp);
            }

            var converter = new RenderGeometryConverter(CacheContext, BlamCache);
            var newLightmapResourceDefinition = converter.Convert(Lbsp.Geometry, lightmapResourceDefinition);

            //
            // convert vertex buffers and add them to the new resource
            //

            foreach (var staticPerVertexLighting in Lbsp.StaticPerVertexLightingBuffers)
            {
                if (staticPerVertexLighting.VertexBufferIndex != -1)
                {
                    staticPerVertexLighting.VertexBuffer = lightmapResourceDefinition.VertexBuffers[staticPerVertexLighting.VertexBufferIndex].Definition;
                    VertexBufferConverter.ConvertVertexBuffer(BlamCache.Version, CacheContext.Version, staticPerVertexLighting.VertexBuffer);
                    var d3dPointer = new D3DStructure <VertexBufferDefinition>();
                    d3dPointer.Definition = staticPerVertexLighting.VertexBuffer;
                    newLightmapResourceDefinition.VertexBuffers.Add(d3dPointer);
                    // set the new buffer index
                    staticPerVertexLighting.VertexBufferIndex = (short)(newLightmapResourceDefinition.VertexBuffers.Elements.Count - 1);
                }
            }

            Lbsp.Geometry.Resource = CacheContext.ResourceCache.CreateRenderGeometryApiResource(newLightmapResourceDefinition);

            return(Lbsp);
        }
Exemplo n.º 2
0
        private ScenarioStructureBsp ConvertScenarioStructureBsp(ScenarioStructureBsp sbsp, CachedTag instance, Dictionary <ResourceLocation, Stream> resourceStreams)
        {
            var converter = new RenderGeometryConverter(CacheContext, BlamCache);   // should be made static

            var blamDecoratorResourceDefinition = BlamCache.ResourceCache.GetRenderGeometryApiResourceDefinition(sbsp.DecoratorGeometry.Resource);
            var blamGeometryResourceDefinition  = BlamCache.ResourceCache.GetRenderGeometryApiResourceDefinition(sbsp.Geometry.Resource);

            var decoratorGeometry = converter.Convert(sbsp.DecoratorGeometry, blamDecoratorResourceDefinition);
            var geometry          = converter.Convert(sbsp.Geometry, blamGeometryResourceDefinition);

            foreach (var cluster in sbsp.Clusters)
            {
                List <ScenarioStructureBsp.Cluster.DecoratorGrid> newDecoratorGrids = new List <ScenarioStructureBsp.Cluster.DecoratorGrid>();

                foreach (var grid in cluster.DecoratorGrids)
                {
                    var buffer = blamDecoratorResourceDefinition.VertexBuffers[grid.Gen3Info.VertexBufferIndex].Definition;
                    var offset = grid.VertexBufferOffset;

                    grid.Vertices = new List <TinyPositionVertex>();
                    using (var stream = new MemoryStream(buffer.Data.Data))
                    {
                        var vertexStream = VertexStreamFactory.Create(BlamCache.Version, stream);
                        stream.Position = offset;

                        for (int i = 0; i < grid.Amount; i++)
                        {
                            grid.Vertices.Add(vertexStream.ReadTinyPositionVertex());
                        }
                    }

                    if (grid.Amount == 0)
                    {
                        newDecoratorGrids.Add(grid);
                    }
                    else
                    {
                        // Get the new grids
                        var newGrids = ConvertDecoratorGrid(grid.Vertices, grid);

                        // Add all to list
                        foreach (var newGrid in newGrids)
                        {
                            newDecoratorGrids.Add(newGrid);
                        }
                    }
                }
                cluster.DecoratorGrids = newDecoratorGrids;
            }

            // convert all the decorator vertex buffers
            foreach (var d3dBuffer in blamDecoratorResourceDefinition.VertexBuffers)
            {
                VertexBufferConverter.ConvertVertexBuffer(BlamCache.Version, CacheContext.Version, d3dBuffer.Definition);
                decoratorGeometry.VertexBuffers.Add(d3dBuffer);
            }

            sbsp.DecoratorGeometry.Resource = CacheContext.ResourceCache.CreateRenderGeometryApiResource(decoratorGeometry);
            sbsp.Geometry.Resource          = CacheContext.ResourceCache.CreateRenderGeometryApiResource(geometry);

            sbsp.CollisionBspResource = ConvertStructureBspTagResources(sbsp);
            sbsp.PathfindingResource  = ConvertStructureBspCacheFileTagResources(sbsp);

            sbsp.Unknown86 = 1;

            //
            // Set compatibility flag for H3 mopps for the engine to perform some fixups just in time
            //

            if (BlamCache.Version == CacheVersion.Halo3Retail || BlamCache.Version == CacheVersion.Halo3Beta)
            {
                sbsp.CompatibilityFlags |= ScenarioStructureBsp.StructureBspCompatibilityValue.UseMoppIndexPatch;
            }

            //
            // Temporary Fixes:
            //

            // Without this 005_intro crash on cortana sbsp
            sbsp.Geometry.MeshClusterVisibility = new List <RenderGeometry.MoppClusterVisiblity>();

            return(sbsp);
        }
Exemplo n.º 3
0
        private RenderGeometry ConvertInstanceRenderGeometry(int geometryIndex, bool iscluster)
        {
            int meshindex        = 0;
            int compressionindex = 0;
            int loddataindex     = -1;

            if (!iscluster)
            {
                var instance    = StructureBsp.InstancedGeometryInstances[geometryIndex];
                var instanceDef = StructureBspResources.InstancedGeometry[instance.MeshIndex];
                meshindex        = instanceDef.MeshIndex;
                compressionindex = instanceDef.CompressionIndex;
                loddataindex     = instance.LodDataIndex;
            }
            if (iscluster)
            {
                var cluster = StructureBsp.Clusters[geometryIndex];
                meshindex = cluster.MeshIndex;
            }

            var mesh = Lbsp.Geometry.Meshes[meshindex];

            var resourceDefinition = GetSingleMeshResourceDefinition(Lbsp.Geometry, meshindex);

            var renderGeometry = new RenderGeometry();

            renderGeometry.Unknown2 = new List <RenderGeometry.UnknownBlock>();
            renderGeometry.Meshes   = new List <Mesh>()
            {
                mesh
            };
            renderGeometry.MeshClusterVisibility = new List <RenderGeometry.MoppClusterVisiblity>()
            {
                Lbsp.Geometry.MeshClusterVisibility[meshindex].DeepClone()
            };

            //instanced geo has a compression index
            if (!iscluster)
            {
                renderGeometry.Compression = new List <RenderGeometryCompression>
                {
                    Lbsp.Geometry.Compression[compressionindex].DeepClone()
                };
            }

            renderGeometry.InstancedGeometryPerPixelLighting = new List <RenderGeometry.StaticPerPixelLighting>();

            if (loddataindex != -1)
            {
                renderGeometry.InstancedGeometryPerPixelLighting.Add(
                    Lbsp.Geometry.InstancedGeometryPerPixelLighting[loddataindex].DeepClone());
            }

            if (SourceCache.Version != DestCache.Version)
            {
                var renderGeometryConverter = new RenderGeometryConverter(DestCache, SourceCache);
                resourceDefinition = renderGeometryConverter.Convert(renderGeometry, resourceDefinition);
            }

            // convert world to rigid (or else it can be dragged)
            if (mesh.ResourceVertexBuffers[0].Format == VertexBufferFormat.World)
            {
                renderGeometry.Meshes[0].ResourceVertexBuffers[0].Format = VertexBufferFormat.Rigid;
                renderGeometry.Meshes[0].Type           = VertexType.Rigid;
                renderGeometry.Meshes[0].RigidNodeIndex = 0;
                var compressionInfo = CompressVertexBuffer(mesh.ResourceVertexBuffers[0]);
                renderGeometry.Compression = new List <RenderGeometryCompression>()
                {
                    compressionInfo
                };
            }

            renderGeometry.Resource = DestCache.ResourceCache.CreateRenderGeometryApiResource(resourceDefinition);

            return(renderGeometry);
        }