示例#1
0
            //---------------------------------------------------------------------------------------------------------
            /// <summary>
            /// Инициализация данных камеры
            /// </summary>
            //---------------------------------------------------------------------------------------------------------
            protected void InitCamera()
            {
                mDefaultOrthographicCamera = new Helix.OrthographicCamera
                {
                    Position          = new Point3D(0, 0, 5),
                    LookDirection     = new Vector3D(-0, -0, -5),
                    UpDirection       = new Vector3D(0, 1, 0),
                    NearPlaneDistance = 0.05,
                    FarPlaneDistance  = 5000
                };

                mDefaultPerspectiveCamera = new Helix.PerspectiveCamera
                {
                    Position          = new Point3D(0, 0, 5),
                    LookDirection     = new Vector3D(-0, -0, -5),
                    UpDirection       = new Vector3D(0, 1, 0),
                    NearPlaneDistance = 0.05,
                    FarPlaneDistance  = 5000
                };

                // camera models
                CameraModelCollection = new List <String>()
                {
                    OrthographicCameraName,
                    PerspectiveCameraName,
                };

                // on camera changed callback
                CameraModelChanged += (sender, args) =>
                {
                    if (mCameraModel == OrthographicCameraName)
                    {
                        if (!(Camera is Helix.OrthographicCamera))
                        {
                            Camera = mDefaultOrthographicCamera;
                        }
                    }
                    else if (mCameraModel == PerspectiveCameraName)
                    {
                        if (!(Camera is Helix.PerspectiveCamera))
                        {
                            Camera = mDefaultPerspectiveCamera;
                        }
                    }
                    else
                    {
                        //throw new Helix3D.("Camera Model Error.");
                    }
                };

                // default camera model
                CameraModel = PerspectiveCameraName;
                Camera      = mDefaultPerspectiveCamera;
            }
示例#2
0
 public PluginViewModel()
 {
     Camera = new OrthographicCamera
     {
         LookDirection     = new Vector3D(0, -10, -10),
         Position          = new Point3D(0, 10, 10),
         UpDirection       = new Vector3D(0, 1, 0),
         FarPlaneDistance  = 5000,
         NearPlaneDistance = 0.1f
     };
 }
示例#3
0
        /// <summary>
        /// Resets the specified orthographic camera.
        /// </summary>
        /// <param name="camera">
        /// The camera.
        /// </param>
        public static void Reset(this OrthographicCamera camera)
        {
            if (camera == null)
            {
                return;
            }

            camera.Position          = new Point3D(20, 10, 40);
            camera.LookDirection     = new Vector3D(-20, -10, -40);
            camera.UpDirection       = new Vector3D(0, 1, 0);
            camera.Width             = 40;
            camera.NearPlaneDistance = 0.1;
            camera.FarPlaneDistance  = 1000;
        }
示例#4
0
        /// <summary>
        /// Animates the orthographic width.
        /// </summary>
        /// <param name="camera">
        /// An orthographic camera.
        /// </param>
        /// <param name="newWidth">
        /// The width to animate to.
        /// </param>
        /// <param name="animationTime">
        /// Animation time in milliseconds
        /// </param>
        public static void AnimateWidth(this OrthographicCamera camera, double newWidth, double animationTime)
        {
            double fromWidth = camera.Width;

            camera.Width = newWidth;

            if (animationTime > 0)
            {
                var a1 = new DoubleAnimation(
                    fromWidth, newWidth, new Duration(TimeSpan.FromMilliseconds(animationTime)))
                {
                    AccelerationRatio = 0.3,
                    DecelerationRatio = 0.5,
                    FillBehavior      = FillBehavior.Stop
                };
                camera.BeginAnimation(OrthographicCamera.WidthProperty, a1);
            }
        }
