Skip to content

Commit

Permalink
fix light edit bug
Browse files Browse the repository at this point in the history
  • Loading branch information
aimoonchen committed Mar 11, 2024
1 parent ea74418 commit 3b297a5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
16 changes: 13 additions & 3 deletions tools/editor/pkg/tools.editor/gizmo_system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,13 @@ local function move_light_gizmo(x, y)
circle_centre = math3d.transform(mat, math3d.vector{0, 0, ilight.range(le)}, 1)
end
local lightPos = iom.get_position(le)
local info = hierarchy:get_node_info(light_gizmo.current_light)
if light_gizmo_mode == 4 then
local curpos = mouse_hit_plane({x, y}, {dir = gizmo_dir_to_world(click_dir_spot_light), pos = math3d.totable(circle_centre)})
ilight.set_outter_radian(le, 2.0 * math.atan(math3d.length(math3d.sub(curpos, circle_centre)), ilight.range(le)))
local value = 2.0 * math.atan(math3d.length(math3d.sub(curpos, circle_centre)), ilight.range(le))
ilight.set_outter_radian(le, value)
info.template.data.light.outter_radian = value
world:pub { "PatchEvent", light_gizmo.current_light, "/data/light/outter_radian", value }
elseif light_gizmo_mode == 5 then
local move_dir = math3d.sub(circle_centre, lightPos)
local ce <close> = world:entity(irq.main_camera(), "camera:in")
Expand All @@ -762,10 +766,16 @@ local function move_light_gizmo(x, y)
if math3d.length(math3d.sub(new_offset, lightPos)) < math3d.length(math3d.sub(init_offset, lightPos)) then
offset = -offset
end
ilight.set_range(le, last_spot_range + offset)
local value = last_spot_range + offset
ilight.set_range(le, value)
info.template.data.light.range = value
world:pub { "PatchEvent", light_gizmo.current_light, "/data/light/range", value }
else
local curpos = mouse_hit_plane({x, y}, {dir = gizmo_dir_to_world(click_dir_point_light), pos = math3d.totable(lightPos)})
ilight.set_range(le, math3d.length(math3d.sub(curpos, lightPos)))
local value = math3d.length(math3d.sub(curpos, lightPos))
ilight.set_range(le, value)
info.template.data.light.range = value
world:pub { "PatchEvent", light_gizmo.current_light, "/data/light/range", value }
end
light_gizmo.update_gizmo()
light_gizmo.highlight(true)
Expand Down
18 changes: 11 additions & 7 deletions tools/editor/pkg/tools.editor/prefab_manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,21 @@ end

local function create_default_light(type, parent)
local light, tpl = ilight.create {
srt = {t = {0, 5, 0}, r = type == "directional" and {math.rad(130), 0, 0} or nil, parent = parent},
srt = {
t = {0, 5, 0},
r = (type == "directional") and {math.rad(130), 0, 0} or nil,
parent = parent
},
name = type .. gen_light_id(),
type = type,
color = {1, 1, 1, 1},
make_shadow = false,
intensity = 130000,--ilight.default_intensity(lt),
make_shadow = true,
intensity = 130000,
intensity_unit = ilight.default_intensity_unit(type),
range = 10,
range = (type ~= "directional") and 10 or nil,
motion_type = "dynamic",
inner_radian = math.rad(10),
outter_radian = math.rad(30)
inner_radian = (type == "spot") and math.rad(10) or nil,
outter_radian = (type == "spot") and math.rad(30) or nil
}
create_light_billboard(light, type)
return light, utils.deep_copy(tpl)
Expand Down Expand Up @@ -370,7 +374,7 @@ function m:on_prefab_ready(prefab)
last_tpl = pt
if e.light then
create_light_billboard(eid, e.light.type)
light_gizmo.bind(eid)
light_gizmo.on_target(eid)
light_gizmo.show(false)
end
end
Expand Down
1 change: 1 addition & 0 deletions tools/editor/pkg/tools.editor/widget/animation_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ function m.show()
on_move_clip(move_type, anim_state.selected_clip_index, move_delta)
end
ImGui.Separator()
-- ImGui.GetIO().WantCaptureMouse = true
if ImGui.BeginTable("EventColumns", edit_timeline and 2 or 3, ImGui.TableFlags {'Resizable', 'ScrollY'}) then
if not edit_timeline then
ImGui.TableSetupColumnEx("Bones", ImGui.TableColumnFlags {'WidthStretch'}, 1.0)
Expand Down
5 changes: 4 additions & 1 deletion tools/editor/pkg/tools.editor/widget/light_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,14 @@ function LightView:update()
end
self.light_property:update()
end

local event_gizmo = world:sub {"Gizmo"}
function LightView:show()
if not self.eid then
return
end
for _, _, _, _ in event_gizmo:unpack() do
self:update()
end
self.light_property:show()
end

Expand Down

0 comments on commit 3b297a5

Please sign in to comment.