Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix templated objects scale (#474) #475

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -101,6 +102,7 @@ private void Awake()
instance = this;
else
Destroy(this);
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
}

private void Start()
Expand Down
1 change: 0 additions & 1 deletion Assets/Scripts/ObjectDisplayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ private void OnImportFinishedBasic(ImportFinishedEvent _e)
bool rendAndCol = !isHidden && ((isReferent && !selectionrefs.Contains(item) && !GameManager.instance.focusMode) || selection.Contains(transform.parent?.gameObject));
bool hideLabels = item.transform.parent?.GetComponent<Room>() is Room room && !room.genNamesDisplayed;
Display(rendAndCol, rendAndCol && (item is not GenericObject || ( item is GenericObject && !hideLabels)), rendAndCol);

foreach (string tagName in item.tags)
{
if (GameManager.instance.GetTag(tagName) is Tag tag && tag.objHightlighted)
Expand Down
26 changes: 21 additions & 5 deletions Assets/Scripts/OgreeGenerators/ObjectGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,21 @@ public Rack CreateRack(SApiObject _rk, Transform _parent)
// Apply scale and move all components to have the rack's pivot at the lower left corner
Vector2 size = Utils.ParseVector2(_rk.attributes["size"]);
float height = Utils.ParseDecFrac(_rk.attributes["height"]);
if (_rk.attributes["heightUnit"] == LengthUnit.U)
height *= UnitValue.U;
else if (_rk.attributes["heightUnit"] == LengthUnit.Centimeter)
height /= 100;
switch (_rk.attributes["heightUnit"])
{
case LengthUnit.U:
height *= UnitValue.U;
break;
case LengthUnit.Centimeter:
height /= 100;
break;
case LengthUnit.Millimeter:
height /= 1000;
break;
default:
GameManager.instance.AppendLogLine($"Unknown {_rk.attributes["heightUnit"]} unit at {_rk.name} creation.", ELogTarget.both, ELogtype.error);
return null;
}
Vector3 scale = new(size.x / 100, height, size.y / 100);

newRack.transform.GetChild(0).localScale = scale;
Expand Down Expand Up @@ -362,6 +373,9 @@ private GameObject GenerateTemplatedDevice(Transform _parent, string _template)
/// <param name="_scale">The scale of the combined slots</param>
private void SlotsShape(Transform _parent, List<Slot> _slotsList, out Vector3 _pivot, out Vector3 _scale)
{
Quaternion parentRot = _parent.rotation;
_parent.rotation = Quaternion.identity;

// x axis
float left = float.PositiveInfinity;
float right = float.NegativeInfinity;
Expand All @@ -383,8 +397,10 @@ private void SlotsShape(Transform _parent, List<Slot> _slotsList, out Vector3 _p
front = Mathf.Max(bounds.max.z, front);
}

_scale = _parent.InverseTransformVector(new Vector3(right - left, top - bottom, front - rear));
_scale = new(right - left, top - bottom, front - rear);
_pivot = new(left, bottom, rear);

_parent.rotation = parentRot;
}

///<summary>
Expand Down
6 changes: 3 additions & 3 deletions Assets/Scripts/ReadFromJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public async Task CreateObjectTemplate(STemplate _data)
obj.attributes["posXYZ"] = "[0,0,0]";
obj.attributes["posXYUnit"] = LengthUnit.Tile;
obj.attributes["rotation"] = "[0,0,0]";
obj.attributes["size"] = $"[{tmp.x.ToString(CultureInfo.InvariantCulture)},{tmp.y.ToString(CultureInfo.InvariantCulture)}]";
obj.attributes["size"] = $"[{tmp.x},{tmp.y}]";
obj.attributes["sizeUnit"] = LengthUnit.Centimeter;
obj.attributes["height"] = tmp.z.ToString(CultureInfo.InvariantCulture);
obj.attributes["height"] = tmp.z.ToString();
obj.attributes["heightUnit"] = LengthUnit.Centimeter;
}
else if (obj.category == Category.Device)
{
obj.attributes["size"] = $"[{_data.sizeWDHmm[0].ToString(CultureInfo.InvariantCulture)},{_data.sizeWDHmm[1].ToString(CultureInfo.InvariantCulture)}]";
obj.attributes["size"] = $"[{_data.sizeWDHmm[0]},{_data.sizeWDHmm[1]}]";
obj.attributes["sizeUnit"] = LengthUnit.Millimeter;
obj.attributes["height"] = _data.sizeWDHmm[2].ToString(CultureInfo.InvariantCulture);
obj.attributes["heightUnit"] = LengthUnit.Millimeter;
Expand Down
6 changes: 3 additions & 3 deletions Assets/Scripts/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public static float ParseDecFrac(string _input)
if (_input.Contains("/"))
{
string[] div = _input.Split('/');
float a = float.Parse(div[0], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture);
float b = float.Parse(div[1], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture);
float a = float.Parse(div[0], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign);
float b = float.Parse(div[1], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign);
return a / b;
}
else
return float.Parse(_input, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture);
return float.Parse(_input, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign);
}

///<summary>
Expand Down