Unit CastleShapes

Description

Shape (TShape class) and a simple tree of shapes (TShapeTree class).

Uses

Overview

Classes, Interfaces, Objects and Records

Name Description
Record TTriangleHelper Triangle in a 3D model.
Class TShapeTree Tree of shapes.
Class TShape Shape is a geometry node Geometry instance and it's State.
Class TShapeTreeGroup Internal (non-leaf) node of the TShapeTree.
Class TShapeTreeSwitch Node of the TShapeTree representing an alternative, choosing one (or none) child from it's children list as active.
Class TShapeTreeTransform Node of the TShapeTree transforming it's children.
Class TShapeTreeLOD Node of the TShapeTree representing the LOD (level of detail) alternative.
Class TProximitySensorInstance  
Class TVisibilitySensorInstance  
Class TShapeTreeIterator Iterates over all TShape items that would be enumerated by Tree.Traverse.
Class TShapeList  
Class TPlaceholderNames  

Types

TShapeSpatialStructure = (...);
TShapeSpatialStructures = set of TShapeSpatialStructure;
TShapeTraverseFunc = procedure (const Shape: TShape) of object;
TEnumerateShapeTexturesFunction = function (Shape: TShape; Texture: TAbstractTextureNode): Pointer of object;
TTestShapeVisibility = function (Shape: TShape): boolean of object;
TShapesHash = QWord;
TShapeSortEvent = function ( const Camera: TViewVectors; const Shape1, Shape2: TShape; const RenderOptions1, RenderOptions2: TCastleRenderOptions; const SceneTransform1, SceneTransform2: TMatrix4) : Integer of object;
TShapeTreeList = specialize TObjectList<TShapeTree>;
TPlaceholderName = function (const Shape: TShape): string;

Constants

DefLocalTriangleOctreeMaxDepth = 10;
DefLocalTriangleOctreeLeafCapacity = 32;
DefLocalTriangleOctreeLimits: TOctreeLimits = ( MaxDepth: DefLocalTriangleOctreeMaxDepth; LeafCapacity: DefLocalTriangleOctreeLeafCapacity );

Variables

DisableAutoDynamicGeometry: Cardinal;
LogShapes: boolean = false;
PlaceholderNames: TPlaceholderNames;

Description

Types

TShapeSpatialStructure = (...);

Possible spatial structure types that may be managed by TShape, see TShape.Spatial.

Values
  • ssTriangles: Create the TShape.OctreeTriangles. This is an octree containing all triangles.
TShapeSpatialStructures = set of TShapeSpatialStructure;

This item has no description.

TShapeTraverseFunc = procedure (const Shape: TShape) of object;

This item has no description.

TEnumerateShapeTexturesFunction = function (Shape: TShape; Texture: TAbstractTextureNode): Pointer of object;

This item has no description.

TTestShapeVisibility = function (Shape: TShape): boolean of object;

This item has no description.

TShapesHash = QWord;

This item has no description.

TShapeSortEvent = function ( const Camera: TViewVectors; const Shape1, Shape2: TShape; const RenderOptions1, RenderOptions2: TCastleRenderOptions; const SceneTransform1, SceneTransform2: TMatrix4) : Integer of object;

Used for TCastleViewport.OnCustomShapeSort.

When TCastleViewport.OnCustomShapeSort is assigned and TCastleViewport.BlendingSort or TCastleViewport.OcclusionSort indicate sortCustom, this is used to sort shapes.

It should return value:

  • < 0 if Shape1 is further from camera than Shape2

  • = 0 if Shape1 is at the same distance from camera than Shape2

  • > 0 if Shape1 is closer to camera than Shape2

The RenderOptions1, RenderOptions2 specify the rendering options for, respectively, Shape1 and Shape2. Note that if TCastleViewport.DynamicBatching is used, these shapes may not come from any particular scene, so their TShapeTree.ParentScene may be Nil. So you cannot rely on e.g. Shape1.ParentScene.RenderOptions to get the same value as RenderOptions1.

