Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: OBJ loader bump map multiplier #12052

Merged
merged 1 commit into from Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions dist/preview release/what's new.md
Expand Up @@ -107,6 +107,7 @@
- Added support for normalized attributes ([#11685](https://github.com/BabylonJS/Babylon.js/issues/11685)) ([RaananW](https://github.com/RaananW))
- Added fallback error logging on mesh loading tasks if no error handler is defined. ([carolhmj](https://github.com/carolhmj))
- Updated the glTF loader to place the skinned mesh as a sibling of the skeleton root node instead of using `skeleton.overrideMesh`. ([bghgary](https://github.com/bghgary))
- Added support for `--bm` bump multiplier to OBJ loader ([brianzinn](https://github.com/brianzinn))

### Navigation

Expand Down
16 changes: 14 additions & 2 deletions loaders/src/OBJ/mtlFileLoader.ts
Expand Up @@ -37,7 +37,7 @@ export class MTLFileLoader {

//Split the lines from the file
var lines = data.split('\n');
//Space char
// whitespace char ie: [ \t\r\n\f]
var delimiter_pattern = /\s+/;
//Array with RGB colors
var color: number[];
Expand Down Expand Up @@ -135,7 +135,19 @@ export class MTLFileLoader {
// continue;
} else if (key === "map_bump" && material) {
//The bump texture
material.bumpTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
const values = value.split(delimiter_pattern);
const bumpMultiplierIndex = values.indexOf('-bm');
let bumpMultiplier: Nullable<string> = null;

if (bumpMultiplierIndex >= 0) {
bumpMultiplier = values[bumpMultiplierIndex + 1];
values.splice(bumpMultiplierIndex, 2); // remove
}

material.bumpTexture = MTLFileLoader._getTexture(rootUrl, values.join(' '), scene);
if (material.bumpTexture && bumpMultiplier !== null) {
material.bumpTexture.level = parseFloat(bumpMultiplier);
}
} else if (key === "map_d" && material) {
// The dissolve of the material
material.opacityTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
Expand Down