示例#1
0
        public bool SetVoxelCell(int x, int y, int z, VoxelCell cell)
        {
            if (this.IsValidCoord(x, y, z))
            {
                int index = GetArrayIndex(x, y, z);
                m_Data[index] = cell;
                return(true);
            }

            return(false);
        }
示例#2
0
        private void ConsiderAddingFace(Vector3Int coord, VoxelCell cell, Vector3Int normal)
        {
            Vector3Int targetCoord = coord + normal;
            VoxelCell  targetCell  = VoxelCell.Invalid;

            m_Volume.TryGetVoxelCell(targetCoord, out targetCell);

            if (m_MaterialResolver.ShouldAddFace(coord, cell, targetCoord, targetCell, out object scratch))
            {
                AddFace(coord, normal, cell, scratch);
            }
        }
示例#3
0
        public bool SetVoxelCell(int x, int y, int z, VoxelCell cell)
        {
            Vector3Int coord = new Vector3Int(x, y, z);

            if (m_Bounds.Contains(coord))
            {
                m_Data[coord] = cell;
                return(true);
            }

            return(false);
        }
示例#4
0
        private int AddVertex(Vector3Int coord, Vector3Int normal, VoxelCell cell, Vector3 offset, object scratch, out Material assignedMaterial)
        {
            VoxelVertexInput input = new VoxelVertexInput
            {
                SourceVolume = m_Volume,
                Coord        = coord,
                CoordOffset  = offset,
                Normal       = normal,
                Cell         = cell
            };

            return(AddVertex(input, scratch, out assignedMaterial));
        }
示例#5
0
            private int AddVertex(Vector3Int coord, Vector3Int normal, VoxelCell cell, Vector3 offset, out int submeshID)
            {
                VoxelVertexInput input = new VoxelVertexInput
                {
                    SourceVolume = m_Volume,
                    Coord        = coord,
                    CoordOffset  = offset,
                    Normal       = normal,
                    Cell         = cell
                };

                return(AddVertex(input, out submeshID));
            }
        public VoxelCell GetVoxelCell(int x, int y, int z)
        {
            VoxelCell cell = new VoxelCell(0);

            if (z == 0 && x >= 0 && x < m_Texture.width && y >= 0 && y < m_Texture.height)
            {
                Color32 pixel = m_Texture.GetPixel(x, y);
                cell.m_uint8_0 = pixel.r;
                cell.m_uint8_1 = pixel.g;
                cell.m_uint8_2 = pixel.b;
                cell.m_uint8_3 = pixel.a;
            }
            return(cell);
        }
        public bool SetVoxelCell(int x, int y, int z, VoxelCell cell)
        {
            Vector3Int coord = new Vector3Int(x, y, z);

            m_Data[coord] = cell;

            if (m_Data.Count == 0)
            {
                m_Bounds.SetMinMax(coord, coord);
            }
            else
            {
                m_Bounds.min = Vector3Int.Min(m_Bounds.min, coord);
                m_Bounds.max = Vector3Int.Max(m_Bounds.max, coord);
            }

            return(true);
        }
示例#8
0
 public StaticArrayVoxelVolume(BoundsInt bounds, VoxelCell missingValue)
 {
     m_Data   = new VoxelCell[(bounds.size.x + 1) * (bounds.size.y + 1) * (bounds.size.z + 1)];
     m_Bounds = bounds;
     m_DefaultMissingValue = missingValue;
 }
示例#9
0
        public static bool TryGetVoxelCell(this IVoxelVolume volume, Vector3Int coord, out VoxelCell value)
        {
            Assert.Message(volume.IsVolumeReadable(), "TryGetVoxelCell being called on non-readable volume");
            if (volume.IsValidCoord(coord))
            {
                value = volume.GetVoxelCell(coord.x, coord.y, coord.z);
                return(true);
            }

            value = VoxelCell.Invalid;
            return(false);
        }
示例#10
0
        public static bool TryGetVoxelCell(this IVoxelVolume volume, int x, int y, int z, out VoxelCell value)
        {
            Assert.Message(volume.IsVolumeReadable(), "TryGetVoxelCell being called on non-readable volume");
            if (volume.IsValidCoord(x, y, z))
            {
                value = volume.GetVoxelCell(x, y, z);
                return(true);
            }

            value = VoxelCell.Invalid;
            return(false);
        }
示例#11
0
 public static bool SetVoxelCell(this IVoxelVolume volume, Vector3Int coord, VoxelCell cell)
 {
     return(volume.SetVoxelCell(coord.x, coord.y, coord.z, cell));
 }
