More asset handles

This commit is contained in:
Simon Lübeß
2023-03-13 20:35:36 +01:00
parent c22d122921
commit c3fb9bbd5d
11 changed files with 97 additions and 75 deletions
@@ -29,7 +29,7 @@ class MaterialAssetPropertiesEditor : AssetPropertiesEditor
mixin DropAssetTarget<T>() where T : Asset
{
Asset asset = null;
AssetHandle handle = .Invalid;
if (ImGui.BeginDragDropTarget())
{
@@ -39,13 +39,13 @@ class MaterialAssetPropertiesEditor : AssetPropertiesEditor
{
StringView fullpath = .((char8*)payload.Data, (int)payload.DataSize);
asset = Content.LoadAsset<Asset>(fullpath);
handle = Content.LoadAsset(fullpath);
}
ImGui.EndDragDropTarget();
}
asset
handle
}
public this(AssetFile asset) : base(asset)
@@ -84,11 +84,11 @@ class MaterialAssetPropertiesEditor : AssetPropertiesEditor
{
StringView path = .((char8*)payload.Data, (int)payload.DataSize);
using (Texture2D newTexture = Content.LoadAsset<Texture2D>(path))//new Texture2D(path, true))
{
newTexture.SamplerState = SamplerStateManager.AnisotropicWrap;
material.SetTexture(texture.key, newTexture);
}
AssetHandle<Texture2D> newTexture = Content.LoadAsset(path);//new Texture2D(path, true))
newTexture.Get().SamplerState = SamplerStateManager.AnisotropicWrap;
//material.SetTexture(texture.key, newTexture);
// TODO!!!
}
ImGui.EndDragDropTarget();
@@ -268,10 +268,7 @@ namespace GlitchyEditor.EditWindows
StringView path = .((char8*)payload.Data, (int)payload.DataSize);
using (Texture2D texture = Content.LoadAsset<Texture2D>(path))
{
spriteRendererComponent.Sprite = texture;
}
spriteRendererComponent.Sprite = Content.LoadAsset(path);
}
ImGui.EndDragDropTarget();
@@ -301,10 +298,7 @@ namespace GlitchyEditor.EditWindows
{
StringView fullpath = .((char8*)payload.Data, (int)payload.DataSize);
using (Material loadedMaterial = Content.LoadAsset<Material>(fullpath))
{
meshRendererComponent.Material = loadedMaterial;
}
meshRendererComponent.Material = Content.LoadAsset(fullpath);
}
ImGui.EndDragDropTarget();
@@ -488,10 +482,7 @@ namespace GlitchyEditor.EditWindows
StringView filePath = fullpath.Substring(0, idx);
StringView meshName = fullpath.Substring(idx + 1);*/
using (GeometryBinding geometry = Content.LoadAsset<GeometryBinding>(fullpath))
{
meshComponent.Mesh = geometry;
}
meshComponent.Mesh = Content.LoadAsset(fullpath);
// TODO: support multiple primitives (treat every primitive as a single mesh? or: mesh can have multiple primitives)
/*using (GeometryBinding binding = ModelLoader.LoadMesh(filePath, meshName, 0))
@@ -18,7 +18,8 @@ class PropertiesWindow : EditorWindow
private append String _selectedFileName = .();
private Asset _currentAsset ~ _?.ReleaseRef();
private AssetHandle _currentAssetHandle;
private Asset _currentAsset;
public this(Editor editor)
{
@@ -78,7 +79,8 @@ class PropertiesWindow : EditorWindow
if (_currentAsset?.Identifier != assetFile.Identifier)
{
_currentAsset?.ReleaseRef();
_currentAsset = _editor.ContentManager.LoadAsset(assetFile.Identifier);
_currentAssetHandle = _editor.ContentManager.LoadAsset(assetFile.Identifier);
_currentAsset = _editor.ContentManager.GetAsset(null, _currentAssetHandle);
}
// TODO: allow changing AssetLoader
+5 -4
View File
@@ -2,12 +2,13 @@ using System;
using GlitchyEngine.Renderer;
using GlitchyEngine.Math;
using GlitchyEngine;
using GlitchyEngine.Content;
namespace GlitchyEditor
{
class EditorIcons : RefCounted
{
Texture2D _texture ~ _.ReleaseRef();
AssetHandle<Texture2D> _texture;
public SubTexture2D DirectionalLight ~ _.ReleaseRef();
public SubTexture2D Camera ~ _.ReleaseRef();
@@ -18,13 +19,13 @@ namespace GlitchyEditor
public SamplerState SamplerState
{
get => _texture.SamplerState;
set => _texture.SamplerState = value;
get => _texture.Get().SamplerState;
set => _texture.Get().SamplerState = value;
}
public this(String texturePath, Vector2 iconSize)
{
_texture = Content.LoadAsset<Texture2D>(texturePath);//new Texture2D(texturePath);
_texture = Content.LoadAsset(texturePath);//new Texture2D(texturePath);
Vector2 pen = .();