亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? load3ds.cpp

?? 3ds 文件讀取程序
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
// Load3DS.cpp: implementation of the CLoad3DS class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Load3DS.h"

// 緩沖區
static int gBuffer[50000] = {0};					
// 用來跳過不需要的數據(此程序不需要)


//////////////////////////////////////////////////////////////////////
/////	This constructor initializes the tChunk data
//////////////////////////////////////////////////////////////////////

CLoad3DS::CLoad3DS()
{
	m_FilePointer = NULL;
}

CLoad3DS::~CLoad3DS()
{
	m_FilePointer = NULL;
}

///////////////////////////////// IMPORT 3DS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
/////	打開3ds文件
/////
///////////////////////////////// IMPORT 3DS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

bool CLoad3DS::Import3DS(CLoad3DS::t3DModel *pModel, char *strFileName)
{
	char strMessage[255] = {0};
	tChunk currentChunk = {0};
	int i=0;

	// 打開文件
	m_FilePointer = fopen(strFileName, "rb");

	// 確保文件打開
	if(!m_FilePointer) 
	{
		sprintf(strMessage, "找不到文件: %s!", strFileName);
		MessageBox(NULL, strMessage, "Error", MB_OK);
		return false;
	}

	// 文件打開后,讀取第一個文件塊

	ReadChunk(&currentChunk);

	// 文件標志判斷
	if (currentChunk.ID != PRIMARY)
	{
		sprintf(strMessage, "Unable to load PRIMARY chuck from file: %s!", strFileName);
		MessageBox(NULL, strMessage, "Error", MB_OK);
		return false;
	}

	// 使用 ProcessNextChunk() 來遞歸讀取內容

	// 家在對象
	ProcessNextChunk(pModel, &currentChunk);

	// 計算法線
	ComputeNormals(pModel);

	// 清除
	CleanUp();

	return true;
}

///////////////////////////////// CLEAN UP \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
/////	清空(關閉文件)
/////
///////////////////////////////// CLEAN UP \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

void CLoad3DS::CleanUp()
{
	if (m_FilePointer) {
		fclose(m_FilePointer);					// Close the current file pointer
		m_FilePointer = NULL;
	}
}


///////////////////////////////// PROCESS NEXT CHUNK\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
/////	函數讀取3ds的各分塊,并且進行深層的遞歸
/////
///////////////////////////////// PROCESS NEXT CHUNK\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

