Пример #1
0
    private void Awake()
    {
        if (DataName == "")
        {
            return;
        }
        m_Go = new GameObject("Chunk");
        m_Go.Reset();

        try
        {
            m_Header = MTFileUtils.LoadQuadTreeHeader(DataName);

            m_Root = new MTQuadTreeNode(m_Header.QuadTreeDepth, m_Header.BoundMin, m_Header.BoundMax, Vector3.zero);
            foreach (var mh in m_Header.Meshes.Values)
            {
                m_Root.AddMesh(mh);
            }
            int gridMax = 1 << m_Header.QuadTreeDepth;               //1<< X 相当于 2的X次方
            mVisiblePatches = new MTArray <uint>(gridMax * gridMax); //(int)Mathf.Pow(2, 2 * m_Header.QuadTreeDepth)

            if (lodPolicy.Length < m_Header.LOD)
            {
                float[] policy = new float[m_Header.LOD];
                for (int i = 0; i < lodPolicy.Length; ++i)
                {
                    policy[i] = lodPolicy[i];
                }
                lodPolicy = policy;
            }
            lodPolicy[0] = Mathf.Clamp(lodPolicy[0], 0.5f * m_Root.Bound.size.x / gridMax, lodPolicy[0]);
            lodPolicy[lodPolicy.Length - 1] = float.MaxValue;
        }
        catch
        {
            m_Header = null;
            m_Root   = null;
            Debug.LogError("MTLoader load quadtree header failed");
        }

        m_Camera = GetComponent <Camera>();
    }
Пример #2
0
 private void Awake()
 {
     if (DataName == "")
     {
         return;
     }
     try
     {
         mHeader = MTFileUtils.LoadQuadTreeHeader(DataName);
         mRoot   = new MTQuadTreeNode(mHeader.QuadTreeDepth, mHeader.BoundMin, mHeader.BoundMax);
         foreach (var mh in mHeader.Meshes.Values)
         {
             mRoot.AddMesh(mh);
         }
         int gridMax = 1 << mHeader.QuadTreeDepth;
         mVisiblePatches = new MTArray <uint>(gridMax * gridMax);
         if (lodPolicy.Length < mHeader.LOD)
         {
             float[] policy = new float[mHeader.LOD];
             for (int i = 0; i < lodPolicy.Length; ++i)
             {
                 policy[i] = lodPolicy[i];
             }
             lodPolicy = policy;
         }
         lodPolicy[0] = Mathf.Clamp(lodPolicy[0], 0.5f * mRoot.Bound.size.x / gridMax, lodPolicy[0]);
         lodPolicy[lodPolicy.Length - 1] = float.MaxValue;
     }
     catch
     {
         mHeader = null;
         mRoot   = null;
         MTLog.LogError("MTLoader load quadtree header failed");
     }
     mCamera = GetComponent <Camera>();
 }