public IMesh CreateMesh()
        {
            var mesh = new RAMMesh();

            foreach (var pair in parts)
            {
                var mat  = pair.Key;
                var data = pair.Value;


                if (data.Positions.Count == 0)
                {
                    continue;
                }

                var geom = new MeshPartGeometryData();
                geom.Sources.Add(new MeshPartGeometryData.Source
                {
                    DataVector3 = data.Positions.ToArray(),
                    Number      = 0,
                    Semantic    = MeshPartGeometryData.Semantic.Position
                });
                geom.Sources.Add(new MeshPartGeometryData.Source
                {
                    DataVector3 = data.Normals.ToArray(),
                    Number      = 0,
                    Semantic    = MeshPartGeometryData.Semantic.Normal
                });
                geom.Sources.Add(new MeshPartGeometryData.Source
                {
                    DataVector2 = data.Texcoords.ToArray(),
                    Number      = 0,
                    Semantic    = MeshPartGeometryData.Semantic.Texcoord
                });
                geom.Sources.Add(new MeshPartGeometryData.Source
                {
                    DataVector3 = calculateTangents(data),
                    Number      = 0,
                    Semantic    = MeshPartGeometryData.Semantic.Tangent
                });

                var part = new RAMMeshPart();
                part.SetGeometryData(geom);

                mesh.GetCoreData().Parts.Add(new MeshCoreData.Part
                {
                    MeshMaterial = mat.ToMeshCoreDataMaterial(),
                    MeshPart     = part,
                    ObjectMatrix = Matrix.Identity.xna()
                });
            }



            return(mesh);
        }
        public static IMesh Transform(IMesh mesh, Matrix transform)
        {
            //TODO: first take deep copy?
            var ret = new RAMMesh();

            ret.GetCoreData().Parts = mesh.GetCoreData().Parts.Select(p =>
            {
                var nPart          = new MeshCoreData.Part();
                nPart.ObjectMatrix = p.ObjectMatrix * transform.xna();
                nPart.MeshMaterial = p.MeshMaterial;
                nPart.MeshPart     = p.MeshPart;
                return(nPart);
            }).ToList();
            return(ret);
        }
Exemple #3
0
        /// <summary>
        /// This might not be a deep copy, so changes to the original may affect the created mesh (this is bug but im lazy)
        /// </summary>
        /// <param name="original"></param>
        /// <returns></returns>
        public IMesh CreateOptimized(IMesh original)
        {
            materials.Clear();
            var builder = new MeshBuilder();


            foreach (var oriPart in original.GetCoreData().Parts)
            {
                MeshBuilder.MeshMaterial meshMaterial = getMaterial(oriPart.MeshMaterial, builder);
                builder.AddGeometryData(oriPart.MeshPart.GetGeometryData(), meshMaterial, oriPart.ObjectMatrix.dx());
            }

            mesh = builder.CreateMesh() as RAMMesh;

            copyCollisionData(mesh, original);


            return(mesh);
        }
        public static IMesh CreateSimpleTestMesh()
        {
            IMesh mesh;

            mesh = new RAMMesh();

            var part = new MeshCoreData.Part();

            part.ObjectMatrix = Matrix.Identity;
            part.MeshPart     = new RAMMeshPart();
            ((RAMMeshPart)part.MeshPart).SetGeometryData(MeshPartGeometryData.CreateTestSquare());

            var mat = new MeshCoreData.Material();

            mat.DiffuseMap = GetTestTexture();

            part.MeshMaterial = mat;
            mesh.GetCoreData().Parts.Add(part);

            return(mesh);
        }
Exemple #5
0
 private void copyCollisionData(RAMMesh ret, IMesh original)
 {
     ret.GetCollisionData().Boxes.AddRange(original.GetCollisionData().Boxes);
     ret.GetCollisionData().ConvexMeshes.AddRange(original.GetCollisionData().ConvexMeshes);
     ret.GetCollisionData().TriangleMesh = original.GetCollisionData().TriangleMesh;
 }