// Use this for initialization
    void Start()
    {
        float voxelSize = 1.0f;
        int   size      = 33;

        Array3 <Voxel> voxels = WorldGenerator.CreateVoxels(size, 0, voxelSize, Vector3.zero);
        MeshData       data   = MarchingCubes.CalculateMeshData(voxels, voxelSize);

        data.CalculateNormals();

        Mesh mesh = null;

        if (data != null)
        {
            mesh = data.CreateMesh();
        }

        ChunkObject obj = SplitManager.GetObject();

        obj.ov.shouldDraw = true;
        obj.mr.material   = mat;
        obj.mf.mesh       = mesh;


        Vector3 center = Vector3.one * (size - 1) / 2.0f;
        Bounds  area   = new Bounds(center, Vector3.one * voxelSize * (size - 1));

        obj.ov.init(0, 0, center, area, null, Color.red);
    }
Example #2
0
    void Start()
    {
        miner = GameObject.Find("Player").GetComponent <VoxelMining>();

        Array3 <Voxel> voxels = WorldGenerator.CreateVoxels(33, 0, 1.0f, Vector3.zero);
        //Array3<Voxel> voxels = WorldGenerator.CreateVoxels(64, 0, 1.0f, Vector3.zero);

        MeshData data = MarchingCubes.CalculateMeshData(voxels, 1.0f);
        Mesh     mesh = data.CreateMesh();

        go                      = SplitManager.GetObject();
        go.mr.enabled           = false;
        go.mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.TwoSided;
        go.mf.sharedMesh        = mesh;
        go.mr.material          = testMat;

        MeshData data2 = MarchingTetrahedra.CalculateMeshData(voxels, 1.0f);

        data2.CalculateSharedNormals();
        Mesh mesh2 = data2.CreateMesh();

        go2 = SplitManager.GetObject();
        go2.mf.sharedMesh        = mesh2;
        go2.mr.material          = testMat;
        go2.mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.TwoSided;
        miner.forceDrawChunk     = go2;
    }
Example #3
0
    public void SetupChunk()
    {
        obj = SplitManager.GetObject();
        //obj.go.name = GetTreeName();

        obj.go.transform.parent        = body.transform;
        obj.go.transform.localPosition = worldPos;
        obj.go.transform.localRotation = Quaternion.identity;
        //obj.go.transform.position = pos;

        obj.mr.material = body.terrainMat; // incase terrain is edited after
                                           //obj.mpb.SetVector(ShaderProps.LocalOffset, worldPos); // not sure what this was for
                                           //obj.UpdatePropBlock();

        obj.ov.init(depth, branch, worldPos, localArea, body, depth == 0 ? Color.blue : Color.red);
    }
Example #4
0
    void Start()
    {
        voxels = WorldGenerator.CreateVoxels(65, 0, 1, Vector3.zero);

        data = MarchingCubes.CalculateMeshData(voxels, 1);
        data.CalculateVertexSharing();
        data.CalculateNormals();

        simp = new Simplification(data.vertices, data.triangles);

        mesh = data.CreateMesh();

        go               = SplitManager.GetObject();
        go.mr.material   = mat;
        go.mf.sharedMesh = mesh;
    }