Пример #1
0
        bspdispinfo[] ReadDispInfo()
        {
            br.BaseStream.Seek(header.lumps [SourceBSPStructs.LUMP_DISPINFO].fileofs, SeekOrigin.Begin);
            int dispinfoCount = header.lumps [SourceBSPStructs.LUMP_DISPINFO].filelen / 176;

            bspdispinfo[] temp = new bspdispinfo[dispinfoCount];
            for (int i = 0; i < dispinfoCount; i++)
            {
                temp[i].startPosition               = ConvertUtils.FlipVector(ConvertUtils.ReadVector3(br));
                temp[i].DispVertStart               = br.ReadInt32();
                temp[i].DispTriStart                = br.ReadInt32();
                temp[i].power                       = br.ReadInt32();
                temp[i].minTess                     = br.ReadInt32();
                temp[i].smoothingAngle              = br.ReadSingle();   //32
                temp[i].contents                    = br.ReadInt32();
                temp[i].MapFace                     = br.ReadUInt32();
                temp[i].LightmapAlphaStart          = br.ReadInt32();
                temp[i].LightmapSamplePositionStart = br.ReadInt32();                //46b

                br.BaseStream.Seek(128, SeekOrigin.Current);

                //temp[i].EdgeNeighbors = ReadDispNeighbor(4);//40b
                //temp[i].CornerNeighbors = ReadDispCornerNeighbors(4);//36b
                //br.BaseStream.Seek(40,SeekOrigin.Current);//40b
            }
            tempLog += ("Load: " + dispinfoCount + " DispInfos \n");
            Debug.Log("Load: " + dispinfoCount + " DispInfos ");
            return(temp);
        }
Пример #2
0
        surface BuildDispFace(int faceIndex, int model, short dispinfoId)
        {
            Vector3[]      vertices   = new Vector3[4];
            List <Vector3> disp_verts = new List <Vector3>();
            List <Vector2> UVs        = new List <Vector2>();
            List <Color32> cols       = new List <Color32>();
            List <int>     indices    = new List <int>();

            bspface curFace = map.facesLump[faceIndex];

            bsptexinfo curTexInfo = map.texinfosLump[curFace.texinfo];
            bsptexdata curTexData = map.texdataLump[curTexInfo.texdata];


            int fEdge = curFace.firstedge;

            for (int i = 0; i < curFace.numedges; i++)
            {
                vertices[i] = (map.surfedgesLump[fEdge + i] > 0 ?
                               map.vertexesLump[map.edgesLump[Mathf.Abs(map.surfedgesLump[fEdge + i])][0]] :
                               map.vertexesLump[map.edgesLump[Mathf.Abs(map.surfedgesLump[fEdge + i])][1]]);
            }

            bspdispinfo curDisp  = map.dispinfoLump [dispinfoId];
            Vector3     startPos = curDisp.startPosition;

            float dist;
            float minDist  = 0.1f;
            int   minIndex = 0;

            for (int i = 0; i < 4; i++)
            {
                dist = Vector3.Distance(startPos, vertices[i]);

                if (dist < minDist)
                {
                    minDist  = dist;
                    minIndex = i;
                }
            }

            Vector3 temp;

            for (int i = 0; i < minIndex; i++)
            {
                temp        = vertices[0];
                vertices[0] = vertices[1];
                vertices[1] = vertices[2];
                vertices[2] = vertices[3];
                vertices[3] = temp;
            }

            Vector3 leftEdge  = vertices[1] - vertices[0];
            Vector3 rightEdge = vertices[2] - vertices[3];


            int numEdgeVertices = (1 << curDisp.power) + 1;

            float subdivideScale = 1.0f / (float)(numEdgeVertices - 1);

            Vector3 leftEdgeStep  = leftEdge * subdivideScale;
            Vector3 rightEdgeStep = rightEdge * subdivideScale;

            int firstVertex = 0;

            Vector3 leftEnd;
            Vector3 rightEnd;
            Vector3 leftRightSeg;
            Vector3 leftRightStep;

            int         dispVertIndex;
            bspDispVert dispVert;

            Vector3 flatVertex;
            Vector3 dispVertex;

            float scaleU = (float)1f / curTexData.width;
            float scaleV = (float)1f / curTexData.height;

            for (int i = 0; i < numEdgeVertices; i++)
            {
                leftEnd   = leftEdgeStep * (float)i;
                leftEnd  += vertices[0];
                rightEnd  = rightEdgeStep * (float)i;
                rightEnd += vertices[3];

                leftRightSeg  = rightEnd - leftEnd;
                leftRightStep = leftRightSeg * subdivideScale;

                for (int j = 0; j < numEdgeVertices; j++)
                {
                    dispVertIndex  = curDisp.DispVertStart;
                    dispVertIndex += i * numEdgeVertices + j;
                    dispVert       = map.dispVertsLump[dispVertIndex];

                    flatVertex = leftEnd + (leftRightStep * (float)j);

                    dispVertex  = dispVert.vec * (dispVert.dist /* *scale*/);
                    dispVertex += flatVertex;

                    disp_verts.Add(dispVertex);


                    float tU = Vector3.Dot(flatVertex, curTexInfo.texvecs) + (curTexInfo.texoffs);
                    float tV = Vector3.Dot(flatVertex, curTexInfo.texvect) + (curTexInfo.texofft);
                    UVs.Add(new Vector2(tU * scaleU, tV * scaleV));

                    cols.Add(new Color32((byte)(dispVert.alpha), 0, 0, 0));
                }
            }

            int curIndex;

            for (int i = 0; i < numEdgeVertices - 1; i++)
            {
                for (int j = 0; j < numEdgeVertices - 1; j++)
                {
                    curIndex = i * numEdgeVertices + j;

                    if ((curIndex % 2) == 1)
                    {
                        curIndex += firstVertex;

                        indices.Add(curIndex + 1);
                        indices.Add(curIndex);
                        indices.Add(curIndex + numEdgeVertices);
                        indices.Add(curIndex + numEdgeVertices + 1);
                        indices.Add(curIndex + 1);
                        indices.Add(curIndex + numEdgeVertices);
                    }
                    else
                    {
                        curIndex += firstVertex;

                        indices.Add(curIndex);
                        indices.Add(curIndex + numEdgeVertices);
                        indices.Add(curIndex + numEdgeVertices + 1);
                        indices.Add(curIndex + 1);
                        indices.Add(curIndex);
                        indices.Add(curIndex + numEdgeVertices + 1);
                    }
                }
            }


            for (int i = 0; i < disp_verts.Count; i++)
            {
                disp_verts[i] *= uSrcSettings.Inst.worldScale;
            }


            surface f = new surface();

            f.index = faceIndex;
            //f.flags = flags;

            f.dispinfo = dispinfoId;

            f.points = disp_verts.ToArray();
            f.uv     = UVs.ToArray();
            //f.uv2 = UV2s;
            f.cols      = cols.ToArray();
            f.triangles = indices.ToArray();

            //f.lightMapW = lightmapW;
            //f.lightMapH = lightmapH;

            return(f);
        }