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

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

?? load3ds.cpp

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

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

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


//////////////////////////////////////////////////////////////////////
/////	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() 來遞歸讀取內(nèi)容

	// 家在對象
	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\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
/////	函數(shù)讀取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一区二区三区免费野_久草精品视频
久久精品国产久精国产| caoporn国产精品| 粉嫩av一区二区三区| 在线观看欧美日本| 久久精品视频网| 亚洲综合激情小说| 国产不卡视频在线观看| 91精品国产综合久久福利软件| 欧美精彩视频一区二区三区| 日韩国产欧美视频| 色婷婷激情综合| 中文字幕一区二区三区精华液 | 欧美久久高跟鞋激| 综合激情成人伊人| 成人一级黄色片| 久久综合九色欧美综合狠狠| 日产国产欧美视频一区精品| 欧美亚洲国产bt| 欧美激情一区不卡| 国产精品一区二区免费不卡| 日韩欧美高清dvd碟片| 日韩专区欧美专区| 欧美欧美午夜aⅴ在线观看| 一区二区在线看| 波多野结衣亚洲| 精品88久久久久88久久久 | 亚洲视频免费观看| 国产揄拍国内精品对白| 欧美一级搡bbbb搡bbbb| 天堂va蜜桃一区二区三区漫画版| 色噜噜狠狠成人网p站| 亚洲三级在线免费| 成人动漫视频在线| 国产精品超碰97尤物18| 成人国产精品视频| 中文字幕一区二区三区不卡在线| 成人美女视频在线观看18| 欧美激情中文不卡| 95精品视频在线| 亚洲天天做日日做天天谢日日欢| 91美女片黄在线观看91美女| 亚洲女厕所小便bbb| 91国偷自产一区二区三区观看| 一区二区三区免费| 56国语精品自产拍在线观看| 久久精品国产免费| 欧美经典一区二区| 色综合欧美在线视频区| 亚洲综合成人在线视频| 欧美一区二区三区日韩| 久久成人久久爱| 国产精品午夜在线观看| 色呦呦国产精品| 日韩高清不卡在线| 欧美精品一区男女天堂| 大白屁股一区二区视频| 亚洲精品成人悠悠色影视| 欧美三级日韩三级| 美女www一区二区| 欧美国产乱子伦| 色综合欧美在线| 久久国产精品一区二区| 国产精品污污网站在线观看| 欧美日韩美少妇| 精品无码三级在线观看视频| 亚洲日本韩国一区| 欧美一级理论性理论a| 国产福利91精品一区| 亚洲一区二区三区美女| 久久综合久色欧美综合狠狠| 91视视频在线直接观看在线看网页在线看 | 国产夜色精品一区二区av| 一本色道久久加勒比精品| 日韩精品免费专区| 国产日产欧美一区二区视频| 欧洲精品视频在线观看| 国产成人精品亚洲777人妖| 亚洲伊人伊色伊影伊综合网| 久久婷婷久久一区二区三区| 欧美三级欧美一级| 99麻豆久久久国产精品免费| 美女国产一区二区| 亚洲主播在线播放| 中文字幕五月欧美| 精品国产成人在线影院 | 亚洲美女区一区| 精品国产一区二区三区久久影院| 在线视频综合导航| voyeur盗摄精品| 国内精品久久久久影院一蜜桃| 亚洲丰满少妇videoshd| 亚洲婷婷综合色高清在线| 久久精品人人做| 日韩精品综合一本久道在线视频| 欧美在线制服丝袜| 成人免费视频视频| 免费在线观看不卡| 亚洲另类在线一区| 国产精品久久久久久久午夜片| 在线电影欧美成精品| 91久久精品一区二区| 99久久国产综合精品麻豆| 韩国成人精品a∨在线观看| 午夜精品一区二区三区免费视频 | 国产一区二区三区在线观看精品 | 中文字幕日韩一区二区| 久久久国产午夜精品| 精品剧情在线观看| 日韩欧美亚洲国产另类| 欧美一区二区视频在线观看2022| 欧美日韩精品一区二区三区| 欧美主播一区二区三区| 欧美性一二三区| 欧美日韩视频在线第一区| 91香蕉视频在线| 色美美综合视频| 色哟哟一区二区三区| 在线精品视频一区二区三四| 欧洲精品一区二区| 欧美日韩精品电影| 91精品国产综合久久久久久漫画| 欧美在线观看一二区| 欧美色男人天堂| 911精品产国品一二三产区| 欧美精品丝袜久久久中文字幕| 欧美视频第二页| 欧美日韩在线综合| 欧美高清你懂得| 日韩女同互慰一区二区| 欧美电影免费观看高清完整版在线 | 亚洲图片自拍偷拍| 日韩专区欧美专区| 国产乱码精品1区2区3区| 成人手机电影网| 99国产精品视频免费观看| 91亚洲资源网| 欧美日韩午夜精品| 精品第一国产综合精品aⅴ| 国产视频911| 中文字幕字幕中文在线中不卡视频| 伊人夜夜躁av伊人久久| 石原莉奈在线亚洲三区| 久久99精品久久只有精品| 国产成人亚洲综合a∨婷婷| 91丝袜国产在线播放| 在线播放欧美女士性生活| 欧美精品一区二| 自拍偷拍亚洲激情| 奇米四色…亚洲| 99精品视频在线观看| 欧美人xxxx| 国产精品久久久久一区| 午夜精品久久久久久久99樱桃| 国内成人精品2018免费看| a级精品国产片在线观看| 欧美日韩高清一区二区三区| www一区二区| 亚洲欧美激情一区二区| 麻豆国产91在线播放| 99久久国产免费看| 日韩精品一区二区三区视频播放| 亚洲欧洲国产日韩| 日本不卡视频一二三区| 99re亚洲国产精品| 欧美成人aa大片| 亚洲免费av在线| 另类的小说在线视频另类成人小视频在线 | 免费看欧美女人艹b| gogogo免费视频观看亚洲一| 日韩一区二区视频| 亚洲一区二区三区四区在线免费观看| 国产在线不卡一卡二卡三卡四卡| 欧美日韩中文字幕一区| 国产精品第13页| 国产激情91久久精品导航| 欧美日韩国产一二三| 亚洲日本成人在线观看| 国产成人综合自拍| 日韩免费一区二区| 天天射综合影视| 在线亚洲免费视频| 亚洲精品久久7777| 成年人网站91| 国产日韩成人精品| 国产成人日日夜夜| www一区二区| 国产在线视频精品一区| 日韩一区二区三免费高清| 日精品一区二区三区| 欧美日韩性生活| 亚洲.国产.中文慕字在线| 99久久er热在这里只有精品66| 国产精品人妖ts系列视频| 国产99久久久国产精品潘金| 国产欧美精品国产国产专区| 国产乱码字幕精品高清av | 欧美一区二区在线观看| 免费av成人在线| 日韩欧美国产1| 欧美色图天堂网|