Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEditor;
- using System.Collections;
- public class VoxTerrain{
- public static int width = 10;
- public static int height = 10;
- public static int depth = 10;
- public float cubesize = 1;
- public float[,,] terrainarray = new float[width,height,depth];
- public GameObject terrain = new GameObject("Terrain");
- public VoxTerrain(){
- }
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- }
- public void GenerateEmpty(){
- terrain.transform.position=new Vector3(0,0,0);
- for(int x = 0; x < width; x++){
- for(int y = 0; y < height; y++){
- for(int z = 0; z < height; z++){
- terrainarray[x,y,z]=0F;
- }
- }
- }
- for(int x = 0; x < width; x++){
- for(int y = 0; y < height-5; y++){
- for(int z = 0; z < height; z++){
- terrainarray[x,y,z]=1F;
- }
- }
- }
- RenderCubes();
- }
- void MakeTriangles(){
- for(int x = 0; x < width; x++){
- for(int y = 0; y < height; y++){
- for(int z = 0; z < height; z++){
- }
- }
- }
- }
- void addnewcube(){
- //Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- }
- void RenderCubes(){
- for(int x = 0; x < width; x++){
- //CombineInstance[] combine = new CombineInstance[width*height*depth];
- for(int y = 0; y < height; y++){
- for(int z = 0; z < height; z++){
- if(terrainarray[x,y,z]==1){
- /*if(terrainarray[x+1,y,z]==0 || terrainarray[x,y+1,z]==0 || terrainarray[x,y,z+1]==0
- ||terrainarray[x+1,y+1,z]==0 || terrainarray[x,y+1,z+1]==0 || terrainarray[x+1,y,z+1]==0 || terrainarray[x+1,y+1,z+1]==0||terrainarray[x-1,y,z]==0 || terrainarray[x,y-1,z]==0 || terrainarray[x,y,z-1]==0||terrainarray[x-1,y-1,z]==0 || terrainarray[x,y-1,z+1]==0 || terrainarray[x-1,y,z+1]==0 || terrainarray[x-1,y-1,z-1]==0){*/
- GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
- cube.transform.position = new Vector3(x*cubesize,y*cubesize,z*cubesize);
- cube.transform.parent = terrain.transform;
- //MeshFilter meshfilter = cube.GetComponent<MeshFilter>();
- //meshfilter.sharedMesh.CombineMeshes(combine);
- //}
- }
- }
- }
- }
- }
- void RenderTriangle(Vector3 x, Vector3 y, Vector3 z){
- GL.PushMatrix();
- GL.Begin(GL.TRIANGLES);
- GL.Vertex3(x.x,x.y,x.z);
- GL.Vertex3(y.x,y.y,y.z);
- GL.Vertex3(z.x,z.y,z.z);
- GL.End();
- GL.PopMatrix();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment