//--------------------------------------------------------------
void AnimatedMotionPath::update(bool bEditorMode){
    
	autoScalingXYZ();
    
    assimpModel.update();
	
	if(position.x != last_positionX){
		setPosition(position);
		last_positionX = position.x;
	}
	if(position.y != last_positionY){
		setPosition(position);
		last_positionY = position.y;
	}
	if(position.z != last_positionZ){
		setPosition(position);
		last_positionZ = position.z;
	}
	
	
	if(angleValX != last_angleValX){
		
		setAngle2Rotate(angleValX, axis2RotateX); //, angleValY, axis2RotateY, angleValZ, axis2RotateZ);
		last_angleValX = angleValX;
	}
	if(angleValY != last_angleValY){
		
		setAngle2Rotate(angleValY, axis2RotateY); // , angleValY, axis2RotateY, angleValZ, axis2RotateZ);
		last_angleValY = angleValY;
	}
	if(angleValZ != last_angleValZ){
		
		setAngle2Rotate(angleValZ, axis2RotateZ); //, angleValY, axis2RotateY, angleValZ, axis2RotateZ);
		last_angleValZ = angleValZ;
	}

    /* Update the model position acording to the motion path */
    switch(m_eMotionControl){
        case MOTION_CONTROL_LOOP:
            assimpPath.setLoopStateForAllAnimations(OF_LOOP_NORMAL);
            assimpPath.playAllAnimations();
            break;
        case MOTION_CONTROL_MANUAL:
            assimpPath.setPausedForAllAnimations(true);
            assimpPath.getAnimation(m_AnimationMeshNo).setPosition(m_motionPathCurPos);
            break;
        case MOTION_CONTROL_END_POINT:
            /* 
             check if the current animation position is not >= m_bAnimationEndPos
             and pause the animation until a new AnimationEndPos is given
             
             TODO the end of the model animation, should reloop?
             */
            if (m_motionPathCurPos >= m_bAnimationEndPos)
                 assimpPath.setPausedForAllAnimations(true);
            else
                assimpPath.setPausedForAllAnimations(false);
            break;
    }
    
    assimpPath.update();
    m_motionPathCurPos = assimpPath.getAnimation(m_AnimationMeshNo).getPosition();
    setPosition(AssimpUtils::getAnimatedObjectPosition(assimpPath));

	body.activate();
    
}
//--------------------------------------------------------------
void GeneratedMesh::update(bool bEditorMode){
    
	autoScalingXYZ();

    
    
    
    
	//Udpate mesch if there are changes
	// add 3D mashes to ofxBullet shape
    //for(int i = 0; i < assimpModel.getNumMeshes(); i++)
    //{
    //btVector3 myBtScale;
    //myBtScale.setX(scale.x);
    //myBtScale.setY(scale.y);
    //myBtScale.setZ(scale.z);
    
    //body.getRigidBody()->getCollisionShape()->setLocalScaling(myObjectScale);//->m_collisionShape
    //setImplicitShapeDimensions(myBtScale);
    //addMesh(assimpModel.getMesh(i), scale, true);
    //}
	
	if(position.x != last_positionX){
		setPosition(position);
		last_positionX = position.x;
	}
	if(position.y != last_positionY){
		setPosition(position);
		last_positionY = position.y;
	}
	if(position.z != last_positionZ){
		setPosition(position);
		last_positionZ = position.z;
	}
	
	
	if(angleValX != last_angleValX){
		
		setAngle2Rotate(angleValX, axis2RotateX); //, angleValY, axis2RotateY, angleValZ, axis2RotateZ);
		last_angleValX = angleValX;
	}
	if(angleValY != last_angleValY){
		
		setAngle2Rotate(angleValY, axis2RotateY); // , angleValY, axis2RotateY, angleValZ, axis2RotateZ);
		last_angleValY = angleValY;
	}
	if(angleValZ != last_angleValZ){
		
		setAngle2Rotate(angleValZ, axis2RotateZ); //, angleValY, axis2RotateY, angleValZ, axis2RotateZ);
		last_angleValZ = angleValZ;
	}
    
    if(bAnimate) {
        vector< ofVec3f >& verts = mesh.getVertices();
        vector< ofVec3f >& overts = omesh.getVertices();
        for( int i = 0; i < verts.size(); i++ ) {
            verts[i].y = ofSignedNoise( verts[i].x*0.025, verts[i].y*0.025 + verts[i].z*0.025, ofGetElapsedTimef() * 0.75 ) * 3;
        }
        body.updateMesh( this->world->world, mesh );
    }
    
    //world.update( ofGetLastFrameTime(), 12 );

	body.activate();
    
}