數據模型網格是從網格類中派生的抽象類。
網格類別是對象,當作為父級到 BaseParts 時,會將零件的外觀變更為預定義網格的外觀。注意,它們只改變零件的外觀,而不是零件的物理/碰撞邊界。想要將網格應用到改變零件碰撞的零件上的開發人員應該使用 MeshParts 。
注意 MeshPart 和 CharacterMesh 類別不從 DataModelMesh 下降。
概要
屬性
網格的偏移決定網格將顯示在哪個 上的相對位置。
網格的尺寸決定網格與原始尺寸相對的大小。
變更網格紋理的顏色,使用 FileMesh.TextureId 。
屬性
Offset
網格的偏移決定網格在 BasePart.Position 的距離將顯示的 BasePart 。
如何使用網格偏移值
偏移屬性會改變網格在相對位置會被渲染的位置。例如,偏移 0、5、0 會導致網格被顯示 5 個單位超過 BasePart 的位置。
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 時
- 對象或 對象設為「磚塊」、「楔子」或「球」尺寸與父元素級的 相對一致
- 物件或 物件,其 設為與父元素 相對的 圓筒 尺寸。對於圓筒高度軸的一致性,並維持圓筒長度和寬度的 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()