Exemple #1
0
        /// <summary>
        /// Set the position of the object frame for this SO without moving the mesh in the scene.
        /// The input frame is the new object frame. So, this is a frame "in scene coordinates" unless
        /// this object has a parent SceneObject (ie is not a child of Scene directly). In that case
        /// the frame needs to be specified relative to that SO. An easy way to do this is to via
        ///   obj_pivot = GetLocalFrame(Object).FromFrame( SceneTransforms.SceneToObject(pivot_in_scene) )
        /// TODO: specify frame coordpace as input argument?
        /// </summary>
        public void RepositionPivot(Frame3f objFrame)
        {
            //if (Parent is FScene == false)
            //    throw new NotSupportedException("DMeshSO.RepositionMeshFrame: have not tested this!");

            Frame3f curFrame = this.GetLocalFrame(CoordSpace.ObjectCoords);
            bool    bNormals = mesh.HasVertexNormals;

            // map vertices to new frame
            foreach (int vid in mesh.VertexIndices())
            {
                Vector3f v = (Vector3f)mesh.GetVertex(vid);
                v = curFrame.FromFrameP(ref v);
                v = objFrame.ToFrameP(ref v);
                mesh.SetVertex(vid, v);

                if (bNormals)
                {
                    Vector3f n = mesh.GetVertexNormal(vid);
                    n = curFrame.FromFrameV(ref n);
                    n = objFrame.ToFrameV(ref n);
                    mesh.SetVertexNormal(vid, n);
                }
            }

            // set new object frame
            SetLocalFrame(objFrame, CoordSpace.ObjectCoords);

            fast_mesh_update(bNormals, false);
            post_mesh_modified();
        }
        public void Precompute_SingleVectorBarycentric()
        {
            int N = DisplaceMesh.MaxTriangleID;

            BaryFaceDisplacements = new BaryDisplace[N];

            //foreach ( int vid in DisplaceMesh.VertexIndices() ) {
            gParallel.ForEach <int>(DisplaceMesh.VertexIndices(), (vid) => {
                Vector3d pos             = DisplaceMesh.GetVertex(vid);
                int tid                  = BaseSpatial.FindNearestTriangle(pos);
                DistPoint3Triangle3 dist = MeshQueries.TriangleDistance(BaseMesh, tid, pos);
                Vector3f dv              = (Vector3f)(pos - dist.TriangleClosest);
                Frame3f triFrame         = BaseMesh.GetTriFrame(tid);
                Vector3f relVec          = triFrame.ToFrameV(dv);


                BaryFaceDisplacements[vid] = new BaryDisplace()
                {
                    tID = tid,
                    a   = (float)dist.TriangleBaryCoords.x,
                    b   = (float)dist.TriangleBaryCoords.y,
                    c   = (float)dist.TriangleBaryCoords.z,
                    dv  = relVec
                };
            });
        }
Exemple #3
0
        public static void AppendMeshSO(DMeshSO appendTo, DMeshSO append)
        {
            FScene scene = appendTo.GetScene();

            if (scene.IsSelected(appendTo))
            {
                scene.Deselect(appendTo);
            }
            if (scene.IsSelected(append))
            {
                scene.Deselect(append);
            }

            Frame3f  f1     = appendTo.GetLocalFrame(CoordSpace.ObjectCoords);
            Vector3f scale1 = appendTo.GetLocalScale();
            Frame3f  f2     = append.GetLocalFrame(CoordSpace.ObjectCoords);
            Vector3f scale2 = append.GetLocalScale();

            DMesh3 mesh1 = appendTo.Mesh;

            DMesh3 mesh2 = append.Mesh;

            foreach (int vid in mesh2.VertexIndices())
            {
                // convert point in mesh2 to scene coords
                Vector3f v2 = (Vector3f)mesh2.GetVertex(vid);
                v2 *= scale2;
                Vector3f v2s = f2.FromFrameP(v2);

                // transfer that scene coord into local coords of mesh1
                Vector3f v2in1 = f1.ToFrameP(v2s);
                v2in1 /= scale1;
                mesh2.SetVertex(vid, v2in1);

                if (mesh1.HasVertexNormals && mesh2.HasVertexNormals)
                {
                    Vector3f n   = mesh2.GetVertexNormal(vid);
                    Vector3f ns  = f2.FromFrameV(n);
                    Vector3f ns2 = f1.ToFrameV(ns);
                    mesh2.SetVertexNormal(vid, ns2);
                }
            }

            MeshEditor editor = new MeshEditor(mesh1);

            editor.AppendMesh(mesh2);

            appendTo.NotifyMeshEdited();

            // [TODO] change record!

            scene.RemoveSceneObject(append, false);
        }
Exemple #4
0
        public static void ToFrame(IDeformableMesh mesh, Frame3f f)
        {
            int  NV          = mesh.MaxVertexID;
            bool bHasNormals = mesh.HasVertexNormals;

            for (int vid = 0; vid < NV; ++vid)
            {
                if (mesh.IsVertex(vid))
                {
                    Vector3D v  = mesh.GetVertex(vid);
                    Vector3D vf = f.ToFrameP((Vector3F)v);
                    mesh.SetVertex(vid, vf);
                    if (bHasNormals)
                    {
                        Vector3F n  = mesh.GetVertexNormal(vid);
                        Vector3F nf = f.ToFrameV(n);
                        mesh.SetVertexNormal(vid, nf);
                    }
                }
            }
        }