Class TVRMLGraphTraverseState

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TVRMLGraphTraverseState = class(TObject)

Description

This describes current "state" (current transformation and such) when traversing VRML graph.

For VRML >= 2.0 this could be smaller, as VRML >= 2.0 doesn't need to keep track of all these LastNodes. But we want to handle VRML 1.0 100% correctly still, so there we are.

Node'y ktore trafiaja na liste LastNodes (bo sa wsrod TraverseStateLastNodesClasses) nie moga wplywac w zaden inny sposob na stan tej klasy podczas wykonywania Traverse w Before/Middle/After Traverse. Innymi slowy, gwarantuje sie ze zmiana wartosci na jakims polu jkaiegos node'a z grupy LastNodesKinds nie wplynie w zaden sposob na sposob w jaki powinien byc renderowany shape ktorego State nie zawiera danego LastNode'a. Korzystam z tego w TFLatScene.ChangedFields.

Podobnie swiatla trafiaja na ActiveLights i w zaden inny sposob nie moga zmieniac State trawersowania.

Hierarchy

Overview

Fields

Public VRML1ActiveLights: TDynActiveLightArray;
Public VRML2ActiveLights: TDynActiveLightArray;
Public Transform: TMatrix4Single;
Public InvertedTransform: TMatrix4Single;
Public AverageScaleTransform: Single;
Public TextureTransform: TMatrix4Single;
Public ParentShape: TNodeShape;

Methods

Public function CurrentActiveLights: TDynActiveLightArray;
Public constructor CreateCopy(Source: TVRMLGraphTraverseState);
Public constructor Create(const ADefaultLastNodes: TTraverseStateLastNodes); overload;
Public constructor Create; overload;
Public destructor Destroy; override;
Public function Equals(SecondValue: TVRMLGraphTraverseState): boolean;
Public function EqualsNoTransform(SecondValue: TVRMLGraphTraverseState): boolean;
Public function Texture: TNodeGeneralTexture;

Properties

Public property LastNodes: TTraverseStateLastNodes read FLastNodes;

Description

Fields

Public VRML1ActiveLights: TDynActiveLightArray;

Lights active in this state, two separate versions for each VRML flavor needed here.

VRML2ActiveLights should be for any VRML >= 2 (including X3D), VRML1ActiveLights should be for any VRML <= 1 (including Inventor).

VRML 2.0 may have more lights active (since DirectionalLight affects all siblings, and other lights affect potentially all). But VRML 2.0 may also have some lights less, since some lights are limited by radius and may be determined to not light here.

Also, note that VRML2ActiveLights cannot be fully calculated in Traverse pass (contrary to everything else in TVRMLGraphTraverseState). DirectionalLights are calculated here, but positional lights have to be calculated later (VRML 2 spec says that they affect whole scene, based on their radius, and regardless of their position in VRML graph; so this is not possible to fill during Traverse call). See how UpdateVRML2ActiveLights in TVRMLFlatScene does this.

Public VRML2ActiveLights: TDynActiveLightArray;

Lights active in this state, two separate versions for each VRML flavor needed here.

VRML2ActiveLights should be for any VRML >= 2 (including X3D), VRML1ActiveLights should be for any VRML <= 1 (including Inventor).

VRML 2.0 may have more lights active (since DirectionalLight affects all siblings, and other lights affect potentially all). But VRML 2.0 may also have some lights less, since some lights are limited by radius and may be determined to not light here.

Also, note that VRML2ActiveLights cannot be fully calculated in Traverse pass (contrary to everything else in TVRMLGraphTraverseState). DirectionalLights are calculated here, but positional lights have to be calculated later (VRML 2 spec says that they affect whole scene, based on their radius, and regardless of their position in VRML graph; so this is not possible to fill during Traverse call). See how UpdateVRML2ActiveLights in TVRMLFlatScene does this.

Public Transform: TMatrix4Single;

Current transformation.

Public InvertedTransform: TMatrix4Single;

