@@ -180,14 +180,14 @@ bool BlendShapeToChunk(FbxScene* fbxScene, FBXChunk& chunk, const Allocaters* al
180
180
bool SceneToChunk (FbxScene* fbxScene, FBXChunk& chunk, const FBXLoadOptionChunk* opt, const Allocaters* allocs)
181
181
{
182
182
chunk.allocs = allocs;
183
- // FbxGeometryConverter* conv = new FbxGeometryConverter(g_FbxManager);
184
- // conv->Triangulate(fbxScene, true);
183
+ FbxGeometryConverter* conv = new FbxGeometryConverter (g_FbxManager);
184
+ conv->Triangulate (fbxScene, true );
185
185
186
186
TraversalFBXNode (fbxScene->GetRootNode (), chunk, opt, allocs);
187
187
SkeletonToChunk (fbxScene, chunk, allocs);
188
188
BlendShapeToChunk (fbxScene, chunk, allocs);
189
189
190
- // delete conv;
190
+ delete conv;
191
191
192
192
return true ;
193
193
}
@@ -206,10 +206,8 @@ uint TraversalFBXNode(FbxNode* node, FBXChunk& chunk, const FBXLoadOptionChunk*
206
206
switch (type)
207
207
{
208
208
case FbxNodeAttribute::EType::eMesh:
209
- {
210
209
if (MeshToChunk (node->GetNameOnly (), node->GetMesh (), chunk, opt, allocs))
211
210
count++;
212
- }
213
211
break ;
214
212
case FbxNodeAttribute::EType::eSkeleton:
215
213
if (SkeletonToChunk (node, chunk, allocs))
@@ -241,12 +239,13 @@ bool MeshToChunk(const char* name, FbxMesh* fbxMesh, FBXChunk& chunk, const FBXL
241
239
242
240
// controlpoint to vertex
243
241
FbxVector4* fbxVertices = fbxMesh->GetControlPoints ();
244
- mesh.geometry .vertices = (Vector3f *)allocs->alloc (sizeof (Vector3f ) * mesh.geometry .vertexCount );
242
+ mesh.geometry .vertices = (Vector4f *)allocs->alloc (sizeof (Vector4f ) * mesh.geometry .vertexCount );
245
243
for (uint i = 0 ; i < mesh.geometry .vertexCount ; i++)
246
244
{
247
245
mesh.geometry .vertices [i].x = static_cast <float >(fbxVertices[i].mData [0 ]);
248
246
mesh.geometry .vertices [i].y = static_cast <float >(fbxVertices[i].mData [1 ]);
249
247
mesh.geometry .vertices [i].z = static_cast <float >(fbxVertices[i].mData [2 ]);
248
+ mesh.geometry .vertices [i].w = 1 .f ;
250
249
}
251
250
252
251
// non-unifoirm polygon to uniform triangle
@@ -261,95 +260,23 @@ bool MeshToChunk(const char* name, FbxMesh* fbxMesh, FBXChunk& chunk, const FBXL
261
260
polygonSize = fbxMesh->GetPolygonSize (i);
262
261
263
262
FALSE_ERROR_MESSAGE_ARGS_RETURN_CODE (
264
- polygonSize == 3 || polygonSize == 4 ,
265
- L" fail to divide polygon(%d), because avaiable polygonsize is 3 or 4 " ,
263
+ polygonSize == 3 ,
264
+ L" fail to divide polygon(%d), because only avaiable polygonsize is 3.. " ,
266
265
false ,
267
266
polygonSize
268
267
);
269
268
270
- indexCount = (polygonSize - 2 ) * 3 ;
271
- if (indexCount + lastTriangleIndex >= triangles.size ())
272
- triangles.reserve (triangles.size () * 2 );
273
-
274
- if (polygonSize == 4 )
269
+ if (!opt->flipface )
275
270
{
276
- bool zOrderQuad = false ;
277
- int idxs[4 ] = {
278
- fbxMesh->GetPolygonVertex (i, 0 ), fbxMesh->GetPolygonVertex (i, 1 ),
279
- fbxMesh->GetPolygonVertex (i, 2 ), fbxMesh->GetPolygonVertex (i, 3 )
280
- };
281
- Vector3f
282
- v0 = (mesh.geometry .vertices [idxs[1 ]] - mesh.geometry .vertices [idxs[0 ]]).normalized (),
283
- v1 = (mesh.geometry .vertices [idxs[3 ]] - mesh.geometry .vertices [idxs[2 ]]).normalized ();
284
- if (1 .f - abs (Dot (v0, v1)) > EPSILON)
285
- zOrderQuad = true ;
286
-
287
- v0 = (mesh.geometry .vertices [idxs[2 ]] - mesh.geometry .vertices [idxs[1 ]]).normalized ();
288
- v1 = (mesh.geometry .vertices [idxs[0 ]] - mesh.geometry .vertices [idxs[3 ]]).normalized ();
289
- if (1 .f - abs (Dot (v0, v1)) > EPSILON)
290
- zOrderQuad = true ;
291
-
292
- if (!zOrderQuad)
293
- {
294
- if (!opt->flipface )
295
- {
296
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 0 ));
297
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 1 ));
298
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 2 ));
299
-
300
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 0 ));
301
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 2 ));
302
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 3 ));
303
- }
304
- else
305
- {
306
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 0 ));
307
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 2 ));
308
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 1 ));
309
-
310
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 0 ));
311
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 3 ));
312
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 2 ));
313
- }
314
- }
315
- else
316
- {
317
- if (!opt->flipface )
318
- {
319
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 0 ));
320
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 1 ));
321
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 2 ));
322
-
323
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 1 ));
324
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 3 ));
325
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 2 ));
326
- }
327
- else
328
- {
329
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 0 ));
330
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 2 ));
331
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 1 ));
332
-
333
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 1 ));
334
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 2 ));
335
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 3 ));
336
- }
337
- }
271
+ triangles.push_back (fbxMesh->GetPolygonVertex (i, 0 ));
272
+ triangles.push_back (fbxMesh->GetPolygonVertex (i, 1 ));
273
+ triangles.push_back (fbxMesh->GetPolygonVertex (i, 2 ));
338
274
}
339
275
else
340
276
{
341
- if (!opt->flipface )
342
- {
343
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 0 ));
344
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 1 ));
345
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 2 ));
346
- }
347
- else
348
- {
349
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 0 ));
350
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 2 ));
351
- triangles.push_back (fbxMesh->GetPolygonVertex (i, 1 ));
352
- }
277
+ triangles.push_back (fbxMesh->GetPolygonVertex (i, 0 ));
278
+ triangles.push_back (fbxMesh->GetPolygonVertex (i, 2 ));
279
+ triangles.push_back (fbxMesh->GetPolygonVertex (i, 1 ));
353
280
}
354
281
}
355
282
@@ -559,8 +486,14 @@ bool MeshToChunk(const char* name, FbxMesh* fbxMesh, FBXChunk& chunk, const FBXL
559
486
for (int itemIndex = 0 ; itemIndex < fbxMesh->GetPolygonSize (polyIndex); itemIndex++)
560
487
{
561
488
int controlPointIndex = fbxMesh->GetPolygonVertex (polyIndex, itemIndex);
489
+
562
490
uvs[controlPointIndex].x = static_cast <float >(fbxUV->GetDirectArray ()[controlPointIndex].mData [0 ]);
563
491
uvs[controlPointIndex].y = static_cast <float >(fbxUV->GetDirectArray ()[controlPointIndex].mData [1 ]);
492
+
493
+ if (opt->flipU )
494
+ uvs[controlPointIndex].x = 1 .f - uvs[controlPointIndex].x ;
495
+ if (opt->flipV )
496
+ uvs[controlPointIndex].y = 1 .f - uvs[controlPointIndex].y ;
564
497
}
565
498
}
566
499
}
@@ -574,6 +507,11 @@ bool MeshToChunk(const char* name, FbxMesh* fbxMesh, FBXChunk& chunk, const FBXL
574
507
int uvIndex = fbxUV->GetIndexArray ()[controlPointIndex];
575
508
uvs[controlPointIndex].x = static_cast <float >(fbxUV->GetDirectArray ()[uvIndex].mData [0 ]);
576
509
uvs[controlPointIndex].y = static_cast <float >(fbxUV->GetDirectArray ()[uvIndex].mData [1 ]);
510
+
511
+ if (opt->flipU )
512
+ uvs[controlPointIndex].x = 1 .f - uvs[controlPointIndex].x ;
513
+ if (opt->flipV )
514
+ uvs[controlPointIndex].y = 1 .f - uvs[controlPointIndex].y ;
577
515
}
578
516
}
579
517
}
@@ -593,6 +531,11 @@ bool MeshToChunk(const char* name, FbxMesh* fbxMesh, FBXChunk& chunk, const FBXL
593
531
int textureUVIndex = fbxMesh->GetTextureUVIndex (polyIndex, itemIndex);
594
532
uvs[controlPointIndex].x = static_cast <float >(fbxUV->GetDirectArray ()[textureUVIndex].mData [0 ]);
595
533
uvs[controlPointIndex].y = static_cast <float >(fbxUV->GetDirectArray ()[textureUVIndex].mData [1 ]);
534
+
535
+ if (opt->flipU )
536
+ uvs[controlPointIndex].x = 1 .f - uvs[controlPointIndex].x ;
537
+ if (opt->flipV )
538
+ uvs[controlPointIndex].y = 1 .f - uvs[controlPointIndex].y ;
596
539
}
597
540
}
598
541
}
0 commit comments