Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Duroure <julien.duroure@gmail.com>2020-04-18 09:56:54 +0300
committerJulien Duroure <julien.duroure@gmail.com>2020-04-18 09:56:54 +0300
commitea5bb9d92065a6c7389c1a9e0415c75014cc08e8 (patch)
tree768a70b7ed77a53509aff0efed51e8dc200a0264
parenteedd49c55e70b0a3e118400e1c7ad2e052de975a (diff)
glTF importer: revert using numpy for vertex color colormanagement.
Perf is bad when mesh has lots of primitives
-rwxr-xr-xio_scene_gltf2/__init__.py2
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_primitive.py28
-rw-r--r--io_scene_gltf2/io/com/gltf2_io_color_management.py28
3 files changed, 14 insertions, 44 deletions
diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index f05cd174..47e90dca 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -15,7 +15,7 @@
bl_info = {
'name': 'glTF 2.0 format',
'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
- "version": (1, 2, 63),
+ "version": (1, 2, 64),
'blender': (2, 83, 9),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py b/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py
index a4df6f3f..95688055 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py
@@ -14,8 +14,6 @@
import bpy
from mathutils import Vector, Matrix
-import numpy as np
-# import time
from .gltf2_blender_material import BlenderMaterial
from ...io.imp.gltf2_io_binary import BinaryData
@@ -196,27 +194,19 @@ class BlenderPrimitive():
layer_name = 'Col' if set_num == 0 else 'Col.%03d' % set_num
layer = BlenderPrimitive.get_layer(bme.loops.layers.color, layer_name)
- # colors is a 2d array: [N][3 or 4]
- gltf_attr_name = 'COLOR_%d' % set_num
- colors_raw = BinaryData.get_data_from_accessor(gltf, attributes[gltf_attr_name], cache=True)
- colors = np.array(colors_raw, dtype=np.float32)
-
+ colors = BinaryData.get_data_from_accessor(gltf, attributes['COLOR_%d' % set_num], cache=True)
is_rgba = len(colors[0]) == 4
- if not is_rgba:
- # RGB -> RGBA
- ones = np.ones((colors.shape[0], 1))
- colors = np.concatenate((colors, ones), axis=1) # add alpha channel
-
- srgb_colors = color_linear_to_srgb(colors)
- # t = time.perf_counter()
- # This needs to be a tight loop because it runs over all vertices,
- # which is why this code looks a little odd.
+
for bidx, pidx in vert_idxs:
- color = srgb_colors[pidx]
- col = (color[0], color[1], color[2], color[3]) # fastest this way
+ color = colors[pidx]
+ col = (
+ color_linear_to_srgb(color[0]),
+ color_linear_to_srgb(color[1]),
+ color_linear_to_srgb(color[2]),
+ color[3] if is_rgba else 1.0,
+ )
for loop in bme_verts[bidx].link_loops:
loop[layer] = col
- # print(f'store colors: {time.perf_counter() - t}')
set_num += 1
diff --git a/io_scene_gltf2/io/com/gltf2_io_color_management.py b/io_scene_gltf2/io/com/gltf2_io_color_management.py
index 58dc3a27..31ac5045 100644
--- a/io_scene_gltf2/io/com/gltf2_io_color_management.py
+++ b/io_scene_gltf2/io/com/gltf2_io_color_management.py
@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import numpy as np
def color_srgb_to_scene_linear(c):
"""
@@ -23,34 +22,15 @@ def color_srgb_to_scene_linear(c):
if c < 0.04045:
return 0.0 if c < 0.0 else c * (1.0 / 12.92)
else:
- return pow((c + 0.055) * (1.0 / 1.055), 2.4)
+ return ((c + 0.055) * (1.0 / 1.055)) ** 2.4
def color_linear_to_srgb(c):
"""
Convert from linear to sRGB color space.
Source: Cycles addon implementation, node_color.h.
- c may be a single color value or an array.
-
- If c's last dimension is 4, it's assumed to be RGBA and the
- alpha channel is not converted.
"""
- if type(c) in (list, np.ndarray):
- colors = np.array(c, np.float32) if type(c) == list else c
- if colors.ndim > 1 and colors.shape[-1] == 4:
- colors_noa = colors[..., 0:3] # only process RGB for speed
- else:
- colors_noa = colors
- not_small = colors_noa >= 0.0031308
- small_result = np.where(colors_noa < 0.0, 0.0, colors_noa * 12.92)
- large_result = 1.055 * np.power(colors_noa, 1.0 / 2.4, where=not_small) - 0.055
- result = np.where(not_small, large_result, small_result)
- if colors.ndim > 1 and colors.shape[-1] == 4:
- # copy alpha from original
- result = np.concatenate((result, colors[..., 3, np.newaxis]), axis=-1)
- return result
+ if c < 0.0031308:
+ return 0.0 if c < 0.0 else c * 12.92
else:
- if c < 0.0031308:
- return 0.0 if c < 0.0 else c * 12.92
- else:
- return 1.055 * pow(c, 1.0 / 2.4) - 0.055
+ return 1.055 * c ** (1.0 / 2.4) - 0.055