本文整理汇总了C#中MeshData.AddTriangle方法的典型用法代码示例。如果您正苦于以下问题:C# MeshData.AddTriangle方法的具体用法?C# MeshData.AddTriangle怎么用?C# MeshData.AddTriangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshData
的用法示例。
在下文中一共展示了MeshData.AddTriangle方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateTerrainMesh
public static MeshData GenerateTerrainMesh(float[,] heightMap) {
int width = heightMap.GetLength (0);
int height = heightMap.GetLength (1);
float topLeftX = (width - 1) / -2f;
float topLeftZ = (height - 1) / 2f;
MeshData meshData = new MeshData (width, height);
int vertexIndex = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
meshData.vertices [vertexIndex] = new Vector3 (topLeftX + x, heightMap [x, y], topLeftZ - y);
meshData.uvs [vertexIndex] = new Vector2 (x / (float)width, y / (float)height);
if (x < width - 1 && y < height - 1) {
meshData.AddTriangle (vertexIndex, vertexIndex + width + 1, vertexIndex + width);
meshData.AddTriangle (vertexIndex + width + 1, vertexIndex, vertexIndex + 1);
}
vertexIndex++;
}
}
return meshData;
}
示例2: 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;
}
示例3: 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;
}
示例4: GenerateTerrainMesh
public static MeshData GenerateTerrainMesh(float[,] heightMap, float heightMultiplier, AnimationCurve _heightCurve, int levelOfDetail) {
AnimationCurve heightCurve = new AnimationCurve (_heightCurve.keys);
int width = heightMap.GetLength (0);
int height = heightMap.GetLength (1);
float topLeftX = (width - 1) / -2f;
float topLeftZ = (height - 1) / 2f;
int meshSimplificationIncrement = (levelOfDetail == 0)?1:levelOfDetail * 2;
int verticesPerLine = (width - 1) / meshSimplificationIncrement + 1;
MeshData meshData = new MeshData (verticesPerLine, verticesPerLine);
int vertexIndex = 0;
for (int y = 0; y < height; y += meshSimplificationIncrement) {
for (int x = 0; x < width; x += meshSimplificationIncrement) {
meshData.vertices [vertexIndex] = new Vector3 (topLeftX + x, heightCurve.Evaluate (heightMap [x, y]) * heightMultiplier, topLeftZ - y);
meshData.uvs [vertexIndex] = new Vector2 (x / (float)width, y / (float)height);
if (x < width - 1 && y < height - 1) {
meshData.AddTriangle (vertexIndex, vertexIndex + verticesPerLine + 1, vertexIndex + verticesPerLine);
meshData.AddTriangle (vertexIndex + verticesPerLine + 1, vertexIndex, vertexIndex + 1);
}
vertexIndex++;
}
}
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: GenerateTerrainMesh
public static MeshData GenerateTerrainMesh(float[,] heightMap, float heightMultiplier, AnimationCurve _heightCurve, int levelOfDetail)
{
AnimationCurve heightCurve = new AnimationCurve(_heightCurve.keys);
int width = heightMap.GetLength(0);
int height = heightMap.GetLength(1);
float topLeftX = (width - 1) / -2f;
float topLeftZ = (height - 1) / 2f;
int meshSimplificationIncrement = levelOfDetail==0 ? 1 : levelOfDetail * 2; //Pour n'afficher qu'un certain nombre de vertices
int verticesPerLine = (width - 1) / meshSimplificationIncrement + 1;
MeshData meshData = new MeshData(verticesPerLine, verticesPerLine);
int vertexIndex = 0;
for(int y=0;y<height;y+= meshSimplificationIncrement)
{
for(int x=0;x<width;x+= meshSimplificationIncrement)
{
meshData.vertices[vertexIndex] = new Vector3(topLeftX + x, heightCurve.Evaluate(heightMap[x, y]) * heightMultiplier - heightMultiplier*0.01f, topLeftZ - y);
meshData.uvs[vertexIndex] = new Vector2(x / (float)width, y/(float)height);
if(x<width-1 && y < height-1)
{
//On ajoute 2 triangles de façon a créer une face carrée
// /!\ Sens Indirect
meshData.AddTriangle(vertexIndex, vertexIndex + verticesPerLine + 1, vertexIndex + verticesPerLine);
meshData.AddTriangle(vertexIndex + verticesPerLine + 1, vertexIndex, vertexIndex + 1);
}
vertexIndex++;
}
}
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: 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);
}
}
示例10: Generate
public void Generate(TerrainConfig config) {
config.MapHeight += 1;
config.MapWidth += 1;
Config = config;
float[,] noiseMap = Noise.GenerateNoiseMap(
config.MapWidth,
config.MapHeight,
config.Seed,
config.NoiseScale,
config.Octaves,
config.Persistance,
config.Lacunarity,
config.Offset
);
Color[] colorMap = new Color[config.MapWidth * config.MapHeight];
for (int y = 0; y < config.MapHeight; y++) {
for (int x = 0; x < config.MapWidth; x++) {
float currentHeight = noiseMap[x, y];
for (int i = 0; i < TerrainTypes.Length; i++) {
if (currentHeight <= TerrainTypes[i].Height) {
colorMap[y * config.MapWidth + x] = TerrainTypes[i].Color;
//print (y * config.MapWidth + x);
break;
}
}
}
}
int width = noiseMap.GetLength(0);
int height = noiseMap.GetLength(1);
float topLeftX = (width - 1) / -2f;
float topLeftZ = (height - 1) / 2f;
MeshData meshData = new MeshData(width, height);
int vertexIndex = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
meshData.Vertices[vertexIndex] = new Vector3((topLeftX + x) / 4, 0, (topLeftZ - y) / 4);
meshData.Uvs[vertexIndex] = new Vector2((x / (float) width), (y / (float) height));
if (x < width - 1 && y < height - 1) {
meshData.AddTriangle(vertexIndex, vertexIndex + width + 1, vertexIndex + width);
meshData.AddTriangle(vertexIndex + width + 1, vertexIndex, vertexIndex + 1);
}
vertexIndex++;
}
}
Texture = new Texture2D(width, height);
Texture.filterMode = FilterMode.Point;
Texture.wrapMode = TextureWrapMode.Clamp;
Texture.SetPixels(colorMap);
Texture.Apply();
Mesh finalMesh = meshData.CreateMesh();
GetComponent<MeshFilter>().sharedMesh = finalMesh;
GetComponent<MeshRenderer>().material.mainTexture = Texture;
GetComponent<MeshCollider>().sharedMesh = finalMesh;
}
示例11: Draw
public void Draw(MeshData meshData, Vector3 cubeOrigin, int[] solution, bool reverseNormal)
{
var edges = new List<int>();
foreach (TriangleDescriptor tri in _trianglesDescriptors)
{
int e0 = FilterBasedLookAtTable.Edges[solution[tri.P0A], solution[tri.P0B]];
int e1 = FilterBasedLookAtTable.Edges[solution[tri.P1A], solution[tri.P1B]];
int e2 = FilterBasedLookAtTable.Edges[solution[tri.P2A], solution[tri.P2B]];
if (!edges.Contains(e0))
edges.Add(e0);
if (!edges.Contains(e1))
edges.Add(e1);
if (!edges.Contains(e2))
edges.Add(e2);
if (e0 == -1 || e1 == -1 || e2 == -1)
throw new IndexOutOfRangeException();
if (reverseNormal)
meshData.AddTriangle(edges.IndexOf(e0), edges.IndexOf(e2), edges.IndexOf(e1));
else
meshData.AddTriangle(edges.IndexOf(e0), edges.IndexOf(e1), edges.IndexOf(e2));
}
foreach (int edge in edges)
meshData.Vertices.Add(cubeOrigin + FilterBasedLookAtTable.EdgeCenters[edge]);
}