Blender Image.pixels 对 sRGB 贴图返回线性值,直接写 Non-Color PNG 会偏暗; 现按 Unity sRGB 导入预期编码 RGB,alpha(AO/透明)保持原值。附单元测试。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
24 lines
705 B
Python
24 lines
705 B
Python
import os
|
|
import sys
|
|
import unittest
|
|
|
|
import numpy as np
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
import bl_convert as bc
|
|
|
|
|
|
class TestBaseTextureEncoding(unittest.TestCase):
|
|
def test_base_texture_rgb_is_encoded_as_srgb_and_alpha_is_preserved(self):
|
|
rgba = np.array([[[0.0, 0.18, 0.5, 0.37]]], dtype=np.float32)
|
|
|
|
encoded = bc.encode_base_texture_for_png(rgba)
|
|
|
|
expected_rgb = np.array([0.0, 0.461356, 0.735357], dtype=np.float32)
|
|
np.testing.assert_allclose(encoded[0, 0, :3], expected_rgb, rtol=0, atol=1e-5)
|
|
self.assertAlmostEqual(float(encoded[0, 0, 3]), 0.37, places=6)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|