Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

514 lines
16 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: d3drmmeshbuilder3obj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // d3drmMeshBuilderObj.cpp : Implementation of CDirectApp and DLL registration.
  11. #include "stdafx.h"
  12. #include "Direct.h"
  13. #include "dms.h"
  14. #include "d3drmMeshBuilder3Obj.h"
  15. #include "d3drmMaterial2Obj.h"
  16. #include "d3drmMeshObj.h"
  17. #include "d3drmFrame3Obj.h"
  18. #include "d3drmFace2Obj.h"
  19. #include "d3drmFaceArrayObj.h"
  20. #include "d3drmTexture3Obj.h"
  21. #include "d3drmVisualObj.h"
  22. extern HRESULT BSTRtoGUID(LPGUID,BSTR);
  23. CONSTRUCTOR(_dxj_Direct3dRMMeshBuilder3, {});
  24. DESTRUCTOR(_dxj_Direct3dRMMeshBuilder3, {});
  25. GETSET_OBJECT(_dxj_Direct3dRMMeshBuilder3);
  26. CLONE_R(_dxj_Direct3dRMMeshBuilder3,Direct3DRMMeshBuilder3);
  27. GETNAME_R(_dxj_Direct3dRMMeshBuilder3);
  28. SETNAME_R(_dxj_Direct3dRMMeshBuilder3);
  29. GETCLASSNAME_R(_dxj_Direct3dRMMeshBuilder3);
  30. ADDDESTROYCALLBACK_R(_dxj_Direct3dRMMeshBuilder3);
  31. DELETEDESTROYCALLBACK_R(_dxj_Direct3dRMMeshBuilder3);
  32. //CLONETO_RX(_dxj_Direct3dRMMeshBuilder3, MeshBuilder3, IID_IDirect3DRMMeshBuilder3);
  33. PASS_THROUGH_CAST_2_R(_dxj_Direct3dRMMeshBuilder3, generateNormals, GenerateNormals, float,(float),long,(DWORD));
  34. PASS_THROUGH1_R(_dxj_Direct3dRMMeshBuilder3, setQuality, SetQuality, d3drmRenderQuality)
  35. PASS_THROUGH1_R(_dxj_Direct3dRMMeshBuilder3, setColor, SetColor, d3dcolor)
  36. PASS_THROUGH_CAST_1_R(_dxj_Direct3dRMMeshBuilder3, setAppData, SetAppData, long,(DWORD));
  37. PASS_THROUGH1_R(_dxj_Direct3dRMMeshBuilder3, setPerspective, SetPerspective, long); //BOOL
  38. PASS_THROUGH_CAST_2_R(_dxj_Direct3dRMMeshBuilder3, setVertexColor, SetVertexColor, long,(DWORD),d3dcolor,(DWORD));
  39. PASS_THROUGH3_R(_dxj_Direct3dRMMeshBuilder3, setColorRGB,SetColorRGB,d3dvalue,d3dvalue,d3dvalue)
  40. PASS_THROUGH3_R(_dxj_Direct3dRMMeshBuilder3, scaleMesh, Scale, d3dvalue, d3dvalue, d3dvalue);
  41. PASS_THROUGH3_R(_dxj_Direct3dRMMeshBuilder3, translate, Translate, d3dvalue, d3dvalue, d3dvalue);
  42. PASS_THROUGH2_R(_dxj_Direct3dRMMeshBuilder3, setTextureTopology, SetTextureTopology, long, long); //BOOL
  43. PASS_THROUGH_CAST_3_R(_dxj_Direct3dRMMeshBuilder3, setTextureCoordinates, SetTextureCoordinates, long,(DWORD), d3dvalue,(float), d3dvalue,(float));
  44. PASS_THROUGH_CAST_3_R(_dxj_Direct3dRMMeshBuilder3, getTextureCoordinates, GetTextureCoordinates, long,(DWORD), d3dvalue*,(float*), d3dvalue*,(float*));
  45. PASS_THROUGH_CAST_4_R(_dxj_Direct3dRMMeshBuilder3, setVertexColorRGB, SetVertexColorRGB, long,(DWORD), d3dvalue,(float), d3dvalue,(float), d3dvalue,(float));
  46. PASS_THROUGH_CAST_1_R(_dxj_Direct3dRMMeshBuilder3, setColorSource, SetColorSource, d3drmColorSource, (enum _D3DRMCOLORSOURCE));
  47. PASS_THROUGH_CAST_1_R(_dxj_Direct3dRMMeshBuilder3, getBox, GetBox, D3dRMBox *,(D3DRMBOX *))
  48. GET_DIRECT_R(_dxj_Direct3dRMMeshBuilder3, getAppData, GetAppData, long);
  49. GET_DIRECT_R(_dxj_Direct3dRMMeshBuilder3, getQuality, GetQuality, d3drmRenderQuality);
  50. GET_DIRECT_R(_dxj_Direct3dRMMeshBuilder3, getPerspective, GetPerspective, long);
  51. GET_DIRECT_R(_dxj_Direct3dRMMeshBuilder3, getVertexCount, GetVertexCount, int);
  52. GET_DIRECT_R(_dxj_Direct3dRMMeshBuilder3, getColorSource, GetColorSource, d3drmColorSource);
  53. GET_DIRECT1_R(_dxj_Direct3dRMMeshBuilder3, getVertexColor, GetVertexColor, d3dcolor, long);
  54. PASS_THROUGH_CAST_4_R(_dxj_Direct3dRMMeshBuilder3, setVertex, SetVertex, long,(DWORD), d3dvalue,(float), d3dvalue,(float), d3dvalue,(float));
  55. PASS_THROUGH_CAST_4_R(_dxj_Direct3dRMMeshBuilder3, setNormal, SetNormal, long,(DWORD), d3dvalue,(float), d3dvalue,(float), d3dvalue,(float));
  56. GET_DIRECT_R(_dxj_Direct3dRMMeshBuilder3, getFaceCount, GetFaceCount, int );
  57. DO_GETOBJECT_ANDUSEIT_R(_dxj_Direct3dRMMeshBuilder3, addMesh, AddMesh, _dxj_Direct3dRMMesh);
  58. DO_GETOBJECT_ANDUSEIT_R(_dxj_Direct3dRMMeshBuilder3, addFace, AddFace, _dxj_Direct3dRMFace2);
  59. DO_GETOBJECT_ANDUSEIT_R(_dxj_Direct3dRMMeshBuilder3, setMaterial, SetMaterial, _dxj_Direct3dRMMaterial2)
  60. RETURN_NEW_ITEM_R(_dxj_Direct3dRMMeshBuilder3, getFaces, GetFaces, _dxj_Direct3dRMFaceArray);
  61. RETURN_NEW_ITEM_R(_dxj_Direct3dRMMeshBuilder3, createMesh,CreateMesh,_dxj_Direct3dRMMesh)
  62. RETURN_NEW_ITEM_R(_dxj_Direct3dRMMeshBuilder3, createFace, CreateFace, _dxj_Direct3dRMFace2);
  63. /////////////////////////////////////////////////////////////////////////////
  64. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::addVertex(d3dvalue x, d3dvalue y, d3dvalue z, int *index)
  65. {
  66. *index = m__dxj_Direct3dRMMeshBuilder3->AddVertex(x,y,z);
  67. return S_OK;
  68. }
  69. /////////////////////////////////////////////////////////////////////////////
  70. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::addNormal(d3dvalue x, d3dvalue y, d3dvalue z, int *index)
  71. {
  72. *index = m__dxj_Direct3dRMMeshBuilder3->AddNormal(x,y,z);
  73. return S_OK;
  74. }
  75. /////////////////////////////////////////////////////////////////////////////
  76. //FOR JAVA
  77. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::addFacesJava(long vcount, float *vertices,
  78. long ncount, float *normals, long *data, I_dxj_Direct3dRMFaceArray **array)
  79. {
  80. HRESULT hr;
  81. LPDIRECT3DRMFACEARRAY lpArray;
  82. __try{
  83. hr = m__dxj_Direct3dRMMeshBuilder3->AddFaces((DWORD)vcount/3, (struct _D3DVECTOR *)vertices, ncount/3, (struct _D3DVECTOR *)normals, (unsigned long *)data, &lpArray);
  84. }
  85. __except(1,1){
  86. return E_INVALIDARG;
  87. }
  88. INTERNAL_CREATE(_dxj_Direct3dRMFaceArray, lpArray, array);
  89. return hr;
  90. }
  91. /////////////////////////////////////////////////////////////////////////////
  92. //STDMETHOD(Save)(BSTR fname, d3drmXofFormat format, d3dSaveOptions save);
  93. //
  94. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::save(BSTR Name, d3drmXofFormat ft, d3drmSaveFlags op)
  95. {
  96. USES_CONVERSION;
  97. LPCTSTR pszName = W2T(Name); // Now convert to ANSI
  98. return m__dxj_Direct3dRMMeshBuilder3->Save(pszName, (enum _D3DRMXOFFORMAT)ft, (DWORD) op );
  99. }
  100. /////////////////////////////////////////////////////////////////////////////
  101. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::loadFromFile(BSTR filename, VARIANT id, long flags, I_dxj_Direct3dRMLoadTextureCallback3 *callme, IUnknown *useMe)
  102. {
  103. D3DRMLOADTEXTURE3CALLBACK d3dtcb = NULL;
  104. LPVOID pArgs = NULL;
  105. TextureCallback3 *tcb = NULL;
  106. HRESULT hr;
  107. if( callme )
  108. {
  109. tcb = new TextureCallback3;
  110. if( tcb )
  111. {
  112. tcb->c = callme;
  113. tcb->pUser = useMe;
  114. tcb->next = TextureCallbacks3;
  115. tcb->prev = (TextureCallback3*)NULL;
  116. TextureCallbacks3 = tcb;
  117. d3dtcb = myLoadTextureCallback3;
  118. pArgs = (void *)tcb;
  119. }
  120. else
  121. {
  122. DPF(1,"Callback object creation failed!\r\n");
  123. return E_FAIL;
  124. }
  125. }
  126. USES_CONVERSION;
  127. LPCTSTR pszName = W2T(filename);
  128. void *args=NULL;
  129. DWORD pos=0;
  130. GUID loadGuid;
  131. VARIANT var;
  132. VariantInit(&var);
  133. if ((flags & D3DRMLOAD_BYNAME)||(D3DRMLOAD_FROMURL & flags)) {
  134. hr=VariantChangeType(&var,&id,0,VT_BSTR);
  135. if FAILED(hr) return E_INVALIDARG;
  136. args=(void*)W2T(V_BSTR(&id));
  137. }
  138. else if(flags & D3DRMLOAD_BYPOSITION){
  139. hr=VariantChangeType(&var,&id,0,VT_I4);
  140. if FAILED(hr) return E_INVALIDARG;
  141. pos=V_I4(&id);
  142. args=&pos;
  143. }
  144. else if(flags & D3DRMLOAD_BYGUID){
  145. hr=VariantChangeType(&var,&id,0,VT_BSTR);
  146. if FAILED(hr) return E_INVALIDARG;
  147. hr=BSTRtoGUID(&loadGuid,V_BSTR(&id));
  148. if FAILED(hr) return E_INVALIDARG;
  149. args=&loadGuid;
  150. }
  151. VariantClear(&var);
  152. if (flags &D3DRMLOAD_FROMRESOURCE){
  153. D3DRMLOADRESOURCE res;
  154. ZeroMemory(&res,sizeof(D3DRMLOADRESOURCE));
  155. res.lpName=pszName;
  156. res.lpType="XFILE";
  157. hr = m__dxj_Direct3dRMMeshBuilder3->Load((void *)&res, (DWORD*)args,(DWORD) flags,d3dtcb, pArgs);
  158. }
  159. else {
  160. hr = m__dxj_Direct3dRMMeshBuilder3->Load((void *)pszName, (DWORD*)args,(DWORD) flags,d3dtcb, pArgs);
  161. }
  162. // Remove ourselves in a thread-safe manner.
  163. if (tcb)
  164. UndoCallbackLink((GeneralCallback*)tcb,
  165. (GeneralCallback**)&TextureCallbacks3);
  166. return hr;
  167. }
  168. /////////////////////////////////////////////////////////////////////////////
  169. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::getNormalCount(long *retval)
  170. {
  171. DWORD vc=0, nc=0, fsize=0;
  172. //Get facedata size only. The other tqo sizes are ignored.
  173. *retval= m__dxj_Direct3dRMMeshBuilder3->GetNormalCount();
  174. return S_OK;
  175. }
  176. /////////////////////////////////////////////////////////////////////////////
  177. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::getFaceDataSize(long *retval)
  178. {
  179. DWORD vc=0, nc=0, fsize=0;
  180. //Get facedata size only. The other tqo sizes are ignored.
  181. return m__dxj_Direct3dRMMeshBuilder3->GetGeometry(&vc, (struct _D3DVECTOR *)NULL,
  182. &nc, (struct _D3DVECTOR *)NULL, (DWORD*)retval, (DWORD*)NULL);
  183. }
  184. /////////////////////////////////////////////////////////////////////////////
  185. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::addFrame(I_dxj_Direct3dRMFrame3 *frame){
  186. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMFRAME3,lpFrame,frame);
  187. return m__dxj_Direct3dRMMeshBuilder3->AddFrame(lpFrame);
  188. }
  189. /////////////////////////////////////////////////////////////////////////////
  190. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::setTexture(I_dxj_Direct3dRMTexture3 *tex){
  191. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMTEXTURE3,lpTex,tex);
  192. return m__dxj_Direct3dRMMeshBuilder3->SetTexture(lpTex);
  193. }
  194. /////////////////////////////////////////////////////////////////////////////
  195. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::addMeshBuilder(I_dxj_Direct3dRMMeshBuilder3 *mb, long flags){
  196. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMMESHBUILDER3,lpMb,mb);
  197. return m__dxj_Direct3dRMMeshBuilder3->AddMeshBuilder(lpMb,(DWORD)flags);
  198. }
  199. /////////////////////////////////////////////////////////////////////////////
  200. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::getGeometry( SAFEARRAY **ppv,
  201. SAFEARRAY **ppn, SAFEARRAY **ppfdata)
  202. {
  203. DWORD vc,nc,fsize;
  204. if (!ppv) return E_INVALIDARG;
  205. if (!ppn) return E_INVALIDARG;
  206. if (!ppfdata) return E_INVALIDARG;
  207. vc= (*ppv)->cbElements;
  208. nc= (*ppn)->cbElements;
  209. fsize= (*ppfdata)->cbElements;
  210. //if (!ISSAFEARRAY1D(ppv,(DWORD)vc)) return E_INVALIDARG;
  211. //if (!ISSAFEARRAY1D(ppn,(DWORD)nc)) return E_INVALIDARG;
  212. //if (!ISSAFEARRAY1D(ppfdata,(DWORD)fsize)) return E_INVALIDARG;
  213. return m__dxj_Direct3dRMMeshBuilder3->GetGeometry((DWORD*)&vc, (struct _D3DVECTOR *)((SAFEARRAY*)*ppv)->pvData, (DWORD*)&nc,
  214. (struct _D3DVECTOR *)((SAFEARRAY*)*ppn)->pvData, (unsigned long *)fsize, (unsigned long *) ((SAFEARRAY*)*ppfdata)->pvData);
  215. }
  216. /////////////////////////////////////////////////////////////////////////////
  217. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::addFaces(long vcount, SAFEARRAY **ppv,
  218. long ncount, SAFEARRAY **ppn, SAFEARRAY **ppfdata, I_dxj_Direct3dRMFaceArray **array)
  219. {
  220. HRESULT hr;
  221. LPDIRECT3DRMFACEARRAY lpArray;
  222. __try
  223. {
  224. hr = m__dxj_Direct3dRMMeshBuilder3->AddFaces(
  225. (DWORD)vcount, (struct _D3DVECTOR *)((SAFEARRAY*)*ppv)->pvData,
  226. (DWORD)ncount, (struct _D3DVECTOR *)((SAFEARRAY*)*ppn)->pvData,
  227. (unsigned long *)((SAFEARRAY*)*ppfdata)->pvData, &lpArray);
  228. }
  229. __except(1,1)
  230. {
  231. return E_INVALIDARG;
  232. }
  233. if FAILED(hr) return hr;
  234. INTERNAL_CREATE(_dxj_Direct3dRMFaceArray, lpArray, array);
  235. return hr;
  236. }
  237. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::addFacesIndexed(
  238. /* [in] */ long flags,
  239. /* [in] */ SAFEARRAY __RPC_FAR * __RPC_FAR *indexArray,
  240. /* [retval][out] */ long __RPC_FAR *newFaceIndex)
  241. {
  242. HRESULT hr;
  243. __try
  244. {
  245. hr = m__dxj_Direct3dRMMeshBuilder3->AddFacesIndexed(
  246. (DWORD)flags, (DWORD *)((SAFEARRAY*)*indexArray)->pvData,
  247. (DWORD*)newFaceIndex, NULL);
  248. }
  249. __except(1,1)
  250. {
  251. return E_INVALIDARG;
  252. }
  253. return hr;
  254. }
  255. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::addTriangles(
  256. /* [in] */ long format,
  257. /* [in] */ long vertexCount,
  258. /* [in] */ void *data)
  259. {
  260. HRESULT hr;
  261. __try
  262. {
  263. hr = m__dxj_Direct3dRMMeshBuilder3->AddTriangles(
  264. (DWORD)0, (DWORD) format, (DWORD) vertexCount,
  265. data);
  266. }
  267. __except(1,1)
  268. {
  269. return E_INVALIDARG;
  270. }
  271. return hr;
  272. }
  273. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::createSubMesh(
  274. I_dxj_Direct3dRMMeshBuilder3 **ret)
  275. {
  276. HRESULT hr;
  277. LPUNKNOWN pUnk=NULL;
  278. LPDIRECT3DRMMESHBUILDER3 pMesh3=NULL;
  279. *ret =NULL;
  280. hr = m__dxj_Direct3dRMMeshBuilder3->CreateSubMesh(&pUnk);
  281. if FAILED(hr) return hr;
  282. if (!pUnk) return E_FAIL;
  283. hr = pUnk->QueryInterface(IID_IDirect3DRMMeshBuilder3,(void**)&pMesh3);
  284. pUnk->Release();
  285. if FAILED(hr) return hr;
  286. INTERNAL_CREATE(_dxj_Direct3dRMMeshBuilder3,pMesh3,ret);
  287. return hr;
  288. }
  289. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::deleteFace( I_dxj_Direct3dRMFace2 *face)
  290. {
  291. HRESULT hr;
  292. if (!face) return E_INVALIDARG;
  293. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMFACE2,pFace,face);
  294. __try {
  295. hr = m__dxj_Direct3dRMMeshBuilder3->DeleteFace(pFace);
  296. }
  297. __except(1,1){
  298. return E_FAIL;
  299. }
  300. return hr;
  301. }
  302. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::deleteNormals( long id, long count)
  303. {
  304. HRESULT hr;
  305. hr = m__dxj_Direct3dRMMeshBuilder3->DeleteNormals((DWORD)id,(DWORD)count);
  306. return hr;
  307. }
  308. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::deleteVertices(long id, long count)
  309. {
  310. HRESULT hr;
  311. __try {
  312. hr = m__dxj_Direct3dRMMeshBuilder3->DeleteVertices((DWORD)id,(DWORD) count);
  313. }
  314. __except(1,1){
  315. return E_FAIL;
  316. }
  317. return hr;
  318. }
  319. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::empty()
  320. {
  321. HRESULT hr;
  322. hr = m__dxj_Direct3dRMMeshBuilder3->Empty((DWORD)0);
  323. return hr;
  324. }
  325. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::enableMesh(long flags)
  326. {
  327. HRESULT hr;
  328. hr = m__dxj_Direct3dRMMeshBuilder3->Enable((DWORD)flags);
  329. return hr;
  330. }
  331. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::getEnable(long *flags)
  332. {
  333. HRESULT hr;
  334. hr = m__dxj_Direct3dRMMeshBuilder3->GetEnable((DWORD*)flags);
  335. return hr;
  336. }
  337. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::getFace(long index, I_dxj_Direct3dRMFace2 **face)
  338. {
  339. HRESULT hr;
  340. LPDIRECT3DRMFACE2 pFace=NULL;
  341. *face=NULL;
  342. hr = m__dxj_Direct3dRMMeshBuilder3->GetFace((DWORD)index,&pFace);
  343. if FAILED(hr) return hr;
  344. if (!pFace) return E_FAIL;
  345. INTERNAL_CREATE(_dxj_Direct3dRMFace2,pFace,face);
  346. return hr;
  347. }
  348. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::getNormal(long index, D3dVector *vec)
  349. {
  350. HRESULT hr;
  351. hr = m__dxj_Direct3dRMMeshBuilder3->GetNormal((DWORD)index,(D3DVECTOR*)vec);
  352. return hr;
  353. }
  354. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::getVertex(long index, D3dVector *vec)
  355. {
  356. HRESULT hr;
  357. hr = m__dxj_Direct3dRMMeshBuilder3->GetVertex((DWORD)index,(D3DVECTOR*)vec);
  358. return hr;
  359. }
  360. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::optimize()
  361. {
  362. HRESULT hr;
  363. hr = m__dxj_Direct3dRMMeshBuilder3->Optimize((DWORD)0);
  364. return hr;
  365. }
  366. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::deleteSubMesh(
  367. I_dxj_Direct3dRMMeshBuilder3 *mesh)
  368. {
  369. HRESULT hr;
  370. if (!mesh) return E_INVALIDARG;
  371. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMMESHBUILDER3,pMesh,mesh);
  372. hr = m__dxj_Direct3dRMMeshBuilder3->DeleteSubMesh(pMesh);
  373. return hr;
  374. }
  375. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::getParentMesh(long flags,
  376. I_dxj_Direct3dRMMeshBuilder3 **mesh)
  377. {
  378. HRESULT hr;
  379. LPUNKNOWN pUnk=NULL;
  380. LPDIRECT3DRMMESHBUILDER3 pMesh=NULL;
  381. hr = m__dxj_Direct3dRMMeshBuilder3->GetParentMesh((DWORD)flags,&pUnk);
  382. if FAILED(hr) return hr;
  383. if (pUnk==NULL){
  384. *mesh=NULL;
  385. return S_OK;
  386. }
  387. hr= pUnk->QueryInterface(IID_IDirect3DRMMeshBuilder3,(void**)&pMesh);
  388. pUnk->Release();
  389. if FAILED(hr) return hr;
  390. INTERNAL_CREATE(_dxj_Direct3dRMMeshBuilder3,pMesh,mesh);
  391. return hr;
  392. }
  393. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::getSubMeshCount(long *count)
  394. {
  395. HRESULT hr;
  396. hr = m__dxj_Direct3dRMMeshBuilder3->GetSubMeshes((DWORD*)count,NULL);
  397. return hr;
  398. }
  399. STDMETHODIMP C_dxj_Direct3dRMMeshBuilder3Object::getSubMeshes(long count,SAFEARRAY **psa)
  400. {
  401. HRESULT hr;
  402. __try{
  403. hr = m__dxj_Direct3dRMMeshBuilder3->GetSubMeshes((DWORD*)&count,(IUnknown**)((SAFEARRAY*)*psa)->pvData);
  404. }
  405. __except(1,1){
  406. return E_INVALIDARG;
  407. }
  408. return hr;
  409. }