Esempio n. 1
0
        public bool Select(SceneNode node, int geometryID = 0)
        {
            SelectableSceneNode n = node as SelectableSceneNode;

            if (n != null)
            {
                if (!multiSelect)
                {
                    Clear();
                }

                //n.Selected = true;
                //selectedNodes.Add(n);

                SelectionElement se = new SelectionElement(n, geometryID);
                se.Highlight();

                selection.Add(se);
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        public void Highlight()
        {
            PhongPatchPNTriangleGeometry g = Origin.Geometries[GeometryID] as PhongPatchPNTriangleGeometry;

            if (g != null && PatchID >= 0)
            {
                IDrawable r = g.ExportRange(PatchID);

                Node = new SelectableSceneNode(r)
                {
                    Selected = true, Priority = 100
                };
                Origin.Add(Node);
            }
            else
            {
                SelectableSceneNode n = Origin as SelectableSceneNode;
                if (n != null)
                {
                    n.Selected = true;
                    Node       = n;
                }
            }
        }
Esempio n. 3
0
        public bool Select(Double2 xy, out PickingResult result)
        {
            bool unselect = inputHandler.IsKeyPressed(Key.ShiftLeft);
            List <PickingResult> r;

            result = null;
            if (sg.Pick(xy, 5, out r))
            {
                if (Validator == null)
                {
                    result = r[0];
                }
                else
                {
                    bool success = false;
                    for (int i = 0; i < r.Count; ++i)
                    {
                        result = r[i];
                        if (Validator(result))
                        {
                            success = true;
                            break;
                        }
                    }
                    if (!success)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }

            if (Pick != null)
            {
                Pick(result, unselect);
            }

            int geometryID = result.GeometryIndex;


            int id = result.PrimitiveIndex;
            PhongPatchPNTriangleGeometry g = result.Node.Geometries[geometryID] as PhongPatchPNTriangleGeometry;

            if (g != null && patchSelectionEnabled)
            {
                int patchID = g.GetRangeIndex(id);
                int index   = GetIndex(result.Node, patchID);

                if (index < 0 && !unselect)
                {
                    if (!multiSelect)
                    {
                        Clear();
                    }

                    SelectionElement se = new SelectionElement(result.Node, geometryID, patchID);
                    se.Highlight();
                    selection.Add(se);
                }
                else if (index >= 0 && unselect)
                {
                    Unselect(index);
                }
                return(true);
            }
            else
            {
                SelectableSceneNode n = result.Node as SelectableSceneNode;
                if (n != null)
                {
                    int index = GetIndex(result.Node, -1);

                    if (index < 0 && !unselect)
                    {
                        if (!multiSelect)
                        {
                            Clear();
                        }

                        SelectionElement se = new SelectionElement(result.Node, geometryID);
                        se.Highlight();
                        selection.Add(se);
                    }
                    else if (index >= 0 && unselect)
                    {
                        Unselect(index);
                    }
                    return(true);
                }
            }
            return(false);
            //}
            //return false;
            //else if (!multiSelect)
            //    Clear();
        }
Esempio n. 4
0
        private void MouseMove(System.Drawing.Point pt, Double2 xy, MouseKey buttons)
        {
            if (buttons == MouseKey.Left && enabled)
            {
                if (shifting && !lockPositions)
                {
                    double  zoomNormalizedScreenHeight = camera.ZoomFactor;
                    Double2 offset = (xy - lastPos);
                    offset.X *= zoomNormalizedScreenHeight * camera.AspectRatio;
                    offset.Y *= zoomNormalizedScreenHeight;

                    Double3 o = camera.Up * offset.Y + camera.Right * offset.X;

                    for (int i = 0; i < selectionHandler.Count; ++i)
                    {
                        SelectableSceneNode node = selectionHandler[i];

                        Double4x4 m = node.AbsoluteTransformation;
                        m.ClearTranslation();
                        Double4x4 mInv = m;
                        mInv.Invert();

                        Double4x4 translation = (mInv * Double4x4.CreateTranslation(o) * m);
                        if (!xDirectionEnabled)
                        {
                            translation.M14 = 0;
                        }
                        if (!yDirectionEnabled)
                        {
                            translation.M24 = 0;
                        }
                        if (!zDirectionEnabled)
                        {
                            translation.M34 = 0;
                        }

                        node.RelativeTransformation = translation * node.RelativeTransformation;
                        OnNodeChanged(node);
                    }

                    lastPos = xy;
                }
                else if (directionEditingEnabled)
                {
                    for (int i = 0; i < selectionHandler.Count; ++i)
                    {
                        IInteractiveDirectionSceneNode n = selectionHandler[i] as IInteractiveDirectionSceneNode;
                        //object test = selectionHandler[i];
                        if (n != null)
                        {
                            if (rotateAroundViewDirectionOnly)
                            {
                                Double3 dir = selectionHandler[i].AbsoluteTransformation.Inverted().TransformDirection(camera.LookAt).Normalized();
                                n.SetEndInPlane(xy, camera, dir);
                            }
                            else
                            {
                                n.SetEnd(xy, camera);
                            }

                            OnNodeChanged(selectionHandler[i]);
                        }
                    }
                }

                if (selectionHandler.Count > 0)
                {
                    OnPositionChanged();
                }
            }
        }