Example #1
1
 private void AddContours(Visual3D model1, int o, int m, int n)
 {
     var bounds = Visual3DHelper.FindBounds(model1, Transform3D.Identity);
     for (int i = 1; i < n; i++)
     {
         this.ContourPlane = new Plane3D(new Point3D(0, 0, bounds.Location.Z + bounds.Size.Z * i / n), new Vector3D(0, 0, 1));
         Visual3DHelper.Traverse<GeometryModel3D>(model1, this.AddContours);
     }
     for (int i = 1; i < m; i++)
     {
         this.ContourPlane = new Plane3D(new Point3D(0, bounds.Location.Y + bounds.Size.Y * i / m, 0), new Vector3D(0, 1, 0));
         Visual3DHelper.Traverse<GeometryModel3D>(model1, this.AddContours);
     }
     for (int i = 1; i < o; i++)
     {
         this.ContourPlane = new Plane3D(new Point3D(bounds.Location.X + bounds.Size.X * i / o, 0, 0), new Vector3D(1, 0, 0));
         Visual3DHelper.Traverse<GeometryModel3D>(model1, this.AddContours);
     }
 }
 public ManipulatorControl(ManipulatorType type, Visual3D visual)
 {
     targetVisual = visual;
     Type = type;
     Transform = targetVisual.Transform;
     Diameter = 0.5;
     double l = 5;
     switch (type)
     {
         case ManipulatorType.TranslateX:
             Normal = new Vector3D(0, 0, 1);
             Direction = new Vector3D(l, 0, 0);
             Fill = Brushes.Red;
             break;
         case ManipulatorType.TranslateY:
             Normal = new Vector3D(0, 0, 1);
             Direction = new Vector3D(0, l, 0);
             Fill = Brushes.Green;
             break;
         case ManipulatorType.TranslateZ:
             Normal = new Vector3D(0, 1, 0);
             Direction = new Vector3D(0, 0, l);
             Fill = Brushes.Blue;
             break;
     }
 }
 public BlipVisual(Visual3D visual, bool isVisualUpright, TranslateTransform3D translate, AxisAngleRotation3D rotate)
 {
     this.Visual = visual;
     this.IsVisualUpright = isVisualUpright;
     this.Translate = translate;
     this.Rotate = rotate;
 }
Example #4
0
 public void Export(Visual3D visual)
 {
     object obj = visual;
     if (CreateResourceDictionary)
         obj = WrapInResourceDictionary(obj);
     XamlWriter.Save(obj, xw);
 }
Example #5
0
 public static void RemoveChild(DependencyObject parent, Visual3D v3d)
 {
     var parentAsModelVisual3D = parent as ModelVisual3D;
     if (parentAsModelVisual3D != null)
     {
         parentAsModelVisual3D.Children.Remove(v3d);
     }
 }
 public Visual3DClickedEventArgs(Visual3D visual, MouseButtonState left, MouseButtonState right, bool hasMoved, Point position)
 {
     _Visual = visual;
     _LeftButton = left;
     _RightButton = right;
     _HasMoved = hasMoved;
     _MousePosition = position;
 }
Example #7
0
 public Point3D? HitTest(Visual3D reference, Point3D point, Vector3D direction)
 {
     if (reference != null)
     {
         var hitParams = new RayHitTestParameters(point, direction);
         hit = false;
         VisualTreeHelper.HitTest(reference, null, HitTestCallback, hitParams);
         if (hit)
         {
             return hitTestValue;
         }
     }
     return null;
 }
        /// <summary>
        /// Determines whether the specified visual is transparent.
        /// </summary>
        /// <param name="v">The v.</param>
        /// <returns>
        /// 	<c>true</c> if the specified visual is transparent; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsTransparent(Visual3D v)
        {
            var mv3D = v as ModelVisual3D;
            if (mv3D != null)
            {
                // check if Model3D is transparent
                if (IsTransparent(mv3D.Content))
                    return true;

                // check if any child Visual3D are transparent
                return mv3D.Children.Any(IsTransparent);
            }

            return false;
        }
Example #9
0
        /// <summary>
        /// Create a clone of a Visual3D
        /// </summary>
        /// <param name="v">
        /// a Visual3D
        /// </param>
        /// <returns>
        /// the clone
        /// </returns>
        public static Visual3D CreateClone(Visual3D v)
        {
            if (v is ModelUIElement3D)
            {
                var m = v as ModelUIElement3D;
                if (m.Model != null)
                {
                    /*if (m.Model.CanFreeze)
                        m.Model.Freeze();
                    if (m.Model.IsFrozen)*/
                    {
                        var clonedModel = m.Model.Clone();
                        var clonedElement = new ModelUIElement3D();
                        clonedElement.Transform = m.Transform;
                        clonedElement.Model = clonedModel;
                        return clonedElement;
                    }
                }
            }

            if (v is ModelVisual3D)
            {
                var m = v as ModelVisual3D;
                var clone = new ModelVisual3D();
                clone.Transform = m.Transform;
                if (m.Content != null && m.Content.CanFreeze)
                {
                    m.Content.Freeze();
                    var clonedModel = m.Content.Clone();
                    clone.Content = clonedModel;
                }

                if (m.Children.Count > 0)
                {
                    foreach (var child in m.Children)
                    {
                        var clonedChild = CreateClone(child);
                        clone.Children.Add(clonedChild);
                    }
                }

                return clone;
            }

            return null;
        }
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors

        internal RayMeshGeometry3DHitTestResult(
            Visual3D visualHit,
            Model3D modelHit,
            MeshGeometry3D meshHit,
            Point3D pointHit,
            double distanceToRayOrigin, 
            int vertexIndex1,
            int vertexIndex2,
            int vertexIndex3,
            Point barycentricCoordinate) : base (visualHit, modelHit)
            {
                _meshHit = meshHit;
                _pointHit = pointHit;
                _distanceToRayOrigin = distanceToRayOrigin;
                _vertexIndex1 = vertexIndex1;
                _vertexIndex2 = vertexIndex2;
                _vertexIndex3 = vertexIndex3;
                _barycentricCoordinate = barycentricCoordinate;
            }
Example #11
0
 /// <summary>
 ///     Notifies the element that you have removed a child.  The Element
 ///     will update the parent pointer, fire the correct events, etc.
 /// </summary>
 void IVisual3DContainer.RemoveChild(Visual3D child)
 {
     RemoveVisual3DChild(child);
 }
Example #12
0
 /// <summary>
 ///     Notifies the element that you have added a child.  The Element
 ///     will update the parent pointer, fire the correct events, etc.
 /// </summary>
 void IVisual3DContainer.AddChild(Visual3D child)
 {
     AddVisual3DChild(child);
 }
 public GeneralTransform3D TransformToAncestor(Visual3D ancestor)
 {
     Contract.Requires(ancestor != null);
     return(default(GeneralTransform3D));
 }
Example #14
0
        /// <summary>
        /// Computes the transformation matrix to go from a 3D point in the given Visual3D's coordinate space out in to
        /// the Viewport3DVisual.
        /// </summary> 
        internal static bool TryTransformToViewport3DVisual(Visual3D visual3D, out Viewport3DVisual viewport, out Matrix3D matrix)
        { 
            matrix = GetWorldTransformationMatrix(visual3D, out viewport); 

            if (viewport != null) 
            {
                matrix *= GetWorldToViewportTransform3D(viewport.Camera, viewport.Viewport);
                return true;
            } 
            else
            { 
                return false; 
            }
        } 
Example #15
0
        /// <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); 
        }
