Read() 공개 메소드

Reads the model from the specified stream.
public Read ( Stream s ) : System.Windows.Media.Media3D.Model3DGroup
s Stream /// The stream. ///
리턴 System.Windows.Media.Media3D.Model3DGroup
예제 #1
0
 public void Read_Skeleton_ValidModel()
 {
     var r = new StudioReader();
     var model = r.Read(@"Models\3ds\skeleton.3ds");
     Assert.AreEqual(1, model.Children.Count);
     var m0 = (MeshGeometry3D)((GeometryModel3D)model.Children[0]).Geometry;
     Assert.AreEqual(4595, m0.TriangleIndices.Count / 3);
 }
예제 #2
0
        /// <summary>
        /// Loads a model from the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="dispatcher">The dispatcher used to create the model.</param>
        /// <param name="freeze">Freeze the model if set to <c>true</c>.</param>
        /// <returns>A model.</returns>
        /// <exception cref="System.InvalidOperationException">File format not supported.</exception>
        public Model3DGroup Load(string path, Dispatcher dispatcher = null, bool freeze = false)
        {
            if (path == null)
            {
                return(null);
            }

            if (dispatcher == null)
            {
                dispatcher = Dispatcher.CurrentDispatcher;
            }

            Model3DGroup model;
            var          ext = Path.GetExtension(path);

            if (ext != null)
            {
                ext = ext.ToLower();
            }

            switch (ext)
            {
            case ".3ds":
            {
                var r = new StudioReader(dispatcher)
                {
                    DefaultMaterial = this.DefaultMaterial, Freeze = freeze
                };
                model = r.Read(path, ApplyNormalToFace);
                break;
            }

            case ".lwo":
            {
                var r = new LwoReader(dispatcher)
                {
                    DefaultMaterial = this.DefaultMaterial, Freeze = freeze
                };
                model = r.Read(path);

                break;
            }

            case ".obj":
            {
                var r = new ObjReader(dispatcher)
                {
                    DefaultMaterial = this.DefaultMaterial, Freeze = freeze
                };
                model = r.Read(path);
                break;
            }

            case ".objz":
            {
                var r = new ObjReader(dispatcher)
                {
                    DefaultMaterial = this.DefaultMaterial, Freeze = freeze
                };
                model = r.ReadZ(path);
                break;
            }

            case ".stl":
            {
                var r = new StLReader(dispatcher)
                {
                    DefaultMaterial = this.DefaultMaterial, Freeze = freeze
                };
                model = r.Read(path);
                break;
            }

            case ".off":
            {
                var r = new OffReader(dispatcher)
                {
                    DefaultMaterial = this.DefaultMaterial, Freeze = freeze
                };
                model = r.Read(path);
                break;
            }

            default:
                throw new InvalidOperationException("File format not supported.");
            }

            //if (!freeze)
            //{
            //    dispatcher.Invoke(new Action(() => model.SetName(Path.GetFileName(path))));
            //}

            return(model);
        }
예제 #3
0
        /// <summary>
        /// Loads a model from the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns>
        /// A model.
        /// </returns>
        /// <exception cref="System.InvalidOperationException">File format not supported.</exception>
        public Model3DGroup Load(string path)
        {
            if (path == null)
            {
                return(null);
            }

            Model3DGroup model;
            var          ext = Path.GetExtension(path);

            if (ext != null)
            {
                ext = ext.ToLower();
            }

            switch (ext)
            {
            case ".3ds":
            {
                var r = new StudioReader();
                model = r.Read(path);
                break;
            }

            case ".lwo":
            {
                var r = new LwoReader {
                    DefaultMaterial = this.DefaultMaterial
                };
                model = r.Read(path);

                break;
            }

            case ".obj":
            {
                var r = new ObjReader {
                    DefaultMaterial = this.DefaultMaterial
                };
                model = r.Read(path);
                break;
            }

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

            case ".stl":
            {
                var r = new StLReader {
                    DefaultMaterial = this.DefaultMaterial
                };
                model = r.Read(path);
                break;
            }

            case ".off":
            {
                var r = new OffReader {
                    DefaultMaterial = this.DefaultMaterial
                };
                model = r.Read(path);
                break;
            }

            default:
                throw new InvalidOperationException("File format not supported.");
            }

            return(model);
        }
예제 #4
-1
        /// <summary>
        /// Loads a model from the specified path.
        /// </summary>
        /// <param name="path">
        /// The path.
        /// </param>
        /// <returns>
        /// A model.
        /// </returns>
        public static Model3DGroup Load(string path)
        {
            if (path == null)
            {
                return null;
            }

            Model3DGroup model = null;
            string ext = Path.GetExtension(path).ToLower();
            switch (ext)
            {
                case ".3ds":
                    {
                        var r = new StudioReader();
                        model = r.Read(path);
                        break;
                    }

                case ".lwo":
                    {
                        var r = new LwoReader();
                        model = r.Read(path);

                        break;
                    }

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

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

                case ".stl":
                    {
                        var r = new StLReader();
                        model = r.Read(path);
                        break;
                    }

                case ".off":
                    {
                        var r = new OffReader();
                        model = r.Read(path);
                        break;
                    }

                default:
                    throw new InvalidOperationException("File format not supported.");
            }

            return model;
        }
