secondlife/viewer#712: Remember previously set textures/materials when possible. Not persistent.

master
Cosmic Linden 2024-02-29 16:52:35 -08:00
parent d79498e259
commit 0cb9e7f7e5
4 changed files with 81 additions and 43 deletions

View File

@ -86,7 +86,6 @@
#include "llviewerstats.h"
#include "llviewertexteditor.h"
#include "llviewerwindow.h"
#include "llvlcomposition.h"
#include "lltrans.h"
#include "llagentui.h"
#include "llmeshrepository.h"
@ -100,7 +99,6 @@
#include "llavatarnamecache.h"
#include "llenvironment.h"
const S32 TERRAIN_TEXTURE_COUNT = 4;
const S32 CORNER_COUNT = 4;
const U32 MAX_LISTED_NAMES = 100;
@ -1335,7 +1333,7 @@ BOOL LLPanelRegionTerrainInfo::validateTextureSizes()
}
static const S32 MAX_TERRAIN_TEXTURE_SIZE = 1024;
for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
for(S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
{
std::string buffer;
buffer = llformat("texture_detail_%d", i);
@ -1397,6 +1395,21 @@ BOOL LLPanelRegionTerrainInfo::validateTextureHeights()
/////////////////////////////////////////////////////////////////////////////
// LLPanelRegionTerrainInfo
/////////////////////////////////////////////////////////////////////////////
LLPanelRegionTerrainInfo::LLPanelRegionTerrainInfo()
: LLPanelRegionInfo()
{
const LLUUID (&default_textures)[LLVLComposition::ASSET_COUNT] = LLVLComposition::getDefaultTextures();
for (S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
{
mLastSetTextures[i] = default_textures[i];
}
for (S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
{
mLastSetMaterials[i] = LLUUID::null;
}
}
// Initialize statics
BOOL LLPanelRegionTerrainInfo::postBuild()
@ -1411,12 +1424,12 @@ BOOL LLPanelRegionTerrainInfo::postBuild()
std::string buffer;
for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
for(S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
{
buffer = llformat("texture_detail_%d", i);
initCtrl(buffer);
}
for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
for(S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
{
buffer = llformat("material_detail_%d", i);
initCtrl(buffer);
@ -1462,7 +1475,7 @@ void LLPanelRegionTerrainInfo::updateForMaterialType()
// Toggle visibility of correct swatches
std::string buffer;
LLTextureCtrl* texture_ctrl;
for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
for(S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
{
buffer = llformat("texture_detail_%d", i);
texture_ctrl = getChild<LLTextureCtrl>(buffer);
@ -1471,7 +1484,7 @@ void LLPanelRegionTerrainInfo::updateForMaterialType()
texture_ctrl->setVisible(show_texture_controls);
}
}
for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
for(S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
{
buffer = llformat("material_detail_%d", i);
texture_ctrl = getChild<LLTextureCtrl>(buffer);
@ -1530,8 +1543,8 @@ bool LLPanelRegionTerrainInfo::refreshFromRegion(LLViewerRegion* region)
bool set_texture_swatches;
bool set_material_swatches;
bool clear_texture_swatches;
bool clear_material_swatches;
bool reset_texture_swatches;
bool reset_material_swatches;
LLTerrainMaterials::Type material_type;
if (!textures_ready && !materials_ready)
{
@ -1540,16 +1553,16 @@ bool LLPanelRegionTerrainInfo::refreshFromRegion(LLViewerRegion* region)
material_type = LLTerrainMaterials::Type::TEXTURE;
set_texture_swatches = true;
set_material_swatches = true;
clear_texture_swatches = false;
clear_material_swatches = false;
reset_texture_swatches = false;
reset_material_swatches = false;
}
else
{
material_type = compp->getMaterialType();
set_texture_swatches = material_type == LLTerrainMaterials::Type::TEXTURE;
set_material_swatches = !set_texture_swatches;
clear_texture_swatches = !set_texture_swatches;
clear_material_swatches = !set_material_swatches;
reset_texture_swatches = !set_texture_swatches;
reset_material_swatches = !set_material_swatches;
}
LLComboBox* material_type_ctrl = getChild<LLComboBox>("terrain_material_type");
@ -1560,7 +1573,7 @@ bool LLPanelRegionTerrainInfo::refreshFromRegion(LLViewerRegion* region)
std::string buffer;
if (set_texture_swatches)
{
for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
for(S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
{
buffer = llformat("texture_detail_%d", i);
asset_ctrl = getChild<LLTextureCtrl>(buffer);
@ -1575,7 +1588,7 @@ bool LLPanelRegionTerrainInfo::refreshFromRegion(LLViewerRegion* region)
}
if (set_material_swatches)
{
for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
for(S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
{
buffer = llformat("material_detail_%d", i);
asset_ctrl = getChild<LLTextureCtrl>(buffer);
@ -1588,27 +1601,27 @@ bool LLPanelRegionTerrainInfo::refreshFromRegion(LLViewerRegion* region)
}
}
}
if (clear_texture_swatches)
if (reset_texture_swatches)
{
for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
for(S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
{
buffer = llformat("texture_detail_%d", i);
asset_ctrl = getChild<LLTextureCtrl>(buffer);
if(asset_ctrl)
{
asset_ctrl->setImageAssetID(LLUUID::null);
asset_ctrl->setImageAssetID(mLastSetTextures[i]);
}
}
}
if (clear_material_swatches)
if (reset_material_swatches)
{
for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
for(S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
{
buffer = llformat("material_detail_%d", i);
asset_ctrl = getChild<LLTextureCtrl>(buffer);
if(asset_ctrl)
{
asset_ctrl->setImageAssetID(LLUUID::null);
asset_ctrl->setImageAssetID(mLastSetMaterials[i]);
}
}
}
@ -1687,26 +1700,35 @@ BOOL LLPanelRegionTerrainInfo::sendUpdate()
// terrain_material_type - they both occupy the same slot.
LLComboBox* material_type_ctrl = getChild<LLComboBox>("terrain_material_type");
const TerrainMaterialType material_type = material_type_ctrl ? material_type_from_index(material_type_ctrl->getCurrentIndex()) : TerrainMaterialType::TEXTURE;
for(S32 i = 0; i < TERRAIN_TEXTURE_COUNT; ++i)
{
for(S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
{
if (material_type == TerrainMaterialType::PBR_MATERIAL)
{
buffer = llformat("material_detail_%d", i);
asset_ctrl = getChild<LLTextureCtrl>(buffer);
}
else
{
buffer = llformat("texture_detail_%d", i);
asset_ctrl = getChild<LLTextureCtrl>(buffer);
}
if(asset_ctrl)
{
LLUUID tmp_id(asset_ctrl->getImageAssetID());
tmp_id.toString(id_str);
buffer = llformat("%d %s", i, id_str.c_str());
strings.push_back(buffer);
}
}
asset_ctrl = getChild<LLTextureCtrl>(buffer);
if (!asset_ctrl) { continue; }
LLUUID tmp_id(asset_ctrl->getImageAssetID());
tmp_id.toString(id_str);
buffer = llformat("%d %s", i, id_str.c_str());
strings.push_back(buffer);
// Store asset for later terrain editing
if (material_type == TerrainMaterialType::PBR_MATERIAL)
{
mLastSetMaterials[i] = tmp_id;
}
else
{
mLastSetTextures[i] = tmp_id;
}
}
sendEstateOwnerMessage(msg, "texturedetail", invoice, strings);
strings.clear();

View File

@ -36,6 +36,7 @@
#include "llpanel.h"
#include "llextendedstatus.h"
#include "llpanelenvironment.h"
#include "llvlcomposition.h"
#include "lleventcoro.h"
@ -243,7 +244,7 @@ class LLPanelRegionTerrainInfo : public LLPanelRegionInfo
LOG_CLASS(LLPanelRegionTerrainInfo);
public:
LLPanelRegionTerrainInfo() : LLPanelRegionInfo() {}
LLPanelRegionTerrainInfo();
~LLPanelRegionTerrainInfo() {}
BOOL postBuild() override;
@ -274,6 +275,8 @@ private:
bool mConfirmedTextureHeights;
bool mAskedTextureHeights;
boost::signals2::connection mRegionChangedSlot;
LLUUID mLastSetTextures[LLTerrainMaterials::ASSET_COUNT];
LLUUID mLastSetMaterials[LLTerrainMaterials::ASSET_COUNT];
};
/////////////////////////////////////////////////////////////////////////////

View File

@ -44,7 +44,6 @@
static const U32 BASE_SIZE = 128;
F32 bilinear(const F32 v00, const F32 v01, const F32 v10, const F32 v11, const F32 x_frac, const F32 y_frac)
{
// Not sure if this is the right math...
@ -286,16 +285,29 @@ bool LLTerrainMaterials::materialReady(LLPointer<LLFetchedGLTFMaterial> &mat, bo
return true;
}
// static
const LLUUID (&LLVLComposition::getDefaultTextures())[ASSET_COUNT]
{
const static LLUUID default_textures[LLVLComposition::ASSET_COUNT] =
{
TERRAIN_DIRT_DETAIL,
TERRAIN_GRASS_DETAIL,
TERRAIN_MOUNTAIN_DETAIL,
TERRAIN_ROCK_DETAIL
};
return default_textures;
}
LLVLComposition::LLVLComposition(LLSurface *surfacep, const U32 width, const F32 scale) :
LLTerrainMaterials(),
LLViewerLayer(width, scale)
{
// Load Terrain Textures - Original ones
setDetailAssetID(0, TERRAIN_DIRT_DETAIL);
setDetailAssetID(1, TERRAIN_GRASS_DETAIL);
setDetailAssetID(2, TERRAIN_MOUNTAIN_DETAIL);
setDetailAssetID(3, TERRAIN_ROCK_DETAIL);
const LLUUID (&default_textures)[LLVLComposition::ASSET_COUNT] = LLVLComposition::getDefaultTextures();
for (S32 i = 0; i < ASSET_COUNT; ++i)
{
setDetailAssetID(i, default_textures[i]);
}
mSurfacep = surfacep;

View File

@ -82,6 +82,11 @@ extern LLTerrainMaterials gLocalTerrainMaterials;
class LLVLComposition : public LLTerrainMaterials, public LLViewerLayer
{
public:
// Heights map into textures (or materials) as 0-1 = first, 1-2 = second, etc.
// So we need to compress heights into this range.
static const S32 ASSET_COUNT = 4;
static const LLUUID (&getDefaultTextures())[ASSET_COUNT];
LLVLComposition(LLSurface *surfacep, const U32 width, const F32 scale);
/*virtual*/ ~LLVLComposition();
@ -93,10 +98,6 @@ public:
// Generate texture from composition values.
BOOL generateMinimapTileLand(const F32 x, const F32 y, const F32 width, const F32 height);
// Heights map into textures (or materials) as 0-1 = first, 1-2 = second, etc.
// So we need to compress heights into this range.
static const S32 ASSET_COUNT = 4;
// Use these as indeces ito the get/setters below that use 'corner'
enum ECorner
{