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


C# MeshBuilder.CreateMesh方法代码示例

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


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

示例1: BuildMesh

    //public virtual Mesh BuildMesh() {
    //    return new Mesh();
    //}
    public Mesh BuildMesh(GizmoMeshShape shape, GizmoType type) {  // SIMPLE CUBE!
        MeshBuilder meshBuilder = new MeshBuilder();

        if(shape == GizmoMeshShape.Cube) {
            meshBuilder = EditorGizmoMeshShapes.GetCubeMesh(meshBuilder);
            //BuildQuad(meshBuilder, new Vector3(-0.5f, -0.5f, -0.5f), Vector3.right, Vector3.up); // FRONT
            //BuildQuad(meshBuilder, new Vector3(-0.5f, -0.5f, 0.5f), Vector3.back, Vector3.up); // LEFT
            //BuildQuad(meshBuilder, new Vector3(-0.5f, 0.5f, 0.5f), Vector3.back, Vector3.right); // TOP
            //BuildQuad(meshBuilder, new Vector3(0.5f, -0.5f, 0.5f), Vector3.left, Vector3.up); // BACK
            //BuildQuad(meshBuilder, new Vector3(0.5f, -0.5f, -0.5f), Vector3.forward, Vector3.up); // RIGHT
            //BuildQuad(meshBuilder, new Vector3(-0.5f, -0.5f, 0.5f), Vector3.right, Vector3.back); // BOTTOM

            if(type != GizmoType.none) {
                collider = this.gameObject.AddComponent<BoxCollider>();
                collider.isTrigger = true;
            }
            
            if (gizmoMaterial == null) {
                gizmoMaterial = new Material(Shader.Find("Custom/CritterEditorGizmo"));
                //gizmoMaterial.renderQueue = 4000;
            }
            GetComponent<MeshRenderer>().material = gizmoMaterial;
        }
        else if(shape == GizmoMeshShape.Arrow) {
            EditorGizmoMeshShapes.GetArrowMesh(meshBuilder);

            if (type != GizmoType.none) {
                MeshCollider meshCollider = this.gameObject.AddComponent<MeshCollider>();
                meshCollider.sharedMesh = meshBuilder.CreateMesh();
                collider = meshCollider;
                //collider.isTrigger = true;
            }

            if (gizmoMaterial == null) {
                gizmoMaterial = new Material(Shader.Find("Custom/CritterEditorGizmo"));
                //gizmoMaterial.renderQueue = 4000;
            }
            GetComponent<MeshRenderer>().material = gizmoMaterial;
        }
        else if (shape == GizmoMeshShape.OmniArrow) {
            EditorGizmoMeshShapes.GetOmniArrowMesh(meshBuilder);

            if (type != GizmoType.none) {
                MeshCollider meshCollider = this.gameObject.AddComponent<MeshCollider>();
                meshCollider.sharedMesh = meshBuilder.CreateMesh();
                collider = meshCollider;
            }

            if (gizmoMaterial == null) {
                gizmoMaterial = new Material(Shader.Find("Custom/CritterEditorGizmo"));
                //gizmoMaterial.renderQueue = 4000;
            }
            GetComponent<MeshRenderer>().material = gizmoMaterial;
        }
        else {
            Debug.Log("No Gizmo Shape!!!");
        }

        return meshBuilder.CreateMesh();
    }
开发者ID:eaclou,项目名称:Master_CreatureTrainer01,代码行数:63,代码来源:EditorGizmoObject.cs

示例2: Generate

	public void Generate(int chunkX, int chunkY, Map parent)	{
		MeshFilter filter = this.gameObject.GetComponent<MeshFilter> ();
		if (filter == null) {
			filter = this.gameObject.AddComponent<MeshFilter> ();
		}

		MeshRenderer rend = this.gameObject.GetComponent<MeshRenderer> ();
		if (rend == null) {
			rend = this.gameObject.AddComponent<MeshRenderer> ();
		}

		rend.material = parent.mapMaterial;

		MeshBuilder meshBuilder = new MeshBuilder();

		int startX = chunkX * 32;
		int startY = chunkY * 32;
		for (int i = startX; i < startX + 32; i++) {
			float xPos = TILE_SIZE * (i - startX);
			for (int j = startY; j < startY + 32; j++) {
				float yPos = TILE_SIZE * (j - startY);
				BuildTile(meshBuilder, new Vector3(xPos, 0, yPos), parent.getTile(i, j));
			}
		}

		this.GetComponent<MeshFilter> ().sharedMesh = meshBuilder.CreateMesh ();
		this.transform.position = new Vector3(chunkX * Map.ChunkSize * TILE_SIZE, 0, chunkY * Map.ChunkSize * TILE_SIZE);
	}
开发者ID:Wolfie13,项目名称:RTSAI,代码行数:28,代码来源:MapChunk.cs

示例3: BuildMesh

    public override Mesh BuildMesh()
    {
        MeshBuilder meshBuilder = new MeshBuilder();

        float heightInc = m_Height / m_HeightSegmentCount;

        //calculate the slope of the cylinder based on the height and difference between radii:
        Vector2 slope = new Vector2(m_RadiusEnd - m_RadiusStart, m_Height);
        slope.Normalize();

        //build the rings:
        for (int i = 0; i <= m_HeightSegmentCount; i++)
        {
            //centre position of this ring:
            Vector3 centrePos = Vector3.up * heightInc * i;

            //V coordinate is based on height:
            float v = (float)i / m_HeightSegmentCount;

            //interpolate between the radii:
            float radius = Mathf.Lerp(m_RadiusStart, m_RadiusEnd, (float)i / m_HeightSegmentCount);

            //build the ring:
            BuildRing(meshBuilder, m_RadialSegmentCount, centrePos, radius, v, i > 0, Quaternion.identity, slope);
        }

        return meshBuilder.CreateMesh();
    }
开发者ID:Ideae,项目名称:SpatialExperiments,代码行数:28,代码来源:ProcCylinderTaper.cs

示例4: BuildMesh

	public override Mesh BuildMesh() {  // SIMPLE PLANE!
		MeshBuilder meshBuilder = new MeshBuilder();

		BuildQuad (meshBuilder, new Vector3(-0.5f, 0.0f, 0.5f), Vector3.back, Vector3.right); // TOP
		
		return meshBuilder.CreateMesh ();
	}
开发者ID:eaclou,项目名称:Master_CreatureTrainer01,代码行数:7,代码来源:GamePieceCommonPlane.cs

示例5: 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

示例6: BuildMesh

    //Build the mesh:
    public override Mesh BuildMesh()
    {
        //Create a new mesh builder:
        MeshBuilder meshBuilder = new MeshBuilder();

        ////one-segment cylinder (build two rings, one at the bottom and one at the top):
        //BuildRing(meshBuilder, m_RadialSegmentCount, Vector3.zero, m_Radius, 0.0f, false);
        //BuildRing(meshBuilder, m_RadialSegmentCount, Vector3.up * m_Height, m_Radius, 1.0f, true);

        //multi-segment cylinder:
        float heightInc = m_Height / m_HeightSegmentCount;

        for (int i = 0; i <= m_HeightSegmentCount; i++)
        {
            //centre position of this ring:
            Vector3 centrePos = Vector3.up * heightInc * i;

            //V coordinate is based on height:
            float v = (float)i / m_HeightSegmentCount;

            BuildRing(meshBuilder, m_RadialSegmentCount, centrePos, m_Radius, v, i > 0);
        }

        ////caps:
        //BuildCap(meshBuilder, Vector3.zero, true);
        //BuildCap(meshBuilder, Vector3.up * m_Height, false);

        return meshBuilder.CreateMesh();
    }
开发者ID:Ideae,项目名称:SpatialExperiments,代码行数:30,代码来源:ProcCylinder.cs

示例7: BuildMesh

    //Build the mesh:
    public override Mesh BuildMesh()
    {
        //Create a new mesh builder:
        MeshBuilder meshBuilder = new MeshBuilder();

        //calculate directional vectors for all 3 dimensions of the cube:
        Vector3 upDir = Vector3.up * m_Height;
        Vector3 rightDir = Vector3.right * m_Width;
        Vector3 forwardDir = Vector3.forward * m_Length;

        //calculate the positions of two corners opposite each other on the cube:

        //positions that will place the pivot at the corner of the cube:
        Vector3 nearCorner = Vector3.zero;
        Vector3 farCorner = upDir + rightDir + forwardDir;

        ////positions that will place the pivot at the centre of the cube:
        //Vector3 farCorner = (upDir + rightDir + forwardDir) / 2;
        //Vector3 nearCorner = -farCorner;

        //build the 3 quads that originate from nearCorner:
        BuildQuad(meshBuilder, nearCorner, forwardDir, rightDir);
        BuildQuad(meshBuilder, nearCorner, rightDir, upDir);
        BuildQuad(meshBuilder, nearCorner, upDir, forwardDir);

        //build the 3 quads that originate from farCorner:
        BuildQuad(meshBuilder, farCorner, -rightDir, -forwardDir);
        BuildQuad(meshBuilder, farCorner, -upDir, -rightDir);
        BuildQuad(meshBuilder, farCorner, -forwardDir, -upDir);

        //initialise the Unity mesh and return it:
        return meshBuilder.CreateMesh();
    }
