3
interface //#################################################################### ■
5
uses System.Classes, System.Math.Vectors,
6
FMX.Types3D, FMX.Controls3D, FMX.MaterialSources,
9
type //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【型】
11
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【レコード】
13
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TVert
20
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TQuad
30
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【クラス】
32
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TBlocks
34
TBlocks = class( TControl3D )
39
_Material :TMaterialSource;
40
_Brics :TArray3<Boolean>;
45
function GetBrics( const X_,Y_,Z_:Integer ) :Boolean;
46
procedure SetBrics( const X_,Y_,Z_:Integer; const Bric_:Boolean );
47
function GetBricsX :Integer;
48
procedure SetBricsX( const BricsX_:Integer );
49
function GetBricsY :Integer;
50
procedure SetBricsY( const BricsY_:Integer );
51
function GetBricsZ :Integer;
52
procedure SetBricsZ( const BricsZ_:Integer );
54
procedure Render; override;
56
constructor Create( AOwner_:TComponent ); override;
57
destructor Destroy; override;
59
property Material :TMaterialSource read _Material write _Material;
60
property Brics[ const X_,Y_,Z_:Integer ] :Boolean read GetBrics write SetBrics ;
61
property BricsX :Integer read GetBricsX write SetBricsX ;
62
property BricsY :Integer read GetBricsY write SetBricsY ;
63
property BricsZ :Integer read GetBricsZ write SetBricsZ ;
65
procedure EndUpdate; override;
69
//const //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【定数】
71
//var //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【変数】
73
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【ルーチン】
75
implementation //############################################################### ■
77
uses System.SysUtils, System.RTLConsts;
79
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【レコード】
81
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【クラス】
83
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TBlocks
85
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
87
procedure TBlocks.MakeBrics;
89
SetLength( _Brics, _BricsZ, _BricsY, _BricsX );
92
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
94
/////////////////////////////////////////////////////////////////////// アクセス
96
function TBlocks.GetBrics( const X_,Y_,Z_:Integer ) :Boolean;
98
if ( 0 <= Z_ ) and ( Z_ < _BricsZ ) and
99
( 0 <= Y_ ) and ( Y_ < _BricsY ) and
100
( 0 <= X_ ) and ( X_ < _BricsX ) then Result := _Brics[ Z_, Y_, X_ ]
101
else Result := False;
104
procedure TBlocks.SetBrics( const X_,Y_,Z_:Integer; const Bric_:Boolean );
106
_Brics[ Z_, Y_, X_ ] := Bric_;
108
if FUpdating = 0 then MakeModel;
111
//------------------------------------------------------------------------------
113
function TBlocks.GetBricsX :Integer;
118
procedure TBlocks.SetBricsX( const BricsX_:Integer );
120
_BricsX := BricsX_; MakeBrics;
123
function TBlocks.GetBricsY :Integer;
128
procedure TBlocks.SetBricsY( const BricsY_:Integer );
130
_BricsY := BricsY_; MakeBrics;
133
function TBlocks.GetBricsZ :Integer;
138
procedure TBlocks.SetBricsZ( const BricsZ_:Integer );
140
_BricsZ := BricsZ_; MakeBrics;
143
/////////////////////////////////////////////////////////////////////// メソッド
145
procedure TBlocks.Render;
147
Context.SetMatrix( TMatrix3D.CreateTranslation( TPoint3D.Create( -_BricsX / 2,
150
* TMatrix3D.CreateScaling( TPoint3D.Create( Width / _BricsX,
155
Context.DrawTriangles( _Geometry.VertexBuffer,
156
_Geometry.IndexBuffer,
157
TMaterialSource.ValidMaterial( _Material ),
161
//------------------------------------------------------------------------------
163
procedure TBlocks.MakeModel;
165
Quads :array [ 1..6 ] of TQuad = (
166
( N:( X:-1; Y: 0; Z: 0 ); P1:( X:0; Y:0; Z:0 ); P2:( X:0; Y:1; Z:0 ); P3:( X:0; Y:1; Z:1 ); P4:( X:0; Y:0; Z:1 ) ),
167
( N:( X: 0; Y:-1; Z: 0 ); P1:( X:0; Y:0; Z:0 ); P2:( X:0; Y:0; Z:1 ); P3:( X:1; Y:0; Z:1 ); P4:( X:1; Y:0; Z:0 ) ),
168
( N:( X: 0; Y: 0; Z:-1 ); P1:( X:0; Y:0; Z:0 ); P2:( X:1; Y:0; Z:0 ); P3:( X:1; Y:1; Z:0 ); P4:( X:0; Y:1; Z:0 ) ),
169
( N:( X:+1; Y: 0; Z: 0 ); P1:( X:1; Y:1; Z:1 ); P2:( X:1; Y:1; Z:0 ); P3:( X:1; Y:0; Z:0 ); P4:( X:1; Y:0; Z:1 ) ),
170
( N:( X: 0; Y:+1; Z: 0 ); P1:( X:1; Y:1; Z:1 ); P2:( X:0; Y:1; Z:1 ); P3:( X:0; Y:1; Z:0 ); P4:( X:1; Y:1; Z:0 ) ),
171
( N:( X: 0; Y: 0; Z:+1 ); P1:( X:1; Y:1; Z:1 ); P2:( X:1; Y:0; Z:1 ); P3:( X:0; Y:0; Z:1 ); P4:( X:0; Y:1; Z:1 ) ) );
185
//······································
186
procedure AddVert( const P_:TByte3D; const N_:TShortint3D );
190
V.Pos := TPoint3D.Create( X+P_.X, Y+P_.Y, Z+P_.Z );
191
V.Nor := TPoint3D.Create( N_.X, N_.Y, N_.Z );
195
//······································
197
VsN, QsN, N, I, J, I00, I01, I10, I11 :Integer;
206
// +----+----+----+ |
207
// | +-/|-+-/|-+--|-+
214
for Z := 0 to _BricsZ-1 do
215
for Y := 0 to _BricsY-1 do
216
for X := 0 to _BricsX-1 do
218
if Brics[ X, Y ,Z ] then
224
if not Brics[ X+N.X, Y+N.Y, Z+N.Z ] then
237
QsN := VsN{Vert} div 4{Vert/Quad};
245
for I := 0 to VsN-1 do
249
Vertices[ I ] := Pos;
250
Normals [ I ] := Nor;
257
Length := QsN{Quad} * 2{Tria/Quad} * 3{Poin/Tria};
272
Indices[ J ] := I00; Inc( J );
273
Indices[ J ] := I01; Inc( J );
274
Indices[ J ] := I11; Inc( J );
276
Indices[ J ] := I11; Inc( J );
277
Indices[ J ] := I10; Inc( J );
278
Indices[ J ] := I00; Inc( J );
286
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
288
constructor TBlocks.Create( AOwner_:TComponent );
292
_Geometry := TMeshData.Create;
302
destructor TBlocks.Destroy;
309
/////////////////////////////////////////////////////////////////////// メソッド
311
procedure TBlocks.EndUpdate;
315
if FUpdating = 0 then MakeModel;
318
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【ルーチン】
320
//############################################################################## □
322
initialization //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 初期化
324
finalization //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 最終化
326
end. //######################################################################### ■