public Watch3DxControl()
        {
            InitializeComponent();
            // DataContext = this;

            // titles
            view1.Title = "Watch3DxNode";
            view1.SubTitle = "SharpDX";

            // camera setup
            view1.Camera = new PerspectiveCamera
            {
                Position = new Point3D(3, 3, 5),
                LookDirection = new Vector3D(-3, -3, -5),
                UpDirection = new Vector3D(0, 1, 0),
                FarPlaneDistance = 5000000
            };

            // default render technique
            view1.RenderTechniquesManager = new DefaultRenderTechniquesManager();
            view1.RenderTechnique = view1.RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Phong];
            view1.EffectsManager = new DefaultEffectsManager(view1.RenderTechniquesManager);

            // Setup lights
            var directionalLight3D = new DirectionalLight3D
            {
                Color = Color.White,
                Direction = new Vector3(-2, -5, -2)
            };

            var ambientLight3D = new AmbientLight3D {Color = Color.White};

            view1.Items.Add(ambientLight3D);
            view1.Items.Add(directionalLight3D);

            // Geometry
            var mb = new MeshBuilder();
            mb.AddSphere(new Vector3(0, 0, 0), 0.5);
            mb.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All);
            var meshGeometry = mb.ToMeshGeometry3D();

            var meshGeomModel = new MeshGeometryModel3D
            {
                Geometry = meshGeometry,
                Material = PhongMaterials.Red
            };
            // Add the Model to the viewport
            view1.Items.Add(meshGeomModel);
        }
Example #2
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);
        }
Example #3
0
        /// <summary>
        /// Initialize the Helix with these values. These values should be attached before the 
        /// visualization starts. Deleting them and attaching them does not make any effect on helix.         
        /// So they are initialized before the process starts.
        /// </summary>
        private void InitializeHelix()
        {
            directionalLight = new DirectionalLight3D
            {
                Color = directionalLightColor,
                Direction = directionalLightDirection
            };

            if (model3DDictionary != null && !model3DDictionary.ContainsKey("DirectionalLight"))
            {
                model3DDictionary.Add("DirectionalLight", directionalLight);
            }

            LineGeometryModel3D gridModel3D = new LineGeometryModel3D
            {
                Geometry = Grid,
                Transform = Model1Transform,
                Color = SharpDX.Color.White,
                Thickness = 0.3,
                IsHitTestVisible = false
            };

            if (model3DDictionary != null && !model3DDictionary.ContainsKey("Grid"))
            {
                model3DDictionary.Add("Grid", gridModel3D);
            }

            LineGeometryModel3D axesModel3D = new LineGeometryModel3D
            {
                Geometry = Axes,
                Transform = Model1Transform,
                Color = SharpDX.Color.White,
                Thickness = 0.3,
                IsHitTestVisible = false
            };

            if (model3DDictionary != null && !model3DDictionary.ContainsKey("Axes"))
            {
                model3DDictionary.Add("Axes", axesModel3D);
            }
        }
        public void SetupLights()
        {
            // Setup lights
            var directionalLight3D = new DirectionalLight3D
            {
                Color = Color.White,
                Direction = new Vector3(-2, -5, -2)
            };
            var ambientLight3D = new AmbientLight3D
            {
                Color = Color.White
            };

            view1.Items.Add(ambientLight3D);
            view1.Items.Add(directionalLight3D);
        }
        /// <summary>
        /// Initialize the Helix with these values. These values should be attached before the 
        /// visualization starts. Deleting them and attaching them does not make any effect on helix.         
        /// So they are initialized before the process starts.
        /// </summary>
        private void InitializeHelix()
        {
            if (Model3DDictionary == null)
            {
                throw new Exception("Helix could not be initialized.");
            }

            directionalLight = new DirectionalLight3D
            {
                Color = directionalLightColor,
                Direction = directionalLightDirection,
                Name = DefaultLightName
            };

            if (!Model3DDictionary.ContainsKey(DefaultLightName))
            {
                Model3DDictionary.Add(DefaultLightName, directionalLight);
            }

            var gridModel3D = new LineGeometryModel3D
            {
                Geometry = Grid,
                Transform = Model1Transform,
                Color = Color.White,
                Thickness = 0.3,
                IsHitTestVisible = false,
                Name = DefaultGridName
            };

            if (!Model3DDictionary.ContainsKey(DefaultGridName))
            {
                Model3DDictionary.Add(DefaultGridName, gridModel3D);
            }

            var axesModel3D = new LineGeometryModel3D
            {
                Geometry = Axes,
                Transform = Model1Transform,
                Color = Color.White,
                Thickness = 0.3,
                IsHitTestVisible = false,
                Name = DefaultAxesName
            };

            if (!Model3DDictionary.ContainsKey(DefaultAxesName))
            {
                Model3DDictionary.Add(DefaultAxesName, axesModel3D);
            }

            AttachAllGeometryModel3DToRenderHost();
        }