Skip to content

Commit 3dc6c22

Browse files
committed
Implemented PBR repeats per meter
1 parent 3e5f4fd commit 3dc6c22

File tree

3 files changed

+177
-15
lines changed

3 files changed

+177
-15
lines changed

indra/newview/llpanelface.cpp

Lines changed: 160 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,36 @@ void LLPanelFace::updateSelectedGLTFMaterials(std::function<void(LLGLTFMaterial*
162162
LLSelectMgr::getInstance()->getSelection()->applyToTEs(&select_func);
163163
}
164164

165+
void LLPanelFace::updateSelectedGLTFMaterialsWithScale(std::function<void(LLGLTFMaterial*, const F32, const F32)> func)
166+
{
167+
struct LLSelectedTEGLTFMaterialFunctor : public LLSelectedTEFunctor
168+
{
169+
LLSelectedTEGLTFMaterialFunctor(std::function<void(LLGLTFMaterial*, const F32, const F32)> func) : mFunc(func) {}
170+
virtual ~LLSelectedTEGLTFMaterialFunctor() {};
171+
bool apply(LLViewerObject* object, S32 face) override
172+
{
173+
LLGLTFMaterial new_override;
174+
const LLTextureEntry* tep = object->getTE(face);
175+
if (tep->getGLTFMaterialOverride())
176+
{
177+
new_override = *tep->getGLTFMaterialOverride();
178+
}
179+
180+
U32 s_axis = VX;
181+
U32 t_axis = VY;
182+
LLPrimitive::getTESTAxes(face, &s_axis, &t_axis);
183+
mFunc(&new_override, object->getScale().mV[s_axis], object->getScale().mV[t_axis]);
184+
LLGLTFMaterialList::queueModify(object, face, &new_override);
185+
186+
return true;
187+
}
188+
189+
std::function<void(LLGLTFMaterial*, const F32, const F32)> mFunc;
190+
} select_func(func);
191+
192+
LLSelectMgr::getInstance()->getSelection()->applyToTEs(&select_func);
193+
}
194+
165195
template<typename T>
166196
void readSelectedGLTFMaterial(std::function<T(const LLGLTFMaterial*)> func, T& value, bool& identical, bool has_tolerance, T tolerance)
167197
{
@@ -182,6 +212,36 @@ void readSelectedGLTFMaterial(std::function<T(const LLGLTFMaterial*)> func, T& v
182212
identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&select_func, value, has_tolerance, tolerance);
183213
}
184214

215+
void getSelectedGLTFMaterialMaxRepeats(LLGLTFMaterial::TextureInfo channel, F32& repeats, bool& identical)
216+
{
217+
// The All channel should read base color values
218+
if (channel == LLGLTFMaterial::TextureInfo::GLTF_TEXTURE_INFO_COUNT)
219+
channel = LLGLTFMaterial::TextureInfo::GLTF_TEXTURE_INFO_BASE_COLOR;
220+
221+
struct LLSelectedTEGetGLTFMaterialMaxRepeatsFunctor : public LLSelectedTEGetFunctor<F32>
222+
{
223+
LLSelectedTEGetGLTFMaterialMaxRepeatsFunctor(LLGLTFMaterial::TextureInfo channel) : mChannel(channel) {}
224+
virtual ~LLSelectedTEGetGLTFMaterialMaxRepeatsFunctor() {};
225+
F32 get(LLViewerObject* object, S32 face) override
226+
{
227+
const LLTextureEntry* tep = object->getTE(face);
228+
const LLGLTFMaterial* render_material = tep->getGLTFRenderMaterial();
229+
if (!render_material)
230+
return 0.f;
231+
232+
U32 s_axis = VX;
233+
U32 t_axis = VY;
234+
LLPrimitive::getTESTAxes(face, &s_axis, &t_axis);
235+
F32 repeats_u = render_material->mTextureTransform[mChannel].mScale[VX] / object->getScale().mV[s_axis];
236+
F32 repeats_v = render_material->mTextureTransform[mChannel].mScale[VY] / object->getScale().mV[t_axis];
237+
return llmax(repeats_u, repeats_v);
238+
}
239+
240+
LLGLTFMaterial::TextureInfo mChannel;
241+
} max_repeats_func(channel);
242+
identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&max_repeats_func, repeats);
243+
}
244+
185245
BOOST_STATIC_ASSERT(MATTYPE_DIFFUSE == LLRender::DIFFUSE_MAP && MATTYPE_NORMAL == LLRender::NORMAL_MAP && MATTYPE_SPECULAR == LLRender::SPECULAR_MAP);
186246

