当前位置: 首页>>代码示例>>C#>>正文


C# MeshBuilder.AddTriangle方法代码示例

本文整理汇总了C#中MeshBuilder.AddTriangle方法的典型用法代码示例。如果您正苦于以下问题:C# MeshBuilder.AddTriangle方法的具体用法?C# MeshBuilder.AddTriangle怎么用?C# MeshBuilder.AddTriangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MeshBuilder的用法示例。


在下文中一共展示了MeshBuilder.AddTriangle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildArcMesh

	public static void BuildArcMesh(MeshBuilder meshBuilder,
	                               float innerRadius,
	                               float outerRadius,
	                               float startAngle,
	                               float endAngle,
	                               int steps) {
		float angleFull = endAngle - startAngle;
		float angleInc = angleFull / steps;
		float angle = startAngle;

		meshBuilder.Resize((steps+1)*2, steps*6);
		meshBuilder.ResetIndices ();

		for (int i = 0; i <= steps; ++i) {
			float uv = i/(float)steps;

			meshBuilder.AddVertex(GetArcPoint(innerRadius, angle));
			meshBuilder.AddVertex(GetArcPoint(outerRadius, angle));

			meshBuilder.AddUv(new Vector2(uv, 0));
			meshBuilder.AddUv(new Vector2(uv, 1));

			if ( i > 0 ) {
				int vi = meshBuilder.VertexIndex;
				meshBuilder.AddTriangle(vi-3, vi-4, vi-2);
				meshBuilder.AddTriangle(vi-1, vi-3, vi-2);
			}

			angle += angleInc;
		}
	}
开发者ID:honi90,项目名称:LeapMotionVRInterface,代码行数:31,代码来源:MeshNative.cs

示例2: BuildQuad

    void BuildQuad(MeshBuilder meshBuilder, Vector3 offset, Vector3 widthDirection, Vector3 lengthDirection)
    {
        Vector3 normal = Vector3.Cross(lengthDirection, widthDirection).normalized;

        //Set up the vertices and triangles:
        meshBuilder.Vertices.Add(offset);
        meshBuilder.Uvs.Add(new Vector2(0.0f, 0.0f));
        meshBuilder.Normals.Add(normal);

        meshBuilder.Vertices.Add(offset + lengthDirection);
        meshBuilder.Uvs.Add(new Vector2(0.0f, 1.0f));
        meshBuilder.Normals.Add(normal);

        meshBuilder.Vertices.Add(offset + lengthDirection + widthDirection);
        meshBuilder.Uvs.Add(new Vector2(1.0f, 1.0f));
        meshBuilder.Normals.Add(normal);

        meshBuilder.Vertices.Add(offset + widthDirection);
        meshBuilder.Uvs.Add(new Vector2(1.0f, 0.0f));
        meshBuilder.Normals.Add(normal);

        int startPoint = meshBuilder.Vertices.Count - 4;
        if(first){
        meshBuilder.AddTriangle(startPoint, startPoint + 1, startPoint + 2);
        meshBuilder.AddTriangle(startPoint, startPoint + 2, startPoint + 3);
        //first = false;
        }
    }
开发者ID:jakupklein,项目名称:martinGame,代码行数:28,代码来源:QuadTest.cs

示例3: BuildQuad

    //BuildQuad with vectors
    public static Mesh BuildQuad(MeshBuilder meshBuilder, Vector3 offset, Vector3 widthDir, Vector3 lengthDir)
    {
        Vector3 normal = Vector3.Cross(lengthDir, widthDir).normalized;

        meshBuilder.Vertices.Add(offset);
        meshBuilder.UVs.Add(new Vector2(0.0f, 0.0f));
        meshBuilder.Normals.Add(normal);

        meshBuilder.Vertices.Add(offset + lengthDir);
        meshBuilder.UVs.Add(new Vector2(0.0f, 1.0f));
        meshBuilder.Normals.Add(normal);

        meshBuilder.Vertices.Add(offset + lengthDir + widthDir);
        meshBuilder.UVs.Add(new Vector2(1.0f, 1.0f));
        meshBuilder.Normals.Add(normal);

        meshBuilder.Vertices.Add(offset + widthDir);
        meshBuilder.UVs.Add(new Vector2(1.0f, 0.0f));
        meshBuilder.Normals.Add(normal);

        int baseIndex = meshBuilder.Vertices.Count - 4;

        meshBuilder.AddTriangle(baseIndex, baseIndex + 1, baseIndex + 2);
        meshBuilder.AddTriangle(baseIndex, baseIndex + 2, baseIndex + 3);

        Mesh _CreatedMesh = meshBuilder.CreateMesh();
        _CreatedMesh.RecalculateNormals();
        return _CreatedMesh;
    }
