| 1 |
{%MainUnit x3dfields.pas} |
| 2 |
{ |
| 3 |
Copyright 2002-2023 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 |
{ Global utilities related to X3D fields. } |
| 18 |
{$ifdef read_interface} |
| 19 |
|
| 20 |
{ Decode color from integer value, following VRML/X3D SFImage specification. |
| 21 |
@groupBegin } |
| 22 |
procedure DecodeX3DColor(const Pixel: UInt32; var G: Byte); overload; |
| 23 |
procedure DecodeX3DColor(const Pixel: UInt32; var GA: TVector2Byte); overload; |
| 24 |
procedure DecodeX3DColor(const Pixel: UInt32; var RGB: TVector3Byte); overload; |
| 25 |
procedure DecodeX3DColor(const Pixel: UInt32; var RGBA: TVector4Byte); overload; |
| 26 |
|
| 27 |
procedure DecodeX3DColor(const Pixel: Int32; var G: Byte); overload; |
| 28 |
procedure DecodeX3DColor(const Pixel: Int32; var GA: TVector2Byte); overload; |
| 29 |
procedure DecodeX3DColor(const Pixel: Int32; var RGB: TVector3Byte); overload; |
| 30 |
procedure DecodeX3DColor(const Pixel: Int32; var RGBA: TVector4Byte); overload; |
| 31 |
{ @groupEnd } |
| 32 |
|
| 33 |
const |
| 34 |
X3DChangeToStr: array [TX3DChange] of string = ( |
| 35 |
'None', |
| 36 |
'Visible Geometry', |
| 37 |
'Visible Non-Geometry', |
| 38 |
'Redisplay', |
| 39 |
'Transform', |
| 40 |
'Coordinate', |
| 41 |
'Normal', |
| 42 |
'Tangent', |
| 43 |
'VRML 1.0 State (but not affecting geometry or Coordinate)', |
| 44 |
'VRML 1.0 State (affecting geometry, but not Coordinate)', |
| 45 |
'Light active property', |
| 46 |
'Light location/direction', |
| 47 |
'Light for shadow volumes', |
| 48 |
'Switch choice', |
| 49 |
'Color node', |
| 50 |
'Texture coordinate', |
| 51 |
'Texture transform', |
| 52 |
'Geometry', |
| 53 |
'Geometry + FontChanged', |
| 54 |
'Environmental sensor bounds', |
| 55 |
'Time stop/start/pause/resume', |
| 56 |
'Viewpoint vectors', |
| 57 |
'Viewpoint projection', |
| 58 |
'Texture image', |
| 59 |
'Texture renderer properties', |
| 60 |
'TextureProperties node', |
| 61 |
'Shadow caster', |
| 62 |
'Generated texture update', |
| 63 |
'FontStyle', |
| 64 |
'FontStyle + FontChanged', |
| 65 |
'HeadLight on', |
| 66 |
'ClipPlane', |
| 67 |
'X3DDragSensorNode.enabled', |
| 68 |
'NavigationInfo', |
| 69 |
'ScreenEffect.enabled', |
| 70 |
'Background', |
| 71 |
'Everything', |
| 72 |
'Shadow maps', |
| 73 |
'Wireframe', |
| 74 |
'Children', |
| 75 |
'Children added', |
| 76 |
'BBox' |
| 77 |
); |
| 78 |
|
| 79 |
function X3DChangesToStr(const Changes: TX3DChanges): string; |
| 80 |
|
| 81 |
var |
| 82 |
{ Float output precision, for outputting 3D models (X3D text encodings, |
| 83 |
in the future also glTF - the JSON parts). |
| 84 |
Not for serializing to CGE JSON using CastleComponentSerialize, |
| 85 |
which shall always use maximum precision. } |
| 86 |
FloatOutputFormat: String = '%g'; |
| 87 |
|
| 88 |
{$endif read_interface} |
| 89 |
|
| 90 |
{$ifdef read_implementation} |
| 91 |
|
| 92 |
procedure DecodeX3DColor(const Pixel: UInt32; var G: Byte); |
| 93 |
begin |
| 94 |
G := Pixel and $FF; |
| 95 |
end; |
| 96 |
|
| 97 |
procedure DecodeX3DColor(const Pixel: UInt32; var GA: TVector2Byte); |
| 98 |
begin |
| 99 |
GA.X := (pixel shr 8) and $FF; |
| 100 |
GA.Y := pixel and $FF; |
| 101 |
end; |
| 102 |
|
| 103 |
procedure DecodeX3DColor(const Pixel: UInt32; var RGB: TVector3Byte); |
| 104 |
begin |
| 105 |
RGB.X := (pixel shr 16) and $FF; |
| 106 |
RGB.Y := (pixel shr 8) and $FF; |
| 107 |
RGB.Z := pixel and $FF; |
| 108 |
end; |
| 109 |
|
| 110 |
procedure DecodeX3DColor(const Pixel: UInt32; var RGBA: TVector4Byte); |
| 111 |
begin |
| 112 |
RGBA.X := (pixel shr 24) and $FF; |
| 113 |
RGBA.Y := (pixel shr 16) and $FF; |
| 114 |
RGBA.Z := (pixel shr 8) and $FF; |
| 115 |
RGBA.W := pixel and $FF; |
| 116 |
end; |
| 117 |
|
| 118 |
{ We have to turn range checking off, because converting from Int32 |
| 119 |
to UInt32 below may cause range check errors. Yes, we want to |
| 120 |
directly treat Int32 as 4 bytes here, because DecodeX3DColor |
| 121 |
works on separate bytes. See |
| 122 |
https://castle-engine.io/x3d_implementation_texturing3d.php |
| 123 |
comments about PixelTexture3D. } |
| 124 |
|
| 125 |
{$include norqcheckbegin.inc} |
| 126 |
|
| 127 |
procedure DecodeX3DColor(const Pixel: Int32; var G: Byte); |
| 128 |
begin |
| 129 |
DecodeX3DColor(UInt32(Pixel), G); |
| 130 |
end; |
| 131 |
|
| 132 |
procedure DecodeX3DColor(const Pixel: Int32; var GA: TVector2Byte); |
| 133 |
begin |
| 134 |
DecodeX3DColor(UInt32(Pixel), GA); |
| 135 |
end; |
| 136 |
|
| 137 |
procedure DecodeX3DColor(const Pixel: Int32; var RGB: TVector3Byte); |
| 138 |
begin |
| 139 |
DecodeX3DColor(UInt32(Pixel), RGB); |
| 140 |
end; |
| 141 |
|
| 142 |
procedure DecodeX3DColor(const Pixel: Int32; var RGBA: TVector4Byte); |
| 143 |
begin |
| 144 |
DecodeX3DColor(UInt32(Pixel), RGBA); |
| 145 |
end; |
| 146 |
|
| 147 |
{$include norqcheckend.inc} |
| 148 |
|
| 149 |
function X3DChangesToStr(const Changes: TX3DChanges): string; |
| 150 |
var |
| 151 |
C: TX3DChange; |
| 152 |
begin |
| 153 |
Result := ''; |
| 154 |
for C := Low(C) to High(C) do |
| 155 |
if C in Changes then |
| 156 |
begin |
| 157 |
if Result <> '' then Result := Result + ','; |
| 158 |
Result := Result + X3DChangeToStr[C]; |
| 159 |
end; |
| 160 |
Result := '[' + Result + ']'; |
| 161 |
end; |
| 162 |
|
| 163 |
{$endif read_implementation} |