Skip to content

Commit

Permalink
Always position upright
Browse files Browse the repository at this point in the history
  • Loading branch information
NanoBob committed May 26, 2022
1 parent b9e2a62 commit 8964ac4
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions RenderWarePreviewer/Scenes/SceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ public void LoadModel(Ped ped)

var models = MeshHelper.GetModels(dff, images);

var rotation = DetermineRotation(models);
this.scene.Clear();
foreach (var model in models)
this.scene.Add(model, new Vector3D(0, 0, 0), new Vector3D(0, 90, 0));
this.scene.Add(model, new Vector3D(0, 0, 0), rotation);
}

public void LoadModel(Ped ped, Image<Rgba32> image, string imageName)
Expand All @@ -82,9 +83,24 @@ public void LoadModel(Ped ped, Image<Rgba32> image, string imageName)
images[imageName] = image;
var models = MeshHelper.GetModels(dff, images);

var rotation = DetermineRotation(models);
this.scene.Clear();
foreach (var model in models)
this.scene.Add(model, new Vector3D(0, 0, 0), new Vector3D(0, 90, 0));
this.scene.Add(model, new Vector3D(0, 0, 0), rotation);
}

private Vector3D DetermineRotation(IEnumerable<GeometryModel3D> models)
{
var vertices = models
.SelectMany(x => (x.Geometry as MeshGeometry3D)!.Positions);
var highestX = vertices.Max(x => x.X);
var highestY = vertices.Max(x => x.Y);
var highestZ = vertices.Max(x => x.Z);

if (highestZ > highestX)
return new Vector3D(0, 0, 270);

return new Vector3D(0, 90, 0);
}

public Image<Rgba32> GetImage(Ped ped, string texture)
Expand Down

0 comments on commit 8964ac4

Please sign in to comment.