File size: 4,898 Bytes
103b0f1 | 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 162 163 164 165 166 167 168 169 170 171 172 |
local isEditor = (Amaz.Macros and Amaz.Macros.EditorSDK) and true or false
local exports = exports or {}
local LumiManager = LumiManager or {}
LumiManager.__index = LumiManager
---@class LumiManager : ScriptComponent
---@field LumiEffectTrans Transform
---@field start_render_layer int
---@field start_render_order int
---@field InputTex Texture
---@field OutputTex Texture
---@field PingPongTex Texture
local function handleAllEntityBySingleParent(_trans, func, ...)
if _trans.children:size() > 0 then
for i = 1, _trans.children:size() do
local child = _trans.children:get(i-1)
handleAllEntityBySingleParent(child, func, ...)
end
end
func(_trans, ...)
end
function LumiManager.new(construct, ...)
local self = setmetatable({}, LumiManager)
self.LumiEffectTrans = nil
self.start_render_layer = 1
self.start_render_order = 1
self.InputTex = nil
self.OutputTex = nil
self.PingPongTex = nil
self.startTime = 0.0
self.endTime = 6.0
self.curTime = 0.0
if construct and LumiManager.constructor then LumiManager.constructor(self, ...) end
return self
end
function LumiManager:onStart(comp)
self.entity = comp.entity
self.trans = self.entity:getComponent("Transform")
-- self.input = comp.entity.scene.assetMgr:SyncLoad("share://input.texture")
-- self.output = comp.entity.scene.assetMgr:SyncLoad("rt/outputTex.rt")
self.lumi_obj_extension = includeRelativePath("LumiObjectExtension")
self.lumi_obj = nil
self.LumiParamsSetter = includeRelativePath("LumiParamsSetter")
if self.LumiParamsSetter then
local ae_tools = includeRelativePath("AETools")
self.lumi_params_setter = self.LumiParamsSetter.new(ae_tools)
end
end
function LumiManager:onDestroy(comp)
if self.LumiEffectTrans and self.lumi_obj_extension then
self.lumi_obj_extension.deregister(self.LumiEffectTrans.entity)
end
self.lumi_obj = nil
end
---@function [UI(Button="ReRender")]
function LumiManager:getCameraCount()
if self.LumiEffectTrans == nil then
return 0
end
self.lumi_obj = nil
self:ReRender()
local cam_count = 0
if self.lumi_obj then
cam_count = self.lumi_obj:getCameraCount()
Amaz.LOGI("AE_LUA_TAG", self.lumi_obj.entity.name .. " camera_count: " .. tostring(cam_count))
end
return cam_count
end
function LumiManager:ReRender()
if self.LumiEffectTrans == nil then
return
end
-- re register
self.lumi_obj = nil
self:registerLumiObj(self.LumiEffectTrans, 1)
if self.lumi_obj == nil then
Amaz.LOGE('AE_LUA_TAG', 'No lumi_obj register')
return
end
-- change layer & order
self:updateCameraLayerAndOrder()
-- change rt pingpong
self:updateRtPingpong()
end
function LumiManager:registerLumiObj(_trans, _idx)
if _trans == nil then return end
-- Amaz.LOGI("lrc ".._idx, _trans.entity.name)
local script_comp = _trans.entity:getComponent("ScriptComponent")
if script_comp then
local lua_obj = Amaz.ScriptUtils.getLuaObj(script_comp:getScript())
if lua_obj then
self.lumi_obj_extension.deregister(_trans.entity)
self.lumi_obj = self.lumi_obj_extension.register(_trans.entity)
end
end
end
function LumiManager:updateCameraLayerAndOrder()
if self.lumi_obj then
self.lumi_obj:updateCameraLayerAndOrder(self.start_render_layer, self.start_render_order)
end
end
function LumiManager:updateRtPingpong()
if self.lumi_obj then
self.lumi_obj:updateRt(self.InputTex, self.OutputTex, self.PingPongTex)
end
end
function LumiManager:onUpdate(comp, deltaTime)
if isEditor then
end
if self.lumi_obj == nil then
self:registerLumiObj(self.LumiEffectTrans, 1)
end
self.curTime = self.curTime + deltaTime
if self.lumi_obj then
self.lumi_obj:setEffectAttr("startTime", self.startTime)
self.lumi_obj:setEffectAttr("endTime", self.endTime)
self.lumi_obj:setEffectAttr("curTime", self.curTime)
end
if self.lumi_params_setter and self.lumi_params_setter.updateKeyFrameData then
self.lumi_params_setter:updateKeyFrameData(self.lumi_obj, self.startTime, self.endTime, self.curTime)
end
if self.lumi_obj and self.lumi_obj.updateMaterials then
self.lumi_obj:updateMaterials(deltaTime)
end
end
function LumiManager:onEvent(comp, event)
if self.lumi_obj == nil then
self:registerLumiObj(self.LumiEffectTrans, 1)
end
if self.lumi_obj == nil then
Amaz.LOGE('AE_LUA_TAG', 'Failed to find lumi_obj')
return
end
if self.lumi_params_setter and self.lumi_params_setter.onEvent then
self.lumi_params_setter:onEvent(self.lumi_obj, event)
end
end
exports.LumiManager = LumiManager
return exports
|