示例#1
0
        private MeshGeometryModel3D CreateBall(HelixToolkit.Wpf.SharpDX.Material mat)
        {
            MeshGeometryModel3D mgm = new MeshGeometryModel3D();
            MeshBuilder         mb  = new MeshBuilder();

            //mb.AddSphere(MapReader.P2V(p), 2);
            mb.AddSphere(Vector3.Zero, 0.5);
            //mb.AddArrow(Vector3.Zero, new Vector3(0, 0, 2), 0.1);

            mgm.Geometry = mb.ToMeshGeometry3D();
            mgm.Material = mat;
            mViewModel.PlayersGeometry.Add(mgm);

            mgm.Attach(mViewModel.modelView.RenderHost);
            return(mgm);
        }
示例#2
0
        public static MeshGeometryModel3D MakeMeshGeometryModel3DUnity(DHTriangle triangle, HelixToolkit.Wpf.SharpDX.Material mat)
        {
            var allIndices = new List <int>(new int[] { 0, 1, 2 });

            var g3d = new HelixToolkit.Wpf.SharpDX.MeshGeometry3D();

            g3d.Positions       = new HelixToolkit.Wpf.SharpDX.Core.Vector3Collection();
            g3d.TriangleIndices = new HelixToolkit.Wpf.SharpDX.Core.IntCollection();
            g3d.Normals         = new HelixToolkit.Wpf.SharpDX.Core.Vector3Collection();
            g3d.Indices         = new HelixToolkit.Wpf.SharpDX.Core.IntCollection();


            g3d.Positions.Add(U2V(triangle.vertices0));
            g3d.Positions.Add(U2V(triangle.vertices1));
            g3d.Positions.Add(U2V(triangle.vertices2));
            g3d.Normals.Add(new SharpDX.Vector3(0, 1, 0));
            g3d.Normals.Add(new SharpDX.Vector3(0, 1, 0));
            g3d.Normals.Add(new SharpDX.Vector3(0, 1, 0));

            for (int i = 0; i < allIndices.Count; i++)
            {
                g3d.Indices.Add(allIndices[i]);
            }
            var ret = new MeshGeometryModel3D();

            ret.Material = mat;
            ret.Geometry = g3d;

            //ret. = new System.Windows.Controls.TextBlock() { Text = caption };

            return(ret);
        }
示例#3
0
        public static MeshGeometryModel3D MakeMeshGeometryModel3D(List <Point3D> allPoints, HelixToolkit.Wpf.SharpDX.Material mat)
        {
            var allIndices = new List <int>();

            for (int i = 0; i < allPoints.Count; i++)
            {
                allIndices.Add(i);
            }
            var g3d = new HelixToolkit.Wpf.SharpDX.MeshGeometry3D();

            g3d.Positions       = new HelixToolkit.Wpf.SharpDX.Core.Vector3Collection();
            g3d.TriangleIndices = new HelixToolkit.Wpf.SharpDX.Core.IntCollection();
            g3d.Normals         = new HelixToolkit.Wpf.SharpDX.Core.Vector3Collection();
            g3d.Indices         = new HelixToolkit.Wpf.SharpDX.Core.IntCollection();
            for (int i = 0; i < allPoints.Count; i++)
            {
                var             p3 = allPoints[i];
                SharpDX.Vector3 v3 = P2V(p3);
                g3d.Positions.Add(v3);
                g3d.Normals.Add(new SharpDX.Vector3(0, 1, 0));
            }
            for (int i = 0; i < allIndices.Count; i++)
            {
                g3d.Indices.Add(allIndices[i]);
            }
            var ret = new MeshGeometryModel3D();

            ret.Material = mat;
            ret.Geometry = g3d;

            //ret. = new System.Windows.Controls.TextBlock() { Text = caption };

            return(ret);
        }
示例#4
0
        /// <summary>
        /// Create a Mesh, with found props
        /// </summary>
        /// <param name="positions"></param>
        /// <param name="textureCoordinates"></param>
        /// <param name="triangleIndices"></param>
        /// <param name="normals"></param>
        /// <param name="tangents"></param>
        /// <param name="bitangents"></param>
        /// <param name="material"></param>
        private void CreateMesh(Vector3Collection positions, Vector2Collection textureCoordinates, IntCollection triangleIndices, out Vector3Collection normals, out Vector3Collection tangents, out Vector3Collection bitangents, Material material)
        {
            ComputeNormals(positions, triangleIndices, out normals);
            if (textureCoordinates == null)
            {
                textureCoordinates = new Vector2Collection();
                foreach (var pos in positions)
                {
                    textureCoordinates.Add(Vector2.One);
                }
            }
            MeshBuilder.ComputeTangents(positions, normals, textureCoordinates, triangleIndices, out tangents, out bitangents);
            MeshGeometry3D mesh = new MeshGeometry3D()
            {
                Positions          = positions,
                Normals            = normals,
                TextureCoordinates = textureCoordinates,
                Indices            = triangleIndices,
                Tangents           = tangents,
                BiTangents         = bitangents
            };
            Object3D ob3d = new Object3D();

            ob3d.Geometry  = mesh;
            ob3d.Material  = material;
            ob3d.Transform = Matrix.Identity;
            ob3d.Name      = "Default";
            this.obGroup.Add(ob3d);
        }
示例#5
0
        /// <summary>
        /// Reads a triangular mesh.
        /// </summary>
        /// <param name="reader">
        /// The reader.
        /// </param>
        /// <param name="chunkSize">
        /// The chunk size.
        /// </param>
        private void ReadTriangularMesh(BinaryReader reader, int chunkSize)
        {
            MeshBuilder       builder            = new MeshBuilder();
            int               bytesRead          = 6;
            Vector3Collection positions          = null;
            IntCollection     faces              = null;
            Vector2Collection textureCoordinates = null;
            List <FaceSet>    facesets           = null;
            IntCollection     triangleIndices    = null;
            Vector3Collection normals            = null;
            MediaMatrix3D     matrix             = MediaMatrix3D.Identity;
            Vector3Collection tangents           = null;
            Vector3Collection bitangents         = null;

            while (bytesRead < chunkSize)
            {
                ChunkID id   = this.ReadChunkId(reader);
                int     size = this.ReadChunkSize(reader);
                bytesRead += size;
                switch (id)
                {
                case ChunkID.TRI_VERTEXL:
                    positions = this.ReadVertexList(reader);
                    break;

                case ChunkID.TRI_FACEL1:
                    faces    = ReadFaceList(reader);
                    size    -= (faces.Count / 3 * 8) + 2;
                    facesets = this.ReadFaceSets(reader, size - 6);
                    break;

                case ChunkID.TRI_TEXCOORD:
                    textureCoordinates = ReadTexCoords(reader);
                    break;

                case ChunkID.TRI_LOCAL:
                    matrix = this.ReadTransformation(reader);
                    break;

                default:
                    this.ReadData(reader, size - 6);
                    break;
                }
            }
            if (!matrix.IsIdentity)
            {
                for (int i = 0; i < positions.Count; i++)
                {
                    positions[i] = Transform(matrix, positions[i]);
                }
            }
            if (faces == null)
            {
                //no faces defined?? return...
                return;
            }

            if (facesets == null || facesets.Count == 0)
            {
                triangleIndices = ConvertFaceIndices(faces, faces);
                CreateMesh(positions, textureCoordinates, triangleIndices, out normals, out tangents, out bitangents, PhongMaterials.Gray);
                //Add default get and setter
            }
            else
            {
                foreach (var fm in facesets)
                {
                    triangleIndices = ConvertFaceIndices(fm.Faces, faces);
                    Material mat = null;
                    if (this.materials.ContainsKey(fm.Name))
                    {
                        mat = this.materials[fm.Name];
                    }
                    CreateMesh(positions, textureCoordinates, triangleIndices, out normals, out tangents, out bitangents, mat);
                }
            }
        }
示例#6
-31
            /// <summary>
            /// Gets the material from the specified path.
            /// </summary>
            /// <param name="texturePath">
            /// The texture path.
            /// </param>
            /// <returns>
            /// The material.
            /// </returns>
            public Material GetMaterial(string texturePath)
            {
                if (this.Material == null)
                {
                    this.Material = this.CreateMaterial(texturePath);
                    //this.Material.Freeze();
                }

                return this.Material;
            }
示例#7
-32
    /// <summary>
    /// Create a Mesh, with found props
    /// </summary>
    /// <param name="positions"></param>
    /// <param name="textureCoordinates"></param>
    /// <param name="triangleIndices"></param>
    /// <param name="normals"></param>
    /// <param name="tangents"></param>
    /// <param name="bitangents"></param>
    /// <param name="material"></param>
    private void CreateMesh(Vector3Collection positions, Vector2Collection textureCoordinates, IntCollection triangleIndices, out Vector3Collection normals, out Vector3Collection tangents, out Vector3Collection bitangents,Material material)
    {
      ComputeNormals(positions, triangleIndices, out normals);
      if (textureCoordinates == null)
      {
        textureCoordinates = new Vector2Collection();
        foreach(var pos in positions)
        {
          textureCoordinates.Add(Vector2.One);
        }
      } 
      MeshBuilder.ComputeTangents(positions, normals, textureCoordinates, triangleIndices, out tangents, out bitangents);
      MeshGeometry3D mesh = new MeshGeometry3D()
      {
        Positions = positions,
        Normals = normals,
        TextureCoordinates = textureCoordinates,
        Indices = triangleIndices,
        Tangents = tangents,
        BiTangents = bitangents

      };
      Object3D ob3d = new Object3D();
      ob3d.Geometry = mesh;
      ob3d.Material = material;
      ob3d.Transform = Matrix.Identity;
      ob3d.Name = "Default";
      this.obGroup.Add(ob3d);
    }