예제 #5
-1
        private MeshGeometry3D ReadGeometryFromFile(string path)
        {
            var geometry = new MeshGeometry3D();

            if (string.IsNullOrEmpty(path))
                return geometry;

            var models = new Model3DGroup();
            
            var fileInfo = new FileInfo(path);

            if (fileInfo.Extension == ".obj")
            {
                var reader = new ObjReader();
                try
                {
                    models = reader.Read(fileInfo.FullName);
                }
                catch (Exception exc)
                {
                    Logger.Instance.Error(string.Format("Error while loading obj file '{0}'.", path), exc);
                }
            }

            if (fileInfo.Extension == ".3ds")
            {
                var reader = new StudioReader();
                try
                {
                    models = reader.Read(fileInfo.FullName);
                }
                catch (Exception exc)
                {
                    Logger.Instance.Error(string.Format("Error while loading 3ds file '{0}'.", path), exc);
                }
            }

            if (models.Children.Count > 0)
            {
                var model = models.Children[0] as GeometryModel3D;
                if (model != null) geometry = model.Geometry as MeshGeometry3D;
            }

            return geometry;
        }
예제 #6
-1
        /// <summary>
        /// Loads a model from the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="dispatcher">The dispatcher used to create the model.</param>
        /// <param name="freeze">Freeze the model if set to <c>true</c>.</param>
        /// <returns>A model.</returns>
        /// <exception cref="System.InvalidOperationException">File format not supported.</exception>
        public Model3DGroup Load(string path, Dispatcher dispatcher = null, bool freeze = false)
        {
            if (path == null)
            {
                return null;
            }

            if (dispatcher == null)
            {
                dispatcher = Dispatcher.CurrentDispatcher;
            }

            Model3DGroup model;
            var ext = Path.GetExtension(path);
            if (ext != null)
            {
                ext = ext.ToLower();
            }

            switch (ext)
            {
                case ".3ds":
                    {
                        var r = new StudioReader(dispatcher) { DefaultMaterial = this.DefaultMaterial, Freeze = freeze };
                        model = r.Read(path);
                        break;
                    }

                case ".lwo":
                    {
                        var r = new LwoReader(dispatcher) { DefaultMaterial = this.DefaultMaterial, Freeze = freeze };
                        model = r.Read(path);

                        break;
                    }

                case ".obj":
                    {
                        var r = new ObjReader(dispatcher) { DefaultMaterial = this.DefaultMaterial, Freeze = freeze };
                        model = r.Read(path);
                        break;
                    }

                case ".objz":
                    {
                        var r = new ObjReader(dispatcher) { DefaultMaterial = this.DefaultMaterial, Freeze = freeze };
                        model = r.ReadZ(path);
                        break;
                    }

                case ".stl":
                    {
                        var r = new StLReader(dispatcher) { DefaultMaterial = this.DefaultMaterial, Freeze = freeze };
                        model = r.Read(path);
                        break;
                    }

                case ".off":
                    {
                        var r = new OffReader(dispatcher) { DefaultMaterial = this.DefaultMaterial, Freeze = freeze };
                        model = r.Read(path);
                        break;
                    }

                default:
                    throw new InvalidOperationException("File format not supported.");
            }

            //if (!freeze)
            //{
            //    dispatcher.Invoke(new Action(() => model.SetName(Path.GetFileName(path))));
            //}

            return model;
        }
예제 #7
-1
        public static Model3DGroup Load(string path, Dispatcher dispatcher = null, bool freeze = false, bool ignoreErrors = false)
        {
            if (path == null)
            {
                return null;
            }

            var defaultMaterial = Materials.Blue;

            if (dispatcher == null)
            {
                dispatcher = Dispatcher.CurrentDispatcher;
            }

            Model3DGroup model;
            var ext = Path.GetExtension(path).ToLower();

            switch (ext)
            {
                case ".3ds":
                    {
                        var r = new StudioReader(dispatcher) { DefaultMaterial = defaultMaterial, Freeze = freeze };
                        model = r.Read(path);
                        break;
                    }

                case ".lwo":
                    {
                        var r = new LwoReader(dispatcher) { DefaultMaterial = defaultMaterial, Freeze = freeze };
                        model = r.Read(path);
                        break;
                    }

                case ".obj":
                    {
                        var r = new ObjReader(dispatcher) { DefaultMaterial = defaultMaterial, Freeze = freeze, IgnoreErrors = ignoreErrors };
                        model = r.Read(path);
                        break;
                    }

                case ".objx":
                    {
                        var r = new ObjReader(dispatcher) { DefaultMaterial = defaultMaterial, Freeze = freeze, IgnoreErrors = ignoreErrors };
                        model = r.ReadZ(path);
                        break;
                    }

                case ".stl":
                    {
                        var r = new StLReader(dispatcher) { DefaultMaterial = defaultMaterial, Freeze = freeze };
                        model = r.Read(path);
                        break;
                    }

                case ".off":
                    {
                        var r = new OffReader(dispatcher) { DefaultMaterial = defaultMaterial, Freeze = freeze };
                        model = r.Read(path);
                        break;
                    }

                default:
                    throw new InvalidOperationException("File format not supported.");
            }

            return model;
        }