Skip to content

Commit

Permalink
Merge branch 'Issue12942'
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Oct 8, 2018
2 parents b7ae192 + 1d65b92 commit 73f4169
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
23 changes: 16 additions & 7 deletions src/loaders/OBJLoader2.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ THREE.OBJLoader2 = function ( manager ) {

this.modelName = '';
this.instanceNo = 0;
this.path = '';
this.path;
this.resourcePath;
this.useIndices = false;
this.disregardNormals = false;
this.materialPerSmoothingGroup = false;
Expand Down Expand Up @@ -69,6 +70,14 @@ THREE.OBJLoader2.prototype = {
this.path = THREE.LoaderSupport.Validator.verifyInput( path, this.path );
},

/**
* Allow to specify resourcePath for dependencies of specified resource.
* @param {string} resourcePath
*/
setResourcePath: function ( resourcePath ) {
this.resourcePath = THREE.LoaderSupport.Validator.verifyInput( resourcePath, this.resourcePath );
},

/**
* Set the node where the loaded objects will be attached directly.
*
Expand Down Expand Up @@ -185,7 +194,7 @@ THREE.OBJLoader2.prototype = {
/**
* Use this convenient method to load a file at the given URL. By default the fileLoader uses an ArrayBuffer.
*
* @param {string} url A string containing the path/URL of the file to be loaded.
* @param {string} url A string containing the path/URL of the file to be loaded.
* @param {callback} onLoad A function to be called after loading is successfully completed. The function receives loaded Object3D as an argument.
* @param {callback} [onProgress] A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, which contains total and Integer bytes.
* @param {callback} [onError] A function to be called if an error occurs during loading. The function receives the error as an argument.
Expand Down Expand Up @@ -231,6 +240,8 @@ THREE.OBJLoader2.prototype = {

}
};
this.setPath( resource.path );
this.setResourcePath( resource.resourcePath );

// fast-fail
if ( ! THREE.LoaderSupport.Validator.isValid( resource.url ) || THREE.LoaderSupport.Validator.isValid( resource.content ) ) {
Expand Down Expand Up @@ -258,9 +269,9 @@ THREE.OBJLoader2.prototype = {


var fileLoader = new THREE.FileLoader( this.manager );
fileLoader.setPath( this.path );
fileLoader.setPath( this.path || this.resourcePath );
fileLoader.setResponseType( 'arraybuffer' );
fileLoader.load( resource.url, fileLoaderOnLoad, onProgress, onError );
fileLoader.load( resource.name, fileLoaderOnLoad, onProgress, onError );

}
},
Expand Down Expand Up @@ -517,7 +528,7 @@ THREE.OBJLoader2.prototype = {
var mtlLoader = new THREE.MTLLoader( this.manager );
crossOrigin = THREE.LoaderSupport.Validator.verifyInput( crossOrigin, 'anonymous' );
mtlLoader.setCrossOrigin( crossOrigin );
mtlLoader.setResourcePath( resource.path );
mtlLoader.setResourcePath( resource.resourcePath || resource.path );
if ( THREE.LoaderSupport.Validator.isValid( materialOptions ) ) mtlLoader.setMaterialOptions( materialOptions );

var parseTextWithMtlLoader = function ( content ) {
Expand Down Expand Up @@ -722,7 +733,6 @@ THREE.OBJLoader2.Parser.prototype = {

/**
* Parse the provided arraybuffer
* @memberOf Parser
*
* @param {Uint8Array} arrayBuffer OBJ data as Uint8Array
*/
Expand Down Expand Up @@ -778,7 +788,6 @@ THREE.OBJLoader2.Parser.prototype = {

/**
* Parse the provided text
* @memberOf Parser
*
* @param {string} text OBJ data as string
*/
Expand Down
6 changes: 0 additions & 6 deletions src/loaders/support/LoaderBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ THREE.LoaderSupport.MeshBuilder.prototype = {

/**
* Enable or disable logging in general (except warn and error), plus enable or disable debug logging.
* @memberOf THREE.LoaderSupport.MeshBuilder
*
* @param {boolean} enabled True or false.
* @param {boolean} debug True or false.
Expand All @@ -35,7 +34,6 @@ THREE.LoaderSupport.MeshBuilder.prototype = {

/**
* Initializes the MeshBuilder (currently only default material initialisation).
* @memberOf THREE.LoaderSupport.MeshBuilder
*
*/
init: function () {
Expand Down Expand Up @@ -72,7 +70,6 @@ THREE.LoaderSupport.MeshBuilder.prototype = {

/**
* Set materials loaded by any supplier of an Array of {@link THREE.Material}.
* @memberOf THREE.LoaderSupport.MeshBuilder
*
* @param {THREE.Material[]} materials Array of {@link THREE.Material}
*/
Expand All @@ -98,7 +95,6 @@ THREE.LoaderSupport.MeshBuilder.prototype = {

/**
* Delegates processing of the payload (mesh building or material update) to the corresponding functions (BW-compatibility).
* @memberOf THREE.LoaderSupport.MeshBuilder
*
* @param {Object} payload Raw Mesh or Material descriptions.
* @returns {THREE.Mesh[]} mesh Array of {@link THREE.Mesh} or null in case of material update
Expand All @@ -118,7 +114,6 @@ THREE.LoaderSupport.MeshBuilder.prototype = {

/**
* Builds one or multiple meshes from the data described in the payload (buffers, params, material info).
* @memberOf THREE.LoaderSupport.MeshBuilder
*
* @param {Object} meshPayload Raw mesh description (buffers, params, materials) used to build one to many meshes.
* @returns {THREE.Mesh[]} mesh Array of {@link THREE.Mesh}
Expand Down Expand Up @@ -277,7 +272,6 @@ THREE.LoaderSupport.MeshBuilder.prototype = {

/**
* Updates the materials with contained material objects (sync) or from alteration instructions (async).
* @memberOf THREE.LoaderSupport.MeshBuilder
*
* @param {Object} materialPayload Material update instructions
*/
Expand Down
24 changes: 15 additions & 9 deletions src/loaders/support/LoaderCommons.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,13 @@ THREE.LoaderSupport.LoadedMeshUserOverride.prototype = {
THREE.LoaderSupport.ResourceDescriptor = function ( url, extension ) {
var urlParts = url.split( '/' );

if ( urlParts.length < 2 ) {
this.path;
this.resourcePath;
this.name = url;
this.url = url;
if ( urlParts.length >= 2 ) {

this.path = null;
this.name = url;
this.url = url;

} else {

this.path = THREE.LoaderSupport.Validator.verifyInput( urlParts.slice( 0, urlParts.length - 1).join( '/' ) + '/', null );
this.path = THREE.LoaderSupport.Validator.verifyInput( urlParts.slice( 0, urlParts.length - 1).join( '/' ) + '/', this.path );
this.name = urlParts[ urlParts.length - 1 ];
this.url = url;

Expand All @@ -167,7 +165,7 @@ THREE.LoaderSupport.ResourceDescriptor = function ( url, extension ) {
this.extension = THREE.LoaderSupport.Validator.verifyInput( extension, 'default' );
this.extension = this.extension.trim();
this.content = null;
}
};

THREE.LoaderSupport.ResourceDescriptor.prototype = {

Expand All @@ -180,6 +178,14 @@ THREE.LoaderSupport.ResourceDescriptor.prototype = {
*/
setContent: function ( content ) {
this.content = THREE.LoaderSupport.Validator.verifyInput( content, null );
},

/**
* Allow to specify resourcePath for dependencies of specified resource.
* @param {string} resourcePath
*/
setResourcePath: function ( resourcePath ) {
this.resourcePath = THREE.LoaderSupport.Validator.verifyInput( resourcePath, this.resourcePath );
}
};

Expand Down
4 changes: 1 addition & 3 deletions src/loaders/support/NodeLoaderWorkerSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ THREE.LoaderSupport.WorkerSupport.NodeLoaderWorker.prototype.constructor = THREE

/**
* @inheritdoc
* @memberOf NodeLoaderWorker
*/
*/
THREE.LoaderSupport.WorkerSupport.NodeLoaderWorker.checkSupport = function() {
try {
// Work around webpack builds failing with NodeJS requires
Expand All @@ -58,7 +57,6 @@ THREE.LoaderSupport.WorkerSupport.NodeLoaderWorker.checkSupport = function() {

/**
* @inheritdoc
* @memberOf NodeLoaderWorker
*/
THREE.LoaderSupport.WorkerSupport.NodeLoaderWorker.prototype.initWorker = function ( code, runnerImplName ) {
var supportError = this.checkSupport();
Expand Down

0 comments on commit 73f4169

Please sign in to comment.