コード例 #1
0
        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);
        }
コード例 #2
0
        /*private IMeshPart findOrCreatePart(MeshCoreData.Material original)
         * {
         *  foreach (var mat in materials)
         *      if (isIdenticalMaterial(original, mat.Key)) return mat.Value;
         *
         *  var copy = createMaterialCopy(original);
         *  var ret = createPart(copy);
         *  materials.Add(copy, ret);
         *
         *  return ret;
         *
         * }*/

        private IMeshPart createPart(MeshCoreData.Material material)
        {
            var ret  = new RAMMeshPart();
            var part = new MeshCoreData.Part();

            part.MeshMaterial = material;
            part.ObjectMatrix = Matrix.Identity;
            part.MeshPart     = ret;

            mesh.GetCoreData().Parts.Add(part);

            return(ret);
        }