Example #16
0
        /// <summary>
        /// Returns the transform or the inverse transform between this visual and the specified ancestor.
        /// If inverse is requested but does not exist (if the transform is not invertible), null is returned.
        /// </summary>
        /// <param name="ancestor">Ancestor visual.</param>
        /// <param name="inverse">Returns inverse if this argument is true.</param>
        private GeneralTransform3D InternalTransformToAncestor(Visual3D ancestor, bool inverse)
        {            
            Debug.Assert(ancestor != null);

            // used to track if all the collected transforms on the way to the ancestor were valid
            bool success = true;
            
            DependencyObject g = this;
            Visual3D lastVisual3D = null;
            
            Matrix3D m = Matrix3D.Identity;
            GeneralTransform3DGroup group = null;

            // This while loop will walk up the visual tree until we encounter the ancestor.
            // As it does so, it will accumulate the descendent->ancestor transform.
            // In most cases, this is simply a matrix, though if we encounter a 2D node we need to
            // transform from 3D out in to 2D and then back in to 3D and continue the parent walk.
            // We will accumulate the current transform in a matrix until we encounter a 2D parent,
            // at which point we will add the matrix's current value and the transform from 3D to 2D to 3D
            // to the GeneralTransform3DGroup and continue to accumulate further transforms in the matrix again.
            // At the end of this loop, we will have 0 or more transforms in the GeneralTransform3DGroup
            // and the matrix which, if not identity, should be appended to the GeneralTransform3DGroup.
            // If, as is commonly the case, this loop terminates without encountering a 2D parent
            // we will simply use the Matrix3D.

            while ((VisualTreeHelper.GetParent(g) != null) && (g != ancestor))
            {
                Visual3D gAsVisual3D = g as Visual3D;
                if (gAsVisual3D != null)
                {
                    Transform3D transform = gAsVisual3D.Transform;
                    if (transform != null)
                    {
                        transform.Append(ref m);
                    }

                    lastVisual3D = gAsVisual3D;
                    g = VisualTreeHelper.GetParent(gAsVisual3D);
                }                
                else
                {
                    if (group == null)
                    {
                        group = new GeneralTransform3DGroup();
                    }

                    group.Children.Add(new MatrixTransform3D(m));
                    m = Matrix3D.Identity;

                    // construct the 3D to 2D to 3D transform
                    Visual gAsVisual = g as Visual;                    
                    GeneralTransform3DTo2D transform3DTo2D = lastVisual3D.TransformToAncestor(gAsVisual);

                    // now find the 3D parent of the 2D object
                    Visual3D containing3DParent = VisualTreeHelper.GetContainingVisual3D(gAsVisual);

                    // if containing3DParent is null, then the ancestor parameter is not really an ancestor
                    // break out of the loop to allow it to fail
                    if (containing3DParent == null) 
                    {
                        break;
                    }

                    GeneralTransform2DTo3D transform2DTo3D = gAsVisual.TransformToAncestor(containing3DParent);

                    // if either transform ends up being null then we don't have a transform
                    if (transform3DTo2D == null || transform2DTo3D == null)
                    {
                        // we don't want to break here because although we own't be able to create a valid transformation
                        // we also want to throw an exception if the ancestor passed in is not a valid ancestor.  We then
                        // continue the tree walk to make sure.
                        success = false;
                    }
                    else
                    {
                        group.Children.Add(new GeneralTransform3DTo2DTo3D(transform3DTo2D, transform2DTo3D));
                    }                    

                    // the last visual3D found is where we continue the search
                    g = containing3DParent;
                }
            }

            if (g != ancestor)
            {
                throw new System.InvalidOperationException(SR.Get(inverse ? SRID.Visual_NotADescendant : SRID.Visual_NotAnAncestor));
            }
            
            // construct the generaltransform3d to return and invert it if necessary
            GeneralTransform3D finalTransform = null;            

            // if we successfully found a transform then we can create it here, otherwise finalTransform stays null
            if (success)
            {
                if (group != null)
                {
                    finalTransform = group;
                }
                else
                {
                    finalTransform = new MatrixTransform3D(m);
                }
                
                if (inverse)
                {          
                    finalTransform = finalTransform.Inverse;
                }
            }

            if (finalTransform != null)
            {
                finalTransform.Freeze();
            }

            return finalTransform;
        }     
 /// <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;
 }
Example #18
0
        /// <summary>
        /// DisconnectChild
        ///
        ///    Derived classes must call this method to notify the Visual3D layer that a
        ///    child was removed from the children collection. The Visual3D layer will then call
        ///    GetVisual3DChild to find out which child has been removed.
        ///
        /// </summary>
        protected void RemoveVisual3DChild(Visual3D child)
        {
            // It is invalid to modify the children collection that we 
            // might be iterating during a property invalidation tree walk.
            if (IsVisualChildrenIterationInProgress)
            {
                throw new InvalidOperationException(SR.Get(SRID.CannotModifyVisualChildrenDuringTreeWalk));
            }

            Debug.Assert(child != null);
            Debug.Assert(child.InternalVisualParent == this);

            child.SetParent(/* newParent = */ (Visual3D) null);  // CS0121: Call is ambigious without casting null to Visual3D.
                    
            // remove the inheritance context
            RemoveSelfAsInheritanceContext(child, null);
                        
            //
            // Remove the child on all the channels 
            // this visual is being marshalled to.
            //

            for (int i = 0, limit = _proxy.Count; i < limit; i++) 
            {
                DUCE.Channel channel = _proxy.GetChannel(i);

                if (child.CheckFlagsAnd(channel, VisualProxyFlags.IsConnectedToParent))
                {
                    child.SetFlags(channel, false, VisualProxyFlags.IsConnectedToParent);
                    DUCE.IResource childResource = (DUCE.IResource)child;
                    childResource.RemoveChildFromParent(this, channel);
                    childResource.ReleaseOnChannel(channel);
                }
            }

            //
            // Force a full precompute and render pass for this visual.
            //

            Visual3D.PropagateFlags(
                this, 
                VisualFlags.IsSubtreeDirtyForPrecompute,
                VisualProxyFlags.IsSubtreeDirtyForRender);

            // 


            // Fire notifications
            child.FireOnVisualParentChanged(this);

            OnVisualChildrenChanged(/* visualAdded = */ null , child);
        }
