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 @@ -7,6 +7,7 @@
Built with Unity 2020.3.

### Added
- Create insert meshes ([#320](https://github.com/freezy/VisualPinball.Engine/pull/320))
- Full support for custom playfield meshes.
- Remove Hybrid Renderer ([#316](https://github.com/freezy/VisualPinball.Engine/pull/316)).
- Create and use Unity assets when importing ([#320](https://github.com/freezy/VisualPinball.Engine/pull/302)).
Expand Down
15 changes: 15 additions & 0 deletions VisualPinball.Engine/VPT/Light/LightData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.IO;
using VisualPinball.Engine.IO;
using VisualPinball.Engine.Math;
using VisualPinball.Engine.VPT.Surface;
using VisualPinball.Engine.VPT.Table;

namespace VisualPinball.Engine.VPT.Light
Expand Down Expand Up @@ -157,4 +158,18 @@ public override void Write(BinaryWriter writer, HashWriter hashWriter)

#endregion
}

public class LightInsertData : ISurfaceData
{
public float HeightBottom { get; }
public float HeightTop { get; }
public DragPointData[] DragPoints { get; }

public LightInsertData(DragPointData[] dragPoints, float height)
{
HeightBottom = -height;
HeightTop = 0f;
DragPoints = dragPoints;
}
}
}
29 changes: 29 additions & 0 deletions VisualPinball.Engine/VPT/Surface/ISurfaceData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Visual Pinball Engine
// Copyright (C) 2021 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 VisualPinball.Engine.Math;

namespace VisualPinball.Engine.VPT.Surface
{
public interface ISurfaceData
{
float HeightBottom { get; }

float HeightTop { get; }

DragPointData[] DragPoints { get; }
}
}

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

6 changes: 1 addition & 5 deletions VisualPinball.Engine/VPT/Surface/Surface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,10 @@ public static Surface GetDefault(Table.Table table)

Matrix3D IRenderable.TransformationMatrix(Table.Table table, Origin origin) => Matrix3D.Identity;

public RenderObject GetRenderObject(Table.Table table, string id = null, Origin origin = Origin.Global, bool asRightHanded = true)
{
return _meshGenerator.GetRenderObject(table, id, table.TableHeight, asRightHanded);
}

public RenderObjectGroup GetRenderObjects(Table.Table table, Origin origin = Origin.Global, bool asRightHanded = true)
{
return _meshGenerator.GetRenderObjects(table, asRightHanded);
return _meshGenerator.GetRenderObjects(table, Data, asRightHanded);
}

#endregion
Expand Down
8 changes: 4 additions & 4 deletions VisualPinball.Engine/VPT/Surface/SurfaceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
namespace VisualPinball.Engine.VPT.Surface
{
[Serializable]
public class SurfaceData : ItemData
public class SurfaceData : ItemData, ISurfaceData
{
public override string GetName() => Name;
public override void SetName(string name) { Name = name; }
Expand Down Expand Up @@ -76,10 +76,10 @@ public class SurfaceData : ItemData
public string SlingShotMaterial = string.Empty;

[BiffFloat("HTBT", Pos = 14)]
public float HeightBottom = 0f;
public float HeightBottom { get; set; }

[BiffFloat("HTTP", Pos = 15)]
public float HeightTop = 50f;
public float HeightTop { get; set; } = 50f;

[BiffBool("INNR", SkipWrite = true)]
public bool Inner = true;
Expand Down Expand Up @@ -127,7 +127,7 @@ public class SurfaceData : ItemData
public bool IsReflectionEnabled = true;

[BiffDragPoint("DPNT", TagAll = true, Pos = 2000)]
public DragPointData[] DragPoints;
public DragPointData[] DragPoints { get; set; }

[BiffBool("TMON", Pos = 6)]
public bool IsTimerEnabled;
Expand Down
40 changes: 19 additions & 21 deletions VisualPinball.Engine/VPT/Surface/SurfaceMeshGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,30 @@ public class SurfaceMeshGenerator
public const string Side = "Side";
public const string Top = "Top";

private readonly SurfaceData _data;
private readonly ISurfaceData _data;

public SurfaceMeshGenerator(SurfaceData data)
public SurfaceMeshGenerator(ISurfaceData data)
{
_data = data;
}

public RenderObject GetRenderObject(Table.Table table, string id, float playfieldHeight, bool asRightHanded, Mesh preGeneratedMesh = null)
public RenderObject GetRenderObject(Table.Table table, SurfaceData data, string id, float playfieldHeight, bool asRightHanded, Mesh preGeneratedMesh = null)
{
var mesh = preGeneratedMesh ?? GenerateMesh(table.Width, table.Height, playfieldHeight, id);
switch (id) {
case Side:
return new RenderObject(
id,
asRightHanded ? mesh.Transform(Matrix3D.RightHanded) : mesh,
new PbrMaterial(table.GetMaterial(_data.SideMaterial), table.GetTexture(_data.SideImage)),
_data.IsSideVisible
new PbrMaterial(table.GetMaterial(data.SideMaterial), table.GetTexture(data.SideImage)),
data.IsSideVisible
);
case Top:
return new RenderObject(
id,
asRightHanded ? mesh.Transform(Matrix3D.RightHanded) : mesh,
new PbrMaterial(table.GetMaterial(_data.TopMaterial), table.GetTexture(_data.Image)),
_data.IsTopBottomVisible
new PbrMaterial(table.GetMaterial(data.TopMaterial), table.GetTexture(data.Image)),
data.IsTopBottomVisible
);
default:
throw new ArgumentException($"Unknown mesh ID \"{id}\".");
Expand All @@ -62,19 +62,19 @@ public Mesh GetMesh(float tableWidth, float tableHeight, float playfieldHeight,
return GenerateMesh(tableWidth, tableHeight, playfieldHeight, id);
}

public RenderObjectGroup GetRenderObjects(Table.Table table, bool asRightHanded = true)
public RenderObjectGroup GetRenderObjects(Table.Table table, SurfaceData data, bool asRightHanded = true)
{
var renderObjects = new List<RenderObject>();
var sideMesh = GenerateSideMesh(table.TableHeight);
var topMesh = GenerateTopMesh(table.Width, table.Height, table.TableHeight);
if (sideMesh != null) {
renderObjects.Add(GetRenderObject(table, Side, table.TableHeight, asRightHanded, sideMesh));
renderObjects.Add(GetRenderObject(table, data, Side, table.TableHeight, asRightHanded, sideMesh));
}
if (topMesh != null) {
renderObjects.Add(GetRenderObject(table, Top, table.TableHeight, asRightHanded, topMesh));
renderObjects.Add(GetRenderObject(table, data, Top, table.TableHeight, asRightHanded, topMesh));
}

return new RenderObjectGroup(_data.Name, "Surfaces", Matrix3D.Identity, renderObjects.ToArray());
return new RenderObjectGroup(data.Name, "Surfaces", Matrix3D.Identity, renderObjects.ToArray());
}

private Mesh GenerateMesh(float tableWidth, float tableHeight, float zHeight, string id)
Expand Down Expand Up @@ -250,19 +250,17 @@ private Mesh GenerateSideMesh(float playfieldHeight) {
sideMesh.Vertices[offset + 3].Y = pv2.Y;
sideMesh.Vertices[offset + 3].Z = bottom;

if (_data.SideImage != null) {
sideMesh.Vertices[offset].Tu = rgTexCoord[i];
sideMesh.Vertices[offset].Tv = 1.0f;
sideMesh.Vertices[offset].Tu = rgTexCoord[i];
sideMesh.Vertices[offset].Tv = 1.0f;

sideMesh.Vertices[offset + 1].Tu = rgTexCoord[i];
sideMesh.Vertices[offset + 1].Tv = 0f;
sideMesh.Vertices[offset + 1].Tu = rgTexCoord[i];
sideMesh.Vertices[offset + 1].Tv = 0f;

sideMesh.Vertices[offset + 2].Tu = rgTexCoord[c];
sideMesh.Vertices[offset + 2].Tv = 0f;
sideMesh.Vertices[offset + 2].Tu = rgTexCoord[c];
sideMesh.Vertices[offset + 2].Tv = 0f;

sideMesh.Vertices[offset + 3].Tu = rgTexCoord[c];
sideMesh.Vertices[offset + 3].Tv = 1.0f;
}
sideMesh.Vertices[offset + 3].Tu = rgTexCoord[c];
sideMesh.Vertices[offset + 3].Tv = 1.0f;

sideMesh.Vertices[offset].Nx = vNormal[0].X;
sideMesh.Vertices[offset].Ny = -vNormal[0].Y;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading