revert to VB and update to new project file format

This commit is contained in:
schedpas
2020-09-25 09:04:15 +02:00
parent 04869b2814
commit 9feaf658be
313 changed files with 9895 additions and 17566 deletions

View File

@@ -1,11 +0,0 @@
using System.Collections.Generic;
namespace Pilz.S3DFileParser
{
public class Face
{
public List<Point> Points { get; private set; } = new List<Point>();
public Material Material { get; set; } = null;
public object Tag { get; set; } = null;
}
}

View File

@@ -0,0 +1,5 @@
Public Class Face
Public ReadOnly Property Points As New List(Of Point)
Public Property Material As Material = Nothing
Public Property Tag As Object = Nothing
End Class

View File

@@ -1,10 +0,0 @@
using System.Threading.Tasks;
namespace Pilz.S3DFileParser
{
public interface IToObject3D
{
Object3D ToObject3D();
Task<Object3D> ToObject3DAsync();
}
}

View File

@@ -0,0 +1,6 @@
Public Interface IToObject3D
Function ToObject3D() As Object3D
Function ToObject3DAsync() As Task(Of Object3D)
End Interface

View File

@@ -1,35 +0,0 @@
using System;
using System.Drawing;
using global::System.Numerics;
namespace Pilz.S3DFileParser
{
public class Material : IComparable
{
public Image Image { get; set; } = null;
public Color? Color { get; set; } = default;
public float? Opacity { get; set; } = default;
public Vector2 Wrap { get; set; } = new Vector2(10497f, 10497f);
public Vector2 Scale { get; set; } = new Vector2(1.0f, 1.0f);
public object Tag { get; set; } = null;
public int CompareTo(object obj)
{
if (obj is object)
{
if (ReferenceEquals(obj, this))
{
return 0;
}
else
{
return -1;
}
}
else
{
return 1;
}
}
}
}

View File

@@ -0,0 +1,25 @@
Imports System.Numerics
Public Class Material
Implements IComparable
Public Property Image As Image = Nothing
Public Property Color As Color? = Nothing
Public Property Opacity As Single? = Nothing
Public Property Wrap As New Vector2(10497, 10497)
Public Property Scale As New Vector2(1.0F, 1.0F)
Public Property Tag As Object = Nothing
Public Function CompareTo(obj As Object) As Integer Implements IComparable.CompareTo
If obj IsNot Nothing Then
If obj Is Me Then
Return 0
Else
Return -1
End If
Else
Return 1
End If
End Function
End Class

View File

@@ -1,50 +0,0 @@
using System.Collections.Generic;
using global::System.Numerics;
namespace Pilz.S3DFileParser
{
public class Mesh
{
public List<Vertex> Vertices { get; private set; } = new List<Vertex>();
public List<Normal> Normals { get; private set; } = new List<Normal>();
public List<UV> UVs { get; private set; } = new List<UV>();
public List<VertexColor> VertexColors { get; private set; } = new List<VertexColor>();
public List<Face> Faces { get; private set; } = new List<Face>();
public void CenterModel()
{
CenterModel(new[] { this });
}
public static void CenterModel(IEnumerable<Mesh> meshes)
{
int avgX = 0;
int avgY = 0;
int avgZ = 0;
long vertsCount = 0L;
foreach (Mesh m in meshes)
{
foreach (Vertex v in m.Vertices)
{
avgX = (int)(avgX + v.X);
avgY = (int)(avgY + v.Y);
avgZ = (int)(avgZ + v.Z);
}
vertsCount += m.Vertices.Count;
}
var avg = new Vector3(avgX, avgY, avgZ);
avg /= new Vector3(vertsCount);
foreach (Mesh m in meshes)
{
foreach (Vertex v in m.Vertices)
{
v.X -= avg.X;
v.Y -= avg.Y;
v.Z -= avg.Z;
}
}
}
}
}

View File