示例#5
0
        public void ResetCameraPosition(Rect3D boundingBox)
        {
            //var boneCollection = MainViewModel.ProjData.BoneCollection;
            //

            Point3D modelCenter = new Point3D(boundingBox.X + boundingBox.SizeX / 2.0, boundingBox.Y + boundingBox.SizeY / 2.0, boundingBox.Z + boundingBox.SizeZ / 2.0);

            //Point3D modelCenter = new Point3D(0,200,0);

            HelixToolkit.Wpf.SharpDX.OrthographicCamera orthoCam1 = Camera1 as HelixToolkit.Wpf.SharpDX.OrthographicCamera;
            if (orthoCam1 != null)
            {
                orthoCam1.Position          = new Point3D(modelCenter.X, modelCenter.Y, modelCenter.Z + 1000 * boundingBox.Size.Z);
                orthoCam1.UpDirection       = new Vector3D(0, 1, 0);
                orthoCam1.LookDirection     = new Vector3D(0, 0, -1000 * boundingBox.Size.Z);
                orthoCam1.NearPlaneDistance = 0;
                orthoCam1.FarPlaneDistance  = 1e15;
                orthoCam1.Width             = 300;
            }

            hVp3D.Camera = orthoCam1;

            HelixToolkit.Wpf.SharpDX.AmbientLight3D     Light1 = new HelixToolkit.Wpf.SharpDX.AmbientLight3D();
            HelixToolkit.Wpf.SharpDX.DirectionalLight3D Light2 = new HelixToolkit.Wpf.SharpDX.DirectionalLight3D();
            HelixToolkit.Wpf.SharpDX.DirectionalLight3D Light3 = new HelixToolkit.Wpf.SharpDX.DirectionalLight3D();
            Light1.Color     = new SharpDX.Color(0.4f, 0.4f, 0.4f);
            Light2.Color     = new SharpDX.Color(0.6f, 0.6f, 0.6f);
            Light3.Color     = new SharpDX.Color(0.5f, 0.5f, 0.5f);
            Light1.Direction = new Vector3(-10, -1000, -(float)boundingBox.Size.Z);
            Light2.Direction = new Vector3(1000, 0, -(float)boundingBox.Size.Z);
            Light3.Direction = new Vector3(-1000, -(float)boundingBox.Size.Y, 300);

            hVp3D.Items.Add(Light1);
            hVp3D.Items.Add(Light2);
            hVp3D.Items.Add(Light3);
        }
示例#6
0
        public override void Render(RenderContext context)
        {
            if (!this.renderHost.IsShadowMapEnabled)
            {
                return;
            }

            /// --- set rasterizes state here with proper shadow-bias, as depth-bias and slope-bias in the rasterizer
            this.Device.ImmediateContext.Rasterizer.SetViewport(0, 0, width, height, 0.0f, 1.0f);
            this.Device.ImmediateContext.OutputMerger.SetTargets(depthViewSM);
            this.Device.ImmediateContext.ClearDepthStencilView(depthViewSM, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);

            var root = context.Canvas.Renderable.Items;

            foreach (var item in root)
            {
                var light = item as Light3D;
                if (light != null)
                {
                    Camera lightCamera = null;
                    //if (light is PointLightBase3D)
                    //{
                    //    var plight = (PointLightBase3D)light;
                    //    lightCamera = new PerspectiveCamera()
                    //    {
                    //        Position = plight.Position,
                    //        LookDirection = plight.Direction,
                    //        UpDirection = Vector3.UnitY.ToVector3D(),
                    //    };
                    //}
                    // else
                    if (light is DirectionalLight3D)
                    {
                        var dlight = (DirectionalLight3D)light;
                        var dir    = light.Direction.Normalized();
                        var pos    = -50 * light.Direction;

                        //lightCamera = new PerspectiveCamera()
                        //{
                        //    LookDirection = dir.ToVector3D(),
                        //    Position = (System.Windows.Media.Media3D.Point3D)(pos.ToVector3D()),
                        //    UpDirection = Vector3.UnitZ.ToVector3D(),
                        //    NearPlaneDistance = 1,
                        //    FarPlaneDistance = 100,
                        //    FieldOfView = 10,
                        //};

                        lightCamera = new OrthographicCamera()
                        {
                            LookDirection     = dir.ToVector3D(),
                            Position          = (System.Windows.Media.Media3D.Point3D)(pos.ToVector3D()),
                            UpDirection       = Vector3.UnitZ.ToVector3D(),
                            Width             = 100,
                            NearPlaneDistance = 1,
                            FarPlaneDistance  = 500,
                        };
                    }

                    if (lightCamera != null)
                    {
                        var sceneCamera = context.Camera;

                        light.LightViewMatrix       = CameraExtensions.GetViewMatrix(lightCamera);
                        light.LightProjectionMatrix = CameraExtensions.GetProjectionMatrix(lightCamera, context.Canvas.ActualWidth / context.Canvas.ActualHeight);

                        this.shadowPassContext.IsShadowPass = true;
                        this.shadowPassContext.Camera       = lightCamera;
                        foreach (var e in root)
                        {
                            var smodel = e as IThrowingShadow;
                            if (smodel != null)
                            {
                                if (smodel.IsThrowingShadow)
                                {
                                    var model = smodel as IRenderable;
                                    model.Render(this.shadowPassContext);
                                }
                            }
                        }
                        context.Camera = sceneCamera;
                    }
                }
            }

            this.texShadowMapVariable.SetResource(this.texShadowMapView);
            //this.texShadowMapVariable.SetResource(this.texColorMapView);
            this.vShadowMapInfoVariable.Set(new Vector4((float)this.Intensity, (float)this.FactorPCF, (float)this.Bias, 0));
            this.vShadowMapSizeVariable.Set(new Vector2(width, height));

            //System.Console.WriteLine("ShadowMap rendered!");
            context.Canvas.SetDefaultRenderTargets();
        }