Inverted Transform matrix. This matrix is crucial for some special effects (for example, it's needed for calculating in tangent space for bump mapping).

This is not calculated using any complex matrix inversion algorithms. Instead, this is calculated by updating this along the way, just like we calculate normal Transform. So it's simple, quick, and guaranteed to be correct assuming that user didn't use VRML 1.0 MatrixTransform along the way. That's why MatrixTransform node was removed from VRML 2.0, it breaks such things.

Also, any scale with zero component along the way will make this partially invalid (we'll substitute identity in place of inverted scaling matrix). This is unavoidable, there's no reverse matrix for scaling with zero factor, since one resulting point may correpond to infinitely many source points (i.e., it's natural that such scaling function cannot be reversed).

Public AverageScaleTransform: Single;

This is a uniform scale caused by matrix Transform.

I.e., if we could extract the scaling from Transform, then it would be AverageScaleTransform. Assuming that the scale is uniform. If we used any non-uniform scale along the way, this is the average scale.

This is calculated by updating it along the way, just like Transform is updated. This way it's calculated easily — contrary to the non-trivial operation of extracting a scale from a 4x4 matrix. It's also 100% correct, assuming that user didn't use VRML 1.0 MatrixTransform along the way.

Public TextureTransform: TMatrix4Single;

Current texture transformation. Usable only for VRML 1.0, in VRML 2.0 texture transformations don't accumulate like modelview transformations.

Public ParentShape: TNodeShape;
 

Methods

Public function CurrentActiveLights: TDynActiveLightArray;

This returns VRML1ActiveLights or VRML2ActiveLights, based on VRML flavor used to render with this state.

More precisely, it checks "VRML flavor" by looking at ParentShape: when ParentShape is Nil, we're in VRML 1 mode, otherwise in VRML 2 mode.

Public constructor CreateCopy(Source: TVRMLGraphTraverseState);
 
Public constructor Create(const ADefaultLastNodes: TTraverseStateLastNodes); overload;
 
Public constructor Create; overload;

Standard create, with standard initial LastNodes state.

This is equivalent to creating last nodes like

  TraverseState_CreateNodes(StateDefaultNodes) 

then creating this object with

  Create(StateDefaultNodes) 

When this object will be freed, such implicitly created StateDefaultNodes will be also freed (using TraverseState_FreeAndNilNodes).

Note: while this constructor seems very comfortable, in some cases it's not useful, exactly because it frees at the end used StateDefaultNodes. Consider e.g. TVRMLFlatScene, that has to traverse all nodes and store the traversing result in a flat list: this means that it must save various TVRMLGraphTraverseState instances, that may have references to nodes from StateDefaultNodes. So it must have independent StateDefaultNodes field that "lives" for the whole lifetime of TVRMLFlatScene and is passed to each TVRMLGraphTraverseState.Create call.

If you don't understand the note above then don't worry, you're probably fine with using this parameter-less constructor :)

Public destructor Destroy; override;
 
Public function Equals(SecondValue: TVRMLGraphTraverseState): boolean;

Compare with other TVRMLGraphTraverseState instance. The idea is that two states are equal if, when applied to the same VRML node, they "mean" the same thing, i.e. produce the same shape, behavior etc.

So note that Equals doesn't compare OwnsLastNodes values, as they don't really define the "content" of the state, they don't change the behavior of VRML node affected by this state.

Public function EqualsNoTransform(SecondValue: TVRMLGraphTraverseState): boolean;

This is like Equals but it ignores some fields that are ignored when rendering using TVRMLOpenGLRenderer.RenderShapeStateNoTransform. For example, it ignores Transform, AverageScaleTransform, InvertedTransform.

Public function Texture: TNodeGeneralTexture;

Returns proper texture node that should be used for nodes within this State, regardless whether this in VRML 1.0 or 2.0.

Details: If ParentShape <> nil, this returns texture node taken from ParentShape.Texture (note that it may be nil, if Apperance of Appearance.Texture node is NULL in VRML). Otherwise it returns texture from LastNodes.Texture2.

Properties

Public property LastNodes: TTraverseStateLastNodes read FLastNodes;

nie, ParentsCount elementow Last* NIE odzwierciedla faktu ze sa one podlegle TVRMLRenderState. W ogole ten obiekt nie zajmuje sie zarzadzaniem tymi polami - on tylko przechowuje sobie ich wartosci. W szczegolnosci wiec gwarantowane jest ze obiekty nigdy nie beda nil ale ta gwarancja musi byc takze zapewniona przez kod ktory tworzy ten obiekt przez Create.


Generated by PasDoc 0.10.0 on 2008-02-25 00:00:42