Example #19
0
        /// <summary>
        /// Propagates the flags up to the root.
        /// </summary>
        /// <remarks>
        /// The walk stops on a node with all of the required flags set.
        /// </remarks>
        internal static void PropagateFlags(
            Visual3D e, 
            VisualFlags flags,
            VisualProxyFlags proxyFlags)
        {
            while ((e != null) && 
                   (!e.CheckFlagsAnd(flags) || !e.CheckFlagsOnAllChannels(proxyFlags)))
            {
                // These asserts are mostly for documentation when diffing the 2D/3D
                // implementations.
                Debug.Assert(!e.CheckFlagsOr(VisualFlags.ShouldPostRender),
                    "Visual3Ds should never be the root of a tree.");
                 Debug.Assert(!e.CheckFlagsOr(VisualFlags.NodeIsCyclicBrushRoot),
                    "Visual3Ds should never be the root of an ICyclicBrush.");

                e.SetFlags(true, flags);
                e.SetFlagsOnAllChannels(true, proxyFlags);

                // If our 3D parent is null call back into VisualTreeUtils to potentially
                // continue the walk in 2D.
                if (e._3DParent == null)
                {
                    Viewport3DVisual viewport = e.InternalVisualParent as Viewport3DVisual;

                    Debug.Assert((viewport == null) == (e.InternalVisualParent == null),
                        "Viewport3DVisual is the only supported 2D parent of a 3D visual.");
                    
                    if(viewport != null)
                    {
                        // We must notify the 2D visual that its contents have changed.
                        // This will cause the 2D visual to set it's content dirty flag
                        // and continue the propagation of IsDirtyForRender/Precompute.
                        viewport.Visual3DTreeChanged();

                        // continue propagating flags up the 2D world
                        Visual.PropagateFlags(viewport, flags, proxyFlags);
                    }
                        
                    // Stop propagating.  We are at the root of the 3D subtree.
                    return;
                }

                e = e._3DParent;
            }
        }
 public GeneralTransform3D TransformToDescendant(Visual3D descendant)
 {
     Contract.Requires(descendant != null);
     return(default(GeneralTransform3D));
 }
