Exemplo n.º 1
0
        protected unsafe virtual void modelPanel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (_playing)
            {
                return;
            }

            ModelPanel         panel    = sender as ModelPanel;
            ModelPanelViewport viewport = panel.CurrentViewport;

            Vector3?point;

            if (_boneSelection.IsMoving() && SelectedBone != null)
            {
                Vector3 transform = GetLocalTransform(e, viewport,
                                                      GetBoneWorldMtx(),
                                                      GetBoneInvWorldMtx(),
                                                      GetBoneParentTransformMtx(),
                                                      _boneSelection,
                                                      out point);

                if (Alt && !_createdNewBone)
                {
                    if (SelectedBone is MDL0BoneNode)
                    {
                        _createdNewBone = true;

                        MDL0BoneNode b       = SelectedBone as MDL0BoneNode;
                        MDL0Node     model   = b.Model;
                        MDL0BoneNode newBone = new MDL0BoneNode();
                        string       name    = "NewBone";
                        if (model != null)
                        {
                            name += "0";
                            int id = 1;
Top:
                            foreach (MDL0BoneNode x in model._linker.BoneCache)
                            {
                                if (x.Name == name)
                                {
                                    name = "NewBone" + id++;
                                    goto Top;
                                }
                            }
                            newBone._entryIndex = model._linker.BoneCache.Length;
                        }

                        newBone.Name       = name;
                        newBone.FrameState = newBone.BindState = FrameState.Neutral;

                        b.AddChild(newBone);

                        newBone.RecalcFrameState();
                        newBone.RecalcBindState(false, false, false);

                        model?._linker.RegenerateBoneCache();
                        BonesPanel?.Reset();

                        SelectedBone = newBone;
                    }
                }

                if (point != null)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        _boneTransform[(int)ControlType](i, transform[i]);
                    }

                    _boneSelection._lastPointLocal = GetBoneInvWorldMtx() * point.Value;
                }
            }

            if (_vertexSelection.IsMoving() && VertexLoc != null)
            {
                Vector3 center    = VertexLoc.Value;
                Vector3 transform = GetLocalTransform(e, viewport,
                                                      Matrix.TranslationMatrix(center),
                                                      Matrix.TranslationMatrix(-center),
                                                      Matrix.Identity,
                                                      _vertexSelection,
                                                      out point);

                if (point != null)
                {
                    switch (ControlType)
                    {
                    case TransformType.Scale:
                        foreach (Vertex3 vertex in _selectedVertices)
                        {
                            vertex.WeightedPosition = Maths.ScaleAboutPoint(vertex.WeightedPosition, center, transform);
                        }
                        break;

                    case TransformType.Rotation:
                        foreach (Vertex3 vertex in _selectedVertices)
                        {
                            vertex.WeightedPosition = Maths.RotateAboutPoint(vertex.WeightedPosition, center, transform);
                        }
                        break;

                    case TransformType.Translation:
                        foreach (Vertex3 vertex in _selectedVertices)
                        {
                            vertex.WeightedPosition += transform;
                        }
                        break;
                    }

                    _vertexLoc = null;
                    _vertexSelection._lastPointLocal = Matrix.TranslationMatrix(-VertexLoc.Value) * point.Value;
                }

                UpdateModel();
            }

            bool allowHighlight    = !DoNotHighlightOnMouseMove;
            bool draggingSelection = viewport.Selecting;

            //if not dragging a point AND (highlighting is allowed, or not but selecting)
            if (!_boneSelection.IsMoving() &&
                !_vertexSelection.IsMoving() &&
                (allowHighlight || (!allowHighlight && draggingSelection)))
            {
                HighlightStuff(e, panel);
            }
        }
Exemplo n.º 2
0
        protected unsafe virtual void modelPanel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (_playing)
            {
                return;
            }

            ModelPanel         panel    = sender as ModelPanel;
            ModelPanelViewport viewport = panel.CurrentViewport;

            bool moving = _scaling || _rotating || _translating;

            if (moving)
            {
                Vector3?point;
                if (SelectedBone != null)
                {
                    Vector3 transform = GetLocalTransform(e, viewport,
                                                          GetBoneWorldMtx(),
                                                          GetBoneInvWorldMtx(),
                                                          GetBoneParentTransformMtx(),
                                                          out point);

                    if (Alt && !_createdNewBone)
                    {
                        if (SelectedBone is MDL0BoneNode)
                        {
                            _createdNewBone = true;

                            MDL0BoneNode b       = SelectedBone as MDL0BoneNode;
                            MDL0Node     model   = b.Model;
                            MDL0BoneNode newBone = new MDL0BoneNode();
                            newBone.Scale                           = new Vector3(1.0f);
                            newBone._bindMatrix                     =
                                newBone._inverseBindMatrix          =
                                    newBone._frameMatrix            =
                                        newBone._inverseFrameMatrix =
                                            Matrix.Identity;
                            if (model != null)
                            {
                                int    id   = 1;
                                string name = "NewBone0";
Top:
                                foreach (MDL0BoneNode x in model._linker.BoneCache)
                                {
                                    if (x.Name == name)
                                    {
                                        name = "NewBone" + id++;
                                        goto Top;
                                    }
                                }
                                newBone.Name        = name;
                                newBone._entryIndex = model._linker.BoneCache.Length;
                                b.AddChild(newBone);
                                model._linker.RegenerateBoneCache();
                            }
                            else
                            {
                                newBone.Name = "NewBone";
                                b.AddChild(newBone);
                            }

                            if (BonesPanel != null)
                            {
                                BonesPanel.Reset();
                            }

                            SelectedBone = newBone;
                        }
                    }

                    if (point != null)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            _boneTransform[(int)ControlType](i, transform[i]);
                        }

                        _lastPointLocal = GetBoneInvWorldMtx() * point.Value;
                    }
                }
                else if (VertexLoc != null)
                {
                    Vector3 center    = VertexLoc.Value;
                    Vector3 transform = GetLocalTransform(e, viewport,
                                                          Matrix.TranslationMatrix(center),
                                                          Matrix.TranslationMatrix(-center),
                                                          Matrix.Identity,
                                                          out point);

                    if (point != null)
                    {
                        switch (ControlType)
                        {
                        case TransformType.Scale:
                            foreach (Vertex3 vertex in _selectedVertices)
                            {
                                vertex.WeightedPosition = Maths.ScaleAboutPoint(vertex.WeightedPosition, center, transform);
                            }
                            break;

                        case TransformType.Rotation:
                            foreach (Vertex3 vertex in _selectedVertices)
                            {
                                vertex.WeightedPosition = Maths.RotateAboutPoint(vertex.WeightedPosition, center, transform);
                            }
                            break;

                        case TransformType.Translation:
                            foreach (Vertex3 vertex in _selectedVertices)
                            {
                                vertex.WeightedPosition += transform;
                            }
                            break;
                        }

                        _vertexLoc      = null;
                        _lastPointLocal = Matrix.TranslationMatrix(-VertexLoc.Value) * point.Value;
                    }

                    UpdateModel();
                }
            }

            //if not dragging a point AND (highlighting is allowed, or not but selecting)
            if (!moving && (!DoNotHighlightOnMouseMove || (DoNotHighlightOnMouseMove && viewport.Selecting)))
            {
                HighlightStuff(e, panel);
            }
        }