Exemplo n.º 1
0
    public TreeInfo AddTreeInfo(Vector3 wpos, int prototype, float wScale, float hScale)
    {
        TreeInfo ti = TreeInfo.GetTI();

        ti.m_clr          = Color.white;
        ti.m_lightMapClr  = Color.white;
        ti.m_widthScale   = wScale;
        ti.m_heightScale  = hScale;
        ti.m_protoTypeIdx = prototype;
        ti.m_pos          = LSubTerrUtils.TreeWorldPosToTerrainPos(wpos);
        return(AddTreeInfo(ti));
    }
    private void PlantAVegetation(int startX, int startZ, int iX, int iZ, int iScl, VoxelPaintXML.PlantDescCLS[] pVeges, float[][] tileHeightBuf, float posVar,
                                  List <TreeInfo> outlstTreeInfo)
    {
        float fx = iX + ((float)myRand.NextDouble() - 0.5f) * posVar; if (fx < 0)
        {
            return;
        }
        float fz = iZ + ((float)myRand.NextDouble() - 0.5f) * posVar; if (fz < 0)
        {
            return;
        }
        int   ix = (int)(fx + 0.5f) + VoxelTerrainConstants._numVoxelsPrefix;
        int   iz = (int)(fz + 0.5f) + VoxelTerrainConstants._numVoxelsPrefix;
        float fy = tileHeightBuf[iz][ix]; if (fy < 4.0f)
        {
            return;                                             //minHeight
        }
        int nVegesTypes = pVeges.Length;
        int idxVegeType = 0;
        int rand100     = myRand.Next(100);

        for (; idxVegeType < nVegesTypes && pVeges[idxVegeType].pct < rand100; idxVegeType++)
        {
            ;
        }
        if (idxVegeType >= nVegesTypes)
        {
            return;
        }

        /* Now there are very few legacy grasses , so we ignore the following code.
         * float rad = tileGradBuf[iz][ix];
         * if (rad > noVegeRad0)
         *  return;
         * if ((rad - fadeVegeRad0) > (float)myRand.NextDouble() * fadeRangeRad0)
         *  return;
         */

        TreeInfo _treeinfo = TreeInfo.GetTI();

        _treeinfo.m_clr          = Color.white;
        _treeinfo.m_lightMapClr  = Color.white;
        _treeinfo.m_protoTypeIdx = pVeges[idxVegeType].idx;
        _treeinfo.m_pos          = new Vector3(fx * iScl + startX, fy, fz * iScl + startZ);
        _treeinfo.m_heightScale  = pVeges[idxVegeType].hScaleMin + (float)(myRand.NextDouble()) * (pVeges[idxVegeType].hScaleMax - pVeges[idxVegeType].hScaleMin);
        _treeinfo.m_widthScale   = pVeges[idxVegeType].wScaleMin + (float)(myRand.NextDouble()) * (pVeges[idxVegeType].wScaleMax - pVeges[idxVegeType].wScaleMin);
        //_treeinfo.m_heightScale = 1;
        //_treeinfo.m_widthScale = 1;
        outlstTreeInfo.Add(_treeinfo);
    }
Exemplo n.º 3
0
    public void ApplyData(byte[] data, int len)
    {
        //_dataLen = len;
        if (len <= 0)
        {
            m_FinishedProcess = true;
            return;
        }

        TreeInfo tmpTi;

        #region READING_DATA
        //Profiler.BeginSample("AddTreeInfo");
        using (MemoryStream ms = new MemoryStream(data))
        {
            //IntVector3 tmpTreePos = IntVector3.Zero;
            BinaryReader br      = new BinaryReader(ms);
            int          mapSize = br.ReadInt32();
            for (int i = 0; i != mapSize; ++i)
            {
                br.ReadInt32();
                br.ReadInt32();
                br.ReadInt32();
                int _listSize = br.ReadInt32();
                for (int j = 0; j != _listSize; ++j)
                {
                    tmpTi                 = TreeInfo.GetTI();
                    tmpTi.m_clr.r         = br.ReadSingle();
                    tmpTi.m_clr.g         = br.ReadSingle();
                    tmpTi.m_clr.b         = br.ReadSingle();
                    tmpTi.m_clr.a         = br.ReadSingle();
                    tmpTi.m_heightScale   = br.ReadSingle();
                    tmpTi.m_lightMapClr.r = br.ReadSingle();
                    tmpTi.m_lightMapClr.g = br.ReadSingle();
                    tmpTi.m_lightMapClr.b = br.ReadSingle();
                    tmpTi.m_lightMapClr.a = br.ReadSingle();
                    tmpTi.m_pos.x         = br.ReadSingle();
                    tmpTi.m_pos.y         = br.ReadSingle();
                    tmpTi.m_pos.z         = br.ReadSingle();
                    tmpTi.m_protoTypeIdx  = br.ReadInt32();
                    tmpTi.m_widthScale    = br.ReadSingle();

                    AddTreeInfo(tmpTi);
                }
            }
            br.Close();
            ms.Close();
        }
        //Profiler.EndSample();

        // cutting deleted tree recorded in saved data
        //Profiler.BeginSample("CutRecordedTree");
        List <Vector3> lstDelPos;
        if (LSubTerrSL.m_mapDelPos.TryGetValue(Index, out lstDelPos))
        {
            int nDelPos = lstDelPos.Count;
            for (int i = 0; i < nDelPos; i++)
            {
                Vector3 delpos = lstDelPos [i];
                _tmpVec3.x = Mathf.FloorToInt(delpos.x);
                _tmpVec3.y = Mathf.FloorToInt(delpos.y);
                _tmpVec3.z = Mathf.FloorToInt(delpos.z);
                int tmpKey = LSubTerrUtils.TreePosToKey(_tmpVec3);
                if (m_mapTrees.TryGetValue(tmpKey, out tmpTi))
                {
                    tmpTi = tmpTi.FindTi(delpos);
                    if (tmpTi != null)
                    {
                        TreeInfo secondFoot = DeleteTreeInfo(tmpTi);
                        if (secondFoot != null)
                        {
                            DeleteTreeInfo(secondFoot);
                        }
                    }
                }
            }
        }
        //Profiler.EndSample();
        #endregion

        #region ASSIGN_LAYERS
        //Profiler.BeginSample("AssignLayer");
        List <LSubTerrLayerOption> layers       = LSubTerrainMgr.Instance.Layers;
        List <TreeInfo> []         layers_trees = new List <TreeInfo> [layers.Count];
        for (int l = layers.Count - 1; l >= 0; --l)
        {
            layers_trees[l] = new List <TreeInfo> ();
        }
        foreach (TreeInfo ti in m_listTrees)
        {
            float height = LSubTerrainMgr.Instance.GlobalPrototypeBounds[ti.m_protoTypeIdx].extents.y * 2F;
            for (int l = layers.Count - 1; l >= 0; --l)
            {
                // Trees in this layer
                if (layers[l].MinTreeHeight <= height && height < layers[l].MaxTreeHeight)
                {
                    layers_trees[l].Add(ti);
                    break;
                }
            }
        }
        for (int l = layers.Count - 1; l >= 0; --l)
        {
            LSubTerrainMgr.Instance.LayerCreators[l].AddTreeBatch(Index, layers_trees[l]);
        }
        //Profiler.EndSample();
        #endregion

        m_FinishedProcess = true;
    }
