# Conflicts:
#	indra/llrender/llgl.cpp
#	indra/llrender/llrendertarget.cpp
#	indra/newview/llfloaterpreference.cpp
#	indra/newview/llviewercontrol.cpp
master
Ansariel 2022-10-24 20:01:04 +02:00
commit 0ae0cd0c88
11 changed files with 150 additions and 104 deletions

View File

@ -80,22 +80,7 @@ LLTextureEntry::LLTextureEntry(const LLTextureEntry &rhs)
, mSelected(false)
, mMaterialUpdatePending(false)
{
mID = rhs.mID;
mScaleS = rhs.mScaleS;
mScaleT = rhs.mScaleT;
mOffsetS = rhs.mOffsetS;
mOffsetT = rhs.mOffsetT;
mRotation = rhs.mRotation;
mColor = rhs.mColor;
mBump = rhs.mBump;
mMediaFlags = rhs.mMediaFlags;
mGlow = rhs.mGlow;
mMaterialID = rhs.mMaterialID;
mMaterial = rhs.mMaterial;
if (rhs.mMediaEntry != NULL) {
// Make a copy
mMediaEntry = new LLMediaEntry(*rhs.mMediaEntry);
}
*this = rhs;
}
LLTextureEntry &LLTextureEntry::operator=(const LLTextureEntry &rhs)
@ -124,6 +109,17 @@ LLTextureEntry &LLTextureEntry::operator=(const LLTextureEntry &rhs)
else {
mMediaEntry = NULL;
}
mMaterialID = rhs.mMaterialID;
if (rhs.mGLTFMaterialOverrides.notNull())
{
mGLTFMaterialOverrides = new LLGLTFMaterial(*rhs.mGLTFMaterialOverrides);
}
else
{
mGLTFMaterialOverrides = nullptr;
}
}
return *this;
@ -218,6 +214,11 @@ void LLTextureEntry::asLLSD(LLSD& sd) const
sd[TEXTURE_MEDIA_DATA_KEY] = mediaData;
}
sd["glow"] = mGlow;
if (mGLTFMaterialOverrides.notNull())
{
sd["gltf_override"] = mGLTFMaterialOverrides->asJSON();
}
}
bool LLTextureEntry::fromLLSD(const LLSD& sd)
@ -282,6 +283,24 @@ bool LLTextureEntry::fromLLSD(const LLSD& sd)
setGlow((F32)sd[w].asReal() );
}
w = "gltf_override";
if (sd.has(w))
{
if (mGLTFMaterialOverrides.isNull())
{
mGLTFMaterialOverrides = new LLGLTFMaterial();
}
std::string warn_msg, error_msg;
if (!mGLTFMaterialOverrides->fromJSON(sd[w].asString(), warn_msg, error_msg))
{
LL_WARNS() << llformat("Failed to parse GLTF json: %s -- %s", warn_msg.c_str(), error_msg.c_str()) << LL_ENDL;
LL_WARNS() << sd[w].asString() << LL_ENDL;
mGLTFMaterialOverrides = nullptr;
}
}
return true;
fail:
return false;

View File

@ -1209,14 +1209,14 @@ bool LLGLManager::initGL()
stop_glerror();
glGetIntegerv(GL_MAX_SAMPLES, &mMaxSamples);
stop_glerror();
if (mGLVersion >= 4.59f)
{
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &mMaxAnisotropy);
stop_glerror();
}
stop_glerror();
initGLStates();
initGLStates();
stop_glerror();
return true;

View File

