Exemplo n.º 1
0
 private bool ShouldPutFace(int x, int y, int z, int dx, int dy, int dz)
 {
     if (!m_Data.GetVoxel(x, y, z).IsEmpty)
     {
         return(m_Data.GetVoxel(x + dx, y + dy, z + dz).IsEmpty);
     }
     return(false);
 }
Exemplo n.º 2
0
    private void SpawnDebris(VoxelObject sourceData, VoxelData data, Vector3 position, Quaternion rotation, Vector3 sprayDirection, int skip)
    {
        int counter = 0;

        for (int x = 0; x < data.Width; ++x)
        {
            for (int y = 0; y < data.Height; ++y)
            {
                for (int z = 0; z < data.Depth; ++z)
                {
                    Voxel voxel = data.GetVoxel(x, y, z);

                    if (!voxel.IsEmpty && ((++counter) % skip) == 0)
                    {
                        Color colour = m_AtlasTexture.GetPixel((int)voxel.m_ColourIndex - 1, 0);

                        VoxelDebris debris = VoxelDebris.NewDebris(m_DebrisType, sourceData, voxel, m_DebrisLifetime, position + rotation * data.GetVoxelPosition(x, y, z, sourceData.m_Scale), rotation);

                        debris.SetColour(colour);
                        debris.ApplyExplostion(m_ExplosiveForce, position, sprayDirection);
                    }
                }
            }
        }
    }
        public override CullingFaces BuildCulling(ref VoxelData d, int x, int y, int z)
        {
            var r = CullingFaces.All;

            if (!d.GetVoxel(x + 1, y, z).IsSolid)
            {
                r -= CullingFaces.East;
            }
            if (!d.GetVoxel(x - 1, y, z).IsSolid)
            {
                r -= CullingFaces.West;
            }
            if (!d.GetVoxel(x, y, z - 1).IsSolid)
            {
                r -= CullingFaces.South;
            }
            if (!d.GetVoxel(x, y, z + 1).IsSolid)
            {
                r -= CullingFaces.North;
            }
            if (!d.GetVoxel(x, y - 1, z).IsSolid)
            {
                r -= CullingFaces.Down;
            }
            if (!d.GetVoxel(x, y + 1, z).IsSolid)
            {
                r -= CullingFaces.Up;
            }

            return(r);
        }
Exemplo n.º 4
0
        public ThreadableMesh Build(VoxelData voxels)
        {
            int vCount        = 0,
                tCount        = 0,
                cCount        = 0,
                nCount        = 0,
                uvCount       = 0,
                uv2Count      = 0,
                lastTrisIndex = 0;


            _vBuffer.Clear();
            _tBuffer.Clear();
            _cBuffer.Clear();
            _uvBuffer.Clear();
            _uv2Buffer.Clear();
            _nBuffer.Clear();


            for (int z = 0; z < voxels.Depth; z++)
            {
                for (int y = 0; y < voxels.Height; y++)
                {
                    for (int x = 0; x < voxels.Width; x++)
                    {
                        var voxel = voxels.GetVoxel(x, y, z);
                        if (!voxel.IsSolid)
                        {
                            continue;
                        }

                        var mask = _cull.BuildCulling(ref voxels, x, y, z);

                        if (mask == CullingFaces.All)
                        {
                            continue;
                        }

                        CopyToBuffer(
                            ref _vBuffer, ref vCount,
                            _verts.BuildVertices(ref vCount, ref mask, ref voxel, x, y, z));

                        CopyToBuffer(
                            ref _tBuffer, ref tCount,
                            _tris.BuildTrianlges(ref tCount, ref mask, ref voxel, ref lastTrisIndex, x, y, z));

                        if (_config.GenerateUV)
                        {
                            CopyToBuffer(
                                ref _uvBuffer, ref uvCount,
                                _uvs.BuildUV(ref uvCount, ref mask, ref voxel, x, y, z));
                        }

                        if (_config.GenerateColors)
                        {
                            CopyToBuffer(
                                ref _cBuffer, ref cCount,
                                _colors.BuildColors(ref cCount, ref mask, ref voxel, x, y, z));
                        }

                        if (_config.GenerateNormals)
                        {
                            CopyToBuffer(
                                ref _nBuffer, ref nCount,
                                _normals.BuildNormals(ref nCount, ref mask, ref voxel, x, y, z));
                        }

                        if (_config.GenerateUV2)
                        {
                            CopyToBuffer(
                                ref _uv2Buffer, ref uv2Count,
                                _uv2s.BuildUV2(ref uv2Count, ref mask, ref voxel, x, y, z));
                        }
                    }
                }
            }

            var mesh = new ThreadableMesh();

            CopyFromBuffer(ref _vBuffer, ref vCount, ref mesh.Vertices);
            CopyFromBuffer(ref _tBuffer, ref tCount, ref mesh.Triangles);

            if (_config.GenerateUV)
            {
                CopyFromBuffer(ref _uvBuffer, ref uvCount, ref mesh.Uvs);
            }

            if (_config.GenerateColors)
            {
                CopyFromBuffer(ref _cBuffer, ref cCount, ref mesh.Colors);
            }

            if (_config.GenerateNormals)
            {
                CopyFromBuffer(ref _nBuffer, ref nCount, ref mesh.Normals);
            }

            if (_config.GenerateUV2)
            {
                CopyFromBuffer(ref _uv2Buffer, ref uv2Count, ref mesh.Uvs1);
            }

            if (_config.GenerateTangents)
            {
                mesh.RecalculateTangets();
            }

            return(mesh);
        }