void CLoad3DS::ProcessNextChunk(CLoad3DS::t3DModel *pModel, tChunk *pPreviousChunk)
{
	t3DObject newObject = {0};					// This is used to add to our object list
	tMaterialInfo newTexture = {0};				// This is used to add to our material list

	tChunk currentChunk = {0};					// The current chunk to load
	tChunk tempChunk = {0};						// A temp chunk for holding data		

	// Below we check our chunk ID each time we read a new chunk.  Then, if
	// we want to extract the information from that chunk, we do so.
	// If we don't want a chunk, we just read past it.  

	// Continue to read the sub chunks until we have reached the length.
	// After we read ANYTHING we add the bytes read to the chunk and then check
	// check against the length.
	while (pPreviousChunk->bytesRead < pPreviousChunk->length)
	{
		// Read next Chunk
		ReadChunk(&currentChunk);

		// Check the chunk ID
		switch (currentChunk.ID)
		{
		case VERSION:							// This holds the version of the file
			
			// If the file was made in 3D Studio Max, this chunk has an int that 
			// holds the file version.  Since there might be new additions to the 3DS file
			// format in 4.0, we give a warning to that problem.
			// However, if the file wasn't made by 3D Studio Max, we don't 100% what the
			// version length will be so we'll simply ignore the value

			// Read the file version and add the bytes read to our bytesRead variable
			currentChunk.bytesRead += fread(gBuffer, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer);

			// If the file version is over 3, give a warning that there could be a problem
			if ((currentChunk.length - currentChunk.bytesRead == 4) && (gBuffer[0] > 0x03)) {
				MessageBox(NULL, "This 3DS file is over version 3 so it may load incorrectly", "Warning", MB_OK);
			}
			break;

		case OBJECTINFO:						// This holds the version of the mesh
			{	
			// This chunk holds the version of the mesh.  It is also the head of the MATERIAL
			// and OBJECT chunks.  From here on we start reading in the material and object info.

			// Read the next chunk
			ReadChunk(&tempChunk);

			// Get the version of the mesh
			tempChunk.bytesRead += fread(gBuffer, 1, tempChunk.length - tempChunk.bytesRead, m_FilePointer);

			// Increase the bytesRead by the bytes read from the last chunk
			currentChunk.bytesRead += tempChunk.bytesRead;

			// Go to the next chunk, which is the object has a texture, it should be MATERIAL, then OBJECT.
			ProcessNextChunk(pModel, &currentChunk);
			break;
		}
		case MATERIAL:							// This holds the material information

			// This chunk is the header for the material info chunks

			// Increase the number of materials
			pModel->numOfMaterials++;

			// Add a empty texture structure to our texture list.
			// If you are unfamiliar with STL's "vector" class, all push_back()
			// does is add a new node onto the list.  I used the vector class
			// so I didn't need to write my own link list functions.  
			pModel->vctMaterials.push_back(newTexture);

			// Proceed to the material loading function
			ProcessNextMaterialChunk(pModel, &currentChunk);
			break;

		case OBJECT:							// This holds the name of the object being read
				
			// This chunk is the header for the object info chunks.  It also
			// holds the name of the object.

			// Increase the object count
			pModel->numOfObjects++;
		
			// Add a new tObject node to our list of objects (like a link list)
			pModel->vctObjects.push_back(newObject);
			
			// Initialize the object and all it's data members
			memset(&(pModel->vctObjects[pModel->numOfObjects - 1]), 0, sizeof(t3DObject));

			// Get the name of the object and store it, then add the read bytes to our byte counter.
			currentChunk.bytesRead += GetString(pModel->vctObjects[pModel->numOfObjects - 1].strName);
			
			// Now proceed to read in the rest of the object information
			ProcessNextObjectChunk(pModel, &(pModel->vctObjects[pModel->numOfObjects - 1]), &currentChunk);
			break;

		case EDITKEYFRAME:

			// Because I wanted to make this a SIMPLE tutorial as possible, I did not include
			// the key frame information.  This chunk is the header for all the animation info.
			// In a later tutorial this will be the subject and explained thoroughly.

			//ProcessNextKeyFrameChunk(pModel, currentChunk);

			// Read past this chunk and add the bytes read to the byte counter
			currentChunk.bytesRead += fread(gBuffer, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer);
			break;

		default: 
			
			// If we didn't care about a chunk, then we get here.  We still need
			// to read past the unknown or ignored chunk and add the bytes read to the byte counter.
			currentChunk.bytesRead += fread(gBuffer, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer);
			break;
		}

		// Add the bytes read from the last chunk to the previous chunk passed in.
		pPreviousChunk->bytesRead += currentChunk.bytesRead;
	}
}


///////////////////////////////// PROCESS NEXT OBJECT CHUNK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
/////	處理一個對象塊
/////
///////////////////////////////// PROCESS NEXT OBJECT CHUNK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

void CLoad3DS::ProcessNextObjectChunk(CLoad3DS::t3DModel *pModel, CLoad3DS::t3DObject *pObject, CLoad3DS::tChunk *pPreviousChunk)
{
	// The current chunk to work with
	tChunk currentChunk = {0};
	vector<tMatREF*> vctMatIDS;
	
	// Continue to read these chunks until we read the end of this sub chunk
	while (pPreviousChunk->bytesRead < pPreviousChunk->length)
	{
		// Read the next chunk
		ReadChunk(&currentChunk);

		// Check which chunk we just read
		switch (currentChunk.ID)
		{
		case OBJECT_MESH:					// This lets us know that we are reading a new object
		
			// We found a new object, so let's read in it's info using recursion
			ProcessNextObjectChunk(pModel, pObject, &currentChunk);
			break;

		case OBJECT_VERTICES:				// This is the objects vertices
			ReadVertices(pObject, &currentChunk);
			break;

		case OBJECT_FACES:					// This is the objects face information
			ReadVertexIndices(pObject, &currentChunk);
			break;

		case OBJECT_MATERIAL:				// This holds the material name that the object has
			
			// This chunk holds the name of the material that the object has assigned to it.
			// This could either be just a color or a texture map.  This chunk also holds
			// the faces that the texture is assigned to (In the case that there is multiple
			// textures assigned to one object, or it just has a texture on a part of the object.
			// Since most of my game objects just have the texture around the whole object, and 
			// they aren't multitextured, I just want the material name.

			// We now will read the name of the material assigned to this object
			ReadObjectMaterial(pModel, pObject, &currentChunk,&vctMatIDS);			
			break;

		case OBJECT_UV:						// This holds the UV texture coordinates for the object

			// This chunk holds all of the UV coordinates for our object.  Let's read them in.
			ReadUVCoordinates(pObject, &currentChunk);
			break;

		case 0x4111: //TRI_VERTEXOPTIONS:
			// Read past the ignored or unknown chunks
			currentChunk.bytesRead += fread(gBuffer, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer);
			break;
		default:  
			// Read past the ignored or unknown chunks
			currentChunk.bytesRead += fread(gBuffer, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer);
			break;
		}

		// Add the bytes read from the last chunk to the previous chunk passed in.
		pPreviousChunk->bytesRead += currentChunk.bytesRead;

	}
	if(pPreviousChunk->ID!=OBJECT_MESH) return;
	//必須是OBJECT_MESH
	int size=vctMatIDS.size();
	if(size)
	{
		pObject->numOfMaterials=size;
		pObject->pMaterialREFS=new tMatREF[size];
		for(int i=0;i<size;i++)
		{
			pObject->pMaterialREFS[i]=*(vctMatIDS[i]);
		}
		vctMatIDS.clear();
	}
}

