[Bf-extensions-cvs] [e8da70ab] master: X3D: basic initial port to blender2.8.

Bastien Montagne noreply at git.blender.org
Sat Mar 16 13:00:44 CET 2019


Commit: e8da70ab73d2dd5ff46e47c87cf2da633446670f
Author: Bastien Montagne
Date:   Sat Mar 16 12:05:30 2019 +0100
Branches: master
https://developer.blender.org/rBAe8da70ab73d2dd5ff46e47c87cf2da633446670f

X3D: basic initial port to blender2.8.

That was a rather heavy work, since in 2.7 that add-on was still using
tessellated geometry API quiet extensively (and that one has been
removed from 2.8)...

Also updated some minor things on the road, like e.g. exporting
ColorRGBA for vertex colors, since ours now have some alpha.

Main remaining TODO is materials afaik (those need to be ported to the
new nodeshader wrapper), not very high priority for now.

Also note that the whole code has many sub-optimal handling, but that
whole format is not really designed for heavy geometries anyway I think,
so this is probably fine for now (and going over whole code to optimize
it would be quiet a work too).

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

M	io_scene_x3d/__init__.py
M	io_scene_x3d/export_x3d.py
M	io_scene_x3d/import_x3d.py

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

diff --git a/io_scene_x3d/__init__.py b/io_scene_x3d/__init__.py
index 8115f72e..54377704 100644
--- a/io_scene_x3d/__init__.py
+++ b/io_scene_x3d/__init__.py
@@ -21,8 +21,8 @@
 bl_info = {
     "name": "Web3D X3D/VRML2 format",
     "author": "Campbell Barton, Bart, Bastien Montagne, Seva Alekseyev",
-    "version": (1, 2, 0),
-    "blender": (2, 76, 0),
+    "version": (2, 2, 0),
+    "blender": (2, 80, 0),
     "location": "File > Import-Export",
     "description": "Import-Export X3D, Import VRML2",
     "warning": "",
@@ -152,7 +152,7 @@ class ExportX3D(bpy.types.Operator, ExportHelper):
                                             ))
         global_matrix = axis_conversion(to_forward=self.axis_forward,
                                         to_up=self.axis_up,
-                                        ).to_4x4() * Matrix.Scale(self.global_scale, 4)
+                                        ).to_4x4() @ Matrix.Scale(self.global_scale, 4)
         keywords["global_matrix"] = global_matrix
 
         return export_x3d.save(context, **keywords)
@@ -168,21 +168,27 @@ def menu_func_export(self, context):
                          text="X3D Extensible 3D (.x3d)")
 
 
+classes = (
+    ExportX3D,
+    ImportX3D,
+)
+
+
 def register():
-    bpy.utils.register_module(__name__)
+    for cls in classes:
+        bpy.utils.register_class(cls)
 
     bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
     bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
 
 
 def unregister():
-    bpy.utils.unregister_module(__name__)
-
     bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
     bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
 
-# NOTES
-# - blender version is hardcoded
+    for cls in classes:
+        bpy.utils.unregister_class(cls)
+
 
 if __name__ == "__main__":
     register()
diff --git a/io_scene_x3d/export_x3d.py b/io_scene_x3d/export_x3d.py
index d6c4a293..88ac5ed2 100644
--- a/io_scene_x3d/export_x3d.py
+++ b/io_scene_x3d/export_x3d.py
@@ -53,7 +53,7 @@ def clight_color(col):
 
 
 def matrix_direction_neg_z(matrix):
-    return (matrix.to_3x3() * mathutils.Vector((0.0, 0.0, -1.0))).normalized()[:]
+    return (matrix.to_3x3() @ mathutils.Vector((0.0, 0.0, -1.0))).normalized()[:]
 
 
 def prefix_quoted_str(value, prefix):
@@ -218,6 +218,7 @@ def h3d_is_object_view(scene, obj):
 def export(file,
            global_matrix,
            scene,
+           view_layer,
            use_mesh_modifiers=False,
            use_selection=True,
            use_triangulate=False,
@@ -410,11 +411,11 @@ def export(file,
         fw('%s</Transform>\n' % ident)
         return ident
 
-    def writeSpotLight(ident, obj, matrix, lamp, world):
+    def writeSpotLight(ident, obj, matrix, light, world):
         # note, light_id is not re-used
         light_id = quoteattr(unique_name(obj, LA_ + obj.name, uuid_cache_light, clean_func=clean_def, sep="_"))
 
-        if world:
+        if world and 0:
             ambi = world.ambient_color
             amb_intensity = ((ambi[0] + ambi[1] + ambi[2]) / 3.0) / 2.5
             del ambi
@@ -439,18 +440,18 @@ def export(file,
         fw(ident_step + 'radius="%.4f"\n' % radius)
         fw(ident_step + 'ambientIntensity="%.4f"\n' % amb_intensity)
         fw(ident_step + 'intensity="%.4f"\n' % intensity)
-        fw(ident_step + 'color="%.4f %.4f %.4f"\n' % clight_color(lamp.color))
+        fw(ident_step + 'color="%.4f %.4f %.4f"\n' % clight_color(light.color))
         fw(ident_step + 'beamWidth="%.4f"\n' % beamWidth)
         fw(ident_step + 'cutOffAngle="%.4f"\n' % cutOffAngle)
         fw(ident_step + 'direction="%.4f %.4f %.4f"\n' % orientation)
         fw(ident_step + 'location="%.4f %.4f %.4f"\n' % location)
         fw(ident_step + '/>\n')
 
-    def writeDirectionalLight(ident, obj, matrix, lamp, world):
+    def writeDirectionalLight(ident, obj, matrix, light, world):
         # note, light_id is not re-used
         light_id = quoteattr(unique_name(obj, LA_ + obj.name, uuid_cache_light, clean_func=clean_def, sep="_"))
 
-        if world:
+        if world and 0:
             ambi = world.ambient_color
             # ambi = world.amb
             amb_intensity = ((float(ambi[0] + ambi[1] + ambi[2])) / 3.0) / 2.5
@@ -458,7 +459,7 @@ def export(file,
             ambi = 0
             amb_intensity = 0.0
 
-        intensity = min(lamp.energy / 1.75, 1.0)
+        intensity = min(light.energy / 1.75, 1.0)
 
         orientation = matrix_direction_neg_z(matrix)
 
@@ -466,16 +467,16 @@ def export(file,
         fw('%s<DirectionalLight ' % ident)))
         fw('DEF=%s\n' % light_id)
         fw(ident_step + 'ambientIntensity="%.4f"\n' % amb_intensity)
-        fw(ident_step + 'color="%.4f %.4f %.4f"\n' % clight_color(lamp.color))
+        fw(ident_step + 'color="%.4f %.4f %.4f"\n' % clight_color(light.color))
         fw(ident_step + 'intensity="%.4f"\n' % intensity)
         fw(ident_step + 'direction="%.4f %.4f %.4f"\n' % orientation)
         fw(ident_step + '/>\n')
 
-    def writePointLight(ident, obj, matrix, lamp, world):
+    def writePointLight(ident, obj, matrix, light, world):
         # note, light_id is not re-used
         light_id = quoteattr(unique_name(obj, LA_ + obj.name, uuid_cache_light, clean_func=clean_def, sep="_"))
 
-        if world:
+        if world and 0:
             ambi = world.ambient_color
             # ambi = world.amb
             amb_intensity = ((float(ambi[0] + ambi[1] + ambi[2])) / 3.0) / 2.5
@@ -483,17 +484,17 @@ def export(file,
             ambi = 0.0
             amb_intensity = 0.0
 
-        intensity = min(lamp.energy / 1.75, 1.0)
+        intensity = min(light.energy / 1.75, 1.0)
         location = matrix.to_translation()[:]
 
         ident_step = ident + (' ' * (-len(ident) + \
         fw('%s<PointLight ' % ident)))
         fw('DEF=%s\n' % light_id)
         fw(ident_step + 'ambientIntensity="%.4f"\n' % amb_intensity)
-        fw(ident_step + 'color="%.4f %.4f %.4f"\n' % clight_color(lamp.color))
+        fw(ident_step + 'color="%.4f %.4f %.4f"\n' % clight_color(light.color))
 
         fw(ident_step + 'intensity="%.4f"\n' % intensity)
-        fw(ident_step + 'radius="%.4f" \n' % lamp.distance)
+        fw(ident_step + 'radius="%.4f" \n' % light.distance)
         fw(ident_step + 'location="%.4f %.4f %.4f"\n' % location)
         fw(ident_step + '/>\n')
 
@@ -504,12 +505,10 @@ def export(file,
         mesh_id_coords = prefix_quoted_str(mesh_id, 'coords_')
         mesh_id_normals = prefix_quoted_str(mesh_id, 'normals_')
 
-        # tessellation faces may not exist
-        if not mesh.tessfaces and mesh.polygons:
-            mesh.update(calc_tessface=True)
-
-        if not mesh.tessfaces:
-            return
+        # Be sure tessellated loop triangles are available!
+        if use_triangulate:
+            if not mesh.loop_triangles and mesh.polygons:
+                mesh.calc_loop_triangles()
 
         use_collnode = bool([mod for mod in obj.modifiers
                              if mod.type == 'COLLISION'
@@ -531,7 +530,7 @@ def export(file,
             fw('%s<Group DEF=%s>\n' % (ident, mesh_id_group))
             ident += '\t'
 
-            is_uv = bool(mesh.tessface_uv_textures.active)
+            is_uv = bool(mesh.uv_layers.active)
             # is_col, defined for each material
 
             is_coords_written = False
@@ -545,7 +544,7 @@ def export(file,
             mesh_material_images = [None] * len(mesh_materials)
 
             for i, material in enumerate(mesh_materials):
-                if material:
+                if 0 and material:
                     for mtex in material.texture_slots:
                         if mtex:
                             tex = mtex.texture
@@ -557,44 +556,34 @@ def export(file,
                                     mesh_material_images[i] = image
                                     break
 
-            mesh_materials_use_face_texture = [getattr(material, 'use_face_texture', True) for material in mesh_materials]
-
             # fast access!
             mesh_vertices = mesh.vertices[:]
-            mesh_faces = mesh.tessfaces[:]
-            mesh_faces_materials = [f.material_index for f in mesh_faces]
-            mesh_faces_vertices = [f.vertices[:] for f in mesh_faces]
-
-            if is_uv and True in mesh_materials_use_face_texture:
-                mesh_faces_image = [(fuv.image
-                                     if mesh_materials_use_face_texture[mesh_faces_materials[i]]
-                                     else mesh_material_images[mesh_faces_materials[i]])
-                                     for i, fuv in enumerate(mesh.tessface_uv_textures.active.data)]
-
-                mesh_faces_image_unique = set(mesh_faces_image)
-            elif len(set(mesh_material_images) | {None}) > 1:  # make sure there is at least one image
-                mesh_faces_image = [mesh_material_images[material_index] for material_index in mesh_faces_materials]
-                mesh_faces_image_unique = set(mesh_faces_image)
+            mesh_loops = mesh.loops[:]
+            mesh_polygons = mesh.polygons[:]
+            mesh_polygons_materials = [p.material_index for p in mesh_polygons]
+            mesh_polygons_vertices = [p.vertices[:] for p in mesh_polygons]
+
+            if len(set(mesh_material_images)) > 0:  # make sure there is at least one image
+                mesh_polygons_image = [mesh_material_images[material_index] for material_index in mesh_polygons_materials]
             else:
-                mesh_faces_image = [None] * len(mesh_faces)
-                mesh_faces_image_unique = {None}
+                mesh_polygons_image = [None] * len(mesh_polygons)
+            mesh_polygons_image_unique = set(mesh_polygons_image)
 
             # group faces
-            face_groups = {}
+            polygons_groups = {}
             for material_index in range(len(mesh_materials)):
-                for image in mesh_faces_image_unique:
-                    face_groups[material_index, image] = []
-            del mesh_faces_image_unique
+                for image in mesh_polygons_image_unique:
+                    polygons_groups[material_index, image] = []
+        

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list