Unit X3DLoad

Classes, Interfaces, Objects and Records
Types

Description

Loading scenes as X3D nodes.

Every format except VRML/X3D is handled by converting it into X3D nodes graph. This allows to use our great X3D renderer, tools, saving to X3D and such, on every model.

Basic guide for adding a new format:

Uses

Overview

Functions and Procedures

function LoadNode(const Url: string; const NilOnUnrecognizedFormat: boolean = false): TX3DRootNode; overload;
function LoadNode(const Stream: TStream; BaseUrl: String; const MimeType: String; const NilOnUnrecognizedFormat: boolean = false): TX3DRootNode; overload;
function Load3D(const Url: string; const AllowStdIn: boolean = false; const NilOnUnrecognizedFormat: boolean = false): TX3DRootNode; deprecated 'use LoadNode, and note it has one less parameter (AllowStdIn is not implemented anymore)';
function LoadScene_FileFilters: String;
function Load3D_FileFilters: String; deprecated 'use LoadScene_FileFilters';
procedure Load3DSequence( const Url: string; const AllowStdIn: boolean; const KeyNodes: TX3DNodeList; const KeyTimes: TSingleList; out ScenesPerTime: Cardinal; out Epsilon: Single; out TimeLoop, TimeBackwards: boolean); deprecated 'use LoadNode instead of Load3DSequence';
function Load3DSequence_FileFilters: String; deprecated 'use LoadScene_FileFilters, and use LoadNode instead of Load3DSequence';
procedure SaveNode(const Node: TX3DNode; const URL: String; const Generator: String = ''; const Source: String = ''); overload;
procedure SaveNode(const Node: TX3DNode; const Stream: TStream; const MimeType: String; const Generator: String = ''; const Source: String = ''); overload;

Constants

SaveX3D_FileFilters = 'All files|*|' + '*X3D XML (*.x3d)|*.x3d|' + 'X3D XML (compressed) (*.x3dz, *.x3d.gz)|*.x3dz;*.x3d.gz|' + 'X3D classic (*.x3dv)|*.x3dv|' + 'X3D classic (compressed) (*.x3dvz, *.x3dv.gz)|*.x3dvz;*.x3dv.gz';
DefaultBakedAnimationSmoothness = 1;

Variables

BakedAnimationSmoothness: Single = DefaultBakedAnimationSmoothness;

Description

Functions and Procedures

function LoadNode(const Url: string; const NilOnUnrecognizedFormat: boolean = false): TX3DRootNode; overload;

Load a scene as X3D node. Guesses scene format based on the URL extension. We load a large number of formats, see https://castle-engine.io/creating_data_model_formats.php .

All the scene formats are loaded as a graph of X3D nodes.

URL is downloaded using the CastleDownload unit, so it supports files, http resources and more. See https://castle-engine.io/manual_network.php about supported URL schemes. If you all you care about is loading normal files, then just pass a normal filename (absolute or relative to the current directory) as the URL parameter.

To actually display, animate and do many other things with the loaded model, you usually want to load it to TCastleScene, using the TCastleSceneCore.Load method. Like this:

var
  RootNode: TX3DRootNode;
  Scene: TCastleScene;
begin
  RootNode := LoadNode('my_model.x3d');
  Scene := TCastleScene.Create(Application);
  Scene.Load(RootNode, true);
  // The 2nd parameter of Load says that Scene owns RootNode
end;

Actually, in most cases you don't need to use LoadNode (and this unit, X3DLoad) at all, and you can simply load from an URL:

var
  Scene: TCastleScene;
begin
  Scene := TCastleScene.Create(Application);
  Scene.Load('my_model.x3d');
  // you can access Scene.RootNode after loading, if needed
end;

Note that usually you want to load models from the game data, so you would actually use 'castle-data:/my_model.x3d' URL instead of 'my_model.x3d'.

function LoadNode(const Stream: TStream; BaseUrl: String; const MimeType: String; const NilOnUnrecognizedFormat: boolean = false): TX3DRootNode; overload;

Load a scene as X3D node from TStream.

Takes a TStream instance with contents to load, and MimeType parameter determines the data content (e.g. X3D or glTF or Spine model).

In most cases, instead of this, you should use a simpler LoadNode overloaded version that just takes URL parameter without the explicit Stream or MimeType parameters. It will automatically create the stream and guess MIME type.

The BaseUrl parameter here is used to resolve relative URLs inside the model, e.g. references to textures from various 3D and 2D model formats are resolved relative to this base URL. It generally should be a URL from which you downloaded the model. If you don't know it, you can use the current directory (which can be conveniently expressed by BaseUrl = '', which is a relative empty URL implying current working dir). We do not use BaseUrl to determine file contents (e.g. we don't look at filename extension here) in this routine.

