예제 #1
0
void AssimpApp::update()
{
	mAssimpLoader.enableTextures( mEnableTextures );
	mAssimpLoader.enableSkinning( mEnableSkinning );
	mAssimpLoader.enableAnimation( mEnableAnimation );

	double time = fmod( getElapsedSeconds(), mAssimpLoader.getAnimationDuration( 0 ) );
	mAssimpLoader.setTime( time );
	mAssimpLoader.update();

	mFps = getAverageFps();
}
void EpicMonsterApp::setup()
{
    mScreenSyphon.setName("Epic Monster Demo");
    
    mFallDirection = Vec3f(0.0,-1.0,0.0);
    listener.setup(7000);
    
    // Slows down particle pulses
    mTimerSlower = 0.05;
    
    // Number of iterations for particle drawing to texture
    n = Vec3f(128, 128, 0);
    
    // Where texture baking shader starts drawing (obsolete)
    mParTexOffset = Vec3f(-1.0, 1.0, 0.0);
    timer = cinder::Timer(true);
    mStep = true;
    try {
        // Multiple render targets shader updates the positions/velocities
        mParticlesShader = gl::GlslProg( ci::app::loadResource( PASSTHROUGH_VERT ), ci::app::loadResource( PARTICLES_FRAG ));
        // Vertex displacement shader
        mDisplacementShader = gl::GlslProg( ci::app::loadResource( VERTEXDISPLACEMENT_VERT ), ci::app::loadResource( VERTEXDISPLACEMENT_FRAG ));
        
        mBakeShader = gl::GlslProg( ci::app::loadResource( BAKE_VERT ), ci::app::loadResource( BAKE_FRAG ));
    }
    catch( ci::gl::GlslProgCompileExc &exc ) {
        std::cout << "Shader compile error: " << endl;
        std::cout << exc.what();
    }
    catch( const std::exception& ex ) {
        std::cout << "Unable to load shader" << endl;
    }
    
    setupPingPongFbo();
    // THE VBO HAS TO BE DRAWN AFTER FBO!
    setupVBO();
    
    // End of Particle setup
    
    try {
    mAssimpLoader = assimp::AssimpLoader( getAssetPath( "Monsu7b.dae" ) );
        
    }
    catch(const std::exception& ex ) {
        std::cout << "Model loading error: " << endl;
        std::cout << ex.what();
    }
    
    mNormalMap	= gl::Texture( loadImage( loadResource( RES_NORMAL ) ) );
	mAssimpLoader.enableSkinning();
    
	mNodeNames = mAssimpLoader.getNodeNames();
	if ( mNodeNames.empty () )
	{
		mNodeNames.push_back( "NO BONES!" );
		mNoBones = true;
	}
	else
	{
		mNoBones = false;
	}
    
	// query original node orientations from model
	mNodeOrientations.assign( mNodeNames.size(), Quatf() );
	if ( !mNoBones )
	{
		for ( size_t i = 0; i < mNodeOrientations.size(); ++i )
		{
			mNodeOrientations[ i ] = mAssimpLoader.getNodeOrientation( mNodeNames[ i ] );
		}
	}
    
    // query original node orientations from model
	mNodePositions.assign( mNodeNames.size(), Vec3f() );
	if ( !mNoBones )
	{
		for ( size_t i = 0; i < mNodePositions.size(); ++i )
		{
			mNodePositions[ i ] = mAssimpLoader.getNodePosition( mNodeNames[ i ] );
		}
	}
    
	mNodeIndex = 0;
    triangles = mAssimpLoader.totalTriangles();
	mEnableWireframe = false;
    mEnableDebugTexture = false;
    
	mParams = params::InterfaceGl( "Parameters", Vec2i( 200, 300 ) );
    
	setupParams();
    
    CameraPersp cam;
	cam.setPerspective( 60, getWindowAspectRatio(), 0.1f, 1000.0f );
	cam.setEyePoint( Vec3f( 0, 1, 3 ) );
	cam.setCenterOfInterestPoint( Vec3f( 0, 0, 0 ) );
	mMayaCam.setCurrentCam( cam );
}