OBJ Exporting incorrect textures

Aspose 3D for .NET
Version: 23.11.0

I’m having some issues when exporting an OBJ file. Ultimately, after some processing, I would like to be able to export the imported OBJ to either: OBJ, FBX or GLTF/GLB, depending on business logic factors.

It looks like the mapping of textures is incorrect. As a test, all I am doing is importing the OBJ, then exporting it without any processing. See images for before and after:

Original imported OBJ:
correct_input.jpg (48.8 KB)

exported OBJ:
incorrect_output.jpg (44.3 KB)

We can see that grass texture has been overlayed onto a car in the incorrect version. I have other examples which are much worse than the above, but the files are too big.

OBJ Load snippet:

var loadOpts = new ObjLoadOptions
{
    FileName = fileName,
    EnableMaterials = true
};

ModelScene = Scene.FromFile(filePath, loadOpts);

OBJ save snippet:

var saveOptions = new ObjSaveOptions
{
    FileName = fileName,
    Verbose = false,
    ExportTextures = true,
    EnableMaterials = true
};

ModelScene.Save(savePath, saveOptions);

Texture files are copied to the correct output directory using the above FYI. Here are the input and output files: (won’t upload - I’ll put in a separate post)

The original OBJ file seems to have a lot of redundant texture files, and the mtl file seems to point to a lot of redundant images also, but the OBJ is visually correct. This is because the user ‘cut out’ this OBJ from a larger OBJ file, and the mtl file kept these references. But it is a valid OBJ, and should be exporting correctly via Aspose.

What could be causing this issue?

I can’t attach the files here, must be exceeding a limit, I’ll send it to the support email and reference this post.

As a note - the same issue DOES NOT occur when exporting out to FBX.

When exporting to GLTF, although the gltf seems to reference the images, they are not applied to the texture.

EDIT:
FYI I have now sent an email to support with the relevant files
Note: the issue does not occur when exporting to FBX

@TPovey2

I’ve received your email. We’ll investigate this matter promptly to determine if it’s a bug. If confirmed, we’ll work on providing a hotfix as soon as possible. Thank you for bringing this to our attention.

Issue ID(s): THREEDNET-1451

That’s great, thanks @lex.chou. As a note, the issue doesn’t occur when exporting to FBX (only tested with binary):

        protected override FbxSaveOptions GetSaveOptions(string? fileName)
        {
            return new FbxSaveOptions(FileFormat.FBX7700Binary)
            {
                FileName = fileName,
                EnableCompression = true,
                EmbedTextures = true,
                ReusePrimitiveMesh = true,
                ExportLegacyMaterialProperties = true,
                VideoForTexture = false
            };
        }

But unfortunately it needs to be OBJ or GLTF 99% of the time

I have some more info:

What works:
FBX input to FBX output
FBX input to GLTF output

What doesn’t:
FBX to OBJ
OBJ to OBJ
OBJ to GLTF
OBJ to GLTF

What’s strange is OBJ - FBX works when opening the resulting FBX in Windows 3D viewer. But doesn’t work when opening in blender. Must be to do with how the packages parse the files.

@TPovey2
Thank you for providing this information; it’s quite helpful. Investigating this issue is now my top priority task.

@TPovey2
Could you share the GLTF file with me? I attempted to convert the OBJ file to GLTF on my end, and the resulting files look flawless in the Windows 3D Viewer.

Additionally, I’ve resolved the issue with the OBJ exporter. Now, it can correctly output content with a reduced file size of 41.5MB.

That’s great thankyou for your time on this - is there a hotfix we can download?

Sure - I’ll generate a new one and send it over

@TPovey2
Absolutely, once the GLTF issues are resolved, I’ll provide you with a hotfix. I can offer DLL files or deploy them to NuGet, depending on your preference and requirements.

Hi @lex.chou,

Nuget would be perfect thanks!

I’ve just sent the GLTF files via email with a download link. I have provided the files in the following formats:

  • GLTF 1.0
  • GLB 1.0
  • GLTF 2.0
  • GLB 2.0

The 1.0 versions won’t open - unsure if they are corrupt or if I don’t have a viewer that supports version 1. For me this is fine as I only require version 2.0.

Version 2.0 GLTF/GLB’s open just fine, and the mesh looks good. The textures are also referenced, but the textures aren’t shown. I’ve tried a number of different viewers, e.g. threeJS, babylonJS, online-gltf-viewer, online-khronus-gltf-viewer.

Here is how it looks:
image.jpg (44.3 KB)

GLTF2 save options:

scene.Save("path\\to\\test.gltf", new GltfSaveOptions(FileFormat.GLTF2)
{
    FileName = "test.gltf",
    SaveExtras = true,
    PrettyPrint = true,
    DracoCompression = false,
    ExportTextures = true,
});

GLB2 save options:

scene.Save("path\\to\\test.glb", new GltfSaveOptions(FileFormat.GLTF2_Binary)
{
    FileName = "test.glb",
    SaveExtras = true,
    PrettyPrint = false,
    DracoCompression = false,
});

FYI the OBJ load options I used are the same as in the original post.

Anything else you need from me just let me know.
Thanks

Also, I’m not sure if this is related to the original OBJ texture issue, so this may be fixed now with your updates, but sometimes textures aren’t exported when other types of models are imported (i.e. CAD/BIM models rather than photogrammetry).

I have sent another email with a test input file and test output files in OBJ, FBX and GLB.
Save options are the same as mentioned previously in this thread.

Here are some images;

Original OBJ input:
image.jpg (67.3 KB)

OBJ output is the same as the input, it works correctly with this dataset, in the past the textures weren’t correct, but unfortunatley I can’t reproduce at this time. When I can I will update this thread.

FBX output:
image.jpg (37.8 KB)

GLB and GLTF output:
image.jpg (39.8 KB)

As a note - sometimes when the original input is an FBX and we export this, the model is exported incorrectly, it looks like it’s something to do with the mesh group hierarchy transformation origins. I will make a separate thread for this as I’m assuming this is a different issue:

Original:
image.jpg (61.0 KB)

Exported OBJ:
image.png (40.8 KB)

@TPovey2
I’ve received the files, and the information you provided has been quite helpful. I’ve successfully reproduced this issue in the web-based glTF viewer. I’m actively working on resolving it and will provide a fix as soon as possible.

1 Like

@TPovey2
The issues with both OBJ and GLTF exports have been resolved. Currently, I’m investigating the problem related to FBX exports.

Excellent thanks @lex.chou

@TPovey2

Please utilize the hotfix version 23.11.1 available on NuGet, which addresses the following issues:

  1. Resolved the problem of excessively large OBJ file exports.
  2. Fixed material-related failures when exporting Mesh with VertexElementMaterial to OBJ.
  3. Rectified the issue causing the loss of non-PBR materials when exporting to GLTF.
  4. Corrected negative Y components in texture coordinates of exported GLTF files.
  5. Improved handling of FBX files exported from Maya that utilize RotationPivot, RotationOffset, ScalingPivot, and ScalingOffset, which previously may have caused transformation calculation failures.

Great thanks for the quick resolution on this @lex.chou

The issues you have found earlier (filed as THREEDNET-1451,THREEDNET-1453) have been fixed in this update. This message was posted using Bugs notification tool by lex.chou