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


C# MeshData类代码示例

本文整理汇总了C#中MeshData的典型用法代码示例。如果您正苦于以下问题:C# MeshData类的具体用法?C# MeshData怎么用?C# MeshData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: AddMesh

    public bool AddMesh(GameObject go)
    {
        if (_lut.ContainsKey(go.GetInstanceID())) {
            return true;
        }

        // returns false if renderer is not available
        if (go.GetComponent<Renderer>() == null) {
            return false;
        }

        // returns false if not a mesh
        MeshFilter mf = (MeshFilter)go.GetComponent (typeof(MeshFilter));
        if (mf == null) {
            return false;
        }

        MeshData md = new MeshData ();
        md._instID = go.GetInstanceID ();
        md._vertCount = mf.mesh.vertexCount;
        md._triCount = mf.mesh.triangles.Length / 3;
        md._materialCount = go.GetComponent<Renderer>().sharedMaterials.Length;
        md._boundSize = go.GetComponent<Renderer>().bounds.size.magnitude;
        _lut.Add (md._instID, md);
        return true;
    }
开发者ID:zhukunqian,项目名称:usmooth,代码行数:26,代码来源:MeshLut.cs

示例2: Update

    //Update is called once per frame
    void Update()
    {
		if (update) {
			//HasUpdatedLights = false;
			if (!IsUpdating) {
				if (!CanUpdateRenderer) {
					IsUpdating = true;
					MyMeshData = new MeshData();
					MyWaterMeshData = new MeshData();
					if (IsUpdateOnThread) {
					UnityThreading.ActionThread NewThread = UnityThreadHelper.CreateThread(() =>
				                                                                       {
						// thread processing
						UpdateChunk();
						CanUpdateRenderer = true;
					});
					} else {
							UpdateChunk();
							CanUpdateRenderer = true;
					}
				}
			} else {
				if (CanUpdateRenderer) {
					UpdateRender();
					update = false;
					IsUpdating = false;
					CanUpdateRenderer = false;
				}
			}
        }
		//if (HasUpdatedLights) {
			//UpdateChunkLightsOnly();
		//	HasUpdatedLights = false;
		//}
    }
开发者ID:Deus0,项目名称:Zeltex,代码行数:36,代码来源:Chunk.cs

示例3: 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;

	}
开发者ID:SebLague,项目名称:Procedural-Landmass-Generation,代码行数:31,代码来源:MeshGenerator.cs

示例4: Blockdata

    public virtual MeshData Blockdata(Chunk chunk, int x, int y, int z, MeshData meshData)
    {
        if (!chunk.GetBlock(x, y + 1, z).IsSolid(Direction.down))
        {
            meshData = FaceDataUp(chunk, x, y, z, meshData);
        }

        if (!chunk.GetBlock(x, y - 1, z).IsSolid(Direction.up))
        {
            meshData = FaceDataDown(chunk, x, y, z, meshData);
        }

        if (!chunk.GetBlock(x, y, z + 1).IsSolid(Direction.south))
        {
            meshData = FaceDataNorth(chunk, x, y, z, meshData);
        }

        if (!chunk.GetBlock(x, y, z - 1).IsSolid(Direction.north))
        {
            meshData = FaceDataSouth(chunk, x, y, z, meshData);
        }

        if (!chunk.GetBlock(x + 1, y, z).IsSolid(Direction.west))
        {
            meshData = FaceDataEast(chunk, x, y, z, meshData);
        }

        if (!chunk.GetBlock(x - 1, y, z).IsSolid(Direction.east))
        {
            meshData = FaceDataWest(chunk, x, y, z, meshData);
        }

        return meshData;
    }
开发者ID:billy1234,项目名称:TerrainGenMaster,代码行数:34,代码来源:Block.cs

示例5: BuildRenderer

 public static void BuildRenderer(Chunk chunk, BlockPos pos, MeshData meshData, Direction direction, Vector3 ModelSize, Vector3 ConnMeshSizeX, Vector3 ConnMeshSizeY, Vector3 ConnMeshSizeZ, Direction[] Dir)
 {
     MakeStickFace(chunk, pos, meshData, direction, false, ModelSize);
     Debug.Log(Dir.Length);
     if (Dir.Length > 0)
         MakeFenceFace(chunk, pos, meshData, direction, false, ModelSize, ConnMeshSizeX, ConnMeshSizeY, ConnMeshSizeZ, Dir);
 }
开发者ID:FaizanDurrani,项目名称:Voxelmetric-ConnectedMeshes,代码行数:7,代码来源:ConnectedBuilder.cs

示例6: 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;

	}
开发者ID:Fildain,项目名称:Procedural-Landmass-Generation,代码行数:27,代码来源:MeshGenerator.cs

示例7: Blockdata

    public virtual MeshData Blockdata(Chunk chunk, int x, int y, int z, MeshData meshData)
    {
        // Check if block on top has a solid down face
        if (!chunk.GetBlock(x, y + 1, z).IsSolid(Direction.down)) {
            meshData = FaceDataUp(chunk, x, y, z, meshData);
        }

        // Check if the block below has a solid up face
        if (!chunk.GetBlock(x, y - 1, z).IsSolid(Direction.up)) {
            meshData = FaceDataDown(chunk, x, y, z, meshData);
        }

        // Check if the block north has a solid south face
        if (!chunk.GetBlock(x, y, z + 1).IsSolid(Direction.south)) {
            meshData = FaceDataNorth(chunk, x, y, z, meshData);
        }

        // Check if the block south has a solid north face
        if (!chunk.GetBlock(x, y, z - 1).IsSolid(Direction.north)) {
            meshData = FaceDataSouth(chunk, x, y, z, meshData);
        }

        // Check if the block east has a solid west face
        if (!chunk.GetBlock(x + 1, y, z).IsSolid(Direction.west)) {
            meshData = FaceDataEast(chunk, x, y, z, meshData);
        }

        // Check if the block west has a solid east face
        if (!chunk.GetBlock(x - 1, y, z).IsSolid(Direction.east)) {
            meshData = FaceDataWest(chunk, x, y, z, meshData);
        }

        return meshData;
    }
开发者ID:strauzen,项目名称:Voxels,代码行数:34,代码来源:Block.cs

示例8: AddBounds

    public void AddBounds(Bounds bounds, Color color)
    {
        MeshData meshData = null;
        for (int i = 0; i < datas.Count; ++i)
        {
            if (datas[i].vertexCount >= vertexBuffSize) continue;
            else meshData = datas[i];
        }
        if (meshData == null)
        {
            meshData = new MeshData();
            datas.Add(meshData);
        }

        Vector3 min = bounds.min;
        Vector3 max = bounds.max;
        meshData.vertices[meshData.vertexCount + 0] = min;
        meshData.vertices[meshData.vertexCount + 1].Set(min.x, min.y, max.z);
        meshData.vertices[meshData.vertexCount + 2].Set(min.x, max.y, min.z);
        meshData.vertices[meshData.vertexCount + 3].Set(min.x, max.y, max.z);
        meshData.vertices[meshData.vertexCount + 4].Set(max.x, min.y, min.z);
        meshData.vertices[meshData.vertexCount + 5].Set(max.x, min.y, max.z);
        meshData.vertices[meshData.vertexCount + 6].Set(max.x, max.y, min.z);
        meshData.vertices[meshData.vertexCount + 7] = max;

        for (int i = 0; i < 8; ++i) meshData.colors[meshData.vertexCount + i] = color;
        for (int i = 0; i < 24; ++i) meshData.indices[meshData.vertexCount * 3 + i] = gWireFrameIndex[i] + meshData.vertexCount;
        meshData.vertexCount += 8;
    }
开发者ID:WaylandGod,项目名称:learn_unity,代码行数:29,代码来源:BoundsRenderer.cs

示例9: blockData

    public override MeshData blockData(Chunk chunk, int x, int y, int z, MeshData meshData)
    {
        meshData.useRenderDataForCol = false;

        if (!chunk.getBlock (x, y + 1, z).isSolid (Direction.up)) {
            meshData = FaceDataUp (chunk, x, y, z, meshData);
        }

        if (!chunk.getBlock (x, y - 1, z).isSolid (Direction.down)) {
            meshData = FaceDataDown (chunk, x, y, z, meshData);
        }

        if (!chunk.getBlock (x, y, z + 1).isSolid (Direction.north)) {
            meshData = FaceDataNorth (chunk, x, y, z, meshData);
        }

        if (!chunk.getBlock (x, y, z - 1).isSolid (Direction.south)) {
            meshData = FaceDataSouth (chunk, x, y, z, meshData);
        }

        if (!chunk.getBlock (x + 1, y, z).isSolid (Direction.east)) {
            meshData = FaceDataEast (chunk, x, y, z, meshData);
        }

        if (!chunk.getBlock (x - 1, y, z).isSolid (Direction.west)) {
            meshData = FaceDataWest (chunk, x, y, z, meshData);
        }

        return meshData;
    }
开发者ID:Aden-Herold,项目名称:AzamRealms,代码行数:30,代码来源:BlockTallGrass.cs

示例10: AddQuadFlatBlend

    public virtual MeshData AddQuadFlatBlend( 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.AddBlendTriangle ();

        meshData.AddVertex(points [1], flatnorm2);
        meshData.AddVertex(points [2], flatnorm2);
        meshData.AddVertex(points [3], flatnorm2);
        meshData.AddBlendTriangle ();

        Color32[] vcolors = new Color32[6];
        vcolors [2] = Color.clear;
        vcolors [4] = Color.clear;
        vcolors [5] = Color.clear;
        vcolors [0] = Color.white;
        vcolors [1] = Color.white;
        vcolors [3] = Color.white;
        meshData.colors.AddRange (vcolors);

        return meshData;
    }
开发者ID:TwoClunkers,项目名称:Clunk-Genesis,代码行数:31,代码来源:Block.cs

示例11: 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;

	}
开发者ID:SebLague,项目名称:Procedural-Landmass-Generation,代码行数:60,代码来源:MeshGenerator.cs

示例12: 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;
        }
开发者ID:TwoClunkers,项目名称:Clunk-Genesis,代码行数:34,代码来源:Beam.cs

示例13: DrawMesh

 public void DrawMesh(MeshData meshData, Texture2D texture)
 {
     // Mesh filter is used to proceduraly change mesh
     // It allow us to get to the mesh components
     meshFilter.sharedMesh = meshData.GenerateMesh();
     meshRenderer.sharedMaterial.mainTexture = texture;
 }
开发者ID:RokKos,项目名称:ProceduralLandScape,代码行数:7,代码来源:MapDisplay.cs

示例14: AddTypeElement

    public bool AddTypeElement(System.Xml.Linq.XElement elemtype)
    {
        XAttribute fileAtt = elemtype.Attribute("file");
        if (fileAtt == null)
        {
            //Add error message here
            return false;
        }
        string filePath = Path.Combine(Path.GetDirectoryName(new Uri(elemtype.BaseUri).LocalPath), fileAtt.Value);
        filePath = Path.GetFullPath(filePath);

        //	Load the OBJ in
        var lStream = new FileStream(filePath, FileMode.Open);
        var lOBJData = OBJLoader.LoadOBJ(lStream);
        lStream.Close();
        meshData = new MeshData[(int)MeshLayer.Count];
        Mesh tempMesh = new Mesh();
        for (int i = 0; i < meshData.Length; i++)
        {
            tempMesh.LoadOBJ(lOBJData, ((MeshLayer)i).ToString());
            meshData[i] = new MeshData(tempMesh);
            tempMesh.Clear();
        }
        lStream = null;
        lOBJData = null;
        return true;
    }
开发者ID:christopherbauer,项目名称:armok-vision,代码行数:27,代码来源:MeshContent.cs

示例15: AddCircularPlane

    public static void AddCircularPlane(float radius, int rings, int segments, Vector3 axis, MeshData meshData)
    {
        var vertices = meshData.Vertices;
        var triangles = meshData.Triangles;
        float radiusScalar = radius / rings;
        var ringPoints = Enumerable.Range(1, rings).Select(i => GetCircleOfPoints(i * radiusScalar, segments, axis)).ToArray();

        int startingIndex = vertices.Count;
        vertices.Add(Vector3.zero);

        //add points to vertex list
        foreach (var circle in ringPoints) foreach (var point in circle) vertices.Add(point);

        //Add triangles from center point to the first ring
        for (int i = 2; i <= segments; i++)
        {
            triangles.AddRange(new int[] { startingIndex, startingIndex + i - 1, startingIndex + i });
        }
        //Add the last triangle
        triangles.AddRange(new int[] { startingIndex, startingIndex + segments, startingIndex + 1 });

        //Now add the rest of the rings
        for(int r=1;r<rings;r++)
        {
            int ringIndex = r * segments + 1 + startingIndex;
            int prevRingIndex = (r - 1) * segments + 1 + startingIndex;
            for(int s=1;s<segments;s++)
            {
                triangles.AddRange(new int[]
                {
                    ringIndex  + s - 1,
                    ringIndex + s,
                    prevRingIndex + s - 1
                });

                triangles.AddRange(new int[]
                {
                    prevRingIndex + s - 1,
                    ringIndex + s,
                    prevRingIndex + s
                });
            }

            //Add final quad
            triangles.AddRange(new int[]
            {
                ringIndex + segments-1,
                ringIndex + 0,
                prevRingIndex + segments-1
            });

            triangles.AddRange(new int[]
            {
                prevRingIndex + segments-1,
                ringIndex + 0,
                prevRingIndex + 0
            });
        }
    }
开发者ID:greengiant83,项目名称:shellexplorer,代码行数:59,代码来源:MeshHelper.cs


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