///////////////////////////////// PROCESS NEXT MATERIAL CHUNK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
/////	處理材料信息,名字,貼圖等
/////
///////////////////////////////// PROCESS NEXT MATERIAL CHUNK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

void CLoad3DS::ProcessNextMaterialChunk(CLoad3DS::t3DModel *pModel, CLoad3DS::tChunk *pPreviousChunk)
{
	// The current chunk to work with
	tChunk currentChunk = {0};

	// Continue to read these chunks until we read the end of this sub chunk
	while (pPreviousChunk->bytesRead < pPreviousChunk->length)
	{
		// Read the next chunk
		ReadChunk(&currentChunk);

		// Check which chunk we just read in
		switch (currentChunk.ID)
		{
		case MATNAME:							// This chunk holds the name of the material
			
			// Here we read in the material name
			currentChunk.bytesRead += fread(pModel->vctMaterials[pModel->numOfMaterials - 1].strName, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer);
			break;

		case MATDIFFUSE:						// This holds the R G B color of our object
			ReadColorChunk(&(pModel->vctMaterials[pModel->numOfMaterials - 1]), &currentChunk);
			break;
		
		case MATMAP:							// This is the header for the texture info
			
			// Proceed to read in the material information
			ProcessNextMaterialChunk(pModel, &currentChunk);
			break;

		case MATMAPFILE:						// This stores the file name of the material

			// Here we read in the material's file name
			currentChunk.bytesRead += fread(pModel->vctMaterials[pModel->numOfMaterials - 1].strFile, 1, currentChunk.length - currentChunk.bytesRead, m_FilePointer);
			break;
		

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本大胆欧美人术艺术动态| 懂色av中文字幕一区二区三区 | 久久综合综合久久综合| 国产一区二区福利| 欧美日韩一区二区三区四区| 国产日产欧美一区| 亚洲超碰精品一区二区| 成人三级伦理片| 欧美电影免费观看高清完整版在线观看| 日韩毛片精品高清免费| 美国毛片一区二区| 日本精品裸体写真集在线观看| 国产亚洲污的网站| 免费高清不卡av| 欧美午夜一区二区| 国产精品免费网站在线观看| 精品一区二区免费| 欧美性色aⅴ视频一区日韩精品| 日本一区二区三区电影| 久久国产精品区| 欧美一区二区美女| 亚洲国产精品一区二区www| 99久久99久久精品国产片果冻| 国产午夜久久久久| 美女精品自拍一二三四| 在线电影欧美成精品| 亚洲国产另类av| 欧美亚男人的天堂| 亚洲图片欧美视频| 91成人免费电影| 亚洲综合色视频| 欧美三级视频在线观看| 一区二区三区中文字幕电影| 在线视频你懂得一区二区三区| 亚洲四区在线观看| 色诱视频网站一区| 亚洲午夜精品在线| 欧美绝品在线观看成人午夜影视| 午夜精品久久一牛影视| 欧美日韩不卡一区| 日韩电影免费在线| 欧美一二三四区在线| 另类综合日韩欧美亚洲| 精品国产麻豆免费人成网站| 国产美女娇喘av呻吟久久| 国产亚洲成aⅴ人片在线观看| 成人av电影在线观看| 中文字幕中文字幕一区二区 | 激情文学综合插| 欧美成人一区二区| 国产资源精品在线观看| 国产精品网曝门| 欧美亚洲日本一区| 日韩中文字幕91| 精品少妇一区二区三区日产乱码| 国产精品亚洲人在线观看| 国产精品国产三级国产aⅴ中文| 色综合色综合色综合色综合色综合| 亚洲一区在线视频| 制服视频三区第一页精品| 久久国产福利国产秒拍| 欧美激情综合五月色丁香小说| 色综合久久久久网| 免播放器亚洲一区| 中文字幕亚洲成人| 欧美日韩1234| 国产99久久精品| 亚洲大片免费看| 久久久亚洲精品石原莉奈| 91天堂素人约啪| 精品一区二区三区av| 亚洲女女做受ⅹxx高潮| 精品欧美乱码久久久久久1区2区| 粉嫩嫩av羞羞动漫久久久| 亚洲福利一区二区三区| 国产日韩欧美精品综合| 欧美视频一区在线观看| 国精产品一区一区三区mba桃花| 亚洲欧美aⅴ...| 久久综合久久99| 欧美理论电影在线| 不卡电影一区二区三区| 日本少妇一区二区| 亚洲天天做日日做天天谢日日欢| 日韩欧美在线不卡| 91在线高清观看| 国产精品一区一区| 日本sm残虐另类| 亚洲免费观看高清完整版在线观看熊| 精品区一区二区| 欧美日韩久久一区二区| 99在线精品观看| 国产盗摄一区二区| 经典一区二区三区| 亚洲国产一区二区三区| 亚洲日本一区二区| 国产精品视频免费| 精品成人佐山爱一区二区| 欧美日韩综合在线免费观看| 日本久久电影网| 成人免费毛片片v| 极品销魂美女一区二区三区| 日本成人中文字幕| 亚洲6080在线| 亚洲成人激情自拍| 亚洲精品日韩专区silk| 中文字幕一区二区三区在线不卡 | 亚洲精品大片www| 日本一区二区电影| 26uuu精品一区二区在线观看| 日韩一区二区电影| 911精品国产一区二区在线| 欧美亚洲综合一区| 在线精品国精品国产尤物884a| 91在线视频播放| 91在线观看高清| 欧美在线一区二区三区| 欧美中文一区二区三区| 欧美又粗又大又爽| 欧美性一区二区| 欧美日韩中字一区| 欧美精品丝袜久久久中文字幕| 欧美日韩国产不卡| 91精品在线观看入口| 91精品国产综合久久久蜜臀粉嫩| 欧美群妇大交群中文字幕| 欧美三级电影一区| 欧美一区二区在线免费播放| 精品国产一区二区三区不卡| 国产三级一区二区| 欧美高清在线视频| 亚洲麻豆国产自偷在线| 亚洲综合免费观看高清在线观看| 舔着乳尖日韩一区| 国内成人自拍视频| av午夜一区麻豆| 欧美色综合久久| 欧美zozozo| 欧美国产精品专区| 亚洲自拍偷拍麻豆| 蜜桃av一区二区| 成人性生交大片免费看视频在线 | 亚洲成人一区二区| 人人超碰91尤物精品国产| 韩国在线一区二区| 波多野结衣中文字幕一区| 欧美亚洲国产怡红院影院| 日韩欧美久久久| 亚洲图片另类小说| 日韩综合在线视频| 东方aⅴ免费观看久久av| 91福利在线看| 欧美mv和日韩mv的网站| 国产精品不卡一区二区三区| 日韩二区在线观看| 国产不卡视频一区二区三区| 欧美在线不卡视频| 欧美videos大乳护士334| 亚洲欧洲精品一区二区三区 | 亚洲精品视频一区二区| 久久99蜜桃精品| 99国产麻豆精品| 日韩精品资源二区在线| 国产精品丝袜黑色高跟| 日韩avvvv在线播放| 97精品视频在线观看自产线路二| 日韩一区二区中文字幕| 日韩一区中文字幕| 九九九久久久精品| 色噜噜狠狠成人中文综合| 久久综合色鬼综合色| 亚洲不卡av一区二区三区| 成人午夜激情视频| 日韩午夜av一区| 亚洲电影中文字幕在线观看| 国产 日韩 欧美大片| 欧美一二区视频| 婷婷成人激情在线网| 99视频一区二区| 国产午夜精品久久久久久免费视| 亚洲不卡一区二区三区| 99久久夜色精品国产网站| 亚洲精品一区二区三区在线观看| 亚洲成人激情综合网| 99re亚洲国产精品| 国产日韩三级在线| 精品亚洲免费视频| 制服视频三区第一页精品| 亚洲综合视频在线| 色婷婷综合久久久久中文| 中文字幕+乱码+中文字幕一区| 久久精品久久99精品久久| 欧美日韩国产一级| 亚洲成av人在线观看| 91美女福利视频| 亚洲色图在线播放| 99久久综合99久久综合网站| 国产精品久久久久久一区二区三区| 粉嫩嫩av羞羞动漫久久久| 国产无人区一区二区三区|