Skip to content

Instantly share code, notes, and snippets.

@mvyasu
Last active March 11, 2025 19:39
Show Gist options
  • Select an option

  • Save mvyasu/a0280b210646238b321eb38db240f277 to your computer and use it in GitHub Desktop.

Select an option

Save mvyasu/a0280b210646238b321eb38db240f277 to your computer and use it in GitHub Desktop.
local MATERIAL_DEMO_SIZE = 4
local MATERIAL_DEMO_SPACING = 1
local MATERIAL_DEMO_SHAPE = Enum.PartType.Block
local MATERIAL_DEMO_COLOR = Color3.fromRGB(255, 255, 255)
local MATERIAL_DEMO_OFFSET = Vector3.yAxis * MATERIAL_DEMO_SIZE/2
local USE_COLUMNS = true
local MATERIALS_PER_ROW = 12
local createdMaterialDemos = {} do
local function tryToCreateMaterialDemo(obj: Instance): Instance?
if not obj:IsA("MaterialVariant") then
return nil
end
if createdMaterialDemos[obj.Name]==nil then
local newMaterialDemo = Instance.new("Part")
newMaterialDemo.Name = `MaterialDemo_{obj.Name}`
newMaterialDemo.Material = obj.BaseMaterial
newMaterialDemo.MaterialVariant = obj.Name
newMaterialDemo.Color = MATERIAL_DEMO_COLOR
newMaterialDemo.Shape = MATERIAL_DEMO_SHAPE
newMaterialDemo.Size = Vector3.one * MATERIAL_DEMO_SIZE
newMaterialDemo.BottomSurface = Enum.SurfaceType.Smooth
newMaterialDemo.TopSurface = Enum.SurfaceType.Smooth
newMaterialDemo.Anchored = true
createdMaterialDemos[obj.Name] = newMaterialDemo
return obj
end
return nil
end
for _,selectedObject in game.Selection:Get() do
tryToCreateMaterialDemo(selectedObject)
for _,descendant in selectedObject:GetDescendants() do
tryToCreateMaterialDemo(descendant)
end
end
end
local newMaterialDemoFolder = Instance.new("Folder")
newMaterialDemoFolder.Name = "MaterialDemos"
newMaterialDemoFolder.Parent = workspace
local demoOffset = Vector2.zero
for materialName,materialDemo in createdMaterialDemos do
local currentOffset = Vector3.new(demoOffset.X, 0, demoOffset.Y)
materialDemo.CFrame =
CFrame.new(MATERIAL_DEMO_OFFSET) *
CFrame.new(currentOffset * (MATERIAL_DEMO_SIZE + MATERIAL_DEMO_SPACING))
materialDemo.Parent = newMaterialDemoFolder
demoOffset += Vector2.xAxis
if not USE_COLUMNS then
continue
end
if demoOffset.X > MATERIALS_PER_ROW then
demoOffset = Vector2.new(0, demoOffset.Y + 1)
end
end
if demoOffset==Vector2.zero then
newMaterialDemoFolder:Destroy()
warn("You have no selected MaterialVariants!")
else
game:GetService("ChangeHistoryService"):SetWaypoint("Created Material Demos")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment