Advertisement
Guest User

Untitled

a guest
Jul 1st, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2. //
  3. // Wired
  4. //
  5. // Copyright(C) 1999-2018, tetraface Inc.
  6. //
  7. // Sample for Object plug-in for deleting faces with reserving lines
  8. // in the faces.
  9. // Created DLL must be installed in "Plugins\Object" directory.
  10. //
  11. //  オブジェクト中の辺のみを残して面を削除するオブジェクトプラグイン
  12. // のサンプル。
  13. //  作成したDLLは"Plugins\Object"フォルダに入れる必要がある。
  14. //
  15. //
  16. //---------------------------------------------------------------------------
  17.  
  18. #ifdef WIN32
  19. #define WIN32_LEAN_AND_MEAN
  20. #define NOMINMAX
  21. #include <windows.h>
  22. #endif
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <math.h>
  26. #include <vector>
  27. #include <algorithm>
  28. #include "MQPlugin.h"
  29. #include "MQBasePlugin.h"
  30. #include "MQWidget.h"
  31. #include "MQBoneManager.h"
  32. #include <wchar.h>
  33. #if __APPLE__
  34. #include "../osx/StringUtil.h"
  35. #endif
  36.  
  37. #ifdef WIN32
  38. HINSTANCE hInstance;
  39.  
  40.  
  41. //---------------------------------------------------------------------------
  42. // DllMain
  43. //---------------------------------------------------------------------------
  44. BOOL APIENTRY DllMain( HANDLE hModule,
  45. DWORD ul_reason_for_call,
  46. LPVOID lpReserved
  47. )
  48. {
  49. // リソース表示に必要なので、インスタンスを保存しておく
  50. // Store the instance because it is necessary for displaying resources.
  51. hInstance = (HINSTANCE)hModule;
  52.  
  53. // プラグインとしては特に必要な処理はないので、何もせずにTRUEを返す
  54. // There is nothing to do for a plugin. So just return TRUE.
  55. return TRUE;
  56. }
  57. #endif
  58.  
  59. //---------------------------------------------------------------------------
  60. // class WiredPlugin
  61. //---------------------------------------------------------------------------
  62. class WiredPlugin : public MQObjectPlugin
  63. {
  64. public:
  65. WiredPlugin();
  66. ~WiredPlugin();
  67.  
  68. void GetPlugInID(DWORD *Product, DWORD *ID) override;
  69. const char *GetPlugInName(void) override;
  70. const char *EnumString(int index) override;
  71. BOOL Execute(int index, MQDocument doc) override;
  72.  
  73. private:
  74. BOOL TestBone(MQDocument doc);
  75. };
  76.  
  77. MQBasePlugin *GetPluginClass()
  78. {
  79. static WiredPlugin plugin;
  80. return &plugin;
  81. }
  82.  
  83.  
  84. WiredPlugin::WiredPlugin()
  85. {
  86. }
  87.  
  88. WiredPlugin::~WiredPlugin()
  89. {
  90. }
  91.  
  92. //---------------------------------------------------------------------------
  93. // MQGetPlugInID
  94. // プラグインIDを返す。
  95. // この関数は起動時に呼び出される。
  96. //---------------------------------------------------------------------------
  97. void WiredPlugin::GetPlugInID(DWORD *Product, DWORD *ID)
  98. {
  99. // プロダクト名(制作者名)とIDを、全部で64bitの値として返す
  100. // 値は他と重複しないようなランダムなもので良い
  101. *Product = 0x56A31D35;
  102. *ID = 0x157E8680;
  103. }
  104.  
  105. //---------------------------------------------------------------------------
  106. // MQGetPlugInName
  107. // プラグイン名を返す。
  108. // この関数は[プラグインについて]表示時に呼び出される。
  109. //---------------------------------------------------------------------------
  110. const char *WiredPlugin::GetPlugInName(void)
  111. {
  112. // プラグイン名
  113. return "TestBone ";
  114. }
  115.  
  116. //---------------------------------------------------------------------------
  117. // MQEnumString
  118. // ポップアップメニューに表示される文字列を返す。
  119. // この関数は起動時に呼び出される。
  120. //---------------------------------------------------------------------------
  121. const char *WiredPlugin::EnumString(int index)
  122. {
  123. static char buffer[256];
  124.  
  125. switch(index){
  126. case 0:
  127. // Note: following $res$ means the string uses system resource string.
  128. return "TestBone";
  129. }
  130. return NULL;
  131. }
  132.  
  133. //---------------------------------------------------------------------------
  134. // MQModifyObject
  135. // メニューから選択されたときに呼び出される。
  136. //---------------------------------------------------------------------------
  137. BOOL WiredPlugin::Execute(int index, MQDocument doc)
  138. {
  139. switch(index){
  140. case 0: return TestBone(doc);
  141. }
  142. return FALSE;
  143. }
  144.  
  145.  
  146. //ワイヤー化
  147. BOOL WiredPlugin::TestBone(MQDocument doc)
  148. {
  149. MQBoneManager bone_manager(this, doc);
  150. int bone_num = bone_manager.GetBoneNum();
  151. std::vector<UINT> bone_id;
  152.  
  153. wchar_t *buf = (wchar_t *)malloc(10000);
  154.  
  155. if(bone_num > 0){
  156. bone_id.resize(bone_num);
  157. bone_manager.EnumBoneID(bone_id);
  158. for(int i=0; i<bone_num; i++)
  159. {
  160. UINT id = bone_id[i];
  161. UINT parent_id;
  162. std::wstring name;
  163. bone_manager.GetName(id, name);
  164. bone_manager.GetParent(id, parent_id);
  165. std::wstring pname;
  166. bone_manager.GetName(parent_id, pname);
  167. int child_num=0;
  168. bone_manager.GetChildNum(id, child_num);
  169. wsprintfW(buf, L"id: %u (%s), parent: %u (%s)\n child: ", id, name.c_str(), parent_id, pname.c_str());
  170. if(child_num>0)
  171. {
  172. std::vector<UINT> child_bone_id;
  173. child_bone_id.resize(child_num);
  174. bone_manager.GetChildren(id, child_bone_id);
  175. for(int k=0;k<child_num;k++)
  176. {
  177. UINT childid = child_bone_id[k];
  178. std::wstring cname;
  179. bone_manager.GetName(childid, cname);
  180. wsprintfW(buf + wcslen(buf), L"%u (%s), ", childid, cname.c_str());
  181. }
  182. }
  183. OutputDebugStringW(buf);
  184. OutputDebugStringW(L"\n");
  185.  
  186. }
  187. }
  188. free(buf);
  189.  
  190. return TRUE;
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement