private QuadtreeTerrain terrain = null;            //  terrain

        //	mins, maxs: aadd in local space
        public QuadtreeMesh(QuadtreeTerrain _trn, int _nodeIdx, Vector3 mins, Vector3 maxs)
        {
            terrain   = _trn;
            nodeIndex = _nodeIdx;
            aabb      = new Bounds();
            aabb.SetMinMax(mins, maxs);
        }
        public Quadtree(QuadtreeTerrain _trn, int _hmSize)
        {
            Debug.Assert(Misc.Is2Power(_hmSize - 1));

            terrain = _trn;
            hmSize  = _hmSize;

            //	create node buffer
            AllocateNodeBuffer();

            //	Initialize root node
            root            = nodeBuf[0];
            root.index      = 0;
            root.hmLeft     = 0;
            root.hmTop      = 0;
            root.hmAreaSize = (ushort)(_hmSize - 1);

            //	Generate tree recursively
            int nodeTempCnt = 1;

            BuildNode_r(0, (sbyte)eChildPos.POS_INVALID, ref nodeTempCnt);

            //	check node number
            Debug.Assert(nodeTempCnt == (int)nodeNum);

            //	Build neighbours info
            BuildNeighbours_r(0);
        }
        public TerrainRendererDefault(QuadtreeTerrain _trn)
        {
            terrain      = _trn;
            drawDataList = new List <DRAWDATA>(256);

            //	load materials
            mtlDefault           = new Material(terrain.GetDefaultShader());
            mtlDefault.hideFlags = HideFlags.DontSave;

            defMtlProp = new MaterialPropertyBlock();
            defMtlProp.SetColor("lodColor", new Color(1.0f, 1.0f, 1.0f, 1.0f));

            //	Create lod material property block
            Action <Color> CreateLODMtlProp = (Color lodColor) =>
            {
                MaterialPropertyBlock prop = new MaterialPropertyBlock();
                prop.SetColor("lodColor", lodColor);
                lodMtlProps.Add(prop);
            };

            //	LOD grade color table
            lodMtlProps = new List <MaterialPropertyBlock>(maxLODCount);
            CreateLODMtlProp(new Color(1.0f, 0.5f, 0.5f, 1.0f));
            CreateLODMtlProp(new Color(0.5f, 1.0f, 0.5f, 1.0f));
            CreateLODMtlProp(new Color(0.5f, 0.5f, 1.0f, 1.0f));
            CreateLODMtlProp(new Color(1.0f, 1.0f, 0.0f, 1.0f));
            CreateLODMtlProp(new Color(0.0f, 1.0f, 1.0f, 1.0f));
            CreateLODMtlProp(new Color(0.75f, 0.0f, 0.0f, 1.0f));
            CreateLODMtlProp(new Color(0.0f, 0.75f, 0.0f, 1.0f));
            CreateLODMtlProp(new Color(0.0f, 0.0f, 0.75f, 1.0f));
            CreateLODMtlProp(new Color(1.0f, 0.75f, 0.0f, 1.0f));
            CreateLODMtlProp(new Color(0.0f, 1.0f, 0.75f, 1.0f));
            CreateLODMtlProp(new Color(0.5f, 0.0f, 0.0f, 1.0f));
            CreateLODMtlProp(new Color(0.0f, 0.5f, 0.0f, 1.0f));
            CreateLODMtlProp(new Color(0.0f, 0.0f, 0.5f, 1.0f));
            CreateLODMtlProp(new Color(1.0f, 0.5f, 0.0f, 1.0f));
            CreateLODMtlProp(new Color(0.0f, 1.0f, 0.5f, 1.0f));
            CreateLODMtlProp(new Color(0.5f, 0.5f, 0.5f, 1.0f));
        }
 public QuadtreeMeshMan(QuadtreeTerrain _trn)
 {
     terrain   = _trn;
     meshTable = new Hashtable(256);
 }
Example #5
0
        public TerrainRes(QuadtreeTerrain _trn)
        {
            terrain = _trn;

            //	Create index buffers for nodes rendering with inborn LOD grade
            int gridWidth = terrain.leafGridSize;
            int vertPitch = gridWidth + 1;

            //	create comuter buffer
            Func <List <int>, ComputeBuffer> CreateCB = (List <int> ib) =>
            {
                ComputeBuffer cb = new ComputeBuffer(ib.Count, 4);
                cb.SetData(ib.ToArray());
                return(cb);
            };

            idxBufs[(int)eIndexBuf.IB_NO_LOD] = CreateIndexBuffer(gridWidth, vertPitch, 0, 0);
            idxBufs[(int)eIndexBuf.IB_LOD_L]  = CreateIndexBuffer(gridWidth, vertPitch, 0, (int)eSideFlag.LEFT);
            idxBufs[(int)eIndexBuf.IB_LOD_T]  = CreateIndexBuffer(gridWidth, vertPitch, 0, (int)eSideFlag.TOP);
            idxBufs[(int)eIndexBuf.IB_LOD_R]  = CreateIndexBuffer(gridWidth, vertPitch, 0, (int)eSideFlag.RIGHT);
            idxBufs[(int)eIndexBuf.IB_LOD_B]  = CreateIndexBuffer(gridWidth, vertPitch, 0, (int)eSideFlag.BOTTOM);
            idxBufs[(int)eIndexBuf.IB_LOD_LT] = CreateIndexBuffer(gridWidth, vertPitch, 0, (int)eSideFlag.LEFT | (int)eSideFlag.TOP);
            idxBufs[(int)eIndexBuf.IB_LOD_RT] = CreateIndexBuffer(gridWidth, vertPitch, 0, (int)eSideFlag.RIGHT | (int)eSideFlag.TOP);
            idxBufs[(int)eIndexBuf.IB_LOD_LB] = CreateIndexBuffer(gridWidth, vertPitch, 0, (int)eSideFlag.LEFT | (int)eSideFlag.BOTTOM);
            idxBufs[(int)eIndexBuf.IB_LOD_RB] = CreateIndexBuffer(gridWidth, vertPitch, 0, (int)eSideFlag.RIGHT | (int)eSideFlag.BOTTOM);

            for (int i = 0; i < (int)eIndexBuf.COUNT; i++)
            {
                ComputeBuffer cb = CreateCB(idxBufs[i]);
                idxCBs.Add(cb);
            }

            //	Create index buffer for nodes LOD grade-up rendering (use parent's LOD)
            int halfGridWidth = gridWidth >> 1;

            Debug.Assert(halfGridWidth > 0);
            //	Base index of child's left-top corner in it's parent's node mesh
            int[] baseIdx = new int[4]
            {
                0,
                halfGridWidth,
                halfGridWidth *vertPitch,
                halfGridWidth *vertPitch + halfGridWidth
            };

            for (int i = 0; i < 4; i++)
            {
                int ltbase = baseIdx[i];

                gradeUpIdxBufs[i] = new List <int> [(int)eIndexBuf.COUNT];

                gradeUpIdxBufs[i][(int)eIndexBuf.IB_NO_LOD] = CreateIndexBuffer(halfGridWidth, vertPitch, ltbase, 0);
                gradeUpIdxBufs[i][(int)eIndexBuf.IB_LOD_L]  = CreateIndexBuffer(halfGridWidth, vertPitch, ltbase, (int)eSideFlag.LEFT);
                gradeUpIdxBufs[i][(int)eIndexBuf.IB_LOD_T]  = CreateIndexBuffer(halfGridWidth, vertPitch, ltbase, (int)eSideFlag.TOP);
                gradeUpIdxBufs[i][(int)eIndexBuf.IB_LOD_R]  = CreateIndexBuffer(halfGridWidth, vertPitch, ltbase, (int)eSideFlag.RIGHT);
                gradeUpIdxBufs[i][(int)eIndexBuf.IB_LOD_B]  = CreateIndexBuffer(halfGridWidth, vertPitch, ltbase, (int)eSideFlag.BOTTOM);
                gradeUpIdxBufs[i][(int)eIndexBuf.IB_LOD_LT] = CreateIndexBuffer(halfGridWidth, vertPitch, ltbase, (int)eSideFlag.LEFT | (int)eSideFlag.TOP);
                gradeUpIdxBufs[i][(int)eIndexBuf.IB_LOD_RT] = CreateIndexBuffer(halfGridWidth, vertPitch, ltbase, (int)eSideFlag.RIGHT | (int)eSideFlag.TOP);
                gradeUpIdxBufs[i][(int)eIndexBuf.IB_LOD_LB] = CreateIndexBuffer(halfGridWidth, vertPitch, ltbase, (int)eSideFlag.LEFT | (int)eSideFlag.BOTTOM);
                gradeUpIdxBufs[i][(int)eIndexBuf.IB_LOD_RB] = CreateIndexBuffer(halfGridWidth, vertPitch, ltbase, (int)eSideFlag.RIGHT | (int)eSideFlag.BOTTOM);

                gradeUpIdxCBs[i] = new List <ComputeBuffer>((int)eIndexBuf.COUNT);
                for (int j = 0; j < (int)eIndexBuf.COUNT; j++)
                {
                    ComputeBuffer cb = CreateCB(gradeUpIdxBufs[i][j]);
                    gradeUpIdxCBs[i].Add(cb);
                }
            }
        }
Example #6
0
 public GeometryBuilder(QuadtreeTerrain _trn)
 {
     terrain  = _trn;
     hsLayers = new List <IHeightStream>();
     tempMesh = new TEMPMESH();
 }