| 1 |
{%MainUnit castlescene.pas} |
| 2 |
{ |
| 3 |
Copyright 2021-2024 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 |
{ Cone with configurable size, position and material. } |
| 21 |
TCastleCone = class(TCastleAbstractPrimitive) |
| 22 |
strict private |
| 23 |
ConeNode: TConeNode; |
| 24 |
FBottomRadius, FHeight: Single; |
| 25 |
FDoubleSided: Boolean; |
| 26 |
FBottom, FSide: Boolean; |
| 27 |
FSlices, FStacks: Cardinal; |
| 28 |
procedure SetBottomRadius(const Value: Single); |
| 29 |
procedure SetHeight(const Value: Single); |
| 30 |
procedure SetDoubleSided(const Value: Boolean); |
| 31 |
procedure SetBottom(const Value: Boolean); |
| 32 |
procedure SetSide(const Value: Boolean); |
| 33 |
procedure SetSlices(const Value: Cardinal); |
| 34 |
procedure SetStacks(const Value: Cardinal); |
| 35 |
public |
| 36 |
constructor Create(AOwner: TComponent); override; |
| 37 |
function PropertySections(const PropertyName: String): TPropertySections; override; |
| 38 |
published |
| 39 |
{ Cone bottom radius. } |
| 40 |
property BottomRadius: Single read FBottomRadius write SetBottomRadius {$ifdef FPC}default 1{$endif}; |
| 41 |
|
| 42 |
{ Cone height. } |
| 43 |
property Height: Single read FHeight write SetHeight {$ifdef FPC}default 2{$endif}; |
| 44 |
|
| 45 |
{ When this is @true, the object is visible (and lit) from both sides. } |
| 46 |
property DoubleSided: Boolean read FDoubleSided write SetDoubleSided default false; |
| 47 |
|
| 48 |
{ Display bottom of the cone. |
| 49 |
When @false, you can see the cone interior if looking from the outside |
| 50 |
(note: turn on DoubleSided to make interior visible). } |
| 51 |
property Bottom: Boolean read FBottom write SetBottom default true; |
| 52 |
|
| 53 |
{ Display sides of the cone. |
| 54 |
When this is @false, and @link(Bottom) is @true, |
| 55 |
then cone bottom is effectively displayed as just a disk. } |
| 56 |
property Side: Boolean read FSide write SetSide default true; |
| 57 |
|
| 58 |
{ How many "slices" to use to approximate the cone. |
| 59 |
The cone is rendered using polygons (triangles and quads) |
| 60 |
that approximate the cone shape. |
| 61 |
The more slices, the more the cone will look like a cone. |
| 62 |
|
| 63 |
Slices divide the objects like slices of a pizza. |
| 64 |
|
| 65 |
The default value of 0 means to follow global variable |
| 66 |
@link(DefaultTriangulationSlices).} |
| 67 |
property Slices: Cardinal read FSlices write SetSlices default 0; |
| 68 |
|
| 69 |
{ How many "stacks" to use to approximate the cone. |
| 70 |
The cone is rendered using polygons (triangles and quads) |
| 71 |
that approximate the cone shape. |
| 72 |
The more stacks, the more the cone will look like a cone. |
| 73 |
|
| 74 |
Stacks divide the objects like stacks of a tower. |
| 75 |
|
| 76 |
The default value of 0 means to follow global variable |
| 77 |
@link(DefaultTriangulationStacks).} |
| 78 |
property Stacks: Cardinal read FStacks write SetStacks default 0; |
| 79 |
end; |
| 80 |
|
| 81 |
{$endif read_interface} |
| 82 |
|
| 83 |
{$ifdef read_implementation} |
| 84 |
|
| 85 |
{ TCastleCone ---------------------------------------------------------------- } |
| 86 |
|
| 87 |
constructor TCastleCone.Create(AOwner: TComponent); |
| 88 |
begin |
| 89 |
inherited; |
| 90 |
|
| 91 |
{ default properties values } |
| 92 |
FBottomRadius := 1; |
| 93 |
FHeight := 2; |
| 94 |
FBottom := true; |
| 95 |
FSide := true; |
| 96 |
|
| 97 |
ConeNode := TConeNode.Create; |
| 98 |
ConeNode.BottomRadius := FBottomRadius; |
| 99 |
ConeNode.Height := FHeight; |
| 100 |
ConeNode.Solid := not FDoubleSided; |
| 101 |
ConeNode.Slices := FSlices; |
| 102 |
ConeNode.Stacks := FStacks; |
| 103 |
ShapeNode.Geometry := ConeNode; |
| 104 |
end; |
| 105 |
|
| 106 |
function TCastleCone.PropertySections(const PropertyName: String): TPropertySections; |
| 107 |
begin |
| 108 |
if ArrayContainsString(PropertyName, ['BottomRadius', 'Height', 'DoubleSided', |
| 109 |
'Bottom', 'Side', 'Slices', 'Stacks']) then |
| 110 |
Result := [psBasic] |
| 111 |
else |
| 112 |
Result := inherited PropertySections(PropertyName); |
| 113 |
end; |
| 114 |
|
| 115 |
procedure TCastleCone.SetBottomRadius(const Value: Single); |
| 116 |
begin |
| 117 |
if FBottomRadius <> Value then |
| 118 |
begin |
| 119 |
FBottomRadius := Value; |
| 120 |
ConeNode.BottomRadius := FBottomRadius; |
| 121 |
UpdateCollider; |
| 122 |
end; |
| 123 |
end; |
| 124 |
|
| 125 |
procedure TCastleCone.SetHeight(const Value: Single); |
| 126 |
begin |
| 127 |
if FHeight <> Value then |
| 128 |
begin |
| 129 |
FHeight := Value; |
| 130 |
ConeNode.Height := FHeight; |
| 131 |
UpdateCollider; |
| 132 |
end; |
| 133 |
end; |
| 134 |
|
| 135 |
procedure TCastleCone.SetDoubleSided(const Value: Boolean); |
| 136 |
begin |
| 137 |
if FDoubleSided <> Value then |
| 138 |
begin |
| 139 |
FDoubleSided := Value; |
| 140 |
ConeNode.Solid := not Value; |
| 141 |
end; |
| 142 |
end; |
| 143 |
|
| 144 |
procedure TCastleCone.SetBottom(const Value: Boolean); |
| 145 |
begin |
| 146 |
if FBottom <> Value then |
| 147 |
begin |
| 148 |
FBottom := Value; |
| 149 |
ConeNode.Bottom := Value; |
| 150 |
end; |
| 151 |
end; |
| 152 |
|
| 153 |
procedure TCastleCone.SetSide(const Value: Boolean); |
| 154 |
begin |
| 155 |
if FSide <> Value then |
| 156 |
begin |
| 157 |
FSide := Value; |
| 158 |
ConeNode.Side := Value; |
| 159 |
end; |
| 160 |
end; |
| 161 |
|
| 162 |
procedure TCastleCone.SetSlices(const Value: Cardinal); |
| 163 |
begin |
| 164 |
if FSlices <> Value then |
| 165 |
begin |
| 166 |
FSlices := Value; |
| 167 |
ConeNode.Slices := FSlices; |
| 168 |
end; |
| 169 |
end; |
| 170 |
|
| 171 |
procedure TCastleCone.SetStacks(const Value: Cardinal); |
| 172 |
begin |
| 173 |
if FStacks <> Value then |
| 174 |
begin |
| 175 |
FStacks := Value; |
| 176 |
ConeNode.Stacks := FStacks; |
| 177 |
end; |
| 178 |
end; |
| 179 |
|
| 180 |
{$endif read_implementation} |