-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Description
Description of the problem
The OBJLoader2Parallel does not correctly apply given materials, added by calling addMaterials(materials) before loading, when using web workers (executeParallel = true) and falls back to default materials instead.
In WorkerRunner.js, payload.materials are applied to the corresponding instance of OBJLoader2Parser using ObjectManipulator.
three.js/examples/jsm/loaders/obj2/worker/parallel/WorkerRunner.js
Lines 52 to 54 in a84f4c4
| ObjectManipulator.applyProperties( parser, payload.params ); | |
| ObjectManipulator.applyProperties( parser, payload.materials ); | |
| ObjectManipulator.applyProperties( parser, callbacks ); |
However, in order for the ObjectManipulator to call the appropriate method, which is setMaterials(payload.materials), the second argument (L53) should be an object with materials as key and payload.materials as value.
three.js/examples/jsm/loaders/obj2/utils/ObjectManipulator.js
Lines 14 to 37 in a84f4c4
| applyProperties: function ( objToAlter, params, forceCreation ) { | |
| // fast-fail | |
| if ( objToAlter === undefined || objToAlter === null || params === undefined || params === null ) return; | |
| let property, funcName, values; | |
| for ( property in params ) { | |
| funcName = 'set' + property.substring( 0, 1 ).toLocaleUpperCase() + property.substring( 1 ); | |
| values = params[ property ]; | |
| if ( typeof objToAlter[ funcName ] === 'function' ) { | |
| objToAlter[ funcName ]( values ); | |
| } else if ( objToAlter.hasOwnProperty( property ) || forceCreation ) { | |
| objToAlter[ property ] = values; | |
| } | |
| } | |
| } |
I would suggest to move materials (L193) to the params object above in OBJLoader2Parallel.js and remove L53 from WorkerRunner.js:
three.js/examples/jsm/loaders/OBJLoader2Parallel.js
Lines 185 to 193 in a84f4c4
| params: { | |
| modelName: this.modelName, | |
| instanceNo: this.instanceNo, | |
| useIndices: this.parser.useIndices, | |
| disregardNormals: this.parser.disregardNormals, | |
| materialPerSmoothingGroup: this.parser.materialPerSmoothingGroup, | |
| useOAsMesh: this.parser.useOAsMesh, | |
| }, | |
| materials: this.materialHandler.getMaterialsJSON(), |
Three.js version
- Dev
- r108
- ...
Browser
- All of them
- Chrome
- Firefox
- Internet Explorer
OS
- All of them
- Windows
- macOS
- Linux
- Android
- iOS