Example #1
0
        public WadStatic Clone()
        {
            WadStatic clone = (WadStatic)MemberwiseClone();

            clone.Mesh = Mesh.Clone();
            return(clone);
        }
Example #2
0
        private static bool LoadStatics(ChunkReader chunkIO, ChunkId idOuter, Wad2 wad, /*Dictionary<long, WadMesh> meshes*/
                                        Dictionary <long, WadTexture> textures)
        {
            if (idOuter != Wad2Chunks.Statics)
            {
                return(false);
            }

            chunkIO.ReadChunks((id, chunkSize) =>
            {
                if (id != Wad2Chunks.Static)
                {
                    return(false);
                }

                var s = new WadStatic(new WadStaticId(LEB128.ReadUInt(chunkIO.Raw)));
                //s.Mesh = meshes[LEB128.ReadInt(chunkIO.Raw)];
                s.Flags        = LEB128.ReadShort(chunkIO.Raw);
                s.LightingType = (WadMeshLightingType)LEB128.ReadShort(chunkIO.Raw);

                chunkIO.ReadChunks((id2, chunkSize2) =>
                {
                    if (id2 == Wad2Chunks.StaticVisibilityBox)
                    {
                        var min = Vector3.Zero;
                        var max = Vector3.Zero;
                        chunkIO.ReadChunks((id3, chunkSize3) =>
                        {
                            if (id3 == Wad2Chunks.MeshBoundingBoxMin)
                            {
                                min = chunkIO.ReadChunkVector3(chunkSize3);
                            }
                            else if (id3 == Wad2Chunks.MeshBoundingBoxMax)
                            {
                                max = chunkIO.ReadChunkVector3(chunkSize3);
                            }
                            else
                            {
                                return(false);
                            }
                            return(true);
                        });
                        s.VisibilityBox = new BoundingBox(min, max);
                    }
                    else if (id2 == Wad2Chunks.StaticCollisionBox)
                    {
                        var min = Vector3.Zero;
                        var max = Vector3.Zero;
                        chunkIO.ReadChunks((id3, chunkSize3) =>
                        {
                            if (id3 == Wad2Chunks.MeshBoundingBoxMin)
                            {
                                min = chunkIO.ReadChunkVector3(chunkSize3);
                            }
                            else if (id3 == Wad2Chunks.MeshBoundingBoxMax)
                            {
                                max = chunkIO.ReadChunkVector3(chunkSize3);
                            }
                            else
                            {
                                return(false);
                            }
                            return(true);
                        });
                        s.CollisionBox = new BoundingBox(min, max);
                    }
                    else if (id2 == Wad2Chunks.Mesh)
                    {
                        s.Mesh = LoadMesh(chunkIO, chunkSize2, textures);
                    }
                    else if (id2 == Wad2Chunks.StaticAmbientLight)
                    {
                        s.AmbientLight = chunkIO.ReadChunkShort(chunkSize2);
                    }
                    else if (id2 == Wad2Chunks.StaticLight)
                    {
                        var light = new WadLight();
                        chunkIO.ReadChunks((id3, chunkSize3) =>
                        {
                            if (id3 == Wad2Chunks.StaticLightPosition)
                            {
                                light.Position = chunkIO.ReadChunkVector3(chunkSize3);
                            }
                            else if (id3 == Wad2Chunks.StaticLightRadius)
                            {
                                light.Radius = chunkIO.ReadChunkFloat(chunkSize3);
                            }
                            else if (id3 == Wad2Chunks.StaticLightIntensity)
                            {
                                light.Intensity = chunkIO.ReadChunkFloat(chunkSize3);
                            }
                            else
                            {
                                return(false);
                            }
                            return(true);
                        });
                        s.Lights.Add(light);
                    }
                    else
                    {
                        return(false);
                    }
                    return(true);
                });

                wad.Statics.Add(s.Id, s);
                return(true);
            });

            return(true);
        }