コード例 #1
0
ファイル: Form1.cs プロジェクト: dmalpica/meshmixer-api
        private void remesh_test()
        {
            mm.RemoteControl rc = new mm.RemoteControl();
            rc.Initialize();

            // you could import a mesh using this command:
            //sc.AppendSceneCommand_AppendMeshFile(...);

            StoredCommands sc = new StoredCommands();

            // [RMS] select entire mesh
            sc.AppendBeginToolCommand("select");
            sc.AppendSelectCommand_All();
            // [RMS] start remesh tool
            sc.AppendBeginToolCommand("remesh");
            // [RMS] configure parameters
            sc.AppendToolParameterCommand("density", 0.2f);
            sc.AppendToolParameterCommand("smooth", 1.0f);
            // [RMS] accept result
            sc.AppendCompleteToolCommand("accept");
            sc.AppendCompleteToolCommand("cancel");     // [RMS] to exit out of selection

            rc.ExecuteCommands(sc);

            // you could export result using this command
            //sc.AppendSceneCommand_ExportMeshFile_CurrentSelection(...);
            rc.Shutdown();
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: dmalpica/meshmixer-api
        private void smooth_groups_test()
        {
            mm.RemoteControl rc = new mm.RemoteControl();
            rc.Initialize();

            List <int> o  = get_selected_objects(rc);
            int        id = o[0];

            StoredCommands sc   = new StoredCommands();
            uint           key1 = sc.AppendSceneCommand_ListFaceGroups(id);

            rc.ExecuteCommands(sc);
            vectori groupv = new vectori();

            sc.GetSceneCommandResult_ListFaceGroups(key1, groupv);
            var vGroups = groupv.ToList();

            foreach (int g in vGroups)
            {
                StoredCommands cmd = new StoredCommands();
                vectori        v   = new vectori()
                {
                    g
                };
                cmd.AppendSelectCommand_ByFaceGroups(v);
                cmd.AppendBeginToolCommand("smoothBoundary");
                cmd.AppendToolParameterCommand("preserveGroupBorders", false);
                cmd.AppendToolParameterCommand("preserveBoundary", true);
                cmd.AppendCompleteToolCommand("accept");
                cmd.AppendCompleteToolCommand("cancel");
                rc.ExecuteCommands(cmd);
            }

            rc.Shutdown();
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: dmalpica/meshmixer-api
        private void pivotTransformButton_Click(object sender, EventArgs e)
        {
            mm.RemoteControl rc = new mm.RemoteControl();
            rc.Initialize();

            // in world units
            Vector3f frameTranslation = new Vector3f(0, 0, 20);

            int objectID = get_object_id(rc, "object");
            int pivotID  = get_object_id(rc, "pivot");

            List <int> selected = get_selected_objects(rc);

            System.Diagnostics.Debug.Assert(selected != null && selected.Count == 1 && selected[0] == objectID, "the mesh you want to move must be selected");

            frame3f  pivotFrame       = get_pivot_frame(rc, pivotID);
            Vector3f x                = new Vector3f(pivotFrame.tan1_x, pivotFrame.tan1_y, pivotFrame.tan1_z);
            Vector3f y                = new Vector3f(pivotFrame.tan2_x, pivotFrame.tan2_y, pivotFrame.tan2_z);
            Vector3f z                = new Vector3f(pivotFrame.origin_x, pivotFrame.origin_y, pivotFrame.origin_z);
            Vector3f worldTranslation = frameTranslation[0] * x
                                        + frameTranslation[1] * y + frameTranslation[2] * z;

            vec3f translate = worldTranslation.toVec3f();

            StoredCommands sc = new StoredCommands();

            sc.AppendBeginToolCommand("transform");
            sc.AppendToolParameterCommand("translationWorld", translate);
            rc.ExecuteCommands(sc);


            rc.Shutdown();
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: dmalpica/meshmixer-api
        private void align_test()
        {
            mm.RemoteControl rc = new mm.RemoteControl();
            rc.Initialize();

            int sourcePivotID = get_object_id(rc, "source_pivot");
            int destPivotID   = get_object_id(rc, "dest_pivot");

            System.Diagnostics.Debug.Assert(sourcePivotID != -1, "scene must have pivot with name source_pivot");
            System.Diagnostics.Debug.Assert(destPivotID != -1, "scene must have pivot with name dest_pivot");

            List <int> selected = get_selected_objects(rc);

            System.Diagnostics.Debug.Assert(selected != null && selected.Count == 1, "the mesh you want to move must be selected");

            StoredCommands sc = new StoredCommands();

            sc.AppendBeginToolCommand("align");
            sc.AppendToolParameterCommand("sourceType", 13);
            sc.AppendToolParameterCommand("targetType", 13);
            sc.AppendToolUtilityCommand("setSourcePivot", sourcePivotID);
            sc.AppendToolUtilityCommand("setDestPivot", destPivotID);
            //sc.AppendToolParameterCommand("flip", true);
            sc.AppendCompleteToolCommand("accept");
        }
コード例 #5
0
        public static DMesh3 ReadMeshFromMM(RemoteControl rc, int nObjectId, bool bWantColors = false)
        {
            Debug.Assert(bWantColors == false); // haven't implemented yet

            DMesh3 mesh = new DMesh3(MeshComponents.FaceGroups);

            int NV           = rc.GetVertexCount(nObjectId);
            int nBatchSize   = 750;
            int nFullBatches = NV / nBatchSize;

            for (int i = 0; i < nFullBatches; ++i)
            {
                Vector3f[] vPositions = rc.GetVertexPositionInRange(nObjectId, i * nBatchSize, nBatchSize);
                for (int j = 0; j < vPositions.Length; ++j)
                {
                    int vid = mesh.AppendVertex((Vector3d)vPositions[j]);
                    Debug.Assert(vid == i * nBatchSize + j);
                }
            }
            int nLeft = NV - nFullBatches * nBatchSize;

            if (nLeft > 0)
            {
                Vector3f[] vPositions = rc.GetVertexPositionInRange(nObjectId, nFullBatches * nBatchSize, nLeft);
                for (int j = 0; j < nLeft; ++j)
                {
                    int vid = mesh.AppendVertex((Vector3d)vPositions[j]);
                }
            }

            int NT = rc.GetTriangleCount(nObjectId);

            nBatchSize   = 750;
            nFullBatches = NT / nBatchSize;
            for (int i = 0; i < nFullBatches; ++i)
            {
                Index3i[] vTriangles = rc.GetTrianglesInRange(nObjectId, i * nBatchSize, nBatchSize);
                int[]     vGroups    = rc.GetFaceGroupsInRange(nObjectId, i * nBatchSize, nBatchSize);
                for (int j = 0; j < vTriangles.Length; ++j)
                {
                    int vid = mesh.AppendTriangle(vTriangles[j], vGroups[j]);
                    Debug.Assert(vid == i * nBatchSize + j);
                }
            }
            nLeft = NT - nFullBatches * nBatchSize;
            if (nLeft > 0)
            {
                Index3i[] vTriangles = rc.GetTrianglesInRange(nObjectId, nFullBatches * nBatchSize, nLeft);
                int[]     vGroups    = rc.GetFaceGroupsInRange(nObjectId, nFullBatches * nBatchSize, nLeft);
                for (int j = 0; j < nLeft; ++j)
                {
                    int vid = mesh.AppendTriangle(vTriangles[j], vGroups[j]);
                }
            }

            return(mesh);
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: dmalpica/meshmixer-api
        private int get_object_id(mm.RemoteControl rc, string name)
        {
            StoredCommands sc  = new StoredCommands();
            uint           key = sc.AppendSceneCommand_FindObjectByName(name);

            rc.ExecuteCommands(sc);
            any_result r   = new any_result();
            bool       bOK = sc.GetSceneCommandResult_FindObjectByName(key, r);

            return((bOK) ? r.i : -1);
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: dmalpica/meshmixer-api
        private frame3f get_pivot_frame(mm.RemoteControl rc, int pivotID)
        {
            StoredCommands sc  = new StoredCommands();
            uint           key = sc.AppendSceneCommand_GetObjectFrame(pivotID);

            rc.ExecuteCommands(sc);
            frame3f f   = new frame3f();
            bool    bOK = sc.GetSceneCommandResult_GetObjectFrame(key, f);

            return(f);
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: dmalpica/meshmixer-api
        private Vector3f get_pivot_location(mm.RemoteControl rc, int pivotID)
        {
            StoredCommands sc  = new StoredCommands();
            uint           key = sc.AppendSceneCommand_GetObjectFrame(pivotID);

            rc.ExecuteCommands(sc);
            frame3f f   = new frame3f();
            bool    bOK = sc.GetSceneCommandResult_GetObjectFrame(key, f);

            return(new Vector3f(f.origin_x, f.origin_y, f.origin_z));
        }
コード例 #9
0
ファイル: Form1.cs プロジェクト: dmalpica/meshmixer-api
        private List <int> get_selected_objects(mm.RemoteControl rc)
        {
            StoredCommands sc  = new StoredCommands();
            uint           key = sc.AppendSceneCommand_ListSelectedObjects();

            rc.ExecuteCommands(sc);
            vectori v   = new vectori();
            bool    bOK = sc.GetSceneCommandResult_ListSelectedObjects(key, v);

            return(v.ToList());
        }
コード例 #10
0
ファイル: Form1.cs プロジェクト: dmalpica/meshmixer-api
        private void plane_cut_test()
        {
            mm.RemoteControl rc = new mm.RemoteControl();
            rc.Initialize();

            StoredCommands sc = new StoredCommands();

            sc.AppendBeginToolCommand("planeCut");
            sc.AppendCompleteToolCommand("accept");

            rc.ExecuteCommands(sc);

            rc.Shutdown();
        }
コード例 #11
0
ファイル: Form1.cs プロジェクト: dmalpica/meshmixer-api
        private void queriesButton_Click(object sender, EventArgs e)
        {
            mm.RemoteControl rc = new mm.RemoteControl();
            rc.Initialize();

            AxisAlignedBox3f bounds = new AxisAlignedBox3f();

            rc.SelectionBoundingBox(ref bounds);
            Vector3f Min = bounds.Min, Max = bounds.Max;

            outputTextBox.Text = String.Format("Bounding Box [{0},{1},{2}]  [{3},{4},{5}]",
                                               Min[0], Min[1], Min[2], Max[0], Max[1], Max[2]);

            rc.Shutdown();
        }
コード例 #12
0
ファイル: Form1.cs プロジェクト: dmalpica/meshmixer-api
        /*
         *  [RMS] test code for dropping solid parts
         */

        private void drop_part_test_1()
        {
            mm.RemoteControl rc = new mm.RemoteControl();
            rc.Initialize();


            // [RMS] use a raycast to get an initial drop point for the part
            StoredCommands raycast_cmd = new StoredCommands();
            vec3f          ray_o       = new vec3f();

            ray_o.x = 0.0f; ray_o.y = 0.0f; ray_o.z = -100.0f;
            vec3f ray_d = new vec3f();

            ray_d.x = 0.0f; ray_d.y = 0.0f; ray_d.z = 1.0f;
            uint rayhit_key = raycast_cmd.AppendQueryCommand_FindRayIntersection(ray_o, ray_d);

            rc.ExecuteCommands(raycast_cmd);
            frame3f f    = new frame3f();
            bool    bHit = raycast_cmd.GetQueryResult_FindRayIntersection(rayhit_key, f);

            System.Diagnostics.Debug.Assert(bHit);

            // begin the interactive part drop. Note that the path is hardcoded to the part .obj file, however
            // the type of slash doesn't matter, we handle that internally
            StoredCommands drop_part_cmd = new StoredCommands();

            drop_part_cmd.AppendActionCommand_DropSolidPartAtPoint(
                "C:\\Users\\schmidr\\Documents/meshmixer\\libraries\\parts\\default\\Primitives\\1397485517_00001_cone.obj",
                //                "C:/GitHub/meshmixer/meshmixer_devel/libraries\\parts\\default\\Primitives\\1397485517_00001_cone.obj",
                f, 0.0f, true);
            drop_part_cmd.AppendToolParameterCommand("operationType", 0);
            rc.ExecuteCommands(drop_part_cmd);


            // accept the drop position
            //StoredCommands accept_cmd = new StoredCommands();
            //accept_cmd.AppendActionCommand_AcceptDropPart();
            //rc.ExecuteCommands(accept_cmd);


            rc.Shutdown();
        }
コード例 #13
0
ファイル: Form1.cs プロジェクト: dmalpica/meshmixer-api
        private void set_mesh_color_test()
        {
            mm.RemoteControl rc = new mm.RemoteControl();
            rc.Initialize();

            List <int> selected = get_selected_objects(rc);

            System.Diagnostics.Debug.Assert(selected != null && selected.Count == 1, "the mesh you want to color must be selected");

            vec3f c = new vec3f();

            c.x = 1.0f; c.y = 0.0f; c.z = 0.0f;

            StoredCommands sc = new StoredCommands();

            sc.ViewControl_SetTriangleColorMode(0);
            sc.AppendSceneCommand_SetAllVertexColors(selected[0], c);
            sc.AppendSceneCommand_UpdateMesh(selected[0]);

            rc.ExecuteCommands(sc);

            rc.Shutdown();
        }
コード例 #14
0
ファイル: Form1.cs プロジェクト: dmalpica/meshmixer-api
        private void drop_part_test_2()
        {
            mm.RemoteControl rc = new mm.RemoteControl();
            rc.Initialize();


            // [RMS] use a raycast to get an initial drop point for the part
            StoredCommands raycast_cmd = new StoredCommands();
            vec3f          ray_o       = new vec3f();

            ray_o.x = 0.0f; ray_o.y = 0.0f; ray_o.z = -100.0f;
            vec3f ray_d = new vec3f();

            ray_d.x = 0.0f; ray_d.y = 0.0f; ray_d.z = 1.0f;
            uint rayhit_key = raycast_cmd.AppendQueryCommand_FindRayIntersection(ray_o, ray_d);

            rc.ExecuteCommands(raycast_cmd);
            frame3f f    = new frame3f();
            bool    bHit = raycast_cmd.GetQueryResult_FindRayIntersection(rayhit_key, f);

            System.Diagnostics.Debug.Assert(bHit);

            StoredCommands drop_part_cmd2 = new StoredCommands();

            drop_part_cmd2.AppendActionCommand_DropSolidPartAtPoint(
                "C:/Users/schmidr/Documents/meshmixer/libraries/parts/user/My Parts/1469555765_00001_solidWatchTest.obj", f, 0.0f, true);
            drop_part_cmd2.AppendToolParameterCommand("operationType", 0);
            rc.ExecuteCommands(drop_part_cmd2);

            // accept the drop position
            //StoredCommands accept_cmd = new StoredCommands();
            //accept_cmd.AppendActionCommand_AcceptDropPart();
            //rc.ExecuteCommands(accept_cmd);

            rc.Shutdown();
        }
コード例 #15
0
        // [RMS] This doesn't work because I did something stupid when
        //   making unwrap meshes. The set of triangles aren't the same. argh.
        public static DMesh3 ConvertUnwrapToUVs(RemoteControl rc, out DenseMeshUVSet UVSet, string mainName = "main")
        {
            int mainID = rc.FindObjectByName(mainName);

            rc.CompactMesh(mainID);
            DMesh3 mainMesh = ReadMeshFromMM(rc, mainID);

            Debug.Assert(mainMesh.IsCompact);

            List <int> all       = rc.ListObjects();
            List <int> unwrapIDs = new List <int>();

            foreach (int id in all)
            {
                string sName = rc.GetObjectName(id);
                if (sName.StartsWith("unwrap", StringComparison.OrdinalIgnoreCase))
                {
                    unwrapIDs.Add(id);
                }
            }
            int[] AllGroups = FaceGroupUtil.FindAllGroups(mainMesh).ToArray();


            Dictionary <int, DMesh3> Unwraps = new Dictionary <int, DMesh3>();

            foreach (int id in unwrapIDs)
            {
                DMesh3        mesh      = ReadMeshFromMM(rc, id);
                HashSet <int> subGroups = FaceGroupUtil.FindAllGroups(mesh);
                Debug.Assert(subGroups.Count == 1);
                int gid = subGroups.ToArray()[0];
                Unwraps[gid] = mesh;
            }


            UVSet = new DenseMeshUVSet();
            UVSet.TriangleUVs.resize(mainMesh.TriangleCount);
            Dictionary <Index2i, int> UVSetMap = new Dictionary <Index2i, int>();

            Dictionary <int, int> GroupCounters = new Dictionary <int, int>();

            for (int i = 0; i < AllGroups.Length; ++i)
            {
                GroupCounters[AllGroups[i]] = 0;
            }

            for (int ti = 0; ti < mainMesh.TriangleCount; ++ti)
            {
                Index3i main_tri = mainMesh.GetTriangle(ti);
                int     gid      = mainMesh.GetTriangleGroup(ti);
                int     sub_tid  = GroupCounters[gid];
                GroupCounters[gid]++;

                DMesh3  SubMesh = Unwraps[gid];
                Index3i sub_tri = SubMesh.GetTriangle(sub_tid);

                for (int j = 0; j < 3; ++j)
                {
                    int     sub_vid = sub_tri[j];
                    Index2i key     = new Index2i(gid, sub_vid);
                    int     uvset_idx;
                    if (UVSetMap.TryGetValue(key, out uvset_idx) == false)
                    {
                        Vector3d v  = SubMesh.GetVertex(sub_vid);
                        Vector2f uv = new Vector2f((float)v.x, (float)v.z);
                        uvset_idx     = UVSet.AppendUV(uv);
                        UVSetMap[key] = uvset_idx;
                    }
                    sub_tri[j] = uvset_idx;
                }

                UVSet.TriangleUVs[ti] = sub_tri;
            }

            return(mainMesh);
        }