Skip to content

Commit 70e3af0

Browse files
authored
Fix OBJ unlit color space (#3147)
1 parent 19dd159 commit 70e3af0

5 files changed

Lines changed: 35 additions & 20 deletions

File tree

application/testing/tests.native.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Tests file formats from native plugin
22
f3d_test(NAME TestPLY DATA suzanne.ply)
33
f3d_test(NAME TestOBJ DATA world.obj)
4+
f3d_test(NAME TestOBJUnlit DATA cube_unlit.obj)
45
f3d_test(NAME TestSTL DATA suzanne.stl)
56
f3d_test(NAME TestVTICell DATA waveletMaterial.vti ARGS -s --coloring-array=Material -c --roughness=1)
67
f3d_test(NAME TestVTU DATA dragon.vtu)

testing/baselines/TestOBJUnlit.png

Lines changed: 3 additions & 0 deletions
Loading

testing/data/cube_unlit.mtl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:48187bfef8e71b74c376879f6787c0eb611a839fc90c5f593ed17bbe61a47920
3+
size 100

testing/data/cube_unlit.obj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:bf212ee2dd625ab64bf8f00211bbf4dee54e184de335247742d918556bbc1a33
3+
size 674

vtkext/private/module/vtkF3DMetaImporter.cxx

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -340,36 +340,41 @@ bool vtkF3DMetaImporter::Update()
340340

341341
// convert to PBR materials if needed
342342
// this should be moved elsewhere, see https://github.com/f3d-app/f3d/issues/2995
343-
if (!genericImporter && actor->GetProperty()->GetInterpolation() != VTK_PBR &&
344-
actor->GetProperty()->GetLighting())
343+
if (!genericImporter && actor->GetProperty()->GetInterpolation() != VTK_PBR)
345344
{
346-
actor->GetProperty()->SetInterpolationToPBR();
347-
348-
// Convert to linear space
349-
auto toLinear = [](double c) { return std::pow(c, 2.2); };
350-
double diffuseColor[3];
351-
actor->GetProperty()->GetColor(diffuseColor);
352-
actor->GetProperty()->SetColor(
353-
toLinear(diffuseColor[0]), toLinear(diffuseColor[1]), toLinear(diffuseColor[2]));
354-
355-
// restore diffuse/specular to 1 and ambient to 0
356-
actor->GetProperty()->SetSpecular(1.0);
357-
actor->GetProperty()->SetDiffuse(1.0);
358-
actor->GetProperty()->SetAmbient(0.0);
359-
360-
// texture diffuse is now base color
345+
// get texture
361346
vtkSmartPointer<vtkTexture> diffuseTex = actor->GetTexture();
362347
if (!diffuseTex)
363348
{
364349
diffuseTex = actor->GetProperty()->GetTexture("diffuseTex");
365350
}
366351
if (diffuseTex)
367352
{
368-
actor->SetTexture(nullptr);
369353
diffuseTex->UseSRGBColorSpaceOn();
354+
}
355+
356+
if (actor->GetProperty()->GetLighting())
357+
{
358+
actor->GetProperty()->SetInterpolationToPBR();
359+
360+
// Convert to linear space
361+
auto toLinear = [](double c) { return std::pow(c, 2.2); };
362+
double diffuseColor[3];
363+
actor->GetProperty()->GetColor(diffuseColor);
364+
actor->GetProperty()->SetColor(
365+
toLinear(diffuseColor[0]), toLinear(diffuseColor[1]), toLinear(diffuseColor[2]));
366+
367+
// restore diffuse/specular to 1 and ambient to 0
368+
actor->GetProperty()->SetSpecular(1.0);
369+
actor->GetProperty()->SetDiffuse(1.0);
370+
actor->GetProperty()->SetAmbient(0.0);
370371

371-
actor->GetProperty()->SetColor(1.0, 1.0, 1.0);
372-
actor->GetProperty()->SetBaseColorTexture(diffuseTex);
372+
if (diffuseTex)
373+
{
374+
actor->SetTexture(nullptr);
375+
actor->GetProperty()->SetColor(1.0, 1.0, 1.0);
376+
actor->GetProperty()->SetBaseColorTexture(diffuseTex);
377+
}
373378
}
374379
}
375380

0 commit comments

Comments
 (0)