示例#12
0
 public bool SetVoxelCell(int x, int y, int z, VoxelCell cell)
 {
     return(m_Source.SetVoxelCell(x, y, z, cell));
 }
 public bool SetVoxelCell(int x, int y, int z, VoxelCell cell)
 {
     throw new System.NotImplementedException();
 }
示例#14
0
 public bool ShouldAddFace(Vector3Int fromCoord, VoxelCell fromCell, Vector3Int toCoord, VoxelCell toCell)
 {
     return(fromCell != toCell);
 }
示例#15
0
        private void AddFace(Vector3Int coord, Vector3Int normal, VoxelCell cell, object scratch)
        {
            int      sign = 0;
            int      i0   = -1;
            int      i1   = -1;
            int      i2   = -1;
            int      i3   = -1;
            Material m0   = null;
            Material m1   = null;
            Material m2   = null;
            Material m3   = null;

            // Add left/right
            if (normal.x != 0)
            {
                sign = normal.x >= 0 ? 1 : -1;

                i0 = AddVertex(coord, normal, cell, new Vector3(1 * sign, 1, 1) * 0.5f, scratch, out m0);
                i1 = AddVertex(coord, normal, cell, new Vector3(1 * sign, 1, -1) * 0.5f, scratch, out m1);
                i2 = AddVertex(coord, normal, cell, new Vector3(1 * sign, -1, 1) * 0.5f, scratch, out m2);
                i3 = AddVertex(coord, normal, cell, new Vector3(1 * sign, -1, -1) * 0.5f, scratch, out m3);
            }

            // Add top/bottom
            if (normal.y != 0)
            {
                sign = normal.y >= 0 ? 1 : -1;

                i0 = AddVertex(coord, normal, cell, new Vector3(1, 1 * sign, 1) * 0.5f, scratch, out m0);
                i1 = AddVertex(coord, normal, cell, new Vector3(-1, 1 * sign, 1) * 0.5f, scratch, out m1);
                i2 = AddVertex(coord, normal, cell, new Vector3(1, 1 * sign, -1) * 0.5f, scratch, out m2);
                i3 = AddVertex(coord, normal, cell, new Vector3(-1, 1 * sign, -1) * 0.5f, scratch, out m3);
            }

            // Add front/back
            else if (normal.z != 0)
            {
                sign = normal.z >= 0 ? 1 : -1;

                i0 = AddVertex(coord, normal, cell, new Vector3(-1, 1, 1 * sign) * 0.5f, scratch, out m0);
                i1 = AddVertex(coord, normal, cell, new Vector3(1, 1, 1 * sign) * 0.5f, scratch, out m1);
                i2 = AddVertex(coord, normal, cell, new Vector3(-1, -1, 1 * sign) * 0.5f, scratch, out m2);
                i3 = AddVertex(coord, normal, cell, new Vector3(1, -1, 1 * sign) * 0.5f, scratch, out m3);
            }

            Assert.Format(m0 == m1 && m0 == m2 && m0 == m3, "Material doesn't match for each face ({0}, {1}, {2}, {3})", m0, m1, m2, m3);
            List <int> triangleIndices;

            if (!m_Intermediate.SubmeshTriangleIndices.TryGetValue(m0, out triangleIndices))
            {
                triangleIndices = new List <int>();
                m_Intermediate.SubmeshTriangleIndices.Add(m0, triangleIndices);
            }

            if (sign == 1)
            {
                triangleIndices.Add(i0);
                triangleIndices.Add(i2);
                triangleIndices.Add(i1);

                triangleIndices.Add(i2);
                triangleIndices.Add(i3);
                triangleIndices.Add(i1);
            }
            else
            {
                triangleIndices.Add(i0);
                triangleIndices.Add(i1);
                triangleIndices.Add(i2);

                triangleIndices.Add(i2);
                triangleIndices.Add(i1);
                triangleIndices.Add(i3);
            }
        }
 public DynamicVoxelVolume(VoxelCell missingValue)
 {
     m_Data = new Dictionary <Vector3Int, VoxelCell>();
     m_DefaultMissingValue = missingValue;
 }
 public DynamicVoxelVolume()
 {
     m_Data = new Dictionary <Vector3Int, VoxelCell>();
     m_DefaultMissingValue = VoxelCell.Invalid;
 }
示例#18
0
 public bool ShouldConsiderForModel(Vector3Int coord, VoxelCell cell)
 {
     return(cell != VoxelCell.Invalid);
 }
示例#19
0
 public StaticDictionaryVoxelVolume(BoundsInt bounds, VoxelCell missingValue)
 {
     m_Data   = new Dictionary <Vector3Int, VoxelCell>();
     m_Bounds = bounds;
     m_DefaultMissingValue = missingValue;
 }