#include "ImportObjExample.h" #include #include "../OpenGLWindow/GLInstancingRenderer.h" #include"Wavefront/tiny_obj_loader.h" #include "../OpenGLWindow/GLInstanceGraphicsShape.h" #include "btBulletDynamicsCommon.h" #include "../OpenGLWindow/SimpleOpenGL3App.h" #include "Wavefront2GLInstanceGraphicsShape.h" #include "../CommonInterfaces/CommonRigidBodyBase.h" class ImportObjSetup : public CommonRigidBodyBase { public: ImportObjSetup(struct GUIHelperInterface* helper); virtual ~ImportObjSetup(); virtual void initPhysics(); }; ImportObjSetup::ImportObjSetup(struct GUIHelperInterface* helper) :CommonRigidBodyBase(helper) { } ImportObjSetup::~ImportObjSetup() { } void ImportObjSetup::initPhysics() { m_guiHelper->setUpAxis(2); this->createEmptyDynamicsWorld(); m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe); const char* fileName = "samurai_monastry.obj"; char relativeFileName[1024]; const char* prefix[]={"./data/","../data/","../../data/","../../../data/","../../../../data/"}; int prefixIndex=-1; { int numPrefixes = sizeof(prefix)/sizeof(char*); for (int i=0;i shapes; std::string err = tinyobj::LoadObj(shapes, relativeFileName, prefix[prefixIndex]); GLInstanceGraphicsShape* gfxShape = btgCreateGraphicsShapeFromWavefrontObj(shapes); btTransform trans; trans.setIdentity(); trans.setRotation(btQuaternion(btVector3(1,0,0),SIMD_HALF_PI)); btVector3 position = trans.getOrigin(); btQuaternion orn = trans.getRotation(); btVector3 color(0,0,1); int shapeId = m_guiHelper->getRenderInterface()->registerShape(&gfxShape->m_vertices->at(0).xyzw[0], gfxShape->m_numvertices, &gfxShape->m_indices->at(0), gfxShape->m_numIndices); //int id = m_guiHelper->getRenderInterface()->registerGraphicsInstance(shapeId,position,orn,color,scaling); } } ExampleInterface* ImportObjCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option) { return new ImportObjSetup(helper); }