开发者ID:Ideae,项目名称:SpatialExperiments,代码行数:34,代码来源:ProcCube.cs

示例8: BuildMesh

    //Build the mesh:
    public override Mesh BuildMesh()
    {
        //Create a new mesh builder:
        MeshBuilder meshBuilder = new MeshBuilder();

        //height segments need to be half m_RadialSegmentCount for the sphere to be even horizontally and vertically:
        int heightSegmentCount = m_RadialSegmentCount / 2;

        //the angle increment per height segment:
        float angleInc = Mathf.PI / heightSegmentCount;

        for (int i = 0; i <= heightSegmentCount; i++)
        {
            Vector3 centrePos = Vector3.zero;

            //calculate a height offset and radius based on a vertical circle calculation:
            centrePos.y = -Mathf.Cos(angleInc * i) * m_Radius;
            float radius = Mathf.Sin(angleInc * i) * m_Radius;

            float v = (float)i / heightSegmentCount;

            //build the ring:
            BuildRingForSphere(meshBuilder, m_RadialSegmentCount, centrePos, radius, v, i > 0);
        }

        return meshBuilder.CreateMesh();
    }
开发者ID:Ideae,项目名称:SpatialExperiments,代码行数:28,代码来源:ProcSphere.cs

示例9: BeginBuild

    public void BeginBuild(bool reverse = true)
    {
        meshBuilder = GetComponent<MeshBuilder>();

        filter = GetComponent<MeshFilter>();

        for (int i = 0; i <= xVal; i++)//xVal
        {
            float z = m_Length * i;
            float v = (1.0f / xVal) * i;//xVal
            for (int j = 0; j <= zVal; j++)//zVal
            {
                float x = m_Width * j;
                float u = (1.0f / zVal) * j;//zval
                Vector3 offset = new Vector3(x, 0, z);
                Vector2 uv = new Vector2(u, v);
                bool buildTriangles = i > 0 && j > 0;
                BuildQuadForGrid(meshBuilder, offset, uv, buildTriangles, zVal + 1);//zval
            }
        }

        if (filter != null)
        {

            filter.sharedMesh = meshBuilder.CreateMesh(reverse);

            //Debug.Log(filter.sharedMesh.vertexCount + " Vertices.");
        }
    }
开发者ID:afeike01,项目名称:PlanetRTS,代码行数:29,代码来源:MeshGenerator.cs

