void Level::SetupLevel() { m_pWorld = EZ_DEFAULT_NEW(ezWorld)("Level"); m_pWorld->SetUserData(this); CreateRandomLevel(); }
ezInputManager::InternalData& ezInputManager::GetInternals() { if (s_pData == NULL) s_pData = EZ_DEFAULT_NEW(InternalData); return *s_pData; }
ezResourceLoadData CustomTextureResourceLoader::OpenDataStream(const ezResource* pResource) { ezString sFileToLoad = pResource->GetResourceID(); if (sFileToLoad.StartsWith("Loaded")) { sFileToLoad = "Textures/Loaded_D.dds"; // redirect all "Loaded_XYZ" files to the same source file } // the entire rest is copied from ezTextureResourceLoader LoadedData* pData = EZ_DEFAULT_NEW(LoadedData); ezResourceLoadData res; #if EZ_ENABLED(EZ_SUPPORTS_FILE_STATS) { ezFileReader File; if (File.Open(sFileToLoad).Failed()) return res; ezFileStats stat; if (ezOSFile::GetFileStats(File.GetFilePathAbsolute(), stat).Succeeded()) { res.m_LoadedFileModificationDate = stat.m_LastModificationTime; } } #endif if (pData->m_Image.LoadFrom(sFileToLoad).Failed()) return res; if (pData->m_Image.GetImageFormat() == ezImageFormat::B8G8R8_UNORM) { ezImageConversion::Convert(pData->m_Image, pData->m_Image, ezImageFormat::B8G8R8A8_UNORM); } ezMemoryStreamWriter w(&pData->m_Storage); ezImage* pImage = &pData->m_Image; w.WriteBytes(&pImage, sizeof(ezImage*)); /// This is a hack to get the SRGB information for the texture const ezStringBuilder sName = ezPathUtils::GetFileName(sFileToLoad); bool bIsFallback = false; bool bSRGB = (sName.EndsWith_NoCase("_D") || sName.EndsWith_NoCase("_SRGB") || sName.EndsWith_NoCase("_diff")); w << bIsFallback; w << bSRGB; res.m_pDataStream = &pData->m_Reader; res.m_pCustomLoaderData = pData; return res; }
Scene::Scene(const RenderWindowGL& renderWindow) : m_pScreenAlignedTriangle(std::make_shared<gl::ScreenAlignedTriangle>()), m_pCamera(EZ_DEFAULT_NEW_UNIQUE(FreeCamera, ezAngle::Degree(70.0f), static_cast<float>(GeneralConfig::g_ResolutionWidth.GetValue()) / GeneralConfig::g_ResolutionHeight.GetValue())), m_pFont(EZ_DEFAULT_NEW_UNIQUE(gl::Font, "Arial", 20, renderWindow.GetDeviceContext())), m_ExtractGeometryTimer(EZ_DEFAULT_NEW_UNIQUE(gl::TimerQuery)), m_DrawTimer(EZ_DEFAULT_NEW_UNIQUE(gl::TimerQuery)), m_UserInterface(EZ_DEFAULT_NEW_UNIQUE(AntTweakBarInterface)) { EZ_LOG_BLOCK("Scene init"); m_pVoxelTerrain = EZ_DEFAULT_NEW(VoxelTerrain)(m_pScreenAlignedTriangle); m_pBackground = EZ_DEFAULT_NEW(Background)(m_pScreenAlignedTriangle); // global ubo init ezDynamicArray<const gl::ShaderObject*> cameraUBOusingShader; cameraUBOusingShader.PushBack(&m_pVoxelTerrain->GetShaderDirectVolVis()); cameraUBOusingShader.PushBack(&m_pBackground->GetShader()); cameraUBOusingShader.PushBack(&m_pVoxelTerrain->GetShaderVolumeRenderShader()); m_CameraUBO.Init(cameraUBOusingShader, "Camera"); ezDynamicArray<const gl::ShaderObject*> globalSceneInfoUBOusingShader; globalSceneInfoUBOusingShader.PushBack(&m_pVoxelTerrain->GetShaderDirectVolVis()); globalSceneInfoUBOusingShader.PushBack(&m_pVoxelTerrain->GetShaderVolumeRenderShader()); m_GlobalSceneInfo.Init(globalSceneInfoUBOusingShader, "GlobalSceneInfo"); /* ezDynamicArray<const gl::ShaderObject*> timeUBOusingShader; cameraUBOusingShader.PushBack(&m_DirectVolVisShader); m_TimeUBO.Init(cameraUBOusingShader, "Time"); */ m_GlobalSceneInfo["GlobalDirLightDirection"].Set(ezVec3(1,-2.0f,1).GetNormalized()); m_GlobalSceneInfo["GlobalDirLightColor"].Set(ezVec3(0.98f, 0.98f, 0.8f)); m_GlobalSceneInfo["GlobalAmbient"].Set(ezVec3(0.3f, 0.3f, 0.3f)); ezVec3 vCameraPos = m_pVoxelTerrain->GetWorldSize(); vCameraPos.x /=2; vCameraPos.z /=2; m_pCamera->SetPosition(vCameraPos); // user interface m_UserInterface->Init(); }
void ezQtEditorApp::ExecuteTests() { if (m_TestFramework == nullptr) { m_TestFramework = EZ_DEFAULT_NEW(ezEditorTests); } m_TestFramework->ShowTests(); }
ezStatus Importer::ImportSkeleton(ezEditableSkeleton& out_Skeleton, const ezSharedPtr<Scene>& scene) { const float fScale = 1.0f; const ezMat3 mTransformation = ezMat3::IdentityMatrix(); const ezMat3 mTransformRotations = ezMat3::IdentityMatrix(); const ezUInt32 numJoints = scene->m_Skeleton.GetJointCount(); ezDynamicArray<ezEditableSkeletonJoint*> allJoints; allJoints.SetCountUninitialized(numJoints); ezSet<ezString> jointNames; ezStringBuilder tmp; for (ezUInt32 b = 0; b < numJoints; ++b) { const ezTransform mJointTransform = scene->m_Skeleton.GetJointByIndex(b).GetBindPoseLocalTransform(); allJoints[b] = EZ_DEFAULT_NEW(ezEditableSkeletonJoint); allJoints[b]->m_sName = scene->m_Skeleton.GetJointByIndex(b).GetName(); allJoints[b]->m_Transform = mJointTransform; allJoints[b]->m_Transform.m_vScale.Set(1.0f); allJoints[b]->m_fLength = 0.1f; allJoints[b]->m_fThickness = 0.01f; allJoints[b]->m_fWidth = 0.01f; allJoints[b]->m_Geometry = ezSkeletonJointGeometryType::None; if (jointNames.Contains(allJoints[b]->m_sName)) { tmp = allJoints[b]->m_sName.GetData(); tmp.AppendFormat("_joint{0}", b); allJoints[b]->m_sName.Assign(tmp.GetData()); } jointNames.Insert(allJoints[b]->m_sName.GetString()); if (scene->m_Skeleton.GetJointByIndex(b).IsRootJoint()) { allJoints[b]->m_Transform.m_vPosition = mTransformation * allJoints[b]->m_Transform.m_vPosition; allJoints[b]->m_Transform.m_qRotation.SetFromMat3(mTransformRotations * allJoints[b]->m_Transform.m_qRotation.GetAsMat3()); out_Skeleton.m_Children.PushBack(allJoints[b]); } else { allJoints[b]->m_Transform.m_vPosition = fScale * allJoints[b]->m_Transform.m_vPosition; ezUInt32 parentIdx = scene->m_Skeleton.GetJointByIndex(b).GetParentIndex(); EZ_ASSERT_DEBUG(parentIdx < b, "Invalid parent joint index"); allJoints[parentIdx]->m_Children.PushBack(allJoints[b]); } } return ezStatus(EZ_SUCCESS); }
ezDataDirectoryType* FolderType::Factory(const char* szDataDirectory) { FolderType* pDataDir = EZ_DEFAULT_NEW(FolderType); if (pDataDir->InitializeDataDirectory(szDataDirectory) == EZ_SUCCESS) return pDataDir; EZ_DEFAULT_DELETE(pDataDir); return NULL; }
ezQtOrbitCamViewWidget::ezQtOrbitCamViewWidget(ezQtEngineDocumentWindow* pOwnerWindow, ezEngineViewConfig* pViewConfig) : ezQtEngineViewWidget(nullptr, pOwnerWindow, pViewConfig) { setAcceptDrops(true); m_pOrbitCameraContext = EZ_DEFAULT_NEW(ezOrbitCameraContext, pOwnerWindow, this); m_pOrbitCameraContext->SetCamera(&m_pViewConfig->m_Camera); m_pOrbitCameraContext->SetOrbitVolume(ezVec3(0, 0, 1), ezVec3(10.0f), ezVec3(-5, 1, 2), true); m_InputContexts.PushBack(m_pOrbitCameraContext.Borrow()); }
EZ_RESOURCE_IMPLEMENT_CREATEABLE(ezPropertyAnimResource, ezPropertyAnimResourceDescriptor) { m_pDescriptor = EZ_DEFAULT_NEW(ezPropertyAnimResourceDescriptor); *m_pDescriptor = descriptor; ezResourceLoadDesc res; res.m_uiQualityLevelsDiscardable = 0; res.m_uiQualityLevelsLoadable = 0; res.m_State = ezResourceState::Loaded; return res; }
VertexDataStream* Mesh::AddDataStream(ezGALVertexAttributeSemantic::Enum semantic, ezUInt32 uiNumElementsPerVertex, VertexElementType elementType) { // A few checks for meaningful element count. // These are necessary to keep the implementation of preprocessing functions like // MergeSubMeshesWithSameMaterials/ComputeNormals/ComputeTangents sane. switch (semantic) { case ezGALVertexAttributeSemantic::Position: EZ_ASSERT_DEBUG(uiNumElementsPerVertex == 3 && elementType == VertexElementType::FLOAT, "Position vertex streams should always have exactly 3 float elements."); break; case ezGALVertexAttributeSemantic::Normal: EZ_ASSERT_DEBUG(uiNumElementsPerVertex == 3 && elementType == VertexElementType::FLOAT, "Normal vertex streams should always have exactly 3 float elements."); break; case ezGALVertexAttributeSemantic::Tangent: EZ_ASSERT_DEBUG(uiNumElementsPerVertex == 3 && elementType == VertexElementType::FLOAT, "Tangent vertex streams should always have exactly 3 float elements."); break; case ezGALVertexAttributeSemantic::BiTangent: EZ_ASSERT_DEBUG((uiNumElementsPerVertex == 3 || uiNumElementsPerVertex == 1) && elementType == VertexElementType::FLOAT, "BiTangent vertex streams should have either 3 float elements (vector) or 1 float element (sign)."); break; case ezGALVertexAttributeSemantic::BoneIndices0: case ezGALVertexAttributeSemantic::BoneIndices1: case ezGALVertexAttributeSemantic::BoneWeights0: case ezGALVertexAttributeSemantic::BoneWeights1: EZ_ASSERT_DEBUG(uiNumElementsPerVertex == 4 || uiNumElementsPerVertex == 1, "Bone weights and index streams should have 1 or 4 elements (single bone / standard skinning)."); break; } VertexDataStream* existingStream = nullptr; if (!m_VertexDataStreams.TryGetValue(static_cast<ezUInt32>(semantic), existingStream)) { m_VertexDataStreams.Insert(semantic, EZ_DEFAULT_NEW(VertexDataStream, uiNumElementsPerVertex, m_Triangles.GetCount(), elementType)); return m_VertexDataStreams[semantic]; } else { if (uiNumElementsPerVertex != existingStream->GetNumElementsPerVertex() || elementType != existingStream->GetElementType()) { return nullptr; } return existingStream; } }
void ezReloadableVariableBase::StoreVariables() { if (s_StoredVariables == NULL) s_StoredVariables = EZ_DEFAULT_NEW(MemStreamMap); ezReloadableVariableBase* pVar = GetFirstInstance(); while (pVar) { ezMemoryStreamWriter Writer(&(*s_StoredVariables)[pVar->m_szVariableName]); pVar->SaveState(Writer); pVar = pVar->GetNextInstance(); } }
void ezEditorEngineProcessApp::CreateRemoteWindow() { EZ_ASSERT_DEV(IsRemoteMode(), "Incorrect app mode"); if (m_pRemoteWindow != nullptr) return; m_pRemoteWindow = EZ_DEFAULT_NEW(ezRemoteProcessWindow); ezWindowCreationDesc desc; desc.m_uiWindowNumber = 0; desc.m_bClipMouseCursor = false; desc.m_bShowMouseCursor = true; desc.m_Resolution = ezSizeU32(1024, 768); desc.m_WindowMode = ezWindowMode::WindowFixedResolution; desc.m_Title = "Engine View"; m_pRemoteWindow->Initialize(desc); }
ezResourceLoadDesc ezPropertyAnimResource::UpdateContent(ezStreamReader* Stream) { EZ_LOG_BLOCK("ezPropertyAnimResource::UpdateContent", GetResourceDescription().GetData()); ezResourceLoadDesc res; res.m_uiQualityLevelsDiscardable = 0; res.m_uiQualityLevelsLoadable = 0; if (Stream == nullptr) { res.m_State = ezResourceState::LoadedResourceMissing; return res; } // skip the absolute file path data that the standard file reader writes into the stream { ezString sAbsFilePath; (*Stream) >> sAbsFilePath; } // skip the asset file header at the start of the file ezAssetFileHeader AssetHash; AssetHash.Read(*Stream); { ezResourceHandleReadContext context; context.BeginReadingFromStream(Stream); context.BeginRestoringHandles(Stream); m_pDescriptor = EZ_DEFAULT_NEW(ezPropertyAnimResourceDescriptor); m_pDescriptor->Load(*Stream); context.EndReadingFromStream(Stream); context.EndRestoringHandles(); } res.m_State = ezResourceState::Loaded; return res; }
ezDataDirectoryWriter* FolderType::OpenFileToWrite(const char* szFile) { FolderWriter* pWriter = NULL; for (ezUInt32 i = 0; i < m_Writers.GetCount(); ++i) { if (!m_Writers[i]->m_bIsInUse) pWriter = m_Writers[i]; } if (pWriter == NULL) { m_Writers.PushBack(EZ_DEFAULT_NEW(FolderWriter)); pWriter = m_Writers.PeekBack(); } // if opening the file fails, the writer state is never set to 'used', so nothing else needs to be done if (pWriter->Open(szFile, this) == EZ_FAILURE) return NULL; // if it succeeds, we return the reader pWriter->m_bIsInUse = true; return pWriter; }
void AfterCoreSystemsStartup() override { ezStringBuilder sProjectDir = ">sdk/Data/Samples/TextureSample"; ezStringBuilder sProjectDirResolved; ezFileSystem::ResolveSpecialDirectory(sProjectDir, sProjectDirResolved); ezFileSystem::SetSpecialDirectory("project", sProjectDirResolved); // setup the 'asset management system' { // which redirection table to search ezDataDirectory::FolderType::s_sRedirectionFile = "AssetCache/LookupTable.ezAsset"; // which platform assets to use ezDataDirectory::FolderType::s_sRedirectionPrefix = "AssetCache/PC/"; } ezFileSystem::RegisterDataDirectoryFactory(ezDataDirectory::FolderType::Factory); ezFileSystem::AddDataDirectory("", "", ":", ezFileSystem::AllowWrites); ezFileSystem::AddDataDirectory(">appdir/", "AppBin", "bin", ezFileSystem::AllowWrites); // writing to the binary directory ezFileSystem::AddDataDirectory(">appdir/", "ShaderCache", "shadercache", ezFileSystem::AllowWrites); // for shader files ezFileSystem::AddDataDirectory(">user/ezEngine Project/TextureSample", "AppData", "appdata", ezFileSystem::AllowWrites); // app user data ezFileSystem::AddDataDirectory(">sdk/Data/Base", "Base", "base"); ezFileSystem::AddDataDirectory(">sdk/Data/FreeContent", "Shared", "shared"); ezFileSystem::AddDataDirectory(">project/", "Project", "project", ezFileSystem::AllowWrites); ezGlobalLog::AddLogWriter(ezLogWriter::Console::LogMessageHandler); ezGlobalLog::AddLogWriter(ezLogWriter::VisualStudio::LogMessageHandler); ezTelemetry::CreateServer(); ezPlugin::LoadPlugin("ezInspectorPlugin"); EZ_VERIFY(ezPlugin::LoadPlugin("ezShaderCompilerHLSL").Succeeded(), "Compiler Plugin not found"); // Register Input { ezInputActionConfig cfg; cfg = ezInputManager::GetInputActionConfig("Main", "CloseApp"); cfg.m_sInputSlotTrigger[0] = ezInputSlot_KeyEscape; ezInputManager::SetInputActionConfig("Main", "CloseApp", cfg, true); cfg = ezInputManager::GetInputActionConfig("Main", "MovePosX"); cfg.m_sInputSlotTrigger[0] = ezInputSlot_MouseMovePosX; cfg.m_bApplyTimeScaling = false; ezInputManager::SetInputActionConfig("Main", "MovePosX", cfg, true); cfg = ezInputManager::GetInputActionConfig("Main", "MoveNegX"); cfg.m_sInputSlotTrigger[0] = ezInputSlot_MouseMoveNegX; cfg.m_bApplyTimeScaling = false; ezInputManager::SetInputActionConfig("Main", "MoveNegX", cfg, true); cfg = ezInputManager::GetInputActionConfig("Main", "MovePosY"); cfg.m_sInputSlotTrigger[0] = ezInputSlot_MouseMovePosY; cfg.m_bApplyTimeScaling = false; ezInputManager::SetInputActionConfig("Main", "MovePosY", cfg, true); cfg = ezInputManager::GetInputActionConfig("Main", "MoveNegY"); cfg.m_sInputSlotTrigger[0] = ezInputSlot_MouseMoveNegY; cfg.m_bApplyTimeScaling = false; ezInputManager::SetInputActionConfig("Main", "MoveNegY", cfg, true); cfg = ezInputManager::GetInputActionConfig("Main", "MouseDown"); cfg.m_sInputSlotTrigger[0] = ezInputSlot_MouseButton0; cfg.m_bApplyTimeScaling = false; ezInputManager::SetInputActionConfig("Main", "MouseDown", cfg, true); } // Create a window for rendering { ezWindowCreationDesc WindowCreationDesc; WindowCreationDesc.m_Resolution.width = g_uiWindowWidth; WindowCreationDesc.m_Resolution.height = g_uiWindowHeight; m_pWindow = EZ_DEFAULT_NEW(TextureSampleWindow); m_pWindow->Initialize(WindowCreationDesc); } // Create a device { ezGALDeviceCreationDescription DeviceInit; DeviceInit.m_bCreatePrimarySwapChain = true; DeviceInit.m_bDebugDevice = true; DeviceInit.m_PrimarySwapChainDescription.m_pWindow = m_pWindow; DeviceInit.m_PrimarySwapChainDescription.m_SampleCount = ezGALMSAASampleCount::None; DeviceInit.m_PrimarySwapChainDescription.m_bAllowScreenshots = true; m_pDevice = EZ_DEFAULT_NEW(ezGALDeviceDX11, DeviceInit); EZ_VERIFY(m_pDevice->Init() == EZ_SUCCESS, "Device init failed!"); ezGALDevice::SetDefaultDevice(m_pDevice); } // now that we have a window and device, tell the engine to initialize the rendering infrastructure ezStartup::StartupHighLevelSystems(); // Get the primary swapchain (this one will always be created by device init except if the user instructs no swap chain creation // explicitly) { ezGALSwapChainHandle hPrimarySwapChain = m_pDevice->GetPrimarySwapChain(); const ezGALSwapChain* pPrimarySwapChain = m_pDevice->GetSwapChain(hPrimarySwapChain); ezGALTextureCreationDescription texDesc; texDesc.m_uiWidth = g_uiWindowWidth; texDesc.m_uiHeight = g_uiWindowHeight; texDesc.m_Format = ezGALResourceFormat::D24S8; texDesc.m_bCreateRenderTarget = true; m_hDepthStencilTexture = m_pDevice->CreateTexture(texDesc); m_hBBRTV = m_pDevice->GetDefaultRenderTargetView(pPrimarySwapChain->GetBackBufferTexture()); m_hBBDSV = m_pDevice->GetDefaultRenderTargetView(m_hDepthStencilTexture); } // Create Rasterizer State { ezGALRasterizerStateCreationDescription RasterStateDesc; RasterStateDesc.m_CullMode = ezGALCullMode::Back; RasterStateDesc.m_bFrontCounterClockwise = true; m_hRasterizerState = m_pDevice->CreateRasterizerState(RasterStateDesc); EZ_ASSERT_DEV(!m_hRasterizerState.IsInvalidated(), "Couldn't create rasterizer state!"); } // Create Depth Stencil state { ezGALDepthStencilStateCreationDescription DepthStencilStateDesc; DepthStencilStateDesc.m_bDepthTest = false; DepthStencilStateDesc.m_bDepthWrite = true; m_hDepthStencilState = m_pDevice->CreateDepthStencilState(DepthStencilStateDesc); EZ_ASSERT_DEV(!m_hDepthStencilState.IsInvalidated(), "Couldn't create depth-stencil state!"); } // Setup Shaders and Materials { ezShaderManager::Configure("DX11_SM50", true); m_hMaterial = ezResourceManager::LoadResource<ezMaterialResource>("Materials/Texture.ezMaterial"); // Create the mesh that we use for rendering CreateSquareMesh(); } // Setup default resources { ezTexture2DResourceHandle hFallback = ezResourceManager::LoadResource<ezTexture2DResource>("Textures/Reference_D.dds"); ezTexture2DResourceHandle hMissing = ezResourceManager::LoadResource<ezTexture2DResource>("Textures/MissingTexture_D.dds"); ezResourceManager::SetResourceTypeLoadingFallback<ezTexture2DResource>(hFallback); ezResourceManager::SetResourceTypeMissingFallback<ezTexture2DResource>(hMissing); // redirect all texture load operations through our custom loader, so that we can duplicate the single source texture // that we have as often as we like (to waste memory) ezResourceManager::SetResourceTypeLoader<ezTexture2DResource>(&m_TextureResourceLoader); } // Setup constant buffer that this sample uses { m_hSampleConstants = ezRenderContext::CreateConstantBufferStorage(m_pSampleConstantBuffer); } // Pre-allocate all textures { // we only do this to be able to see the unloaded resources in the ezInspector // this does NOT preload the resources ezStringBuilder sResourceName; for (ezInt32 y = -g_iMaxHalfExtent; y < g_iMaxHalfExtent; ++y) { for (ezInt32 x = -g_iMaxHalfExtent; x < g_iMaxHalfExtent; ++x) { sResourceName.Printf("Loaded_%+03i_%+03i_D", x, y); ezTexture2DResourceHandle hTexture = ezResourceManager::LoadResource<ezTexture2DResource>(sResourceName); if (g_bPreloadAllTextures) ezResourceManager::PreloadResource(hTexture, ezTime::Seconds(1.0)); } } } }