@@ -907,19 +907,33 @@ public struct MeshInfo
907
907
/// Ex: if triangles = [3,4,2], then we have one triangle with vertices vertices[3], vertices[4], and vertices[2]
908
908
/// </summary>
909
909
/// <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
+ } }
911
915
912
916
/// <summary>
913
917
/// Gets the vertices, represented in local coordinates.
914
918
/// </summary>
915
919
/// <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
+ } }
917
925
918
926
/// <summary>
919
927
/// Gets the normals for the vertices.
920
928
/// </summary>
921
929
/// <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
+ } }
923
937
924
938
/// <summary>
925
939
/// TODO: Gets the binormals for the vertices.
@@ -934,12 +948,12 @@ public Vector3 [] Binormals {
934
948
/// => Math.cross (normal, tangent.xyz) * tangent.w
935
949
if ( m_Binormals == null || m_Binormals . Length == 0 )
936
950
{
937
- m_Binormals = new Vector3 [ mesh . normals . Length ] ;
951
+ m_Binormals = new Vector3 [ Normals . Length ] ;
938
952
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 ;
943
957
944
958
}
945
959
return m_Binormals ;
@@ -950,19 +964,37 @@ public Vector3 [] Binormals {
950
964
/// TODO: Gets the tangents for the vertices.
951
965
/// </summary>
952
966
/// <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
+ } }
954
974
955
975
/// <summary>
956
- /// TODO: Gets the tangents for the vertices.
976
+ /// TODO: Gets the vertex colors for the vertices.
957
977
/// </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
+ } }
960
986
961
987
/// <summary>
962
988
/// Gets the uvs.
963
989
/// </summary>
964
990
/// <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
+ } }
966
998
967
999
/// <summary>
968
1000
/// The material used, if any; otherwise null.
@@ -1002,6 +1034,12 @@ public MeshInfo (Mesh mesh)
1002
1034
this . xform = Matrix4x4 . identity ;
1003
1035
this . unityObject = null ;
1004
1036
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 ;
1005
1043
}
1006
1044
1007
1045
/// <summary>
@@ -1015,6 +1053,12 @@ public MeshInfo (GameObject gameObject, Mesh mesh)
1015
1053
this . xform = gameObject . transform . localToWorldMatrix ;
1016
1054
this . unityObject = gameObject ;
1017
1055
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 ;
1018
1062
}
1019
1063
}
1020
1064
0 commit comments