Version: 2017.1
Obsolete public static void DrawMesh (Mesh mesh, Vector3 position, Quaternion rotation);
Obsolete public static void DrawMesh (Mesh mesh, Vector3 position, Quaternion rotation, int materialIndex);
public static void DrawMesh (Mesh mesh, Vector3 position, Quaternion rotation, Material material, int layer, Camera camera= null, int submeshIndex= 0, MaterialPropertyBlock properties= null, bool castShadows= true, bool receiveShadows= true, bool useLightProbes= true);
public static void DrawMesh (Mesh mesh, Vector3 position, Quaternion rotation, Material material, int layer, Camera camera, int submeshIndex, MaterialPropertyBlock properties, Rendering.ShadowCastingMode castShadows, bool receiveShadows= true, Transform probeAnchor= null, bool useLightProbes= true);
Obsolete public static void DrawMesh (Mesh mesh, Matrix4x4 matrix);
Obsolete public static void DrawMesh (Mesh mesh, Matrix4x4 matrix, int materialIndex);
public static void DrawMesh (Mesh mesh, Matrix4x4 matrix, Material material, int layer, Camera camera= null, int submeshIndex= 0, MaterialPropertyBlock properties= null, bool castShadows= true, bool receiveShadows= true, bool useLightProbes= true);
public static void DrawMesh (Mesh mesh, Matrix4x4 matrix, Material material, int layer, Camera camera, int submeshIndex, MaterialPropertyBlock properties, Rendering.ShadowCastingMode castShadows, bool receiveShadows= true, Transform probeAnchor= null, bool useLightProbes= true);

参数

mesh 要绘制的 Mesh
position 网格的位置。
rotation 网格的旋转。
materialIndex 要绘制的网格子集。
matrix 网格的变换矩阵(组合了位置、旋转和其他变换)。
material 要使用的 Material
layer 要使用的 Layer
camera 如果为 /null/(默认值),将在所有摄像机中绘制网格。否则,仅在给定摄像机中渲染网格。
submeshIndex 要绘制网格的哪个子集。这只适用于由若干种材质构成的网格。
properties 在绘制此网格之前应用于材质的其他材质属性。请参阅 MaterialPropertyBlock
castShadows 网格是否应投射阴影?
receiveShadows 网格是否应接受阴影?
useLightProbes 网格是否应使用光照探针?
probeAnchor 如果使用,网格将使用该变换组件的位置对光照探针进行采样,并找到匹配的反射探针。

描述

绘制一个网格。

DrawMesh 为一帧绘制一个网格。网格可以投射和接受阴影, 并受到光照和投影器的影响 - 它就像是某些游戏对象的一部分。可以为所有摄像机或 只为某些特定摄像机绘制网格。

如果您需要绘制大量网格但又不希望出现创建和管理游戏对象的开销, 则可以使用 DrawMesh。注意,DrawMesh 不立即绘制网格;它只“提交”网格以进行渲染。网格 将作为正常渲染过程的一部分进行渲染。若要立即绘制网格,请使用 Graphics.DrawMeshNow

DrawMesh 不立即绘制网格,因此如果您在该函数调用之间修改材质属性, 网格不会收到这些更改。若要绘制一系列具有相同材质但属性略有不同(例如,更改每个网格的颜色)的网格, 请使用 MaterialPropertyBlock 参数。

Note that this call will create some internal resources while the mesh is queued up for rendering. The allocation happens immediatly and will be kept around until the end of frame (if the object was queued for all cameras) or until the specified camera renders itself.

另请参阅:MaterialPropertyBlock

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Mesh mesh; public Material material; public void Update() { // will make the mesh appear in the scene at origin position Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, material, 0); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961