2 * Implementation of IDirect3DRMMeshBuilderX and IDirect3DRMMesh interfaces
4 * Copyright 2010, 2012 Christian Costa
5 * Copyright 2011 André Hentschel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
26 #include "wine/debug.h"
33 #include "d3drm_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(d3drm);
39 D3DRMVERTEX* vertices;
41 unsigned vertex_per_face;
45 IDirect3DRMMaterial2* material;
46 IDirect3DRMTexture3* texture;
50 IDirect3DRMMesh IDirect3DRMMesh_iface;
52 DWORD groups_capacity;
55 } IDirect3DRMMeshImpl;
64 IDirect3DRMMaterial2 *material;
65 IDirect3DRMTexture3 *texture;
69 IDirect3DRMMeshBuilder2 IDirect3DRMMeshBuilder2_iface;
70 IDirect3DRMMeshBuilder3 IDirect3DRMMeshBuilder3_iface;
83 IDirect3DRMMaterial2 *material;
84 IDirect3DRMTexture3 *texture;
86 mesh_material *materials;
87 DWORD *material_indices;
88 } IDirect3DRMMeshBuilderImpl;
94 "<3D82AB43-62DA-11CF-AB39-0020AF71E433>"
101 "<3D82AB5E-62DA-11CF-AB39-0020AF71E433>"
108 "<F6F23F44-7686-11CF-8F52-0040333594A3>"
114 "<F6F23F45-7686-11CF-8F52-0040333594A3>"
115 "array FLOAT matrix[16];"
119 "<35FF44E0-6C7C-11CF-8F52-0040333594A3>"
127 "<D3E16E81-7835-11CF-8F52-0040333594A3>"
132 "template IndexedColor"
134 "<1630B820-7842-11CF-8F52-0040333594A3>"
136 "ColorRGBA indexColor;"
140 "<537DA6A0-CA37-11D0-941C-0080C80CFA7B>"
145 "<4885AE63-78E8-11CF-8F52-0040333594A3>"
149 "template MaterialWrap"
151 "<4885AE60-78E8-11CF-8F52-0040333594A3>"
155 "template TextureFilename"
157 "<A42790E1-7810-11CF-8F52-0040333594A3>"
162 "<3D82AB4D-62DA-11CF-AB39-0020AF71E433>"
163 "ColorRGBA faceColor;"
165 "ColorRGB specularColor;"
166 "ColorRGB emissiveColor;"
171 "<3D82AB5F-62DA-11CF-AB39-0020AF71E433>"
172 "DWORD nFaceVertexIndices;"
173 "array DWORD faceVertexIndices[nFaceVertexIndices];"
175 "template MeshFaceWraps"
177 "<ED1EC5C0-C0A8-11D0-941C-0080C80CFA7B>"
178 "DWORD nFaceWrapValues;"
179 "array Boolean2d faceWrapValues[nFaceWrapValues];"
181 "template MeshTextureCoords"
183 "<F6F23F40-7686-11CF-8F52-0040333594A3>"
184 "DWORD nTextureCoords;"
185 "array Coords2d textureCoords[nTextureCoords];"
187 "template MeshMaterialList"
189 "<F6F23F42-7686-11CF-8F52-0040333594A3>"
191 "DWORD nFaceIndexes;"
192 "array DWORD faceIndexes[nFaceIndexes];"
195 "template MeshNormals"
197 "<F6F23F43-7686-11CF-8F52-0040333594A3>"
199 "array Vector normals[nNormals];"
200 "DWORD nFaceNormals;"
201 "array MeshFace faceNormals[nFaceNormals];"
203 "template MeshVertexColors"
205 "<1630B821-7842-11CF-8F52-0040333594A3>"
206 "DWORD nVertexColors;"
207 "array IndexedColor vertexColors[nVertexColors];"
211 "<3D82AB44-62DA-11CF-AB39-0020AF71E433>"
213 "array Vector vertices[nVertices];"
215 "array MeshFace faces[nFaces];"
218 "template FrameTransformMatrix"
220 "<F6F23F41-7686-11CF-8F52-0040333594A3>"
221 "Matrix4x4 frameMatrix;"
225 "<3D82AB46-62DA-11CF-AB39-0020AF71E433>"
230 "<10DD46A9-775B-11CF-8F52-0040333594A3>"
232 "array FLOAT values[nValues];"
234 "template TimedFloatKeys"
236 "<F406B180-7B3B-11CF-8F52-0040333594A3>"
240 "template AnimationKey"
242 "<10DD46A8-775B-11CF-8F52-0040333594A3>"
245 "array TimedFloatKeys keys[nKeys];"
247 "template AnimationOptions"
249 "<E2BF56C0-840F-11CF-8F52-0040333594A3>"
251 "DWORD positionquality;"
255 "<3D82AB4F-62DA-11CF-AB39-0020AF71E433>"
258 "template AnimationSet"
260 "<3D82AB50-62DA-11CF-AB39-0020AF71E433>"
263 "template InlineData"
265 "<3A23EEA0-94B1-11D0-AB39-0020AF71E433>"
270 "<3A23EEA1-94B1-11D0-AB39-0020AF71E433>"
272 "array STRING urls[nUrls];"
274 "template ProgressiveMesh"
276 "<8A63C360-997D-11D0-941C-0080C80CFA7B>"
281 "<A42790E0-7810-11CF-8F52-0040333594A3>"
285 "array UCHAR data4[8];"
287 "template StringProperty"
289 "<7F0F21E0-BFE1-11D1-82C0-00A0C9697271>"
293 "template PropertyBag"
295 "<7F0F21E1-BFE1-11D1-82C0-00A0C9697271>"
298 "template ExternalVisual"
300 "<98116AA0-BDBA-11D1-82C0-00A0C9697271>"
301 "Guid guidExternalVisual;"
304 "template RightHanded"
306 "<7F5D5EA0-D53A-11D1-82C0-00A0C9697271>"
307 "DWORD bRightHanded;"
311 static inline IDirect3DRMMeshImpl *impl_from_IDirect3DRMMesh(IDirect3DRMMesh *iface)
313 return CONTAINING_RECORD(iface, IDirect3DRMMeshImpl, IDirect3DRMMesh_iface);
316 static inline IDirect3DRMMeshBuilderImpl *impl_from_IDirect3DRMMeshBuilder2(IDirect3DRMMeshBuilder2 *iface)
318 return CONTAINING_RECORD(iface, IDirect3DRMMeshBuilderImpl, IDirect3DRMMeshBuilder2_iface);
321 static inline IDirect3DRMMeshBuilderImpl *impl_from_IDirect3DRMMeshBuilder3(IDirect3DRMMeshBuilder3 *iface)
323 return CONTAINING_RECORD(iface, IDirect3DRMMeshBuilderImpl, IDirect3DRMMeshBuilder3_iface);
326 static void clean_mesh_builder_data(IDirect3DRMMeshBuilderImpl *mesh_builder)
330 HeapFree(GetProcessHeap(), 0, mesh_builder->name);
331 mesh_builder->name = NULL;
332 HeapFree(GetProcessHeap(), 0, mesh_builder->pVertices);
333 mesh_builder->pVertices = NULL;
334 mesh_builder->nb_vertices = 0;
335 HeapFree(GetProcessHeap(), 0, mesh_builder->pNormals);
336 mesh_builder->pNormals = NULL;
337 mesh_builder->nb_normals = 0;
338 HeapFree(GetProcessHeap(), 0, mesh_builder->pFaceData);
339 mesh_builder->pFaceData = NULL;
340 mesh_builder->face_data_size = 0;
341 mesh_builder->nb_faces = 0;
342 HeapFree(GetProcessHeap(), 0, mesh_builder->pCoords2d);
343 mesh_builder->pCoords2d = NULL;
344 mesh_builder->nb_coords2d = 0;
345 for (i = 0; i < mesh_builder->nb_materials; i++)
347 if (mesh_builder->materials[i].material)
348 IDirect3DRMMaterial2_Release(mesh_builder->materials[i].material);
349 if (mesh_builder->materials[i].texture)
350 IDirect3DRMTexture3_Release(mesh_builder->materials[i].texture);
352 mesh_builder->nb_materials = 0;
353 HeapFree(GetProcessHeap(), 0, mesh_builder->materials);
354 HeapFree(GetProcessHeap(), 0, mesh_builder->material_indices);
357 /*** IUnknown methods ***/
358 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_QueryInterface(IDirect3DRMMeshBuilder2* iface,
359 REFIID riid, void** ppvObject)
361 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
363 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
367 if(IsEqualGUID(riid, &IID_IUnknown) ||
368 IsEqualGUID(riid, &IID_IDirect3DRMMeshBuilder) ||
369 IsEqualGUID(riid, &IID_IDirect3DRMMeshBuilder2))
371 *ppvObject = &This->IDirect3DRMMeshBuilder2_iface;
373 else if(IsEqualGUID(riid, &IID_IDirect3DRMMeshBuilder3))
375 *ppvObject = &This->IDirect3DRMMeshBuilder3_iface;
379 FIXME("interface %s not implemented\n", debugstr_guid(riid));
380 return E_NOINTERFACE;
383 IDirect3DRMMeshBuilder_AddRef(iface);
387 static ULONG WINAPI IDirect3DRMMeshBuilder2Impl_AddRef(IDirect3DRMMeshBuilder2* iface)
389 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
390 ULONG ref = InterlockedIncrement(&This->ref);
392 TRACE("(%p)->(): new ref = %d\n", This, ref);
397 static ULONG WINAPI IDirect3DRMMeshBuilder2Impl_Release(IDirect3DRMMeshBuilder2* iface)
399 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
400 ULONG ref = InterlockedDecrement(&This->ref);
402 TRACE("(%p)->(): new ref = %d\n", This, ref);
406 clean_mesh_builder_data(This);
408 IDirect3DRMMaterial2_Release(This->material);
410 IDirect3DRMTexture3_Release(This->texture);
411 HeapFree(GetProcessHeap(), 0, This);
417 /*** IDirect3DRMObject methods ***/
418 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_Clone(IDirect3DRMMeshBuilder2* iface,
419 LPUNKNOWN pUnkOuter, REFIID riid,
422 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
424 FIXME("(%p)->(%p,%s,%p): stub\n", This, pUnkOuter, debugstr_guid(riid), ppvObj);
429 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddDestroyCallback(IDirect3DRMMeshBuilder2* iface,
430 D3DRMOBJECTCALLBACK cb,
433 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
435 FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
440 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_DeleteDestroyCallback(IDirect3DRMMeshBuilder2* iface,
441 D3DRMOBJECTCALLBACK cb,
444 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
446 FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
451 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetAppData(IDirect3DRMMeshBuilder2* iface,
454 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
456 FIXME("(%p)->(%u): stub\n", This, data);
461 static DWORD WINAPI IDirect3DRMMeshBuilder2Impl_GetAppData(IDirect3DRMMeshBuilder2* iface)
463 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
465 FIXME("(%p)->(): stub\n", This);
470 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetName(IDirect3DRMMeshBuilder2* iface,
473 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
475 TRACE("(%p)->(%s)\n", This, debugstr_a(name));
477 return IDirect3DRMMeshBuilder3_SetName(&This->IDirect3DRMMeshBuilder3_iface, name);
480 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetName(IDirect3DRMMeshBuilder2* iface,
481 LPDWORD size, LPSTR name)
483 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
485 TRACE("(%p)->(%p,%p)\n", This, size, name);
487 return IDirect3DRMMeshBuilder3_GetName(&This->IDirect3DRMMeshBuilder3_iface, size, name);
490 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetClassName(IDirect3DRMMeshBuilder2* iface,
491 LPDWORD size, LPSTR name)
493 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
495 TRACE("(%p)->(%p, %p)\n", This, size, name);
497 return IDirect3DRMMeshBuilder3_GetClassName(&This->IDirect3DRMMeshBuilder3_iface, size, name);
500 /*** IDirect3DRMMeshBuilder2 methods ***/
501 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_Load(IDirect3DRMMeshBuilder2* iface,
502 LPVOID filename, LPVOID name,
503 D3DRMLOADOPTIONS loadflags,
504 D3DRMLOADTEXTURECALLBACK cb, LPVOID arg)
506 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
508 TRACE("(%p)->(%p,%p,%x,%p,%p)\n", This, filename, name, loadflags, cb, arg);
511 FIXME("Texture callback is not yet supported\n");
513 return IDirect3DRMMeshBuilder3_Load(&This->IDirect3DRMMeshBuilder3_iface, filename, name,
514 loadflags, NULL, arg);
517 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_Save(IDirect3DRMMeshBuilder2* iface,
518 const char *filename, D3DRMXOFFORMAT format,
519 D3DRMSAVEOPTIONS save)
521 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
523 FIXME("(%p)->(%s,%d,%d): stub\n", This, filename, format, save);
528 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_Scale(IDirect3DRMMeshBuilder2* iface,
529 D3DVALUE sx, D3DVALUE sy, D3DVALUE sz)
531 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
533 TRACE("(%p)->(%f,%f,%f)\n", This, sx, sy, sz);
535 return IDirect3DRMMeshBuilder3_Scale(&This->IDirect3DRMMeshBuilder3_iface, sx, sy, sz);
538 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_Translate(IDirect3DRMMeshBuilder2* iface,
539 D3DVALUE tx, D3DVALUE ty, D3DVALUE tz)
541 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
543 FIXME("(%p)->(%f,%f,%f): stub\n", This, tx, ty, tz);
548 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetColorSource(IDirect3DRMMeshBuilder2* iface,
549 D3DRMCOLORSOURCE color)
551 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
553 FIXME("(%p)->(%x): stub\n", This, color);
558 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetBox(IDirect3DRMMeshBuilder2* iface,
561 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
563 FIXME("(%p)->(%p): stub\n", This, pBox);
568 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GenerateNormals(IDirect3DRMMeshBuilder2* iface)
570 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
572 FIXME("(%p)->(): stub\n", This);
577 static D3DRMCOLORSOURCE WINAPI IDirect3DRMMeshBuilder2Impl_GetColorSource(IDirect3DRMMeshBuilder2* iface)
579 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
581 FIXME("(%p)->(): stub\n", This);
586 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddMesh(IDirect3DRMMeshBuilder2* iface,
587 LPDIRECT3DRMMESH pMesh)
589 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
591 FIXME("(%p)->(%p): stub\n", This, pMesh);
596 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddMeshBuilder(IDirect3DRMMeshBuilder2* iface,
597 LPDIRECT3DRMMESHBUILDER pMeshBuilder)
599 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
601 FIXME("(%p)->(%p): stub\n", This, pMeshBuilder);
606 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddFrame(IDirect3DRMMeshBuilder2* iface,
607 LPDIRECT3DRMFRAME pFrame)
609 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
611 FIXME("(%p)->(%p): stub\n", This, pFrame);
616 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddFace(IDirect3DRMMeshBuilder2* iface,
617 LPDIRECT3DRMFACE pFace)
619 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
621 FIXME("(%p)->(%p): stub\n", This, pFace);
626 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddFaces(IDirect3DRMMeshBuilder2* iface,
627 DWORD vcount, D3DVECTOR *vertices,
628 DWORD ncount, D3DVECTOR *normals,
630 LPDIRECT3DRMFACEARRAY* pFaceArray)
632 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
634 FIXME("(%p)->(%d,%p,%d,%p,%p,%p): stub\n", This, vcount, vertices, ncount, normals, data, pFaceArray);
639 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_ReserveSpace(IDirect3DRMMeshBuilder2* iface,
644 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
646 FIXME("(%p)->(%d,%d,%d): stub\n", This, vertex_Count, normal_count, face_count);
651 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetColorRGB(IDirect3DRMMeshBuilder2* iface,
652 D3DVALUE red, D3DVALUE green,
655 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
657 TRACE("(%p)->(%f,%f,%f)\n", This, red, green, blue);
659 return IDirect3DRMMeshBuilder3_SetColorRGB(&This->IDirect3DRMMeshBuilder3_iface, red, green, blue);
662 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetColor(IDirect3DRMMeshBuilder2* iface,
665 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
667 TRACE("(%p)->(%x)\n", This, color);
669 return IDirect3DRMMeshBuilder3_SetColor(&This->IDirect3DRMMeshBuilder3_iface, color);
672 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetTexture(IDirect3DRMMeshBuilder2* iface,
673 LPDIRECT3DRMTEXTURE texture)
675 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
676 LPDIRECT3DRMTEXTURE3 texture3 = NULL;
677 HRESULT hr = D3DRM_OK;
680 hr = IDirect3DRMTexture_QueryInterface(texture, &IID_IDirect3DRMTexture3, (LPVOID*)&texture3);
682 hr = IDirect3DRMMeshBuilder3_SetTexture(&This->IDirect3DRMMeshBuilder3_iface, texture3);
684 IDirect3DRMTexture3_Release(texture3);
689 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetMaterial(IDirect3DRMMeshBuilder2* iface,
690 LPDIRECT3DRMMATERIAL material)
692 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
694 TRACE("(%p)->(%p)\n", This, material);
696 return IDirect3DRMMeshBuilder3_SetMaterial(&This->IDirect3DRMMeshBuilder3_iface, (LPDIRECT3DRMMATERIAL2)material);
699 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetTextureTopology(IDirect3DRMMeshBuilder2* iface,
700 BOOL wrap_u, BOOL wrap_v)
702 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
704 FIXME("(%p)->(%d,%d): stub\n", This, wrap_u, wrap_v);
709 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetQuality(IDirect3DRMMeshBuilder2* iface,
710 D3DRMRENDERQUALITY quality)
712 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
714 FIXME("(%p)->(%d): stub\n", This, quality);
719 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetPerspective(IDirect3DRMMeshBuilder2* iface,
722 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
724 FIXME("(%p)->(%d): stub\n", This, enable);
729 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetVertex(IDirect3DRMMeshBuilder2* iface,
731 D3DVALUE x, D3DVALUE y, D3DVALUE z)
733 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
735 FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
740 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetNormal(IDirect3DRMMeshBuilder2* iface,
742 D3DVALUE x, D3DVALUE y, D3DVALUE z)
744 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
746 FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
751 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetTextureCoordinates(IDirect3DRMMeshBuilder2* iface,
753 D3DVALUE u, D3DVALUE v)
755 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
757 TRACE("(%p)->(%u,%f,%f)\n", This, index, u, v);
759 return IDirect3DRMMeshBuilder3_SetTextureCoordinates(&This->IDirect3DRMMeshBuilder3_iface,
763 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetVertexColor(IDirect3DRMMeshBuilder2* iface,
764 DWORD index, D3DCOLOR color)
766 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
768 FIXME("(%p)->(%d,%x): stub\n", This, index, color);
773 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetVertexColorRGB(IDirect3DRMMeshBuilder2* iface,
774 DWORD index, D3DVALUE red,
775 D3DVALUE green, D3DVALUE blue)
777 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
779 FIXME("(%p)->(%d,%f,%f,%f): stub\n", This, index, red, green, blue);
784 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetFaces(IDirect3DRMMeshBuilder2* iface,
785 LPDIRECT3DRMFACEARRAY* pFaceArray)
787 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
789 FIXME("(%p)->(%p): stub\n", This, pFaceArray);
794 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetVertices(IDirect3DRMMeshBuilder2* iface,
795 DWORD *vcount, D3DVECTOR *vertices,
796 DWORD *ncount, D3DVECTOR *normals,
797 DWORD *face_data_size,
800 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
802 TRACE("(%p)->(%p,%p,%p,%p,%p,%p)\n", This, vcount, vertices, ncount, normals, face_data_size, face_data);
804 if (vertices && (!vcount || (*vcount < This->nb_vertices)))
805 return D3DRMERR_BADVALUE;
807 *vcount = This->nb_vertices;
808 if (vertices && This->nb_vertices)
809 memcpy(vertices, This->pVertices, This->nb_vertices * sizeof(D3DVECTOR));
811 if (normals && (!ncount || (*ncount < This->nb_normals)))
812 return D3DRMERR_BADVALUE;
814 *ncount = This->nb_normals;
815 if (normals && This->nb_normals)
816 memcpy(normals, This->pNormals, This->nb_normals * sizeof(D3DVECTOR));
818 if (face_data && (!face_data_size || (*face_data_size < This->face_data_size)))
819 return D3DRMERR_BADVALUE;
821 *face_data_size = This->face_data_size;
822 if (face_data && This->face_data_size)
823 memcpy(face_data, This->pFaceData, This->face_data_size * sizeof(DWORD));
828 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetTextureCoordinates(IDirect3DRMMeshBuilder2* iface,
830 D3DVALUE *u, D3DVALUE *v)
832 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
834 TRACE("(%p)->(%u,%p,%p)\n", This, index, u, v);
836 return IDirect3DRMMeshBuilder3_GetTextureCoordinates(&This->IDirect3DRMMeshBuilder3_iface,
840 static int WINAPI IDirect3DRMMeshBuilder2Impl_AddVertex(IDirect3DRMMeshBuilder2* iface,
841 D3DVALUE x, D3DVALUE y, D3DVALUE z)
843 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
845 FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
850 static int WINAPI IDirect3DRMMeshBuilder2Impl_AddNormal(IDirect3DRMMeshBuilder2* iface,
851 D3DVALUE x, D3DVALUE y, D3DVALUE z)
853 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
855 FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
860 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_CreateFace(IDirect3DRMMeshBuilder2* iface,
861 LPDIRECT3DRMFACE* ppFace)
863 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
865 FIXME("(%p)->(%p): stub\n", This, ppFace);
870 static D3DRMRENDERQUALITY WINAPI IDirect3DRMMeshBuilder2Impl_GetQuality(IDirect3DRMMeshBuilder2* iface)
872 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
874 FIXME("(%p)->(): stub\n", This);
879 static BOOL WINAPI IDirect3DRMMeshBuilder2Impl_GetPerspective(IDirect3DRMMeshBuilder2* iface)
881 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
883 FIXME("(%p)->(): stub\n", This);
888 static int WINAPI IDirect3DRMMeshBuilder2Impl_GetFaceCount(IDirect3DRMMeshBuilder2* iface)
890 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
892 TRACE("(%p)->()\n", This);
894 return This->nb_faces;
897 static int WINAPI IDirect3DRMMeshBuilder2Impl_GetVertexCount(IDirect3DRMMeshBuilder2* iface)
899 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
901 TRACE("(%p)->()\n", This);
903 return This->nb_vertices;
906 static D3DCOLOR WINAPI IDirect3DRMMeshBuilder2Impl_GetVertexColor(IDirect3DRMMeshBuilder2* iface,
909 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
911 FIXME("(%p)->(%d): stub\n", This, index);
916 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_CreateMesh(IDirect3DRMMeshBuilder2* iface,
917 LPDIRECT3DRMMESH* mesh)
919 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
921 TRACE("(%p)->(%p)\n", This, mesh);
923 return IDirect3DRMMeshBuilder3_CreateMesh(&This->IDirect3DRMMeshBuilder3_iface, mesh);
926 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GenerateNormals2(IDirect3DRMMeshBuilder2* iface,
927 D3DVALUE crease, DWORD dwFlags)
929 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
931 FIXME("(%p)->(%f,%u): stub\n", This, crease, dwFlags);
936 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetFace(IDirect3DRMMeshBuilder2* iface,
937 DWORD index, LPDIRECT3DRMFACE* ppFace)
939 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
941 FIXME("(%p)->(%u,%p): stub\n", This, index, ppFace);
946 static const struct IDirect3DRMMeshBuilder2Vtbl Direct3DRMMeshBuilder2_Vtbl =
948 /*** IUnknown methods ***/
949 IDirect3DRMMeshBuilder2Impl_QueryInterface,
950 IDirect3DRMMeshBuilder2Impl_AddRef,
951 IDirect3DRMMeshBuilder2Impl_Release,
952 /*** IDirect3DRMObject methods ***/
953 IDirect3DRMMeshBuilder2Impl_Clone,
954 IDirect3DRMMeshBuilder2Impl_AddDestroyCallback,
955 IDirect3DRMMeshBuilder2Impl_DeleteDestroyCallback,
956 IDirect3DRMMeshBuilder2Impl_SetAppData,
957 IDirect3DRMMeshBuilder2Impl_GetAppData,
958 IDirect3DRMMeshBuilder2Impl_SetName,
959 IDirect3DRMMeshBuilder2Impl_GetName,
960 IDirect3DRMMeshBuilder2Impl_GetClassName,
961 /*** IDirect3DRMMeshBuilder methods ***/
962 IDirect3DRMMeshBuilder2Impl_Load,
963 IDirect3DRMMeshBuilder2Impl_Save,
964 IDirect3DRMMeshBuilder2Impl_Scale,
965 IDirect3DRMMeshBuilder2Impl_Translate,
966 IDirect3DRMMeshBuilder2Impl_SetColorSource,
967 IDirect3DRMMeshBuilder2Impl_GetBox,
968 IDirect3DRMMeshBuilder2Impl_GenerateNormals,
969 IDirect3DRMMeshBuilder2Impl_GetColorSource,
970 IDirect3DRMMeshBuilder2Impl_AddMesh,
971 IDirect3DRMMeshBuilder2Impl_AddMeshBuilder,
972 IDirect3DRMMeshBuilder2Impl_AddFrame,
973 IDirect3DRMMeshBuilder2Impl_AddFace,
974 IDirect3DRMMeshBuilder2Impl_AddFaces,
975 IDirect3DRMMeshBuilder2Impl_ReserveSpace,
976 IDirect3DRMMeshBuilder2Impl_SetColorRGB,
977 IDirect3DRMMeshBuilder2Impl_SetColor,
978 IDirect3DRMMeshBuilder2Impl_SetTexture,
979 IDirect3DRMMeshBuilder2Impl_SetMaterial,
980 IDirect3DRMMeshBuilder2Impl_SetTextureTopology,
981 IDirect3DRMMeshBuilder2Impl_SetQuality,
982 IDirect3DRMMeshBuilder2Impl_SetPerspective,
983 IDirect3DRMMeshBuilder2Impl_SetVertex,
984 IDirect3DRMMeshBuilder2Impl_SetNormal,
985 IDirect3DRMMeshBuilder2Impl_SetTextureCoordinates,
986 IDirect3DRMMeshBuilder2Impl_SetVertexColor,
987 IDirect3DRMMeshBuilder2Impl_SetVertexColorRGB,
988 IDirect3DRMMeshBuilder2Impl_GetFaces,
989 IDirect3DRMMeshBuilder2Impl_GetVertices,
990 IDirect3DRMMeshBuilder2Impl_GetTextureCoordinates,
991 IDirect3DRMMeshBuilder2Impl_AddVertex,
992 IDirect3DRMMeshBuilder2Impl_AddNormal,
993 IDirect3DRMMeshBuilder2Impl_CreateFace,
994 IDirect3DRMMeshBuilder2Impl_GetQuality,
995 IDirect3DRMMeshBuilder2Impl_GetPerspective,
996 IDirect3DRMMeshBuilder2Impl_GetFaceCount,
997 IDirect3DRMMeshBuilder2Impl_GetVertexCount,
998 IDirect3DRMMeshBuilder2Impl_GetVertexColor,
999 IDirect3DRMMeshBuilder2Impl_CreateMesh,
1000 /*** IDirect3DRMMeshBuilder2 methods ***/
1001 IDirect3DRMMeshBuilder2Impl_GenerateNormals2,
1002 IDirect3DRMMeshBuilder2Impl_GetFace
1006 /*** IUnknown methods ***/
1007 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_QueryInterface(IDirect3DRMMeshBuilder3* iface,
1008 REFIID riid, void** ppvObject)
1010 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1011 return IDirect3DRMMeshBuilder2_QueryInterface(&This->IDirect3DRMMeshBuilder2_iface, riid, ppvObject);
1014 static ULONG WINAPI IDirect3DRMMeshBuilder3Impl_AddRef(IDirect3DRMMeshBuilder3* iface)
1016 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1017 return IDirect3DRMMeshBuilder2_AddRef(&This->IDirect3DRMMeshBuilder2_iface);
1020 static ULONG WINAPI IDirect3DRMMeshBuilder3Impl_Release(IDirect3DRMMeshBuilder3* iface)
1022 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1023 return IDirect3DRMMeshBuilder2_Release(&This->IDirect3DRMMeshBuilder2_iface);
1026 /*** IDirect3DRMObject methods ***/
1027 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Clone(IDirect3DRMMeshBuilder3* iface,
1028 LPUNKNOWN pUnkOuter, REFIID riid,
1031 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1033 FIXME("(%p)->(%p,%s,%p): stub\n", This, pUnkOuter, debugstr_guid(riid), ppvObj);
1038 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddDestroyCallback(IDirect3DRMMeshBuilder3* iface,
1039 D3DRMOBJECTCALLBACK cb,
1042 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1044 FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
1049 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteDestroyCallback(IDirect3DRMMeshBuilder3* iface,
1050 D3DRMOBJECTCALLBACK cb,
1053 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1055 FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
1060 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetAppData(IDirect3DRMMeshBuilder3* iface,
1063 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1065 FIXME("(%p)->(%u): stub\n", This, data);
1070 static DWORD WINAPI IDirect3DRMMeshBuilder3Impl_GetAppData(IDirect3DRMMeshBuilder3* iface)
1072 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1074 FIXME("(%p)->(): stub\n", This);
1079 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetName(IDirect3DRMMeshBuilder3* iface,
1082 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1083 char *string = NULL;
1085 TRACE("(%p)->(%s)\n", This, debugstr_a(name));
1089 string = HeapAlloc(GetProcessHeap(), 0, strlen(name) + 1);
1090 if (!string) return E_OUTOFMEMORY;
1091 strcpy(string, name);
1093 HeapFree(GetProcessHeap(), 0, This->name);
1094 This->name = string;
1099 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetName(IDirect3DRMMeshBuilder3* iface,
1100 LPDWORD size, LPSTR name)
1102 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1104 TRACE("(%p)->(%p,%p)\n", This, size, name);
1115 if (*size < (strlen(This->name) + 1))
1116 return E_INVALIDARG;
1118 strcpy(name, This->name);
1119 *size = strlen(This->name) + 1;
1124 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetClassName(IDirect3DRMMeshBuilder3* iface,
1125 LPDWORD size, LPSTR name)
1127 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1129 TRACE("(%p)->(%p, %p)\n", This, size, name);
1131 if (!size || *size < strlen("Builder") || !name)
1132 return E_INVALIDARG;
1134 strcpy(name, "Builder");
1135 *size = sizeof("Builder");
1140 HRESULT load_mesh_data(IDirect3DRMMeshBuilder3 *iface, IDirectXFileData *pData, D3DRMLOADTEXTURECALLBACK load_texture_proc, void *arg)
1142 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1143 IDirectXFileData *pData2 = NULL;
1148 HRESULT ret = D3DRMERR_BADOBJECT;
1149 DWORD* faces_vertex_idx_data = NULL;
1150 DWORD* faces_vertex_idx_ptr;
1151 DWORD faces_vertex_idx_size;
1152 DWORD* faces_normal_idx_data = NULL;
1153 DWORD* faces_normal_idx_ptr = NULL;
1154 DWORD* faces_data_ptr;
1155 DWORD faces_data_size = 0;
1158 TRACE("(%p)->(%p)\n", This, pData);
1160 hr = IDirectXFileData_GetName(pData, NULL, &size);
1161 if (hr != DXFILE_OK)
1165 This->name = HeapAlloc(GetProcessHeap(), 0, size);
1167 return E_OUTOFMEMORY;
1169 hr = IDirectXFileData_GetName(pData, This->name, &size);
1170 if (hr != DXFILE_OK)
1174 TRACE("Mesh name is '%s'\n", This->name ? This->name : "");
1176 This->nb_normals = 0;
1178 hr = IDirectXFileData_GetData(pData, NULL, &size, (void**)&ptr);
1179 if (hr != DXFILE_OK)
1182 This->nb_vertices = *(DWORD*)ptr;
1183 This->nb_faces = *(DWORD*)(ptr + sizeof(DWORD) + This->nb_vertices * sizeof(D3DVECTOR));
1184 faces_vertex_idx_size = size - sizeof(DWORD) - This->nb_vertices * sizeof(D3DVECTOR) - sizeof(DWORD);
1185 faces_vertex_idx_ptr = (DWORD*)(ptr + sizeof(DWORD) + This->nb_vertices * sizeof(D3DVECTOR) + sizeof(DWORD));
1187 TRACE("Mesh: nb_vertices = %d, nb_faces = %d, faces_vertex_idx_size = %d\n", This->nb_vertices, This->nb_faces, faces_vertex_idx_size);
1189 This->pVertices = HeapAlloc(GetProcessHeap(), 0, This->nb_vertices * sizeof(D3DVECTOR));
1190 memcpy(This->pVertices, ptr + sizeof(DWORD), This->nb_vertices * sizeof(D3DVECTOR));
1192 faces_vertex_idx_ptr = faces_vertex_idx_data = HeapAlloc(GetProcessHeap(), 0, faces_vertex_idx_size);
1193 memcpy(faces_vertex_idx_data, ptr + sizeof(DWORD) + This->nb_vertices * sizeof(D3DVECTOR) + sizeof(DWORD), faces_vertex_idx_size);
1195 /* Each vertex index will have its normal index counterpart so just allocate twice the size */
1196 This->pFaceData = HeapAlloc(GetProcessHeap(), 0, faces_vertex_idx_size * 2);
1197 faces_data_ptr = (DWORD*)This->pFaceData;
1201 IDirectXFileObject *object;
1203 hr = IDirectXFileData_GetNextObject(pData, &object);
1204 if (hr == DXFILEERR_NOMOREOBJECTS)
1206 TRACE("No more object\n");
1209 if (hr != DXFILE_OK)
1212 hr = IDirectXFileObject_QueryInterface(object, &IID_IDirectXFileData, (void**)&pData2);
1213 IDirectXFileObject_Release(object);
1214 if (hr != DXFILE_OK)
1217 hr = IDirectXFileData_GetType(pData2, &guid);
1218 if (hr != DXFILE_OK)
1221 TRACE("Found object type whose GUID = %s\n", debugstr_guid(guid));
1223 if (IsEqualGUID(guid, &TID_D3DRMMeshNormals))
1225 DWORD nb_faces_normals;
1226 DWORD faces_normal_idx_size;
1228 hr = IDirectXFileData_GetData(pData2, NULL, &size, (void**)&ptr);
1229 if (hr != DXFILE_OK)
1232 This->nb_normals = *(DWORD*)ptr;
1233 nb_faces_normals = *(DWORD*)(ptr + sizeof(DWORD) + This->nb_normals * sizeof(D3DVECTOR));
1235 TRACE("MeshNormals: nb_normals = %d, nb_faces_normals = %d\n", This->nb_normals, nb_faces_normals);
1236 if (nb_faces_normals != This->nb_faces)
1237 WARN("nb_face_normals (%d) != nb_faces (%d)\n", nb_faces_normals, This->nb_normals);
1239 This->pNormals = HeapAlloc(GetProcessHeap(), 0, This->nb_normals * sizeof(D3DVECTOR));
1240 memcpy(This->pNormals, ptr + sizeof(DWORD), This->nb_normals * sizeof(D3DVECTOR));
1242 faces_normal_idx_size = size - (2 * sizeof(DWORD) + This->nb_normals * sizeof(D3DVECTOR));
1243 faces_normal_idx_ptr = faces_normal_idx_data = HeapAlloc(GetProcessHeap(), 0, faces_normal_idx_size);
1244 memcpy(faces_normal_idx_data, ptr + sizeof(DWORD) + This->nb_normals * sizeof(D3DVECTOR) + sizeof(DWORD), faces_normal_idx_size);
1246 else if (IsEqualGUID(guid, &TID_D3DRMMeshTextureCoords))
1248 hr = IDirectXFileData_GetData(pData2, NULL, &size, (void**)&ptr);
1249 if (hr != DXFILE_OK)
1252 This->nb_coords2d = *(DWORD*)ptr;
1254 TRACE("MeshTextureCoords: nb_coords2d = %d\n", This->nb_coords2d);
1256 This->pCoords2d = HeapAlloc(GetProcessHeap(), 0, This->nb_coords2d * sizeof(Coords2d));
1257 memcpy(This->pCoords2d, ptr + sizeof(DWORD), This->nb_coords2d * sizeof(Coords2d));
1260 else if (IsEqualGUID(guid, &TID_D3DRMMeshMaterialList))
1263 DWORD nb_face_indices;
1265 IDirectXFileObject *child;
1269 TRACE("Process MeshMaterialList\n");
1271 hr = IDirectXFileData_GetData(pData2, NULL, &size, (void**)&ptr);
1272 if (hr != DXFILE_OK)
1275 nb_materials = *(DWORD*)ptr;
1276 nb_face_indices = *(DWORD*)(ptr + sizeof(DWORD));
1277 data_size = 2 * sizeof(DWORD) + nb_face_indices * sizeof(DWORD);
1279 TRACE("nMaterials = %u, nFaceIndexes = %u\n", nb_materials, nb_face_indices);
1281 if (size != data_size)
1282 WARN("Returned size %u does not match expected one %u\n", size, data_size);
1284 This->material_indices = HeapAlloc(GetProcessHeap(), 0, sizeof(*This->material_indices) * nb_face_indices);
1285 if (!This->material_indices)
1287 memcpy(This->material_indices, ptr + 2 * sizeof(DWORD), sizeof(*This->material_indices) * nb_face_indices),
1289 This->materials = HeapAlloc(GetProcessHeap(), 0, sizeof(*This->materials) * nb_materials);
1290 if (!This->materials)
1292 HeapFree(GetProcessHeap(), 0, This->material_indices);
1295 This->nb_materials = nb_materials;
1297 while (SUCCEEDED(hr = IDirectXFileData_GetNextObject(pData2, &child)) && (i < nb_materials))
1299 IDirectXFileData *data;
1300 IDirectXFileDataReference *reference;
1301 IDirectXFileObject *material_child;
1303 hr = IDirectXFileObject_QueryInterface(child, &IID_IDirectXFileData, (void **)&data);
1306 hr = IDirectXFileObject_QueryInterface(child, &IID_IDirectXFileDataReference, (void **)&reference);
1307 IDirectXFileObject_Release(child);
1311 hr = IDirectXFileDataReference_Resolve(reference, &data);
1312 IDirectXFileDataReference_Release(reference);
1318 IDirectXFileObject_Release(child);
1321 hr = Direct3DRMMaterial_create(&This->materials[i].material);
1324 IDirectXFileData_Release(data);
1328 hr = IDirectXFileData_GetData(data, NULL, &size, (void**)&ptr);
1329 if (hr != DXFILE_OK)
1331 IDirectXFileData_Release(data);
1336 WARN("Material size %u does not match expected one %u\n", size, 44);
1338 values = (float*)ptr;
1340 This->materials[i].color = D3DCOLOR_ARGB((BYTE)(values[3] * 255.0f), (BYTE)(values[0] * 255.0f),
1341 (BYTE)(values[1] * 255.0f), (BYTE)(values[2] * 255.0f));
1343 IDirect3DRMMaterial2_SetAmbient(This->materials[i].material, values[0], values [1], values[2]); /* Alpha ignored */
1344 IDirect3DRMMaterial2_SetPower(This->materials[i].material, values[4]);
1345 IDirect3DRMMaterial2_SetSpecular(This->materials[i].material, values[5], values[6], values[7]);
1346 IDirect3DRMMaterial2_SetEmissive(This->materials[i].material, values[8], values[9], values[10]);
1348 This->materials[i].texture = NULL;
1350 hr = IDirectXFileData_GetNextObject(data, &material_child);
1353 IDirectXFileData *data;
1356 hr = IDirectXFileObject_QueryInterface(material_child, &IID_IDirectXFileData, (void **)&data);
1359 IDirectXFileDataReference *reference;
1361 hr = IDirectXFileObject_QueryInterface(material_child, &IID_IDirectXFileDataReference, (void **)&reference);
1365 hr = IDirectXFileDataReference_Resolve(reference, &data);
1366 IDirectXFileDataReference_Release(reference);
1371 hr = IDirectXFileData_GetType(data, &guid);
1372 if (hr != DXFILE_OK)
1374 if (!IsEqualGUID(guid, &TID_D3DRMTextureFilename))
1376 WARN("Not a texture filename\n");
1381 hr = IDirectXFileData_GetData(data, NULL, &size, (void**)&filename);
1384 if (load_texture_proc)
1386 IDirect3DRMTexture *texture;
1388 hr = load_texture_proc(*filename, arg, &texture);
1391 hr = IDirect3DTexture_QueryInterface(texture, &IID_IDirect3DRMTexture3, (void**)&This->materials[i].texture);
1392 IDirect3DTexture_Release(texture);
1399 /* If the texture file is not found, no texture is associated with the material */
1400 file = CreateFileA(*filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
1401 if (file != INVALID_HANDLE_VALUE)
1405 hr = Direct3DRMTexture_create(&IID_IDirect3DRMTexture3, (IUnknown**)&This->materials[i].texture);
1408 IDirectXFileData_Release(data);
1415 else if (hr != DXFILEERR_NOMOREOBJECTS)
1421 IDirectXFileData_Release(data);
1426 IDirectXFileObject_Release(child);
1427 WARN("Found more sub-objects than expected\n");
1429 else if (hr != DXFILEERR_NOMOREOBJECTS)
1437 FIXME("Unknown GUID %s, ignoring...\n", debugstr_guid(guid));
1440 IDirectXFileData_Release(pData2);
1444 if (!This->nb_normals)
1446 /* Allocate normals, one per vertex */
1447 This->pNormals = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->nb_vertices * sizeof(D3DVECTOR));
1448 if (!This->pNormals)
1452 for (i = 0; i < This->nb_faces; i++)
1455 DWORD nb_face_indexes;
1456 D3DVECTOR face_normal;
1458 if (faces_vertex_idx_size < sizeof(DWORD))
1459 WARN("Not enough data to read number of indices of face %d\n", i);
1461 nb_face_indexes = *(faces_data_ptr + faces_data_size++) = *(faces_vertex_idx_ptr++);
1462 faces_vertex_idx_size--;
1463 if (faces_normal_idx_data && (*(faces_normal_idx_ptr++) != nb_face_indexes))
1464 WARN("Faces indices number mismatch\n");
1466 if (faces_vertex_idx_size < (nb_face_indexes * sizeof(DWORD)))
1467 WARN("Not enough data to read all indices of face %d\n", i);
1469 if (!This->nb_normals)
1471 /* Compute face normal */
1472 if (nb_face_indexes > 2)
1476 D3DRMVectorSubtract(&a, &This->pVertices[faces_vertex_idx_ptr[2]], &This->pVertices[faces_vertex_idx_ptr[1]]);
1477 D3DRMVectorSubtract(&b, &This->pVertices[faces_vertex_idx_ptr[0]], &This->pVertices[faces_vertex_idx_ptr[1]]);
1478 D3DRMVectorCrossProduct(&face_normal, &a, &b);
1479 D3DRMVectorNormalize(&face_normal);
1483 face_normal.u1.x = 0.0f;
1484 face_normal.u2.y = 0.0f;
1485 face_normal.u3.z = 0.0f;
1489 for (j = 0; j < nb_face_indexes; j++)
1491 /* Copy vertex index */
1492 *(faces_data_ptr + faces_data_size++) = *faces_vertex_idx_ptr;
1493 /* Copy normal index */
1494 if (This->nb_normals)
1496 /* Read from x file */
1497 *(faces_data_ptr + faces_data_size++) = *(faces_normal_idx_ptr++);
1501 DWORD vertex_idx = *faces_vertex_idx_ptr;
1502 if (vertex_idx >= This->nb_vertices)
1504 WARN("Found vertex index %u but only %u vertices available => use index 0\n", vertex_idx, This->nb_vertices);
1507 *(faces_data_ptr + faces_data_size++) = vertex_idx;
1508 /* Add face normal to vertex normal */
1509 D3DRMVectorAdd(&This->pNormals[vertex_idx], &This->pNormals[vertex_idx], &face_normal);
1511 faces_vertex_idx_ptr++;
1513 faces_vertex_idx_size -= nb_face_indexes;
1516 /* Last DWORD must be 0 */
1517 *(faces_data_ptr + faces_data_size++) = 0;
1519 /* Set size (in number of DWORD) of all faces data */
1520 This->face_data_size = faces_data_size;
1522 if (!This->nb_normals)
1524 /* Normalize all normals */
1525 for (i = 0; i < This->nb_vertices; i++)
1527 D3DRMVectorNormalize(&This->pNormals[i]);
1529 This->nb_normals = This->nb_vertices;
1532 /* If there is no texture coordinates, generate default texture coordinates (0.0f, 0.0f) for each vertex */
1533 if (!This->pCoords2d)
1535 This->nb_coords2d = This->nb_vertices;
1536 This->pCoords2d = HeapAlloc(GetProcessHeap(), 0, This->nb_coords2d * sizeof(Coords2d));
1537 for (i = 0; i < This->nb_coords2d; i++)
1539 This->pCoords2d[i].u = 0.0f;
1540 This->pCoords2d[i].v = 0.0f;
1544 TRACE("Mesh data loaded successfully\n");
1550 HeapFree(GetProcessHeap(), 0, faces_normal_idx_data);
1551 HeapFree(GetProcessHeap(), 0, faces_vertex_idx_data);
1556 /*** IDirect3DRMMeshBuilder3 methods ***/
1557 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Load(IDirect3DRMMeshBuilder3* iface,
1558 void *filename, void *name,
1559 D3DRMLOADOPTIONS loadflags,
1560 D3DRMLOADTEXTURE3CALLBACK cb, void *arg)
1562 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1563 DXFILELOADOPTIONS load_options;
1564 IDirectXFile *dxfile = NULL;
1565 IDirectXFileEnumObject *enum_object = NULL;
1566 IDirectXFileData *data = NULL;
1571 HRESULT ret = D3DRMERR_BADOBJECT;
1573 TRACE("(%p)->(%p,%p,%x,%p,%p)\n", This, filename, name, loadflags, cb, arg);
1575 clean_mesh_builder_data(This);
1577 if (loadflags == D3DRMLOAD_FROMMEMORY)
1579 load_options = DXFILELOAD_FROMMEMORY;
1581 else if (loadflags == D3DRMLOAD_FROMFILE)
1583 load_options = DXFILELOAD_FROMFILE;
1584 TRACE("Loading from file %s\n", debugstr_a(filename));
1588 FIXME("Load options %d not supported yet\n", loadflags);
1592 hr = DirectXFileCreate(&dxfile);
1593 if (hr != DXFILE_OK)
1596 hr = IDirectXFile_RegisterTemplates(dxfile, templates, strlen(templates));
1597 if (hr != DXFILE_OK)
1600 hr = IDirectXFile_CreateEnumObject(dxfile, filename, load_options, &enum_object);
1601 if (hr != DXFILE_OK)
1604 hr = IDirectXFileEnumObject_GetNextDataObject(enum_object, &data);
1605 if (hr != DXFILE_OK)
1608 hr = IDirectXFileData_GetType(data, &guid);
1609 if (hr != DXFILE_OK)
1612 TRACE("Found object type whose GUID = %s\n", debugstr_guid(guid));
1614 if (!IsEqualGUID(guid, &TID_DXFILEHeader))
1616 ret = D3DRMERR_BADFILE;
1620 hr = IDirectXFileData_GetData(data, NULL, &size, (void**)&header);
1621 if ((hr != DXFILE_OK) || (size != sizeof(Header)))
1624 TRACE("Version is %d %d %d\n", header->major, header->minor, header->flags);
1626 /* Version must be 1.0.x */
1627 if ((header->major != 1) || (header->minor != 0))
1629 ret = D3DRMERR_BADFILE;
1633 IDirectXFileData_Release(data);
1636 hr = IDirectXFileEnumObject_GetNextDataObject(enum_object, &data);
1637 if (hr != DXFILE_OK)
1639 ret = D3DRMERR_NOTFOUND;
1643 hr = IDirectXFileData_GetType(data, &guid);
1644 if (hr != DXFILE_OK)
1647 TRACE("Found object type whose GUID = %s\n", debugstr_guid(guid));
1649 if (!IsEqualGUID(guid, &TID_D3DRMMesh))
1651 ret = D3DRMERR_NOTFOUND;
1655 /* We don't care about the texture interface version since we rely on QueryInterface */
1656 hr = load_mesh_data(iface, data, (D3DRMLOADTEXTURECALLBACK)cb, arg);
1663 IDirectXFileData_Release(data);
1665 IDirectXFileEnumObject_Release(enum_object);
1667 IDirectXFile_Release(dxfile);
1669 if (ret != D3DRM_OK)
1670 clean_mesh_builder_data(This);
1675 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Save(IDirect3DRMMeshBuilder3* iface,
1676 const char* filename, D3DRMXOFFORMAT format,
1677 D3DRMSAVEOPTIONS save)
1679 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1681 FIXME("(%p)->(%s,%d,%d): stub\n", This, filename, format, save);
1686 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Scale(IDirect3DRMMeshBuilder3* iface,
1687 D3DVALUE sx, D3DVALUE sy, D3DVALUE sz)
1689 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1692 TRACE("(%p)->(%f,%f,%f)\n", This, sx, sy, sz);
1694 for (i = 0; i < This->nb_vertices; i++)
1696 This->pVertices[i].u1.x *= sx;
1697 This->pVertices[i].u2.y *= sy;
1698 This->pVertices[i].u3.z *= sz;
1701 /* Normals are not affected by Scale */
1706 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Translate(IDirect3DRMMeshBuilder3* iface,
1707 D3DVALUE tx, D3DVALUE ty, D3DVALUE tz)
1709 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1711 FIXME("(%p)->(%f,%f,%f): stub\n", This, tx, ty, tz);
1716 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetColorSource(IDirect3DRMMeshBuilder3* iface,
1717 D3DRMCOLORSOURCE color)
1719 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1721 FIXME("(%p)->(%x): stub\n", This, color);
1726 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetBox(IDirect3DRMMeshBuilder3* iface,
1729 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1731 FIXME("(%p)->(%p): stub\n", This, box);
1736 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GenerateNormals(IDirect3DRMMeshBuilder3* iface,
1737 D3DVALUE crease, DWORD flags)
1739 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1741 FIXME("(%p)->(%f,%u): stub\n", This, crease, flags);
1746 static D3DRMCOLORSOURCE WINAPI IDirect3DRMMeshBuilder3Impl_GetColorSource(IDirect3DRMMeshBuilder3* iface)
1748 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1750 FIXME("(%p)->(): stub\n", This);
1755 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddMesh(IDirect3DRMMeshBuilder3* iface,
1756 LPDIRECT3DRMMESH Mesh)
1758 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1760 FIXME("(%p)->(%p): stub\n", This, Mesh);
1765 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddMeshBuilder(IDirect3DRMMeshBuilder3* iface,
1766 LPDIRECT3DRMMESHBUILDER3 MeshBuilder,
1769 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1771 FIXME("(%p)->(%p,%u): stub\n", This, MeshBuilder, flags);
1776 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddFrame(IDirect3DRMMeshBuilder3* iface,
1777 LPDIRECT3DRMFRAME3 Frame)
1779 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1781 FIXME("(%p)->(%p): stub\n", This, Frame);
1786 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddFace(IDirect3DRMMeshBuilder3* iface,
1787 LPDIRECT3DRMFACE2 Face)
1789 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1791 FIXME("(%p)->(%p): stub\n", This, Face);
1796 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddFaces(IDirect3DRMMeshBuilder3* iface,
1797 DWORD vcount, D3DVECTOR* vertices,
1798 DWORD ncount, D3DVECTOR* normals,
1800 LPDIRECT3DRMFACEARRAY* FaceArray)
1802 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1804 FIXME("(%p)->(%d,%p,%d,%p,%p,%p): stub\n", This, vcount, vertices, ncount,
1805 normals, data, FaceArray);
1810 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_ReserveSpace(IDirect3DRMMeshBuilder3* iface,
1815 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1817 FIXME("(%p)->(%d,%d,%d): stub\n", This, vertex_Count, normal_count, face_count);
1822 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetColorRGB(IDirect3DRMMeshBuilder3* iface,
1823 D3DVALUE red, D3DVALUE green,
1826 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1828 TRACE("(%p)->(%f,%f,%f)\n", This, red, green, blue);
1830 This->color = D3DCOLOR_ARGB(0xff, (BYTE)(red * 255.0f),
1831 (BYTE)(green * 255.0f),
1832 (BYTE)(blue * 255.0f));
1837 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetColor(IDirect3DRMMeshBuilder3* iface,
1840 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1842 TRACE("(%p)->(%x)\n", This, color);
1844 This->color = color;
1849 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetTexture(IDirect3DRMMeshBuilder3* iface,
1850 LPDIRECT3DRMTEXTURE3 texture)
1852 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1854 TRACE("(%p)->(%p)\n", This, texture);
1857 IDirect3DRMTexture3_AddRef(texture);
1859 IDirect3DRMTexture3_Release(This->texture);
1860 This->texture = texture;
1865 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetMaterial(IDirect3DRMMeshBuilder3* iface,
1866 LPDIRECT3DRMMATERIAL2 material)
1868 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1870 TRACE("(%p)->(%p)\n", This, material);
1873 IDirect3DRMTexture2_AddRef(material);
1875 IDirect3DRMTexture2_Release(This->material);
1876 This->material = material;
1881 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetTextureTopology(IDirect3DRMMeshBuilder3* iface,
1882 BOOL wrap_u, BOOL wrap_v)
1884 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1886 FIXME("(%p)->(%d,%d): stub\n", This, wrap_u, wrap_v);
1891 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetQuality(IDirect3DRMMeshBuilder3* iface,
1892 D3DRMRENDERQUALITY quality)
1894 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1896 FIXME("(%p)->(%d): stub\n", This, quality);
1901 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetPerspective(IDirect3DRMMeshBuilder3* iface,
1904 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1906 FIXME("(%p)->(%d): stub\n", This, enable);
1911 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetVertex(IDirect3DRMMeshBuilder3* iface,
1913 D3DVALUE x, D3DVALUE y, D3DVALUE z)
1915 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1917 FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
1922 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetNormal(IDirect3DRMMeshBuilder3* iface,
1924 D3DVALUE x, D3DVALUE y, D3DVALUE z)
1926 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1928 FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
1933 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetTextureCoordinates(IDirect3DRMMeshBuilder3* iface,
1934 DWORD index, D3DVALUE u,
1937 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1939 TRACE("(%p)->(%u,%f,%f)\n", This, index, u, v);
1941 if (index >= This->nb_coords2d)
1942 return D3DRMERR_BADVALUE;
1944 This->pCoords2d[index].u = u;
1945 This->pCoords2d[index].v = v;
1950 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetVertexColor(IDirect3DRMMeshBuilder3* iface,
1951 DWORD index, D3DCOLOR color)
1953 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1955 FIXME("(%p)->(%d,%x): stub\n", This, index, color);
1960 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetVertexColorRGB(IDirect3DRMMeshBuilder3* iface,
1962 D3DVALUE red, D3DVALUE green,
1965 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1967 FIXME("(%p)->(%d,%f,%f,%f): stub\n", This, index, red, green, blue);
1972 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetFaces(IDirect3DRMMeshBuilder3* iface,
1973 LPDIRECT3DRMFACEARRAY* FaceArray)
1975 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1977 FIXME("(%p)->(%p): stub\n", This, FaceArray);
1982 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetGeometry(IDirect3DRMMeshBuilder3* iface,
1983 DWORD* vcount, D3DVECTOR* vertices,
1984 DWORD* ncount, D3DVECTOR* normals,
1985 DWORD* face_data_size,
1988 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1990 FIXME("(%p)->(%p,%p,%p,%p,%p,%p): stub\n", This, vcount, vertices, ncount, normals,
1991 face_data_size, face_data);
1996 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetTextureCoordinates(IDirect3DRMMeshBuilder3* iface,
1997 DWORD index, D3DVALUE* u,
2000 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2002 TRACE("(%p)->(%d,%p,%p)\n", This, index, u, v);
2004 if (index >= This->nb_coords2d)
2005 return D3DRMERR_BADVALUE;
2007 *u = This->pCoords2d[index].u;
2008 *v = This->pCoords2d[index].v;
2014 static int WINAPI IDirect3DRMMeshBuilder3Impl_AddVertex(IDirect3DRMMeshBuilder3* iface,
2015 D3DVALUE x, D3DVALUE y, D3DVALUE z)
2017 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2019 FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
2024 static int WINAPI IDirect3DRMMeshBuilder3Impl_AddNormal(IDirect3DRMMeshBuilder3* iface,
2025 D3DVALUE x, D3DVALUE y, D3DVALUE z)
2027 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2029 FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
2034 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_CreateFace(IDirect3DRMMeshBuilder3* iface,
2035 LPDIRECT3DRMFACE2* Face)
2037 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2039 FIXME("(%p)->(%p): stub\n", This, Face);
2044 static D3DRMRENDERQUALITY WINAPI IDirect3DRMMeshBuilder3Impl_GetQuality(IDirect3DRMMeshBuilder3* iface)
2046 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2048 FIXME("(%p)->(): stub\n", This);
2053 static BOOL WINAPI IDirect3DRMMeshBuilder3Impl_GetPerspective(IDirect3DRMMeshBuilder3* iface)
2055 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2057 FIXME("(%p)->(): stub\n", This);
2062 static int WINAPI IDirect3DRMMeshBuilder3Impl_GetFaceCount(IDirect3DRMMeshBuilder3* iface)
2064 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2066 TRACE("(%p)->()\n", This);
2068 return This->nb_faces;
2071 static int WINAPI IDirect3DRMMeshBuilder3Impl_GetVertexCount(IDirect3DRMMeshBuilder3* iface)
2073 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2075 TRACE("(%p)->()\n", This);
2077 return This->nb_vertices;
2080 static D3DCOLOR WINAPI IDirect3DRMMeshBuilder3Impl_GetVertexColor(IDirect3DRMMeshBuilder3* iface,
2083 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2085 FIXME("(%p)->(%d): stub\n", This, index);
2090 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_CreateMesh(IDirect3DRMMeshBuilder3* iface,
2091 LPDIRECT3DRMMESH* mesh)
2093 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2095 D3DRMGROUPINDEX group;
2097 TRACE("(%p)->(%p)\n", This, mesh);
2102 hr = Direct3DRMMesh_create(mesh);
2106 /* If there is mesh data, create a group and put data inside */
2107 if (This->nb_vertices)
2111 D3DRMVERTEX* vertices;
2113 vertices = HeapAlloc(GetProcessHeap(), 0, This->nb_vertices * sizeof(D3DRMVERTEX));
2116 IDirect3DRMMesh_Release(*mesh);
2117 return E_OUTOFMEMORY;
2119 for (i = 0; i < This->nb_vertices; i++)
2120 vertices[i].position = This->pVertices[i];
2121 hr = IDirect3DRMMesh_SetVertices(*mesh, 0, 0, This->nb_vertices, vertices);
2122 HeapFree(GetProcessHeap(), 0, vertices);
2124 /* Groups are in reverse order compared to materials list in X file */
2125 for (k = This->nb_materials - 1; k >= 0; k--)
2127 unsigned* face_data;
2129 DWORD* in_ptr = This->pFaceData;
2130 ULONG vertex_per_face = 0;
2131 BOOL* used_vertices;
2132 unsigned nb_vertices = 0;
2133 unsigned nb_faces = 0;
2135 used_vertices = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->face_data_size * sizeof(*used_vertices));
2138 IDirect3DRMMesh_Release(*mesh);
2139 return E_OUTOFMEMORY;
2142 face_data = HeapAlloc(GetProcessHeap(), 0, This->face_data_size * sizeof(*face_data));
2145 HeapFree(GetProcessHeap(), 0, used_vertices);
2146 IDirect3DRMMesh_Release(*mesh);
2147 return E_OUTOFMEMORY;
2149 out_ptr = face_data;
2151 /* If all faces have the same number of vertex, set vertex_per_face */
2152 for (i = 0; i < This->nb_faces; i++)
2154 /* Process only faces belonging to the group */
2155 if (This->material_indices[i] == k)
2157 if (vertex_per_face && (vertex_per_face != *in_ptr))
2159 vertex_per_face = *in_ptr;
2161 in_ptr += 1 + *in_ptr * 2;
2163 if (i != This->nb_faces)
2164 vertex_per_face = 0;
2166 /* Put only vertex indices */
2167 in_ptr = This->pFaceData;
2168 for (i = 0; i < This->nb_faces; i++)
2170 DWORD nb_indices = *in_ptr++;
2172 /* Skip faces not belonging to the group */
2173 if (This->material_indices[i] != k)
2175 in_ptr += 2 * nb_indices;
2179 /* Don't put nb indices when vertex_per_face is set */
2180 if (vertex_per_face)
2181 *out_ptr++ = nb_indices;
2183 for (j = 0; j < nb_indices; j++)
2185 *out_ptr = *in_ptr++;
2186 used_vertices[*out_ptr++] = TRUE;
2187 /* Skip normal index */
2194 for (i = 0; i < This->nb_vertices; i++)
2195 if (used_vertices[i])
2198 hr = IDirect3DRMMesh_AddGroup(*mesh, nb_vertices, nb_faces, vertex_per_face, face_data, &group);
2199 HeapFree(GetProcessHeap(), 0, used_vertices);
2200 HeapFree(GetProcessHeap(), 0, face_data);
2202 hr = IDirect3DRMMesh_SetGroupColor(*mesh, group, This->materials[k].color);
2204 hr = IDirect3DRMMesh_SetGroupMaterial(*mesh, group, (LPDIRECT3DRMMATERIAL)This->materials[k].material);
2205 if (SUCCEEDED(hr) && This->materials[k].texture)
2207 LPDIRECT3DRMTEXTURE texture;
2209 IDirect3DRMTexture3_QueryInterface(This->materials[k].texture, &IID_IDirect3DRMTexture, (LPVOID*)&texture);
2210 hr = IDirect3DRMMesh_SetGroupTexture(*mesh, group, texture);
2211 IDirect3DRMTexture_Release(texture);
2215 IDirect3DRMMesh_Release(*mesh);
2224 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetFace(IDirect3DRMMeshBuilder3* iface,
2225 DWORD index, LPDIRECT3DRMFACE2* Face)
2227 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2229 FIXME("(%p)->(%u,%p): stub\n", This, index, Face);
2234 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetVertex(IDirect3DRMMeshBuilder3 *iface,
2235 DWORD index, D3DVECTOR *vector)
2237 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2239 FIXME("(%p)->(%u,%p): stub\n", This, index, vector);
2244 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetNormal(IDirect3DRMMeshBuilder3 *iface,
2245 DWORD index, D3DVECTOR *vector)
2247 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2249 FIXME("(%p)->(%u,%p): stub\n", This, index, vector);
2254 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteVertices(IDirect3DRMMeshBuilder3* iface,
2255 DWORD IndexFirst, DWORD count)
2257 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2259 FIXME("(%p)->(%u,%u): stub\n", This, IndexFirst, count);
2264 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteNormals(IDirect3DRMMeshBuilder3* iface,
2265 DWORD IndexFirst, DWORD count)
2267 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2269 FIXME("(%p)->(%u,%u): stub\n", This, IndexFirst, count);
2274 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteFace(IDirect3DRMMeshBuilder3* iface,
2275 LPDIRECT3DRMFACE2 Face)
2277 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2279 FIXME("(%p)->(%p): stub\n", This, Face);
2284 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Empty(IDirect3DRMMeshBuilder3* iface, DWORD flags)
2286 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2288 FIXME("(%p)->(%u): stub\n", This, flags);
2293 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Optimize(IDirect3DRMMeshBuilder3* iface,
2296 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2298 FIXME("(%p)->(%u): stub\n", This, flags);
2303 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddFacesIndexed(IDirect3DRMMeshBuilder3* iface,
2304 DWORD flags, DWORD* indices,
2305 DWORD* IndexFirst, DWORD* count)
2307 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2309 FIXME("(%p)->(%u,%p,%p,%p): stub\n", This, flags, indices, IndexFirst, count);
2314 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_CreateSubMesh(IDirect3DRMMeshBuilder3* iface,
2317 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2319 FIXME("(%p)->(%p): stub\n", This, unkwn);
2324 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetParentMesh(IDirect3DRMMeshBuilder3* iface,
2325 DWORD flags, LPUNKNOWN *unkwn)
2327 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2329 FIXME("(%p)->(%u,%p): stub\n", This, flags, unkwn);
2334 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetSubMeshes(IDirect3DRMMeshBuilder3* iface,
2335 LPDWORD count, LPUNKNOWN *unkwn)
2337 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2339 FIXME("(%p)->(%p,%p): stub\n", This, count, unkwn);
2344 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteSubMesh(IDirect3DRMMeshBuilder3* iface,
2347 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2349 FIXME("(%p)->(%p): stub\n", This, unkwn);
2354 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Enable(IDirect3DRMMeshBuilder3* iface,
2357 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2359 FIXME("(%p)->(%u): stub\n", This, index);
2364 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetEnable(IDirect3DRMMeshBuilder3* iface,
2367 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2369 FIXME("(%p)->(%p): stub\n", This, indices);
2374 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddTriangles(IDirect3DRMMeshBuilder3* iface,
2375 DWORD flags, DWORD format,
2376 DWORD VertexCount, LPVOID data)
2378 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2380 FIXME("(%p)->(%u,%u,%u,%p): stub\n", This, flags, format, VertexCount, data);
2385 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetVertices(IDirect3DRMMeshBuilder3 *iface,
2386 DWORD IndexFirst, DWORD count, D3DVECTOR *vector)
2388 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2390 FIXME("(%p)->(%u,%u,%p): stub\n", This, IndexFirst, count, vector);
2395 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetVertices(IDirect3DRMMeshBuilder3 *iface,
2396 DWORD IndexFirst, DWORD *vcount, D3DVECTOR *vertices)
2398 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2399 DWORD count = This->nb_vertices - IndexFirst;
2401 TRACE("(%p)->(%u,%p,%p)\n", This, IndexFirst, vcount, vertices);
2405 if (vertices && This->nb_vertices)
2406 memcpy(vertices, This->pVertices + IndexFirst, count * sizeof(D3DVECTOR));
2411 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetNormals(IDirect3DRMMeshBuilder3 *iface,
2412 DWORD IndexFirst, DWORD count, D3DVECTOR *vector)
2414 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2416 FIXME("(%p)->(%u,%u,%p): stub\n", This, IndexFirst, count, vector);
2421 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetNormals(IDirect3DRMMeshBuilder3 *iface,
2422 DWORD IndexFirst, DWORD *count, D3DVECTOR *vector)
2424 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2426 FIXME("(%p)->(%u,%p,%p): stub\n", This, IndexFirst, count, vector);
2431 static int WINAPI IDirect3DRMMeshBuilder3Impl_GetNormalCount(IDirect3DRMMeshBuilder3* iface)
2433 IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2435 FIXME("(%p)->(): stub\n", This);
2440 static const struct IDirect3DRMMeshBuilder3Vtbl Direct3DRMMeshBuilder3_Vtbl =
2442 /*** IUnknown methods ***/
2443 IDirect3DRMMeshBuilder3Impl_QueryInterface,
2444 IDirect3DRMMeshBuilder3Impl_AddRef,
2445 IDirect3DRMMeshBuilder3Impl_Release,
2446 /*** IDirect3DRMObject methods ***/
2447 IDirect3DRMMeshBuilder3Impl_Clone,
2448 IDirect3DRMMeshBuilder3Impl_AddDestroyCallback,
2449 IDirect3DRMMeshBuilder3Impl_DeleteDestroyCallback,
2450 IDirect3DRMMeshBuilder3Impl_SetAppData,
2451 IDirect3DRMMeshBuilder3Impl_GetAppData,
2452 IDirect3DRMMeshBuilder3Impl_SetName,
2453 IDirect3DRMMeshBuilder3Impl_GetName,
2454 IDirect3DRMMeshBuilder3Impl_GetClassName,
2455 /*** IDirect3DRMMeshBuilder3 methods ***/
2456 IDirect3DRMMeshBuilder3Impl_Load,
2457 IDirect3DRMMeshBuilder3Impl_Save,
2458 IDirect3DRMMeshBuilder3Impl_Scale,
2459 IDirect3DRMMeshBuilder3Impl_Translate,
2460 IDirect3DRMMeshBuilder3Impl_SetColorSource,
2461 IDirect3DRMMeshBuilder3Impl_GetBox,
2462 IDirect3DRMMeshBuilder3Impl_GenerateNormals,
2463 IDirect3DRMMeshBuilder3Impl_GetColorSource,
2464 IDirect3DRMMeshBuilder3Impl_AddMesh,
2465 IDirect3DRMMeshBuilder3Impl_AddMeshBuilder,
2466 IDirect3DRMMeshBuilder3Impl_AddFrame,
2467 IDirect3DRMMeshBuilder3Impl_AddFace,
2468 IDirect3DRMMeshBuilder3Impl_AddFaces,
2469 IDirect3DRMMeshBuilder3Impl_ReserveSpace,
2470 IDirect3DRMMeshBuilder3Impl_SetColorRGB,
2471 IDirect3DRMMeshBuilder3Impl_SetColor,
2472 IDirect3DRMMeshBuilder3Impl_SetTexture,
2473 IDirect3DRMMeshBuilder3Impl_SetMaterial,
2474 IDirect3DRMMeshBuilder3Impl_SetTextureTopology,
2475 IDirect3DRMMeshBuilder3Impl_SetQuality,
2476 IDirect3DRMMeshBuilder3Impl_SetPerspective,
2477 IDirect3DRMMeshBuilder3Impl_SetVertex,
2478 IDirect3DRMMeshBuilder3Impl_SetNormal,
2479 IDirect3DRMMeshBuilder3Impl_SetTextureCoordinates,
2480 IDirect3DRMMeshBuilder3Impl_SetVertexColor,
2481 IDirect3DRMMeshBuilder3Impl_SetVertexColorRGB,
2482 IDirect3DRMMeshBuilder3Impl_GetFaces,
2483 IDirect3DRMMeshBuilder3Impl_GetGeometry,
2484 IDirect3DRMMeshBuilder3Impl_GetTextureCoordinates,
2485 IDirect3DRMMeshBuilder3Impl_AddVertex,
2486 IDirect3DRMMeshBuilder3Impl_AddNormal,
2487 IDirect3DRMMeshBuilder3Impl_CreateFace,
2488 IDirect3DRMMeshBuilder3Impl_GetQuality,
2489 IDirect3DRMMeshBuilder3Impl_GetPerspective,
2490 IDirect3DRMMeshBuilder3Impl_GetFaceCount,
2491 IDirect3DRMMeshBuilder3Impl_GetVertexCount,
2492 IDirect3DRMMeshBuilder3Impl_GetVertexColor,
2493 IDirect3DRMMeshBuilder3Impl_CreateMesh,
2494 IDirect3DRMMeshBuilder3Impl_GetFace,
2495 IDirect3DRMMeshBuilder3Impl_GetVertex,
2496 IDirect3DRMMeshBuilder3Impl_GetNormal,
2497 IDirect3DRMMeshBuilder3Impl_DeleteVertices,
2498 IDirect3DRMMeshBuilder3Impl_DeleteNormals,
2499 IDirect3DRMMeshBuilder3Impl_DeleteFace,
2500 IDirect3DRMMeshBuilder3Impl_Empty,
2501 IDirect3DRMMeshBuilder3Impl_Optimize,
2502 IDirect3DRMMeshBuilder3Impl_AddFacesIndexed,
2503 IDirect3DRMMeshBuilder3Impl_CreateSubMesh,
2504 IDirect3DRMMeshBuilder3Impl_GetParentMesh,
2505 IDirect3DRMMeshBuilder3Impl_GetSubMeshes,
2506 IDirect3DRMMeshBuilder3Impl_DeleteSubMesh,
2507 IDirect3DRMMeshBuilder3Impl_Enable,
2508 IDirect3DRMMeshBuilder3Impl_GetEnable,
2509 IDirect3DRMMeshBuilder3Impl_AddTriangles,
2510 IDirect3DRMMeshBuilder3Impl_SetVertices,
2511 IDirect3DRMMeshBuilder3Impl_GetVertices,
2512 IDirect3DRMMeshBuilder3Impl_SetNormals,
2513 IDirect3DRMMeshBuilder3Impl_GetNormals,
2514 IDirect3DRMMeshBuilder3Impl_GetNormalCount
2517 HRESULT Direct3DRMMeshBuilder_create(REFIID riid, IUnknown** ppObj)
2519 IDirect3DRMMeshBuilderImpl* object;
2521 TRACE("(%p)\n", ppObj);
2523 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DRMMeshBuilderImpl));
2525 return E_OUTOFMEMORY;
2527 object->IDirect3DRMMeshBuilder2_iface.lpVtbl = &Direct3DRMMeshBuilder2_Vtbl;
2528 object->IDirect3DRMMeshBuilder3_iface.lpVtbl = &Direct3DRMMeshBuilder3_Vtbl;
2531 if (IsEqualGUID(riid, &IID_IDirect3DRMMeshBuilder3))
2532 *ppObj = (IUnknown*)&object->IDirect3DRMMeshBuilder3_iface;
2534 *ppObj = (IUnknown*)&object->IDirect3DRMMeshBuilder2_iface;
2539 /*** IUnknown methods ***/
2540 static HRESULT WINAPI IDirect3DRMMeshImpl_QueryInterface(IDirect3DRMMesh* iface,
2541 REFIID riid, void** ppvObject)
2543 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2545 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
2549 if (IsEqualGUID(riid, &IID_IUnknown) ||
2550 IsEqualGUID(riid, &IID_IDirect3DRMMesh))
2552 *ppvObject = &This->IDirect3DRMMesh_iface;
2556 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2557 return E_NOINTERFACE;
2560 IDirect3DRMMesh_AddRef(iface);
2564 static ULONG WINAPI IDirect3DRMMeshImpl_AddRef(IDirect3DRMMesh* iface)
2566 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2567 ULONG ref = InterlockedIncrement(&This->ref);
2569 TRACE("(%p)->(): new ref = %d\n", This, ref);
2574 static ULONG WINAPI IDirect3DRMMeshImpl_Release(IDirect3DRMMesh* iface)
2576 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2577 ULONG ref = InterlockedDecrement(&This->ref);
2579 TRACE("(%p)->(): new ref = %d\n", This, ref);
2585 for (i = 0; i < This->nb_groups; i++)
2587 HeapFree(GetProcessHeap(), 0, This->groups[i].vertices);
2588 HeapFree(GetProcessHeap(), 0, This->groups[i].face_data);
2589 if (This->groups[i].material)
2590 IDirect3DRMMaterial2_Release(This->groups[i].material);
2591 if (This->groups[i].texture)
2592 IDirect3DRMTexture3_Release(This->groups[i].texture);
2594 HeapFree(GetProcessHeap(), 0, This->groups);
2595 HeapFree(GetProcessHeap(), 0, This);
2601 /*** IDirect3DRMObject methods ***/
2602 static HRESULT WINAPI IDirect3DRMMeshImpl_Clone(IDirect3DRMMesh* iface,
2603 LPUNKNOWN pUnkOuter, REFIID riid,
2606 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2608 FIXME("(%p)->(%p,%s,%p): stub\n", This, pUnkOuter, debugstr_guid(riid), ppvObj);
2613 static HRESULT WINAPI IDirect3DRMMeshImpl_AddDestroyCallback(IDirect3DRMMesh* iface,
2614 D3DRMOBJECTCALLBACK cb,
2617 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2619 FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
2624 static HRESULT WINAPI IDirect3DRMMeshImpl_DeleteDestroyCallback(IDirect3DRMMesh* iface,
2625 D3DRMOBJECTCALLBACK cb,
2628 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2630 FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
2635 static HRESULT WINAPI IDirect3DRMMeshImpl_SetAppData(IDirect3DRMMesh* iface,
2638 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2640 FIXME("(%p)->(%u): stub\n", This, data);
2645 static DWORD WINAPI IDirect3DRMMeshImpl_GetAppData(IDirect3DRMMesh* iface)
2647 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2649 FIXME("(%p)->(): stub\n", This);
2654 static HRESULT WINAPI IDirect3DRMMeshImpl_SetName(IDirect3DRMMesh* iface,
2657 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2659 FIXME("(%p)->(%s): stub\n", This, pName);
2664 static HRESULT WINAPI IDirect3DRMMeshImpl_GetName(IDirect3DRMMesh* iface,
2665 LPDWORD lpdwSize, LPSTR lpName)
2667 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2669 FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
2674 static HRESULT WINAPI IDirect3DRMMeshImpl_GetClassName(IDirect3DRMMesh* iface,
2675 LPDWORD size, LPSTR name)
2677 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2679 TRACE("(%p)->(%p, %p)\n", This, size, name);
2681 if (!size || *size < strlen("Mesh") || !name)
2682 return E_INVALIDARG;
2684 strcpy(name, "Mesh");
2685 *size = sizeof("Mesh");
2690 /*** IDirect3DRMMesh methods ***/
2691 static HRESULT WINAPI IDirect3DRMMeshImpl_Scale(IDirect3DRMMesh* iface,
2692 D3DVALUE sx, D3DVALUE sy, D3DVALUE sz)
2694 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2696 FIXME("(%p)->(%f,%f,%f): stub\n", This, sx, sy,sz);
2701 static HRESULT WINAPI IDirect3DRMMeshImpl_Translate(IDirect3DRMMesh* iface,
2702 D3DVALUE tx, D3DVALUE ty, D3DVALUE tz)
2704 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2706 FIXME("(%p)->(%f,%f,%f): stub\n", This, tx, ty,tz);
2711 static HRESULT WINAPI IDirect3DRMMeshImpl_GetBox(IDirect3DRMMesh* iface,
2714 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2716 FIXME("(%p)->(%p): stub\n", This, box);
2721 static HRESULT WINAPI IDirect3DRMMeshImpl_AddGroup(IDirect3DRMMesh* iface,
2722 unsigned vertex_count, unsigned face_count, unsigned vertex_per_face,
2723 unsigned *face_data, D3DRMGROUPINDEX *return_id)
2725 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2728 TRACE("(%p)->(%u,%u,%u,%p,%p)\n", This, vertex_count, face_count, vertex_per_face, face_data, return_id);
2730 if (!face_data || !return_id)
2733 if ((This->nb_groups + 1) > This->groups_capacity)
2738 if (!This->groups_capacity)
2741 groups = HeapAlloc(GetProcessHeap(), 0, new_capacity * sizeof(mesh_group));
2745 new_capacity = This->groups_capacity * 2;
2746 groups = HeapReAlloc(GetProcessHeap(), 0, This->groups, new_capacity * sizeof(mesh_group));
2750 return E_OUTOFMEMORY;
2752 This->groups_capacity = new_capacity;
2753 This->groups = groups;
2756 group = This->groups + This->nb_groups;
2758 group->vertices = HeapAlloc(GetProcessHeap(), 0, vertex_count * sizeof(D3DRMVERTEX));
2759 if (!group->vertices)
2760 return E_OUTOFMEMORY;
2761 group->nb_vertices = vertex_count;
2762 group->nb_faces = face_count;
2763 group->vertex_per_face = vertex_per_face;
2765 if (vertex_per_face)
2767 group->face_data_size = face_count * vertex_per_face;
2772 unsigned nb_indices;
2773 unsigned* face_data_ptr = face_data;
2774 group->face_data_size = 0;
2776 for (i = 0; i < face_count; i++)
2778 nb_indices = *face_data_ptr;
2779 group->face_data_size += nb_indices + 1;
2780 face_data_ptr += nb_indices;
2784 group->face_data = HeapAlloc(GetProcessHeap(), 0, group->face_data_size * sizeof(unsigned));
2785 if (!group->face_data)
2787 HeapFree(GetProcessHeap(), 0 , group->vertices);
2788 return E_OUTOFMEMORY;
2791 memcpy(group->face_data, face_data, group->face_data_size * sizeof(unsigned));
2793 group->material = NULL;
2794 group->texture = NULL;
2796 *return_id = This->nb_groups++;
2801 static HRESULT WINAPI IDirect3DRMMeshImpl_SetVertices(IDirect3DRMMesh* iface,
2802 D3DRMGROUPINDEX id, unsigned index, unsigned count,
2803 D3DRMVERTEX *values)
2805 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2807 TRACE("(%p)->(%u,%u,%u,%p)\n", This, id, index, count, values);
2809 if (id >= This->nb_groups)
2810 return D3DRMERR_BADVALUE;
2812 if ((index + count - 1) >= This->groups[id].nb_vertices)
2813 return D3DRMERR_BADVALUE;
2818 memcpy(This->groups[id].vertices + index, values, count * sizeof(D3DRMVERTEX));
2823 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupColor(IDirect3DRMMesh* iface,
2824 D3DRMGROUPINDEX id, D3DCOLOR color)
2826 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2828 TRACE("(%p)->(%u,%x)\n", This, id, color);
2830 if (id >= This->nb_groups)
2831 return D3DRMERR_BADVALUE;
2833 This->groups[id].color = color;
2838 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupColorRGB(IDirect3DRMMesh* iface,
2839 D3DRMGROUPINDEX id, D3DVALUE red, D3DVALUE green, D3DVALUE blue)
2841 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2843 TRACE("(%p)->(%u,%f,%f,%f)\n", This, id, red, green, blue);
2845 if (id >= This->nb_groups)
2846 return D3DRMERR_BADVALUE;
2848 This->groups[id].color = D3DCOLOR_ARGB(0xff, (BYTE)(red * 255.0f),
2849 (BYTE)(green * 255.0f),
2850 (BYTE)(blue * 255.0f));
2855 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupMapping(IDirect3DRMMesh* iface,
2856 D3DRMGROUPINDEX id, D3DRMMAPPING value)
2858 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2860 FIXME("(%p)->(%u,%u): stub\n", This, id, value);
2865 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupQuality(IDirect3DRMMesh* iface,
2866 D3DRMGROUPINDEX id, D3DRMRENDERQUALITY value)
2868 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2870 FIXME("(%p)->(%u,%u): stub\n", This, id, value);
2875 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupMaterial(IDirect3DRMMesh* iface,
2876 D3DRMGROUPINDEX id, LPDIRECT3DRMMATERIAL material)
2878 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2880 TRACE("(%p)->(%u,%p)\n", This, id, material);
2882 if (id >= This->nb_groups)
2883 return D3DRMERR_BADVALUE;
2885 if (This->groups[id].material)
2886 IDirect3DRMMaterial2_Release(This->groups[id].material);
2888 This->groups[id].material = (LPDIRECT3DRMMATERIAL2)material;
2891 IDirect3DRMMaterial2_AddRef(This->groups[id].material);
2896 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupTexture(IDirect3DRMMesh* iface,
2897 D3DRMGROUPINDEX id, LPDIRECT3DRMTEXTURE texture)
2899 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2901 TRACE("(%p)->(%u,%p)\n", This, id, texture);
2903 if (id >= This->nb_groups)
2904 return D3DRMERR_BADVALUE;
2906 if (This->groups[id].texture)
2907 IDirect3DRMTexture3_Release(This->groups[id].texture);
2911 This->groups[id].texture = NULL;
2915 return IDirect3DRMTexture3_QueryInterface(texture, &IID_IDirect3DRMTexture, (LPVOID*)&This->groups[id].texture);
2918 static DWORD WINAPI IDirect3DRMMeshImpl_GetGroupCount(IDirect3DRMMesh* iface)
2920 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2922 TRACE("(%p)->()\n", This);
2924 return This->nb_groups;
2927 static HRESULT WINAPI IDirect3DRMMeshImpl_GetGroup(IDirect3DRMMesh* iface,
2928 D3DRMGROUPINDEX id, unsigned *vertex_count, unsigned *face_count, unsigned *vertex_per_face,
2929 DWORD *face_data_size, unsigned *face_data)
2931 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2933 TRACE("(%p)->(%u,%p,%p,%p,%p,%p)\n", This, id, vertex_count, face_count, vertex_per_face, face_data_size, face_data);
2935 if (id >= This->nb_groups)
2936 return D3DRMERR_BADVALUE;
2939 *vertex_count = This->groups[id].nb_vertices;
2941 *face_count = This->groups[id].nb_faces;
2942 if (vertex_per_face)
2943 *vertex_per_face = This->groups[id].vertex_per_face;
2945 *face_data_size = This->groups[id].face_data_size;
2947 memcpy(face_data, This->groups[id].face_data, This->groups[id].face_data_size * sizeof(DWORD));
2952 static HRESULT WINAPI IDirect3DRMMeshImpl_GetVertices(IDirect3DRMMesh* iface,
2953 D3DRMGROUPINDEX id, DWORD index, DWORD count, D3DRMVERTEX *return_ptr)
2955 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2957 TRACE("(%p)->(%u,%u,%u,%p)\n", This, id, index, count, return_ptr);
2959 if (id >= This->nb_groups)
2960 return D3DRMERR_BADVALUE;
2962 if ((index + count - 1) >= This->groups[id].nb_vertices)
2963 return D3DRMERR_BADVALUE;
2968 memcpy(return_ptr, This->groups[id].vertices + index, count * sizeof(D3DRMVERTEX));
2973 static D3DCOLOR WINAPI IDirect3DRMMeshImpl_GetGroupColor(IDirect3DRMMesh* iface, D3DRMGROUPINDEX id)
2975 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2977 TRACE("(%p)->(%u)\n", This, id);
2979 return This->groups[id].color;
2982 static D3DRMMAPPING WINAPI IDirect3DRMMeshImpl_GetGroupMapping(IDirect3DRMMesh* iface, D3DRMGROUPINDEX id)
2984 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2986 FIXME("(%p)->(%u): stub\n", This, id);
2990 static D3DRMRENDERQUALITY WINAPI IDirect3DRMMeshImpl_GetGroupQuality(IDirect3DRMMesh* iface, D3DRMGROUPINDEX id)
2992 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2994 FIXME("(%p)->(%u): stub\n", This, id);
2999 static HRESULT WINAPI IDirect3DRMMeshImpl_GetGroupMaterial(IDirect3DRMMesh* iface,
3000 D3DRMGROUPINDEX id, LPDIRECT3DRMMATERIAL *material)
3002 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
3004 TRACE("(%p)->(%u,%p)\n", This, id, material);
3006 if (id >= This->nb_groups)
3007 return D3DRMERR_BADVALUE;
3012 if (This->groups[id].material)
3013 IDirect3DRMTexture_QueryInterface(This->groups[id].material, &IID_IDirect3DRMMaterial, (void**)material);
3020 static HRESULT WINAPI IDirect3DRMMeshImpl_GetGroupTexture(IDirect3DRMMesh* iface,
3021 D3DRMGROUPINDEX id, LPDIRECT3DRMTEXTURE *texture)
3023 IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
3025 TRACE("(%p)->(%u,%p)\n", This, id, texture);
3027 if (id >= This->nb_groups)
3028 return D3DRMERR_BADVALUE;
3033 if (This->groups[id].texture)
3034 IDirect3DRMTexture_QueryInterface(This->groups[id].texture, &IID_IDirect3DRMTexture, (void**)texture);
3041 static const struct IDirect3DRMMeshVtbl Direct3DRMMesh_Vtbl =
3043 /*** IUnknown methods ***/
3044 IDirect3DRMMeshImpl_QueryInterface,
3045 IDirect3DRMMeshImpl_AddRef,
3046 IDirect3DRMMeshImpl_Release,
3047 /*** IDirect3DRMObject methods ***/
3048 IDirect3DRMMeshImpl_Clone,
3049 IDirect3DRMMeshImpl_AddDestroyCallback,
3050 IDirect3DRMMeshImpl_DeleteDestroyCallback,
3051 IDirect3DRMMeshImpl_SetAppData,
3052 IDirect3DRMMeshImpl_GetAppData,
3053 IDirect3DRMMeshImpl_SetName,
3054 IDirect3DRMMeshImpl_GetName,
3055 IDirect3DRMMeshImpl_GetClassName,
3056 /*** IDirect3DRMMesh methods ***/
3057 IDirect3DRMMeshImpl_Scale,
3058 IDirect3DRMMeshImpl_Translate,
3059 IDirect3DRMMeshImpl_GetBox,
3060 IDirect3DRMMeshImpl_AddGroup,
3061 IDirect3DRMMeshImpl_SetVertices,
3062 IDirect3DRMMeshImpl_SetGroupColor,
3063 IDirect3DRMMeshImpl_SetGroupColorRGB,
3064 IDirect3DRMMeshImpl_SetGroupMapping,
3065 IDirect3DRMMeshImpl_SetGroupQuality,
3066 IDirect3DRMMeshImpl_SetGroupMaterial,
3067 IDirect3DRMMeshImpl_SetGroupTexture,
3068 IDirect3DRMMeshImpl_GetGroupCount,
3069 IDirect3DRMMeshImpl_GetGroup,
3070 IDirect3DRMMeshImpl_GetVertices,
3071 IDirect3DRMMeshImpl_GetGroupColor,
3072 IDirect3DRMMeshImpl_GetGroupMapping,
3073 IDirect3DRMMeshImpl_GetGroupQuality,
3074 IDirect3DRMMeshImpl_GetGroupMaterial,
3075 IDirect3DRMMeshImpl_GetGroupTexture
3078 HRESULT Direct3DRMMesh_create(IDirect3DRMMesh** obj)
3080 IDirect3DRMMeshImpl* object;
3082 TRACE("(%p)\n", obj);
3084 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DRMMeshImpl));
3086 return E_OUTOFMEMORY;
3088 object->IDirect3DRMMesh_iface.lpVtbl = &Direct3DRMMesh_Vtbl;
3091 *obj = &object->IDirect3DRMMesh_iface;