SceneTransform1, SceneTransform2 specify the shapes transformations. Note that a shape, just like TCastleScene, may be present multiple times in the same viewport (e.g. when you add the same TCastleScene instance multiple times to TCastleViewport.Items, or if you use TCastleTransformReference). That's why SceneTransform1, SceneTransform2 are useful, as they refer to given shape instance, in a particular transformation.

A sample implementation, doing actually the same thing as standard sort3DOrigin, may look like this:

function TMyView.MyShapeSort(
  const Camera: TViewVectors;
  const Shape1, Shape2: TShape;
  const RenderOptions1, RenderOptions2: TCastleRenderOptions;
  const SceneTransform1, SceneTransform2: TMatrix4): Integer;
var
  PointA, PointB: TVector3;
begin
  PointA := (SceneTransform1 * Shape1.OriginalState.Transformation.Transform).MultPoint(TVector3.Zero);
  PointB := (SceneTransform2 * Shape2.OriginalState.Transformation.Transform).MultPoint(TVector3.Zero);
  Result := Sign(
    TVector3.DotProduct(PointB, Camera.Direction) -
    TVector3.DotProduct(PointA, Camera.Direction));
  // Other approach:
  // Result := Sign(
  //   PointsDistanceSqr(PointB, Camera.Translation) -
  //   PointsDistanceSqr(PointA, Camera.Translation));
end;

TShapeTreeList = specialize TObjectList<TShapeTree>;

This item has no description.

TPlaceholderName = function (const Shape: TShape): string;

Detect the 3D placeholder name set in the external modeler, like 3D object name set in Blender or 3DS Max. Assumes that a specific modeler was used to create and export this 3D model. Each TPlaceholderName function is made to follow the logic of a single modeler, and they are gathered in PlaceholderNames.

Returns empty string if none.

When implementing this, you may find useful the following properties of the shape: TShape.OriginalGeometry.X3DName, TShape.Node.X3DName, TShape.GeometryParentNode.X3DName, TShape.GeometryGrandParentNode.X3DName, TShape.GeometryGrandGrandParentNode.X3DName.

Preferably, the result should be unique, only for this VRML/X3D shape. But in practice it's the responsibility of the modeler and model author to make it true. For example, modelers that allow multiple materials on object (like Blender) must split a single 3D object into many VRML/X3D shapes sometimes. So just don't use shapes with multiple materials if this shape may be meaningful for a placeholder.

This is used only by TLevel.Load placeholders. Ultimately, this should be something that is easy to set when creating a 3D model in given external modeler. Nothing else in our engine depends on a particular modeler strategy for exporting VRML/X3D models.

This should be object name (to allow sharing a single mesh underneath). Except when it's not possible (like for old Blender VRML 1.0 exporter, when only mesh names are stored in VRML/X3D exported files), in which case it can be a mesh name.

Constants

DefLocalTriangleOctreeMaxDepth = 10;

This item has no description.

DefLocalTriangleOctreeLeafCapacity = 32;

Default octree leaf capacity for TShape.OctreeTriangles.

This is slightly larger than DefTriangleOctreeLeafCapacity, as this octree will usually be used interactively for collision detection, not by ray-tracer. So octree construction speed is somewhat important, and cannot be too large...

DefLocalTriangleOctreeLimits: TOctreeLimits = ( MaxDepth: DefLocalTriangleOctreeMaxDepth; LeafCapacity: DefLocalTriangleOctreeLeafCapacity );

This item has no description.

Variables

DisableAutoDynamicGeometry: Cardinal;

If nonzero, disables automatic TShape.DynamicGeometry detection on every node modification. This is useful if you do some interactive editing of the shape, but you don't want to mark shape as dynamic.

LogShapes: boolean = false;

Log various information about shapes. This displays quite a lot of non-critical information when opening non-trivial models.

PlaceholderNames: TPlaceholderNames;

This item has no description.


Generated by PasDoc 0.16.0-snapshot.