Exemplo n.º 4
0
    private TreeInfo AddTreeInfo(TreeInfo ti)
    {
        // Tree place holder works
        if (ti.m_protoTypeIdx == LSubTerrainMgr.TreePlaceHolderPrototypeIndex ||
            ti.m_pos.x < 0.00001 || ti.m_pos.z < 0.00001 || ti.m_pos.x > 0.99999 || ti.m_pos.z > 0.99999)               // Avoid bugs
        {
            TreeInfo.FreeTI(ti);
            return(null);
        }

        // Add to tree map
        _tmpVec3.x = Mathf.FloorToInt(ti.m_pos.x * LSubTerrConstant.SizeF);
        _tmpVec3.y = Mathf.FloorToInt(ti.m_pos.y * LSubTerrConstant.HeightF);
        _tmpVec3.z = Mathf.FloorToInt(ti.m_pos.z * LSubTerrConstant.SizeF);
        int      tmpKey = LSubTerrUtils.TreePosToKey(_tmpVec3);
        TreeInfo tmpTi;

        if (m_mapTrees.TryGetValue(tmpKey, out tmpTi))
        {
            tmpTi.AttachTi(ti);
        }
        else
        {
            m_mapTrees.Add(tmpKey, ti);
        }

        // Add to tree list
        m_listTrees.Add(ti);
        // Add to 32 tree map
        if (LSubTerrainMgr.HasCollider(ti.m_protoTypeIdx) || LSubTerrainMgr.HasLight(ti.m_protoTypeIdx))
        {
            tmpKey = LSubTerrUtils.TreeWorldPosTo32Key(LSubTerrUtils.TreeTerrainPosToWorldPos(X, Z, ti.m_pos));
            List <TreeInfo> tmpTis;
            if (!LSubTerrainMgr.Instance.m_map32Trees.TryGetValue(tmpKey, out tmpTis))
            {
                tmpTis = new List <TreeInfo>();
                LSubTerrainMgr.Instance.m_map32Trees.Add(tmpKey, tmpTis);
            }
            tmpTis.Add(ti);
        }

        // Tree place holder works
        LTreePlaceHolderInfo tphinfo = LSubTerrainMgr.GetTreePlaceHolderInfo(ti.m_protoTypeIdx);

        if (tphinfo != null)
        {
            TreeInfo tph = TreeInfo.GetTI();
            tph.m_clr         = Color.white;
            tph.m_heightScale = tphinfo.m_HeightScale * ti.m_heightScale;
            tph.m_lightMapClr = Color.white;
            Vector3 tphoffset = tphinfo.TerrOffset;
            tphoffset.x       *= ti.m_widthScale;
            tphoffset.y       *= ti.m_heightScale;
            tphoffset.z       *= ti.m_widthScale;
            tph.m_pos          = ti.m_pos + tphoffset;
            tph.m_protoTypeIdx = LSubTerrainMgr.TreePlaceHolderPrototypeIndex;
            tph.m_widthScale   = tphinfo.m_WidthScale * ti.m_widthScale;

            // Add to tree map
            _tmpVec3.x = Mathf.FloorToInt(tph.m_pos.x * LSubTerrConstant.SizeF);
            _tmpVec3.y = Mathf.FloorToInt(tph.m_pos.y * LSubTerrConstant.HeightF);
            _tmpVec3.z = Mathf.FloorToInt(tph.m_pos.z * LSubTerrConstant.SizeF);
            tmpKey     = LSubTerrUtils.TreePosToKey(_tmpVec3);
            if (m_mapTrees.TryGetValue(tmpKey, out tmpTi))
            {
                tmpTi.AttachTi(tph);
            }
            else
            {
                m_mapTrees.Add(tmpKey, tph);
            }

            // Add to tree list
            m_listTrees.Add(tph);
            m_mapTwoFeetTrees.Add(tph, ti);
            m_mapTwoFeetTrees.Add(ti, tph);
        }
        return(ti);
    }