Not a member of GistPad yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------------------------------------------------
- -- RE2 LIGHTPROBES CONTROL TEST
- -- TEST INTENSITY
- --
- -- 8 LIGHTPROBES
- -- CHECKBOX INDIVIDUELLE
- -- OPTION TOUT
- --
- -- READ + WRITE RUNTIME
- -- Aucun JSON
- -- Aucun changement permanent
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- -- LOG
- --------------------------------------------------------------------------------
- local function test_log(message)
- log.info(
- "[LIGHTPROBES-CONTROL-TEST] " ..
- tostring(message)
- )
- end
- --------------------------------------------------------------------------------
- -- LOAD LIGHTPROBES DATABASE
- --------------------------------------------------------------------------------
- local function load_lightprobes_database()
- local path =
- "Light/LightProbs/LightProbes.lua"
- test_log(
- "LOADING DATABASE: " ..
- path
- )
- local source =
- fs.read(
- path
- )
- if not source
- then
- test_log(
- "DATABASE FILE NOT FOUND"
- )
- return false
- end
- test_log(
- "DATABASE FILE READ OK"
- )
- local chunk,
- error_message =
- load(
- source,
- "@LightProbs/LightProbes.lua"
- )
- if not chunk
- then
- test_log(
- "DATABASE LUA COMPILE FAILED"
- )
- test_log(
- tostring(
- error_message
- )
- )
- return false
- end
- local ok,
- result =
- pcall(
- chunk
- )
- if not ok
- then
- test_log(
- "DATABASE LUA EXECUTION FAILED"
- )
- test_log(
- tostring(
- result
- )
- )
- return false
- end
- if type(result) ~= "table"
- then
- test_log(
- "DATABASE RETURN IS NOT A TABLE"
- )
- test_log(
- "TYPE = " ..
- tostring(
- type(result)
- )
- )
- return false
- end
- LIGHTPROBES_DATABASE =
- result
- test_log(
- "DATABASE LOADED SUCCESSFULLY"
- )
- test_log(
- "DATABASE ENTRIES = " ..
- tostring(
- #LIGHTPROBES_DATABASE
- )
- )
- return true
- end
- --------------------------------------------------------------------------------
- -- ACTIVE LIGHTPROBES ZONE
- --------------------------------------------------------------------------------
- local LIGHTPROBES_LIST =
- {
- }
- local LIGHTPROBES_ZONES =
- {
- }
- local selected_lightprobes_zone =
- nil
- local function build_lightprobes_zones()
- LIGHTPROBES_ZONES =
- {
- }
- if type(LIGHTPROBES_DATABASE) ~= "table"
- then
- return false
- end
- for zone_name,
- zone_data
- in pairs(
- LIGHTPROBES_DATABASE
- )
- do
- if type(zone_data) == "table"
- then
- LIGHTPROBES_ZONES[
- #LIGHTPROBES_ZONES + 1
- ] =
- zone_name
- end
- end
- table.sort(
- LIGHTPROBES_ZONES
- )
- if #LIGHTPROBES_ZONES > 0
- then
- selected_lightprobes_zone =
- LIGHTPROBES_ZONES[1]
- end
- return true
- end
- local function build_lightprobes_list_for_zone(
- zone_name
- )
- LIGHTPROBES_LIST =
- {
- }
- if type(LIGHTPROBES_DATABASE) ~= "table"
- then
- return false
- end
- local zone_data =
- LIGHTPROBES_DATABASE[
- zone_name
- ]
- if type(zone_data) ~= "table"
- then
- return false
- end
- for i = 1,
- #zone_data
- do
- local source =
- zone_data[i]
- if source
- and source.id
- and source.guid
- then
- LIGHTPROBES_LIST[
- #LIGHTPROBES_LIST + 1
- ] =
- {
- zone = zone_name,
- name = source.id,
- guid = source.guid,
- selected = true
- }
- end
- end
- return true
- end
- --------------------------------------------------------------------------------
- -- RUNTIME CACHE
- --------------------------------------------------------------------------------
- local resolved_lightprobes =
- {
- }
- local original_intensity =
- {
- }
- --------------------------------------------------------------------------------
- -- CONTROL VALUES
- --------------------------------------------------------------------------------
- local control_intensity = 0.005
- local control_red = 1.0
- local control_green = 1.0
- local control_blue = 1.0
- local control_saturate = 0.0
- local control_ambient_color_intensity = 1.0
- --------------------------------------------------------------------------------
- -- GET CURRENT SCENE
- --------------------------------------------------------------------------------
- local function get_current_scene()
- local scene_manager =
- sdk.get_native_singleton(
- "via.SceneManager"
- )
- if not scene_manager
- then
- test_log(
- "SCENE MANAGER NOT FOUND"
- )
- return nil
- end
- local scene =
- nil
- local ok_scene,
- scene_result =
- pcall(
- function()
- return sdk.call_native_func(
- scene_manager,
- sdk.find_type_definition(
- "via.SceneManager"
- ),
- "get_CurrentScene"
- )
- end
- )
- if ok_scene
- and scene_result
- then
- scene =
- scene_result
- end
- if not scene
- then
- local ok_call,
- result_call =
- pcall(
- function()
- return scene_manager:call(
- "get_CurrentScene"
- )
- end
- )
- if ok_call
- and result_call
- then
- scene =
- result_call
- end
- end
- if not scene
- then
- test_log(
- "CURRENT SCENE NOT FOUND"
- )
- return nil
- end
- return scene
- end
- --------------------------------------------------------------------------------
- -- RESOLVE ALL LIGHTPROBES
- --------------------------------------------------------------------------------
- local function resolve_all_lightprobes()
- resolved_lightprobes =
- {
- }
- local scene =
- get_current_scene()
- if not scene
- then
- test_log(
- "CURRENT SCENE NOT FOUND"
- )
- return false
- end
- test_log(
- "CURRENT SCENE FOUND"
- )
- local ok_components,
- transforms =
- pcall(
- function()
- return scene:call(
- "findComponents(System.Type)",
- sdk.typeof(
- "via.Transform"
- )
- )
- end
- )
- if not ok_components
- or not transforms
- then
- test_log(
- "TRANSFORM ENUMERATION FAILED"
- )
- return false
- end
- local ok_count,
- count =
- pcall(
- function()
- return transforms:get_Count()
- end
- )
- if not ok_count
- or not count
- then
- test_log(
- "TRANSFORM COUNT FAILED"
- )
- return false
- end
- test_log(
- "TRANSFORMS = " ..
- tostring(
- count
- )
- )
- local guid_to_index =
- {
- }
- for i = 1,
- #LIGHTPROBES_LIST
- do
- local entry =
- LIGHTPROBES_LIST[i]
- if entry
- and entry.guid
- then
- guid_to_index[
- tostring(
- entry.guid
- )
- ] =
- i
- end
- end
- local guid_count =
- 0
- for _,
- _ in pairs(
- guid_to_index
- )
- do
- guid_count =
- guid_count + 1
- end
- test_log(
- "ACTIVE ZONE GUIDS = " ..
- tostring(
- guid_count
- )
- )
- for i = 0,
- count - 1
- do
- local ok_transform,
- transform =
- pcall(
- function()
- return transforms:get_Item(
- i
- )
- end
- )
- if ok_transform
- and transform
- then
- local ok_game_object,
- game_object =
- pcall(
- function()
- return transform:call(
- "get_GameObject"
- )
- end
- )
- if ok_game_object
- and game_object
- then
- local ok_name,
- object_name =
- pcall(
- function()
- return game_object:call(
- "get_Name"
- )
- end
- )
- if ok_name
- and object_name
- then
- object_name =
- tostring(
- object_name
- )
- end
- local ok_guid,
- object_guid =
- pcall(
- function()
- return game_object:call(
- "get_GUID"
- )
- end
- )
- if ok_guid
- and object_guid
- then
- object_guid =
- tostring(
- object_guid
- )
- local database_index =
- guid_to_index[
- object_guid
- ]
- if database_index
- then
- test_log(
- "GUID MATCH = " ..
- object_guid ..
- " | NAME = " ..
- tostring(
- object_name
- )
- )
- local ok_components_go,
- components =
- pcall(
- function()
- return game_object:call(
- "get_Components"
- )
- end
- )
- if ok_components_go
- and components
- then
- local ok_component_count,
- component_count =
- pcall(
- function()
- return components:get_Count()
- end
- )
- if ok_component_count
- and component_count
- then
- for c = 0,
- component_count - 1
- do
- local ok_component,
- component =
- pcall(
- function()
- return components:get_Item(
- c
- )
- end
- )
- if ok_component
- and component
- then
- local ok_type,
- type_definition =
- pcall(
- function()
- return component:get_type_definition()
- end
- )
- if ok_type
- and type_definition
- then
- local ok_full_name,
- full_name =
- pcall(
- function()
- return type_definition:get_full_name()
- end
- )
- if ok_full_name
- and full_name
- and tostring(
- full_name
- ) ==
- "via.render.LightProbes"
- then
- resolved_lightprobes[
- database_index
- ] =
- component
- test_log(
- "LIGHTPROBE RESOLVED = " ..
- tostring(
- object_name
- ) ..
- " | GUID = " ..
- object_guid
- )
- break
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- local resolved_count =
- 0
- for i = 1,
- #LIGHTPROBES_LIST
- do
- if resolved_lightprobes[i]
- then
- resolved_count =
- resolved_count + 1
- end
- end
- test_log(
- "RESOLVED = " ..
- tostring(
- resolved_count
- ) ..
- " / " ..
- tostring(
- #LIGHTPROBES_LIST
- )
- )
- return true
- end
- --------------------------------------------------------------------------------
- -- GET TARGET
- --------------------------------------------------------------------------------
- local function get_target(index)
- if resolved_lightprobes[index]
- then
- return resolved_lightprobes[index]
- end
- resolve_all_lightprobes()
- return resolved_lightprobes[index]
- end
- --------------------------------------------------------------------------------
- -- COLOR CACHE
- --------------------------------------------------------------------------------
- local original_color =
- {
- }
- --------------------------------------------------------------------------------
- -- READ COLOR
- --------------------------------------------------------------------------------
- local function read_selected_color()
- test_log(
- "================================================"
- )
- test_log(
- "READ COLOR"
- )
- for i = 1,
- #LIGHTPROBES_LIST
- do
- local entry =
- LIGHTPROBES_LIST[i]
- if entry.selected
- then
- local lightprobes =
- get_target(
- i
- )
- if lightprobes
- then
- local ok,
- color =
- pcall(
- function()
- return lightprobes:get_AmbientColor()
- end
- )
- if ok
- and color
- then
- local ok_x,
- r =
- pcall(
- function()
- return color.x
- end
- )
- local ok_y,
- g =
- pcall(
- function()
- return color.y
- end
- )
- local ok_z,
- b =
- pcall(
- function()
- return color.z
- end
- )
- if ok_x
- and ok_y
- and ok_z
- then
- original_color[i] =
- {
- x = r,
- y = g,
- z = b
- }
- test_log(
- entry.name ..
- " | COLOR = " ..
- tostring(r) ..
- " / " ..
- tostring(g) ..
- " / " ..
- tostring(b)
- )
- else
- test_log(
- entry.name ..
- " | COLOR COMPONENT READ FAILED"
- )
- end
- else
- test_log(
- entry.name ..
- " | get_AmbientColor FAILED"
- )
- end
- else
- test_log(
- entry.name ..
- " | TARGET NOT FOUND"
- )
- end
- end
- end
- test_log(
- "================================================"
- )
- end
- --------------------------------------------------------------------------------
- -- RESTORE COLOR
- --------------------------------------------------------------------------------
- local function restore_selected_color()
- test_log(
- "================================================"
- )
- test_log(
- "RESTORE COLOR"
- )
- for i = 1,
- #LIGHTPROBES_LIST
- do
- local entry =
- LIGHTPROBES_LIST[i]
- if entry.selected
- then
- local lightprobes =
- get_target(
- i
- )
- local original =
- original_color[i]
- if lightprobes
- and original
- then
- local ok_color,
- color =
- pcall(
- function()
- return lightprobes:get_AmbientColor()
- end
- )
- if ok_color
- and color
- then
- color.x =
- original.x
- color.y =
- original.y
- color.z =
- original.z
- local ok_set =
- pcall(
- function()
- lightprobes:set_AmbientColor(
- color
- )
- end
- )
- if ok_set
- then
- test_log(
- entry.name ..
- " | COLOR RESTORED = " ..
- tostring(original.x) ..
- " / " ..
- tostring(original.y) ..
- " / " ..
- tostring(original.z)
- )
- else
- test_log(
- entry.name ..
- " | COLOR RESTORE FAILED"
- )
- end
- else
- test_log(
- entry.name ..
- " | get_AmbientColor FAILED"
- )
- end
- else
- test_log(
- entry.name ..
- " | NOTHING TO RESTORE"
- )
- end
- end
- end
- test_log(
- "================================================"
- )
- end
- --------------------------------------------------------------------------------
- -- APPLY x2
- --------------------------------------------------------------------------------
- local function apply_selected_intensity_x2()
- test_log(
- "================================================"
- )
- test_log(
- "INTENSITY x2 SELECTED"
- )
- for i = 1,
- #LIGHTPROBES_LIST
- do
- local entry =
- LIGHTPROBES_LIST[i]
- if entry.selected
- then
- local lightprobes =
- get_target(
- i
- )
- if lightprobes
- then
- local ok_read,
- current =
- pcall(
- function()
- return lightprobes:get_Intensity()
- end
- )
- if ok_read
- then
- if original_intensity[i] == nil
- then
- original_intensity[i] =
- current
- end
- local new_value =
- current * 2.0
- local ok_set =
- pcall(
- function()
- lightprobes:set_Intensity(
- new_value
- )
- end
- )
- if ok_set
- then
- test_log(
- entry.name ..
- " | OLD = " ..
- tostring(
- current
- ) ..
- " | NEW = " ..
- tostring(
- new_value
- )
- )
- else
- test_log(
- entry.name ..
- " | SET INTENSITY FAILED"
- )
- end
- else
- test_log(
- entry.name ..
- " | get_Intensity FAILED"
- )
- end
- else
- test_log(
- entry.name ..
- " | TARGET NOT FOUND"
- )
- end
- end
- end
- test_log(
- "================================================"
- )
- end
- --------------------------------------------------------------------------------
- -- RESTORE
- --------------------------------------------------------------------------------
- local function restore_selected_intensity()
- test_log(
- "================================================"
- )
- test_log(
- "RESTORE SELECTED"
- )
- for i = 1,
- #LIGHTPROBES_LIST
- do
- local entry =
- LIGHTPROBES_LIST[i]
- if entry.selected
- then
- local lightprobes =
- get_target(
- i
- )
- local original =
- original_intensity[i]
- if lightprobes
- and original ~= nil
- then
- local ok_set =
- pcall(
- function()
- lightprobes:set_Intensity(
- original
- )
- end
- )
- if ok_set
- then
- test_log(
- entry.name ..
- " | RESTORED = " ..
- tostring(
- original
- )
- )
- else
- test_log(
- entry.name ..
- " | RESTORE FAILED"
- )
- end
- else
- test_log(
- entry.name ..
- " | NOTHING TO RESTORE"
- )
- end
- end
- end
- test_log(
- "================================================"
- )
- end
- --------------------------------------------------------------------------------
- -- READ CURRENT CONTROLS
- --------------------------------------------------------------------------------
- local function read_current_controls()
- for i = 1,
- #LIGHTPROBES_LIST
- do
- if LIGHTPROBES_LIST[i].selected
- then
- local lightprobes =
- get_target(
- i
- )
- if lightprobes
- then
- ----------------------------------------------------------------
- -- INTENSITY
- ----------------------------------------------------------------
- local ok_intensity,
- intensity =
- pcall(
- function()
- return lightprobes:get_Intensity()
- end
- )
- if ok_intensity
- and intensity ~= nil
- then
- control_intensity =
- intensity
- end
- ----------------------------------------------------------------
- -- COLOR
- ----------------------------------------------------------------
- local ok_color,
- color =
- pcall(
- function()
- return lightprobes:get_AmbientColor()
- end
- )
- if ok_color
- and color
- then
- local ok_r,
- r =
- pcall(
- function()
- return color.x
- end
- )
- local ok_g,
- g =
- pcall(
- function()
- return color.y
- end
- )
- local ok_b,
- b =
- pcall(
- function()
- return color.z
- end
- )
- if ok_r
- and ok_g
- and ok_b
- then
- control_red =
- r
- control_green =
- g
- control_blue =
- b
- end
- end
- break
- end
- end
- end
- test_log(
- "CONTROL VALUES READ"
- )
- test_log(
- "INTENSITY = " ..
- tostring(
- control_intensity
- )
- )
- test_log(
- "COLOR = " ..
- tostring(
- control_red
- ) ..
- " / " ..
- tostring(
- control_green
- ) ..
- " / " ..
- tostring(
- control_blue
- )
- )
- end
- --------------------------------------------------------------------------------
- -- SELECT ALL
- --------------------------------------------------------------------------------
- local function select_all()
- for i = 1,
- #LIGHTPROBES_LIST
- do
- LIGHTPROBES_LIST[i].selected =
- true
- end
- end
- --------------------------------------------------------------------------------
- -- DESELECT ALL
- --------------------------------------------------------------------------------
- local function deselect_all()
- for i = 1,
- #LIGHTPROBES_LIST
- do
- LIGHTPROBES_LIST[i].selected =
- false
- end
- end
- --------------------------------------------------------------------------------
- -- COUNT SELECTED
- --------------------------------------------------------------------------------
- local function count_selected()
- local count =
- 0
- for i = 1,
- #LIGHTPROBES_LIST
- do
- if LIGHTPROBES_LIST[i].selected
- then
- count =
- count + 1
- end
- end
- return count
- end
- ----------------------------------------------------------------------------
- -- SELECTION
- ----------------------------------------------------------------------------
- local function draw_selection_buttons()
- if imgui.button(
- "TOUT"
- )
- then
- select_all()
- end
- imgui.same_line()
- if imgui.button(
- "RIEN"
- )
- then
- deselect_all()
- end
- end
- ----------------------------------------------------------------------------
- -- RESOLVE
- ----------------------------------------------------------------------------
- local function draw_resolve_button()
- if imgui.button(
- "RESOLVE 16 LIGHTPROBES"
- )
- then
- resolve_all_lightprobes()
- end
- end
- ----------------------------------------------------------------------------
- -- INTENSITY
- ----------------------------------------------------------------------------
- local function draw_intensity_control()
- local intensity_changed,
- new_intensity =
- imgui.slider_float(
- "Intensity",
- control_intensity,
- 0.0,
- 1.0
- )
- if intensity_changed
- then
- control_intensity =
- new_intensity
- for i = 1,
- #LIGHTPROBES_LIST
- do
- local entry =
- LIGHTPROBES_LIST[i]
- if entry
- and entry.selected
- then
- local lightprobes =
- get_target(i)
- if lightprobes
- then
- pcall(
- function()
- lightprobes:set_Intensity(
- control_intensity
- )
- end
- )
- end
- end
- end
- end
- end
- ----------------------------------------------------------------------------
- -- RED
- ----------------------------------------------------------------------------
- local function draw_red_control()
- local red_changed,
- new_red =
- imgui.slider_float(
- "Red",
- control_red,
- 0.0,
- 1.0
- )
- if red_changed
- then
- control_red =
- new_red
- for i = 1,
- #LIGHTPROBES_LIST
- do
- local entry =
- LIGHTPROBES_LIST[i]
- if entry
- and entry.selected
- then
- local lightprobes =
- get_target(i)
- if lightprobes
- then
- local ok,
- color =
- pcall(
- function()
- return lightprobes:get_AmbientColor()
- end
- )
- if ok
- and color
- then
- color.x =
- control_red
- pcall(
- function()
- lightprobes:set_AmbientColor(
- color
- )
- end
- )
- end
- end
- end
- end
- end
- end
- ----------------------------------------------------------------------------
- -- GREEN
- ----------------------------------------------------------------------------
- local function draw_green_control()
- local green_changed,
- new_green =
- imgui.slider_float(
- "Green",
- control_green,
- 0.0,
- 1.0
- )
- if green_changed
- then
- control_green =
- new_green
- for i = 1,
- #LIGHTPROBES_LIST
- do
- local entry =
- LIGHTPROBES_LIST[i]
- if entry
- and entry.selected
- then
- local lightprobes =
- get_target(i)
- if lightprobes
- then
- local ok,
- color =
- pcall(
- function()
- return lightprobes:get_AmbientColor()
- end
- )
- if ok
- and color
- then
- color.y =
- control_green
- pcall(
- function()
- lightprobes:set_AmbientColor(
- color
- )
- end
- )
- end
- end
- end
- end
- end
- end
- ----------------------------------------------------------------------------
- -- BLUE
- ----------------------------------------------------------------------------
- local function draw_blue_control()
- local blue_changed,
- new_blue =
- imgui.slider_float(
- "Blue",
- control_blue,
- 0.0,
- 1.0
- )
- if blue_changed
- then
- control_blue =
- new_blue
- for i = 1,
- #LIGHTPROBES_LIST
- do
- local entry =
- LIGHTPROBES_LIST[i]
- if entry
- and entry.selected
- then
- local lightprobes =
- get_target(i)
- if lightprobes
- then
- local ok,
- color =
- pcall(
- function()
- return lightprobes:get_AmbientColor()
- end
- )
- if ok
- and color
- then
- color.z =
- control_blue
- pcall(
- function()
- lightprobes:set_AmbientColor(
- color
- )
- end
- )
- end
- end
- end
- end
- end
- end
- ----------------------------------------------------------------------------
- -- VALUES
- ----------------------------------------------------------------------------
- local function draw_values()
- imgui.text(
- "Intensity = " ..
- string.format(
- "%.6f",
- control_intensity
- )
- )
- imgui.text(
- "RGB = " ..
- string.format(
- "%.3f",
- control_red
- ) ..
- " / " ..
- string.format(
- "%.3f",
- control_green
- ) ..
- " / " ..
- string.format(
- "%.3f",
- control_blue
- )
- )
- imgui.text(
- "Saturate = " ..
- string.format(
- "%.3f",
- control_saturate
- )
- )
- imgui.text(
- "Ambient Color Intensity = " ..
- string.format(
- "%.3f",
- control_ambient_color_intensity
- )
- )
- end
- ----------------------------------------------------------------------------
- -- RESTORE
- ----------------------------------------------------------------------------
- local function draw_restore_button()
- if imgui.button(
- "RESTORE ORIGINAL"
- )
- then
- restore_selected_intensity()
- restore_selected_color()
- end
- end
- ----------------------------------------------------------------------------
- -- RESTORE COLOR
- ----------------------------------------------------------------------------
- local function draw_restore_color_button()
- if imgui.button(
- "RESTORE COLOR"
- )
- then
- restore_selected_color()
- end
- end
- ----------------------------------------------------------------------------
- -- LIGHTPROBES LIST
- ----------------------------------------------------------------------------
- local function draw_lightprobes_list()
- for i = 1,
- #LIGHTPROBES_LIST
- do
- local entry =
- LIGHTPROBES_LIST[i]
- local changed,
- selected =
- imgui.checkbox(
- entry.name,
- entry.selected
- )
- if changed
- then
- entry.selected =
- selected
- end
- imgui.same_line()
- imgui.text(
- entry.guid
- )
- end
- end
- ----------------------------------------------------------------------------
- -- SATURATE CONTROL
- ----------------------------------------------------------------------------
- local function draw_saturate_control()
- local saturate_changed,
- new_saturate =
- imgui.slider_float(
- "Saturate",
- control_saturate,
- 0.0,
- 1.0
- )
- if saturate_changed
- then
- control_saturate =
- new_saturate
- for i = 1,
- #LIGHTPROBES_LIST
- do
- local entry =
- LIGHTPROBES_LIST[i]
- if entry
- and entry.selected
- then
- local lightprobes =
- get_target(i)
- if lightprobes
- then
- pcall(
- function()
- lightprobes:set_Saturate(
- control_saturate
- )
- end
- )
- end
- end
- end
- end
- end
- ----------------------------------------------------------------------------
- -- AMBIENT COLOR INTENSITY CONTROL
- ----------------------------------------------------------------------------
- local function draw_ambient_color_intensity_control()
- local changed,
- new_value =
- imgui.slider_float(
- "Ambient Color Intensity",
- control_ambient_color_intensity,
- 0.0,
- 2.0
- )
- if changed
- then
- control_ambient_color_intensity =
- new_value
- for i = 1,
- #LIGHTPROBES_LIST
- do
- local entry =
- LIGHTPROBES_LIST[i]
- if entry
- and entry.selected
- then
- local lightprobes =
- get_target(i)
- if lightprobes
- then
- pcall(
- function()
- lightprobes:set_AmbientColorIntensity(
- control_ambient_color_intensity
- )
- end
- )
- end
- end
- end
- end
- end
- --------------------------------------------------------------------------------
- -- AMBIENT COLOR PICKER
- --------------------------------------------------------------------------------
- local control_alpha = 1.0
- local function draw_ambient_color_picker()
- local color =
- Vector4f.new(
- control_red,
- control_green,
- control_blue,
- control_alpha
- )
- local changed,
- new_color =
- imgui.color_edit4(
- "Ambient Color",
- color
- )
- if changed
- and new_color
- then
- control_red =
- new_color.x
- control_green =
- new_color.y
- control_blue =
- new_color.z
- control_alpha =
- new_color.w
- for i = 1,
- #LIGHTPROBES_LIST
- do
- local entry =
- LIGHTPROBES_LIST[i]
- if entry
- and entry.selected
- then
- local lightprobes =
- get_target(i)
- if lightprobes
- then
- pcall(
- function()
- local ambient_color =
- lightprobes:get_AmbientColor()
- ambient_color.x =
- control_red
- ambient_color.y =
- control_green
- ambient_color.z =
- control_blue
- lightprobes:set_AmbientColor(
- ambient_color
- )
- end
- )
- end
- end
- end
- end
- end
- --------------------------------------------------------------------------------
- -- COLOR TEMPERATURE CONTROL
- --------------------------------------------------------------------------------
- local control_black_body_radiation =
- 0.0
- local control_temperature =
- 6500.0
- local function draw_color_temperature_controls()
- ----------------------------------------------------------------
- -- BLACK BODY RADIATION
- ----------------------------------------------------------------
- local changed_blackbody,
- new_blackbody =
- imgui.slider_float(
- "Black Body Radiation",
- control_black_body_radiation,
- 0.0,
- 1.0,
- "%.2f"
- )
- if changed_blackbody
- then
- control_black_body_radiation =
- new_blackbody
- test_log(
- "BlackBodyRadiation CHANGE = " ..
- tostring(
- control_black_body_radiation
- )
- )
- for i = 1,
- #LIGHTPROBES_LIST
- do
- local entry =
- LIGHTPROBES_LIST[i]
- if entry
- and entry.selected
- then
- local lightprobes =
- get_target(i)
- if lightprobes
- then
- local ok,
- result =
- pcall(
- function()
- return lightprobes:call(
- "set_BlackBodyRadiation",
- control_black_body_radiation
- )
- end
- )
- test_log(
- entry.name ..
- " | set_BlackBodyRadiation | OK = " ..
- tostring(ok) ..
- " | RESULT = " ..
- tostring(result)
- )
- end
- end
- end
- end
- ----------------------------------------------------------------
- -- TEMPERATURE
- ----------------------------------------------------------------
- local changed_temperature,
- new_temperature =
- imgui.slider_float(
- "Temperature",
- control_temperature,
- 1000.0,
- 20000.0,
- "%.0f K"
- )
- if changed_temperature
- then
- control_temperature =
- new_temperature
- test_log(
- "Temperature CHANGE = " ..
- tostring(
- control_temperature
- )
- )
- for i = 1,
- #LIGHTPROBES_LIST
- do
- local entry =
- LIGHTPROBES_LIST[i]
- if entry
- and entry.selected
- then
- local lightprobes =
- get_target(i)
- if lightprobes
- then
- local ok,
- result =
- pcall(
- function()
- return lightprobes:call(
- "set_Temperature",
- control_temperature
- )
- end
- )
- test_log(
- entry.name ..
- " | set_Temperature | OK = " ..
- tostring(ok) ..
- " | RESULT = " ..
- tostring(result)
- )
- end
- end
- end
- end
- end
- --------------------------------------------------------------------------------
- -- UI
- --------------------------------------------------------------------------------
- re.on_draw_ui(
- function()
- if imgui.tree_node(
- "LightProbes Control Test"
- )
- then
- --------------------------------------------------------------------------------
- -- LIGHTPROBES ZONE SELECTOR
- --------------------------------------------------------------------------------
- if #LIGHTPROBES_ZONES > 0
- then
- local current_zone_index =
- 1
- for i = 1,
- #LIGHTPROBES_ZONES
- do
- if LIGHTPROBES_ZONES[i]
- == selected_lightprobes_zone
- then
- current_zone_index =
- i
- break
- end
- end
- local changed_zone,
- new_zone_index =
- imgui.combo(
- "Zone",
- current_zone_index - 1,
- LIGHTPROBES_ZONES
- )
- if changed_zone
- then
- local new_zone =
- LIGHTPROBES_ZONES[
- new_zone_index + 1
- ]
- if new_zone
- and new_zone ~= selected_lightprobes_zone
- then
- selected_lightprobes_zone =
- new_zone
- test_log(
- "ZONE CHANGED = " ..
- tostring(
- selected_lightprobes_zone
- )
- )
- resolved_lightprobes =
- {
- }
- original_intensity =
- {
- }
- original_color =
- {
- }
- build_lightprobes_list_for_zone(
- selected_lightprobes_zone
- )
- test_log(
- "PROBES IN NEW ZONE = " ..
- tostring(
- #LIGHTPROBES_LIST
- )
- )
- end
- end
- end
- imgui.text(
- "LightProbes : " ..
- tostring(
- #LIGHTPROBES_LIST
- )
- )
- imgui.text(
- "Selected : " ..
- tostring(
- count_selected()
- ) ..
- " / " ..
- tostring(
- #LIGHTPROBES_LIST
- )
- )
- imgui.separator()
- draw_selection_buttons()
- draw_resolve_button()
- imgui.separator()
- imgui.text(
- "LIGHTPROBES CONTROL"
- )
- draw_intensity_control()
- draw_red_control()
- draw_green_control()
- draw_blue_control()
- draw_ambient_color_picker()
- draw_saturate_control()
- draw_ambient_color_intensity_control()
- draw_color_temperature_controls()
- draw_values()
- imgui.separator()
- draw_restore_button()
- imgui.same_line()
- draw_restore_color_button()
- imgui.separator()
- draw_lightprobes_list()
- imgui.tree_pop()
- end
- end
- )
- --------------------------------------------------------------------------------
- -- STARTUP
- --------------------------------------------------------------------------------
- test_log(
- "SCRIPT LOADED"
- )
- if load_lightprobes_database()
- then
- test_log(
- "LIGHTPROBES DATABASE LOADED"
- )
- if build_lightprobes_zones()
- then
- test_log(
- "LIGHTPROBES ZONES = " ..
- tostring(
- #LIGHTPROBES_ZONES
- )
- )
- for i = 1,
- #LIGHTPROBES_ZONES
- do
- test_log(
- "ZONE [" ..
- tostring(i) ..
- "] = " ..
- tostring(
- LIGHTPROBES_ZONES[i]
- )
- )
- end
- if selected_lightprobes_zone
- then
- test_log(
- "SELECTED ZONE = " ..
- tostring(
- selected_lightprobes_zone
- )
- )
- if build_lightprobes_list_for_zone(
- selected_lightprobes_zone
- )
- then
- test_log(
- "PROBES IN ZONE = " ..
- tostring(
- #LIGHTPROBES_LIST
- )
- )
- for i = 1,
- #LIGHTPROBES_LIST
- do
- local entry =
- LIGHTPROBES_LIST[i]
- if entry
- then
- test_log(
- tostring(i) ..
- " | " ..
- tostring(
- entry.zone
- ) ..
- " | " ..
- tostring(
- entry.name
- ) ..
- " | " ..
- tostring(
- entry.guid
- )
- )
- end
- end
- else
- test_log(
- "LIGHTPROBES ZONE LIST BUILD FAILED"
- )
- end
- else
- test_log(
- "NO LIGHTPROBES ZONE SELECTED"
- )
- end
- else
- test_log(
- "LIGHTPROBES ZONES BUILD FAILED"
- )
- end
- else
- test_log(
- "LIGHTPROBES DATABASE LOAD FAILED"
- )
- end
RAW Paste Data
Copied
Advertisement
