Class: File

PD. File


new File()

Provides tools and methods for reading and saving a range of model file formats.

Author:
  • drajmarsh

Classes

ExportOptions

Members


:boolean

fsAPISupported <static>

Stores whether or not the File System Access API is supported.

Type
  • boolean

Methods


exportGeometry(object, exporter) <static>

Exports a THREE.Object3D and its children to a local file.

This method exports the geometry of a given object/group to a file in the specified format using the THREE exporters. Many of these exporters will include empty objects in the output and do not respect the drawRange property of geometries. As the geometry model used in the framework is highly dynamic, it will often contain empty objects (such as the transparent mesh on a roof level with no skylights) and makes full use of draw ranges.

To accommodate this, a temporary model hierarchy is created that mirrors the given object/group hierarchy, but includes only meshes and object that have renderable content and converts any dynamic PD.PolyMesh instances to static THREE.Mesh instances. These temporary objects are never added to the scene and thus do not use any resources on the GPU, so will be garbage collected at some point after the export is complete.

Parameters:
Name Type Description
object THREE.Object3D

The object/group to export.

exporter PD.File.ExportOptions

The export settings configuration object.

Returns:

Returns true if the export was successful.

Type
boolean

fileOpen( [config]) <async, static>

Attempts to open a file from disk.

This method first checks if the File System Access API is supported and uses it if available. If not supported, or a security error occurs, it falls back to a legacy <input type="file"> method.

Parameters:
Name Type Argument Description
config Object <optional>

An optional configuration object for opening the file(s).

Properties of config:
Name Type Argument Description
id string <optional>

The unique identifier for the file picker that the system can use to remember selected folders.

description string <optional>

The description to display alongside the file-type selector.

extensions Array.<string> <optional>

The file extension(s) to display in the file-type selector.

mimeType Array.<string> <optional>

The MIME type of the file(s) to open, defaults to ["/"].

startIn string <optional>

The well known directory to start in ('desktop'|'documents'|'downloads'|'music'|'pictures'|'videos'), defaults to an empty string.

options.multiple boolean <optional>

Whether or not to allow multiple file selection, defaults to false.

Returns:

Returns a promise that resolves to the selected file or file(s), or null if the user cancels.

Type
Promise.<(File|Array.<File>|null)>

fileSave(blobOrPromiseBlobOrResponse [, config] [, existingHandle] [, throwIfExistingHandleNotGood] [, filePickerShown]) <async, static>

Attempts to save a file to disk.

This method first checks if the File System Access API is supported and uses it if available. If not supported, or a security error occurs, it falls back to a legacy <input type="file"> method.

Parameters:
Name Type Argument Description
blobOrPromiseBlobOrResponse Blob | Promise.<Blob> | Response

The Blob, Promise resolving to a Blob, or Response to save.

config Object | Array.<Object> <optional>

An optional configuration object.

Properties of config:
Name Type Argument Description
id string <optional>

The unique identifier for the file picker that the system can use to remember selected folders.

description string <optional>

The description to display alongside the file-type selector.

extensions Array.<string> <optional>

The file extension(s) to display in the file-type selector.

mimeType Array.<string> <optional>

The MIME type of the file(s) to open, defaults to ["/"].

startIn string <optional>

The well known directory to start in ('desktop'|'documents'|'downloads'|'music'|'pictures'|'videos'), defaults to an empty string.

fileName string <optional>

The default name of the file to save/download, defaults to 'Untitled'.

existingHandle FileHandle <optional>

An existing file handle to save the data to, defaults to null.

throwIfExistingHandleNotGood boolean <optional>

Whether or not to throw an error if the existing file handle is not valid, defaults to false.

filePickerShown function <optional>

A callback function to call when the file picker is shown, defaults to null.

Returns:

Returns a promise that resolves to a file handle or null if the user cancels.

Type
Promise.<(FileHandle|null)>

loadFile(file, manager [, filesMap]) <static>

Imports a single geometry file and add its contents to the model.

Parameters:
Name Type Argument Description
file File

A file object to load.

manager THREE.LoadingManager

