Object TTriangle

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TTriangle = object(T3DTriangle)

Description

Triangle in VRML/X3D model. This is the most basic item for our VRML/X3D collision detection routines, returned by octrees descending from TBaseTrianglesOctree.

Hierarchy

Overview

Fields

Public Shape: TObject;
Public Normal: TTriangle3Single;
Public TexCoord: TTriangle4Single;
Public Face: TFaceIndex;
Public MailboxSavedTag: TMailboxTag;
Public MailboxIsIntersection: boolean;
Public MailboxIntersection: TVector3Single;
Public MailboxIntersectionDistance: Single;

Methods

Public constructor Init(AShape: TObject; const APosition: TTriangle3Single; const ANormal: TTriangle3Single; const ATexCoord: TTriangle4Single; const AFace: TFaceIndex);
Public procedure UpdateWorld;
Public function State: TX3DGraphTraverseState;
Public function SegmentDirCollision( out Intersection: TVector3Single; out IntersectionDistance: Single; const Odc0, OdcVector: TVector3Single; const SegmentTag: TMailboxTag): boolean;
Public function RayCollision( out Intersection: TVector3Single; out IntersectionDistance: Single; const RayOrigin, RayDirection: TVector3Single; const RayTag: TMailboxTag): boolean;
Public function MaterialInfo: TX3DMaterialInfoAbstract;
Public function Transparency: Single;
Public function IsTransparent: boolean;
Public function IgnoreForShadowRays: boolean;
Public function ITexCoord(const Point: TVector3Single): TVector4Single;
Public function ITexCoord2D(const Point: TVector3Single): TVector2Single;
Public function INormal(const Point: TVector3Single): TVector3Single;

Description

Fields

Public Shape: TObject;

See TTriangleEvent for the meaning of these fields.

Public Normal: TTriangle3Single;
 
Public TexCoord: TTriangle4Single;
 
Public Face: TFaceIndex;
 
Public MailboxSavedTag: TMailboxTag;

Tag of an object (like a ray or a line segment) for which we have saved an intersection result. Intersection result is in MailboxIsIntersection, MailboxIntersection, MailboxIntersectionDistance.

To make things correct, we obviously assume that every segment and ray have different tags. Also, tag -1 is reserved. In practice, we simply initialize MailboxSavedTag to -1, and each new segment/ray get consecutive tags starting from 0.

History: a naive implementation at the beginning was not using tags, instead I had MailboxState (empty, ray or segment) and I was storing ray/line vectors (2 TVector3Single values). This had much larger size (6 * SizeOf(Single) + SizeOf(enum) = 28 bytes) than tag, which is important (3D models have easily thousands of TTriangle). And it took longer to compare and assign, so it was working much slower.

Public MailboxIsIntersection: boolean;
 
Public MailboxIntersection: TVector3Single;
 
Public MailboxIntersectionDistance: Single;
 

Methods

Public constructor Init(AShape: TObject; const APosition: TTriangle3Single; const ANormal: TTriangle3Single; const ATexCoord: TTriangle4Single; const AFace: TFaceIndex);

Initialize new triangle. Given APosition must satisfy IsValidTriangle.

Public procedure UpdateWorld;
 
Public function State: TX3DGraphTraverseState;

State of this shape, containing various information about 3D shape. This is a shortcut of TShape(Shape).State.

Public function SegmentDirCollision( out Intersection: TVector3Single; out IntersectionDistance: Single; const Odc0, OdcVector: TVector3Single; const SegmentTag: TMailboxTag): boolean;

Check collisions between TTriangle and ray/segment.

Always use these routines to check for collisions, to use mailboxes if possible. Mailboxes are used only if this was compiled with TRIANGLE_OCTREE_USE_MAILBOX defined.

Increments TriangleCollisionTestsCounter if actual test was done (that is, if we couldn't use mailbox to get the result quickier).

Public function RayCollision( out Intersection: TVector3Single; out IntersectionDistance: Single; const RayOrigin, RayDirection: TVector3Single; const RayTag: TMailboxTag): boolean;
 
Public function MaterialInfo: TX3DMaterialInfoAbstract;

Create material information instance for material of this triangle. See TX3DMaterialInfoAbstract for usage description.

Returns Nil when no Material node is defined, this can happen only for VRML >= 2.0.

Returned TX3DMaterialInfoAbstract is valid only as long as the Material node (for VRML 1.0 or 2.0) on which it was based.

Public function Transparency: Single;

Return transparency of this triangle's material. Equivalent to MaterialInfo.Transparency, although a little faster.

Public function IsTransparent: boolean;

Returns True for triangles that are transparent.

Public function IgnoreForShadowRays: boolean;

Returns True for triangles that should be ignored by shadow rays. Returns True for transparent triangles (with Material.Transparency > 0) and non-shadow-casting triangles (with Appearance.shadowCaster = FALSE).

See also
TBaseTrianglesOctree.IgnoreForShadowRays
Ignore (return True) transparent triangles (with Material.Transparency > 0) and non-shadow-casting triangles (with Appearance.shadowCaster = FALSE).
Public function ITexCoord(const Point: TVector3Single): TVector4Single;

For a given position (in world coordinates), return the texture coordinate at this point. It is an interpolated texture coordinate from our per-vertex texture coordinates in TexCoord field.

This assumes that Position actually lies within the triangle.

The ITexCoord2D returns the same, but cut to the first 2 texture coordinate components. Usable for normal 2D textures.

Public function ITexCoord2D(const Point: TVector3Single): TVector2Single;
 
Public function INormal(const Point: TVector3Single): TVector3Single;

For a given position (in world coordinates), return the smooth normal vector at this point. It is an interpolated normal from our per-vertex normals in Normal field. Like them, it is a normal vector in local coordinates.

This assumes that Position actally lies within the triangle.