Exemple #1
0
        /// <summary>
        /// Finds the bounding box for the specified visual.
        /// </summary>
        /// <param name="visual">
        /// The visual.
        /// </param>
        /// <param name="transform">
        /// The transform of the visual.
        /// </param>
        /// <returns>
        /// A <see cref="Rect3D"/>.
        /// </returns>
        public static Rect3D FindBounds(this Visual3D visual, Transform3D transform)
        {
            var bounds         = Rect3D.Empty;
            var childTransform = Transform3DHelper.CombineTransform(visual.Transform, transform);
            var model          = GetModel(visual);

            if (model != null)
            {
                // apply transform
                var transformedBounds = childTransform.TransformBounds(model.Bounds);
                if (!double.IsNaN(transformedBounds.X))
                {
                    bounds.Union(transformedBounds);
                }
            }

            foreach (var child in GetChildren(visual))
            {
                var b = FindBounds(child, childTransform);
                bounds.Union(b);
            }

            return(bounds);
        }
Exemple #2
0
        /// <summary>
        /// Gets the object space to world space transformation for the given Visual3D
        /// </summary>
        /// <param name="visual3DStart">The visual whose world space transform should be found</param>
        /// <param name="viewport">The containing Viewport3D for the Visual3D</param>
        /// <returns>The world space transformation</returns>
        internal static Matrix3D GetWorldTransformationMatrix(Visual3D visual3DStart, out Viewport3DVisual viewport)
        {
            DependencyObject dependencyObject = visual3DStart;
            Matrix3D         worldTransform   = Matrix3D.Identity;

            while (dependencyObject != null)
            {
                Visual3D visual3D = dependencyObject as Visual3D;

                // we reached the top
                if (visual3D == null)
                {
                    break;
                }

                Transform3D transform = (Transform3D)visual3D.GetValue(Visual3D.TransformProperty);

                if (transform != null)
                {
                    transform.Append(ref worldTransform);
                }

                dependencyObject = VisualTreeHelper.GetParent(dependencyObject);
            }

            if (dependencyObject != null)
            {
                viewport = (Viewport3DVisual)dependencyObject;
            }
            else
            {
                viewport = null;
            }

            return(worldTransform);
        }
Exemple #3
0
        private void AddVisualForVisualizationObject(IRemoteVisualizationObject visualizationObject)
        {
            Visual3D visual = ((I3DVisualizationObject)visualizationObject).Visual3D;

            this.SortingVisualRoot.Children.Add(visual);
        }
Exemple #4
0
 public void Traverse <T>(Visual3D visual, Action <T, Transform3D> action) where T : Model3D
 {
     Traverse(visual, Transform3D.Identity, action);
 }
Exemple #5
0
        private void Create()
        {
            if (source == null)
            {
                return;
            }
            IDataConsumer  cons = this;
            string         x    = source.Xaml;
            string         s    = ProcessXaml(x);
            Visual3D       v3d  = null;
            object         ob   = System.Windows.Markup.XamlReader.Parse(s);
            MeshGeometry3D mg   = null;

            if (ob is Visual3D)
            {
                v3d = ob as Visual3D;
                List <MeshGeometry3D> lm = new List <MeshGeometry3D>();
                Detect(v3d, lm);
                xaml = x;
                if (source == null)
                {
                    return;
                }
                // MeshGeometry3D pattern = Mesh;
                foreach (AlName an in al)
                {
                    if (an.alias == null)
                    {
                        return;
                    }
                    if (an.name == null)
                    {
                        return;
                    }
                }
                foreach (IMeasurement mea in m)
                {
                    if (mea == null)
                    {
                        return;
                    }
                }

                /* mg.Positions.Clear();
                 * for (int i = 0; i < pattern.Positions.Count; i++)
                 * {
                 *   Point3D pat = pattern.Positions[i];
                 *   //Point3D p = mg.Positions[i];
                 *   for (int l = 0; l < 3; l++)
                 *   {
                 *       al[l].alias[al[l].name] = pat.GetCoordinate(l);
                 *   }
                 *   cons.UpdateChildrenData();
                 *   Point3D p = new Point3D((double)m[0].Parameter(), (double)m[1].Parameter(), (double)m[2].Parameter());
                 *   mg.Positions.Add(p);
                 *   this.FullReset();
                 * }*/
                lmesh.Clear();
                foreach (MeshGeometry3D mh in lm)
                {
                    Point3DCollection pp = mh.Positions;
                    Point3DCollection p  = new Point3DCollection();
                    foreach (Point3D pat in pp)
                    {
                        for (int l = 0; l < 3; l++)
                        {
                            al[l].alias[al[l].name] = pat.GetCoordinate(l);
                        }
                        cons.UpdateChildrenData();
                        Point3D pr = new Point3D((double)m[0].Parameter(), (double)m[1].Parameter(), (double)m[2].Parameter());
                        p.Add(pr);
                        this.FullReset();
                    }
                    mh.Positions = p;
                    lmesh.Add(p);
                }
                //xaml = System.Windows.Markup.XamlWriter.Save(v3d);
            }
        }
