Class TArraysGenerator

Unit

Declaration

type TArraysGenerator = class(TObject)

Description

Generate TGeometryArrays for a VRML/X3D shape. This is the basis of our renderer: generate a TGeometryArrays for a shape, then TGLRenderer will pass TGeometryArrays to OpenGL.

Geometry must be based on coordinates when using this, that is TAbstractGeometryNode.Coord must return True.

Hierarchy

  • TObject
  • TArraysGenerator

Overview

Fields

Protected IndexesFromCoordIndex: TGeometryIndexList;
Protected ArrayIndexNum: Integer;
Protected Arrays: TGeometryArrays;
Public TexCoordsNeeded: Cardinal;
Public MaterialOpacity: Single;
Public FogVolumetric: boolean;
Public FogVolumetricDirection: TVector3;
Public FogVolumetricVisibilityStart: Single;
Public ShapeBumpMappingUsed: boolean;
Public ShapeBumpMappingTextureCoordinatesId: Cardinal;
Public OnRadianceTransfer: TRadianceTransferFunction;
Public OnVertexColor: TVertexColorFunction;
Public FacesNeeded: boolean;

Methods

Protected procedure WarningShadingProblems( const ColorPerVertex, NormalPerVertex: boolean);
Protected procedure GenerateVertex(IndexNum: Integer); virtual;
Protected function GetVertex(IndexNum: integer): TVector3;
Protected function CoordCount: Integer;
Protected procedure GenerateCoordinate; virtual; abstract;
Protected procedure GenerateCoordinateBegin; virtual;
Protected procedure GenerateCoordinateEnd; virtual;
Protected procedure GenerateCoordsRange( const RangeNumber: Cardinal; BeginIndex, EndIndex: Integer); virtual;
Protected procedure PrepareIndexesPrimitives; virtual; abstract;
Protected procedure PrepareAttributes(var AllowIndexed: boolean); virtual;
Public constructor Create(AShape: TShape; AOverTriangulate: boolean); virtual;
Public function GenerateArrays: TGeometryArrays;
Public class function BumpMappingAllowed: boolean; virtual;

Properties

Protected property Shape: TShape read FShape;
Protected property State: TX3DGraphTraverseState read FState;
Protected property Geometry: TAbstractGeometryNode read FGeometry;
Protected property Coord: TMFVec3f read FCoord;
Protected property CoordIndex: TMFLong read FCoordIndex;
Protected property CurrentRangeNumber: Cardinal read FCurrentRangeNumber;

Description

Fields

Protected IndexesFromCoordIndex: TGeometryIndexList;

Indexes, only when Arrays.Indexes = nil but original node was indexed.

Protected ArrayIndexNum: Integer;

Index to Arrays. Suitable always to index Arrays.Position / Color / Normal and other Arrays attribute arrays. Calculated in each TAbstractCoordinateGenerator.GenerateVertex, always call "inherited" first fro GenerateVertex overrides.

There are three cases:

1. When CoordIndex <> nil (so we have indexed node) and Arrays.Indexes <> nil (so we can render it by indexes, because AllowIndexed = true) then it's an index to node coordinates. It's equivalent to CoordIndex[IndexNum], and it can be used to index node's Coord as well as Arrays.Position (since they are ordered the same in this case).

2. When CoordIndex <> nil (so we have indexed node) and Arrays.Indexes = nil (so we cannot render it by indexes, because AllowIndexed = false) then it's a number of vertex, that is it's incremented in each TAbstractCoordinateGenerator.GenerateVertex call.

In this case IndexesFromCoordIndex <> nil, and Arrays attributes have the same count as IndexesFromCoordIndex.Count. GenerateVertex must be called in exactly the same order as IndexesFromCoordIndex were generated for this.

