Texture map options not parsed from mtl file #371
This commit is contained in:
parent
d12051de2e
commit
9bd495bcd5
@ -226,13 +226,53 @@ export class ImporterObj extends ImporterBase
|
|||||||
|
|
||||||
ProcessMaterialParameter (keyword, parameters, line)
|
ProcessMaterialParameter (keyword, parameters, line)
|
||||||
{
|
{
|
||||||
function CreateTexture (keyword, line, callbacks)
|
function ExtractTextureParameters (parameters)
|
||||||
|
{
|
||||||
|
let textureParameters = new Map ();
|
||||||
|
let lastParameter = null;
|
||||||
|
for (let i = 0; i < parameters.length - 1; i++) {
|
||||||
|
let parameter = parameters[i];
|
||||||
|
if (parameter.startsWith ('-')) {
|
||||||
|
lastParameter = parameter;
|
||||||
|
textureParameters.set (lastParameter, []);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (lastParameter !== null) {
|
||||||
|
textureParameters.get (lastParameter).push (parameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return textureParameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
function CreateTexture (parameters, callbacks)
|
||||||
{
|
{
|
||||||
let texture = new TextureMap ();
|
let texture = new TextureMap ();
|
||||||
let textureName = NameFromLine (line, keyword.length, '#');
|
let textureName = parameters[parameters.length - 1];
|
||||||
let textureBuffer = callbacks.getFileBuffer (textureName);
|
let textureBuffer = callbacks.getFileBuffer (textureName);
|
||||||
texture.name = textureName;
|
texture.name = textureName;
|
||||||
texture.buffer = textureBuffer;
|
texture.buffer = textureBuffer;
|
||||||
|
|
||||||
|
let textureParameters = ExtractTextureParameters (parameters);
|
||||||
|
if (textureParameters.has ('-o')) {
|
||||||
|
let offsetParameters = textureParameters.get ('-o');
|
||||||
|
if (offsetParameters.length > 0) {
|
||||||
|
texture.offset.x = parseFloat (offsetParameters[0]);
|
||||||
|
}
|
||||||
|
if (offsetParameters.length > 1) {
|
||||||
|
texture.offset.y = parseFloat (offsetParameters[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (textureParameters.has ('-s')) {
|
||||||
|
let scaleParameters = textureParameters.get ('-s');
|
||||||
|
if (scaleParameters.length > 0) {
|
||||||
|
texture.scale.x = parseFloat (scaleParameters[0]);
|
||||||
|
}
|
||||||
|
if (scaleParameters.length > 1) {
|
||||||
|
texture.scale.y = parseFloat (scaleParameters[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,20 +317,20 @@ export class ImporterObj extends ImporterBase
|
|||||||
if (this.currentMaterial === null || parameters.length === 0) {
|
if (this.currentMaterial === null || parameters.length === 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
this.currentMaterial.diffuseMap = CreateTexture (keyword, line, this.callbacks);
|
this.currentMaterial.diffuseMap = CreateTexture (parameters, this.callbacks);
|
||||||
UpdateMaterialTransparency (this.currentMaterial);
|
UpdateMaterialTransparency (this.currentMaterial);
|
||||||
return true;
|
return true;
|
||||||
} else if (keyword === 'map_ks') {
|
} else if (keyword === 'map_ks') {
|
||||||
if (this.currentMaterial === null || parameters.length === 0) {
|
if (this.currentMaterial === null || parameters.length === 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
this.currentMaterial.specularMap = CreateTexture (keyword, line, this.callbacks);
|
this.currentMaterial.specularMap = CreateTexture (parameters, this.callbacks);
|
||||||
return true;
|
return true;
|
||||||
} else if (keyword === 'map_bump' || keyword === 'bump') {
|
} else if (keyword === 'map_bump' || keyword === 'bump') {
|
||||||
if (this.currentMaterial === null || parameters.length === 0) {
|
if (this.currentMaterial === null || parameters.length === 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
this.currentMaterial.bumpMap = CreateTexture (keyword, line, this.callbacks);
|
this.currentMaterial.bumpMap = CreateTexture (parameters, this.callbacks);
|
||||||
return true;
|
return true;
|
||||||
} else if (keyword === 'ka') {
|
} else if (keyword === 'ka') {
|
||||||
if (this.currentMaterial === null || parameters.length < 3) {
|
if (this.currentMaterial === null || parameters.length < 3) {
|
||||||
|
|||||||
15
test/testfiles/obj/texture_parameters.mtl
Normal file
15
test/testfiles/obj/texture_parameters.mtl
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
newmtl No Parameters
|
||||||
|
Kd 1.000000 1.000000 1.000000
|
||||||
|
map_Kd texture.png
|
||||||
|
|
||||||
|
newmtl Offset
|
||||||
|
Kd 1.000000 1.000000 1.000000
|
||||||
|
map_Kd -o 0.1 0.2 0.0 texture.png
|
||||||
|
|
||||||
|
newmtl Scale
|
||||||
|
Kd 1.000000 1.000000 1.000000
|
||||||
|
map_Kd -s 2.0 3.0 0.0 texture.png
|
||||||
|
|
||||||
|
newmtl Offset and scale
|
||||||
|
Kd 1.000000 1.000000 1.000000
|
||||||
|
map_Kd -o 0.1 0.2 0.0 -s 2.0 3.0 0.0 texture.png
|
||||||
50
test/testfiles/obj/texture_parameters.obj
Normal file
50
test/testfiles/obj/texture_parameters.obj
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# Texture parameters
|
||||||
|
|
||||||
|
mtllib texture_parameters.mtl
|
||||||
|
|
||||||
|
vn 0.0 0.0 1.0
|
||||||
|
|
||||||
|
vt 0.0 0.0
|
||||||
|
vt 1.0 0.0
|
||||||
|
vt 1.0 1.0
|
||||||
|
vt 0.0 1.0
|
||||||
|
|
||||||
|
g No parameters
|
||||||
|
usemtl No Parameters
|
||||||
|
|
||||||
|
v 0.0 0.0 0.0
|
||||||
|
v 1.0 0.0 0.0
|
||||||
|
v 1.0 1.0 0.0
|
||||||
|
v 0.0 1.0 0.0
|
||||||
|
|
||||||
|
f -4/1/1 -3/2/1 -2/3/1 -1/4/1
|
||||||
|
|
||||||
|
g Offset
|
||||||
|
usemtl Offset
|
||||||
|
|
||||||
|
v 1.0 0.0 0.0
|
||||||
|
v 2.0 0.0 0.0
|
||||||
|
v 2.0 1.0 0.0
|
||||||
|
v 1.0 1.0 0.0
|
||||||
|
|
||||||
|
f -4/1/1 -3/2/1 -2/3/1 -1/4/1
|
||||||
|
|
||||||
|
g Scale
|
||||||
|
usemtl Scale
|
||||||
|
|
||||||
|
v 2.0 0.0 0.0
|
||||||
|
v 3.0 0.0 0.0
|
||||||
|
v 3.0 1.0 0.0
|
||||||
|
v 2.0 1.0 0.0
|
||||||
|
|
||||||
|
f -4/1/1 -3/2/1 -2/3/1 -1/4/1
|
||||||
|
|
||||||
|
g Offset and scale
|
||||||
|
usemtl Offset and scale
|
||||||
|
|
||||||
|
v 3.0 0.0 0.0
|
||||||
|
v 4.0 0.0 0.0
|
||||||
|
v 4.0 1.0 0.0
|
||||||
|
v 3.0 1.0 0.0
|
||||||
|
|
||||||
|
f -4/1/1 -3/2/1 -2/3/1 -1/4/1
|
||||||
Loading…
Reference in New Issue
Block a user