Skip to content

Commit

Permalink
* Moved modelDraw and thumbnail handling from levelEditor to the pare…
Browse files Browse the repository at this point in the history
…nt editor

so they can be used for the Asset Browser.
* The Asset Browser now shows models.
  • Loading branch information
luciusDXL committed Jan 19, 2024
1 parent 0c72a4e commit 152c227
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
24 changes: 8 additions & 16 deletions TheForceEngine/TFE_Editor/AssetBrowser/assetBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <TFE_Editor/editorProject.h>
#include <TFE_Editor/editorResources.h>
#include <TFE_Editor/editor.h>
#include <TFE_Editor/EditorAsset/editor3dThumbnails.h>
#include <TFE_Editor/EditorAsset/editorAsset.h>
#include <TFE_Editor/EditorAsset/editorTexture.h>
#include <TFE_Editor/EditorAsset/editorFrame.h>
Expand Down Expand Up @@ -697,7 +698,7 @@ namespace AssetBrowser
s32 offsetX = 0, offsetY = 0;
s32 width = s_editorConfig.thumbnailSize, height = s_editorConfig.thumbnailSize;

TextureGpu* textureGpu = nullptr;
const TextureGpu* textureGpu = nullptr;
f32 u0 = 0.0f, v0 = 1.0f;
f32 u1 = 1.0f, v1 = 0.0f;
if (s_viewAssetList[a].type == TYPE_TEXTURE || s_viewAssetList[a].type == TYPE_PALETTE)
Expand Down Expand Up @@ -767,21 +768,12 @@ namespace AssetBrowser
else if (s_viewAssetList[a].type == TYPE_3DOBJ)
{
EditorObj3D* obj3D = (EditorObj3D*)getAssetData(s_viewAssetList[a].handle);
textureGpu = obj3D ? obj3D->thumbnail : nullptr;
if (textureGpu)
{
// Preserve the image aspect ratio.
if (textureGpu->getWidth() >= textureGpu->getHeight())
{
height = textureGpu->getHeight() * s_editorConfig.thumbnailSize / textureGpu->getWidth();
offsetY = (width - height) / 2;
}
else
{
width = textureGpu->getWidth() * s_editorConfig.thumbnailSize / textureGpu->getHeight();
offsetX = (height - width) / 2;
}
}
Vec2f uv0, uv1;
textureGpu = obj3D ? getThumbnail(obj3D, &uv0, &uv1, false) : nullptr;
u0 = uv0.x;
u1 = uv1.x;
v0 = uv0.z;
v1 = uv1.z;
}
else if (s_viewAssetList[a].type == TYPE_LEVEL)
{
Expand Down
4 changes: 1 addition & 3 deletions TheForceEngine/TFE_Editor/LevelEditor/Rendering/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ namespace LevelEditor
grid2d_init();
tri2d_init();
tri3d_init();
modelDraw_init();
grid3d_init();
TFE_RenderShared::line3d_init();
}
Expand All @@ -140,7 +139,6 @@ namespace LevelEditor
grid2d_destroy();
tri2d_destroy();
tri3d_destroy();
modelDraw_destroy();
grid3d_destroy();
TFE_RenderShared::line3d_destroy();
s_viewportRt = 0;
Expand Down Expand Up @@ -364,7 +362,7 @@ namespace LevelEditor
compute2dCamera(camera);

// Submit.
TFE_RenderShared::modelDraw_draw(&camera, s_viewportSize.x, s_viewportSize.z, false);
TFE_RenderShared::modelDraw_draw(&camera, (f32)s_viewportSize.x, (f32)s_viewportSize.z, false);
TFE_RenderShared::triDraw2d_draw();
TFE_RenderShared::lineDraw2d_drawLines();
}
Expand Down
6 changes: 1 addition & 5 deletions TheForceEngine/TFE_Editor/LevelEditor/levelEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <TFE_FrontEndUI/frontEndUi.h>
#include <TFE_Editor/AssetBrowser/assetBrowser.h>
#include <TFE_Asset/imageAsset.h>
#include <TFE_Editor/EditorAsset/editor3dThumbnails.h>
#include <TFE_Editor/LevelEditor/Rendering/viewport.h>
#include <TFE_Editor/errorMessages.h>
#include <TFE_Editor/editorConfig.h>
Expand Down Expand Up @@ -288,8 +287,7 @@ namespace LevelEditor
loadPaletteAndColormap();

viewport_init();
thumbnail_init(64);


viewport_update((s32)UI_SCALE(480) + 16, (s32)UI_SCALE(68) + 18);
s_gridIndex = 7;
s_gridSize = c_gridSizeMap[s_gridIndex];
Expand Down Expand Up @@ -365,7 +363,6 @@ namespace LevelEditor
{
s_level.sectors.clear();
viewport_destroy();
thumbnail_destroy();
TFE_RenderShared::destroy();

TFE_RenderBackend::freeTexture(s_editCtrlToolbarData);
Expand Down Expand Up @@ -5076,7 +5073,6 @@ namespace LevelEditor
updateWindowControls();
handleHotkeys();

thumbnail_update();
viewport_update((s32)UI_SCALE(480) + 16, (s32)UI_SCALE(68) + 18);
viewport_render(s_view);

Expand Down
9 changes: 9 additions & 0 deletions TheForceEngine/TFE_Editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
#include "editorLevel.h"
#include "editorResources.h"
#include "editorProject.h"

#include <TFE_Settings/settings.h>
#include <TFE_Editor/AssetBrowser/assetBrowser.h>
#include <TFE_Editor/LevelEditor/levelEditor.h>
#include <TFE_Editor/EditorAsset/editorAsset.h>
#include <TFE_Editor/EditorAsset/editor3dThumbnails.h>
#include <TFE_Input/input.h>
#include <TFE_RenderBackend/renderBackend.h>
#include <TFE_RenderShared/modelDraw.h>
#include <TFE_System/system.h>
#include <TFE_FileSystem/fileutil.h>
#include <TFE_FileSystem/paths.h>
Expand Down Expand Up @@ -81,12 +84,16 @@ namespace TFE_Editor
loadFonts();
loadConfig();
AssetBrowser::init();
TFE_RenderShared::modelDraw_init();
thumbnail_init(64);
s_msgBox = {};
}

void disable()
{
AssetBrowser::destroy();
thumbnail_destroy();
TFE_RenderShared::modelDraw_destroy();
}

bool messageBoxUi()
Expand Down Expand Up @@ -238,6 +245,8 @@ namespace TFE_Editor

bool update(bool consoleOpen)
{
thumbnail_update();

TFE_RenderBackend::clearWindow();

updateTooltips();
Expand Down

0 comments on commit 152c227

Please sign in to comment.