[Bf-extensions-cvs] [11bb2337] master: glTF exporter: fix exporting with Draco compression

Julien Duroure noreply at git.blender.org
Tue May 14 20:39:31 CEST 2019


Commit: 11bb2337e021efb6463fcbbb704c955366f0319a
Author: Julien Duroure
Date:   Tue May 14 20:38:46 2019 +0200
Branches: master
https://developer.blender.org/rBA11bb2337e021efb6463fcbbb704c955366f0319a

glTF exporter: fix exporting with Draco compression

===================================================================

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/io/exp/gltf2_io_draco_compression_extension.py

===================================================================

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index 35d80a91..cacf2dca 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": (0, 9, 7),
+    "version": (0, 9, 8),
     'blender': (2, 80, 0),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/io/exp/gltf2_io_draco_compression_extension.py b/io_scene_gltf2/io/exp/gltf2_io_draco_compression_extension.py
index 845e2d2d..1eb8affb 100644
--- a/io_scene_gltf2/io/exp/gltf2_io_draco_compression_extension.py
+++ b/io_scene_gltf2/io/exp/gltf2_io_draco_compression_extension.py
@@ -4,6 +4,7 @@ from ctypes import *
 from pathlib import Path
 
 from io_scene_gltf2.io.exp.gltf2_io_binary_data import BinaryData
+from ...io.com.gltf2_io_debug import print_console
 
 
 def dll_path() -> Path:
@@ -111,18 +112,40 @@ def compress_scene_primitives(scenes, export_settings):
 
     for scene in scenes:
         for node in scene.nodes:
-            __traverse_node(node, dll, export_settings)
+            __traverse_node(node, lambda node: __compress_node(node, dll, export_settings))
 
+    for scene in scenes:
+        for node in scene.nodes:
+            __traverse_node(node, __dispose_memory)
+
+def __dispose_memory(node):
+    """Remove buffers from attribute, since the data now resides inside the compressed Draco buffer."""
+    if not (node.mesh is None):
+        for primitive in node.mesh.primitives:
+
+            # Drop indices.
+            primitive.indices.buffer_view = None
 
-def __traverse_node(node, dll, export_settings):
+            # Drop attributes.
+            attributes = primitive.attributes
+            attributes['POSITION'].buffer_view = None
+            attributes['NORMAL'].buffer_view = None
+            for attribute in [attributes[attr] for attr in attributes if attr.startswith('TEXCOORD_')]:
+                attribute.buffer_view = None
+
+def __compress_node(node, dll, export_settings):
+    """Compress a single node."""
     if not (node.mesh is None):
-        print("Compressing mesh " + node.name)
+        print_console("INFO", "Compressing mesh " + node.name)
         for primitive in node.mesh.primitives:
             __compress_primitive(primitive, dll, export_settings)
 
+def __traverse_node(node, f):
+    """Calls f for each node and all child nodes, recursively."""
+    f(node)
     if not (node.children is None):
         for child in node.children:
-            __traverse_node(child, dll, export_settings)
+            __traverse_node(child)
 
 
 def __compress_primitive(primitive, dll, export_settings):
@@ -151,7 +174,6 @@ def __compress_primitive(primitive, dll, export_settings):
     }
     indices = primitive.indices
     dll.setFaces(compressor, indices.count, index_byte_length[indices.component_type.name], indices.buffer_view.data)
-    indices.buffer_view = None
 
     # Set compression parameters.
     dll.setCompressionLevel(compressor, export_settings['gltf_draco_mesh_compression_level'])
@@ -199,12 +221,6 @@ def __compress_primitive(primitive, dll, export_settings):
         # Set to triangle list mode.
         primitive.mode = 4
 
-        # Remove buffers from attribute, since the data now resides inside the compressed Draco buffer.
-        attributes['POSITION'].buffer_view = None
-        attributes['NORMAL'].buffer_view = None
-        for attribute in [attributes[attr] for attr in attributes if attr.startswith('TEXCOORD_')]:
-            attribute.buffer_view = None
-
     # Afterwards, the compressor can be released.
     dll.disposeCompressor(compressor)



More information about the Bf-extensions-cvs mailing list