Пример #1
0
 /*
  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;
 }
float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray& array, unsigned int index)
{
	if (index >= array.getValuesCount())
		return 0.0f;

	if (array.getType() == COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT)
		return array.getFloatValues()->getData()[index];
	else 
		return array.getDoubleValues()->getData()[index];
}