Skip to content

Commit

Permalink
Fix: Invert Y texture co-ordinates for OBJ exported via Blender
Browse files Browse the repository at this point in the history
  • Loading branch information
leezer3 committed Dec 10, 2023
1 parent 22034a5 commit a4ae983
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions source/AssimpParser/Wavefront/ObjFileParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ protected void ParseFile(string[] lines)
{
Model.Exporter = ModelExporter.BlockBench;
}
if (buffer.IndexOf("Blender", StringComparison.InvariantCultureIgnoreCase) != -1)
{
Model.Exporter = ModelExporter.Blender;
}
if(hash != -1)
{
string afterHash = buffer.Substring(hash + 1).Trim();
Expand Down
4 changes: 3 additions & 1 deletion source/OpenBveApi/Objects/Helpers/ModelExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public enum ModelExporter
/// <summary>Google SketchUp</summary>
SketchUp,
/// <summary>BlockBench</summary>
BlockBench
BlockBench,
/// <summary>Blender</summary>
Blender
}
}
1 change: 1 addition & 0 deletions source/Plugins/Object.Wavefront/Parsers/AssimpObjParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ internal static StaticObject ReadObject(string FileName)
textureCoordinate.X *= -1.0;
textureCoordinate.Y *= -1.0;
break;
case ModelExporter.Blender:
case ModelExporter.BlockBench:
textureCoordinate.Y *= -1.0;
break;
Expand Down
6 changes: 6 additions & 0 deletions source/Plugins/Object.Wavefront/Parsers/WavefrontObjParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ internal static StaticObject ReadObject(string FileName, System.Text.Encoding En
{
Exporter = ModelExporter.BlockBench;
}

if (Lines[i].IndexOf("Blender", StringComparison.InvariantCultureIgnoreCase) != -1)
{
Exporter = ModelExporter.Blender;
}
if(hash != -1 && eq != -1)
{
string afterHash = Lines[i].Substring(hash + 1).Trim();
Expand Down Expand Up @@ -255,6 +260,7 @@ internal static StaticObject ReadObject(string FileName, System.Text.Encoding En
newVertex.TextureCoordinates.X *= -1.0;
newVertex.TextureCoordinates.Y *= -1.0;
break;
case ModelExporter.Blender:
case ModelExporter.BlockBench:
newVertex.TextureCoordinates.Y *= -1.0;
break;
Expand Down

0 comments on commit a4ae983

Please sign in to comment.