Пример #1
0
    /// <summary>
    /// Returns the voxel using Unity's (z, y, x) coordinates.
    /// </summary>
    /// <returns>
    /// The voxel byte, indicating material number.
    /// </returns>
    /// <param name='unityZ'>
    /// Z.
    /// </param>
    /// <param name='unityY'>
    /// Y.
    /// </param>
    /// <param name='unityX'>
    /// X.
    /// </param>
    public byte VoxelAt(int unityX, int unityY, int unityZ)
    {
        if (!m_blob.IsValidPoint(unityX, unityY, unityZ))
        {
            return(0);
        }

        return(m_blob[unityX, unityY, unityZ]);
    }
Пример #2
0
    IEnumerator GenColorFacesFromBlob(VoxelBlob blob)
    {
        float currentProgress = 0;
        float maxProgress     = blob.width * blob.height * blob.depth;

        loadProgress = 0;

        int3 minVals = new int3(0, 0, 0);
        int3 maxVals = new int3(blob.width, blob.height, blob.depth);

        if (blob.minVoxelBounds.x != -1)
        {
            minVals = blob.minVoxelBounds;
            maxVals = blob.maxVoxelBounds;
        }

        multicolorFaces = new List <List <Face> >();

        for (int mat = 1; mat < 5; mat++)
        {
            faces = new List <Face>();
            for (int x = minVals.x; x < maxVals.x; ++x)
            {
                for (int y = minVals.y; y < maxVals.y; ++y)
                {
                    for (int z = minVals.z; z < maxVals.z; ++z)
                    {
                        if (Scheduler.ShouldYield())
                        {
                            yield return(null);
                        }
                        if (blob[x, y, z] != mat)
                        {
                            continue;
                        }

                        //figure out if each face is a surface face
                        Vector3 block = new Vector3(x, y, z);
                        for (int dim = 0; dim < 3; ++dim)
                        {
                            for (int dir = -1; dir < 2; dir += 2)
                            {
                                Vector3 neighbor = block;
                                neighbor[dim] += dir;
                                bool onSurface = true;
                                if (blob.IsValidPoint((int)neighbor.x, (int)neighbor.y, (int)neighbor.z) &&
                                    blob[(int)neighbor.x, (int)neighbor.y, (int)neighbor.z] == mat)
                                {
                                    onSurface = false;
                                }

                                if (onSurface)
                                {
                                    int axis1 = (dir < 0 ? (dim + 2) % 3 : (dim + 1) % 3);
                                    int axis2 = (dir < 0 ? (dim + 1) % 3 : (dim + 2) % 3);

                                    Vector3 p0;
                                    if (dir < 0)
                                    {
                                        p0 = block;
                                    }
                                    else
                                    {
                                        p0 = block + Vector3.one;
                                    }

                                    Vector3 p1 = p0;
                                    p1[axis1] -= dir;
                                    Vector3 p2 = p0;
                                    p2[axis2] -= dir;
                                    Face face = new Face(p0, p1, p2);
                                    face.Init();
                                    faces.Add(face);
                                    Vector3 p3 = p1;
                                    p3[axis2] -= dir;
                                    face       = new Face(p3, p2, p1);
                                    face.Init();
                                    faces.Add(face);
                                }
                            }
                        }
                    }
                }
                currentProgress += blob.height * blob.depth;
                loadProgress     = currentProgress / maxProgress;
            }
            multicolorFaces.Add(faces);
        }

        m_loaded = true;
    }
Пример #3
0
    IEnumerator GenFacesFromBlob(VoxelBlob blob)
    {
        float currentProgress = 0;
        float maxProgress     = blob.width * blob.height * blob.depth;

        loadProgress = 0;

        faces = new List <Face>();
        for (int x = 0; x < blob.width; ++x)
        {
            for (int y = 0; y < blob.height; ++y)
            {
                for (int z = 0; z < blob.depth; ++z)
                {
                    if (Scheduler.ShouldYield())
                    {
                        yield return(null);
                    }
                    if (blob[x, y, z] == MeshManager.kVoxelEmpty)
                    {
                        continue;
                    }

                    //figure out if each face is a surface face
                    Vector3 block = new Vector3(x, y, z);
                    for (int dim = 0; dim < 3; ++dim)
                    {
                        for (int dir = -1; dir < 2; dir += 2)
                        {
                            Vector3 neighbor = block;
                            neighbor[dim] += dir;
                            bool onSurface = true;
                            if (blob.IsValidPoint((int)neighbor.x, (int)neighbor.y, (int)neighbor.z) &&
                                blob[(int)neighbor.x, (int)neighbor.y, (int)neighbor.z] != MeshManager.kVoxelEmpty)
                            {
                                onSurface = false;
                            }

                            if (onSurface)
                            {
                                int axis1 = (dir < 0 ? (dim + 2) % 3 : (dim + 1) % 3);
                                int axis2 = (dir < 0 ? (dim + 1) % 3 : (dim + 2) % 3);

                                Vector3 p0;
                                if (dir < 0)
                                {
                                    p0 = block;
                                }
                                else
                                {
                                    p0 = block + Vector3.one;
                                }

                                Vector3 p1 = p0;
                                p1[axis1] -= dir;
                                Vector3 p2 = p0;
                                p2[axis2] -= dir;
                                Face face = new Face(p0, p1, p2);
                                face.Init();
                                faces.Add(face);
                                Vector3 p3 = p1;
                                p3[axis2] -= dir;
                                face       = new Face(p3, p2, p1);
                                face.Init();
                                faces.Add(face);
                            }
                        }
                    }
                }
            }
            currentProgress += blob.height * blob.depth;
            loadProgress     = currentProgress / maxProgress;
        }
        MoveFacesToOrigin();
        m_loaded = true;
    }