| 1 |
{%MainUnit x3dfields.pas} |
| 2 |
{ |
| 3 |
Copyright 2002-2018 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 |
{ Stores information about available VRML/X3D field classes. |
| 20 |
The only use for now is to make a mapping from VRML/X3D field name to |
| 21 |
actual class (needed by VRML/X3D interface declarations). } |
| 22 |
TX3DFieldsManager = class |
| 23 |
strict private |
| 24 |
Registered: TStringList; |
| 25 |
public |
| 26 |
constructor Create; |
| 27 |
destructor Destroy; override; |
| 28 |
|
| 29 |
procedure RegisterClass(AClass: TX3DFieldClass); |
| 30 |
procedure RegisterClasses(const Classes: array of TX3DFieldClass); |
| 31 |
|
| 32 |
{ Return field class for given name. Returns @nil if not found. } |
| 33 |
function X3DTypeToClass(const X3DType: string): TX3DFieldClass; |
| 34 |
end; |
| 35 |
|
| 36 |
function X3DFieldsManager: TX3DFieldsManager; |
| 37 |
|
| 38 |
{$endif read_interface} |
| 39 |
|
| 40 |
{$ifdef read_implementation} |
| 41 |
|
| 42 |
{ TX3DFieldsManager --------------------------------------------------------- } |
| 43 |
|
| 44 |
constructor TX3DFieldsManager.Create; |
| 45 |
begin |
| 46 |
inherited; |
| 47 |
Registered := TStringList.Create; |
| 48 |
{ All VRML/X3D names are case-sensitive. } |
| 49 |
Registered.CaseSensitive := true; |
| 50 |
|
| 51 |
RegisterClasses([ |
| 52 |
TSFBitMask, |
| 53 |
TSFEnum, |
| 54 |
TSFBool, TMFBool, |
| 55 |
TSFFloat, TMFFloat, |
| 56 |
TSFImage, |
| 57 |
TSFLong, TMFLong, |
| 58 |
TSFInt32, TMFInt32, |
| 59 |
|
| 60 |
TSFMatrix3f, TMFMatrix3f, |
| 61 |
TSFMatrix, |
| 62 |
TSFMatrix3d, TMFMatrix3d, |
| 63 |
TSFMatrix4f, TMFMatrix4f, |
| 64 |
TSFMatrix4d, TMFMatrix4d, |
| 65 |
|
| 66 |
TSFRotation, TMFRotation, |
| 67 |
TSFString, TMFString, |
| 68 |
TSFDouble, TMFDouble, |
| 69 |
TSFTime, TMFTime, |
| 70 |
TSFVec2f, TMFVec2f, |
| 71 |
TSFVec3f, TMFVec3f, |
| 72 |
TSFColor, TMFColor, |
| 73 |
TSFVec4f, TMFVec4f, |
| 74 |
TSFVec2d, TMFVec2d, |
| 75 |
TSFVec3d, TMFVec3d, |
| 76 |
TSFVec4d, TMFVec4d, |
| 77 |
TSFColorRGBA,TMFColorRGBA |
| 78 |
]); |
| 79 |
end; |
| 80 |
|
| 81 |
destructor TX3DFieldsManager.Destroy; |
| 82 |
begin |
| 83 |
FreeAndNil(Registered); |
| 84 |
inherited; |
| 85 |
end; |
| 86 |
|
| 87 |
procedure TX3DFieldsManager.RegisterClass(AClass: TX3DFieldClass); |
| 88 |
begin |
| 89 |
Registered.AddObject(AClass.X3DType, TObject(AClass)); |
| 90 |
end; |
| 91 |
|
| 92 |
procedure TX3DFieldsManager.RegisterClasses( |
| 93 |
const Classes: array of TX3DFieldClass); |
| 94 |
var |
| 95 |
I: Integer; |
| 96 |
begin |
| 97 |
for I := 0 to High(Classes) do |
| 98 |
RegisterClass(Classes[I]); |
| 99 |
end; |
| 100 |
|
| 101 |
function TX3DFieldsManager.X3DTypeToClass( |
| 102 |
const X3DType: string): TX3DFieldClass; |
| 103 |
var |
| 104 |
I: Integer; |
| 105 |
begin |
| 106 |
I := Registered.IndexOf(X3DType); |
| 107 |
if I <> -1 then |
| 108 |
Result := TX3DFieldClass(Registered.Objects[I]) else |
| 109 |
Result := nil; |
| 110 |
end; |
| 111 |
|
| 112 |
var |
| 113 |
FX3DFieldsManager: TX3DFieldsManager; |
| 114 |
|
| 115 |
function X3DFieldsManager: TX3DFieldsManager; |
| 116 |
{ This function automatically creates FX3DFieldsManager instance. |
| 117 |
I don't do this in initialization of this unit, since (because |
| 118 |
of circular uses clauses) X3DFieldsManager may be referenced |
| 119 |
before our initialization (e.g. by initialization of X3DNodes). } |
| 120 |
begin |
| 121 |
if FX3DFieldsManager = nil then |
| 122 |
FX3DFieldsManager := TX3DFieldsManager.Create; |
| 123 |
Result := FX3DFieldsManager; |
| 124 |
end; |
| 125 |
|
| 126 |
{$endif read_implementation} |