public void DrawToMesh(float x, float y, ChunkMesh msh, TerrainChunk chunk, int xi, int yi) { if (invisible) { return; } float xp = x * blockSize; float yp = y * blockSize; MakeFrontFace(xp, yp, msh); if (yi == TerrainChunk.ChunkHeight - 1 || chunk[xi, yi + 1].invisible) { MakeTopFace(xp, yp, msh); } if (yi == 0 || chunk[xi, yi - 1].invisible) { MakeBottomFace(xp, yp, msh); } if (xi == 0 || chunk[xi - 1, yi].invisible) { MakeLeftFace(xp, yp, msh); } if (xi == TerrainChunk.ChunkWidth - 1 || chunk[xi + 1, yi].invisible) { MakeRightFace(xp, yp, msh); } }
//public List<Vector3> normals = new List<Vector3>(); public MeshTile(ChunkMesh c, Vector2Int g) { cm = c; gridLoc = g; h = Island.instance.GetHeight(gridLoc); worldLoc = HexGrid.GridToWorld(gridLoc, h); }
/// <summary> /// Get a GameObject from the pool and attach a mesh to it /// </summary> /// <param name="mesh">Mesh to attach</param> protected virtual void AttachMesh(GameObject go, Chunk chunk, MeshData meshData) { if (go != null) { go.name = chunk.ToString(); MeshFilter filter = go.GetComponent <MeshFilter>(); if (filter == null) { filter = go.AddComponent <MeshFilter>(); } MeshCollider col = go.GetComponent <MeshCollider>(); if (col == null) { col = go.AddComponent <MeshCollider>(); } ChunkMesh chunkMesh = go.GetComponent <ChunkMesh>(); if (chunkMesh == null) { chunkMesh = go.AddComponent <ChunkMesh>(); } Mesh mesh = meshData.ToMesh(); filter.sharedMesh = mesh; col.sharedMesh = mesh; chunkMesh.Chunk = chunk; } }
void Start() { filter = GetComponent <MeshFilter>(); col = GetComponent <MeshCollider>(); chmesh = new ChunkMesh(); }
protected override ChunkMesh FaceDataWest(ChunkMesh meshData, float x, float y, float z, Shape shape) { meshData.addVertices(shape.MakeShape(x, y, z, WorldTypes.Direction.west)); meshData.createQuads(); meshData.UVs.AddRange(FaceUVs(WorldTypes.Direction.west)); return(meshData); }
/// <summary> /// Creates chunks on a background thread until policy changes. /// </summary> void MeshLoop() { Thread.CurrentThread.IsBackground = true; Thread.CurrentThread.Name = "Meshalyzer - " + _game.World.Title; var meshalyzer = _currentMeshalyzer; if (meshalyzer == null) { Debug.Assert(false); return; } // TODO: Meshalyzer should be refactored to spit out basic info (coords, colors) only. // An intermediate object would package it into a buffer while (Policy == ChunkCreationPolicy.Run) { ChunkPosition pos; if (!_prioritizer.GetNextDesiredChunk(_game.Camera.ChunkPosition, out pos)) { Thread.Sleep(1000); continue; } var box = new BoxSelection(pos, new ChunkSize(16, 256, 16)); var chunkVolume = new BlockSelection(box, _game.Dimension, _game.World); var buffer = meshalyzer.Meshalyze(_game, chunkVolume); var mesh = new ChunkMesh(chunkVolume.Selection.Lesser.AsVector3(), _vertexLit, buffer); _chunksToIntegrate.Enqueue(new ChunkMeshPositionPair(mesh, pos)); } }
public void MakeFrontFace(float xp, float yp, ChunkMesh msh) { if(invisible) return; int ti = msh.vertices.Count; msh.vertices.Add(new Vector3(xp, yp)); msh.vertices.Add(new Vector3(xp + blockSize, yp)); msh.vertices.Add(new Vector3(xp + blockSize, yp + blockSize)); msh.vertices.Add(new Vector3(xp, yp + blockSize)); // msh.triangles.Add(ti); // msh.triangles.Add(ti + 3); // msh.triangles.Add(ti + 1); // msh.triangles.Add(ti + 1); // msh.triangles.Add(ti + 3); // msh.triangles.Add(ti + 2); finishFace(ti, msh); // for(int i = 0; i < 4; i++) // msh.colours.Add(colour); // // msh.uvs.Add(new Vector2(uv.x + uvCorrect, uv.y + uvCorrect)); // msh.uvs.Add(new Vector2(uv.x + uvFactor - uvCorrect, uv.y + uvCorrect)); // msh.uvs.Add(new Vector2(uv.x + uvFactor - uvCorrect, uv.y + uvFactor - uvCorrect)); // msh.uvs.Add(new Vector2(uv.x + uvCorrect, uv.y + uvFactor - uvCorrect)); }
public override ChunkMesh Draw(SubChunk chunk, int x, int y, int z, ChunkMesh data) { Shape shape = GetShape(); if (!chunk.getBlock(x, y + 1, z).isSolid(WorldTypes.Direction.down, BlockBin.Air)) { data = FaceDataUp(data, x, y, z, shape); } if (!chunk.getBlock(x, y - 1, z).isSolid(WorldTypes.Direction.up, BlockBin.Air)) { data = FaceDataDown(data, x, y, z, shape); } if (!chunk.getBlock(x, y, z - 1).isSolid(WorldTypes.Direction.north, BlockBin.Air)) { data = FaceDataSouth(data, x, y, z, shape); } if (!chunk.getBlock(x, y, z + 1).isSolid(WorldTypes.Direction.south, BlockBin.Air)) { data = FaceDataNorth(data, x, y, z, shape); } if (!chunk.getBlock(x - 1, y, z).isSolid(WorldTypes.Direction.east, BlockBin.Air)) { data = FaceDataWest(data, x, y, z, shape); } if (!chunk.getBlock(x + 1, y, z).isSolid(WorldTypes.Direction.west, BlockBin.Air)) { data = FaceDataEast(data, x, y, z, shape); } return(data); }
public void MakeFrontFace(float xp, float yp, ChunkMesh msh) { if (invisible) { return; } int ti = msh.vertices.Count; msh.vertices.Add(new Vector3(xp, yp)); msh.vertices.Add(new Vector3(xp + blockSize, yp)); msh.vertices.Add(new Vector3(xp + blockSize, yp + blockSize)); msh.vertices.Add(new Vector3(xp, yp + blockSize)); // msh.triangles.Add(ti); // msh.triangles.Add(ti + 3); // msh.triangles.Add(ti + 1); // msh.triangles.Add(ti + 1); // msh.triangles.Add(ti + 3); // msh.triangles.Add(ti + 2); finishFace(ti, msh); // for(int i = 0; i < 4; i++) // msh.colours.Add(colour); // // msh.uvs.Add(new Vector2(uv.x + uvCorrect, uv.y + uvCorrect)); // msh.uvs.Add(new Vector2(uv.x + uvFactor - uvCorrect, uv.y + uvCorrect)); // msh.uvs.Add(new Vector2(uv.x + uvFactor - uvCorrect, uv.y + uvFactor - uvCorrect)); // msh.uvs.Add(new Vector2(uv.x + uvCorrect, uv.y + uvFactor - uvCorrect)); }
/// <summary> /// Adds the face which faces the given direction to the given chunk mesh. /// </summary> /// <param name="direction">The direction of the face</param> /// <param name="chunkMesh">The reference to the chunk mesh that is going to be manipulated</param> void AddBlockFace(FaceDirection direction, ref ChunkMesh chunkMesh) { Vector3 point1; Vector3 point2; Vector3 point3; Vector3 point4; // assign the points depending on the directio of the face switch (direction) { case FaceDirection.south: point1 = new Vector3(blockPos.x - 0.5f, blockPos.y + 0.5f, blockPos.z - 0.5f); // upper left front point point2 = new Vector3(blockPos.x + 0.5f, blockPos.y + 0.5f, blockPos.z - 0.5f); // upper right front point point3 = new Vector3(blockPos.x + 0.5f, blockPos.y - 0.5f, blockPos.z - 0.5f); // lower right front point point4 = new Vector3(blockPos.x - 0.5f, blockPos.y - 0.5f, blockPos.z - 0.5f); // lower left front point break; case FaceDirection.north: point1 = new Vector3(blockPos.x + 0.5f, blockPos.y + 0.5f, blockPos.z + 0.5f); // upper right back point point2 = new Vector3(blockPos.x - 0.5f, blockPos.y + 0.5f, blockPos.z + 0.5f); // upper left back point point3 = new Vector3(blockPos.x - 0.5f, blockPos.y - 0.5f, blockPos.z + 0.5f); // lower left back point point4 = new Vector3(blockPos.x + 0.5f, blockPos.y - 0.5f, blockPos.z + 0.5f); // lower right back poin break; case FaceDirection.west: point1 = new Vector3(blockPos.x - 0.5f, blockPos.y + 0.5f, blockPos.z + 0.5f); // upper left back point point2 = new Vector3(blockPos.x - 0.5f, blockPos.y + 0.5f, blockPos.z - 0.5f); // upper left front point point3 = new Vector3(blockPos.x - 0.5f, blockPos.y - 0.5f, blockPos.z - 0.5f); // lower left front point point4 = new Vector3(blockPos.x - 0.5f, blockPos.y - 0.5f, blockPos.z + 0.5f); // lower left back point break; case FaceDirection.east: point1 = new Vector3(blockPos.x + 0.5f, blockPos.y + 0.5f, blockPos.z - 0.5f); // upper right front point point2 = new Vector3(blockPos.x + 0.5f, blockPos.y + 0.5f, blockPos.z + 0.5f); // upper right back point point3 = new Vector3(blockPos.x + 0.5f, blockPos.y - 0.5f, blockPos.z + 0.5f); // lower right back point point4 = new Vector3(blockPos.x + 0.5f, blockPos.y - 0.5f, blockPos.z - 0.5f); // lower right front poin break; case FaceDirection.down: point1 = new Vector3(blockPos.x - 0.5f, blockPos.y - 0.5f, blockPos.z - 0.5f); // lower left front point point2 = new Vector3(blockPos.x + 0.5f, blockPos.y - 0.5f, blockPos.z - 0.5f); // lower right front point point3 = new Vector3(blockPos.x + 0.5f, blockPos.y - 0.5f, blockPos.z + 0.5f); // lower right back point point4 = new Vector3(blockPos.x - 0.5f, blockPos.y - 0.5f, blockPos.z + 0.5f); // upper left front point break; default: // default case is to add the upper face point1 = new Vector3(blockPos.x - 0.5f, blockPos.y + 0.5f, blockPos.z + 0.5f); // upper left back point point2 = new Vector3(blockPos.x + 0.5f, blockPos.y + 0.5f, blockPos.z + 0.5f); // upper right back point point3 = new Vector3(blockPos.x + 0.5f, blockPos.y + 0.5f, blockPos.z - 0.5f); // upper right front point point4 = new Vector3(blockPos.x - 0.5f, blockPos.y + 0.5f, blockPos.z - 0.5f); // upper left front point break; } // add the mesh data to the chunk mesh chunkMesh.AddFace(point1, point2, point3, point4); // add the uv coordinates of the face Vector2[] uvCoords = GetFaceUVCoordinates(direction); chunkMesh.AddUVCoordinates(uvCoords); }
protected override ChunkMesh FaceDataUp(ChunkMesh meshData, float x, float y, float z, Shape shape) { //For 2 do createDoubleQuads meshData.addVertices(shape.MakeShape(x, y, z, WorldTypes.Direction.up)); meshData.createQuads(); meshData.UVs.AddRange(FaceUVs(WorldTypes.Direction.up)); return(meshData); }
// Start is called before the first frame update void Start() { // get the mesh components and assign them meshFilter = GetComponent <MeshFilter>(); meshCollider = GetComponent <MeshCollider>(); chunkMesh = new ChunkMesh(); }
private ChunkMesh GetExistingChunkMesh(ChunkMeshCluster chunkMeshCluster, RendererType rendererType) { availableChunkMeshCount--; ChunkMesh returnChunkMesh = availableChunkMeshes.Pop(); returnChunkMesh.Setup(chunkMeshCluster, rendererType); return(returnChunkMesh); }
public RasterizeWorker(Chunk chunk) { this.chunk = chunk; this.chunk.Working = true; mesh = new ChunkMesh(); renderer = new ChunkRenderer(); chunkView = new ChunkView(chunk); }
private async Task GenerateChunk(Vector2 pos, ChunkMesh mesh) { mesh.transform.parent = m_children; mesh.Noise = m_noise; mesh.transform.position = new Vector3(pos.x * 16, 0, pos.y * 16); mesh.ChunkIndex = new Vector2(pos.x, pos.y); await Task.Run(mesh.GenerateMesh); }
ChunkMesh GenerateTerrainMesh() { int bx = chunkx << Chunk.CHUNK_X_SHIFT; int bz = chunkz << Chunk.CHUNK_Z_SHIFT; Chunk c20 = terrain.GetChunk(chunkx + 1, chunkz - 1); Chunk c21 = terrain.GetChunk(chunkx + 1, chunkz); Chunk c22 = terrain.GetChunk(chunkx + 1, chunkz + 1); Chunk c10 = terrain.GetChunk(chunkx, chunkz - 1); Chunk c11 = terrain.GetChunk(chunkx, chunkz); Chunk c12 = terrain.GetChunk(chunkx, chunkz + 1); Chunk c00 = terrain.GetChunk(chunkx - 1, chunkz - 1); Chunk c01 = terrain.GetChunk(chunkx - 1, chunkz); Chunk c02 = terrain.GetChunk(chunkx - 1, chunkz + 1); ChunkMesh m = new ChunkMesh(); var watch = Stopwatch.StartNew(); for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++) { switch (x) { case 0: if (c01 == null || z == 0 && c00 == null || z == Chunk.SIZE_Z_MINUS_ONE && c02 == null) { continue; } goto default; case Chunk.SIZE_X_MINUS_ONE: if (c21 == null || z == 0 && c20 == null || z == Chunk.SIZE_Z_MINUS_ONE && c22 == null) { continue; } goto default; default: if (z == 0 && c10 == null || z == Chunk.SIZE_Z_MINUS_ONE && c12 == null) { continue; } // if (x == 0) Debug.Log("0"); for (int y = 1; y < 127; y++) { Block b = BlockManager.blocks[c11[x, y, z].index]; b.renderer?.GenerateTerrainVertices(x + bx, y, z + bz, terrain, m); } break; } } } watch.Stop(); print(watch.ElapsedMilliseconds); return(m); }
public override IEnumerator renderMesh(ChunkMesh data) { filter.mesh.Clear(); filter.mesh.vertices = data.Vertices.ToArray(); filter.mesh.triangles = data.Triangles.ToArray(); filter.mesh.uv = data.UVs.ToArray(); filter.mesh.RecalculateNormals(); collide.sharedMesh = filter.mesh; yield return(0); }
public override bool Equals(object other) { ChunkMesh mesh = other as ChunkMesh; if (other == null) { return(false); } return(mesh.Chunk.Position.Equals(Chunk.Position)); }
public void MakeBottomFace(float xp, float yp, ChunkMesh msh) { if(invisible) return; int ti = msh.vertices.Count; msh.vertices.Add(new Vector3(xp, yp, blockSize)); msh.vertices.Add(new Vector3(xp + blockSize, yp, blockSize)); msh.vertices.Add(new Vector3(xp + blockSize, yp)); msh.vertices.Add(new Vector3(xp, yp)); finishFace(ti, msh); }
/// <summary> /// Unloads a chunkmesh /// </summary> /// <param name="chunkMesh"></param> public void UnloadChunkMesh(ChunkMesh chunkMesh) { lock (_chunkMeshes) { // check if chunk exists if (!_chunkMeshes.Contains(chunkMesh) || chunkMesh == null) { return; } Destroy(chunkMesh.gameObject); _chunkMeshes.Remove(chunkMesh); } }
public void ReturnChunkMesh(ChunkMesh chunkMesh) { if (chunkMesh == null) { return; } chunkMesh.ClearName(); chunkMesh.ClearMeshes(); lock (padlock) { availableChunkMeshes.Push(chunkMesh); availableChunkMeshCount++; } }
private void Update() { // Get player position. if (m_player == null) { return; } int chunkX = Mathf.FloorToInt(m_player.position.x / 16.0f); int chunkZ = Mathf.FloorToInt(m_player.position.z / 16.0f); m_chunkRange.Clear(); int chunkDistance = m_chunkDistance / 2; // Generate a circle around the player to generate chunks. for (int z = -chunkDistance; z < chunkDistance; z++) { for (int x = -chunkDistance; x < chunkDistance; x++) { Vector2 chunk = new Vector2(chunkX + x, chunkZ + z); m_chunkRange.Add(chunk); if (m_loadedChunks.ContainsKey(chunk)) { continue; } LoadChunk(chunk); } } // Unload chunks foreach (Vector2 loadedChunk in m_loadedChunks.Keys.Where(loadedChunk => !m_chunkRange.Contains(loadedChunk))) { m_chunksToUnload.Add(loadedChunk); } foreach (Vector2 unload in m_chunksToUnload) { ChunkMesh chunk = m_loadedChunks[unload]; m_loadedChunks.Remove(unload); m_chunkPool.Return(chunk); } m_chunksToUnload.Clear(); }
public override ChunkMesh Draw(SubChunk chunk, int x, int y, int z, ChunkMesh data) { Shape shape = GetShape(); data = FaceDataSouth(data, x, y, z, shape); data = FaceDataNorth(data, x, y, z, shape); data = FaceDataWest(data, x, y, z, shape); data = FaceDataEast(data, x, y, z, shape); return(data); }
void UpdateChunkMesh() { chunkMesh = new ChunkMesh(); // iterate through the chunk and get the block data from every block for (int x = 0; x < chunkSize; x++) { for (int z = 0; z < chunkSize; z++) { for (int y = 0; y < chunkSize; y++) { blocks[x, y, z].AddBlockToChunk(this, ref chunkMesh); } } } }
public void MakeBottomFace(float xp, float yp, ChunkMesh msh) { if (invisible) { return; } int ti = msh.vertices.Count; msh.vertices.Add(new Vector3(xp, yp, blockSize)); msh.vertices.Add(new Vector3(xp + blockSize, yp, blockSize)); msh.vertices.Add(new Vector3(xp + blockSize, yp)); msh.vertices.Add(new Vector3(xp, yp)); finishFace(ti, msh); }
public override IEnumerator ReDraw() { if (this == null) { while (waitingChunks.Count > 0 && waitingChunks[0] == null) { waitingChunks.RemoveAt(0); } if (waitingChunks.Count > 0) { StartCoroutine(waitingChunks[0].Generate()); } yield return(0); } yield return(0); ChunkMesh data = new ChunkMesh(); for (int x = 0; x < chunkWidth; x++) { for (int y = 0; y < chunkHeight; y++) { for (int z = 0; z < chunkDepth; z++) { if (blocks [x, y, z] != 0) { data = BlockBin.GetBlock(blocks [x, y, z]).Draw(this, x, y, z, data); } } } } StartCoroutine(renderMesh(data)); renderChunks.Remove(this); while (renderChunks.Count > 0 && renderChunks[0] == null) { renderChunks.RemoveAt(0); } if (renderChunks.Count > 0) { StartCoroutine(renderChunks[0].ReDraw()); } else { state = 3; } }
/// <summary> /// Generate the mesh vales for a chunk /// </summary> /// <param name="chunk"></param> /// <returns type="ChunkMesh">The parts of the chunk's mesh</returns> public ChunkMesh generateMeshFor(Chunk chunk) { chunkMesh = new ChunkMesh(new List <Vector3>(), new List <int>(), new List <Vector2>(), chunk.location); faceCount = 0; if (chunk == null) { Debug.Log("Chunk is empty, cannot generate mesh"); } else { this.chunk = chunk; generateMesh(); chunk.hasBeenRendered = true; chunk.isRendered = true; } return(chunkMesh); }
private static void InitMesh(GxContext context) { // all tiles will supply their own vertex buffer ChunkMesh.VertexBuffer.Dispose(); ChunkMesh.AddElement("POSITION", 0, 3); ChunkMesh.AddElement("NORMAL", 0, 3); ChunkMesh.AddElement("TEXCOORD", 0, 2); ChunkMesh.AddElement("TEXCOORD", 1, 2); ChunkMesh.AddElement("COLOR", 0, 4, DataType.Byte, true); ChunkMesh.AddElement("COLOR", 1, 4, DataType.Byte, true); ChunkMesh.IndexCount = 768; ChunkMesh.Stride = IO.SizeCache <IO.Files.Terrain.AdtVertex> .Size; ChunkMesh.BlendState.BlendEnabled = false; ChunkMesh.DepthState.DepthEnabled = true; ChunkMesh.RasterizerState.CullEnabled = true; BlendNew = new ShaderProgram(context); BlendNew.SetVertexShader(Resources.Shaders.TerrainVertex); BlendNew.SetPixelShader(Resources.Shaders.TerrainPixelNew); ChunkMesh.Program = BlendNew; ChunkMesh.InitLayout(BlendNew); BlendOld = new ShaderProgram(context); BlendOld.SetVertexShader(Resources.Shaders.TerrainVertex); BlendOld.SetPixelShader(Resources.Shaders.TerrainPixel); ColorSampler = new Sampler(context) { AddressU = SharpDX.Direct3D11.TextureAddressMode.Wrap, AddressV = SharpDX.Direct3D11.TextureAddressMode.Wrap, AddressW = SharpDX.Direct3D11.TextureAddressMode.Clamp, Filter = SharpDX.Direct3D11.Filter.Anisotropic, MaximumAnisotropy = 16, }; AlphaSampler = new Sampler(context) { AddressU = SharpDX.Direct3D11.TextureAddressMode.Clamp, AddressV = SharpDX.Direct3D11.TextureAddressMode.Clamp, AddressW = SharpDX.Direct3D11.TextureAddressMode.Clamp, Filter = SharpDX.Direct3D11.Filter.Anisotropic, MaximumAnisotropy = 16, }; }
private void LoadChunk(Vector2 pos) { // Don't load an already loaded chunk. if (m_loadedChunks.ContainsKey(pos)) { return; } ChunkMesh mesh = m_chunkPool.Get(); if (mesh == null) { return; } m_loadedChunks.Add(pos, mesh); m_loadingChunks.Add(new Tuple <Task, ChunkMesh>(GenerateChunk(pos, mesh), mesh)); }
public void DrawToMesh(float x, float y, ChunkMesh msh, TerrainChunk chunk, int xi, int yi) { if(invisible) return; float xp = x * blockSize; float yp = y * blockSize; MakeFrontFace(xp, yp, msh); if(yi == TerrainChunk.ChunkHeight - 1 || chunk[xi, yi + 1].invisible) MakeTopFace(xp, yp, msh); if(yi == 0 || chunk[xi, yi - 1].invisible) MakeBottomFace(xp, yp, msh); if(xi == 0 || chunk[xi - 1, yi].invisible) MakeLeftFace(xp, yp, msh); if(xi == TerrainChunk.ChunkWidth - 1 || chunk[xi + 1, yi].invisible) MakeRightFace(xp, yp, msh); }
void finishFace(int ti, ChunkMesh msh) { msh.triangles.Add(ti); msh.triangles.Add(ti + 3); msh.triangles.Add(ti + 1); msh.triangles.Add(ti + 1); msh.triangles.Add(ti + 3); msh.triangles.Add(ti + 2); for (int i = 0; i < 4; i++) { msh.colours.Add(colour); } msh.uvs.Add(new Vector2(uv.x + uvCorrect, uv.y + uvCorrect)); msh.uvs.Add(new Vector2(uv.x + uvFactor - uvCorrect, uv.y + uvCorrect)); msh.uvs.Add(new Vector2(uv.x + uvFactor - uvCorrect, uv.y + uvFactor - uvCorrect)); msh.uvs.Add(new Vector2(uv.x + uvCorrect, uv.y + uvFactor - uvCorrect)); }
/// <summary> /// Adds the mesh data of the block to the given chunk mesh. /// </summary> /// <param name="chunkMesh">The given chunk mesh</param> /// <returns></returns> public virtual void AddBlockToChunk(Chunk chunk, ref ChunkMesh chunkMesh) { // check the block above and below Block upperBlock = chunk.GetBlock(new Vector3(blockPos.x, blockPos.y + 1, blockPos.z)); Block lowerBlock = chunk.GetBlock(new Vector3(blockPos.x, blockPos.y - 1, blockPos.z)); if (!upperBlock.IsFaceSolid(FaceDirection.down)) { AddBlockFace(FaceDirection.up, ref chunkMesh); } if (!lowerBlock.IsFaceSolid(FaceDirection.up)) { AddBlockFace(FaceDirection.down, ref chunkMesh); } // check the east and west block Block eastBlock = chunk.GetBlock(new Vector3(blockPos.x + 1, blockPos.y, blockPos.z)); Block westBlock = chunk.GetBlock(new Vector3(blockPos.x - 1, blockPos.y, blockPos.z)); if (!eastBlock.IsFaceSolid(FaceDirection.west)) { AddBlockFace(FaceDirection.east, ref chunkMesh); } if (!westBlock.IsFaceSolid(FaceDirection.east)) { AddBlockFace(FaceDirection.west, ref chunkMesh); } // check the north and south block Block northBlock = chunk.GetBlock(new Vector3(blockPos.x, blockPos.y, blockPos.z + 1)); Block southBlock = chunk.GetBlock(new Vector3(blockPos.x, blockPos.y, blockPos.z - 1)); if (!northBlock.IsFaceSolid(FaceDirection.south)) { AddBlockFace(FaceDirection.north, ref chunkMesh); } if (!southBlock.IsFaceSolid(FaceDirection.north)) { AddBlockFace(FaceDirection.south, ref chunkMesh); } }
public void ApplyAmbient() { if (ambientWorker.stop) { return; } //empty mesh check if (ambient == null || hiMesh.vertexCount == 0) { return; } #if WDEBUG Profiler.BeginSample("Apply Ambient"); #endif //hi mesh int[] hiTris = hiMesh.triangles; Vector2[] hiAmbient = ChunkMesh.SetAmbient(ambient, hiTris, indexToCoord, hiMesh.vertexCount); hiMesh.uv4 = hiAmbient; //lo mesh Vector2[] loAmbient = new Vector2[loMesh.vertexCount]; for (int i = 0; i < loAmbient.Length; i++) { loAmbient[i] = hiAmbient[i]; } loMesh.uv4 = loAmbient; //grass if (grassMesh.vertexCount != 0) { Vector2[] grassAmbient = ChunkMesh.SetGrassAmbient(ambient, grassMesh.vertices, grassMesh.triangles, grassMesh.uv4, transform.localPosition); grassMesh.uv4 = grassAmbient; } #if WDEBUG Profiler.EndSample(); #endif }
void Start() { filter = GetComponent<MeshFilter>(); col = GetComponent<MeshCollider>(); chmesh = new ChunkMesh(); }
void finishFace(int ti, ChunkMesh msh) { msh.triangles.Add(ti); msh.triangles.Add(ti + 3); msh.triangles.Add(ti + 1); msh.triangles.Add(ti + 1); msh.triangles.Add(ti + 3); msh.triangles.Add(ti + 2); for(int i = 0; i < 4; i++) msh.colours.Add(colour); msh.uvs.Add(new Vector2(uv.x + uvCorrect, uv.y + uvCorrect)); msh.uvs.Add(new Vector2(uv.x + uvFactor - uvCorrect, uv.y + uvCorrect)); msh.uvs.Add(new Vector2(uv.x + uvFactor - uvCorrect, uv.y + uvFactor - uvCorrect)); msh.uvs.Add(new Vector2(uv.x + uvCorrect, uv.y + uvFactor - uvCorrect)); }