示例10: BuildMesh

	public override Mesh BuildMesh() {  // SIMPLE CUBE!
		MeshBuilder meshBuilder = new MeshBuilder();

		// OG:
		/*BuildQuad (meshBuilder, new Vector3(-0.5f, -0.5f, -0.5f), Vector3.right, Vector3.up); // FRONT
		BuildQuad (meshBuilder, new Vector3(-0.5f, -0.5f, 0.5f), Vector3.back, Vector3.up); // LEFT
		BuildQuad (meshBuilder, new Vector3(-0.5f, 0.5f, 0.5f), Vector3.back, Vector3.right); // TOP
		BuildQuad (meshBuilder, new Vector3(0.5f, -0.5f, 0.5f), Vector3.left, Vector3.up); // BACK
		BuildQuad (meshBuilder, new Vector3(0.5f, -0.5f, -0.5f), Vector3.forward, Vector3.up); // RIGHT
		BuildQuad (meshBuilder, new Vector3(-0.5f, -0.5f, 0.5f), Vector3.right, Vector3.back); // BOTTOM
		*/

		int m_HeightSegmentCount = 8;
		int m_RadialSegmentCount = 8;
		float m_Radius = 0.25f;
		float m_VerticalScale = 1f;
		Quaternion rotation = Quaternion.identity;
		Vector3 offset = new Vector3(0f, -0.25f, 0f);
		//the angle increment per height segment:
		float angleInc = Mathf.PI / m_HeightSegmentCount;
		
		//the vertical (scaled) radius of the sphere:
		float verticalRadius = m_Radius * m_VerticalScale;
		
		//build the rings:
		for (int i = 0; i <= m_HeightSegmentCount; i++)
		{
			Vector3 centrePos = Vector3.zero;
			
			//calculate a height offset and radius based on a vertical circle calculation:
			centrePos.y = -Mathf.Cos(angleInc * i);
			float radius = Mathf.Sin(angleInc * i);
			
			//calculate the slope of the shpere at this ring based on the height and radius:
			Vector2 slope = new Vector3(-centrePos.y / m_VerticalScale, radius);
			slope.Normalize();
			
			//multiply the unit height by the vertical radius, and then add the radius to the height to make this sphere originate from its base rather than its centre:
			centrePos.y = centrePos.y * verticalRadius + verticalRadius;
			
			//scale the radius by the one stored in the partData:
			radius *= m_Radius;
			
			//calculate the final position of the ring centre:
			Vector3 finalRingCentre = rotation * centrePos + offset;
			
			//V coordinate:
			float v = (float)i / m_HeightSegmentCount;
			
			//build the ring:
			BuildRing(meshBuilder, m_RadialSegmentCount, finalRingCentre, radius, v, i > 0, rotation, slope);
		}

		return meshBuilder.CreateMesh ();
	}
开发者ID:eaclou,项目名称:Master_CreatureTrainer01,代码行数:55,代码来源:Playground_GamePieceWormSegment.cs

示例11: BuildMesh

    public override Mesh BuildMesh()
    {
        MeshBuilder meshBuilder = new MeshBuilder();

        BuildQuad (meshBuilder, new Vector3(-1f, -1f, 1f), Vector3.right*2f, Vector3.up*2f); // BACK
        BuildQuad (meshBuilder, new Vector3(1f, -1f, 1f), Vector3.back*2f, Vector3.up*2f); // RIGHT
        BuildQuad (meshBuilder, new Vector3(-1f, -1f, 1f), Vector3.back*2f, Vector3.right*2f); // BOTTOM
        BuildQuad (meshBuilder, new Vector3(1f, -1f, -1f), Vector3.left*2f, Vector3.up*2f); // FRONT
        BuildQuad (meshBuilder, new Vector3(-1f, -1f, -1f), Vector3.forward*2f, Vector3.up*2f); // LEFT
        BuildQuad (meshBuilder, new Vector3(-1f, 1f, 1f), Vector3.right*2f, Vector3.back*2f); // TOP
        return meshBuilder.CreateMesh ();
    }
开发者ID:eaclou,项目名称:ANNTrainerProject,代码行数:12,代码来源:GamePieceMoveToTargetWalls.cs

示例12: Start

	// Use this for initialization
	void Start () {
        MeshBuilder meshBuilder = new MeshBuilder();

        //BuildQuad(meshBuilder, new Vector3(-0.5f, -0.5f, -0.5f), Vector3.right, Vector3.up); // FRONT
        //BuildQuad(meshBuilder, new Vector3(-0.5f, -0.5f, 0.5f), Vector3.back, Vector3.up); // LEFT
        //BuildQuad(meshBuilder, new Vector3(-0.5f, 0.5f, 0.5f), Vector3.back, Vector3.right); // TOP
        //BuildQuad(meshBuilder, new Vector3(0.5f, -0.5f, 0.5f), Vector3.left, Vector3.up); // BACK
        //BuildQuad(meshBuilder, new Vector3(0.5f, -0.5f, -0.5f), Vector3.forward, Vector3.up); // RIGHT
        //BuildQuad(meshBuilder, new Vector3(-0.5f, -0.5f, 0.5f), Vector3.right, Vector3.back); // BOTTOM

        this.GetComponent<MeshFilter>().sharedMesh = meshBuilder.CreateMesh();
    }
开发者ID:eaclou,项目名称:Master_CreatureTrainer01,代码行数:13,代码来源:TestSegmentMesh.cs