The loading manager to use for loading the file.

filesMap Map <optional>

A map of file names to File objects.

Returns:

Returns an object or group containing the loaded geometry.

Type
THREE.Object3D

loadFiles(files [, filesMap]) <async, static>

Load one or more model geometry files.

Parameters:
Name Type Argument Description
files Array.<File>

An array of File objects to load.

filesMap Map <optional>

A map of file names to File objects. This is used by a file manager to load assets that are referenced by model files and included in the given array of files, and to avoid loading the same file multiple times. If not provided, a new map will be created from the files array. A map should contain file names as keys and File objects as values. This allows the loading manager to resolve file URLs correctly.

Returns:

Returns true if files were loaded, false if the files array is empty.

Type
boolean

parseCityJSON(json, element [, options]) <static>

Imports a CityJSON file into the given element shell.

Parameters:
Name Type Argument Description
json object

The JSON data object.

element BIM.Element

The element to add the geometry to.

options object <optional>

Optional configuration callbacks and mesh options.

Properties of options:
Name Type Argument Description
progressIncrement number <optional>

An optional fractional progress rate for callbacks.

callbackProgress function <optional>

An optional function to call after each progress increment.

callbackComplete function <optional>

An optional function to call when parsing is complete.

debug boolean <optional>

An optional flag to show parsing time in the console.

Throws:

Occurs if the file is empty or invalid.

Type
TypeError
Returns:

Returns true recognizable geometry was added to the shell.

Type
boolean

parseGBXML(gbxml [, options]) <static>

Creates a new project from an imported gbXML file.

Parameters:
Name Type Argument Description
gbxml object

A JSON object representation of the XML data.

options object <optional>

Optional configuration callbacks and mesh options.

Properties of options:
Name Type Argument Description
progressIncrement number <optional>

An optional fractional progress rate for callbacks.

callbackProgress function <optional>

An optional function to call after each progress increment.

callbackComplete function <optional>

An optional function to call when parsing is complete.

debug boolean <optional>

An optional flag to show parsing time in the console.

Throws:

Occurs if the file is empty or invalid.

Type
TypeError
Returns:

Returns a new BIM.Project, or null if the gbXML is invalid.

Type
BIM.Project

parseJSON(json [, manager]) <async, static>

Handles loading JSON data containing multiple objects and meshes.

Parameters:
Name Type Argument Description
json Object

A hierarchical JSON object.

manager THREE.LoadingManager <optional>

A loading manager to use for loading asset files.

Returns:

A promise that resolves when the JSON file has been processed.

Type
Promise.<void>

parseMOD(reader [, options]) <static>

Imports an Ecotect .MOD file as a BIM.Element.Composite element.

Parameters:
Name Type Argument Description
reader object

A container to avoid large string copies.

Properties of reader:
Name Type Description
result object

The textual contents of the Ecotect .MOD file.

options object <optional>

Optional configuration callbacks and mesh options.

Properties of options:
Name Type Argument Description
groupBy function <optional>

A store for materials loaded from associated mtllib files.

progressIncrement number <optional>

An optional fractional progress rate for callbacks.

callbackProgress function <optional>

An optional function to call after each progress increment.

callbackComplete function <optional>

An optional function to call when parsing is complete.

fileInfo object <optional>

The file information associated with the selected .MOD file.

debug boolean <optional>

An optional flag to show parsing time in the console.

Throws:

Occurs if the file is empty or invalid.

Type
TypeError
Returns:

Returns composite element containing all elements in the file.

Type
BIM.Element.Composite

parseOBJ(reader [, options]) <static>

Imports a WaveFront .OBJ file as one or more BRep shapes.

Parameters:
Name Type Argument Description
reader object

A container to avoid large string copies.

Properties of reader:
Name Type Description
result object

The textual contents of the Wavefront OBJ file.

options object <optional>

Optional configuration callbacks and mesh options.

Properties of options:
Name Type Argument Description
materials function <optional>

A store for materials loaded from associated mtllib files.

progressIncrement number <optional>

An optional fractional progress rate for callbacks.

callbackProgress function <optional>