Example #21
0
        internal override void RenderContent(RenderContext ctx, bool isOnChannel)
        {
            DUCE.Channel channel = ctx.Channel;

            //
            // At this point, the visual has to be marshalled. Force
            // marshalling of the camera and viewport in case we have
            // just created a new visual resource.
            //

            Debug.Assert(IsOnChannel(channel));
            VisualProxyFlags flags = _proxy.GetFlags(channel);


            //
            // Make sure the camera resource is being marshalled properly.
            //

            if ((flags & VisualProxyFlags.Viewport3DVisual_IsCameraDirty) != 0)
            {
                Camera camera = Camera;
                if (camera != null)
                {
                    DUCE.Viewport3DVisualNode.SetCamera(
                        ((DUCE.IResource) this).GetHandle(channel),
                        ((DUCE.IResource)camera).AddRefOnChannel(channel),
                        channel);
                }
                else if (isOnChannel) /* camera == null */
                {
                    DUCE.Viewport3DVisualNode.SetCamera(
                        ((DUCE.IResource) this).GetHandle(channel),
                        DUCE.ResourceHandle.Null,
                        channel);
                }
                SetFlags(channel, false, VisualProxyFlags.Viewport3DVisual_IsCameraDirty);
            }


            //
            // Set the viewport if it's dirty.
            //

            if ((flags & VisualProxyFlags.Viewport3DVisual_IsViewportDirty) != 0)
            {
                DUCE.Viewport3DVisualNode.SetViewport(
                    ((DUCE.IResource) this).GetHandle(channel),
                    Viewport,
                    channel);
                SetFlags(channel, false, VisualProxyFlags.Viewport3DVisual_IsViewportDirty);
            }


            //we only want to recurse in the children if the visual does not have a bitmap effect
            //or we are in the BitmapVisualManager render pass

            // Visit children of this node -----------------------------------------------------------------------

            Debug.Assert(!CheckFlagsAnd(channel, VisualProxyFlags.IsContentNodeConnected),
                         "Only HostVisuals are expected to have a content node.");

            if (_children != null)
            {
                for (uint i = 0; i < _children.InternalCount; i++)
                {
                    Visual3D child = _children.InternalGetItem((int)i);

                    if (child != null)
                    {
                        if (child.CheckFlagsAnd(channel, VisualProxyFlags.IsSubtreeDirtyForRender) || // or the visual is dirty
                            !(child.IsOnChannel(channel)))                                            // or the child has not been marshalled yet.
                        {
                            child.RenderRecursive(ctx);
                        }

                        if (child.IsOnChannel(channel))
                        {
                            if (!child.CheckFlagsAnd(channel, VisualProxyFlags.IsConnectedToParent))
                            {
                                DUCE.Visual3DNode.InsertChildAt(
                                    _proxy3D.GetHandle(channel),
                                    ((DUCE.IResource)child).GetHandle(channel),
                                    /* iPosition = */ i,
                                    channel);

                                child.SetFlags(channel, true, VisualProxyFlags.IsConnectedToParent);
                            }
                        }
                    }
                }
            }
        }
Example #22
0
        // NOTE:  The code here is highly similar to RemoveChildCore in ModelVisual3D,
        //        but slightly different because the parent is 2D here.
        void IVisual3DContainer.RemoveChild(Visual3D child)
        {
            int index = child.ParentIndex;

            // It is invalid to modify the children collection that we
            // might be iterating during a property invalidation tree walk.
            if (IsVisualChildrenIterationInProgress)
            {
                throw new InvalidOperationException(SR.Get(SRID.CannotModifyVisualChildrenDuringTreeWalk));
            }

            // invalid during a VisualTreeChanged event
            VisualDiagnostics.VerifyVisualTreeChange(this);

            Debug.Assert(child != null);
            Debug.Assert(child.InternalVisualParent == this);

            VisualDiagnostics.OnVisualChildChanged(this, child, false);

            child.SetParent(/* newParent = */ (Visual)null);   // CS0121: Call is ambigious without casting null to Visual.

            // remove the inheritance context
            if (_inheritanceContextForChildren != null)
            {
                _inheritanceContextForChildren.RemoveSelfAsInheritanceContext(child, null);
            }

            //
            // Remove the child on all channels this visual is marshalled to.
            //

            for (int i = 0, limit = _proxy3D.Count; i < limit; i++)
            {
                DUCE.Channel channel = _proxy3D.GetChannel(i);

                if (child.CheckFlagsAnd(channel, VisualProxyFlags.IsConnectedToParent))
                {
                    child.SetFlags(channel, false, VisualProxyFlags.IsConnectedToParent);
                    DUCE.IResource childResource = (DUCE.IResource)child;
                    childResource.RemoveChildFromParent(this, channel);
                    childResource.ReleaseOnChannel(channel);
                }
            }

            SetFlagsOnAllChannels(true, VisualProxyFlags.IsContentDirty);

            //
            // Force a full precompute and render pass for this visual.
            //

            Visual.PropagateFlags(
                this,
                VisualFlags.IsSubtreeDirtyForPrecompute,
                VisualProxyFlags.IsSubtreeDirtyForRender);

            //


            child.FireOnVisualParentChanged(this);

            OnVisualChildrenChanged(/* visualAdded = */ null, child);
        }