187247
//
@@ -322,6 +382,7 @@ bool LLPanelFace::postBuild()
322382

323383
getChildSetCommitCallback(mPBRScaleU, "gltfTextureScaleU", [&](LLUICtrl*, const LLSD&) { onCommitGLTFTextureScaleU(); });
324384
getChildSetCommitCallback(mPBRScaleV, "gltfTextureScaleV", [&](LLUICtrl*, const LLSD&) { onCommitGLTFTextureScaleV(); });
385+
getChildSetCommitCallback(mPBRRepeat, "gltfRptctrl", [&](LLUICtrl*, const LLSD&) { onCommitGLTFRepeatsPerMeter(); });
325386
getChildSetCommitCallback(mPBRRotate, "gltfTextureRotation", [&](LLUICtrl*, const LLSD&) { onCommitGLTFRotation(); });
326387
getChildSetCommitCallback(mPBROffsetU, "gltfTextureOffsetU", [&](LLUICtrl*, const LLSD&) { onCommitGLTFTextureOffsetU(); });
327388
getChildSetCommitCallback(mPBROffsetV, "gltfTextureOffsetV", [&](LLUICtrl*, const LLSD&) { onCommitGLTFTextureOffsetV(); });
@@ -1591,74 +1652,112 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/)
15911652
F32 repeats_norm = 1.f;
15921653
F32 repeats_spec = 1.f;
15931654

1655+
F32 repeats_pbr_basecolor = 1.f;
1656+
F32 repeats_pbr_metallic_roughness = 1.f;
1657+
F32 repeats_pbr_normal = 1.f;
1658+
F32 repeats_pbr_emissive = 1.f;
1659+
15941660
bool identical_diff_repeats = false;
15951661
bool identical_norm_repeats = false;
15961662
bool identical_spec_repeats = false;
15971663

1598-
LLSelectedTE::getMaxDiffuseRepeats(repeats_diff, identical_diff_repeats);
1599-
LLSelectedTEMaterial::getMaxNormalRepeats(repeats_norm, identical_norm_repeats);
1600-
LLSelectedTEMaterial::getMaxSpecularRepeats(repeats_spec, identical_spec_repeats);
1664+
bool identical_pbr_basecolor_repeats = false;
1665+
bool identical_pbr_metallic_roughness_repeats = false;
1666+
bool identical_pbr_normal_repeats = false;
1667+
bool identical_pbr_emissive_repeats = false;
16011668

16021669
{
1670+
LLSpinCtrl* repeats_spin_ctrl = nullptr;
16031671
S32 index = mComboTexGen ? mComboTexGen->getCurrentIndex() : 0;
16041672
bool enabled = editable && (index != 1);
16051673
bool identical_repeats = true;
16061674
S32 material_selection = mComboMatMedia->getCurrentIndex();
16071675
F32 repeats = 1.0f;
16081676

1609-
U32 material_type = MATTYPE_DIFFUSE;
1610-
if (material_selection == MATMEDIA_MATERIAL)
1677+
LLRender::eTexIndex material_channel = LLRender::DIFFUSE_MAP;
1678+
if (material_selection != MATMEDIA_PBR)
16111679
{
1612-
material_type = mRadioMaterialType->getSelectedIndex();
1680+
repeats_spin_ctrl = mTexRepeat;
1681+
material_channel = getMatTextureChannel();
1682+
LLSelectedTE::getMaxDiffuseRepeats(repeats_diff, identical_diff_repeats);
1683+
LLSelectedTEMaterial::getMaxNormalRepeats(repeats_norm, identical_norm_repeats);
1684+
LLSelectedTEMaterial::getMaxSpecularRepeats(repeats_spec, identical_spec_repeats);
16131685
}
16141686
else if (material_selection == MATMEDIA_PBR)
16151687
{
1688+
repeats_spin_ctrl = mPBRRepeat;
16161689
enabled = editable && has_pbr_material;
1617-
material_type = mRadioPbrType->getSelectedIndex();
1690+
material_channel = getPBRTextureChannel();
1691+
1692+
getSelectedGLTFMaterialMaxRepeats(LLGLTFMaterial::TextureInfo::GLTF_TEXTURE_INFO_BASE_COLOR,
1693+
repeats_pbr_basecolor, identical_pbr_basecolor_repeats);
1694+
getSelectedGLTFMaterialMaxRepeats(LLGLTFMaterial::TextureInfo::GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS,
1695+
repeats_pbr_metallic_roughness, identical_pbr_metallic_roughness_repeats);
1696+
getSelectedGLTFMaterialMaxRepeats(LLGLTFMaterial::TextureInfo::GLTF_TEXTURE_INFO_NORMAL,
1697+
repeats_pbr_normal, identical_pbr_normal_repeats);
1698+
getSelectedGLTFMaterialMaxRepeats(LLGLTFMaterial::TextureInfo::GLTF_TEXTURE_INFO_EMISSIVE,
1699+
repeats_pbr_emissive, identical_pbr_emissive_repeats);
16181700
}
16191701

1620-
switch (material_type)
1702+
switch (material_channel)
16211703
{
16221704
default:
1623-
case MATTYPE_DIFFUSE:
1705+
case LLRender::DIFFUSE_MAP:
16241706
if (material_selection != MATMEDIA_PBR)
16251707
{
16261708
enabled = editable && !id.isNull();
16271709
}
16281710
identical_repeats = identical_diff_repeats;
16291711
repeats = repeats_diff;
16301712
break;
1631-
case MATTYPE_SPECULAR:
1713+
case LLRender::SPECULAR_MAP:
16321714
if (material_selection != MATMEDIA_PBR)
16331715
{
16341716
enabled = (editable && ((shiny == SHINY_TEXTURE) && !specmap_id.isNull()));
16351717
}
16361718
identical_repeats = identical_spec_repeats;
16371719
repeats = repeats_spec;
16381720
break;
1639-
case MATTYPE_NORMAL:
1721+
case LLRender::NORMAL_MAP:
16401722
if (material_selection != MATMEDIA_PBR)
16411723
{
16421724
enabled = (editable && ((bumpy == BUMPY_TEXTURE) && !normmap_id.isNull()));
16431725
}
16441726
identical_repeats = identical_norm_repeats;
16451727
repeats = repeats_norm;
16461728
break;
1729+
case LLRender::NUM_TEXTURE_CHANNELS:
1730+
case LLRender::BASECOLOR_MAP:
1731+
identical_repeats = identical_pbr_basecolor_repeats;
1732+
repeats = repeats_pbr_basecolor;
1733+
break;
1734+
case LLRender::METALLIC_ROUGHNESS_MAP:
1735+
identical_repeats = identical_pbr_metallic_roughness_repeats;
1736+
repeats = repeats_pbr_metallic_roughness;
1737+
break;
1738+
case LLRender::GLTF_NORMAL_MAP:
1739+
identical_repeats = identical_pbr_normal_repeats;
1740+
repeats = repeats_pbr_normal;
1741+
break;
1742+
case LLRender::EMISSIVE_MAP:
1743+
identical_repeats = identical_pbr_emissive_repeats;
1744+
repeats = repeats_pbr_emissive;
1745+
break;
16471746
}
16481747

16491748
bool repeats_tentative = !identical_repeats;
16501749

16511750
if (force_set_values)
16521751
{
16531752
// onCommit, previosly edited element updates related ones
1654-
mTexRepeat->forceSetValue(editable ? repeats : 1.0f);
1753+
repeats_spin_ctrl->forceSetValue(editable ? repeats : 1.0f);
16551754
}
16561755
else
16571756
{
1658-
mTexRepeat->setValue(editable ? repeats : 1.0f);
1757+
repeats_spin_ctrl->setValue(editable ? repeats : 1.0f);
16591758
}
1660-
mTexRepeat->setTentative(LLSD(repeats_tentative));
1661-
mTexRepeat->setEnabled(has_material && !identical_planar_texgen && enabled);
1759+
repeats_spin_ctrl->setTentative(LLSD(repeats_tentative));
1760+
repeats_spin_ctrl->setEnabled(!identical_planar_texgen && enabled);
16621761
}
16631762
}
16641763

