本文整理汇总了C#中MeshData.AddVertex方法的典型用法代码示例。如果您正苦于以下问题:C# MeshData.AddVertex方法的具体用法?C# MeshData.AddVertex怎么用?C# MeshData.AddVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshData
的用法示例。
在下文中一共展示了MeshData.AddVertex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FaceDataSouth
protected override MeshData FaceDataSouth(Chunk chunk, int x, int y, int z, MeshData meshData)
{
meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z - 0.5f));
meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z - 0.5f));
meshData.AddVertex(new Vector3(x + 0.5f, y + 0.5f, z - 0.5f));
meshData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, z - 0.5f));
meshData.AddQuadTempVertexTriangles();
meshData.uv.AddRange(FaceUVs(Direction.south));
return meshData;
}
示例2: Vector3
protected virtual MeshData FaceDataDown
(Chunk chunk, int x, int y, int z, MeshData meshData)
{
meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z - 0.5f));
meshData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, z - 0.5f));
meshData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, z + 0.5f));
meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z + 0.5f));
meshData.AddQuadTriangles();
meshData.uv.AddRange(FaceUVs(Direction.down));
return meshData;
}
示例3: GenerateTerrainMesh
public static MeshData GenerateTerrainMesh(float[,] heightMap, float heightMultiplier, AnimationCurve _heightCurve, int levelOfDetail) {
AnimationCurve heightCurve = new AnimationCurve (_heightCurve.keys);
int meshSimplificationIncrement = (levelOfDetail == 0)?1:levelOfDetail * 2;
int borderedSize = heightMap.GetLength (0);
int meshSize = borderedSize - 2*meshSimplificationIncrement;
int meshSizeUnsimplified = borderedSize - 2;
float topLeftX = (meshSizeUnsimplified - 1) / -2f;
float topLeftZ = (meshSizeUnsimplified - 1) / 2f;
int verticesPerLine = (meshSize - 1) / meshSimplificationIncrement + 1;
MeshData meshData = new MeshData (verticesPerLine);
int[,] vertexIndicesMap = new int[borderedSize,borderedSize];
int meshVertexIndex = 0;
int borderVertexIndex = -1;
for (int y = 0; y < borderedSize; y += meshSimplificationIncrement) {
for (int x = 0; x < borderedSize; x += meshSimplificationIncrement) {
bool isBorderVertex = y == 0 || y == borderedSize - 1 || x == 0 || x == borderedSize - 1;
if (isBorderVertex) {
vertexIndicesMap [x, y] = borderVertexIndex;
borderVertexIndex--;
} else {
vertexIndicesMap [x, y] = meshVertexIndex;
meshVertexIndex++;
}
}
}
for (int y = 0; y < borderedSize; y += meshSimplificationIncrement) {
for (int x = 0; x < borderedSize; x += meshSimplificationIncrement) {
int vertexIndex = vertexIndicesMap [x, y];
Vector2 percent = new Vector2 ((x-meshSimplificationIncrement) / (float)meshSize, (y-meshSimplificationIncrement) / (float)meshSize);
float height = heightCurve.Evaluate (heightMap [x, y]) * heightMultiplier;
Vector3 vertexPosition = new Vector3 (topLeftX + percent.x * meshSizeUnsimplified, height, topLeftZ - percent.y * meshSizeUnsimplified);
meshData.AddVertex (vertexPosition, percent, vertexIndex);
if (x < borderedSize - 1 && y < borderedSize - 1) {
int a = vertexIndicesMap [x, y];
int b = vertexIndicesMap [x + meshSimplificationIncrement, y];
int c = vertexIndicesMap [x, y + meshSimplificationIncrement];
int d = vertexIndicesMap [x + meshSimplificationIncrement, y + meshSimplificationIncrement];
meshData.AddTriangle (a,d,c);
meshData.AddTriangle (d,a,b);
}
vertexIndex++;
}
}
return meshData;
}
示例4: Vector3
protected virtual MeshData FaceDataUp
(Chunk chunk, int x, int y, int z, MeshData meshData, int CycleNumber)
{
meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z + 0.5f));
meshData.AddVertex(new Vector3(x + 0.5f, y + 0.5f, z + 0.5f));
meshData.AddVertex(new Vector3(x + 0.5f, y + 0.5f, z - 0.5f));
meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z - 0.5f));
meshData.AddQuadTriangles();
meshData.uv.AddRange(FaceUVs(Direction.up));
return meshData;
}
示例5: getBeamMesh
public virtual MeshData getBeamMesh(Vector3 start, Vector3 end, float width, MeshData meshData)
{
Vector3[] points = new Vector3[3];
Vector2[] UVs = new Vector2[3];
Vector3 tip = end - start;
float mag = tip.magnitude;
Vector3 perp = new Vector3 (-tip.y, tip.x, tip.z) / mag;
Vector3 base1 = (perp * width/4) + tip/mag;
Vector3 base2 = (perp * -width/4) + tip/mag;
//Vector3 base3 = Quaternion.Euler(300, 0, 0) * perp;
UVs [2] = new Vector2 (0.0f, Math.Min (0.4f+width,1.0f));
UVs [1] = new Vector2 (0.0f, Math.Max (0.6f-width,0.0f));
UVs [0] = new Vector2 (0.1f, 0.5f);
meshData.AddVertex(Vector3.zero);
meshData.AddVertex(base1);
meshData.AddVertex(base2);
meshData.AddTriangle();
meshData.uv.AddRange(UVs);
UVs [1] = new Vector2 (0.0f, Math.Min (0.4f+width,1.0f));
UVs [2] = new Vector2 (0.0f, Math.Max (0.6f-width,0.0f));
UVs [0] = new Vector2 (0.1f, 0.5f);
meshData.AddVertex(tip);
meshData.AddVertex(base2);
meshData.AddVertex(base1);
meshData.AddTriangle();
meshData.uv.AddRange(UVs);
return meshData;
}
示例6: AddQuadFlat
public virtual MeshData AddQuadFlat( Vector3[] points, MeshData meshData)
{
//Takes 4 points, calculates two normals for two faces
//Adds the points and triangles to the mesh
Vector3 flatnorm1 = new Vector3();
flatnorm1 = Vector3.Cross (points [1] - points [0], points [3] - points [0]);
Vector3 flatnorm2 = new Vector3();
flatnorm2 = Vector3.Cross (points [3] - points [2], points [1] - points [2]);
//set the vertices
meshData.AddVertex(points [0], flatnorm1);
meshData.AddVertex(points [1], flatnorm1);
meshData.AddVertex(points [3], flatnorm1);
meshData.AddTriangle();
meshData.AddVertex(points [1], flatnorm2);
meshData.AddVertex(points [2], flatnorm2);
meshData.AddVertex(points [3], flatnorm2);
meshData.AddTriangle();
Color32[] vcolors = new Color32[6];
vcolors [2] = Color.white;
vcolors [4] = Color.white;
vcolors [5] = Color.white;
vcolors [0] = Color.white;
vcolors [1] = Color.white;
vcolors [3] = Color.white;
meshData.colors.AddRange (vcolors);
return meshData;
}
示例7: AddBlockData
public override void AddBlockData(Chunk chunk, BlockPos pos, MeshData meshData, Block block)
{
int initialVertCount = meshData.vertices.Count;
foreach (var vert in verts)
{
meshData.AddVertex(vert + (Vector3)pos);
if (uvs.Length == 0)
meshData.uv.Add(new Vector2(0, 0));
float lighting;
if (Config.Toggle.BlockLighting)
{
lighting = block.data1 / 255f;
}
else
{
lighting = 1;
}
meshData.colors.Add(new Color(lighting, lighting, lighting, 1));
}
if (uvs.Length != 0)
{
Rect texture;
if (collection != null)
texture = collection.GetTexture(chunk, pos, Direction.down);
else
texture = new Rect();
foreach (var uv in uvs)
{
meshData.uv.Add(new Vector2((uv.x * texture.width) + texture.x, (uv.y * texture.height) + texture.y));
}
}
foreach (var tri in tris)
{
meshData.AddTriangle(tri + initialVertCount);
}
}
示例8: AddBlockData
public override void AddBlockData(Chunk chunk, BlockPos pos, MeshData meshData, Block block)
{
int initialVertCount = meshData.vertices.Count;
foreach (var vert in verts)
{
meshData.AddVertex(vert + (Vector3)pos);
if (uvs.Length == 0)
meshData.uv.Add(new Vector2(0, 0));
float lighting;
if (Config.Toggle.BlockLighting)
{
lighting = block.data1 / 255f;
}
else
{
lighting = 1;
}
meshData.colors.Add(new Color(lighting, lighting, lighting, 1));
}
if (uvs.Length != 0)
{
foreach (var uv in uvs)
{
meshData.uv.Add(uv);
}
}
foreach (var tri in tris)
{
meshData.AddTriangle(tri + initialVertCount);
}
}
示例9: CrossMeshRenderer
public static void CrossMeshRenderer(Chunk chunk, BlockPos pos, MeshData meshData, TextureCollection texture, Block block)
{
float halfBlock = (Config.Env.BlockSize / 2) + Config.Env.BlockFacePadding;
float colliderOffest = 0.05f * Config.Env.BlockSize;
float blockHeight = halfBlock * 2 * (block.data2 / 255f);
//Converting the position to a vector adjusts it based on block size and gives us real world coordinates for x, y and z
Vector3 vPos = pos;
float blockLight = ( (block.data1/255f) * Config.Env.BlockLightStrength) + (0.8f*Config.Env.AOStrength);
meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z + halfBlock));
meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock + blockHeight, vPos.z + halfBlock));
meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock + blockHeight, vPos.z - halfBlock));
meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z - halfBlock));
meshData.AddQuadTriangles();
BlockBuilder.BuildTexture(chunk, vPos, meshData, Direction.north, texture);
meshData.AddColors(blockLight, blockLight, blockLight, blockLight, blockLight);
meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z - halfBlock));
meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock + blockHeight, vPos.z - halfBlock));
meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock + blockHeight, vPos.z + halfBlock));
meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z + halfBlock));
meshData.AddQuadTriangles();
BlockBuilder.BuildTexture(chunk, vPos, meshData, Direction.north, texture);
meshData.AddColors(blockLight, blockLight, blockLight, blockLight, blockLight);
meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z + halfBlock));
meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock + blockHeight, vPos.z + halfBlock));
meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock + blockHeight, vPos.z - halfBlock));
meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z - halfBlock));
meshData.AddQuadTriangles();
BlockBuilder.BuildTexture(chunk, vPos, meshData, Direction.north, texture);
meshData.AddColors(blockLight, blockLight, blockLight, blockLight, blockLight);
meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z - halfBlock));
meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock + blockHeight, vPos.z - halfBlock));
meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock + blockHeight, vPos.z + halfBlock));
meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z + halfBlock));
meshData.AddQuadTriangles();
BlockBuilder.BuildTexture(chunk, vPos, meshData, Direction.north, texture);
meshData.AddColors(blockLight, blockLight, blockLight, blockLight, blockLight);
meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock + colliderOffest, vPos.z + halfBlock), collisionMesh: true);
meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock + colliderOffest, vPos.z + halfBlock), collisionMesh: true);
meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock + colliderOffest, vPos.z - halfBlock), collisionMesh: true);
meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock + colliderOffest, vPos.z - halfBlock), collisionMesh: true);
meshData.AddQuadTriangles(collisionMesh:true);
}
示例10: buildFaceWest
protected virtual MeshData buildFaceWest(Vector3 start, Vector3 end, MeshData meshData)
{
meshData.AddVertex (new Vector3(end.x, start.y, start.z));
meshData.AddVertex (new Vector3(end.x, start.y, end.z));
meshData.AddVertex (new Vector3(end.x, end.y, end.z));
meshData.AddVertex (new Vector3(end.x, end.y, start.z));
meshData.AddQuadTriangles();
meshData.uv.AddRange (FlatUVs ());
return meshData;
}
示例11: AddQuadToMeshData
static void AddQuadToMeshData(Chunk chunk, BlockPos pos, MeshData meshData, Direction direction,bool useCollisionMesh)
{
//Adding a tiny overlap between block meshes may solve floating point imprecision
//errors causing pixel size gaps between blocks when looking closely
float halfBlock = 0.5005f;
switch (direction)
{
case Direction.up:
meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y + halfBlock, pos.z + halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y + halfBlock, pos.z + halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y + halfBlock, pos.z - halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y + halfBlock, pos.z - halfBlock), useCollisionMesh);
break;
case Direction.down:
meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y - halfBlock, pos.z - halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y - halfBlock, pos.z - halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y - halfBlock, pos.z + halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y - halfBlock, pos.z + halfBlock), useCollisionMesh);
break;
case Direction.north:
meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y - halfBlock, pos.z + halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y + halfBlock, pos.z + halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y + halfBlock, pos.z + halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y - halfBlock, pos.z + halfBlock), useCollisionMesh);
break;
case Direction.east:
meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y - halfBlock, pos.z - halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y + halfBlock, pos.z - halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y + halfBlock, pos.z + halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y - halfBlock, pos.z + halfBlock), useCollisionMesh);
break;
case Direction.south:
meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y - halfBlock, pos.z - halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y + halfBlock, pos.z - halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y + halfBlock, pos.z - halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y - halfBlock, pos.z - halfBlock), useCollisionMesh);
break;
case Direction.west:
meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y - halfBlock, pos.z + halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y + halfBlock, pos.z + halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y + halfBlock, pos.z - halfBlock), useCollisionMesh);
meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y - halfBlock, pos.z - halfBlock), useCollisionMesh);
break;
default:
Debug.LogError("Direction not recognized");
break;
}
meshData.AddQuadTriangles(useCollisionMesh);
}
示例12: FaceData
protected virtual MeshData FaceData(Chunk chunk, Vector3 corner, Vector3 v1, Vector3 v2, Direction direction, MeshData meshData)
{
meshData.AddVertex (corner + v1);
meshData.AddVertex (corner + v1 + v2);
meshData.AddVertex (corner + v2);
meshData.AddVertex (corner);
meshData.AddQuadTriangles ();
meshData.uv.AddRange(FaceUVs(direction));
return meshData;
}
示例13: GetFace
// converts the block model into mesh data
// block model stores 6 different meshes that correspond to sides
protected override MeshData GetFace(Direction direction, Chunk chunk, int x, int y, int z, MeshData meshData, int CycleNumber) {
if ((CycleNumber == 0 && TileIndex != 4) || (CycleNumber == 1 && TileIndex == 4)) {
if (chunk.DataManager == null) {
Debug.LogError("Chunk.DataManager ?,? is null inside mesh creation");
return meshData;
}
BlockModel MyModel = chunk.DataManager.GetBlockModel (TileIndex);
if (MyModel == null) {
Debug.LogError("MyModel is null inside mesh creation");
return meshData;
}
MyMesh FaceModel = MyModel.GetModel (direction);
if (FaceModel == null) {
Debug.LogError("My FaceModel! is null inside mesh creation");
return meshData;
}
BlockData MyBlockData = chunk.DataManager.GetBlockData (TileIndex);
if (MyBlockData == null) {
Debug.LogError("MyBlockData is null inside mesh creation");
return meshData;
}
// reposition indicies by the the previously added vertice count
int TrianglesBuffer = meshData.vertices.Count;
for (int i = 0; i < FaceModel.Indicies.Count; i++) {
meshData.triangles.Add (TrianglesBuffer + FaceModel.Indicies [i]);
if (chunk.IsCollisions)
meshData.colTriangles.Add (TrianglesBuffer + FaceModel.Indicies [i]);
}
// reposition meshes by the grid
for (int i = 0; i < FaceModel.Verticies.Count; i++) {
Vector3 NewVert = new Vector3 (x, y, z) + FaceModel.Verticies [i];
if (MyBlockData.IsDeformed) {
float VertexNoiseValue = Noise.Generate (NewVert.x + chunk.pos.x, NewVert.y + chunk.pos.y, NewVert.z + chunk.pos.z) / 4f;
NewVert += new Vector3 (VertexNoiseValue, VertexNoiseValue, VertexNoiseValue);
}
meshData.AddVertex (NewVert);
}
List<Vector2> BlockTextureCoordinates = MyModel.GetTextureCoordinates (TileIndex, direction);
for (int i = 0; i < BlockTextureCoordinates.Count; i++) {
meshData.uv.Add (BlockTextureCoordinates [i]);
}
for (int i = 0; i < FaceModel.Verticies.Count; i++) {
if (direction == Direction.up) {
int LightValue2 = 255;
BlockBase AdjacentBlock = chunk.GetBlock(x,y+1,z);
if (AdjacentBlock != null) {
LightValue2 = AdjacentBlock.LightValue;
}
meshData.colors.Add (new Color32((byte)LightValue2,(byte)LightValue2,(byte)LightValue2,255));
}
else if (direction == Direction.down) {
int LightValue2 = 255;
BlockBase AdjacentBlock = chunk.GetBlock(x,y-1,z);
if (AdjacentBlock != null) {
LightValue2 = AdjacentBlock.LightValue;
}
meshData.colors.Add (new Color32((byte)LightValue2,(byte)LightValue2,(byte)LightValue2,255));
} else if (direction == Direction.west) {
int LightValue2 = 255;
BlockBase AdjacentBlock = chunk.GetBlock(x-1,y,z);
if (AdjacentBlock != null) {
LightValue2 = AdjacentBlock.LightValue;
}
meshData.colors.Add (new Color32((byte)LightValue2,(byte)LightValue2,(byte)LightValue2,255));
}
else if (direction == Direction.east) {
int LightValue2 = 255;
BlockBase AdjacentBlock = chunk.GetBlock(x+1,y,z);
if (AdjacentBlock != null) {
LightValue2 = AdjacentBlock.LightValue;
}
meshData.colors.Add (new Color32((byte)LightValue2,(byte)LightValue2,(byte)LightValue2,255));
}
else if (direction == Direction.north) {
int LightValue2 = 255;
BlockBase AdjacentBlock = chunk.GetBlock(x,y,z+1);
if (AdjacentBlock != null) {
LightValue2 = AdjacentBlock.LightValue;
}
meshData.colors.Add (new Color32((byte)LightValue2,(byte)LightValue2,(byte)LightValue2,255));
}
else if (direction == Direction.south) {
int LightValue2 = 255;
BlockBase AdjacentBlock = chunk.GetBlock(x,y,z-1);
if (AdjacentBlock != null) {
LightValue2 = AdjacentBlock.LightValue;
}
meshData.colors.Add (new Color32((byte)LightValue2,(byte)LightValue2,(byte)LightValue2,255));
}
}
}
return meshData;
}
示例14: MakeFenceFace
static void MakeFenceFace(Chunk chunk, BlockPos pos, MeshData meshData, Direction direction, bool useCollisionMesh, Vector3 ModelSize, Vector3 ConnMeshSizeX, Vector3 ConnMeshSizeY, Vector3 ConnMeshSizeZ, Direction[] Dir)
{
//Adding a tiny overlap between block meshes may solve floating point imprecision
//errors causing pixel size gaps between blocks when looking closely
float halfBlockX = 0;
float halfBlockY = 0;
float halfBlockZ = 0;
//Converting the position to a vector adjusts it based on block size and gives us real world coordinates for x, y and z
foreach (Direction localDir in Dir)
{
Vector3 vPos = new Vector3();
if (localDir == Direction.north)
{
vPos = new Vector3(pos.x, pos.y, pos.z + ModelSize.z);
halfBlockX = (ConnMeshSizeZ.x / 2) + Config.Env.BlockFacePadding;
halfBlockY = (ConnMeshSizeZ.y / 2) + Config.Env.BlockFacePadding;
halfBlockZ = (ConnMeshSizeZ.z / 2) + Config.Env.BlockFacePadding;
}
else if (localDir == Direction.south)
{
vPos = new Vector3(pos.x, pos.y, pos.z - ModelSize.z);
halfBlockX = (ConnMeshSizeZ.x / 2) + Config.Env.BlockFacePadding;
halfBlockY = (ConnMeshSizeZ.y / 2) + Config.Env.BlockFacePadding;
halfBlockZ = (ConnMeshSizeZ.z / 2) + Config.Env.BlockFacePadding;
}
else if (localDir == Direction.east)
{
vPos = new Vector3(pos.x + ModelSize.x, pos.y, pos.z);
halfBlockX = (ConnMeshSizeX.x / 2) + Config.Env.BlockFacePadding;
halfBlockY = (ConnMeshSizeX.y / 2) + Config.Env.BlockFacePadding;
halfBlockZ = (ConnMeshSizeX.z / 2) + Config.Env.BlockFacePadding;
}
else if (localDir == Direction.west)
{
vPos = new Vector3(pos.x - ModelSize.x, pos.y, pos.z);
halfBlockX = (ConnMeshSizeX.x / 2) + Config.Env.BlockFacePadding;
halfBlockY = (ConnMeshSizeX.y / 2) + Config.Env.BlockFacePadding;
halfBlockZ = (ConnMeshSizeX.z / 2) + Config.Env.BlockFacePadding;
}
else if (localDir == Direction.up)
{
vPos = new Vector3(pos.x, pos.y + ModelSize.y, pos.z);
halfBlockX = (ConnMeshSizeY.x / 2) + Config.Env.BlockFacePadding;
halfBlockY = (ConnMeshSizeY.y / 2) + Config.Env.BlockFacePadding;
halfBlockZ = (ConnMeshSizeY.z / 2) + Config.Env.BlockFacePadding;
}
else if (localDir == Direction.down)
{
vPos = new Vector3(pos.x, pos.y - ModelSize.y, pos.z);
halfBlockX = (ConnMeshSizeY.x / 2) + Config.Env.BlockFacePadding;
halfBlockY = (ConnMeshSizeY.y / 2) + Config.Env.BlockFacePadding;
halfBlockZ = (ConnMeshSizeY.z / 2) + Config.Env.BlockFacePadding;
}
switch (direction)
{
case Direction.up:
meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y + halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y + halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y + halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y + halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
break;
case Direction.down:
meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y - halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y - halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y - halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y - halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
break;
case Direction.north:
meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y - halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y + halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y + halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y - halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
break;
case Direction.east:
meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y - halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y + halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y + halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y - halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
break;
case Direction.south:
meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y - halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y + halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y + halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y - halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
break;
case Direction.west:
meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y - halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y + halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y + halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y - halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
break;
default:
Debug.LogError("Direction not recognized");
break;
}
meshData.AddQuadTriangles(useCollisionMesh);
}
//.........这里部分代码省略.........
示例15: AddBlockData
public override void AddBlockData(Chunk chunk, BlockPos pos, MeshData meshData, Block block)
{
int initialVertCount = meshData.vertices.Count;
int colInitialVertCount = meshData.colVertices.Count;
foreach (var vert in verts)
{
meshData.AddVertex(vert + (Vector3)pos);
meshData.colVertices.Add(vert + (Vector3)pos);
if (uvs.Length == 0)
meshData.uv.Add(new Vector2(0, 0));
float lighting;
if (Config.Toggle.BlockLighting)
{
lighting = block.data1 / 255f;
}
else
{
lighting = 1;
}
meshData.colors.Add(new Color(lighting, lighting, lighting, 1));
}
if (uvs.Length != 0)
{
Rect texture;
if (collection != null)
texture = collection.GetTexture(chunk, pos, Direction.down);
else
texture = new Rect();
foreach (var uv in uvs)
{
meshData.uv.Add(new Vector2((uv.x * texture.width) + texture.x, (uv.y * texture.height) + texture.y));
}
}
if (!chunk.GetBlock(pos.Add(Direction.up)).controller.IsSolid(Direction.down))
{
foreach (var tri in trisUp)
{
meshData.AddTriangle(tri + initialVertCount);
meshData.colTriangles.Add(tri + colInitialVertCount);
}
}
if (!chunk.GetBlock(pos.Add(Direction.down)).controller.IsSolid(Direction.up))
{
foreach (var tri in trisDown)
{
meshData.AddTriangle(tri + initialVertCount);
meshData.colTriangles.Add(tri + colInitialVertCount);
}
}
if (!chunk.GetBlock(pos.Add(Direction.north)).controller.IsSolid(Direction.south))
{
foreach (var tri in trisNorth)
{
meshData.AddTriangle(tri + initialVertCount);
meshData.colTriangles.Add(tri + colInitialVertCount);
}
}
if (!chunk.GetBlock(pos.Add(Direction.south)).controller.IsSolid(Direction.north))
{
foreach (var tri in trisSouth)
{
meshData.AddTriangle(tri + initialVertCount);
meshData.colTriangles.Add(tri + colInitialVertCount);
}
}
if (!chunk.GetBlock(pos.Add(Direction.west)).controller.IsSolid(Direction.east))
{
foreach (var tri in trisWest)
{
meshData.AddTriangle(tri + initialVertCount);
meshData.colTriangles.Add(tri + colInitialVertCount);
}
}
if (!chunk.GetBlock(pos.Add(Direction.east)).controller.IsSolid(Direction.west))
{
foreach (var tri in trisEast)
{
meshData.AddTriangle(tri + initialVertCount);
meshData.colTriangles.Add(tri + colInitialVertCount);
}
}
foreach (var tri in trisOther)
{
meshData.AddTriangle(tri + initialVertCount);
meshData.colTriangles.Add(tri + colInitialVertCount);
}
}