Beispiel #1
0
//********************************************************************************************************************
//get the record at the specified position - pass in an empty pointer to a record (don't pass a pointer to alloc'd mem).
//********************************************************************************************************************
ierr TimeBuf::GetRec(void** lpRec, unsigned int AtPos)
{
	int Ret;

	//EnterCriticalSection(&ThreadSafe);

	Ret = NLX_OK;

	if (!FileOpen) {
		Amb("Please open a file before attempting to get records.");
		//LeaveCriticalSection(&ThreadSafe);
		return(NLX_FILENOTOPEN);
	}

	if (NumRecsInFile == 0) { 
		Amb("Empty File.  NumRecs = 0.");
		//LeaveCriticalSection(&ThreadSafe);
		return(NLX_RANGE); 
	}

	*lpRec = &(Buf[(AtPos*RecSizeBytes)]);

	//LeaveCriticalSection(&ThreadSafe);
	return(Ret);
}
Beispiel #2
0
bool	FBXLoader::GetMaterial(KFbxGeometry* g, Object* o)
{
	int		m_count;
	KFbxNode*	n;

	m_count = 0;
	n = NULL;
	if (g)
	{
		n = g->GetNode();
		if (n)
			m_count = n->GetMaterialCount();
	}
	if (m_count > 0)
	{
		KFbxPropertyDouble3	double3;
		KFbxPropertyDouble1	double1;
		KFbxColor		col;
		Material*		mat;
		int			i;

		i = 0;
		while (i < m_count)
		{
			KFbxSurfaceMaterial*		_mat;
			const KFbxImplementation*	imp;
			KString				imp_type;

			_mat = n->GetMaterial(i);
			mat = new (std::nothrow) Material;
			if (mat == NULL)
			{
				std::cout << "[FbxLoader]{__GetMaterial} Error: Can not allocate memory \n";
				return (false);
			}
			mat->SetName((char*)_mat->GetName());
			imp = GetImplementation(_mat, ImplementationHLSL);
			imp_type = "HLSL";
			if (!imp)
			{
				imp = GetImplementation(_mat, ImplementationCGFX);
				imp_type = "CGFX";
			}
			if (_mat->GetClassId().Is(KFbxSurfacePhong::ClassId))
			{
				double3 = ((KFbxSurfacePhong*)_mat)->Ambient;
				col.Set(double3.Get()[0], double3.Get()[1], double3.Get()[2]);

				Color Amb(double3);
				mat->SetAmbient(Amb);
				double3 = ((KFbxSurfacePhong*)_mat)->Diffuse;
				col.Set(double3.Get()[0], double3.Get()[1], double3.Get()[2]);
				Color Diff(double3);
				mat->SetDiffuse(Diff);
				double3 = ((KFbxSurfacePhong*)_mat)->Specular;
				col.Set(double3.Get()[0], double3.Get()[1], double3.Get()[2]);
				Color Spec(double3);
				mat->SetSpecular(Spec);
				double3 = ((KFbxSurfacePhong*)_mat)->Emissive;
				col.Set(double3.Get()[0], double3.Get()[1], double3.Get()[2]);
				Color Em(double3);
				mat->SetEmissive(Em);
				double1 = ((KFbxSurfacePhong*)_mat)->TransparencyFactor;
				mat->SetOpacity(1.0 - double1.Get());
				double1 = ((KFbxSurfacePhong*)_mat)->Shininess;
				mat->SetShininess(double1.Get());
				double1 = ((KFbxSurfacePhong*)_mat)->ReflectionFactor;
				mat->SetReflection(1.0 - double1.Get());
				mat->SetShadingModel(1);
			}
			else if (_mat->GetClassId().Is(KFbxSurfaceLambert::ClassId))
			{
				double3 = ((KFbxSurfaceLambert*)_mat)->Ambient;
				col.Set(double3.Get()[0], double3.Get()[1], double3.Get()[2]);
				Color Amb(double3);
				mat->SetAmbient(Amb);
				double3 = ((KFbxSurfaceLambert*)_mat)->Diffuse;
				col.Set(double3.Get()[0], double3.Get()[1], double3.Get()[2]);
				Color Diff(double3);
				mat->SetDiffuse(Diff);
				double3 = ((KFbxSurfaceLambert*)_mat)->Emissive;
				col.Set(double3.Get()[0], double3.Get()[1], double3.Get()[2]);
				Color Em(double3);
				mat->SetEmissive(Em);
				double1 = ((KFbxSurfaceLambert*)_mat)->TransparencyFactor;
				mat->SetOpacity(1.0 - double1.Get());
				mat->SetShadingModel(2);
			}
			o->AddMaterial(mat);
			++i;
		}
	}
	return (true);
}
Beispiel #3
0
//********************************************************************************************************************
//********************************************************************************************************************
TimeBuf* TimeBuf::FromFile(std::fstream& File, CString FileName)
{
	TimeBuf* Obj = NULL;
	int FileType;
	int err;

	//must check to see if we have a .t file, b/c otherwise, nlxFileType will think its a .nts file and thats bad
	char buf[100];
	File.read( buf, 100 );
	CString str = buf;

	File.seekg(0, std::ios_base::beg);
	if( str.Find("%%BEGINHEADER") != -1 ) {
		//now close it, so we can reopen in Objfer
		File.close();

		Obj = new TimeMClustTSBuf;
		if (NULL == Obj) { return(NULL); }

		//now reopen into TimeObj
		err = Obj->OpenFile(FileName);
		if (0 != err) {
			return(NULL);
		}
		return(Obj);
	}

	err = NlxFileType(FileType, FileName);
	if (0 != err) {
		return(NULL);
	}

	switch (FileType) {
		case 1: {
			Obj = new TimeSEBuf;
			break;
		}
		case 2: {
			Obj = new TimeSTBuf;
			break;
		}
		case 3: {
			Obj = new TimeTSBuf;
			break;
		}
		case 4: {
			Obj = new TimeTTBuf;
			break;
		}
		case 5: {
			Obj = new TimeCSCBuf;
			break;
		}
		case 6: {
			Obj = new TimeEventBuf;
			break;
		}
		case 7: {
			Obj = new TimeVideoBuf;
			break;
		}
	}

	if (NULL == Obj) {
		Amb("Error allocating memory for Time Buffer Object, Pointer is equal to Null, cannot proceed");
		return(NULL); 
	}

	//now close it, so we can reopen in Objfer
	File.close();
	//now reopen into TimeObj
	err = Obj->OpenFile(FileName);
	if (0 != err) {
		return(NULL);
	}

	return(Obj);
}
Beispiel #4
0
//********************************************************************************************************************
//********************************************************************************************************************
//
//in the GCC/UNIX version of this function file access is done with low-level POSIX functions and not std::fstream because
//mmap needs the raw file handle which is not available when using std::fstream.
//
ierr TimeBuf::OpenFile(CString FileName)
{
	ierr Ret;
	ULONGLONG FileSizeBytes;
	//CFileException e;
	int FileType;
	uintd BytesRead;
	struct stat statbuf;
		
	//open file
	fd=0;
	fd = open( FileName, O_RDONLY);
	
	if ( fd == 0  ) { // opens file fname_buf.
		Amb("Error opening file; Is the file/path name correct? Win Err:");
		return(0);
	}

	FileOpen = TRUE;
	ThisFileName = FileName;

	//get file size
 	fstat (fd,&statbuf);
	FileSizeBytes = statbuf.st_size; //File.GetLength();    // size of file in bytes

	//must check to see if we have a .t file, b/c otherwise, nlxFileType will think its a .nts file and thats bad
	char buf[100];
	CString str;
	int ret = -1;
	int position = 0;
	ULONGLONG newPosition = 0;

	read(fd,buf,100);
	str = buf;
	if( str.Find("%%BEGINHEADER") != -1 ) {
		//now close it, so we can reopen in Objfer

		ret = str.Find("%%ENDHEADER");
		while(  ret == -1 ) {

			memcpy( buf, &buf[80], sizeof(char)*20 );
			read(fd,&buf[20], 80 );

			str = buf;
			position += 80;
			ret = str.Find("%%ENDHEADER");
		}

		position += ret;
		position += 12;

		newPosition=lseek(fd,position,SEEK_SET);		
		FileSizeBytes -= newPosition;

	} else {
		lseek(fd,0,SEEK_SET);
		Ret = NlxFileType(FileType,FileName);
		if (Ret == NLX_OK) {
			if (FileType != DATAFILETYPE) {
				FileOpen = FALSE;
				close(fd);
				Amb("Invalid FileType found, cannot proceed");
				return(NLX_WRONGFILETYPE);
			}
		} else {
			Amb("Unable to calculate file type: Error Code - ", Ret);
		}

		lseek(fd,0,SEEK_SET);
		FileHeader = HasHeader(fd);
		if (FileHeader) {
			//do the actual read
			lseek(fd,0,SEEK_SET);
			BytesRead = read(fd,HeaderBuf,NlxHeaderLength);
			
			//err check
			if (BytesRead != NlxHeaderLength ) {
				Amb("Insufficient read length.  Likely corrupt header or invalid file.  Bytes read:", BytesRead);
				//LeaveCriticalSection(&ThreadSafe);
				return(NLX_RANGE);
			}

			FileSizeBytes -= NlxHeaderLength;
		} 

	}

	NumRecsInFile = (unsigned int)(FileSizeBytes / ((ULONGLONG)RecSizeBytes));  // count of total records in file

	if (FileSizeBytes % RecSizeBytes) {
		Amb("FileSizeBytes=", FileSizeBytes);
		Amb("Corrupt file - incomplete record encountered: Record size in bytes :", RecSizeBytes);
	}
	
	/*DataFileMap = CreateFileMapping(File.m_hFile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
	if (DataFileMap == NULL) {
			Ret = GetLastError();
			Amb("Error Creating File Mapping, GetLastError = ", Ret);
			FileOpen = FALSE;
			File.Close();
			//LeaveCriticalSection(&ThreadSafe);
			return(Ret);
	}
	
	
	Buf = (char*)( MapViewOfFileEx(DataFileMap, FILE_MAP_READ, 0, 0, 0, NULL) );
	BufValueForUnmappingFile = Buf;
	if (Buf == NULL) {
			Ret = GetLastError();
			Amb("Error Mapping View Of File, GetLastError = ", Ret);
			FileOpen = FALSE;
			CloseHandle(DataFileMap);
			File.close();
			//LeaveCriticalSection(&ThreadSafe);
			return(Ret);
	}
	*/
		
	mmapSize=statbuf.st_size;
	Buf = (char*) mmap (0, mmapSize, PROT_READ, MAP_SHARED, fd, 0);
	BufValueForUnmappingFile = Buf;
	
	if( position != 0 ) {
		Buf += position;
	}

	//adjust for header
	if (FileHeader) {
		Buf += NlxHeaderLength;
	}
	
	return(0);
}