singe/testScripts/scene32.singe

138 lines
4.5 KiB
Text

-- Bloom and views: the Fox walks a plain lit by a low sun and a bright lamp; a monitor on a stand
-- shows a security camera's view of it from behind (a view rendered to a texture), a rear-view
-- mirror shows the camera on the Fox looking back, and bloom makes the lamp and the sun glow.
-- A name tag (text on a billboard) and a crate icon (a sprite that turns about its own axis)
-- float over the Fox, and a fixed sign stands by the lamp.
local font = fontLoad("Singe/FreeSansBold.ttf", 28)
local frames = 0
fontSelect(font)
sceneEnable(true)
sceneSetSky("testScripts/sky.png")
sceneSetSkyIntensity(0.8)
sceneSetBloom(1.0, 0.35)
local ground = materialNew()
materialSetColor(ground, 110, 120, 95)
materialSetRoughness(ground, 0.9)
local plain = nodeNew()
nodeSetMesh(plain, meshPlane(60, 60), ground)
local foxModel = modelLoad("testScripts/Models/Fox.glb")
local fox = modelInstance(foxModel)
nodeSetScale(fox, 0.02)
nodeSetPosition(fox, 0, 0, 0)
animationPlay(fox, "Walk", true)
-- Over the Fox: a name in the selected font facing the camera squarely, and a crate icon that
-- turns about its own up axis only.
local tag = nodeNew()
nodeSetParent(tag, fox)
nodeSetPosition(tag, 0, 110, 0)
nodeSetScale(tag, 50)
nodeSetText(tag, "FOX", 0.6)
nodeSetBillboard(tag, BILLBOARD_ALL)
nodeSetShadow(tag, false)
local icon = nodeNew()
nodeSetParent(icon, fox)
nodeSetPosition(icon, 0, 150, 0)
nodeSetScale(icon, 50)
nodeSetSprite(icon, spriteLoad("testScripts/crate.png"), 0.5)
nodeSetBillboard(icon, BILLBOARD_Y)
-- A sign that stays put, lit by the scene.
local sign = nodeNew()
nodeSetPosition(sign, 4.2, 1.2, -1.2)
nodeSetRotation(sign, 0, -30, 0)
nodeSetText(sign, "LAMP", 0.5)
-- A bright lamp on a post, for the glow.
local dark = materialNew()
materialSetColor(dark, 40, 40, 45)
local glow = materialNew()
materialSetColor(glow, 255, 240, 200)
materialSetEmissive(glow, 255, 240, 200)
materialSetUnlit(glow, true)
local post = nodeNew()
nodeSetMesh(post, meshCylinder(0.08, 3, 10), dark)
nodeSetPosition(post, 3, 1.5, -2)
local bulbNode = nodeNew()
nodeSetMesh(bulbNode, meshSphere(0.18, 16), glow)
nodeSetPosition(bulbNode, 3, 3.1, -2)
nodeSetShadow(bulbNode, false)
local lamp = lightNew(LIGHT_POINT)
nodeSetPosition(lamp, 3, 3.1, -2)
lightSetColor(lamp, 255, 230, 190)
lightSetIntensity(lamp, 12)
lightSetRange(lamp, 14)
lightSetShadow(lamp, true)
local sun = lightNew(LIGHT_DIRECTIONAL)
nodeSetPosition(sun, -8, 3, 6)
nodeLookAt(sun, 0, 0, 0)
lightSetIntensity(sun, 1.5)
lightSetColor(sun, 255, 210, 170)
lightSetShadow(sun, true)
-- The security camera behind the Fox, and the monitor showing it.
local securityCamera = nodeNew()
nodeSetPosition(securityCamera, 0, 2.2, -5)
nodeLookAt(securityCamera, 0, 0.6, 0)
local security = viewNew(512, 384)
viewSetCamera(security, securityCamera)
local screen = materialNew()
materialSetView(screen, security)
materialSetUnlit(screen, true)
local bezel = materialNew()
materialSetColor(bezel, 30, 30, 35)
local stand = nodeNew()
nodeSetMesh(stand, meshBox(0.1, 1.4, 0.1), dark)
nodeSetPosition(stand, -3, 0.7, 1)
local frameBox = nodeNew()
nodeSetMesh(frameBox, meshBox(2.1, 1.6, 0.1), bezel)
nodeSetPosition(frameBox, -3, 2.1, 1)
local monitor = nodeNew()
nodeSetMesh(monitor, meshPlane(2.0, 1.5), screen)
nodeSetPosition(monitor, -3, 2.1, 1.06)
nodeSetRotation(monitor, 90, 0, 0)
-- The rear-view mirror: a camera on the Fox looking back, shown on a small panel.
local rearCamera = nodeNew()
nodeSetParent(rearCamera, fox)
nodeSetPosition(rearCamera, 0, 60, -20)
nodeSetRotation(rearCamera, 0, 180, 0)
local rear = viewNew(384, 256)
viewSetCamera(rear, rearCamera)
local mirror = materialNew()
materialSetView(mirror, rear)
materialSetUnlit(mirror, true)
local panel = nodeNew()
nodeSetMesh(panel, meshPlane(1.5, 1.0), mirror)
nodeSetPosition(panel, 3, 2.0, 1.5)
nodeSetRotation(panel, 90, 0, 0)
local camera = nodeNew()
cameraSet(camera)
cameraSetPerspective(50, 0.1, 100)
local stops = {
{ 0, 2.2, 7, 0, 1.3, 0 }, -- The monitor, the panel and the Fox
{ -2, 1.8, 4, -3, 2.0, 1 }, -- Close on the monitor
{ 4, 2, 4, 3, 2.2, -1 }, -- The lamp glowing beside the panel
{ 0, 1.2, 5, 0, 0.8, 0 }, -- Low on the Fox
}
function onOverlayUpdate()
local stop = stops[math.min(#stops, math.floor(frames / 45) + 1)]
frames = frames + 1
nodeSetPosition(camera, stop[1], stop[2], stop[3])
nodeLookAt(camera, stop[4], stop[5], stop[6])
overlayClear()
fontPrint(20, 20, "Bloom and views, frame " .. frames)
if frames == 40 or frames == 85 or frames == 130 or frames == 175 then
singeScreenshot()
end
if frames == 180 then
singeQuit()
end
end