GBE.CubeExtend.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. unit GBE.CubeExtend;
  2. interface
  3. uses
  4. System.SysUtils,
  5. System.Classes,
  6. FMX.Types,
  7. FMX.Controls3D,
  8. FMX.Objects3D,
  9. FMX.MaterialSources;
  10. type
  11. TGBECubeExtend = class(TDummy)
  12. private
  13. FMaterialSourceFaceFront, FMaterialSourceFaceRight, FMaterialSourceFaceBack,
  14. FMaterialSourceFaceLeft, FMaterialSourceFaceTop, FMaterialSourceFaceBottom
  15. : TMaterialSource;
  16. fSubdivisionsWidth, fSubdivisionsHeight, fSubdivisionsDepth: integer;
  17. fFaceFront, fFaceRight, fFaceBack, fFaceLeft, fFaceTop, fFaceBottom: TPlane;
  18. fFaceFrontVisible, fFaceRightVisible, fFaceBackVisible, fFaceLeftVisible,
  19. fFaceTopVisible, fFaceBottomVisible: boolean;
  20. fWidth, fDepth, fHeight: single;
  21. // Materials
  22. procedure SetMaterialSourceFaceFront(const Value: TMaterialSource);
  23. procedure SetMaterialSourceFaceBack(const Value: TMaterialSource);
  24. procedure SetMaterialSourceFaceBottom(const Value: TMaterialSource);
  25. procedure SetMaterialSourceFaceLeft(const Value: TMaterialSource);
  26. procedure SetMaterialSourceFaceRight(const Value: TMaterialSource);
  27. procedure SetMaterialSourceFaceTop(const Value: TMaterialSource);
  28. // Subdivisions
  29. procedure SetSubdivisionsDepth(const Value: integer);
  30. procedure SetSubdivisionsHeight(const Value: integer);
  31. procedure SetSubdivisionsWidth(const Value: integer);
  32. // Faces
  33. procedure SetFaceFrontVisible(const Value: boolean);
  34. procedure SetFaceRightVisible(const Value: boolean);
  35. procedure SetFaceBackVisible(const Value: boolean);
  36. procedure SetFaceLeftVisible(const Value: boolean);
  37. procedure SetFaceTopVisible(const Value: boolean);
  38. procedure SetFaceBottomVisible(const Value: boolean);
  39. // Drawing
  40. procedure DrawCube;
  41. procedure SetDepth(const Value: single);
  42. procedure SetHeight(const Value: single);
  43. procedure SetWidth(const Value: single);
  44. protected
  45. public
  46. constructor Create(AOwner: TComponent); override;
  47. destructor Destroy; override;
  48. published
  49. property SubdivisionsDepth: integer read fSubdivisionsDepth
  50. write SetSubdivisionsDepth;
  51. property SubdivisionsHeight: integer read fSubdivisionsHeight
  52. write SetSubdivisionsHeight;
  53. property SubdivisionsWidth: integer read fSubdivisionsWidth
  54. write SetSubdivisionsWidth;
  55. property MaterialSourceFaceFront: TMaterialSource
  56. read FMaterialSourceFaceFront write SetMaterialSourceFaceFront;
  57. property MaterialSourceFaceRight: TMaterialSource
  58. read FMaterialSourceFaceRight write SetMaterialSourceFaceRight;
  59. property MaterialSourceFaceBack: TMaterialSource
  60. read FMaterialSourceFaceBack write SetMaterialSourceFaceBack;
  61. property MaterialSourceFaceLeft: TMaterialSource
  62. read FMaterialSourceFaceLeft write SetMaterialSourceFaceLeft;
  63. property MaterialSourceFaceTop: TMaterialSource read FMaterialSourceFaceTop
  64. write SetMaterialSourceFaceTop;
  65. property MaterialSourceFaceBottom: TMaterialSource
  66. read FMaterialSourceFaceBottom write SetMaterialSourceFaceBottom;
  67. property Width: single read fWidth write SetWidth;
  68. property Height: single read fHeight write SetHeight;
  69. property Depth: single read fDepth write SetDepth;
  70. property FaceFrontVisible: boolean read fFaceFrontVisible
  71. write SetFaceFrontVisible;
  72. property FaceRightVisible: boolean read fFaceRightVisible
  73. write SetFaceRightVisible;
  74. property FaceBackVisible: boolean read fFaceBackVisible
  75. write SetFaceBackVisible;
  76. property FaceLeftVisible: boolean read fFaceLeftVisible
  77. write SetFaceLeftVisible;
  78. property FaceTopVisible: boolean read fFaceTopVisible
  79. write SetFaceTopVisible;
  80. property FaceBottomVisible: boolean read fFaceBottomVisible
  81. write SetFaceBottomVisible;
  82. end;
  83. procedure Register;
  84. implementation // -------------------------------------------------------------
  85. // TGBECube
  86. constructor TGBECubeExtend.Create(AOwner: TComponent);
  87. begin
  88. inherited;
  89. fWidth := 1;
  90. fHeight := 1;
  91. fDepth := 1;
  92. fSubdivisionsHeight := 1;
  93. fSubdivisionsWidth := 1;
  94. fSubdivisionsDepth := 1;
  95. fFaceFront := TPlane.Create(nil);
  96. fFaceFront.Parent := self;
  97. fFaceFront.Stored := false;
  98. fFaceFront.HitTest := false;
  99. fFaceFront.Locked := true;
  100. fFaceRight := TPlane.Create(nil);
  101. fFaceRight.Parent := self;
  102. fFaceRight.Stored := false;
  103. fFaceRight.HitTest := false;
  104. fFaceRight.Locked := true;
  105. fFaceBack := TPlane.Create(nil);
  106. fFaceBack.Parent := self;
  107. fFaceBack.Stored := false;
  108. fFaceBack.HitTest := false;
  109. fFaceBack.Locked := true;
  110. fFaceLeft := TPlane.Create(nil);
  111. fFaceLeft.Parent := self;
  112. fFaceLeft.Stored := false;
  113. fFaceLeft.HitTest := false;
  114. fFaceLeft.Locked := true;
  115. fFaceTop := TPlane.Create(nil);
  116. fFaceTop.Parent := self;
  117. fFaceTop.Stored := false;
  118. fFaceTop.HitTest := false;
  119. fFaceTop.Locked := true;
  120. fFaceBottom := TPlane.Create(nil);
  121. fFaceBottom.Parent := self;
  122. fFaceBottom.Stored := false;
  123. fFaceBottom.HitTest := false;
  124. fFaceBottom.Locked := true;
  125. fFaceFrontVisible := true;
  126. fFaceRightVisible := true;
  127. fFaceBackVisible := true;
  128. fFaceLeftVisible := true;
  129. fFaceTopVisible := true;
  130. fFaceBottomVisible := true;
  131. DrawCube;
  132. end;
  133. destructor TGBECubeExtend.Destroy;
  134. begin
  135. DeleteChildren;
  136. inherited;
  137. end;
  138. procedure TGBECubeExtend.DrawCube;
  139. begin
  140. fFaceFront.Visible := fFaceFrontVisible;
  141. if fFaceFrontVisible then
  142. begin
  143. fFaceFront.SubdivisionsHeight := fSubdivisionsHeight;
  144. fFaceFront.SubdivisionsWidth := fSubdivisionsWidth;
  145. end
  146. else
  147. begin
  148. fFaceFront.SubdivisionsHeight := 1;
  149. fFaceFront.SubdivisionsWidth := 1;
  150. end;
  151. fFaceRight.Visible := fFaceRightVisible;
  152. if fFaceRightVisible then
  153. begin
  154. fFaceRight.SubdivisionsHeight := fSubdivisionsHeight;
  155. fFaceRight.SubdivisionsWidth := fSubdivisionsWidth;
  156. end
  157. else
  158. begin
  159. fFaceRight.SubdivisionsHeight := 1;
  160. fFaceRight.SubdivisionsWidth := 1;
  161. end;
  162. fFaceBack.Visible := fFaceBackVisible;
  163. if fFaceBackVisible then
  164. begin
  165. fFaceBack.SubdivisionsHeight := fSubdivisionsHeight;
  166. fFaceBack.SubdivisionsWidth := fSubdivisionsWidth;
  167. end
  168. else
  169. begin
  170. fFaceBack.SubdivisionsHeight := 1;
  171. fFaceBack.SubdivisionsWidth := 1;
  172. end;
  173. fFaceLeft.Visible := fFaceLeftVisible;
  174. if fFaceLeftVisible then
  175. begin
  176. fFaceLeft.SubdivisionsHeight := fSubdivisionsHeight;
  177. fFaceLeft.SubdivisionsWidth := fSubdivisionsWidth;
  178. end
  179. else
  180. begin
  181. fFaceLeft.SubdivisionsHeight := 1;
  182. fFaceLeft.SubdivisionsWidth := 1;
  183. end;
  184. fFaceTop.Visible := fFaceTopVisible;
  185. if fFaceTopVisible then
  186. begin
  187. fFaceTop.SubdivisionsHeight := fSubdivisionsHeight;
  188. fFaceTop.SubdivisionsWidth := fSubdivisionsWidth;
  189. end
  190. else
  191. begin
  192. fFaceTop.SubdivisionsHeight := 1;
  193. fFaceTop.SubdivisionsWidth := 1;
  194. end;
  195. fFaceBottom.Visible := fFaceBottomVisible;
  196. if fFaceBottomVisible then
  197. begin
  198. fFaceBottom.SubdivisionsHeight := fSubdivisionsHeight;
  199. fFaceBottom.SubdivisionsWidth := fSubdivisionsWidth;
  200. end
  201. else
  202. begin
  203. fFaceBottom.SubdivisionsHeight := 1;
  204. fFaceBottom.SubdivisionsWidth := 1;
  205. end;
  206. fFaceFront.Position.X := 0;
  207. fFaceFront.Position.Y := 0;
  208. fFaceFront.Position.Z := -Depth * 0.5;
  209. fFaceRight.Position.X := Width * 0.5;
  210. fFaceRight.Position.Y := 0;
  211. fFaceRight.Position.Z := 0;
  212. fFaceRight.RotationAngle.Y := -90;
  213. fFaceBack.Position.X := 0;
  214. fFaceBack.Position.Y := 0;
  215. fFaceBack.Position.Z := Depth * 0.5;
  216. fFaceBack.RotationAngle.Y := 180;
  217. fFaceLeft.Position.X := -Width * 0.5;
  218. fFaceLeft.Position.Y := 0;
  219. fFaceLeft.Position.Z := 0;
  220. fFaceLeft.RotationAngle.Y := 90;
  221. fFaceTop.Position.X := 0;
  222. fFaceTop.Position.Y := -Height * 0.5;
  223. fFaceTop.Position.Z := 0;
  224. fFaceTop.RotationAngle.X := -90;
  225. fFaceBottom.Position.X := 0;
  226. fFaceBottom.Position.Y := Height * 0.5;
  227. fFaceBottom.Position.Z := 0;
  228. fFaceBottom.RotationAngle.X := 90;
  229. end;
  230. procedure TGBECubeExtend.SetDepth(const Value: single);
  231. begin
  232. fDepth := Value;
  233. fFaceFront.Depth := Value;
  234. fFaceRight.Width := Value;
  235. fFaceBack.Depth := Value;
  236. fFaceLeft.Width := Value;
  237. fFaceTop.Height := Value;
  238. fFaceBottom.Height := Value;
  239. DrawCube;
  240. end;
  241. procedure TGBECubeExtend.SetFaceBackVisible(const Value: boolean);
  242. begin
  243. fFaceBackVisible := Value;
  244. DrawCube;
  245. end;
  246. procedure TGBECubeExtend.SetFaceBottomVisible(const Value: boolean);
  247. begin
  248. fFaceBottomVisible := Value;
  249. DrawCube;
  250. end;
  251. procedure TGBECubeExtend.SetFaceFrontVisible(const Value: boolean);
  252. begin
  253. fFaceFrontVisible := Value;
  254. DrawCube;
  255. end;
  256. procedure TGBECubeExtend.SetFaceLeftVisible(const Value: boolean);
  257. begin
  258. fFaceLeftVisible := Value;
  259. DrawCube;
  260. end;
  261. procedure TGBECubeExtend.SetFaceRightVisible(const Value: boolean);
  262. begin
  263. fFaceRightVisible := Value;
  264. DrawCube;
  265. end;
  266. procedure TGBECubeExtend.SetFaceTopVisible(const Value: boolean);
  267. begin
  268. fFaceTopVisible := Value;
  269. DrawCube;
  270. end;
  271. procedure TGBECubeExtend.SetHeight(const Value: single);
  272. begin
  273. fHeight := Value;
  274. fFaceFront.Height := Value;
  275. fFaceRight.Height := Value;
  276. fFaceBack.Height := Value;
  277. fFaceLeft.Height := Value;
  278. DrawCube;
  279. end;
  280. procedure TGBECubeExtend.SetMaterialSourceFaceBack
  281. (const Value: TMaterialSource);
  282. begin
  283. FMaterialSourceFaceBack := Value;
  284. fFaceBack.MaterialSource := Value;
  285. end;
  286. procedure TGBECubeExtend.SetMaterialSourceFaceBottom
  287. (const Value: TMaterialSource);
  288. begin
  289. FMaterialSourceFaceBottom := Value;
  290. fFaceBottom.MaterialSource := Value;
  291. end;
  292. procedure TGBECubeExtend.SetMaterialSourceFaceFront
  293. (const Value: TMaterialSource);
  294. begin
  295. FMaterialSourceFaceFront := Value;
  296. fFaceFront.MaterialSource := Value;
  297. end;
  298. procedure TGBECubeExtend.SetMaterialSourceFaceLeft
  299. (const Value: TMaterialSource);
  300. begin
  301. FMaterialSourceFaceLeft := Value;
  302. fFaceLeft.MaterialSource := Value;
  303. end;
  304. procedure TGBECubeExtend.SetMaterialSourceFaceRight
  305. (const Value: TMaterialSource);
  306. begin
  307. FMaterialSourceFaceRight := Value;
  308. fFaceRight.MaterialSource := Value;
  309. end;
  310. procedure TGBECubeExtend.SetMaterialSourceFaceTop(const Value: TMaterialSource);
  311. begin
  312. FMaterialSourceFaceTop := Value;
  313. fFaceTop.MaterialSource := Value;
  314. end;
  315. procedure TGBECubeExtend.SetSubdivisionsDepth(const Value: integer);
  316. begin
  317. fSubdivisionsDepth := Value;
  318. fFaceRight.SubdivisionsWidth := Value;
  319. fFaceLeft.SubdivisionsWidth := Value;
  320. fFaceTop.SubdivisionsHeight := Value;
  321. fFaceBottom.SubdivisionsHeight := Value;
  322. DrawCube;
  323. end;
  324. procedure TGBECubeExtend.SetSubdivisionsHeight(const Value: integer);
  325. begin
  326. fSubdivisionsHeight := Value;
  327. fFaceFront.SubdivisionsHeight := Value;
  328. fFaceBack.SubdivisionsHeight := Value;
  329. fFaceLeft.SubdivisionsHeight := Value;
  330. fFaceRight.SubdivisionsHeight := Value;
  331. DrawCube;
  332. end;
  333. procedure TGBECubeExtend.SetSubdivisionsWidth(const Value: integer);
  334. begin
  335. fSubdivisionsWidth := Value;
  336. fFaceFront.SubdivisionsWidth := Value;
  337. fFaceBack.SubdivisionsWidth := Value;
  338. fFaceTop.SubdivisionsWidth := Value;
  339. fFaceBottom.SubdivisionsWidth := Value;
  340. DrawCube;
  341. end;
  342. procedure TGBECubeExtend.SetWidth(const Value: single);
  343. begin
  344. fWidth := Value;
  345. fFaceFront.Width := Value;
  346. fFaceRight.Depth := Value;
  347. fFaceBack.Width := Value;
  348. fFaceLeft.Depth := Value;
  349. fFaceTop.Width := Value;
  350. fFaceBottom.Width := Value;
  351. DrawCube;
  352. end;
  353. // ----------------------------------------------------------------------------
  354. procedure Register;
  355. begin
  356. RegisterComponents('GXScene GBE', [TGBECubeExtend]);
  357. end;
  358. end.