1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
|
#include "GLTF.h"
#include "../GLTFOpenCOLLADA.h"
#include "GLTFAsset.h"
#include "meshConverter.h"
#include "../helpers/mathHelpers.h"
#include "../helpers/geometryHelpers.h"
//--- X3DGC
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#ifdef USE_OPEN3DGC
#include <math.h>
#include "../extensions/o3dgc-compression/GLTF-Open3DGC.h"
#endif
//--- X3DGC
using namespace rapidjson;
#if __cplusplus <= 199711L
using namespace std::tr1;
#endif
using namespace std;
namespace GLTF
{
/*
Convert an OpenCOLLADA's FloatOrDoubleArray type to a GLTFBufferView
Note: the resulting GLTFBufferView is not typed, it's the call responsability to keep track of the type if needed.
*/
shared_ptr <GLTFBufferView> convertFloatOrDoubleArrayToGLTFBufferView(const COLLADAFW::FloatOrDoubleArray &floatOrDoubleArray) {
unsigned char* sourceData = 0;
size_t sourceSize = 0;
switch (floatOrDoubleArray.getType()) {
case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT: {
const COLLADAFW::FloatArray* array = floatOrDoubleArray.getFloatValues();
sourceData = (unsigned char*)array->getData();
sourceSize = array->getCount() * sizeof(float);
}
break;
case COLLADAFW::MeshVertexData::DATA_TYPE_DOUBLE: {
const COLLADAFW::DoubleArray* array = floatOrDoubleArray.getDoubleValues();
sourceData = (unsigned char*)array->getData();
sourceSize = array->getCount() * sizeof(double);
}
break;
default:
case COLLADAFW::MeshVertexData::DATA_TYPE_UNKNOWN:
//FIXME report error
break;
}
unsigned char* copiedData = (unsigned char*)malloc(sourceSize);
memcpy(copiedData, sourceData, sourceSize);
shared_ptr <GLTF::GLTFBufferView> bufferView = createBufferViewWithAllocatedBuffer(copiedData, 0, sourceSize, true);
return bufferView;
}
shared_ptr <GLTFBufferView> convertUnsignedIntArrayToGLTFBufferView(const COLLADAFW::UIntValuesArray &array) {
unsigned char* sourceData = (unsigned char*)array.getData();
size_t sourceSize = array.getCount() * sizeof(unsigned int);
unsigned char* copiedData = (unsigned char*)malloc(sourceSize);
memcpy(copiedData, sourceData, sourceSize);
shared_ptr <GLTF::GLTFBufferView> bufferView = createBufferViewWithAllocatedBuffer(copiedData, 0, sourceSize, true);
return bufferView;
}
//FIXME: these 3 functions up there could use some refactoring
shared_ptr <GLTFBufferView> convertIntArrayToGLTFBufferView(const COLLADAFW::IntValuesArray &array) {
unsigned char* sourceData = (unsigned char*)array.getData();
size_t sourceSize = array.getCount() * sizeof(int);
unsigned char* copiedData = (unsigned char*)malloc(sourceSize);
memcpy(copiedData, sourceData, sourceSize);
shared_ptr <GLTF::GLTFBufferView> bufferView = createBufferViewWithAllocatedBuffer(copiedData, 0, sourceSize, true);
return bufferView;
}
static void __ScaleOpenCOLLADAMeshVertexData(const COLLADAFW::MeshVertexData &vertexData, double distanceScale)
{
if (distanceScale == 1.0)
return;
size_t length;
size_t byteOffset = 0;
size_t inputLength = 0;
size_t setCount = vertexData.getNumInputInfos();
bool unpatchedOpenCOLLADA = (setCount == 0); // reliable heuristic to know if the input have not been set
if (unpatchedOpenCOLLADA)
setCount = 1;
for (size_t indexOfSet = 0; indexOfSet < setCount; indexOfSet++) {
if (!unpatchedOpenCOLLADA) {
inputLength = vertexData.getLength(indexOfSet);
}
else {
// for unpatched version of OpenCOLLADA we need this work-around.
inputLength = vertexData.getLength(0);
}
length = inputLength ? inputLength : vertexData.getValuesCount();
unsigned char *sourceData = 0;
size_t sourceSize = 0;
switch (vertexData.getType()) {
case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT: {
const COLLADAFW::FloatArray* array = vertexData.getFloatValues();
sourceData = (unsigned char*)array->getData() + byteOffset;
sourceSize = length * sizeof(float);
float *floatSourceData = (float*)sourceData;
for (size_t indexFloat = 0; indexFloat < length; ++indexFloat)
{
floatSourceData[indexFloat] *= (float)distanceScale;
}
byteOffset += sourceSize; //Doh! - OpenCOLLADA store all sets contiguously in the same array
}
break;
case COLLADAFW::MeshVertexData::DATA_TYPE_DOUBLE: {
const COLLADAFW::DoubleArray* array = vertexData.getDoubleValues();
sourceData = (unsigned char*)array->getData() + byteOffset;
sourceSize = length * sizeof(double);
double *doubleSourceData = (double*)sourceData;
for (size_t indexFloat = 0; indexFloat < length; ++indexFloat)
{
doubleSourceData[indexFloat] *= distanceScale;
}
byteOffset += sourceSize; //Doh! - OpenCOLLADA store all sets contiguously in the same array
}
break;
default:
case COLLADAFW::MeshVertexData::DATA_TYPE_UNKNOWN:
//FIXME report error
break;
}
}
}
static unsigned int __ConvertOpenCOLLADAMeshVertexDataToGLTFAccessors(const COLLADAFW::MeshVertexData &vertexData,
GLTFMesh* mesh,
GLTF::Semantic semantic,
size_t allowedComponentsPerAttribute,
shared_ptr<GLTFProfile> profile)
{
// The following are OpenCOLLADA fmk issues preventing doing a totally generic processing of sources
//1. "set"(s) other than texCoord don't have valid input infos
//2. not the original id in the source
std::string id;
size_t length, elementsCount;
size_t stride = 0;
size_t componentsPerElement = 0;
size_t byteOffset = 0;
size_t inputLength = 0;
size_t setCount = vertexData.getNumInputInfos();
bool unpatchedOpenCOLLADA = (setCount == 0); // reliable heuristic to know if the input have not been set
if (unpatchedOpenCOLLADA)
setCount = 1;
for (size_t indexOfSet = 0 ; indexOfSet < setCount ; indexOfSet++) {
bool meshAttributeOwnsBuffer = false;
if (!unpatchedOpenCOLLADA) {
id = vertexData.getName(indexOfSet);
componentsPerElement = vertexData.getStride(indexOfSet);
inputLength = vertexData.getLength(indexOfSet);
} else {
// for unpatched version of OpenCOLLADA we need this work-around.
id = GLTF::GLTFUtils::generateIDForType("buffer").c_str();
componentsPerElement = 3; //only normal and positions should reach this code
inputLength = vertexData.getLength(0);
}
length = inputLength ? inputLength : vertexData.getValuesCount();
elementsCount = length / componentsPerElement;
unsigned char *sourceData = 0;
size_t sourceSize = 0;
std::string componentType = "";
switch (vertexData.getType()) {
case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT: {
componentType = "FLOAT";
stride = sizeof(float) * componentsPerElement;
const COLLADAFW::FloatArray* array = vertexData.getFloatValues();
sourceData = (unsigned char*)array->getData() + byteOffset;
sourceSize = length * sizeof(float);
byteOffset += sourceSize; //Doh! - OpenCOLLADA store all sets contiguously in the same array
}
break;
case COLLADAFW::MeshVertexData::DATA_TYPE_DOUBLE: {
/*
componentType = GLTF::DOUBLE;
stride = sizeof(double) * componentsPerElement;
const COLLADAFW::DoubleArray* array = vertexData.getDoubleValues();
sourceData = (unsigned char*)array->getData() + byteOffset;
sourceSize = length * sizeof(double);
byteOffset += sourceSize; //Doh! - OpenCOLLADA store all sets contiguously in the same array
*/
}
break;
default:
case COLLADAFW::MeshVertexData::DATA_TYPE_UNKNOWN:
//FIXME report error
break;
}
//FIXME: this is assuming float
if (allowedComponentsPerAttribute != componentsPerElement) {
sourceSize = elementsCount * sizeof(float) * allowedComponentsPerAttribute;
float *adjustedSource = (float*)malloc(sourceSize);
float *originalSource = (float*)sourceData;
size_t adjustedStride = sizeof(float) * allowedComponentsPerAttribute;
if (allowedComponentsPerAttribute < componentsPerElement) {
for (size_t i = 0 ; i < elementsCount ; i++) {
for (size_t j= 0 ; j < allowedComponentsPerAttribute ; j++) {
adjustedSource[(i*allowedComponentsPerAttribute) + j] = originalSource[(i*componentsPerElement) + j];
}
}
} else {
//FIXME: unlikely but should be taken care of
}
//Free source before replacing it
if (meshAttributeOwnsBuffer) {
free(sourceData);
}
componentsPerElement = allowedComponentsPerAttribute;
meshAttributeOwnsBuffer = true;
sourceData = (unsigned char*)adjustedSource;
stride = adjustedStride;
}
// FIXME: the source could be shared, store / retrieve it here
shared_ptr <GLTFBufferView> cvtBufferView = createBufferViewWithAllocatedBuffer(id, sourceData, 0, sourceSize, meshAttributeOwnsBuffer);
shared_ptr <GLTFAccessor> cvtMeshAttribute(new GLTFAccessor(profile, componentType, GLTFUtils::getTypeForVectorSize(componentsPerElement)));
cvtMeshAttribute->setBufferView(cvtBufferView);
cvtMeshAttribute->setByteStride(stride);
cvtMeshAttribute->setCount(elementsCount);
mesh->setMeshAttribute(semantic, indexOfSet, cvtMeshAttribute);
}
return (unsigned int)setCount;
}
static void __AppendIndices(shared_ptr <GLTF::GLTFPrimitive> &primitive, IndicesVector &primitiveIndicesVector, shared_ptr <GLTF::GLTFAccessor> &indices, GLTF::Semantic semantic, unsigned int indexOfSet)
{
primitive->appendVertexAttribute(shared_ptr <GLTF::JSONVertexAttribute>( new GLTF::JSONVertexAttribute(semantic,indexOfSet)));
primitiveIndicesVector.push_back(indices);
}
static void __HandleIndexList(unsigned int idx,
COLLADAFW::IndexList *indexList,
Semantic semantic,
bool shouldTriangulate,
unsigned int count,
unsigned int vcount,
unsigned int *verticesCountArray,
shared_ptr <GLTF::GLTFPrimitive> cvtPrimitive,
IndicesVector &primitiveIndicesVector,
shared_ptr<GLTFProfile> profile)
{
unsigned int triangulatedIndicesCount = 0;
bool ownData = false;
unsigned int *indices = indexList->getIndices().getData();
if (shouldTriangulate) {
indices = createTrianglesFromPolylist(verticesCountArray, indices, vcount, &triangulatedIndicesCount);
count = triangulatedIndicesCount;
ownData = true;
}
//Why is OpenCOLLADA doing this ? why adding an offset the indices ??
//We need to offset it backward here.
unsigned int initialIndex = (unsigned int)indexList->getInitialIndex();
if (initialIndex != 0) {
unsigned int *bufferDestination = 0;
if (!ownData) {
bufferDestination = (unsigned int*)malloc(sizeof(unsigned int) * count);
ownData = true;
} else {
bufferDestination = indices;
}
for (size_t idx = 0 ; idx < count ; idx++) {
bufferDestination[idx] = indices[idx] - initialIndex;
}
indices = bufferDestination;
}
shared_ptr <GLTF::GLTFBufferView> uvBuffer = createBufferViewWithAllocatedBuffer(indices, 0, count * sizeof(unsigned int), ownData);
shared_ptr <GLTFAccessor> accessor(new GLTFAccessor(profile, "UNSIGNED_SHORT", "SCALAR"));
accessor->setBufferView(uvBuffer);
accessor->setCount(count);
__AppendIndices(cvtPrimitive, primitiveIndicesVector, accessor, semantic, idx);
}
static shared_ptr <GLTF::GLTFPrimitive> __ConvertOpenCOLLADAMeshPrimitive(COLLADAFW::MeshPrimitive *openCOLLADAMeshPrimitive,
IndicesVector &primitiveIndicesVector,
shared_ptr<GLTFProfile> profile)
{
shared_ptr <GLTF::GLTFPrimitive> cvtPrimitive(new GLTF::GLTFPrimitive());
// We want to match OpenGL/ES mode , as WebGL spec points to OpenGL/ES spec...
// "Symbolic constants GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, and GL_TRIANGLES are accepted."
std::string type;
bool shouldTriangulate = false;
switch(openCOLLADAMeshPrimitive->getPrimitiveType()) {
//these 2 requires transforms
case COLLADAFW::MeshPrimitive::POLYLIST:
case COLLADAFW::MeshPrimitive::POLYGONS:
// FIXME: perform conversion, but until not done report error
//these mode are supported by WebGL
shouldTriangulate = true;
//force triangles
type = "TRIANGLES";
break;
case COLLADAFW::MeshPrimitive::LINES:
type = "LINES";
break;
case COLLADAFW::MeshPrimitive::LINE_STRIPS:
type = "LINE_STRIP";
break;
case COLLADAFW::MeshPrimitive::TRIANGLES:
type = "TRIANGLES";
break;
case COLLADAFW::MeshPrimitive::TRIANGLE_FANS:
type = "TRIANGLE_FANS";
break;
case COLLADAFW::MeshPrimitive::TRIANGLE_STRIPS:
type = "TRIANGLE_STRIPS";
break;
case COLLADAFW::MeshPrimitive::POINTS:
type = "POINTS";
break;
default:
break;
}
cvtPrimitive->setMaterialObjectID((unsigned int)openCOLLADAMeshPrimitive->getMaterialId());
cvtPrimitive->setPrimitive(profile->getGLenumForString(type));
//count of indices , it must be the same for all kind of indices
size_t count = openCOLLADAMeshPrimitive->getPositionIndices().getCount();
//vertex
//IndexList &positionIndexList = openCOLLADAMeshPrimitive->getPositionIndices();
unsigned int *indices = openCOLLADAMeshPrimitive->getPositionIndices().getData();
unsigned int *verticesCountArray = 0;
unsigned int vcount = 0; //count of elements in the array containing the count of indices per polygon & polylist.
if (shouldTriangulate) {
unsigned int triangulatedIndicesCount = 0;
//We have to upcast to polygon to retrieve the array of vertexCount
//OpenCOLLADA use polylist as polygon.
COLLADAFW::Polygons *polygon = (COLLADAFW::Polygons*)openCOLLADAMeshPrimitive;
const COLLADAFW::Polygons::VertexCountArray& vertexCountArray = polygon->getGroupedVerticesVertexCountArray();
vcount = (unsigned int)vertexCountArray.getCount();
verticesCountArray = (unsigned int*)malloc(sizeof(unsigned int) * vcount);
for (size_t i = 0; i < vcount; i++) {
verticesCountArray[i] = polygon->getGroupedVerticesVertexCount(i);;
}
indices = createTrianglesFromPolylist(verticesCountArray, indices, vcount, &triangulatedIndicesCount);
count = triangulatedIndicesCount;
}
shared_ptr <GLTFBufferView> positionBuffer = createBufferViewWithAllocatedBuffer(indices, 0, count * sizeof(unsigned int), shouldTriangulate ? true : false);
shared_ptr <GLTF::GLTFAccessor> positionIndices(new GLTF::GLTFAccessor(profile, "UNSIGNED_SHORT", "SCALAR"));
positionIndices->setBufferView(positionBuffer);
positionIndices->setCount(count);
__AppendIndices(cvtPrimitive, primitiveIndicesVector, positionIndices, POSITION, 0);
if (openCOLLADAMeshPrimitive->hasNormalIndices()) {
unsigned int triangulatedIndicesCount = 0;
indices = openCOLLADAMeshPrimitive->getNormalIndices().getData();
if (shouldTriangulate) {
indices = createTrianglesFromPolylist(verticesCountArray, indices, vcount, &triangulatedIndicesCount);
count = triangulatedIndicesCount;
}
shared_ptr <GLTF::GLTFBufferView> normalBuffer = createBufferViewWithAllocatedBuffer(indices, 0, count * sizeof(unsigned int), shouldTriangulate ? true : false);
shared_ptr <GLTF::GLTFAccessor> normalIndices(new GLTF::GLTFAccessor(profile, "UNSIGNED_SHORT", "SCALAR"));
normalIndices->setBufferView(normalBuffer);
normalIndices->setCount(count);
__AppendIndices(cvtPrimitive, primitiveIndicesVector, normalIndices, NORMAL, 0);
}
if (openCOLLADAMeshPrimitive->hasColorIndices()) {
COLLADAFW::IndexListArray& colorListArray = openCOLLADAMeshPrimitive->getColorIndicesArray();
for (size_t i = 0 ; i < colorListArray.getCount() ; i++) {
COLLADAFW::IndexList* indexList = openCOLLADAMeshPrimitive->getColorIndices(i);
__HandleIndexList((unsigned int)i,
indexList,
GLTF::COLOR,
shouldTriangulate,
(unsigned int)count,
vcount,
verticesCountArray,
cvtPrimitive,
primitiveIndicesVector,
profile);
}
}
if (openCOLLADAMeshPrimitive->hasUVCoordIndices()) {
COLLADAFW::IndexListArray& uvListArray = openCOLLADAMeshPrimitive->getUVCoordIndicesArray();
for (size_t i = 0 ; i < uvListArray.getCount() ; i++) {
COLLADAFW::IndexList* indexList = openCOLLADAMeshPrimitive->getUVCoordIndices(i);
__HandleIndexList((unsigned int)i,
indexList,
GLTF::TEXCOORD,
shouldTriangulate,
(unsigned int)count,
vcount,
verticesCountArray,
cvtPrimitive,
primitiveIndicesVector,
profile);
}
}
//TODO:refactor
if (openCOLLADAMeshPrimitive->hasBinormalIndices()) {
unsigned int triangulatedIndicesCount = 0;
indices = openCOLLADAMeshPrimitive->getBinormalIndices().getData();
if (shouldTriangulate) {
indices = createTrianglesFromPolylist(verticesCountArray, indices, vcount, &triangulatedIndicesCount);
count = triangulatedIndicesCount;
}
shared_ptr <GLTF::GLTFBufferView> binormalBuffer = createBufferViewWithAllocatedBuffer(indices, 0, count * sizeof(unsigned int), shouldTriangulate ? true : false);
shared_ptr <GLTF::GLTFAccessor> binormalIndices(new GLTF::GLTFAccessor(profile, "UNSIGNED_SHORT", "SCALAR"));
binormalIndices->setBufferView(binormalBuffer);
binormalIndices->setCount(count);
__AppendIndices(cvtPrimitive, primitiveIndicesVector, binormalIndices, TEXBINORMAL, 0);
}
//TODO:refactor
if (openCOLLADAMeshPrimitive->hasTangentIndices()) {
unsigned int triangulatedIndicesCount = 0;
indices = openCOLLADAMeshPrimitive->getTangentIndices().getData();
if (shouldTriangulate) {
indices = createTrianglesFromPolylist(verticesCountArray, indices, vcount, &triangulatedIndicesCount);
count = triangulatedIndicesCount;
}
shared_ptr <GLTF::GLTFBufferView> tangentBuffer = createBufferViewWithAllocatedBuffer(indices, 0, count * sizeof(unsigned int), shouldTriangulate ? true : false);
shared_ptr <GLTF::GLTFAccessor> tangentIndices(new GLTF::GLTFAccessor(profile, "UNSIGNED_SHORT", "SCALAR"));
tangentIndices->setBufferView(tangentBuffer);
tangentIndices->setCount(count);
__AppendIndices(cvtPrimitive, primitiveIndicesVector, tangentIndices, TEXTANGENT, 0);
}
if (verticesCountArray) {
free(verticesCountArray);
}
return cvtPrimitive;
}
shared_ptr<GLTFMesh> convertOpenCOLLADAMesh(COLLADAFW::Mesh* openCOLLADAMesh, GLTFAsset* asset) {
shared_ptr <GLTF::GLTFMesh> cvtMesh(new GLTF::GLTFMesh());
cvtMesh->setID(openCOLLADAMesh->getOriginalId());
cvtMesh->setName(openCOLLADAMesh->getName());
const COLLADAFW::MeshPrimitiveArray& primitives = openCOLLADAMesh->getMeshPrimitives();
size_t primitiveCount = primitives.getCount();
std::vector< shared_ptr<IndicesVector> > allPrimitiveIndicesVectors;
__ScaleOpenCOLLADAMeshVertexData(openCOLLADAMesh->getPositions(), asset->getDistanceScale());
// get all primitives
for (size_t i = 0 ; i < primitiveCount ; i++) {
const COLLADAFW::MeshPrimitive::PrimitiveType primitiveType = primitives[i]->getPrimitiveType();
if ((primitiveType != COLLADAFW::MeshPrimitive::TRIANGLES) &&
//(primitiveType != COLLADAFW::MeshPrimitive::TRIANGLE_STRIPS) &&
(primitiveType != COLLADAFW::MeshPrimitive::POLYLIST) &&
(primitiveType != COLLADAFW::MeshPrimitive::POLYGONS) &&
//(primitiveType != COLLADAFW::MeshPrimitive::LINE_STRIPS) &&
(primitiveType != COLLADAFW::MeshPrimitive::LINES)) {
static bool printedOnce = false;
if (!printedOnce) {
if (asset->converterConfig()->boolForKeyPath("verboseLogging")) {
asset->log("WARNING: some primitives failed to convert\nCurrently supported are TRIANGLES, POLYLIST, POLYGONS and LINES\nMore: https://github.com/KhronosGroup/glTF/issues/129\nand https://github.com/KhronosGroup/glTF/issues/135\n");
printedOnce = true;
}
}
continue;
}
shared_ptr <GLTF::IndicesVector> primitiveIndicesVector(new GLTF::IndicesVector());
allPrimitiveIndicesVectors.push_back(primitiveIndicesVector);
shared_ptr <GLTF::GLTFPrimitive> primitive = __ConvertOpenCOLLADAMeshPrimitive(primitives[i],*primitiveIndicesVector, asset->profile());
cvtMesh->appendPrimitive(primitive);
VertexAttributeVector vertexAttributes = primitive->getVertexAttributes();
primitiveIndicesVector = allPrimitiveIndicesVectors[allPrimitiveIndicesVectors.size()-1];
// once we got a primitive, keep track of its meshAttributes
std::vector< shared_ptr<GLTF::GLTFAccessor> > allIndices = *primitiveIndicesVector;
for (size_t k = 0 ; k < allIndices.size() ; k++) {
shared_ptr<GLTF::GLTFAccessor> indices = allIndices[k];
GLTF::Semantic semantic = vertexAttributes[k]->getSemantic();
switch (semantic) {
case GLTF::POSITION:
__ConvertOpenCOLLADAMeshVertexDataToGLTFAccessors(openCOLLADAMesh->getPositions(), cvtMesh.get(), GLTF::POSITION, 3, asset->profile());
break;
case GLTF::NORMAL:
__ConvertOpenCOLLADAMeshVertexDataToGLTFAccessors(openCOLLADAMesh->getNormals(), cvtMesh.get(), GLTF::NORMAL, 3, asset->profile());
break;
case GLTF::TEXCOORD:
__ConvertOpenCOLLADAMeshVertexDataToGLTFAccessors(openCOLLADAMesh->getUVCoords(), cvtMesh.get(), GLTF::TEXCOORD, 2, asset->profile());
break;
case GLTF::COLOR:
__ConvertOpenCOLLADAMeshVertexDataToGLTFAccessors(openCOLLADAMesh->getColors(), cvtMesh.get(), GLTF::COLOR, 4, asset->profile());
break;
case GLTF::TEXBINORMAL:
__ConvertOpenCOLLADAMeshVertexDataToGLTFAccessors(openCOLLADAMesh->getBinormals(), cvtMesh.get(), GLTF::TEXBINORMAL, 3, asset->profile());
break;
case GLTF::TEXTANGENT:
__ConvertOpenCOLLADAMeshVertexDataToGLTFAccessors(openCOLLADAMesh->getTangents(), cvtMesh.get(), GLTF::TEXTANGENT, 3, asset->profile());
break;
default:
break;
}
}
}
if (cvtMesh->getPrimitivesCount() > 0) {
//After this point cvtMesh should be referenced anymore and will be deallocated
return createUnifiedIndexesMeshFromMesh(cvtMesh.get(), allPrimitiveIndicesVectors, asset->profile());
}
return nullptr;
}
}
|