主题
FileMesh
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- [FileMesh](5 属性)
继承成员
1 个来源 / 4 属性 / 25 函数 / 6 事件
- 来自 Unit(4 属性 / 25 函数 / 6 事件)
- 属性:
AssetId、Name、Desc、Parent - 函数:
ClearAllChildren、GetChildren、GetDescendants、IsAncestorOf、IsDescendantOf、FindFirstAncestor、FindFirstAncestorWhichIsA、FindFirstAncestorOfClass、FindFirstChild、FindFirstChildWhichIsA、FindFirstChildOfClass、HasChildren、GetChildCount、GetChildAtIndex、SetAttribute、GetAttribute、GetAllProps、Clone、IsA、Destroy、GetPropertyChangedSignal、GetAttributeChangedSignal、FindFromPath、GetFullPath、GetDebugId - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
FileMesh 是用于在场景中显示自定义网格外观的单位,通过 MeshId 指定网格资产、TextureId 指定纹理资产,并可借助 Scale 与 Offset 调整网格的缩放与偏移,用 VertexColor 控制顶点着色效果。它通常作为已有渲染或空间单位的子节点存在,为宿主附加或替换可见模型。
适用场景
适用于需要给场景中已有部件叠加自定义网格外观的场合,例如先按名称找到目标部件,再创建一个 FileMesh 挂到该部件下,为其指定网格与纹理资产来改变显示效果。
使用要点
先通过 game:CreateUnit("FileMesh", config) 或 World:CreateUnit("FileMesh", config) 创建实例,再把返回实例的 Parent 指向已有的渲染或空间单位;随后给 MeshId 赋 official://mesh/... 形式的网格标识、给 TextureId 赋 official://skin/... 形式的纹理标识,并按需设置 Scale、Offset(Vector3)与 VertexColor(Color)。
注意事项
FileMesh 通过 World:CreateUnit("FileMesh", config) 创建,再挂到已有渲染/空间 Unit 下。MeshId 使用 official://mesh/...,TextureId 使用 official://skin/...;Scale 和 Offset 使用 Vector3,VertexColor 按公开类型使用 Color.New(r,g,b,a)。
代码示例
创建 FileMesh 并设置网格外观
lua
-- @runtime client
local world = game:GetService("World")
-- 创建一个可作为父级的渲染对象
local parentPart = world:CreateUnit("RenderUnit", {
Name = "MeshParent",
RenderMeshId = "official://mesh/59268",
Position = Vector3.New(0, 0, 0),
})
local fileMesh = world:CreateUnit("FileMesh", {
Name = "MyFileMesh",
})
fileMesh.Parent = parentPart
fileMesh.MeshId = "official://mesh/90003"
fileMesh.TextureId = "official://skin/110"
fileMesh.Scale = Vector3.New(4, 4, 4)
fileMesh.Offset = Vector3.New(0, 1, 0)
fileMesh.VertexColor = Color.New(255, 0, 0, 255)属性 (5)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
MeshId | String | "" | FileMesh 的网格资产 ID 属性,类型为字符串,用于指定该网格单位所使用的网格资源标识。 |
TextureId | String | "" | FileMesh 的纹理资产 ID 属性,类型为字符串,用于指定贴在网格表面上的纹理资源标识。 |
Scale | Vector3 | [1, 1, 1] | Scale 是 FileMesh 的公开可编辑属性,类型为 Vector3,默认值为 (1, 1, 1)。它用于描述该网格在各个坐标轴方向上的缩放系数,与 Offset 一起控制网格的呈现尺寸与位置微调。 |
Offset | Vector3 | [0, 0, 0] | Offset 是 FileMesh 的公开可编辑属性,类型为 Vector3,默认值为 (0, 0, 0)。它用于描述该网格在自身坐标系下的偏移量,常与 Scale、MeshId、TextureId 等属性一起决定网格的呈现方式。 |
VertexColor | Color | Color.New(255, 255, 255, 255) | 设置 FileMesh 所有顶点的统一颜色,影响网格的最终渲染色调。 |
