Ejemplo n.º 1
0
        internal void grabUpperPlane_x()
        {
            Model3DGroup   _model     = (Model3DGroup)this.Content;
            MeshGeometry3D _modelMesh = null;

            foreach (GeometryModel3D gm in _model.Children)
            {
                _modelMesh = (MeshGeometry3D)gm.Geometry;
            }

            Model3DGroup   _planeModel = (Model3DGroup)_plane.Content;
            MeshGeometry3D _planeMesh  = null;

            foreach (GeometryModel3D gm in _planeModel.Children)
            {
                _planeMesh = (MeshGeometry3D)gm.Geometry;
            }
            Int32Collection indices = _modelMesh.TriangleIndices;
            SmileObjReader  obj     = new SmileObjReader();

            //TODO: cut the upper mesh
            for (int i = 0; i < indices.Count; i = i + 3)
            {
                int index1 = indices[i];
                int index2 = indices[i + 1];
                int index3 = indices[i + 2];
            }
        }
Ejemplo n.º 2
0
        public static ModelVisual3D Load(string path)
        {
            if (path == null)
            {
                return(null);
            }
            ModelVisual3D model = new ModelVisual3D();
            string        ext   = Path.GetExtension(path).ToLower();

            switch (ext)
            {
            case ".obj":
            {
                var r = new SmileObjReader();
                model = r.Read(path);
                break;
            }

            case ".objz":
            {
                var r = new SmileObjReader();
                model = r.ReadZ(path);
                break;
            }

            default:
                throw new InvalidOperationException("File format not supported.");
            }
            return(model);
        }
Ejemplo n.º 3
0
        internal void grabUpperPlane_old()
        {
            Model3DGroup      model  = (Model3DGroup)this.Content;
            SmileObjReader    obj    = new SmileObjReader();
            Model3DCollection childs = model.Children;
            int c = 0;
            int i = 1;

            foreach (GeometryModel3D gm in childs)
            {
                MeshGeometry3D mesh = (MeshGeometry3D)gm.Geometry;
                obj.AddGroup("mesh" + c);
                Console.WriteLine("Positions:" + mesh.Positions.Count);
                Console.WriteLine("Indices:" + mesh.TriangleIndices.Count);
                Point3DCollection positions = mesh.Positions;
                foreach (var pp in positions)
                {
                    //Point3D pp = ToLocal(p);
                    if (pp.Z >= 0)
                    {
                        obj.AddVertex(pp.X + " " + pp.Y + " " + pp.Z);

                        if (i % 4 == 0)
                        {
                            obj.AddFace((i - 3) + " " + (i - 2) + " " + (i - 1));
                            obj.AddFace((i - 2) + " " + (i - 1) + " " + (i));
                        }

                        i++;
                    }
                    else
                    {
                        //obj.AddVertex(p.X + " " + p.Y + " " + 0);
                    }
                }

                /*
                 * for (int i = 0; i < mesh.TriangleIndices.Count; i = i + 3)
                 * {
                 *  int index1 = mesh.TriangleIndices[i];
                 *  int index2 = mesh.TriangleIndices[i + 1];
                 *  int index3 = mesh.TriangleIndices[i + 2];
                 *
                 *  Point3D point1 = mesh.Positions[index1];
                 *  Point3D point2 = mesh.Positions[index2];
                 *  Point3D point3 = mesh.Positions[index3];
                 *
                 *  if (point1.Z >= 0)
                 *  {
                 *      obj.AddVertex(point1.X + " " + point1.Y + " " + point1.Z);
                 *  }
                 *  else
                 *  {
                 *      obj.AddVertex(point1.X + " " + point1.Y + " " + 0);
                 *  }
                 *
                 *  if (point2.Z >= 0)
                 *  {
                 *      obj.AddVertex(point2.X + " " + point2.Y + " " + point2.Z);
                 *  }
                 *  else
                 *  {
                 *      obj.AddVertex(point2.X + " " + point2.Y + " " + 0);
                 *  }
                 *
                 *  if (point3.Z >= 0)
                 *  {
                 *      obj.AddVertex(point3.X + " " + point3.Y + " " + point3.Z);
                 *  }
                 *  else
                 *  {
                 *      obj.AddVertex(point3.X + " " + point3.Y + " " + 0);
                 *  }
                 *
                 *
                 *  obj.AddFace(i + " " + (i + 1) + " " + (i + 2));
                 *  //obj.AddFace(index1 + " " + index2 + " " + index3);
                 *
                 * }
                 */
                c++;
            }
            ModelVisual3D v = new ModelVisual3D();

            v.Content = obj.BuildModel();

            parent.Children.Add(v);
        }