SetMaterial

This function sets a surface material.

Syntax

Parameters

Returns

This function will increment the reference count of the new material and decrement the reference count of the old material (if they exist).

Example

--Create a window
window = Window:Create()
context = Context:Create(window)
world = World:Create()
local camera = Camera:Create()
camera:SetRotation(35,0,0)
camera:Move(0,0,-3)
local light = DirectionalLight:Create()
light:SetRotation(35,35,0)

--Create model
model = Model:Box()

--Create a material
local material = Material:Create()
local surface = model:GetSurface(0)
surface:SetMaterial(material)

while true do
if window:Closed() or window:KeyHit(Key.Escape) then return false end

model:Turn(0,Time:GetSpeed(),0)

--Get the model surface
local surface = model:GetSurface(0)

--Get the surface material
local material = surface:GetMaterial()

--Modify the material color
local color = material:GetColor()
color.r = Math:Mod(color.r+Time:GetSpeed()*0.01,1)
color.g = Math:Mod(color.g+Time:GetSpeed()*0.012,1)
color.b = Math:Mod(color.b+Time:GetSpeed()*0.015,1)
material:SetColor(color)

Time:Update()
world:Update()
world:Render()
context:Sync()
end