示例#7
0
        public override void Render(RenderContext context)
        {
            if (!this.renderHost.IsShadowMapEnabled)
            {
                return;
            }

            /// --- set rasterizes state here with proper shadow-bias, as depth-bias and slope-bias in the rasterizer
            this.Device.ImmediateContext.Rasterizer.SetViewport(0, 0, width, height, 0.0f, 1.0f);
            this.Device.ImmediateContext.OutputMerger.SetTargets(depthViewSM);
            this.Device.ImmediateContext.ClearDepthStencilView(depthViewSM, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);

            var root = context.Canvas.Renderable.Items;
            foreach (var item in root)
            {
                var light = item as Light3D;
                if (light != null)
                {
                    Camera lightCamera = null;
                    //if (light is PointLightBase3D)
                    //{
                    //    var plight = (PointLightBase3D)light;
                    //    lightCamera = new PerspectiveCamera()
                    //    {
                    //        Position = plight.Position,
                    //        LookDirection = plight.Direction,
                    //        UpDirection = Vector3.UnitY.ToVector3D(),
                    //    };
                    //}
                    // else
                    if (light is DirectionalLight3D)
                    {
                        var dlight = (DirectionalLight3D)light;
                        var dir = light.Direction.Normalized();
                        var pos = -50 * light.Direction;

                        //lightCamera = new PerspectiveCamera()
                        //{
                        //    LookDirection = dir.ToVector3D(),
                        //    Position = (System.Windows.Media.Media3D.Point3D)(pos.ToVector3D()),
                        //    UpDirection = Vector3.UnitZ.ToVector3D(),
                        //    NearPlaneDistance = 1,
                        //    FarPlaneDistance = 100,
                        //    FieldOfView = 10,
                        //};

                        lightCamera = new OrthographicCamera()
                        {
                            LookDirection = dir.ToVector3D(),
                            Position = (System.Windows.Media.Media3D.Point3D)(pos.ToVector3D()),
                            UpDirection = Vector3.UnitZ.ToVector3D(),
                            Width = 100,
                            NearPlaneDistance = 1,
                            FarPlaneDistance = 500,
                        };
                    }

                    if (lightCamera != null)
                    {
                        var sceneCamera = context.Camera;

                        light.LightViewMatrix = CameraExtensions.GetViewMatrix(lightCamera);
                        light.LightProjectionMatrix = CameraExtensions.GetProjectionMatrix(lightCamera, context.Canvas.ActualWidth / context.Canvas.ActualHeight);

                        this.shadowPassContext.IsShadowPass = true;
                        this.shadowPassContext.Camera = lightCamera;
                        foreach (var e in root)
                        {
                            var smodel = e as IThrowingShadow;
                            if (smodel != null)
                            {
                                if (smodel.IsThrowingShadow)
                                {
                                    var model = smodel as IRenderable;
                                    model.Render(this.shadowPassContext);
                                }
                            }
                        }
                        context.Camera = sceneCamera;
                    }
                }
            }

            this.texShadowMapVariable.SetResource(this.texShadowMapView);
            //this.texShadowMapVariable.SetResource(this.texColorMapView);
            this.vShadowMapInfoVariable.Set(new Vector4((float)this.Intensity, (float)this.FactorPCF, (float)this.Bias, 0));
            this.vShadowMapSizeVariable.Set(new Vector2(width, height));

            //System.Console.WriteLine("ShadowMap rendered!");
            context.Canvas.SetDefaultRenderTargets();
        }
