void FillMesh(NBTChunk chunk, CubeAttributes ca, NBTMesh nbtMesh) { chunk.GetLights(ca.pos.x, ca.pos.y, ca.pos.z, out float skyLight, out float blockLight); FaceAttributes fa = new FaceAttributes(); fa.faceIndex = TextureArrayManager.GetIndexByName("ladder"); fa.color = Color.white; fa.skyLight = new float[] { skyLight, skyLight, skyLight, skyLight }; fa.blockLight = new float[] { blockLight, blockLight, blockLight, blockLight }; fa.normal = Vector3.zero; fa.uv = uv_zero; if (ca.blockData == 2) { fa.pos = frontFace; AddFace(nbtMesh, fa, ca); } else if (ca.blockData == 3) { fa.pos = backFace; AddFace(nbtMesh, fa, ca); } else if (ca.blockData == 4) { fa.pos = leftFace; AddFace(nbtMesh, fa, ca); } else if (ca.blockData == 5) { fa.pos = rightFace; AddFace(nbtMesh, fa, ca); } }
public override void AddCube(NBTChunk chunk, byte blockData, Vector3Int pos, NBTGameObject nbtGO) { ca.pos = pos; ca.blockData = blockData; chunk.GetLights(pos.x, pos.y, pos.z, out float skyLight, out float blockLight); FaceAttributes fa = new FaceAttributes(); fa.faceIndex = GetPlantIndexByData(chunk, blockData); fa.color = Color.white; fa.skyLight = new float[] { skyLight, skyLight, skyLight, skyLight }; fa.blockLight = new float[] { blockLight, blockLight, blockLight, blockLight }; fa.normal = Vector3.zero; fa.uv = uv_zero; try { fa.pos = face1; AddFace(nbtGO.nbtMesh, fa, ca); fa.pos = face2; AddFace(nbtGO.nbtMesh, fa, ca); fa.pos = face3; AddFace(nbtGO.nbtMesh, fa, ca); fa.pos = face4; AddFace(nbtGO.nbtMesh, fa, ca); } catch (System.Exception e) { Debug.Log(e.ToString() + "\n" + "pos=" + pos + ",data=" + blockData); } }
public override Mesh GetItemMesh(NBTChunk chunk, Vector3Int pos, byte blockData) { CubeAttributes ca = new CubeAttributes(); ca.blockData = blockData; NBTMesh nbtMesh = new NBTMesh(256); chunk.GetLights(pos.x - chunk.x * 16, pos.y, pos.z - chunk.z * 16, out float skyLight, out float blockLight); FaceAttributes fa = new FaceAttributes(); fa.faceIndex = TextureArrayManager.GetIndexByName(GetNameByData(blockData)); fa.skyLight = new float[] { skyLight, skyLight, skyLight, skyLight }; fa.blockLight = new float[] { blockLight, blockLight, blockLight, blockLight }; fa.color = Color.white; FillMesh(fa, ca, nbtMesh); nbtMesh.Refresh(); nbtMesh.Dispose(); return(nbtMesh.mesh); }
public override void AddCube(NBTChunk chunk, byte blockData, Vector3Int localPosition, NBTGameObject nbtGO) { ca.pos = localPosition; ca.worldPos = new Vector3Int(localPosition.x + chunk.x * 16, localPosition.y, localPosition.z + chunk.z * 16); ca.blockData = blockData; InitBlockAttributes(chunk, ref ca); chunk.GetLights(localPosition.x, localPosition.y, localPosition.z, out float skyLight, out float blockLight); FaceAttributes fa = new FaceAttributes(); fa.skyLight = new float[] { skyLight, skyLight, skyLight, skyLight }; fa.blockLight = new float[] { blockLight, blockLight, blockLight, blockLight }; fa.uv = uv_zero; fa.pos = frontVertices; fa.normal = Vector3.forward; fa.faceIndex = GetFrontIndexByData(chunk, ca.blockData); fa.color = GetFrontTintColorByData(chunk, localPosition, ca.blockData); AddFace(nbtGO.nbtMesh, fa, ca); fa.pos = backVertices; fa.normal = Vector3.back; fa.faceIndex = GetBackIndexByData(chunk, ca.blockData); fa.color = GetBackTintColorByData(chunk, localPosition, ca.blockData); AddFace(nbtGO.nbtMesh, fa, ca); fa.pos = topVertices; fa.normal = Vector3.up; fa.faceIndex = GetTopIndexByData(chunk, ca.blockData); fa.color = GetTopTintColorByData(chunk, localPosition, ca.blockData); AddFace(nbtGO.nbtMesh, fa, ca); fa.pos = bottomVertices; fa.normal = Vector3.down; fa.faceIndex = GetBottomIndexByData(chunk, ca.blockData); fa.color = GetBottomTintColorByData(chunk, localPosition, ca.blockData); AddFace(nbtGO.nbtMesh, fa, ca); fa.pos = leftVertices; fa.normal = Vector3.left; fa.faceIndex = GetLeftIndexByData(chunk, ca.blockData); fa.color = GetLeftTintColorByData(chunk, localPosition, ca.blockData); AddFace(nbtGO.nbtMesh, fa, ca); fa.pos = rightVertices; fa.normal = Vector3.right; fa.faceIndex = GetRightIndexByData(chunk, ca.blockData); fa.color = GetRightTintColorByData(chunk, localPosition, ca.blockData); AddFace(nbtGO.nbtMesh, fa, ca); }
protected override FaceAttributes GetRightFaceAttributes(NBTChunk chunk, NBTMesh mesh, CubeAttributes ca) { chunk.GetLights(ca.pos.x + 1, ca.pos.y, ca.pos.z, out float skyLight, out float blockLight); FaceAttributes fa = new FaceAttributes(); fa.pos = rightVertices_snow; fa.faceIndex = GetRightIndexByData(chunk, ca.blockData); fa.color = GetRightTintColorByData(chunk, ca.pos, ca.blockData); fa.skyLight = new float[] { skyLight, skyLight, skyLight, skyLight }; fa.blockLight = new float[] { blockLight, blockLight, blockLight, blockLight }; fa.normal = Vector3.right; fa.uv = uv_bot; return(fa); }
protected override FaceAttributes GetBottomFaceAttributes(NBTChunk chunk, NBTMesh mesh, CubeAttributes ca) { chunk.GetLights(ca.pos.x, ca.pos.y - 1, ca.pos.z, out float skyLight, out float blockLight); FaceAttributes fa = new FaceAttributes(); fa.pos = bottomVertices_snow; fa.faceIndex = GetBottomIndexByData(chunk, ca.blockData); fa.color = GetBottomTintColorByData(chunk, ca.pos, ca.blockData); fa.skyLight = new float[] { skyLight, skyLight, skyLight, skyLight }; fa.blockLight = new float[] { blockLight, blockLight, blockLight, blockLight }; fa.normal = Vector3.down; fa.uv = uv_full; return(fa); }
public override void AddCube(NBTChunk chunk, byte blockData, Vector3Int localPosition, NBTGameObject nbtGO) { MeshData mesh = GetMesh(chunk, localPosition, blockData); int faceIndex = TextureArrayManager.GetIndexByName(stairsName); chunk.GetLights(localPosition.x, localPosition.y + 1, localPosition.z, out float skyLight, out float blockLight); NBTMesh nbtMesh = nbtGO.nbtMesh; ushort startIndex = nbtMesh.vertexCount; for (int i = 0; i < mesh.vertices.Length; i++) { SetVertex(nbtMesh, mesh.vertices[i] + localPosition, faceIndex, mesh.uv[i], skyLight, blockLight, Color.white, Vector3.zero); } foreach (int index in mesh.triangles) { nbtMesh.triangleArray[nbtMesh.triangleCount++] = (ushort)(startIndex + index); } }
void AddAntiDiagonalFace(NBTChunk chunk, NBTMesh mesh, CubeAttributes ca) { chunk.GetLights(ca.pos.x, ca.pos.y, ca.pos.z, out float skyLight, out float blockLight); antidiagonalFA.pos = antiDiagonalFace; antidiagonalFA.faceIndex = GetPlantIndexByData(chunk, ca.pos, ca.blockData); antidiagonalFA.color = GetTintColorByData(chunk, ca.pos, ca.blockData); antidiagonalFA.skyLight[0] = skyLight; antidiagonalFA.skyLight[1] = skyLight; antidiagonalFA.skyLight[2] = skyLight; antidiagonalFA.skyLight[3] = skyLight; antidiagonalFA.blockLight[0] = blockLight; antidiagonalFA.blockLight[1] = blockLight; antidiagonalFA.blockLight[2] = blockLight; antidiagonalFA.blockLight[3] = blockLight; antidiagonalFA.normal = Vector3.zero; antidiagonalFA.uv = uv_plant; AddFace(mesh, antidiagonalFA, ca); }
protected override FaceAttributes GetTopFaceAttributes(NBTChunk chunk, NBTMesh mesh, CubeAttributes ca) { chunk.GetLights(ca.pos.x, ca.pos.y + 1, ca.pos.z, out float skyLight, out float blockLight); FaceAttributes fa = new FaceAttributes(); if (ca.blockData >= 8) { fa.pos = topVertices_top; } else { fa.pos = topVertices_bottom; } fa.faceIndex = GetTopIndexByData(chunk, ca.blockData); fa.color = GetTopTintColorByData(chunk, ca.pos, ca.blockData); fa.skyLight = new float[] { skyLight, skyLight, skyLight, skyLight }; fa.blockLight = new float[] { blockLight, blockLight, blockLight, blockLight }; fa.normal = Vector3.up; fa.uv = uv_full; return(fa); }
public override void AddCube(NBTChunk chunk, byte blockData, Vector3Int pos, NBTGameObject nbtGO) { UnityEngine.Profiling.Profiler.BeginSample(GetType().Name + " AddCube"); int faceIndex = TextureArrayManager.GetIndexByName(fenceName); MeshData mesh = GetMesh(chunk, pos); chunk.GetLights(pos.x, pos.y, pos.z, out float skyLight, out float blockLight); NBTMesh nbtMesh = nbtGO.nbtMesh; ushort startIndex = nbtMesh.vertexCount; for (int i = 0; i < mesh.vertices.Length; i++) { SetVertex(nbtMesh, mesh.vertices[i] + pos, faceIndex, mesh.uv[i], skyLight, blockLight, Color.white, mesh.normals[i]); } foreach (int index in mesh.triangles) { nbtMesh.triangleArray[nbtMesh.triangleCount++] = (ushort)(startIndex + index); } UnityEngine.Profiling.Profiler.EndSample(); }
// for break effect & drop item (will be affected by light) public override Mesh GetItemMesh(NBTChunk chunk, Vector3Int pos, byte blockData) { CubeAttributes ca = new CubeAttributes(); //ca.pos = pos; ca.blockData = blockData; NBTMesh nbtMesh = new NBTMesh(256); chunk.GetLights(pos.x - chunk.x * 16, pos.y, pos.z - chunk.z * 16, out float skyLight, out float blockLight); FaceAttributes fa = new FaceAttributes(); fa.skyLight = new float[] { skyLight, skyLight, skyLight, skyLight }; fa.blockLight = new float[] { blockLight, blockLight, blockLight, blockLight }; fa.uv = uv_zero; try { fa.pos = frontVertices; fa.normal = Vector3.forward; fa.faceIndex = GetFrontIndexByData(chunk, ca.blockData); fa.color = GetFrontTintColorByData(chunk, pos, ca.blockData); AddFace(nbtMesh, fa, ca); fa.pos = backVertices; fa.normal = Vector3.back; fa.faceIndex = GetBackIndexByData(chunk, ca.blockData); fa.color = GetBackTintColorByData(chunk, pos, ca.blockData); AddFace(nbtMesh, fa, ca); fa.pos = topVertices; fa.normal = Vector3.up; fa.faceIndex = GetTopIndexByData(chunk, ca.blockData); fa.color = GetTopTintColorByData(chunk, pos, ca.blockData); AddFace(nbtMesh, fa, ca); fa.pos = bottomVertices; fa.normal = Vector3.down; fa.faceIndex = GetBottomIndexByData(chunk, ca.blockData); fa.color = GetBottomTintColorByData(chunk, pos, ca.blockData); AddFace(nbtMesh, fa, ca); fa.pos = leftVertices; fa.normal = Vector3.left; fa.faceIndex = GetLeftIndexByData(chunk, ca.blockData); fa.color = GetLeftTintColorByData(chunk, pos, ca.blockData); AddFace(nbtMesh, fa, ca); fa.pos = rightVertices; fa.normal = Vector3.right; fa.faceIndex = GetRightIndexByData(chunk, ca.blockData); fa.color = GetRightTintColorByData(chunk, pos, ca.blockData); AddFace(nbtMesh, fa, ca); } catch (System.Exception e) { Debug.LogError("GetItemMesh error,generator=" + GetType() + ",message=\n" + e.Message); } nbtMesh.Refresh(); nbtMesh.Dispose(); return(nbtMesh.mesh); }
public override void AddCube(NBTChunk chunk, byte blockData, Vector3Int pos, NBTGameObject nbtGO) { ca.pos = pos; ca.blockData = blockData; chunk.GetBlockData(pos.x, pos.y, pos.z - 1, out byte frontType, out byte frontData); chunk.GetBlockData(pos.x, pos.y, pos.z + 1, out byte backType, out byte backData); chunk.GetBlockData(pos.x - 1, pos.y, pos.z, out byte leftType, out byte leftData); chunk.GetBlockData(pos.x + 1, pos.y, pos.z, out byte rightType, out byte rightData); chunk.GetBlockData(pos.x, pos.y - 1, pos.z, out byte bottomType, out byte bottomData); chunk.GetBlockData(pos.x, pos.y + 1, pos.z, out byte topType, out byte topData); bool selfIsVerticalWater = IsVerticalWater(blockData); chunk.GetLights(pos.x, pos.y, pos.z, out float skyLight, out float blockLight); fa.color = Color.white; fa.skyLight = skylight_default; fa.blockLight = blocklight_default; fa.uv = uv_zero; if (NBTGeneratorManager.IsTransparent(frontType) && frontType != TYPE_WATER) { if (selfIsVerticalWater) { fa.pos[0] = nearBottomLeft; fa.pos[1] = nearTopLeft; fa.pos[2] = nearTopRight; fa.pos[3] = nearBottomRight; } else { fa.pos[0] = nearBottomLeft; fa.pos[1] = nearTopLeft_still; fa.pos[2] = nearTopRight_still; fa.pos[3] = nearBottomRight; } fa.normal = Vector3.forward; AddFace(nbtGO.nbtMesh, fa, ca); } if (NBTGeneratorManager.IsTransparent(backType) && backType != TYPE_WATER) { if (selfIsVerticalWater) { fa.pos[0] = farBottomRight; fa.pos[1] = farTopRight; fa.pos[2] = farTopLeft; fa.pos[3] = farBottomLeft; } else { fa.pos[0] = farBottomRight; fa.pos[1] = farTopRight_still; fa.pos[2] = farTopLeft_still; fa.pos[3] = farBottomLeft; } fa.normal = Vector3.back; AddFace(nbtGO.nbtMesh, fa, ca); } if (NBTGeneratorManager.IsTransparent(leftType) && leftType != TYPE_WATER) { if (selfIsVerticalWater) { fa.pos[0] = farBottomLeft; fa.pos[1] = farTopLeft; fa.pos[2] = nearTopLeft; fa.pos[3] = nearBottomLeft; } else { fa.pos[0] = farBottomLeft; fa.pos[1] = farTopLeft_still; fa.pos[2] = nearTopLeft_still; fa.pos[3] = nearBottomLeft; } fa.normal = Vector3.left; AddFace(nbtGO.nbtMesh, fa, ca); } if (NBTGeneratorManager.IsTransparent(rightType) && rightType != TYPE_WATER) { if (selfIsVerticalWater) { fa.pos[0] = nearBottomRight; fa.pos[1] = nearTopRight; fa.pos[2] = farTopRight; fa.pos[3] = farBottomRight; } else { fa.pos[0] = nearBottomRight; fa.pos[1] = nearTopRight_still; fa.pos[2] = farTopRight_still; fa.pos[3] = farBottomRight; } fa.normal = Vector3.right; AddFace(nbtGO.nbtMesh, fa, ca); } if (NBTGeneratorManager.IsTransparent(topType) && topType != TYPE_WATER) { if (selfIsVerticalWater) { fa.pos[0] = farTopRight; fa.pos[1] = nearTopRight; fa.pos[2] = nearTopLeft; fa.pos[3] = farTopLeft; } else { bool leftIsVerticalWater = IsVerticalWater(leftData, leftType); bool rightIsVerticalWater = IsVerticalWater(rightData, rightType); bool frontIsVerticalWater = IsVerticalWater(frontData, frontType); bool backIsVerticalWater = IsVerticalWater(backData, backType); fa.pos[0] = backIsVerticalWater || rightIsVerticalWater ? farTopRight : farTopRight_still; fa.pos[1] = frontIsVerticalWater || rightIsVerticalWater ? nearTopRight : nearTopRight_still; fa.pos[2] = frontIsVerticalWater || leftIsVerticalWater ? nearTopLeft : nearTopLeft_still; fa.pos[3] = backIsVerticalWater || leftIsVerticalWater ? farTopLeft : farTopLeft_still; } fa.normal = Vector3.up; AddFace(nbtGO.nbtMesh, fa, ca); } if (NBTGeneratorManager.IsTransparent(bottomType) && bottomType != TYPE_WATER) { fa.pos[0] = nearBottomRight; fa.pos[1] = farBottomRight; fa.pos[2] = farBottomLeft; fa.pos[3] = nearBottomLeft; fa.normal = Vector3.down; AddFace(nbtGO.nbtMesh, fa, ca); } }
// upper door // 0x1: 0 if hinge is on the left (the default), 1 if on the right // 0x2: 0 if unpowered, 1 if powered // 0x4: unused // 0x8: Always 1 for the upper part of a door. // lower door // 0x1,0x2: Two bits storing a value from 0 to 3 specifying the direction the door is facing: // 0: Facing east // 1: Facing south // 2: Facing west // 3: Facing north // 0x4: 0 if the entire door is closed, 1 if open. // 0x8: Always 0 for the lower part of a door. void FillMesh(NBTChunk chunk, CubeAttributes ca, NBTMesh nbtMesh) { float skyLight, blockLight; if (ca.isItemMesh) { chunk.GetLights(ca.worldPos.x, ca.worldPos.y, ca.worldPos.z, out skyLight, out blockLight); } else { chunk.GetLights(ca.pos.x, ca.pos.y, ca.pos.z, out skyLight, out blockLight); } FaceAttributes fa = new FaceAttributes(); fa.color = Color.white; fa.skyLight = new float[] { skyLight, skyLight, skyLight, skyLight }; fa.blockLight = new float[] { blockLight, blockLight, blockLight, blockLight }; fa.normal = Vector3.zero; bool isUpper = (ca.blockData & 0b1000) > 0; int hinge; DoorDirection direction = 0; bool isOpen = false; if (isUpper) { chunk.GetBlockData(ca.pos.x, ca.pos.y - 1, ca.pos.z, out byte belowType, out byte belowData); if (belowType == 64) { isOpen = (belowData & 0b0100) > 0; direction = (DoorDirection)(belowData & 0b0011); } hinge = (ca.blockData & 0b0001); } else { isOpen = (ca.blockData & 0b0100) > 0; direction = (DoorDirection)(ca.blockData & 0b0011); chunk.GetBlockData(ca.pos.x, ca.pos.y + 1, ca.pos.z, out byte aboveType, out byte aboveData); hinge = (aboveData & 0b0001); } if (ca.isBreakingMesh) { ca.pos = Vector3Int.zero; } try { fa.faceIndex = TextureArrayManager.GetIndexByName(isUpper ? "door_wood_upper" : "door_wood_lower"); if ((direction == DoorDirection.East && isOpen == false) || (direction == DoorDirection.South && isOpen && hinge == 1) || (direction == DoorDirection.North && isOpen && hinge == 0)) { fa.uv = uv_top; fa.pos = topVertices_east; AddFace(nbtMesh, fa, ca); fa.pos = bottomVertices_east; AddFace(nbtMesh, fa, ca); fa.uv = hinge == 0 ? uv_flip : uv_zero; fa.pos = leftVertices_east; AddFace(nbtMesh, fa, ca); fa.pos = rightVertices_east; AddFace(nbtMesh, fa, ca); fa.uv = hinge == 0 ? uv_side_flip : uv_side; fa.pos = frontVertices_east; AddFace(nbtMesh, fa, ca); fa.pos = backVertices_east; AddFace(nbtMesh, fa, ca); } else if ((direction == DoorDirection.South && isOpen == false) || (direction == DoorDirection.East && isOpen && hinge == 0) || (direction == DoorDirection.West && isOpen && hinge == 1)) { fa.uv = hinge == 0 ? uv_flip : uv_zero; fa.pos = frontVertices_south; AddFace(nbtMesh, fa, ca); fa.pos = backVertices_south; AddFace(nbtMesh, fa, ca); fa.uv = uv_top; fa.pos = topVertices_south; AddFace(nbtMesh, fa, ca); fa.pos = bottomVertices_south; AddFace(nbtMesh, fa, ca); fa.uv = hinge == 0 ? uv_side_flip : uv_side; fa.pos = leftVertices_south; AddFace(nbtMesh, fa, ca); fa.pos = rightVertices_south; AddFace(nbtMesh, fa, ca); } else if ((direction == DoorDirection.West && isOpen == false) || (direction == DoorDirection.South && isOpen && hinge == 0) || (direction == DoorDirection.North && isOpen && hinge == 1)) { fa.uv = uv_top; fa.pos = topVertices_west; AddFace(nbtMesh, fa, ca); fa.pos = bottomVertices_west; AddFace(nbtMesh, fa, ca); fa.uv = hinge == 0 ? uv_flip : uv_zero; fa.pos = leftVertices_west; AddFace(nbtMesh, fa, ca); fa.pos = rightVertices_west; AddFace(nbtMesh, fa, ca); fa.uv = hinge == 0 ? uv_side_flip : uv_side; fa.pos = frontVertices_west; AddFace(nbtMesh, fa, ca); fa.pos = backVertices_west; AddFace(nbtMesh, fa, ca); } else if ((direction == DoorDirection.North && isOpen == false) || (direction == DoorDirection.East && isOpen && hinge == 1) || (direction == DoorDirection.West && isOpen && hinge == 0)) { fa.uv = hinge == 0 ? uv_flip : uv_zero; fa.pos = frontVertices_north; AddFace(nbtMesh, fa, ca); fa.pos = backVertices_north; AddFace(nbtMesh, fa, ca); fa.uv = uv_top; fa.pos = topVertices_north; AddFace(nbtMesh, fa, ca); fa.pos = bottomVertices_north; AddFace(nbtMesh, fa, ca); fa.uv = hinge == 0 ? uv_side_flip : uv_side; fa.pos = leftVertices_north; AddFace(nbtMesh, fa, ca); fa.pos = rightVertices_north; AddFace(nbtMesh, fa, ca); } } catch (System.Exception e) { Debug.Log(e.ToString() + "\n" + "pos=" + ca.pos + ",data=" + ca.blockData); } }