3. When CoordIndex = nil (so we don't have an indexed node, also Arrays.Indexes = IndexesFromCoordIndex = nil always in this case) then it's an index to attributes. This is the trivial case, as Arrays attributes are then ordered just like node's Coord. It's equal to IndexNum then.

Protected Arrays: TGeometryArrays;

Generated TGeometryArrays instance, available inside GenerateCoordinate*.

Public TexCoordsNeeded: Cardinal;

Assign these before calling GenerateArrays.

Public MaterialOpacity: Single;
 
Public FogVolumetric: boolean;
 
Public FogVolumetricDirection: TVector3;
 
Public FogVolumetricVisibilityStart: Single;
 
Public ShapeBumpMappingUsed: boolean;
 
Public ShapeBumpMappingTextureCoordinatesId: Cardinal;
 
Public OnRadianceTransfer: TRadianceTransferFunction;
 
Public OnVertexColor: TVertexColorFunction;
 
Public FacesNeeded: boolean;

Do we need TGeometryArrays.Faces

Methods

Protected procedure WarningShadingProblems( const ColorPerVertex, NormalPerVertex: boolean);
 
Protected procedure GenerateVertex(IndexNum: Integer); virtual;

Generate arrays content for given vertex. Given IndexNum indexes Coord, or (if CoordIndex is assigned) indexes CoordIndex (and CoordIndex then indexes actual Coord).

Protected function GetVertex(IndexNum: integer): TVector3;

Get vertex coordinate. Returned vertex is in local coordinate space (use State.Transform if you want to get global coordinates).

Protected function CoordCount: Integer;

Count of indexes. You can pass index between 0 and CoordCount - 1 to various methods taking an index, like GenerateVertex.

Protected procedure GenerateCoordinate; virtual; abstract;

Generate contents of Arrays. These are all called only when Coord is assigned.

GenerateCoordinate can be overridden only by the class that actually knows how to deconstruct (triangulate etc.) this node. It must call GenerateVertex (or call GenerateCoordsRange, that has to be then overridden to call GenerateVertex after inherited).

GenerateCoordinateBegin, GenerateCoordinateEnd will be called before / after GenerateCoordinate. It's useful to override them for intermediate classes in this file, that cannot triangulate, but still want to add something before / after GenerateCoordinate. When overriding GenerateCoordinateBegin, always call inherited at the begin. When overriding GenerateCoordinateEnd, always call inherited at the end.

Protected procedure GenerateCoordinateBegin; virtual;
 
Protected procedure GenerateCoordinateEnd; virtual;
 
Protected procedure GenerateCoordsRange( const RangeNumber: Cardinal; BeginIndex, EndIndex: Integer); virtual;

Generate arrays content for one coordinate range (like a face). This is not called, not used, anywhere in this base TAbstractCoordinateGenerator class. In descendants, it may be useful to use this, like Geometry.InternalMakeCoordRanges(State, @GenerateCoordsRange).

GenerateCoordsRange is supposed to generate the parts of the mesh between BeginIndex and EndIndex - 1 vertices. BeginIndex and EndIndex are indexes to CoordIndex array, if CoordIndex is assigned, or just indexes to Coord.

Protected procedure PrepareIndexesPrimitives; virtual; abstract;

If CoordIndex assigned (this VRML/X3D node is IndexedXxx) then calculate and set IndexesFromCoordIndex here. This is also the place to set Arrays.Primitive and Arrays.Counts.

Protected procedure PrepareAttributes(var AllowIndexed: boolean); virtual;

Called when constructing Arrays, before the Arrays.Count is set. Descendants can override this to do stuff like Arrays.AddColor or Arrays.AddAttribute('foo'). Descendants can also set AllowIndexed to False, if we can't use indexed rendering (because e.g. we have colors per-face, which means that the same vertex position may have different colors, which means it has to be duplicated in arrays anyway, so there's no point in indexing).

Public constructor Create(AShape: TShape; AOverTriangulate: boolean); virtual;
 
Public function GenerateArrays: TGeometryArrays;

Create and generate Arrays contents.

Public class function BumpMappingAllowed: boolean; virtual;
 

Properties

Protected property Shape: TShape read FShape;

Current shape properties, constant for the whole lifetime of the generator, set in constructor.

Protected property State: TX3DGraphTraverseState read FState;
 
Protected property Geometry: TAbstractGeometryNode read FGeometry;
 
Protected property Coord: TMFVec3f read FCoord;

Coordinates, taken from Geometry.Coord. Usually coming from (coord as Coordinate).points field. If Nil then nothing will be rendered.

In our constructor we initialize Coord and CoordIndex from Geometry, using TAbstractGeometryNode.Coord and TAbstractGeometryNode.CoordIndex values.

Protected property CoordIndex: TMFLong read FCoordIndex;

Coordinate index, taken from Geometry.CoordIndex.

If Nil, then GenerateVertex (and all other routines taking some index) will just directly index Coord (this is useful for non-indexed geometry, like TriangleSet instead of IndexedTriangleSet).

Protected property CurrentRangeNumber: Cardinal read FCurrentRangeNumber;

The number of current range (like a face), equal to RangeNumber passed to GenerateCoordsRange. Read this only while in GenerateCoordsRange. In fact, this is just set by GenerateCoordsRange in this class (so call inherited first when overriding it).

It's comfortable e.g. when you need RangeNumber inside GenerateVertex, and you know that GenerateVertex will be called only from GenerateCoordsRange.


Generated by PasDoc 0.15.0.