@@ -0,0 +1,42 @@
Imports System.Numerics
Public Class Mesh
Public ReadOnly Property Vertices As New List(Of Vertex)
Public ReadOnly Property Normals As New List(Of Normal)
Public ReadOnly Property UVs As New List(Of UV)
Public ReadOnly Property VertexColors As New List(Of VertexColor)
Public ReadOnly Property Faces As New List(Of Face)
Public Sub CenterModel()
CenterModel({Me})
End Sub
Public Shared Sub CenterModel(meshes As IEnumerable(Of Mesh))
Dim avgX As Integer = 0
Dim avgY As Integer = 0
Dim avgZ As Integer = 0
Dim vertsCount As Long = 0
For Each m As Mesh In meshes
For Each v As Vertex In m.Vertices
avgX += v.X
avgY += v.Y
avgZ += v.Z
Next
vertsCount += m.Vertices.Count
Next
Dim avg As New Vector3(avgX, avgY, avgZ)
avg /= New Vector3(vertsCount)
For Each m As Mesh In meshes
For Each v As Vertex In m.Vertices
v.X -= avg.X
v.Y -= avg.Y
v.Z -= avg.Z
Next
Next
End Sub
End Class

View File

@@ -1,16 +0,0 @@
using global::System.Numerics;
namespace Pilz.S3DFileParser
{
public class ModelBoundaries
{
public readonly Vector3 Upper;
public readonly Vector3 Lower;
public ModelBoundaries(Vector3 upper, Vector3 lower)
{
Upper = upper;
Lower = lower;
}
}
}

View File

@@ -0,0 +1,11 @@
Imports System.Numerics
Public Class ModelBoundaries
Public ReadOnly Upper As Vector3
Public ReadOnly Lower As Vector3
Public Sub New(upper As Vector3, lower As Vector3)
Me.Upper = upper
Me.Lower = lower
End Sub
End Class

View File

@@ -1,10 +0,0 @@
namespace Pilz.S3DFileParser
{
public class Normal
{
public float X { get; set; } = 0f;
public float Y { get; set; } = 0f;
public float Z { get; set; } = 0f;
}
}

View File

@@ -0,0 +1,5 @@
Public Class Normal
Public Property X As Single = 0
Public Property Y As Single = 0
Public Property Z As Single = 0
End Class

View File