示例#8
0
        public static void AddPointCloud(Dictionary <KeyValuePair <int, int>, double> PointCollection, out PointModel Points,
                                         out GridModel Grid, out AxisModel Axis, out HelixToolkit.Wpf.SharpDX.Camera Camera, bool cameraType = false)
        {
            Camera = null;
            Points = null;
            Grid   = null;
            Axis   = null;

            var points = new PointGeometry3D();
            var col    = new Color4Collection();  // color gradient
            var ptPos  = new Vector3Collection(); // point positions
            var ptIdx  = new IntCollection();     // point indexes

            if (PointCollection != null && PointCollection.Count() > 1)
            {
                //newdataFromTxt(path, positionX, positionY, positionZ);
                var maxX    = PointCollection.Max(x => x.Key.Key);   // X
                var minX    = PointCollection.Min(x => x.Key.Key);   // X
                var maxY    = PointCollection.Max(x => x.Key.Value); // Y
                var minY    = PointCollection.Min(x => x.Key.Value); // Y
                var maxZ    = PointCollection.Max(x => x.Value);     // Z
                var minZ    = PointCollection.Min(x => x.Value);     // Z
                var minYObj = PointCollection.First(x => x.Key.Value == minY);

                Trace.WriteLine($"{maxX} {minX} {maxY} {minY} {maxZ} {minZ}");

                if (PointCollection.Count() <= 0)
                {
                    return;
                }
                foreach (var point in PointCollection)
                {
                    var positionToColour = point.Value;

                    ptIdx.Add(ptPos.Count);
                    ptPos.Add(new Vector3((float)point.Key.Key, ((float)point.Key.Value), (float)point.Value));
                    col.Add(new Color4(RedBlueScale((float)minZ, (float)maxZ, (float)positionToColour)));
                }
                Points = new PointModel
                {
                    // indexes and color gradient
                    PointsGeometry = new PointGeometry3D {
                        Positions = ptPos, Indices = ptIdx, Colors = col
                    },
                    PointsColor     = Colors.White,
                    PointsTransform = new TranslateTransform3D(-minX, -minY, -minZ)
                };
                // floor plane grid
                LineBuilder gridLines = new LineBuilder();
                VisualizationTools.CreateGrid(gridLines, maxX, minX, maxY, minY, minZ);
                Grid = new GridModel
                {
                    GridGeometry  = gridLines.ToLineGeometry3D(),
                    GridColor     = new Color4(153 / 255.0f, 204 / 255.0f, 255 / 255.0f, 0.3f).ToColor(),
                    GridTransform = new TranslateTransform3D(0, 0, 0)
                };
                // lines
                LineBuilder arrows = new LineBuilder();
                VisualizationTools.CreateAxes(arrows, (float)maxX, (float)minX, (float)maxY, (float)minY, (float)maxZ, (float)minZ);
                Axis = new AxisModel
                {
                    AxisGeometry  = arrows.ToLineGeometry3D(),
                    AxisColor     = new Color4(0, 255 / 255.0f, 255 / 255.0f, 0.5f).ToColor(),
                    AxisTransform = new TranslateTransform3D(0, 0, 0)
                };

                if (cameraType == false)
                {
                    Camera = new HelixToolkit.Wpf.SharpDX.PerspectiveCamera
                    {
                        Position         = new Point3D(0, 0, Math.Abs(minZ * 100)),
                        LookDirection    = new Vector3D(((float)maxX - (float)minX) / 2, ((float)maxY - (float)minY) / 2, -Math.Abs(minZ * 100)),//z kamerą jest problem przy przybliżaniu prawdopodobnie przez ten LookDirection albo sposób poruszania kamerą
                        UpDirection      = new Vector3D(0, 1, 0),
                        FarPlaneDistance = 5000000
                    };
                }
                else
                {
                    Camera = new HelixToolkit.Wpf.SharpDX.OrthographicCamera
                    {
                        Position         = new Point3D(0, 0, Math.Abs(minZ * 100)),
                        LookDirection    = new Vector3D(((float)maxX - (float)minX) / 2, ((float)maxY - (float)minY) / 2, -Math.Abs(minZ * 100)),//z kamerą jest problem przy przybliżaniu prawdopodobnie przez ten LookDirection albo sposób poruszania kamerą
                        UpDirection      = new Vector3D(0, 1, 0),
                        FarPlaneDistance = 5000000
                    };
                }
            }
        }
        protected BaseViewModel()
        {
            // camera models
            CameraModelCollection = new List<string>()
            {
                Orthographic,
                Perspective,
            };

            // on camera changed callback
            CameraModelChanged += (s, e) =>
            {
                if (cameraModel == Orthographic)
                {
                    if (this.Camera != null)
                    {
                        var newCamera = new OrthographicCamera();
                        this.Camera.CopyTo(newCamera);
                        newCamera.NearPlaneDistance = 1;
                        newCamera.FarPlaneDistance = 100;
                        this.Camera = newCamera;

                    }
                    else
                    {
                        Camera = defaultOrthographicCamera;
                    }
                }
                else if (cameraModel == Perspective)
                {
                    if (this.Camera != null)
                    {
                        var newCamera = new PerspectiveCamera();
                        this.Camera.CopyTo(newCamera);
                        newCamera.NearPlaneDistance = 1;
                        newCamera.FarPlaneDistance = 100;
                        this.Camera = newCamera;
                    }
                    else
                    {
                        Camera = defaultPerspectiveCamera;
                    }
                }
                else
                {
                    throw new HelixToolkitException("Camera Model Error.");
                }
            };

            // default camera model
            CameraModel = Perspective;

            Title = "Demo (HelixToolkitDX)";
            SubTitle = "Default Base View Model";
        }
