-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
122 lines (107 loc) · 3.7 KB
/
Copy pathUtils.cs
File metadata and controls
122 lines (107 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using IFBLibUnity.Meshes;
using IFBOptLib.IFBGraphics;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Assertions;
namespace IFBLibUnity
{
public static class Utils
{
public static Mesh CloneUnityMesh(this Mesh mesh)
{
var inputMeshVerts = mesh.vertices;
var inputMeshNormals = mesh.normals;
var inputMeshUvs = mesh.uv;
var inputMeshIndices = mesh.triangles;
var newMesh = new Mesh();
var vertices = new Vector3[inputMeshVerts.Length];
var normals = new Vector3[inputMeshNormals.Length];
var uvs = new Vector2[inputMeshUvs.Length];
var indices = new int[inputMeshIndices.Length];
Array.Copy(inputMeshVerts, vertices, inputMeshVerts.Length);
Array.Copy(inputMeshNormals, normals, inputMeshNormals.Length);
Array.Copy(inputMeshUvs, uvs, inputMeshUvs.Length);
Array.Copy(inputMeshIndices, indices, inputMeshIndices.Length);
newMesh.vertices = vertices;
newMesh.normals = normals;
newMesh.uv = uvs;
newMesh.triangles = indices;
return newMesh;
}
public static IEnumerable<float> SelectRawVerticesXYZ(this Vector3[] vertices)
{
foreach(var vert in vertices)
{
yield return vert.x;
yield return vert.y;
yield return vert.z;
}
}
public static IFBMesh.MeshSimplMagEffortType ToEffortType(this EMeshSimplifyStrength simplifyStrength)
{
switch(simplifyStrength)
{
case EMeshSimplifyStrength.LOW:
{
return IFBConstants.MeshSimpl.LOW;
}
case EMeshSimplifyStrength.MID:
{
return IFBConstants.MeshSimpl.MEDIUM;
}
case EMeshSimplifyStrength.HIGH:
{
return IFBConstants.MeshSimpl.HARD;
}
default:
{
throw new NotSupportedException();
}
}
}
public static void GuardMeshBeforeNative(this FastUnityMesh fmesh)
{
#if !DEBUG
return;
#endif
if(fmesh.Vertices == null)
{
throw new ArgumentNullException("FastUnityMesh.Vertices");
}
if (fmesh.Normals == null)
{
throw new ArgumentNullException("FastUnityMesh.Normals");
}
if (fmesh.Uvs == null)
{
throw new ArgumentNullException("FastUnityMesh.Uvs");
}
if (fmesh.Indices == null)
{
throw new ArgumentNullException("FastUnityMesh.Indices");
}
if (fmesh.Vertices.Length <= 0)
{
throw new ArgumentException("FastUnityMesh.Vertices.Length EMPTY");
}
if (fmesh.Normals.Length <= 0)
{
throw new ArgumentException("FastUnityMesh.Normals.Length EMPTY");
}
if (fmesh.Uvs.Length <= 0)
{
throw new ArgumentException("FastUnityMesh.Uvs.Length EMPTY");
}
if (fmesh.Indices.Length <= 0)
{
throw new ArgumentException("FastUnityMesh.Indices.Length EMPTY");
}
if (fmesh.Indices.Length % 3 != 0)
{
throw new ArgumentException("fmesh.Indices.Length % 3 != 0");
}
}
}
}