@@ -162,6 +162,36 @@ void LLPanelFace::updateSelectedGLTFMaterials(std::function<void(LLGLTFMaterial*
162
162
LLSelectMgr::getInstance ()->getSelection ()->applyToTEs (&select_func);
163
163
}
164
164
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
+
165
195
template <typename T>
166
196
void readSelectedGLTFMaterial (std::function<T(const LLGLTFMaterial*)> func, T& value, bool& identical, bool has_tolerance, T tolerance)
167
197
{
@@ -182,6 +212,36 @@ void readSelectedGLTFMaterial(std::function<T(const LLGLTFMaterial*)> func, T& v
182
212
identical = LLSelectMgr::getInstance ()->getSelection ()->getSelectedTEValue (&select_func, value, has_tolerance, tolerance);
183
213
}
184
214
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
+
185
245
BOOST_STATIC_ASSERT (MATTYPE_DIFFUSE == LLRender::DIFFUSE_MAP && MATTYPE_NORMAL == LLRender::NORMAL_MAP && MATTYPE_SPECULAR == LLRender::SPECULAR_MAP);
186
246
187
247
//
@@ -322,6 +382,7 @@ bool LLPanelFace::postBuild()
322
382
323
383
getChildSetCommitCallback (mPBRScaleU , " gltfTextureScaleU" , [&](LLUICtrl*, const LLSD&) { onCommitGLTFTextureScaleU (); });
324
384
getChildSetCommitCallback (mPBRScaleV , " gltfTextureScaleV" , [&](LLUICtrl*, const LLSD&) { onCommitGLTFTextureScaleV (); });
385
+ getChildSetCommitCallback (mPBRRepeat , " gltfRptctrl" , [&](LLUICtrl*, const LLSD&) { onCommitGLTFRepeatsPerMeter (); });
325
386
getChildSetCommitCallback (mPBRRotate , " gltfTextureRotation" , [&](LLUICtrl*, const LLSD&) { onCommitGLTFRotation (); });
326
387
getChildSetCommitCallback (mPBROffsetU , " gltfTextureOffsetU" , [&](LLUICtrl*, const LLSD&) { onCommitGLTFTextureOffsetU (); });
327
388
getChildSetCommitCallback (mPBROffsetV , " gltfTextureOffsetV" , [&](LLUICtrl*, const LLSD&) { onCommitGLTFTextureOffsetV (); });
@@ -1591,74 +1652,112 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/)
1591
1652
F32 repeats_norm = 1 .f ;
1592
1653
F32 repeats_spec = 1 .f ;
1593
1654
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
+
1594
1660
bool identical_diff_repeats = false ;
1595
1661
bool identical_norm_repeats = false ;
1596
1662
bool identical_spec_repeats = false ;
1597
1663
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 ;
1601
1668
1602
1669
{
1670
+ LLSpinCtrl* repeats_spin_ctrl = nullptr ;
1603
1671
S32 index = mComboTexGen ? mComboTexGen ->getCurrentIndex () : 0 ;
1604
1672
bool enabled = editable && (index != 1 );
1605
1673
bool identical_repeats = true ;
1606
1674
S32 material_selection = mComboMatMedia ->getCurrentIndex ();
1607
1675
F32 repeats = 1 .0f ;
1608
1676
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 )
1611
1679
{
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);
1613
1685
}
1614
1686
else if (material_selection == MATMEDIA_PBR)
1615
1687
{
1688
+ repeats_spin_ctrl = mPBRRepeat ;
1616
1689
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);
1618
1700
}
1619
1701
1620
- switch (material_type )
1702
+ switch (material_channel )
1621
1703
{
1622
1704
default :
1623
- case MATTYPE_DIFFUSE :
1705
+ case LLRender::DIFFUSE_MAP :
1624
1706
if (material_selection != MATMEDIA_PBR)
1625
1707
{
1626
1708
enabled = editable && !id.isNull ();
1627
1709
}
1628
1710
identical_repeats = identical_diff_repeats;
1629
1711
repeats = repeats_diff;
1630
1712
break ;
1631
- case MATTYPE_SPECULAR :
1713
+ case LLRender::SPECULAR_MAP :
1632
1714
if (material_selection != MATMEDIA_PBR)
1633
1715
{
1634
1716
enabled = (editable && ((shiny == SHINY_TEXTURE) && !specmap_id.isNull ()));
1635
1717
}
1636
1718
identical_repeats = identical_spec_repeats;
1637
1719
repeats = repeats_spec;
1638
1720
break ;
1639
- case MATTYPE_NORMAL :
1721
+ case LLRender::NORMAL_MAP :
1640
1722
if (material_selection != MATMEDIA_PBR)
1641
1723
{
1642
1724
enabled = (editable && ((bumpy == BUMPY_TEXTURE) && !normmap_id.isNull ()));
1643
1725
}
1644
1726
identical_repeats = identical_norm_repeats;
1645
1727
repeats = repeats_norm;
1646
1728
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 ;
1647
1746
}
1648
1747
1649
1748
bool repeats_tentative = !identical_repeats;
1650
1749
1651
1750
if (force_set_values)
1652
1751
{
1653
1752
// onCommit, previosly edited element updates related ones
1654
- mTexRepeat ->forceSetValue (editable ? repeats : 1 .0f );
1753
+ repeats_spin_ctrl ->forceSetValue (editable ? repeats : 1 .0f );
1655
1754
}
1656
1755
else
1657
1756
{
1658
- mTexRepeat ->setValue (editable ? repeats : 1 .0f );
1757
+ repeats_spin_ctrl ->setValue (editable ? repeats : 1 .0f );
1659
1758
}
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);
1662
1761
}
1663
1762
}
1664
1763
@@ -1804,6 +1903,7 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/)
1804
1903
}
1805
1904
mLabelColorTransp ->setEnabled (false );
1806
1905
mTexRepeat ->setEnabled (false );
1906
+ mPBRRepeat ->setEnabled (false );
1807
1907
mLabelTexGen ->setEnabled (false );
1808
1908
mLabelShininess ->setEnabled (false );
1809
1909
mLabelBumpiness ->setEnabled (false );
@@ -1999,6 +2099,7 @@ void LLPanelFace::updateVisibilityGLTF(LLViewerObject* objectp /*= nullptr */)
1999
2099
mPBRRotate ->setVisible (show_pbr);
2000
2100
mPBROffsetU ->setVisible (show_pbr);
2001
2101
mPBROffsetV ->setVisible (show_pbr);
2102
+ mPBRRepeat ->setVisible (show_pbr);
2002
2103
}
2003
2104
2004
2105
void LLPanelFace::updateCopyTexButton ()
@@ -3693,6 +3794,21 @@ void LLPanelFace::onCommitRepeatsPerMeter()
3693
3794
updateUI (true );
3694
3795
}
3695
3796
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
+
3696
3812
struct LLPanelFaceSetMediaFunctor : public LLSelectedTEFunctor
3697
3813
{
3698
3814
virtual bool apply (LLViewerObject* object, S32 te)
@@ -4642,6 +4758,29 @@ void LLPanelFace::updateGLTFTextureTransform(std::function<void(LLGLTFMaterial::
4642
4758
}
4643
4759
}
4644
4760
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
+
4645
4784
void LLPanelFace::setMaterialOverridesFromSelection ()
4646
4785
{
4647
4786
const LLGLTFMaterial::TextureInfo texture_info = getPBRTextureInfo ();
@@ -4728,6 +4867,12 @@ void LLPanelFace::setMaterialOverridesFromSelection()
4728
4867
mPBRRotate ->setTentative (!rotation_same);
4729
4868
mPBROffsetU ->setTentative (!offset_u_same);
4730
4869
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);
4731
4876
}
4732
4877
4733
4878
void LLPanelFace::Selection::connect ()
0 commit comments