示例#10
0
        public void VisualizeFigure(BaseModel m)
        {
            // визуализируем исходный контур
            var(points, inxs) = GetContourPointAndInx(m);
            LineGeometry3D      lineGeom0 = new() { Positions = points, Indices = inxs, };
            LineGeometryModel3D lines     = new() { Geometry = lineGeom0, Color = Colors.Red, Thickness = 3 };

            viewport.Items.Add(lines);

            // визуализируем фигуру
            m.Update();
            var tmp = ToGeometry(m);
            MeshGeometryModel3D model = new() { Geometry = tmp };

            if (m.Error)
            {
                MessageBoxResult result = MessageBox.Show(m.ErrorStr);
            }
            else
            {
                // определяем различные цвета
                var colorAlpha = 0.5f;
                var material   = blueOnlyCheckBox.IsChecked == true
                    ? PhongMaterials.Blue
                    : materials[rnd.Next(0, materials.Count - 1)];
                material.DiffuseColor = new Color4(material.DiffuseColor.ToVector3(), colorAlpha);
                model.Material        = material;
                //model.CullMode = CullMode.Back;
                model.IsTransparent = true;
                viewport.Items.Add(model);
            }

            // визуализируем ребра
            var inxs2 = new IntCollection();

            m.Edges.ForEach(x2 => inxs2.AddAll(x2.Indices));
            m.Faces.ForEach(x => x.Edges.ForEach(x2 => inxs2.AddAll(x2.Indices)));
            LineGeometry3D      lineGeom = new() { Positions = m.Positions, Indices = inxs2, };
            LineGeometryModel3D edge     = new() { Geometry = lineGeom, Color = Colors.Black };

            viewport.Items.Add(edge);
        }

        private MeshGeometry3D ToGeometry(BaseModel m)
        {
            var model = new MeshGeometry3D()
            {
                Positions          = m.Positions,
                Indices            = m.Indices,
                Normals            = m.Normals,
                TextureCoordinates = null,
                Tangents           = null,
                BiTangents         = null,
            };

            return(model);
        }

        private OrthographicCamera _ortoCam = new OrthographicCamera()
        {
            Position = new Point3D(100, 100, 100), LookDirection = new Vector3D(-100, -100, -100), UpDirection = new Vector3D(0, 0, 1), Width = 200, FarPlaneDistance = 1000
        };