Exemple #6
0
 public RenderItemListener(Visual3D visual, AegirLib.Behaviour.World.Transform item)
 {
     this.Visual = visual;
     this.Item   = item;
 }
Exemple #7
0
 public NodeItem(Visual3D visual, ulong nodeId, MatrixTransform3D transform)
 {
     NodeId    = nodeId;
     Visual    = visual;
     Transform = transform;
 }
Exemple #8
0
 public void Export(Visual3D visual, Patient p)
 {
     this.patient = p;
     Traverse <GeometryModel3D>(visual, this.ExportModel);
     finished = true;
 }
Exemple #9
0
 public static void SetPrimitiveData(Visual3D target, SelectablePrimitive value)
 {
     target.SetValue(PrimitiveDataProperty, value);
 }
Exemple #10
0
 public static SelectablePrimitive GetPrimitiveData(Visual3D target)
 {
     return((SelectablePrimitive)target.GetValue(PrimitiveDataProperty));
 }
Exemple #11
0
 /// <summary>
 /// Exports the specified visual.
 /// </summary>
 /// <param name="visual">
 /// The visual.
 /// </param>
 public void Export(Visual3D visual)
 {
     this.ExportHeader();
     Visual3DHelper.Traverse <GeometryModel3D>(visual, this.ExportModel);
 }
Exemple #12
0
        public void AddDummy(AegirLib.Behaviour.World.Transform transformBehaviour)
        {
            Visual3D dummyVisual = VisualFactory.GetDummyVisual();

            AddVisual(dummyVisual, transformBehaviour);
        }
Exemple #13
0
 public SceneActor ResolveRenderItem(Visual3D visual)
 {
     return(VisualFactory?.GetRenderItem(RenderMode, visual));
 }
Exemple #14
0
 public void Select(Visual3D visual)
 {
     this.SelectedObject = visual;
 }
Exemple #15
0
        /// <summary>
        /// Creates facets
        /// </summary>
        protected void CreateFacets()
        {
            if (facetCount > 0)
            {
                return;
            }
            Visual3D v3d = Visual;

            if (mesh == null)
            {
                return;
            }
            mesh.Create(out areas, out centers);
            Vector3DCollection coll = mesh.Normals;

            facetCount = coll.Count;
            colors     = new Color[facetCount];
            int n = coll.Count;

            normals = new double[n][];
            for (int i = 0; i < n; i++)
            {
                System.Windows.Media.Media3D.Vector3D v = coll[i];
                double[] x = new double[] { v.X, v.Y, v.Z };
                normals[i] = x;
            }
            if (bp == null)
            {
                return;
            }
            List <object>         tt  = new List <object>();
            List <List <object> > par = new List <List <object> >();

            System.Windows.Media.Int32Collection  ic = bp.DoubleIndex;
            System.Windows.Media.DoubleCollection dc = bp.DoubleParameters;
            Double a  = 0;
            int    kk = 0;

            foreach (int i in ic)
            {
                tt.Add(new ArrayReturnType(a, new int[] { i }, false));
                List <object> pp = new List <object>();
                par.Add(pp);
                for (int j = 0; j < facetCount; j++)
                {
                    double[] x = new double[i];
                    pp.Add(x);
                    for (int k = 0; k < i; k++)
                    {
                        x[k] = dc[kk];
                        ++kk;
                    }
                }
            }
            types      = tt.ToArray();
            parameters = new object[par.Count][];
            for (int i = 0; i < par.Count; i++)
            {
                parameters[i] = par[i].ToArray();
            }
        }
