texture | 要绘制的体积纹理。 |
slicePositions | 纹理采样平面的位置。 |
filterMode | 设置要使用的纹理过滤模式。 |
useColorRamp | 启用颜色渐变可视化。 |
customColorRamp | Unity 用作颜色渐变的自定义渐变。如果未指定,Unity 使用 Google Turbo 颜色渐变。 |
在 3D 空间中使用切片渲染模式绘制 3D 纹理。
使用自定义渐变以切片模式渲染的头扫描。
using UnityEditor; using UnityEngine;
[ExecuteInEditMode] public class Reference : MonoBehaviour { public Texture3D texture; public Vector3 slicePositions; public FilterMode filterMode; public bool useColorRamp; public bool useCustomColorRamp;
// We should initialize this gradient before using it as a custom color ramp public Gradient customColorRampGradient; }
[CanEditMultipleObjects] [CustomEditor(typeof(Reference))] public class Handle : Editor { private void OnSceneViewGUI(SceneView sv) { Object[] objects = targets; foreach (var obj in objects) { Reference reference = obj as Reference; if (reference != null && reference.texture != null) { Handles.matrix = reference.transform.localToWorldMatrix; Handles.DrawTexture3DSlice(reference.texture, reference.slicePositions, reference.filterMode, reference.useColorRamp, reference.useCustomColorRamp ? reference.customColorRampGradient : null); } } }
void OnEnable() { SceneView.duringSceneGui += OnSceneViewGUI; }
void OnDisable() { SceneView.duringSceneGui -= OnSceneViewGUI; } }