Suche gute Minecraft Kopie mit erweiterungs Tutorials?

Mp28pa

Lieutenant
Registriert
März 2014
Beiträge
726
Hallo Leute

Es gibt einige Minecraft Kopien in Unity und UE4, doch welche ist davon am besten? Vorhandene Tutorials über custom Blöcke wäre auch sehr gut.

Kennt ihr da gute?
 
Java hat ne .... Performance, würd es mit Lichteffekten, 4k textures etc modden.Wie gut das auf der Java version läuft wisst ihr ja wahrscheinlich.
 
Aber nicht wirklich modbar bzw noch keine Tutorials gesehen
 
Wen du magst lade ich dir meine kleine Voxel Engine für unity3d hoch.
Ist undokommentiert und simple dafür kannst damit machen was du willst falls du dich zurecht findest.
 

Anhänge

  • tmp_10685-terrain543047385.jpg
    tmp_10685-terrain543047385.jpg
    207,6 KB · Aufrufe: 216
Zespire schrieb:
Wen du magst lade ich dir meine kleine Voxel Engine für unity3d hoch.
Ist undokommentiert und simple dafür kannst damit machen was du willst falls du dich zurecht findest.

Das wär echt nett :D Bitte mach das, hoffe ich versteh deinen Code xD
 
Sollte so bei dir laufen im Anhang ist noch eine Textur.


Code:
using UnityEngine;
using System.Collections.Generic;
using System.Threading;

public class Main : MonoBehaviour 
{
	//unity settings
	public Material material;
	public int chunkWidth = 32;
	public int chunkHeight = 32;
	public int chunkDepth = 32;
	public int worldWidth = 256;
	public int worldHeight = 64;
	public int worldDepth = 256;
	public bool saveMap = false;

	private Chunk[,,] chunks;
	private TerrainMeshGenerator tmg;

	void Start () 
	{

		tmg = new TerrainMeshGenerator ();
		chunks = new Chunk[worldWidth / chunkWidth,worldHeight / chunkHeight,worldDepth / chunkDepth];

		for (int x = 0; x < worldWidth / chunkWidth; x ++) 
			for (int y = 0; y < worldHeight / chunkHeight; y ++) 
				for (int z = 0; z < worldDepth / chunkDepth; z ++) 
					chunks [x ,y ,z ] = new Chunk (new Vector3(chunkWidth,chunkHeight,chunkDepth),new Vector3(x*chunkWidth,y * chunkHeight,z*chunkDepth));
 
		for (int x = 0; x < worldWidth; x ++)
			for (int y = 0; y < worldHeight; y ++)
				for (int z = 0; z < worldDepth; z ++) 
			{
				if(Mathf.PerlinNoise (x/80.0f,  z/80.0f) * 68 < y)
					continue;

				int chunkPosX = x / chunkWidth;
				int chunkPosY = y / chunkHeight;
				int chunkPosZ = z / chunkDepth;
				
				chunks[chunkPosX,chunkPosY,chunkPosZ].WorldData[x - chunkPosX * chunkWidth,y - chunkPosY * chunkHeight,z - chunkPosZ * chunkDepth] = 1;
				chunks[chunkPosX,chunkPosY,chunkPosZ].NeedUpdate = true;
			}
	}


	private void AddTerrainBlock(Chunk _chunk,int _positionX,int _positionZ, int _terrainID )
	{
		_chunk.WorldData[_positionX,0,_positionZ] = _terrainID;
		_chunk.NeedUpdate = true;
	}

	private void RemoveTerrainBlock(Chunk _chunk,int _positionX,int _positionZ)
	{
		_chunk.WorldData[_positionX,0,_positionZ] = 0;
		_chunk.NeedUpdate = true;
	}
		
	void Update () 
	{
		foreach (Chunk chunk in chunks) 
		{
			if(chunk == null)
				return;
			if (chunk.NeedUpdate)
			{
				chunk.SetMesh (tmg.GenerateMesh (chunk.WorldData, chunk.Position,(int) chunk.Size.x,(int) chunk.Size.y,(int) chunk.Size.z));
				chunk.NeedUpdate = false;
				chunk.IsEmpty = false;
			}
			if (!chunk.IsEmpty)
				Graphics.DrawMesh (chunk.Mesh, Vector3.zero, Quaternion.identity, material, 0);
		}
	}
}

Code:
using System;
using UnityEngine;
using System.Collections;

public class Chunk
{
	private Mesh mesh;
	private bool isEmpty;
	private bool needUpdate;
	private int[,,] worldData;
	private Vector3 size;
	private Vector3 position;
//	private List<GameObject> worldObjects;

	public Chunk(Vector3 _size, Vector3 _position) 
	{
		isEmpty = true;
		needUpdate = false;
		size = _size;
		position = _position;
		worldData = new int[(int)_size.x,(int)_size.y,(int)_size.z];
	}

