Skip to content

Commit

Permalink
Any saved transform property for an obj now takes precedence over the…
Browse files Browse the repository at this point in the history
… georeferenced transform of an obj. This allows the user to tweak the positioning of a georeferenced object and save the changes.
  • Loading branch information
TomSimons committed Jan 7, 2025
1 parent 938cbc0 commit 690bbec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPropertySectionInstantiator>().ToList();
toggleScatterPropertySectionInstantiator = GetComponent<ToggleScatterPropertySectionInstantiator>();
}
Expand Down Expand Up @@ -100,7 +101,8 @@ public virtual void LoadProperties(List<LayerPropertyData> 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);
Expand Down
22 changes: 18 additions & 4 deletions Assets/_Functionalities/ObjImporter/Scripts/ObjSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HierarchicalObjectLayerGameObject>();
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<MeshCollider>();

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)
Expand Down

0 comments on commit 690bbec

Please sign in to comment.