Example #1
0
        public void Free()
        {
            if (data != null)
            {
                data.Free();
                data = null;
            }

            RGPoolSig.Destroy();
        }
Example #2
0
        public void Init()
        {
            RedGrassInstance.Init();

            data = new RGDataSource();
            data.Init(evniAsset, dataIO);

            RGPoolSig.Init();

            // Render Part Init
            mTree = new RGLODQuadTree(evniAsset);
        }
Example #3
0
        public void Dirty(RGDataSource data, bool dirty)
        {
            int expand = 1 << LOD;

            for (int x = xIndex; x < xIndex + expand; x++)
            {
                for (int z = zIndex; z < zIndex + expand; z++)
                {
                    RGChunk gc = data.Node(x, z);
                    if (gc != null)
                    {
                        gc.Dirty = dirty;
                    }
                }
            }
        }
Example #4
0
        public bool IsDirty(RGDataSource data)
        {
            int expand = 1 << LOD;

            for (int x = xIndex; x < xIndex + expand; x++)
            {
                for (int z = zIndex; z < zIndex + expand; z++)
                {
                    RGChunk gc = data.Node(x, z);
                    if (gc != null && gc.Dirty)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #5
0
        public List <RGChunk> GetChunks(RGDataSource data)
        {
            List <RGChunk> gc_list = new List <RGChunk>();

            int expand = 1 << LOD;


            for (int x = xIndex; x < xIndex + expand; x++)
            {
                for (int z = zIndex; z < zIndex + expand; z++)
                {
                    RGChunk gc = data.Node(x, z);

                    if (gc == null)
                    {
                        continue;
                    }
                    gc_list.Add(gc);
                }
            }

            return(gc_list);
        }
Example #6
0
        public GameObject ComputeNow(RGLODQuadTreeNode node, RGDataSource data, float density)
        {
            try
            {
                List <RGChunk> chunks = node.GetChunks(data);

                if (chunks == null)
                {
                    return(null);
                }

                foreach (RGChunk ck in chunks)
                {
                    foreach (KeyValuePair <int, RedGrassInstance> kvp in ck.grasses)
                    {
                        if (kvp.Value.Layer == 0)
                        {
                            _grasses.Add(kvp.Value);
                        }
                        else
                        {
                            _triGrasses.Add(kvp.Value);
                        }

                        if (ck.HGrass.ContainsKey(kvp.Key))
                        {
                            foreach (RedGrassInstance rgi in ck.HGrass[kvp.Key])
                            {
                                if (rgi.Layer == 0)
                                {
                                    _grasses.Add(rgi);
                                }
                                else
                                {
                                    _triGrasses.Add(rgi);
                                }
                            }
                        }
                    }
                }

                RedGrassMeshComputer.ComputeMesh(_grasses, _triGrasses, density);
                _grasses.Clear();
                _triGrasses.Clear();

                // Get Billboard output struct
                OutputGroup opg = new OutputGroup();

                int billboardCnt = RedGrassMeshComputer.s_Output.BillboardCount;
                int offsetCnt    = 0;

                while (billboardCnt > 0)
                {
                    int       cnt      = Mathf.Min(billboardCnt, mEvni.MeshQuadMaxCount);
                    Vector3[] verts    = new Vector3[cnt * 4];
                    Vector3[] norms    = new Vector3[cnt * 4];
                    Vector2[] uvs      = new Vector2[cnt * 4];
                    Vector2[] uv2s     = new Vector2[cnt * 4];
                    Color32[] colors32 = new Color32[cnt * 4];
                    int[]     indices  = new int[cnt * 6];

                    System.Array.Copy(RedGrassMeshComputer.s_Output.Verts, offsetCnt * 4, verts, 0, cnt * 4);
                    System.Array.Copy(RedGrassMeshComputer.s_Output.Norms, offsetCnt * 4, norms, 0, cnt * 4);
                    System.Array.Copy(RedGrassMeshComputer.s_Output.UVs, offsetCnt * 4, uvs, 0, cnt * 4);
                    System.Array.Copy(RedGrassMeshComputer.s_Output.UV2s, offsetCnt * 4, uv2s, 0, cnt * 4);
                    System.Array.Copy(RedGrassMeshComputer.s_Output.Color32s, offsetCnt * 4, colors32, 0, cnt * 4);
                    System.Array.Copy(RedGrassMeshComputer.s_Output.Indices, indices, cnt * 6);

                    opg.billboard.mVerts.Add(verts);
                    opg.billboard.mNorms.Add(norms);
                    opg.billboard.mUVs.Add(uvs);
                    opg.billboard.mUV2s.Add(uv2s);
                    opg.billboard.mColors32.Add(colors32);
                    opg.billboard.mIndices.Add(indices);

                    billboardCnt = billboardCnt - mEvni.MeshQuadMaxCount;
                    offsetCnt   += mEvni.MeshQuadMaxCount;
                }

                // Get Tri-Angel output struct
                int triCnt = RedGrassMeshComputer.s_Output.TriquadCount;
                offsetCnt = RedGrassMeshComputer.s_Output.BillboardCount;

                while (triCnt > 0)
                {
                    int cnt = Mathf.Min(triCnt, mEvni.MeshQuadMaxCount);

                    Vector3[] verts    = new Vector3[cnt * 4];
                    Vector3[] norms    = new Vector3[cnt * 4];
                    Vector2[] uvs      = new Vector2[cnt * 4];
                    Vector2[] uv2s     = new Vector2[cnt * 4];
                    Color32[] colors32 = new Color32[cnt * 4];
                    int[]     indices  = new int[cnt * 6];

                    System.Array.Copy(RedGrassMeshComputer.s_Output.Verts, offsetCnt * 4, verts, 0, cnt * 4);
                    System.Array.Copy(RedGrassMeshComputer.s_Output.Norms, offsetCnt * 4, norms, 0, cnt * 4);
                    System.Array.Copy(RedGrassMeshComputer.s_Output.UVs, offsetCnt * 4, uvs, 0, cnt * 4);
                    System.Array.Copy(RedGrassMeshComputer.s_Output.UV2s, offsetCnt * 4, uv2s, 0, cnt * 4);
                    System.Array.Copy(RedGrassMeshComputer.s_Output.Color32s, offsetCnt * 4, colors32, 0, cnt * 4);
                    System.Array.Copy(RedGrassMeshComputer.s_Output.Indices, indices, cnt * 6);

                    opg.tri.mVerts.Add(verts);
                    opg.tri.mNorms.Add(norms);
                    opg.tri.mUVs.Add(uvs);
                    opg.tri.mUV2s.Add(uv2s);
                    opg.tri.mColors32.Add(colors32);
                    opg.tri.mIndices.Add(indices);

                    triCnt     = triCnt - mEvni.MeshQuadMaxCount;
                    offsetCnt += mEvni.MeshQuadMaxCount;
                }

                string     desc = "Grass Batch [" + node.xIndex.ToString() + ", " + node.zIndex.ToString() + "] _ LOD [" + node.LOD + "]";
                GameObject go   = CreateBatchGos(desc, opg.billboard, opg.tri);
                node.gameObject = go;

                if (go != null)
                {
                    go.transform.parent        = transform;
                    go.transform.localPosition = Vector3.zero;

                    if (go.activeSelf != node.visible)
                    {
                        go.SetActive(node.visible);
                    }
                }

                return(go);
            }
            catch
            {
                return(null);
            }
        }
Example #7
0
 public void Init(EvniAsset evni, RGDataSource data)
 {
     base.Init(evni);
     mData = data;
 }