mirror of
https://github.com/LazyDuchess/OpenTS2.git
synced 2025-01-23 00:31:47 -05:00
Add gameobject to transform from sims2 space to unity
Previously we were using an ad-hoc system where we were rotating meshes to -90 on the x-axis and applying a -1 scale to them. This worked to show them properly but meant that because our coordinate system was flipped all rotations from the game had to be inverted from a right-hand system to a left-hand system. This change introduces a simRotations object that all the meshes sit under that takes raw rotations from the game. The parent game object then converts these all at once into the unity space. All rotations from the game should now be applied to this simRotations object, we should likely move this ScenegraphResourceAsset generated game object into a helper MonoBehavior to make this easier to use.
This commit is contained in:
parent
af8f67a56d
commit
c9010e20ff
2 changed files with 23 additions and 12 deletions
|
@ -26,10 +26,20 @@ namespace OpenTS2.Content.DBPF.Scenegraph
|
|||
var shape = ContentProvider.Get().GetAsset<ScenegraphShapeAsset>(shapeKey);
|
||||
|
||||
shape.LoadModelsAndMaterials();
|
||||
|
||||
var gameObject = new GameObject(resourceName, typeof(MeshFilter), typeof(MeshRenderer), typeof(AssetReferenceComponent));
|
||||
|
||||
var gameObject = new GameObject(resourceName, typeof(AssetReferenceComponent));
|
||||
|
||||
// Apply a transformation to convert from the sims coordinate space to unity.
|
||||
gameObject.transform.Rotate(-90, 0, 0);
|
||||
gameObject.transform.localScale = new Vector3(1, -1, 1);
|
||||
|
||||
// Keeps a strong reference to the Shape asset.
|
||||
gameObject.GetComponent<AssetReferenceComponent>().AddReference(shape);
|
||||
|
||||
// This is the component that holds rotations from sims space. All rotations from the game such as applying
|
||||
// quaternions and angles should be performed on it or components under it.
|
||||
var simsRotation = new GameObject("simsRotations");
|
||||
|
||||
// Render out each model.
|
||||
foreach (var model in shape.Models)
|
||||
{
|
||||
|
@ -40,7 +50,6 @@ namespace OpenTS2.Content.DBPF.Scenegraph
|
|||
{
|
||||
transform =
|
||||
{
|
||||
parent = gameObject.transform,
|
||||
rotation = shapeTransform.Rotation,
|
||||
position = shapeTransform.Transform
|
||||
}
|
||||
|
@ -51,13 +60,12 @@ namespace OpenTS2.Content.DBPF.Scenegraph
|
|||
{
|
||||
primitiveObject.GetComponent<MeshRenderer>().material = material.GetAsUnityMaterial();
|
||||
}
|
||||
|
||||
primitiveObject.transform.SetParent(simsRotation.transform);
|
||||
}
|
||||
}
|
||||
// TODO: Models in the game use a different up-axis, adjusting for that here right now. See if there's a
|
||||
// better spot.
|
||||
gameObject.transform.Rotate(-90, 0, 0);
|
||||
gameObject.transform.localScale = new Vector3(1, -1, 1);
|
||||
|
||||
simsRotation.transform.SetParent(gameObject.transform, worldPositionStays:false);
|
||||
return gameObject;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,10 +37,9 @@ namespace OpenTS2.Scenes
|
|||
var bridgeObject = model.CreateGameObjectForShape();
|
||||
bridgeObject.transform.position = (bridge.Road.Position.Position + bridge.PositionOffset);
|
||||
|
||||
// TODO: this is a temporary hack to fix bridge orientation, there's something weird going on with one
|
||||
// of our axes that we need to do this...
|
||||
var eulerRotation = bridge.ModelOrientation.eulerAngles;
|
||||
bridgeObject.transform.Rotate(eulerRotation.x, eulerRotation.y, -eulerRotation.z);
|
||||
// TODO: put this in a helper MonoBehavior or something.
|
||||
var simsRotation = bridgeObject.transform.Find("simsRotations");
|
||||
simsRotation.localRotation = bridge.ModelOrientation;
|
||||
|
||||
// Parent to this component.
|
||||
bridgeObject.transform.parent = transform;
|
||||
|
@ -62,7 +61,11 @@ namespace OpenTS2.Scenes
|
|||
|
||||
var decorationObject = model.CreateGameObjectForShape();
|
||||
decorationObject.transform.position = decoration.Position.Position;
|
||||
decorationObject.transform.Rotate(0, 0, -decoration.Rotation);
|
||||
|
||||
// TODO: put this in a helper MonoBehavior or something.
|
||||
var simsRotation = decorationObject.transform.Find("simsRotations");
|
||||
simsRotation.Rotate(0, 0, decoration.Rotation);
|
||||
|
||||
// Parent to this component.
|
||||
decorationObject.transform.parent = transform;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue