⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guiobjectview.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 2 页
字号:
	if (index != -1)
	{
		mMeshObjects.mMesh[index].setSequence(seq, time);
	}
	else
	{
		Con::printf("Error: Could not find object %s", name);
	}
}

//-----------------------------------------------------------
void GuiObjectView::Clear()
{ 
	mMeshObjects.Clear(); 
}


bool GuiObjectView::AttachPlayer(RPG::GPlayer* pGPlayer,CSTR pName,int detail)
{
	if(pGPlayer == NULL)
		return false;
	Player* pPlayer = dynamic_cast<Player*>(pGPlayer->GetGameBase());
	if(pPlayer == NULL)
		return false;



	//ShapeBaseData* pDataBlock = dynamic_cast<ShapeBaseData*>(pPlayer->getDataBlock());
	//if(pDataBlock == NULL)
	//	return false;
//new TSShapeInstance(mDataBlock->shape
	//mMeshObjects.mMainObject = pPlayer->getShapeInstance();

	mMeshObjects.m_bAttachShapeInst	= TRUE;


	mMeshObjects.setTSInstance(0, pName, pPlayer->getShapeInstance() , -1, detail);
	//mMeshObjects.load(0, pName, pDataBlock->shape , -1, detail);

	pGPlayer->UpdateToTShape();

	m_pGPlayer = pGPlayer;

	fitToCamera();

	return true;
}


void GuiObjectView::LoadDefaultDSQ(CSTR sTag)
{
	if(m_pGPlayer == NULL)
		return;

	for(U32 n=0; n < GOV_MAX; n++)
	{
		if(m_arSequences[n] == 0 || m_arSequences[n][0] == 0)
			continue;
		CSTR pFileName = avar("models/chars/%s/seq/%s.dsq",
								m_pGPlayer->GetPathTitle(),
								m_arSequences[n]);
		loadDSQ(sTag, pFileName);
	}
}


//-----------------------------------------------------------
GuiObjectView::meshObjects::meshObjects()
{
	mMainObject = NULL;
	mDetail		= 0;
	m_bAttachShapeInst	= FALSE;
	//m_pSkinMan	= NULL;

	for(U32 n=0; n<MESH_NUM; n++)
		mMesh[n].initMeshs();
}

GuiObjectView::meshObjects::~meshObjects()
{
	//通常在退出系统时,才调用此析造函数,故Attach模式下,不需要调用Clear了
	if(!m_bAttachShapeInst)
		Clear();
	//delete m_pSkinMan;
	//if(!m_bAttachShapeInst)
	//{
	//	//for(U32 n=0; n<MESH_NUM; n++)
	//	//	mMesh[n].destroyMeshs();
	//}
}

void GuiObjectView::meshObjects::load(S32 index, const char* name, const char* shape, const char* skin, S32 pNode, S32 detail)
{
//-----------------------------------------------------------
	char fileBuffer[256];
	
	// Load the shape
	dSprintf(fileBuffer, sizeof( fileBuffer ), "%s", shape);

	// Load the shape into the ResourceManager
	Resource<TSShape> hShape = ResourceManager->load(fileBuffer);

	if (!bool(hShape))
	{
		Con::printf("Error: Unable to load: %s", shape);
		return;
	}

	load( index, name,  hShape,    pNode,  detail);

	// Load the skin
	if(dStrcmp(skin,"") != 0)
	{
		dSprintf(fileBuffer, sizeof( fileBuffer ), "%s", skin);
		TextureHandle texture			= TextureHandle(fileBuffer, MeshTexture, false);
		TSMaterialList* materialList	= mMesh[index].mesh->getMaterialList();
		materialList->mMaterials[0]	= texture;
	}
	Con::printf("Loading object %s", shape);
}


void GuiObjectView::meshObjects::load(S32 index, const char* name, Resource<TSShape>& hShape, S32 pNode, S32 detail)
{
	if (!bool(hShape))
		return;

	// Copy the shape to mMesh
	TSShapeInstance* pNewInst = new TSShapeInstance(hShape, true);
	setTSInstance(index, name, pNewInst, pNode, detail);
}


void GuiObjectView::meshObjects::setTSInstance(S32 index, const char* name, TSShapeInstance* pShapeInst, S32 pNode, S32 detail)
{
	AssertFatal(pShapeInst, "ERROR!  Failed to load object model!");

	mMesh[index].mesh = pShapeInst;
	if (pNode == -1)
	{
		// If this is the main object setup the pointer and global detail level
		mMainObject = mMesh[index].mesh;
		mDetail		= detail;
		//m_pSkinMan	= new TSSkinMan(mMainObject);
	}
	else
	{
		// If this is a mounted object set the mountPoint node and parentNode
		mMesh[index].node			= mMesh[index].mesh->getShape()->findNode("mountPoint");
		mMesh[index].parentNode = pNode;
	}

	// Set the name
	dSprintf(mMesh[index].name, sizeof( mMesh[index].name ), "%s", name);

	// Set the detail level
	mMesh[index].detail = (detail != -1) ? detail : mDetail;

	// Check the detail level to make sure LOD is valid
	U32 dlNum = mMesh[index].mesh->getNumDetails();
	if(mMesh[index].detail >= dlNum)
	{
		mMesh[index].detail = dlNum - 1;
	}
	mMesh[index].mesh->setCurrentDetail(mMesh[index].detail);

}

//-----------------------------------------------------------
void GuiObjectView::meshObjects::unLoad(S32 index)
{

	if (mMesh[index].mesh)
	{
		dStrcpy(mMesh[index].name, "");
		mMesh[index].mode = 0;
		mMesh[index].node = -1;
		mMesh[index].parentNode = -1;
		mMesh[index].detail = -1;
		mMesh[index].lastRenderTime = 0;
		if (mMesh[index].thread)
		{
			mMesh[index].mesh->destroyThread(mMesh[index].thread);
			mMesh[index].thread = 0;
		}
		
		if(!m_bAttachShapeInst)
		{
			delete mMesh[index].mesh;
		}

		mMesh[index].mesh = NULL;
	}
}

//-----------------------------------------------------------
S32 GuiObjectView::meshObjects::findOpen()
{
	for (S32 i = 0; i<33; i++)
	{
		if (!mMesh[i].mesh)
		{
			return i;
		}
	}

	return -1;
}

//-----------------------------------------------------------
S32 GuiObjectView::meshObjects::findMeshByName(const char* name)
{
	for (S32 i = 0; i<33; i++)
	{
		if (dStrcmp(mMesh[i].name, name) == 0)
		{
			return i;
		}
	}

	return -1;
}

//-----------------------------------------------------------
S32 GuiObjectView::meshObjects::findMeshByNode(const char* node)
{
	S32 pNode = mMainObject->getShape()->findNode(node);
	if (pNode != -1)
	{
		for (S32 i = 0; i<33; i++)
		{
			if (mMesh[i].parentNode == pNode)
			{
				return i;
			}
		}
	}

	return -1;
}

//-----------------------------------------------------------
void GuiObjectView::meshObjects::Clear()
{
	for (S32 i = 0; i < 33; i++)
	{
		unLoad(i);
	}
	
	mMainObject = NULL;
	mDetail = -1;

}

//-----------------------------------------------------------
void GuiObjectView::meshObjects::meshs::initMeshs()
{
	mesh = NULL;
	mode = 0;
	node = -1;
	parentNode = -1;
	detail = 0;
	lastRenderTime = 0;
	thread = 0;
}

void GuiObjectView::meshObjects::meshs::destroyMeshs()
{
	if (mesh)
	{
		delete mesh;
		mesh = NULL;
	}

	if (thread)
	{
		mesh->destroyThread(thread);
		thread = 0;
	}
}

//-----------------------------------------------------------
void GuiObjectView::meshObjects::meshs::loadDSQ(const char* dsq)
{
	Stream * f;
	char fileBuffer[256];

	dSprintf(fileBuffer, sizeof( fileBuffer ), "%s", dsq);

	f = ResourceManager->openStream(fileBuffer);
	if (f)
	{
		if (!mesh->getShape()->importSequences(f) || f->getStatus()!=Stream::Ok)
		{
			Con::errorf(ConsoleLogEntry::General,"Load sequence %s failed",dsq);
			return;
		}

		ResourceManager->closeStream(f);
		Con::printf("Loading dsq %s", dsq);
	}
	else
	{
		Con::printf("Error: Unable to open %s", dsq);
	}
}