@@ -1,217 +0,0 @@
using System.Collections.Generic;
using global::System.Numerics;
namespace Pilz.S3DFileParser
{
public class Object3D
{
public List<Mesh> Meshes { get; private set; } = new List<Mesh>();
public Dictionary<string, Material> Materials { get; private set; } = new Dictionary<string, Material>();
public Shading Shading { get; set; } = new Shading();
public void ScaleModel(float factor)
{
foreach (Mesh m in Meshes)
{
foreach (Vertex v in m.Vertices)
{
v.X *= factor;
v.Y *= factor;
v.Z *= factor;
}
}
}
public void OffsetModel(Vector3 off)
{
foreach (Mesh m in Meshes)
{
foreach (Vertex v in m.Vertices)
{
v.X += off.X;
v.Y += off.Y;
v.Z += off.Z;
}
}
}
public ModelBoundaries GetBoundaries()
{
float? maxX = default;
float? maxY = default;
float? maxZ = default;
float? minX = default;
float? minY = default;
float? minZ = default;
foreach (Mesh m in Meshes)
{
foreach (Vertex vert in m.Vertices)
{
if (maxX is null || vert.X > maxX)
maxX = (float?)vert.X;
if (maxY is null || vert.Y > maxY)
maxY = (float?)vert.Y;
if (maxZ is null || vert.Z > maxZ)
maxZ = (float?)vert.Z;
if (minX is null || vert.X < minX)
minX = (float?)vert.X;
if (minY is null || vert.Y < minY)
minY = (float?)vert.Y;
if (minZ is null || vert.Z < minZ)
minZ = (float?)vert.Z;
}
}
if (maxX is null)
maxX = 0;
if (maxY is null)
maxY = 0;
if (maxZ is null)
maxZ = 0;
if (minX is null)
minX = 0;
if (minY is null)
minY = 0;
if (minZ is null)
minZ = 0;
return new ModelBoundaries(new Vector3((float)maxX, (float)maxY, (float)maxZ), new Vector3((float)minX, (float)minY, (float)minZ));
}
public void SetNullVertices()
{
var newVert = new Vertex() { X = 0d, Y = 0d, Z = 0d };
int nullCounter;
foreach (Mesh m in Meshes)
{
nullCounter = 0;
foreach (Face f in m.Faces)
{
foreach (Point p in f.Points)
{
if (p.Vertex is null)
{
p.Vertex = newVert;
nullCounter += 1;
}
}
}
if (nullCounter > 0)
{
m.Vertices.Add(newVert);
}
}
}
public void SetNullUVs()
{
var newUV = new UV() { U = 0f, V = 0f };
int nullCounter;
foreach (Mesh m in Meshes)
{
nullCounter = 0;
foreach (Face f in m.Faces)
{
foreach (Point p in f.Points)
{
if (p.UV is null)
{
p.UV = newUV;
nullCounter += 1;
}
}
}
if (nullCounter > 0)
{
m.UVs.Add(newUV);
}
}
}
public void SetNullNormals()
{
var newNormal = new Normal() { X = 0f, Y = 0f, Z = 1f };
int nullCounter;
foreach (Mesh m in Meshes)
{
nullCounter = 0;
foreach (Face f in m.Faces)
{
foreach (Point p in f.Points)
{
if (p.Normal is null)
{
p.Normal = newNormal;
nullCounter += 1;
}
}
}
if (nullCounter > 0)
{
m.Normals.Add(newNormal);
}
}
}
public void RemoveUnusedMaterials()
{
// Dim usedMats As New List(Of Material)
// Dim unusedMats As New List(Of String)
// For Each f As Face In Faces
// If Not usedMats.Contains(f.Material) Then
// usedMats.Add(f.Material)
// End If
// Next
// For Each kvp As KeyValuePair(Of String, Material) In Materials
// If Not usedMats.Contains(kvp.Value) Then
// unusedMats.Add(kvp.Key)
// End If
// Next
// For Each k As String In unusedMats
// Materials.Remove(k)
// Next
}
public Object3D ToOneMesh()
{
var newObject3D = new Object3D();
var newMesh = new Mesh();
foreach (KeyValuePair<string, Material> mat in Materials)
newObject3D.Materials.Add(mat.Key, mat.Value);
foreach (Mesh m in Meshes)
{
foreach (Vertex v in m.Vertices)
newMesh.Vertices.Add(v);
foreach (VertexColor vc in m.VertexColors)
newMesh.VertexColors.Add(vc);
foreach (Normal n in m.Normals)
newMesh.Normals.Add(n);
foreach (UV uv in m.UVs)
newMesh.UVs.Add(uv);
foreach (Face f in m.Faces)
newMesh.Faces.Add(f);
}
newObject3D.Meshes.Add(newMesh);
return newObject3D;
}
public void CenterModel()
{
Mesh.CenterModel(Meshes);
}
public static void CenterModel(IEnumerable<Object3D> objs)
{
var meshes = new List<Mesh>();
foreach (Object3D obj in objs)
meshes.AddRange(obj.Meshes);
Mesh.CenterModel(meshes);
}
}
}

View File

