public void AddCubeSurface(MeshTool.BlockSurface surface, int normalIndex, BlockTypeFunBase blockFun) { int startVericesNum = vertices.Count; //三角形 for (int t = 0; t < 6; t++) { triangles.Add(startVericesNum + indices[t]); } //顶点 for (int p = 0; p < 4; p++) { vertices.Add(surface.pos + MeshTool.VertexOffset[normalIndex, p]); normals.Add(MeshTool.NormalDefine[normalIndex]); tangents.Add(new Vector4(surface.raytraceAo[0], surface.raytraceAo[1], surface.raytraceAo[2], surface.raytraceAo[3])); colors.Add(blockFun.getFaceColor(surface.type, (Block.BlockFaceIndex)normalIndex)); } //uv Rect rect = blockFun.getTextureUV(surface.type, (Block.BlockFaceIndex)normalIndex); uv.Add(new Vector2(rect.xMax, rect.yMin)); uv.Add(new Vector2(rect.xMin, rect.yMin)); uv.Add(new Vector2(rect.xMin, rect.yMax)); uv.Add(new Vector2(rect.xMax, rect.yMax)); //uv2 uv2.Add(new Vector2(0, 0)); uv2.Add(new Vector2(0, 1)); uv2.Add(new Vector2(1, 1)); uv2.Add(new Vector2(1, 0)); }
public void AddSurface(MeshTool.BlockSurface surface, int normalIndex, BlockTypeFunBase blockFun) { if (surface.type >= (short)Game.BlockType.StairLeft && surface.type <= (short)Game.BlockType.StairFront) { string[] names = { "stair0", "stair1", "stair4", "stair5" }; SimpleModel model = SimpleModelFactory.GetModel(names[surface.type - (short)Game.BlockType.StairLeft]); for (int i = 0; i < model.quads[normalIndex].Count; i++) { SimpleModel.Quad quad = model.quads[normalIndex][i]; AddSubSurface(surface, normalIndex, blockFun, quad.rect, quad.depth); } } else { AddCubeSurface(surface, normalIndex, blockFun); } }
private void AddSubSurface(MeshTool.BlockSurface surface, int normalIndex, BlockTypeFunBase blockFun, Rect rect, float depth) { int startVericesNum = vertices.Count; //三角形 for (int t = 0; t < 6; t++) { triangles.Add(startVericesNum + indices[t]); } //顶点 Vector3[] vs = GetSubSurfaceVertex(normalIndex, rect, depth); for (int p = 0; p < 4; p++) { Vector3 pos = surface.pos + vs[p]; vertices.Add(pos); normals.Add(MeshTool.NormalDefine[normalIndex]); //tangents.Add(new Vector4(surface.raytraceAo[0], surface.raytraceAo[1], surface.raytraceAo[2], surface.raytraceAo[3])); Color color = blockFun.getFaceColor(surface.type, (Block.BlockFaceIndex)normalIndex); //color *= ((vs[p] - Vector3.one * 0.5f).magnitude); //color.a = surface.raytraceAo[p]; color.a = (surface.extendAo[p] * 0.5f + 0.5f) * surface.raytraceAo[p]; colors.Add(color); } //uv Rect uvRect = blockFun.getTextureUV(surface.type, (Block.BlockFaceIndex)normalIndex); uvRect = GetSubRect(uvRect, rect); uv.Add(new Vector2(uvRect.xMax, uvRect.yMin)); uv.Add(new Vector2(uvRect.xMin, uvRect.yMin)); uv.Add(new Vector2(uvRect.xMin, uvRect.yMax)); uv.Add(new Vector2(uvRect.xMax, uvRect.yMax)); //uv2 uv2.Add(new Vector2(rect.xMin, rect.yMin)); uv2.Add(new Vector2(rect.xMax, rect.yMin)); uv2.Add(new Vector2(rect.xMax, rect.yMax)); uv2.Add(new Vector2(rect.xMin, rect.yMax)); }
public abstract void AddSurface(MeshTool.BlockSurface surface, int normalIndex, BlockTypeFunBase blockFun);