| 1 |
{ |
| 2 |
Copyright 2008-2018 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 |
{$ifdef read_implementation_nested} |
| 17 |
var |
| 18 |
{ List of Collada visual scenes, for <visual_scene> Collada elements. |
| 19 |
Every visual scene is X3D TAbstractGroupingNode instance. |
| 20 |
This is for Collada >= 1.4.x (for Collada < 1.4.x, |
| 21 |
the <scene> element is directly placed as a rendered scene). } |
| 22 |
VisualScenes: TX3DChildrenList; |
| 23 |
|
| 24 |
{ Read <visual_scene>. Obtained scene X3D node is added both |
| 25 |
to VisualScenes list and VisualScenesSwitch.choice. } |
| 26 |
procedure ReadVisualScene(VisualScenesSwitch: TSwitchNode; |
| 27 |
VisualSceneElement: TDOMElement); |
| 28 |
var |
| 29 |
VisualSceneId: string; |
| 30 |
Group: TGroupNode; |
| 31 |
begin |
| 32 |
if not VisualSceneElement.AttributeString('id', VisualSceneId) then |
| 33 |
VisualSceneId := ''; |
| 34 |
|
| 35 |
Group := TGroupNode.Create(VisualSceneId, BaseUrl); |
| 36 |
VisualScenes.Add(Group); |
| 37 |
VisualScenesSwitch.AddChildren(Group); |
| 38 |
|
| 39 |
ReadNodesSequence(Group, VisualSceneElement); |
| 40 |
end; |
| 41 |
|
| 42 |
{ Read <library_visual_scenes> from Collada 1.4.x } |
| 43 |
procedure ReadLibraryVisualScenes(LibraryElement: TDOMElement); |
| 44 |
var |
| 45 |
I: TXMLElementIterator; |
| 46 |
LibraryId: string; |
| 47 |
VisualScenesSwitch: TSwitchNode; |
| 48 |
begin |
| 49 |
if not LibraryElement.AttributeString('id', LibraryId) then |
| 50 |
LibraryId := ''; |
| 51 |
|
| 52 |
{ Library of visual scenes is simply a X3D Switch, with each |
| 53 |
scene inside as one choice. This way we export to X3D all |
| 54 |
scenes from Collada, even those not chosen as current scene. |
| 55 |
That's good --- it's always nice to keep some data when |
| 56 |
converting. } |
| 57 |
|
| 58 |
VisualScenesSwitch := TSwitchNode.Create(LibraryId, BaseUrl); |
| 59 |
ResultModel.AddChildren(VisualScenesSwitch); |
| 60 |
|
| 61 |
I := LibraryElement.ChildrenIterator('visual_scene'); |
| 62 |
try |
| 63 |
while I.GetNext do |
| 64 |
ReadVisualScene(VisualScenesSwitch, I.Current); |
| 65 |
{ other I.Current.TagName not supported for now } |
| 66 |
finally FreeAndNil(I) end; |
| 67 |
end; |
| 68 |
|
| 69 |
{ Read <scene> element. } |
| 70 |
procedure ReadSceneElement(SceneElement: TDOMElement); |
| 71 |
var |
| 72 |
SceneId: string; |
| 73 |
|
| 74 |
procedure Collada14; |
| 75 |
var |
| 76 |
InstanceVisualScene: TDOMElement; |
| 77 |
VisualSceneId: string; |
| 78 |
VisualScene: TAbstractChildNode; |
| 79 |
begin |
| 80 |
InstanceVisualScene := SceneElement.ChildElement( |
| 81 |
'instance_visual_scene', false); |
| 82 |
if InstanceVisualScene <> nil then |
| 83 |
begin |
| 84 |
if InstanceVisualScene.AttributeString('url', VisualSceneId) and |
| 85 |
SCharIs(VisualSceneId, 1, '#') then |
| 86 |
begin |
| 87 |
Delete(VisualSceneId, 1, 1); |
| 88 |
VisualScene := VisualScenes.FindName(VisualSceneId); |
| 89 |
if VisualScene = nil then |
| 90 |
WritelnWarning('Collada', Format('<instance_visual_scene> instantiates non-existing ' + |
| 91 |
'<visual_scene> element "%s"', [VisualSceneId])) else |
| 92 |
ResultModel.AddChildren(VisualScene); |
| 93 |
end; |
| 94 |
end; |
| 95 |
end; |
| 96 |
|
| 97 |
procedure Collada13; |
| 98 |
var |
| 99 |
Group: TGroupNode; |
| 100 |
begin |
| 101 |
Group := TGroupNode.Create(SceneId, BaseUrl); |
| 102 |
ResultModel.AddChildren(Group); |
| 103 |
|
| 104 |
ReadNodesSequence(Group, SceneElement); |
| 105 |
end; |
| 106 |
|
| 107 |
begin |
| 108 |
if not SceneElement.AttributeString('id', SceneId) then |
| 109 |
SceneId := ''; |
| 110 |
|
| 111 |
{ <scene> element is different in two Collada versions, it's most clear |
| 112 |
to just branch and do different procedure depending on Collada version. } |
| 113 |
|
| 114 |
if Version14 then |
| 115 |
Collada14 else |
| 116 |
Collada13; |
| 117 |
end; |
| 118 |
|
| 119 |
{$endif read_implementation_nested} |