Exemple #1
0
 void testDecode(shared_ptr <GLTFMesh> mesh, BinaryStream &bstream)
 {
     SC3DMCDecoder <unsigned short> decoder;
     IndexedFaceSet <unsigned short> ifs;
     unsigned char* outputData;
     
     decoder.DecodeHeader(ifs, bstream);
     
     unsigned int vertexSize = ifs.GetNCoord() * 3 * sizeof(float);
     unsigned int normalSize = ifs.GetNNormal() * 3 * sizeof(float);
     unsigned int texcoordSize = ifs.GetNFloatAttribute(0) * 2 * sizeof(float);
     unsigned int indicesSize = ifs.GetNCoordIndex() * 3 * sizeof(unsigned short);
     
     outputData = (unsigned char*)malloc(vertexSize + normalSize + texcoordSize + indicesSize);
     
     size_t vertexOffset = indicesSize;
     
     float* uncompressedVertices = (Real * const )(outputData + vertexOffset);
     
     ifs.SetCoordIndex((unsigned short * const ) outputData );
     ifs.SetCoord((Real * const )uncompressedVertices);
     
     if (ifs.GetNNormal() > 0) {
         ifs.SetNormal((Real * const )(outputData + indicesSize + vertexSize));
     }
     if (ifs.GetNFloatAttribute(0)) {
         ifs.SetFloatAttribute(0, (Real * const )(outputData + indicesSize + vertexSize + normalSize));
     }
     
     decoder.DecodePlayload(ifs, bstream);
     
     //---
     
     shared_ptr <GLTFMeshAttribute> meshAttribute = mesh->getMeshAttribute(POSITION, 0);
     
     meshAttribute->computeMinMax();
     const double* min = meshAttribute->getMin();
     const double* max = meshAttribute->getMax();
     
     float* vertices = (float*)meshAttribute->getBufferView()->getBufferDataByApplyingOffset();
     
     printf("coord nb:%d\n",(int)meshAttribute->getCount());
     printf("min: %f %f %f\n", min[0], min[1], min[2]);
     printf("max: %f %f %f\n", max[0], max[1], max[2]);
     float maxQuantError[3];
     maxQuantError[0] = (float)(max[0] - min[0]) / (2^12 - 1);
     maxQuantError[1] = (float)(max[1] - min[1]) / (2^12 - 1);
     maxQuantError[2] = (float)(max[2] - min[2]) / (2^12 - 1);
     if (meshAttribute->getCount() == ifs.GetNCoord()) {
         for (size_t i = 0 ; i < (meshAttribute->getCount() * 3) ; i++ ) {
             float error = vertices[i] - uncompressedVertices[i];
             
             if (error > maxQuantError[i%3]) {
                 printf("%d:input:%f compressed:%f\n",(int) i%3, vertices[i], uncompressedVertices[i]);
                 printf("delta is: %f\n", error);
             } else {
                 //printf("ok\n");
             }
         }
         
     } else {
         printf("Fatal error: vertex count do not match\n");
     }
     
     free(outputData);
 }
Exemple #2
0
 bool SaveIFS(std::string & fileName, const IndexedFaceSet<unsigned short> & ifs)
 {
     std::ofstream fout;
     fout.open(fileName.c_str());
     if (!fout.fail())
     {
         SaveIFSUnsignedShortArray(fout, "* CoordIndex", 0, (const unsigned short * const) ifs.GetCoordIndex(), ifs.GetNCoordIndex(), 3);
         SaveIFSIntArray(fout, "* MatID", 0, (const long * const) ifs.GetIndexBufferID(), ifs.GetNCoordIndex(), 1);
         SaveIFSFloatArray(fout, "* Coord", 0, ifs.GetCoord(), ifs.GetNCoord(), 3);
         SaveIFSFloatArray(fout, "* Normal", 0, ifs.GetNormal(), ifs.GetNNormal(), 3);
         for(unsigned long a = 0; a < ifs.GetNumFloatAttributes(); ++a)
         {
             SaveIFSFloatArray(fout, "* FloatAttribute", a, ifs.GetFloatAttribute(a), ifs.GetNFloatAttribute(a), ifs.GetFloatAttributeDim(a));
         }
         for(unsigned long a = 0; a < ifs.GetNumIntAttributes(); ++a)
         {
             SaveIFSIntArray(fout, "* IntAttribute", a, ifs.GetIntAttribute(a), ifs.GetNIntAttribute(a), ifs.GetIntAttributeDim(a));
         }
         fout.close();
     }
     else
     {
         std::cout << "Not able to create file" << std::endl;
         return false;
     }
     return true;
 }