Exemple #1
0
        /// <summary>
        /// Finds the nearest point and its normal.
        /// </summary>
        /// <param name="viewport">
        /// The viewport.
        /// </param>
        /// <param name="position">
        /// The position.
        /// </param>
        /// <param name="point">
        /// The point.
        /// </param>
        /// <param name="normal">
        /// The normal.
        /// </param>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <returns>
        /// The find nearest.
        /// </returns>
        public static bool FindNearest(this Viewport3DX viewport, Point position,
                                       out Vector3 point, out Vector3 normal, out Element3D model)
        {
            point  = new Vector3();
            normal = new Vector3();
            model  = null;

            var camera = viewport.Camera as ProjectionCamera;

            if (camera == null)
            {
                return(false);
            }

            var hits = FindHits(viewport, position);

            if (hits.Count > 0)
            {
                point  = hits[0].PointHit;
                normal = hits[0].NormalAtHit;
                model  = hits[0].ModelHit as Element3D;
                return(true);
            }
            else
            {
                // check for nearest points in the scene
                // TODO!!
                return(false);
            }
        }
 private void Element3DPresenter_ContentChanged(object sender, Element3D content)
 {
     if (currentContent != null)
     {
         (SceneNode as GroupNode).RemoveChildNode(currentContent.SceneNode);
         AttachChild(null);
     }
     if (Content is Element3D elem)
     {
         currentContent = elem;
         (SceneNode as GroupNode).AddChildNode(elem.SceneNode);
         AttachChild(elem);
     }
 }
Exemple #3
0
 /// <summary>
 /// Finds the nearest point and its normal.
 /// </summary>
 /// <param name="viewport">
 /// The viewport.
 /// </param>
 /// <param name="position">
 /// The position.
 /// </param>
 /// <param name="point">
 /// The point.
 /// </param>
 /// <param name="normal">
 /// The normal.
 /// </param>
 /// <param name="model">
 /// The model.
 /// </param>
 /// <param name="node"></param>
 /// <returns>
 /// The find nearest.
 /// </returns>
 public static bool FindNearest(this Viewport3DX viewport, Point position,
                                out Vector3 point, out Vector3 normal, out Element3D model, out SceneNode node)
 {
     model = null;
     node  = null;
     if (viewport.FindNearest(position.ToVector2(), out point, out normal, out var m))
     {
         if (m is Element3D ele)
         {
             model = ele;
             node  = ele.SceneNode;
         }
         else if (m is SceneNode nd)
         {
             node  = nd;
             model = null;
         }
         return(true);
     }
     return(false);
 }
        /// <summary>
        /// Traverses the Visual3D/Element3D tree and invokes the specified action on each Element3D of the specified type.
        /// </summary>
        /// <typeparam name="T">
        /// The type filter.
        /// </typeparam>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="function">
        /// The action.
        /// </param>
        public static void Traverse <T>(this Element3D element, Func <T, bool> function) where T : Element3D
        {
            var sceneNode = new SceneNode[] { element.SceneNode };

            Traverse(element, function);
        }
        /// <summary>
        /// Traverses the Visual3D/Element3D tree and invokes the specified action on each Element3D of the specified type.
        /// </summary>
        /// <typeparam name="T">
        /// The type filter.
        /// </typeparam>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="action">
        /// The action.
        /// </param>
        public static void Traverse <T>(this Element3D element, Action <T> action) where T : Element3D
        {
            var sceneNode = new SceneNode[] { element.SceneNode };

            Traverse(element, action);
        }