Debian Codegraph @

src/scene/x3d/castlefields_x3dreader.inc

raw
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 { Reading of VRML/X3D from stream.
20 Common knowledge for both classic and XML reader.
21 X3DNodes unit extends this into TX3DReaderNames. }
22 TX3DReader = class
23 strict private
24 FVersion: TX3DVersion;
25 FBaseUrl: String;
26 private
27 AngleConversionFactor: Float;
28 public
29 LengthConversionFactor: Float;
30
31 { Parent node, always TX3DNode, @nil if this is top-level.
32 Fow now only used to enhance DefaultContainerFieldInContext knowledge,
33 for XML encoding writing, though we maintain it for all encodings. }
34 ParentNode: TObject;
35
36 constructor Create(const ABaseUrl: String;
37 const AVersion: TX3DVersion);
38 constructor CreateCopy(Source: TX3DReader);
39
40 { Base path for resolving URLs from nodes in this namespace.
41 See TX3DNode.BaseUrl. }
42 property BaseUrl: String read FBaseUrl;
43
44 { VRML/X3D version number. For resolving node class names and other stuff. }
45 property Version: TX3DVersion read FVersion;
46
47 { Apply unit conversion.
48 If this is angle conversion factor, it is stored and used internally.
49 If this is length conversion factor, we update our
50 LengthConversionFactor property, but it's callers responsibility
51 to make use of it. (You want to use here TX3DRootNode.Scale.) }
52 procedure UnitConversion(const Category, Name: string;
53 const ConversionFactor: Float);
54 end;
55
56 {$endif read_interface}
57
58 {$ifdef read_implementation}
59
60 { TX3DReader ----------------------------------------------------------------- }
61
62 constructor TX3DReader.Create(
63 const ABaseUrl: String; const AVersion: TX3DVersion);
64 begin
65 inherited Create;
66 FBaseUrl := ABaseUrl;
67 FVersion := AVersion;
68 AngleConversionFactor := 1;
69 LengthConversionFactor := 1;
70 end;
71
72 constructor TX3DReader.CreateCopy(Source: TX3DReader);
73 begin
74 inherited Create;
75 FBaseUrl := Source.BaseUrl;
76 FVersion := Source.Version;
77 AngleConversionFactor := Source.AngleConversionFactor;
78 LengthConversionFactor := Source.LengthConversionFactor;
79 end;
80
81 procedure TX3DReader.UnitConversion(const Category, Name: string;
82 const ConversionFactor: Float);
83 begin
84 if (Version.Major < 3) or
85 ( (Version.Major = 3) and
86 (Version.Minor < 3) ) then
87 WritelnWarning('X3D', 'UNIT declaration found, but X3D version is < 3.3');
88
89 { store UNIT inside Reader }
90 if Category = 'angle' then
91 AngleConversionFactor := ConversionFactor else
92 if Category = 'force' then
93 { TODO } else
94 if Category = 'length' then
95 LengthConversionFactor := ConversionFactor else
96 if Category = 'mass' then
97 { TODO } else
98 WritelnWarning('X3D', FormatDot('UNIT category "%s" unknown. Only the categories listed in X3D specification as base units are allowed',
99 [Category]));
100 end;
101
102 {$endif read_implementation}