SpecialMesh
The SpecialMesh object applies a mesh to a BasePart depending on the MeshType property. A number of options are available.
- Brick - A block shape, equivalent to a BlockMesh
- FileMesh - A user uploaded Mesh, equivalent to FileMesh that a texture can be applied to using the FileMesh.TextureId property
- Head - A character head shape
- Sphere - A sphere shape, similar to a Part with a Part.Shape of 'Ball' but can be freely resized on all axis
- Wedge - A wedge shape, identical to a WedgePart
- Torso - A block with sloped sides, due to be deprecated
Note, each SpecialMesh.MeshType will scale differently when using DataModelMesh.Scale, for more information on this please see the page on DataModelMesh.Scale. The SpecialMesh object also exposes the DataModelMesh.Offset property.
It is important to remember that when using a SpecialMesh, only the appearance of a part changes. The collision model of the part remains the same. For example, a character will not be able to walk correctly over a mesh as the mesh geometry is not taken into account.
SpecialMesh vs MeshPart
There are currently two ways of using a developer created mesh. They are using a SpecialMesh with the SpecialMesh.FileType set to 'FileMesh', or by using a MeshPart. Although, on the whole, the MeshPart object has superseded the SpecialMesh there are some differences developers should be aware of.
- BasePart.Material displays correctly on the mesh when using a MeshPart and not when using a SpecialMesh
- MeshParts include the MeshPart.CollisionFidelity property, meaning the collision model of a MeshPart can be set to resemble the geometry of the mesh. The SpecialMesh object by contrast, uses the parent BaseParts collision model
- The MeshId property of a SpecialMesh can be changed by a Script or LocalScript during runtime. The MeshId property of a MeshPart can not.
Code Samples
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()
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
Summary
Properties
Determines the type of mesh that will be applied to the BasePart the SpecialMesh is parented to.
The MeshId is the content ID of the mesh that is to be displayed.
The TextureId is the content ID of the texture that is to be applied to the mesh.
The Offset of a mesh determines the relative position from the BasePart.Position of a BasePart that the mesh will be displayed at.
The Scale of a mesh determines the size of the mesh relative to its original dimensions.
Changes the hue of a mesh's texture, used with FileMesh.TextureId.
Properties
MeshType
The mesh that the SpecialMeshobject applies to the BasePart depends on the MeshType property. A number of options are available.
- Brick - A block shape, equivalent to a BlockMesh
- FileMesh - A user uploaded Mesh, equivalent to FileMesh that a texture can be applied to using the FileMesh.TextureId property
- Head - A character head shape
- Sphere - A sphere shape, similar to a Part with a Part.Shape of 'Ball' but can be freely resized on all axis
- Wedge - A wedge shape, identical to a WedgePart
- Torso - A block with sloped sides, due to be deprecated
Note, each MeshType will scale differently when using DataModelMesh.Scale, for more information on this please see the page on DataModelMesh.Scale.
Code Samples
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