开发者ID:Boerlam001,项目名称:DungeonGrind,代码行数:30,代码来源:ProceduralGen.cs

示例4: BuildQuad

    /// <summary>
    /// Builds a single quad based on a position offset and width and length vectors.
    /// </summary>
    /// <param name="meshBuilder">The mesh builder currently being added to.</param>
    /// <param name="offset">A position offset for the quad.</param>
    /// <param name="widthDir">The width vector of the quad.</param>
    /// <param name="lengthDir">The length vector of the quad.</param>
    public static void BuildQuad(MeshBuilder meshBuilder, Vector3 offset, Vector3 widthDir, Vector3 lengthDir) {
        Vector3 normal = Vector3.Cross(lengthDir, widthDir).normalized;

        meshBuilder.Vertices.Add(offset);
        meshBuilder.UVs.Add(new Vector2(0.0f, 0.0f));
        meshBuilder.Normals.Add(normal);

        meshBuilder.Vertices.Add(offset + lengthDir);
        meshBuilder.UVs.Add(new Vector2(0.0f, 1.0f));
        meshBuilder.Normals.Add(normal);

        meshBuilder.Vertices.Add(offset + lengthDir + widthDir);
        meshBuilder.UVs.Add(new Vector2(1.0f, 1.0f));
        meshBuilder.Normals.Add(normal);

        meshBuilder.Vertices.Add(offset + widthDir);
        meshBuilder.UVs.Add(new Vector2(1.0f, 0.0f));
        meshBuilder.Normals.Add(normal);

        //we don't know how many verts the meshBuilder is up to, but we only care about the four we just added:
        int baseIndex = meshBuilder.Vertices.Count - 4;

        meshBuilder.AddTriangle(baseIndex, baseIndex + 1, baseIndex + 2);
        meshBuilder.AddTriangle(baseIndex, baseIndex + 2, baseIndex + 3);
    }
开发者ID:eaclou,项目名称:Master_CreatureTrainer01,代码行数:32,代码来源:MeshBuilderPrimitiveShapes.cs

示例5: BuildRectangleMesh

	public static void BuildRectangleMesh(MeshBuilder meshBuilder, 
	                                      float width,
	                                      float height, 
	                                      float wStart,
	                                      float hStart,
	                                      float amount) {
		float fullW;
		float fullH;
		
		if ( width >= height ) {
			fullH = height*amount;
			fullW = width-(height-fullH);
		}
		else {
			fullW = width*amount;
			fullH = height-(width-fullW);
		}

		meshBuilder.Resize(4, 6);
		meshBuilder.ResetIndices();
		
		meshBuilder.AddVertex(new Vector3(fullW,  fullH, 0));
		meshBuilder.AddVertex(new Vector3(fullW, fullH*hStart, 0)); 
		meshBuilder.AddVertex(new Vector3(fullW*wStart, fullH*hStart, 0));
		meshBuilder.AddVertex(new Vector3(fullW*wStart, fullH, 0));
		
		meshBuilder.AddTriangle(0, 1, 2);
		meshBuilder.AddTriangle(0, 2, 3);
		
		meshBuilder.AddRemainingUvs(Vector2.zero);
	}
开发者ID:honi90,项目名称:LeapMotionVRInterface,代码行数:31,代码来源:MeshNative.cs

示例6: BuildQuad

    void BuildQuad(MeshBuilder meshBuilder, Vector3 offset, Vector3 widthDir, Vector3 lengthDir, int sizeX, int sizeY)
    {
        Vector3 normal = Vector3.Cross (lengthDir, widthDir).normalized;

        float vx, vy;

        // Define vertices e triangulos
        for (int y = 0; y <= sizeY; y++) {
            for (int x = 0; x <= sizeX; x++) {
                vx = ((float) x / sizeX);
                vy = ((float) y / sizeY);

                meshBuilder.Vertices.Add (offset + vx * lengthDir + vy * widthDir);
                meshBuilder.UVs.Add (new Vector2(vx, vy));
                meshBuilder.Normals.Add (normal);
            }
        }

        int baseIndex = meshBuilder.Vertices.Count - (sizeX+1) * (sizeY+1);

        for (int vi = baseIndex, y = 0; y < sizeY; y++, vi++) {
            for (int x = 0; x < sizeX; x++, vi++) {
                meshBuilder.AddTriangle (vi, vi+1, vi+sizeX+2);
                meshBuilder.AddTriangle (vi, vi+sizeX+2, vi+sizeX+1);
            }
        }
    }