@@ -0,0 +1,195 @@
Imports System.IO
Imports System.Numerics
Public Class Object3D
Public ReadOnly Property Meshes As New List(Of Mesh)
Public ReadOnly Property Materials As New Dictionary(Of String, Material)
Public Property Shading As New Shading
Public Sub ScaleModel(factor As Single)
For Each m As Mesh In Meshes
For Each v As Vertex In m.Vertices
v.X *= factor
v.Y *= factor
v.Z *= factor
Next
Next
End Sub
Public Sub OffsetModel(off As Vector3)
For Each m As Mesh In Meshes
For Each v As Vertex In m.Vertices
v.X += off.X
v.Y += off.Y
v.Z += off.Z
Next
Next
End Sub
Public Function GetBoundaries() As ModelBoundaries
Dim maxX As Single? = Nothing
Dim maxY As Single? = Nothing
Dim maxZ As Single? = Nothing
Dim minX As Single? = Nothing
Dim minY As Single? = Nothing
Dim minZ As Single? = Nothing
For Each m As Mesh In Meshes
For Each vert As Vertex In m.Vertices
If maxX Is Nothing OrElse vert.X > maxX Then maxX = vert.X
If maxY Is Nothing OrElse vert.Y > maxY Then maxY = vert.Y
If maxZ Is Nothing OrElse vert.Z > maxZ Then maxZ = vert.Z
If minX Is Nothing OrElse vert.X < minX Then minX = vert.X
If minY Is Nothing OrElse vert.Y < minY Then minY = vert.Y
If minZ Is Nothing OrElse vert.Z < minZ Then minZ = vert.Z
Next
Next
If maxX Is Nothing Then maxX = 0
If maxY Is Nothing Then maxY = 0
If maxZ Is Nothing Then maxZ = 0
If minX Is Nothing Then minX = 0
If minY Is Nothing Then minY = 0
If minZ Is Nothing Then minZ = 0
Return New ModelBoundaries(New Vector3(maxX, maxY, maxZ),
New Vector3(minX, minY, minZ))
End Function
Public Sub SetNullVertices()
Dim newVert As New Vertex With {.X = 0, .Y = 0, .Z = 0}
Dim nullCounter As Integer
For Each m As Mesh In Meshes
nullCounter = 0
For Each f As Face In m.Faces
For Each p As Point In f.Points
If p.Vertex Is Nothing Then
p.Vertex = newVert
nullCounter += 1
End If
Next
Next
If nullCounter > 0 Then
m.Vertices.Add(newVert)
End If
Next
End Sub
Public Sub SetNullUVs()
Dim newUV As New UV With {.U = 0, .V = 0}
Dim nullCounter As Integer
For Each m As Mesh In Meshes
nullCounter = 0
For Each f As Face In m.Faces
For Each p As Point In f.Points
If p.UV Is Nothing Then
p.UV = newUV
nullCounter += 1
End If
Next
Next
If nullCounter > 0 Then
m.UVs.Add(newUV)
End If
Next
End Sub
Public Sub SetNullNormals()
Dim newNormal As New Normal With {.X = 0, .Y = 0, .Z = 1}
Dim nullCounter As Integer
For Each m As Mesh In Meshes
nullCounter = 0
For Each f As Face In m.Faces
For Each p As Point In f.Points
If p.Normal Is Nothing Then
p.Normal = newNormal
nullCounter += 1
End If
Next
Next
If nullCounter > 0 Then
m.Normals.Add(newNormal)
End If
Next
End Sub
Public Sub RemoveUnusedMaterials()
'Dim usedMats As New List(Of Material)
'Dim unusedMats As New List(Of String)
'For Each f As Face In Faces
' If Not usedMats.Contains(f.Material) Then
' usedMats.Add(f.Material)
' End If
'Next
'For Each kvp As KeyValuePair(Of String, Material) In Materials
' If Not usedMats.Contains(kvp.Value) Then
' unusedMats.Add(kvp.Key)
' End If
'Next
'For Each k As String In unusedMats
' Materials.Remove(k)
'Next
End Sub
Public Function ToOneMesh() As Object3D
Dim newObject3D As New Object3D
Dim newMesh As New Mesh
For Each mat As KeyValuePair(Of String, Material) In Materials
newObject3D.Materials.Add(mat.Key, mat.Value)
Next
For Each m As Mesh In Meshes
For Each v As Vertex In m.Vertices
newMesh.Vertices.Add(v)
Next
For Each vc As VertexColor In m.VertexColors
newMesh.VertexColors.Add(vc)
Next
For Each n As Normal In m.Normals
newMesh.Normals.Add(n)
Next
For Each uv As UV In m.UVs
newMesh.UVs.Add(uv)
Next
For Each f As Face In m.Faces
newMesh.Faces.Add(f)
Next
Next
newObject3D.Meshes.Add(newMesh)
Return newObject3D
End Function
Public Sub CenterModel()
Mesh.CenterModel(Meshes)
End Sub
Public Shared Sub CenterModel(objs As IEnumerable(Of Object3D))
Dim meshes As New List(Of Mesh)
For Each obj As Object3D In objs
meshes.AddRange(obj.Meshes)
Next
Mesh.CenterModel(meshes)
End Sub
End Class

