| 1 |
{%MainUnit x3dnodes.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 |
{ Not recognized VRML/X3D node type. Used for nodes found when parsing |
| 20 |
VRML/X3D file that are not implemented. |
| 21 |
|
| 22 |
TX3DUnknownNode is parsed (in classic VRML encoding) in a special way, |
| 23 |
to be able to omit it gracefully. |
| 24 |
While such "unknown" node doesn't really do match in our graph, |
| 25 |
it works correctly with VRML/X3D DEF/USE mechanism. |
| 26 |
|
| 27 |
Never instantiate this class by a standard constructor. |
| 28 |
Always use CreateUnknown constructor, this way we can safely assume |
| 29 |
that X3DType is always correctly set. } |
| 30 |
TX3DUnknownNode = class(TX3DNode) |
| 31 |
strict private |
| 32 |
fX3DType: string; |
| 33 |
protected |
| 34 |
function DeepCopyCreate(CopyState: TX3DNodeDeepCopyState): TX3DNode; override; |
| 35 |
public |
| 36 |
function X3DType: string; override; |
| 37 |
procedure Parse(Lexer: TX3DLexer; Reader: TX3DReaderNames); override; |
| 38 |
|
| 39 |
{ base Create will throw exception. Always use CreateUnknown* } |
| 40 |
constructor Create(const AName: string; const ABaseUrl: String); override; |
| 41 |
|
| 42 |
constructor CreateUnknown(const AName, ABaseUrl: String; const AX3DType :string); |
| 43 |
end; |
| 44 |
|
| 45 |
{$endif read_interface} |
| 46 |
|
| 47 |
{$ifdef read_implementation} |
| 48 |
|
| 49 |
{ TX3DUnknownNode ---------------------------------------------------------------- } |
| 50 |
|
| 51 |
function TX3DUnknownNode.X3DType: string; |
| 52 |
begin |
| 53 |
result := fX3DType; |
| 54 |
end; |
| 55 |
|
| 56 |
procedure TX3DUnknownNode.Parse(Lexer: TX3DLexer; Reader: TX3DReaderNames); |
| 57 |
|
| 58 |
(*TODO: use "fields" and "isA" VRML 1.0 extensibility features here. |
| 59 |
|
| 60 |
For now, we just always parse up to the matching closing "}". |
| 61 |
The VRML1Children*Allowed is set to false. |
| 62 |
|
| 63 |
We should handle: |
| 64 |
|
| 65 |
- node that has "fields", but not "isA" field (or "isA" points to |
| 66 |
another unknown node name). In this case we can create Fields |
| 67 |
array and parse fields of this node. We will not know how to handle |
| 68 |
this node anyway, but at least we'll know it's fields names and values, |
| 69 |
and we'll be able to save it back to stream. |
| 70 |
|
| 71 |
The VRML1Children*Allowed set to true? To allow it to work like |
| 72 |
VRML 1.0 Group? |
| 73 |
|
| 74 |
- node that has "fields" and valid "isA". In this case we can create Fields |
| 75 |
array, parse fields of this node. Then create a helper node |
| 76 |
of type given by "isA", and replace (or add as a child) |
| 77 |
our TX3DUnknownNode by this helper node. |
| 78 |
|
| 79 |
The VRML1Children*Allowed should be copied from referred "isA" node. |
| 80 |
*) |
| 81 |
begin |
| 82 |
{ In TX3DUnknownNode case, VRML1Children*Allowed must be initialized during |
| 83 |
parsing. } |
| 84 |
VRML1ChildrenAllowed := false; |
| 85 |
VRML1ChildrenParsingAllowed := false; |
| 86 |
|
| 87 |
Lexer.CheckTokenIs(vtOpenCurlyBracket); |
| 88 |
Lexer.NextToken; |
| 89 |
ParseIgnoreToMatchingCurlyBracket(Lexer, Reader); |
| 90 |
|
| 91 |
FBaseUrl := Reader.BaseUrl; |
| 92 |
|
| 93 |
WritelnWarning('VRML/X3D', 'Unknown node of type "'+ X3DType + '" (named "'+ X3DName +'")'); |
| 94 |
end; |
| 95 |
|
| 96 |
constructor TX3DUnknownNode.Create(const AName: string; const ABaseUrl: String); |
| 97 |
begin |
| 98 |
{ Safety check: never create a TX3DUnknownNode instance by this method, |
| 99 |
to not leave FX3DType unset. } |
| 100 |
raise Exception.Create('You cannot create Unknown node using default constructor'); |
| 101 |
end; |
| 102 |
|
| 103 |
constructor TX3DUnknownNode.CreateUnknown(const AName, ABaseUrl: String; const AX3DType :string); |
| 104 |
begin |
| 105 |
inherited Create(AName, ABaseUrl); |
| 106 |
fX3DType := AX3DType; |
| 107 |
end; |
| 108 |
|
| 109 |
function TX3DUnknownNode.DeepCopyCreate( |
| 110 |
CopyState: TX3DNodeDeepCopyState): TX3DNode; |
| 111 |
begin |
| 112 |
Result := TX3DUnknownNode.CreateUnknown(X3DName, BaseUrl, X3DType); |
| 113 |
end; |
| 114 |
|
| 115 |
{$endif read_implementation} |