Skip to content

Materials not correctly applied by ObjLoader2Parallel (jsm) #17615

@Jens84

Description

@Jens84
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.

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.

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:

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
Hardware Requirements (graphics card, VR Device, ...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions