| 1 |
{ |
| 2 |
Copyright 2008-2020 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 |
|
| 16 |
{ Pass on command-line the URL (usually just a filename) |
| 17 |
of 3D model file and the name of placeholder detection routine |
| 18 |
(like "x3dshape" or "blender"). |
| 19 |
We will output information about detected placeholders in the file. |
| 20 |
|
| 21 |
For example, |
| 22 |
./placeholder_names model.x3d blender |
| 23 |
./placeholder_names ../fps_game/data/example_level/example_level.gltf blender |
| 24 |
will assume that model.x3d was created using standard Blender X3D exporter, |
| 25 |
and will show Blender object names for every shape in the model. |
| 26 |
|
| 27 |
See TLevel.Load for a description where we use |
| 28 |
placeholders in the engine. } |
| 29 |
program placeholder_names; |
| 30 |
|
| 31 |
{$ifdef MSWINDOWS} {$apptype CONSOLE} {$endif} |
| 32 |
|
| 33 |
uses SysUtils, CastleUtils, CastleShapes, CastleSceneCore, CastleParameters, |
| 34 |
X3DNodes; |
| 35 |
|
| 36 |
var |
| 37 |
PlaceholderName: TPlaceholderName; |
| 38 |
Scene: TCastleSceneCore; |
| 39 |
ShapeList: TShapeList; |
| 40 |
Shape: TShape; |
| 41 |
PlaceholderNameKey: string; |
| 42 |
begin |
| 43 |
{ show PlaceholderNames } |
| 44 |
Writeln(Format('Available placeholder detection methods (%d):', |
| 45 |
[PlaceholderNames.Count])); |
| 46 |
for PlaceholderNameKey in PlaceholderNames.Keys do |
| 47 |
Writeln(' ', PlaceholderNameKey); |
| 48 |
|
| 49 |
if Parameters.High = 0 then |
| 50 |
begin |
| 51 |
|
| 52 |
Writeln(NL+ |
| 53 |
'placeholder_names: Outputs information about detected placeholders in the scene file.' + NL + |
| 54 |
NL + |
| 55 |
'Call with 2 arguments:' + NL + |
| 56 |
'- URL (can be just a filename) of scene file' + NL + |
| 57 |
'- name of placeholder detection routine, see above for possible values' + NL + |
| 58 |
NL + |
| 59 |
'Examples:' + NL + |
| 60 |
' ./placeholder_names scene.x3d blender' + NL + |
| 61 |
' ./placeholder_names ../fps_game/data/example_level/example_level.gltf blender' |
| 62 |
); |
| 63 |
Halt(1); |
| 64 |
end; |
| 65 |
|
| 66 |
{ calculate PlaceholderName looking at command-line parameter } |
| 67 |
Parameters.CheckHigh(2); |
| 68 |
if not PlaceholderNames.TryGetValue(Parameters[2], PlaceholderName) then |
| 69 |
raise Exception.CreateFmt('Placeholder detection method "%s" not found', |
| 70 |
[Parameters[2]]); |
| 71 |
|
| 72 |
Scene := TCastleSceneCore.Create(nil); |
| 73 |
try |
| 74 |
Scene.Load(Parameters[1]); |
| 75 |
ShapeList := Scene.Shapes.TraverseList({ OnlyActive } true); |
| 76 |
for Shape in ShapeList do |
| 77 |
begin |
| 78 |
if PlaceholderName(Shape) <> '' then |
| 79 |
Writeln(Format('Detected placeholder "%s" for shape. Shape geometry node name "%s", geometry parent node name "%s", geometry grand-parent node name "%s", geometry grand-grand-parent node name "%s".', |
| 80 |
[PlaceholderName(Shape), |
| 81 |
Shape.OriginalGeometry.X3DName, |
| 82 |
Shape.GeometryParentNodeName, |
| 83 |
Shape.GeometryGrandParentNodeName, |
| 84 |
Shape.GeometryGrandGrandParentNodeName])); |
| 85 |
end; |
| 86 |
finally FreeAndNil(Scene) end; |
| 87 |
end. |