This commit is contained in:
Nahuel Rocchetti 2023-07-27 16:58:37 -03:00
commit 61b578cd4f
2 changed files with 23 additions and 11 deletions

View file

@ -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;
}
}

View file

@ -37,9 +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...
bridgeObject.transform.rotation *= new Quaternion(bridge.ModelOrientation.x, -bridge.ModelOrientation.y, -bridge.ModelOrientation.z, bridge.ModelOrientation.w);
// 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;
@ -61,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;
}