数据模型网格是一个抽象类,从而网格类下降。
网格类是对象,当作为父级到 BaseParts 时,将零件的外观更改为预定义网格的外观请注意,它们仅更改零件的外观,而不是零件的物理/碰撞边界。想要将网格应用到改变零件碰撞的零件上的开发人员应该使用 MeshParts 。
注意 MeshPart 和 CharacterMesh 类不从 DataModelMesh 下降。
概要
属性
网格的抵消决定了网格在显示时的相对位置,从 BasePart.Position 的 BasePart 显示网格。
网格的尺寸决定了网格相对于原始尺寸的大小。
更改网格纹理的色调,用于 FileMesh.TextureId 。
属性
Offset
网格的偏移决定了网格在显示时与 BasePart.Position 的距离,网格将显示在哪个 BasePart 。
如何使用网格偏移值
抵消属性改变网格在相对位置渲染的关系。例如,偏移 0、5、0 会导致网格显示在 BasePart 的位置上 5 格。
BasePart的位置不会改变,这意味着零件的物理碰撞箱仍将保持在同一位置。这在下面的图像中得到了展示,其中绿色轮廓(a SelectionBox)显示了BasePart的边界。
网格偏移值的其他用途
网格偏移属性有很多有趣的用途。
- 抵消和 可以使用相对便宜的方式进行动画,因为引擎不需要进行任何物理/碰撞计算,因为 不移动。
- 更改网格和其碰撞边界之间的关系(由 BasePart 决定)
代码示例
In this code sample a BasePart is instanced with a SpecialMesh. The DataModelMesh.Scale and DataModelMesh.Offset properties of the SpecialMesh are then animated using TweenService.
local TweenService = game:GetService("TweenService")
-- instance a part and a mesh
local part = Instance.new("Part")
part.Size = Vector3.new(4, 8, 4)
part.Position = Vector3.new(0, 4, 0)
part.Anchored = true
part.CanCollide = false
local mesh = Instance.new("SpecialMesh")
mesh.MeshType = Enum.MeshType.FileMesh
mesh.MeshId = "rbxassetid://1086413449"
mesh.TextureId = "rbxassetid://1461576423"
mesh.Offset = Vector3.new(0, 0, 0)
mesh.Scale = Vector3.new(4, 4, 4)
mesh.Parent = part
-- selection box to show part extents
local box = Instance.new("SelectionBox")
box.Adornee = part
box.Parent = part
-- parent part to workspace
part.Parent = workspace
-- animate offset and scale with a tween
local tween = TweenService:Create(
mesh,
TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1, true, 0),
{ Scale = Vector3.new(1, 1, 1), Offset = Vector3.new(0, 3, 0) }
)
tween:Play()
Scale
网格的尺寸决定了网格相对于原始尺寸的大小。
如何使用网格缩放
使用的网格类型不同,缩放属性的工作方式略有不同。注意 BasePart 的大小仍然不变,这意味着零件的物理碰撞箱仍然相同。
- SpecialMesh 对象与 SpecialMesh.FileType 设置为在上传到 Roblox 时网格的原始尺寸相对于网格的“FileMesh”缩放
- CylinderMesh 对象或 SpecialMesh 对象,其 SpecialMesh.FileType 设置为与父元素级的 BasePart.Size 相对的“圆柱”尺寸。为气缸高度轴制定统一标准,并保持气缸长度和宽度的 1:1 比例,使用最低值。
- SpecialMesh 对象与 SpecialMesh.FileType 设置为“头”目前以非标准方式缩放。开发人员不应该依赖这一点,因为有计划改变这种行为。
- SpecialMesh 对象与 SpecialMesh.FileType 设置为“躯干”尺寸以非标准方式。开发人员不应该依赖这一点,因为有计划停止此网格输入。
网格缩放示范
上述行为可以在以下示范图像中看到。
对“砖块”、“楔子”和“球体”网格的部件尺寸相对线性缩放。
对“文件网格”网格的原始上传网格相对线性缩放
对“圆柱”网格的非标准约束缩放
网格缩放的其他用途
网格偏移属性有很多有趣的用途。
- 更改网格和其碰撞边界之间的关系(由 BasePart 决定)
代码示例
In this code sample a BasePart is instanced with a SpecialMesh. The DataModelMesh.Scale and DataModelMesh.Offset properties of the SpecialMesh are then animated using TweenService.
local TweenService = game:GetService("TweenService")
-- instance a part and a mesh
local part = Instance.new("Part")
part.Size = Vector3.new(4, 8, 4)
part.Position = Vector3.new(0, 4, 0)
part.Anchored = true
part.CanCollide = false
local mesh = Instance.new("SpecialMesh")
mesh.MeshType = Enum.MeshType.FileMesh
mesh.MeshId = "rbxassetid://1086413449"
mesh.TextureId = "rbxassetid://1461576423"
mesh.Offset = Vector3.new(0, 0, 0)
mesh.Scale = Vector3.new(4, 4, 4)
mesh.Parent = part
-- selection box to show part extents
local box = Instance.new("SelectionBox")
box.Adornee = part
box.Parent = part
-- parent part to workspace
part.Parent = workspace
-- animate offset and scale with a tween
local tween = TweenService:Create(
mesh,
TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1, true, 0),
{ Scale = Vector3.new(1, 1, 1), Offset = Vector3.new(0, 3, 0) }
)
tween:Play()