Example #1
0
    public static MCOutputData Get(List <Vector3> srcPosLst, List <Vector2> srcNorm01Lst, List <Vector2> srcNorm2tLst, int srcIdx, int len)
    {
        MCOutputData ret;

        if (len > SurfExtractorsMan.c_vertsCnt4Pool)
        {
            Vector3[] pos    = new Vector3[len];
            Vector2[] norm01 = new Vector2[len];
            Vector2[] norm2t = new Vector2[len];
            int[]     indice = new int[len];
            srcPosLst.CopyTo(srcIdx, pos, 0, len);
            srcNorm01Lst.CopyTo(srcIdx, norm01, 0, len);
            srcNorm2tLst.CopyTo(srcIdx, norm2t, 0, len);
            Array.Copy(SurfExtractorsMan.s_indiceMax, indice, len);
            ret = new MCOutputData(pos, norm01, norm2t, indice);
            return(ret);
        }
        else
        {
            ret = s_dataPool.Get();
            srcPosLst.CopyTo(srcIdx, ret._pos, 0, len);
            srcNorm01Lst.CopyTo(srcIdx, ret._norm01, 0, len);
            srcNorm2tLst.CopyTo(srcIdx, ret._norm2t, 0, len);
            if (len == SurfExtractorsMan.c_vertsCnt4Pool)
            {
                ret._indice = SurfExtractorsMan.s_indice4Pool;
            }
            else if (ret._indice == null || len != ret._indice.Length)
            {
                ret._indice = new int[len];
                Array.Copy(SurfExtractorsMan.s_indiceMax, ret._indice, len);
            }
        }
        return(ret);
    }
Example #2
0
 public void Clone(MCOutputData data)
 {
     _pos    = data._pos;
     _norm01 = data._norm01;
     _norm2t = data._norm2t;
     _indice = data._indice;
 }
Example #3
0
    public void FillOutData(List <Vector3> srcPosLst, List <Vector2> srcNorm01Lst, List <Vector2> srcNorm2tLst, int srcIdx, int len)
    {
        while (len > 0)
        {
            int          chunkVertsCurCnt = len > _nVertsPerMesh ? _nVertsPerMesh : len;
            MCOutputData data             = MCOutputData.Get(srcPosLst, srcNorm01Lst, srcNorm2tLst, srcIdx, chunkVertsCurCnt);
            _outDatas.Add(data);

            srcIdx += chunkVertsCurCnt;
            len    -= chunkVertsCurCnt;
        }
    }
Example #4
0
    public void FillOutData(Vector3[] srcPosArray, Vector2[] srcNorm01Array, Vector2[] srcNorm2tArray, int srcIdx, int len)
    {
        while (len > 0)
        {
            int          chunkVertsCurCnt = len > _nVertsPerMesh ? _nVertsPerMesh : len;
            MCOutputData data             = MCOutputData.Get(srcPosArray, srcNorm01Array, srcNorm2tArray, srcIdx, chunkVertsCurCnt);
            _outDatas.Add(data);

            srcIdx += chunkVertsCurCnt;
            len    -= chunkVertsCurCnt;
        }
    }
Example #5
0
    public static void Free(SurfExtractReqMC req)
    {
        int n = req._outDatas.Count;

        if (n > 0)
        {
            // If mesh data not been filled
            for (int i = 0; i < n; i++)
            {
                MCOutputData.Free(req._outDatas [i]);
            }
            req._outDatas.Clear();
        }
        s_reqPool.Free(req);
    }
Example #6
0
 public static void Free(MCOutputData data)
 {
     if (data._pos.Length == SurfExtractorsMan.c_vertsCnt4Pool)
     {
         s_dataPool.Free(data);
         data._indice = null;
     }
     else
     {
         data._pos    = null;
         data._norm01 = null;
         data._norm2t = null;
         data._indice = null;
     }
 }
Example #7
0
    // Delegates
    public void OnWaterDataLoad(VFVoxelChunkData chunkData, byte[] chunkDataVT, bool bFromPool)
    {
        if (chunkDataVT.Length != VFVoxel.c_VTSize || chunkDataVT[0] != c_iSurfaceVol)
        {
            // not surface chunk
            chunkData.OnDataLoaded(chunkDataVT, bFromPool);
            return;
        }

        // surface chunk
        int step = 1 << chunkData.LOD;

        if (c_fWaterLvl >= ((chunkData.ChunkPosLod.y + step) << VoxelTerrainConstants._shift))
        {
            chunkData.OnDataLoaded(VFVoxelChunkData.S_ChunkDataWaterSolid);
            return;
        }

        if (_seaSurfaceVerts[chunkData.LOD] == null)
        {
            float     fy  = (c_fWaterLvl - (chunkData.ChunkPosLod.y << VoxelTerrainConstants._shift)) / step;
            Vector3[] pos = new Vector3[4] {
                new Vector3(0.0f, fy, 0.0f),
                new Vector3(0.0f, fy, 32.0f),
                new Vector3(32.0f, fy, 0.0f),
                new Vector3(32.0f, fy, 32.0f),
            };
            Vector2[] norm01 = new Vector2[4] {
                new Vector2(), new Vector2(), new Vector2(), new Vector2(),
            };
            Vector2[] norm2t = new Vector2[4] {
                new Vector2(), new Vector2(), new Vector2(), new Vector2(),
            };
            int[] indice = new int[6] {
                0, 1, 2, 1, 3, 2
            };
            MCOutputData chunkMeshData = new MCOutputData(pos, norm01, norm2t, indice);
            _seaSurfaceVerts[chunkData.LOD] = chunkMeshData;
        }
        lock (_seaSurfaceChunkReqs)
        {
            _seaSurfaceChunkReqs.Add(SurfExtractReqMC.Get(chunkData, ProcGenSeaSurface));
        }
        // if surface chunk data not the following format, we should set it to this
        //chunkDataVT[0] = c_iSurfaceVol;
        //chunkDataVT[1] = c_iSeaWaterType;
        chunkData.SetDataVT(chunkDataVT);
    }
Example #8
0
    public int  FillMesh(Mesh mesh)
    {
        int n = _outDatas.Count;

        if (mesh == null)
        {
            return(n);
        }

        --n;
        //mesh.name       = "ocl_mesh";
        mesh.triangles = null;

        _outDatas [n].SetToMesh(mesh);
        //mesh.SetIndices(splitMeshesData[n].indice,MeshTopology.Points,0); // point sprites
        //mesh.Optimize(); --- this will down 7~8fps
        MCOutputData.Free(_outDatas[n]);
        _outDatas.RemoveAt(n);
        return(n);
    }
Example #9
0
 public void AddOutData(MCOutputData data)
 {
     _outDatas.Add(data);
 }