summaryrefslogtreecommitdiff
path: root/indra/llprimitive
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llprimitive')
-rw-r--r--indra/llprimitive/llgltfmaterial.cpp31
-rw-r--r--indra/llprimitive/llgltfmaterial.h8
2 files changed, 39 insertions, 0 deletions
diff --git a/indra/llprimitive/llgltfmaterial.cpp b/indra/llprimitive/llgltfmaterial.cpp
index cc4921416f..930222e3db 100644
--- a/indra/llprimitive/llgltfmaterial.cpp
+++ b/indra/llprimitive/llgltfmaterial.cpp
@@ -923,3 +923,34 @@ void LLGLTFMaterial::updateTextureTracking()
// setTEGLTFMaterialOverride is responsible for tracking
// for material overrides editor will set it
}
+
+void LLGLTFMaterial::convertTextureTransformToPBR(
+ F32 tex_scale_s,
+ F32 tex_scale_t,
+ F32 tex_offset_s,
+ F32 tex_offset_t,
+ F32 tex_rotation,
+ LLVector2& pbr_scale,
+ LLVector2& pbr_offset,
+ F32& pbr_rotation)
+{
+ pbr_scale.set(tex_scale_s, tex_scale_t);
+ pbr_rotation = -(tex_rotation) / 2.f;
+ const F32 adjusted_offset_s = tex_offset_s;
+ const F32 adjusted_offset_t = -tex_offset_t;
+ F32 center_adjust_s = 0.5f * (1.0f - tex_scale_s);
+ F32 center_adjust_t = 0.5f * (1.0f - tex_scale_t);
+
+ if (pbr_rotation != 0.0f)
+ {
+ const F32 c = cosf(pbr_rotation);
+ const F32 s = sinf(pbr_rotation);
+ const F32 tmp_s = center_adjust_s * c - center_adjust_t * s;
+ const F32 tmp_t = center_adjust_s * s + center_adjust_t * c;
+ center_adjust_s = tmp_s;
+ center_adjust_t = tmp_t;
+ }
+
+ pbr_offset.set(adjusted_offset_s + center_adjust_s,
+ adjusted_offset_t + center_adjust_t);
+}
diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h
index 10df4c8ee1..8d45cb6185 100644
--- a/indra/llprimitive/llgltfmaterial.h
+++ b/indra/llprimitive/llgltfmaterial.h
@@ -214,6 +214,14 @@ public:
bool hasLocalTextures() { return !mTrackingIdToLocalTexture.empty(); }
virtual bool replaceLocalTexture(const LLUUID& tracking_id, const LLUUID &old_id, const LLUUID& new_id);
virtual void updateTextureTracking();
+
+ // Convert legacy TE transform values to PBR transform values.
+ static void convertTextureTransformToPBR(F32 tex_scale_s, F32 tex_scale_t,
+ F32 tex_offset_s, F32 tex_offset_t,
+ F32 tex_rotation,
+ LLVector2& pbr_scale,
+ LLVector2& pbr_offset,
+ F32& pbr_rotation);
protected:
static LLVector2 vec2FromJson(const std::map<std::string, tinygltf::Value>& object, const char* key, const LLVector2& default_value);
static F32 floatFromJson(const std::map<std::string, tinygltf::Value>& object, const char* key, const F32 default_value);