A visual element that shows a sphere defined by center and radius.
Inheritance: MeshElement3D
Beispiel #1
0
        /// <summary>
        /// Called when show lights is changed.
        /// </summary>
        protected void OnShowLightsChanged()
        {
            this.lightsVisual.Children.Clear();
            if (this.ShowLights)
            {
                foreach (var light in this.lightGroup.Children)
                {
                    var pl = light as PointLight;
                    if (pl != null)
                    {
                        var sphere = new SphereVisual3D();
                        sphere.BeginEdit();
                        sphere.Center = pl.Position;
                        sphere.Radius = 1.0;
                        sphere.Fill   = new SolidColorBrush(pl.Color);
                        sphere.EndEdit();
                        this.lightsVisual.Children.Add(sphere);
                    }

                    var dl = light as DirectionalLight;
                    if (dl != null)
                    {
                        var dir = dl.Direction;
                        dir.Normalize();

                        var target = new Point3D(0, 0, 0);
                        var source = target - (dir * 20);
                        var p2     = source + (dir * 10);

                        var sphere = new SphereVisual3D();
                        sphere.BeginEdit();
                        sphere.Center = source;
                        sphere.Radius = 1.0;
                        sphere.Fill   = new SolidColorBrush(dl.Color);
                        sphere.EndEdit();
                        this.lightsVisual.Children.Add(sphere);

                        var arrow = new ArrowVisual3D();
                        arrow.BeginEdit();
                        arrow.Point1   = source;
                        arrow.Point2   = p2;
                        arrow.Diameter = 0.5;
                        arrow.Fill     = new SolidColorBrush(dl.Color);
                        arrow.EndEdit();
                        this.lightsVisual.Children.Add(arrow);
                    }

                    var al = light as AmbientLight;
                    if (al != null)
                    {
                        var pos = new Point3D(0, 0, 20);
                        this.lightsVisual.Children.Add(
                            new CubeVisual3D {
                            Center = pos, SideLength = 1.0, Fill = new SolidColorBrush(al.Color)
                        });
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Called when the light changed.
        /// </summary>
        protected virtual void OnLightChanged()
        {
            this.Children.Clear();
            if (this.Light == null)
            {
                return;
            }

            var dl = this.Light as DirectionalLight;

            if (dl != null)
            {
                var    arrow    = new ArrowVisual3D();
                double distance = 10;
                double length   = 5;
                arrow.BeginEdit();
                arrow.Point1   = new Point3D() + dl.Direction * distance;
                arrow.Point2   = arrow.Point1 - dl.Direction * length;
                arrow.Diameter = 0.1 * length;
                arrow.Fill     = new SolidColorBrush(dl.Color);
                arrow.EndEdit();
                this.Children.Add(arrow);
            }

            var sl = this.Light as SpotLight;

            if (sl != null)
            {
                var sphere = new SphereVisual3D();
                sphere.BeginEdit();
                sphere.Center = sl.Position;
                sphere.Fill   = new SolidColorBrush(sl.Color);
                sphere.EndEdit();
                this.Children.Add(sphere);

                var arrow = new ArrowVisual3D();
                arrow.BeginEdit();
                arrow.Point1   = sl.Position;
                arrow.Point2   = sl.Position + sl.Direction;
                arrow.Diameter = 0.1;
                arrow.EndEdit();
                this.Children.Add(arrow);
            }

            var pl = this.Light as PointLight;

            if (pl != null)
            {
                var sphere = new SphereVisual3D();
                sphere.BeginEdit();
                sphere.Center = pl.Position;
                sphere.Fill   = new SolidColorBrush(pl.Color);
                sphere.EndEdit();
                this.Children.Add(sphere);
            }

            var al = this.Light as AmbientLight;
        }
Beispiel #3
0
        /// <summary>
        /// Called when the light changed.
        /// </summary>
        protected virtual void OnLightChanged()
        {
            this.Children.Clear();
            if (this.Light == null)
            {
                return;
            }

            var dl = this.Light as DirectionalLight;
            if (dl != null)
            {
                var arrow = new ArrowVisual3D();
                double distance = 10;
                double length = 5;
                arrow.BeginEdit();
                arrow.Point1 = new Point3D() + dl.Direction * distance;
                arrow.Point2 = arrow.Point1 - dl.Direction * length;
                arrow.Diameter = 0.1 * length;
                arrow.Fill = new SolidColorBrush(dl.Color);
                arrow.EndEdit();
                this.Children.Add(arrow);
            }

            var sl = this.Light as SpotLight;
            if (sl != null)
            {
                var sphere = new SphereVisual3D();
                sphere.BeginEdit();
                sphere.Center = sl.Position;
                sphere.Fill = new SolidColorBrush(sl.Color);
                sphere.EndEdit();
                this.Children.Add(sphere);

                var arrow = new ArrowVisual3D();
                arrow.BeginEdit();
                arrow.Point1 = sl.Position;
                arrow.Point2 = sl.Position + sl.Direction;
                arrow.Diameter = 0.1;
                arrow.EndEdit();
                this.Children.Add(arrow);
            }

            var pl = this.Light as PointLight;
            if (pl != null)
            {
                var sphere = new SphereVisual3D();
                sphere.BeginEdit();
                sphere.Center = pl.Position;
                sphere.Fill = new SolidColorBrush(pl.Color);
                sphere.EndEdit();
                this.Children.Add(sphere);
            }

            var al = this.Light as AmbientLight;
        }
 public TexturedObject3D()
 {
     Sphere = new SphereVisual3D() { ThetaDiv = 60, PhiDiv = 30 };
     Children.Add(Sphere);
 }
        private void UpdateVisuals()
        {
            Children.Clear();
            if (WindTurbine == null) return;

            var baseTower = new TruncatedConeVisual3D
                                {
                                    Fill = Brushes.Yellow,
                                    Origin = new Point3D(0, 0, -WindTurbine.BaseHeight)
                                };
            baseTower.Height = -baseTower.Origin.Z + 2;
            baseTower.BaseRadius = baseTower.TopRadius = WindTurbine.Diameter;

            var tower = new TruncatedConeVisual3D
                            {
                                Fill = Brushes.White,
                                Origin = new Point3D(0, 0, 2),
                                Height = WindTurbine.Height,
                                BaseRadius = WindTurbine.Diameter
                            };
            tower.TopRadius = tower.BaseRadius * (1 - WindTurbine.Height * Math.Sin(WindTurbine.ShaftAngle / 180.0 * Math.PI));

            var nacelle = new TruncatedConeVisual3D
                              {
                                  Fill = Brushes.White,
                                  Origin = new Point3D(WindTurbine.Overhang, 0, tower.Origin.Z + tower.Height),
                                  Normal = new Vector3D(-1, 0, 0),
                                  TopRadius = WindTurbine.NacelleDiameter
                              };
            nacelle.BaseRadius = nacelle.TopRadius * 0.7;
            nacelle.Height = WindTurbine.NacelleLength;

            Children.Add(baseTower);
            Children.Add(tower);
            Children.Add(nacelle);


            var endcap = new SphereVisual3D
                             {
                                 Center = new Point3D(WindTurbine.Overhang - WindTurbine.NacelleLength, 0,
                                                      tower.Origin.Z + tower.Height),
                                 Radius = nacelle.TopRadius,
                                 Fill = Brushes.White
                             };
            Children.Add(endcap);

            var rotor = new ModelVisual3D();

            for (int i = 0; i < WindTurbine.Blades; i++)
            {
                double angle = (double)i / WindTurbine.Blades * Math.PI * 2;

                // todo: the blade is simplified to a cone... it should be a real profile...
                var blade = new TruncatedConeVisual3D
                                {
                                    Origin = nacelle.Origin,
                                    Normal = new Vector3D(0, Math.Cos(angle), Math.Sin(angle)),
                                    Height = WindTurbine.BladeLength,
                                    BaseRadius = WindTurbine.BladeRootChord,
                                    TopRadius = WindTurbine.BladeTipChord,
                                    Fill = Brushes.White
                                };
                rotor.Children.Add(blade);
            }

            var hub = new SphereVisual3D
                          {
                              Fill = Brushes.White,
                              Center = nacelle.Origin,
                              Radius = WindTurbine.HubDiameter / 2
                          };
            rotor.Children.Add(hub);
            Children.Add(rotor);

            var rotation = new AxisAngleRotation3D(new Vector3D(1, 0, 0), 0);
            var rotorTransform = new RotateTransform3D(null, hub.Center) { Rotation = rotation };
            rotor.Transform = rotorTransform;

            var b = new Binding("RotationAngle") { Source = this };
            BindingOperations.SetBinding(rotation, AxisAngleRotation3D.AngleProperty, b);
        }
Beispiel #6
0
        /// <summary>
        /// Called when show lights is changed.
        /// </summary>
        protected void OnShowLightsChanged()
        {
            this.lightsVisual.Children.Clear();
            if (this.ShowLights)
            {
                foreach (var light in this.lightGroup.Children)
                {
                    var pl = light as PointLight;
                    if (pl != null)
                    {
                        var sphere = new SphereVisual3D();
                        sphere.BeginEdit();
                        sphere.Center = pl.Position;
                        sphere.Radius = 1.0;
                        sphere.Fill = new SolidColorBrush(pl.Color);
                        sphere.EndEdit();
                        this.lightsVisual.Children.Add(sphere);
                    }

                    var dl = light as DirectionalLight;
                    if (dl != null)
                    {
                        var dir = dl.Direction;
                        dir.Normalize();

                        var target = new Point3D(0, 0, 0);
                        var source = target - (dir * 20);
                        var p2 = source + (dir * 10);

                        var sphere = new SphereVisual3D();
                        sphere.BeginEdit();
                        sphere.Center = source;
                        sphere.Radius = 1.0;
                        sphere.Fill = new SolidColorBrush(dl.Color);
                        sphere.EndEdit();
                        this.lightsVisual.Children.Add(sphere);

                        var arrow = new ArrowVisual3D();
                        arrow.BeginEdit();
                        arrow.Point1 = source;
                        arrow.Point2 = p2;
                        arrow.Diameter = 0.5;
                        arrow.Fill = new SolidColorBrush(dl.Color);
                        arrow.EndEdit();
                        this.lightsVisual.Children.Add(arrow);
                    }

                    var al = light as AmbientLight;
                    if (al != null)
                    {
                        var pos = new Point3D(0, 0, 20);
                        this.lightsVisual.Children.Add(
                            new CubeVisual3D { Center = pos, SideLength = 1.0, Fill = new SolidColorBrush(al.Color) });
                    }
                }
            }
        }
        private async void StartUpdateTask()
        {
            if (_updateTask != null && _updateTask.Status == TaskStatus.Running) return;

            _ctsUpdate = new CancellationTokenSource();
            try
            {
                _updateTask = Task.Factory.StartNew(() =>
                {
                    Stopwatch sw = new Stopwatch();
                    while (!_ctsUpdate.Token.IsCancellationRequested)
                    {
                        sw.Restart();
                        foreach(MotionControllerModel mc in _camera.Controllers)
                        {
                            var mc1 = mc;
                            // update if the controller is selected for tracking
                            if(mc.Tracking.ContainsKey(_camera) && mc.Tracking[_camera])
                            {
                                // add if missing
                                if (!_controllerObjects.ContainsKey(mc))
                                {
                                    DispatcherHelper.UIDispatcher.Invoke(() =>
                                    {
                                        // convert color
                                        byte r = (byte)(mc1.Color.r * 255 + 0.5);
                                        byte g = (byte)(mc1.Color.g * 255 + 0.5);
                                        byte b = (byte)(mc1.Color.b * 255 + 0.5);
                                        Color color = Color.FromRgb(r, g, b);

                                        SphereVisual3D sphere = new SphereVisual3D
                                        {
                                            Center = new Point3D(mc1.WorldPosition[_camera].x,
                                                mc1.WorldPosition[_camera].z,
                                                mc1.WorldPosition[_camera].y),
                                            Radius = ((int)((14.0 / Math.PI) * 100)) / 200.0,
                                            Fill = new SolidColorBrush(color)
                                        };
                                        _controllerObjects.Add(mc1, sphere);
                                        _items.Add(sphere);
                                    });
                                }
                                // update position
                                if (mc.WorldPosition.ContainsKey(_camera))
                                {
                                    DispatcherHelper.UIDispatcher.Invoke((Action)(() => _controllerObjects[mc1].Center = new Point3D(
                                    mc1.WorldPosition[_camera].x,
                                    mc1.WorldPosition[_camera].z,
                                    mc1.WorldPosition[_camera].y))); 
                                }
                            }
                            // remove objects corresponding to unselected controllers
                            else
                            {
                                if(_controllerObjects.ContainsKey(mc))
                                {
                                    DispatcherHelper.UIDispatcher.Invoke((Action)(() => _items.Remove(_controllerObjects[mc1])));
                                    _controllerObjects.Remove(mc);
                                }
                            }
                        } // foreach
                        sw.Stop();
                        // taking the processing time of the task itself into account, pause the thread to approximately reach the given FPS 
                        Thread.Sleep((int)(Math.Max((1000.0 / _camera.FPS) - sw.ElapsedMilliseconds, 0) + 0.5));
                    } // while
                }, _ctsUpdate.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
                await _updateTask;
            }
            catch(OperationCanceledException ex)
            {
                Console.WriteLine(ex.StackTrace);
                Stop();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Stop();
            }
        }
Beispiel #8
0
        public LotEditorItemMarker CreateGeometry()
        {
            LotEditorItemMarker marker;

            if (this.ModelRepresentation == null)
            {
                marker = new LotEditorItemMarker(this);
            }
            else
            {
                marker = this.ModelRepresentation;
            }

            if (ViewLotEditor.LightTypes[LightType.InstanceId] == "Spot")
            {
                TruncatedConeVisual3D cone = new TruncatedConeVisual3D();
                cone.Height     = LightLength.Value;
                cone.BaseRadius = 0;
                cone.TopRadius  = LightOuterRadius.Value;
                Transform3DGroup transforms = new Transform3DGroup();
                transforms.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), -90)));
                Transform3D coneTransform = new MatrixTransform3D(LightTransform.GetAsMatrix3D());
                transforms.Children.Add(coneTransform);
                // cone.Transform = transforms;

                cone.Material = MaterialHelper.CreateMaterial(Brushes.Black, new SolidColorBrush(LightColor.Color), opacity: 0.6);
                //ModelRepresentation.Model = cone.Model;

                marker.Transform        = transforms;
                marker.ManipulatorModel = cone.Model;
                ModelRepresentation     = marker;
                return(marker);
            }
            else if (ViewLotEditor.LightTypes[LightType.InstanceId] == "Point")
            {
                HelixToolkit.Wpf.SphereVisual3D sphere = new HelixToolkit.Wpf.SphereVisual3D();
                sphere.Radius = 1;

                sphere.Material = MaterialHelper.CreateMaterial(Brushes.Black, new SolidColorBrush(LightColor.Color));

                marker.Transform        = new MatrixTransform3D(LightTransform.GetAsMatrix3D());
                marker.ManipulatorModel = sphere.Model;
                ModelRepresentation     = marker;
                return(marker);
            }
            else if (ViewLotEditor.LightTypes[LightType.InstanceId] == "Line")
            {
                BoxVisual3D lineLight = new BoxVisual3D();
                lineLight.Height = LightLength.Value;

                lineLight.Center = new Point3D(0, 0, -(LightLength.Value / 2));

                Transform3DGroup transforms = new Transform3DGroup();
                // transforms.Children.Add(new TranslateTransform3D(0, 0, -(light.LightLength / 2)));
                transforms.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90)));
                transforms.Children.Add(new MatrixTransform3D(LightTransform.GetAsMatrix3D()));

                lineLight.Material = MaterialHelper.CreateMaterial(Brushes.Black, new SolidColorBrush(LightColor.Color));

                marker.Transform        = transforms;
                marker.ManipulatorModel = lineLight.Model;
                ModelRepresentation     = marker;
                return(marker);
            }

            return(new LotEditorItemMarker(this));
        }