Example #1
0
vector<KeyFrame>
ModelLoaderMD3::loadKeyFrames(const FileName &fileName,
                              const FileName &skinName,
                              TextureFactory &textureFactory) const {
	FILE * stream = fopen(fileName.c_str(), "rb");

	
	VERIFY(stream && !ferror(stream), "MD3 failed to open: "+fileName.str());
	
	Header header = readHeader(stream);
	
	Frame *frames = readFrames(stream, header);
	
	Tag *tags = readTags(stream, header);
	
	Surface *surfaces = readSurfaces(stream, header);
	
	fclose(stream);
	
	vector<KeyFrame> keyFrames = buildKeyFrame(surfaces,
	                             fileName,
	                             skinName,
	                             header,
	                             textureFactory);
	                             
	delete [] frames;
	delete [] tags;
	delete [] surfaces;
	
	return keyFrames;
}
Example #2
0
void md5Animation::load(const char* animationFile)
{
	// Open file
	string fileToOpen = Import::GetResourcesFolder() + "Res/models/" ;
	fileToOpen += animationFile;

	LOGE("[MD5ANIMATION][Load] Loading %s", fileToOpen.c_str());

	FILE* fp = fopen (fileToOpen.c_str(), "rb");
	if (!fp)
    {
		printf("Error: could not open file '%s'!\n", fileToOpen.c_str());
		return ;
    }


	readVersion(fp);				//CHECK_LOADING_STATUS;
	readCommandline(fp);				//CHECK_LOADING_STATUS;
	readNumFrames(fp);				//CHECK_LOADING_STATUS;
	readNumJoints(fp);				//CHECK_LOADING_STATUS;
	readFrameRate(fp);				//CHECK_LOADING_STATUS;
	readNumAnimatedComponents(fp);			//CHECK_LOADING_STATUS;
	readHierarchy(fp);				//CHECK_LOADING_STATUS;
	readBounds(fp);				///	CHECK_LOADING_STATUS;
	readBaseFrame(fp);				//CHECK_LOADING_STATUS;
	readFrames(fp);					//CHECK_LOADING_STATUS;

	fclose(fp);
	loadingErrors = false;
}
Example #3
0
int main( int argc, char* argv[] )
{
  try {
    readFrames( argc, argv );
  }
  catch( pfs::Exception ex ) {
    std::cerr << PROG_NAME << " error: " << ex.getMessage() << std::endl;
    return EXIT_FAILURE;
  }        
  catch( QuietException  ex ) {
    return EXIT_FAILURE;
  }        
  return EXIT_SUCCESS;
}
Example #4
0
	void BVH::read(std::istream& in)
	{
		//int lineIndex = 0;
		std::string line;
		while( in && !in.eof() )
		{
			//lineIndex++;
			std::getline(in,line);
			if ( in.bad() ){
				std::cout << "  Warning! Could not read file properly! BVH part: skeleton"<<std::endl;
			}

			trimString(line);
			if ( line.size() == 0 || line[0] == '#' || isspace(line[0]) || line.empty() ) 
			{
				continue;
			}

			std::string keyWrd;
			std::stringstream stream(line);
			stream >> keyWrd;
			if(!stream.fail())
			{
				if(keyWrd == "HIERARCHY")
				{
//#if defined(_DEBUG) || defined(DEBUG)
//					std::cout<<"HIERARCHY " <<std::endl;
//#endif
				}
				else if(keyWrd == "ROOT")
				{
//#if defined(_DEBUG) || defined(DEBUG)
//					std::cout<<"Root " <<std::endl;
//#endif
					stream >> keyWrd;
					readJoint(in, keyWrd);
				}
				else if(keyWrd == "MOTION")
				{
//#if defined(_DEBUG) || defined(DEBUG)
//					std::cout<<"MOTION " <<std::endl;
//#endif
					stream >> keyWrd;
					readFrames(in);
				}
int main( int argc, char* argv[] )
{
  try {
    readFrames( argc, argv );
  }
  catch( pfs::Exception ex ) {
    std::cerr << PROG_NAME << " error: " << ex.getMessage() << std::endl;
    return EXIT_FAILURE;
  }        
  catch( Magick::Exception &ex ) { //This is comming from ImageMagick
    std::cerr << PROG_NAME << " error: " << ex.what() << std::endl;
    return EXIT_FAILURE;
  }
  catch( QuietException  ex ) {
    return EXIT_FAILURE;
  }        
  return EXIT_SUCCESS;
}
Example #6
0
vector<KeyFrame>
ModelLoaderMD2::loadKeyFrames(const FileName &fileName,
                              const FileName &skinName,
                              TextureFactory &textureFactory) const {
	FILE *stream=0;
	
//	fopen_s(&stream, fileName.c_str(), "rb");
	stream = fopen(fileName.c_str(), "rb");
	
	VERIFY(stream && !ferror(stream), "MD2 failed to open: "+fileName.str());
	
	Header header = readHeader(stream);
	Skin *skins = readSkins(stream, header);
	TexCoord *texCoords = readTexCoords(stream, header);
	Triangle *triangles = readTriangles(stream, header);
	Frame *frames = readFrames(stream, header);
	
	fclose(stream);
	
	Material skin;
	
	if (header.numOfSkins>0) {
		skin.setTexture(textureFactory.load(FileName((const char*)skins[0].name)));
	} else {
		skin.setTexture(textureFactory.load(skinName));
	}
	
	vector<KeyFrame> keyFrames = buildKeyFrames(fileName,
	                             skin,
	                             header,
	                             texCoords,
	                             triangles,
	                             frames);
	                             
	delete [] skins;
	delete [] texCoords;
	delete [] triangles;
	delete [] frames;
	
	return keyFrames;
}
Example #7
0
Int64 BufferedAudioSource::readFrames(float* buffer, UInt32 numChannels, UInt32 numFrames, AudioSourceState& state)
{
	RScopedLock l(&mLock);

	Int64 framesRead = numFrames;
	int framesAvailable = mBuffer.size() / getNumChannels() - state.mCurrentFrame;

	// For disk-streaming sources we calculate available frames using the whole buffer
    if(!isLoadedInMemory()) {
        framesAvailable = mBuffer.size() / getNumChannels();
	}

	Int64 loopEndFrame = convertSecondsToSamples(state.mLoopEnd);
	Int64 totalFrames = convertSecondsToSamples(getLength());
	bool needToLoop = state.mLooping && ((state.mCurrentFrame >= loopEndFrame && loopEndFrame > 0) || (framesAvailable == 0 && mEOF));

	if(framesAvailable > 0 && !needToLoop)
	{

		// Make sure we don't read passed the end loop frame
		if(state.mLooping && loopEndFrame > 0 && loopEndFrame > state.mCurrentFrame)
			framesRead = (std::min)(framesRead, loopEndFrame-state.mCurrentFrame);

		if(framesAvailable < framesRead)
			framesRead = framesAvailable;

		int sourceChannels = getNumChannels();
        int frameOffset = state.mCurrentFrame;

        // For disk-streaming sources we always start at the beginning of the buffer
        if(!isLoadedInMemory())
            frameOffset = 0;

		for(UInt32 j = 0; j < numChannels; ++j)
		{
			float *in = NULL;
			if(sourceChannels == 1)
				in = mBuffer.getData(0, frameOffset);
			else
				in = mBuffer.getData(j, frameOffset);

			for(UInt32 i = 0; i < framesRead; ++i)
			{
				*(buffer++) = *in;
				in += sourceChannels;
			}
		}

        state.mCurrentFrame += framesRead;
		
        if(!isLoadedInMemory())
		{
			mBuffer.erase(0, framesRead);
			framesAvailable = mBuffer.size() / getNumChannels();
			UInt32 minimumFrames = getSampleRate() * SECONDS_TO_BUFFER / 2;
			if(framesAvailable <= minimumFrames)
			{
				BufferedAudioSourceThread::getInstance()->readMore();
			}
		}
	}
    else
    {
        framesRead = ERR_BUFFERING;

		if(needToLoop)
		{
			setPosition(state.mLoopStart);
			state.mCurrentFrame = convertSecondsToSamples(state.mLoopStart);

			// Now that we rewinded, read new data if preloaded
			if(isLoadedInMemory())
			{
				return readFrames(buffer, numChannels, numFrames, state);
			}
		}

        if(mEOF)
        {
            return 0; // signal that we are done
        }
		else if(!isLoadedInMemory())
		{
			BufferedAudioSourceThread::getInstance()->readMore();
		}
    }
    
	return framesRead;
}
int main(int argc, char **argv)
{
    CFBundleRef myBundle;
    UInt32 numDevs, i;
    UInt32 standard;
    Boolean isEnabled;
    OSErr err;
    DVDeviceID device;
    DVNotificationID notifyID;
    char name[256];
    int file;
    int pos = 1;
    int destruct = 0;
    
    while(argc > pos) {
        if(strcmp(argv[pos], "-w") == 0)
            sWrite = 1;
        else if(strcmp(argv[pos], "-r") == 0)
            sWrite = 0;
        else if(strcmp(argv[pos], "-d") == 0)
            destruct = 1;
        else if(strcmp(argv[pos], "-l") == 0)
            sLoop = 1;
        else if(strcmp(argv[pos], "-sdl") == 0)
            sSDL = 1;
        else if(strcmp(argv[pos], "-DVCPro") == 0)
            sDVCPro = 1;
        else if(strcmp(argv[pos], "-n") == 0)
            sNotifyTest = 1;
        else if(strcmp(argv[pos], "-h") == 0) {
            printf("%s [-w/-r] [-l(oop)] [-d(estructoTest)] [-sdl/-DVCPro] [-n(otify test] [filename]\n", argv[0]);
            exit(0);
        }
        else
            sFile = argv[pos];
        pos++;
    }
    myBundle = findMe();
    printf("sLoop = %d\n", sLoop);
    numDevs = sDVFuncs.fDVCountDevices();
    printf("Number of devices: %ld\n", numDevs);
    if(numDevs == 0) {
        err = sDVFuncs.fDVNewNotification( kEveryDVDeviceRefNum, myNotifyProc,
						0x1234, &notifyID );
        if(err)
            printf("Error %d calling DVNewNotification(, %ld)\n", err, kEveryDVDeviceRefNum);
        err = sDVFuncs.fDVNotifyMeWhen( kEveryDVDeviceRefNum, notifyID,
            kDVDeviceAdded | kDVDeviceRemoved);
        if(err)
            printf("Error %d calling NotifyMeWhen(%ld, %ld)\n", err, kEveryDVDeviceRefNum, notifyID);

        while (numDevs == 0 || sNotifyTest) {
            printf("Waiting for devices: %ld\n", numDevs);
            usleep(1000000);	// 1000 milliseconds
            numDevs = sDVFuncs.fDVCountDevices();
        }
    }
    for(i=1; i<=numDevs; i++) {
        DVDeviceRefNum refNum;
        err = sDVFuncs.fDVGetIndDevice(&device, i);
        if(err)
            printf("Error %d calling DVGetIndDevice(, %ld)\n", err, i);
        err = sDVFuncs.fDVGetDeviceName(device, name);
        if(err)
            printf("Error %d calling DVGetDeviceName(%ld)\n", err, device);
        else
            printf("Device %ld name is %s\n", device, name);
            
        err = sDVFuncs.fDVOpenDriver( device, &refNum );
        if(err) {
            if(err == (OSErr)kIOReturnExclusiveAccess) {
                do {
                    sleep(1);
                	err = sDVFuncs.fDVOpenDriver( device, &refNum );
                }
                while (err == (OSErr)kIOReturnExclusiveAccess);
            }
            printf("Error %d calling DVOpenDriver(%ld)\n", err, device);
        }
        err = sDVFuncs.fDVGetDeviceStandard(refNum, &standard);
        if(err)
            printf("Error %d calling DVGetDeviceStandard(%ld)\n", err, device);
        else if(standard == kNTSCStandard)
            printf("Device %ld video standard is NTSC\n", device);
        else if(standard == kPALStandard)
            printf("Device %ld video standard is PAL\n", device);
        else
            printf("Device %ld, unknown video standard %ld\n", device, standard);

        err = sDVFuncs.fDVIsEnabled(refNum, &isEnabled);
        if(err)
            printf("Error %d calling DVIsEnabled(%ld)\n", err, device);
        else
            printf("Device %ld isEnabled: %d\n", device, isEnabled);
        
        if(sWrite) {
            if(sSDL) {
                err = sDVFuncs.fDVSetWriteSignalMode(refNum, kAVCSignalModeSDL525_60);
            }
            file = open(sFile, O_RDONLY, 0666);
            printf("opened file, %d\n", file);
            if(destruct)
                destructoWrite(device, refNum, file);
            else
                writeFrames(refNum, file);
        }
        else {
            file = open(sFile, O_CREAT | O_WRONLY | O_TRUNC, 0666);
    // Start camera playing
            
            err = doControlTest(refNum, kAVCPlayOpcode, kAVCPlayForward);
            
            if(destruct)
                destructoRead(refNum);
            else
                readFrames(refNum, file, 300);
        
            //sleep(10);
            err = doControlTest(refNum, kAVCWindOpcode, kAVCWindStop);
            
            err = sDVFuncs.fDVCloseDriver( refNum );
            if(err)
                printf("Error %d calling DVCloseDriver(%ld)\n", err, device);
            while(sLoop) {
                readFrames(refNum, 0, 300);
            }
        }
        err = sDVFuncs.fDVCloseDriver(refNum );

    }
    
    sleep(10);
    // Unload the bundle's executable code.
    // Don't, because there's no way to stop it!
    //CFBundleUnloadExecutable( myBundle );
    //CFRelease( myBundle );
    return 0;
}