开发者ID:adrianogil,项目名称:MeshGeneration,代码行数:27,代码来源:MeshPlayground.cs

示例7: AddQuadTriangles

 protected void AddQuadTriangles(MeshBuilder meshBuilder, int index0, int index1, int index2, int index3)
 {
     if (meshFace == MeshFace.Front || meshFace == MeshFace.Both) {
         meshBuilder.AddTriangle(index0, index1, index2);
         meshBuilder.AddTriangle(index1, index3, index2);
     }
     if(meshFace == MeshFace.Back || meshFace == MeshFace.Both){
         meshBuilder.AddTriangle(index1, index0, index2);
         meshBuilder.AddTriangle(index1, index2, index3);
     }
 }
开发者ID:adrianogil,项目名称:MeshGeneration,代码行数:11,代码来源:MeshBuilderGeneration.cs

示例8: AddTrianglesAtIndex

 protected virtual void AddTrianglesAtIndex(MeshBuilder meshBuilder, int originIndex, int i)
 {
     if (meshFace == MeshFace.Front || meshFace == MeshFace.Both) {
         meshBuilder.AddTriangle(originIndex,
                                 originIndex + i + 1,
                                 originIndex + (i + 1) % curveVerticesNumber + 1);
     }
     if(meshFace == MeshFace.Back || meshFace == MeshFace.Both){
         meshBuilder.AddTriangle(originIndex,
                                 originIndex + (i + 1) % curveVerticesNumber + 1,
                                 originIndex + i + 1);
     }
 }
开发者ID:adrianogil,项目名称:MeshGeneration,代码行数:13,代码来源:CircleGeneration.cs

示例9: GenerateCurveTriangles

    MeshBuilder GenerateCurveTriangles(MeshBuilder meshBuilder, bool doubleTriangles = false)
    {
        int baseIndex = 0;
        int sizeX = 2;
        int sizeY = meshBuilder.Vertices.Count / 3 - 1;

        int vi = baseIndex;

        for (int y = 0; y < sizeY; y++, vi++) {
            for (int x = 0; x < sizeX; x++, vi++) {
                meshBuilder.AddTriangle (vi, vi + sizeX + 1, vi + 1);
                meshBuilder.AddTriangle (vi + 1, vi + sizeX + 1, vi + sizeX + 2);

                if (y == sizeY - 1) {
                    meshBuilder.AddTriangle (vi + sizeX + 1, baseIndex + x, vi + sizeX + 2);
                    meshBuilder.AddTriangle (baseIndex + x + 1, vi + sizeX + 2, baseIndex + x);
                }

                if (doubleTriangles) {
                    meshBuilder.AddTriangle (vi + 1, vi + sizeX + 1, vi);
                    meshBuilder.AddTriangle (vi + sizeX + 2, vi + sizeX + 1, vi + 1);

                    if (y == sizeY - 1) {
                        meshBuilder.AddTriangle (vi + sizeX + 2, baseIndex + x, vi + sizeX + 1);
                        meshBuilder.AddTriangle (baseIndex + x, vi + sizeX + 2, baseIndex + x + 1);
                    }
                }
            }
        }
        return meshBuilder;
    }
开发者ID:adrianogil,项目名称:ProceduralRace,代码行数:31,代码来源:TrackGeneration.cs

示例10: BuildQuadForGrid

    void BuildQuadForGrid(MeshBuilder meshBuilder, Vector3 position, Vector2 uv,
    bool buildTriangles, int vertsPerRow)
    {
        meshBuilder.Vertices.Add(position);
        meshBuilder.UVs.Add(uv);

        if (buildTriangles)
        {
            int baseIndex = meshBuilder.Vertices.Count - 1;

            int index0 = baseIndex;
            int index1 = baseIndex - 1;
            int index2 = baseIndex - vertsPerRow;
            int index3 = baseIndex - vertsPerRow - 1;

            meshBuilder.AddTriangle(index0, index2, index1);
            meshBuilder.AddTriangle(index2, index3, index1);
        }
    }
开发者ID:TechLogic,项目名称:herosofspace,代码行数:19,代码来源:AsteroidMeshGeneration.cs

