Version: 2021.3
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);
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);
public static void DrawMesh (Mesh mesh, Matrix4x4 matrix, Material material, int layer, Camera camera, int submeshIndex, MaterialPropertyBlock properties, Rendering.ShadowCastingMode castShadows, bool receiveShadows, Transform probeAnchor, Rendering.LightProbeUsage lightProbeUsage, LightProbeProxyVolume lightProbeProxyVolume= null);

参数

mesh 要绘制的 Mesh
position 网格的位置。
rotation 网格的旋转。
matrix 网格的变换矩阵(组合了位置、旋转和其他变换)。
material 要使用的 Material
layer 要使用的 Layer
camera If null (default), the mesh will be drawn in all cameras. Otherwise it will be rendered in the given Camera only.
submeshIndex 要绘制网格的哪个子集。这只适用于由若干种材质构成的网格。
properties 在绘制此网格之前应用于材质的其他材质属性。请参阅 MaterialPropertyBlock
castShadows 确定网格是否可以投射阴影。
receiveShadows 确定网格是否可以接受阴影。
useLightProbes 网格是否应使用光照探针?
probeAnchor 如果使用,网格将使用该变换组件的位置对光照探针进行采样,并找到匹配的反射探针。
lightProbeUsage 网格的 LightProbeUsage

描述

绘制一个网格。

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

如果您需要绘制大量网格但又不希望出现创建和管理游戏对象的开销, 则可以使用 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 them up. 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.

注意,在网格排队等待渲染时,该调用将创建一些内部资源。该分配立即执行,并将保留到帧结束(如果对象排队等待所有摄像机),或直到指定摄像机渲染自身。

另请参阅: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