[name]

Supporting classes for file loaders and web worker based loaders.

Sub-Classes

[page:LoaderSupport.Builder]
[page:LoaderSupport.LoadedMeshUserOverride]
[page:LoaderSupport.WorkerSupport]
[page:LoaderSupport.WorkerRunnerRefImpl]
[page:LoaderSupport.WorkerDirector]
[page:LoaderSupport.ResourceDescriptor]
[page:LoaderSupport.PrepData]
[page:LoaderSupport.Callbacks]
[page:LoaderSupport.Validator]

Example

[example:webgl_loader_obj2_meshspray] - Example using [page:LoaderSupport.LoaderWorkerDirector] and [page:LoaderSupport.LoaderWorkerSupport].

Classes


Builder

Constructor

Builder()

Builds one or many [page:Mesh] from one raw set of Arraybuffers, materialGroup descriptions and further parameters. Supports vertex, vertexColor, normal, uv and index buffers.

Methods

[method:null setLogging] ( [param:Boolean enabled], [param:Boolean debug] )

[page:Boolean enabled] True or false.
[page:Boolean debug] True or false.

Enable or disable logging in general (except warn and error), plus enable or disable debug logging.

[method:null init] ()

Initializes the Builder (currently only default material initialisation).

[method:null setMaterials] ( Array of [param:Material materials] )

Array of [page:Material materials] - Array of [page:Material Materials]

Set materials loaded by any supplier of an Array of [page:Material Materials].

[method:Array processPayload] ( Object payload )

[page:Object payload] - Raw Mesh or Material descriptions.

Delegates processing of the payload (mesh building or material update) to the corresponding functions (BW-compatibility).

[method:Array buildMeshes] ( Object meshPayload )

[page:Object meshPayload] - Raw mesh description (buffers, params, materials) used to build one to many meshes.

Builds one or multiple meshes from the data described in the payload (buffers, params, material info).

[method:null updateMaterials] ( Object materialPayload )

[page:Object materialPayload] - Material update instructions

Updates the materials with contained material objects (sync) or from alteration instructions (async).

[method:Object getMaterialsJSON] ()

Returns the mapping object of material name and corresponding jsonified material.

[method:Object getMaterials] ()

Returns the mapping object of material name and corresponding material.



LoadedMeshUserOverride

Constructor

LoadedMeshUserOverride( [param:Boolean disregardMesh], [param:BufferGeometry bufferGeometry] )

[page:Boolean disregardMesh] - Tell implementation to completely disregard this mesh
[page:Boolean alteredMesh] - Tell implementation that mesh(es) have been altered or added

Object to return by callback onMeshAlter. Used to disregard a certain mesh or to return one to many meshes.

Methods

[method:null addMesh] ( [param:Mesh mesh] )

[page:Mesh mesh] - Mesh

Add a mesh created within callback.

[method:boolean isDisregardMesh] ()

Answers if mesh shall be disregarded completely.

[method:boolean providesAlteredMeshes] ()

Answers if new mesh(es) were created.



WorkerSupport

Constructor

WorkerSupport()

This class provides means to transform existing parser code into a web worker. It defines a simple communication protocol which allows to configure the worker and receive raw mesh data during execution.

Methods

[method:null setLogging]( [param:Boolean enabled], [param:Boolean debug] )

[page:Boolean enabled] True or false.
[page:Boolean debug] True or false.

Enable or disable logging in general (except warn and error), plus enable or disable debug logging.

[method:null setForceWorkerDataCopy]( [param:Boolean forceWorkerDataCopy] )

[page:Boolean forceWorkerDataCopy] True or false.

Forces all ArrayBuffers to be transferred to worker to be copied.

[method:null validate] ( [param:Function functionCodeBuilder], Array of [param:String libLocations], [param:String libPath], [param:LoaderSupport.WorkerRunnerRefImpl runnerImpl] )

[page:Function functionCodeBuilder] - Function that is invoked with funcBuildObject and funcBuildSingleton that allows stringification of objects and singletons.
Array of [page:String libLocations] - URL of libraries that shall be added to worker code relative to libPath.
[page:String libPath] - Base path used for loading libraries.
[page:LoaderSupport.WorkerRunnerRefImpl runnerImpl] - The default worker parser wrapper implementation (communication and execution). An extended class could be passed here.

Validate the status of worker code and the derived worker.

[method:null setTerminateRequested] ( [param:Boolean terminateRequested] )

[page:Boolean terminateRequested] - True or false.

Request termination of worker once parser is finished.

[method:null setCallbacks] ( [param:Function builder], [param:Function onLoad] )

[page:Function builder] - The builder function. Default is [page:LoaderSupport.Builder].
[page:Function onLoad] - The function that is called when parsing is complete.

Specify functions that should be build when new raw mesh data becomes available and when the parser is finished.

[method:null run] ( [param:Object payload] )

[page:Object payload] - Raw mesh description (buffers, params, materials) used to build one to many meshes.

Runs the parser with the provided configuration.



WorkerRunnerRefImpl

Constructor

WorkerRunnerRefImpl()

Default implementation of the WorkerRunner responsible for creation and configuration of the parser within the worker.

Methods

[method:null applyProperties] ( [param:Object parser], [param:Object params] )

[page:Object parser] - The parser instance
[page:Object params] - The parameter object

Applies values from parameter object via set functions or via direct assignment.

[method:null run] ( [param:Object payload] )

[page:Object payload] - Raw mesh description (buffers, params, materials) used to build one to many meshes.

Configures the Parser implementation according the supplied configuration object.



WorkerDirector

Constructor

WorkerDirector( [param:String classDef] )

[page:String classDef] - Class definition to be used for construction