示例11: buildTri

 private static object buildTri()
 {
     var mb = new MeshBuilder(true, false);
     var p0 = new Point3D(0, 0, 0);
     var p1 = new Point3D(1, 0, 0);
     var p2 = new Point3D(1, 1, 0);
     mb.AddTriangle(p0, p1, p2);
     mb.Normals.ToList().ForEach(x => System.Diagnostics.Trace.WriteLine(x.ToString()));
     return mb.ToMesh();
 }
开发者ID:chantsunman,项目名称:helix-toolkit,代码行数:10,代码来源:MainWindow.xaml.cs

示例12: BuildRing

    static void BuildRing(MeshBuilder meshBuilder, int segmentCount, Vector3 center, float radius,
                           float v, bool buildTriangles, Quaternion rotation)
    {
        // Precomputed Sine/Cosine circle drawing from http://slabode.exofire.net/circle_draw.shtml
        float theta = 2f * Mathf.PI / (float)segmentCount;
        float c = Mathf.Cos(theta);
        float s = Mathf.Sin(theta);
        float t;

        float x = radius;//we start at angle = 0
        float y = 0;

        // Since we haven't added any yet, we don't need to -1
        int ringBaseIndex = meshBuilder.VertexCount;
        for (int i = 0; i < segmentCount; i++) {
            Vector3 unitPosition = Vector3.zero;
            unitPosition.x = x;
            unitPosition.z = y;

            unitPosition = rotation * unitPosition;
            meshBuilder.AddVertex(center + unitPosition);// * radius
            meshBuilder.AddNormal(unitPosition);
            meshBuilder.AddUV(new Vector2((float)i / segmentCount, v));

            if (buildTriangles) {
                int vertsPerRow = segmentCount;
                int index0 = ringBaseIndex + i;
                int index1 = ringBaseIndex + MathHelpers.Mod(i - 1, segmentCount); // before base
                int index2 = ringBaseIndex + i - vertsPerRow; // below base
                int index3 = ringBaseIndex + MathHelpers.Mod(i - 1, segmentCount) - vertsPerRow; // before below base

                // Debug.Log(string.Format("TRI{0}>{1}>{2}", index0, index2, index1));
                meshBuilder.AddTriangle(index0, index2, index1);
                // Debug.Log(string.Format("TRI{0}>{1}>{2}", index2, index3, index1));
                meshBuilder.AddTriangle(index2, index3, index1);
            }

            t = x;
            x = c * x - s * y;
            y = s * t + c * y;
        }
    }
开发者ID:jceipek,项目名称:UnityBase,代码行数:42,代码来源:TubeRenderer.cs

示例13: Start

    //Initialisation:
    private void Start()
    {
        //Create a new mesh builder:
        MeshBuilder meshBuilder = new MeshBuilder();

        //Add the vertices:
        meshBuilder.Vertices.Add(new Vector3(0.0f, 0.0f, 0.0f));
        meshBuilder.UVs.Add(new Vector2(0.0f, 0.0f));
        meshBuilder.Normals.Add(Vector3.up);

        meshBuilder.Vertices.Add(new Vector3(0.0f, 0.0f, m_Length));
        meshBuilder.UVs.Add(new Vector2(0.0f, 1.0f));
        meshBuilder.Normals.Add(Vector3.up);

        meshBuilder.Vertices.Add(new Vector3(m_Width, 0.0f, m_Length));
        meshBuilder.UVs.Add(new Vector2(1.0f, 1.0f));
        meshBuilder.Normals.Add(Vector3.up);

        meshBuilder.Vertices.Add(new Vector3(m_Width, 0.0f, 0.0f));
        meshBuilder.UVs.Add(new Vector2(1.0f, 0.0f));
        meshBuilder.Normals.Add(Vector3.up);

        //Add the triangles:
        meshBuilder.AddTriangle(0, 1, 2);
        meshBuilder.AddTriangle(0, 2, 3);

        //Create the mesh:
        Mesh mesh = meshBuilder.CreateMesh();

        //Look for a MeshFilter component attached to this GameObject:
        MeshFilter filter = GetComponent<MeshFilter>();

        //If the MeshFilter exists, attach the new mesh to it.
        //Assuming the GameObject also has a renderer attached, our new mesh will now be visible in the scene.
        if (filter != null)
        {
            filter.sharedMesh = mesh;
        }
    }
开发者ID:Ideae,项目名称:SpatialExperiments,代码行数:40,代码来源:ProcQuad.cs

