Skip to content

Commit

Permalink
export: Partly fix mesh conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
freezy committed Jun 10, 2021
1 parent d7237b0 commit 5f3d331
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// 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 UnityEngine.Rendering;
using VisualPinball.Engine.Math;
Expand Down Expand Up @@ -82,15 +83,21 @@ public static Mesh ToUnityMesh(this Engine.VPT.Mesh vpMesh, string name = null)

public static void ApplyToVpMesh(this Mesh mesh, Engine.VPT.Mesh vpMesh)
{
vpMesh.Vertices = new Vertex3DNoTex2[mesh.vertices.Length];
for (var i = 0; i < mesh.vertices.Length; i++) {
var vertices = mesh.vertices;
var normals = mesh.normals;
var uv = mesh.uv;
var triangles = mesh.triangles;
Debug.Log($"Copying {vertices.Length} vertices back to {mesh.name}");
vpMesh.Vertices = new Vertex3DNoTex2[vertices.Length];
for (var i = 0; i < vertices.Length; i++) {
vpMesh.Vertices[i] = new Vertex3DNoTex2(
mesh.vertices[i].x, mesh.vertices[i].y, mesh.vertices[i].z,
mesh.normals[i].x, mesh.normals[i].y, mesh.normals[i].z,
mesh.uv[i].x, mesh.uv[i].y
vertices[i].x, vertices[i].y, vertices[i].z,
normals[i].x, normals[i].y, normals[i].z,
uv[i].x, uv[i].y
);
}
vpMesh.Indices = mesh.triangles;
vpMesh.Indices = new int[triangles.Length];
Buffer.BlockCopy(triangles, 0, vpMesh.Indices, 0, triangles.Length);
}

public static void ApplyToUnityMesh(this Engine.VPT.Mesh vpMesh, Mesh mesh)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ public void Refresh()
public override void Save(string fileName)
{
Refresh();
//FillBinaryData();
FillBinaryData();
PrepareForExport();

base.Save(fileName);

//FreeBinaryData();
FreeBinaryData();
}

private void PrepareForExport()
Expand Down

0 comments on commit 5f3d331

Please sign in to comment.