Пример #1
0
 public OctreeNode BuildSeamTree(List <OctreeNode> seamNodes, Vector3 eMin, int size)
 {
     return(tree.ConstructUpwards(seamNodes, eMin, size));
 }
    protected override void ThreadFunction()
    {
        if (i_Tree != null && i_Count > 0 && i_VoxMins.Length > 0 && i_VoxMaterials.Length > 0 && i_Voxs.Length > 0 && i_Size != 0)
        {
            List <OctreeNode> computedVoxels = new List <OctreeNode>();


            int HIGHEST_VOXEL_RES = 64;
            int voxelSize         = HIGHEST_VOXEL_RES / i_Size;
            for (int i = 0; i < i_Count; i++)
            {
                if (i_Voxs[i].numPoints != 0)
                {
                    OctreeNode leaf = new OctreeNode();
                    leaf.type = OctreeNodeType.Node_Leaf;
                    leaf.size = voxelSize;
                    OctreeDrawInfo drawInfo = new OctreeDrawInfo();
                    drawInfo.position      = i_Voxs[i].vertPoint;
                    drawInfo.averageNormal = i_Voxs[i].avgNormal;
                    drawInfo.corners       = (int)i_VoxMaterials[i];
                    leaf.drawInfo          = drawInfo;
                    leaf.min = i_VoxMins[i];
                    computedVoxels.Add(leaf);
                }
            }

            //Debug.Log(computedVoxels.Count);

            if (computedVoxels.Count > 0)
            {
                if (updatingChunk && chunkToUpdate != null)
                {
                    chunkToUpdate.DestroyOctree();
                }
                m_Root = i_Tree.ConstructUpwards(computedVoxels, i_Min, HIGHEST_VOXEL_RES);
                if (m_Root != null)
                {
                    i_Tree.GenerateMeshFromOctree(m_Root, m_Vertices, m_Normals, m_Indices, voxelSize);
                }
            }

            //m_Vertices.TrimExcess();
            //m_Normals.TrimExcess();
            //m_Indices.TrimExcess();

            computedVoxels.Clear();
            computedVoxels = null;

            i_Min   = Vector3.zero;
            i_Size  = 0;
            i_Count = 0;
            i_Tree  = null;
            //Array.Clear(i_VoxMins, 0, i_VoxMins.Length);
            i_VoxMins = null;
            //Array.Clear(i_VoxMaterials, 0, i_VoxMaterials.Length);
            i_VoxMaterials = null;
            //Array.Clear(i_Voxs, 0, i_Voxs.Length);
            i_Voxs = null;

            //Debug.Log ("Finished loading chunk");

            if (!updatingChunk)
            {
                m_Test.informGame();
            }

            if (updatingChunk)
            {
                m_Test.informGame(chunkToUpdate);
                chunkToUpdate = null;
                updatingChunk = false;
            }
        }
    }