Exemple #16
0
        private void HitTest(Point mousePosition, out GeometryModel3D hitGeometryModel3D, out Visual3D hitVisual3D)
        {
            if (SimpleHitTestRadioButton.IsChecked ?? false)
            {
                // The most simple hit testing is done with calling HitTest method.
                // This is the easiest option and can be used when we want to get the first hit object and do not need to filter hit objects.
                _lastHitResult = VisualTreeHelper.HitTest(MainViewport, mousePosition) as RayMeshGeometry3DHitTestResult;
            }
            else if (CallbackRadioButton.IsChecked ?? false)
            {
                // A more advanced hit testing is done with using hit result callback.
                // There we decide if we want to continue hit testing or stop the hit testing.
                // This way it is possible to get all 3D objects under the mouse or do hit test filtering.
                PointHitTestParameters pointParams = new PointHitTestParameters(mousePosition);
                VisualTreeHelper.HitTest(MainViewport, null, HitTestResultHandler, pointParams);
            }
            else if (FilterAndCallbackRadioButton.IsChecked ?? false)
            {
                // When using hit result callback we can filter the hit objects in the HitTestResultHandler.
                // But a better way to filer hit objects is to filter with using HitTestFilterCallback.
                // This way we can skip hit testing on entire parts of the 3D hierarchy.
                PointHitTestParameters pointParams = new PointHitTestParameters(mousePosition);
                VisualTreeHelper.HitTest(MainViewport, HitTestFilterCallback, HitTestResultHandler, pointParams);
            }

            if (_lastHitResult != null)
            {
                hitGeometryModel3D = _lastHitResult.ModelHit as GeometryModel3D;
                hitVisual3D        = _lastHitResult.VisualHit;
            }
            else
            {
                hitGeometryModel3D = null;
                hitVisual3D        = null;
            }
        }
Exemple #17
0
        private Visual3D EnsureChild(Visual3D currentChild, Shape3DMaterial material)
        {
            Visual3D newChild = null;

            if (material != null)
            {
                if (material.HasElement)
                {
                    // We need a Viewport2DVisual3D to display an element.
                    if (currentChild is Viewport2DVisual3D)
                    {
                        newChild = currentChild;
                    }
                    else
                    {
                        //Viewbox viewbox = new Viewbox();
                        //viewbox.StretchDirection = StretchDirection.Both;
                        //viewbox.Stretch = Stretch.Fill;

                        Border border = new Border();
                        border.UseLayoutRounding = true;
                        border.Background        = Brushes.Green;
                        //border.Child = viewbox;

                        Viewport2DVisual3D viewport = new Viewport2DVisual3D();
                        viewport.Visual = border;

                        newChild = viewport;
                    }

                    // Set the appropriate caching strategy.
                    CacheScale cacheScale = CacheScale;
                    if (cacheScale == null)
                    {
                        // Remove any VisualBrush caching.
                        RenderOptions.SetCachingHint(newChild, CachingHint.Unspecified);

                        // Remove any BitmapCache.
                        ((Viewport2DVisual3D)newChild).CacheMode = null;
                    }
                    else if (cacheScale.IsAuto)
                    {
                        // Remove any BitmapCache.
                        ((Viewport2DVisual3D)newChild).CacheMode = null;

                        // Specify VisualBrush caching with 2x min and max
                        // thresholds.
                        RenderOptions.SetCachingHint(newChild, CachingHint.Cache);
                        RenderOptions.SetCacheInvalidationThresholdMinimum(newChild, 0.5);
                        RenderOptions.SetCacheInvalidationThresholdMaximum(newChild, 2.0);
                    }
                    else
                    {
                        // Remove any VisualBrush caching.
                        RenderOptions.SetCachingHint(newChild, CachingHint.Unspecified);

                        // Set a BitmapCache with the appropriate scale.
                        BitmapCache bitmapCache = ((Viewport2DVisual3D)newChild).CacheMode as BitmapCache;
                        if (bitmapCache == null)
                        {
                            ((Viewport2DVisual3D)newChild).CacheMode = new BitmapCache(cacheScale.Scale);
                        }
                        else
                        {
                            bitmapCache.RenderAtScale = cacheScale.Scale;
                        }
                    }
                }
                else
                {
                    Debug.Assert(material.HasMaterial);

                    // We need a ModelVisual3D to display the material.
                    if (currentChild is ModelVisual3D)
                    {
                        Debug.Assert(((ModelVisual3D)currentChild).Content is GeometryModel3D);
                        newChild = currentChild;
                    }
                    else
                    {
                        newChild = new ModelVisual3D();
                        ((ModelVisual3D)newChild).Content = new GeometryModel3D();
                    }
                }
            }

            return(newChild);
        }
 /// <summary>
 /// Determines if the specified visual is transparent.
 /// </summary>
 /// <param name="visual">
 /// The visual.
 /// </param>
 /// <returns>
 /// True if the visual is transparent.
 /// </returns>
 private bool IsVisualTransparent(Visual3D visual)
 {
     return(ElementSortingHelper.IsTransparent(visual));
 }