View File

@@ -1,11 +0,0 @@
namespace Pilz.S3DFileParser
{
public class Point
{
public Vertex Vertex { get; set; } = null;
public UV UV { get; set; } = null;
public VertexColor VertexColor { get; set; } = null;
public Normal Normal { get; set; } = null;
}
}

View File

@@ -0,0 +1,6 @@
Public Class Point
Public Property Vertex As Vertex = Nothing
Public Property UV As UV = Nothing
Public Property VertexColor As VertexColor = Nothing
Public Property Normal As Normal = Nothing
End Class

View File

@@ -1,12 +0,0 @@
using System;
using System.Drawing;
namespace Pilz.S3DFileParser
{
public class Shading
{
public Color AmbientColor { get; set; } = Color.FromArgb(Convert.ToInt32(0xFFFFFFFF));
public Color DiffuseColor { get; set; } = Color.FromArgb(Convert.ToInt32(0xFF7F7F7F));
public Vertex DiffusePosition { get; set; } = null;
}
}

View File

@@ -0,0 +1,5 @@
Public Class Shading
Public Property AmbientColor As Color = Color.FromArgb(&HFFFFFFFF)
Public Property DiffuseColor As Color = Color.FromArgb(&HFF7F7F7F)
Public Property DiffusePosition As Vertex = Nothing
End Class

View File

@@ -1,9 +0,0 @@
namespace Pilz.S3DFileParser
{
public class UV
{
public float U { get; set; } = 0f;
public float V { get; set; } = 0f;
}
}

View File

@@ -0,0 +1,4 @@
Public Class UV
Public Property U As Single = 0
Public Property V As Single = 0
End Class

View File

@@ -1,9 +0,0 @@
namespace Pilz.S3DFileParser
{
public enum UpAxis
{
Y,
Z
}
}

View File

@@ -0,0 +1,4 @@
Public Enum UpAxis
Y
Z
End Enum

View File

@@ -1,10 +0,0 @@
namespace Pilz.S3DFileParser
{
public class Vertex
{
public double X { get; set; } = 0d;
public double Y { get; set; } = 0d;
public double Z { get; set; } = 0d;
}
}

View File

@@ -0,0 +1,5 @@
Public Class Vertex
Public Property X As Double = 0
Public Property Y As Double = 0
Public Property Z As Double = 0
End Class

View File

@@ -1,11 +0,0 @@
namespace Pilz.S3DFileParser
{
public class VertexColor
{
public float R { get; set; } = 1f;
public float G { get; set; } = 1f;
public float B { get; set; } = 1f;
public float A { get; set; } = 1f;
}
}

View File

@@ -0,0 +1,6 @@
Public Class VertexColor
Public Property R As Single = 1
Public Property G As Single = 1
Public Property B As Single = 1
Public Property A As Single = 1
End Class