Ejemplo n.º 1
0
 void UpdateVisualChunk(VoxelMesh vm)
 {
     if (vm != null && vm.needsRegen)
     {
         vm.RegenerateVisualMesh(voxelScale);
         --m_needsRegenCount;
     }
 }
Ejemplo n.º 2
0
    /// <summary>
    /// Loads the visual chunks as soon as it can fit them in without ruining framerates.
    /// </summary>
    /// <returns>
    /// The visual chunks.
    /// </returns>
    public IEnumerator LoadVisualChunks()
    {
        int colEnd   = Mathf.CeilToInt(((float)m_blob.width / (float)chunkSize) * voxelScale);
        int layerEnd = Mathf.CeilToInt(((float)m_blob.height / (float)chunkSize) * voxelScale);
        int rowEnd   = Mathf.CeilToInt(((float)m_blob.depth / (float)chunkSize) * voxelScale);

        Text.Log("Making the visual cache size: {0}x{1}x{2}", colEnd, layerEnd, rowEnd);
        m_visualCacheSize.x = colEnd;
        m_visualCacheSize.y = layerEnd;
        m_visualCacheSize.z = rowEnd;

        m_visualCache = new VoxelMesh[colEnd, layerEnd, rowEnd];

        VoxelMesh.manager       = this;
        VoxelMesh.voxelScale    = voxelScale;
        VoxelMesh.layer         = (int)Mathf.Log(voxelLayer.value, 2);
        VoxelMesh.blockMaterial = voxelMaterial;

        for (int aLayer = 0; aLayer < layerEnd; ++aLayer)
        {
            for (int aRow = 0; aRow < rowEnd; ++aRow)
            {
                for (int aCol = 0; aCol < colEnd; ++aCol)
                {
                    Vector3 meshPosition = new Vector3(aCol, aLayer, aRow)
                                           * (float)chunkSize / voxelScale;

                    VoxelMesh chunkMesh = new VoxelMesh(meshPosition);
                    m_visualCache[aCol, aLayer, aRow] = chunkMesh;
                    chunkMesh.RegenerateVisualMesh(voxelScale);

                    if (Scheduler.ShouldYield())
                    {
                        yield return(null);
                    }
                }
            }
        }
    }