Converts the ad-hoc design of the Material Editor to utilize the same inspector interface as most everything else does.

- Overhauls the material editor to simplify and streamline the logic behind it since the inspector does most of the work
- Tweak a few order positions of materialdefinition fields to work better
- Sets AO, Rough and Metal channel fields to use an enum type for human readability
- Updates the MaterialPreview gui control to work with assetIds
- MatEd now supports setting of parent material to inherit from
- Creating a new material now can prompt selecting an existing material to inherit from
- Can now edit the mapTo value of a material in the matEd
- New standalone Composite Texture Editor window for convering AO, Roughness and Metalness maps in a material to an ORMMap
- Can also star the creation of a composite texture via RMB context menu in AB on an image asset
- Moved logic of CubemapEditor from MatEd to it's own stuff
- Made ImageAsset fields now be more clear when they have nothing assigned, and also have a clear button to empty the field's value so it's consistent across the board
- Reorganized the layout of the gui and image files for the MatEd to be easier to navigate
- MaterialEditor now overlays the EditorGUI instead of being forcefully embedded in it, allowing easy editing of the MatEd Gui via the Gui editor
This commit is contained in:
JeffR 2025-08-03 12:03:02 -05:00
parent 8e93753b15
commit f3cad0d77e
173 changed files with 3713 additions and 6977 deletions

View file

@ -808,6 +808,8 @@ GuiControl* GuiInspectorTypeImageAssetPtr::constructEditControl()
if (Sim::findObject("ToolsGuiTextEditProfile", toolEditProfile))
editTextCtrl->setControlProfile(toolEditProfile);
editTextCtrl->setPlaceholderText("(None)");
GuiControlProfile* toolDefaultProfile = nullptr;
Sim::findObject("ToolsGuiDefaultProfile", toolDefaultProfile);
@ -836,21 +838,25 @@ GuiControl* GuiInspectorTypeImageAssetPtr::constructEditControl()
//
// Create "Open in Editor" button
/*mEditButton = new GuiBitmapButtonCtrl();
mEditButton = new GuiBitmapButtonCtrl();
if (mInspector->getInspectObject() != nullptr)
dSprintf(szBuffer, sizeof(szBuffer), "%d.apply(\"\");", getId());
else
dSprintf(szBuffer, sizeof(szBuffer), "%s = \"\";", mVariableName);
dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.editAsset(%d.getText());", retCtrl->getId());
mEditButton->setField("Command", szBuffer);
mEditButton->setText("Edit");
mEditButton->setSizing(horizResizeLeft, vertResizeAspectTop);
mEditButton->setBitmap(StringTable->insert("ToolsModule:delete_n_image"));
mEditButton->setSizing(horizResizeRight, vertResizeAspectBottom);
mEditButton->setDataField(StringTable->insert("Profile"), NULL, "ToolsGuiButtonProfile");
mEditButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
mEditButton->setDataField(StringTable->insert("hovertime"), NULL, "1000");
mEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this asset in the Image Editor");
mEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Clear this ImageAsset");
mEditButton->registerObject();
addObject(mEditButton);*/
addObject(mEditButton);
//
mUseHeightOverride = true;
@ -875,9 +881,9 @@ bool GuiInspectorTypeImageAssetPtr::updateRects()
mPreviewImage->resize(previewRect.point, previewRect.extent);
S32 editPos = previewRect.point.x + previewRect.extent.x + 10;
mEdit->resize(Point2I(editPos, rowSize * 1.5), Point2I(fieldExtent.x - editPos - 5, rowSize));
mEdit->resize(Point2I(editPos, rowSize * 1.5), Point2I(fieldExtent.x - editPos - 5 - rowSize, rowSize));
//mEditButton->resize(Point2I(fieldExtent.x - 105, previewRect.point.y + previewRect.extent.y - rowSize), Point2I(100, rowSize));
mEditButton->resize(Point2I(mEdit->getPosition().x + mEdit->getExtent().x, mEdit->getPosition().y), Point2I(rowSize, rowSize));
mBrowseButton->setHidden(true);
@ -975,7 +981,7 @@ void GuiInspectorTypeImageAssetPtr::updatePreviewImage()
//if what we're working with isn't even a valid asset, don't present like we found a good one
if (!AssetDatabase.isDeclaredAsset(previewImage))
{
mPreviewImage->_setBitmap(StringTable->EmptyString());
mPreviewImage->_setBitmap(StringTable->insert("ToolsModule:unknownImage_image"));
return;
}
@ -1003,7 +1009,7 @@ void GuiInspectorTypeImageAssetPtr::setPreviewImage(StringTableEntry assetId)
//if what we're working with isn't even a valid asset, don't present like we found a good one
if (!AssetDatabase.isDeclaredAsset(assetId))
{
mPreviewImage->_setBitmap(StringTable->EmptyString());
mPreviewImage->_setBitmap(StringTable->insert("ToolsModule:unknownImage_image"));
return;
}
@ -1025,4 +1031,20 @@ void GuiInspectorTypeImageAssetPtr::setPreviewImage(StringTableEntry assetId)
if (mPreviewImage->getBitmapAsset().isNull())
mPreviewImage->_setBitmap(StringTable->insert("ToolsModule:genericAssetIcon_image"));
}
void GuiInspectorTypeImageAssetPtr::setCaption(StringTableEntry caption)
{
mCaption = caption;
mLabel->setText(mCaption);
}
DefineEngineMethod(GuiInspectorTypeImageAssetPtr, setCaption, void, (String newCaption), , "() - Sets the caption of the field.")
{
object->setCaption(StringTable->insert(newCaption.c_str()));
}
DefineEngineMethod(GuiInspectorTypeImageAssetPtr, setIsDeleteBtnVisible, void, (bool isVisible), (false), "() - Sets if the delete/clear button is visible for the field")
{
object->setIsDeleteBtnVisible(isVisible);
}
#endif