@ -134,7 +134,7 @@ bool LLRenderTarget::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, boo
mUsage = usage;
mUseDepth = depth;
if (sUseFBO || use_fbo)
if ((sUseFBO || use_fbo))
{
if (depth)
{

View File

@ -23,6 +23,7 @@
* $/LicenseInfo$
*/
/*[EXTRA_CODE_HERE]*/
//class1/deferred/materialF.glsl
@ -40,13 +41,12 @@ out vec4 frag_data[4];
void main()
{
#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
frag_color = vec4(1,0,0,0.5);
frag_color = vec4(1, 0, 0, 0.5);
#else
// emissive red PBR material
frag_data[0] = vec4(0,0,0,0);
frag_data[1] = vec4(0,0,0,0);
frag_data[2] = vec4(1,0,0,GBUFFER_FLAG_HAS_PBR);
frag_data[3] = vec4(1,0,0,0);
frag_data[0] = vec4(0, 0, 0, 0);
frag_data[1] = vec4(0, 0, 0, 0);
frag_data[2] = vec4(1, 0, 0, GBUFFER_FLAG_HAS_PBR);
frag_data[3] = vec4(1, 0, 0, 0);
#endif
}

View File

@ -45,59 +45,58 @@
namespace
{
class LLGLTFOverrideDispatchHandler : public LLDispatchHandler
class LLGLTFMaterialOverrideDispatchHandler : public LLDispatchHandler
{
LOG_CLASS(LLGLTFOverrideDispatchHandler);
LOG_CLASS(LLGLTFMaterialOverrideDispatchHandler);
public:
LLGLTFOverrideDispatchHandler() = default;
~LLGLTFOverrideDispatchHandler() override = default;
LLGLTFMaterialOverrideDispatchHandler() = default;
~LLGLTFMaterialOverrideDispatchHandler() override = default;
bool operator()(const LLDispatcher* dispatcher, const std::string& key, const LLUUID& invoice, const sparam_t& strings) override
{
// iterate over pairs of parameters
int i;
for (i = 0; i+1 < strings.size(); i += 2)
{
std::string params_json = strings[i];
std::string override_json = strings[i+1];
// receive override data from simulator via LargeGenericMessage
// message should have:
// object_id - UUID of LLViewerObject
// side - S32 index of texture entry
// gltf_json - String of GLTF json for override data
LL_DEBUGS() << "received override: " << params_json << " | " << override_json << LL_ENDL;
Json::Value params;
Json::Reader reader;
bool success = reader.parse(params_json, params);
if (!success)
LLSD message;
sparam_t::const_iterator it = strings.begin();
if (it != strings.end()) {
const std::string& llsdRaw = *it++;
std::istringstream llsdData(llsdRaw);
if (!LLSDSerialize::deserialize(message, llsdData, llsdRaw.length()))
{
LL_WARNS() << "failed to parse override parameters. errors: " << reader.getFormatedErrorMessages() << LL_ENDL;
break;
LL_WARNS() << "LLGLTFMaterialOverrideDispatchHandler: Attempted to read parameter data into LLSD but failed:" << llsdRaw << LL_ENDL;
}
}
LLViewerObject * obj = gObjectList.findObject(message["object_id"].asUUID());
llassert(obj); // should never get an override for an object we don't know about
S32 side = message["side"].asInteger();
std::string gltf_json = message["gltf_json"].asString();
LLViewerObject * obj = gObjectList.findObject(LLUUID(params["object_id"].asString()));
S32 side = params["side"].asInt();
std::string warn_msg, error_msg;
LLPointer<LLGLTFMaterial> override_data = new LLGLTFMaterial();
success = override_data->fromJSON(override_json, warn_msg, error_msg);
// if (!success)
// {
// LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL;
// break;
// }
if(obj)
std::string warn_msg, error_msg;
LLPointer<LLGLTFMaterial> override_data = new LLGLTFMaterial();
bool success = override_data->fromJSON(gltf_json, warn_msg, error_msg);
if (!success)
{
LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL;
}
else
{
if (obj)
{
obj->setTEGLTFMaterialOverride(side, override_data);
}
LL_DEBUGS() << "successfully parsed override: " << override_data->asJSON() << LL_ENDL;
}
LL_WARNS_IF(i != strings.size()) << "parse error or unhandled mismatched odd number of parameters for material override" << LL_ENDL;
return true;
}
};
LLGLTFOverrideDispatchHandler handle_gltf_override_message;
LLGLTFMaterialOverrideDispatchHandler handle_gltf_override_message;
}
LLGLTFMaterialList gGLTFMaterialList;
@ -256,5 +255,5 @@ void LLGLTFMaterialList::flushMaterials()
// static
void LLGLTFMaterialList::registerCallbacks()
{
gGenericDispatcher.addHandler("GLTF", &handle_gltf_override_message);
gGenericDispatcher.addHandler("GLTFMaterialOverride", &handle_gltf_override_message);
}

View File

@ -1401,17 +1401,31 @@ void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 ind
}
}
void LLMaterialEditor::loadLiveMaterial(LLUUID &asset_id)
void LLMaterialEditor::loadLive()
{
LLMaterialEditor* me = (LLMaterialEditor*)LLFloaterReg::getInstance("material_editor", LLSD(LIVE_MATERIAL_EDITOR_KEY));
me->setTitle(me->getString("material_override_title"));
me->setAssetId(asset_id);
if (asset_id.notNull())
if (me->setFromSelection())
{
me->setFromGLTFMaterial(gGLTFMaterialList.getMaterial(asset_id));
me->mIsOverride = true;
me->setTitle(me->getString("material_override_title"));
me->childSetVisible("save", false);
me->childSetVisible("save_as", false);
me->openFloater();
me->setFocus(TRUE);
}
}
void LLMaterialEditor::loadObjectSave()
{
LLMaterialEditor* me = (LLMaterialEditor*)LLFloaterReg::getInstance("material_editor", LLSD(LIVE_MATERIAL_EDITOR_KEY));
if (me->setFromSelection())
{
me->mIsOverride = false;
me->childSetVisible("save", false);
me->openFloater();
me->setFocus(TRUE);
}
me->openFloater();
me->setFocus(TRUE);
}
void LLMaterialEditor::loadFromGLTFMaterial(LLUUID &asset_id)
@ -1872,42 +1886,24 @@ public:
bool apply(LLViewerObject* objectp, S32 te) override
{
// post override from given object and te to the simulator
// requestData should have:
// object_id - UUID of LLViewerObject
// side - S32 index of texture entry
// gltf_json - String of GLTF json for override data
if (objectp && objectp->permModify() && objectp->getVolume())
{
//LLVOVolume* vobjp = (LLVOVolume*)objectp;
S32 local_id = objectp->getLocalID();
LLPointer<LLGLTFMaterial> material = new LLGLTFMaterial();
LLPointer<LLGLTFMaterial> base;
mEditor->getGLTFMaterial(material);
tinygltf::Model model_out;
if(mAssetID != LLUUID::null)
{
base = gGLTFMaterialList.getMaterial(mAssetID);
material->writeOverridesToModel(model_out, 0, base);
}
else
{
material->writeToModel(model_out, 0);
}
std::string overrides_json;
{
tinygltf::TinyGLTF gltf;
std::ostringstream str;
gltf.WriteGltfSceneToStream(&model_out, str, false, false);
overrides_json = str.str();
LL_DEBUGS() << "overrides_json " << overrides_json << LL_ENDL;
}
std::string overrides_json = material->asJSON();
LLSD overrides = llsd::map(
"local_id", local_id,
"object_id", objectp->getID(),
"side", te,
"overrides", overrides_json
"gltf_json", overrides_json
);
LLCoros::instance().launch("modifyMaterialCoro", std::bind(&LLMaterialEditor::modifyMaterialCoro, mEditor, mCapUrl, overrides));
}
@ -1922,7 +1918,7 @@ private:
void LLMaterialEditor::applyToSelection()
{
if (!mKey.isUUID() || mKey.asUUID() != LIVE_MATERIAL_EDITOR_KEY)
if (!mIsOverride)
{
// Only apply if working with 'live' materials
// Might need a better way to distinguish 'live' mode.
@ -1992,6 +1988,28 @@ void LLMaterialEditor::setFromGLTFMaterial(LLGLTFMaterial* mat)
setAlphaCutoff(mat->mAlphaCutoff);
}
bool LLMaterialEditor::setFromSelection()
{
struct LLSelectedTEGetGLTFRenderMaterial : public LLSelectedTEGetFunctor<LLPointer<LLGLTFMaterial> >
{
LLPointer<LLGLTFMaterial> get(LLViewerObject* object, S32 te_index)
{
return object->getTE(te_index)->getGLTFRenderMaterial(); // present user with combined override + asset
}
} func;
LLPointer<LLGLTFMaterial> mat;
LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&func, mat);
if (mat.notNull())
{
setFromGLTFMaterial(mat);
return true;
}
return false;
}
void LLMaterialEditor::loadAsset()
{
// derived from LLPreviewNotecard::loadAsset

View File

@ -103,7 +103,8 @@ public:
// will promt to select specific one
static void loadMaterialFromFile(const std::string& filename, S32 index = -1);
static void loadLiveMaterial(LLUUID &asset_id);
static void loadLive();
static void loadObjectSave();
static void loadFromGLTFMaterial(LLUUID &asset_id);
@ -222,6 +223,7 @@ public:
private:
void setFromGLTFMaterial(LLGLTFMaterial* mat);
bool setFromSelection();
void loadMaterial(const tinygltf::Model &model, const std::string &filename_lc, S32 index);
@ -271,5 +273,8 @@ private:
S32 mExpectedUploadCost;
std::string mMaterialNameShort;
std::string mMaterialName;
// if true, this instance is live instance editing overrides
bool mIsOverride = false;
};

View File

@ -4771,7 +4771,7 @@ void LLPanelFace::onPbrStartEditing()
LL_DEBUGS() << "loading material live editor with asset " << material_id << LL_ENDL;
LLMaterialEditor::loadLiveMaterial(material_id);
LLMaterialEditor::loadLive();
}
bool LLPanelFace::isIdenticalPlanarTexgen()

View File

@ -8877,6 +8877,7 @@ DEF_DUMMY_CHECK_FUNCTOR(int)
DEF_DUMMY_CHECK_FUNCTOR(LLColor4)
DEF_DUMMY_CHECK_FUNCTOR(LLMediaEntry)
DEF_DUMMY_CHECK_FUNCTOR(LLPointer<LLMaterial>)
DEF_DUMMY_CHECK_FUNCTOR(LLPointer<LLGLTFMaterial>)
DEF_DUMMY_CHECK_FUNCTOR(std::string)
DEF_DUMMY_CHECK_FUNCTOR(std::vector<std::string>)

View File

@ -3639,7 +3639,7 @@ void load_life_gltf_material(bool copy)
}
else
{
LLMaterialEditor::loadLiveMaterial(mat_id);
LLMaterialEditor::loadLive();
}
LLViewerJoystick::getInstance()->moveObjects(true);
@ -3648,12 +3648,13 @@ void load_life_gltf_material(bool copy)
void handle_object_edit_gltf_material()
{
load_life_gltf_material(false);
handle_object_edit();
LLMaterialEditor::loadLive();
}
void handle_object_save_gltf_material()
{
load_life_gltf_material(true);
LLMaterialEditor::loadObjectSave();
}
void handle_attachment_edit(const LLUUID& inv_item_id)

View File

@ -5506,6 +5506,9 @@ S32 LLViewerObject::setTEGLTFMaterialOverride(U8 te, LLGLTFMaterial* override_ma
tep->setGLTFMaterialOverride(override_mat);
// if override mat exists, we must also have a source mat
llassert(override_mat ? src_mat : true);
if (override_mat && src_mat)
{
LLFetchedGLTFMaterial* render_mat = new LLFetchedGLTFMaterial(*src_mat);