TriMesh 类
内容
[
隐藏
]TriMesh class
TriMesh 包含可直接被 GPU 使用的原始数据。此类是一个实用工具,用于帮助构建仅包含每顶点数据的网格。
public class TriMesh : Entity, IEnumerable<Vertex>
构造函数
| 名称 | 描述 |
|---|---|
| TriMesh(string, VertexDeclaration) | 初始化 TriMesh 实例 |
属性
| 名称 | 描述 |
|---|---|
| Capacity { get; } | 预分配顶点的容量。 |
| Excluded { get; set; } | 获取或设置在导出时是否排除此实体。 |
| IndicesCount { get; } | 此 TriMesh 中索引的数量 |
| virtual Name { get; set; } | 获取或设置名称。 |
| ParentNode { get; set; } | 获取或设置第一个父节点,如果设置了第一个父节点,则此实体将从其他父节点分离。 |
| ParentNodes { get; } | 获取所有父节点,实体可以附加到多个父节点以实现几何实例化 |
| Properties { get; } | 获取所有属性的集合。 |
| Scene { get; } | 获取此对象所属的场景 |
| UnmergedVerticesCount { get; } | 通过 BeginVertex 和 EndVertex 传入的未合并顶点的数量。 |
| VertexDeclaration { get; } | TriMesh 的顶点布局。 |
| VerticesCount { get; } | 此 TriMesh 中顶点的数量 |
| VerticesSizeInBytes { get; } | 所有顶点的总大小(字节) |
方法
| 名称 | 描述 |
|---|---|
| static CopyFrom(TriMesh, VertexDeclaration) | 使用新的顶点布局从输入复制 TriMesh |
| static FromMesh(Mesh, bool) | 根据给定的网格对象创建 TriMesh,顶点声明基于输入网格的结构。 |
| static FromMesh(VertexDeclaration, Mesh) | 使用给定的顶点布局从指定的网格对象创建 TriMesh。 |
| static FromRawData(VertexDeclaration, byte[], int[], bool) | 从原始数据创建 TriMesh |
| AddTriangle(int, int, int) | 添加一个新三角形 |
| BeginVertex() | 开始添加顶点 |
| EndVertex() | 结束添加顶点 |
| FindProperty(string) | 查找属性。它可以是动态属性(由 CreateDynamicProperty/SetProperty 创建)或本地属性(通过其名称识别) |
| GetBoundingBox() | 获取当前实体在其对象空间坐标系中的包围盒。 |
| virtual GetEntityRendererKey() | 获取在渲染器中注册的实体渲染器的键 |
| GetEnumerator() | 获取枚举器以枚举 Vertex |
| GetProperty(string) | 获取指定属性的值 |
| IndicesToArray(out int[]) | |
| IndicesToArray(out ushort[]) | |
| LoadVerticesFromBytes(byte[]) | 从字节加载顶点,字节长度必须是顶点大小的整数倍。 |
| ReadDouble(int, VertexField) | 读取 double 字段 |
| ReadFloat(int, VertexField) | 读取 float 字段 |
| ReadFVector2(int, VertexField) | 读取 vector2 字段 |
| ReadFVector3(int, VertexField) | 读取 vector3 字段 |
| ReadFVector4(int, VertexField) | 读取 vector4 字段 |
| ReadVector2(int, VertexField) | 读取 vector2 字段 |
| ReadVector3(int, VertexField) | 读取 vector3 字段 |
| ReadVector4(int, VertexField) | 读取 vector4 字段 |
| RemoveProperty(Property) | 移除动态属性。 |
| RemoveProperty(string) | 移除通过名称识别的指定属性 |
| SetProperty(string, object) | 设置指定属性的值 |
| override ToString() | 获取 TriMesh 的字符串表示 |
| VerticesToArray() | 将顶点数据转换为字节数组 |
| Write16bIndicesTo(Stream) | 将索引数据以 16 位整数写入流 |
| Write32bIndicesTo(Stream) | 将索引数据以 32 位整数写入流 |
| WriteVerticesTo(Stream) | 将顶点数据写入指定的流 |
示例
以下代码展示了如何使用自定义内存布局创建 TriMesh 并将其导出到文件。
//将顶点声明定义为 {FVector3 Position; FVector3 Normal; FVector2 UV}
VertexDeclaration vd = new VertexDeclaration();
vd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Position);
vd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Normal);
vd.AddField(VertexFieldDataType.FVector2, VertexFieldSemantic.UV);
//使用指定的内存布局将网格转换为 tri-mesh
var mesh = (new Sphere()).ToMesh();
var triMesh = TriMesh.FromMesh(vd, mesh);
//将其保存到流中,115 个顶点 * 每顶点 32 字节
using (var stream = new FileStream("output.bin", FileMode.Create))
{
triMesh.WriteVerticesTo(stream);
//将索引以 ushort 保存到流中,504 个索引 * 每索引 2 字节
triMesh.Write16bIndicesTo(stream);
}
另请参见
- class Entity
- class Vertex
- namespace Aspose.ThreeD.Entities
- assembly Aspose.3D