Esempio n. 1
0
            /// <summary>
            /// Create a serialiser for the given mesh details.
            /// </summary>
            /// <param name="details">The mesh to serialise.</param>
            public MeshSerialiser(MeshDetails details)
            {
                Details = details;
                RenderMesh mesh = details.Mesh;

                // Migrate data fields.
                ID = details.ID;
                Maths.Matrix4 transform = Maths.Rotation.ToMatrix4(Maths.QuaternionExt.FromUnity(details.LocalRotation));
                transform.Translation = Maths.Vector3Ext.FromUnity(details.LocalPosition);
                transform.ApplyScaling(Maths.Vector3Ext.FromUnity(details.LocalScale));
                Transform = transform;
                Tint      = Maths.ColourExt.FromUnity(details.Tint).Value;
                DrawType  = (byte)mesh.DrawType;
                // TODO: (KS) track this flag. Mind you, the normals will have been calculated by now...
                CalculateNormals = false;//Details.Builder.CalculateNormals;

                MeshComponentFlag components = 0;

                // Copy arrays into the correct format.
                _vertices = Maths.Vector3Ext.FromUnity(mesh.Vertices);

                _indices = new int[mesh.IndexCount];
                Array.Copy(mesh.Indices, _indices, _indices.Length);

                if (mesh.HasNormals)
                {
                    _normals = Maths.Vector3Ext.FromUnity(mesh.Normals);
                }
                if (mesh.HasUVs)
                {
                    _uvs = Maths.Vector2Ext.FromUnity(mesh.UVs);
                }
                if (mesh.HasColours)
                {
                    _colours = new uint[mesh.VertexCount];
                    Array.Copy(mesh.Colours, _colours, _colours.Length);
                }

                if (mesh.VertexCount > 0)
                {
                    components |= MeshComponentFlag.Vertex;
                }
                if (mesh.IndexCount > 0)
                {
                    components |= MeshComponentFlag.Index;
                }
                if (_normals != null)
                {
                    components |= MeshComponentFlag.Normal;
                }
                if (_uvs != null)
                {
                    components |= MeshComponentFlag.UV;
                }
                if (_colours != null)
                {
                    components |= MeshComponentFlag.Colour;
                }
                Components = components;
            }
Esempio n. 2
0
 /// <summary>
 /// Create a new mesh resource.
 /// </summary>
 /// <param name="id">The unique mesh resource ID for this mesh.</param>
 /// <param name="drawType">Defines the topology.</param>
 /// <param name="components">Identifies the required <see cref="MeshComponentFlag"/>.</param>
 public SimpleMesh(uint id, MeshDrawType drawType = MeshDrawType.Triangles,
                   MeshComponentFlag components   = MeshComponentFlag.Vertex | MeshComponentFlag.Index)
 {
     ID         = id;
     DrawType   = (byte)MeshDrawType.Triangles;
     Tint       = 0xffffffffu;
     Transform  = Matrix4.Identity;
     Components = components;
     _vertices  = new List <Vector3>();
     if ((components & MeshComponentFlag.Index) == MeshComponentFlag.Index)
     {
         _indices = new List <int>();
     }
     CalculateNormals = true;
 }
Esempio n. 3
0
            /// <summary>
            /// Create a serialiser for the given mesh details.
            /// </summary>
            /// <param name="details">The mesh to serialise.</param>
            public MeshSerialiser(MeshDetails details)
            {
                Details = details;

                // Migrate data fields.
                ID = details.ID;
                Maths.Matrix4 transform = Maths.Rotation.ToMatrix4(Maths.QuaternionExt.FromUnity(details.LocalRotation));
                transform.Translation = Maths.Vector3Ext.FromUnity(details.LocalPosition);
                transform.ApplyScaling(Maths.Vector3Ext.FromUnity(details.LocalScale));
                Transform        = transform;
                Tint             = Maths.ColourExt.FromUnity(details.Tint).Value;
                DrawType         = Details.DrawType;
                CalculateNormals = Details.Builder.CalculateNormals;

                MeshComponentFlag components = 0;

                // Copy arrays into the correct format.
                _vertices = Maths.Vector3Ext.FromUnity(details.Builder.Vertices);
                _normals  = Maths.Vector3Ext.FromUnity(details.Builder.Normals);
                _uvs      = Maths.Vector2Ext.FromUnity(details.Builder.UVs);
                _colours  = Maths.ColourExt.FromUnityUInts(details.Builder.Colours);

                if (details.VertexCount > 0)
                {
                    components |= MeshComponentFlag.Vertex;
                }
                if (details.Builder.ExplicitIndices)
                {
                    components |= MeshComponentFlag.Index;
                }
                if (_colours != null && _colours.Length > 0)
                {
                    components |= MeshComponentFlag.Colour;
                }
                if (_normals != null && _normals.Length > 0)
                {
                    components |= MeshComponentFlag.Normal;
                }
                if (_uvs != null && _uvs.Length > 0)
                {
                    components |= MeshComponentFlag.UV;
                }
                Components = components;
            }