/usr/src/castle-game-engine-5.0.0/x3d/x3dnodes_avalon.inc is in castle-game-engine-src 5.0.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 | {
Copyright 2008-2014 Michalis Kamburelis.
This file is part of "Castle Game Engine".
"Castle Game Engine" is free software; see the file COPYING.txt,
included in this distribution, for details about the copyright.
"Castle Game Engine" is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
----------------------------------------------------------------------------
}
{ Nodes that are defined by Avalon extensions, see
[http://instant-reality.com/] and in particular the specifications on
[http://instant-reality.com/documentation/nodetype/]. }
{$ifdef read_interface}
{ MatrixTransform node for VRML/X3D >= 2.0. From Avalon extension,
see [http://instant-reality.com/documentation/nodetype/MatrixTransform/]. }
TMatrixTransformNode = class(TAbstractX3DGroupingNode, ITransformNode)
protected
procedure DirectEnumerateActive(
Func: TEnumerateChildrenFunction); override;
procedure ApplyTransform(State: TX3DGraphTraverseState); override;
public
procedure CreateNode; override;
class function ClassNodeTypeName: string; override;
class function URNMatching(const URN: string): boolean; override;
class function ForVRMLVersion(const Version: TX3DVersion): boolean;
override;
function TransformationChange: TNodeTransformationChange; override;
private FFdMatrix: TSFMatrix4f;
public property FdMatrix: TSFMatrix4f read FFdMatrix;
end;
TMatrixTransformNode_2 = TMatrixTransformNode;
TTeapotNode = class(TAbstractX3DGeometryNode)
protected
procedure DirectEnumerateActive(
Func: TEnumerateChildrenFunction); override;
public
procedure CreateNode; override;
class function ClassNodeTypeName: string; override;
class function URNMatching(const URN: string): boolean; override;
private FFdSize: TSFVec3f;
public property FdSize: TSFVec3f read FFdSize;
private FFdSolid: TSFBool;
public property FdSolid: TSFBool read FFdSolid;
private FFdManifold: TSFBool;
public property FdManifold: TSFBool read FFdManifold;
private FFdTexCoord: TSFNode;
public property FdTexCoord: TSFNode read FFdTexCoord;
function Proxy(var State: TX3DGraphTraverseState;
const OverTriangulate: boolean): TAbstractGeometryNode; override;
function ProxyUsesOverTriangulate: boolean; override;
function TexCoordField: TSFNode; override;
function AutoGenerate3DTexCoords: boolean; override;
end;
TLoggerNode = class(TAbstractChildNode)
private
WriteStream: TStream;
OwnsWriteStream: boolean;
WriteStreamInitialized: boolean;
procedure EventWriteReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
public
procedure CreateNode; override;
destructor Destroy; override;
class function ClassNodeTypeName: string; override;
class function URNMatching(const URN: string): boolean; override;
private FFdLevel: TSFInt32;
public property FdLevel: TSFInt32 read FFdLevel;
private FFdLogFile: TSFString;
public property FdLogFile: TSFString read FFdLogFile;
private FFdEnabled: TSFBool;
public property FdEnabled: TSFBool read FFdEnabled;
private FEventWrite: TXFAnyEvent;
public property EventWrite: TXFAnyEvent read FEventWrite;
end;
TConverterNode = class(TAbstractChildNode)
private
procedure EventInReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
public
procedure CreateNode; override;
class function ClassNodeTypeName: string; override;
class function URNMatching(const URN: string): boolean; override;
private FFdEnabled: TSFBool;
public property FdEnabled: TSFBool read FFdEnabled;
{ Event in } { }
private FEventIn: TXFAnyEvent;
public property EventIn: TXFAnyEvent read FEventIn;
{ Event out } { }
private FEventOut: TXFAnyEvent;
public property EventOut: TXFAnyEvent read FEventOut;
end;
TRenderedTextureNode = class(TAbstractTextureNode)
private
FGeneratedTextureHandler: TGeneratedTextureHandler;
public
procedure CreateNode; override;
destructor Destroy; override;
class function ClassNodeTypeName: string; override;
class function URNMatching(const URN: string): boolean; override;
property GeneratedTextureHandler: TGeneratedTextureHandler
read FGeneratedTextureHandler;
private FFdViewpoint: TSFNode;
public property FdViewpoint: TSFNode read FFdViewpoint;
private FFdBackground: TSFNode;
public property FdBackground: TSFNode read FFdBackground;
private FFdFog: TSFNode;
public property FdFog: TSFNode read FFdFog;
private FFdEnvironment: TSFNode;
public property FdEnvironment: TSFNode read FFdEnvironment;
private FFdScene: TSFNode;
public property FdScene: TSFNode read FFdScene;
private FFdDimensions: TMFInt32;
public property FdDimensions: TMFInt32 read FFdDimensions;
private FFdDepthMap: TMFBool;
public property FdDepthMap: TMFBool read FFdDepthMap;
private FFdForeground: TSFNode;
public property FdForeground: TSFNode read FFdForeground;
private FFdZOffset: TMFInt32;
public property FdZOffset: TMFInt32 read FFdZOffset;
private FFdTargets: TMFNode;
public property FdTargets: TMFNode read FFdTargets;
private FFdDescription: TSFString;
public property FdDescription: TSFString read FFdDescription;
{ Event out } { }
private FEventViewing: TSFMatrix4fEvent;
public property EventViewing: TSFMatrix4fEvent read FEventViewing;
{ Event out } { }
private FEventProjection: TSFMatrix4fEvent;
public property EventProjection: TSFMatrix4fEvent read FEventProjection;
private FFdUpdate: TSFTextureUpdate;
public property FdUpdate: TSFTextureUpdate read FFdUpdate;
private FFdFrameBufferMode: TSFString;
public property FdFrameBufferMode: TSFString read FFdFrameBufferMode;
private FFdExcludeNodes: TMFNode;
public property FdExcludeNodes: TMFNode read FFdExcludeNodes;
private FFdTriggerName: TSFString;
public property FdTriggerName: TSFString read FFdTriggerName;
{ Event in } { }
private FEventTriggerSlot: TSFTimeEvent;
public property EventTriggerSlot: TSFTimeEvent read FEventTriggerSlot;
{ Event out } { }
private FEventImage_changed: TSFImageEvent;
public property EventImage_changed: TSFImageEvent read FEventImage_changed;
private FFdTextureProperties: TSFNode;
public property FdTextureProperties: TSFNode read FFdTextureProperties;
private FFdRepeatS: TSFBool;
public property FdRepeatS: TSFBool read FFdRepeatS;
private FFdRepeatT: TSFBool;
public property FdRepeatT: TSFBool read FFdRepeatT;
private FFdRepeatR: TSFBool;
public property FdRepeatR: TSFBool read FFdRepeatR;
{ Event out } { }
private FEventRendering: TSFBoolEvent;
public property EventRendering: TSFBoolEvent read FEventRendering;
end;
TPlaneNode = class(TAbstractX3DGeometryNode)
public
procedure CreateNode; override;
class function ClassNodeTypeName: string; override;
class function URNMatching(const URN: string): boolean; override;
private FFdSize: TSFVec2f;
public property FdSize: TSFVec2f read FFdSize;
private FFdSolid: TSFBool;
public property FdSolid: TSFBool read FFdSolid;
function Proxy(var State: TX3DGraphTraverseState;
const OverTriangulate: boolean): TAbstractGeometryNode; override;
function ProxyUsesOverTriangulate: boolean; override;
end;
TTogglerNode = class(TAbstractChildNode)
private
procedure EventStatusReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
procedure EventNotStatusReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
procedure EventToggleReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
procedure EventSetReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
procedure EventResetReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
public
procedure CreateNode; override;
class function ClassNodeTypeName: string; override;
class function URNMatching(const URN: string): boolean; override;
private FFdStatus: TSFBool;
public property FdStatus: TSFBool read FFdStatus;
private FFdNotStatus: TSFBool;
public property FdNotStatus: TSFBool read FFdNotStatus;
{ Event in } { }
private FEventToggle: TXFAnyEvent;
public property EventToggle: TXFAnyEvent read FEventToggle;
{ Event in } { }
private FEventSet: TXFAnyEvent;
public property EventSet: TXFAnyEvent read FEventSet;
{ Event in } { }
private FEventReset: TXFAnyEvent;
public property EventReset: TXFAnyEvent read FEventReset;
{ Event out } { }
private FEventChanged: TSFBoolEvent;
public property EventChanged: TSFBoolEvent read FEventChanged;
{ Event out } { }
private FEventOn: TSFBoolEvent;
public property EventOn: TSFBoolEvent read FEventOn;
{ Event out } { }
private FEventOff: TSFBoolEvent;
public property EventOff: TSFBoolEvent read FEventOff;
private FFdEnabled: TSFBool;
public property FdEnabled: TSFBool read FFdEnabled;
end;
{$endif read_interface}
{$ifdef read_implementation}
procedure TMatrixTransformNode.CreateNode;
begin
inherited;
FFdMatrix := TSFMatrix4f.Create(Self, 'matrix', IdentityMatrix4Single);
FdMatrix.ChangesAlways := [chTransform];
Fields.Add(FFdMatrix);
DefaultContainerField := 'children';
end;
class function TMatrixTransformNode.ClassNodeTypeName: string;
begin
Result := 'MatrixTransform';
end;
class function TMatrixTransformNode.URNMatching(const URN: string): boolean;
begin
Result := (inherited URNMatching(URN)) or
(URN = URNKambiNodes + ClassNodeTypeName) or
(URN = URNKambiNodes2 + ClassNodeTypeName);
end;
class function TMatrixTransformNode.ForVRMLVersion(const Version: TX3DVersion): boolean;
begin
Result := Version.Major >= 2;
end;
procedure TMatrixTransformNode.DirectEnumerateActive(Func: TEnumerateChildrenFunction);
var
I: Integer;
begin
for I := 0 to FdChildren.Count - 1 do
Func(Self, FdChildren[I]);
end;
procedure TMatrixTransformNode.ApplyTransform(State: TX3DGraphTraverseState);
var
InvertedMatrix: TMatrix4Single;
begin
inherited;
{ Inherited TAbstractGroupingNode already saved State.Transform and such. }
State.Transform := MatrixMult(State.Transform, FdMatrix.Value);
if TryMatrixInverse(FdMatrix.Value, InvertedMatrix) then
begin
State.InvertedTransform :=
MatrixMult(InvertedMatrix, State.InvertedTransform);
end else
begin
if Log then
WritelnLogMultiline('Matrix',
'Cannot invert matrix:' + NL + MatrixToRawStr(FdMatrix.Value, ' '));
{ When determinant is zero, we treat inverted matrix
like identity (like in TMatrixTransformNode_1.Transformation).
So no need to multiply State.InvertedTransform by anything. }
end;
State.TransformScale *= FdMatrix.TransformScale;
end;
function TMatrixTransformNode.TransformationChange: TNodeTransformationChange;
begin
Result := ntcTransform;
end;
procedure TTeapotNode.CreateNode;
begin
inherited;
FFdSize := TSFVec3f.Create(Self, 'size', Vector3Single(3, 3, 3));
FdSize.Exposed := false;
FdSize.ChangesAlways := [chGeometry];
Fields.Add(FFdSize);
FFdSolid := TSFBool.Create(Self, 'solid', true);
FdSolid.Exposed := false;
FdSolid.ChangesAlways := [chGeometry];
Fields.Add(FFdSolid);
FFdManifold := TSFBool.Create(Self, 'manifold', false);
FdManifold.Exposed := false;
FdManifold.ChangesAlways := [chGeometry];
Fields.Add(FFdManifold);
FFdTexCoord := TSFNode.Create(Self, 'texCoord', [TTextureCoordinateGeneratorNode, TProjectedTextureCoordinateNode, TMultiTextureCoordinateNode]);
FdTexCoord.ChangesAlways := [chGeometry];
Fields.Add(FFdTexCoord);
end;
class function TTeapotNode.ClassNodeTypeName: string;
begin
Result := 'Teapot';
end;
class function TTeapotNode.URNMatching(const URN: string): boolean;
begin
Result := (inherited URNMatching(URN)) or
(URN = URNKambiNodes + ClassNodeTypeName) or
(URN = URNKambiNodes2 + ClassNodeTypeName);
end;
function TTeapotNode.Proxy(var State: TX3DGraphTraverseState;
const OverTriangulate: boolean): TAbstractGeometryNode;
const
{ TeapotCoord: array [0..0] of TVector3Single = ((0, 0, 0));
TeapotCoordIndex: array [0..0] of LongInt = (0);
TeapotManifoldCoord: array [0..0] of TVector3Single = ((0, 0, 0));
TeapotManifoldCoordIndex: array [0..0] of LongInt = (0);
}
{$I teapot/teapot.inc}
var
CoordNode: TCoordinateNode;
IFS: TIndexedFaceSetNode absolute Result;
begin
IFS := TIndexedFaceSetNode.Create(NodeName, BaseUrl);
try
CoordNode := TCoordinateNode.Create('', BaseUrl);
IFS.FdCoord.Value := CoordNode;
if FdManifold.Value then
CoordNode.FdPoint.Items.AssignArray(TeapotManifoldCoord) else
CoordNode.FdPoint.Items.AssignArray(TeapotCoord);
{ Scale Coords according to "size" field.
Assumes that original coords are good for default size (3, 3, 3). }
if not FdSize.EqualsDefaultValue then
begin
CoordNode.FdPoint.Items.MultiplyComponents(
VectorScale(FdSize.Value, 1/3));
end;
if FdManifold.Value then
IFS.FdCoordIndex.Items.AddArray(TeapotManifoldCoordIndex) else
IFS.FdCoordIndex.Items.AddArray(TeapotCoordIndex);
IFS.FdSolid.Value := FdSolid.Value;
if FdTexCoord.CurrentChildAllowed then
IFS.FdTexCoord.Value := FdTexCoord.Value;
{ Set CreaseAngle to anything larger than Pi, to make this completely
smooth later using fast CreateSmoothNormalsCoordinateNode routine. }
IFS.FdCreaseAngle.Value := 4;
except FreeAndNil(Result); raise end;
end;
function TTeapotNode.ProxyUsesOverTriangulate: boolean;
begin
Result := false;
end;
procedure TTeapotNode.DirectEnumerateActive(
Func: TEnumerateChildrenFunction);
begin
inherited;
FdtexCoord.EnumerateValid(Func);
end;
function TTeapotNode.TexCoordField: TSFNode;
begin
Result := FdTexCoord;
end;
function TTeapotNode.AutoGenerate3DTexCoords: boolean;
begin
Result := (FdTexCoord.Value = nil) or not FdTexCoord.CurrentChildAllowed;
end;
procedure TLoggerNode.CreateNode;
begin
inherited;
FFdLevel := TSFInt32.Create(Self, 'level', 1);
Fields.Add(FFdLevel);
FFdLogFile := TSFString.Create(Self, 'logFile', '');
FFdLogFile.Exposed := false;
Fields.Add(FFdLogFile);
FFdEnabled := TSFBool.Create(Self, 'enabled', true);
Fields.Add(FFdEnabled);
FEventWrite := TXFAnyEvent.Create(Self, 'write', true);
Events.Add(FEventWrite);
FEventWrite.OnReceive.Add(@EventWriteReceive);
end;
destructor TLoggerNode.Destroy;
begin
if WriteStreamInitialized then
begin
if OwnsWriteStream then
FreeAndNil(WriteStream);
end;
inherited;
end;
procedure TLoggerNode.EventWriteReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
procedure StdOutNotAvail;
begin
OnWarning(wtMajor, 'VRML/X3D',
'Logger node wants to write on standard output, but it seems that stdout (standard output) ' +
'is not available. Under Windows you should explicitly ' +
'redirect program''s stdout to make it available, e.g. ' +
'run "' + ApplicationName + ' > ' + ApplicationName + '.log".');
end;
procedure WritelnLogMessage;
var
S: string;
Writer: TX3DWriterNames;
begin
S := Format('Logger "%s": received field "%s" (%s). Time: %f.',
[NodeName, Value.Name, Value.TypeName, Time.Seconds]);
if FdLevel.Value = 1 then
begin
WritelnStr(WriteStream, S);
end else
begin
Assert(FdLevel.Value >= 2);
if (FdLevel.Value >= 3) and (Value.ParentNode <> nil) then
begin
S += Format(' Sending node: "%s" (%s).',
[(Value.ParentNode as TX3DNode).NodeName,
(Value.ParentNode as TX3DNode).NodeTypeName]);
end;
WriteStr(WriteStream, S + ' Value: ');
Writer := TX3DWriterNames.Create(WriteStream, X3DVersion, xeClassic);
try
Value.FieldSaveToStream(Writer, true);
finally
FreeAndNil(Writer);
end;
end;
end;
begin
if FdEnabled.Value and (Fdlevel.Value > 0) then
begin
{ First reception of "write" event causes initialization of
WriteStream, based on logFile field value. This is Ok, since
logFile is not exposed, so it cannot change after the file is loaded. }
if not WriteStreamInitialized then
begin
Assert(WriteStream = nil);
WriteStreamInitialized := true;
if FdLogFile.Value <> '' then
begin
WriteStream := TFileStream.Create(
FileNameAutoInc(ApplicationName + '_logger_' +
DeleteURIExt(ExtractURIName(FdLogFile.Value)) + '_%d.log'), fmCreate);
OwnsWriteStream := true;
end else
begin
WriteStream := StdOutStream;
OwnsWriteStream := false;
if WriteStream = nil then
begin
{ report stdout not available, leave WriteStream = nil and
WriteStreamInitialized = true. This way we will not try to
reinit this again. }
StdOutNotAvail;
Exit;
end;
end;
end;
if WriteStream <> nil then
begin
try
WritelnLogMessage;
except
on E: EWriteError do
begin
if not OwnsWriteStream then
begin
{ This means that we have stdout, and it just failed...
This is possible on Windows.
Ideally, check for "StdOutStream = nil" should be all that is needed,
and wrapping WritelnStr inside try...except should not be needed.
But... see StdOutStream comments: you cannot
depend on the fact that "StdOutStream <> nil means that stdout
is actually available (because user redirected stdout etc.). }
StdOutNotAvail;
end else
raise;
end;
end;
end;
end;
end;
class function TLoggerNode.ClassNodeTypeName: string;
begin
Result := 'Logger';
end;
class function TLoggerNode.URNMatching(const URN: string): boolean;
begin
Result := (inherited URNMatching(URN)) or
(URN = URNKambiNodes + ClassNodeTypeName) or
(URN = URNKambiNodes2 + ClassNodeTypeName);
end;
procedure TConverterNode.CreateNode;
begin
inherited;
FFdEnabled := TSFBool.Create(Self, 'enabled', true);
Fields.Add(FFdEnabled);
FEventIn := TXFAnyEvent.Create(Self, 'in', true);
Events.Add(FEventIn);
FEventIn.OnReceive.Add(@EventInReceive);
FEventOut := TXFAnyEvent.Create(Self, 'out', true);
Events.Add(FEventOut);
end;
procedure TConverterNode.EventInReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
begin
if FdEnabled.Value then
{ TODO: uhhhmmmm, I cannot convert here (as I don't know to what I should
convert... Convertion must be done along the route, when destination
is known. }
EventOut.Send(Value, Time);
end;
class function TConverterNode.ClassNodeTypeName: string;
begin
Result := 'Converter';
end;
class function TConverterNode.URNMatching(const URN: string): boolean;
begin
Result := (inherited URNMatching(URN)) or
(URN = URNKambiNodes + ClassNodeTypeName) or
(URN = URNKambiNodes2 + ClassNodeTypeName);
end;
procedure TRenderedTextureNode.CreateNode;
begin
inherited;
FFdViewpoint := TSFNode.Create(Self, 'viewpoint', [TAbstractViewpointNode]);
FdViewpoint.ChangesAlways := [chGeneratedTextureUpdateNeeded];
Fields.Add(FFdViewpoint);
FFdBackground := TSFNode.Create(Self, 'background', [TAbstractBackgroundNode]);
FdBackground.ChangesAlways := [chGeneratedTextureUpdateNeeded];
Fields.Add(FFdBackground);
FFdFog := TSFNode.Create(Self, 'fog', [TFogNode]);
FdFog.ChangesAlways := [chGeneratedTextureUpdateNeeded];
Fields.Add(FFdFog);
FFdEnvironment := TSFNode.Create(Self, 'environment', [TX3DNode] { nothing sensible in core X3D for this });
FdEnvironment.ChangesAlways := [chGeneratedTextureUpdateNeeded];
Fields.Add(FFdEnvironment);
FFdScene := TSFNode.Create(Self, 'scene', [TX3DNode]);
FdScene.ChangesAlways := [chGeneratedTextureUpdateNeeded];
Fields.Add(FFdScene);
FFdDimensions := TMFInt32.Create(Self, 'dimensions',
[ DefaultRenderedTextureWidth,
DefaultRenderedTextureHeight, 4, 1, 1]);
FdDimensions.ChangesAlways := [chTextureRendererProperties];
Fields.Add(FFdDimensions);
FFdDepthMap := TMFBool.Create(Self, 'depthMap', []);
FdDepthMap.ChangesAlways := [chTextureRendererProperties];
Fields.Add(FFdDepthMap);
FFdForeground := TSFNode.Create(Self, 'foreground', [TX3DNode] { nothing sensible in core X3D for this });
FdForeground.ChangesAlways := [chGeneratedTextureUpdateNeeded];
Fields.Add(FFdForeground);
FFdZOffset := TMFInt32.Create(Self, 'zOffset', []);
FdZOffset.ChangesAlways := [chTextureRendererProperties];
Fields.Add(FFdZOffset);
FFdTargets := TMFNode.Create(Self, 'targets', [TAbstractTextureNode]);
FdTargets.ChangesAlways := [chTextureRendererProperties];
Fields.Add(FFdTargets);
FFdDescription := TSFString.Create(Self, 'description', '');
Fields.Add(FFdDescription);
FEventViewing := TSFMatrix4fEvent.Create(Self, 'viewing', false);
Events.Add(FEventViewing);
FEventProjection := TSFMatrix4fEvent.Create(Self, 'projection', false);
Events.Add(FEventProjection);
FFdUpdate := TSFTextureUpdate.Create(Self, 'update', upNone);
Fields.Add(FFdUpdate);
FFdFrameBufferMode := TSFString.Create(Self, 'frameBufferMode', 'auto');
FdFrameBufferMode.ChangesAlways := [chTextureRendererProperties];
Fields.Add(FFdFrameBufferMode);
FFdExcludeNodes := TMFNode.Create(Self, 'excludeNodes', [TX3DNode]);
FdExcludeNodes.Exposed := false;
FdExcludeNodes.ChangesAlways := [chGeneratedTextureUpdateNeeded];
Fields.Add(FFdExcludeNodes);
FFdTriggerName := TSFString.Create(Self, 'triggerName', 'Render');
FdTriggerName.Exposed := false;
Fields.Add(FFdTriggerName);
FEventTriggerSlot := TSFTimeEvent.Create(Self, 'triggerSlot', true);
Events.Add(FEventTriggerSlot);
FEventImage_changed := TSFImageEvent.Create(Self, 'image_changed', false);
Events.Add(FEventImage_changed);
FFdTextureProperties := TSFNode.Create(Self, 'textureProperties', [TTexturePropertiesNode]);
FdTextureProperties.Exposed := false;
FdTextureProperties.ChangesAlways := [chTextureRendererProperties];
Fields.Add(FFdTextureProperties);
FFdRepeatS := TSFBool.Create(Self, 'repeatS', true);
FdRepeatS.Exposed := false;
FdRepeatS.ChangesAlways := [chTextureRendererProperties];
Fields.Add(FFdRepeatS);
FFdRepeatT := TSFBool.Create(Self, 'repeatT', true);
FdRepeatT.Exposed := false;
FdRepeatT.ChangesAlways := [chTextureRendererProperties];
Fields.Add(FFdRepeatT);
FFdRepeatR := TSFBool.Create(Self, 'repeatR', true);
FdRepeatR.Exposed := false;
FdRepeatR.ChangesAlways := [chTextureRendererProperties];
Fields.Add(FFdRepeatR);
FEventRendering := TSFBoolEvent.Create(Self, 'rendering', false);
Events.Add(FEventRendering);
FGeneratedTextureHandler := TGeneratedTextureHandler.Create;
FGeneratedTextureHandler.FUpdate := FdUpdate;
end;
destructor TRenderedTextureNode.Destroy;
begin
FreeAndNil(FGeneratedTextureHandler);
inherited;
end;
class function TRenderedTextureNode.ClassNodeTypeName: string;
begin
Result := 'RenderedTexture';
end;
class function TRenderedTextureNode.URNMatching(const URN: string): boolean;
begin
Result := (inherited URNMatching(URN)) or
(URN = URNKambiNodes + ClassNodeTypeName) or
(URN = URNKambiNodes2 + ClassNodeTypeName);
end;
procedure TPlaneNode.CreateNode;
begin
inherited;
FFdSize := TSFVec2f.Create(Self, 'size', Vector2Single(2, 2));
FdSize.Exposed := false;
FdSize.ChangesAlways := [chGeometry];
Fields.Add(FFdSize);
{ X3D specification comment: (0,Inf) }
FFdSolid := TSFBool.Create(Self, 'solid', true);
FdSolid.Exposed := false;
FdSolid.ChangesAlways := [chGeometry];
Fields.Add(FFdSolid);
end;
class function TPlaneNode.ClassNodeTypeName: string;
begin
Result := 'Plane';
end;
class function TPlaneNode.URNMatching(const URN: string): boolean;
begin
Result := (inherited URNMatching(URN)) or
(URN = URNKambiNodes + ClassNodeTypeName) or
(URN = URNKambiNodes2 + ClassNodeTypeName);
end;
function TPlaneNode.Proxy(var State: TX3DGraphTraverseState;
const OverTriangulate: boolean): TAbstractGeometryNode;
begin
Result := Rectangle2DProxy(Self, FdSize.Value, FdSolid.Value);
end;
function TPlaneNode.ProxyUsesOverTriangulate: boolean;
begin
Result := false;
end;
type
TSFBoolIgnorable = class(TSFBool)
protected
class function ExposedEventsFieldClass: TX3DFieldClass; override;
procedure ExposedEventReceive(Event: TX3DEvent; AValue: TX3DField;
const Time: TX3DTime); override;
end;
class function TSFBoolIgnorable.ExposedEventsFieldClass: TX3DFieldClass;
begin
Result := TSFBool;
end;
procedure TSFBoolIgnorable.ExposedEventReceive(Event: TX3DEvent; AValue: TX3DField;
const Time: TX3DTime);
begin
{ This makes status and notStatus input events ignored,
and output events not generated when enabled = FALSE. }
if (ParentNode <> nil) and
(not (ParentNode as TTogglerNode).FdEnabled.Value) then Exit;
inherited;
end;
procedure TTogglerNode.CreateNode;
begin
inherited;
FFdStatus := TSFBoolIgnorable.Create(Self, 'status', false);
FdStatus.OnReceive.Add(@EventStatusReceive);
Fields.Add(FFdStatus);
FFdNotStatus := TSFBoolIgnorable.Create(Self, 'notStatus', true);
FdNotstatus.OnReceive.Add(@EventNotStatusReceive);
Fields.Add(FFdNotStatus);
FEventToggle := TXFAnyEvent.Create(Self, 'toggle', true);
FEventToggle.OnReceive.Add(@EventToggleReceive);
Events.Add(FEventToggle);
FEventSet := TXFAnyEvent.Create(Self, 'set', true);
EventSet.OnReceive.Add(@EventSetReceive);
Events.Add(FEventSet);
FEventReset := TXFAnyEvent.Create(Self, 'reset', true);
EventReset.OnReceive.Add(@EventResetReceive);
Events.Add(FEventReset);
FEventChanged := TSFBoolEvent.Create(Self, 'changed', false);
Events.Add(FEventChanged);
FEventOn := TSFBoolEvent.Create(Self, 'on', false);
Events.Add(FEventOn);
FEventOff := TSFBoolEvent.Create(Self, 'off', false);
Events.Add(FEventOff);
FFdEnabled := TSFBool.Create(Self, 'enabled', true);
Fields.Add(FFdEnabled);
end;
class function TTogglerNode.ClassNodeTypeName: string;
begin
Result := 'Toggler';
end;
class function TTogglerNode.URNMatching(const URN: string): boolean;
begin
Result := (inherited URNMatching(URN)) or
(URN = URNKambiNodes + ClassNodeTypeName) or
(URN = URNKambiNodes2 + ClassNodeTypeName);
end;
procedure TTogglerNode.EventStatusReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
begin
{ Do not send event to notStatus, if it already has correct value
(so our own value didn't actually changed).
This avoids calling status and notStatus events in a loop.
By the way, also avoid sending excessive changed/on/off. }
if FdnotStatus.Value <> not FdStatus.Value then
begin
FdnotStatus.Send(not FdStatus.Value);
EventChanged.Send(true, Time);
if FdStatus.Value then EventOn.Send(true, Time);
if not FdStatus.Value then EventOff.Send(true, Time);
end;
end;
procedure TTogglerNode.EventNotStatusReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
begin
{ Do not send event to status, if it already has correct value
(so our own value didn't actually changed).
This avoids calling status and notStatus events in a loop.
By the way, also avoid sending excessive changed/on/off. }
if FdnotStatus.Value <> not FdStatus.Value then
begin
FdStatus.Send(not FdnotStatus.Value);
EventChanged.Send(true, Time);
if FdStatus.Value then EventOn.Send(true, Time);
if not FdStatus.Value then EventOff.Send(true, Time);
end;
end;
procedure TTogglerNode.EventToggleReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
begin
if FdEnabled.Value then
FdStatus.Send(not FdStatus.Value);
end;
procedure TTogglerNode.EventSetReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
begin
if FdEnabled.Value then
FdStatus.Send(true);
end;
procedure TTogglerNode.EventResetReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
begin
if FdEnabled.Value then
FdStatus.Send(false);
end;
procedure RegisterAvalonNodes;
begin
NodesManager.RegisterNodeClasses([
TMatrixTransformNode,
TTeapotNode,
TLoggerNode,
TConverterNode,
TRenderedTextureNode,
TPlaneNode,
TTogglerNode
]);
end;
{$endif read_implementation}
|