[Bf-blender-cvs] [02b81b3] wiggly-widgets: Add python exporter that exports a mesh in a C file in a renderer-ready format (vertices + normals + triangle vertex indices)

Antony Riakiotakis noreply at git.blender.org
Wed Oct 8 15:50:40 CEST 2014


Commit: 02b81b3bca64edfdd80728ee71f4bc483130ffd4
Author: Antony Riakiotakis
Date:   Wed Oct 8 15:50:30 2014 +0200
Branches: wiggly-widgets
https://developer.blender.org/rB02b81b3bca64edfdd80728ee71f4bc483130ffd4

Add python exporter that exports a mesh in a C file in a renderer-ready
format (vertices + normals + triangle vertex indices)

This will allow us to create widgets in blender instead of defining them
programmatically.

May also support facegroups for different colors in the future though
they must be somehow tied to the UI colors.

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

A	release/datafiles/widget_export.py
A	source/blender/editors/interface/3d_widgets/arrow_widget.c
A	source/blender/editors/interface/3d_widgets/ui_widget_library.h
M	source/blender/editors/interface/CMakeLists.txt
M	source/blender/editors/interface/interface_generic_widgets.c
M	source/blender/windowmanager/intern/wm_widgets.c

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

diff --git a/release/datafiles/widget_export.py b/release/datafiles/widget_export.py
new file mode 100644
index 0000000..b43c616
--- /dev/null
+++ b/release/datafiles/widget_export.py
@@ -0,0 +1,79 @@
+import bpy
+from bpy.types import Operator
+from bpy.props import StringProperty
+from bpy_extras.io_utils import ExportHelper
+
+def mesh_triangulate(me):
+    import bmesh
+    bm = bmesh.new()
+    bm.from_mesh(me)
+    bmesh.ops.triangulate(bm, faces=bm.faces)
+    bm.to_mesh(me)
+    bm.free()
+    
+
+class ExportWidget(Operator, ExportHelper):
+    """Export a widget mesh as a C file"""
+    bl_idname = "export_scene.widget"
+    bl_label = "Export Widget"
+    bl_options = {'PRESET', 'UNDO'}
+
+    filename_ext = ".c"
+    filter_glob = StringProperty(
+            default="*.c;",
+            options={'HIDDEN'},
+            )
+    @classmethod
+    def poll(cls, context):
+        obj = context.active_object
+        return (obj and obj.type == 'MESH')
+
+    def execute(self, context):
+        ob = context.active_object
+        scene = context.scene
+
+        try:
+            me = ob.to_mesh(scene, True, 'PREVIEW', calc_tessface=False)
+        except RuntimeError:
+            me = None
+
+        if me is None:
+            return {'CANCELLED'}
+
+        mesh_triangulate(me)
+
+        name = ob.name
+        f = open(self.filepath, 'w')
+        f.write("int _WIDGET_nverts_%s = %d;\n" % (name, len(me.vertices)))
+        f.write("int _WIDGET_nfaces_%s = %d;\n\n" % (name, len(me.polygons)))
+        f.write("float _WIDGET_verts_%s[][3] = {\n" % name)
+        for v in me.vertices:
+            f.write("    {%.6f, %.6f, %.6f},\n" % v.co[:])            
+        f.write("};\n\n")
+        f.write("float _WIDGET_normals_%s[][3] = {\n" % name)
+        for v in me.vertices:
+            f.write("    {%.6f, %.6f, %.6f},\n" % v.normal[:])            
+        f.write("};\n\n")
+        f.write("unsigned short _WIDGET_indices_%s[] = {\n" % name)
+        for p in me.polygons:
+            f.write("    %d, %d, %d,\n" % p.vertices[:])            
+        f.write("};\n")
+        f.close()
+        
+        return {'FINISHED'}
+
+def menu_func_export(self, context):
+    self.layout.operator(ExportWidget.bl_idname, text="Widget (.c)")
+
+        
+def register():
+   bpy.utils.register_module(__name__)
+   bpy.types.INFO_MT_file_export.append(menu_func_export)
+
+
+def unregister():
+    bpy.utils.unregister_module(__name__)
+    bpy.types.INFO_MT_file_export.remove(menu_func_export)
+
+if __name__ == "__main__":
+    register()
diff --git a/source/blender/editors/interface/3d_widgets/arrow_widget.c b/source/blender/editors/interface/3d_widgets/arrow_widget.c
new file mode 100644
index 0000000..feb9ca8
--- /dev/null
+++ b/source/blender/editors/interface/3d_widgets/arrow_widget.c
@@ -0,0 +1,249 @@
+int _WIDGET_nverts_arrow = 81;
+int _WIDGET_nfaces_arrow = 76;
+
+float _WIDGET_verts_arrow[][3] = {
+    {0.069024, 0.069024, 0.001571},
+    {0.090184, 0.037355, 0.001571},
+    {0.097614, 0.000000, 0.001571},
+    {0.090184, -0.037355, 0.001571},
+    {0.069024, -0.069024, 0.001571},
+    {0.037355, -0.090184, 0.001571},
+    {-0.000000, -0.097614, 0.001571},
+    {-0.037356, -0.090184, 0.001571},
+    {-0.069024, -0.069024, 0.001571},
+    {-0.090184, -0.037355, 0.001571},
+    {-0.097615, -0.000000, 0.001571},
+    {-0.090184, 0.037355, 0.001571},
+    {-0.069024, 0.069024, 0.001571},
+    {-0.037356, 0.090184, 0.001571},
+    {-0.000000, 0.097614, 0.001571},
+    {0.037355, 0.090184, 0.001571},
+    {-0.000000, 0.393391, 2.000000},
+    {-0.150544, 0.363446, 2.000000},
+    {-0.278169, 0.278169, 2.000000},
+    {-0.363446, 0.150544, 2.000000},
+    {-0.393391, -0.000000, 2.000000},
+    {-0.363446, -0.150544, 2.000000},
+    {-0.278169, -0.278169, 2.000000},
+    {-0.150544, -0.363446, 2.000000},
+    {-0.000000, -0.393391, 2.000000},
+    {0.150544, -0.363446, 2.000000},
+    {0.278169, -0.278169, 2.000000},
+    {0.363446, -0.150544, 2.000000},
+    {0.393391, 0.000000, 2.000000},
+    {0.363446, 0.150544, 2.000000},
+    {0.278169, 0.278169, 2.000000},
+    {0.150544, 0.363446, 2.000000},
+    {-0.000000, 0.393391, 2.000000},
+    {-0.150544, 0.363446, 2.000000},
+    {-0.278169, 0.278169, 2.000000},
+    {-0.363446, 0.150544, 2.000000},
+    {-0.393391, -0.000000, 2.000000},
+    {-0.363446, -0.150544, 2.000000},
+    {-0.278169, -0.278169, 2.000000},
+    {-0.150544, -0.363446, 2.000000},
+    {-0.000000, -0.393391, 2.000000},
+    {0.150544, -0.363446, 2.000000},
+    {0.278169, -0.278169, 2.000000},
+    {0.363446, -0.150544, 2.000000},
+    {0.393391, 0.000000, 2.000000},
+    {0.363446, 0.150544, 2.000000},
+    {0.278169, 0.278169, 2.000000},
+    {0.150544, 0.363446, 2.000000},
+    {-0.000000, -0.000000, 3.000072},
+    {0.069024, 0.069024, 0.001571},
+    {0.090184, 0.037355, 0.001571},
+    {0.097614, 0.000000, 0.001571},
+    {0.090184, -0.037355, 0.001571},
+    {0.069024, -0.069024, 0.001571},
+    {0.037355, -0.090184, 0.001571},
+    {-0.000000, -0.097614, 0.001571},
+    {-0.037356, -0.090184, 0.001571},
+    {-0.069024, -0.069024, 0.001571},
+    {-0.090184, -0.037355, 0.001571},
+    {-0.097615, -0.000000, 0.001571},
+    {-0.090184, 0.037355, 0.001571},
+    {-0.069024, 0.069024, 0.001571},
+    {-0.037356, 0.090184, 0.001571},
+    {-0.000000, 0.097614, 0.001571},
+    {0.037355, 0.090184, 0.001571},
+    {0.069024, 0.069024, 2.021901},
+    {0.090184, 0.037355, 2.021901},
+    {0.097614, 0.000000, 2.021901},
+    {0.090184, -0.037355, 2.021901},
+    {0.069024, -0.069024, 2.021901},
+    {0.037355, -0.090184, 2.021901},
+    {-0.000000, -0.097614, 2.021901},
+    {-0.037356, -0.090184, 2.021901},
+    {-0.069024, -0.069024, 2.021901},
+    {-0.090184, -0.037355, 2.021901},
+    {-0.097615, -0.000000, 2.021901},
+    {-0.090184, 0.037355, 2.021901},
+    {-0.069024, 0.069024, 2.021901},
+    {-0.037356, 0.090184, 2.021901},
+    {-0.000000, 0.097614, 2.021901},
+    {0.037355, 0.090184, 2.021901},
+};
+
+float _WIDGET_normals_arrow[][3] = {
+    {0.000000, 0.000000, -1.000000},
+    {0.000000, 0.000000, -1.000000},
+    {0.000000, 0.000000, -1.000000},
+    {0.000000, 0.000000, -1.000000},
+    {0.000000, 0.000000, -1.000000},
+    {0.000000, 0.000000, -1.000000},
+    {0.000000, 0.000000, -1.000000},
+    {0.000000, 0.000000, -1.000000},
+    {0.000000, 0.000000, -1.000000},
+    {0.000000, 0.000000, -1.000000},
+    {0.000000, 0.000000, -1.000000},
+    {0.000000, 0.000000, -1.000000},
+    {0.000000, 0.000000, -1.000000},
+    {0.000000, 0.000000, -1.000000},
+    {0.000000, 0.000000, -1.000000},
+    {0.000000, 0.000000, -1.000000},
+    {0.000000, 0.000000, 1.000000},
+    {0.000000, 0.000000, 1.000000},
+    {0.000000, 0.000000, 1.000000},
+    {0.000000, 0.000000, 1.000000},
+    {0.000000, 0.000000, 1.000000},
+    {0.000000, 0.000000, 1.000000},
+    {0.000000, 0.000000, 1.000000},
+    {0.000000, 0.000000, 1.000000},
+    {0.000000, 0.000000, 1.000000},
+    {0.000000, 0.000000, 1.000000},
+    {0.000000, 0.000000, 1.000000},
+    {0.000000, 0.000000, 1.000000},
+    {0.000000, 0.000000, 1.000000},
+    {0.000000, 0.000000, 1.000000},
+    {0.000000, 0.000000, 1.000000},
+    {0.000000, 0.000000, 1.000000},
+    {0.000000, 0.930570, 0.366039},
+    {-0.356120, 0.859737, 0.366039},
+    {-0.658010, 0.658010, 0.366039},
+    {-0.859737, 0.356120, 0.366039},
+    {-0.930570, 0.000000, 0.366039},
+    {-0.859737, -0.356120, 0.366039},
+    {-0.658010, -0.658010, 0.366039},
+    {-0.356120, -0.859737, 0.366039},
+    {0.000000, -0.930570, 0.366039},
+    {0.356120, -0.859737, 0.366039},
+    {0.658010, -0.658010, 0.366039},
+    {0.859737, -0.356120, 0.366039},
+    {0.930570, 0.000000, 0.366039},
+    {0.859737, 0.356120, 0.366039},
+    {0.658010, 0.658010, 0.366039},
+    {0.356120, 0.859737, 0.366039},
+    {0.000000, 0.000000, 1.000000},
+    {0.707083, 0.707083, 0.000000},
+    {0.923856, 0.382672, 0.000000},
+    {1.000000, 0.000000, 0.000000},
+    {0.923856, -0.382672, 0.000000},
+    {0.707083, -0.707083, 0.000000},
+    {0.382672, -0.923856, 0.000000},
+    {0.000000, -1.000000, 0.000000},
+    {-0.382672, -0.923856, 0.000000},
+    {-0.707083, -0.707083, 0.000000},
+    {-0.923856, -0.382672, 0.000000},
+    {-1.000000, 0.000000, 0.000000},
+    {-0.923856, 0.382672, 0.000000},
+    {-0.707083, 0.707083, 0.000000},
+    {-0.382672, 0.923856, 0.000000},
+    {0.000000, 1.000000, 0.000000},
+    {0.382672, 0.923856, 0.000000},
+    {0.707083, 0.707083, 0.000000},
+    {0.923856, 0.382672, 0.000000},
+    {1.000000, 0.000000, 0.000000},
+    {0.923856, -0.382672, 0.000000},
+    {0.707083, -0.707083, 0.000000},
+    {0.382672, -0.923856, 0.000000},
+    {0.000000, -1.000000, 0.000000},
+    {-0.382672, -0.923856, 0.000000},
+    {-0.707083, -0.707083, 0.000000},
+    {-0.923856, -0.382672, 0.000000},
+    {-1.000000, 0.000000, 0.000000},
+    {-0.923856, 0.382672, 0.000000},
+    {-0.707083, 0.707083, 0.000000},
+    {-0.382672, 0.923856, 0.000000},
+    {0.000000, 1.000000, 0.000000},
+    {0.382672, 0.923856, 0.000000},
+};
+
+unsigned short _WIDGET_indices_arrow[] = {
+    1, 13, 14,
+    49, 65, 66,
+    62, 78, 79,
+    51, 67, 68,
+    53, 69, 70,
+    55, 71, 72,
+    57, 73, 74,
+    59, 75, 76,
+    64, 80, 65,
+    61, 77, 78,
+    50, 66, 67,
+    52, 68, 69,
+    54, 70, 71,
+    56, 72, 73,
+    20, 21, 22,
+    39, 40, 48,
+    37, 38, 48,
+    35, 36, 48,
+    46, 47, 48,
+    33, 34, 48,
+    44, 45, 48,
+    42, 43, 48,
+    40, 41, 48,
+    38, 39, 48,
+    36, 37, 48,
+    47, 32, 48,
+    34, 35, 48,
+    45, 46, 48,
+    32, 33, 48,
+    43, 44, 48,
+    41, 42, 48,
+    60, 76, 77,
+    63, 79, 80,
+    58, 74, 75,
+    11, 12, 13,
+    11, 13, 10,
+    7, 8, 9,
+    7, 13, 6,
+    3, 4, 5,
+    3, 6, 2,
+    15, 0, 1,
+    15, 1, 14,
+    10, 13, 7,
+    9, 10, 7,
+    5, 6, 3,
+    63, 62, 79,
+    50, 49, 66,
+    6, 1, 2,
+    6, 13, 1,
+    52, 51, 68,
+    54, 53, 70,
+    56, 55, 72,
+    58, 57, 74,
+    60, 59, 76,
+    49, 64, 65,
+    62, 61, 78,
+    51, 50, 67,
+    53, 52, 69,
+    55, 54, 71,
+    57, 56, 73,
+    30, 31, 25,
+    20, 17, 18,
+    29, 30, 28,
+  

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list