| 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 |
{$ifdef read_interface} |
| 18 |
|
| 19 |
type |
| 20 |
{ Box with configurable size, position and material. } |
| 21 |
TCastleBox = class(TCastleAbstractPrimitive) |
| 22 |
strict private |
| 23 |
BoxNode: TBoxNode; |
| 24 |
FSize: TVector3; |
| 25 |
FDoubleSided: Boolean; |
| 26 |
procedure SetSize(const Value: TVector3); |
| 27 |
procedure SetDoubleSided(const Value: Boolean); |
| 28 |
public |
| 29 |
constructor Create(AOwner: TComponent); override; |
| 30 |
destructor Destroy; override; |
| 31 |
function PropertySections(const PropertyName: String): TPropertySections; override; |
| 32 |
|
| 33 |
{ Size of the box in 3D. By default (2, 2, 2). } |
| 34 |
property Size: TVector3 read FSize write SetSize; |
| 35 |
|
| 36 |
{ Get or set the box @link(Size) and @link(Translation) using the TBox3D type. } |
| 37 |
// TODO: property Box: TBox3D read GetBox write SetBox; |
| 38 |
published |
| 39 |
{ When this is @true, the object is visible (and lit) from both sides. } |
| 40 |
property DoubleSided: Boolean read FDoubleSided write SetDoubleSided default false; |
| 41 |
|
| 42 |
{$define read_interface_class} |
| 43 |
{$I auto_generated_persistent_vectors/tcastlebox_persistent_vectors.inc} |
| 44 |
{$undef read_interface_class} |
| 45 |
end; |
| 46 |
|
| 47 |
{$endif read_interface} |
| 48 |
|
| 49 |
{$ifdef read_implementation} |
| 50 |
|
| 51 |
{ TCastleBox ---------------------------------------------------------------- } |
| 52 |
|
| 53 |
constructor TCastleBox.Create(AOwner: TComponent); |
| 54 |
begin |
| 55 |
inherited; |
| 56 |
|
| 57 |
{ default properties values } |
| 58 |
FSize := Vector3(2, 2, 2); |
| 59 |
|
| 60 |
BoxNode := TBoxNode.Create; |
| 61 |
BoxNode.Size := FSize; |
| 62 |
ShapeNode.Geometry := BoxNode; |
| 63 |
|
| 64 |
{$define read_implementation_constructor} |
| 65 |
{$I auto_generated_persistent_vectors/tcastlebox_persistent_vectors.inc} |
| 66 |
{$undef read_implementation_constructor} |
| 67 |
end; |
| 68 |
|
| 69 |
destructor TCastleBox.Destroy; |
| 70 |
begin |
| 71 |
{$define read_implementation_destructor} |
| 72 |
{$I auto_generated_persistent_vectors/tcastlebox_persistent_vectors.inc} |
| 73 |
{$undef read_implementation_destructor} |
| 74 |
|
| 75 |
inherited; |
| 76 |
end; |
| 77 |
|
| 78 |
function TCastleBox.PropertySections(const PropertyName: String): TPropertySections; |
| 79 |
begin |
| 80 |
if (PropertyName = 'SizePersistent') or |
| 81 |
(PropertyName = 'DoubleSided') then |
| 82 |
Result := [psBasic] |
| 83 |
else |
| 84 |
Result := inherited PropertySections(PropertyName); |
| 85 |
end; |
| 86 |
|
| 87 |
procedure TCastleBox.SetSize(const Value: TVector3); |
| 88 |
begin |
| 89 |
if not TVector3.PerfectlyEquals(FSize, Value) then |
| 90 |
begin |
| 91 |
FSize := Value; |
| 92 |
BoxNode.Size := FSize; |
| 93 |
UpdateCollider; |
| 94 |
end; |
| 95 |
end; |
| 96 |
|
| 97 |
procedure TCastleBox.SetDoubleSided(const Value: Boolean); |
| 98 |
begin |
| 99 |
if FDoubleSided <> Value then |
| 100 |
begin |
| 101 |
FDoubleSided := Value; |
| 102 |
BoxNode.Solid := not Value; |
| 103 |
end; |
| 104 |
end; |
| 105 |
|
| 106 |
{$define read_implementation_methods} |
| 107 |
{$I auto_generated_persistent_vectors/tcastlebox_persistent_vectors.inc} |
| 108 |
{$undef read_implementation_methods} |
| 109 |
|
| 110 |
{$endif read_implementation} |