d3drm: Implement IDirect3DRMMeshImpl_SetGroupColorRGB.
[wine] / dlls / d3drm / meshbuilder.c
1 /*
2  * Implementation of IDirect3DRMMeshBuilderX and IDirect3DRMMesh interfaces
3  *
4  * Copyright 2010, 2012 Christian Costa
5  * Copyright 2011 AndrĂ© Hentschel
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #define NONAMELESSUNION
23
24 #define COBJMACROS
25
26 #include "wine/debug.h"
27
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "dxfile.h"
31 #include "rmxfguid.h"
32
33 #include "d3drm_private.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(d3drm);
36
37 static HRESULT Direct3DRMMesh_create(IDirect3DRMMesh** obj);
38
39 typedef struct {
40     unsigned nb_vertices;
41     D3DRMVERTEX* vertices;
42     unsigned nb_faces;
43     unsigned vertex_per_face;
44     DWORD face_data_size;
45     unsigned* face_data;
46     D3DCOLOR color;
47     IDirect3DRMMaterial2* material;
48     IDirect3DRMTexture3* texture;
49 } mesh_group;
50
51 typedef struct {
52     IDirect3DRMMesh IDirect3DRMMesh_iface;
53     LONG ref;
54     DWORD groups_capacity;
55     DWORD nb_groups;
56     mesh_group* groups;
57 } IDirect3DRMMeshImpl;
58
59 typedef struct {
60     D3DVALUE u;
61     D3DVALUE v;
62 } Coords2d;
63
64 typedef struct {
65     IDirect3DRMMeshBuilder2 IDirect3DRMMeshBuilder2_iface;
66     IDirect3DRMMeshBuilder3 IDirect3DRMMeshBuilder3_iface;
67     LONG ref;
68     char* name;
69     DWORD nb_vertices;
70     D3DVECTOR* pVertices;
71     DWORD nb_normals;
72     D3DVECTOR* pNormals;
73     DWORD nb_faces;
74     DWORD face_data_size;
75     LPVOID pFaceData;
76     DWORD nb_coords2d;
77     Coords2d* pCoords2d;
78     D3DCOLOR color;
79     IDirect3DRMMaterial2* material;
80     IDirect3DRMTexture3* texture;
81 } IDirect3DRMMeshBuilderImpl;
82
83 char templates[] = {
84 "xof 0302txt 0064"
85 "template Header"
86 "{"
87 "<3D82AB43-62DA-11CF-AB39-0020AF71E433>"
88 "WORD major;"
89 "WORD minor;"
90 "DWORD flags;"
91 "}"
92 "template Vector"
93 "{"
94 "<3D82AB5E-62DA-11CF-AB39-0020AF71E433>"
95 "FLOAT x;"
96 "FLOAT y;"
97 "FLOAT z;"
98 "}"
99 "template Coords2d"
100 "{"
101 "<F6F23F44-7686-11CF-8F52-0040333594A3>"
102 "FLOAT u;"
103 "FLOAT v;"
104 "}"
105 "template Matrix4x4"
106 "{"
107 "<F6F23F45-7686-11CF-8F52-0040333594A3>"
108 "array FLOAT matrix[16];"
109 "}"
110 "template ColorRGBA"
111 "{"
112 "<35FF44E0-6C7C-11CF-8F52-0040333594A3>"
113 "FLOAT red;"
114 "FLOAT green;"
115 "FLOAT blue;"
116 "FLOAT alpha;"
117 "}"
118 "template ColorRGB"
119 "{"
120 "<D3E16E81-7835-11CF-8F52-0040333594A3>"
121 "FLOAT red;"
122 "FLOAT green;"
123 "FLOAT blue;"
124 "}"
125 "template IndexedColor"
126 "{"
127 "<1630B820-7842-11CF-8F52-0040333594A3>"
128 "DWORD index;"
129 "ColorRGBA indexColor;"
130 "}"
131 "template Boolean"
132 "{"
133 "<537DA6A0-CA37-11D0-941C-0080C80CFA7B>"
134 "DWORD truefalse;"
135 "}"
136 "template Boolean2d"
137 "{"
138 "<4885AE63-78E8-11CF-8F52-0040333594A3>"
139 "Boolean u;"
140 "Boolean v;"
141 "}"
142 "template MaterialWrap"
143 "{"
144 "<4885AE60-78E8-11CF-8F52-0040333594A3>"
145 "Boolean u;"
146 "Boolean v;"
147 "}"
148 "template TextureFilename"
149 "{"
150 "<A42790E1-7810-11CF-8F52-0040333594A3>"
151 "STRING filename;"
152 "}"
153 "template Material"
154 "{"
155 "<3D82AB4D-62DA-11CF-AB39-0020AF71E433>"
156 "ColorRGBA faceColor;"
157 "FLOAT power;"
158 "ColorRGB specularColor;"
159 "ColorRGB emissiveColor;"
160 "[...]"
161 "}"
162 "template MeshFace"
163 "{"
164 "<3D82AB5F-62DA-11CF-AB39-0020AF71E433>"
165 "DWORD nFaceVertexIndices;"
166 "array DWORD faceVertexIndices[nFaceVertexIndices];"
167 "}"
168 "template MeshFaceWraps"
169 "{"
170 "<ED1EC5C0-C0A8-11D0-941C-0080C80CFA7B>"
171 "DWORD nFaceWrapValues;"
172 "array Boolean2d faceWrapValues[nFaceWrapValues];"
173 "}"
174 "template MeshTextureCoords"
175 "{"
176 "<F6F23F40-7686-11CF-8F52-0040333594A3>"
177 "DWORD nTextureCoords;"
178 "array Coords2d textureCoords[nTextureCoords];"
179 "}"
180 "template MeshMaterialList"
181 "{"
182 "<F6F23F42-7686-11CF-8F52-0040333594A3>"
183 "DWORD nMaterials;"
184 "DWORD nFaceIndexes;"
185 "array DWORD faceIndexes[nFaceIndexes];"
186 "[Material]"
187 "}"
188 "template MeshNormals"
189 "{"
190 "<F6F23F43-7686-11CF-8F52-0040333594A3>"
191 "DWORD nNormals;"
192 "array Vector normals[nNormals];"
193 "DWORD nFaceNormals;"
194 "array MeshFace faceNormals[nFaceNormals];"
195 "}"
196 "template MeshVertexColors"
197 "{"
198 "<1630B821-7842-11CF-8F52-0040333594A3>"
199 "DWORD nVertexColors;"
200 "array IndexedColor vertexColors[nVertexColors];"
201 "}"
202 "template Mesh"
203 "{"
204 "<3D82AB44-62DA-11CF-AB39-0020AF71E433>"
205 "DWORD nVertices;"
206 "array Vector vertices[nVertices];"
207 "DWORD nFaces;"
208 "array MeshFace faces[nFaces];"
209 "[...]"
210 "}"
211 "template FrameTransformMatrix"
212 "{"
213 "<F6F23F41-7686-11CF-8F52-0040333594A3>"
214 "Matrix4x4 frameMatrix;"
215 "}"
216 "template Frame"
217 "{"
218 "<3D82AB46-62DA-11CF-AB39-0020AF71E433>"
219 "[...]"
220 "}"
221 "template FloatKeys"
222 "{"
223 "<10DD46A9-775B-11CF-8F52-0040333594A3>"
224 "DWORD nValues;"
225 "array FLOAT values[nValues];"
226 "}"
227 "template TimedFloatKeys"
228 "{"
229 "<F406B180-7B3B-11CF-8F52-0040333594A3>"
230 "DWORD time;"
231 "FloatKeys tfkeys;"
232 "}"
233 "template AnimationKey"
234 "{"
235 "<10DD46A8-775B-11CF-8F52-0040333594A3>"
236 "DWORD keyType;"
237 "DWORD nKeys;"
238 "array TimedFloatKeys keys[nKeys];"
239 "}"
240 "template AnimationOptions"
241 "{"
242 "<E2BF56C0-840F-11CF-8F52-0040333594A3>"
243 "DWORD openclosed;"
244 "DWORD positionquality;"
245 "}"
246 "template Animation"
247 "{"
248 "<3D82AB4F-62DA-11CF-AB39-0020AF71E433>"
249 "[...]"
250 "}"
251 "template AnimationSet"
252 "{"
253 "<3D82AB50-62DA-11CF-AB39-0020AF71E433>"
254 "[Animation]"
255 "}"
256 "template InlineData"
257 "{"
258 "<3A23EEA0-94B1-11D0-AB39-0020AF71E433>"
259 "[BINARY]"
260 "}"
261 "template Url"
262 "{"
263 "<3A23EEA1-94B1-11D0-AB39-0020AF71E433>"
264 "DWORD nUrls;"
265 "array STRING urls[nUrls];"
266 "}"
267 "template ProgressiveMesh"
268 "{"
269 "<8A63C360-997D-11D0-941C-0080C80CFA7B>"
270 "[Url,InlineData]"
271 "}"
272 "template Guid"
273 "{"
274 "<A42790E0-7810-11CF-8F52-0040333594A3>"
275 "DWORD data1;"
276 "WORD data2;"
277 "WORD data3;"
278 "array UCHAR data4[8];"
279 "}"
280 "template StringProperty"
281 "{"
282 "<7F0F21E0-BFE1-11D1-82C0-00A0C9697271>"
283 "STRING key;"
284 "STRING value;"
285 "}"
286 "template PropertyBag"
287 "{"
288 "<7F0F21E1-BFE1-11D1-82C0-00A0C9697271>"
289 "[StringProperty]"
290 "}"
291 "template ExternalVisual"
292 "{"
293 "<98116AA0-BDBA-11D1-82C0-00A0C9697271>"
294 "Guid guidExternalVisual;"
295 "[...]"
296 "}"
297 "template RightHanded"
298 "{"
299 "<7F5D5EA0-D53A-11D1-82C0-00A0C9697271>"
300 "DWORD bRightHanded;"
301 "}"
302 };
303
304 static inline IDirect3DRMMeshImpl *impl_from_IDirect3DRMMesh(IDirect3DRMMesh *iface)
305 {
306     return CONTAINING_RECORD(iface, IDirect3DRMMeshImpl, IDirect3DRMMesh_iface);
307 }
308
309 static inline IDirect3DRMMeshBuilderImpl *impl_from_IDirect3DRMMeshBuilder2(IDirect3DRMMeshBuilder2 *iface)
310 {
311     return CONTAINING_RECORD(iface, IDirect3DRMMeshBuilderImpl, IDirect3DRMMeshBuilder2_iface);
312 }
313
314 static inline IDirect3DRMMeshBuilderImpl *impl_from_IDirect3DRMMeshBuilder3(IDirect3DRMMeshBuilder3 *iface)
315 {
316     return CONTAINING_RECORD(iface, IDirect3DRMMeshBuilderImpl, IDirect3DRMMeshBuilder3_iface);
317 }
318
319 /*** IUnknown methods ***/
320 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_QueryInterface(IDirect3DRMMeshBuilder2* iface,
321                                                                  REFIID riid, void** ppvObject)
322 {
323     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
324
325     TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
326
327     *ppvObject = NULL;
328
329     if(IsEqualGUID(riid, &IID_IUnknown) ||
330        IsEqualGUID(riid, &IID_IDirect3DRMMeshBuilder) ||
331        IsEqualGUID(riid, &IID_IDirect3DRMMeshBuilder2))
332     {
333         *ppvObject = &This->IDirect3DRMMeshBuilder2_iface;
334     }
335     else if(IsEqualGUID(riid, &IID_IDirect3DRMMeshBuilder3))
336     {
337         *ppvObject = &This->IDirect3DRMMeshBuilder3_iface;
338     }
339     else
340     {
341         FIXME("interface %s not implemented\n", debugstr_guid(riid));
342         return E_NOINTERFACE;
343     }
344
345     IDirect3DRMMeshBuilder_AddRef(iface);
346     return S_OK;
347 }
348
349 static ULONG WINAPI IDirect3DRMMeshBuilder2Impl_AddRef(IDirect3DRMMeshBuilder2* iface)
350 {
351     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
352     ULONG ref = InterlockedIncrement(&This->ref);
353
354     TRACE("(%p)->(): new ref = %d\n", This, ref);
355
356     return ref;
357 }
358
359 static ULONG WINAPI IDirect3DRMMeshBuilder2Impl_Release(IDirect3DRMMeshBuilder2* iface)
360 {
361     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
362     ULONG ref = InterlockedDecrement(&This->ref);
363
364     TRACE("(%p)->(): new ref = %d\n", This, ref);
365
366     if (!ref)
367     {
368         if (This->material)
369             IDirect3DRMMaterial2_Release(This->material);
370         if (This->texture)
371             IDirect3DRMTexture3_Release(This->texture);
372         HeapFree(GetProcessHeap(), 0, This->name);
373         HeapFree(GetProcessHeap(), 0, This->pVertices);
374         HeapFree(GetProcessHeap(), 0, This->pNormals);
375         HeapFree(GetProcessHeap(), 0, This->pFaceData);
376         HeapFree(GetProcessHeap(), 0, This->pCoords2d);
377         HeapFree(GetProcessHeap(), 0, This);
378     }
379
380     return ref;
381 }
382
383 /*** IDirect3DRMObject methods ***/
384 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_Clone(IDirect3DRMMeshBuilder2* iface,
385                                                         LPUNKNOWN pUnkOuter, REFIID riid,
386                                                         LPVOID *ppvObj)
387 {
388     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
389
390     FIXME("(%p)->(%p,%s,%p): stub\n", This, pUnkOuter, debugstr_guid(riid), ppvObj);
391
392     return E_NOTIMPL;
393 }
394
395 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddDestroyCallback(IDirect3DRMMeshBuilder2* iface,
396                                                                      D3DRMOBJECTCALLBACK cb,
397                                                                      LPVOID argument)
398 {
399     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
400
401     FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
402
403     return E_NOTIMPL;
404 }
405
406 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_DeleteDestroyCallback(IDirect3DRMMeshBuilder2* iface,
407                                                                         D3DRMOBJECTCALLBACK cb,
408                                                                         LPVOID argument)
409 {
410     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
411
412     FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
413
414     return E_NOTIMPL;
415 }
416
417 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetAppData(IDirect3DRMMeshBuilder2* iface,
418                                                              DWORD data)
419 {
420     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
421
422     FIXME("(%p)->(%u): stub\n", This, data);
423
424     return E_NOTIMPL;
425 }
426
427 static DWORD WINAPI IDirect3DRMMeshBuilder2Impl_GetAppData(IDirect3DRMMeshBuilder2* iface)
428 {
429     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
430
431     FIXME("(%p)->(): stub\n", This);
432
433     return 0;
434 }
435
436 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetName(IDirect3DRMMeshBuilder2* iface,
437                                                           LPCSTR name)
438 {
439     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
440
441     TRACE("(%p)->(%s)\n", This, debugstr_a(name));
442
443     return IDirect3DRMMeshBuilder3_SetName(&This->IDirect3DRMMeshBuilder3_iface, name);
444 }
445
446 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetName(IDirect3DRMMeshBuilder2* iface,
447                                                           LPDWORD size, LPSTR name)
448 {
449     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
450
451     TRACE("(%p)->(%p,%p)\n", This, size, name);
452
453     return IDirect3DRMMeshBuilder3_GetName(&This->IDirect3DRMMeshBuilder3_iface, size, name);
454 }
455
456 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetClassName(IDirect3DRMMeshBuilder2* iface,
457                                                                LPDWORD lpdwSize, LPSTR lpName)
458 {
459     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
460
461     FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
462
463     return E_NOTIMPL;
464 }
465
466 /*** IDirect3DRMMeshBuilder2 methods ***/
467 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_Load(IDirect3DRMMeshBuilder2* iface,
468                                                        LPVOID filename, LPVOID name,
469                                                        D3DRMLOADOPTIONS loadflags,
470                                                        D3DRMLOADTEXTURECALLBACK cb, LPVOID arg)
471 {
472     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
473
474     TRACE("(%p)->(%p,%p,%x,%p,%p)\n", This, filename, name, loadflags, cb, arg);
475
476     if (cb)
477         FIXME("Texture callback is not yet supported\n");
478
479     return IDirect3DRMMeshBuilder3_Load(&This->IDirect3DRMMeshBuilder3_iface, filename, name,
480                                         loadflags, NULL, arg);
481 }
482
483 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_Save(IDirect3DRMMeshBuilder2* iface,
484                                                        const char *filename, D3DRMXOFFORMAT format,
485                                                        D3DRMSAVEOPTIONS save)
486 {
487     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
488
489     FIXME("(%p)->(%s,%d,%d): stub\n", This, filename, format, save);
490
491     return E_NOTIMPL;
492 }
493
494 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_Scale(IDirect3DRMMeshBuilder2* iface,
495                                                         D3DVALUE sx, D3DVALUE sy, D3DVALUE sz)
496 {
497     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
498
499     TRACE("(%p)->(%f,%f,%f)\n", This, sx, sy, sz);
500
501     return IDirect3DRMMeshBuilder3_Scale(&This->IDirect3DRMMeshBuilder3_iface, sx, sy, sz);
502 }
503
504 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_Translate(IDirect3DRMMeshBuilder2* iface,
505                                                             D3DVALUE tx, D3DVALUE ty, D3DVALUE tz)
506 {
507     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
508
509     FIXME("(%p)->(%f,%f,%f): stub\n", This, tx, ty, tz);
510
511     return E_NOTIMPL;
512 }
513
514 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetColorSource(IDirect3DRMMeshBuilder2* iface,
515                                                                  D3DRMCOLORSOURCE color)
516 {
517     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
518
519     FIXME("(%p)->(%x): stub\n", This, color);
520
521     return E_NOTIMPL;
522 }
523
524 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetBox(IDirect3DRMMeshBuilder2* iface,
525                                                          D3DRMBOX *pBox)
526 {
527     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
528
529     FIXME("(%p)->(%p): stub\n", This, pBox);
530
531     return E_NOTIMPL;
532 }
533
534 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GenerateNormals(IDirect3DRMMeshBuilder2* iface)
535 {
536     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
537
538     FIXME("(%p)->(): stub\n", This);
539
540     return E_NOTIMPL;
541 }
542
543 static D3DRMCOLORSOURCE WINAPI IDirect3DRMMeshBuilder2Impl_GetColorSource(IDirect3DRMMeshBuilder2* iface)
544 {
545     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
546
547     FIXME("(%p)->(): stub\n", This);
548
549     return E_NOTIMPL;
550 }
551
552 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddMesh(IDirect3DRMMeshBuilder2* iface,
553                                                           LPDIRECT3DRMMESH pMesh)
554 {
555     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
556
557     FIXME("(%p)->(%p): stub\n", This, pMesh);
558
559     return E_NOTIMPL;
560 }
561
562 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddMeshBuilder(IDirect3DRMMeshBuilder2* iface,
563                                                                  LPDIRECT3DRMMESHBUILDER pMeshBuilder)
564 {
565     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
566
567     FIXME("(%p)->(%p): stub\n", This, pMeshBuilder);
568
569     return E_NOTIMPL;
570 }
571
572 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddFrame(IDirect3DRMMeshBuilder2* iface,
573                                                            LPDIRECT3DRMFRAME pFrame)
574 {
575     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
576
577     FIXME("(%p)->(%p): stub\n", This, pFrame);
578
579     return E_NOTIMPL;
580 }
581
582 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddFace(IDirect3DRMMeshBuilder2* iface,
583                                                           LPDIRECT3DRMFACE pFace)
584 {
585     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
586
587     FIXME("(%p)->(%p): stub\n", This, pFace);
588
589     return E_NOTIMPL;
590 }
591
592 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddFaces(IDirect3DRMMeshBuilder2* iface,
593                                                            DWORD vcount, D3DVECTOR *vertices,
594                                                            DWORD ncount, D3DVECTOR *normals,
595                                                            DWORD *data,
596                                                            LPDIRECT3DRMFACEARRAY* pFaceArray)
597 {
598     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
599
600     FIXME("(%p)->(%d,%p,%d,%p,%p,%p): stub\n", This, vcount, vertices, ncount, normals, data, pFaceArray);
601
602     return E_NOTIMPL;
603 }
604
605 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_ReserveSpace(IDirect3DRMMeshBuilder2* iface,
606                                                                DWORD vertex_Count,
607                                                                DWORD normal_count,
608                                                                DWORD face_count)
609 {
610     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
611
612     FIXME("(%p)->(%d,%d,%d): stub\n", This, vertex_Count, normal_count, face_count);
613
614     return E_NOTIMPL;
615 }
616
617 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetColorRGB(IDirect3DRMMeshBuilder2* iface,
618                                                               D3DVALUE red, D3DVALUE green,
619                                                               D3DVALUE blue)
620 {
621     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
622
623     TRACE("(%p)->(%f,%f,%f)\n", This, red, green, blue);
624
625     return IDirect3DRMMeshBuilder3_SetColorRGB(&This->IDirect3DRMMeshBuilder3_iface, red, green, blue);
626 }
627
628 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetColor(IDirect3DRMMeshBuilder2* iface,
629                                                            D3DCOLOR color)
630 {
631     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
632
633     TRACE("(%p)->(%x)\n", This, color);
634
635     return IDirect3DRMMeshBuilder3_SetColor(&This->IDirect3DRMMeshBuilder3_iface, color);
636 }
637
638 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetTexture(IDirect3DRMMeshBuilder2* iface,
639                                                              LPDIRECT3DRMTEXTURE texture)
640 {
641     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
642     LPDIRECT3DRMTEXTURE3 texture3 = NULL;
643     HRESULT hr = D3DRM_OK;
644
645     if (texture)
646         hr = IDirect3DRMTexture_QueryInterface(texture, &IID_IDirect3DRMTexture3, (LPVOID*)&texture3);
647     if (SUCCEEDED(hr))
648         hr = IDirect3DRMMeshBuilder3_SetTexture(&This->IDirect3DRMMeshBuilder3_iface, texture3);
649     if (texture3)
650         IDirect3DRMTexture3_Release(texture3);
651
652     return hr;
653 }
654
655 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetMaterial(IDirect3DRMMeshBuilder2* iface,
656                                                               LPDIRECT3DRMMATERIAL material)
657 {
658     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
659
660     TRACE("(%p)->(%p)\n", This, material);
661
662     return IDirect3DRMMeshBuilder3_SetMaterial(&This->IDirect3DRMMeshBuilder3_iface, (LPDIRECT3DRMMATERIAL2)material);
663 }
664
665 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetTextureTopology(IDirect3DRMMeshBuilder2* iface,
666                                                                      BOOL wrap_u, BOOL wrap_v)
667 {
668     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
669
670     FIXME("(%p)->(%d,%d): stub\n", This, wrap_u, wrap_v);
671
672     return E_NOTIMPL;
673 }
674
675 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetQuality(IDirect3DRMMeshBuilder2* iface,
676                                                              D3DRMRENDERQUALITY quality)
677 {
678     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
679
680     FIXME("(%p)->(%d): stub\n", This, quality);
681
682     return E_NOTIMPL;
683 }
684
685 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetPerspective(IDirect3DRMMeshBuilder2* iface,
686                                                                  BOOL enable)
687 {
688     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
689
690     FIXME("(%p)->(%d): stub\n", This, enable);
691
692     return E_NOTIMPL;
693 }
694
695 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetVertex(IDirect3DRMMeshBuilder2* iface,
696                                                             DWORD index,
697                                                             D3DVALUE x, D3DVALUE y, D3DVALUE z)
698 {
699     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
700
701     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
702
703     return E_NOTIMPL;
704 }
705
706 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetNormal(IDirect3DRMMeshBuilder2* iface,
707                                                             DWORD index,
708                                                             D3DVALUE x, D3DVALUE y, D3DVALUE z)
709 {
710     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
711
712     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
713
714     return E_NOTIMPL;
715 }
716
717 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetTextureCoordinates(IDirect3DRMMeshBuilder2* iface,
718                                                                         DWORD index,
719                                                                         D3DVALUE u, D3DVALUE v)
720 {
721     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
722
723     TRACE("(%p)->(%u,%f,%f)\n", This, index, u, v);
724
725     return IDirect3DRMMeshBuilder3_SetTextureCoordinates(&This->IDirect3DRMMeshBuilder3_iface,
726                                                          index, u, v);
727 }
728
729 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetVertexColor(IDirect3DRMMeshBuilder2* iface,
730                                                                  DWORD index, D3DCOLOR color)
731 {
732     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
733
734     FIXME("(%p)->(%d,%x): stub\n", This, index, color);
735
736     return E_NOTIMPL;
737 }
738
739 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetVertexColorRGB(IDirect3DRMMeshBuilder2* iface,
740                                                                     DWORD index, D3DVALUE red,
741                                                                     D3DVALUE green, D3DVALUE blue)
742 {
743     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
744
745     FIXME("(%p)->(%d,%f,%f,%f): stub\n", This, index, red, green, blue);
746
747     return E_NOTIMPL;
748 }
749
750 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetFaces(IDirect3DRMMeshBuilder2* iface,
751                                                            LPDIRECT3DRMFACEARRAY* pFaceArray)
752 {
753     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
754
755     FIXME("(%p)->(%p): stub\n", This, pFaceArray);
756
757     return E_NOTIMPL;
758 }
759
760 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetVertices(IDirect3DRMMeshBuilder2* iface,
761                                                               DWORD *vcount, D3DVECTOR *vertices,
762                                                               DWORD *ncount, D3DVECTOR *normals,
763                                                               DWORD *face_data_size,
764                                                               DWORD *face_data)
765 {
766     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
767
768     TRACE("(%p)->(%p,%p,%p,%p,%p,%p)\n", This, vcount, vertices, ncount, normals, face_data_size, face_data);
769
770     if (vcount)
771         *vcount = This->nb_vertices;
772     if (vertices && This->nb_vertices)
773         memcpy(vertices, This->pVertices, This->nb_vertices * sizeof(D3DVECTOR));
774     if (ncount)
775         *ncount = This->nb_normals;
776     if (normals && This->nb_normals)
777         memcpy(normals, This->pNormals, This->nb_normals * sizeof(D3DVECTOR));
778     if (face_data_size)
779         *face_data_size = This->face_data_size;
780     if (face_data && This->face_data_size)
781         memcpy(face_data, This->pFaceData, This->face_data_size * sizeof(DWORD));
782
783     return D3DRM_OK;
784 }
785
786 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetTextureCoordinates(IDirect3DRMMeshBuilder2* iface,
787                                                                         DWORD index,
788                                                                         D3DVALUE *u, D3DVALUE *v)
789 {
790     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
791
792     TRACE("(%p)->(%u,%p,%p)\n", This, index, u, v);
793
794     return IDirect3DRMMeshBuilder3_GetTextureCoordinates(&This->IDirect3DRMMeshBuilder3_iface,
795                                                          index, u, v);
796 }
797
798 static int WINAPI IDirect3DRMMeshBuilder2Impl_AddVertex(IDirect3DRMMeshBuilder2* iface,
799                                                         D3DVALUE x, D3DVALUE y, D3DVALUE z)
800 {
801     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
802
803     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
804
805     return 0;
806 }
807
808 static int WINAPI IDirect3DRMMeshBuilder2Impl_AddNormal(IDirect3DRMMeshBuilder2* iface,
809                                                         D3DVALUE x, D3DVALUE y, D3DVALUE z)
810 {
811     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
812
813     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
814
815     return 0;
816 }
817
818 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_CreateFace(IDirect3DRMMeshBuilder2* iface,
819                                                              LPDIRECT3DRMFACE* ppFace)
820 {
821     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
822
823     FIXME("(%p)->(%p): stub\n", This, ppFace);
824
825     return E_NOTIMPL;
826 }
827
828 static D3DRMRENDERQUALITY WINAPI IDirect3DRMMeshBuilder2Impl_GetQuality(IDirect3DRMMeshBuilder2* iface)
829 {
830     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
831
832     FIXME("(%p)->(): stub\n", This);
833
834     return 0;
835 }
836
837 static BOOL WINAPI IDirect3DRMMeshBuilder2Impl_GetPerspective(IDirect3DRMMeshBuilder2* iface)
838 {
839     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
840
841     FIXME("(%p)->(): stub\n", This);
842
843     return FALSE;
844 }
845
846 static int WINAPI IDirect3DRMMeshBuilder2Impl_GetFaceCount(IDirect3DRMMeshBuilder2* iface)
847 {
848     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
849
850     TRACE("(%p)->()\n", This);
851
852     return This->nb_faces;
853 }
854
855 static int WINAPI IDirect3DRMMeshBuilder2Impl_GetVertexCount(IDirect3DRMMeshBuilder2* iface)
856 {
857     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
858
859     TRACE("(%p)->()\n", This);
860
861     return This->nb_vertices;
862 }
863
864 static D3DCOLOR WINAPI IDirect3DRMMeshBuilder2Impl_GetVertexColor(IDirect3DRMMeshBuilder2* iface,
865                                                                   DWORD index)
866 {
867     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
868
869     FIXME("(%p)->(%d): stub\n", This, index);
870
871     return 0;
872 }
873
874 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_CreateMesh(IDirect3DRMMeshBuilder2* iface,
875                                                              LPDIRECT3DRMMESH* mesh)
876 {
877     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
878
879     TRACE("(%p)->(%p)\n", This, mesh);
880
881     return IDirect3DRMMeshBuilder3_CreateMesh(&This->IDirect3DRMMeshBuilder3_iface, mesh);
882 }
883
884 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GenerateNormals2(IDirect3DRMMeshBuilder2* iface,
885                                                                    D3DVALUE crease, DWORD dwFlags)
886 {
887     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
888
889     FIXME("(%p)->(%f,%u): stub\n", This, crease, dwFlags);
890
891     return E_NOTIMPL;
892 }
893
894 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetFace(IDirect3DRMMeshBuilder2* iface,
895                                                           DWORD index, LPDIRECT3DRMFACE* ppFace)
896 {
897     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
898
899     FIXME("(%p)->(%u,%p): stub\n", This, index, ppFace);
900
901     return E_NOTIMPL;
902 }
903
904 static const struct IDirect3DRMMeshBuilder2Vtbl Direct3DRMMeshBuilder2_Vtbl =
905 {
906     /*** IUnknown methods ***/
907     IDirect3DRMMeshBuilder2Impl_QueryInterface,
908     IDirect3DRMMeshBuilder2Impl_AddRef,
909     IDirect3DRMMeshBuilder2Impl_Release,
910     /*** IDirect3DRMObject methods ***/
911     IDirect3DRMMeshBuilder2Impl_Clone,
912     IDirect3DRMMeshBuilder2Impl_AddDestroyCallback,
913     IDirect3DRMMeshBuilder2Impl_DeleteDestroyCallback,
914     IDirect3DRMMeshBuilder2Impl_SetAppData,
915     IDirect3DRMMeshBuilder2Impl_GetAppData,
916     IDirect3DRMMeshBuilder2Impl_SetName,
917     IDirect3DRMMeshBuilder2Impl_GetName,
918     IDirect3DRMMeshBuilder2Impl_GetClassName,
919     /*** IDirect3DRMMeshBuilder methods ***/
920     IDirect3DRMMeshBuilder2Impl_Load,
921     IDirect3DRMMeshBuilder2Impl_Save,
922     IDirect3DRMMeshBuilder2Impl_Scale,
923     IDirect3DRMMeshBuilder2Impl_Translate,
924     IDirect3DRMMeshBuilder2Impl_SetColorSource,
925     IDirect3DRMMeshBuilder2Impl_GetBox,
926     IDirect3DRMMeshBuilder2Impl_GenerateNormals,
927     IDirect3DRMMeshBuilder2Impl_GetColorSource,
928     IDirect3DRMMeshBuilder2Impl_AddMesh,
929     IDirect3DRMMeshBuilder2Impl_AddMeshBuilder,
930     IDirect3DRMMeshBuilder2Impl_AddFrame,
931     IDirect3DRMMeshBuilder2Impl_AddFace,
932     IDirect3DRMMeshBuilder2Impl_AddFaces,
933     IDirect3DRMMeshBuilder2Impl_ReserveSpace,
934     IDirect3DRMMeshBuilder2Impl_SetColorRGB,
935     IDirect3DRMMeshBuilder2Impl_SetColor,
936     IDirect3DRMMeshBuilder2Impl_SetTexture,
937     IDirect3DRMMeshBuilder2Impl_SetMaterial,
938     IDirect3DRMMeshBuilder2Impl_SetTextureTopology,
939     IDirect3DRMMeshBuilder2Impl_SetQuality,
940     IDirect3DRMMeshBuilder2Impl_SetPerspective,
941     IDirect3DRMMeshBuilder2Impl_SetVertex,
942     IDirect3DRMMeshBuilder2Impl_SetNormal,
943     IDirect3DRMMeshBuilder2Impl_SetTextureCoordinates,
944     IDirect3DRMMeshBuilder2Impl_SetVertexColor,
945     IDirect3DRMMeshBuilder2Impl_SetVertexColorRGB,
946     IDirect3DRMMeshBuilder2Impl_GetFaces,
947     IDirect3DRMMeshBuilder2Impl_GetVertices,
948     IDirect3DRMMeshBuilder2Impl_GetTextureCoordinates,
949     IDirect3DRMMeshBuilder2Impl_AddVertex,
950     IDirect3DRMMeshBuilder2Impl_AddNormal,
951     IDirect3DRMMeshBuilder2Impl_CreateFace,
952     IDirect3DRMMeshBuilder2Impl_GetQuality,
953     IDirect3DRMMeshBuilder2Impl_GetPerspective,
954     IDirect3DRMMeshBuilder2Impl_GetFaceCount,
955     IDirect3DRMMeshBuilder2Impl_GetVertexCount,
956     IDirect3DRMMeshBuilder2Impl_GetVertexColor,
957     IDirect3DRMMeshBuilder2Impl_CreateMesh,
958     /*** IDirect3DRMMeshBuilder2 methods ***/
959     IDirect3DRMMeshBuilder2Impl_GenerateNormals2,
960     IDirect3DRMMeshBuilder2Impl_GetFace
961 };
962
963
964 /*** IUnknown methods ***/
965 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_QueryInterface(IDirect3DRMMeshBuilder3* iface,
966                                                                  REFIID riid, void** ppvObject)
967 {
968     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
969     return IDirect3DRMMeshBuilder2_QueryInterface(&This->IDirect3DRMMeshBuilder2_iface, riid, ppvObject);
970 }
971
972 static ULONG WINAPI IDirect3DRMMeshBuilder3Impl_AddRef(IDirect3DRMMeshBuilder3* iface)
973 {
974     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
975     return IDirect3DRMMeshBuilder2_AddRef(&This->IDirect3DRMMeshBuilder2_iface);
976 }
977
978 static ULONG WINAPI IDirect3DRMMeshBuilder3Impl_Release(IDirect3DRMMeshBuilder3* iface)
979 {
980     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
981     return IDirect3DRMMeshBuilder2_Release(&This->IDirect3DRMMeshBuilder2_iface);
982 }
983
984 /*** IDirect3DRMObject methods ***/
985 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Clone(IDirect3DRMMeshBuilder3* iface,
986                                                         LPUNKNOWN pUnkOuter, REFIID riid,
987                                                         LPVOID *ppvObj)
988 {
989     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
990
991     FIXME("(%p)->(%p,%s,%p): stub\n", This, pUnkOuter, debugstr_guid(riid), ppvObj);
992
993     return E_NOTIMPL;
994 }
995
996 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddDestroyCallback(IDirect3DRMMeshBuilder3* iface,
997                                                                      D3DRMOBJECTCALLBACK cb,
998                                                                      LPVOID argument)
999 {
1000     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1001
1002     FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
1003
1004     return E_NOTIMPL;
1005 }
1006
1007 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteDestroyCallback(IDirect3DRMMeshBuilder3* iface,
1008                                                                         D3DRMOBJECTCALLBACK cb,
1009                                                                         LPVOID argument)
1010 {
1011     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1012
1013     FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
1014
1015     return E_NOTIMPL;
1016 }
1017
1018 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetAppData(IDirect3DRMMeshBuilder3* iface,
1019                                                              DWORD data)
1020 {
1021     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1022
1023     FIXME("(%p)->(%u): stub\n", This, data);
1024
1025     return E_NOTIMPL;
1026 }
1027
1028 static DWORD WINAPI IDirect3DRMMeshBuilder3Impl_GetAppData(IDirect3DRMMeshBuilder3* iface)
1029 {
1030     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1031
1032     FIXME("(%p)->(): stub\n", This);
1033
1034     return 0;
1035 }
1036
1037 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetName(IDirect3DRMMeshBuilder3* iface,
1038                                                           LPCSTR name)
1039 {
1040     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1041     char *string = NULL;
1042
1043     TRACE("(%p)->(%s)\n", This, debugstr_a(name));
1044
1045     if (name)
1046     {
1047         string = HeapAlloc(GetProcessHeap(), 0, strlen(name) + 1);
1048         if (!string) return E_OUTOFMEMORY;
1049         strcpy(string, name);
1050     }
1051     HeapFree(GetProcessHeap(), 0, This->name);
1052     This->name = string;
1053
1054     return D3DRM_OK;
1055 }
1056
1057 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetName(IDirect3DRMMeshBuilder3* iface,
1058                                                           LPDWORD size, LPSTR name)
1059 {
1060     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1061
1062     TRACE("(%p)->(%p,%p)\n", This, size, name);
1063
1064     if (!size)
1065         return E_POINTER;
1066
1067     if (!This->name)
1068     {
1069         *size = 0;
1070         return D3DRM_OK;
1071     }
1072
1073     if (*size < (strlen(This->name) + 1))
1074         return E_INVALIDARG;
1075
1076     strcpy(name, This->name);
1077     *size = strlen(This->name) + 1;
1078
1079     return D3DRM_OK;
1080 }
1081
1082 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetClassName(IDirect3DRMMeshBuilder3* iface,
1083                                                                LPDWORD lpdwSize, LPSTR lpName)
1084 {
1085     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1086
1087     FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
1088
1089     return E_NOTIMPL;
1090 }
1091
1092 HRESULT load_mesh_data(IDirect3DRMMeshBuilder3* iface, LPDIRECTXFILEDATA pData)
1093 {
1094     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1095     LPDIRECTXFILEOBJECT pObject = NULL;
1096     LPDIRECTXFILEDATA pData2 = NULL;
1097     const GUID* pGuid;
1098     DWORD size;
1099     LPBYTE ptr;
1100     HRESULT hr;
1101     HRESULT ret = D3DRMERR_BADOBJECT;
1102     DWORD* faces_vertex_idx_data = NULL;
1103     DWORD* faces_vertex_idx_ptr;
1104     DWORD faces_vertex_idx_size;
1105     DWORD* faces_normal_idx_data = NULL;
1106     DWORD* faces_normal_idx_ptr = NULL;
1107     DWORD* faces_data_ptr;
1108     DWORD faces_data_size = 0;
1109     DWORD i;
1110
1111     TRACE("(%p)->(%p)\n", This, pData);
1112
1113     /* Remove previous name */
1114     HeapFree(GetProcessHeap(), 0, This->name);
1115     This->name = NULL;
1116     hr = IDirectXFileData_GetName(pData, NULL, &size);
1117     if (hr != DXFILE_OK)
1118         return hr;
1119     if (size)
1120     {
1121         This->name = HeapAlloc(GetProcessHeap(), 0, size);
1122         if (!This->name)
1123             return E_OUTOFMEMORY;
1124
1125         hr = IDirectXFileData_GetName(pData, This->name, &size);
1126         if (hr != DXFILE_OK)
1127         {
1128             HeapFree(GetProcessHeap(), 0, This->name);
1129             This->name = NULL;
1130             return hr;
1131         }
1132     }
1133
1134     TRACE("Mesh name is '%s'\n", This->name ? This->name : "");
1135
1136     This->nb_normals = 0;
1137
1138     hr = IDirectXFileData_GetData(pData, NULL, &size, (void**)&ptr);
1139     if (hr != DXFILE_OK)
1140         goto end;
1141
1142     This->nb_vertices = *(DWORD*)ptr;
1143     This->nb_faces = *(DWORD*)(ptr + sizeof(DWORD) + This->nb_vertices * sizeof(D3DVECTOR));
1144     faces_vertex_idx_size = size - sizeof(DWORD) - This->nb_vertices * sizeof(D3DVECTOR) - sizeof(DWORD);
1145     faces_vertex_idx_ptr = (DWORD*)(ptr + sizeof(DWORD) + This->nb_vertices * sizeof(D3DVECTOR) + sizeof(DWORD));
1146
1147     TRACE("Mesh: nb_vertices = %d, nb_faces = %d, faces_vertex_idx_size = %d\n", This->nb_vertices, This->nb_faces, faces_vertex_idx_size);
1148
1149     This->pVertices = HeapAlloc(GetProcessHeap(), 0, This->nb_vertices * sizeof(D3DVECTOR));
1150     memcpy(This->pVertices, ptr + sizeof(DWORD), This->nb_vertices * sizeof(D3DVECTOR));
1151
1152     faces_vertex_idx_ptr = faces_vertex_idx_data = HeapAlloc(GetProcessHeap(), 0, faces_vertex_idx_size);
1153     memcpy(faces_vertex_idx_data, ptr + sizeof(DWORD) + This->nb_vertices * sizeof(D3DVECTOR) + sizeof(DWORD), faces_vertex_idx_size);
1154
1155     /* Each vertex index will have its normal index counterpart so just allocate twice the size */
1156     This->pFaceData = HeapAlloc(GetProcessHeap(), 0, faces_vertex_idx_size*2);
1157     faces_data_ptr = (DWORD*)This->pFaceData;
1158
1159     while (1)
1160     {
1161         hr =  IDirectXFileData_GetNextObject(pData, &pObject);
1162         if (hr == DXFILEERR_NOMOREOBJECTS)
1163         {
1164             TRACE("No more object\n");
1165             break;
1166         }
1167         if (hr != DXFILE_OK)
1168            goto end;
1169
1170         hr = IDirectXFileObject_QueryInterface(pObject, &IID_IDirectXFileData, (void**)&pData2);
1171         IDirectXFileObject_Release(pObject);
1172         if (hr != DXFILE_OK)
1173             goto end;
1174
1175         hr = IDirectXFileData_GetType(pData2, &pGuid);
1176         if (hr != DXFILE_OK)
1177             goto end;
1178
1179         TRACE("Found object type whose GUID = %s\n", debugstr_guid(pGuid));
1180
1181         if (IsEqualGUID(pGuid, &TID_D3DRMMeshNormals))
1182         {
1183             DWORD nb_faces_normals;
1184             DWORD faces_normal_idx_size;
1185
1186             hr = IDirectXFileData_GetData(pData2, NULL, &size, (void**)&ptr);
1187             if (hr != DXFILE_OK)
1188                 goto end;
1189
1190             This->nb_normals = *(DWORD*)ptr;
1191             nb_faces_normals = *(DWORD*)(ptr + sizeof(DWORD) + This->nb_normals * sizeof(D3DVECTOR));
1192
1193             TRACE("MeshNormals: nb_normals = %d, nb_faces_normals = %d\n", This->nb_normals, nb_faces_normals);
1194             if (nb_faces_normals != This->nb_faces)
1195                 WARN("nb_face_normals (%d) != nb_faces (%d)\n", nb_faces_normals, This->nb_normals);
1196
1197             This->pNormals = HeapAlloc(GetProcessHeap(), 0, This->nb_normals * sizeof(D3DVECTOR));
1198             memcpy(This->pNormals, ptr + sizeof(DWORD), This->nb_normals * sizeof(D3DVECTOR));
1199
1200             faces_normal_idx_size = size - (2*sizeof(DWORD) + This->nb_normals * sizeof(D3DVECTOR));
1201             faces_normal_idx_ptr = faces_normal_idx_data = HeapAlloc(GetProcessHeap(), 0, faces_normal_idx_size);
1202             memcpy(faces_normal_idx_data, ptr + sizeof(DWORD) + This->nb_normals * sizeof(D3DVECTOR) + sizeof(DWORD), faces_normal_idx_size);
1203         }
1204         else if (IsEqualGUID(pGuid, &TID_D3DRMMeshTextureCoords))
1205         {
1206             hr = IDirectXFileData_GetData(pData2, NULL, &size, (void**)&ptr);
1207             if (hr != DXFILE_OK)
1208                 goto end;
1209
1210             This->nb_coords2d = *(DWORD*)ptr;
1211
1212             TRACE("MeshTextureCoords: nb_coords2d = %d\n", This->nb_coords2d);
1213
1214             This->pCoords2d = HeapAlloc(GetProcessHeap(), 0, This->nb_coords2d * sizeof(Coords2d));
1215             memcpy(This->pCoords2d, ptr + sizeof(DWORD), This->nb_coords2d * sizeof(Coords2d));
1216
1217         }
1218         else if (IsEqualGUID(pGuid, &TID_D3DRMMeshMaterialList))
1219         {
1220             DWORD nb_materials;
1221             DWORD nb_face_indices;
1222             DWORD data_size;
1223             LPDIRECTXFILEOBJECT child;
1224             DWORD i = 0;
1225             float* values;
1226
1227             TRACE("Process MeshMaterialList\n");
1228
1229             hr = IDirectXFileData_GetData(pData2, NULL, &size, (void**)&ptr);
1230             if (hr != DXFILE_OK)
1231                 goto end;
1232
1233             nb_materials = *(DWORD*)ptr;
1234             nb_face_indices = *(DWORD*)(ptr + sizeof(DWORD));
1235             data_size = 2 * sizeof(DWORD) + nb_face_indices * sizeof(DWORD);
1236
1237             TRACE("nMaterials = %u, nFaceIndexes = %u\n", nb_materials, nb_face_indices);
1238
1239             if (size != data_size)
1240                 WARN("Returned size %u does not match expected one %u\n", size, data_size);
1241
1242             if (nb_materials > 2)
1243             {
1244                 FIXME("Only one material per mesh supported, first one applies to all faces\n");
1245                 nb_materials = 1;
1246             }
1247
1248             while (SUCCEEDED(hr = IDirectXFileData_GetNextObject(pData2, &child)) && (i < nb_materials))
1249             {
1250                 LPDIRECTXFILEDATA data;
1251                 LPDIRECTXFILEDATAREFERENCE reference;
1252                 LPDIRECT3DRMMATERIAL2 material;
1253                 LPDIRECTXFILEOBJECT material_child;
1254
1255                 hr = IDirectXFileObject_QueryInterface(child, &IID_IDirectXFileData, (void **)&data);
1256                 if (FAILED(hr))
1257                 {
1258                     hr = IDirectXFileObject_QueryInterface(child, &IID_IDirectXFileDataReference, (void **)&reference);
1259                     if (FAILED(hr))
1260                         goto end;
1261
1262                     hr = IDirectXFileDataReference_Resolve(reference, &data);
1263                     IDirectXFileDataReference_Release(reference);
1264                     if (FAILED(hr))
1265                         goto end;
1266                 }
1267
1268                 hr = Direct3DRMMaterial_create(&material);
1269                 if (FAILED(hr))
1270                 {
1271                     IDirectXFileData_Release(data);
1272                     goto end;
1273                 }
1274
1275                 hr = IDirectXFileData_GetData(data, NULL, &size, (void**)&ptr);
1276                 if (hr != DXFILE_OK)
1277                 {
1278                     IDirectXFileData_Release(data);
1279                     goto end;
1280                 }
1281
1282                 if (size != 44)
1283                     WARN("Material size %u does not match expected one %u\n", size, 44);
1284
1285                 values = (float*)ptr;
1286
1287                 IDirect3DRMMeshBuilder3_SetColorRGB(iface, values[0], values [1], values[2]); /* Alpha ignored */
1288
1289                 IDirect3DRMMaterial2_SetAmbient(material, values[0], values [1], values[2]); /* Alpha ignored */
1290                 IDirect3DRMMaterial2_SetPower(material, values[4]);
1291                 IDirect3DRMMaterial2_SetSpecular(material, values[5], values[6], values[7]);
1292                 IDirect3DRMMaterial2_SetEmissive(material, values[8], values[9], values[10]);
1293
1294                 This->material = material;
1295
1296                 hr = IDirectXFileData_GetNextObject(data, &material_child);
1297                 if (hr == S_OK)
1298                 {
1299                     LPDIRECTXFILEDATA data;
1300                     LPDIRECT3DRMTEXTURE3 texture;
1301                     char** filename;
1302
1303                     hr = IDirectXFileObject_QueryInterface(material_child, &IID_IDirectXFileData, (void **)&data);
1304                     if (FAILED(hr))
1305                     {
1306                         LPDIRECTXFILEDATAREFERENCE reference;
1307
1308                         hr = IDirectXFileObject_QueryInterface(material_child, &IID_IDirectXFileDataReference, (void **)&reference);
1309                         if (FAILED(hr))
1310                             goto end;
1311
1312                         hr = IDirectXFileDataReference_Resolve(reference, &data);
1313                         IDirectXFileDataReference_Release(reference);
1314                         if (FAILED(hr))
1315                             goto end;
1316                     }
1317
1318                     hr = IDirectXFileData_GetType(data, &pGuid);
1319                     if (hr != DXFILE_OK)
1320                         goto end;
1321                     if (!IsEqualGUID(pGuid, &TID_D3DRMTextureFilename))
1322                     {
1323                          WARN("Not a texture filename\n");
1324                          goto end;
1325                     }
1326
1327                     size = 4;
1328                     hr = IDirectXFileData_GetData(data, NULL, &size, (void**)&filename);
1329                     if (SUCCEEDED(hr))
1330                     {
1331                         HANDLE file;
1332
1333                         file = CreateFileA(*filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
1334                         if (file != INVALID_HANDLE_VALUE)
1335                         {
1336                             hr = Direct3DRMTexture_create(&IID_IDirect3DRMTexture3, (LPUNKNOWN*)&texture);
1337                             if (FAILED(hr))
1338                             {
1339                                 IDirectXFileData_Release(data);
1340                                 goto end;
1341                             }
1342                             This->texture = texture;
1343                         }
1344                     }
1345                 }
1346                 else if (hr != DXFILEERR_NOMOREOBJECTS)
1347                 {
1348                     goto end;
1349                 }
1350                 hr = S_OK;
1351
1352                 IDirectXFileData_Release(data);
1353                 i++;
1354             }
1355             if (hr == S_OK)
1356                 WARN("Found more sub-objects than expected\n");
1357             else if (hr != DXFILEERR_NOMOREOBJECTS)
1358                 goto end;
1359             hr = S_OK;
1360         }
1361         else
1362         {
1363             FIXME("Unknown GUID %s, ignoring...\n", debugstr_guid(pGuid));
1364         }
1365
1366         IDirectXFileData_Release(pData2);
1367         pData2 = NULL;
1368     }
1369
1370     if (!This->nb_normals)
1371     {
1372         /* Allocate normals, one per vertex */
1373         This->pNormals = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->nb_vertices * sizeof(D3DVECTOR));
1374         if (!This->pNormals)
1375             goto end;
1376     }
1377
1378     for (i = 0; i < This->nb_faces; i++)
1379     {
1380         DWORD j;
1381         DWORD nb_face_indexes;
1382         D3DVECTOR face_normal;
1383
1384         if (faces_vertex_idx_size < sizeof(DWORD))
1385             WARN("Not enough data to read number of indices of face %d\n", i);
1386
1387         nb_face_indexes  = *(faces_data_ptr + faces_data_size++) = *(faces_vertex_idx_ptr++);
1388         faces_vertex_idx_size--;
1389         if (faces_normal_idx_data && (*(faces_normal_idx_ptr++) != nb_face_indexes))
1390             WARN("Faces indices number mismatch\n");
1391
1392         if (faces_vertex_idx_size < (nb_face_indexes * sizeof(DWORD)))
1393             WARN("Not enough data to read all indices of face %d\n", i);
1394
1395         if (!This->nb_normals)
1396         {
1397             /* Compute face normal */
1398             if (nb_face_indexes > 2)
1399             {
1400                 D3DVECTOR a, b;
1401
1402                 D3DRMVectorSubtract(&a, &This->pVertices[faces_vertex_idx_ptr[2]], &This->pVertices[faces_vertex_idx_ptr[1]]);
1403                 D3DRMVectorSubtract(&a, &This->pVertices[faces_vertex_idx_ptr[1]], &This->pVertices[faces_vertex_idx_ptr[0]]);
1404                 D3DRMVectorCrossProduct(&face_normal, &a, &b);
1405                 D3DRMVectorNormalize(&face_normal);
1406             }
1407             else
1408             {
1409                 face_normal.u1.x = 0.0f;
1410                 face_normal.u2.y = 0.0f;
1411                 face_normal.u3.z = 0.0f;
1412             }
1413         }
1414
1415         for (j = 0; j < nb_face_indexes; j++)
1416         {
1417             /* Copy vertex index */
1418             *(faces_data_ptr + faces_data_size++) = *faces_vertex_idx_ptr;
1419             /* Copy normal index */
1420             if (This->nb_normals)
1421             {
1422                 /* Read from x file */
1423                 *(faces_data_ptr + faces_data_size++) = *(faces_normal_idx_ptr++);
1424             }
1425             else
1426             {
1427                 DWORD vertex_idx = *faces_vertex_idx_ptr;
1428                 if (vertex_idx >= This->nb_vertices)
1429                 {
1430                     WARN("Found vertex index %u but only %u vertices available => use index 0\n", vertex_idx, This->nb_vertices);
1431                     vertex_idx = 0;
1432                 }
1433                 *(faces_data_ptr + faces_data_size++) = vertex_idx;
1434                 /* Add face normal to vertex normal */
1435                 D3DRMVectorAdd(&This->pNormals[vertex_idx], &This->pNormals[vertex_idx], &face_normal);
1436             }
1437             faces_vertex_idx_ptr++;
1438         }
1439         faces_vertex_idx_size -= nb_face_indexes;
1440     }
1441
1442     /* Last DWORD must be 0 */
1443     *(faces_data_ptr + faces_data_size++) = 0;
1444
1445     /* Set size (in number of DWORD) of all faces data */
1446     This->face_data_size = faces_data_size;
1447
1448     if (!This->nb_normals)
1449     {
1450         /* Normalize all normals */
1451         for (i = 0; i < This->nb_vertices; i++)
1452         {
1453             D3DRMVectorNormalize(&This->pNormals[i]);
1454         }
1455         This->nb_normals = This->nb_vertices;
1456     }
1457
1458     /* If there is no texture coordinates, generate default texture coordinates (0.0f, 0.0f) for each vertex */
1459     if (!This->pCoords2d)
1460     {
1461         This->nb_coords2d = This->nb_vertices;
1462         This->pCoords2d = HeapAlloc(GetProcessHeap(), 0, This->nb_coords2d * sizeof(Coords2d));
1463         for (i = 0; i < This->nb_coords2d; i++)
1464         {
1465             This->pCoords2d[i].u = 0.0f;
1466             This->pCoords2d[i].v = 0.0f;
1467         }
1468     }
1469
1470     TRACE("Mesh data loaded successfully\n");
1471
1472     ret = D3DRM_OK;
1473
1474 end:
1475
1476     HeapFree(GetProcessHeap(), 0, faces_normal_idx_data);
1477     HeapFree(GetProcessHeap(), 0, faces_vertex_idx_data);
1478
1479     return ret;
1480 }
1481
1482 /*** IDirect3DRMMeshBuilder3 methods ***/
1483 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Load(IDirect3DRMMeshBuilder3* iface,
1484                                                        LPVOID filename, LPVOID name,
1485                                                        D3DRMLOADOPTIONS loadflags,
1486                                                        D3DRMLOADTEXTURE3CALLBACK cb, LPVOID arg)
1487 {
1488     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1489     DXFILELOADOPTIONS load_options;
1490     LPDIRECTXFILE pDXFile = NULL;
1491     LPDIRECTXFILEENUMOBJECT pEnumObject = NULL;
1492     LPDIRECTXFILEDATA pData = NULL;
1493     LPDIRECTXFILEDATA pData2 = NULL;
1494     const GUID* pGuid;
1495     DWORD size;
1496     Header* pHeader;
1497     HRESULT hr;
1498     HRESULT ret = D3DRMERR_BADOBJECT;
1499
1500     TRACE("(%p)->(%p,%p,%x,%p,%p)\n", This, filename, name, loadflags, cb, arg);
1501
1502     /* First free allocated buffers of previous mesh data */
1503     HeapFree(GetProcessHeap(), 0, This->pVertices);
1504     This->pVertices = NULL;
1505     HeapFree(GetProcessHeap(), 0, This->pNormals);
1506     This->pNormals = NULL;
1507     HeapFree(GetProcessHeap(), 0, This->pFaceData);
1508     This->pFaceData = NULL;
1509     HeapFree(GetProcessHeap(), 0, This->pCoords2d);
1510     This->pCoords2d = NULL;
1511
1512     if (loadflags == D3DRMLOAD_FROMMEMORY)
1513     {
1514         load_options = DXFILELOAD_FROMMEMORY;
1515     }
1516     else if (loadflags == D3DRMLOAD_FROMFILE)
1517     {
1518         load_options = DXFILELOAD_FROMFILE;
1519         TRACE("Loading from file %s\n", debugstr_a(filename));
1520     }
1521     else
1522     {
1523         FIXME("Load options %d not supported yet\n", loadflags);
1524         return E_NOTIMPL;
1525     }
1526
1527     hr = DirectXFileCreate(&pDXFile);
1528     if (hr != DXFILE_OK)
1529         goto end;
1530
1531     hr = IDirectXFile_RegisterTemplates(pDXFile, templates, strlen(templates));
1532     if (hr != DXFILE_OK)
1533         goto end;
1534
1535     hr = IDirectXFile_CreateEnumObject(pDXFile, filename, load_options, &pEnumObject);
1536     if (hr != DXFILE_OK)
1537         goto end;
1538
1539     hr = IDirectXFileEnumObject_GetNextDataObject(pEnumObject, &pData);
1540     if (hr != DXFILE_OK)
1541         goto end;
1542
1543     hr = IDirectXFileData_GetType(pData, &pGuid);
1544     if (hr != DXFILE_OK)
1545         goto end;
1546
1547     TRACE("Found object type whose GUID = %s\n", debugstr_guid(pGuid));
1548
1549     if (!IsEqualGUID(pGuid, &TID_DXFILEHeader))
1550     {
1551         ret = D3DRMERR_BADFILE;
1552         goto end;
1553     }
1554
1555     hr = IDirectXFileData_GetData(pData, NULL, &size, (void**)&pHeader);
1556     if ((hr != DXFILE_OK) || (size != sizeof(Header)))
1557         goto end;
1558
1559     TRACE("Version is %d %d %d\n", pHeader->major, pHeader->minor, pHeader->flags);
1560
1561     /* Version must be 1.0.x */
1562     if ((pHeader->major != 1) || (pHeader->minor != 0))
1563     {
1564         ret = D3DRMERR_BADFILE;
1565         goto end;
1566     }
1567
1568     IDirectXFileData_Release(pData);
1569     pData = NULL;
1570
1571     hr = IDirectXFileEnumObject_GetNextDataObject(pEnumObject, &pData);
1572     if (hr != DXFILE_OK)
1573     {
1574         ret = D3DRMERR_NOTFOUND;
1575         goto end;
1576     }
1577
1578     hr = IDirectXFileData_GetType(pData, &pGuid);
1579     if (hr != DXFILE_OK)
1580         goto end;
1581
1582     TRACE("Found object type whose GUID = %s\n", debugstr_guid(pGuid));
1583
1584     if (!IsEqualGUID(pGuid, &TID_D3DRMMesh))
1585     {
1586         ret = D3DRMERR_NOTFOUND;
1587         goto end;
1588     }
1589
1590     hr = load_mesh_data(iface, pData);
1591     if (hr == S_OK)
1592         ret = D3DRM_OK;
1593
1594 end:
1595
1596     if (pData2)
1597         IDirectXFileData_Release(pData2);
1598     if (pData)
1599         IDirectXFileData_Release(pData);
1600     if (pEnumObject)
1601         IDirectXFileEnumObject_Release(pEnumObject);
1602     if (pDXFile)
1603         IDirectXFile_Release(pDXFile);
1604
1605     if (ret != D3DRM_OK)
1606     {
1607         /* Clean mesh data */
1608         This->nb_vertices = 0;
1609         This->nb_normals = 0;
1610         This->nb_faces = 0;
1611         This->face_data_size = 0;
1612         This->nb_coords2d = 0;
1613         HeapFree(GetProcessHeap(), 0, This->pVertices);
1614         This->pVertices = NULL;
1615         HeapFree(GetProcessHeap(), 0, This->pNormals);
1616         This->pNormals = NULL;
1617         HeapFree(GetProcessHeap(), 0, This->pFaceData);
1618         This->pFaceData = NULL;
1619         HeapFree(GetProcessHeap(), 0, This->pCoords2d);
1620         This->pCoords2d = NULL;
1621     }
1622
1623     return ret;
1624 }
1625
1626 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Save(IDirect3DRMMeshBuilder3* iface,
1627                                                        const char* filename, D3DRMXOFFORMAT format,
1628                                                        D3DRMSAVEOPTIONS save)
1629 {
1630     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1631
1632     FIXME("(%p)->(%s,%d,%d): stub\n", This, filename, format, save);
1633
1634     return E_NOTIMPL;
1635 }
1636
1637 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Scale(IDirect3DRMMeshBuilder3* iface,
1638                                                         D3DVALUE sx, D3DVALUE sy, D3DVALUE sz)
1639 {
1640     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1641     int i;
1642
1643     TRACE("(%p)->(%f,%f,%f)\n", This, sx, sy, sz);
1644
1645     for (i = 0; i < This->nb_vertices; i++)
1646     {
1647         This->pVertices[i].u1.x *= sx;
1648         This->pVertices[i].u2.y *= sy;
1649         This->pVertices[i].u3.z *= sz;
1650     }
1651
1652     /* Normals are not affected by Scale */
1653
1654     return D3DRM_OK;
1655 }
1656
1657 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Translate(IDirect3DRMMeshBuilder3* iface,
1658                                                             D3DVALUE tx, D3DVALUE ty, D3DVALUE tz)
1659 {
1660     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1661
1662     FIXME("(%p)->(%f,%f,%f): stub\n", This, tx, ty, tz);
1663
1664     return E_NOTIMPL;
1665 }
1666
1667 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetColorSource(IDirect3DRMMeshBuilder3* iface,
1668                                                                  D3DRMCOLORSOURCE color)
1669 {
1670     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1671
1672     FIXME("(%p)->(%x): stub\n", This, color);
1673
1674     return E_NOTIMPL;
1675 }
1676
1677 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetBox(IDirect3DRMMeshBuilder3* iface,
1678                                                          D3DRMBOX* box)
1679 {
1680     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1681
1682     FIXME("(%p)->(%p): stub\n", This, box);
1683
1684     return E_NOTIMPL;
1685 }
1686
1687 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GenerateNormals(IDirect3DRMMeshBuilder3* iface,
1688                                                                   D3DVALUE crease, DWORD flags)
1689 {
1690     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1691
1692     FIXME("(%p)->(%f,%u): stub\n", This, crease, flags);
1693
1694     return E_NOTIMPL;
1695 }
1696
1697 static D3DRMCOLORSOURCE WINAPI IDirect3DRMMeshBuilder3Impl_GetColorSource(IDirect3DRMMeshBuilder3* iface)
1698 {
1699     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1700
1701     FIXME("(%p)->(): stub\n", This);
1702
1703     return E_NOTIMPL;
1704 }
1705
1706 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddMesh(IDirect3DRMMeshBuilder3* iface,
1707                                                           LPDIRECT3DRMMESH Mesh)
1708 {
1709     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1710
1711     FIXME("(%p)->(%p): stub\n", This, Mesh);
1712
1713     return E_NOTIMPL;
1714 }
1715
1716 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddMeshBuilder(IDirect3DRMMeshBuilder3* iface,
1717                                                                  LPDIRECT3DRMMESHBUILDER3 MeshBuilder,
1718                                                                  DWORD flags)
1719 {
1720     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1721
1722     FIXME("(%p)->(%p,%u): stub\n", This, MeshBuilder, flags);
1723
1724     return E_NOTIMPL;
1725 }
1726
1727 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddFrame(IDirect3DRMMeshBuilder3* iface,
1728                                                            LPDIRECT3DRMFRAME3 Frame)
1729 {
1730     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1731
1732     FIXME("(%p)->(%p): stub\n", This, Frame);
1733
1734     return E_NOTIMPL;
1735 }
1736
1737 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddFace(IDirect3DRMMeshBuilder3* iface,
1738                                                           LPDIRECT3DRMFACE2 Face)
1739 {
1740     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1741
1742     FIXME("(%p)->(%p): stub\n", This, Face);
1743
1744     return E_NOTIMPL;
1745 }
1746
1747 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddFaces(IDirect3DRMMeshBuilder3* iface,
1748                                                            DWORD vcount, D3DVECTOR* vertices,
1749                                                            DWORD ncount, D3DVECTOR* normals,
1750                                                            DWORD* data,
1751                                                            LPDIRECT3DRMFACEARRAY* FaceArray)
1752 {
1753     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1754
1755     FIXME("(%p)->(%d,%p,%d,%p,%p,%p): stub\n", This, vcount, vertices, ncount,
1756           normals, data, FaceArray);
1757
1758     return E_NOTIMPL;
1759 }
1760
1761 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_ReserveSpace(IDirect3DRMMeshBuilder3* iface,
1762                                                                DWORD vertex_Count,
1763                                                                DWORD normal_count,
1764                                                                DWORD face_count)
1765 {
1766     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1767
1768     FIXME("(%p)->(%d,%d,%d): stub\n", This, vertex_Count, normal_count, face_count);
1769
1770     return E_NOTIMPL;
1771 }
1772
1773 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetColorRGB(IDirect3DRMMeshBuilder3* iface,
1774                                                               D3DVALUE red, D3DVALUE green,
1775                                                               D3DVALUE blue)
1776 {
1777     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1778
1779     TRACE("(%p)->(%f,%f,%f)\n", This, red, green, blue);
1780
1781     This->color = D3DCOLOR_ARGB(0xff, (BYTE)(red   * 255.0f),
1782                                       (BYTE)(green * 255.0f),
1783                                       (BYTE)(blue  * 255.0f));
1784
1785     return D3DRM_OK;
1786 }
1787
1788 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetColor(IDirect3DRMMeshBuilder3* iface,
1789                                                            D3DCOLOR color)
1790 {
1791     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1792
1793     TRACE("(%p)->(%x)\n", This, color);
1794
1795     This->color = color;
1796
1797     return D3DRM_OK;
1798 }
1799
1800 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetTexture(IDirect3DRMMeshBuilder3* iface,
1801                                                              LPDIRECT3DRMTEXTURE3 texture)
1802 {
1803     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1804
1805     TRACE("(%p)->(%p)\n", This, texture);
1806
1807     if (texture)
1808         IDirect3DRMTexture3_AddRef(texture);
1809     if (This->texture)
1810         IDirect3DRMTexture3_Release(This->texture);
1811     This->texture = texture;
1812
1813     return D3DRM_OK;
1814 }
1815
1816 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetMaterial(IDirect3DRMMeshBuilder3* iface,
1817                                                               LPDIRECT3DRMMATERIAL2 material)
1818 {
1819     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1820
1821     TRACE("(%p)->(%p)\n", This, material);
1822
1823     if (material)
1824         IDirect3DRMTexture2_AddRef(material);
1825     if (This->material)
1826         IDirect3DRMTexture2_Release(This->material);
1827     This->material = material;
1828
1829     return D3DRM_OK;
1830 }
1831
1832 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetTextureTopology(IDirect3DRMMeshBuilder3* iface,
1833                                                                      BOOL wrap_u, BOOL wrap_v)
1834 {
1835     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1836
1837     FIXME("(%p)->(%d,%d): stub\n", This, wrap_u, wrap_v);
1838
1839     return E_NOTIMPL;
1840 }
1841
1842 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetQuality(IDirect3DRMMeshBuilder3* iface,
1843                                                              D3DRMRENDERQUALITY quality)
1844 {
1845     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1846
1847     FIXME("(%p)->(%d): stub\n", This, quality);
1848
1849     return E_NOTIMPL;
1850 }
1851
1852 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetPerspective(IDirect3DRMMeshBuilder3* iface,
1853                                                                  BOOL enable)
1854 {
1855     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1856
1857     FIXME("(%p)->(%d): stub\n", This, enable);
1858
1859     return E_NOTIMPL;
1860 }
1861
1862 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetVertex(IDirect3DRMMeshBuilder3* iface,
1863                                                             DWORD index,
1864                                                             D3DVALUE x, D3DVALUE y, D3DVALUE z)
1865 {
1866     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1867
1868     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
1869
1870     return E_NOTIMPL;
1871 }
1872
1873 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetNormal(IDirect3DRMMeshBuilder3* iface,
1874                                                             DWORD index,
1875                                                             D3DVALUE x, D3DVALUE y, D3DVALUE z)
1876 {
1877     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1878
1879     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
1880
1881     return E_NOTIMPL;
1882 }
1883
1884 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetTextureCoordinates(IDirect3DRMMeshBuilder3* iface,
1885                                                                         DWORD index, D3DVALUE u,
1886                                                                         D3DVALUE v)
1887 {
1888     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1889
1890     TRACE("(%p)->(%u,%f,%f)\n", This, index, u, v);
1891
1892     if (index >= This->nb_coords2d)
1893         return D3DRMERR_BADVALUE;
1894
1895     This->pCoords2d[index].u = u;
1896     This->pCoords2d[index].v = v;
1897
1898     return D3DRM_OK;
1899 }
1900
1901 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetVertexColor(IDirect3DRMMeshBuilder3* iface,
1902                                                                  DWORD index, D3DCOLOR color)
1903 {
1904     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1905
1906     FIXME("(%p)->(%d,%x): stub\n", This, index, color);
1907
1908     return E_NOTIMPL;
1909 }
1910
1911 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetVertexColorRGB(IDirect3DRMMeshBuilder3* iface,
1912                                                                     DWORD index,
1913                                                                     D3DVALUE red, D3DVALUE green,
1914                                                                     D3DVALUE blue)
1915 {
1916     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1917
1918     FIXME("(%p)->(%d,%f,%f,%f): stub\n", This, index, red, green, blue);
1919
1920     return E_NOTIMPL;
1921 }
1922
1923 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetFaces(IDirect3DRMMeshBuilder3* iface,
1924                                                            LPDIRECT3DRMFACEARRAY* FaceArray)
1925 {
1926     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1927
1928     FIXME("(%p)->(%p): stub\n", This, FaceArray);
1929
1930     return E_NOTIMPL;
1931 }
1932
1933 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetGeometry(IDirect3DRMMeshBuilder3* iface,
1934                                                               DWORD* vcount, D3DVECTOR* vertices,
1935                                                               DWORD* ncount, D3DVECTOR* normals,
1936                                                               DWORD* face_data_size,
1937                                                               DWORD* face_data)
1938 {
1939     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1940
1941     FIXME("(%p)->(%p,%p,%p,%p,%p,%p): stub\n", This, vcount, vertices, ncount, normals,
1942           face_data_size, face_data);
1943
1944     return E_NOTIMPL;
1945 }
1946
1947 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetTextureCoordinates(IDirect3DRMMeshBuilder3* iface,
1948                                                                         DWORD index, D3DVALUE* u,
1949                                                                         D3DVALUE* v)
1950 {
1951     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1952
1953     TRACE("(%p)->(%d,%p,%p)\n", This, index, u, v);
1954
1955     if (index >= This->nb_coords2d)
1956         return D3DRMERR_BADVALUE;
1957
1958     *u = This->pCoords2d[index].u;
1959     *v = This->pCoords2d[index].v;
1960
1961     return D3DRM_OK;
1962 }
1963
1964
1965 static int WINAPI IDirect3DRMMeshBuilder3Impl_AddVertex(IDirect3DRMMeshBuilder3* iface,
1966                                                         D3DVALUE x, D3DVALUE y, D3DVALUE z)
1967 {
1968     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1969
1970     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
1971
1972     return 0;
1973 }
1974
1975 static int WINAPI IDirect3DRMMeshBuilder3Impl_AddNormal(IDirect3DRMMeshBuilder3* iface,
1976                                                         D3DVALUE x, D3DVALUE y, D3DVALUE z)
1977 {
1978     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1979
1980     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
1981
1982     return 0;
1983 }
1984
1985 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_CreateFace(IDirect3DRMMeshBuilder3* iface,
1986                                                              LPDIRECT3DRMFACE2* Face)
1987 {
1988     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1989
1990     FIXME("(%p)->(%p): stub\n", This, Face);
1991
1992     return E_NOTIMPL;
1993 }
1994
1995 static D3DRMRENDERQUALITY WINAPI IDirect3DRMMeshBuilder3Impl_GetQuality(IDirect3DRMMeshBuilder3* iface)
1996 {
1997     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1998
1999     FIXME("(%p)->(): stub\n", This);
2000
2001     return 0;
2002 }
2003
2004 static BOOL WINAPI IDirect3DRMMeshBuilder3Impl_GetPerspective(IDirect3DRMMeshBuilder3* iface)
2005 {
2006     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2007
2008     FIXME("(%p)->(): stub\n", This);
2009
2010     return FALSE;
2011 }
2012
2013 static int WINAPI IDirect3DRMMeshBuilder3Impl_GetFaceCount(IDirect3DRMMeshBuilder3* iface)
2014 {
2015     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2016
2017     TRACE("(%p)->()\n", This);
2018
2019     return This->nb_faces;
2020 }
2021
2022 static int WINAPI IDirect3DRMMeshBuilder3Impl_GetVertexCount(IDirect3DRMMeshBuilder3* iface)
2023 {
2024     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2025
2026     TRACE("(%p)->()\n", This);
2027
2028     return This->nb_vertices;
2029 }
2030
2031 static D3DCOLOR WINAPI IDirect3DRMMeshBuilder3Impl_GetVertexColor(IDirect3DRMMeshBuilder3* iface,
2032                                                                   DWORD index)
2033 {
2034     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2035
2036     FIXME("(%p)->(%d): stub\n", This, index);
2037
2038     return 0;
2039 }
2040
2041 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_CreateMesh(IDirect3DRMMeshBuilder3* iface,
2042                                                              LPDIRECT3DRMMESH* mesh)
2043 {
2044     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2045     HRESULT hr;
2046     D3DRMGROUPINDEX group;
2047
2048     TRACE("(%p)->(%p)\n", This, mesh);
2049
2050     if (!mesh)
2051         return E_POINTER;
2052
2053     hr = Direct3DRMMesh_create(mesh);
2054     if (FAILED(hr))
2055         return hr;
2056
2057     /* If there is mesh data, create a group and put data inside */
2058     if (This->nb_vertices)
2059     {
2060         unsigned* face_data;
2061         unsigned* out_ptr;
2062         DWORD* in_ptr = This->pFaceData;
2063         int i, j;
2064
2065         face_data = HeapAlloc(GetProcessHeap(), 0, This->face_data_size * sizeof(DWORD));
2066         if (!face_data)
2067         {
2068             IDirect3DRMMesh_Release(*mesh);
2069             return E_OUTOFMEMORY;
2070         }
2071         out_ptr = face_data;
2072
2073         /* Put only vertex indices */
2074         for (i = 0; i < This->nb_faces; i++)
2075         {
2076             DWORD nb_indices = *out_ptr++ = *in_ptr++;
2077             for (j = 0; j < nb_indices; j++)
2078             {
2079                 *out_ptr++ = *in_ptr++;
2080                 /* Skip normal index */
2081                 in_ptr++;
2082             }
2083         }
2084
2085         hr = IDirect3DRMMesh_AddGroup(*mesh, This->nb_vertices, This->nb_faces, 0, face_data, &group);
2086         HeapFree(GetProcessHeap(), 0, face_data);
2087         if (SUCCEEDED(hr))
2088         {
2089             D3DRMVERTEX* vertices;
2090
2091             vertices = HeapAlloc(GetProcessHeap(), 0, This->nb_vertices * sizeof(D3DRMVERTEX));
2092             if (vertices)
2093             {
2094                 for (i = 0; i < This->nb_vertices; i++)
2095                 {
2096                     vertices[i].position = This->pVertices[i];
2097                 }
2098                 hr = IDirect3DRMMesh_SetVertices(*mesh, 0, 0, This->nb_vertices, vertices);
2099                 HeapFree(GetProcessHeap(), 0, vertices);
2100             }
2101             else
2102             {
2103                 hr = E_OUTOFMEMORY;
2104             }
2105         }
2106         if (SUCCEEDED(hr))
2107             hr = IDirect3DRMMesh_SetGroupColor(*mesh, 0, This->color);
2108         if (SUCCEEDED(hr))
2109             hr = IDirect3DRMMesh_SetGroupMaterial(*mesh, 0, (LPDIRECT3DRMMATERIAL)This->material);
2110         if (SUCCEEDED(hr) && This->texture)
2111         {
2112              LPDIRECT3DRMTEXTURE texture;
2113
2114              IDirect3DRMTexture3_QueryInterface(This->texture, &IID_IDirect3DRMTexture, (LPVOID*)&texture);
2115              hr = IDirect3DRMMesh_SetGroupTexture(*mesh, 0, texture);
2116              IDirect3DRMTexture_Release(texture);
2117         }
2118         if (FAILED(hr))
2119             IDirect3DRMMesh_Release(*mesh);
2120     }
2121
2122     return hr;
2123 }
2124
2125 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetFace(IDirect3DRMMeshBuilder3* iface,
2126                                                           DWORD index, LPDIRECT3DRMFACE2* Face)
2127 {
2128     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2129
2130     FIXME("(%p)->(%u,%p): stub\n", This, index, Face);
2131
2132     return E_NOTIMPL;
2133 }
2134
2135 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetVertex(IDirect3DRMMeshBuilder3* iface,
2136                                                             DWORD index, LPD3DVECTOR vector)
2137 {
2138     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2139
2140     FIXME("(%p)->(%u,%p): stub\n", This, index, vector);
2141
2142     return E_NOTIMPL;
2143 }
2144
2145 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetNormal(IDirect3DRMMeshBuilder3* iface,
2146                                                             DWORD index, LPD3DVECTOR vector)
2147 {
2148     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2149
2150     FIXME("(%p)->(%u,%p): stub\n", This, index, vector);
2151
2152     return E_NOTIMPL;
2153 }
2154
2155 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteVertices(IDirect3DRMMeshBuilder3* iface,
2156                                                                  DWORD IndexFirst, DWORD count)
2157 {
2158     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2159
2160     FIXME("(%p)->(%u,%u): stub\n", This, IndexFirst, count);
2161
2162     return E_NOTIMPL;
2163 }
2164
2165 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteNormals(IDirect3DRMMeshBuilder3* iface,
2166                                                                 DWORD IndexFirst, DWORD count)
2167 {
2168     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2169
2170     FIXME("(%p)->(%u,%u): stub\n", This, IndexFirst, count);
2171
2172     return E_NOTIMPL;
2173 }
2174
2175 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteFace(IDirect3DRMMeshBuilder3* iface,
2176                                                              LPDIRECT3DRMFACE2 Face)
2177 {
2178     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2179
2180     FIXME("(%p)->(%p): stub\n", This, Face);
2181
2182     return E_NOTIMPL;
2183 }
2184
2185 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Empty(IDirect3DRMMeshBuilder3* iface, DWORD flags)
2186 {
2187     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2188
2189     FIXME("(%p)->(%u): stub\n", This, flags);
2190
2191     return E_NOTIMPL;
2192 }
2193
2194 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Optimize(IDirect3DRMMeshBuilder3* iface,
2195                                                            DWORD flags)
2196 {
2197     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2198
2199     FIXME("(%p)->(%u): stub\n", This, flags);
2200
2201     return E_NOTIMPL;
2202 }
2203
2204 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddFacesIndexed(IDirect3DRMMeshBuilder3* iface,
2205                                                                   DWORD flags, DWORD* indices,
2206                                                                   DWORD* IndexFirst, DWORD* count)
2207 {
2208     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2209
2210     FIXME("(%p)->(%u,%p,%p,%p): stub\n", This, flags, indices, IndexFirst, count);
2211
2212     return E_NOTIMPL;
2213 }
2214
2215 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_CreateSubMesh(IDirect3DRMMeshBuilder3* iface,
2216                                                                 LPUNKNOWN *unkwn)
2217 {
2218     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2219
2220     FIXME("(%p)->(%p): stub\n", This, unkwn);
2221
2222     return E_NOTIMPL;
2223 }
2224
2225 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetParentMesh(IDirect3DRMMeshBuilder3* iface,
2226                                                                 DWORD flags, LPUNKNOWN *unkwn)
2227 {
2228     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2229
2230     FIXME("(%p)->(%u,%p): stub\n", This, flags, unkwn);
2231
2232     return E_NOTIMPL;
2233 }
2234
2235 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetSubMeshes(IDirect3DRMMeshBuilder3* iface,
2236                                                                LPDWORD count, LPUNKNOWN *unkwn)
2237 {
2238     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2239
2240     FIXME("(%p)->(%p,%p): stub\n", This, count, unkwn);
2241
2242     return E_NOTIMPL;
2243 }
2244
2245 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteSubMesh(IDirect3DRMMeshBuilder3* iface,
2246                                                                 LPUNKNOWN unkwn)
2247 {
2248     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2249
2250     FIXME("(%p)->(%p): stub\n", This, unkwn);
2251
2252     return E_NOTIMPL;
2253 }
2254
2255 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Enable(IDirect3DRMMeshBuilder3* iface,
2256                                                          DWORD index)
2257 {
2258     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2259
2260     FIXME("(%p)->(%u): stub\n", This, index);
2261
2262     return E_NOTIMPL;
2263 }
2264
2265 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetEnable(IDirect3DRMMeshBuilder3* iface,
2266                                                             DWORD* indices)
2267 {
2268     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2269
2270     FIXME("(%p)->(%p): stub\n", This, indices);
2271
2272     return E_NOTIMPL;
2273 }
2274
2275 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddTriangles(IDirect3DRMMeshBuilder3* iface,
2276                                                                DWORD flags, DWORD format,
2277                                                                DWORD VertexCount, LPVOID data)
2278 {
2279     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2280
2281     FIXME("(%p)->(%u,%u,%u,%p): stub\n", This, flags, format, VertexCount, data);
2282
2283     return E_NOTIMPL;
2284 }
2285
2286 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetVertices(IDirect3DRMMeshBuilder3* iface,
2287                                                               DWORD IndexFirst, DWORD count,
2288                                                               LPD3DVECTOR vector)
2289 {
2290     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2291
2292     FIXME("(%p)->(%u,%u,%p): stub\n", This, IndexFirst, count, vector);
2293
2294     return E_NOTIMPL;
2295 }
2296
2297 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetVertices(IDirect3DRMMeshBuilder3* iface,
2298                                                               DWORD IndexFirst, LPDWORD vcount,
2299                                                               LPD3DVECTOR vertices)
2300 {
2301     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2302     DWORD count = This->nb_vertices - IndexFirst;
2303
2304     TRACE("(%p)->(%u,%p,%p)\n", This, IndexFirst, vcount, vertices);
2305
2306     if (vcount)
2307         *vcount = count;
2308     if (vertices && This->nb_vertices)
2309         memcpy(vertices, This->pVertices + IndexFirst, count * sizeof(D3DVECTOR));
2310
2311     return D3DRM_OK;
2312 }
2313
2314 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetNormals(IDirect3DRMMeshBuilder3* iface,
2315                                                              DWORD IndexFirst, DWORD count,
2316                                                              LPD3DVECTOR vector)
2317 {
2318     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2319
2320     FIXME("(%p)->(%u,%u,%p): stub\n", This, IndexFirst, count, vector);
2321
2322     return E_NOTIMPL;
2323 }
2324
2325 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetNormals(IDirect3DRMMeshBuilder3* iface,
2326                                                              DWORD IndexFirst, LPDWORD count,
2327                                                              LPD3DVECTOR vector)
2328 {
2329     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2330
2331     FIXME("(%p)->(%u,%p,%p): stub\n", This, IndexFirst, count, vector);
2332
2333     return E_NOTIMPL;
2334 }
2335
2336 static int WINAPI IDirect3DRMMeshBuilder3Impl_GetNormalCount(IDirect3DRMMeshBuilder3* iface)
2337 {
2338     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2339
2340     FIXME("(%p)->(): stub\n", This);
2341
2342     return E_NOTIMPL;
2343 }
2344
2345 static const struct IDirect3DRMMeshBuilder3Vtbl Direct3DRMMeshBuilder3_Vtbl =
2346 {
2347     /*** IUnknown methods ***/
2348     IDirect3DRMMeshBuilder3Impl_QueryInterface,
2349     IDirect3DRMMeshBuilder3Impl_AddRef,
2350     IDirect3DRMMeshBuilder3Impl_Release,
2351     /*** IDirect3DRMObject methods ***/
2352     IDirect3DRMMeshBuilder3Impl_Clone,
2353     IDirect3DRMMeshBuilder3Impl_AddDestroyCallback,
2354     IDirect3DRMMeshBuilder3Impl_DeleteDestroyCallback,
2355     IDirect3DRMMeshBuilder3Impl_SetAppData,
2356     IDirect3DRMMeshBuilder3Impl_GetAppData,
2357     IDirect3DRMMeshBuilder3Impl_SetName,
2358     IDirect3DRMMeshBuilder3Impl_GetName,
2359     IDirect3DRMMeshBuilder3Impl_GetClassName,
2360     /*** IDirect3DRMMeshBuilder3 methods ***/
2361     IDirect3DRMMeshBuilder3Impl_Load,
2362     IDirect3DRMMeshBuilder3Impl_Save,
2363     IDirect3DRMMeshBuilder3Impl_Scale,
2364     IDirect3DRMMeshBuilder3Impl_Translate,
2365     IDirect3DRMMeshBuilder3Impl_SetColorSource,
2366     IDirect3DRMMeshBuilder3Impl_GetBox,
2367     IDirect3DRMMeshBuilder3Impl_GenerateNormals,
2368     IDirect3DRMMeshBuilder3Impl_GetColorSource,
2369     IDirect3DRMMeshBuilder3Impl_AddMesh,
2370     IDirect3DRMMeshBuilder3Impl_AddMeshBuilder,
2371     IDirect3DRMMeshBuilder3Impl_AddFrame,
2372     IDirect3DRMMeshBuilder3Impl_AddFace,
2373     IDirect3DRMMeshBuilder3Impl_AddFaces,
2374     IDirect3DRMMeshBuilder3Impl_ReserveSpace,
2375     IDirect3DRMMeshBuilder3Impl_SetColorRGB,
2376     IDirect3DRMMeshBuilder3Impl_SetColor,
2377     IDirect3DRMMeshBuilder3Impl_SetTexture,
2378     IDirect3DRMMeshBuilder3Impl_SetMaterial,
2379     IDirect3DRMMeshBuilder3Impl_SetTextureTopology,
2380     IDirect3DRMMeshBuilder3Impl_SetQuality,
2381     IDirect3DRMMeshBuilder3Impl_SetPerspective,
2382     IDirect3DRMMeshBuilder3Impl_SetVertex,
2383     IDirect3DRMMeshBuilder3Impl_SetNormal,
2384     IDirect3DRMMeshBuilder3Impl_SetTextureCoordinates,
2385     IDirect3DRMMeshBuilder3Impl_SetVertexColor,
2386     IDirect3DRMMeshBuilder3Impl_SetVertexColorRGB,
2387     IDirect3DRMMeshBuilder3Impl_GetFaces,
2388     IDirect3DRMMeshBuilder3Impl_GetGeometry,
2389     IDirect3DRMMeshBuilder3Impl_GetTextureCoordinates,
2390     IDirect3DRMMeshBuilder3Impl_AddVertex,
2391     IDirect3DRMMeshBuilder3Impl_AddNormal,
2392     IDirect3DRMMeshBuilder3Impl_CreateFace,
2393     IDirect3DRMMeshBuilder3Impl_GetQuality,
2394     IDirect3DRMMeshBuilder3Impl_GetPerspective,
2395     IDirect3DRMMeshBuilder3Impl_GetFaceCount,
2396     IDirect3DRMMeshBuilder3Impl_GetVertexCount,
2397     IDirect3DRMMeshBuilder3Impl_GetVertexColor,
2398     IDirect3DRMMeshBuilder3Impl_CreateMesh,
2399     IDirect3DRMMeshBuilder3Impl_GetFace,
2400     IDirect3DRMMeshBuilder3Impl_GetVertex,
2401     IDirect3DRMMeshBuilder3Impl_GetNormal,
2402     IDirect3DRMMeshBuilder3Impl_DeleteVertices,
2403     IDirect3DRMMeshBuilder3Impl_DeleteNormals,
2404     IDirect3DRMMeshBuilder3Impl_DeleteFace,
2405     IDirect3DRMMeshBuilder3Impl_Empty,
2406     IDirect3DRMMeshBuilder3Impl_Optimize,
2407     IDirect3DRMMeshBuilder3Impl_AddFacesIndexed,
2408     IDirect3DRMMeshBuilder3Impl_CreateSubMesh,
2409     IDirect3DRMMeshBuilder3Impl_GetParentMesh,
2410     IDirect3DRMMeshBuilder3Impl_GetSubMeshes,
2411     IDirect3DRMMeshBuilder3Impl_DeleteSubMesh,
2412     IDirect3DRMMeshBuilder3Impl_Enable,
2413     IDirect3DRMMeshBuilder3Impl_GetEnable,
2414     IDirect3DRMMeshBuilder3Impl_AddTriangles,
2415     IDirect3DRMMeshBuilder3Impl_SetVertices,
2416     IDirect3DRMMeshBuilder3Impl_GetVertices,
2417     IDirect3DRMMeshBuilder3Impl_SetNormals,
2418     IDirect3DRMMeshBuilder3Impl_GetNormals,
2419     IDirect3DRMMeshBuilder3Impl_GetNormalCount
2420 };
2421
2422 HRESULT Direct3DRMMeshBuilder_create(REFIID riid, IUnknown** ppObj)
2423 {
2424     IDirect3DRMMeshBuilderImpl* object;
2425
2426     TRACE("(%p)\n", ppObj);
2427
2428     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DRMMeshBuilderImpl));
2429     if (!object)
2430     {
2431         ERR("Out of memory\n");
2432         return E_OUTOFMEMORY;
2433     }
2434
2435     object->IDirect3DRMMeshBuilder2_iface.lpVtbl = &Direct3DRMMeshBuilder2_Vtbl;
2436     object->IDirect3DRMMeshBuilder3_iface.lpVtbl = &Direct3DRMMeshBuilder3_Vtbl;
2437     object->ref = 1;
2438
2439     if (IsEqualGUID(riid, &IID_IDirect3DRMMeshBuilder3))
2440         *ppObj = (IUnknown*)&object->IDirect3DRMMeshBuilder3_iface;
2441     else
2442         *ppObj = (IUnknown*)&object->IDirect3DRMMeshBuilder2_iface;
2443
2444     return S_OK;
2445 }
2446
2447 /*** IUnknown methods ***/
2448 static HRESULT WINAPI IDirect3DRMMeshImpl_QueryInterface(IDirect3DRMMesh* iface,
2449                                                          REFIID riid, void** ppvObject)
2450 {
2451     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2452
2453     TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
2454
2455     *ppvObject = NULL;
2456
2457     if (IsEqualGUID(riid, &IID_IUnknown) ||
2458         IsEqualGUID(riid, &IID_IDirect3DRMMesh))
2459     {
2460         *ppvObject = &This->IDirect3DRMMesh_iface;
2461     }
2462     else
2463     {
2464         FIXME("interface %s not implemented\n", debugstr_guid(riid));
2465         return E_NOINTERFACE;
2466     }
2467
2468     IDirect3DRMMesh_AddRef(iface);
2469     return S_OK;
2470 }
2471
2472 static ULONG WINAPI IDirect3DRMMeshImpl_AddRef(IDirect3DRMMesh* iface)
2473 {
2474     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2475     ULONG ref = InterlockedIncrement(&This->ref);
2476
2477     TRACE("(%p)->(): new ref = %d\n", This, ref);
2478
2479     return ref;
2480 }
2481
2482 static ULONG WINAPI IDirect3DRMMeshImpl_Release(IDirect3DRMMesh* iface)
2483 {
2484     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2485     ULONG ref = InterlockedDecrement(&This->ref);
2486
2487     TRACE("(%p)->(): new ref = %d\n", This, ref);
2488
2489     if (!ref)
2490     {
2491         int i;
2492
2493         for (i = 0; i < This->nb_groups; i++)
2494         {
2495             HeapFree(GetProcessHeap(), 0, This->groups[i].vertices);
2496             HeapFree(GetProcessHeap(), 0, This->groups[i].face_data);
2497             if (This->groups[i].material)
2498                 IDirect3DRMMaterial2_Release(This->groups[i].material);
2499             if (This->groups[i].texture)
2500                 IDirect3DRMTexture3_Release(This->groups[i].texture);
2501         }
2502         HeapFree(GetProcessHeap(), 0, This->groups);
2503         HeapFree(GetProcessHeap(), 0, This);
2504     }
2505
2506     return ref;
2507 }
2508
2509 /*** IDirect3DRMObject methods ***/
2510 static HRESULT WINAPI IDirect3DRMMeshImpl_Clone(IDirect3DRMMesh* iface,
2511                                                 LPUNKNOWN pUnkOuter, REFIID riid,
2512                                                 LPVOID *ppvObj)
2513 {
2514     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2515
2516     FIXME("(%p)->(%p,%s,%p): stub\n", This, pUnkOuter, debugstr_guid(riid), ppvObj);
2517
2518     return E_NOTIMPL;
2519 }
2520
2521 static HRESULT WINAPI IDirect3DRMMeshImpl_AddDestroyCallback(IDirect3DRMMesh* iface,
2522                                                              D3DRMOBJECTCALLBACK cb,
2523                                                              LPVOID argument)
2524 {
2525     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2526
2527     FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
2528
2529     return E_NOTIMPL;
2530 }
2531
2532 static HRESULT WINAPI IDirect3DRMMeshImpl_DeleteDestroyCallback(IDirect3DRMMesh* iface,
2533                                                                  D3DRMOBJECTCALLBACK cb,
2534                                                                  LPVOID argument)
2535 {
2536     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2537
2538     FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
2539
2540     return E_NOTIMPL;
2541 }
2542
2543 static HRESULT WINAPI IDirect3DRMMeshImpl_SetAppData(IDirect3DRMMesh* iface,
2544                                                      DWORD data)
2545 {
2546     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2547
2548     FIXME("(%p)->(%u): stub\n", This, data);
2549
2550     return E_NOTIMPL;
2551 }
2552
2553 static DWORD WINAPI IDirect3DRMMeshImpl_GetAppData(IDirect3DRMMesh* iface)
2554 {
2555     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2556
2557     FIXME("(%p)->(): stub\n", This);
2558
2559     return 0;
2560 }
2561
2562 static HRESULT WINAPI IDirect3DRMMeshImpl_SetName(IDirect3DRMMesh* iface,
2563                                                   LPCSTR pName)
2564 {
2565     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2566
2567     FIXME("(%p)->(%s): stub\n", This, pName);
2568
2569     return E_NOTIMPL;
2570 }
2571
2572 static HRESULT WINAPI IDirect3DRMMeshImpl_GetName(IDirect3DRMMesh* iface,
2573                                                   LPDWORD lpdwSize, LPSTR lpName)
2574 {
2575     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2576
2577     FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
2578
2579     return E_NOTIMPL;
2580 }
2581
2582 static HRESULT WINAPI IDirect3DRMMeshImpl_GetClassName(IDirect3DRMMesh* iface,
2583                                                        LPDWORD lpdwSize, LPSTR lpName)
2584 {
2585     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2586
2587     FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
2588
2589     return E_NOTIMPL;
2590 }
2591
2592 /*** IDirect3DRMMesh methods ***/
2593 static HRESULT WINAPI IDirect3DRMMeshImpl_Scale(IDirect3DRMMesh* iface,
2594                                                 D3DVALUE sx, D3DVALUE sy, D3DVALUE sz)
2595 {
2596     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2597
2598     FIXME("(%p)->(%f,%f,%f): stub\n", This, sx, sy,sz);
2599
2600     return E_NOTIMPL;
2601 }
2602
2603 static HRESULT WINAPI IDirect3DRMMeshImpl_Translate(IDirect3DRMMesh* iface,
2604                                                     D3DVALUE tx, D3DVALUE ty, D3DVALUE tz)
2605 {
2606     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2607
2608     FIXME("(%p)->(%f,%f,%f): stub\n", This, tx, ty,tz);
2609
2610     return E_NOTIMPL;
2611 }
2612
2613 static HRESULT WINAPI IDirect3DRMMeshImpl_GetBox(IDirect3DRMMesh* iface,
2614                                                  D3DRMBOX * box)
2615 {
2616     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2617
2618     FIXME("(%p)->(%p): stub\n", This, box);
2619
2620     return E_NOTIMPL;
2621 }
2622
2623 static HRESULT WINAPI IDirect3DRMMeshImpl_AddGroup(IDirect3DRMMesh* iface,
2624                                                    unsigned vertex_count, unsigned face_count, unsigned vertex_per_face,
2625                                                    unsigned *face_data, D3DRMGROUPINDEX *return_id)
2626 {
2627     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2628     mesh_group* group;
2629
2630     TRACE("(%p)->(%u,%u,%u,%p,%p)\n", This, vertex_count, face_count, vertex_per_face, face_data, return_id);
2631
2632     if (!face_data || !return_id)
2633         return E_POINTER;
2634
2635     if ((This->nb_groups + 1) > This->groups_capacity)
2636     {
2637         ULONG new_capacity;
2638         mesh_group* groups;
2639
2640         if (!This->groups_capacity)
2641         {
2642             new_capacity = 16;
2643             groups = HeapAlloc(GetProcessHeap(), 0, new_capacity * sizeof(mesh_group));
2644         }
2645         else
2646         {
2647             new_capacity = This->groups_capacity * 2;
2648             groups = HeapReAlloc(GetProcessHeap(), 0, This->groups, new_capacity * sizeof(mesh_group));
2649         }
2650
2651         if (!groups)
2652             return E_OUTOFMEMORY;
2653
2654         This->groups_capacity = new_capacity;
2655         This->groups = groups;
2656     }
2657
2658     group = This->groups + This->nb_groups;
2659
2660     group->vertices = HeapAlloc(GetProcessHeap(), 0, vertex_count * sizeof(D3DRMVERTEX));
2661     if (!group->vertices)
2662         return E_OUTOFMEMORY;
2663     group->nb_vertices = vertex_count;
2664     group->nb_faces = face_count;
2665     group->vertex_per_face = vertex_per_face;
2666
2667     if (vertex_per_face)
2668     {
2669         group->face_data_size = face_count * vertex_per_face;
2670     }
2671     else
2672     {
2673         int i;
2674         unsigned nb_indices;
2675         unsigned* face_data_ptr = face_data;
2676         group->face_data_size = 0;
2677
2678         for (i = 0; i < face_count; i++)
2679         {
2680             nb_indices = *face_data_ptr;
2681             group->face_data_size += nb_indices + 1;
2682             face_data_ptr += nb_indices;
2683         }
2684     }
2685
2686     group->face_data = HeapAlloc(GetProcessHeap(), 0, group->face_data_size * sizeof(unsigned));
2687     if (!group->face_data)
2688     {
2689         HeapFree(GetProcessHeap(), 0 , group->vertices);
2690         return E_OUTOFMEMORY;
2691     }
2692
2693     memcpy(group->face_data, face_data, group->face_data_size * sizeof(unsigned));
2694
2695     group->material = NULL;
2696     group->texture = NULL;
2697
2698     *return_id = This->nb_groups++;
2699
2700     return D3DRM_OK;
2701 }
2702
2703 static HRESULT WINAPI IDirect3DRMMeshImpl_SetVertices(IDirect3DRMMesh* iface,
2704                                                       D3DRMGROUPINDEX id, unsigned index, unsigned count,
2705                                                       D3DRMVERTEX *values)
2706 {
2707     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2708
2709     TRACE("(%p)->(%u,%u,%u,%p)\n", This, id, index, count, values);
2710
2711     if (id >= This->nb_groups)
2712         return D3DRMERR_BADVALUE;
2713
2714     if ((index + count - 1) >= This->groups[id].nb_vertices)
2715         return D3DRMERR_BADVALUE;
2716
2717     if (!values)
2718         return E_POINTER;
2719
2720     memcpy(This->groups[id].vertices + index, values, count * sizeof(D3DRMVERTEX));
2721
2722     return D3DRM_OK;
2723 }
2724
2725 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupColor(IDirect3DRMMesh* iface,
2726                                                         D3DRMGROUPINDEX id, D3DCOLOR color)
2727 {
2728     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2729
2730     TRACE("(%p)->(%u,%x)\n", This, id, color);
2731
2732     if (id >= This->nb_groups)
2733         return D3DRMERR_BADVALUE;
2734
2735     This->groups[id].color = color;
2736
2737     return D3DRM_OK;
2738 }
2739
2740 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupColorRGB(IDirect3DRMMesh* iface,
2741                                                            D3DRMGROUPINDEX id, D3DVALUE red, D3DVALUE green, D3DVALUE blue)
2742 {
2743     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2744
2745     TRACE("(%p)->(%u,%f,%f,%f)\n", This, id, red, green, blue);
2746
2747     if (id >= This->nb_groups)
2748         return D3DRMERR_BADVALUE;
2749
2750     This->groups[id].color = D3DCOLOR_ARGB(0xff, (BYTE)(red   * 255.0f),
2751                                                  (BYTE)(green * 255.0f),
2752                                                  (BYTE)(blue  * 255.0f));
2753
2754     return D3DRM_OK;
2755 }
2756
2757 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupMapping(IDirect3DRMMesh* iface,
2758                                                           D3DRMGROUPINDEX id, D3DRMMAPPING value)
2759 {
2760     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2761
2762     FIXME("(%p)->(%u,%u): stub\n", This, id, value);
2763
2764     return E_NOTIMPL;
2765 }
2766
2767 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupQuality(IDirect3DRMMesh* iface,
2768                                                           D3DRMGROUPINDEX id, D3DRMRENDERQUALITY value)
2769 {
2770     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2771
2772     FIXME("(%p)->(%u,%u): stub\n", This, id, value);
2773
2774     return E_NOTIMPL;
2775 }
2776
2777 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupMaterial(IDirect3DRMMesh* iface,
2778                                                            D3DRMGROUPINDEX id, LPDIRECT3DRMMATERIAL material)
2779 {
2780     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2781
2782     TRACE("(%p)->(%u,%p)\n", This, id, material);
2783
2784     if (id >= This->nb_groups)
2785         return D3DRMERR_BADVALUE;
2786
2787     if (This->groups[id].material)
2788         IDirect3DRMMaterial2_Release(This->groups[id].material);
2789
2790     This->groups[id].material = (LPDIRECT3DRMMATERIAL2)material;
2791
2792     if (material)
2793         IDirect3DRMMaterial2_AddRef(This->groups[id].material);
2794
2795     return D3DRM_OK;
2796 }
2797
2798 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupTexture(IDirect3DRMMesh* iface,
2799                                                           D3DRMGROUPINDEX id, LPDIRECT3DRMTEXTURE texture)
2800 {
2801     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2802
2803     TRACE("(%p)->(%u,%p)\n", This, id, texture);
2804
2805     if (id >= This->nb_groups)
2806         return D3DRMERR_BADVALUE;
2807
2808     if (This->groups[id].texture)
2809         IDirect3DRMTexture3_Release(This->groups[id].texture);
2810
2811     if (!texture)
2812     {
2813         This->groups[id].texture = NULL;
2814         return D3DRM_OK;
2815     }
2816
2817     return IDirect3DRMTexture3_QueryInterface(texture, &IID_IDirect3DRMTexture, (LPVOID*)&This->groups[id].texture);
2818 }
2819
2820 static DWORD WINAPI IDirect3DRMMeshImpl_GetGroupCount(IDirect3DRMMesh* iface)
2821 {
2822     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2823
2824     TRACE("(%p)->()\n", This);
2825
2826     return This->nb_groups;
2827 }
2828
2829 static HRESULT WINAPI IDirect3DRMMeshImpl_GetGroup(IDirect3DRMMesh* iface,
2830                                                    D3DRMGROUPINDEX id, unsigned *vertex_count, unsigned *face_count, unsigned *vertex_per_face,
2831                                                    DWORD *face_data_size, unsigned *face_data)
2832 {
2833     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2834
2835     TRACE("(%p)->(%u,%p,%p,%p,%p,%p)\n", This, id, vertex_count, face_count, vertex_per_face, face_data_size, face_data);
2836
2837     if (id >= This->nb_groups)
2838         return D3DRMERR_BADVALUE;
2839
2840     if (vertex_count)
2841         *vertex_count = This->groups[id].nb_vertices;
2842     if (face_count)
2843         *face_count = This->groups[id].nb_faces;
2844     if (vertex_per_face)
2845         *vertex_per_face = This->groups[id].vertex_per_face;
2846     if (face_data_size)
2847         *face_data_size = This->groups[id].face_data_size;
2848     if (face_data)
2849         memcpy(face_data, This->groups[id].face_data, This->groups[id].face_data_size);
2850
2851     return D3DRM_OK;
2852 }
2853
2854 static HRESULT WINAPI IDirect3DRMMeshImpl_GetVertices(IDirect3DRMMesh* iface,
2855                                                       D3DRMGROUPINDEX id, DWORD index, DWORD count, D3DRMVERTEX *return_ptr)
2856 {
2857     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2858
2859     TRACE("(%p)->(%u,%u,%u,%p)\n", This, id, index, count, return_ptr);
2860
2861     if (id >= This->nb_groups)
2862         return D3DRMERR_BADVALUE;
2863
2864     if ((index + count - 1) >= This->groups[id].nb_vertices)
2865         return D3DRMERR_BADVALUE;
2866
2867     if (!return_ptr)
2868         return E_POINTER;
2869
2870     memcpy(return_ptr, This->groups[id].vertices + index, count * sizeof(D3DRMVERTEX));
2871
2872     return D3DRM_OK;
2873 }
2874
2875 static D3DCOLOR WINAPI IDirect3DRMMeshImpl_GetGroupColor(IDirect3DRMMesh* iface, D3DRMGROUPINDEX id)
2876 {
2877     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2878
2879     TRACE("(%p)->(%u)\n", This, id);
2880
2881     return This->groups[id].color;
2882 }
2883
2884 static D3DRMMAPPING WINAPI IDirect3DRMMeshImpl_GetGroupMapping(IDirect3DRMMesh* iface, D3DRMGROUPINDEX id)
2885 {
2886     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2887
2888     FIXME("(%p)->(%u): stub\n", This, id);
2889
2890     return 0;
2891 }
2892 static D3DRMRENDERQUALITY WINAPI IDirect3DRMMeshImpl_GetGroupQuality(IDirect3DRMMesh* iface, D3DRMGROUPINDEX id)
2893 {
2894     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2895
2896     FIXME("(%p)->(%u): stub\n", This, id);
2897
2898     return 0;
2899 }
2900
2901 static HRESULT WINAPI IDirect3DRMMeshImpl_GetGroupMaterial(IDirect3DRMMesh* iface,
2902                                                            D3DRMGROUPINDEX id, LPDIRECT3DRMMATERIAL *material)
2903 {
2904     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2905
2906     TRACE("(%p)->(%u,%p)\n", This, id, material);
2907
2908     if (id >= This->nb_groups)
2909         return D3DRMERR_BADVALUE;
2910
2911     if (!material)
2912         return E_POINTER;
2913
2914     if (This->groups[id].material)
2915         IDirect3DRMTexture_QueryInterface(This->groups[id].material, &IID_IDirect3DRMMaterial, (void**)material);
2916     else
2917         *material = NULL;
2918
2919     return D3DRM_OK;
2920 }
2921
2922 static HRESULT WINAPI IDirect3DRMMeshImpl_GetGroupTexture(IDirect3DRMMesh* iface,
2923                                                           D3DRMGROUPINDEX id, LPDIRECT3DRMTEXTURE *texture)
2924 {
2925     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2926
2927     TRACE("(%p)->(%u,%p)\n", This, id, texture);
2928
2929     if (id >= This->nb_groups)
2930         return D3DRMERR_BADVALUE;
2931
2932     if (!texture)
2933         return E_POINTER;
2934
2935     if (This->groups[id].texture)
2936         IDirect3DRMTexture_QueryInterface(This->groups[id].texture, &IID_IDirect3DRMTexture, (void**)texture);
2937     else
2938         *texture = NULL;
2939
2940     return D3DRM_OK;
2941 }
2942
2943 static const struct IDirect3DRMMeshVtbl Direct3DRMMesh_Vtbl =
2944 {
2945     /*** IUnknown methods ***/
2946     IDirect3DRMMeshImpl_QueryInterface,
2947     IDirect3DRMMeshImpl_AddRef,
2948     IDirect3DRMMeshImpl_Release,
2949     /*** IDirect3DRMObject methods ***/
2950     IDirect3DRMMeshImpl_Clone,
2951     IDirect3DRMMeshImpl_AddDestroyCallback,
2952     IDirect3DRMMeshImpl_DeleteDestroyCallback,
2953     IDirect3DRMMeshImpl_SetAppData,
2954     IDirect3DRMMeshImpl_GetAppData,
2955     IDirect3DRMMeshImpl_SetName,
2956     IDirect3DRMMeshImpl_GetName,
2957     IDirect3DRMMeshImpl_GetClassName,
2958     /*** IDirect3DRMMesh methods ***/
2959     IDirect3DRMMeshImpl_Scale,
2960     IDirect3DRMMeshImpl_Translate,
2961     IDirect3DRMMeshImpl_GetBox,
2962     IDirect3DRMMeshImpl_AddGroup,
2963     IDirect3DRMMeshImpl_SetVertices,
2964     IDirect3DRMMeshImpl_SetGroupColor,
2965     IDirect3DRMMeshImpl_SetGroupColorRGB,
2966     IDirect3DRMMeshImpl_SetGroupMapping,
2967     IDirect3DRMMeshImpl_SetGroupQuality,
2968     IDirect3DRMMeshImpl_SetGroupMaterial,
2969     IDirect3DRMMeshImpl_SetGroupTexture,
2970     IDirect3DRMMeshImpl_GetGroupCount,
2971     IDirect3DRMMeshImpl_GetGroup,
2972     IDirect3DRMMeshImpl_GetVertices,
2973     IDirect3DRMMeshImpl_GetGroupColor,
2974     IDirect3DRMMeshImpl_GetGroupMapping,
2975     IDirect3DRMMeshImpl_GetGroupQuality,
2976     IDirect3DRMMeshImpl_GetGroupMaterial,
2977     IDirect3DRMMeshImpl_GetGroupTexture
2978 };
2979
2980 static HRESULT Direct3DRMMesh_create(IDirect3DRMMesh** obj)
2981 {
2982     IDirect3DRMMeshImpl* object;
2983
2984     TRACE("(%p)\n", obj);
2985
2986     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DRMMeshImpl));
2987     if (!object)
2988     {
2989         ERR("Out of memory\n");
2990         return E_OUTOFMEMORY;
2991     }
2992
2993     object->IDirect3DRMMesh_iface.lpVtbl = &Direct3DRMMesh_Vtbl;
2994     object->ref = 1;
2995
2996     *obj = &object->IDirect3DRMMesh_iface;
2997
2998     return S_OK;
2999 }