Skip to content

Commit fc30063

Browse files
committed
store triangles,vertices,tangents,etc. in MeshInfo
1 parent 78d78fc commit fc30063

File tree

1 file changed

+57
-13
lines changed

1 file changed

+57
-13
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -907,19 +907,33 @@ public struct MeshInfo
907907
/// Ex: if triangles = [3,4,2], then we have one triangle with vertices vertices[3], vertices[4], and vertices[2]
908908
/// </summary>
909909
/// <value>The triangles.</value>
910-
public int [] Triangles { get { return mesh.triangles; } }
910+
private int[] m_triangles;
911+
public int [] Triangles { get {
912+
if(m_triangles == null) { m_triangles = mesh.triangles; }
913+
return m_triangles;
914+
} }
911915

912916
/// <summary>
913917
/// Gets the vertices, represented in local coordinates.
914918
/// </summary>
915919
/// <value>The vertices.</value>
916-
public Vector3 [] Vertices { get { return mesh.vertices; } }
920+
private Vector3[] m_vertices;
921+
public Vector3 [] Vertices { get {
922+
if(m_vertices == null) { m_vertices = mesh.vertices; }
923+
return m_vertices;
924+
} }
917925

918926
/// <summary>
919927
/// Gets the normals for the vertices.
920928
/// </summary>
921929
/// <value>The normals.</value>
922-
public Vector3 [] Normals { get { return mesh.normals; } }
930+
private Vector3[] m_normals;
931+
public Vector3 [] Normals { get {
932+
if (m_normals == null) {
933+
m_normals = mesh.normals;
934+
}
935+
return m_normals;
936+
} }
923937

924938
/// <summary>
925939
/// TODO: Gets the binormals for the vertices.
@@ -934,12 +948,12 @@ public Vector3 [] Binormals {
934948
/// => Math.cross (normal, tangent.xyz) * tangent.w
935949
if (m_Binormals == null || m_Binormals.Length == 0)
936950
{
937-
m_Binormals = new Vector3 [mesh.normals.Length];
951+
m_Binormals = new Vector3 [Normals.Length];
938952

939-
for (int i = 0; i < mesh.normals.Length; i++)
940-
m_Binormals [i] = Vector3.Cross (mesh.normals [i],
941-
mesh.tangents [i])
942-
* mesh.tangents [i].w;
953+
for (int i = 0; i < Normals.Length; i++)
954+
m_Binormals [i] = Vector3.Cross (Normals [i],
955+
Tangents [i])
956+
* Tangents [i].w;
943957

944958
}
945959
return m_Binormals;
@@ -950,19 +964,37 @@ public Vector3 [] Binormals {
950964
/// TODO: Gets the tangents for the vertices.
951965
/// </summary>
952966
/// <value>The tangents.</value>
953-
public Vector4 [] Tangents { get { return mesh.tangents; } }
967+
private Vector4[] m_tangents;
968+
public Vector4 [] Tangents { get {
969+
if (m_tangents == null) {
970+
m_tangents = mesh.tangents;
971+
}
972+
return m_tangents;
973+
} }
954974

955975
/// <summary>
956-
/// TODO: Gets the tangents for the vertices.
976+
/// TODO: Gets the vertex colors for the vertices.
957977
/// </summary>
958-
/// <value>The tangents.</value>
959-
public Color32 [] VertexColors { get { return mesh.colors32; } }
978+
/// <value>The vertex colors.</value>
979+
private Color32 [] m_vertexColors;
980+
public Color32 [] VertexColors { get {
981+
if (m_vertexColors == null) {
982+
m_vertexColors = mesh.colors32;
983+
}
984+
return m_vertexColors;
985+
} }
960986

961987
/// <summary>
962988
/// Gets the uvs.
963989
/// </summary>
964990
/// <value>The uv.</value>
965-
public Vector2 [] UV { get { return mesh.uv; } }
991+
private Vector2[] m_UVs;
992+
public Vector2 [] UV { get {
993+
if (m_UVs == null) {
994+
m_UVs = mesh.uv;
995+
}
996+
return m_UVs;
997+
} }
966998

967999
/// <summary>
9681000
/// The material used, if any; otherwise null.
@@ -1002,6 +1034,12 @@ public MeshInfo (Mesh mesh)
10021034
this.xform = Matrix4x4.identity;
10031035
this.unityObject = null;
10041036
this.m_Binormals = null;
1037+
this.m_vertices = null;
1038+
this.m_triangles = null;
1039+
this.m_normals = null;
1040+
this.m_UVs = null;
1041+
this.m_vertexColors = null;
1042+
this.m_tangents = null;
10051043
}
10061044

10071045
/// <summary>
@@ -1015,6 +1053,12 @@ public MeshInfo (GameObject gameObject, Mesh mesh)
10151053
this.xform = gameObject.transform.localToWorldMatrix;
10161054
this.unityObject = gameObject;
10171055
this.m_Binormals = null;
1056+
this.m_vertices = null;
1057+
this.m_triangles = null;
1058+
this.m_normals = null;
1059+
this.m_UVs = null;
1060+
this.m_vertexColors = null;
1061+
this.m_tangents = null;
10181062
}
10191063
}
10201064

0 commit comments

Comments
 (0)