Castle Game Engine: CastleShapes: Class TShape

# Class TShape
Description | Hierarchy | Fields | Methods | Properties
## Unit CastleShapes ## Declaration `type TShape = class(TShapeTree)` ## Description Shape is a geometry node Geometry instance and it's State. For VRML >= 2.0, this usually corresponds to a single instance of actual VRML `Shape` node. It allows to perform many operations that need to know both geometry and it's current state (parent Shape node, current transformation and such). This class caches results of methods LocalBoundingBox, BoundingBox, and most others (see TShapeValidities for hints). This means that things work fast, but this also means that you must manually call Changed when you changed some properties of Geometry or contents of State. But note that you can't change Geometry or State to different objects — they are readonly properties. Also note that if you're using TCastleSceneCore class then you don't have to worry about calling Changed of items in TCastleSceneCore.Shapes. All you have to do is to call appropriate `Changed*` methods of TCastleSceneCore. ## Hierarchy TObject TShapeTree TShape ## Overview ### Methods
| `constructor Create(AParentScene: TObject; AOriginalGeometry: TAbstractGeometryNode; AOriginalState: TX3DGraphTraverseState; ParentInfo: PTraversingInfo);`
| `destructor Destroy; override;`
| `function Geometry(const OverTriangulate: boolean = true): TAbstractGeometryNode;`
| `function State(const OverTriangulate: boolean = true): TX3DGraphTraverseState;`
| `function LocalBoundingBox: TBox3D;`
| `function BoundingBox: TBox3D;`
| `function VerticesCount(OverTriangulate: boolean): Cardinal;`
| `function TrianglesCount(OverTriangulate: boolean): Cardinal;`
| `function GeometryArrays(OverTriangulate: boolean): TGeometryArrays;`
| `function BoundingSphereCenter: TVector3Single;`
| `function BoundingSphereRadiusSqr: Single;`
| `function FrustumBoundingSphereCollisionPossible( const Frustum: TFrustum): TFrustumCollisionPossible;`
| `function FrustumBoundingSphereCollisionPossibleSimple( const Frustum: TFrustum): boolean;`
| `procedure Changed(const InactiveOnly: boolean; const Changes: TX3DChanges); virtual;`
| `function OctreeTriangles: TTriangleOctree;`
| `function TriangleOctreeLimits: POctreeLimits;`
| `function Transparent: boolean;`
| `procedure Traverse(Func: TShapeTraverseFunc; const OnlyActive: boolean; const OnlyVisible: boolean = false; const OnlyCollidable: boolean = false); override;`
| `function ShapesCount(const OnlyActive: boolean; const OnlyVisible: boolean = false; const OnlyCollidable: boolean = false): Cardinal; override;`
| `function Visible: boolean;`
| `function Collidable: boolean;`
| `function RayCollision( const Tag: TMailboxTag; out Intersection: TVector3Single; out IntersectionDistance: Single; const RayOrigin, RayDirection: TVector3Single; const ReturnClosestIntersection: boolean; const TriangleToIgnore: PTriangle; const IgnoreMarginAtStart: boolean; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): PTriangle;`
| `function SegmentCollision( const Tag: TMailboxTag; out Intersection: TVector3Single; out IntersectionDistance: Single; const Pos1, Pos2: TVector3Single; const ReturnClosestIntersection: boolean; const TriangleToIgnore: PTriangle; const IgnoreMarginAtStart: boolean; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): PTriangle;`
| `function NormalsSmooth(OverTriangulate: boolean): TVector3SingleList;`
| `function NormalsFlat(OverTriangulate: boolean): TVector3SingleList;`
| `function NormalsCreaseAngle(OverTriangulate: boolean; const CreaseAngle: Single): TVector3SingleList;`
| `procedure EnumerateTextures(Enumerate: TEnumerateShapeTexturesFunction); override;`
| `function UsesTexture(Node: TAbstractTextureNode): boolean;`
| `function ShadowCaster: boolean;`
| `procedure Triangulate(OverTriangulate: boolean; TriangleEvent: TTriangleEvent);`
| `procedure LocalTriangulate(OverTriangulate: boolean; TriangleEvent: TTriangleEvent);`
| `function DebugInfo(const Indent: string = ''): string; override;`
| `function NiceName: string;`
| `function Node: TAbstractShapeNode;`
| `function MaterialProperty: TMaterialProperty;`
### Properties
| `property OriginalGeometry: TAbstractGeometryNode read FOriginalGeometry;`
| `property OriginalState: TX3DGraphTraverseState read FOriginalState;`
| `property Spatial: TShapeSpatialStructures read FSpatial write SetSpatial;`
| `property TriangleOctreeProgressTitle: string read FTriangleOctreeProgressTitle write FTriangleOctreeProgressTitle;`
| `property DynamicGeometry: boolean read FDynamicGeometry write FDynamicGeometry;`
| `property GeometryParentNodeName: string read FGeometryParentNodeName;`
| `property GeometryGrandParentNodeName: string read FGeometryGrandParentNodeName;`
| `property GeometryGrandGrandParentNodeName: string read FGeometryGrandGrandParentNodeName;`
## Description ### Methods
| `constructor Create(AParentScene: TObject; AOriginalGeometry: TAbstractGeometryNode; AOriginalState: TX3DGraphTraverseState; ParentInfo: PTraversingInfo);`
Constructor. ###### Parameters ParentInfo Resursive information about parents, for the geometry node of given shape. Note that for VRML 2.0/X3D, the immediate parent of geometry node is always TShapeNode.
| `destructor Destroy; override;`
| `function Geometry(const OverTriangulate: boolean = true): TAbstractGeometryNode;`
Geometry of this shape. This may come from initial VRML/X3D node graph (see OriginalGeometry), or it may be processed by TAbstractGeometryNode.Proxy for easier handling.
| `function State(const OverTriangulate: boolean = true): TX3DGraphTraverseState;`
State of this shape. This may come from initial VRML/X3D node graph (see OriginalState), or it may be processed by TAbstractGeometryNode.Proxy for easier handling. Owned by this TShape class.
| `function LocalBoundingBox: TBox3D;`
Calculate bounding box and vertices/triangles count, see TAbstractGeometryNode methods.
| `function BoundingBox: TBox3D;`
| `function VerticesCount(OverTriangulate: boolean): Cardinal;`
| `function TrianglesCount(OverTriangulate: boolean): Cardinal;`
| `function GeometryArrays(OverTriangulate: boolean): TGeometryArrays;`
Decompose the geometry into primitives, with arrays of per-vertex data.
| `function BoundingSphereCenter: TVector3Single;`
Calculates bounding sphere based on BoundingBox. In the future this may be changed to use BoundingSphere method of TAbstractGeometryNode, when I will implement it. For now, BoundingSphere is always worse approximation of bounding volume than BoundingBox (i.e. BoundingSphere is always larger) but it may be useful in some cases when detecting collision versus bounding sphere is much faster than detecting them versus bounding box. BoundingSphereRadiusSqr = 0 and `BoundingSphereCenter` is undefined if Box is empty.
| `function BoundingSphereRadiusSqr: Single;`
| `function FrustumBoundingSphereCollisionPossible( const Frustum: TFrustum): TFrustumCollisionPossible;`
Exactly equivalent to getting BoundingSphereCenter and BoundingSphereRadiusSqr and then using TFrustum.SphereCollisionPossible. But it may be a little faster since it avoids some small speed problems (like copying memory contents when you get values of BoundingSphereXxx properties and checking twice are BoundingSphereXxx calculated).
| `function FrustumBoundingSphereCollisionPossibleSimple( const Frustum: TFrustum): boolean;`
Exactly equivalent to getting BoundingSphereCenter and BoundingSphereRadiusSqr and then using TFrustum.SphereCollisionPossibleSimple. But it may be a little faster since it avoids some small speed problems.
| `procedure Changed(const InactiveOnly: boolean; const Changes: TX3DChanges); virtual;`
Notify this shape that you changed a field inside one of it's nodes (automatically done by TCastleSceneCore). This should be called when fields within Shape.Geometry, Shape.State.Last*, Shape.State.ShapeNode or such change. Pass InactiveOnly = `True` is you know that this shape is fully in inactive VRML graph part (inactive Switch, LOD etc. children). Including chTransform in Changes means something more than general chTransform (which means that transformation of children changed, which implicates many things — not only shape changes). Here, chTransform in Changes means that only the transformation of TShape.State changed (so only on fields ignored by EqualsNoTransform).
| `function OctreeTriangles: TTriangleOctree;`
The dynamic octree containing all triangles. It contains only triangles within this shape. There is no distinction here between collidable / visible (as for TCastleSceneCore octrees), since the whole shape may be visible and/or collidable. The triangles are specified in local coordinate system of this shape (that is, they are independent from transformation within State.Transform). This allows the tree to remain unmodified when transformation of this shape changes. This is automatically managed (initialized, updated, and used) by parent TCastleSceneCore. You usually don't need to know about this octree from outside. To initialize this, add ssTriangles to Spatial property, otherwise it's `Nil`. Parent TCastleSceneCore will take care of this (when parent TCastleSceneCore.Spatial contains ssDynamicCollisions, then all shapes contain ssTriangles within their Spatial). Parent TCastleSceneCore will take care to keep this octree always updated. Parent TCastleSceneCore will also take care of actually using this octree: TCastleSceneCore.OctreeCollisions methods actually use the octrees of specific shapes at the bottom.
| `function TriangleOctreeLimits: POctreeLimits;`
Properties of created triangle octrees. See TriangleOctree unit comments for description. Default value comes from DefLocalTriangleOctreeLimits. If TriangleOctreeProgressTitle <> '', it will be shown during octree creation (through TProgress.Title). Will be shown only if progress is not active already ( so we avoid starting "progress bar within progress bar"). They are used only when the octree is created, so usually you want to set them right before changing Spatial from [] to something else.
| `function Transparent: boolean;`
Looking at material and color and texture nodes, decide if the shape is opaque or (partially) transparent. For VRML >= 2.0, shape is transparent if material exists and has transparency > 0 (epsilon). It's also transparent if it has ColorRGBA node inside "color" field. For VRML <= 1.0, for now shape is transparent if all it's transparent values (in VRML 1.0, material node has actually many material values) have transparency > 0 (epsilon). We also look at texture, does it have a full-range alpha channel (for blending). It looks at data of texture node, material node and so on, so should be done before any calls to TCastleSceneCore.FreeResources. It checks AlphaChannel of textures, so assumes that given shape textures are already loaded.
| `procedure Traverse(Func: TShapeTraverseFunc; const OnlyActive: boolean; const OnlyVisible: boolean = false; const OnlyCollidable: boolean = false); override;`
| `function ShapesCount(const OnlyActive: boolean; const OnlyVisible: boolean = false; const OnlyCollidable: boolean = false): Cardinal; override;`
| `function Visible: boolean;`
Is shape visible, according to VRML Collision node rules. Ths is simply a shortcut (with more obvious name) for `State.InsideInvisible = 0`.
| `function Collidable: boolean;`
Is shape collidable, according to VRML Collision node rules. Ths is simply a shortcut (with more obvious name) for `State.InsideIgnoreCollision = 0`.
| `function RayCollision( const Tag: TMailboxTag; out Intersection: TVector3Single; out IntersectionDistance: Single; const RayOrigin, RayDirection: TVector3Single; const ReturnClosestIntersection: boolean; const TriangleToIgnore: PTriangle; const IgnoreMarginAtStart: boolean; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): PTriangle;`
Equivalent to using OctreeTriangles.RayCollision, except this wil use the mailbox.
| `function SegmentCollision( const Tag: TMailboxTag; out Intersection: TVector3Single; out IntersectionDistance: Single; const Pos1, Pos2: TVector3Single; const ReturnClosestIntersection: boolean; const TriangleToIgnore: PTriangle; const IgnoreMarginAtStart: boolean; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): PTriangle;`
Equivalent to using OctreeTriangles.SegmentCollision, except this wil use the mailbox.
| `function NormalsSmooth(OverTriangulate: boolean): TVector3SingleList;`
Create normals suitable for this shape. You can call this only when Geometry is coordinate-based VRML geometry, implementing Coord and having non-empty coordinates (that is, Geometry.Coord returns `True` and sets ACoord <> `Nil`), and having Geometry.CoordIndex <> `Nil`. For `NormalsSmooth`, also Geometry.CoordIndex = `Nil` is allowed, but make sure that Geometry.CoordPolygons is available. See CreateSmoothNormalsCoordinateNode. Smooth normals are perfectly smooth, per-vertex. As an exception, you can call this even when coords are currently empty (Geometry.Coord returns `True` but ACoord is `Nil`), then result is also `Nil`. Flat normals are per-face. Calculated by CreateFlatNormals. Finally NormalsCreaseAngle creates separate normal per index (auto-smoothing by CreaseAngle). The normals here are cached. So using these methods makes condiderable speedup if the shape will not change (Changed method) and will need normals many times (e.g. will be rendered many times). Normals generated always point out from CCW (FromCCW = `True` is passed to all Create*Normals internally).
| `function NormalsFlat(OverTriangulate: boolean): TVector3SingleList;`
| `function NormalsCreaseAngle(OverTriangulate: boolean; const CreaseAngle: Single): TVector3SingleList;`
| `procedure EnumerateTextures(Enumerate: TEnumerateShapeTexturesFunction); override;`
| `function UsesTexture(Node: TAbstractTextureNode): boolean;`
Is the texture node Node possibly used by this shape. This is equivalent to checking does EnumerateShapeTextures return this shape.
| `function ShadowCaster: boolean;`
Check is shape a shadow caster. Looks at Shape's Appearance.shadowCaster field (see http://castle-engine.sourceforge.net/x3d_extensions.php#section_ext_shadow_caster).
| `procedure Triangulate(OverTriangulate: boolean; TriangleEvent: TTriangleEvent);`
`Triangulate` shape. Calls TriangleEvent callback for each triangle. LocalTriangulate returns coordinates in local shape transformation (that is, not transformed by State.Transform yet). OverTriangulate determines if we should make more triangles for Gouraud shading. For example, it makes Cones and Cylinders divided into additional stacks.
| `procedure LocalTriangulate(OverTriangulate: boolean; TriangleEvent: TTriangleEvent);`
| `function DebugInfo(const Indent: string = ''): string; override;`
| `function NiceName: string;`
| `function Node: TAbstractShapeNode;`
Shape node in VRML/X3D graph. This is always present for VRML >= 2 (including X3D). For VRML 1.0 and Inventor this is `Nil`.
| `function MaterialProperty: TMaterialProperty;`
Material property associated with this shape's material/texture.
### Properties
| `property OriginalGeometry: TAbstractGeometryNode read FOriginalGeometry;`
Original geometry node, that you get from a VRML/X3D graph.
| `property OriginalState: TX3DGraphTraverseState read FOriginalState;`
Original state, that you get from a VRML/X3D graph.
| `property Spatial: TShapeSpatialStructures read FSpatial write SetSpatial;`
Which spatial structrues (octrees, for now) should be created and managed. This works analogous to TCastleSceneCore.Spatial, but this manages octrees within this TShape.
| `property TriangleOctreeProgressTitle: string read FTriangleOctreeProgressTitle write FTriangleOctreeProgressTitle;`
| `property DynamicGeometry: boolean read FDynamicGeometry write FDynamicGeometry;`
Local geometry is treated as dynamic (changes very often, like every frame). This is automatically detected and set to `True`, although you can also explicitly set this if you want. Dynamic geometry has worse collision detection (using a crude approximation) and falls back to rendering method better for dynamic geometry (for example, marking VBO data as dynamic for OpenGL rendering).
| `property GeometryParentNodeName: string read FGeometryParentNodeName;`
Node names of parents of the geometry node. Note that for X3D/VRML 2.0, `GeometryParentNodeName` is the same as Node.NodeName, because the parent of geometry node is always a TShapeNode.
| `property GeometryGrandParentNodeName: string read FGeometryGrandParentNodeName;`
| `property GeometryGrandGrandParentNodeName: string read FGeometryGrandGrandParentNodeName;`
Generated by PasDoc 0.13.0 on 2013-08-17 21:27:14