An optional function to call after each progress increment.

callbackComplete function <optional>

An optional function to call when parsing is complete.

swapYZ boolean <optional>

An optional flag to swap the Y and Z axis in the model, defaults to false.

flipY boolean <optional>

An optional flag to reverse the Y axis in the model, defaults to false.

debug boolean <optional>

An optional flag to show parsing time in the console.

Throws:

Occurs if the file is empty or invalid.

Type
TypeError
Returns:

Returns a Map with object names and breps parsed from the file.

Type
Map

parseZIP(container) <async, static>

Handles loading a ZIP file containing multiple 3D model files.

Parameters:
Name Type Description
container Object

A container object holding the ZIP file data.

Properties of container:
Name Type Description
result ArrayBuffer

The contents of the ZIP file as an ArrayBuffer.

Returns:

A promise that resolves when the ZIP file has been processed.

Type
Promise.<void>

saveAs3DM(object, filename) <async, static>

Saves a 3D object as a Rhino 3DM file.

When the object has been converted to a 3DM object URL, this function calls the PD.GlobalActions.saveObjectURLToClient method to save the data to the local file system. The file will be saved with the given filename suffixed with the current date/time and the .3dm file extension.

Parameters:
Name Type Description
object THREE.Object3D

The root 3D object to save.

filename string

The name of the file to save.


saveAs3MF(object, filename) <async, static>

Saves a 3D object as a 3MF file.

When the object has been converted to a 3MF object URL, this function calls the PD.GlobalActions.saveObjectURLToClient method to save the data to the local file system. The file will be saved with the given filename suffixed with the current date/time and the .3mf file extension.

Parameters:
Name Type Description
object THREE.Object3D

The root 3D object to save.

filename string

The name of the file to save.


saveAsGLTF(object, filename [, binary]) <async, static>

Saves a THREE 3D object as a GLB/GLTF file.

When the object has been converted to a GLB/GLTF object URL, this function calls the PD.GlobalActions.saveObjectURLToClient method to save the data to the local file system. The file will be saved with the given filename suffixed with the current date/time and either the .glb or .gltf file extension, depending on the value of the binary argument.

Parameters:
Name Type Argument Description
object THREE.Object3D

The root 3D object to save.

filename string

The name of the file to save.

binary boolean <optional>

Whether to save as binary GLB instead of ASCII GLTF, defaults to true.


saveAsOBJ(object, filename) <async, static>

Saves a 3D object as a Wavefront Object file.

When the object has been converted to an OBJ object URL, this function calls the PD.GlobalActions.saveObjectURLToClient method to save the data to the local file system. The file will be saved with the given filename suffixed with the current date/time and the .obj file extension.

Parameters:
Name Type Description
object THREE.Object3D

The root 3D object to save.

filename string

The name of the file to save.


saveAsPLY(object, filename) <async, static>

Saves a 3D object as a Stanford Triangle Format file.

When the object has been converted to a PLY object URL, this function calls the PD.GlobalActions.saveObjectURLToClient method to save the data to the local file system. The file will be saved with the given filename suffixed with the current date/time and the .ply file extension.

Parameters:
Name Type Description
object THREE.Object3D

The root 3D object to save.

filename string

The name of the file to save.


saveAsSTL(object, filename) <async, static>

Saves a 3D object as a Stereolithography file.

When the object has been converted to a STL object URL, this function calls the PD.GlobalActions.saveObjectURLToClient method to save the data to the local file system. The file will be saved with the given filename suffixed with the current date/time and the .stl file extension.

Parameters:
Name Type Description
object THREE.Object3D

The root 3D object to save.

filename string

The name of the file to save.


saveAsUSDZ(object, filename) <async, static>

Saves a 3D object as a USDZ file.

When the object has been converted to a USDZ object URL, this function calls the PD.GlobalActions.saveObjectURLToClient method to save the data to the local file system. The file will be saved with the given filename suffixed with the current date/time and the .usdz file extension.

Parameters:
Name Type Description
object THREE.Object3D

The root 3D object to save.

filename string

The name of the file to save.