返回介绍

MeshFilter.mesh 网格

发布于 2019-12-18 15:38:02 字数 4176 浏览 1072 评论 0 收藏 0

JavaScript => public var mesh: Mesh;
C# => public Mesh mesh;

Description 描述

Returns the instantiated Mesh assigned to the mesh filter.

返回实例化网格并指定到该网格过滤器。

If no mesh is assigned to the mesh filter a new mesh will be created and assigned.

如果没有网格指定到网格过滤器,一个新的网格将会被创建并被指定。

If a mesh is assigned to the mesh filter already, then first query of mesh property will create a duplicate of it, and this copy will be returned. Further queries of mesh property will return this duplicated mesh instance. Once mesh property is queried, link to the original shared mesh is lost and MeshFilter.sharedMesh property becomes an alias to mesh. If you want to avoid this automatic mesh duplication, use MeshFilter.sharedMesh instead.

如果网格已经被指定到网格过滤器,那么首先查询的网格属性将会创建一个它的副本,并且该副本将会被返回。接下来查询的网格属性将会返回该网格的实例。一旦网格属性是queried,链接到原来共享的网格丢失并MeshFilter.sharedMesh属性变成别的网格名。如果你要避免自动网格副本使用MeshFilter.sharedMesh替代。

By using mesh property you can modify the mesh for a single object only. The other objects that used the same mesh will not be modified.

通过使用网格属性,你仅可以修改单个对象的网格。其他对象使用同样的网格将不会被修改。

It is your responsibility to destroy the automatically instantiated mesh when the game object is being destroyed. Resources.UnloadUnusedAssets also destroys the mesh but it is usually only called when loading a new level.

当游戏对象被销毁时,摧毁自动实例化网格是你的责任。Resources.UnloadUnusedAssets也销毁网格但是它通常仅在加载一个新的级别时调用。

Consider mesh property as a shortcut for the following code:

对于接下来的代码考虑网格属性是种快捷方式:

JavaScript:

#pragma strict
function Start() {
	var mesh: Mesh = GetComponent.<MeshFilter>().sharedMesh;
	var mesh2: Mesh = Instantiate(mesh);
	GetComponent.<MeshFilter>().sharedMesh = mesh2;
}

Which is called on first query of mesh property.

在首先查询的网格属性哪一个被调用。

Note: If MeshFilter is a part of an asset object, quering mesh property is not allowed and only asset mesh can be assigned.

注意:如果网格过滤器是对象资源的一部分,查询网格属性是不被允许的并且仅资源网格可以被分配。

JavaScript:

#pragma strict
// Distorts the mesh vertically.
function Update() {
	// Get instantiated mesh
	var mesh: Mesh = GetComponent.<MeshFilter>().mesh;
	// Randomly change vertices
	var vertices: Vector3[] = mesh.vertices;
	var p: int = 0;
	while ( p < vertices.Length ) {
		vertices[p] += new Vector3(0, Random.Range(-0.3F, 0.3F), 0);
		p++;
	}
	mesh.vertices = vertices;
	mesh.RecalculateNormals();
}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void Start() {
        Mesh mesh = GetComponent<MeshFilter>().sharedMesh;
        Mesh mesh2 = Instantiate(mesh);
        GetComponent<MeshFilter>().sharedMesh = mesh2;
    }
}

Which is called on first query of mesh property.

在首先查询的网格属性哪一个被调用。

Note: If MeshFilter is a part of an asset object, quering mesh property is not allowed and only asset mesh can be assigned.

注意:如果网格过滤器是对象资源的一部分,查询网格属性是不被允许的并且仅资源网格可以被分配。

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    // Distorts the mesh vertically.
    void Update() {
        // Get instantiated mesh
        Mesh mesh = GetComponent<MeshFilter>().mesh;
        // Randomly change vertices
        Vector3[] vertices = mesh.vertices;
        int p = 0;
        while (p < vertices.Length) {
            vertices[p] += new Vector3(0, Random.Range(-0.3F, 0.3F), 0);
            p++;
        }
        mesh.vertices = vertices;
        mesh.RecalculateNormals();
    }
}

meshfilter

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文