View file

@ -16,7 +16,9 @@ public:
GuiTextCtrl* mLabel = NULL;
GuiBitmapButtonCtrl* mPreviewBorderButton = NULL;
GuiBitmapCtrl* mPreviewImage = NULL;
GuiButtonCtrl* mEditButton = NULL;
GuiBitmapButtonCtrl* mEditButton = NULL;
bool mIsDeleteButtonVisible;
DECLARE_CONOBJECT(GuiInspectorTypeImageAssetPtr);
static void consoleInit();
@ -29,6 +31,16 @@ public:
void updatePreviewImage();
void setPreviewImage(StringTableEntry assetId);
/// Sets this control's caption text, usually set within setInspectorField,
/// this is exposed in case someone wants to override the normal caption.
void setCaption(StringTableEntry caption) override;
void setIsDeleteBtnVisible(const bool& isVisible)
{
if (mEditButton)
mEditButton->setVisible(isVisible);
}
};
class GuiInspectorTypeImageAssetId : public GuiInspectorTypeImageAssetPtr

View file

@ -40,7 +40,8 @@
// GuiMaterialPreview
GuiMaterialPreview::GuiMaterialPreview()
: mMouseState(None),
mModel(NULL),
mModelInstance(NULL),
mMountedModelInstance(NULL),
runThread(0),
lastRenderTime(0),
mLastMousePoint(0, 0),
@ -64,13 +65,13 @@ GuiMaterialPreview::GuiMaterialPreview()
// By default don't do dynamic reflection
// updates for this viewport.
mReflectPriority = 0.0f;
mMountedModel = NULL;
mSkinTag = 0;
}
GuiMaterialPreview::~GuiMaterialPreview()
{
SAFE_DELETE(mModel);
SAFE_DELETE(mModelInstance);
SAFE_DELETE(mFakeSun);
}
@ -258,30 +259,34 @@ void GuiMaterialPreview::onMiddleMouseDragged(const GuiEvent &event)
}
// This is used to set the model we want to view in the control object.
void GuiMaterialPreview::setObjectModel(const char* modelName)
void GuiMaterialPreview::setObjectModel(StringTableEntry modelName)
{
deleteModel();
Resource<TSShape> model = ResourceManager::get().load(modelName);
if (! bool(model))
_setModel(modelName);
if (!getModel())
{
Con::warnf(avar("GuiMaterialPreview: Failed to load model %s. Please check your model name and load a valid model.", modelName));
Con::warnf("GuiMaterialPreview::setObjectModel - Failed to load model '%s'", modelName);
return;
}
mModel = new TSShapeInstance(model, true);
AssertFatal(mModel, avar("GuiMaterialPreview: Failed to load model %s. Please check your model name and load a valid model.", modelName));
mModelInstance = new TSShapeInstance(getModel(), true);
mModelInstance->resetMaterialList();
mModelInstance->cloneMaterialList();
AssertFatal(mModelInstance, avar("GuiMaterialPreview: Failed to load model %s. Please check your model name and load a valid model.", modelName));
// Initialize camera values:
mOrbitPos = mModel->getShape()->center;
mMinOrbitDist = mModel->getShape()->mRadius;
mOrbitPos = mModelInstance->getShape()->center;
mMinOrbitDist = mModelInstance->getShape()->mRadius;
lastRenderTime = Platform::getVirtualMilliseconds();
}
void GuiMaterialPreview::deleteModel()
{
SAFE_DELETE(mModel);
SAFE_DELETE(mModelInstance);
runThread = 0;
}
@ -358,7 +363,7 @@ void GuiMaterialPreview::onMouseLeave(const GuiEvent & event)
void GuiMaterialPreview::renderWorld(const RectI &updateRect)
{
// nothing to render, punt
if ( !mModel && !mMountedModel )
if ( !mModelInstance && !mMountedModelInstance )
return;
S32 time = Platform::getVirtualMilliseconds();
@ -408,10 +413,10 @@ void GuiMaterialPreview::renderWorld(const RectI &updateRect)
LIGHTMGR->unregisterAllLights();
LIGHTMGR->setSpecialLight( LightManager::slSunLightType, mFakeSun );
if ( mModel )
mModel->render( rdata );
if ( mModelInstance )
mModelInstance->render( rdata );
if ( mMountedModel )
if ( mMountedModelInstance )
{
// render a weapon
/*
@ -441,7 +446,7 @@ void GuiMaterialPreview::renderSunDirection() const
{
// Render four arrows aiming in the direction of the sun's light
ColorI color = LinearColorF(mFakeSun->getColor()).toColorI();
F32 length = mModel->getShape()->mBounds.len() * 0.8f;
F32 length = mModelInstance->getShape()->mBounds.len() * 0.8f;
// Get the sun's vectors
Point3F fwd = mFakeSun->getTransform().getForwardVector();
@ -449,8 +454,8 @@ void GuiMaterialPreview::renderSunDirection() const
Point3F right = mFakeSun->getTransform().getRightVector() * length / 8;
// Calculate the start and end points of the first arrow (bottom left)
Point3F start = mModel->getShape()->center - fwd * length - up / 2 - right / 2;
Point3F end = mModel->getShape()->center - fwd * length / 3 - up / 2 - right / 2;
Point3F start = mModelInstance->getShape()->center - fwd * length - up / 2 - right / 2;
Point3F end = mModelInstance->getShape()->center - fwd * length / 3 - up / 2 - right / 2;
GFXStateBlockDesc desc;
desc.setZReadWrite(true, true);
@ -476,7 +481,7 @@ void GuiMaterialPreview::resetViewport()
mCameraRot.set( mDegToRad(30.0f), 0, mDegToRad(-30.0f) );
mCameraPos.set(0.0f, 1.75f, 1.25f);
mOrbitDist = 5.0f;
mOrbitPos = mModel->getShape()->center;
mOrbitPos = mModelInstance->getShape()->center;
// Reset the viewport's lighting.
GuiMaterialPreview::mFakeSun->setColor( LinearColorF( 1.0f, 1.0f, 1.0f ) );
@ -498,7 +503,7 @@ DefineEngineMethod(GuiMaterialPreview, setModel, void, ( const char* shapeName )
"Sets the model to be displayed in this control\n\n"
"@param shapeName Name of the model to display.\n")
{
object->setObjectModel(shapeName);
object->setObjectModel(StringTable->insert(shapeName));
}
DefineEngineMethod(GuiMaterialPreview, deleteModel, void, (),,

View file

@ -28,6 +28,8 @@
#ifndef _GUIMATERIALPREVIEW_H_
#define _GUIMATERIALPREVIEW_H_
#include "assets/ShapeAsset.h"
#include "gui/3d/guiTSControl.h"
#include "ts/tsShapeInstance.h"
@ -50,8 +52,11 @@ protected:
MouseState mMouseState;
TSShapeInstance* mModel;
TSShapeInstance* mMountedModel;
DECLARE_SHAPEASSET_REFACTOR(GuiMaterialPreview, Model)
DECLARE_SHAPEASSET_REFACTOR(GuiMaterialPreview, MountedModel)
TSShapeInstance* mModelInstance;
TSShapeInstance* mMountedModelInstance;
U32 mSkinTag;
// For Camera Panning.