Debian Codegraph @

src/scene/castlescene_abstractlight.inc

raw
1 {%MainUnit castlescene.pas}
2 {
3 Copyright 2021-2022 Michalis Kamburelis.
4
5 This file is part of "Castle Game Engine".
6
7 "Castle Game Engine" is free software; see the file COPYING.txt,
8 included in this distribution, for details about the copyright.
9
10 "Castle Game Engine" is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 ----------------------------------------------------------------------------
15 }
16
17 { Lights that can be easily added and adjusted inside TCastleViewport. }
18
19 {$ifdef read_interface}
20
21 type
22 { Base class to express lights that can be easily added and
23 adjusted inside TCastleViewport. }
24 TCastleAbstractLight = class(TCastleTransform)
25 strict private
26 FScene: TCastleScene;
27 FRootNode: TX3DRootNode;
28 FLightNode: TAbstractLightNode;
29 FGizmo: TInternalCastleEditorGizmo;
30 procedure SetLightNode(const Value: TAbstractLightNode);
31 protected
32 { Descendants should set X3D light node here. }
33 property LightNode: TAbstractLightNode read FLightNode write SetLightNode;
34 property Gizmo: TInternalCastleEditorGizmo read FGizmo;
35 public
36 constructor Create(AOwner: TComponent); override;
37 destructor Destroy; override;
38 function PropertySections(const PropertyName: String): TPropertySections; override;
39 published
40 end;
41
42 {$endif read_interface}
43
44 {$ifdef read_implementation}
45
46 constructor TCastleAbstractLight.Create(AOwner: TComponent);
47 begin
48 inherited;
49
50 { internal stuff create }
51 FScene := TCastleScene.Create(nil);
52 FScene.SetTransient;
53 FScene.CastGlobalLights := true;
54 Add(FScene);
55
56 { build X3D nodes }
57 FRootNode := TX3DRootNode.Create;
58 FScene.Load(FRootNode, true);
59
60 if CastleDesignMode then
61 begin
62 FGizmo := TInternalCastleEditorGizmo.Create(Self);
63 { The features shown by light gizmo are not affected by scale,
64 and we don't want light icon to get huge/small because of scaling. }
65 FGizmo.InternalIgnoreParentScale := true;
66 Add(FGizmo);
67 end;
68 end;
69
70 destructor TCastleAbstractLight.Destroy;
71 begin
72 FreeAndNil(FScene);
73 inherited;
74 end;
75
76 procedure TCastleAbstractLight.SetLightNode(const Value: TAbstractLightNode);
77 begin
78 if FLightNode <> Value then
79 begin
80 if FLightNode <> nil then
81 FRootNode.RemoveChildren(FLightNode);
82 FLightNode := Value;
83 if FLightNode <> nil then
84 FRootNode.AddChildren(FLightNode);
85 end;
86 end;
87
88 function TCastleAbstractLight.PropertySections(const PropertyName: String): TPropertySections;
89 begin
90 if ArrayContainsString(PropertyName, [
91 'CastShadows', 'RenderLayer'
92 ]) then
93 // Hide some properties inherited from TCastleTransform that actually do nothing for light sources
94 Result := []
95 else
96 Result := inherited PropertySections(PropertyName);
97 end;
98
99 {$endif read_implementation}