wordpad: Replaced toolbar.bmp with a Tango compliant tool strip.
[wine] / dlls / d3drm / meshbuilder.c
1 /*
2  * Implementation of IDirect3DRMMeshBuilder Interface
3  *
4  * Copyright 2010 Christian Costa
5  *
6  * This file contains the (internal) driver registration functions,
7  * driver enumeration APIs and DirectDraw creation functions.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #include "wine/debug.h"
25
26 #define COBJMACROS
27
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "dxfile.h"
31
32 #include "d3drm_private.h"
33 #include "d3drm.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(d3drm);
36
37 typedef struct {
38     D3DVALUE u;
39     D3DVALUE v;
40 } Coords2d;
41
42 typedef struct {
43     const IDirect3DRMMeshBuilderVtbl *lpVtbl;
44     LONG ref;
45     DWORD nb_vertices;
46     D3DVECTOR* pVertices;
47     DWORD nb_normals;
48     D3DVECTOR* pNormals;
49     DWORD nb_faces;
50     DWORD face_data_size;
51     LPVOID pFaceData;
52     DWORD nb_coords2d;
53     Coords2d* pCoords2d;
54 } IDirect3DRMMeshBuilderImpl;
55
56 typedef struct {
57     WORD major;
58     WORD minor;
59     DWORD flags;
60 } Header;
61
62 static const struct IDirect3DRMMeshBuilderVtbl Direct3DRMMeshBuilder_Vtbl;
63
64 static const GUID GUID_Header =            { 0x3D82AB43, 0x62DA, 0x11CF, { 0xAB, 0x39, 0x00, 0x20, 0xAF, 0x71, 0xE4, 0x33 } };
65 static const GUID GUID_Mesh =              { 0x3D82AB44, 0x62DA, 0x11CF, { 0xAB, 0x39, 0x00, 0x20, 0xAF, 0x71, 0xE4, 0x33 } };
66 static const GUID GUID_MeshTextureCoords = { 0xF6F23F40, 0x7686, 0x11CF, { 0x8F, 0x52, 0x00, 0x40, 0x33, 0x35, 0x94, 0xA3 } };
67 static const GUID GUID_MeshMaterialList =  { 0xF6F23F42, 0x7686, 0x11CF, { 0x8F, 0x52, 0x00, 0x40, 0x33, 0x35, 0x94, 0xA3 } };
68 static const GUID GUID_MeshNormals =       { 0xF6F23F43, 0x7686, 0x11CF, { 0x8F, 0x52, 0x00, 0x40, 0x33, 0x35, 0x94, 0xA3 } };
69
70 static char templates[] = {
71 "xof 0302txt 0064"
72 "template Header"
73 "{"
74 "<3D82AB43-62DA-11CF-AB39-0020AF71E433>"
75 "WORD major;"
76 "WORD minor;"
77 "DWORD flags;"
78 "}"
79 "template Vector"
80 "{"
81 "<3D82AB5E-62DA-11CF-AB39-0020AF71E433>"
82 "FLOAT x;"
83 "FLOAT y;"
84 "FLOAT z;"
85 "}"
86 "template Coords2d"
87 "{"
88 "<F6F23F44-7686-11CF-8F52-0040333594A3>"
89 "FLOAT u;"
90 "FLOAT v;"
91 "}"
92 "template Matrix4x4"
93 "{"
94 "<F6F23F45-7686-11CF-8F52-0040333594A3>"
95 "array FLOAT matrix[16];"
96 "}"
97 "template ColorRGBA"
98 "{"
99 "<35FF44E0-6C7C-11CF-8F52-0040333594A3>"
100 "FLOAT red;"
101 "FLOAT green;"
102 "FLOAT blue;"
103 "FLOAT alpha;"
104 "}"
105 "template ColorRGB"
106 "{"
107 "<D3E16E81-7835-11CF-8F52-0040333594A3>"
108 "FLOAT red;"
109 "FLOAT green;"
110 "FLOAT blue;"
111 "}"
112 "template IndexedColor"
113 "{"
114 "<1630B820-7842-11CF-8F52-0040333594A3>"
115 "DWORD index;"
116 "ColorRGBA indexColor;"
117 "}"
118 "template Boolean"
119 "{"
120 "<537DA6A0-CA37-11D0-941C-0080C80CFA7B>"
121 "DWORD truefalse;"
122 "}"
123 "template Boolean2d"
124 "{"
125 "<4885AE63-78E8-11CF-8F52-0040333594A3>"
126 "Boolean u;"
127 "Boolean v;"
128 "}"
129 "template MaterialWrap"
130 "{"
131 "<4885AE60-78E8-11CF-8F52-0040333594A3>"
132 "Boolean u;"
133 "Boolean v;"
134 "}"
135 "template TextureFilename"
136 "{"
137 "<A42790E1-7810-11CF-8F52-0040333594A3>"
138 "STRING filename;"
139 "}"
140 "template Material"
141 "{"
142 "<3D82AB4D-62DA-11CF-AB39-0020AF71E433>"
143 "ColorRGBA faceColor;"
144 "FLOAT power;"
145 "ColorRGB specularColor;"
146 "ColorRGB emissiveColor;"
147 "[...]"
148 "}"
149 "template MeshFace"
150 "{"
151 "<3D82AB5F-62DA-11CF-AB39-0020AF71E433>"
152 "DWORD nFaceVertexIndices;"
153 "array DWORD faceVertexIndices[nFaceVertexIndices];"
154 "}"
155 "template MeshFaceWraps"
156 "{"
157 "<ED1EC5C0-C0A8-11D0-941C-0080C80CFA7B>"
158 "DWORD nFaceWrapValues;"
159 "array Boolean2d faceWrapValues[nFaceWrapValues];"
160 "}"
161 "template MeshTextureCoords"
162 "{"
163 "<F6F23F40-7686-11CF-8F52-0040333594A3>"
164 "DWORD nTextureCoords;"
165 "array Coords2d textureCoords[nTextureCoords];"
166 "}"
167 "template MeshMaterialList"
168 "{"
169 "<F6F23F42-7686-11CF-8F52-0040333594A3>"
170 "DWORD nMaterials;"
171 "DWORD nFaceIndexes;"
172 "array DWORD faceIndexes[nFaceIndexes];"
173 "[Material]"
174 "}"
175 "template MeshNormals"
176 "{"
177 "<F6F23F43-7686-11CF-8F52-0040333594A3>"
178 "DWORD nNormals;"
179 "array Vector normals[nNormals];"
180 "DWORD nFaceNormals;"
181 "array MeshFace faceNormals[nFaceNormals];"
182 "}"
183 "template MeshVertexColors"
184 "{"
185 "<1630B821-7842-11CF-8F52-0040333594A3>"
186 "DWORD nVertexColors;"
187 "array IndexedColor vertexColors[nVertexColors];"
188 "}"
189 "template Mesh"
190 "{"
191 "<3D82AB44-62DA-11CF-AB39-0020AF71E433>"
192 "DWORD nVertices;"
193 "array Vector vertices[nVertices];"
194 "DWORD nFaces;"
195 "array MeshFace faces[nFaces];"
196 "[...]"
197 "}"
198 "template FrameTransformMatrix"
199 "{"
200 "<F6F23F41-7686-11CF-8F52-0040333594A3>"
201 "Matrix4x4 frameMatrix;"
202 "}"
203 "template Frame"
204 "{"
205 "<3D82AB46-62DA-11CF-AB39-0020AF71E433>"
206 "[...]"
207 "}"
208 "template FloatKeys"
209 "{"
210 "<10DD46A9-775B-11CF-8F52-0040333594A3>"
211 "DWORD nValues;"
212 "array FLOAT values[nValues];"
213 "}"
214 "template TimedFloatKeys"
215 "{"
216 "<F406B180-7B3B-11CF-8F52-0040333594A3>"
217 "DWORD time;"
218 "FloatKeys tfkeys;"
219 "}"
220 "template AnimationKey"
221 "{"
222 "<10DD46A8-775B-11CF-8F52-0040333594A3>"
223 "DWORD keyType;"
224 "DWORD nKeys;"
225 "array TimedFloatKeys keys[nKeys];"
226 "}"
227 "template AnimationOptions"
228 "{"
229 "<E2BF56C0-840F-11CF-8F52-0040333594A3>"
230 "DWORD openclosed;"
231 "DWORD positionquality;"
232 "}"
233 "template Animation"
234 "{"
235 "<3D82AB4F-62DA-11CF-AB39-0020AF71E433>"
236 "[...]"
237 "}"
238 "template AnimationSet"
239 "{"
240 "<3D82AB50-62DA-11CF-AB39-0020AF71E433>"
241 "[Animation]"
242 "}"
243 "template InlineData"
244 "{"
245 "<3A23EEA0-94B1-11D0-AB39-0020AF71E433>"
246 "[BINARY]"
247 "}"
248 "template Url"
249 "{"
250 "<3A23EEA1-94B1-11D0-AB39-0020AF71E433>"
251 "DWORD nUrls;"
252 "array STRING urls[nUrls];"
253 "}"
254 "template ProgressiveMesh"
255 "{"
256 "<8A63C360-997D-11D0-941C-0080C80CFA7B>"
257 "[Url,InlineData]"
258 "}"
259 "template Guid"
260 "{"
261 "<A42790E0-7810-11CF-8F52-0040333594A3>"
262 "DWORD data1;"
263 "WORD data2;"
264 "WORD data3;"
265 "array UCHAR data4[8];"
266 "}"
267 "template StringProperty"
268 "{"
269 "<7F0F21E0-BFE1-11D1-82C0-00A0C9697271>"
270 "STRING key;"
271 "STRING value;"
272 "}"
273 "template PropertyBag"
274 "{"
275 "<7F0F21E1-BFE1-11D1-82C0-00A0C9697271>"
276 "[StringProperty]"
277 "}"
278 "template ExternalVisual"
279 "{"
280 "<98116AA0-BDBA-11D1-82C0-00A0C9697271>"
281 "Guid guidExternalVisual;"
282 "[...]"
283 "}"
284 "template RightHanded"
285 "{"
286 "<7F5D5EA0-D53A-11D1-82C0-00A0C9697271>"
287 "DWORD bRightHanded;"
288 "}"
289 };
290
291 HRESULT Direct3DRMMeshBuilder_create(LPDIRECT3DRMMESHBUILDER* ppMeshBuilder)
292 {
293     IDirect3DRMMeshBuilderImpl* object;
294
295     TRACE("(%p)\n", ppMeshBuilder);
296
297     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DRMMeshBuilderImpl));
298     if (!object)
299     {
300         ERR("Out of memory\n");
301         return E_OUTOFMEMORY;
302     }
303
304     object->lpVtbl = &Direct3DRMMeshBuilder_Vtbl;
305     object->ref = 1;
306
307     *ppMeshBuilder = (IDirect3DRMMeshBuilder*)object;
308
309     return S_OK;
310 }
311
312 /*** IUnknown methods ***/
313 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_QueryInterface(IDirect3DRMMeshBuilder* iface, REFIID riid, void** ppvObject)
314 {
315     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
316
317     TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
318
319     if (IsEqualGUID(riid, &IID_IUnknown) ||
320         IsEqualGUID(riid, &IID_IDirect3DRMMeshBuilder))
321     {
322         IClassFactory_AddRef(iface);
323         *ppvObject = This;
324         return S_OK;
325     }
326
327     ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
328     return E_NOINTERFACE;
329 }
330
331 static ULONG WINAPI IDirect3DRMMeshBuilderImpl_AddRef(IDirect3DRMMeshBuilder* iface)
332 {
333     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
334
335     TRACE("(%p)\n", This);
336
337     return InterlockedIncrement(&This->ref);
338 }
339
340 static ULONG WINAPI IDirect3DRMMeshBuilderImpl_Release(IDirect3DRMMeshBuilder* iface)
341 {
342     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
343     ULONG ref = InterlockedDecrement(&This->ref);
344
345     TRACE("(%p)\n", This);
346
347     if (!ref)
348     {
349         HeapFree(GetProcessHeap(), 0, This->pVertices);
350         HeapFree(GetProcessHeap(), 0, This->pNormals);
351         HeapFree(GetProcessHeap(), 0, This->pFaceData);
352         HeapFree(GetProcessHeap(), 0, This);
353     }
354
355     return ref;
356 }
357
358 /*** IDirect3DRMObject methods ***/
359 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_Clone(IDirect3DRMMeshBuilder* iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObj)
360 {
361     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
362
363     FIXME("(%p)->(%p,%s,%p): stub\n", This, pUnkOuter, debugstr_guid(riid), ppvObj);
364
365     return E_NOTIMPL;
366 }
367
368 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_AddDestroyCallback(IDirect3DRMMeshBuilder* iface, D3DRMOBJECTCALLBACK cb, LPVOID argument)
369 {
370     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
371
372     FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
373
374     return E_NOTIMPL;
375 }
376
377 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_DeleteDestroyCallback(IDirect3DRMMeshBuilder* iface, D3DRMOBJECTCALLBACK cb, LPVOID argument)
378 {
379     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
380
381     FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
382
383     return E_NOTIMPL;
384 }
385
386 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_SetAppData(IDirect3DRMMeshBuilder* iface, DWORD data)
387 {
388     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
389
390     FIXME("(%p)->(%u): stub\n", This, data);
391
392     return E_NOTIMPL;
393 }
394
395 static DWORD WINAPI IDirect3DRMMeshBuilderImpl_GetAppData(IDirect3DRMMeshBuilder* iface)
396 {
397     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
398
399     FIXME("(%p)->(): stub\n", This);
400
401     return 0;
402 }
403
404 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_SetName(IDirect3DRMMeshBuilder* iface, LPCSTR pName)
405 {
406     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
407
408     FIXME("(%p)->(%s): stub\n", This, pName);
409
410     return E_NOTIMPL;
411 }
412
413 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_GetName(IDirect3DRMMeshBuilder* iface, LPDWORD lpdwSize, LPSTR lpName)
414 {
415     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
416
417     FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
418
419     return E_NOTIMPL;
420 }
421
422 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_GetClassName(IDirect3DRMMeshBuilder* iface, LPDWORD lpdwSize, LPSTR lpName)
423 {
424     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
425
426     FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
427
428     return E_NOTIMPL;
429 }
430
431 /*** IDirect3DRMMeshBuilder methods ***/
432 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_Load(IDirect3DRMMeshBuilder* iface, LPVOID filename, LPVOID name, D3DRMLOADOPTIONS loadflags, D3DRMLOADTEXTURECALLBACK cb, LPVOID pArg)
433 {
434     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
435     DXFILELOADOPTIONS load_options;
436     LPDIRECTXFILE pDXFile = NULL;
437     LPDIRECTXFILEENUMOBJECT pEnumObject = NULL;
438     LPDIRECTXFILEDATA pData = NULL;
439     LPDIRECTXFILEOBJECT pObject = NULL;
440     LPDIRECTXFILEDATA pData2 = NULL;
441     const GUID* pGuid;
442     DWORD size;
443     Header* pHeader;
444     LPBYTE ptr;
445     HRESULT hr;
446     HRESULT ret = D3DRMERR_BADOBJECT;
447
448     FIXME("(%p)->(%p,%p,%x,%p,%p): partial stub\n", This, filename, name, loadflags, cb, pArg);
449
450     /* First free allocated buffers of previous mesh data */
451     HeapFree(GetProcessHeap(), 0, This->pVertices);
452     This->pVertices = NULL;
453     HeapFree(GetProcessHeap(), 0, This->pNormals);
454     This->pNormals = NULL;
455     HeapFree(GetProcessHeap(), 0, This->pFaceData);
456     This->pFaceData = NULL;
457     HeapFree(GetProcessHeap(), 0, This->pCoords2d);
458     This->pCoords2d = NULL;
459
460     if (loadflags == D3DRMLOAD_FROMMEMORY)
461     {
462         load_options = DXFILELOAD_FROMMEMORY;
463     }
464     else
465     {
466         FIXME("Load options %d not supported yet\n", loadflags);
467         return E_NOTIMPL;
468     }
469
470     hr = DirectXFileCreate(&pDXFile);
471     if (hr != DXFILE_OK)
472         goto end;
473
474     hr = IDirectXFile_RegisterTemplates(pDXFile, templates, strlen(templates));
475     if (hr != DXFILE_OK)
476         goto end;
477
478     hr = IDirectXFile_CreateEnumObject(pDXFile, filename, load_options, &pEnumObject);
479     if (hr != DXFILE_OK)
480         goto end;
481
482     hr = IDirectXFileEnumObject_GetNextDataObject(pEnumObject, &pData);
483     if (hr != DXFILE_OK)
484         goto end;
485
486     hr = IDirectXFileData_GetType(pData, &pGuid);
487     if (hr != DXFILE_OK)
488         goto end;
489
490     TRACE("Found object type whose GUID = %s\n", debugstr_guid(pGuid));
491
492     if (!IsEqualGUID(pGuid, &GUID_Header))
493     {
494         ret = D3DRMERR_BADFILE;
495         goto end;
496     }
497
498     hr = IDirectXFileData_GetData(pData, NULL, &size, (void**)&pHeader);
499     if ((hr != DXFILE_OK) || (size != sizeof(Header)))
500         goto end;
501
502     TRACE("Version is %d %d %d\n", pHeader->major, pHeader->minor, pHeader->flags);
503
504     /* Version must be 1.0.x */
505     if ((pHeader->major != 1) || (pHeader->minor != 0))
506     {
507         ret = D3DRMERR_BADFILE;
508         goto end;
509     }
510
511     IDirectXFileData_Release(pData);
512     pData = NULL;
513
514     hr = IDirectXFileEnumObject_GetNextDataObject(pEnumObject, &pData);
515     if (hr != DXFILE_OK)
516     {
517         ret = D3DRMERR_NOTFOUND;
518         goto end;
519     }
520
521     hr = IDirectXFileData_GetType(pData, &pGuid);
522     if (hr != DXFILE_OK)
523         goto end;
524
525     TRACE("Found object type whose GUID = %s\n", debugstr_guid(pGuid));
526
527     if (!IsEqualGUID(pGuid, &GUID_Mesh))
528     {
529         ret = D3DRMERR_NOTFOUND;
530         goto end;
531     }
532
533     hr = IDirectXFileData_GetData(pData, NULL, &size, (void**)&ptr);
534     if (hr != DXFILE_OK)
535         goto end;
536
537     This->nb_vertices = *(DWORD*)ptr;
538     This->nb_faces = *(DWORD*)(ptr + sizeof(DWORD) + This->nb_vertices * sizeof(D3DVECTOR));
539     This->face_data_size = size - sizeof(DWORD) - This->nb_vertices * sizeof(D3DVECTOR) - sizeof(DWORD);
540
541     TRACE("Mesh: nb_vertices = %d, nb_faces = %d, face_data_size = %d\n", This->nb_vertices, This->nb_faces, This->face_data_size);
542
543     This->pVertices = HeapAlloc(GetProcessHeap(), 0, This->nb_vertices * sizeof(D3DVECTOR));
544     memcpy(This->pVertices, ptr + sizeof(DWORD), This->nb_vertices * sizeof(D3DVECTOR));
545
546     This->pFaceData = HeapAlloc(GetProcessHeap(), 0, This->face_data_size);
547     memcpy(This->pFaceData, ptr + sizeof(DWORD) + This->nb_vertices * sizeof(D3DVECTOR) + sizeof(DWORD), This->face_data_size);
548
549     while (1)
550     {
551         hr =  IDirectXFileData_GetNextObject(pData, &pObject);
552         if (hr == DXFILEERR_NOMOREOBJECTS)
553         {
554             FIXME("no more object\n");
555             break;
556         }
557         if (hr != DXFILE_OK)
558            goto end;
559
560             hr = IDirectXFileObject_QueryInterface(pObject, &IID_IDirectXFileData, (void**)&pData2);
561         IDirectXFileObject_Release(pObject);
562         if (hr != DXFILE_OK)
563             goto end;
564
565         hr = IDirectXFileData_GetType(pData2, &pGuid);
566         if (hr != DXFILE_OK)
567         {
568             IDirectXFileData_Release(pData2);
569             goto end;
570         }
571
572         FIXME("toto: Found object type whose GUID = %s\n", debugstr_guid(pGuid));
573
574         if (!IsEqualGUID(pGuid, &GUID_MeshNormals))
575         {
576             DWORD tmp;
577
578             hr = IDirectXFileData_GetData(pData, NULL, &size, (void**)&ptr);
579             if (hr != DXFILE_OK)
580                 goto end;
581
582             This->nb_normals = *(DWORD*)ptr;
583             tmp = *(DWORD*)(ptr + sizeof(DWORD) + This->nb_normals * sizeof(D3DVECTOR));
584
585             FIXME("MeshNormals: nb_normals = %d, nb_faces_normals = %d\n", This->nb_normals, tmp);
586
587             This->pNormals = HeapAlloc(GetProcessHeap(), 0, This->nb_normals * sizeof(D3DVECTOR));
588             memcpy(This->pNormals, ptr + sizeof(DWORD), This->nb_normals * sizeof(D3DVECTOR));
589         }
590         else if(!IsEqualGUID(pGuid, &GUID_MeshTextureCoords))
591         {
592             hr = IDirectXFileData_GetData(pData, NULL, &size, (void**)&ptr);
593             if (hr != DXFILE_OK)
594                 goto end;
595
596             This->nb_coords2d = *(DWORD*)ptr;
597
598             FIXME("MeshTextureCoords: nb_coords2d = %d\n", This->nb_coords2d);
599
600             This->pCoords2d = HeapAlloc(GetProcessHeap(), 0, This->nb_coords2d * sizeof(Coords2d));
601             memcpy(This->pCoords2d, ptr + sizeof(DWORD), This->nb_coords2d * sizeof(Coords2d));
602
603         }
604         else if(!IsEqualGUID(pGuid, &GUID_MeshMaterialList))
605         {
606             FIXME("MeshMaterialList not supported yet, ignoring...\n");
607         }
608         else
609         {
610             FIXME("Unknown GUID %s, ignoring...\n", debugstr_guid(pGuid));
611         }
612
613         IDirectXFileData_Release(pData2);
614     }
615
616     ret = D3DRM_OK;
617
618 end:
619     if (pData)
620         IDirectXFileData_Release(pData);
621     if (pEnumObject)
622         IDirectXFileEnumObject_Release(pEnumObject);
623     if (pDXFile)
624         IDirectXFile_Release(pDXFile);
625
626     if (ret != D3DRM_OK)
627     {
628         /* Clean mesh data */
629         This->nb_vertices = 0;
630         This->nb_normals = 0;
631         This->nb_faces = 0;
632         This->face_data_size = 0;
633         This->nb_coords2d = 0;
634         HeapFree(GetProcessHeap(), 0, This->pVertices);
635         This->pVertices = NULL;
636         HeapFree(GetProcessHeap(), 0, This->pNormals);
637         This->pNormals = NULL;
638         HeapFree(GetProcessHeap(), 0, This->pFaceData);
639         This->pFaceData = NULL;
640         HeapFree(GetProcessHeap(), 0, This->pCoords2d);
641         This->pCoords2d = NULL;
642     }
643
644     return ret;
645 }
646
647 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_Save(IDirect3DRMMeshBuilder* iface, const char *filename, D3DRMXOFFORMAT format, D3DRMSAVEOPTIONS save)
648 {
649     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
650
651     FIXME("(%p)->(%s,%d,%d): stub\n", This, filename, format, save);
652
653     return E_NOTIMPL;
654 }
655
656 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_Scale(IDirect3DRMMeshBuilder* iface, D3DVALUE sx, D3DVALUE sy, D3DVALUE sz)
657 {
658     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
659
660     FIXME("(%p)->(%f,%f,%f): stub\n", This, sx, sy, sz);
661
662     return E_NOTIMPL;
663 }
664
665 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_Translate(IDirect3DRMMeshBuilder* iface, D3DVALUE tx, D3DVALUE ty, D3DVALUE tz)
666 {
667     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
668
669     FIXME("(%p)->(%f,%f,%f): stub\n", This, tx, ty, tz);
670
671     return E_NOTIMPL;
672 }
673
674 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_SetColorSource(IDirect3DRMMeshBuilder* iface, D3DRMCOLORSOURCE color)
675 {
676     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
677
678     FIXME("(%p)->(%x): stub\n", This, color);
679
680     return E_NOTIMPL;
681 }
682
683 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_GetBox(IDirect3DRMMeshBuilder* iface, D3DRMBOX *pBox)
684 {
685     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
686
687     FIXME("(%p)->(%p): stub\n", This, pBox);
688
689     return E_NOTIMPL;
690 }
691
692 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_GenerateNormals(IDirect3DRMMeshBuilder* iface)
693 {
694     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
695
696     FIXME("(%p)->(): stub\n", This);
697
698     return E_NOTIMPL;
699 }
700
701 static D3DRMCOLORSOURCE WINAPI IDirect3DRMMeshBuilderImpl_GetColorSource(IDirect3DRMMeshBuilder* iface)
702 {
703     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
704
705     FIXME("(%p)->(): stub\n", This);
706
707     return E_NOTIMPL;
708 }
709
710 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_AddMesh(IDirect3DRMMeshBuilder* iface, LPDIRECT3DRMMESH pMesh)
711 {
712     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
713
714     FIXME("(%p)->(%p): stub\n", This, pMesh);
715
716     return E_NOTIMPL;
717 }
718
719 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_AddMeshBuilder(IDirect3DRMMeshBuilder* iface, LPDIRECT3DRMMESHBUILDER pMeshBuilder)
720 {
721     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
722
723     FIXME("(%p)->(%p): stub\n", This, pMeshBuilder);
724
725     return E_NOTIMPL;
726 }
727
728 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_AddFrame(IDirect3DRMMeshBuilder* iface, LPDIRECT3DRMFRAME pFrame)
729 {
730     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
731
732     FIXME("(%p)->(%p): stub\n", This, pFrame);
733
734     return E_NOTIMPL;
735 }
736
737 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_AddFace(IDirect3DRMMeshBuilder* iface, LPDIRECT3DRMFACE pFace)
738 {
739     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
740
741     FIXME("(%p)->(%p): stub\n", This, pFace);
742
743     return E_NOTIMPL;
744 }
745
746 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_AddFaces(IDirect3DRMMeshBuilder* iface, DWORD vcount, D3DVECTOR *vertices, DWORD ncount, D3DVECTOR *normals, DWORD *data, LPDIRECT3DRMFACEARRAY* pFaceArray)
747 {
748     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
749
750     FIXME("(%p)->(%d,%p,%d,%p,%p,%p): stub\n", This, vcount, vertices, ncount, normals, data, pFaceArray);
751
752     return E_NOTIMPL;
753 }
754
755 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_ReserveSpace(IDirect3DRMMeshBuilder* iface, DWORD vertex_Count, DWORD normal_count, DWORD face_count)
756 {
757     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
758
759     FIXME("(%p)->(%d,%d,%d): stub\n", This, vertex_Count, normal_count, face_count);
760
761     return E_NOTIMPL;
762 }
763
764 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_SetColorRGB(IDirect3DRMMeshBuilder* iface, D3DVALUE red, D3DVALUE green, D3DVALUE blue)
765 {
766     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
767
768     FIXME("(%p)->(%f,%f,%f): stub\n", This, red, green, blue);
769
770     return E_NOTIMPL;
771 }
772
773 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_SetColor(IDirect3DRMMeshBuilder* iface, D3DCOLOR color)
774 {
775     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
776
777     FIXME("(%p)->(%x): stub\n", This, color);
778
779     return E_NOTIMPL;
780 }
781
782 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_SetTexture(IDirect3DRMMeshBuilder* iface, LPDIRECT3DRMTEXTURE pTexture)
783 {
784     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
785
786     FIXME("(%p)->(%p): stub\n", This, pTexture);
787
788     return E_NOTIMPL;
789 }
790
791 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_SetMaterial(IDirect3DRMMeshBuilder* iface, LPDIRECT3DRMMATERIAL pMaterial)
792 {
793     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
794
795     FIXME("(%p)->(%p): stub\n", This, pMaterial);
796
797     return E_NOTIMPL;
798 }
799
800 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_SetTextureTopology(IDirect3DRMMeshBuilder* iface, BOOL wrap_u, BOOL wrap_v)
801 {
802     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
803
804     FIXME("(%p)->(%d,%d): stub\n", This, wrap_u, wrap_v);
805
806     return E_NOTIMPL;
807 }
808
809 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_SetQuality(IDirect3DRMMeshBuilder* iface, D3DRMRENDERQUALITY quality)
810 {
811     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
812
813     FIXME("(%p)->(%d): stub\n", This, quality);
814
815     return E_NOTIMPL;
816 }
817
818 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_SetPerspective(IDirect3DRMMeshBuilder* iface, BOOL enable)
819 {
820     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
821
822     FIXME("(%p)->(%d): stub\n", This, enable);
823
824     return E_NOTIMPL;
825 }
826
827 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_SetVertex(IDirect3DRMMeshBuilder* iface, DWORD index, D3DVALUE x, D3DVALUE y, D3DVALUE z)
828 {
829     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
830
831     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
832
833     return E_NOTIMPL;
834 }
835
836 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_SetNormal(IDirect3DRMMeshBuilder* iface, DWORD index, D3DVALUE x, D3DVALUE y, D3DVALUE z)
837 {
838     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
839
840     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
841
842     return E_NOTIMPL;
843 }
844
845 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_SetTextureCoordinates(IDirect3DRMMeshBuilder* iface, DWORD index, D3DVALUE u, D3DVALUE v)
846 {
847     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
848
849     FIXME("(%p)->(%f,%f): stub\n", This, u, v);
850
851     return E_NOTIMPL;
852 }
853
854 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_SetVertexColor(IDirect3DRMMeshBuilder* iface, DWORD index, D3DCOLOR color)
855 {
856     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
857
858     FIXME("(%p)->(%d,%x): stub\n", This, index, color);
859
860     return E_NOTIMPL;
861 }
862
863 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_SetVertexColorRGB(IDirect3DRMMeshBuilder* iface, DWORD index, D3DVALUE red, D3DVALUE green, D3DVALUE blue)
864 {
865     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
866
867     FIXME("(%p)->(%d,%f,%f,%f): stub\n", This, index, red, green, blue);
868
869     return E_NOTIMPL;
870 }
871
872 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_GetFaces(IDirect3DRMMeshBuilder* iface, LPDIRECT3DRMFACEARRAY* pFaceArray)
873 {
874     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
875
876     FIXME("(%p)->(%p): stub\n", This, pFaceArray);
877
878     return E_NOTIMPL;
879 }
880
881 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_GetVertices(IDirect3DRMMeshBuilder* iface, DWORD *vcount, D3DVECTOR *vertices, DWORD *ncount, D3DVECTOR *normals, DWORD *face_data_size, DWORD *face_data)
882 {
883     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
884
885     TRACE("(%p)->(%p,%p,%p,%p,%p,%p)\n", This, vcount, vertices, ncount, normals, face_data_size, face_data);
886
887     if (vcount)
888         *vcount = This->nb_vertices;
889     if (vertices && This->nb_vertices)
890         memcpy(vertices, This->pVertices, This->nb_vertices * sizeof(D3DVECTOR));
891     if (ncount)
892         *ncount = This->nb_normals;
893     if (normals && This->nb_normals)
894         memcpy(normals, This->pNormals, This->nb_normals * sizeof(D3DVECTOR));
895     if (face_data_size)
896         *face_data_size = This->face_data_size;
897     if (face_data && This->face_data_size)
898         memcpy(face_data, This->pFaceData, This->face_data_size);
899
900     return D3DRM_OK;
901 }
902
903 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_GetTextureCoordinates(IDirect3DRMMeshBuilder* iface, DWORD index, D3DVALUE *u, D3DVALUE *v)
904 {
905     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
906
907     FIXME("(%p)->(%d,%p,%p): stub\n", This, index, u, v);
908
909     if (index >= This->nb_coords2d)
910         return D3DRMERR_NOTFOUND;
911
912     *u = This->pCoords2d[index].u;
913     *v = This->pCoords2d[index].v;
914
915     return D3DRM_OK;
916 }
917
918 static int WINAPI IDirect3DRMMeshBuilderImpl_AddVertex(IDirect3DRMMeshBuilder* iface, D3DVALUE x, D3DVALUE y, D3DVALUE z)
919 {
920     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
921
922     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
923
924     return 0;
925 }
926
927 static int WINAPI IDirect3DRMMeshBuilderImpl_AddNormal(IDirect3DRMMeshBuilder* iface, D3DVALUE x, D3DVALUE y, D3DVALUE z)
928 {
929     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
930
931     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
932
933     return 0;
934 }
935
936 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_CreateFace(IDirect3DRMMeshBuilder* iface, LPDIRECT3DRMFACE* ppFace)
937 {
938     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
939
940     FIXME("(%p)->(%p): stub\n", This, ppFace);
941
942     return E_NOTIMPL;
943 }
944
945 static D3DRMRENDERQUALITY WINAPI IDirect3DRMMeshBuilderImpl_GetQuality(IDirect3DRMMeshBuilder* iface)
946 {
947     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
948
949     FIXME("(%p)->(): stub\n", This);
950
951     return 0;
952 }
953
954 static BOOL WINAPI IDirect3DRMMeshBuilderImpl_GetPerspective(IDirect3DRMMeshBuilder* iface)
955 {
956     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
957
958     FIXME("(%p)->(): stub\n", This);
959
960     return FALSE;
961 }
962
963 static int WINAPI IDirect3DRMMeshBuilderImpl_GetFaceCount(IDirect3DRMMeshBuilder* iface)
964 {
965     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
966
967     TRACE("(%p)->()\n", This);
968
969     return This->nb_faces;
970 }
971
972 static int WINAPI IDirect3DRMMeshBuilderImpl_GetVertexCount(IDirect3DRMMeshBuilder* iface)
973 {
974     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
975
976     TRACE("(%p)->()\n", This);
977
978     return This->nb_vertices;
979 }
980
981 static D3DCOLOR WINAPI IDirect3DRMMeshBuilderImpl_GetVertexColor(IDirect3DRMMeshBuilder* iface, DWORD index)
982 {
983     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
984
985     FIXME("(%p)->(%d): stub\n", This, index);
986
987     return 0;
988 }
989
990 static HRESULT WINAPI IDirect3DRMMeshBuilderImpl_CreateMesh(IDirect3DRMMeshBuilder* iface, LPDIRECT3DRMMESH* ppMesh)
991 {
992     IDirect3DRMMeshBuilderImpl *This = (IDirect3DRMMeshBuilderImpl *)iface;
993
994     FIXME("(%p)->(%p): stub\n", This, ppMesh);
995
996     return E_NOTIMPL;
997 }
998
999 static const struct IDirect3DRMMeshBuilderVtbl Direct3DRMMeshBuilder_Vtbl =
1000 {
1001     /*** IUnknown methods ***/
1002     IDirect3DRMMeshBuilderImpl_QueryInterface,
1003     IDirect3DRMMeshBuilderImpl_AddRef,
1004     IDirect3DRMMeshBuilderImpl_Release,
1005     /*** IDirect3DRMObject methods ***/
1006     IDirect3DRMMeshBuilderImpl_Clone,
1007     IDirect3DRMMeshBuilderImpl_AddDestroyCallback,
1008     IDirect3DRMMeshBuilderImpl_DeleteDestroyCallback,
1009     IDirect3DRMMeshBuilderImpl_SetAppData,
1010     IDirect3DRMMeshBuilderImpl_GetAppData,
1011     IDirect3DRMMeshBuilderImpl_SetName,
1012     IDirect3DRMMeshBuilderImpl_GetName,
1013     IDirect3DRMMeshBuilderImpl_GetClassName,
1014     /*** IDirect3DRMMeshBuilder methods ***/
1015     IDirect3DRMMeshBuilderImpl_Load,
1016     IDirect3DRMMeshBuilderImpl_Save,
1017     IDirect3DRMMeshBuilderImpl_Scale,
1018     IDirect3DRMMeshBuilderImpl_Translate,
1019     IDirect3DRMMeshBuilderImpl_SetColorSource,
1020     IDirect3DRMMeshBuilderImpl_GetBox,
1021     IDirect3DRMMeshBuilderImpl_GenerateNormals,
1022     IDirect3DRMMeshBuilderImpl_GetColorSource,
1023     IDirect3DRMMeshBuilderImpl_AddMesh,
1024     IDirect3DRMMeshBuilderImpl_AddMeshBuilder,
1025     IDirect3DRMMeshBuilderImpl_AddFrame,
1026     IDirect3DRMMeshBuilderImpl_AddFace,
1027     IDirect3DRMMeshBuilderImpl_AddFaces,
1028     IDirect3DRMMeshBuilderImpl_ReserveSpace,
1029     IDirect3DRMMeshBuilderImpl_SetColorRGB,
1030     IDirect3DRMMeshBuilderImpl_SetColor,
1031     IDirect3DRMMeshBuilderImpl_SetTexture,
1032     IDirect3DRMMeshBuilderImpl_SetMaterial,
1033     IDirect3DRMMeshBuilderImpl_SetTextureTopology,
1034     IDirect3DRMMeshBuilderImpl_SetQuality,
1035     IDirect3DRMMeshBuilderImpl_SetPerspective,
1036     IDirect3DRMMeshBuilderImpl_SetVertex,
1037     IDirect3DRMMeshBuilderImpl_SetNormal,
1038     IDirect3DRMMeshBuilderImpl_SetTextureCoordinates,
1039     IDirect3DRMMeshBuilderImpl_SetVertexColor,
1040     IDirect3DRMMeshBuilderImpl_SetVertexColorRGB,
1041     IDirect3DRMMeshBuilderImpl_GetFaces,
1042     IDirect3DRMMeshBuilderImpl_GetVertices,
1043     IDirect3DRMMeshBuilderImpl_GetTextureCoordinates,
1044     IDirect3DRMMeshBuilderImpl_AddVertex,
1045     IDirect3DRMMeshBuilderImpl_AddNormal,
1046     IDirect3DRMMeshBuilderImpl_CreateFace,
1047     IDirect3DRMMeshBuilderImpl_GetQuality,
1048     IDirect3DRMMeshBuilderImpl_GetPerspective,
1049     IDirect3DRMMeshBuilderImpl_GetFaceCount,
1050     IDirect3DRMMeshBuilderImpl_GetVertexCount,
1051     IDirect3DRMMeshBuilderImpl_GetVertexColor,
1052     IDirect3DRMMeshBuilderImpl_CreateMesh
1053 };