Example #23
0
        // --------------------------------------------------------------------
        //
        //   Visual-to-Visual Transforms
        //
        // --------------------------------------------------------------------

        #region Visual-to-Visual Transforms

        /// <summary>
        /// Returns a transform that can be used to transform coordinates from this
        /// node to the specified ancestor, or null if the transformation cannot be created.
        /// 2D is allowed to be between the 3D nodes.
        /// </summary>
        /// <exception cref="ArgumentNullException">
        /// If ancestor is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If the ancestor Visual3D is not a ancestor of Visual3D.
        /// </exception>
        /// <exception cref="InvalidOperationException">If the Visual3Ds are not connected.</exception>
        public GeneralTransform3D TransformToAncestor(Visual3D ancestor)
        {
            if (ancestor == null)
            {
                throw new ArgumentNullException("ancestor");
            }

            VerifyAPIReadOnly(ancestor);

            return InternalTransformToAncestor(ancestor, false);
        }
Example #24
0
 /// <summary>
 /// Gets the distance from the camera for the specified visual.
 /// </summary>
 /// <param name="c">
 /// The visual.
 /// </param>
 /// <param name="cameraPos">
 /// The camera position.
 /// </param>
 /// <param name="transform">
 /// The total transform of the visual.
 /// </param>
 /// <returns>
 /// The camera distance.
 /// </returns>
 private double GetCameraDistance(Visual3D c, Point3D cameraPos, Transform3D transform)
 {
     var bounds = Visual3DHelper.FindBounds(c, transform);
     switch (this.Method)
     {
         case SortingMethod.BoundingBoxCenter:
             var mid = new Point3D(
                 bounds.X + bounds.SizeX * 0.5, bounds.Y + bounds.SizeY * 0.5, bounds.Z + bounds.SizeZ * 0.5);
             return (mid - cameraPos).LengthSquared;
         case SortingMethod.BoundingBoxCorners:
             double d = double.MaxValue;
             d = Math.Min(d, cameraPos.DistanceTo(new Point3D(bounds.X, bounds.Y, bounds.Z)));
             d = Math.Min(d, cameraPos.DistanceTo(new Point3D(bounds.X + bounds.SizeX, bounds.Y, bounds.Z)));
             d = Math.Min(
                 d, cameraPos.DistanceTo(new Point3D(bounds.X + bounds.SizeX, bounds.Y + bounds.SizeY, bounds.Z)));
             d = Math.Min(d, cameraPos.DistanceTo(new Point3D(bounds.X, bounds.Y + bounds.SizeY, bounds.Z)));
             d = Math.Min(d, cameraPos.DistanceTo(new Point3D(bounds.X, bounds.Y, bounds.Z + bounds.SizeZ)));
             d = Math.Min(
                 d, cameraPos.DistanceTo(new Point3D(bounds.X + bounds.SizeX, bounds.Y, bounds.Z + bounds.SizeZ)));
             d = Math.Min(
                 d,
                 cameraPos.DistanceTo(
                     new Point3D(bounds.X + bounds.SizeX, bounds.Y + bounds.SizeY, bounds.Z + bounds.SizeZ)));
             d = Math.Min(
                 d, cameraPos.DistanceTo(new Point3D(bounds.X, bounds.Y + bounds.SizeY, bounds.Z + bounds.SizeZ)));
             return d;
         default:
             var boundingSphere = BoundingSphere.CreateFromRect3D(bounds);
             return boundingSphere.DistanceFrom(cameraPos);
     }
 }
Example #25
0
        /// <summary>
        /// Returns a transform that can be used to transform coordinates from this
        /// node to the specified descendant, or null if the transform from descendant to "this"
        /// is non-invertible.  This is the case when 2D is between the nodes.
        ///
        /// </summary>
        /// <exception cref="ArgumentException">
        /// If the reference Visual3D is not a ancestor of the descendant Visual3D.
        /// </exception>
        /// <exception cref="ArgumentNullException">If the descendant argument is null.</exception>
        /// <exception cref="InvalidOperationException">If the Visual3Ds are not connected.</exception>
        public GeneralTransform3D TransformToDescendant(Visual3D descendant)
        {
            if (descendant == null)
            {
                throw new ArgumentNullException("descendant");
            }

            VerifyAPIReadOnly(descendant);

            return descendant.InternalTransformToAncestor(this, true);
        }       
 /// <summary>
 /// Initializes a new instance of the <see cref="BillboardGeometryBuilder"/> class.
 /// </summary>
 /// <param name="visual">
 /// The visual.
 /// </param>
 public BillboardGeometryBuilder(Visual3D visual)
     : base(visual)
 {
 }
Example #27
0
        /// <summary>
        ///     Check all the children for a bit.
        /// </summary>
        internal static bool DoAnyChildrenHaveABitSet(Visual3D pe,
                                                      VisualFlags flag)
        {

            int count = pe.InternalVisual2DOr3DChildrenCount;
            for (int i = 0; i < count; i++)
            {
                DependencyObject child = pe.InternalGet2DOr3DVisualChild(i);
                                
                Visual v = null;
                Visual3D v3D = null;
                VisualTreeUtils.AsNonNullVisual(child, out v, out v3D);
                
                if (v != null && v.CheckFlagsAnd(flag))
                {
                    return true;
                }
                else if (v3D != null && v3D.CheckFlagsAnd(flag))
                {
                    return true;
                }
            }

            return false;
        }
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors

        // Prevent 3rd parties from extending this abstract base class.
        internal RayHitTestResult(Visual3D visualHit, Model3D modelHit) : base(visualHit)
        {
            _modelHit = modelHit;
        }
Example #29
0
        //------------------------------------------------------
        //
        //  Public Properties
        //
        //------------------------------------------------------
        
        //------------------------------------------------------
        //
        //  Public Events
        //
        //------------------------------------------------------

        //------------------------------------------------------
        //
        //  Protected Methods
        //
        //------------------------------------------------------
        
        #region Protected Methods

        /// <summary>
        /// AttachChild
        ///
        ///    Derived classes must call this method to notify the Visual3D layer that a new
        ///    child appeard in the children collection. The Visual3D layer will then call the GetVisual3DChild
        ///    method to find out where the child was added.
        ///
        ///  Remark: To move a Visual3D child in a collection it must be first disconnected and then connected
        ///    again. (Moving forward we might want to add a special optimization there so that we do not
        ///    unmarshal our composition resources).
        /// </summary>
        protected void AddVisual3DChild(Visual3D child)
        {            
            // It is invalid to modify the children collection that we 
            // might be iterating during a property invalidation tree walk.
            if (IsVisualChildrenIterationInProgress)
            {
                throw new InvalidOperationException(SR.Get(SRID.CannotModifyVisualChildrenDuringTreeWalk));
            }

            Debug.Assert(child != null);
            Debug.Assert(child.InternalVisualParent == null);

            child.SetParent(this);
            
            // set the inheritance context so databinding, etc... work
            ProvideSelfAsInheritanceContext(child, null);
            
            // The child already might be dirty. Hence we need to propagate dirty information
            // from the parent and from the child.
            Visual3D.PropagateFlags(
                this, 
                VisualFlags.IsSubtreeDirtyForPrecompute, 
                VisualProxyFlags.IsSubtreeDirtyForRender);

            Visual3D.PropagateFlags(
                child, 
                VisualFlags.IsSubtreeDirtyForPrecompute, 
                VisualProxyFlags.IsSubtreeDirtyForRender);

            // 


            // Fire notifications
            OnVisualChildrenChanged(child, /* visualRemoved = */ null);
            
            child.FireOnVisualParentChanged(null);
        }
 /// <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)
 {
 }
Example #31
0
        internal void SetParent(Visual3D newParent)
        {
            _2DParent.ClearValue(this);
            _3DParent = newParent;

            Debug.Assert(InternalVisualParent == newParent);
        }
 void MS.Internal.IVisual3DContainer.RemoveChild(Visual3D child)
 {
 }
 public System.Windows.Media.Media3D.GeneralTransform2DTo3D TransformToAncestor(System.Windows.Media.Media3D.Visual3D ancestor)
 {
     Contract.Requires(ancestor != null);
     return(default(System.Windows.Media.Media3D.GeneralTransform2DTo3D));
 }
 protected void RemoveVisual3DChild(Visual3D child)
 {
 }
Example #35
0
 /// <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);
 }
 public GeneralTransform3D TransformToAncestor(Visual3D ancestor)
 {
     return(default(GeneralTransform3D));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PointGeometryBuilder"/> class.
 /// </summary>
 /// <param name="visual">
 /// The visual.
 /// </param>
 public PointGeometryBuilder(Visual3D visual)
     : base(visual)
 {
 }
 public GeneralTransform3D TransformToDescendant(Visual3D descendant)
 {
     return(default(GeneralTransform3D));
 }
Example #39
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; 
        }
 protected void AddVisual3DChild(Visual3D child)
 {
 }
 /// <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;
 }
 void MS.Internal.IVisual3DContainer.AddChild(Visual3D child)
 {
 }