Thanks for the reproduction!
Testing:
-
Your model is correctly “lighten up”. So ViewMain.LightupColor
correctly executes.
-
But then, it is never brought back to the default lighting. Because you compare Viewport.TransformUnderMouse <> nil
, so whenever mouse is over anything (not necessarily your character), the model is lit up.
So you never see any change, because the EffectColorField.Send(Vector3(1, 1, 1));
from TViewMain.Update
never executes. The color is always (1.3,1.3,1.3).
As a simple test to confirm this, I propose to change NewColor
in TViewMain.LightupColor
implementation to something drastically different, like saturated red, NewColor := Vector3(1, 0, 0);
. When you do this, you will notice that character turns red immediately when you move the mouse, and just stays red all the time.
Solution: to make a “highlight”, what you want is to compare Viewport.TransformUnderMouse
with your character, so
if Viewport.TransformUnderMouse <> nil then
→
if Viewport.TransformUnderMouse = Scene1 then
P.S. (Notes not directly related to your problem, but just mentioning in case they are useful):
-
Note that the Sender
in procedure TViewMain.LightupColor(Sender: TObject)
is not used. At least in this testcase – I realize that you probably cut it down before sending to me, so maybe you want to ignore this note, I just mention it in case it will be helpful.
-
You don’t need to run it as ViewMain.LightupColor(Scene1);
(through the instance variable), you can just call it as LightupColor(...);
when you’re already within another method TViewMain.Update
.
All in all, in this simple testcase, I would implement TViewMain.Update
in more obvious way, without LightupColor
helper:
procedure TViewMain.Update(const SecondsPassed: Single; var HandleInput: Boolean);
begin
inherited;
if Viewport.TransformUnderMouse <> nil then
Label1.Caption := Viewport.TransformUnderMouse.Name
else
Label1.Caption := ' ';
if Viewport.TransformUnderMouse = Scene1 then
EffectColorField.Send(Vector3(1.3, 1.3, 1.3))
else
EffectColorField.Send(Vector3(1, 1, 1));
end;
Note that I completely separated setting Label1.Caption
from setting EffectColorField. They are independent, need different conditions.