~ubuntu-branches/debian/sid/cloudcompare/sid

« back to all changes in this revision

Viewing changes to libs/qCC_io/MAFilter.cpp

  • Committer: Package Import Robot
  • Author(s): Gürkan Myczko
  • Date: 2018-02-23 08:38:00 UTC
  • Revision ID: package-import@ubuntu.com-20180223083800-m96gby901656yjd1
Tags: upstream-2.9.1+git20180223
Import upstream version 2.9.1+git20180223

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//##########################################################################
 
2
//#                                                                        #
 
3
//#                              CLOUDCOMPARE                              #
 
4
//#                                                                        #
 
5
//#  This program is free software; you can redistribute it and/or modify  #
 
6
//#  it under the terms of the GNU General Public License as published by  #
 
7
//#  the Free Software Foundation; version 2 or later of the License.      #
 
8
//#                                                                        #
 
9
//#  This program is distributed in the hope that it will be useful,       #
 
10
//#  but WITHOUT ANY WARRANTY; without even the implied warranty of        #
 
11
//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          #
 
12
//#  GNU General Public License for more details.                          #
 
13
//#                                                                        #
 
14
//#          COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI)             #
 
15
//#                                                                        #
 
16
//##########################################################################
 
17
 
 
18
#include "MAFilter.h"
 
19
 
 
20
//qCC_db
 
21
#include <ccLog.h>
 
22
#include <ccPointCloud.h>
 
23
#include <ccMesh.h>
 
24
#include <ccProgressDialog.h>
 
25
 
 
26
//Qt
 
27
#include <QFileInfo>
 
28
 
 
29
//System
 
30
#include <string.h>
 
31
#include <assert.h>
 
32
 
 
33
bool MAFilter::canLoadExtension(QString upperCaseExt) const
 
34
{
 
35
        //import not supported
 
36
        return false;
 
37
}
 
38
 
 
39
bool MAFilter::canSave(CC_CLASS_ENUM type, bool& multiple, bool& exclusive) const
 
40
{
 
41
        if (type == CC_TYPES::MESH)
 
42
        {
 
43
                multiple = false;
 
44
                exclusive = true;
 
45
                return true;
 
46
        }
 
47
        return false;
 
48
}
 
49
 
 
50
struct edge
 
51
{
 
52
        int edgeIndex;
 
53
        bool positif;
 
54
        unsigned theOtherPoint;
 
55
        edge* nextEdge;
 
56
};
 
57
 
 
58
void ReleaseEdgeList(edge**& theEdges, unsigned numberOfVertexes, CCLib::NormalizedProgress* nprogress = 0)
 
59
{
 
60
        for (unsigned i = 0; i < numberOfVertexes; ++i)
 
61
        {
 
62
                if (theEdges[i])
 
63
                {
 
64
                        edge* e = theEdges[i]->nextEdge;
 
65
                        while (e)
 
66
                        {
 
67
                                edge* nextE = e->nextEdge;
 
68
                                delete e;
 
69
                                e = nextE;
 
70
                        }
 
71
                        delete theEdges[i];
 
72
                }
 
73
 
 
74
                if (nprogress)
 
75
                {
 
76
                        nprogress->oneStep();
 
77
                }
 
78
        }
 
79
        delete[] theEdges;
 
80
        theEdges = 0;
 
81
}
 
82
 
 
83
struct faceIndexes
 
84
{
 
85
        int faceIndex;
 
86
        faceIndexes* nextFace;
 
87
};
 
88
 
 
89
CC_FILE_ERROR MAFilter::saveToFile(ccHObject* entity, QString filename, SaveParameters& parameters)
 
