From 3265f8b076195f84ee1bf368b152442ec2165f1d Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 May 2024 03:51:57 -0400 Subject: [PATCH 1/5] Add parentPath to scatter --- NewHorizons/Builder/Props/ScatterBuilder.cs | 24 ++++++++++++++++--- .../External/Modules/Props/ScatterInfo.cs | 5 ++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index e725bf8a..e9416b3a 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -3,6 +3,7 @@ using NewHorizons.External.Modules.Props; using NewHorizons.Utility; using NewHorizons.Utility.Files; using NewHorizons.Utility.Geometry; +using NewHorizons.Utility.OWML; using OWML.Common; using System; using System.Collections.Generic; @@ -120,10 +121,27 @@ namespace NewHorizons.Builder.Props } } + + var parent = sector?.transform ?? go.transform; + + if (go != null && !string.IsNullOrEmpty(propInfo.parentPath)) + { + var newParent = go.transform.Find(propInfo.parentPath); + if (newParent != null) + { + parent = newParent; + sector = newParent.GetComponentInParent(); + } + else + { + NHLogger.LogError($"Cannot find parent object at path: {go.name}/{propInfo.parentPath}"); + } + } + var prop = scatterPrefab.InstantiateInactive(); - prop.transform.SetParent(sector?.transform ?? go.transform); - prop.transform.localPosition = go.transform.TransformPoint(point * height); - var up = go.transform.InverseTransformPoint(prop.transform.position).normalized; + prop.transform.SetParent(parent, false); + prop.transform.position = go.transform.TransformPoint(point * height); + var up = (prop.transform.position - go.transform.position).normalized; prop.transform.rotation = Quaternion.FromToRotation(Vector3.up, up); if (propInfo.offset != null) prop.transform.localPosition += prop.transform.TransformVector(propInfo.offset); diff --git a/NewHorizons/External/Modules/Props/ScatterInfo.cs b/NewHorizons/External/Modules/Props/ScatterInfo.cs index b53cd4e8..21d32d35 100644 --- a/NewHorizons/External/Modules/Props/ScatterInfo.cs +++ b/NewHorizons/External/Modules/Props/ScatterInfo.cs @@ -66,5 +66,10 @@ namespace NewHorizons.External.Modules.Props /// Should this detail stay loaded even if you're outside the sector (good for very large props) /// public bool keepLoaded; + + /// + /// The relative path from the planet to the parent of this object. Optional (will default to the root sector). + /// + public string parentPath; } } From 90f7d234794298d71bdb61bcf42fe3e5c098b06f Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 May 2024 08:40:09 -0400 Subject: [PATCH 2/5] Make it local so that scatter works on tidally locked bodies --- NewHorizons/Builder/Props/ScatterBuilder.cs | 2 +- NewHorizons/External/Modules/Props/ScatterInfo.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index e9416b3a..5b6faa34 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -140,7 +140,7 @@ namespace NewHorizons.Builder.Props var prop = scatterPrefab.InstantiateInactive(); prop.transform.SetParent(parent, false); - prop.transform.position = go.transform.TransformPoint(point * height); + prop.transform.localPosition = point * height; var up = (prop.transform.position - go.transform.position).normalized; prop.transform.rotation = Quaternion.FromToRotation(Vector3.up, up); diff --git a/NewHorizons/External/Modules/Props/ScatterInfo.cs b/NewHorizons/External/Modules/Props/ScatterInfo.cs index 21d32d35..a03b2003 100644 --- a/NewHorizons/External/Modules/Props/ScatterInfo.cs +++ b/NewHorizons/External/Modules/Props/ScatterInfo.cs @@ -68,7 +68,7 @@ namespace NewHorizons.External.Modules.Props public bool keepLoaded; /// - /// The relative path from the planet to the parent of this object. Optional (will default to the root sector). + /// The relative path from the planet to the parent of this object. Optional (will default to the root sector). This parent should be at the position where you'd like to scatter (which would usually be zero). /// public string parentPath; } From 5027ca8fd028c4db3126f07d5927dbd28f003e23 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 3 May 2024 09:52:32 -0400 Subject: [PATCH 3/5] Update schemas --- NewHorizons/Schemas/body_schema.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 3e9321e8..b679d7d3 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -2046,6 +2046,10 @@ "keepLoaded": { "type": "boolean", "description": "Should this detail stay loaded even if you're outside the sector (good for very large props)" + }, + "parentPath": { + "type": "string", + "description": "The relative path from the planet to the parent of this object. Optional (will default to the root sector). This parent should be at the position where you'd like to scatter (which would usually be zero)." } } }, From 6a516ef6af48ae6a7ad57e9082bf0ab06e092363 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 31 May 2024 06:18:33 -0400 Subject: [PATCH 4/5] Move scatter after details So that we can parent it to a root detail --- NewHorizons/Builder/Props/PropBuildManager.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/NewHorizons/Builder/Props/PropBuildManager.cs b/NewHorizons/Builder/Props/PropBuildManager.cs index 86dcf826..f8c1380f 100644 --- a/NewHorizons/Builder/Props/PropBuildManager.cs +++ b/NewHorizons/Builder/Props/PropBuildManager.cs @@ -47,17 +47,6 @@ namespace NewHorizons.Builder.Props } } } - if (config.Props.scatter != null) - { - try - { - ScatterBuilder.Make(go, sector, config, mod); - } - catch (Exception ex) - { - NHLogger.LogError($"Couldn't make planet scatter for [{go.name}]:\n{ex}"); - } - } if (config.Props.details != null) { foreach (var detail in config.Props.details) @@ -72,6 +61,17 @@ namespace NewHorizons.Builder.Props } } } + if (config.Props.scatter != null) + { + try + { + ScatterBuilder.Make(go, sector, config, mod); + } + catch (Exception ex) + { + NHLogger.LogError($"Couldn't make planet scatter for [{go.name}]:\n{ex}"); + } + } if (config.Props.geysers != null) { foreach (var geyserInfo in config.Props.geysers) From e617d98e1f31898f2a6bdb20780cc5bb62073ecb Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 3 Jun 2024 22:52:04 -0400 Subject: [PATCH 5/5] Add comment --- NewHorizons/Builder/Props/ScatterBuilder.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index 5b6faa34..862f0629 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -139,6 +139,7 @@ namespace NewHorizons.Builder.Props } var prop = scatterPrefab.InstantiateInactive(); + // Have to use SetParent method to work with tidally locked bodies #872 prop.transform.SetParent(parent, false); prop.transform.localPosition = point * height; var up = (prop.transform.position - go.transform.position).normalized;