예제 #1
0
파일: Game.cpp 프로젝트: alanhaugen/wire3d
//----------------------------------------------------------------------------
Node* Game::LoadAndInitializeScene()
{
	Importer importer("Data/Scene/");
	Node* pScene = importer.LoadSceneFromXml("Scene.xml", mspPhysicsWorld);
	if (!pScene)
	{
		return NULL;
	}

	NodeCamera* pCameraNode = pScene->FindChild<NodeCamera>();
	WIRE_ASSERT(pCameraNode /* No Camera in scene.xml */);
	mspSceneCamera = pCameraNode->Get();
	mSortingCuller.SetCamera(mspSceneCamera);

	// The maximum number of objects that are going to be culled is the
	// number of objects we imported. If we don't set the size of the set now,
	// the culler will dynamically increase it during runtime. This is not
	// a big deal, however it is better to avoid memory allocations during the
	// render loop.
	UInt renderObjectCount = importer.GetStatistics()->RenderObjectCount;
	mSortingCuller.SetMaxQuantity(renderObjectCount);

	// Create and configure probe robot controller
	SpatialPtr spRedHealthBar = mspGUI->FindChild("RedHealthBar");
	WIRE_ASSERT(spRedHealthBar /* No RedHealthBar in GUI.xml */);

	Node* pProbeRobotSpatial = DynamicCast<Node>(pScene->FindChild("Probe Robot"));
	WIRE_ASSERT(pProbeRobotSpatial /* No Probe Robot in Scene.xml */);

	// Detach red energy/health bar and attach it robot probe as a billboard
	NodeBillboard* pBillboard = WIRE_NEW NodeBillboard;
	pProbeRobotSpatial->AttachChild(pBillboard);
	Node* pParent = DynamicCast<Node>(spRedHealthBar->GetParent());
	WIRE_ASSERT(pParent);
	pParent->DetachChild(spRedHealthBar);
	pBillboard->AttachChild(spRedHealthBar);

	Spatial* pPlayerSpatial = pScene->FindChild("Player");
	WIRE_ASSERT(pPlayerSpatial /* No Player in Scene.xml */);

	mspProbeRobot = WIRE_NEW ProbeRobot(mspPhysicsWorld, pPlayerSpatial,
		spRedHealthBar);
	pProbeRobotSpatial->AttachController(mspProbeRobot);

	// Create and configure player controller
	mspPlayer = WIRE_NEW Player(mspSceneCamera, mspPhysicsWorld);
	pPlayerSpatial->AttachController(mspPlayer);

 	Spatial* pPlatform = pScene->FindChild("Platform");
  	WIRE_ASSERT(pPlatform /* Platform object missing in scene */);
  	pPlatform->AttachController(WIRE_NEW Elevator(mspPhysicsWorld));

	pScene->Bind(GetRenderer());
	pScene->WarmUpRendering(GetRenderer());

	return pScene;
}
예제 #2
0
파일: Game.cpp 프로젝트: alanhaugen/wire3d
//----------------------------------------------------------------------------
Node* Game::LoadAndInitializeLoading()
{
	Importer importer("Data/Logo/");
	Node* pRoot = importer.LoadSceneFromXml("logo.xml");
	if (!pRoot)
	{
		return NULL;
	}

	NodeCamera* pCameraNode = pRoot->FindChild<NodeCamera>();
	WIRE_ASSERT(pCameraNode /* No Camera in logo.xml */);
	mspLogoCamera = pCameraNode->Get();

	// center 512x256 logo on screen
	pRoot->Local.SetTranslate(Vector3F((GetWidthF()-512.0F) * 0.5F,
		(GetHeightF() - 256.0F)  * 0.5F, 0));

	pRoot->Bind(GetRenderer());
	return pRoot;
}
예제 #3
0
파일: Game.cpp 프로젝트: alanhaugen/wire3d
//----------------------------------------------------------------------------
Node* Game::LoadAndInitializeGUI()
{
	Importer importer("Data/GUI/");
	Node* pRoot = importer.LoadSceneFromXml("GUI.xml");
	if (!pRoot)
	{
		return NULL;
	}

	NodeCamera* pCameraNode = pRoot->FindChild<NodeCamera>();
	WIRE_ASSERT(pCameraNode /* No Camera in GUI.xml */);
	mspGUICamera = pCameraNode->Get();

	mspCrosshair = pRoot->FindChild("Crosshair");
	WIRE_ASSERT(mspCrosshair /* No Crosshair in GUI.xml */);

	pRoot->Bind(GetRenderer());

	return pRoot;
}
예제 #4
0
int Controller::LoadMesh(Render *re, SceneRenderLayer *srl)
{
	BlenderFileLoader loader(re, srl);

	loader.setRenderMonitor(_pRenderMonitor);

	_Chrono.start();

	NodeGroup *blenderScene = loader.Load();

	if (blenderScene == NULL) {
		if (G.debug & G_DEBUG_FREESTYLE) {
			cout << "Cannot load scene" << endl;
		}
		return 1;
	}

	if (blenderScene->numberOfChildren() < 1) {
		if (G.debug & G_DEBUG_FREESTYLE) {
			cout << "Empty scene" << endl;
		}
		blenderScene->destroy();
		delete blenderScene;
		return 1;
	}

	real duration = _Chrono.stop();
	if (G.debug & G_DEBUG_FREESTYLE) {
		cout << "Scene loaded" << endl;
		printf("Mesh cleaning    : %lf\n", duration);
		printf("View map cache   : %s\n", _EnableViewMapCache ? "enabled" : "disabled");
	}
	_SceneNumFaces += loader.numFacesRead();

#if 0
	if (loader.minEdgeSize() < _minEdgeSize) {
		_minEdgeSize = loader.minEdgeSize();
	}
#endif

#if 0  // DEBUG
	ScenePrettyPrinter spp;
	blenderScene->accept(spp);
#endif

	_RootNode->AddChild(blenderScene);
	_RootNode->UpdateBBox(); // FIXME: Correct that by making a Renderer to compute the bbox

	_pView->setModel(_RootNode);
	//_pView->FitBBox();

	if (_pRenderMonitor->testBreak())
		return 0;

	if (_EnableViewMapCache) {

		NodeCamera *cam;
		if (g_freestyle.proj[3][3] != 0.0)
			cam = new NodeOrthographicCamera;
		else
			cam = new NodePerspectiveCamera;
		double proj[16];
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				proj[i * 4 + j] = g_freestyle.proj[i][j];
			}
		}
		cam->setProjectionMatrix(proj);
		_RootNode->AddChild(cam);
		_RootNode->AddChild(new NodeSceneRenderLayer(*re->scene, *srl));

		sceneHashFunc.reset();
		//blenderScene->accept(sceneHashFunc);
		_RootNode->accept(sceneHashFunc);
		if (G.debug & G_DEBUG_FREESTYLE) {
			cout << "Scene hash       : " << sceneHashFunc.toString() << endl;
		}
		if (hitViewMapCache()) {
			ClearRootNode();
			return 0;
		}
		else {
			delete _ViewMap;
			_ViewMap = NULL;
		}
	}

	_Chrono.start();

	WXEdgeBuilder wx_builder;
	wx_builder.setRenderMonitor(_pRenderMonitor);
	blenderScene->accept(wx_builder);
	_winged_edge = wx_builder.getWingedEdge();

	duration = _Chrono.stop();
	if (G.debug & G_DEBUG_FREESTYLE) {
		printf("WEdge building   : %lf\n", duration);
	}

