| 1 |
{ |
| 2 |
Copyright 2022-2023 Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
{ Main view, where most of the application logic takes place. } |
| 16 |
unit GameViewMain; |
| 17 |
|
| 18 |
interface |
| 19 |
|
| 20 |
uses Classes, |
| 21 |
CastleVectors, CastleComponentSerialize, |
| 22 |
CastleUIControls, CastleControls, CastleKeysMouse, CastleScene, X3DNodes; |
| 23 |
|
| 24 |
type |
| 25 |
{ Main view, where most of the application logic takes place. } |
| 26 |
TViewMain = class(TCastleView) |
| 27 |
published |
| 28 |
{ Components designed using CGE editor. |
| 29 |
These fields will be automatically initialized at Start. } |
| 30 |
LabelWasVisible, LabelFps: TCastleLabel; |
| 31 |
SceneTestBlocks: TCastleScene; |
| 32 |
private |
| 33 |
ShapeRed, ShapeGreen, ShapeBlue, ShapeWhite: TShapeNode; |
| 34 |
public |
| 35 |
constructor Create(AOwner: TComponent); override; |
| 36 |
procedure Start; override; |
| 37 |
procedure Update(const SecondsPassed: Single; var HandleInput: Boolean); override; |
| 38 |
end; |
| 39 |
|
| 40 |
var |
| 41 |
ViewMain: TViewMain; |
| 42 |
|
| 43 |
implementation |
| 44 |
|
| 45 |
uses SysUtils, |
| 46 |
CastleUtils; |
| 47 |
|
| 48 |
{ TViewMain ----------------------------------------------------------------- } |
| 49 |
|
| 50 |
constructor TViewMain.Create(AOwner: TComponent); |
| 51 |
begin |
| 52 |
inherited; |
| 53 |
DesignUrl := 'castle-data:/gameviewmain.castle-user-interface'; |
| 54 |
end; |
| 55 |
|
| 56 |
procedure TViewMain.Start; |
| 57 |
begin |
| 58 |
inherited; |
| 59 |
|
| 60 |
{ We get X3D Shape nodes knowing how the Blender->glTF exporter works, |
| 61 |
and then how glTF is converted into X3D nodes in CGE. |
| 62 |
|
| 63 |
- Each Blender object is X3D group (glTF transform node), |
| 64 |
- with Blender mesh inside as another X3D group (glTF mesh), |
| 65 |
- that contains a list of X3D shapes for each different material |
| 66 |
(one X3D shape is one glTF primitive). |
| 67 |
|
| 68 |
As all our Blender meshes have just 1 material, we just access the X3D shape |
| 69 |
node by accessing the 1st child or TGroupNode. |
| 70 |
|
| 71 |
To see the X3D nodes, just open ../data/test_blocks.gltf in castle-model-viewer |
| 72 |
and use "File -> Save As" to save it as X3DV file, and then read it |
| 73 |
in any text editor. } |
| 74 |
|
| 75 |
ShapeRed := (SceneTestBlocks.Node('RedMesh') as TGroupNode).FdChildren[0] as TShapeNode; |
| 76 |
ShapeGreen := (SceneTestBlocks.Node('GreenMesh') as TGroupNode).FdChildren[0] as TShapeNode; |
| 77 |
ShapeBlue := (SceneTestBlocks.Node('BlueMesh') as TGroupNode).FdChildren[0] as TShapeNode; |
| 78 |
ShapeWhite := (SceneTestBlocks.Node('WhiteMesh') as TGroupNode).FdChildren[0] as TShapeNode; |
| 79 |
end; |
| 80 |
|
| 81 |
procedure TViewMain.Update(const SecondsPassed: Single; var HandleInput: Boolean); |
| 82 |
begin |
| 83 |
inherited; |
| 84 |
LabelFps.Caption := 'FPS: ' + Container.Fps.ToString; |
| 85 |
LabelWasVisible.Caption := Format( |
| 86 |
'SceneTestBlocks.WasVisible = %s' + NL + |
| 87 |
'ShapeRed.WasVisible = %s' + NL + |
| 88 |
'ShapeGreen.WasVisible = %s' + NL + |
| 89 |
'ShapeBlue.WasVisible = %s' + NL + |
| 90 |
'ShapeWhite.WasVisible = %s', [ |
| 91 |
BoolToStr(SceneTestBlocks.WasVisible, true), |
| 92 |
BoolToStr(ShapeRed.WasVisible, true), |
| 93 |
BoolToStr(ShapeGreen.WasVisible, true), |
| 94 |
BoolToStr(ShapeBlue.WasVisible, true), |
| 95 |
BoolToStr(ShapeWhite.WasVisible, true) |
| 96 |
]); |
| 97 |
end; |
| 98 |
|
| 99 |
end. |