| 1 |
{%MainUnit x3dnodes.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 |
{$ifdef read_interface} |
| 18 |
{ } |
| 19 |
TCoordRangeHandler = procedure (const RangeNumber: Cardinal; |
| 20 |
BeginIndex, EndIndex: Integer) of object; |
| 21 |
|
| 22 |
TIndexedPolygonHandler = procedure (const Indexes: array of Cardinal) |
| 23 |
of object; |
| 24 |
|
| 25 |
ENotCoordinateBasedNode = class(EX3DError); |
| 26 |
|
| 27 |
{ Base node for a visible geometry in X3D. } |
| 28 |
TAbstractGeometryNode = class(TAbstractNode) |
| 29 |
strict private |
| 30 |
HasBounds2DST: boolean; |
| 31 |
Bounds2DS, Bounds2DT: T3DAxis; |
| 32 |
FIgnoredSolid: boolean; {< keeps value of Solid property when FdSolid is nil } |
| 33 |
FIgnoredConvex: boolean; {< keeps value of Convex property when FdConvex is nil } |
| 34 |
MappingWarningDone: Boolean; |
| 35 |
{ Workaround http://bugs.freepascal.org/view.php?id=17402 |
| 36 |
by these methods. } |
| 37 |
function CallProxyLocalBoundingBox( |
| 38 |
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): TBox3D; |
| 39 |
function CallProxyBoundingBox( |
| 40 |
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): TBox3D; |
| 41 |
function CallProxyTrianglesCount( |
| 42 |
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal; |
| 43 |
function CallProxyVerticesCount( |
| 44 |
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal; |
| 45 |
function GetSolid: boolean; |
| 46 |
procedure SetSolid(const Value: boolean); |
| 47 |
function GetConvex: boolean; |
| 48 |
procedure SetConvex(const Value: boolean); |
| 49 |
protected |
| 50 |
{ Returns an information how to split @link(InternalCoord) array into ranges. |
| 51 |
|
| 52 |
When CoordIndex = @nil, then if the node's @link(InternalCoord) array |
| 53 |
can be divided into some "ranges", we will use this information. |
| 54 |
This is used (and should be overridden) for X3D non-indexed nodes, |
| 55 |
like fanCount or stripCount or vertexCount. |
| 56 |
|
| 57 |
What precisely is a "range of coordinates" is not specified |
| 58 |
here. It may be a line stip, or one triangle strip, etc. --- |
| 59 |
depending on the descendant. |
| 60 |
|
| 61 |
Returns @true if this is available. In this case, RangeCount must |
| 62 |
be set to something <> nil, and the rest of returned variables |
| 63 |
are mainly to generate proper warnings by MakeCoordRanges. } |
| 64 |
function InternalCoordRangesCounts(out RangeCount: TInt32List; |
| 65 |
out SRanges, SRangeName: string; |
| 66 |
out RangeMinimumCount: Cardinal): boolean; virtual; |
| 67 |
public |
| 68 |
{ Used only for reading glTF now, in the future will be used for skin animation on GPU. @exclude } |
| 69 |
InternalSkinJoints: TVector4IntegerList; |
| 70 |
{ Used only for reading glTF now, in the future will be used for skin animation on GPU. @exclude } |
| 71 |
InternalSkinWeights: TVector4List; |
| 72 |
|
| 73 |
constructor Create(const AX3DName: string = ''; const ABaseUrl: String = ''); override; |
| 74 |
destructor Destroy; override; |
| 75 |
|
| 76 |
{ Calculate bounding box of this geometry node. |
| 77 |
They require State of this node during VRML traverse state --- this |
| 78 |
is mainly for VRML 1.0 nodes, that depend on such state. |
| 79 |
|
| 80 |
LocalBoundingBox gives a bounding box ignoring current transformation |
| 81 |
(or, equivalently, assuming like Transform = IdentityMatrix). |
| 82 |
Normal BoundingBox gives a bounding box taking current transformation |
| 83 |
into account. |
| 84 |
|
| 85 |
@italic(Notes for descendants implementors:) |
| 86 |
|
| 87 |
The default implementations of these methods in TAbstractGeometryNode |
| 88 |
try to be smart and cover all common bases, so that you have to do |
| 89 |
as little work as possible to implement working descendant. |
| 90 |
|
| 91 |
@orderedList( |
| 92 |
@item( |
| 93 |
For nodes based on coordinates (when @link(InternalCoord) returns @true), |
| 94 |
LocalBoundingBox and BoundingBox |
| 95 |
already have optimal and correct implementation in this class. |
| 96 |
Using Coord and CoordIndex, no other information is needed.) |
| 97 |
|
| 98 |
@item( |
| 99 |
For other nodes, we first check ProxyGeometry and ProxyState. |
| 100 |
If ProxyGeometry is non-nil, we assume these came from @link(Proxy) |
| 101 |
call and we will use them to calculate |
| 102 |
bounding boxes, local and not local. |
| 103 |
|
| 104 |
So for nodes with @link(Proxy) overridden, you don't have |
| 105 |
to implement bounding box calculation, instead a ProxyGeometry |
| 106 |
will be created and provided here by the caller. |
| 107 |
This will work Ok if @link(Proxy) node will |
| 108 |
have bounding box calculation implemented. |
| 109 |
|
| 110 |
You can always override these methods, if you don't want |
| 111 |
to use proxy (for example, maybe there exists much faster |
| 112 |
method to calculate bounding box, or maybe tighter |
| 113 |
bounding box may be calculated directly).) |
| 114 |
|
| 115 |
@item( |
| 116 |
For other nodes (not coordinate-based and without a proxy): |
| 117 |
|
| 118 |
The default implementation of LocalBoundingBox just calls |
| 119 |
BoundingBox with a specially modified State, such that |
| 120 |
Transform is identity. |
| 121 |
|
| 122 |
The default implementation of BoundingBox, in turn, just calls |
| 123 |
LocalBoundingBox and transforms this bounding box. |
| 124 |
|
| 125 |
So the default implementations call each other, and will loop |
| 126 |
infinitely... But if you override any one of them |
| 127 |
(local or not local), the other one will magically work. |
| 128 |
|
| 129 |
Note that the default implementation of LocalBoundingBox |
| 130 |
may be non-optimal as far as time is concerned, |
| 131 |
as we'll do useless multiplications by identity matrix. |
| 132 |
And the default implementation of BoundingBox may generate |
| 133 |
non-optimal bounding box, more direct approach (transforming |
| 134 |
each vertex) may give much tightier bounding box. |
| 135 |
|
| 136 |
So you only have to override one method --- although if you |
| 137 |
want the best implementation, fastest and with the best tight |
| 138 |
bounding boxes, you may need to override both of them for some nodes.) |
| 139 |
) |
| 140 |
|
| 141 |
@groupBegin } |
| 142 |
function BoundingBox(State: TX3DGraphTraverseState; |
| 143 |
ProxyGeometry: TAbstractGeometryNode; |
| 144 |
ProxyState: TX3DGraphTraverseState): TBox3D; virtual; |
| 145 |
function LocalBoundingBox(State: TX3DGraphTraverseState; |
| 146 |
ProxyGeometry: TAbstractGeometryNode; |
| 147 |
ProxyState: TX3DGraphTraverseState): TBox3D; virtual; |
| 148 |
{ @groupEnd } |
| 149 |
|
| 150 |
{ Calculate vertex and triangles count of this node. |
| 151 |
|
| 152 |
They require State of this node during VRML traverse state --- this |
| 153 |
is mainly for VRML 1.0 nodes, that depend on such state. |
| 154 |
|
| 155 |
Vertices count calculates number of different vertexes in this node. |
| 156 |
That is, it doesn't eliminate doubles in cases like Coordinate node |
| 157 |
with multiple points the same. But if some face is known to use |
| 158 |
twice the same vertex index, then this counts like a single vertex. |
| 159 |
The idea is that this indicates rendering speed. |
| 160 |
|
| 161 |
For triangles count, the returned value may be different then |
| 162 |
actual if some faces were non-convex. Things like TriangulateFace |
| 163 |
may remove degenerate triangles, so actual number of triangles may |
| 164 |
be slightly less. So don't depend on TrianglesCount as a precise |
| 165 |
measure --- but it's a good fast measure of complexity of given |
| 166 |
node, how fast it will be rendered, used with collision detection etc. |
| 167 |
|
| 168 |
@italic(Notes for descendants implementors:) |
| 169 |
|
| 170 |
For coordinate-based nodes (when @link(InternalCoord) returns @true), |
| 171 |
VerticesCount is already implemented in this class. |
| 172 |
Using Coord method, no other information is needed. |
| 173 |
|
| 174 |
For other nodes, the default implementation of |
| 175 |
both VerticesCount and TrianglesCount in this TAbstractGeometryNode |
| 176 |
class will use ProxyGeometry and ProxyState to do the work. |
| 177 |
You should override these methods if @link(Proxy) is not available |
| 178 |
(so caller will always pass ProxyGeometry = @nil) |
| 179 |
or some faster approach is possible. |
| 180 |
|
| 181 |
@groupBegin } |
| 182 |
function VerticesCount(State: TX3DGraphTraverseState; |
| 183 |
ProxyGeometry: TAbstractGeometryNode; |
| 184 |
ProxyState: TX3DGraphTraverseState): Cardinal; virtual; |
| 185 |
function TrianglesCount(State: TX3DGraphTraverseState; |
| 186 |
ProxyGeometry: TAbstractGeometryNode; |
| 187 |
ProxyState: TX3DGraphTraverseState): Cardinal; virtual; |
| 188 |
{ @groupEnd } |
| 189 |
|
| 190 |
{ Return node's list of coordinates. Returns @false if node is |
| 191 |
not based on coordinates. Returns @true and sets ACoord |
| 192 |
if the node is based on coordinates. Even when returns @true, |
| 193 |
it can set ACoord = @nil, which means that node is based on |
| 194 |
coordinates but they are empty right now (so for example |
| 195 |
bounding box may be considered empty). |
| 196 |
|
| 197 |
In base TAbstractGeometryNode class this always returns @false. |
| 198 |
|
| 199 |
Override this for descendants that have some kind of "coord" field, |
| 200 |
then this should return @true and set ACoord to coord.point field, |
| 201 |
assuming that coord is set and specifies Coordinate node. |
| 202 |
Override this even if coordinates affect the look indirectly, |
| 203 |
e.g. NURBS "controlPoint" fields also should be returned here. |
| 204 |
Otherwise should return @true and set ACoord = @nil. |
| 205 |
|
| 206 |
For VRML 1.0, coord may be taken from State, that's why we have to |
| 207 |
pass current traverse state here. } |
| 208 |
function InternalCoord(State: TX3DGraphTraverseState; |
| 209 |
out ACoord: TMFVec3f): boolean; virtual; |
| 210 |
|
| 211 |
{ Return node's list of coordinates, raising exception if node |
| 212 |
is not based on coordinates. |
| 213 |
|
| 214 |
This is just like the @link(InternalCoord) method, |
| 215 |
except it simply returns the coordinates, not the boolean result. |
| 216 |
If virtual @link(InternalCoord) returns @false (indicating the node |
| 217 |
is not coordinate-based) this raises ENotCoordinateBasedNode. |
| 218 |
|
| 219 |
@raises(ENotCoordinateBasedNode If node is not coordinate-based, |
| 220 |
that is @link(InternalCoord) returns false.) |
| 221 |
} |
| 222 |
function InternalCoordinates(State: TX3DGraphTraverseState): TMFVec3f; |
| 223 |
|
| 224 |
{ Node's "coord" field where you can place TCoordinateNode, or @nil if not available. |
| 225 |
|
| 226 |
This gives you more possibilities than the @link(InternalCoord) |
| 227 |
and @link(InternalCoordinates) methods (as you can assign texCoord using this). |
| 228 |
However, it doesn't work for old VRML 1.0 (since they have coordinate |
| 229 |
information, but no "coord" field). } |
| 230 |
function CoordField: TSFNode; virtual; |
| 231 |
|
| 232 |
{ Node's "normal" field where you can place TNormalNode, or @nil if not available. } |
| 233 |
function NormalField: TSFNode; virtual; |
| 234 |
|
| 235 |
{ Node's "tangent" field where you can place TTangentNode, or @nil if not available. } |
| 236 |
function TangentField: TSFNode; virtual; |
| 237 |
|
| 238 |
{ Returns normal vectors that are specified explicitly. |
| 239 |
The vectors are taken from the Normal node inside our FdNormal field. |
| 240 |
In case of problems (no Normal node specified, invalid node specified etc.) |
| 241 |
returns @nil. } |
| 242 |
function InternalNormal: TVector3List; |
| 243 |
|
| 244 |
{ Returns tangent vectors that are specified explicitly, see @link(TAbstractComposedGeometryNode.Tangent). |
| 245 |
Returns @nil if not specified. } |
| 246 |
function InternalTangent: TVector3List; |
| 247 |
|
| 248 |
{ Node's list of coordinate indexes. |
| 249 |
|
| 250 |
In base TAbstractGeometryNode class this always returns @nil. |
| 251 |
|
| 252 |
Override this for descendants that have some kind of "coordIndex" |
| 253 |
or "index" field used to index @link(InternalCoord) array. } |
| 254 |
function CoordIndexField: TMFLong; virtual; |
| 255 |
|
| 256 |
{ Splits @link(InternalCoord) array into ranges. |
| 257 |
|
| 258 |
If CoordIndex is assigned, then a "range of coordinates" is |
| 259 |
just a range of non-negative indexes within CoordIndex. |
| 260 |
Otherwise (when CoordIndex = @nil), InternalCoordRangesCounts must |
| 261 |
return @true and we will use RangeCount to split coordinates. |
| 262 |
|
| 263 |
Call this only for nodes with coordinates, that is only when |
| 264 |
@link(InternalCoord) returns @true. } |
| 265 |
procedure InternalMakeCoordRanges( |
| 266 |
State: TX3DGraphTraverseState; |
| 267 |
CoordRangeHandler: TCoordRangeHandler); |
| 268 |
|
| 269 |
{ Splits coordinate-based node into polygons. |
| 270 |
|
| 271 |
Indexes in PolygonHandler point to CoordIndex, if assigned, |
| 272 |
or directly to Coord. The ordering of generated polygons is correct, |
| 273 |
so what pointed CCW in the node field, will still point CCW |
| 274 |
according to generated PolygonHandler indexes. |
| 275 |
|
| 276 |
In this class this does nothing. Some, but not all, coordinate-based |
| 277 |
nodes (the ones when @link(InternalCoord) returns @true) override this. |
| 278 |
So currently, whether this is implemented is coordinated with |
| 279 |
CastleInternalNormals and such internal needs. } |
| 280 |
procedure InternalCoordPolygons( |
| 281 |
State: TX3DGraphTraverseState; |
| 282 |
PolygonHandler: TIndexedPolygonHandler); virtual; |
| 283 |
|
| 284 |
{ Node's texture coordinates. Returns @false if node |
| 285 |
cannot have texture coordinates. |
| 286 |
|
| 287 |
Returns @true and sets ATexCoord to a node defining texture coords. |
| 288 |
ATexCoord may be set to TAbstractTextureCoordinateNode descendant or |
| 289 |
to TTextureCoordinate2Node_1 (latter one only for VRML <= 1.0). |
| 290 |
ATexCoord can also be set to @nil in this case, which means that |
| 291 |
this node has a field for texCoord, but it's empty right now. |
| 292 |
|
| 293 |
In base TAbstractGeometryNode class this looks at TexCoordField, |
| 294 |
eventually returns @false. } |
| 295 |
function InternalTexCoord(State: TX3DGraphTraverseState; |
| 296 |
out ATexCoord: TX3DNode): boolean; virtual; |
| 297 |
|
| 298 |
{ Node's texCoord field, or @nil if not available. |
| 299 |
Various nodes may have different exact rules about what is |
| 300 |
allowed here, but everything allows TextureCoordinateGenerator |
| 301 |
and ProjectedTextureCoordinate instances. |
| 302 |
|
| 303 |
This gives you more possibilities than the @link(InternalTexCoord) method |
| 304 |
(as you can assign texCoord using this), however it may be not available |
| 305 |
in all cases --- for example VRML 1.0 nodes do not have texCoord field, |
| 306 |
but they may have a texture coordinate node (from the state). } |
| 307 |
function TexCoordField: TSFNode; virtual; |
| 308 |
|
| 309 |
{ Find a texture coordinate node with given Mapping value. |
| 310 |
Returns nil (and Index = -1) if not found. |
| 311 |
This implements X3D 4.0 section |
| 312 |
"12.2.4 Texture mapping specified in material nodes". |
| 313 |
|
| 314 |
If MakeWarning, we make a warning if Mapping is not empty, |
| 315 |
and yet it doesn't match anything. This is not allowed, according to spec. } |
| 316 |
function FindTextureMapping(const Mapping: String; |
| 317 |
const MakeWarning: Boolean = true): TAbstractSingleTextureCoordinateNode; overload; |
| 318 |
function FindTextureMapping(const Mapping: String; out TexCoordIndex: Integer; |
| 319 |
const MakeWarning: Boolean = true): TAbstractSingleTextureCoordinateNode; overload; |
| 320 |
|
| 321 |
{ Converts this node to another node class that may be better supported. |
| 322 |
|
| 323 |
Typically, converts some complex geometry node (like |
| 324 |
Extrusion or Teapot) into more common node like IndexedFaceSet |
| 325 |
or IndexedTriangleSet. TShape class wraps this method into |
| 326 |
a more comfortable interface, that is TShape methods |
| 327 |
simply automatically convert geometry nodes to their proxy versions |
| 328 |
if needed. |
| 329 |
|
| 330 |
In the base TAbstractGeometryNode class, returns @nil indicating |
| 331 |
that no conversion is known. |
| 332 |
|
| 333 |
The resulting node's Name (if the result is not @nil) must be |
| 334 |
equal to our Name. |
| 335 |
|
| 336 |
Some Proxy implementations (especially for VRML 1.0) will have |
| 337 |
to create new State (TX3DGraphTraverseState) instance along |
| 338 |
with a new geometry node. You should do this by copying the State |
| 339 |
into a new TX3DGraphTraverseState instance, and modyfying |
| 340 |
the State reference. Simply speaking, do |
| 341 |
|
| 342 |
@longcode(# |
| 343 |
State := TX3DGraphTraverseState.CreateCopy(State); |
| 344 |
#) |
| 345 |
|
| 346 |
You should @italic(not) just modify the fields |
| 347 |
of the provided State instance. (Reasoning: some proxy methods |
| 348 |
rely on getting the original State, e.g. with original MaterialBinding, |
| 349 |
not the transformed state, to work correctly.) |
| 350 |
|
| 351 |
You can modify State variable only when returning non-nil geometry. } |
| 352 |
function Proxy(var State: TX3DGraphTraverseState): TAbstractGeometryNode; virtual; |
| 353 |
|
| 354 |
{ Returns color.point field, assuming that "color" field is set and |
| 355 |
specifies Color (or ColorRGBA) node. Otherwise returns @nil. |
| 356 |
|
| 357 |
Note that only one of Color and ColorRGBA may return non-nil, |
| 358 |
since "color" field may contain only one of them. |
| 359 |
|
| 360 |
@groupBegin } |
| 361 |
function InternalColor: TMFVec3f; |
| 362 |
function InternalColorRGBA: TMFColorRGBA; |
| 363 |
function InternalColorNode: TAbstractColorNode; |
| 364 |
{ @groupEnd } |
| 365 |
|
| 366 |
function InternalFogCoord: TMFFloat; virtual; |
| 367 |
function AttribField: TMFNode; virtual; |
| 368 |
|
| 369 |
function ColorField: TSFNode; virtual; |
| 370 |
|
| 371 |
{ Is backface culling used. |
| 372 |
@nil if given geometry node doesn't have a field to control it. } |
| 373 |
function SolidField: TSFBool; virtual; |
| 374 |
|
| 375 |
{ Are faces guaranteed to be convex. |
| 376 |
@nil if given geometry node doesn't have a field to control it. } |
| 377 |
function ConvexField: TSFBool; virtual; |
| 378 |
|
| 379 |
{ Should renderer automatically generate 3D texture coordinates, |
| 380 |
in case we will apply 3D texture on this geometry. |
| 381 |
|
| 382 |
The generated coordinates will follow the X3D specification |
| 383 |
at "Texturing3D" component: "Texture coordinate generation |
| 384 |
for primitive objects". The 3D texture space will be mapped nicely |
| 385 |
to the shape bounding box. |
| 386 |
|
| 387 |
Implementation in this class (TAbstractGeometryNode) returns always |
| 388 |
@false. Override it for primitives that have no texture coordinates |
| 389 |
to return @true. } |
| 390 |
function AutoGenerate3DTexCoords: boolean; virtual; |
| 391 |
|
| 392 |
function TransformationChange: TNodeTransformationChange; override; |
| 393 |
|
| 394 |
{ Calculate texture S, T coordinates for BOUNDS2D texture mapping. |
| 395 |
This mapping is like the default IndexedFaceSet texture mapping, |
| 396 |
following X3D spec. We also use it for other geometry nodes, |
| 397 |
and even allow explicitly requesting it by TextureCoordinateGenerator.mode = "BOUNDS2D". } |
| 398 |
procedure GetTextureBounds2DST(const LocalBoxSizes: TVector3; |
| 399 |
out S, T: T3DAxis); |
| 400 |
|
| 401 |
{ Is this object lit, disregarding the material. |
| 402 |
Default implementation in TAbstractGeometryNode says @true. } |
| 403 |
function Lit(State: TX3DGraphTraverseState): boolean; virtual; |
| 404 |
|
| 405 |
{ Should renderer setup an extra texture slot with font texture |
| 406 |
when rendering this node. This is useful for rendering Text nodes, |
| 407 |
that want to cooperate with normal texturing and shading, |
| 408 |
and additionally they want to use extra texture determined by font |
| 409 |
(not by Appearance node). } |
| 410 |
function FontTextureNode: TAbstractTexture2DNode; virtual; |
| 411 |
|
| 412 |
{ Are faces guaranteed to be convex. |
| 413 |
If your faces may be concave, you must set this to @false, |
| 414 |
otherwise the results (rendering and collisions) may be incorrect. } |
| 415 |
property Convex: boolean read GetConvex write SetConvex; |
| 416 |
|
| 417 |
{ Is backface culling used. } |
| 418 |
property Solid: boolean read GetSolid write SetSolid; |
| 419 |
|
| 420 |
{ Create an instance of this geometry node, |
| 421 |
and make it a child of a new shape node (TShapeNode). |
| 422 |
This way you get a ready shape that can be used inside the X3D scene graph |
| 423 |
to show this geometry. |
| 424 |
|
| 425 |
You usually want to add the resulting Shape node to some scene, |
| 426 |
e.g. like this: |
| 427 |
|
| 428 |
@longCode(# |
| 429 |
Box := TBoxNode.CreateWithShape(Shape); |
| 430 |
|
| 431 |
Root := TX3DRootNode.Create; |
| 432 |
Root.AddChildren(Shape); |
| 433 |
|
| 434 |
Scene := TCastleScene.Create(nil); |
| 435 |
Scene.Load(Root, true); |
| 436 |
#) |
| 437 |
|
| 438 |
Remember that once the node is a children of another node, |
| 439 |
then this node will be automatically freed. |
| 440 |
So you should not free the resulting geometry node. |
| 441 |
Instead, free the resulting Shape node, |
| 442 |
or add it to some scene, as shown above. |
| 443 |
} |
| 444 |
constructor CreateWithShape(out Shape: TShapeNode); |
| 445 |
|
| 446 |
{ Create an instance of this geometry node, |
| 447 |
and make it a child of a new shape node (TShapeNode), |
| 448 |
and make it a child of a new transform node (TTransformNode). |
| 449 |
This way you get a ready transformation that can be used inside |
| 450 |
the X3D scene graph to show and transform this geometry. |
| 451 |
|
| 452 |
You usually want to add the resulting Transform node to some scene, |
| 453 |
e.g. like this: |
| 454 |
|
| 455 |
@longCode(# |
| 456 |
Box := TBoxNode.CreateWithTransform(Shape, Transform); |
| 457 |
|
| 458 |
Root := TX3DRootNode.Create; |
| 459 |
Root.AddChildren(Transform); |
| 460 |
|
| 461 |
Scene := TCastleScene.Create(nil); |
| 462 |
Scene.Load(Root, true); |
| 463 |
#) |
| 464 |
|
| 465 |
Remember that once the node is a children of another node, |
| 466 |
then this node will be automatically freed. |
| 467 |
So you should not free the resulting geometry node |
| 468 |
or Shape node. |
| 469 |
Instead, free the resulting Transform node, |
| 470 |
or add it to some scene, as shown above. |
| 471 |
} |
| 472 |
constructor CreateWithTransform(out Shape: TShapeNode; out Transform: TTransformNode); |
| 473 |
|
| 474 |
{$I auto_generated_node_helpers/x3dnodes_x3dgeometrynode.inc} |
| 475 |
end; |
| 476 |
|
| 477 |
TAbstractGeometryNodeClass = class of TAbstractGeometryNode; |
| 478 |
|
| 479 |
{ Base node type for all geometric property node types. } |
| 480 |
TAbstractGeometricPropertyNode = class(TAbstractNode) |
| 481 |
{$I auto_generated_node_helpers/x3dnodes_x3dgeometricpropertynode.inc} |
| 482 |
end; |
| 483 |
|
| 484 |
TAbstractX3DGeometryNode = TAbstractGeometryNode deprecated 'use TAbstractGeometryNode'; |
| 485 |
|
| 486 |
{ Base node for color specifications. } |
| 487 |
TAbstractColorNode = class(TAbstractGeometricPropertyNode) |
| 488 |
{$I auto_generated_node_helpers/x3dnodes_x3dcolornode.inc} |
| 489 |
end; |
| 490 |
|
| 491 |
TAbstractVertexAttributeNode = class; |
| 492 |
|
| 493 |
{ Base node type for all composed 3D geometry. } |
| 494 |
TAbstractComposedGeometryNode = class(TAbstractGeometryNode) |
| 495 |
protected |
| 496 |
function DirectEnumerateActive(Func: TEnumerateChildrenFunction): Pointer; override; |
| 497 |
public |
| 498 |
{ Access the coordinate node, and inside this node access it's points list. } |
| 499 |
function InternalCoord(State: TX3DGraphTraverseState; |
| 500 |
out ACoord: TMFVec3f): boolean; override; |
| 501 |
function CoordField: TSFNode; override; |
| 502 |
function TexCoordField: TSFNode; override; |
| 503 |
function ColorField: TSFNode; override; |
| 504 |
function SolidField: TSFBool; override; |
| 505 |
function AttribField: TMFNode; override; |
| 506 |
function NormalField: TSFNode; override; |
| 507 |
function TangentField: TSFNode; override; |
| 508 |
|
| 509 |
function InternalFogCoord: TMFFloat; override; |
| 510 |
|
| 511 |
{$I auto_generated_node_helpers/x3dnodes_x3dcomposedgeometrynode.inc} |
| 512 |
end; |
| 513 |
|
| 514 |
{ Base node type for all coordinate node types. } |
| 515 |
TAbstractCoordinateNode = class(TAbstractGeometricPropertyNode) |
| 516 |
public |
| 517 |
{ Count of coordinates within. } |
| 518 |
function CoordCount: Cardinal; virtual; abstract; |
| 519 |
|
| 520 |
{$I auto_generated_node_helpers/x3dnodes_x3dcoordinatenode.inc} |
| 521 |
end; |
| 522 |
|
| 523 |
{ Base node type for all normal node types. } |
| 524 |
TAbstractNormalNode = class(TAbstractGeometricPropertyNode) |
| 525 |
{$I auto_generated_node_helpers/x3dnodes_x3dnormalnode.inc} |
| 526 |
end; |
| 527 |
|
| 528 |
{ Clip the geometry with a plane. } |
| 529 |
TClipPlaneNode = class(TAbstractChildNode) |
| 530 |
protected |
| 531 |
procedure GroupBeforeTraverse(const State: TX3DGraphTraverseState; var WasPointingDeviceSensor: Boolean); override; |
| 532 |
public |
| 533 |
{$I auto_generated_node_helpers/x3dnodes_clipplane.inc} |
| 534 |
end; |
| 535 |
|
| 536 |
{ Set of RGB colours. } |
| 537 |
TColorNode = class(TAbstractColorNode) |
| 538 |
{$I auto_generated_node_helpers/x3dnodes_color.inc} |
| 539 |
end; |
| 540 |
|
| 541 |
{ Set of RGBA colours. } |
| 542 |
TColorRGBANode = class(TAbstractColorNode) |
| 543 |
{$I auto_generated_node_helpers/x3dnodes_colorrgba.inc} |
| 544 |
end; |
| 545 |
|
| 546 |
{ Set of 3D coordinates to be used in the @code(Coord) |
| 547 |
field of vertex-based geometry nodes. } |
| 548 |
TCoordinateNode = class(TAbstractCoordinateNode) |
| 549 |
public |
| 550 |
function CoordCount: Cardinal; override; |
| 551 |
{$I auto_generated_node_helpers/x3dnodes_coordinate.inc} |
| 552 |
end; |
| 553 |
|
| 554 |
{ Mode for line primitive defined by TIndexedLineSetNode or TLineSetNode. } |
| 555 |
TLineMode = ( |
| 556 |
{ Lines form a strip (polyline). |
| 557 |
|
| 558 |
In case of TIndexedLineSetNode, indexes (TIndexedLineSetNode.FdIndex) |
| 559 |
may be separated by -1 to define many strips |
| 560 |
in an TIndexedLineSetNode. |
| 561 |
|
| 562 |
In case of TLineSetNode, count (TIndexedLineSetNode.FdVertexCount) |
| 563 |
defines how many vertexes are for each strip. } |
| 564 |
lmStrip, |
| 565 |
|
| 566 |
{ Lines form a loop (closed polyline). |
| 567 |
|
| 568 |
In case of TIndexedLineSetNode, indexes (TIndexedLineSetNode.FdIndex) |
| 569 |
may be separated by -1 to define many loop |
| 570 |
in an TIndexedLineSetNode. |
| 571 |
|
| 572 |
In case of TLineSetNode, count (TIndexedLineSetNode.FdVertexCount) |
| 573 |
defines how many vertexes are for each loop. } |
| 574 |
lmLoop, |
| 575 |
|
| 576 |
{ Each pair of vertexes forms a line. |
| 577 |
If the number of vertexes is odd, the last (unmatched) vertex is ignored. |
| 578 |
|
| 579 |
In case of TIndexedLineSetNode, all indexes must be >= 0. |
| 580 |
|
| 581 |
In case of TLineSetNode, vertexCount is ignored. } |
| 582 |
lmPair |
| 583 |
); |
| 584 |
|
| 585 |
{ Geometry formed by constructing polylines from 3D vertices. } |
| 586 |
TIndexedLineSetNode = class(TAbstractGeometryNode) |
| 587 |
strict private |
| 588 |
procedure EventSet_ColorIndexReceive( |
| 589 |
const Event: TX3DEvent; const Value: TX3DField; const Time: TX3DTime); |
| 590 |
procedure EventSet_CoordIndexReceive( |
| 591 |
const Event: TX3DEvent; const Value: TX3DField; const Time: TX3DTime); |
| 592 |
public |
| 593 |
constructor Create(const AX3DName: string = ''; const ABaseUrl: String = ''); override; |
| 594 |
class function ForVRMLVersion(const Version: TX3DVersion): boolean; |
| 595 |
override; |
| 596 |
function TrianglesCount(State: TX3DGraphTraverseState; |
| 597 |
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal; override; |
| 598 |
function Lit(State: TX3DGraphTraverseState): boolean; override; |
| 599 |
function InternalCoord(State: TX3DGraphTraverseState; |
| 600 |
out ACoord: TMFVec3f): boolean; override; |
| 601 |
function CoordIndexField: TMFLong; override; |
| 602 |
function CoordField: TSFNode; override; |
| 603 |
function ColorField: TSFNode; override; |
| 604 |
function InternalFogCoord: TMFFloat; override; |
| 605 |
function AttribField: TMFNode; override; |
| 606 |
|
| 607 |
{$I auto_generated_node_helpers/x3dnodes_indexedlineset.inc} |
| 608 |
end; |
| 609 |
TIndexedLineSetNode_2 = TIndexedLineSetNode; |
| 610 |
|
| 611 |
{ Triangles that form a fan shape around the first vertex. } |
| 612 |
TIndexedTriangleFanSetNode = class(TAbstractComposedGeometryNode) |
| 613 |
strict private |
| 614 |
procedure EventSet_IndexReceive( |
| 615 |
const Event: TX3DEvent; const Value: TX3DField; const Time: TX3DTime); |
| 616 |
public |
| 617 |
constructor Create(const AX3DName: string = ''; const ABaseUrl: String = ''); override; |
| 618 |
function FieldSetByEvent(const Event: TX3DEvent): TX3DField; override; |
| 619 |
function CoordIndexField: TMFLong; override; |
| 620 |
procedure InternalCoordPolygons( |
| 621 |
State: TX3DGraphTraverseState; |
| 622 |
PolygonHandler: TIndexedPolygonHandler); override; |
| 623 |
function TrianglesCount(State: TX3DGraphTraverseState; |
| 624 |
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal; override; |
| 625 |
|
| 626 |
{$I auto_generated_node_helpers/x3dnodes_indexedtrianglefanset.inc} |
| 627 |
end; |
| 628 |
|
| 629 |
{ A collection of triangles. } |
| 630 |
TIndexedTriangleSetNode = class(TAbstractComposedGeometryNode) |
| 631 |
strict private |
| 632 |
procedure EventSet_IndexReceive( |
| 633 |
const Event: TX3DEvent; const Value: TX3DField; const Time: TX3DTime); |
| 634 |
public |
| 635 |
constructor Create(const AX3DName: string = ''; const ABaseUrl: String = ''); override; |
| 636 |
function FieldSetByEvent(const Event: TX3DEvent): TX3DField; override; |
| 637 |
function CoordIndexField: TMFLong; override; |
| 638 |
procedure InternalCoordPolygons( |
| 639 |
State: TX3DGraphTraverseState; |
| 640 |
PolygonHandler: TIndexedPolygonHandler); override; |
| 641 |
function TrianglesCount(State: TX3DGraphTraverseState; |
| 642 |
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal; override; |
| 643 |
|
| 644 |
{$I auto_generated_node_helpers/x3dnodes_indexedtriangleset.inc} |
| 645 |
end; |
| 646 |
|
| 647 |
{ Strips of triangles. } |
| 648 |
TIndexedTriangleStripSetNode = class(TAbstractComposedGeometryNode) |
| 649 |
strict private |
| 650 |
procedure EventSet_IndexReceive( |
| 651 |
const Event: TX3DEvent; const Value: TX3DField; const Time: TX3DTime); |
| 652 |
public |
| 653 |
constructor Create(const AX3DName: string = ''; const ABaseUrl: String = ''); override; |
| 654 |
function FieldSetByEvent(const Event: TX3DEvent): TX3DField; override; |
| 655 |
function CoordIndexField: TMFLong; override; |
| 656 |
procedure InternalCoordPolygons( |
| 657 |
State: TX3DGraphTraverseState; |
| 658 |
PolygonHandler: TIndexedPolygonHandler); override; |
| 659 |
function TrianglesCount(State: TX3DGraphTraverseState; |
| 660 |
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal; override; |
| 661 |
|
| 662 |
{$I auto_generated_node_helpers/x3dnodes_indexedtrianglestripset.inc} |
| 663 |
end; |
| 664 |
|
| 665 |
{ Lines. } |
| 666 |
TLineSetNode = class(TAbstractGeometryNode) |
| 667 |
strict private |
| 668 |
FVertexCountForPair: TInt32List; |
| 669 |
protected |
| 670 |
function DirectEnumerateActive(Func: TEnumerateChildrenFunction): Pointer; override; |
| 671 |
function InternalCoordRangesCounts(out RangeCount: TInt32List; |
| 672 |
out SRanges, SRangeName: string; |
| 673 |
out RangeMinimumCount: Cardinal): boolean; override; |
| 674 |
public |
| 675 |
destructor Destroy; override; |
| 676 |
function InternalCoord(State: TX3DGraphTraverseState; |
| 677 |
out ACoord: TMFVec3f): boolean; override; |
| 678 |
function CoordField: TSFNode; override; |
| 679 |
function ColorField: TSFNode; override; |
| 680 |
function InternalFogCoord: TMFFloat; override; |
| 681 |
function AttribField: TMFNode; override; |
| 682 |
function TrianglesCount(State: TX3DGraphTraverseState; |
| 683 |
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal; override; |
| 684 |
function Lit(State: TX3DGraphTraverseState): boolean; override; |
| 685 |
|
| 686 |
{$I auto_generated_node_helpers/x3dnodes_lineset.inc} |
| 687 |
end; |
| 688 |
|
| 689 |
{ Normal (information for lighting) node. } |
| 690 |
TNormalNode = class(TAbstractNormalNode) |
| 691 |
{$I auto_generated_node_helpers/x3dnodes_normal.inc} |
| 692 |
end; |
| 693 |
|
| 694 |
{ Tangent vectors information, for bump mapping. |
| 695 |
The "vector" field should contain normalized tangent vectors, |
| 696 |
in right-handed coordinate system. |
| 697 |
|
| 698 |
The ordering of the tangent vectors is exactly the same as ordering |
| 699 |
of normal vectors would be, |
| 700 |
so e.g. @link(TAbstractComposedGeometryNode.NormalPerVertex) affects |
| 701 |
the interpretation of tangent vectors as well. } |
| 702 |
TTangentNode = class(TAbstractGeometricPropertyNode) |
| 703 |
{$I auto_generated_node_helpers/x3dnodes_tangent.inc} |
| 704 |
public |
| 705 |
{ Set tangent vectors from a list of 4D vectors following glTF specification. |
| 706 |
https://github.com/KhronosGroup/glTF/tree/master/specification/2.0 says |
| 707 |
"XYZW vertex tangents where the w component is a sign value |
| 708 |
(-1 or +1) indicating handedness of the tangent basis". } |
| 709 |
procedure SetVector4D(const List: TVector4List); |
| 710 |
end; |
| 711 |
|
| 712 |
{ Points. } |
| 713 |
TPointSetNode = class(TAbstractGeometryNode) |
| 714 |
protected |
| 715 |
function DirectEnumerateActive(Func: TEnumerateChildrenFunction): Pointer; override; |
| 716 |
public |
| 717 |
class function ForVRMLVersion(const Version: TX3DVersion): boolean; |
| 718 |
override; |
| 719 |
function TrianglesCount(State: TX3DGraphTraverseState; |
| 720 |
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal; override; |
| 721 |
function Lit(State: TX3DGraphTraverseState): boolean; override; |
| 722 |
function InternalCoord(State: TX3DGraphTraverseState; |
| 723 |
out ACoord: TMFVec3f): boolean; override; |
| 724 |
function CoordField: TSFNode; override; |
| 725 |
function ColorField: TSFNode; override; |
| 726 |
function InternalFogCoord: TMFFloat; override; |
| 727 |
function AttribField: TMFNode; override; |
| 728 |
|
| 729 |
{$I auto_generated_node_helpers/x3dnodes_pointset.inc} |
| 730 |
end; |
| 731 |
TPointSetNode_2 = TPointSetNode; |
| 732 |
|
| 733 |
{ Triangles that form a fan shape around the first vertex. |
| 734 |
In constrast to @link(TIndexedTriangleFanSetNode), this doesn't use indexes |
| 735 |
to compose vertexes into triangles. } |
| 736 |
TTriangleFanSetNode = class(TAbstractComposedGeometryNode) |
| 737 |
protected |
| 738 |
function InternalCoordRangesCounts(out RangeCount: TInt32List; |
| 739 |
out SRanges, SRangeName: string; |
| 740 |
out RangeMinimumCount: Cardinal): boolean; override; |
| 741 |
public |
| 742 |
procedure InternalCoordPolygons( |
| 743 |
State: TX3DGraphTraverseState; |
| 744 |
PolygonHandler: TIndexedPolygonHandler); override; |
| 745 |
function TrianglesCount(State: TX3DGraphTraverseState; |
| 746 |
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal; override; |
| 747 |
|
| 748 |
{$I auto_generated_node_helpers/x3dnodes_trianglefanset.inc} |
| 749 |
end; |
| 750 |
|
| 751 |
{ A collection of triangles. |
| 752 |
In constrast to @link(TIndexedTriangleSetNode), this doesn't use indexes |
| 753 |
to compose vertexes into triangles. } |
| 754 |
TTriangleSetNode = class(TAbstractComposedGeometryNode) |
| 755 |
public |
| 756 |
procedure InternalCoordPolygons( |
| 757 |
State: TX3DGraphTraverseState; |
| 758 |
PolygonHandler: TIndexedPolygonHandler); override; |
| 759 |
function TrianglesCount(State: TX3DGraphTraverseState; |
| 760 |
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal; override; |
| 761 |
|
| 762 |
{$I auto_generated_node_helpers/x3dnodes_triangleset.inc} |
| 763 |
end; |
| 764 |
|
| 765 |
{ Strips of triangles. |
| 766 |
In contrast to @link(TIndexedTriangleStripSetNode), this doesn't use indexes |
| 767 |
to compose vertexes into triangles. } |
| 768 |
TTriangleStripSetNode = class(TAbstractComposedGeometryNode) |
| 769 |
protected |
| 770 |
function InternalCoordRangesCounts(out RangeCount: TInt32List; |
| 771 |
out SRanges, SRangeName: string; |
| 772 |
out RangeMinimumCount: Cardinal): boolean; override; |
| 773 |
public |
| 774 |
procedure InternalCoordPolygons( |
| 775 |
State: TX3DGraphTraverseState; |
| 776 |
PolygonHandler: TIndexedPolygonHandler); override; |
| 777 |
function TrianglesCount(State: TX3DGraphTraverseState; |
| 778 |
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal; override; |
| 779 |
|
| 780 |
{$I auto_generated_node_helpers/x3dnodes_trianglestripset.inc} |
| 781 |
end; |
| 782 |
{$endif read_interface} |
| 783 |
|
| 784 |
{$ifdef read_implementation} |
| 785 |
|
| 786 |
const |
| 787 |
ColorModeNames: array [TColorMode] of String = ( |
| 788 |
'REPLACE', 'MODULATE' |
| 789 |
); |
| 790 |
|
| 791 |
LineModeNames: array [TLineMode] of String = ( |
| 792 |
'STRIP', 'LOOP', 'PAIR' |
| 793 |
); |
| 794 |
|
| 795 |
{ TAbstractGeometryNode ---------------------------------------------------------- } |
| 796 |
|
| 797 |
constructor TAbstractGeometryNode.Create(const AX3DName, ABaseUrl: String); |
| 798 |
begin |
| 799 |
inherited; |
| 800 |
|
| 801 |
{ To make nodes without FdSolid and FdConvex field behave consistently, |
| 802 |
we keep the value you set by SetSolid / SetConvex to return it in GetSolid / GetConvex. |
| 803 |
The defaults are "true", which are more efficient (e.g. solid=true |
| 804 |
doesn't activate two-sided lighting) and correspond to X3D defaults on other nodes. } |
| 805 |
FIgnoredSolid := true; |
| 806 |
FIgnoredConvex := true; |
| 807 |
end; |
| 808 |
|
| 809 |
destructor TAbstractGeometryNode.Destroy; |
| 810 |
begin |
| 811 |
FreeAndNil(InternalSkinJoints); |
| 812 |
FreeAndNil(InternalSkinWeights); |
| 813 |
inherited; |
| 814 |
end; |
| 815 |
|
| 816 |
constructor TAbstractGeometryNode.CreateWithShape(out Shape: TShapeNode); |
| 817 |
begin |
| 818 |
Create; |
| 819 |
|
| 820 |
Shape := TShapeNode.Create; |
| 821 |
Shape.Geometry := Self; |
| 822 |
end; |
| 823 |
|
| 824 |
constructor TAbstractGeometryNode.CreateWithTransform(out Shape: TShapeNode; out Transform: TTransformNode); |
| 825 |
begin |
| 826 |
Create; |
| 827 |
|
| 828 |
Shape := TShapeNode.Create; |
| 829 |
Shape.Geometry := Self; |
| 830 |
|
| 831 |
Transform := TTransformNode.Create; |
| 832 |
Transform.AddChildren(Shape); |
| 833 |
end; |
| 834 |
|
| 835 |
function TAbstractGeometryNode.InternalCoord(State: TX3DGraphTraverseState; |
| 836 |
out ACoord: TMFVec3f): boolean; |
| 837 |
begin |
| 838 |
Result := false; |
| 839 |
end; |
| 840 |
|
| 841 |
function TAbstractGeometryNode.InternalCoordinates(State: TX3DGraphTraverseState): TMFVec3f; |
| 842 |
begin |
| 843 |
if not InternalCoord(State, Result) then |
| 844 |
raise ENotCoordinateBasedNode.CreateFmt('Node %s is not a coordinate-based node', |
| 845 |
[X3DType]); |
| 846 |
end; |
| 847 |
|
| 848 |
function TAbstractGeometryNode.CoordField: TSFNode; |
| 849 |
begin |
| 850 |
Result := nil; |
| 851 |
end; |
| 852 |
|
| 853 |
function TAbstractGeometryNode.CoordIndexField: TMFLong; |
| 854 |
begin |
| 855 |
Result := nil; |
| 856 |
end; |
| 857 |
|
| 858 |
function TAbstractGeometryNode.InternalCoordRangesCounts( |
| 859 |
out RangeCount: TInt32List; |
| 860 |
out SRanges, SRangeName: string; |
| 861 |
out RangeMinimumCount: Cardinal): boolean; |
| 862 |
begin |
| 863 |
Result := false; |
| 864 |
end; |
| 865 |
|
| 866 |
procedure TAbstractGeometryNode.InternalMakeCoordRanges( |
| 867 |
State: TX3DGraphTraverseState; |
| 868 |
CoordRangeHandler: TCoordRangeHandler); |
| 869 |
var |
| 870 |
BeginIndex, EndIndex: Integer; |
| 871 |
RangeNumber: Cardinal; |
| 872 |
RangeCount: TInt32List; |
| 873 |
SRanges, SRangeName: string; |
| 874 |
RangeMinimumCount: Cardinal; |
| 875 |
C: TMFVec3f; |
| 876 |
begin |
| 877 |
C := InternalCoordinates(State); |
| 878 |
|
| 879 |
if C = nil then |
| 880 |
Exit; |
| 881 |
|
| 882 |
if CoordIndexField <> nil then |
| 883 |
begin |
| 884 |
BeginIndex := 0; |
| 885 |
RangeNumber := 0; |
| 886 |
while BeginIndex < CoordIndexField.Count do |
| 887 |
begin |
| 888 |
EndIndex := BeginIndex; |
| 889 |
while (EndIndex < CoordIndexField.Count) and |
| 890 |
(CoordIndexField.Items.Items[EndIndex] >= 0) do |
| 891 |
Inc(EndIndex); |
| 892 |
CoordRangeHandler(RangeNumber, BeginIndex, EndIndex); |
| 893 |
Inc(RangeNumber); |
| 894 |
BeginIndex := EndIndex + 1; |
| 895 |
end; |
| 896 |
end else |
| 897 |
begin |
| 898 |
if not InternalCoordRangesCounts(RangeCount, SRanges, SRangeName, |
| 899 |
RangeMinimumCount) then |
| 900 |
raise EInternalError.CreateFmt('%s.InternalMakeCoordRanges: either CoordIndex or InternalCoordRangesCounts must be defined to split coordinates', [ClassName]); |
| 901 |
EndIndex := 0; |
| 902 |
if RangeCount.Count > 0 then |
| 903 |
for RangeNumber := 0 to RangeCount.Count - 1 do |
| 904 |
begin |
| 905 |
BeginIndex := EndIndex; |
| 906 |
EndIndex := BeginIndex + RangeCount.Items[RangeNumber]; |
| 907 |
{ Note that EndIndex *may* be equal to C.Count, |
| 908 |
as EndIndex is not taken into account by CoordRangeHandler. } |
| 909 |
if EndIndex > C.Count then |
| 910 |
begin |
| 911 |
WritelnWarning('VRML/X3D', Format('Too much %s (not enough coordinates) in %s', |
| 912 |
[SRanges, X3DType])); |
| 913 |
Break; |
| 914 |
end; |
| 915 |
if Cardinal(EndIndex - BeginIndex) >= RangeMinimumCount then |
| 916 |
CoordRangeHandler(RangeNumber, BeginIndex, EndIndex) else |
| 917 |
WritelnWarning('VRML/X3D', Format('%s is less than %d in %s', |
| 918 |
[SRangeName, RangeMinimumCount, X3DType])); |
| 919 |
end; |
| 920 |
end; |
| 921 |
end; |
| 922 |
|
| 923 |
procedure TAbstractGeometryNode.InternalCoordPolygons( |
| 924 |
State: TX3DGraphTraverseState; |
| 925 |
PolygonHandler: TIndexedPolygonHandler); |
| 926 |
begin |
| 927 |
{ Nothing to do in this class. } |
| 928 |
end; |
| 929 |
|
| 930 |
function TAbstractGeometryNode.InternalTexCoord(State: TX3DGraphTraverseState; |
| 931 |
out ATexCoord: TX3DNode): boolean; |
| 932 |
begin |
| 933 |
Result := TexCoordField <> nil; |
| 934 |
if Result and |
| 935 |
(TexCoordField.Value <> nil) and |
| 936 |
TexCoordField.CurrentChildAllowed then |
| 937 |
ATexCoord := TexCoordField.Value else |
| 938 |
ATexCoord := nil; |
| 939 |
end; |
| 940 |
|
| 941 |
function TAbstractGeometryNode.TexCoordField: TSFNode; |
| 942 |
begin |
| 943 |
Result := nil; |
| 944 |
end; |
| 945 |
|
| 946 |
function TAbstractGeometryNode.FindTextureMapping(const Mapping: String; |
| 947 |
const MakeWarning: Boolean): TAbstractSingleTextureCoordinateNode; |
| 948 |
var |
| 949 |
TexCoordIndex: Integer; |
| 950 |
begin |
| 951 |
Result := FindTextureMapping(Mapping, TexCoordIndex, MakeWarning); |
| 952 |
end; |
| 953 |
|
| 954 |
function TAbstractGeometryNode.FindTextureMapping(const Mapping: String; |
| 955 |
out TexCoordIndex: Integer; const MakeWarning: Boolean): TAbstractSingleTextureCoordinateNode; |
| 956 |
var |
| 957 |
T: TX3DNode; |
| 958 |
MultiCoord: TMultiTextureCoordinateNode; |
| 959 |
I: Integer; |
| 960 |
begin |
| 961 |
Result := nil; |
| 962 |
TexCoordIndex := -1; |
| 963 |
|
| 964 |
if TexCoordField = nil then |
| 965 |
Exit; |
| 966 |
|
| 967 |
T := TexCoordField.Value; |
| 968 |
if T is TMultiTextureCoordinateNode then |
| 969 |
begin |
| 970 |
MultiCoord := TMultiTextureCoordinateNode(T); |
| 971 |
for I := 0 to MultiCoord.FdTexCoord.Count - 1 do |
| 972 |
if (MultiCoord.FdTexCoord[I] is TAbstractSingleTextureCoordinateNode) and |
| 973 |
{ Mapping empty matches first item. |
| 974 |
All children of MultiTextureCoordinate should be TAbstractSingleTextureCoordinateNode |
| 975 |
in valid files. } |
| 976 |
( (Mapping = '') or |
| 977 |
(Mapping = TAbstractSingleTextureCoordinateNode(MultiCoord.FdTexCoord[I]).Mapping) ) then |
| 978 |
begin |
| 979 |
Result := TAbstractSingleTextureCoordinateNode(MultiCoord.FdTexCoord[I]); |
| 980 |
TexCoordIndex := I; |
| 981 |
Exit; |
| 982 |
end; |
| 983 |
|
| 984 |
if MakeWarning and (Mapping <> '') and (not MappingWarningDone) then |
| 985 |
begin |
| 986 |
WritelnWarning('Texture mapping "%s" not found within MultiTextureCoordinate list', [Mapping]); |
| 987 |
MappingWarningDone := true; |
| 988 |
end; |
| 989 |
end else |
| 990 |
if T is TAbstractSingleTextureCoordinateNode then |
| 991 |
begin |
| 992 |
if ( (Mapping = '') or |
| 993 |
(Mapping = TAbstractSingleTextureCoordinateNode(T).Mapping) ) then |
| 994 |
begin |
| 995 |
Result := TAbstractSingleTextureCoordinateNode(T); |
| 996 |
TexCoordIndex := 0; |
| 997 |
Exit; |
| 998 |
end; |
| 999 |
|
| 1000 |
if MakeWarning and (Mapping <> '') and (not MappingWarningDone) then |
| 1001 |
begin |
| 1002 |
WritelnWarning('Texture mapping "%s" not matching the only texture coordinate node possible', [Mapping]); |
| 1003 |
MappingWarningDone := true; |
| 1004 |
end; |
| 1005 |
end; |
| 1006 |
end; |
| 1007 |
|
| 1008 |
function TAbstractGeometryNode.Proxy(var State: TX3DGraphTraverseState): TAbstractGeometryNode; |
| 1009 |
begin |
| 1010 |
Result := nil; |
| 1011 |
end; |
| 1012 |
|
| 1013 |
function TAbstractGeometryNode.InternalFogCoord: TMFFloat; |
| 1014 |
begin |
| 1015 |
Result := nil; |
| 1016 |
end; |
| 1017 |
|
| 1018 |
function TAbstractGeometryNode.AttribField: TMFNode; |
| 1019 |
begin |
| 1020 |
Result := nil; |
| 1021 |
end; |
| 1022 |
|
| 1023 |
function TAbstractGeometryNode.AutoGenerate3DTexCoords: boolean; |
| 1024 |
begin |
| 1025 |
Result := false; |
| 1026 |
end; |
| 1027 |
|
| 1028 |
function TAbstractGeometryNode.TransformationChange: TNodeTransformationChange; |
| 1029 |
begin |
| 1030 |
Result := ntcGeometry; |
| 1031 |
end; |
| 1032 |
|
| 1033 |
procedure TAbstractGeometryNode.GetTextureBounds2DST(const LocalBoxSizes: TVector3; |
| 1034 |
out S, T: T3DAxis); |
| 1035 |
var |
| 1036 |
C1, C2: T3DAxis; |
| 1037 |
begin |
| 1038 |
{ Calculate SCoord and TCoord. Following VRML spec: |
| 1039 |
SCoord is the coord where LocalBBoxSize is largest, |
| 1040 |
TCoord is the second-to-largest (and if some sizes are equal, |
| 1041 |
then X is more important than Y than Z). |
| 1042 |
|
| 1043 |
Do it once (setting HasBounds2DST), this fixes JoeH-AnimKick0a.x3dv |
| 1044 |
renderering, see x3d-public thread about castle-model-viewer 3.8.0 announcement. } |
| 1045 |
|
| 1046 |
if not HasBounds2DST then |
| 1047 |
begin |
| 1048 |
HasBounds2DST := true; |
| 1049 |
Bounds2DS := MaxVectorCoord(LocalBoxSizes); |
| 1050 |
RestOf3DCoords(Bounds2DS, C1, C2); |
| 1051 |
if LocalBoxSizes[C1] >= LocalBoxSizes[C2] then |
| 1052 |
Bounds2DT := C1 |
| 1053 |
else |
| 1054 |
Bounds2DT := C2; |
| 1055 |
end; |
| 1056 |
|
| 1057 |
S := Bounds2DS; |
| 1058 |
T := Bounds2DT; |
| 1059 |
end; |
| 1060 |
|
| 1061 |
function TAbstractGeometryNode.Lit(State: TX3DGraphTraverseState): boolean; |
| 1062 |
begin |
| 1063 |
Result := true; |
| 1064 |
end; |
| 1065 |
|
| 1066 |
function TAbstractGeometryNode.ConvexField: TSFBool; |
| 1067 |
begin |
| 1068 |
Result := nil; |
| 1069 |
end; |
| 1070 |
|
| 1071 |
function TAbstractGeometryNode.GetConvex: boolean; |
| 1072 |
var |
| 1073 |
F: TSFBool; |
| 1074 |
begin |
| 1075 |
F := ConvexField; |
| 1076 |
if F <> nil then |
| 1077 |
Result := F.Value else |
| 1078 |
Result := FIgnoredConvex; |
| 1079 |
end; |
| 1080 |
|
| 1081 |
procedure TAbstractGeometryNode.SetConvex(const Value: boolean); |
| 1082 |
var |
| 1083 |
F: TSFBool; |
| 1084 |
begin |
| 1085 |
F := ConvexField; |
| 1086 |
if F <> nil then |
| 1087 |
F.Send(Value) else |
| 1088 |
FIgnoredConvex := Value; |
| 1089 |
end; |
| 1090 |
|
| 1091 |
function TAbstractGeometryNode.SolidField: TSFBool; |
| 1092 |
begin |
| 1093 |
Result := nil; |
| 1094 |
end; |
| 1095 |
|
| 1096 |
function TAbstractGeometryNode.GetSolid: boolean; |
| 1097 |
var |
| 1098 |
F: TSFBool; |
| 1099 |
begin |
| 1100 |
F := SolidField; |
| 1101 |
if F <> nil then |
| 1102 |
Result := F.Value else |
| 1103 |
Result := FIgnoredSolid; |
| 1104 |
end; |
| 1105 |
|
| 1106 |
procedure TAbstractGeometryNode.SetSolid(const Value: boolean); |
| 1107 |
var |
| 1108 |
F: TSFBool; |
| 1109 |
begin |
| 1110 |
F := SolidField; |
| 1111 |
if F <> nil then |
| 1112 |
F.Send(Value) else |
| 1113 |
FIgnoredSolid := Value; |
| 1114 |
end; |
| 1115 |
|
| 1116 |
function TAbstractGeometryNode.ColorField: TSFNode; |
| 1117 |
begin |
| 1118 |
Result := nil; |
| 1119 |
end; |
| 1120 |
|
| 1121 |
function TAbstractGeometryNode.InternalColorNode: TAbstractColorNode; |
| 1122 |
var |
| 1123 |
F: TSFNode; |
| 1124 |
begin |
| 1125 |
F := ColorField; |
| 1126 |
if (F <> nil) and |
| 1127 |
(F.Value is TAbstractColorNode) then |
| 1128 |
Result := TAbstractColorNode(F.Value) |
| 1129 |
else |
| 1130 |
Result := nil; |
| 1131 |
end; |
| 1132 |
|
| 1133 |
function TAbstractGeometryNode.InternalColor: TMFVec3f; |
| 1134 |
var |
| 1135 |
F: TSFNode; |
| 1136 |
begin |
| 1137 |
F := ColorField; |
| 1138 |
if (F <> nil) and |
| 1139 |
(F.Value is TColorNode) then |
| 1140 |
Result := TColorNode(F.Value).FdColor |
| 1141 |
else |
| 1142 |
Result := nil; |
| 1143 |
end; |
| 1144 |
|
| 1145 |
function TAbstractGeometryNode.InternalColorRGBA: TMFColorRGBA; |
| 1146 |
var |
| 1147 |
F: TSFNode; |
| 1148 |
begin |
| 1149 |
F := ColorField; |
| 1150 |
if (F <> nil) and |
| 1151 |
(F.Value is TColorRGBANode) then |
| 1152 |
Result := TColorRGBANode(F.Value).FdColor |
| 1153 |
else |
| 1154 |
Result := nil; |
| 1155 |
end; |
| 1156 |
|
| 1157 |
function TAbstractGeometryNode.FontTextureNode: TAbstractTexture2DNode; |
| 1158 |
begin |
| 1159 |
Result := nil; |
| 1160 |
end; |
| 1161 |
|
| 1162 |
function TAbstractGeometryNode.NormalField: TSFNode; |
| 1163 |
begin |
| 1164 |
Result := nil; |
| 1165 |
end; |
| 1166 |
|
| 1167 |
function TAbstractGeometryNode.TangentField: TSFNode; |
| 1168 |
begin |
| 1169 |
Result := nil; |
| 1170 |
end; |
| 1171 |
|
| 1172 |
function TAbstractGeometryNode.InternalNormal: TVector3List; |
| 1173 |
begin |
| 1174 |
if (NormalField <> nil) and |
| 1175 |
(NormalField.Value is TNormalNode) then |
| 1176 |
Result := TNormalNode(NormalField.Value).FdVector.Items |
| 1177 |
else |
| 1178 |
Result := nil; |
| 1179 |
end; |
| 1180 |
|
| 1181 |
function TAbstractGeometryNode.InternalTangent: TVector3List; |
| 1182 |
begin |
| 1183 |
if (TangentField <> nil) and |
| 1184 |
(TangentField.Value is TTangentNode) then |
| 1185 |
Result := TTangentNode(TangentField.Value).FdVector.Items |
| 1186 |
else |
| 1187 |
Result := nil; |
| 1188 |
end; |
| 1189 |
|
| 1190 |
{ TAbstractComposedGeometryNode ------------------------------------------------------ } |
| 1191 |
|
| 1192 |
function TAbstractComposedGeometryNode.CoordField: TSFNode; |
| 1193 |
begin |
| 1194 |
Result := FdCoord; |
| 1195 |
end; |
| 1196 |
|
| 1197 |
function TAbstractComposedGeometryNode.InternalCoord(State: TX3DGraphTraverseState; |
| 1198 |
out ACoord: TMFVec3f): boolean; |
| 1199 |
begin |
| 1200 |
Result := true; |
| 1201 |
if FdCoord.Value is TCoordinateNode then // also checks that FdCoord.Value <> nil |
| 1202 |
ACoord := TCoordinateNode(FdCoord.Value).FdPoint |
| 1203 |
else |
| 1204 |
ACoord := nil; |
| 1205 |
end; |
| 1206 |
|
| 1207 |
function TAbstractComposedGeometryNode.TexCoordField: TSFNode; |
| 1208 |
begin |
| 1209 |
Result := FdTexCoord; |
| 1210 |
end; |
| 1211 |
|
| 1212 |
function TAbstractComposedGeometryNode.ColorField: TSFNode; |
| 1213 |
begin |
| 1214 |
Result := FdColor; |
| 1215 |
end; |
| 1216 |
|
| 1217 |
function TAbstractComposedGeometryNode.SolidField: TSFBool; |
| 1218 |
begin |
| 1219 |
Result := FdSolid; |
| 1220 |
end; |
| 1221 |
|
| 1222 |
function TAbstractComposedGeometryNode.InternalFogCoord: TMFFloat; |
| 1223 |
begin |
| 1224 |
{$ifndef CASTLE_SLIM_NODES} |
| 1225 |
if (FdFogCoord.Value <> nil) and |
| 1226 |
(FdFogCoord.Value is TFogCoordinateNode) then |
| 1227 |
Result := TFogCoordinateNode(FdFogCoord.Value).FdDepth |
| 1228 |
else |
| 1229 |
{$endif} |
| 1230 |
Result := nil; |
| 1231 |
end; |
| 1232 |
|
| 1233 |
function TAbstractComposedGeometryNode.AttribField: TMFNode; |
| 1234 |
begin |
| 1235 |
Result := {$ifndef CASTLE_SLIM_NODES} FdAttrib {$else} nil {$endif}; |
| 1236 |
end; |
| 1237 |
|
| 1238 |
function TAbstractComposedGeometryNode.NormalField: TSFNode; |
| 1239 |
begin |
| 1240 |
Result := FdNormal; |
| 1241 |
end; |
| 1242 |
|
| 1243 |
function TAbstractComposedGeometryNode.TangentField: TSFNode; |
| 1244 |
begin |
| 1245 |
Result := FdTangent; |
| 1246 |
end; |
| 1247 |
|
| 1248 |
function TAbstractComposedGeometryNode.DirectEnumerateActive(Func: TEnumerateChildrenFunction): Pointer; |
| 1249 |
begin |
| 1250 |
{$ifndef CASTLE_SLIM_NODES} |
| 1251 |
Result := Fdattrib.Enumerate(Func); |
| 1252 |
if Result <> nil then Exit; |
| 1253 |
{$endif} |
| 1254 |
|
| 1255 |
Result := Fdcolor.Enumerate(Func); |
| 1256 |
if Result <> nil then Exit; |
| 1257 |
|
| 1258 |
Result := Fdcoord.Enumerate(Func); |
| 1259 |
if Result <> nil then Exit; |
| 1260 |
|
| 1261 |
{$ifndef CASTLE_SLIM_NODES} |
| 1262 |
Result := FdfogCoord.Enumerate(Func); |
| 1263 |
if Result <> nil then Exit; |
| 1264 |
{$endif} |
| 1265 |
|
| 1266 |
Result := FdNormal.Enumerate(Func); |
| 1267 |
if Result <> nil then Exit; |
| 1268 |
|
| 1269 |
Result := FdTangent.Enumerate(Func); |
| 1270 |
if Result <> nil then Exit; |
| 1271 |
|
| 1272 |
Result := FdtexCoord.Enumerate(Func); |
| 1273 |
if Result <> nil then Exit; |
| 1274 |
end; |
| 1275 |
|
| 1276 |
{ TClipPlaneNode ------------------------------------------------------------- } |
| 1277 |
|
| 1278 |
procedure TClipPlaneNode.GroupBeforeTraverse(const State: TX3DGraphTraverseState; var WasPointingDeviceSensor: Boolean); |
| 1279 |
var |
| 1280 |
CP: PClipPlane; |
| 1281 |
begin |
| 1282 |
inherited; |
| 1283 |
CP := State.AddClipPlane; |
| 1284 |
CP^.Node := Self; |
| 1285 |
CP^.Transform := State.Transformation.Transform; |
| 1286 |
end; |
| 1287 |
|
| 1288 |
{ TCoordinateNode ------------------------------------------------------------ } |
| 1289 |
|
| 1290 |
function TCoordinateNode.CoordCount: Cardinal; |
| 1291 |
begin |
| 1292 |
Result := FdPoint.Items.Count; |
| 1293 |
end; |
| 1294 |
|
| 1295 |
{ TIndexedLineSetNode -------------------------------------------------------- } |
| 1296 |
|
| 1297 |
constructor TIndexedLineSetNode.Create(const AX3DName, ABaseUrl: String); |
| 1298 |
begin |
| 1299 |
inherited; |
| 1300 |
Eventset_colorIndex.AddNotification({$ifdef FPC}@{$endif} EventSet_ColorIndexReceive); |
| 1301 |
Eventset_coordIndex.AddNotification({$ifdef FPC}@{$endif} EventSet_CoordIndexReceive); |
| 1302 |
end; |
| 1303 |
|
| 1304 |
class function TIndexedLineSetNode.ForVRMLVersion(const Version: TX3DVersion): boolean; |
| 1305 |
begin |
| 1306 |
Result := Version.Major >= 2; |
| 1307 |
end; |
| 1308 |
|
| 1309 |
function TIndexedLineSetNode.CoordField: TSFNode; |
| 1310 |
begin |
| 1311 |
Result := FdCoord; |
| 1312 |
end; |
| 1313 |
|
| 1314 |
function TIndexedLineSetNode.InternalCoord(State: TX3DGraphTraverseState; |
| 1315 |
out ACoord: TMFVec3f): boolean; |
| 1316 |
begin |
| 1317 |
Result := true; |
| 1318 |
if FdCoord.Value is TCoordinateNode then // also checks that FdCoord.Value <> nil |
| 1319 |
ACoord := TCoordinateNode(FdCoord.Value).FdPoint |
| 1320 |
else |
| 1321 |
ACoord := nil; |
| 1322 |
end; |
| 1323 |
|
| 1324 |
function TIndexedLineSetNode.ColorField: TSFNode; |
| 1325 |
begin |
| 1326 |
Result := FdColor; |
| 1327 |
end; |
| 1328 |
|
| 1329 |
function TIndexedLineSetNode.InternalFogCoord: TMFFloat; |
| 1330 |
begin |
| 1331 |
{$ifndef CASTLE_SLIM_NODES} |
| 1332 |
if (FdFogCoord.Value <> nil) and |
| 1333 |
(FdFogCoord.Value is TFogCoordinateNode) then |
| 1334 |
Result := TFogCoordinateNode(FdFogCoord.Value).FdDepth |
| 1335 |
else |
| 1336 |
{$endif} |
| 1337 |
Result := nil; |
| 1338 |
end; |
| 1339 |
|
| 1340 |
function TIndexedLineSetNode.AttribField: TMFNode; |
| 1341 |
begin |
| 1342 |
Result := {$ifndef CASTLE_SLIM_NODES} FdAttrib {$else} nil {$endif}; |
| 1343 |
end; |
| 1344 |
|
| 1345 |
function TIndexedLineSetNode.CoordIndexField: TMFLong; |
| 1346 |
begin |
| 1347 |
Result := FdCoordIndex; |
| 1348 |
end; |
| 1349 |
|
| 1350 |
procedure TIndexedLineSetNode.EventSet_ColorIndexReceive( |
| 1351 |
const Event: TX3DEvent; const Value: TX3DField; const Time: TX3DTime); |
| 1352 |
begin |
| 1353 |
FdColorIndex.Assign(Value); |
| 1354 |
FdColorIndex.Changed; |
| 1355 |
end; |
| 1356 |
|
| 1357 |
procedure TIndexedLineSetNode.EventSet_CoordIndexReceive( |
| 1358 |
const Event: TX3DEvent; const Value: TX3DField; const Time: TX3DTime); |
| 1359 |
begin |
| 1360 |
FdCoordIndex.Assign(Value); |
| 1361 |
FdCoordIndex.Changed; |
| 1362 |
end; |
| 1363 |
|
| 1364 |
function TIndexedLineSetNode.Lit(State: TX3DGraphTraverseState): boolean; |
| 1365 |
begin |
| 1366 |
{ VRML 2.0 specification says that IndexedLineSet should always be unlit } |
| 1367 |
Result := false; |
| 1368 |
end; |
| 1369 |
|
| 1370 |
{ TIndexedTriangleFanSetNode ------------------------------------------------- } |
| 1371 |
|
| 1372 |
constructor TIndexedTriangleFanSetNode.Create(const AX3DName, ABaseUrl: String); |
| 1373 |
begin |
| 1374 |
inherited; |
| 1375 |
Eventset_index.AddNotification({$ifdef FPC}@{$endif} EventSet_IndexReceive); |
| 1376 |
end; |
| 1377 |
|
| 1378 |
function TIndexedTriangleFanSetNode.CoordIndexField: TMFLong; |
| 1379 |
begin |
| 1380 |
Result := FdIndex; |
| 1381 |
end; |
| 1382 |
|
| 1383 |
procedure TIndexedTriangleFanSetNode.EventSet_IndexReceive( |
| 1384 |
const Event: TX3DEvent; const Value: TX3DField; const Time: TX3DTime); |
| 1385 |
begin |
| 1386 |
FdIndex.Send(Value); |
| 1387 |
end; |
| 1388 |
|
| 1389 |
function TIndexedTriangleFanSetNode.FieldSetByEvent(const Event: TX3DEvent): TX3DField; |
| 1390 |
begin |
| 1391 |
if Event = EventSet_index then |
| 1392 |
Exit(FdIndex); |
| 1393 |
Result := inherited; |
| 1394 |
end; |
| 1395 |
|
| 1396 |
{ TIndexedTriangleSetNode ---------------------------------------------------- } |
| 1397 |
|
| 1398 |
constructor TIndexedTriangleSetNode.Create(const AX3DName, ABaseUrl: String); |
| 1399 |
begin |
| 1400 |
inherited; |
| 1401 |
Eventset_index.AddNotification({$ifdef FPC}@{$endif} EventSet_IndexReceive); |
| 1402 |
end; |
| 1403 |
|
| 1404 |
function TIndexedTriangleSetNode.CoordIndexField: TMFLong; |
| 1405 |
begin |
| 1406 |
Result := FdIndex; |
| 1407 |
end; |
| 1408 |
|
| 1409 |
procedure TIndexedTriangleSetNode.EventSet_IndexReceive( |
| 1410 |
const Event: TX3DEvent; const Value: TX3DField; const Time: TX3DTime); |
| 1411 |
begin |
| 1412 |
FdIndex.Send(Value); |
| 1413 |
end; |
| 1414 |
|
| 1415 |
function TIndexedTriangleSetNode.FieldSetByEvent(const Event: TX3DEvent): TX3DField; |
| 1416 |
begin |
| 1417 |
if Event = EventSet_index then |
| 1418 |
Exit(FdIndex); |
| 1419 |
Result := inherited; |
| 1420 |
end; |
| 1421 |
|
| 1422 |
{ TIndexedTriangleStripSetNode ----------------------------------------------- } |
| 1423 |
|
| 1424 |
constructor TIndexedTriangleStripSetNode.Create(const AX3DName, ABaseUrl: String); |
| 1425 |
begin |
| 1426 |
inherited; |
| 1427 |
Eventset_index.AddNotification({$ifdef FPC}@{$endif} EventSet_IndexReceive); |
| 1428 |
end; |
| 1429 |
|
| 1430 |
function TIndexedTriangleStripSetNode.CoordIndexField: TMFLong; |
| 1431 |
begin |
| 1432 |
Result := FdIndex; |
| 1433 |
end; |
| 1434 |
|
| 1435 |
procedure TIndexedTriangleStripSetNode.EventSet_IndexReceive( |
| 1436 |
const Event: TX3DEvent; const Value: TX3DField; const Time: TX3DTime); |
| 1437 |
begin |
| 1438 |
FdIndex.Send(Value); |
| 1439 |
end; |
| 1440 |
|
| 1441 |
function TIndexedTriangleStripSetNode.FieldSetByEvent(const Event: TX3DEvent): TX3DField; |
| 1442 |
begin |
| 1443 |
if Event = EventSet_index then |
| 1444 |
Exit(FdIndex); |
| 1445 |
Result := inherited; |
| 1446 |
end; |
| 1447 |
|
| 1448 |
{ TLineSetNode --------------------------------------------------------------- } |
| 1449 |
|
| 1450 |
destructor TLineSetNode.Destroy; |
| 1451 |
begin |
| 1452 |
FreeAndNil(FVertexCountForPair); |
| 1453 |
inherited; |
| 1454 |
end; |
| 1455 |
|
| 1456 |
function TLineSetNode.CoordField: TSFNode; |
| 1457 |
begin |
| 1458 |
Result := FdCoord; |
| 1459 |
end; |
| 1460 |
|
| 1461 |
function TLineSetNode.InternalCoord(State: TX3DGraphTraverseState; |
| 1462 |
out ACoord: TMFVec3f): boolean; |
| 1463 |
begin |
| 1464 |
Result := true; |
| 1465 |
if FdCoord.Value is TCoordinateNode then // also checks that FdCoord.Value <> nil |
| 1466 |
ACoord := TCoordinateNode(FdCoord.Value).FdPoint |
| 1467 |
else |
| 1468 |
ACoord := nil; |
| 1469 |
end; |
| 1470 |
|
| 1471 |
function TLineSetNode.ColorField: TSFNode; |
| 1472 |
begin |
| 1473 |
Result := FdColor; |
| 1474 |
end; |
| 1475 |
|
| 1476 |
function TLineSetNode.InternalFogCoord: TMFFloat; |
| 1477 |
begin |
| 1478 |
{$ifndef CASTLE_SLIM_NODES} |
| 1479 |
if (FdFogCoord.Value <> nil) and |
| 1480 |
(FdFogCoord.Value is TFogCoordinateNode) then |
| 1481 |
Result := TFogCoordinateNode(FdFogCoord.Value).FdDepth |
| 1482 |
else |
| 1483 |
{$endif} |
| 1484 |
Result := nil; |
| 1485 |
end; |
| 1486 |
|
| 1487 |
function TLineSetNode.AttribField: TMFNode; |
| 1488 |
begin |
| 1489 |
Result := {$ifndef CASTLE_SLIM_NODES} FdAttrib {$else} nil {$endif}; |
| 1490 |
end; |
| 1491 |
|
| 1492 |
function TLineSetNode.InternalCoordRangesCounts( |
| 1493 |
out RangeCount: TInt32List; |
| 1494 |
out SRanges, SRangeName: string; |
| 1495 |
out RangeMinimumCount: Cardinal): boolean; |
| 1496 |
var |
| 1497 |
CoordCount: Integer; |
| 1498 |
begin |
| 1499 |
if Mode = lmPair then |
| 1500 |
begin |
| 1501 |
{ For lmPair, return just the count of coordinates. |
| 1502 |
These vertexes form one big "lines primitive" for rendering. } |
| 1503 |
if FVertexCountForPair = nil then |
| 1504 |
FVertexCountForPair := TInt32List.Create; |
| 1505 |
if FdCoord.Value is TCoordinateNode then // also checks that FdCoord.Value <> nil |
| 1506 |
CoordCount := TCoordinateNode(FdCoord.Value).FdPoint.Count |
| 1507 |
else |
| 1508 |
CoordCount := 0; |
| 1509 |
if CoordCount <> 0 then |
| 1510 |
begin |
| 1511 |
FVertexCountForPair.Count := 1; |
| 1512 |
FVertexCountForPair[0] := CoordCount; |
| 1513 |
end else |
| 1514 |
begin |
| 1515 |
{ When no coordinates, make RangeCount an empty list, |
| 1516 |
to avoid warnings from TAbstractGeometryNode.InternalMakeCoordRanges |
| 1517 |
that LineSet doesn't have 2 coordinates when using |
| 1518 |
TLineSetNode.Mode = lmPair with empty coordinates. |
| 1519 |
Testcase: CGE editor camera gizmo visualizations, should not make warnings. } |
| 1520 |
FVertexCountForPair.Count := 0; |
| 1521 |
end; |
| 1522 |
RangeCount := FVertexCountForPair; |
| 1523 |
end else |
| 1524 |
RangeCount := FdVertexCount.Items; |
| 1525 |
|
| 1526 |
SRanges := 'lines'; |
| 1527 |
SRangeName := 'Vertex count'; |
| 1528 |
RangeMinimumCount := 2; |
| 1529 |
Result := true; |
| 1530 |
end; |
| 1531 |
|
| 1532 |
function TLineSetNode.DirectEnumerateActive(Func: TEnumerateChildrenFunction): Pointer; |
| 1533 |
begin |
| 1534 |
{$ifndef CASTLE_SLIM_NODES} |
| 1535 |
Result := Fdattrib.Enumerate(Func); |
| 1536 |
if Result <> nil then Exit; |
| 1537 |
{$endif} |
| 1538 |
|
| 1539 |
Result := Fdcolor.Enumerate(Func); |
| 1540 |
if Result <> nil then Exit; |
| 1541 |
|
| 1542 |
Result := Fdcoord.Enumerate(Func); |
| 1543 |
if Result <> nil then Exit; |
| 1544 |
|
| 1545 |
{$ifndef CASTLE_SLIM_NODES} |
| 1546 |
Result := FdfogCoord.Enumerate(Func); |
| 1547 |
if Result <> nil then Exit; |
| 1548 |
{$endif} |
| 1549 |
end; |
| 1550 |
|
| 1551 |
function TLineSetNode.Lit(State: TX3DGraphTraverseState): boolean; |
| 1552 |
begin |
| 1553 |
{ X3D specification says that LineSet should always be unlit } |
| 1554 |
Result := false; |
| 1555 |
end; |
| 1556 |
|
| 1557 |
{ TTangentNode --------------------------------------------------------------- } |
| 1558 |
|
| 1559 |
procedure TTangentNode.SetVector4D(const List: TVector4List); |
| 1560 |
var |
| 1561 |
I, Len: Integer; |
| 1562 |
Source: PVector4; |
| 1563 |
Dest: PVector3; |
| 1564 |
W: Single; |
| 1565 |
begin |
| 1566 |
Len := List.Count; |
| 1567 |
FdVector.Items.Count := Len; |
| 1568 |
if Len = 0 then Exit; |
| 1569 |
|
| 1570 |
Source := PVector4(List.L); |
| 1571 |
Dest := PVector3(FdVector.Items.L); |
| 1572 |
for I := 0 to Len - 1 do |
| 1573 |
begin |
| 1574 |
// convert tangents to right-handed |
| 1575 |
// slower: Dest^ := Source^.XYZ * Source^.W; |
| 1576 |
W := Source^.W; |
| 1577 |
Dest^.X := Source^.X * W; |
| 1578 |
Dest^.Y := Source^.Y * W; |
| 1579 |
Dest^.Z := Source^.Z * W; |
| 1580 |
Inc(Source); |
| 1581 |
Inc(Dest); |
| 1582 |
end; |
| 1583 |
end; |
| 1584 |
|
| 1585 |
class function TPointSetNode.ForVRMLVersion(const Version: TX3DVersion): boolean; |
| 1586 |
begin |
| 1587 |
Result := Version.Major >= 2; |
| 1588 |
end; |
| 1589 |
|
| 1590 |
function TPointSetNode.CoordField: TSFNode; |
| 1591 |
begin |
| 1592 |
Result := FdCoord; |
| 1593 |
end; |
| 1594 |
|
| 1595 |
function TPointSetNode.InternalCoord(State: TX3DGraphTraverseState; |
| 1596 |
out ACoord: TMFVec3f): boolean; |
| 1597 |
begin |
| 1598 |
Result := true; |
| 1599 |
if FdCoord.Value is TCoordinateNode then // also checks that FdCoord.Value <> nil |
| 1600 |
ACoord := TCoordinateNode(FdCoord.Value).FdPoint |
| 1601 |
else |
| 1602 |
ACoord := nil; |
| 1603 |
end; |
| 1604 |
|
| 1605 |
function TPointSetNode.ColorField: TSFNode; |
| 1606 |
begin |
| 1607 |
Result := FdColor; |
| 1608 |
end; |
| 1609 |
|
| 1610 |
function TPointSetNode.InternalFogCoord: TMFFloat; |
| 1611 |
begin |
| 1612 |
{$ifndef CASTLE_SLIM_NODES} |
| 1613 |
if (FdFogCoord.Value <> nil) and |
| 1614 |
(FdFogCoord.Value is TFogCoordinateNode) then |
| 1615 |
Result := TFogCoordinateNode(FdFogCoord.Value).FdDepth |
| 1616 |
else |
| 1617 |
{$endif} |
| 1618 |
Result := nil; |
| 1619 |
end; |
| 1620 |
|
| 1621 |
function TPointSetNode.AttribField: TMFNode; |
| 1622 |
begin |
| 1623 |
Result := {$ifndef CASTLE_SLIM_NODES} FdAttrib {$else} nil {$endif}; |
| 1624 |
end; |
| 1625 |
|
| 1626 |
function TPointSetNode.DirectEnumerateActive(Func: TEnumerateChildrenFunction): Pointer; |
| 1627 |
begin |
| 1628 |
{$ifndef CASTLE_SLIM_NODES} |
| 1629 |
Result := Fdattrib.Enumerate(Func); |
| 1630 |
if Result <> nil then Exit; |
| 1631 |
{$endif} |
| 1632 |
|
| 1633 |
Result := Fdcolor.Enumerate(Func); |
| 1634 |
if Result <> nil then Exit; |
| 1635 |
|
| 1636 |
Result := Fdcoord.Enumerate(Func); |
| 1637 |
if Result <> nil then Exit; |
| 1638 |
|
| 1639 |
{$ifndef CASTLE_SLIM_NODES} |
| 1640 |
Result := FdfogCoord.Enumerate(Func); |
| 1641 |
if Result <> nil then Exit; |
| 1642 |
{$endif} |
| 1643 |
end; |
| 1644 |
|
| 1645 |
function TPointSetNode.Lit(State: TX3DGraphTraverseState): boolean; |
| 1646 |
begin |
| 1647 |
Result := false; |
| 1648 |
end; |
| 1649 |
|
| 1650 |
{ TTriangleFanSetNode -------------------------------------------------------- } |
| 1651 |
|
| 1652 |
function TTriangleFanSetNode.InternalCoordRangesCounts( |
| 1653 |
out RangeCount: TInt32List; |
| 1654 |
out SRanges, SRangeName: string; |
| 1655 |
out RangeMinimumCount: Cardinal): boolean; |
| 1656 |
begin |
| 1657 |
RangeCount := FdFanCount.Items; |
| 1658 |
SRanges := 'fans'; |
| 1659 |
SRangeName := 'Fan count'; |
| 1660 |
RangeMinimumCount := 3; |
| 1661 |
Result := true; |
| 1662 |
end; |
| 1663 |
|
| 1664 |
{ TTriangleStripSetNode ------------------------------------------------------ } |
| 1665 |
|
| 1666 |
function TTriangleStripSetNode.InternalCoordRangesCounts( |
| 1667 |
out RangeCount: TInt32List; |
| 1668 |
out SRanges, SRangeName: string; |
| 1669 |
out RangeMinimumCount: Cardinal): boolean; |
| 1670 |
begin |
| 1671 |
RangeCount := FdStripCount.Items; |
| 1672 |
SRanges := 'strips'; |
| 1673 |
SRangeName := 'Strip count'; |
| 1674 |
RangeMinimumCount := 3; |
| 1675 |
Result := true; |
| 1676 |
end; |
| 1677 |
|
| 1678 |
procedure RegisterRenderingNodes; |
| 1679 |
begin |
| 1680 |
NodesManager.RegisterNodeClasses([ |
| 1681 |
TClipPlaneNode, |
| 1682 |
TColorNode, |
| 1683 |
TColorRGBANode, |
| 1684 |
TCoordinateNode, |
| 1685 |
TIndexedLineSetNode, |
| 1686 |
TIndexedTriangleFanSetNode, |
| 1687 |
TIndexedTriangleSetNode, |
| 1688 |
TIndexedTriangleStripSetNode, |
| 1689 |
TLineSetNode, |
| 1690 |
TNormalNode, |
| 1691 |
TTangentNode, |
| 1692 |
TPointSetNode, |
| 1693 |
TTriangleFanSetNode, |
| 1694 |
TTriangleSetNode, |
| 1695 |
TTriangleStripSetNode |
| 1696 |
]); |
| 1697 |
end; |
| 1698 |
|
| 1699 |
{$endif read_implementation} |