Orchestrate loading of multiple OBJ files/data from an instruction queue with a configurable amount of workers (1-16).
- Workflow:
- prepareWorkers
- enqueueForRun
- processQueue
- tearDown

Methods

[method:null setLogging]( [param:Boolean enabled], [param:Boolean debug] )

[page:Boolean enabled] True or false.
[page:Boolean debug] True or false.

Enable or disable logging in general (except warn and error), plus enable or disable debug logging.

[method:null setForceWorkerDataCopy]( [param:Boolean forceWorkerDataCopy] )

[page:Boolean forceWorkerDataCopy] True or false.

Forces all ArrayBuffers to be transferred to worker to be copied.

[method:null prepareWorkers]( [param:WWOBJLoader2.Callbacks globalCallbacks], [param:Number maxQueueSize], [param:Number maxWebWorkers] )

[page:LoaderSupport.Callbacks globalCallbacks] - Register global callbacks used by all web workers
[page:Number maxQueueSize] - Set the maximum size of the instruction queue (1-1024)
[page:Number maxWebWorkers] - Set the maximum amount of workers (1-16)

Create or destroy workers according limits. Set the name and register callbacks for dynamically created web workers.

[method:null enqueueForRun]( [param:LoaderSupport.PrepData runParams] )

[page:LoaderSupport.PrepData runParams]

Store run instructions in internal instructionQueue.

[method:null processQueue]()

Process the instructionQueue until it is depleted.

[method:null tearDown]( [param:Function callbackOnFinishedProcessing] )

[page:Function callbackOnFinishedProcessing] - Function called once all workers finished processing.

Terminate all workers.

[method:null getMaxQueueSize]()

Returns the maximum length of the instruction queue.

[method:null getMaxWebWorkers]()

Returns the maximum number of workers.

[method:Boolean isRunning]()

Returns if any workers are running.

[method:null setCrossOrigin]( [param:String crossOrigin] )

[page:String crossOrigin] - CORS value

Sets the CORS string to be used.



ResourceDescriptor

Constructor

ResourceDescriptor( [param:String url], [param:String extension] )

[page:String url] - URL to the file
[page:String extension] - The file extension (type)

A resource description used by [page:LoaderSupport.PrepData] and others.

Methods

[method:null setContent]( [param:Object content )

[page:Object content] - The file content as ArrayBuffer or text

Set the content of this resource

[method:null setResourcePath] ( [param:String resourcePath] )

[page:String resourcePath] - URL

Allows to specify resourcePath for dependencies of specified resource.



PrepData

Constructor

PrepData( [param:String modelName] )

[page:String modelName] - Overall name of the model

Configuration instructions to be used by run method.

Methods

[method:null setLogging]( [param:Boolean enabled], [param:Boolean debug] )

[page:Boolean enabled] True or false.
[page:Boolean debug] True or false.

Enable or disable logging in general (except warn and error), plus enable or disable debug logging.

[method:Callbacks getCallbacks]()

Returns all callbacks as [page:LoaderSupport.Callbacks].

[method:null addResource]( [param:LoaderSupport.ResourceDescriptor resource] )

[page:LoaderSupport.ResourceDescriptor resource] Adds a [page:LoaderSupport.ResourceDescriptor]

Add a resource description.

[method:null checkResourceDescriptorFiles] ( [param:LoaderSupport.ResourceDescriptor resources], [param:Object fileDesc] )

[page:LoaderSupport.ResourceDescriptor resources] - Array of [page:LoaderSupport.ResourceDescriptor]
[page:Object fileDesc] - Object describing which resources are of interest (ext, type (string or UInt8Array) and ignore (boolean))

Identify files or content of interest from an Array of [page:LoaderSupport.ResourceDescriptor]. Returns Object with each "ext" and the corresponding [page:LoaderSupport.ResourceDescriptor]

[method:PrepData clone] ()

Clones this object and returns it afterwards. Callbacks and resources are not cloned deep (references!).



Callbacks

Constructor

Callbacks()

Callbacks utilized by loaders and builder.

Methods

[method:null setCallbackOnProgress]( [param:Function callbackOnProgress] )

[page:Function callbackOnProgress] - Callback function for described functionality

Register callback function that is invoked by internal function "announceProgress" to print feedback.

[method:null setCallbackOnReportError]( [param:Function callbackOnReportError] )

[page:Function callbackOnReportError] - Callback function for described functionality

Register callback function that is invoked when an error is reported.

[method:null setCallbackOnMeshAlter]( [param:Function callbackOnMeshAlter] )

[page:Function callbackOnMeshAlter] - Callback function for described functionality

Register callback function that is called every time a mesh was loaded. Use [page:LoadedMeshUserOverride] for alteration instructions (geometry, material or disregard mesh).

[method:null setCallbackOnLoad]( [param:Function callbackOnLoad] )

[page:Function callbackOnLoad] - Callback function for described functionality

Register callback function that is called once loading of the complete OBJ file is completed.

[method:null setCallbackOnLoadMaterials]( [param:Function callbackOnLoadMaterials] )

[page:Function callbackOnLoadMaterials] - Callback function for described functionality

Register callback function that is called when materials have been loaded.



Validator

Constructor

Validator()

Validation functions.

Methods

[method:Boolean isValid]( [param:Object input] )

[page:Object input] - Can be anything

If given input is null or undefined, false is returned otherwise true.

[method:null verifyInput]( [param:Object input], [param:Object defaultValue] )

[page:Object input] - Can be anything
[page:Object defaultValue] - Can be anything

If given input is null or undefined, the defaultValue is returned otherwise the given input.



Source

[link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/LoaderSupport.js examples/js/loaders/LoaderSupport.js]