示例#1
0
std::string GetExecutablePathWithName()
{
	std::vector<char>executablePath(MAX_PATH);

	// Try to get the executable path with a buffer of MAX_PATH characters.
	DWORD result = ::GetModuleFileName(
		nullptr, &executablePath[0], static_cast<DWORD>(executablePath.size())
		);

	// As long the function returns the buffer size, it is indicating that the buffer
	// was too small. Keep enlarging the buffer by a factor of 2 until it fits.
	while (result == executablePath.size()) {
		executablePath.resize(executablePath.size() * 2);
		result = ::GetModuleFileName(
			nullptr, &executablePath[0], static_cast<DWORD>(executablePath.size())
			);
	}

	// If the function returned 0, something went wrong
	if (result == 0) 
	{
		DEBUGWARNING(("Failed to find path of executable! Current working directory will be tried as path."));
	}

	// We've got the path, construct a standard string from it
	return std::string(executablePath.begin(), executablePath.begin() + result);
}
vector<ModelResource*>* ModelBaseFactory::createAllModelData( 
	const InstanceInstruction* p_instanceData, 
	AglScene* p_scene, 
	vector<InstanceInstruction>* p_outInstanceInstructions)
{
	ModelResourceCollection* models = new ModelResourceCollection();
	// if several models were found, or none, add a root entity
	unsigned int numberOfModels = p_scene->getMeshes().size();
	if (numberOfModels>1 || numberOfModels==0)
	{
		ModelResource* mr = new ModelResource(p_instanceData->filename+"-ROOT");

		//Necessary Oriented bounding box for collision detection - ADDED BY ANTON
		mr->meshHeader.minimumOBB = p_scene->getSceneOBB();
		mr->meshHeader.transform = AglMatrix::identityMatrix();

		models->collection.push_back(mr);
		models->rootIndex=models->collection.size()-1;
		mr->scene = p_scene;
	}
	// check all models
	for (unsigned int i=0; i<numberOfModels; i++)
	{	
		AglMesh* aglMesh = p_scene->getMeshes()[i];
		AglMeshHeader aglMeshHeader = aglMesh->getHeader();	
		// parse mesh name
		string meshName = p_scene->getName(aglMeshHeader.nameID);
		pair<MeshNameScriptParser::Data,MeshNameScriptParser::Token> parsedAction;
		parsedAction = MeshNameScriptParser::parse(meshName);
		// DEBUGWARNING(( ("Creating mesh "+meshName).c_str() ));
		// Actions based on parsed name
		switch (parsedAction.second) 
		{
		case MeshNameScriptParser::INSTANTIATE: // instantiate
			{
				if (p_outInstanceInstructions!=NULL)
				{
					InstanceInstruction inst = {parsedAction.first.instanceSpecFilename,
						aglMeshHeader.transform};

					DEBUGWARNING(((p_instanceData->filename+": Found mesh with instancing instruction. Conversion error?").c_str()));
					// Not possible yet-> p_model->instances.push_back(inst);
					p_outInstanceInstructions->push_back(inst);
				}

				break;
			}

		case MeshNameScriptParser::MESH: // normal mesh
		default:				
			{
				// DEBUGWARNING(( string("Normal mesh").c_str() ));
				SourceData source={p_scene,aglMesh,&aglMeshHeader,
					i,
					parsedAction.first.name};
				//
				createAndAddModel(models, 
					p_instanceData, 
					source, 
					p_outInstanceInstructions);
				break;
			}
		}

	}
	m_modelResourceCache->addResource(p_instanceData->filename,models); // register collection in cache

	return &models->collection;
}