Ejemplo n.º 1
0
        public void Apply()
        {
            Vector3d Origin    = BendPlane.Origin;
            Vector3d BendAxis1 = BendPlane.Z;

            float sideSign = (BendAngle > 0) ? 1 : -1;
            MeshVertexSelection vertices = new MeshVertexSelection(Mesh);

            foreach (int vid in Mesh.VertexIndices())
            {
                Vector3d v    = Mesh.GetVertex(vid);
                float    sign = BendPlane.DistanceToPlaneSigned((Vector3f)v, 1);
                if (sign * sideSign > 0)
                {
                    vertices.Select(vid);
                }
            }

            Quaterniond rotation = Quaterniond.AxisAngleD(BendPlane.X, -BendAngle);

            foreach (int vid in vertices)
            {
                Vector3d v    = Mesh.GetVertex(vid);
                Vector3d vNew = rotation * (v - Origin) + Origin;
                Mesh.SetVertex(vid, vNew);
            }
        }
Ejemplo n.º 2
0
        public void EndStroke()
        {
            if (CurrentStroke.Count >= 2)
            {
                DMesh3 mesh = Target.Mesh;

                TransformSequence toScene = SceneTransforms.ObjectToSceneXForm(Target);

                List <int> tris1 = new List <int>(), tris2 = new List <int>();
                Ray3f      first = CurrentStroke[0], last = CurrentStroke[CurrentStroke.Count - 1];

                Vector3f v0 = PlaneFrameS.RayPlaneIntersection(first.Origin, first.Direction, 2);
                Vector3f v1 = PlaneFrameS.RayPlaneIntersection(last.Origin, last.Direction, 2);

                Vector3f planeN = Vector3f.Cross(first.Direction, last.Direction);
                Frame3f  planeF = new Frame3f((v0 + v1) / 2, planeN);

                foreach (int tid in mesh.TriangleIndices())
                {
                    Vector3f c = (Vector3f)mesh.GetTriCentroid(tid);
                    c = toScene.TransformP(c);
                    if (planeF.DistanceToPlaneSigned(c, 2) < 0)
                    {
                        tris1.Add(tid);
                    }
                    else
                    {
                        tris2.Add(tid);
                    }
                }

                double area1 = MeshMeasurements.AreaT(mesh, tris1);
                double area2 = MeshMeasurements.AreaT(mesh, tris2);

                lastSelection = new MeshFaceSelection(mesh);
                lastSelection.Select((area1 > area2) ? tris2 : tris1);
                lastSelection.LocalOptimize();

                if (OnStrokeCompletedF != null)
                {
                    OnStrokeCompletedF(Target, lastSelection);
                }
            }

            CurrentStroke.Clear();
        }