Exemple #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScreenGeometryBuilder"/> class.
 /// </summary>
 /// <param name="visual">
 /// The visual.
 /// </param>
 protected ScreenGeometryBuilder(Visual3D visual)
 {
     this.visual = visual;
 }
Exemple #20
0
 public void Start(Visual3D snappedPrimitive)
 {
     currentDragVector       = new Vector3D(0, 0, 0);
     currentSnappedPrimitive = snappedPrimitive;
     originalDuplicate       = null;
 }
Exemple #21
0
        /// <summary>
        /// Gets the distance squared.
        /// </summary>
        /// <param name="position">
        /// The position.
        /// </param>
        /// <param name="visual">
        /// The visual.
        /// </param>
        /// <returns>
        /// The get distance squared.
        /// </returns>
        public static double GetDistanceSquared(Point3D position, Visual3D visual)
        {
            var bounds = Visual3DHelper.FindBounds(visual, Transform3D.Identity);

            return(Point3D.Subtract(bounds.Location, position).LengthSquared);
        }
Exemple #22
0
 public void Reset()
 {
     currentSnappedPrimitive = null;
     currentDuplicate        = null;
     originalDuplicate       = null;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BillboardGeometryBuilder"/> class.
 /// </summary>
 /// <param name="visual">
 /// The visual.
 /// </param>
 public BillboardGeometryBuilder(Visual3D visual)
     : base(visual)
 {
 }
        void eventSource3D_MouseEnter(object sender, Ab3d.DirectX.Common.EventManager3D.Mouse3DEventArgs e)
        {
            if (e.RayHitResult != null)
            {
                Log("MouseEnter: " + e.RayHitResult.HitSceneNode);

                // We need to save the hit SceneNode.
                // This way we will be able to change the material back in the eventSource3D_MouseLeave event handler.
                _selectedVisual3D = e.RayHitResult.HitSceneNode.GetVisual3D();

                var wpfGeometryModel3DNode = e.RayHitResult.HitSceneNode as WpfGeometryModel3DNode;
                if (wpfGeometryModel3DNode != null)
                {
                    _selectedGeometryModel3D = wpfGeometryModel3DNode.GeometryModel3D;
                }
                else
                {
                    _selectedGeometryModel3D = null;
                }


                var dxRayInstancedHitTestResult = e.RayHitResult as DXRayInstancedHitTestResult;
                if (dxRayInstancedHitTestResult != null)
                {
                    _selectedInstanceIndex = dxRayInstancedHitTestResult.HitInstanceIndex;
                }


                if (_wireCrossVisual3D == null)
                {
                    _wireCrossVisual3D = new WireCrossVisual3D()
                    {
                        LineColor     = Colors.DeepPink,
                        LineThickness = 2,
                        LinesLength   = 10
                    };
                }

                _wireCrossVisual3D.Position = e.RayHitResult.HitPosition.ToWpfPoint3D();

                if (!MainViewport3D.Children.Contains(_wireCrossVisual3D))
                {
                    MainViewport3D.Children.Add(_wireCrossVisual3D);
                }
            }
            else
            {
                _selectedVisual3D        = null;
                _selectedGeometryModel3D = null;
                _selectedInstanceIndex   = -1;

                Log("MouseEnter: <null>");
                return;
            }

            if (_selectedInstanceIndex != -1)
            {
                ChangeInstanceColor(_selectedInstanceIndex, Colors.Red);
            }
            else
            {
                ChangeColor(e, Colors.Red);
            }
        }
Exemple #25
0
 /// <summary>
 /// GetDescendantBounds returns the union of all of the content bounding
 /// boxes of the specified Visual3D's sub-graph.
 /// </summary>
 public static Rect3D GetDescendantBounds(Visual3D reference)
 {
     CheckVisualReferenceArgument(reference);
     return(reference.VisualDescendantBounds);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LineGeometryBuilder"/> class.
 /// </summary>
 /// <param name="visual">
 /// The visual parent of the geometry (the transform is calculated from this object).
 /// </param>
 public LineGeometryBuilder(Visual3D visual)
     : base(visual)
 {
 }
Exemple #27
0
 public void Export(Visual3D visual, Patient p)
 {
     //this.ExportHeader();
     this.patient = p;
     Traverse <GeometryModel3D>(visual, this.ExportModel);
 }
Exemple #28
0
        private void UpdateDisplay()
        {
            if (current_game != Setting.param.Kind ||
                current_quality != Setting.param.Quality ||
                current_resolution != Setting.param.Resolution)
            {
                // ------------------------------
                // Change mesh resolution
                // ------------------------------
                int div;
                switch (Setting.param.Quality)
                {
                case 1:
                    div = 30;
                    break;

                case 2:
                    div = 60;
                    break;

                case 3:
                default:
                    div = 90;
                    break;
                }
                double SamplingInterval = Math.PI / div;
                UpdateMeshResolution((short)(1 << Setting.param.Resolution), SamplingInterval);

                // ------------------------------
                // Create game rule
                // ------------------------------
                if (Setting.param.Kind == GameKind.GAMEKIND_OTHELLO)
                {
                    rule = new RuleOthello(pixelization);
                }
                else
                {
                    rule = new RuleIgo(pixelization);
                }
                Title = rule.GetName();

                // ------------------------------
                // Remove all pieces
                // ------------------------------
                PieceArray2D = new UIElement[rule.GetMaxIndex()];
                PieceArray3D = new Visual3D[rule.GetMaxIndex()];
                canvas_projection_piece.Children.Clear();
                PieceContainer.Children.Clear();

                TerritoryArray2D = new UIElement[rule.GetMaxIndex()];
                TerritoryArray3D = new Visual3D[rule.GetMaxIndex()];
                canvas_projection_territory.Children.Clear();
                TerritoryContainer.Children.Clear();

                // ------------------------------
                // Select UI panel
                // ------------------------------
#if false
                UserInterfaceArea.Children.Clear();
                if (Setting.param.Kind == GameKind.GAMEKIND_IGO)
                {
                    ConsoleIgo control = new ConsoleIgo();
                    UserInterfaceArea.Children.Add(control);
                    UserInterface = control;
                }
                else
                {
                    ConsoleOthello control = new ConsoleOthello();
                    UserInterfaceArea.Children.Add(control);
                    UserInterface = control;
                }
#else
                if (Setting.param.Kind == GameKind.GAMEKIND_IGO)
                {
                    UserInterface         = PanelIgo;
                    TabItemIgo.IsSelected = true;
                }
                else
                {
                    UserInterface             = PanelOthello;
                    TabItemOthello.IsSelected = true;
                }
#endif
                UserInterface.SetOnConfigurationsChanged(delegate(object sender, System.EventArgs e) { UpdateDisplay(); });
                UserInterface.SetGameRule(rule);

                // ------------------------------
                // Prepare initial piece arrangements
                // ------------------------------
                rule.SetPieceManipulator(ManipulatePiece);
                rule.SetInitialPieces();

                // ------------------------------
                // Remember current settings
                // ------------------------------
                current_resolution = Setting.param.Resolution;
                current_quality    = Setting.param.Quality;
                current_game       = Setting.param.Kind;
            }

            SphereMaterial.Brush = new SolidColorBrush(Setting.param.ForeColor);
            MapBase.Fill         = SphereMaterial.Brush;
        }
Exemple #29
0
        private void RemoveVisualForVisualizationObject(VisualizationObject visualizationObject)
        {
            Visual3D visual = ((I3DVisualizationObject)visualizationObject).Visual3D;

            this.SortingVisualRoot.Children.Remove(visual);
        }
        /// <summary>
        /// Gets the object space to world space transformation for the given Visual3D
        /// </summary>
        /// <param name="visual">The visual whose world space transform should be found</param>
        /// <returns>The world space transformation</returns>
        internal static Matrix3D GetWorldTransformationMatrix(Visual3D visual)
        {
            Viewport3DVisual ignored;

            return(GetWorldTransformationMatrix(visual, out ignored));
        }