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 ShapeNode: TAbstractShapeNode;
Public function Material: TMaterialNode;
Public function MaterialNode: TMaterialNode; deprecated 'use Material';
Public function MaterialInfo: TMaterialInfo;
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;
Public function INormalCore(const Point: TVector3Single): TVector3Single;
Public function INormalWorldSpace(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 ShapeNode: TAbstractShapeNode;

X3D shape node of this triangle. May be Nil in case of VRML 1.0.

Public function Material: TMaterialNode;

X3D material node of this triangle. May be Nil in case material is not set, or in VRML 1.0.

Public function MaterialNode: TMaterialNode; deprecated 'use Material';

Warning: this symbol is deprecated: use Material

 
Public function MaterialInfo: TMaterialInfo;

Material information for the material of this triangle. See TMaterialInfo for usage description. Returns Nil when no node determines material properties (which indicates white unlit look).

Returned TMaterialInfo is valid only as long as the underlying Material or CommonSurfaceShader node exists. Do not free it yourself, it will be automatically freed.

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 the Normal field, thus is supports also the case when you have smooth shading (normals change throughout the triangle).

Like the Normal field, the returned vector is a normal vector in the local coordinates. Use INormalWorldSpace to get a normal vector in scene coordinates.

This assumes that Position actally lies within the triangle.

Public function INormalCore(const Point: TVector3Single): TVector3Single;

Like INormal, but not necessarily normalized.

Public function INormalWorldSpace(const Point: TVector3Single): TVector3Single;

For a given position (in world coordinates), return the smooth normal vector at this point, with the resulting normal vector in world coordinates.

See also
INormal
For a given position (in world coordinates), return the smooth normal vector at this point.

Generated by PasDoc 0.14.0.