Example #1
0
void LoadMeshFromCollada(const char* relativeFileName, btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes, btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances, btTransform& upAxisTransform, float& unitMeterScaling, int clientUpAxis, struct CommonFileIOInterface* fileIO)
{
	//	GLInstanceGraphicsShape* instance = 0;

	//usually COLLADA files don't have that many visual geometries/shapes
	visualShapes.reserve(MAX_VISUAL_SHAPES);

	float extraScaling = 1;  //0.01;
	btHashMap<btHashString, int> name2ShapeIndex;
	
	char filename[1024];
	if (!fileIO->findResourcePath(relativeFileName, filename, 1024))
	{
		b3Warning("File not found: %s\n", filename);
		return;
	}

	XMLDocument doc;
	//doc.Parse((const char*)filedata, 0, TIXML_ENCODING_UTF8);
	b3AlignedObjectArray<char> xmlString;
	int fileHandle = fileIO->fileOpen(filename,"r");
	if (fileHandle>=0)
	{
		int size = fileIO->getFileSize(fileHandle);
		xmlString.resize(size);
		int actual = fileIO->fileRead(fileHandle, &xmlString[0],size);
		if (actual==size)
		{
		}
	}
	if (xmlString.size()==0)
		return;

	if (doc.Parse(&xmlString[0], xmlString.size()) != XML_SUCCESS)
	//if (doc.LoadFile(filename) != XML_SUCCESS)
		return;

	//We need units to be in meter, so apply a scaling using the asset/units meter
	unitMeterScaling = 1;
	upAxisTransform.setIdentity();

	//Also we can optionally compensate all transforms using the asset/up_axis as well as unit meter scaling
	getUnitMeterScalingAndUpAxisTransform(doc, upAxisTransform, unitMeterScaling, clientUpAxis);

	btMatrix4x4 ident;
	ident.setIdentity();

	readLibraryGeometries(doc, visualShapes, name2ShapeIndex, extraScaling);

	readVisualSceneInstanceGeometries(doc, name2ShapeIndex, visualShapeInstances);
}
Example #2
0
void	readFloatArray(TiXmlElement* source, btAlignedObjectArray<float>& floatArray, int& componentStride) 
{
	int numVals, stride;
	TiXmlElement* array = source->FirstChildElement("float_array");
	if(array) 
	{
		componentStride = 1;
		if (source->FirstChildElement("technique_common")->FirstChildElement("accessor")->QueryIntAttribute("stride", &stride)!= TIXML_NO_ATTRIBUTE)
		{
			componentStride = stride;
		}
		array->QueryIntAttribute("count", &numVals);
		TokenFloatArray adder(floatArray);
		floatArray.reserve(numVals);
		tokenize(array->GetText(),adder);
		assert(floatArray.size() == numVals);
	}
}
Example #3
0
void LoadMeshFromCollada(const char* relativeFileName, btAlignedObjectArray<GLInstanceGraphicsShape>& visualShapes, btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances, btTransform& upAxisTransform, float& unitMeterScaling,int clientUpAxis)
{

	GLInstanceGraphicsShape* instance = 0;
	
	//usually COLLADA files don't have that many visual geometries/shapes
	visualShapes.reserve(32);

	float extraScaling = 1;//0.01;
	btHashMap<btHashString, int> name2ShapeIndex;
	b3FileUtils f;
	char filename[1024];
	if (!f.findFile(relativeFileName,filename,1024))
	{
		printf("File not found: %s\n", filename);
		return;
	}
	 
	TiXmlDocument doc(filename);
	if (!doc.LoadFile())
		return;

	//We need units to be in meter, so apply a scaling using the asset/units meter 
	unitMeterScaling=1;
	upAxisTransform.setIdentity();

	//Also we can optionally compensate all transforms using the asset/up_axis as well as unit meter scaling
	getUnitMeterScalingAndUpAxisTransform(doc, upAxisTransform, unitMeterScaling,clientUpAxis);
	
	btMatrix4x4 ident;
	ident.setIdentity();

	readLibraryGeometries(doc, visualShapes, name2ShapeIndex, extraScaling);
	
	readVisualSceneInstanceGeometries(doc, name2ShapeIndex, visualShapeInstances);

}