//-----------------------------------------------------------
void GuiObjectView::meshObjects::meshs::setSequence(const char* seq, F32 time)
{
	S32 sequence = mesh->getShape()->findSequence(seq);

	if( sequence != -1 )
	{
		F32 pos;

		if (thread)
		{
			//mesh->destroyThread(thread);
			pos = mesh->getPos(thread);
		}
		else
		{
			pos = 0.f;
			thread = mesh->addThread();
		}

		// If you found the sequence add the thread and set sequence and scale
		//thread = mesh->addThread();
		lastRenderTime = Platform::getVirtualMilliseconds();
		//mesh->setPos( thread, pos );
		mesh->setTimeScale( thread, time );
		//mesh->setSequence( thread, sequence, 0 );
		mesh->transitionToSequence( thread, sequence, pos, 0.25f, true );
		mode = 1;
		//Con::printf("Loading sequence %s", seq);
	}
	else
	{
		//Con::printf("Error: Could not locate sequence %s", seq);
	}
}




///////////////////////////////////////////////////////////////////////////
// Script function handling for "setMouse"
ConsoleMethod( GuiObjectView, setMouse, void, 4, 4, "ObjectView.setMouse(canZoom, canSpin)" ) 
{
	argc;
	GuiObjectView* view = static_cast<GuiObjectView*>( object );
	view->setMouseOptions(dAtob(argv[2]), dAtob(argv[3]));
}

// Script function handling for "setObject"
ConsoleMethod( GuiObjectView, setObject, void, 6, 6, "ObjectView.setObject(name, model, skin, lod)" )
{
	argc;
	GuiObjectView* view = static_cast<GuiObjectView*>( object );
	view->loadObject(argv[2], argv[3], argv[4], "", dAtoi(argv[5]));
	view->fitToCamera();
}

// Script function handling for "mountObject"
ConsoleMethod( GuiObjectView, mountObject, void, 7, 7, "ObjectView.mountObject(name, model, skin, node, lod)" ) 
{
	argc;
	GuiObjectView* view = static_cast<GuiObjectView*>( object );
	view->loadObject(argv[2], argv[3], argv[4], argv[5], dAtoi(argv[6]));
}

// Script function handling for "unMountObject"
ConsoleMethod( GuiObjectView, unMountObject, void, 4, 4, "ObjectView.unMountObject(name, node)" ) 
{
	argc;
	GuiObjectView* view = static_cast<GuiObjectView*>( object );
	view->unLoadObject(argv[2], argv[3]);
}

// Script function handling for "setEmpty"
ConsoleMethod( GuiObjectView, setEmpty, void, 2, 2, "ObjectView.setEmpty( )" ) 
{
	argc;
	GuiObjectView* view = static_cast<GuiObjectView*>( object );
	view->Clear();
}

// Script function handling for "setSequence"
ConsoleMethod( GuiObjectView, loadDSQ, void, 4, 4, "ObjectView.loadDSQ(name, dsq)" )
{
	argc;
	GuiObjectView* view = static_cast<GuiObjectView*>( object );
	view->loadDSQ(argv[2], argv[3]);
}

// Script function handling for "setSequence"
ConsoleMethod( GuiObjectView, setSequence, void, 5, 5, "ObjectView.setSequence(name, seq, time)" ) 
{
	argc;
	GuiObjectView* view = static_cast<GuiObjectView*>( object );
	view->setSequence(argv[2], argv[3], dAtof(argv[4]));
}

ConsoleMethod( GuiObjectView, LoadDefaultDSQ, void, 3, 3, "ObjectView.LoadDefaultDSQ(sTag)" ) 
{
	argc;
	GuiObjectView* view = static_cast<GuiObjectView*>( object );
	view->LoadDefaultDSQ(argv[2]);
}

ConsoleMethod( GuiObjectView, AttachPlayer, bool, 5, 5, "ObjectView.AttachPlayer(player,slotName, detail)" ) 
{
	argc;
	GuiObjectView* view = static_cast<GuiObjectView*>( object );
	SimObject*  pAttach = Sim::findObject(argv[2]);
	if(pAttach)
	{
		RPG::GPlayer* pPlayer = dynamic_cast<RPG::GPlayer*>(pAttach);
		return view->AttachPlayer(pPlayer,argv[3], dAtoi(argv[4]) );
		//if(pPlayer)
		//{
		//	if(view->AttachPlayer(dynamic_cast<Player*>(pPlayer->GetGameBase()), argv[3], dAtoi(argv[4])))
		//	{
		//		pPlayer->UpdateToTShape();
		//		return true;
		//	}
		//}
	}
	return false;
}



//static void cAddSkinModifier(SimObject * obj, S32, const char **argv)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -