Graphics.DrawMesh 绘制网格

static function DrawMesh (mesh : Mesh, position : Vector3, rotation : Quaternion, material : Material, layer : int, camera : Camera = null, submeshIndex : int = 0, properties : MaterialPropertyBlock = null) : void
static function DrawMesh (mesh : Mesh, matrix : Matrix4x4, material : Material, layer : int, camera : Camera = null, submeshIndex : int = 0, properties : MaterialPropertyBlock = null) : void

Parameters参数

Description描述

Draw a mesh.

绘制一个网格。

DrawMesh draws a mesh for one frame. The mesh will be affected by the lights, can cast and receive shadows and be affected by Projectors - just like it was part of some game object. It can be drawn for all cameras or just for some specific camera.

DrawMesh 在一帧中绘制一个网格。这个网格将受到光照的影响,可以投射和接收阴影并受投射器影响,就像它是某个游戏物体的一部分。他可以绘制于所有相机或者只在特定的一些相机。

Use DrawMesh in situations where you want to draw large amount of meshes, but don't want the overhead of creating and managing game objects. Note that DrawMesh does not draw the mesh immediately; it merely "submits" it for rendering. The mesh will be rendered as part of normal rendering process. If you want to draw a mesh immediately, use Graphics.DrawMeshNow.

使用DrawMesh的情况,你想绘制大量的网格,而又不想在创建和管理游戏物体的开销。注意,DrawMesh不会立即绘制网格;它仅仅提交它用于渲染。网格将被作为普通渲染过程的一部分。如果想立即绘制一个网格。使用Graphics.DrawMeshNow

Because DrawMesh does not draw mesh immediately, modifying material properties between calls to this function won't make the meshes pick up them. If you want to draw series of meshes with the same material, but slightly different properties (e.g. change color of each mesh), use MaterialPropertyBlock parameter.

因为DrawMesh不会立即绘制网格,在调用这个函数期间修改材质属性不会使材质指定它们。如果你想绘制一系列相同材质的网格,但是稍微有些不同的属性(例如,改变每个网格的颜色),那么使用MaterialPropertyBlock参数。

参见:MaterialPropertyBlock.

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public Mesh aMesh;
	public Material aMaterial;
	void Update() {
		Graphics.DrawMesh(aMesh, Vector3.zero, Quaternion.identity, aMaterial, 0);
	}	
}
// Draws aMesh with aMaterial at (0,0,0) with no rotation for one frame
//绘制网格和材质在(0,0,0) 在一帧不带有旋转

var aMesh : Mesh;
var aMaterial : Material;

function Update() {
	Graphics.DrawMesh(aMesh, Vector3.zero, Quaternion.identity, aMaterial, 0);
}
最后修改:2011年2月27日 Sunday 19:36

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。