Esempio n. 1
0
/**
*  @brief
*    Called when a scene node was found
*/
void EngineApplication::OnSceneNode(SceneQuery &cQuery, SceneNode &cSceneNode)
{
	// Is this a camera?
	if (cSceneNode.IsCamera()) {
		if (!m_pFirstFoundCamera)
			m_pFirstFoundCamera = &cSceneNode;

		// Deactivate all camera's by default
		cSceneNode.SetActive(false);

	// Key/value data scene node?
	} else if (cSceneNode.IsInstanceOf("PLScene::SNKeyValue")) {
		const SNKeyValue &cKeyValue = static_cast<const SNKeyValue&>(cSceneNode);

		// SceneRenderer
		if (cKeyValue.Key.GetString() == "SceneRenderer") {
			// Use the first found key
			if (!m_sDefaultSceneRenderer.GetLength())
				m_sDefaultSceneRenderer = cKeyValue.Value.GetString();

		// SceneRendererVariables
		} else if (cKeyValue.Key.GetString() == "SceneRendererVariables") {
			// Use the first found key
			if (!m_sSceneRendererVariables.GetLength())
				m_sSceneRendererVariables = cKeyValue.Value.GetString();

		// ClearColor
		} else if (cKeyValue.Key.GetString() == "ClearColor") {
			// Use the first found key
			if (!m_sClearColor.GetLength())
				m_sClearColor = cKeyValue.Value.GetString();

		// StartCamera
		} else if (cKeyValue.Key.GetString() == "StartCamera") {
			// Use the first found key
			if (!m_sStartCamera.GetLength())
				m_sStartCamera = cKeyValue.Value.GetString();
		}

	// Load screen scene node?
	} else if (cSceneNode.IsInstanceOf("PLEngine::SNLoadScreenBase")) {
		m_bHasLoadScreen = true;
	}
}
Esempio n. 2
0
bool EngineApplication::LoadScene(const String &sFilename)
{
	// Get the scene container holding our scene
	SceneContainer *pContainer = GetScene();
	if (!pContainer)
		return false; // Error! (should NEVER happen...)

	// Disable the ingame GUI
	SceneNode *pGui = pContainer->GetContainer()->GetByName("GUI");
	if (pGui)
		pGui->SetActive(false);

	// Clear the scene, after calling this method the scene is empty
	ClearScene();

	// Load the scene
	bool bResult = pContainer->LoadByFilename(sFilename);
	if (bResult) {
		// Set a null pointer camera and default scene renderer
		m_sDefaultSceneRenderer		= "";
		m_sSceneRendererVariables	= "";
		m_sClearColor				= "";
		m_sStartCamera				= "";
		m_pFirstFoundCamera			= nullptr;
		m_bHasLoadScreen			= false;

		// Get scene surface painter
		SurfacePainter *pPainter = GetPainter();
		if (pPainter && pPainter->IsInstanceOf("PLScene::SPScene")) {
			// Assign the first found camera scene node to your surface listener and look for
			// known key/value data scene nodes
			SceneQuery *pSceneQuery = pContainer->CreateQuery("PLScene::SQEnumerate");
			if (pSceneQuery) {
				// Connect event handler
				pSceneQuery->SignalSceneNode.Connect(EventHandlerSceneNode);

				// Perform the query
				pSceneQuery->PerformQuery();

				// Destroy the query
				pContainer->DestroyQuery(*pSceneQuery);
			}

			// Set to default scene renderer?
			if (!m_sDefaultSceneRenderer.GetLength())
				m_sDefaultSceneRenderer = DefaultSceneRenderer;

			// Sets all scene renderer pass attribute values to their default value
			GetSceneRendererTool().SetDefaultValues();

			// Set the used scene renderer
			GetSceneRendererTool().SetSceneRenderer(pContainer, m_sDefaultSceneRenderer, DefaultSceneRenderer);

			// Set clear color
			GetSceneRendererTool().SetPassAttribute("Begin", "ColorClear", m_sClearColor);

			// Set scene renderer variables
			if (m_sSceneRendererVariables.GetLength())
				GetSceneRendererTool().SetValues(m_sSceneRendererVariables);

			// Is there a given start camera?
			SceneNode *pCamera = nullptr;
			if (m_sStartCamera.GetLength()) {
				SceneNode *pStartCamera = pContainer->GetByName(m_sStartCamera);
				if (pStartCamera && pStartCamera->IsCamera())
					pCamera = pStartCamera;
			}

			// Use the first found camera?
			if (!pCamera)
				pCamera = m_pFirstFoundCamera;

			// Activate the current used camera by default
			if (pCamera)
				pCamera->SetActive(true);

			// Assign this camera to the scene renderer and to the application
			SetCamera(reinterpret_cast<SNCamera*>(pCamera));
		}

		// Emit the scene loading has been finished successfully event
		SignalSceneLoadingFinished();
	}

	// Enable the ingame GUI
	if (pGui)
		pGui->SetActive(true);

	// Done
	return bResult;
}
Esempio n. 3
0
//[-------------------------------------------------------]
//[ Public virtual SceneNode functions                    ]
//[-------------------------------------------------------]
void SCRenderToTexture::DrawPre(Renderer &cRenderer, const VisNode *pVisNode)
{
	if (IsActive() && m_pSurfaceTextureBuffer) {
		// Call base implementation
		SceneContainer::DrawPre(cRenderer, pVisNode);

		// Check FPS limitation
		if (FPSLimit) {
			const uint64 nCurrentTime = System::GetInstance()->GetMilliseconds();
			if (m_nFPSLimitLastTime && nCurrentTime-m_nFPSLimitLastTime < static_cast<uint64>(1000.0f/FPSLimit))
				return; // Do not update
			m_nFPSLimitLastTime = nCurrentTime;
		}

		// Get the surface scene painter
		SurfacePainter *pSurfacePainter = m_pSurfaceTextureBuffer->GetPainter();
		if (pSurfacePainter && pSurfacePainter->IsInstanceOf("PLScene::SPScene")) {
			SPScene *pPainter = static_cast<SPScene*>(pSurfacePainter);

			// Deactivate THIS node to avoid recursion
			SetActive(false);

			// Get current camera
			SNCamera *pCameraBackup = SNCamera::GetCamera();

			// Set camera
			SceneNode *pSceneNode = GetByName(CameraName.Get());
			if (pSceneNode && pSceneNode->IsCamera()) {
				// If the camera is not active, we do not need to do anything in here...
				if (!pSceneNode->IsActive())
					return;

				pPainter->SetCamera(static_cast<SNCamera*>(pSceneNode));
				static_cast<SNCamera*>(pSceneNode)->SetCamera(cRenderer);
			} else
				pPainter->SetCamera(nullptr);

			// Get current render target
			Surface *pSurfaceBackup = cRenderer.GetRenderTarget();


			// [HACK] If the painter has no scene container, check if the scene container exists now...
			if (!pPainter->GetSceneContainer()) {
				pSceneNode = GetByName(m_sSceneName);
				if (pSceneNode && pSceneNode->IsContainer())
					pPainter->SetSceneContainer(static_cast<SceneContainer*>(pSceneNode));
			}


			// Check the render target type
			if (m_bCube) { // Render to cube texture
				// Setup the camera
				SNCamera *pCamera = pPainter->GetCamera();
				if (pCamera) {
					// Set field of view and aspect
					pCamera->SetFOV(90.0f);
					pCamera->SetAspect(1.0f);

					// For each of the 6 cube faces...
					for (uint8 nFace=0; nFace<6; nFace++) {
						// Set rotation
						switch (nFace) {
							// x-positive
							case 0:
								pCamera->SetRotation(Vector3(  0.0f, -90.0f, 180.0f));
								break;

							// x-negative
							case 1:
								pCamera->SetRotation(Vector3(  0.0f,  90.0f, 180.0f));
								break;

							// y-positive
							case 2:
								pCamera->SetRotation(Vector3( 90.0f,   0.0f, 180.0f));
								break;

							// y-negative
							case 3:
								pCamera->SetRotation(Vector3(-90.0f,   0.0f, 180.0f));
								break;

							// z-positive
							case 4:
								pCamera->SetRotation(Vector3(  0.0f,   0.0f, 180.0f));
								break;

							// z-negative
							case 5:
								pCamera->SetRotation(Vector3(  0.0f, 180.0f, 180.0f));
								break;
						}

						// Set the new render target
						if (cRenderer.SetRenderTarget(m_pSurfaceTextureBuffer, nFace)) {
							// Draw a nice and colorful picture :)
							pPainter->OnPaint(*m_pSurfaceTextureBuffer);
						}
					}
				} else {
					// For each of the 6 cube faces...
					for (uint8 nFace=0; nFace<6; nFace++) {
						// Set the new render target
						if (cRenderer.SetRenderTarget(m_pSurfaceTextureBuffer, nFace)) {
							// Draw a nice and colorful picture :)
							pPainter->OnPaint(*m_pSurfaceTextureBuffer);
						}
					}
				}

			} else { // Render to 2D/rectangle texture
				// Set the new render target
				if (cRenderer.SetRenderTarget(m_pSurfaceTextureBuffer)) {
					// Draw a nice and colorful picture :)
					pPainter->OnPaint(*m_pSurfaceTextureBuffer);
				}
			}

			// Reset renderer target
			cRenderer.SetRenderTarget(pSurfaceBackup);
			if (pCameraBackup) {
				pPainter->SetCamera(pCameraBackup);
				pCameraBackup->SetCamera(cRenderer);
			}

			// Reactivate THIS node to avoid recursion
			SetActive(true);
		}
	}
}