	public Chunk(Vector3 _size, Vector3 _position, int[,,] _worldData) 
	{
		isEmpty = true;
		needUpdate = true;
		size = _size;
		position = _position;
		worldData = _worldData;
	}

	public void AddMesh(Vector3[] _vertices,Vector3[] _normals,int[] _faces, Vector2[] _uvCoordinates)
	{
		//vertices
		Array.Resize (ref _vertices, mesh.vertices.Length + _vertices.Length);
		Array.ConstrainedCopy (mesh.vertices, 0,_vertices , _vertices.Length - mesh.vertices.Length, mesh.vertices.Length);
		mesh.vertices = _vertices;
		//normals
		Array.Resize (ref _normals, mesh.normals.Length + _normals.Length);
		Array.ConstrainedCopy (mesh.normals, 0,_normals , _normals.Length - mesh.normals.Length, mesh.normals.Length);
		mesh.normals = _normals;
		//faces
		Array.Resize (ref _faces, mesh.triangles.Length + _faces.Length);
		Array.ConstrainedCopy (mesh.triangles, 0,_faces , _faces.Length - mesh.triangles.Length, mesh.triangles.Length);
		mesh.triangles = _faces;
		//uvCoordinates
		Array.Resize (ref _uvCoordinates, mesh.uv.Length + _uvCoordinates.Length);
		Array.ConstrainedCopy (mesh.uv, 0,_faces , _uvCoordinates.Length - mesh.uv.Length, mesh.uv.Length);
		mesh.uv = _uvCoordinates;

		mesh.Optimize();
	}

	public void SetMesh(Vector3[] _vertices,Vector3[] _normals,int[] _faces, Vector2[] _uvCoordinates)
	{
		if (_vertices.Length == 0) 
		{
			mesh = null;
			isEmpty = true;
			return;
		}

		mesh.vertices = _vertices;
		mesh.normals = _normals;
		mesh.triangles = _faces;
		mesh.uv = _uvCoordinates;
		
		mesh.Optimize();
	}

	public bool IsEmpty
	{
		set{isEmpty = value;}
		get{return isEmpty;}
	}
	public bool NeedUpdate
	{
		set{needUpdate = value;}
		get{return needUpdate;}
	}
	public void SetMesh(Mesh _mesh)
	{
		mesh = _mesh;
		mesh.Optimize();
	}
	public int[,,] WorldData
	{
		set{worldData = value;}
		get{return worldData;}
	}
	public Mesh Mesh
	{
		get{return mesh;}
	}

