File size: 5,180 Bytes
b6a38d7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
local l_PreviousOpacities = {}
local l_PreviousInvisibleObjectHelpersEnabled = false
local l_PreviousVisibilities = {}
-- Show a selected object(s) without it's selection markers (outlines, contours, etc)
-- Override in game code for game-specific changes
function ShowWithoutSelectionMarkers(current_selection)
for _, obj in ipairs(current_selection) do
local parentObj = obj:GetParent()
while parentObj do
GameToolsShowObject(parentObj)
parentObj = parentObj:GetParent()
end
GameToolsShowObject(obj)
end
end
-- Restore (re-show) the selection markers of the selection object(s)
-- Override in game code for game-specific changes
function RestoreSelectionMarkers(current_selection)
if IsEditorActive() then
for _, obj in ipairs(current_selection) do
-- Show the editor handles of Light objects
if IsKindOf(obj, "Light") then
local opacity = l_PreviousOpacities[obj] or 100
obj:SetOpacity(opacity)
elseif IsKindOf(obj, "DecorStateFXObjectNoSound") then
local visible = l_PreviousVisibilities[obj]
if visible and visible > 0 then
obj:SetEnumFlags(const.efVisible)
end
end
end
end
end
function GetIsolatedObjectScreenshotSelection()
local is_editor = IsEditorActive()
return is_editor and editor.GetSel() or Selection
end
-- Takes a screenshot of only the selected object(s) on black background
function IsolatedObjectScreenshot(obj)
-- Check if we're in the editor (or in-game)
local is_editor = IsEditorActive()
local selection = obj and { obj } or GetIsolatedObjectScreenshotSelection()
if #(selection or "") == 0 then return end
CreateRealTimeThread(function()
local time_factor = GetTimeFactor()
-- Stop the game time to avoid objects moving out of place
SetTimeFactor(0)
local isolated_features_off = {
RenderBillboards = 0,
RenderTerrain = 0,
RenderSky = 0, -- Black sky and black horizon fog
AutoExposureMode = 0, -- AutoExposure will cause the object to turn white when on a black background
RenderClutter = 0,
RenderRain = 0
}
table.change(hr, "IsolatedObjectScreenshot", isolated_features_off)
PauseInfiniteLoopDetection("IsolatedObjectScreenshot")
Msg("PreIsolatedObjectScreenshot")
-- Hide all objects
SuspendPassEdits("IsolatedObjectScreenshot", true)
MapForEach("map", "attached", false, "CObject", nil, const.efVisible, function(obj)
if not editor.HiddenManually[obj] then
editor.HiddenManually[obj] = true
GameToolsHideObject(obj)
end
end)
local current_selection = table.copy(selection, not "deep")
ShowWithoutSelectionMarkers(current_selection)
if is_editor then
-- Hide InvisibleObjects' helpers
l_PreviousInvisibleObjectHelpersEnabled = InvisibleObjectHelpersEnabled
SetInvisibleObjectHelpersEnabled(false)
table.clear(l_PreviousOpacities)
table.clear(l_PreviousVisibilities)
for _, obj in ipairs(current_selection) do
-- Remove the editor selection boxes and mouse hover highlight
obj:ClearHierarchyGameFlags(const.gofEditorSelection | const.gofEditorHighlight)
-- Hide the editor handles of Light objects
if IsKindOf(obj, "Light") then
l_PreviousOpacities[obj] = obj:GetOpacity()
obj:SetOpacity(0)
elseif IsKindOf(obj, "DecorStateFXObjectNoSound") then
l_PreviousVisibilities[obj] = obj:GetEnumFlags(const.efVisible)
obj:ClearEnumFlags(const.efVisible)
end
end
end
-- Hide lightmodel stars
SetSceneParam(1, "StarsIntensity", 0)
SetSceneParam(1, "StarsBlueTint", 0)
SetSceneParam(1, "MilkyWayIntensity", 0)
SetSceneParam(1, "MilkyWayBlueTint", 0)
LockCamera("IsolatedObjectScreenshot")
-- Wait a few frames for the renderer to apply the changes
WaitNextFrame(5)
local prefix = "SSAA"
if #current_selection == 1 then
prefix = prefix .. "_" .. current_selection[1].class .. "_"
end
local filename = GenerateScreenshotFilename(prefix, "AppData/")
MovieWriteScreenshot(filename, 0, 64, false)
print(filename)
SetTimeFactor(time_factor)
UnlockCamera("IsolatedObjectScreenshot")
-- Restore renderer settings
table.restore(hr, "IsolatedObjectScreenshot")
-- Restore InvisibleObjects' helpers
SetInvisibleObjectHelpersEnabled(l_PreviousInvisibleObjectHelpersEnabled)
-- Restore lightmodel stars
SetSceneParam(1, "StarsIntensity", CurrentLightmodel[1].stars_intensity)
SetSceneParam(1, "StarsBlueTint", CurrentLightmodel[1].stars_blue_tint)
SetSceneParam(1, "MilkyWayIntensity", CurrentLightmodel[1].mw_intensity)
SetSceneParam(1, "MilkyWayBlueTint", CurrentLightmodel[1].mw_blue_tint)
RestoreSelectionMarkers(current_selection)
-- Show all hidden objects
local hidden = editor.HiddenManually
editor.HiddenManually = setmetatable({}, weak_keys_meta)
for obj in pairs(hidden) do
GameToolsShowObject(obj)
end
ResumePassEdits("IsolatedObjectScreenshot", true)
ResumeInfiniteLoopDetection("IsolatedObjectScreenshot")
if is_editor then
editor.ClearSel()
for _, obj in ipairs(current_selection) do
-- Reselect the previous selections
editor.AddObjToSel(obj)
end
end
Msg("PostIsolatedObjectScreenshot")
end)
end
|