コード例 #1
0
ファイル: InputController.cs プロジェクト: xdray/CubeWorld
        protected void OnLButtonClicked()
        {
            Vector3 MousePos = Input.mousePosition;

            RaycastHit RayHit;
            Ray MouseRay = Camera.main.ScreenPointToRay(MousePos);

            if (Physics.Raycast(MouseRay, out RayHit))
            {
                LogMgr.Log(string.Format("{0},{1},{2}", RayHit.point.x, RayHit.point.y, RayHit.point.z));
                //Tree2 tree = ObjMgr.Create<Tree2>();
                //tree.gameObj.transform.localScale = new Vector3(40.0f, 40.0f, 40.0f);
                //tree.gameObj.transform.position = new Vector3(RayHit.point.x, RayHit.point.y, RayHit.point.z);

                Vector3 Pos = RayHit.point;
                Pos += (MouseRay.direction * ((float)(Global.CubeSize) * 0.5f));

                VoxelCoord vc = new VoxelCoord();
                Helper.W2VoxelCoord(Pos, vc);

                CubeTerrain.Instance.ModifyVoxel(vc, VoxelType.Air);

                LogMgr.Log(string.Format("{0},{1},{2}", vc.X, vc.Y, vc.Z));
            }
        }
コード例 #2
0
ファイル: CubeTerrain.cs プロジェクト: xdray/CubeWorld
        public void ModifyVoxel(VoxelCoord vc, VoxelType newtype)
        {
            VoxelType oldtype = Global.VoxelsData[vc];
            Global.VoxelsData[vc] = newtype;

            ChunksTree.BuildAndUpdateChunk(vc);
        }
コード例 #3
0
    /// <summary>
    /// Function to sort observable voxels.null It compares the posibilities of each voxel.
    /// </summary>
    private int CompareObservableVoxels(VoxelCoord x, VoxelCoord y)
    {
        if (_voxelPosibilites[x.x, x.y, x.z].nValidIndexes == _voxelPosibilites[y.x, y.y, y.z].nValidIndexes)
        {
            return(0);
        }

        if (_voxelPosibilites[x.x, x.y, x.z].nValidIndexes > _voxelPosibilites[y.x, y.y, y.z].nValidIndexes)
        {
            return(1);
        }

        return(-1);
    }
コード例 #4
0
ファイル: ChunkTree.cs プロジェクト: xdray/CubeWorld
 public void BuildAndUpdateChunk(VoxelCoord vc)
 {
     __BuildAndUpdateChunk(vc.X, vc.Y, vc.Z, true);
     CombineMeshes();
 }
コード例 #5
0
 public void RemoveVoxel(VoxelCoord vc)
 {
     RemoveVoxel(vc.X, vc.Y, vc.Z);
 }
コード例 #6
0
 public VoxelType this[VoxelCoord vc]
 {
     get { return this[vc.X, vc.Y, vc.Z]; }
     set { this[vc.X, vc.Y, vc.Z] = value; }
 }
コード例 #7
0
ファイル: Chunk.cs プロジェクト: xdray/CubeWorld
 public bool IsContain(VoxelCoord vc)
 {
     return IsContain(vc.X, vc.Y, vc.Z);
 }
コード例 #8
0
    /// <summary>
    /// Generates a map based on the Wave Function Collapse Algotithm
    /// https://github.com/mxgmn/WaveFunctionCollapse
    /// </summary>
    protected override void Generate()
    {
        // Build propagator

        _voxelPosibilites = new BitMemory[_sizeX + 1, _sizeY + 1, _sizeZ + 1];

        // init DP memory
        for (int i = 0; i < _sizeX + 1; i++)
        {
            for (int j = 0; j < _sizeY + 1; j++)
            {
                for (int k = 0; k < _sizeZ + 1; k++)
                {
                    _voxelPosibilites[i, j, k] = new BitMemory(_pieces.Count);
                }
            }
        }



        // start generation, all not-assigned spaces have the value -1
        List <VoxelCoord> observableVoxels = new List <VoxelCoord>();

        for (int j = 0; j < _sizeY + 1; j++)
        {
            for (int k = 1; k < _sizeZ + 1; k++)
            {
                for (int i = 1; i < _sizeX + 1; i++)
                {
                    EvaluateTilePossibilities(i, j, k);
                    VoxelCoord vc = new VoxelCoord();
                    vc.x = i;
                    vc.y = j;
                    vc.z = k;
                    observableVoxels.Add(vc);
                }
            }
        }

        observableVoxels.Sort(CompareObservableVoxels);

        bool isContradiction;

        // do
        // {
        isContradiction = false;

        while (observableVoxels.Count > 0)
        {
            // Lowest entropy voxel
            VoxelCoord cVx = observableVoxels[0];

            if (_voxelPosibilites[cVx.x, cVx.y, cVx.z].nValidIndexes == 0)
            {
                Debug.Log("Oops");
                Debug.Log(cVx.x + "|" + cVx.y + "|" + cVx.z);
                isContradiction = true;
                break;
            }
            else
            {
                Debug.Log("Non-Oops");
                // Choose random possibility
                Map[cVx.x, cVx.y, cVx.z] = Random.Range(0, _voxelPosibilites[cVx.x, cVx.y, cVx.z].nValidIndexes);
                Map[cVx.x, cVx.y, cVx.z] = _voxelPosibilites[cVx.x, cVx.y, cVx.z].ValidIndexes[Map[cVx.x, cVx.y, cVx.z]];

                // Update neighboards entropy
                observableVoxels.RemoveAt(0);
                if (cVx.x < _sizeX)
                {
                    EvaluateTilePossibilities(cVx.x + 1, cVx.y, cVx.z);
                }
                if (cVx.x > 1)
                {
                    EvaluateTilePossibilities(cVx.x - 1, cVx.y, cVx.z);
                }
                if (cVx.y < _sizeY)
                {
                    EvaluateTilePossibilities(cVx.x, cVx.y + 1, cVx.z);
                }
                if (cVx.y > 0)
                {
                    EvaluateTilePossibilities(cVx.x, cVx.y - 1, cVx.z);
                }
                if (cVx.z < _sizeZ)
                {
                    EvaluateTilePossibilities(cVx.x, cVx.y, cVx.z + 1);
                }
                if (cVx.z > 1)
                {
                    EvaluateTilePossibilities(cVx.x, cVx.y, cVx.z - 1);
                }

                observableVoxels.Sort(CompareObservableVoxels);
            }
        }
        // } while (isContradiction);

        // for (int j = 0; j < _sizeY+1; j++)
        // {
        //     for (int k = 1; k < _sizeZ+1; k++)
        //     {
        //         for (int i = 1; i < _sizeX+1; i++)
        //         {
        //             if (_map[i,j,k] > 0)
        //                 continue;

        //             EvaluateTilePossibilities(i,j,k);
        //             List<int> possibilities = _voxelPosibilites[i,j,k].ValidIndexes;

        //             if (possibilities.Count == 0)
        //             {
        //                 Debug.Log("Oops");

        //             }
        //             else
        //             {
        //                 _map[i,j,k] = possibilities[Random.Range(0, possibilities.Count)];
        //             }

        //         }
        //     }
        // }
    }