singe/testScripts/scene2.singe
2026-09-05 19:52:04 -05:00

82 lines
2.1 KiB
Text

-- Stage 2 test: a lit spinning cube, a textured plane and a glass sphere over the disc, with
-- overlay text pinned to the cube through sceneProject.
local font = fontLoad("Singe/FreeSansBold.ttf", 28)
local boxArt = spriteLoad("testScripts/Box.png")
local frames = 0
fontSelect(font)
discPlay()
sceneEnable(true)
sceneSetBackground(0, 0, 0, 0)
sceneSetAmbient(40, 40, 60)
local red = materialNew()
materialSetColor(red, 220, 40, 40)
materialSetRoughness(red, 0.3)
materialSetMetallic(red, 0.2)
local tiled = materialNew()
materialSetTexture(tiled, boxArt)
local glass = materialNew()
materialSetColor(glass, 80, 160, 255, 110)
materialSetBlend(glass, true)
materialSetRoughness(glass, 0.1)
local gold = materialNew()
materialSetColor(gold, 255, 200, 60)
materialSetMetallic(gold, 1.0)
materialSetRoughness(gold, 0.35)
local cube = nodeNew()
nodeSetMesh(cube, meshBox(1.2, 1.2, 1.2), red)
nodeSetPosition(cube, -1.6, 0.3, 0)
local floor = nodeNew()
nodeSetMesh(floor, meshPlane(6, 4), tiled)
nodeSetPosition(floor, 0, -1, -1)
local ball = nodeNew()
nodeSetMesh(ball, meshSphere(0.7, 32), glass)
nodeSetPosition(ball, 1.4, 0.2, 0.5)
local ring = nodeNew()
nodeSetMesh(ring, meshTorus(0.8, 0.2, 40), gold)
nodeSetPosition(ring, 1.4, 0.2, 0.5)
local cone = nodeNew()
nodeSetMesh(cone, meshCone(0.4, 0.9, 24), gold)
nodeSetPosition(cone, 0, -0.55, 1.2)
local sun = lightNew(LIGHT_DIRECTIONAL)
nodeSetPosition(sun, 2, 4, 3)
nodeLookAt(sun, 0, 0, 0)
lightSetIntensity(sun, 1.2)
local lamp = lightNew(LIGHT_POINT)
nodeSetPosition(lamp, -2, 1.5, 2)
lightSetColor(lamp, 120, 200, 255)
lightSetIntensity(lamp, 6)
lightSetRange(lamp, 8)
local camera = nodeNew()
nodeSetPosition(camera, 0, 1.6, 5.5)
nodeLookAt(camera, 0, 0, 0)
cameraSet(camera)
cameraSetPerspective(55, 0.1, 100)
function onOverlayUpdate()
frames = frames + 1
nodeRotate(cube, 0.8, 1.7, 0)
nodeRotate(ring, 0, 2.0, 1.0)
overlayClear()
local x, y, depth, inFront = sceneProject(nodeGetWorldPosition(cube))
fontPrint(x - 40, y - 70, "cube")
fontPrint(20, 20, "Stage 2, frame " .. frames)
if frames == 90 then
singeScreenshot()
end
if frames == 120 then
singeQuit()
end
end