public void AddBlock(Vector3Int pos, Vector3Int renderOffset, BlockData block, IWorldRAccessor accessor) { Quaternion rotation = accessor.GetBlockRotation(pos.x, pos.y, pos.z, Quaternion.identity); BlockMesh mesh = accessor.World.BlockDataTable.GetMesh(block.Mesh.Value); for (int i = 0; i < mesh.Faces.Length; i++) { BlockMesh.FaceData face = mesh.Faces[i]; BlockFace faceDir = RotateFace(face.Face, rotation); if (EnableFaceClipping) { // 没有撑满一格的方块所有的面都渲染 Vector3 size = mesh.BoundingBox.Size; bool neverClip = face.NeverClip | size.x < 1 | size.y < 1 | size.z < 1; if (!neverClip && ClipFace(pos, block, faceDir, accessor)) { continue; } } int?[] texIndices = block.Textures[i]; // !!! must add indices first for (int j = 0; j < face.Indices.Length; j++) { AddIndex(face.Indices[j], block.Material.Value); } for (int j = 0; j < face.Vertices.Length; j++) { BlockVertexData vertex = face.Vertices[j]; vertex.Position = MathUtility.RotatePoint(vertex.Position, rotation, mesh.Pivot); float emission = block.GetEmissionValue(); Vector2 ambient = LightingUtility.AmbientOcclusion(pos, faceDir, vertex.CornerInFace, accessor, !EnableAmbientOcclusion); Vector3 posWS = WriteBlockWSPosToVertexData ? (pos + accessor.WorldSpaceOrigin) : Vector3.down; AddVertex(new BlockMeshVertexData { PositionOS = vertex.Position + pos + renderOffset, UV = vertex.UV, TexIndices = new Vector3Int(texIndices[0].Value, texIndices[1].Value, texIndices[2].Value), Lights = new Vector3(emission, ambient.x, ambient.y), BlockPositionWS = posWS }); } } }