From 690bbec87deb4c64ceb67c59ebcd5afc1505b0a1 Mon Sep 17 00:00:00 2001 From: Tom Simons Date: Tue, 7 Jan 2025 12:46:24 +0100 Subject: [PATCH] Any saved transform property for an obj now takes precedence over the georeferenced transform of an obj. This allows the user to tweak the positioning of a georeferenced object and save the changes. --- .../HierarchicalObjectLayerGameObject.cs | 6 +++-- .../ObjImporter/Scripts/ObjSpawner.cs | 22 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/Layers/LayerTypes/HierarchicalObjectLayerGameObject.cs b/Assets/Scripts/Layers/LayerTypes/HierarchicalObjectLayerGameObject.cs index 227302d59..76fc6d0c9 100644 --- a/Assets/Scripts/Layers/LayerTypes/HierarchicalObjectLayerGameObject.cs +++ b/Assets/Scripts/Layers/LayerTypes/HierarchicalObjectLayerGameObject.cs @@ -22,11 +22,12 @@ public class HierarchicalObjectLayerGameObject : LayerGameObject, IPointerClickH private Vector3 previousScale; LayerPropertyData ILayerWithPropertyData.PropertyData => transformPropertyData; + public bool TransformIsSetFromProperty { get; private set; } = false; protected void Awake() { transformPropertyData = new TransformLayerPropertyData(new Coordinate(transform.position), transform.eulerAngles, transform.localScale); - + propertySections = GetComponents().ToList(); toggleScatterPropertySectionInstantiator = GetComponent(); } @@ -100,7 +101,8 @@ public virtual void LoadProperties(List properties) UpdatePosition(this.transformPropertyData.Position); UpdateRotation(this.transformPropertyData.EulerRotation); UpdateScale(this.transformPropertyData.LocalScale); - + TransformIsSetFromProperty = true; + transformPropertyData.OnPositionChanged.AddListener(UpdatePosition); transformPropertyData.OnRotationChanged.AddListener(UpdateRotation); transformPropertyData.OnScaleChanged.AddListener(UpdateScale); diff --git a/Assets/_Functionalities/ObjImporter/Scripts/ObjSpawner.cs b/Assets/_Functionalities/ObjImporter/Scripts/ObjSpawner.cs index c14a16f82..bbbe14f4e 100644 --- a/Assets/_Functionalities/ObjImporter/Scripts/ObjSpawner.cs +++ b/Assets/_Functionalities/ObjImporter/Scripts/ObjSpawner.cs @@ -93,24 +93,38 @@ private void ImportObj(string objPath, string mtlPath = "") private void OnObjImported(GameObject returnedGameObject) { - // By explicitly stating the worldPositionStays to false, we ensure Obj is spawned and it will retain the - // position and scale in this parent object bool isGeoReferenced = !importer.createdGameobjectIsMoveable; + bool hasTransformProperty = false; + + var holgo = GetComponent(); + if (holgo) + hasTransformProperty = holgo.TransformIsSetFromProperty; + importedObject = returnedGameObject; if (isGeoReferenced) { - transform.position = returnedGameObject.transform.position; + SetObjectPosition(returnedGameObject, hasTransformProperty); Debug.Log("Geo-referenced object importer, moving camera to this position: " + returnedGameObject.transform.position); var mainCam = Camera.main; mainCam.transform.position = returnedGameObject.transform.position + (-cameraDistanceFromGeoReferencedObject * mainCam.transform.forward); } - returnedGameObject.transform.SetParent(this.transform, isGeoReferenced); + // In case the returned object is georeferenced, or this (parent) object has its transform set from a property, we will use either of those positionings, and need to retain the world position. + returnedGameObject.transform.SetParent(this.transform, isGeoReferenced || hasTransformProperty); returnedGameObject.AddComponent(); DisposeImporter(); } + private void SetObjectPosition(GameObject returnedGameObject, bool hasTransformProperty) + { + // if we already have a position from the transform properties, match the returned object's positioning to this saved position, otherwise set it to the returned object's positioning, since this is the georeferenced position. + if (hasTransformProperty) + returnedGameObject.transform.position = transform.position; + else + transform.position = returnedGameObject.transform.position; + } + private void DisposeImporter() { if (importer != null)