LoaderSupport

Supporting classes for file loaders and web worker based loaders.

Sub-Classes

LoaderSupport.Builder
LoaderSupport.LoadedMeshUserOverride
LoaderSupport.WorkerSupport
LoaderSupport.WorkerRunnerRefImpl
LoaderSupport.WorkerDirector
LoaderSupport.ResourceDescriptor
LoaderSupport.PrepData
LoaderSupport.Callbacks
LoaderSupport.Validator

Example

webgl_loader_obj2_meshspray - Example using LoaderSupport.LoaderWorkerDirector and LoaderSupport.LoaderWorkerSupport.

Classes


Builder

Constructor

Builder()

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

Methods

.setLogging (enabled : Boolean, debug : Boolean) : null

enabled True or false.
debug True or false.

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

.init () : null

Initializes the Builder (currently only default material initialisation).

.setMaterials (Array of materials : Material) : null

Array of materials - Array of Materials

Set materials loaded by any supplier of an Array of Materials.

.processPayload (Object payload) : Array

payload - Raw Mesh or Material descriptions.

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

.buildMeshes (Object meshPayload) : Array

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).

.updateMaterials (Object materialPayload) : null

materialPayload - Material update instructions

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

.getMaterialsJSON () : Object

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

.getMaterials () : Object

Returns the mapping object of material name and corresponding material.



LoadedMeshUserOverride

Constructor

LoadedMeshUserOverride(disregardMesh : Boolean, bufferGeometry : BufferGeometry)

disregardMesh - Tell implementation to completely disregard this mesh
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

.addMesh (mesh : Mesh) : null

mesh - Mesh

Add a mesh created within callback.

.isDisregardMesh () : boolean

Answers if mesh shall be disregarded completely.

.providesAlteredMeshes () : boolean

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

.setLogging (enabled : Boolean, debug : Boolean) : null

enabled True or false.
debug True or false.

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

.setForceWorkerDataCopy (forceWorkerDataCopy : Boolean) : null

forceWorkerDataCopy True or false.

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

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

functionCodeBuilder - Function that is invoked with funcBuildObject and funcBuildSingleton that allows stringification of objects and singletons.
Array of libLocations - URL of libraries that shall be added to worker code relative to libPath.
libPath - Base path used for loading libraries.
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.

.setTerminateRequested (terminateRequested : Boolean) : null

terminateRequested - True or false.

Request termination of worker once parser is finished.

.setCallbacks (builder : Function, onLoad : Function) : null

builder - The builder function. Default is LoaderSupport.Builder.
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.

.run (payload : Object) : null

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

.applyProperties (parser : Object, params : Object) : null

parser - The parser instance
params - The parameter object

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

.run (payload : Object) : null

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(classDef : 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

.setLogging (enabled : Boolean, debug : Boolean) : null

enabled True or false.
debug True or false.

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

.setForceWorkerDataCopy (forceWorkerDataCopy : Boolean) : null

forceWorkerDataCopy True or false.

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

.prepareWorkers (globalCallbacks : WWOBJLoader2.Callbacks, maxQueueSize : Number, maxWebWorkers : Number) : null

globalCallbacks - Register global callbacks used by all web workers
maxQueueSize - Set the maximum size of the instruction queue (1-1024)
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.

.enqueueForRun (runParams : LoaderSupport.PrepData) : null

runParams

Store run instructions in internal instructionQueue.

.processQueue () : null

Process the instructionQueue until it is depleted.

.tearDown (callbackOnFinishedProcessing : Function) : null

callbackOnFinishedProcessing - Function called once all workers finished processing.

Terminate all workers.

.getMaxQueueSize () : null

Returns the maximum length of the instruction queue.

.getMaxWebWorkers () : null

Returns the maximum number of workers.

.isRunning () : Boolean

Returns if any workers are running.

.setCrossOrigin (crossOrigin : String) : null

crossOrigin - CORS value

Sets the CORS string to be used.



ResourceDescriptor

Constructor

ResourceDescriptor(url : String, extension : String)

url - URL to the file
extension - The file extension (type)

A resource description used by LoaderSupport.PrepData and others.

Methods

.setContent ([param:Object content) : null

content - The file content as ArrayBuffer or text

Set the content of this resource

.setResourcePath (resourcePath : String) : null

resourcePath - URL

Allows to specify resourcePath for dependencies of specified resource.



PrepData

Constructor

PrepData(modelName : String)

modelName - Overall name of the model

Configuration instructions to be used by run method.

Methods

.setLogging (enabled : Boolean, debug : Boolean) : null

enabled True or false.
debug True or false.

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

.getCallbacks () : Callbacks

Returns all callbacks as LoaderSupport.Callbacks.

.addResource (resource : LoaderSupport.ResourceDescriptor) : null

resource Adds a LoaderSupport.ResourceDescriptor

Add a resource description.

.checkResourceDescriptorFiles (resources : LoaderSupport.ResourceDescriptor, fileDesc : Object) : null

resources - Array of LoaderSupport.ResourceDescriptor
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 LoaderSupport.ResourceDescriptor. Returns Object with each "ext" and the corresponding LoaderSupport.ResourceDescriptor

.clone () : PrepData

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

.setCallbackOnProgress (callbackOnProgress : Function) : null

callbackOnProgress - Callback function for described functionality

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

.setCallbackOnReportError (callbackOnReportError : Function) : null

callbackOnReportError - Callback function for described functionality

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

.setCallbackOnMeshAlter (callbackOnMeshAlter : Function) : null

callbackOnMeshAlter - Callback function for described functionality

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

.setCallbackOnLoad (callbackOnLoad : Function) : null

callbackOnLoad - Callback function for described functionality

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

.setCallbackOnLoadMaterials (callbackOnLoadMaterials : Function) : null

callbackOnLoadMaterials - Callback function for described functionality

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



Validator

Constructor

Validator()

Validation functions.

Methods

.isValid (input : Object) : Boolean

input - Can be anything

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

.verifyInput (input : Object, defaultValue : Object) : null

input - Can be anything
defaultValue - Can be anything

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



Source

For more info on how to obtain the source code of this module see this page.