#if 0
	_pView->setDebug(_DebugNode);

	// delete stuff
	if (0 != ws_builder) {
		delete ws_builder;
		ws_builder = 0;
	}

	soc QFileInfo qfi(iFileName);
	soc string basename((const char*)qfi.fileName().toAscii().data());
	char cleaned[FILE_MAX];
	BLI_strncpy(cleaned, iFileName, FILE_MAX);
	BLI_cleanup_file(NULL, cleaned);
	string basename = string(cleaned);
#endif

	_ListOfModels.push_back("Blender_models");

	_Scene3dBBox = _RootNode->bbox();

	_bboxDiag = (_RootNode->bbox().getMax() - _RootNode->bbox().getMin()).norm();
	if (G.debug & G_DEBUG_FREESTYLE) {
		cout << "Triangles nb     : " << _SceneNumFaces << " imported, " <<
		        _winged_edge->getNumFaces() << " retained" << endl;
		cout << "Bounding Box     : " << _bboxDiag << endl;
	}

	ClearRootNode();

	_SceneNumFaces = _winged_edge->getNumFaces();
	if (_SceneNumFaces == 0) {
		DeleteWingedEdge();
		return 1;
	}

	return 0;
}
예제 #5
0
//----------------------------------------------------------------------------
void NodeCamera::Draw(TArray<NodeCamera*>& rNodeCameras, Spatial* pRoot,
	Culler& rCuller, Renderer* pRenderer)
{
	WIRE_ASSERT(pRenderer && pRoot);
	if (!pRenderer || !pRoot)
	{
		return;
	}

	const UInt maxCameraCount = 64;
	if (rNodeCameras.GetQuantity() >= 64)
	{
		WIRE_ASSERT(false);
		return;
	}

	// cull all skyboxes attached to cameras in the scene
	Spatial::CullingMode tempCullingModes[maxCameraCount];
	for (UInt i = 0; i < rNodeCameras.GetQuantity(); i++)
	{
		NodeCamera* pNodeCamera = rNodeCameras[i];
		WIRE_ASSERT(pNodeCamera);
		Node* pSkybox = pNodeCamera->mspSkybox;
		if (pSkybox && pNodeCamera->IsEnabled())
		{
			tempCullingModes[i] = pSkybox->Culling;
			pSkybox->Culling = Spatial::CULL_ALWAYS;
		}
	}

	for (UInt i = 0; i < rNodeCameras.GetQuantity(); i++)
	{
		NodeCamera* pNodeCamera = rNodeCameras[i];
		WIRE_ASSERT(pNodeCamera && pNodeCamera->Get());
		if (!pNodeCamera->IsEnabled())
		{
			continue;
		}

		Camera* pCamera = pNodeCamera->Get();

		rCuller.SetCamera(pCamera);
		rCuller.ComputeVisibleSet(pRoot);

		Float left;
		Float right;
		Float top;
		Float bottom;
		pCamera->GetViewport(left, right, top, bottom);
		UInt width = pRenderer->GetWidth();
		UInt height = pRenderer->GetHeight();
		Vector4F rect;
		rect.X() = MathF::Round(left*width);
		rect.Y() = MathF::Round((1.0F-top)*height);
		rect.Z() = MathF::Round((right-left)*width);
		rect.W() = MathF::Round((top-bottom)*height);

		ColorRGBA clearColor = pRenderer->GetClearColor();
		switch (rNodeCameras[i]->mClearFlag)
		{
		case CF_ALL:
			pRenderer->SetClearColor(pNodeCamera->GetClearColor());
			pRenderer->ClearBuffers(true, true, rect);
			pRenderer->SetClearColor(clearColor);
			break;

		case CF_Z_ONLY:
			pRenderer->ClearBuffers(false, true, rect);
			break;

		case CF_NONE:		
			break;

		default:
			WIRE_ASSERT(false);
		}

		pRenderer->SetCamera(pCamera);
		pRenderer->Draw(rCuller.GetVisibleSets());

		Node* pSkybox = pNodeCamera->mspSkybox;
		if (pSkybox)
		{
			pSkybox->Culling = Spatial::CULL_NEVER;
			rCuller.ComputeVisibleSet(pSkybox);
			pRenderer->Draw(rCuller.GetVisibleSets());
			pSkybox->Culling = Spatial::CULL_ALWAYS;
		}
	}

	// restore culling mode of all skyboxes attached to cameras in the scene
	for (UInt i = 0; i < rNodeCameras.GetQuantity(); i++)
	{
		NodeCamera* pNodeCamera = rNodeCameras[i];
		WIRE_ASSERT(pNodeCamera);
		Node* pSkybox = pNodeCamera->mspSkybox;
		if (pSkybox && pNodeCamera->IsEnabled())
		{
			pSkybox->Culling = tempCullingModes[i];
		}
	}
}