	public Vector3 Size
	{
		get{return size;}
	}
	public Vector3 Position
	{
		get{return position;}
	}

}

Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class TerrainMeshGenerator
{
	List<Vector3> vertices;
	List<Vector3> normals;
	List<int> faces;
	List<Vector2> uvCoordinates;
	Mesh mesh;
//	MeshCollider meshCollider;

	public Mesh GenerateMesh(int[,,] _map,Vector3 _worldPosition, int _width, int _height, int _depth)
	{
		mesh = new Mesh ();
		vertices = new List<Vector3>();
		normals = new List<Vector3>();
		faces = new List<int>();
		uvCoordinates = new List<Vector2>();

		for (int x = 0; x < _width; x ++) 
			for (int y = 0; y < _height; y ++) 
				for (int z = 0; z < _depth ; z ++) 
		{
			if(_map[x,y,z] == 0)
					continue;
			if(x - 1 == -1 || _map[x - 1,y,z] == 0)
				AddSide (Voxel.Direction.Left, new Vector3(x,y,z) + _worldPosition);
			if(x + 1 == _width || _map[x +1,y,z] == 0)
				AddSide (Voxel.Direction.Right, new Vector3(x,y,z) + _worldPosition);
			if(y - 1 == -1 || _map[x,y -1,z] == 0)
				AddSide (Voxel.Direction.Bottom, new Vector3(x,y,z) + _worldPosition);
			if(y + 1 == _height || _map[x,y +1,z] == 0)
				AddSide (Voxel.Direction.Top, new Vector3(x,y,z) + _worldPosition);
			if(z - 1 == -1 || _map[x,y,z -1] == 0)
				AddSide (Voxel.Direction.Back, new Vector3(x,y,z) + _worldPosition);
			if( z + 1 == _depth || _map[x,y,z +1] == 0)
				AddSide (Voxel.Direction.Front, new Vector3(x,y,z) + _worldPosition);
		}

		mesh.vertices = vertices.ToArray();
		mesh.normals = normals.ToArray();
		mesh.triangles = faces.ToArray();
		mesh.uv = uvCoordinates.ToArray();
		mesh.Optimize();

		return mesh;
	}

	private void AddSide(Voxel.Direction _direction, Vector3 _position)
	{
		faces.AddRange (Voxel.GetFaces (vertices.Count));
		vertices.AddRange (Voxel.GetVertices (_direction, _position, 0.5f));
		normals.AddRange (Voxel.GetNormals (_direction));

		//texture height/width = 0.015625f
		int rnd = Random.Range (0,3);
		float x = ((int)_position.y) * 0.015625f;
		x += rnd * 0.015625f;

		uvCoordinates.Add (new Vector2(x,0.015625f));
		uvCoordinates.Add (new Vector2(x + 0.015625f,0.015625f));
		uvCoordinates.Add (new Vector2(x + 0.015625f,0));
		uvCoordinates.Add (new Vector2(x,0));

	}
}

Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public static class Voxel
{
	public enum  Direction {Top, Bottom ,Left, Right, Front, Back};
	
	private static Vector3 v0;
	private static Vector3 v1;
	private static Vector3 v2;
	private static Vector3 v3;	
	private static Vector3 v4;
	private static Vector3 v5;
	private static Vector3 v6;
	private static Vector3 v7;

	private static readonly Vector3[] 	topNormals 		= new Vector3[]{Vector3.up		, Vector3.up		, Vector3.up		, Vector3.up};
	private static readonly Vector3[] 	bottomNormals 	= new Vector3[]{Vector3.down	, Vector3.down		, Vector3.down		, Vector3.down};
	private static readonly Vector3[] 	leftNormals 	= new Vector3[]{Vector3.left	, Vector3.left		, Vector3.left		, Vector3.left};
	private static readonly Vector3[] 	rightNormals 	= new Vector3[]{Vector3.right	, Vector3.right		, Vector3.right		, Vector3.right};
	private static readonly Vector3[] 	frontNormals 	= new Vector3[]{Vector3.forward	, Vector3.forward	, Vector3.forward	, Vector3.forward};
	private static readonly Vector3[] 	backNormals 	= new Vector3[]{Vector3.back	, Vector3.back		, Vector3.back		, Vector3.back};
	
	public static Vector3[] GetVertices(Direction _direction, Vector3 _position, float _voxelSize )
	{
		SetWorldPosition (_position.x, _position.y, _position.z, _voxelSize);
		if(_direction == Direction.Top)
		return new Vector3[]{v0, v1, v2, v3};
		if(_direction == Direction.Bottom)
		return new Vector3[]{v7, v6, v5, v4};
		if(_direction == Direction.Left)
		return new Vector3[]{v7, v4, v0, v3};
		if(_direction == Direction.Right)
		return new Vector3[]{v5, v6, v2, v1};
		if(_direction == Direction.Front)
		return new Vector3[]{v4, v5, v1, v0};
		if(_direction == Direction.Back)
		return new Vector3[]{v6, v7, v3, v2};
		
		return null;
	}
	
	private static void SetWorldPosition(float _worldPositionX,float _worldPositionY,float _worldPositionZ, float _voxelSize)
	{
		v0 = new Vector3 (-_voxelSize + _worldPositionX, _voxelSize + _worldPositionY,  _voxelSize + _worldPositionZ);
		v1 = new Vector3 (_voxelSize + _worldPositionX , _voxelSize + _worldPositionY,  _voxelSize + _worldPositionZ);
		v2 = new Vector3 (_voxelSize + _worldPositionX , _voxelSize + _worldPositionY, -_voxelSize + _worldPositionZ);
		v3 = new Vector3 (-_voxelSize + _worldPositionX, _voxelSize + _worldPositionY, -_voxelSize + _worldPositionZ);
		v4 = new Vector3 (-_voxelSize + _worldPositionX, -_voxelSize + _worldPositionY,  _voxelSize + _worldPositionZ);
		v5 = new Vector3 (_voxelSize + _worldPositionX , -_voxelSize + _worldPositionY,  _voxelSize + _worldPositionZ);
		v6 = new Vector3 (_voxelSize + _worldPositionX , -_voxelSize + _worldPositionY, -_voxelSize + _worldPositionZ);
		v7 = new Vector3 (-_voxelSize + _worldPositionX, -_voxelSize + _worldPositionY, -_voxelSize + _worldPositionZ);
	}

	public static Vector3[] GetNormals(Direction _direction)
	{
		if(_direction == Direction.Top)
			return topNormals;
		if(_direction == Direction.Bottom)
			return bottomNormals;
		if(_direction == Direction.Left)
			return leftNormals;
		if(_direction == Direction.Right)
			return rightNormals;
		if(_direction == Direction.Front)
			return frontNormals;
		if(_direction == Direction.Back)
			return backNormals;
		
		return null;
	}
	
	public static int[] GetFaces(int _vertices)
	{
		return new int[]{_vertices, _vertices + 1, _vertices + 3,_vertices + 1, _vertices + 2, _vertices + 3};
	}
}
 

Anhänge

  • VoxelTexture.png
    VoxelTexture.png
    3 KB · Aufrufe: 250
Zuletzt bearbeitet:
Zurück
Oben