亚洲欧美第一页_禁久久精品乱码_粉嫩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 MAT_AMBIENT:
			ReadColorChunk(&(pModel->vctMaterials[pModel->numOfMaterials - 1]), &currentChunk,MAT_AMBIENT);
			break;
		case MAT_SPECULAR:
			ReadColorChunk(&(pModel->vctMaterials[pModel->numOfMaterials - 1]), &currentChunk,MAT_SPECULAR);
			break;
		case MAT_EMISSIVE:
			ReadColorChunk(&(pModel->vctMaterials[pModel->numOfMaterials - 1]), &currentChunk,MAT_EMISSIVE);
			break;
		case MATDIFFUSE:						// This holds the R G B color of our object
			ReadColorChunk(&(pModel->vctMaterials[pModel->numOfMaterials - 1]), &currentChunk,MATDIFFUSE);
			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;
		
		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;
	}
}

///////////////////////////////// READ CHUNK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色婷婷一区二区| 国产精品嫩草99a| 国产精品天干天干在观线| 一区二区三区欧美激情| 国产一区日韩二区欧美三区| 欧美日韩一区二区三区免费看| 精品国产欧美一区二区| 五月天网站亚洲| 色综合久久99| 中文字幕一区二区三区精华液 | 日韩一区二区三区精品视频| 国产精品福利在线播放| 紧缚捆绑精品一区二区| 91精品在线观看入口| 亚洲午夜电影在线| 色成人在线视频| 亚洲欧洲av一区二区三区久久| 国产一区二区三区精品欧美日韩一区二区三区 | 久久精品亚洲精品国产欧美kt∨| 亚洲成人高清在线| 欧美综合天天夜夜久久| 中文字幕一区日韩精品欧美| 成人综合在线视频| 中文字幕高清不卡| 国产精品一区二区91| 精品久久久久香蕉网| 日韩av一区二区三区| 欧美精品九九99久久| 亚洲国产一二三| 在线观看成人小视频| 亚洲综合丁香婷婷六月香| 色婷婷香蕉在线一区二区| 亚洲欧美另类小说| 色一情一伦一子一伦一区| 亚洲女人小视频在线观看| 色婷婷一区二区| 亚洲一区免费在线观看| 欧美丝袜自拍制服另类| 亚洲成av人片www| 69av一区二区三区| 蜜桃精品在线观看| 久久人人爽爽爽人久久久| 狠狠色丁香久久婷婷综合_中| 26uuu国产在线精品一区二区| 久久国产精品区| 国产日韩欧美亚洲| 91小视频免费观看| 天堂蜜桃一区二区三区 | 国产精品人妖ts系列视频| 成人不卡免费av| 亚洲精品视频免费看| 欧美亚洲综合久久| 免费在线视频一区| 久久久久国产精品厨房| 91尤物视频在线观看| 天堂成人免费av电影一区| 日韩欧美电影一二三| 成人综合日日夜夜| 亚洲18色成人| 久久久精品日韩欧美| 色八戒一区二区三区| 蜜臀久久久99精品久久久久久| 久久久一区二区三区捆绑**| 色av成人天堂桃色av| 看电影不卡的网站| 亚洲精品国产品国语在线app| 欧美一区二区在线免费观看| 九九精品一区二区| 1区2区3区精品视频| 欧美一区二区三区公司| 9久草视频在线视频精品| 舔着乳尖日韩一区| 国产精品激情偷乱一区二区∴| 3atv一区二区三区| av不卡一区二区三区| 极品瑜伽女神91| 亚洲大片一区二区三区| 国产欧美日韩不卡| 欧美一区二区三区系列电影| 99re成人精品视频| 国产乱子伦视频一区二区三区| 亚洲曰韩产成在线| 国产精品久久久久影院色老大| 777午夜精品免费视频| 波多野结衣亚洲| 美国毛片一区二区三区| 亚洲一区中文日韩| 最新日韩在线视频| 国产日韩欧美高清| 精品国产欧美一区二区| 911精品产国品一二三产区 | 不卡的av在线播放| 经典一区二区三区| 青娱乐精品在线视频| 亚洲精品国产成人久久av盗摄| 国产亚洲欧美日韩在线一区| 日韩精品一区二区三区四区| 欧美日韩三级一区| 欧美在线观看视频在线| a亚洲天堂av| 99热在这里有精品免费| 国产91精品露脸国语对白| 韩国午夜理伦三级不卡影院| 热久久国产精品| 日韩电影在线观看电影| 亚洲第四色夜色| 午夜不卡在线视频| 亚洲国产日韩精品| 亚洲一二三区不卡| 亚洲图片欧美一区| 五月天激情小说综合| 日韩有码一区二区三区| 日韩高清不卡一区二区三区| 日本中文在线一区| 麻豆91免费看| 国产一区二区影院| 成人小视频免费观看| www.性欧美| 97se亚洲国产综合自在线观| 97久久精品人人做人人爽50路| 91免费在线看| 欧美亚洲国产怡红院影院| 欧美三级蜜桃2在线观看| 欧美精品在欧美一区二区少妇| 欧美精品在线一区二区三区| 欧美一区二区视频网站| 欧美不卡一区二区三区四区| 久久综合中文字幕| 国产精品女人毛片| 亚洲精品乱码久久久久| 日韩不卡免费视频| 经典三级在线一区| 99视频精品在线| 在线播放日韩导航| 26uuu成人网一区二区三区| 成人欧美一区二区三区视频网页| 亚洲一区免费在线观看| 麻豆久久久久久| www.成人在线| 欧美日韩激情在线| 久久综合久久鬼色中文字| 欧美激情一区三区| 亚洲高清视频在线| 成人性生交大片| 91官网在线观看| 精品国产一区二区三区忘忧草 | 精品女同一区二区| 欧美韩日一区二区三区| 午夜私人影院久久久久| 国产91精品在线观看| 欧美浪妇xxxx高跟鞋交| 国产亚洲污的网站| 天天综合色天天| 丁香桃色午夜亚洲一区二区三区| 欧美亚洲日本国产| 中国色在线观看另类| 亚洲成人黄色影院| www.亚洲免费av| 精品国内二区三区| 亚洲国产成人91porn| 成人av综合一区| 精品久久久久香蕉网| 一区二区三区免费看视频| 国产真实乱子伦精品视频| 欧美视频完全免费看| 欧美激情一区二区三区全黄| 蜜臀va亚洲va欧美va天堂| 91久久精品一区二区二区| 国产日韩视频一区二区三区| 美腿丝袜亚洲色图| 欧美性生活一区| 亚洲人一二三区| 国产成人av影院| 337p日本欧洲亚洲大胆色噜噜| 亚洲成在人线在线播放| 91在线视频播放地址| 国产亚洲精品超碰| 精品在线观看视频| 日韩精品一区二区三区在线 | 亚洲自拍与偷拍| eeuss鲁片一区二区三区| 久久久久97国产精华液好用吗| 亚洲一卡二卡三卡四卡| 97se亚洲国产综合自在线不卡| 精品第一国产综合精品aⅴ| 三级亚洲高清视频| 欧美老肥妇做.爰bbww视频| 亚洲一二三区在线观看| 欧美在线啊v一区| 一区二区三区欧美激情| 91搞黄在线观看| 亚洲国产综合在线| 欧美日韩mp4| 日韩国产欧美在线播放| 欧美日韩精品一区二区三区| 午夜久久久久久久久久一区二区| 欧美性xxxxxxxx| 五月婷婷色综合| 日韩三级av在线播放| 精品在线播放免费|