Ashlar checks / tooling (push) Successful in 5s
- Shoulder view, auto shoulder switch, standing preview, deferred preview rotation, move 360, smooth view change and [Game] smooth movement are on by default. - Collision ease-out: the camera still snaps in on collision but eases back out (0.15 s half-life, 60 u/s minimum speed). - Aim mode: with a ranged weapon or a spell readied in third person the view stays over the shoulder, moves closer and narrows the FOV. Camera interface v2 adds getAimWeight and enable/disable functions. - Pure math in camera/ease.lua with unit tests; SCENARIO=camera with PASS/FAIL checks; docs in docs/ashlar/CAMERA.md. - ashlar-run.sh deletes stored Lua settings before each run so changed defaults are tested. Closes #29 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
111 lines
4.1 KiB
Lua
111 lines
4.1 KiB
Lua
-- Ashlar headless camera scenario (CC0). Switches to third person and runs timed phases:
|
|
-- shoulder third person, standing still: the view should be over the shoulder
|
|
-- wall a wall appears behind the camera: the distance must drop at once
|
|
-- clear the wall is removed: the distance must ease back out over several frames, not jump
|
|
-- aim a bow is readied: aim weight rises to 1, distance and field of view tighten, shoulder view stays
|
|
-- unaim the bow is put away: aim weight falls to 0 and the field of view returns to the base value
|
|
-- done third person with nothing readied, for the screenshot
|
|
-- Lines start with ASHLAR_CAMERA; docker/ashlar-run.sh summarizes them.
|
|
local camera = require('openmw.camera')
|
|
local core = require('openmw.core')
|
|
local self = require('openmw.self')
|
|
local types = require('openmw.types')
|
|
local I = require('openmw.interfaces')
|
|
|
|
local Actor = types.Actor
|
|
local MODE = camera.MODE
|
|
|
|
local PHASES = {
|
|
{ name = 'settle', at = 0 },
|
|
{ name = 'shoulder', at = 3 },
|
|
{ name = 'wall', at = 6 },
|
|
{ name = 'clear', at = 9 },
|
|
{ name = 'aim', at = 13 },
|
|
{ name = 'unaim', at = 19 },
|
|
{ name = 'done', at = 23 },
|
|
}
|
|
|
|
local MODE_NAMES = {}
|
|
for k, v in pairs(MODE) do MODE_NAMES[v] = k end
|
|
|
|
local t = 0
|
|
local phase
|
|
local bow
|
|
local logTimer = 0
|
|
|
|
local function log(fmt, ...)
|
|
print('ASHLAR_CAMERA ' .. string.format(fmt, ...))
|
|
end
|
|
|
|
local function sample(tag)
|
|
local offset = camera.getFocalPreferredOffset()
|
|
log('%s %s t=%.3f mode=%s dist=%.1f target=%.1f offsetX=%.1f offsetY=%.1f aim=%.3f fov=%.4f base=%.4f',
|
|
tag, phase.name, t, MODE_NAMES[camera.getMode()] or '?', camera.getThirdPersonDistance(),
|
|
I.Camera.getTargetThirdPersonDistance(), offset.x, offset.y, I.Camera.getAimWeight(),
|
|
camera.getFieldOfView(), camera.getBaseFieldOfView())
|
|
end
|
|
|
|
local function enterPhase(p)
|
|
phase = p
|
|
log('phase %s', p.name)
|
|
if p.name == 'settle' then
|
|
camera.setMode(MODE.ThirdPerson)
|
|
log('interface version=%d aimModeEnabled=%s', I.Camera.version, tostring(I.Camera.isAimModeEnabled()))
|
|
elseif p.name == 'wall' then
|
|
core.sendGlobalEvent('AshlarCameraWall', { player = self.object, yaw = camera.getYaw(), distance = 100,
|
|
on = true })
|
|
elseif p.name == 'clear' then
|
|
core.sendGlobalEvent('AshlarCameraWall', { player = self.object, yaw = camera.getYaw(), on = false })
|
|
elseif p.name == 'aim' then
|
|
core.sendGlobalEvent('AshlarCameraBow', { player = self.object })
|
|
elseif p.name == 'unaim' then
|
|
Actor.setStance(self, Actor.STANCE.Nothing)
|
|
end
|
|
end
|
|
|
|
return {
|
|
eventHandlers = {
|
|
AshlarCameraBowReady = function(e)
|
|
bow = e.bow
|
|
local eq = Actor.getEquipment(self)
|
|
eq[Actor.EQUIPMENT_SLOT.CarriedRight] = bow
|
|
Actor.setEquipment(self, eq)
|
|
Actor.setStance(self, Actor.STANCE.Weapon)
|
|
log('bow equipped')
|
|
end,
|
|
},
|
|
engineHandlers = {
|
|
onFrame = function(dt)
|
|
if dt <= 0 or (phase and phase.name == 'done' and t > 25) then
|
|
return
|
|
end
|
|
if not phase then
|
|
enterPhase(PHASES[1])
|
|
end
|
|
t = t + dt
|
|
local nextPhase = phase
|
|
for _, p in ipairs(PHASES) do
|
|
if t >= p.at then
|
|
nextPhase = p
|
|
end
|
|
end
|
|
if nextPhase ~= phase then
|
|
enterPhase(nextPhase)
|
|
end
|
|
if phase.name == 'aim' and bow and Actor.getStance(self) ~= Actor.STANCE.Weapon then
|
|
Actor.setStance(self, Actor.STANCE.Weapon)
|
|
end
|
|
-- Every frame while the distance or the aim framing changes; twice a second otherwise.
|
|
if phase.name == 'wall' or phase.name == 'clear' or phase.name == 'aim' or phase.name == 'unaim' then
|
|
sample('frame')
|
|
else
|
|
logTimer = logTimer + dt
|
|
if logTimer >= 0.5 then
|
|
logTimer = 0
|
|
sample('sample')
|
|
end
|
|
end
|
|
end,
|
|
},
|
|
}
|