More enhancements to cameras.lua

Tidy up `createTempCam()`
Add `loadLocation()` and `clearLoadLocation()` functions
Add `renderTime` variable for `stopTempCam()`

Add wrapper functions for each one (for my own sanity):
`createCam()` = `createTempCam()`
`startCam()` = `startTempCam()`
`stopTempCam()` = `stopTempCam()`
This commit is contained in:
Jim Shield
2025-09-06 12:22:27 +01:00
parent 188fb81bdc
commit 42630cc3c4

View File

@@ -21,32 +21,28 @@ function createTempCam(ent, coords)
local camID = nil local camID = nil
if Config.Crafting?.craftCam or Config.System.enableCam then if Config.Crafting?.craftCam or Config.System.enableCam then
-- if not ent or coords are provided, make a basic camera to control later
if not ent and not coords then if not ent and not coords then
camID = CreateCam("DEFAULT_SCRIPTED_CAMERA", true) camID = CreateCam("DEFAULT_SCRIPTED_CAMERA", true)
camCache[#camCache+1] = camID camCache[#camCache+1] = camID
return camID return camID
end end
debugPrint("^6Bridge^7: ^2Custom Camera Created")
local camCoords = nil -- if received a vector3 or vector4 use those coords for origin point, otherwrise get offset from entity
--local pointCoords = nil local camCoords = type(ent) ~= "number" and ent or GetOffsetFromEntityInWorldCoords(ent, 1.0, -0.3, 0.8)
if type(ent) ~= "number" then -- if received a vector3 or vector4 use those coords for origin point
camCoords = ent
else
camCoords = GetOffsetFromEntityInWorldCoords(ent, 1.0, -0.3, 0.8)
end
-- Create the camera -- Create the camera
camID = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", camCoords.x, camCoords.y, camCoords.z + 0.5, 1.0, 0.0, 0.0, 60.00, false, 0) camID = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", camCoords.x, camCoords.y, camCoords.z + 0.5, 1.0, 0.0, 0.0, 60.00, false, 0)
camCache[#camCache+1] = camID camCache[#camCache+1] = camID
debugPrint("^6Bridge^7: ^2Custom Camera Created")
--if type(coords) == "number" then --if type(coords) == "number" then
-- SetCamCoord(camID, GetCamCoord(camID) + vec3(0, 0, 1.0)) -- SetCamCoord(camID, GetCamCoord(camID) + vec3(0, 0, 1.0))
--end --end
if coords then
camLookAt(camID, coords) camLookAt(camID, coords)
end
end end
return camID return camID
@@ -69,9 +65,10 @@ local cachePrevCam = nil
-- ```lua -- ```lua
-- startTempCam(camID, 1000, true, { postFx = "HeistCelebEnd" }) -- startTempCam(camID, 1000, true, { postFx = "HeistCelebEnd" })
-- ``` -- ```
function startTempCam(cam, renderTime, loadScene, filter) function startTempCam(cam, renderTime, loadScene, filter, switchCam)
if cam and DoesCamExist(cam) then if cam and DoesCamExist(cam) then
if cachePrevCam then -- if moving from a cached previous cam, or you've sent a camre id for it to switch from, interpolate to it
if switchCam or cachePrevCam then
SetCamActiveWithInterp(cam, cachePrevCam, renderTime or 1000, 0, 0) SetCamActiveWithInterp(cam, cachePrevCam, renderTime or 1000, 0, 0)
else else
SetCamActive(cam, true) SetCamActive(cam, true)
@@ -101,21 +98,7 @@ function startTempCam(cam, renderTime, loadScene, filter)
end end
if loadScene then if loadScene then
local pos = GetCamCoord(cam) loadLocation(cam, nil, 100.0)
local radius = 100.0
SetFocusPosAndVel(pos.x, pos.y, pos.z, 0.0, 0.0, 0.0)
RequestCollisionAtCoord(pos.x, pos.y, pos.z)
NewLoadSceneStart(pos.x, pos.y, pos.z, 0.0, 0.0, 0.0, radius, 0)
local t0 = GetGameTimer()
while not IsNewLoadSceneLoaded() and (GetGameTimer() - t0) < 2000 do
RequestCollisionAtCoord(pos.x, pos.y, pos.z)
Wait(0)
end
NewLoadSceneStop()
end end
RenderScriptCams(true, true, renderTime or 1000, true, true) RenderScriptCams(true, true, renderTime or 1000, true, true)
@@ -124,7 +107,7 @@ end
-- Follow cam or coords -- Follow cam or coords
function camLookAt(cam, entCoords) function camLookAt(cam, entCoords)
if cam and entCoords then if cam and DoesCamExist(cam) and entCoords then
if type(entCoords) ~= "number" then if type(entCoords) ~= "number" then
PointCamAtCoord(cam, entCoords.xyz) PointCamAtCoord(cam, entCoords.xyz)
else else
@@ -133,6 +116,28 @@ function camLookAt(cam, entCoords)
end end
end end
function loadLocation(cam, pos, radius)
local pos = pos or GetCamCoord(cam)
SetFocusPosAndVel(pos.x, pos.y, pos.z, 0.0, 0.0, 0.0)
RequestCollisionAtCoord(pos.x, pos.y, pos.z)
NewLoadSceneStart(pos.x, pos.y, pos.z, 0.0, 0.0, 0.0, radius or 100.0, 0)
local t0 = GetGameTimer()
while not IsNewLoadSceneLoaded() and (GetGameTimer() - t0) < 2000 do
RequestCollisionAtCoord(pos.x, pos.y, pos.z)
Wait(0)
end
NewLoadSceneStop()
end
function clearLoadLocation()
ClearFocus()
NewLoadSceneStop()
end
--- Deactivates the temporary camera and stops rendering. --- Deactivates the temporary camera and stops rendering.
-- --
-- This function waits for one second, then stops rendering script cameras and destroys all cameras. -- This function waits for one second, then stops rendering script cameras and destroys all cameras.
@@ -144,7 +149,7 @@ end
-- ```lua -- ```lua
-- stopTempCam() -- stopTempCam()
-- ``` -- ```
function stopTempCam() function stopTempCam(renderTime)
CreateThread(function() CreateThread(function()
Wait(1000) Wait(1000)
@@ -160,13 +165,18 @@ function stopTempCam()
cacheCameraEffect.timecycle = nil cacheCameraEffect.timecycle = nil
end end
RenderScriptCams(false, true, 500, true, true) RenderScriptCams(false, true, renderTime or 500, true, true)
clearLoadLocation()
Wait(renderTime or 0)
for i = 1, #camCache do for i = 1, #camCache do
DestroyCam(camCache[i], true) DestroyCam(camCache[i], true)
end end
camCache = {} camCache = {}
--DestroyAllCams()
ClearFocus()
NewLoadSceneStop()
end) end)
end end
function createCam(...) createTempCam(...) end
function startCam(...) startTempCam(...) end
function stopTempCam(...) startCam(...) end