DataModelMesh

Show Deprecated
not creatable
not browsable

The DataModelMesh is an abstract class from which mesh classes descend.

Mesh classes are objects that, when parented to BaseParts alter the appearance of the part to that of a predefined mesh. Note, they only alter the appearance of the part and not the physics/collision boundaries of the part. Developers looking to apply a mesh to a part that alters the part's collision should use MeshParts.

Note the MeshPart and CharacterMesh classes do not descend from DataModelMesh.

Summary

Properties

Properties

Offset

read parallel

The Offset of a mesh determines the distance from the BasePart.Position of a BasePart that the mesh will be displayed.

How to use mesh offset

The Offset property changes the relative position the mesh will be rendered at. For example, an offset of 0, 5, 0 will cause the mesh to be displayed 5 studs above the position of the BasePart.

The position of the BasePart remains unchanged, meaning the physics collision box of the part will remain in the same location. This is demonstrated in the image below where the green outline (a SelectionBox) shows the extents of the BasePart.

Other uses for mesh offset

There are a number of interesting uses for the mesh offset property.

  • Offset and DataModelMesh.Scale can be animated using TweenService relatively inexpensively as the engine does not need to make any physics/collision calculations as the BasePart is not moved.
  • Changing the relationship between the mesh and its collision extents (determined by the BasePart)

Code Samples

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

read parallel

The Scale of a mesh determines the size of the mesh relative to its original dimensions.

How to use mesh scale

The scale property works slightly differently depending on the type of mesh being used. Note the size of the BasePart remains unchanged, meaning the physics collision box of the part will remain the same.

Mesh scale demonstration

The above behavior can be seen in the following demonstration images.

Linear scaling relative to part size for 'Brick', 'Wedge' and 'Sphere' meshes.

Linear scaling relative to original uploaded mesh for 'FileMesh' meshes

Non-uniform constrained scaling for 'Cylinder' meshes

Other uses for mesh scale

There are a number of interesting uses for the mesh offset property.

  • DataModelMesh.Offset and Scale can be animated using TweenService relatively inexpensively as the engine does not need to make any physics/collision calculations as the BasePart is not changed.
  • Changing the relationship between the mesh and its collision extents (determined by the BasePart)

Code Samples

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

read parallel

VertexColor determines the hue change of the Texture of a FileMesh.

The image below shows two versions of the hat "Ozzy's Formal Top Hat". The left has a default VertexColor of (1, 1, 1), or white. The right has a VertexColor of (0, 0, 1), or blue. The RGB colors on the texture of the red and white hat are multiplied with that of the VertexColor's XYZ components.

It should be noted that this property is a Vector3 rather than a Color3. To convert, use the following function:


local function color3ToVector3(c3)
return Vector3.new(c3.r, c3.g, c3.b)
end

Although this property allows basic modification of a texture, changing a texture entirely provides more control. See MeshPart for more details.

Code Samples

Mesh VertexColor

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.VertexColor = Vector3.new(1, 1, 1)
mesh.Parent = part
-- parent part to workspace
part.Parent = workspace
-- create tweens
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local blackTween = TweenService:Create(mesh, tweenInfo, { VertexColor = Vector3.new(0, 0, 0) })
local redTween = TweenService:Create(mesh, tweenInfo, { VertexColor = Vector3.new(1, 0, 0) })
local greenTween = TweenService:Create(mesh, tweenInfo, { VertexColor = Vector3.new(0, 1, 0) })
local blueTween = TweenService:Create(mesh, tweenInfo, { VertexColor = Vector3.new(0, 0, 1) })
local resetTween = TweenService:Create(mesh, tweenInfo, { VertexColor = Vector3.new(1, 1, 1) })
-- animate
while true do
blackTween:Play()
blackTween.Completed:Wait()
redTween:Play()
redTween.Completed:Wait()
greenTween:Play()
greenTween.Completed:Wait()
blueTween:Play()
blueTween.Completed:Wait()
resetTween:Play()
resetTween.Completed:Wait()
task.wait()
end

Methods

Events