Skip to content

Commit 73f4169

Browse files
committed
Merge branch 'Issue12942'
2 parents b7ae192 + 1d65b92 commit 73f4169

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

src/loaders/OBJLoader2.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ THREE.OBJLoader2 = function ( manager ) {
2020

2121
this.modelName = '';
2222
this.instanceNo = 0;
23-
this.path = '';
23+
this.path;
24+
this.resourcePath;
2425
this.useIndices = false;
2526
this.disregardNormals = false;
2627
this.materialPerSmoothingGroup = false;
@@ -69,6 +70,14 @@ THREE.OBJLoader2.prototype = {
6970
this.path = THREE.LoaderSupport.Validator.verifyInput( path, this.path );
7071
},
7172

73+
/**
74+
* Allow to specify resourcePath for dependencies of specified resource.
75+
* @param {string} resourcePath
76+
*/
77+
setResourcePath: function ( resourcePath ) {
78+
this.resourcePath = THREE.LoaderSupport.Validator.verifyInput( resourcePath, this.resourcePath );
79+
},
80+
7281
/**
7382
* Set the node where the loaded objects will be attached directly.
7483
*
@@ -185,7 +194,7 @@ THREE.OBJLoader2.prototype = {
185194
/**
186195
* Use this convenient method to load a file at the given URL. By default the fileLoader uses an ArrayBuffer.
187196
*
188-
* @param {string} url A string containing the path/URL of the file to be loaded.
197+
* @param {string} url A string containing the path/URL of the file to be loaded.
189198
* @param {callback} onLoad A function to be called after loading is successfully completed. The function receives loaded Object3D as an argument.
190199
* @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.
191200
* @param {callback} [onError] A function to be called if an error occurs during loading. The function receives the error as an argument.
@@ -231,6 +240,8 @@ THREE.OBJLoader2.prototype = {
231240

232241
}
233242
};
243+
this.setPath( resource.path );
244+
this.setResourcePath( resource.resourcePath );
234245

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

259270

260271
var fileLoader = new THREE.FileLoader( this.manager );
261-
fileLoader.setPath( this.path );
272+
fileLoader.setPath( this.path || this.resourcePath );
262273
fileLoader.setResponseType( 'arraybuffer' );
263-
fileLoader.load( resource.url, fileLoaderOnLoad, onProgress, onError );
274+
fileLoader.load( resource.name, fileLoaderOnLoad, onProgress, onError );
264275

265276
}
266277
},
@@ -517,7 +528,7 @@ THREE.OBJLoader2.prototype = {
517528
var mtlLoader = new THREE.MTLLoader( this.manager );
518529
crossOrigin = THREE.LoaderSupport.Validator.verifyInput( crossOrigin, 'anonymous' );
519530
mtlLoader.setCrossOrigin( crossOrigin );
520-
mtlLoader.setResourcePath( resource.path );
531+
mtlLoader.setResourcePath( resource.resourcePath || resource.path );
521532
if ( THREE.LoaderSupport.Validator.isValid( materialOptions ) ) mtlLoader.setMaterialOptions( materialOptions );
522533

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

723734
/**
724735
* Parse the provided arraybuffer
725-
* @memberOf Parser
726736
*
727737
* @param {Uint8Array} arrayBuffer OBJ data as Uint8Array
728738
*/
@@ -778,7 +788,6 @@ THREE.OBJLoader2.Parser.prototype = {
778788

779789
/**
780790
* Parse the provided text
781-
* @memberOf Parser
782791
*
783792
* @param {string} text OBJ data as string
784793
*/

src/loaders/support/LoaderBuilder.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ THREE.LoaderSupport.MeshBuilder.prototype = {
2323

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

3635
/**
3736
* Initializes the MeshBuilder (currently only default material initialisation).
38-
* @memberOf THREE.LoaderSupport.MeshBuilder
3937
*
4038
*/
4139
init: function () {
@@ -72,7 +70,6 @@ THREE.LoaderSupport.MeshBuilder.prototype = {
7270

7371
/**
7472
* Set materials loaded by any supplier of an Array of {@link THREE.Material}.
75-
* @memberOf THREE.LoaderSupport.MeshBuilder
7673
*
7774
* @param {THREE.Material[]} materials Array of {@link THREE.Material}
7875
*/
@@ -98,7 +95,6 @@ THREE.LoaderSupport.MeshBuilder.prototype = {
9895

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

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

278273
/**
279274
* Updates the materials with contained material objects (sync) or from alteration instructions (async).
280-
* @memberOf THREE.LoaderSupport.MeshBuilder
281275
*
282276
* @param {Object} materialPayload Material update instructions
283277
*/

src/loaders/support/LoaderCommons.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,13 @@ THREE.LoaderSupport.LoadedMeshUserOverride.prototype = {
150150
THREE.LoaderSupport.ResourceDescriptor = function ( url, extension ) {
151151
var urlParts = url.split( '/' );
152152

153-
if ( urlParts.length < 2 ) {
153+
this.path;
154+
this.resourcePath;
155+
this.name = url;
156+
this.url = url;
157+
if ( urlParts.length >= 2 ) {
154158

155-
this.path = null;
156-
this.name = url;
157-
this.url = url;
158-
159-
} else {
160-
161-
this.path = THREE.LoaderSupport.Validator.verifyInput( urlParts.slice( 0, urlParts.length - 1).join( '/' ) + '/', null );
159+
this.path = THREE.LoaderSupport.Validator.verifyInput( urlParts.slice( 0, urlParts.length - 1).join( '/' ) + '/', this.path );
162160
this.name = urlParts[ urlParts.length - 1 ];
163161
this.url = url;
164162

@@ -167,7 +165,7 @@ THREE.LoaderSupport.ResourceDescriptor = function ( url, extension ) {
167165
this.extension = THREE.LoaderSupport.Validator.verifyInput( extension, 'default' );
168166
this.extension = this.extension.trim();
169167
this.content = null;
170-
}
168+
};
171169

172170
THREE.LoaderSupport.ResourceDescriptor.prototype = {
173171

@@ -180,6 +178,14 @@ THREE.LoaderSupport.ResourceDescriptor.prototype = {
180178
*/
181179
setContent: function ( content ) {
182180
this.content = THREE.LoaderSupport.Validator.verifyInput( content, null );
181+
},
182+
183+
/**
184+
* Allow to specify resourcePath for dependencies of specified resource.
185+
* @param {string} resourcePath
186+
*/
187+
setResourcePath: function ( resourcePath ) {
188+
this.resourcePath = THREE.LoaderSupport.Validator.verifyInput( resourcePath, this.resourcePath );
183189
}
184190
};
185191

src/loaders/support/NodeLoaderWorkerSupport.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ THREE.LoaderSupport.WorkerSupport.NodeLoaderWorker.prototype.constructor = THREE
4343

4444
/**
4545
* @inheritdoc
46-
* @memberOf NodeLoaderWorker
47-
*/
46+
*/
4847
THREE.LoaderSupport.WorkerSupport.NodeLoaderWorker.checkSupport = function() {
4948
try {
5049
// Work around webpack builds failing with NodeJS requires
@@ -58,7 +57,6 @@ THREE.LoaderSupport.WorkerSupport.NodeLoaderWorker.checkSupport = function() {
5857

5958
/**
6059
* @inheritdoc
61-
* @memberOf NodeLoaderWorker
6260
*/
6361
THREE.LoaderSupport.WorkerSupport.NodeLoaderWorker.prototype.initWorker = function ( code, runnerImplName ) {
6462
var supportError = this.checkSupport();

0 commit comments

Comments
 (0)