Read() публичный Метод

Reads the model from the specified stream.
public Read ( Stream s, HelixToolkit.Wpf.SharpDX.ModelInfo info = default(ModelInfo) ) : System.Collections.Generic.List
s Stream /// The stream. ///
info HelixToolkit.Wpf.SharpDX.ModelInfo
Результат System.Collections.Generic.List
        public override void Calculate()
        {
            if (InputPorts[0].Data == null) return;

            if (InputPorts[0].Data is string)
            {
                var extension = Path.GetExtension(InputPorts[0].Data as string);

                var flag = false;

                switch (extension)
                {
                    case ".obj":
                        var currentHelixObjReader = new ObjReader();
                        try
                        {
                            var objModel = currentHelixObjReader.Read((string) InputPorts[0].Data);
                            var modelGroup = new GroupModel3D();
                            var modelGeometry = new Element3DCollection();
                            modelGeometry.AddRange(
                                objModel.Select(
                                    x =>
                                        new MeshGeometryModel3D
                                        {
                                            Geometry = x.Geometry as MeshGeometry3D,
                                            Material = x.Material
                                        }));

                            modelGroup.Children = modelGeometry;

                            Dispatcher.BeginInvoke((Action) delegate { _control.ViewPort3D.Items.Add(modelGroup); });
                        }
                        catch (Exception)
                        {
                            // ignore
                        }
                        break;
                    case ".stl":
                        var currentHelixStlReader = new StLReader();
                        try
                        {
                            var myModel = currentHelixStlReader.Read((string) InputPorts[0].Data);
                            // _control.ViewPort3D.Items.Add(myModel);
                        }
                        catch (Exception)
                        {
                            // ignore
                        }
                        break;
                }
            }
        }
Пример #2
0
        public MainViewModel()
        {
            // ----------------------------------------------
            // titles
            this.Title = "Screen Space Ambient Occlusion Demo";
            this.SubTitle = "WPF & SharpDX";

            // camera setup
            this.Camera = new PerspectiveCamera { Position = new Point3D(1.5, 2.5, 2.5), LookDirection = new Vector3D(-1.5, -2.5, -2.5), UpDirection = new Vector3D(0, 1, 0) };

            // default render technique
            this.RenderTechnique = Techniques.RenderDeferred;

            // background
            this.BackgroundColor = (Color4)Color.White;

            // setup lighting
            this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f);
            this.DirectionalLightColor = Color.White;
            this.DirectionalLightDirection1 = new Vector3(-2, -5, -2);
            this.DirectionalLightDirection2 = new Vector3(+2, +5, +5);

            // model materials
            this.DefaultMaterial = PhongMaterials.DefaultVRML;

            //load model
            var reader = new ObjReader();
            var objModel = reader.Read(@"./Media/CornellBox-Glossy.obj");

            this.ModelGeometry = new Element3DCollection();
            this.ModelGeometry.AddRange(objModel.Select(x => new MeshGeometryModel3D() { Geometry = x.Geometry as MeshGeometry3D, Material = x.Material, }));

            // model trafos
            this.ModelTransform = new Media3D.TranslateTransform3D(0, 0, 0);
        }
Пример #3
0
        public override void Calculate()
        {
            if (InputPorts[0].Data == null)
            {
                return;
            }

            if (InputPorts[0].Data is string)
            {
                var extension = Path.GetExtension(InputPorts[0].Data as string);

                var flag = false;

                switch (extension)
                {
                case ".obj":
                    var currentHelixObjReader = new ObjReader();
                    try
                    {
                        var objModel      = currentHelixObjReader.Read((string)InputPorts[0].Data);
                        var modelGroup    = new GroupModel3D();
                        var modelGeometry = new Element3DCollection();
                        modelGeometry.AddRange(
                            objModel.Select(
                                x =>
                                new MeshGeometryModel3D
                        {
                            Geometry = x.Geometry as MeshGeometry3D,
                            Material = x.Material
                        }));

                        modelGroup.Children = modelGeometry;

                        Dispatcher.BeginInvoke((Action) delegate { _control.ViewPort3D.Items.Add(modelGroup); });
                    }
                    catch (Exception)
                    {
                        // ignore
                    }
                    break;

                case ".stl":
                    var currentHelixStlReader = new StLReader();
                    try
                    {
                        var myModel = currentHelixStlReader.Read((string)InputPorts[0].Data);
                        // _control.ViewPort3D.Items.Add(myModel);
                    }
                    catch (Exception)
                    {
                        // ignore
                    }
                    break;
                }
            }
        }