@@ -1804,6 +1903,7 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/)
18041903
}
18051904
mLabelColorTransp->setEnabled(false);
18061905
mTexRepeat->setEnabled(false);
1906+
mPBRRepeat->setEnabled(false);
18071907
mLabelTexGen->setEnabled(false);
18081908
mLabelShininess->setEnabled(false);
18091909
mLabelBumpiness->setEnabled(false);
@@ -1999,6 +2099,7 @@ void LLPanelFace::updateVisibilityGLTF(LLViewerObject* objectp /*= nullptr */)
19992099
mPBRRotate->setVisible(show_pbr);
20002100
mPBROffsetU->setVisible(show_pbr);
20012101
mPBROffsetV->setVisible(show_pbr);
2102+
mPBRRepeat->setVisible(show_pbr);
20022103
}
20032104

20042105
void LLPanelFace::updateCopyTexButton()
@@ -3693,6 +3794,21 @@ void LLPanelFace::onCommitRepeatsPerMeter()
36933794
updateUI(true);
36943795
}
36953796

3797+
// Commit the number of GLTF repeats per meter
3798+
void LLPanelFace::onCommitGLTFRepeatsPerMeter()
3799+
{
3800+
F32 repeats_per_meter = (F32)mPBRRepeat->getValue().asReal();
3801+
3802+
LLGLTFMaterial::TextureInfo material_type = getPBRTextureInfo();
3803+
updateGLTFTextureTransformWithScale(material_type, [&](LLGLTFMaterial::TextureTransform* new_transform, F32 scale_s, F32 scale_t)
3804+
{
3805+
new_transform->mScale.mV[VX] = scale_s * repeats_per_meter;
3806+
new_transform->mScale.mV[VY] = scale_t * repeats_per_meter;
3807+
});
3808+
3809+
updateUI(true);
3810+
}
3811+
36963812
struct LLPanelFaceSetMediaFunctor : public LLSelectedTEFunctor
36973813
{
36983814
virtual bool apply(LLViewerObject* object, S32 te)
@@ -4642,6 +4758,29 @@ void LLPanelFace::updateGLTFTextureTransform(std::function<void(LLGLTFMaterial::
46424758
}
46434759
}
46444760

4761+
void LLPanelFace::updateGLTFTextureTransformWithScale(const LLGLTFMaterial::TextureInfo texture_info, std::function<void(LLGLTFMaterial::TextureTransform*, const F32, const F32)> edit)
4762+
{
4763+
if (texture_info == LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT)
4764+
{
4765+
updateSelectedGLTFMaterialsWithScale([&](LLGLTFMaterial* new_override, const F32 scale_s, const F32 scale_t)
4766+
{
4767+
for (U32 i = 0; i < LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT; ++i)
4768+
{
4769+
LLGLTFMaterial::TextureTransform& new_transform = new_override->mTextureTransform[(LLGLTFMaterial::TextureInfo)i];
4770+
edit(&new_transform, scale_s, scale_t);
4771+
}
4772+
});
4773+
}
4774+
else
4775+
{
4776+
updateSelectedGLTFMaterialsWithScale([&](LLGLTFMaterial* new_override, const F32 scale_s, const F32 scale_t)
4777+
{
4778+
LLGLTFMaterial::TextureTransform& new_transform = new_override->mTextureTransform[texture_info];
4779+
edit(&new_transform, scale_s, scale_t);
4780+
});
4781+
}
4782+
}
4783+
46454784
void LLPanelFace::setMaterialOverridesFromSelection()
46464785
{
46474786
const LLGLTFMaterial::TextureInfo texture_info = getPBRTextureInfo();
@@ -4728,6 +4867,12 @@ void LLPanelFace::setMaterialOverridesFromSelection()
47284867
mPBRRotate->setTentative(!rotation_same);
47294868
mPBROffsetU->setTentative(!offset_u_same);
47304869
mPBROffsetV->setTentative(!offset_v_same);
4870+
4871+
F32 repeats = 1.f;
4872+
bool identical = false;
4873+
getSelectedGLTFMaterialMaxRepeats(getPBRDropChannel(), repeats, identical);
4874+
mPBRRepeat->forceSetValue(repeats);
4875+
mPBRRepeat->setTentative(!identical || !scale_u_same || !scale_v_same);
47314876
}
47324877

47334878
void LLPanelFace::Selection::connect()

indra/newview/llpanelface.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ class LLPanelFace : public LLPanel
250250
void onCommitGLTFRotation();
251251
void onCommitGLTFTextureOffsetU();
252252
void onCommitGLTFTextureOffsetV();
253+
void onCommitGLTFRepeatsPerMeter();
253254

254255
void onClickAutoFix();
255256
void onAlignTexture();
@@ -358,6 +359,7 @@ class LLPanelFace : public LLPanel
358359
LLButton* mDelMedia { nullptr };
359360
LLSpinCtrl* mPBRScaleU { nullptr };
360361
LLSpinCtrl* mPBRScaleV { nullptr };
362+
LLSpinCtrl* mPBRRepeat { nullptr };
361363
LLSpinCtrl* mPBRRotate { nullptr };
362364
LLSpinCtrl* mPBROffsetU { nullptr };
363365
LLSpinCtrl* mPBROffsetV { nullptr };
@@ -551,7 +553,9 @@ class LLPanelFace : public LLPanel
551553
void updateVisibilityGLTF(LLViewerObject* objectp = nullptr);
552554

553555
void updateSelectedGLTFMaterials(std::function<void(LLGLTFMaterial*)> func);
556+
void updateSelectedGLTFMaterialsWithScale(std::function<void(LLGLTFMaterial*, const F32, const F32)> func);
554557
void updateGLTFTextureTransform(std::function<void(LLGLTFMaterial::TextureTransform*)> edit);
558+
void updateGLTFTextureTransformWithScale(const LLGLTFMaterial::TextureInfo texture_info, std::function<void(LLGLTFMaterial::TextureTransform*, const F32, const F32)> edit);
555559

556560
void setMaterialOverridesFromSelection();
557561

indra/newview/skins/default/xui/en/panel_tools_texture.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,19 @@
985985
max_val="100"
986986
name="gltfTextureScaleV"
987987
width="265" />
988+
<spinner
989+
decimal_digits="1"
990+
follows="left|top"
991+
height="19"
992+
initial_value=""
993+
label="Repeats per meter"
994+
layout="topleft"
995+
label_width="205"
996+
left="10"
997+
max_val="100"
998+
min_val="-100"
999+
name="gltfRptctrl"
1000+
width="265" />
9881001
<spinner
9891002
follows="left|top"
9901003
height="19"

0 commit comments

Comments
 (0)