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
3 changes: 0 additions & 3 deletions VisualPinball.Engine/Math/DragPointData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public DragPointData Lerp(DragPointData dp, float pos)
IsSlingshot = dp.IsSlingshot,
HasAutoTexture = dp.HasAutoTexture,
TextureCoord = dp.TextureCoord,
IsLocked = dp.IsLocked,
EditorLayer = dp.EditorLayer,
EditorLayerName = dp.EditorLayerName,
EditorLayerVisibility = EditorLayerVisibility
Expand All @@ -109,7 +108,6 @@ public DragPointData Clone()
IsSlingshot = IsSlingshot,
HasAutoTexture = HasAutoTexture,
TextureCoord = TextureCoord,
IsLocked = IsLocked,
EditorLayer = EditorLayer,
EditorLayerName = EditorLayerName,
EditorLayerVisibility = EditorLayerVisibility,
Expand Down Expand Up @@ -147,7 +145,6 @@ public DragPointData(DragPointData rf) : base(null)
IsSlingshot = rf.IsSlingshot;
HasAutoTexture = rf.HasAutoTexture;
TextureCoord = rf.TextureCoord;
IsLocked = rf.IsLocked;
EditorLayer = rf.EditorLayer;
CalcHeight = rf.CalcHeight;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ All models must be [UV-mapped](https://en.wikipedia.org/wiki/UV_mapping).

If your model contains art that varies from instance to instance, use a [decal mesh](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@17.2/manual/understand-decals.html). Decals should be used where you would find literal decals or imprints in the real world. Examples include spinners, aprons, targets, and bumpers.

On the right side you see two drop target meshes which their corresponding decal meshes in orange.
On the right side you see two drop target meshes with their corresponding decal meshes in orange.

The decal geometry should be in a separate object parented to the main object. The UVs of the decal mesh should be laid out in a way that allows its textures to be created with non-specialized image editors.

Expand Down Expand Up @@ -211,7 +211,7 @@ We're aiming for a resolution of about 6 pixels per millimeter (approximately 15
> [!note]
> You can determine the resolution by looking at your UV map and the size of the asset. Let's take the gate from the previous section as an example.
>
> 1. Take a large section of your mesh, and measure it. The larger, the more precise it will be. Here I'm measuring the top surface, from where the bevel starts:<br>
> 1. Take a large section of your mesh, and measure it. The larger, the more precise it will be. Here we're measuring the top surface, from where the bevel starts:<br>
> <img src="assetlib-dpi1.png" style="max-height:80px" />
> 2. Next, identify that section on your UV map, and note where in UV space they are:<br>
> <img src="assetlib-dpi2.png" style="max-height:160px" /><br/>
Expand All @@ -220,9 +220,9 @@ We're aiming for a resolution of about 6 pixels per millimeter (approximately 15
> - Width in UV space: 0.955 - 0.36 = 0.595
> - Width in real world space: 29.2mm
> 4. At 6px / mm, that makes 6px × 29.2mm = 175.2px for the 0.595 UVs
> 5. To get the resolution of the whole UV map: 175.2px / 0.592 = 296px
> 5. To get the resolution of the whole UV map: 175.2px / 0.592 = **296px**
>
> So, a texture map at 296×296 would correspond to 6px / mm. Since we're at power of twos, we can go for either 512×512 or 256×256.
> So, a texture map at 296×296 would correspond to 6px / mm. Since we're at power of twos, we could go for either 512×512 or 256×256.


### File Format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public partial class AssetBrowser : EditorWindow, IDragHandler
[NonSerialized]
public AssetQuery Query;

public const string ThumbPath = "Packages/org.visualpinball.unity.assetlibrary/Editor/Thumbnails~";
public const int ThumbSize = 256;

private AssetResult LastSelectedResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private VisualElement NewItem(AssetResult result)
private void LoadThumb(VisualElement el, Asset asset)
{
if (!_thumbCache.ContainsKey(asset.GUID)) {
var thumbPath = $"{ThumbPath}/{asset.GUID}.png";
var thumbPath = $"{asset.Library.ThumbnailRoot}/{asset.GUID}.png";
if (File.Exists(thumbPath)) {
var tex = new Texture2D(ThumbSize, ThumbSize);
tex.LoadImage(File.ReadAllBytes(thumbPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public class AssetLibrary : ScriptableObject, ISerializationCallbackReceiver

public string LibraryRoot;

public string ThumbnailRoot;

public string DatabaseRoot;

public bool IsLocked;

public Preset DefaultThumbCameraPreset;
Expand Down Expand Up @@ -210,7 +214,7 @@ public void OnBeforeSerialize()
if (string.IsNullOrEmpty(LibraryRoot)) {
var path = AssetDatabase.GetAssetPath(this);
if (!string.IsNullOrEmpty(path)) {
LibraryRoot = Path.GetDirectoryName(path);
LibraryRoot = Path.GetDirectoryName(path)?.Replace("\\", "/");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ private static (int, int, int, int, int, int) CountVertices(GameObject go)
if (mesh != null) {
meshes++;
vertices += mesh.vertexCount;
triangles += mesh.triangles.Length;
triangles += mesh.triangles.Length / 3;
uvs += mesh.uv.Length;
subMeshes += mesh.subMeshCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AssetMaterialCombination
public string Name => string.Join(", ", _variations.Select(v => $"{v.Item2.Name} {v.Item1.Name}"));

public string ThumbId => GenerateThumbID();
public string ThumbPath => $"{AssetBrowser.ThumbPath}/{ThumbId}.png";
public string ThumbPath => $"{Asset.Library.ThumbnailRoot}/{ThumbId}.png";

public bool IsOriginal => _variations.Length == 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class AssetMaterialCombinationElement: VisualElement

public readonly AssetMaterialCombination Combination;

public AssetMaterialCombinationElement(AssetMaterialCombination combination)
public AssetMaterialCombinationElement(AssetMaterialCombination combination, Asset asset)
{
Combination = combination;

Expand All @@ -49,7 +49,7 @@ public AssetMaterialCombinationElement(AssetMaterialCombination combination)

ui.Q<Label>("label").text = Name;

var thumbPath = $"{AssetBrowser.ThumbPath}/{Combination.ThumbId}.png";
var thumbPath = $"{asset.Library.ThumbnailRoot}/{Combination.ThumbId}.png";
if (File.Exists(thumbPath)) {
var tex = new Texture2D(AssetBrowser.ThumbSize, AssetBrowser.ThumbSize);
tex.LoadImage(File.ReadAllBytes(thumbPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void SetValue(Asset asset)
Clear();

foreach (var combination in materialCombinations) {
var combinationEl = new AssetMaterialCombinationElement(combination);
var combinationEl = new AssetMaterialCombinationElement(combination, asset);
combinationEl.OnClicked += OnVariationClicked;
_container.Add(combinationEl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ namespace VisualPinball.Unity.Editor
[Serializable]
public class LibraryDatabase
{
private const string DatabaseFolder = "_database";

[SerializeField] private Assets Assets = new();
[SerializeField] private Categories Categories = new();

Expand Down Expand Up @@ -151,7 +149,7 @@ public void RemoveAsset(Asset asset)

public bool HasAsset(string guid) => Assets.Contains(guid);
public Asset GetAsset(string guid) => Assets[guid];
private string AssetMetaPath(Asset asset, AssetLibrary lib) => $"{lib.LibraryRoot}/{DatabaseFolder}/{asset.GUID}.asset";
private string AssetMetaPath(Asset asset, AssetLibrary lib) => $"{lib.DatabaseRoot}/{asset.GUID}.asset";

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ public void AddDragPointOnTraveller()
return;
}

var dragPoint = new DragPointData(DragPointInspector.DragPoints[CurveTravellerControlPointIdx]) {
IsLocked = false
};

var dragPoint = new DragPointData(DragPointInspector.DragPoints[CurveTravellerControlPointIdx]);
var newIdx = CurveTravellerControlPointIdx + 1;
var dragPointPosition = CurveTravellerPosition.TranslateToVpx(Transform);
dragPointPosition.z = 0;
Expand Down Expand Up @@ -181,13 +178,6 @@ public void RemoveDragPoint(int controlId)
if (idx < 0) {
return;
}
var removalOk = !ControlPoints[idx].DragPoint.IsLocked;
if (!removalOk) {
removalOk = EditorUtility.DisplayDialog("Locked DragPoint Removal", "This drag point is locked!\nAre you really sure you want to remove it?", "Yes", "No");
}
if (!removalOk) {
return;
}
var dragPoints = DragPointInspector.DragPoints.ToList();
dragPoints.RemoveAt(idx);
DragPointInspector.DragPoints = dragPoints.ToArray();
Expand Down Expand Up @@ -256,17 +246,17 @@ public void CenterPivot()
/// </summary>
/// <param name="itemLock">New lock status</param>
/// <returns>True if at least one lock status changed, false otherwise.</returns>
public bool UpdateDragPointsLock(bool itemLock)
{
var lockChanged = false;
foreach (var controlPoint in ControlPoints) {
if (controlPoint.DragPoint.IsLocked != itemLock) {
controlPoint.DragPoint.IsLocked = itemLock;
lockChanged = true;
}
}
return lockChanged;
}
// public bool UpdateDragPointsLock(bool itemLock)
// {
// var lockChanged = false;
// foreach (var controlPoint in ControlPoints) {
// if (controlPoint.DragPoint.IsLocked != itemLock) {
// controlPoint.DragPoint.IsLocked = itemLock;
// lockChanged = true;
// }
// }
// return lockChanged;
// }

/// <summary>
/// Re-creates the control points of the scene view and references their
Expand Down Expand Up @@ -377,7 +367,7 @@ private void OnSceneLayout()
//Setup Screen positions & controlID for control points (in case of modification of drag points coordinates outside)
foreach (var controlPoint in ControlPoints) {
_center += controlPoint.AbsolutePosition;
if (controlPoint.IsSelected && !controlPoint.DragPoint.IsLocked) {
if (controlPoint.IsSelected) {
SelectedControlPoints.Add(controlPoint);
}

Expand Down Expand Up @@ -416,7 +406,7 @@ private void OnMouseDown()
{
if (Event.current.button == 0) {
var nearestControlPoint = ControlPoints.Find(cp => cp.ControlId == HandleUtility.nearestControl);
if (nearestControlPoint != null && !nearestControlPoint.DragPoint.IsLocked) {
if (nearestControlPoint != null) {
if (!Event.current.control) {
ClearAllSelection();
nearestControlPoint.IsSelected = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,7 @@ private void DisplayControlPoints()
};
for (var i = 0; i < _handler.ControlPoints.Count; ++i) {
var controlPoint = _handler.ControlPoints[i];
Handles.color = controlPoint.DragPoint.IsLocked
? Color.red
: controlPoint.IsSelected
? Color.green
: Color.gray;
Handles.color = controlPoint.IsSelected ? Color.green : Color.gray;

var pos = controlPoint.EditorPositionWorld;
var handleSize = controlPoint.HandleSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected override void OnEnable()

protected override void OnPreInspectorGUI()
{
PropertyField(IsKinematicProperty, "Movable");
PropertyField(IsKinematicProperty, "Movable", updateColliders: true);
base.OnPreInspectorGUI();
}

Expand All @@ -83,7 +83,11 @@ public override void OnInspectorGUI()
refresh = showAabbs != ColliderComponent.ShowAabbs;
ColliderComponent.ShowAabbs = showAabbs;

EditorGUI.BeginChangeCheck();
var showColliders = EditorGUILayout.Toggle("Show Colliders", ColliderComponent.ShowColliderMesh);
if (EditorGUI.EndChangeCheck()) {
ColliderComponent.CollidersDirty = true;
}
refresh = refresh || showColliders != ColliderComponent.ShowColliderMesh;
ColliderComponent.ShowColliderMesh = showColliders;

Expand Down
Loading
Loading