public void Read_Apple_ValidModel()
 {
     // LWO2 not yet supported
     var r = new LwoReader();
     var model = r.Read(@"Models\lwo\apple.lwo");
     Assert.AreEqual(1, model.Children.Count);
     var m0 = (MeshGeometry3D)((GeometryModel3D)model.Children[0]).Geometry;
     Assert.AreEqual(0, m0.TriangleIndices.Count / 3);
 }
 public void Read_Teddy_ValidModel()
 {
     var r = new LwoReader();
     var model = r.Read(@"Models\lwo\teddy.lwo");
     Assert.AreEqual(3, model.Children.Count);
     var m0 = (MeshGeometry3D)((GeometryModel3D)model.Children[0]).Geometry;
     var m1 = (MeshGeometry3D)((GeometryModel3D)model.Children[1]).Geometry;
     var m2 = (MeshGeometry3D)((GeometryModel3D)model.Children[2]).Geometry;
     Assert.AreEqual(1848, m0.TriangleIndices.Count / 3);
     Assert.AreEqual(96, m1.TriangleIndices.Count / 3);
     Assert.AreEqual(168, m2.TriangleIndices.Count / 3);
 }
Example #3
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);
        }
Example #4
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);
        }
        /// <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;
        }
        /// <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;
        }
Example #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;
        }