Esempio n. 1
0
        private static List <Vertex> ReadVerts(bsp_header_lump_t lump, BinaryStreamReader src)
        {
            int           count    = (int)lump.length / 44;
            List <Vertex> elements = new List <Vertex>();

            src.Seek(lump.offset);
            for (int i = 0; i < count; ++i)
            {
                elements.Add(new Vertex()
                {
                    pos        = new Vector3(src.ReadFloat(), src.ReadFloat(), src.ReadFloat()),
                    texCoord   = new Vector2(src.ReadFloat(), src.ReadFloat()),
                    lmCoord    = new Vector2(src.ReadFloat(), src.ReadFloat()),
                    lmNewCoord = new Vector2(0.0f, 0.0f),
                    normal     = new Vector3(src.ReadFloat(), src.ReadFloat(), src.ReadFloat()),
                    color      = BspHelpers.brightnessAdjustVertex(BspHelpers.colorToVec(src.ReadUInt32()), 4.0f) // ReadUInt64
                });
            }

            return(elements);
        }
Esempio n. 2
0
        /// <summary>
        /// Read all lightmaps
        /// </summary>
        private static List <lightmap_rect_t> ReadLightmaps(bsp_header_lump_t lump, BinaryStreamReader src)
        {
            int lightmapSize = 128 * 128;
            int count        = (int)lump.length / (lightmapSize * 3);

            var gridSize = 2;

            while (gridSize * gridSize < count)
            {
                gridSize *= 2;
            }

            var textureSize = gridSize * 128;

            int xOffset = 0;
            int yOffset = 0;

            List <lightmap_t>      lightmaps     = new List <lightmap_t>();
            List <lightmap_rect_t> lightmapRects = new List <lightmap_rect_t>();
            Vector3 rgb = Vector3.Zero;

            src.Seek(lump.offset);
            for (int i = 0; i < count; ++i)
            {
                byte[] elements = new byte[lightmapSize * 4];

                for (int j = 0; j < lightmapSize * 4; j += 4)
                {
                    rgb.X = src.ReadUByte();
                    rgb.Y = src.ReadUByte();
                    rgb.Z = src.ReadUByte();

                    rgb = BspHelpers.brightnessAdjust(rgb, 4.0f);

                    elements[j]     = (byte)rgb.X;
                    elements[j + 1] = (byte)rgb.Y;
                    elements[j + 2] = (byte)rgb.Z;
                    elements[j + 3] = 255;
                }

                lightmap_t l = new lightmap_t();
                l.x      = xOffset;
                l.y      = yOffset;
                l.width  = 128;
                l.height = 128;
                l.bytes  = elements;
                lightmaps.Add(l);

                lightmap_rect_t r = new lightmap_rect_t();
                r.x      = (float)xOffset / (float)textureSize;
                r.y      = (float)yOffset / (float)textureSize;
                r.xScale = 128f / (float)textureSize;
                r.yScale = 128f / (float)textureSize;
                lightmapRects.Add(r);

                xOffset += 128;

                if (xOffset >= textureSize)
                {
                    yOffset += 128;
                    xOffset  = 0;
                }
            }

            // Send the lightmap data back to the render thread
            q3bsp.onMessage(new MessageParams()
            {
                type      = "lightmap",
                size      = textureSize,
                lightmaps = lightmaps
            });

            return(lightmapRects);
        }