90
{
 
91
        if (!entity || filename.isEmpty())
 
92
                return CC_FERR_BAD_ARGUMENT;
 
93
 
 
94
        //the mesh to save
 
95
        ccGenericMesh* theMesh = ccHObjectCaster::ToGenericMesh(entity);
 
96
        if (!theMesh)
 
97
        {
 
98
                ccLog::Error("[MA] This filter can only save one mesh at a time!");
 
99
                return CC_FERR_BAD_ENTITY_TYPE;
 
100
        }
 
101
        //and its vertices
 
102
        ccGenericPointCloud* theCloud = theMesh->getAssociatedCloud();
 
103
 
 
104
        unsigned numberOfTriangles = theMesh->size();
 
105
        unsigned numberOfVertexes = theCloud->size();
 
106
 
 
107
        if (numberOfTriangles == 0 || numberOfVertexes == 0)
 
108
        {
 
109
                ccLog::Error("Mesh is empty!");
 
110
                return CC_FERR_BAD_ENTITY_TYPE;
 
111
        }
 
112
 
 
113
        bool hasColors = false;
 
114
        if (theCloud->isA(CC_TYPES::POINT_CLOUD))
 
115
                static_cast<ccPointCloud*>(theCloud)->hasColors();
 
116
 
 
117
        //and its scalar field
 
118
        //ccScalarField* sf = 0;
 
119
        //if (theCloud->isA(CC_TYPES::POINT_CLOUD))
 
120
        //      sf = static_cast<ccPointCloud*>(theCloud)->getCurrentDisplayedScalarField();
 
121
 
 
122
        //if (!sf)
 
123
        //      ccLog::Warning("No displayed scalar field! Values will all be 0!\n");
 
124
 
 
125
        //open ASCII file for writing
 
126
        FILE* fp = fopen(qPrintable(filename) , "wt");
 
127
 
 
128
        if (!fp)
 
129
                return CC_FERR_WRITING;
 
130
 
 
131
        //progress dialog
 
132
        QScopedPointer<ccProgressDialog> pDlg(0);
 
133
        const int coloursAdjustment = (hasColors ? 1 : 0);
 
134
        if (parameters.parentWidget)
 
135
        {
 
136
                pDlg.reset(new ccProgressDialog(true, parameters.parentWidget)); //cancel available
 
137
                pDlg->setMethodTitle(QObject::tr("Save MA file"));
 
138
                pDlg->setInfo(QObject::tr("Triangles = %1").arg(numberOfTriangles));
 
139
                pDlg->start();
 
140
        }
 
141
        CCLib::NormalizedProgress nprogress(pDlg.data(), ((2 + coloursAdjustment) * numberOfTriangles + (3 + coloursAdjustment) * numberOfVertexes));
 
142
 
 
143
        //we extract the (short) filename from the whole path
 
144
        QString baseFilename = QFileInfo(filename).fileName();
 
145
 
 
146
        //header
 
147
        if (fprintf(fp,"//Maya ASCII 7.0 scene\n") < 0)
 
148
                {fclose(fp);return CC_FERR_WRITING;}
 
149
        if (fprintf(fp,"//Name: %s\n",qPrintable(baseFilename)) < 0)
 
150
                {fclose(fp);return CC_FERR_WRITING;}
 
151
        if (fprintf(fp,"//Last modified: Sat, Mai 10, 2008 00:00:00 PM\n") < 0)
 
152
                {fclose(fp);return CC_FERR_WRITING;}
 
153
        if (fprintf(fp,"requires maya \"4.0\";\n") < 0)
 
154
                {fclose(fp);return CC_FERR_WRITING;}
 
155
        if (fprintf(fp,"currentUnit -l %s -a degree -t film;\n","centimeter") < 0)
 
156
                {fclose(fp);return CC_FERR_WRITING;}
 
157
 
 
158
        //for multiple meshes handling (does not work yet)
 
159
        unsigned char currentMesh = 0;
 
160
 
 
161
        //transformation node
 
162
        if (fprintf(fp,"createNode transform -n \"Mesh%i\";\n",currentMesh+1) < 0)
 
163
                {fclose(fp);return CC_FERR_WRITING;}
 
164
 
 
165
        //main node
 
166
        if (fprintf(fp,"createNode mesh -n \"MeshShape%i\" -p \"Mesh%i\";\n",currentMesh+1,currentMesh+1) < 0)
 
167
                {fclose(fp);return CC_FERR_WRITING;}
 
168
 
 
169
        if (fprintf(fp,"\tsetAttr -k off \".v\";\n") < 0)
 
170
                {fclose(fp);return CC_FERR_WRITING;}
 
171
 
 
172
        if (fprintf(fp,"\tsetAttr \".uvst[0].uvsn\" -type \"string\" \"map1\";\n") < 0)
 
173
                {fclose(fp);return CC_FERR_WRITING;}
 
174
        if (fprintf(fp,"\tsetAttr \".cuvs\" -type \"string\" \"map1\";\n") < 0)
 
175
                {fclose(fp);return CC_FERR_WRITING;}
 
176
        if (hasColors)
 
177
        {
 
178
                if (fprintf(fp,"\tsetAttr \".dcol\" yes;\n") < 0)
 
179
                        {fclose(fp);return CC_FERR_WRITING;}
 
180
        }
 
181
        if (fprintf(fp,"\tsetAttr \".dcc\" -type \"string\" \"Ambient+Diffuse\";\n") < 0)
 
182
                {fclose(fp);return CC_FERR_WRITING;}
 
183
        if (fprintf(fp,"\tsetAttr \".ccls\" -type \"string\" \"colorSet%i\";\n",currentMesh+1) < 0)
 
184
                {fclose(fp);return CC_FERR_WRITING;}
 
185
        if (fprintf(fp,"\tsetAttr \".clst[0].clsn\" -type \"string\" \"colorSet%i\";\n",currentMesh+1) < 0)
 
186
                {fclose(fp);return CC_FERR_WRITING;}
 
187
        if (hasColors)
 
188
        {
 
189
                if (fprintf(fp,"\tsetAttr \".ndt\" 0;\n") < 0)
 
190
                        {fclose(fp);return CC_FERR_WRITING;}
 
191
                if (fprintf(fp,"\tsetAttr \".tgsp\" 1;\n") < 0)
 
192
                        {fclose(fp);return CC_FERR_WRITING;}
 
193
 
 
194
                //insert a secondary nodes
 
195
                if (fprintf(fp,"createNode mesh -n \"polySurfaceShape%i\" -p \"Mesh%i\";\n",currentMesh+1,currentMesh+1) < 0)
 
196
                        {fclose(fp);return CC_FERR_WRITING;}
 
197
 
 
198
                if (fprintf(fp,"\tsetAttr -k off \".v\";\n") < 0)
 
199
                        {fclose(fp);return CC_FERR_WRITING;}
 
200
                if (fprintf(fp,"\tsetAttr \".io\" yes;\n") < 0)
 
201
                        {fclose(fp);return CC_FERR_WRITING;}
 
202
                if (fprintf(fp,"\tsetAttr \".uvst[0].uvsn\" -type \"string\" \"map1\";\n") < 0)
 
203
                        {fclose(fp);return CC_FERR_WRITING;}
 
204
                if (fprintf(fp,"\tsetAttr \".cuvs\" -type \"string\" \"map1\";\n") < 0)
 
205
                        {fclose(fp);return CC_FERR_WRITING;}
 
206
                if (fprintf(fp,"\tsetAttr \".dcol\" yes;\n") < 0)
 
207
                        {fclose(fp);return CC_FERR_WRITING;}
 
208
                if (fprintf(fp,"\tsetAttr \".dcc\" -type \"string\" \"Ambient+Diffuse\";\n") < 0)
 
209
                        {fclose(fp);return CC_FERR_WRITING;}
 
210
                if (fprintf(fp,"\tsetAttr \".ccls\" -type \"string\" \"colorSet%i\";\n",currentMesh+1) < 0)
 
211
                        {fclose(fp);return CC_FERR_WRITING;}
 
212
                if (fprintf(fp,"\tsetAttr \".clst[0].clsn\" -type \"string\" \"colorSet%i\";\n",currentMesh+1) < 0)
 
213
                        {fclose(fp);return CC_FERR_WRITING;}
 
214
        }
 
215
 
 
216
        //save vertexes
 
217
        if (fprintf(fp,"\tsetAttr -s %u \".vt[0:%u]\"\n",numberOfVertexes,numberOfVertexes-1) < 0)
 
218
        {
 
219
                fclose(fp);
 
220
                return CC_FERR_WRITING;
 
221
        }
 
222
        {
 
223
                for (unsigned i = 0; i < numberOfVertexes; ++i)
 
224
                {
 
225
                        const CCVector3* P = theCloud->getPoint(i);
 
226
                        CCVector3d Pglobal = theCloud->toGlobal3d<PointCoordinateType>(*P);
 
227
                        if (fprintf(fp, (i + 1 == numberOfVertexes ? "\t\t%f %f %f;\n" : "\t\t%f %f %f\n"),
 
228
                                                        Pglobal.x,
 
229
                                                        Pglobal.y,
 
230
                                                        Pglobal.z) < 0)
 
231
                        {
 
232
                                fclose(fp);
 
233
                                return CC_FERR_WRITING;
 
234
                        }
 
235
 
 
236
                        if (pDlg)
 
237
                        {
 
238
                                nprogress.oneStep();
 
239
                        }
 
240
                }
 
241
        }
 
242
 
 
243
        //save "edges"
 
244
        edge** theEdges = new edge*[numberOfVertexes];
 
245
        memset(theEdges,0,sizeof(edge*)*numberOfVertexes);
 
246
        unsigned ind[3], a, b;
 
247
        int lastEdgeIndexPushed = -1;
 
248
 
 
249
        int hard = 0; //Maya edges cab be "hard" or "soft" ...
 
250
        {
 
251
 
 
252
                theMesh->placeIteratorAtBegining();
 
253
                for (unsigned i = 0; i < numberOfTriangles; ++i)
 
254
                {
 
255
                        const CCLib::VerticesIndexes* tsi = theMesh->getNextTriangleVertIndexes(); //DGM: getNextTriangleVertIndexes is faster for mesh groups!
 
256
 
 
257
                        ind[0] = tsi->i1;
 
258
                        ind[1] = tsi->i2;
 
259
                        ind[2] = tsi->i3;
 
260
 
 
261
                        for (unsigned char k=0; k<3; ++k)
 
262
                        {
 
263
                                unsigned char l = (k<2 ? k+1 : 0);
 
264
                                a = (ind[k]<ind[l] ? ind[k] : ind[l]);
 
265
                                b = (a==ind[k] ? ind[l] : ind[k]);
 
266
 
 
267
                                int currentEdgeIndex = -1;
 
268
                                edge* e = theEdges[a];
 
269
                                while (e)
 
270
                                {
 
271
                                        if (e->theOtherPoint == b)
 
272
                                        {
 
273
                                                currentEdgeIndex = e->edgeIndex;
 
274
                                                break;
 
275
                                        }
 
276
                                        e = e->nextEdge;
 
277
                                }
 
278
 
 
279
                                if (currentEdgeIndex < 0) //create a new edge
 
280
                                {
 
281
                                        edge* newEdge = new edge;
 
282
                                        newEdge->nextEdge = NULL;
 
283
                                        newEdge->theOtherPoint = b;
 
284
                                        newEdge->positif = (a == ind[k]);
 
285
                                        //newEdge->edgeIndex = ++lastEdgeIndexPushed; //don't write the edge right now
 
286
                                        newEdge->edgeIndex = 0;
 
287
                                        ++lastEdgeIndexPushed;
 
288
                                        //currentEdgeIndex = lastEdgeIndexPushed;
 
289
 
 
290
                                        //don't forget the node!
 
291
                                        if (theEdges[a])
 
292
                                        {
 
293
                                                e = theEdges[a];
 
294
                                                while (e->nextEdge)
 
295
                                                        e = e->nextEdge;
 
296
                                                e->nextEdge = newEdge;
 
297
                                        }
 
298
                                        else
 
299
                                        {
 
300
                                                theEdges[a] = newEdge;
 
301
                                        }
 
302
 
 
303
                                        /*if (fprintf(fp,"\n \t\t%i %i %i",a,b,hard) < 0)
 
304
                                                return CC_FERR_WRITING;*/
 
305
                                }
 
306
                        }
 
307
 
 
308
                        if (pDlg)
 
309
                        {
 
310
                                nprogress.oneStep();
 
311
                        }
 
312
                }
 
313
        }
 
314
 
 
315
        //now write the edges
 
316
        {
 
317
                unsigned numberOfEdges = static_cast<unsigned>(lastEdgeIndexPushed+1);
 
318
                if (fprintf(fp,"\tsetAttr -s %u \".ed[0:%u]\"",numberOfEdges,numberOfEdges-1) < 0)
 
319
                {
 
320
                        fclose(fp);
 
321
                        ReleaseEdgeList(theEdges, numberOfVertexes);
 
322
                        return CC_FERR_WRITING;
 
323
                }
 
324
 
 
325
                lastEdgeIndexPushed = 0;
 
326
                for (unsigned i=0; i<numberOfVertexes; ++i)
 
327
                {
 
328
                        edge* e = theEdges[i];
 
329
                        while (e)
 
330
                        {
 
331
                                e->edgeIndex = lastEdgeIndexPushed++;
 
332
                                if (fprintf(fp,"\n \t\t%u %u %i",i,e->theOtherPoint,hard) < 0)
 
333
                                {
 
334
                                        fclose(fp);
 
335
                                        ReleaseEdgeList(theEdges, numberOfVertexes);
 
336
                                        return CC_FERR_WRITING;
 
337
                                }
 
338
                                e = e->nextEdge;
 
339
                        }
 
340
 
 
341
                        if (pDlg)
 
342
                        {
 
343
                                nprogress.oneStep();
 
344
                        }
 
345
                }
 
346
        }
 
347
 
 
348
        if (fprintf(fp,";\n") < 0)
 
349
        {
 
350
                fclose(fp);
 
351
                ReleaseEdgeList(theEdges, numberOfVertexes);
 
352
                return CC_FERR_WRITING;
 
353
        }
 
354
 
 
355
        //write faces
 
356
        if (fprintf(fp,"\tsetAttr -s %u \".fc[0:%u]\" -type \"polyFaces\"\n",numberOfTriangles,numberOfTriangles-1) < 0)
 
357
        {
 
358
                fclose(fp);
 
359
                ReleaseEdgeList(theEdges, numberOfVertexes);
 
360
                return CC_FERR_WRITING;
 
361
        }
 
362
 
 
363
        theMesh->placeIteratorAtBegining();
 
364
        {
 
365
                for (unsigned i=0; i<numberOfTriangles; ++i)
 
366
                {
 
367
                        if (fprintf(fp,"\t\tf 3") < 0)
 
368
                        {
 
369
                                fclose(fp);
 
370
                                ReleaseEdgeList(theEdges, numberOfVertexes);
 
371
                                return CC_FERR_WRITING;
 
372
                        }
 
373
 
 
374
                        CCLib::VerticesIndexes* tsi = theMesh->getNextTriangleVertIndexes(); //DGM: getNextTriangleVertIndexes is faster for mesh groups!
 
375
                        ind[0] = tsi->i1;
 
376
                        ind[1] = tsi->i2;
 
377
                        ind[2] = tsi->i3;
 
378
 
 
379
                        for (unsigned char k=0; k<3; ++k)
 
380
                        {
 
381
                                unsigned char l = (k<2 ? k+1 : 0);
 
382
                                a = (ind[k]<ind[l] ? ind[k] : ind[l]);
 
383
                                b = (a==ind[k] ? ind[l] : ind[k]);
 
384
 
 
385
                                edge* e = theEdges[a];
 
386
                                while (e->theOtherPoint != b)
 
387
                                        e = e->nextEdge;
 
388
 
 
389
                                if (fprintf(fp," %i",((e->positif && a==ind[k]) || (!e->positif && a==ind[l]) ? e->edgeIndex : -(e->edgeIndex+1))) < 0)
 
390
                                {
 
391
                                        fclose(fp);
 
392
                                        ReleaseEdgeList(theEdges, numberOfVertexes);
 
393
                                        return CC_FERR_WRITING;
 
394
                                }
 
395
                        }
 
396
 
 
397
                        if (fprintf(fp,(i+1==numberOfTriangles ? ";\n" : "\n")) < 0)
 
398
                        {
 
399
                                fclose(fp);
 
400
                                ReleaseEdgeList(theEdges, numberOfVertexes);
 
401
                                return CC_FERR_WRITING;
 
402
                        }
 
403
 
 
404
                        if (pDlg)
 
405
                        {
 
406
                                nprogress.oneStep();
 
407
                        }
 
408
                }
 
409
        }
 
410
 
 
411
        //free memory
 
412
        {
 
413
                ReleaseEdgeList(theEdges, numberOfVertexes, pDlg ? &nprogress : 0);
 
414
        }
 
415
 
 
416
        //bonus track
 
417
        if (    fprintf(fp,"\tsetAttr \".cd\" -type \"dataPolyComponent\" Index_Data Edge 0 ;\n") < 0
 
418
                ||      fprintf(fp,"\tsetAttr \".ndt\" 0;\n") < 0
 
419
                ||      fprintf(fp,"\tsetAttr \".tgsp\" 1;\n") < 0 )
 
420
        {
 
421
                fclose(fp);
 
422
                return CC_FERR_WRITING;
 
423
        }
 
424
 
 
425
        //vertex colors
 
426
        if (hasColors)
 
427
        {
 
428
                assert(theCloud->isA(CC_TYPES::POINT_CLOUD));
 
429
                ccPointCloud* pc = static_cast<ccPointCloud*>(theCloud);
 
430
 
 
431
                if (fprintf(fp,"createNode polyColorPerVertex -n \"polyColorPerVertex%i\";\n",currentMesh+1) < 0)
 
432
                        {fclose(fp);return CC_FERR_WRITING;}
 
433
 
 
434
                if (fprintf(fp,"\tsetAttr \".uopa\" yes;\n") < 0)
 
435
                        {fclose(fp);return CC_FERR_WRITING;}
 
436
 
 
437
                if (fprintf(fp,"\tsetAttr -s %u \".vclr\";\n",numberOfVertexes) < 0)
 
438
                        {fclose(fp);return CC_FERR_WRITING;}
 
439
 
 
440
                //association of each vertex with the faces it belongs to
 
441
                faceIndexes** theFacesIndexes = new faceIndexes*[numberOfVertexes];
 
442
                memset(theFacesIndexes,0,sizeof(faceIndexes*)*numberOfVertexes);
 
443
                theMesh->placeIteratorAtBegining();
 
444
                {
 
445
                        for (unsigned i=0; i<numberOfTriangles; ++i)
 
446
                        {
 
447
                                CCLib::VerticesIndexes* tsi = theMesh->getNextTriangleVertIndexes(); //DGM: getNextTriangleVertIndexes is faster for mesh groups!
 
448
                                ind[0] = tsi->i1;
 
449
                                ind[1] = tsi->i2;
 
450
                                ind[2] = tsi->i3;
 
451
 
 
452
                                for (unsigned char j=0; j<3; ++j)
 
453
                                {
 
454
                                        if (!theFacesIndexes[ind[j]])
 
455
                                        {
 
456
                                                faceIndexes* f = new faceIndexes;
 
457
                                                f->faceIndex = i;
 
458
                                                f->nextFace = NULL;
 
459
                                                theFacesIndexes[ind[j]] = f;
 
460
                                        }
 
461
                                        else
 
462
                                        {
 
463
                                                faceIndexes* f = theFacesIndexes[ind[j]];
 
464
                                                while (f->nextFace)
 
465
                                                        f = f->nextFace;
 
466
                                                f->nextFace = new faceIndexes;
 
467
                                                f->nextFace->faceIndex = i;
 
468
                                                f->nextFace->nextFace = NULL;
 
469
                                        }
 
470
                                }
 
471
 
 
472
                                if (pDlg)
 
473
                                {
 
474
                                        nprogress.oneStep();
 
475
                                }
 
476
                        }
 
477
                }
 
478
 
 
479
                //for each vertex
 
480
                {
 
481
                        for (unsigned i = 0; i < numberOfVertexes; ++i)
 
482
                        {
 
483
                                const ColorCompType* c = pc->getPointColor(i);
 
484
                                ccColor::Rgbf col(      static_cast<float>(c[0])/ccColor::MAX,
 
485
                                                                        static_cast<float>(c[1])/ccColor::MAX,
 
486
                                                                        static_cast<float>(c[2])/ccColor::MAX);
 
487
 
 
488
                                //on compte le nombre de faces
 
489
                                int nf = 0;
 
490
                                faceIndexes* f = theFacesIndexes[i];
 
491
                                while (f)
 
492
                                {
 
493
                                        ++nf;
 
494
                                        f = f->nextFace;
 
495
                                }
 
496
 
 
497
                                if (nf > 0)
 
498
                                {
 
499
                                        if (fprintf(fp,"\tsetAttr -s %i \".vclr[%u].vfcl\";\n",nf,i) < 0)
 
500
                                        {
 
501
                                                fclose(fp);
 
502
                                                delete[] theFacesIndexes; //DGM: we are missing some faces here, aren't we?
 
503
                                                return CC_FERR_WRITING;
 
504
                                        }
 
505
 
 
506
                                        faceIndexes* f = theFacesIndexes[i];
 
507
                                        while (f)
 
508
                                        {
 
509
                                                if (fprintf(fp,"\tsetAttr \".vclr[%u].vfcl[%i].frgb\" -type \"float3\" %f %f %f;\n",i,f->faceIndex,col.r,col.g,col.b) < 0)
 
510
                                                {
 
511
                                                        fclose(fp);
 
512
                                                        delete[] theFacesIndexes; //DGM: we are missing some faces here, aren't we?
 
513
                                                        return CC_FERR_WRITING;
 
514
                                                }
 
515
 
 
516
                                                faceIndexes* oldf = f;
 
517
                                                f = f->nextFace;
 
518
                                                delete oldf;
 
519
                                        }
 
520
                                        theFacesIndexes[i] = NULL;
 
521
                                }
 
522
 
 
523
                                if (pDlg)
 
524
                                {
 
525
                                        nprogress.oneStep();
 
526
                                }
 
527
                        }
 
528
                }
 
529
                delete[] theFacesIndexes;
 
530
                theFacesIndexes = 0;
 
531
 
 
532
                if (fprintf(fp,"\tsetAttr \".cn\" -type \"string\" \"colorSet%i\";\n",currentMesh+1) < 0)
 
533
                {
 
534
                        fclose(fp);
 
535
                        return CC_FERR_WRITING;
 
536
                }
 
537
        }
 
538
 
 
539
        //Maya connections
 
540
        if (hasColors)
 
541
        {
 
542
                if (    fprintf(fp,"connectAttr \"polyColorPerVertex%i.out\" \"MeshShape%i.i\";\n",currentMesh+1,currentMesh+1) < 0
 
543
                        ||      fprintf(fp,"connectAttr \"polySurfaceShape%i.o\" \"polyColorPerVertex%i.ip\";\n",currentMesh+1,currentMesh+1) < 0 )
 
544
                {
 
545
                        fclose(fp);
 
546
                        return CC_FERR_WRITING;
 
547
                }
 
548
        }
 
549
        
 
550
        if (fprintf(fp,"connectAttr \"MeshShape%i.iog\" \":initialShadingGroup.dsm\" -na;\n",currentMesh+1) < 0)
 
551
        {
 
552
                fclose(fp);
 
553
                return CC_FERR_WRITING;
 
554
        }
 
555
 
 
556
        //end of file
 
557
        if (fprintf(fp,"//End of %s\n",qPrintable(baseFilename)) < 0)
 
558
        {
 
559
                fclose(fp);
 
560
                return CC_FERR_WRITING;
 
561
        }
 
562
 
 
563
        fclose(fp);
 
564
 
 
565
        return CC_FERR_NO_ERROR;
 
566
}