예제 #1
0
 public Neighbor(bool _exists, bool _generated, Vector3Int _location, IVoxelBuilder _controller)
 {
     Exists      = _exists;
     generated   = _generated;
     pagePositon = _location;
     controller  = _controller;
 }
예제 #2
0
 public void Close()
 {
     _destroyed = true;
     if (builder != null)
     {
         builder.Dispose();
         builder         = null;
         builderInstance = null;
     }
 }
예제 #3
0
    public IVoxelBuilder GetBuilder(int x, int y, int z)
    {
        IVoxelBuilder result   = null;
        Vector3Int    location = new Vector3Int(x, y, z);

        if (BuilderExists(x, y, z))
        {
            result = Chunks[new Vector3Int(x, y, z)].builder;
        }
        return(result);
    }
예제 #4
0
 public void createChunkBuilder()
 {
     builder = new SmoothVoxelBuilder(TerrainController.Instance,
                                      chunkPosition,
                                      VoxelSettings.voxelsPerMeter,
                                      VoxelSettings.MeterSizeX,
                                      VoxelSettings.MeterSizeY,
                                      VoxelSettings.MeterSizeZ);
     builder.SetBlockTypes(TerrainController.Instance.BlocksArray, TerrainController.Instance.AtlasUvs);
     builderInstance = (SmoothVoxelBuilder)builder;
 }
예제 #5
0
    public IVoxelBuilder GetBuilder(int x, int y, int z)
    {
        IVoxelBuilder result   = null;
        Vector3Int    location = new Vector3Int(x, y, z);

        if (BuilderExists(x, y, z))
        {
            result = Chunks[location].builder;
        }
        return(result);
    } // needs to be changed if using superchunks.
예제 #6
0
    public IVoxelBuilder GetBuilder(int x, int y, int z)
    {
        IVoxelBuilder result = null;

        try {
            Vector3Int location = new Vector3Int(x, y, z);
            if (BuilderExists(x, y, z))
            {
                result = Chunks[new Vector3Int(x, y, z)].builder;
            }
        }
        catch (KeyNotFoundException e) {
            return(result);
        }
        return(result);
    }
예제 #7
0
 private void Setpage(int index, Vector3Int pageLoc)
 {
     if (controller.BuilderExists(pageLoc.x, pageLoc.y, pageLoc.z))
     {
         IVoxelBuilder _builder = controller.GetBuilder(pageLoc.x, pageLoc.y, pageLoc.z);
         if (_builder != null)
         {
             neighbors[index] = new Neighbor(true, controller.BuilderGenerated(pageLoc.x, pageLoc.y, pageLoc.z), pageLoc, _builder);
         }
         else
         {
             neighbors[index] = new Neighbor(false, false, pageLoc, null);
         }
     }
     else
     {
         neighbors[index] = new Neighbor(false, false, pageLoc, null);
     }
 }
예제 #8
0
 private void Setpage(int index, Vector3Int pageLoc)
 {
     if (controller.BuilderExists(pageLoc.x, pageLoc.y, pageLoc.z))
     {
         IVoxelBuilder _builder = controller.GetBuilder(pageLoc.x, pageLoc.y, pageLoc.z);
         if (_builder != null)
         {
             neighbors[index] = new Neighbor(true, controller.BuilderGenerated(pageLoc.x, pageLoc.y, pageLoc.z), pageLoc, _builder);
         }
         else
         {
             SafeDebug.LogError("Controller says chunk builder exists, but chunk builder is null!.");
             neighbors[index] = new Neighbor(false, false, pageLoc, null);
         }
     }
     else
     {
         neighbors[index] = new Neighbor(false, false, pageLoc, null);
     }
 }
예제 #9
0
 public void Init(Vector3Int chunkPos, Vector3 worldPos, IModule module, IPageController controller, int lodLevel, SmoothVoxelBuilder smoothBuilder)
 {
     editQueue          = new List <BlockChange>();
     _lockObj           = new object();
     surface            = new List <Vector3Int>();
     chunkPosition      = chunkPos;
     surfaceModule      = module;
     LODlevel           = lodLevel;
     oldLODlevel        = lodLevel;
     pageController     = controller;
     transform.position = worldPos;
     transform.parent   = controller.getGameObject().transform;
     globalPosition     = transform.position;
     _renderer          = gameObject.GetComponent <MeshRenderer>();
     _filter            = gameObject.GetComponent <MeshFilter>();
     _collider          = gameObject.GetComponent <MeshCollider>();
     //_renderer.material.SetTexture("_MainTex", TerrainController.Instance.textureAtlas);
     //_player = TerrainController.Instance.player;
     builderInstance = smoothBuilder;
     builder         = smoothBuilder;
 }
예제 #10
0
    public GridPoint GetVector4(Vector3 world, Vector3Int local, Vector3Int global, bool generate)
    {
        //Vector3 origin = new Vector3(ChunkSizeX / 2, ChunkSizeY / 2, ChunkSizeX / 2);
        //return new Vector4(world.x, world.y, world.z, Vector3.Distance(origin, world));
        GridPoint result = default(GridPoint);

        Vector3Int chunk = VoxelConversions.VoxelToChunk(global);
        uint       type;

        if (generate)
        {
            if (IsInBounds(local.x, local.y, local.z))
            {
                result = new GridPoint(world.x, world.y, world.z, (float)GetIsoValue(local, global, generate, out type), type);
            }
            else
            {
                result = new GridPoint(world.x, world.y, world.z, (float)Sampler.GetIsoValue(local, global, out type), type);

                //result = new GridPoint(world.x, world.y, world.z, 100);

                /*Vector3Int chunklocalVoxel = VoxelConversions.GlobalToLocalChunkCoord(chunk, global);
                 * SmoothVoxelBuilder builder = (SmoothVoxelBuilder)controller.GetBuilder(chunk.x, chunk.y, chunk.z);
                 * if (builder != null)
                 * {
                 *  result = new GridPoint(world.x, world.y, world.z, (float)builder.Sampler.GetIsoValue(local, global, out type), type);
                 * }
                 * else
                 * {
                 *  //result = new GridPoint(world.x, world.y, world.z, (float)Sampler.GetIsoValue(chunklocalVoxel, global, out type), type);
                 *  result = new GridPoint(world.x, world.y, world.z, (float)Sampler.GetIsoValue(local, global, out type), type);
                 * }*/
            }
        }
        else
        {
            if (chunk != location)
            {
                Vector3Int    chunklocalVoxel = VoxelConversions.GlobalToLocalChunkCoord(chunk, global);
                IVoxelBuilder builder         = controller.GetBuilder(chunk.x, chunk.y, chunk.z);
                if (builder != null)
                {
                    Block builderBlock = builder.GetBlock(chunklocalVoxel.x, chunklocalVoxel.y, chunklocalVoxel.z);
                    result = new GridPoint(world.x, world.y, world.z, (float)builderBlock.iso, builderBlock.type);
                }
                else
                {
                    result = new GridPoint(world.x, world.y, world.z, (float)Sampler.GetIsoValue(chunklocalVoxel, global, out type));
                }
            }
            else
            {
                result = new GridPoint(world.x, world.y, world.z, (float)GetIsoValue(local, global, generate, out type), (byte)type);
            }
        }

        result.OriginLocal  = local;
        result.OriginGlobal = global;

        return(result);
    }
예제 #11
0
 public void Close()
 {
     builder.Dispose();
     builder         = null;
     builderInstance = null;
 }