示例14: BuildQuad

    void BuildQuad(MeshBuilder meshBuilder, Vector3 offset)
    {
        meshBuilder.Vertices.Add(new Vector3(0.0f, 0.0f, 0.0f) + offset);
        meshBuilder.UVs.Add(new Vector2(0.0f, 0.0f));
        meshBuilder.Normals.Add(Vector3.up);

        meshBuilder.Vertices.Add(new Vector3(0.0f, 0.0f, spacing) + offset);
        meshBuilder.UVs.Add(new Vector2(0.0f, 1.0f));
        meshBuilder.Normals.Add(Vector3.up);

        meshBuilder.Vertices.Add(new Vector3(spacing, 0.0f, spacing) + offset);
        meshBuilder.UVs.Add(new Vector2(1.0f, 1.0f));
        meshBuilder.Normals.Add(Vector3.up);

        meshBuilder.Vertices.Add(new Vector3(spacing, 0.0f, 0.0f) + offset);
        meshBuilder.UVs.Add(new Vector2(1.0f, 0.0f));
        meshBuilder.Normals.Add(Vector3.up);

        int baseIndex = meshBuilder.Vertices.Count - 4;

        meshBuilder.AddTriangle(baseIndex, baseIndex + 1, baseIndex + 2);
        meshBuilder.AddTriangle(baseIndex, baseIndex + 2, baseIndex + 3);
    }
开发者ID:TechLogic,项目名称:herosofspace,代码行数:23,代码来源:AsteroidMeshGeneration.cs

示例15: BuildLinkBezier

    public void BuildLinkBezier(MeshBuilder meshBuilder, BezierCurve connectionBezier, float widthStart, float widthEnd, Color colorStart, Color colorEnd) {
        List<int> verticesList = new List<int>();

        float m_splineStartRadius = widthStart;
        float m_splineEndRadius = widthEnd;
        int m_splineHeightSegmentCount = 8;
        int m_splineRadialSegmentCount = 4;

        float tInc = 1f / m_splineHeightSegmentCount; // How many subdivisions along the length of the spline

        for (int i = 0; i <= m_splineHeightSegmentCount; i++) {
            float t = tInc * (float)i;
            Vector3 ringCenter = connectionBezier.GetPoint(t);
            //Quaternion rot = Quaternion.identity;
            Vector3 dir = connectionBezier.GetDirection(t);
            Quaternion rot = Quaternion.identity;
            if (dir != Vector3.zero) {
                rot.SetLookRotation(dir);
            }
            float radius = ((1f - t) * m_splineStartRadius) + (t * m_splineEndRadius);
            // Construct the mesh Ring!
            //BuildBezierCurveRing(meshBuilder, m_splineRadialSegmentCount, ringCenter, radius, t, i > 0, rot); 
            //protected void BuildBezierCurveRing(MeshBuilder meshBuilder, int segmentCount, Vector3 center, float radius, float v, bool buildTriangles, Quaternion rotation) {
            float angleInc = (Mathf.PI * 2.0f) / m_splineRadialSegmentCount;

            for (int j = 0; j <= m_splineRadialSegmentCount; j++) {
                float angle = angleInc * j;

                Vector3 unitPosition = Vector3.zero;
                unitPosition.x = Mathf.Cos(angle);
                unitPosition.y = Mathf.Sin(angle);

                unitPosition = rot * unitPosition;
                Vector3 normal = unitPosition;

                meshBuilder.Vertices.Add(ringCenter + unitPosition * radius);
                meshBuilder.Normals.Add(normal);
                //meshBuilder.UVs.Add(new Vector2((float)i / segmentCount, v));
                meshBuilder.UVs.Add(new Vector2((float)j / m_splineRadialSegmentCount, t));
                verticesList.Add(meshBuilder.Vertices.Count - 1);
                meshBuilder.Colors.Add(Color.Lerp(colorStart, colorEnd, t));

                if (j > 0 && i > 0) {
                    //Debug.Log ("buildTriangles!");
                    int baseIndex = meshBuilder.Vertices.Count - 1;

                    int vertsPerRow = m_splineRadialSegmentCount + 1;

                    int index0 = baseIndex;
                    int index1 = baseIndex - 1;
                    int index2 = baseIndex - vertsPerRow;
                    int index3 = baseIndex - vertsPerRow - 1;

                    meshBuilder.AddTriangle(index1, index2, index0);
                    meshBuilder.AddTriangle(index1, index3, index2);
                }
            }            
        }
        connectionVertexList.Add(verticesList);  // keep track of Connection's vertices so their color can be changed without rebuilding every frame
    }
开发者ID:eaclou,项目名称:Master_CreatureTrainer01,代码行数:60,代码来源:BrainNetworkVisualizer.cs


注:本文中的MeshBuilder.AddTriangle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。