Note that some formats (like glTF) require a stream with free seeking capabilities. Call Download with soForceMemoryStream, or wrap the stream in TMemoryStream manually, if unsure. The overloaded LoadNode without explicit TStream uses soForceMemoryStream when necessary.

Note that this routine assumes that the stream is not gzip-compressed. The overloaded LoadNode without explicit TStream accounts for gzip-compressed streams in some cases.

function Load3D(const Url: string; const AllowStdIn: boolean = false; const NilOnUnrecognizedFormat: boolean = false): TX3DRootNode; deprecated 'use LoadNode, and note it has one less parameter (AllowStdIn is not implemented anymore)';

Warning: this symbol is deprecated: use LoadNode, and note it has one less parameter (AllowStdIn is not implemented anymore)

 
function LoadScene_FileFilters: String;

File filters for files loaded by TCastleSceneCore.Load and LoadNode. Suitable for TFileFilterList.AddFiltersFromString and TCastleWindow.FileDialog.

function Load3D_FileFilters: String; deprecated 'use LoadScene_FileFilters';

Warning: this symbol is deprecated: use LoadScene_FileFilters

File filters for files loaded by TCastleSceneCore.Load and LoadNode. Suitable for TFileFilterList.AddFiltersFromString and TCastleWindow.FileDialog.

procedure Load3DSequence( const Url: string; const AllowStdIn: boolean; const KeyNodes: TX3DNodeList; const KeyTimes: TSingleList; out ScenesPerTime: Cardinal; out Epsilon: Single; out TimeLoop, TimeBackwards: boolean); deprecated 'use LoadNode instead of Load3DSequence';

Warning: this symbol is deprecated: use LoadNode instead of Load3DSequence

Load various model formats as animation expressed by VRML/X3D sequence.

For model formats that cannot express animations (like GEO or Wavefront OBJ) or that express animations in a single file (like VRML/X3D >= 2.0) we load them exactly like LoadNode, adding exactly one item to KeyNodes. So this function handles at least the same model formats as LoadNode.

Additionally, we load castle-anim-frames and MD3 formats to a sequence of frames.

Parameters
KeyNodes
Sequence of root nodes will be stored there. Pass here some created and empty instance of TX3DNodeList.
KeyTimes
Sequence of time values. Pass here some created and empty instance of TSingleList.
function Load3DSequence_FileFilters: String; deprecated 'use LoadScene_FileFilters, and use LoadNode instead of Load3DSequence';

Warning: this symbol is deprecated: use LoadScene_FileFilters, and use LoadNode instead of Load3DSequence

File filters for files loaded by Load3DSequence, suitable for TFileFilterList.AddFiltersFromString and TCastleWindow.FileDialog.

procedure SaveNode(const Node: TX3DNode; const URL: String; const Generator: String = ''; const Source: String = ''); overload;

Save model to a file. Right now we only support saving to the X3D format, in classic (MIME type 'model/x3d+vrml') or XML encoding (MIME type 'model/x3d+xml').

The overloaded version with explicit URL also automatically detects and handles gzip compression of the resulting file.

Parameters
Generator
Optional name, or short description, of the application generating this file. This value is not interpreted in any way, it is simply a "metadata" information we store in the resulting file.
Source
Optional name of the original file, if this file is a result of some conversion or transformation. This value is not interpreted in any way, it is simply a "metadata" information we store in the resulting file.
procedure SaveNode(const Node: TX3DNode; const Stream: TStream; const MimeType: String; const Generator: String = ''; const Source: String = ''); overload;
 

Constants

SaveX3D_FileFilters = 'All files|*|' + '*X3D XML (*.x3d)|*.x3d|' + 'X3D XML (compressed) (*.x3dz, *.x3d.gz)|*.x3dz;*.x3d.gz|' + 'X3D classic (*.x3dv)|*.x3dv|' + 'X3D classic (compressed) (*.x3dvz, *.x3dv.gz)|*.x3dvz;*.x3dv.gz';
 
DefaultBakedAnimationSmoothness = 1;
 

Variables

BakedAnimationSmoothness: Single = DefaultBakedAnimationSmoothness;

A smoothness value for "baked" animations loaded from castle-anim-frames files. This is multiplied by the scenes_per_time value recorded in castle-anim-frames file (30 by default), and determines the number of extra frames we add to the baked animation (between key frames).


Generated by PasDoc 0.16.0.