PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

Scale

DataModelMesh

Vector3

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.

  • SpecialMesh objects with SpecialMesh/FileType set to ‘FileMesh’ scale relative to the original dimensions of the mesh when it was uploaded to Roblox
  • BlockMesh objects or SpecialMesh objects with SpecialMesh/FileType set to ‘Brick’, ‘Wedge’ or ‘Sphere’ scale uniformly relative to the BasePart/Size of their parent
  • CylinderMesh objects or SpecialMesh objects with SpecialMesh/FileType set to ‘Cylinder’ scale relative to the BasePart/Size of their parent. Uniformly for the cylinders height axis and maintaining a 1:1 ratio for the length and width of the cylinder, using the lowest value.
  • SpecialMesh objects with SpecialMesh/FileType set to ‘Head’ currently scale in a non standard manner. Developers should not rely on this as their are plans to change this behavior
  • SpecialMesh objects with SpecialMesh/FileType set to ‘Torso’ scale in a non standard manner. Developers should not rely on this as their are plans to deprecate this mesh type.

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.
enter image description here

Linear scaling relative to original uploaded mesh for ‘FileMesh’ meshes
enter image description here

Non-uniform constrained scaling for ‘Cylinder’ meshes
enter image description here

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

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", part)
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)

-- selection box to show part extents
local box = Instance.new("SelectionBox", part)
box.Adornee = 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()