DataModelMesh

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

無法建立
無法瀏覽

數據模型網格是從網格類中派生的抽象類。

網格類別是對象,當作為父級到 BaseParts 時,會將零件的外觀變更為預定義網格的外觀。注意,它們只改變零件的外觀,而不是零件的物理/碰撞邊界。想要將網格應用到改變零件碰撞的零件上的開發人員應該使用 MeshParts

注意 MeshPartCharacterMesh 類別不從 DataModelMesh 下降。

概要

屬性

屬性

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.

Mesh Offset and Scale

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非標準方式縮放到"托索"尺寸。開發人員不應該依賴這個,因為有計劃停用此網格輸入。

網格縮放示範

上述行為可以在以下示範圖像中看到。

對於「磚塊」、「楔子」和「球」網格的部件尺寸相對線性縮放。

對於「檔案網格」網格的原始上傳網格相對線性縮放

對「圓筒」網格的非一致約束縮放

網格比例放的其他用途

網格偏移屬性有許多有趣的用途。

  • DataModelMesh.Offset 和縮放可以使用 TweenService 相對便宜地進行動畫,因為引擎不需要進行任何物理/碰撞計算,因為 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.

Mesh Offset and Scale

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()

VertexColor

平行讀取

VertexColor 決定了 TextureFileMesh 的顏色變化。請注意,此屬性是 Vector3 而不是 Color3;要轉換,請使用 Color3.RColor3.GColor3.B 屬性。

雖然此屬性允許對紋理進行基本修改,但完全更改紋理提供更多控制。請見 MeshPart 獲得更多詳情。

方法

活動