示例13: BuildMesh

    //public virtual Mesh BuildMesh() {
    //    return new Mesh();
    //}
    public Mesh BuildMesh() {  // SIMPLE CUBE!
        MeshBuilder meshBuilder = new MeshBuilder();

        BuildQuad(meshBuilder, new Vector3(-0.5f, -0.5f, -0.5f), Vector3.right, Vector3.up); // FRONT
        BuildQuad(meshBuilder, new Vector3(-0.5f, -0.5f, 0.5f), Vector3.back, Vector3.up); // LEFT
        BuildQuad(meshBuilder, new Vector3(-0.5f, 0.5f, 0.5f), Vector3.back, Vector3.right); // TOP
        BuildQuad(meshBuilder, new Vector3(0.5f, -0.5f, 0.5f), Vector3.left, Vector3.up); // BACK
        BuildQuad(meshBuilder, new Vector3(0.5f, -0.5f, -0.5f), Vector3.forward, Vector3.up); // RIGHT
        BuildQuad(meshBuilder, new Vector3(-0.5f, -0.5f, 0.5f), Vector3.right, Vector3.back); // BOTTOM

        return meshBuilder.CreateMesh();
    }
开发者ID:eaclou,项目名称:Master_CreatureTrainer01,代码行数:15,代码来源:CritterSegment.cs

示例14: BuildMesh

    public override Mesh BuildMesh()
    {
        MeshBuilder builder = new MeshBuilder();
        float length = 1f;
        float width = 10f;
        float height = 1f;

        Vector3 currentPos = Vector3.zero;
        Vector3 forward = Vector3.forward * length;
        Vector3 right = Vector3.right * width;
        Vector3 up = Vector3.up * height;
        Vector3 tempForward = forward;
        //Vector3 tempRight = right;
        int amount = 200;
        //int periodUp = 40;
        //int periodRight = 20;
        int periodUp = Random.Range(10,80);
        int periodRight = Random.Range(10, 80);
        float ampUp = Random.Range(0.1f, 5f);
        float ampRight = Random.Range(0.1f, 0.2f);

        float r = 1f;
        float randUp = Random.Range(-r, r);
        float randRight = Random.Range(-r, r);

        int range = 10;
        Quaternion rot = Quaternion.Euler(Random.Range(0, range), Random.Range(0, range), Random.Range(0, range));

        for (int i = 0; i < amount; i++)
        {
            BuildQuadDouble(builder, currentPos, tempForward, right);
            currentPos += tempForward;

            //float sinefactUp = Mathf.Sin(((float)i / periodUp) * Mathf.PI * 2f) - 0.5f;
            //float sinefactRight = Mathf.Sin(((float)i / periodRight) * Mathf.PI * 2f) - 0.5f;
            //tempForward = forward + up * sinefactUp * ampUp + right * sinefactRight * ampRight;

            //float r = 1f;
            //float randUp = Random.Range(-r, r);
            //float randRight = Random.Range(-r, r);
            //tempForward = forward + up * randUp + right * randRight;

            tempForward = rot * tempForward;

        }
        return builder.CreateMesh();
    }
开发者ID:Ideae,项目名称:SpatialExperiments,代码行数:47,代码来源:TunnelGenerator.cs

示例15: BuildMesh

    //Build the mesh:
    public override Mesh BuildMesh()
    {
        //Create a new mesh builder:
        MeshBuilder meshBuilder = new MeshBuilder();

        //Loop through the rows:
        for (int i = 0; i <= m_SegmentCount; i++)
        {
            //incremented values for the Z position and V coordinate:
            float z = m_Length * i;
            float v = (1.0f / m_SegmentCount) * i;

            //Loop through the collumns:
            for (int j = 0; j <= m_SegmentCount; j++)
            {
                //incremented values for the X position and U coordinate:
                float x = m_Width * j;
                float u = (1.0f / m_SegmentCount) * j;

                //The position offset for this quad, with a random height between zero and m_MaxHeight:
                Vector3 offset = new Vector3(x, Random.Range(0.0f, m_Height), z);

                ////Build individual quads:
                //BuildQuad(meshBuilder, offset);

                //build quads that share vertices:
                Vector2 uv = new Vector2(u, v);
                bool buildTriangles = i > 0 && j > 0;

                BuildQuadForGrid(meshBuilder, offset, uv, buildTriangles, m_SegmentCount + 1);
            }
        }

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

        //have the mesh calculate its own normals:
        mesh.RecalculateNormals();

        //return the new mesh:
        return mesh;
    }
开发者ID:Ideae,项目名称:SpatialExperiments,代码行数:43,代码来源:ProcGround.cs


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