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.

View file

@ -1050,6 +1050,15 @@ DefineEngineMethod(GuiInspectorField, setCaption, void, (String newCaption),, "(
object->setCaption(StringTable->insert(newCaption.c_str()));
}
DefineEngineMethod(GuiInspectorField, getFieldName, const char*, (), , "() - Gets the fieldName of the field.")
{
constexpr U32 bufSize = 128;
char* retBuffer = Con::getReturnBuffer(bufSize);
dSprintf(retBuffer, bufSize, "%s", object->getFieldName());
return retBuffer;
}
DefineEngineMethod(GuiInspectorField, setSpecialEditVariableName, void, (String newCaption), , "() - Sets the variable name for special edit fields.")
{
object->setSpecialEditVariableName(StringTable->insert(newCaption.c_str()));

View file

@ -132,6 +132,8 @@ class GuiInspectorField : public GuiControl
/// this is exposed in case someone wants to override the normal caption.
virtual void setCaption( StringTableEntry caption ) { mCaption = caption; }
virtual StringTableEntry getCaption() { return mCaption; }
void setEditControl(GuiControl* editCtrl);
void setHeightOverride(bool useOverride, U32 heightOverride);

View file

@ -211,7 +211,7 @@ GuiInspectorField *GuiInspectorGroup::findField( const char *fieldName )
for( ; i != mChildren.end(); i++ )
{
if( (*i)->getFieldName() != NULL && dStricmp( (*i)->getFieldName(), fieldName ) == 0 )
if( ((*i)->getFieldName() != NULL && dStricmp( (*i)->getFieldName(), fieldName ) == 0) || ((*i)->getCaption() != StringTable->EmptyString() && dStricmp((*i)->getCaption(), fieldName) == 0) )
return (*i);
}
@ -834,3 +834,26 @@ DefineEngineMethod(GuiInspectorGroup, setForcedArrayIndex, void, (S32 arrayIndex
{
object->setForcedArrayIndex(arrayIndex);
}
DefineEngineMethod(GuiInspectorGroup, findField, S32, (const char* fieldName),,
"Finds an Inspector field in this group of a given name.\n"
"@param fieldName The name of the field to be found.\n"
"@return Field SimObjectId")
{
if (dStrEqual(fieldName, ""))
return 0;
GuiInspectorField* field = object->findField(StringTable->insert(fieldName));
if (field == nullptr)
return 0;
return field->getId();
}
DefineEngineMethod(GuiInspectorGroup, refresh, void, (), ,
"Finds an Inspector field in this group of a given name.\n"
"@param fieldName The name of the field to be found.\n"
"@return Field SimObjectId")
{
object->inspectGroup();
}

View file

@ -101,6 +101,15 @@ ImplementEnumType(MaterialWaveType,
{ Material::Square, "Square", "Warps the material along a wave which transitions between two oppposite states. As a Square Wave, the transition is quick and sudden." },
EndImplementEnumType;
ImplementEnumType(MaterialSourceChannelType,
"When sampling from ORM Texture maps, dictates what channel to sample from for a given AO, Roughness or Metalness texture.\n"
"@ingroup GFX\n")
{ Material::RedChannel, "Red", "Red Channel" },
{ Material::GreenChannel, "Green", "Green Channel" },
{ Material::BlueChannel, "Blue", "Blue Channel" },
{ Material::AlphaChannel, "Alpha", "Alpha Channel" },
EndImplementEnumType;
bool Material::sAllowTextureTargetAssignment = false;
GFXCubemap* Material::GetNormalizeCube()
@ -254,6 +263,11 @@ void Material::initPersistFields()
addGroup("Light Influence Maps");
addFieldV("roughness", TypeRangedF32, Offset(mRoughness, Material), &CommonValidators::F32_8BitPercent, MAX_STAGES,
"The degree of roughness when not using a ORMConfigMap.");
addFieldV("metalness", TypeRangedF32, Offset(mMetalness, Material), &CommonValidators::F32_8BitPercent, MAX_STAGES,
"The degree of Metalness when not using a ORMConfigMap.");
INITPERSISTFIELD_IMAGEASSET_ARRAY(ORMConfigMap, MAX_STAGES, Material, "AO|Roughness|metalness map");
addField("isSRGb", TypeBool, Offset(mIsSRGb, Material), MAX_STAGES,
"Substance Designer Workaround.");
@ -261,21 +275,19 @@ void Material::initPersistFields()
"Treat Roughness as Roughness");
INITPERSISTFIELD_IMAGEASSET_ARRAY(AOMap, MAX_STAGES, Material, "AOMap");
INITPERSISTFIELD_IMAGEASSET_ARRAY(RoughMap, MAX_STAGES, Material, "RoughMap (also needs MetalMap)");
INITPERSISTFIELD_IMAGEASSET_ARRAY(MetalMap, MAX_STAGES, Material, "MetalMap (also needs RoughMap)");
INITPERSISTFIELD_IMAGEASSET_ARRAY(GlowMap, MAX_STAGES, Material, "GlowMap (needs Albedo)");
addFieldV("AOChan", TypeRangedS32, Offset(mAOChan, Material), &bmpChanRange, MAX_STAGES,
addField("AOChan", TYPEID< SourceChannelType >(), Offset(mAOChan, Material), MAX_STAGES,
"The input channel AO maps use.");
addFieldV("roughness", TypeRangedF32, Offset(mRoughness, Material), &CommonValidators::F32_8BitPercent,MAX_STAGES,
"The degree of roughness when not using a ORMConfigMap.");
addFieldV("roughnessChan", TypeRangedS32, Offset(mRoughnessChan, Material), &bmpChanRange, MAX_STAGES,
INITPERSISTFIELD_IMAGEASSET_ARRAY(RoughMap, MAX_STAGES, Material, "RoughMap (also needs MetalMap)");
addField("roughnessChan", TYPEID< SourceChannelType >(), Offset(mRoughnessChan, Material), MAX_STAGES,
"The input channel roughness maps use.");
addFieldV("metalness", TypeRangedF32, Offset(mMetalness, Material), &CommonValidators::F32_8BitPercent, MAX_STAGES,
"The degree of Metalness when not using a ORMConfigMap.");
addFieldV("metalChan", TypeRangedS32, Offset(mMetalChan, Material), &bmpChanRange, MAX_STAGES,
INITPERSISTFIELD_IMAGEASSET_ARRAY(MetalMap, MAX_STAGES, Material, "MetalMap (also needs RoughMap)");
addField("metalChan", TYPEID< SourceChannelType >(), Offset(mMetalChan, Material), MAX_STAGES,
"The input channel metalness maps use.");
INITPERSISTFIELD_IMAGEASSET_ARRAY(GlowMap, MAX_STAGES, Material, "GlowMap (needs Albedo)");
addFieldV("glowMul", TypeRangedF32, Offset(mGlowMul, Material),&glowMulRange, MAX_STAGES,
"glow mask multiplier");
endGroup("Light Influence Maps");

View file

@ -129,6 +129,14 @@ public:
Square,
};
enum SourceChannelType
{
RedChannel = 0,
GreenChannel,
BlueChannel,
AlphaChannel
};
class StageData
{
protected:
@ -425,9 +433,11 @@ private:
typedef Material::AnimType MaterialAnimType;
typedef Material::BlendOp MaterialBlendOp;
typedef Material::WaveType MaterialWaveType;
typedef Material::SourceChannelType MaterialSourceChannelType;
DefineBitfieldType(MaterialAnimType);
DefineEnumType(MaterialBlendOp);
DefineEnumType(MaterialWaveType);
DefineEnumType(MaterialSourceChannelType);
#endif // _MATERIALDEFINITION_H_