Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Built with Unity 2021.3.0
- Put game-, mesh-, collision- animation data into separate components ([#227](https://github.com/freezy/VisualPinball.Engine/pull/227), [Documentation](https://docs.visualpinball.org/creators-guide/editor/unity-components.html)).

### Fixed
- Disappearing objects due to wrong bounding box ([#441](https://github.com/freezy/VisualPinball.Engine/pull/441)).
- Default table import ([#434](https://github.com/freezy/VisualPinball.Engine/pull/434))
- Remaining ball spinning issue should now be solved ([#397](https://github.com/freezy/VisualPinball.Engine/pull/397)).
- Physics error when the ball would stop rotate ([#393](https://github.com/freezy/VisualPinball.Engine/pull/393)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NLog;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using Logger = NLog.Logger;

namespace VisualPinball.Unity.Editor
{
Expand Down Expand Up @@ -59,6 +61,8 @@ private AssetResult LastSelectedAsset {
private readonly Dictionary<LibraryAsset, VisualElement> _elementByAsset = new();
private readonly Dictionary<VisualElement, AssetResult> _assetsByElement = new();

private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

[MenuItem("Visual Pinball/Asset Browser")]
public static void ShowWindow()
{
Expand Down Expand Up @@ -297,10 +301,10 @@ public void AddAssets(IEnumerable<string> paths, Func<AssetLibrary, LibraryCateg
var category = getCategory(assetLibrary);

if (assetLibrary.AddAsset(obj, category)) {
Debug.Log($"{Path.GetFileName(path)} added to library {assetLibrary.Name}.");
Logger.Debug($"{Path.GetFileName(path)} added to library {assetLibrary.Name}.");
numAdded++;
} else {
Debug.Log($"{Path.GetFileName(path)} updated in library {assetLibrary.Name}.");
Logger.Debug($"{Path.GetFileName(path)} updated in library {assetLibrary.Name}.");
numUpdated++;
}
updatedLibrary = assetLibrary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using NLog;
using Unity.Mathematics;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace VisualPinball.Unity.Editor
Expand All @@ -41,6 +41,8 @@ public class AssetQuery
private readonly Dictionary<string, HashSet<string>> _attributes = new();
private readonly HashSet<string> _tags = new();

private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

public AssetQuery(List<AssetLibrary> libraries)
{
_libraries = libraries;
Expand Down Expand Up @@ -135,7 +137,7 @@ private void Run()
});

} catch (Exception e) {
Debug.LogError($"Error reading assets from {lib.Name}, maybe corruption? ({e.Message})\n{e.StackTrace}");
Logger.Error($"Error reading assets from {lib.Name}, maybe corruption? ({e.Message})\n{e.StackTrace}");
// old data or whatever, just don't crash here.
return Array.Empty<AssetResult>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

using System;
using System.Linq;
using NLog;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using Logger = NLog.Logger;

namespace VisualPinball.Unity.Editor
{
Expand All @@ -28,6 +30,8 @@ public class TypeRestrictionPropertyDrawer : PropertyDrawer
private MonoBehaviour _component;
private AdvancedDropdownState _itemPickDropdownState;

private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

public override float GetPropertyHeight(SerializedProperty property, GUIContent label) => EditorGUIUtility.singleLineHeight + 2;

public override void OnGUI(Rect pos, SerializedProperty property, GUIContent label)
Expand All @@ -36,7 +40,7 @@ public override void OnGUI(Rect pos, SerializedProperty property, GUIContent lab
#region Sanity Checks

if (property.propertyType != SerializedPropertyType.ObjectReference) {
Debug.LogError("[TypeRestriction] attribute must be on an object reference.");
Logger.Error("[TypeRestriction] attribute must be on an object reference.");
return;
}

Expand All @@ -46,7 +50,7 @@ public override void OnGUI(Rect pos, SerializedProperty property, GUIContent lab

var comp = property.serializedObject.targetObject as Component;
if (comp == null) {
Debug.LogError($"Cannot find component of {property.serializedObject.targetObject.name}.");
Logger.Error($"Cannot find component of {property.serializedObject.targetObject.name}.");
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Visual Pinball Engine
// Copyright (C) 2022 freezy and VPE Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using UnityEngine;

namespace VisualPinball.Unity.Editor
{
public class BoundingBoxComponent : MonoBehaviour
{

void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
var r = GetComponent<Renderer>();
if (r != null) {
var b = r.bounds;
Gizmos.DrawSphere(b.center, 0.001f); //center sphere
Gizmos.DrawWireCube(b.center, b.size);
} else {
var rs = GetComponentsInChildren<Renderer>();
foreach (var r2 in rs) {
var b = r2.bounds;
Gizmos.DrawSphere(b.center, 0.001f); //center sphere
Gizmos.DrawWireCube(b.center, b.size);
}
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions VisualPinball.Unity/VisualPinball.Unity/VPT/MeshComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
using VisualPinball.Engine.Math;
using VisualPinball.Engine.VPT;
using VisualPinball.Engine.VPT.Table;
using Mesh = VisualPinball.Engine.VPT.Mesh;
Expand Down Expand Up @@ -98,6 +101,25 @@ public static void CreateMesh(GameObject gameObject, Mesh m, PbrMaterial materia
}
}

protected static Bounds CalculateBounds(IEnumerable<DragPointData> dragPoints, float margin = 0, float sizeZ = 0, float posZ = 0)
{
var min = new float3(float.MaxValue, float.MaxValue, float.MaxValue);
var max = new float3(float.MinValue, float.MinValue, float.MinValue);
foreach (var t in dragPoints) {
var p = (float3)t.Center.ToUnityVector3();
min = math.min(min, p);
max = math.max(max, p);
}
var middle = min + (max - min) / 2;
var size = max - min;
if (sizeZ > 0) {
middle.z = posZ + sizeZ / 2;
size.z = sizeZ;
}

return new Bounds(middle, size + margin * new float3(1f, 1f, 1f));
}

private void UpdateMesh()
{
var data = MainComponent.InstantiateData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System;
using System.Collections.Generic;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
using VisualPinball.Engine.Math;
using VisualPinball.Engine.VPT;
Expand Down Expand Up @@ -195,7 +196,7 @@ public override MetalWireGuideData CopyDataTo(MetalWireGuideData data, string[]

#region Editor Tooling

private Vector3 DragPointCenter {
internal Vector3 DragPointCenter {
get {
var sum = Vertex3D.Zero;
foreach (var t in DragPoints) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using System;
using UnityEngine;
using VisualPinball.Engine.VPT;
using VisualPinball.Engine.VPT.MetalWireGuide;
Expand All @@ -32,5 +31,13 @@ protected override Mesh GetMesh(MetalWireGuideData data)

protected override PbrMaterial GetMaterial(MetalWireGuideData data, Table table)
=> new MetalWireGuideMeshGenerator(MainComponent).GetMaterial(table, data);

public override void RebuildMeshes()
{
base.RebuildMeshes();
var mwgComponent = GetComponentInParent<MetalWireGuideComponent>();
var mr = GetComponent<MeshRenderer>();
mr.localBounds = CalculateBounds(mwgComponent.DragPoints, 25f, mwgComponent._standheight);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@ protected override Mesh GetMesh(SurfaceData data)

protected override PbrMaterial GetMaterial(SurfaceData data, Table table)
=> new SurfaceMeshGenerator(data).GetMaterial(SurfaceMeshGenerator.Side, table, data);

public override void RebuildMeshes()
{
base.RebuildMeshes();
var sc = GetComponentInParent<SurfaceComponent>();
var mr = GetComponent<MeshRenderer>();
mr.localBounds = CalculateBounds(sc.DragPoints, 0, sc.HeightTop - sc.HeightBottom, sc.HeightBottom);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@ protected override Mesh GetMesh(SurfaceData data)

protected override PbrMaterial GetMaterial(SurfaceData data, Table table)
=> new SurfaceMeshGenerator(data).GetMaterial(SurfaceMeshGenerator.Top, table, data);

public override void RebuildMeshes()
{
base.RebuildMeshes();
var sc = GetComponentInParent<SurfaceComponent>();
var mr = GetComponent<MeshRenderer>();
mr.localBounds = CalculateBounds(sc.DragPoints, 0, 2f, sc.HeightTop - 1f);
}
}
}