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

VertexColor

DataModelMesh

Vector3

Changes the hue of the mesh’s texture.

Note this property is only functional when a texture has been applied to the mesh. For this reason it only works with the SpecialMesh object as it includes the SpecialMesh/TextureId property.

How to use VertexColor

See below for a visual example of the impact of VertexColor on a mesh’s texture.

enter image description here

Note this property uses the Vector3 rather than the Color3 data type. Therefore developers will generally need to convert the Color3 rgb components to the `Vector3 xyz components. See below for a brief example.

local yellow = BrickColor.new("Bright yellow")
local yColor = yellow.Color
local yVector = Vector3.new(yColor.r,yColor.g,yColor.b)
workspace.Baseplate.Mesh.VertexColor = yVector

Alternative to VertexColor

Although VertexColor can be used to make changes to the appearance of a Mesh’s texture much more flexibility is offered by uploading a new texture for the mesh. For more information on textures, see the page for MeshParts.


Code Samples


Mesh VertexColor

In this code sample a BasePart is instanced with a SpecialMesh. The DataModelMesh/VertexColor property of the SpecialMesh is 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)
mesh.VertexColor = Vector3.new(1, 1, 1)

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