Пример #4
0
 /// <summary>
 /// load the model from obj-file
 /// </summary>
 /// <param name="filename">filename</param>
 /// <param name="faces">Determines if facades should be treated as triangles (Default) or as quads (Quads)</param>
 private void LoadModel(string filename, MeshFaces faces)
 {
     // load model
     var reader = new ObjReader();
     var objModel = reader.Read(filename, new ModelInfo() { Faces = faces });
     this.DefaultModel = objModel[0].Geometry as MeshGeometry3D;
     this.DefaultModel.Colors = new Color4Collection(this.DefaultModel.Positions.Select(x => new Color4(1, 0, 0, 1)));
 }  
Пример #5
0
        /// <summary>
        /// Constructor of the MainViewModel
        /// </summary>
        public MainViewModel()
        {
            // titles
            this.Title = "Deferred Shading Demo";
            this.SubTitle = "WPF & SharpDX";

            // camera setup
            this.Camera = new PerspectiveCamera { Position = new Point3D(18, 64, 30), LookDirection = new Vector3D(-18, -64, -30), UpDirection = new Vector3D(0, 1, 0) };

            // deferred render technique
            RenderTechniquesManager = new DeferredTechniquesManager();
            RenderTechnique = RenderTechniquesManager.RenderTechniques[DeferredRenderTechniqueNames.Deferred];
            EffectsManager = new DeferredEffectsManager(RenderTechniquesManager);
            SupportDeferredRender = true;

            //load model
            var reader = new ObjReader();
            var objModel = reader.Read(@"./Media/bunny.obj");
            this.Model = objModel[0].Geometry as MeshGeometry3D;
            var scale = 2.0;

            // model trafos
            var transf1 = new Transform3DGroup();
            transf1.Children.Add(new ScaleTransform3D(scale, scale, scale));
            transf1.Children.Add(new RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 1, 0), 40), 0.0, 0.0, 0.0));
            transf1.Children.Add(new TranslateTransform3D(0, -2, 3));
            this.Model1Transform = transf1;

            var transf2 = new Transform3DGroup();
            transf2.Children.Add(new ScaleTransform3D(scale, scale, scale));
            transf2.Children.Add(new Media3D.RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 1, 0), 66), 0.0, 0.0, 0.0));
            transf2.Children.Add(new Media3D.TranslateTransform3D(-3.0, -2, -2.5));
            this.Model2Transform = transf2;

            var transf3 = new Transform3DGroup();
            transf3.Children.Add(new ScaleTransform3D(scale, scale, scale));
            transf3.Children.Add(new TranslateTransform3D(+3.5, -2, -1.0));
            this.Model3Transform = transf3;

            // floor plane
            var meshBuilder = new MeshBuilder();
            meshBuilder.AddBox(new Vector3(0, 0, 0), 100, 0.0, 100, BoxFaces.PositiveY);
            this.Plane = meshBuilder.ToMeshGeometry3D();
            this.PlaneTransform = new TranslateTransform3D(0, -1.05, 0);

            // model materials
            this.RedMaterial = PhongMaterials.Red;
            this.GreenMaterial = PhongMaterials.Green;
            this.BlueMaterial = PhongMaterials.Blue;
            this.PlaneMaterial = PhongMaterials.DefaultVRML;
            this.PlaneMaterial.DiffuseMap = new BitmapImage(new System.Uri(@"./Media/TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute));
            this.PlaneMaterial.NormalMap = new BitmapImage(new System.Uri(@"./Media/TextureCheckerboard2_dot3.jpg", System.UriKind.RelativeOrAbsolute));

            // setup lighting
            this.AmbientLightColor = new Color4(0.3f, 0.3f, 0.3f, 1.0f);
            this.DirectionalLightColor = new Color4(0.2f, 0.2f, 0.2f, 1.0f);
            this.DirectionalLightDirection = new Vector3(-2, -5, -2);

            this.PointLightColor = (Color4)Color.White;
            this.PointLightAttenuation = new Vector3(0.0f, 0.0f, 0.18f); //1/0/0 ; 0.1, 0.2, 0.3
            this.PointLightTransform1 = new TranslateTransform3D(new Vector3D(0, 1, 0));
            this.PointLightTransform2 = new TranslateTransform3D(new Vector3D(6, 1, 3));
            this.PointLightTransform3 = new TranslateTransform3D(new Vector3D(-3, 1, -6));

            this.SpotLightColor = (Color4)Color.AntiqueWhite;
            this.SpotLightAttenuation = new Vector3(1.0f, 0.1f, 0.01f);

            // light collection
            this.PointLightCollection = new Element3DCollection();
            this.PointLightCount = 7;
            this.PointLightSpread = 100;

            // spotlight collection
            this.SpotLightCollection = new Element3DCollection();
            this.SpotLightCount = 7;
            this.SpotLightSpread = 100;
        }