[Bf-blender-cvs] [5acf2e1a95b] soc-2017-vertex_paint: added the addons to script folder, alpha supprt for fbx and oly

Darshan Kadu noreply at git.blender.org
Wed Jul 12 09:13:54 CEST 2017


Commit: 5acf2e1a95b75da0eccbb94e1fc7e18074341b0c
Author: Darshan Kadu
Date:   Wed Jul 12 12:34:17 2017 +0530
Branches: soc-2017-vertex_paint
https://developer.blender.org/rB5acf2e1a95b75da0eccbb94e1fc7e18074341b0c

added the addons to script folder, alpha supprt for fbx and oly

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

A	release/scripts/startup/io_mesh_ply_soc/__init__.py
A	release/scripts/startup/io_mesh_ply_soc/export_ply_soc.py
A	release/scripts/startup/io_mesh_ply_soc/import_ply_soc.py
A	release/scripts/startup/io_scene_fbx_soc/__init__.py
A	release/scripts/startup/io_scene_fbx_soc/data_types.py
A	release/scripts/startup/io_scene_fbx_soc/encode_bin.py
A	release/scripts/startup/io_scene_fbx_soc/export_fbx_bin_soc.py
A	release/scripts/startup/io_scene_fbx_soc/export_fbx_soc.py
A	release/scripts/startup/io_scene_fbx_soc/fbx2json.py
A	release/scripts/startup/io_scene_fbx_soc/fbx_utils.py
A	release/scripts/startup/io_scene_fbx_soc/import_fbx_soc.py
A	release/scripts/startup/io_scene_fbx_soc/json2fbx.py
A	release/scripts/startup/io_scene_fbx_soc/parse_fbx.py
M	source/blender/makesrna/intern/rna_mesh.c

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

diff --git a/release/scripts/startup/io_mesh_ply_soc/__init__.py b/release/scripts/startup/io_mesh_ply_soc/__init__.py
new file mode 100644
index 00000000000..5c7453bafb7
--- /dev/null
+++ b/release/scripts/startup/io_mesh_ply_soc/__init__.py
@@ -0,0 +1,205 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8-80 compliant>
+
+bl_info = {
+    "name": "Stanford PLY format-soc",
+    "author": "Bruce Merry, Campbell Barton",
+    "blender": (2, 74, 0),
+    "location": "File > Import-Export",
+    "description": "Import-Export PLY mesh data withs UV's and vertex colors-soc",
+    "warning": "",
+    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
+                "Scripts/Import-Export/Stanford_PLY",
+    "support": 'OFFICIAL',
+    "category": "Import-Export"}
+
+# Copyright (C) 2004, 2005: Bruce Merry, bmerry at cs.uct.ac.za
+# Contributors: Bruce Merry, Campbell Barton
+
+# To support reload properly, try to access a package var,
+# if it's there, reload everything
+if "bpy" in locals():
+    import importlib
+    if "export_ply_soc" in locals():
+        importlib.reload(export_ply_soc)
+    if "import_ply_soc" in locals():
+        importlib.reload(import_ply_soc)
+
+
+import os
+import bpy
+from bpy.props import (
+        CollectionProperty,
+        StringProperty,
+        BoolProperty,
+        EnumProperty,
+        FloatProperty,
+        )
+from bpy_extras.io_utils import (
+        ImportHelper,
+        ExportHelper,
+        orientation_helper_factory,
+        axis_conversion,
+        )
+
+
+IOPLYOrientationHelper = orientation_helper_factory("IOPLYOrientationHelper", axis_forward='Y', axis_up='Z')
+
+
+class SocImportPLY(bpy.types.Operator, ImportHelper):
+    """Load a PLY geometry file"""
+    bl_idname = "import_mesh_soc.ply"
+    bl_label = "Import PLY soc"
+    bl_options = {'UNDO'}
+
+    files = CollectionProperty(name="File Path",
+                          description="File path used for importing "
+                                      "the PLY file",
+                          type=bpy.types.OperatorFileListElement)
+
+    directory = StringProperty()
+
+    filename_ext = ".ply"
+    filter_glob = StringProperty(default="*.ply", options={'HIDDEN'})
+
+    def execute(self, context):
+        paths = [os.path.join(self.directory, name.name)
+                 for name in self.files]
+        if not paths:
+            paths.append(self.filepath)
+
+        from . import import_ply_soc
+
+        for path in paths:
+            import_ply_soc.load(self, context, path)
+
+        return {'FINISHED'}
+
+
+class SocExportPLY(bpy.types.Operator, ExportHelper, IOPLYOrientationHelper):
+    """Export a single object as a Stanford PLY with normals, """ \
+    """colors and texture coordinates"""
+    bl_idname = "export_mesh_soc.ply"
+    bl_label = "Export PLY soc"
+
+    filename_ext = ".ply"
+    filter_glob = StringProperty(default="*.ply", options={'HIDDEN'})
+
+    use_mesh_modifiers = BoolProperty(
+            name="Apply Modifiers",
+            description="Apply Modifiers to the exported mesh",
+            default=True,
+            )
+    use_normals = BoolProperty(
+            name="Normals",
+            description="Export Normals for smooth and "
+                        "hard shaded faces "
+                        "(hard shaded faces will be exported "
+                        "as individual faces)",
+            default=True,
+            )
+    use_uv_coords = BoolProperty(
+            name="UVs",
+            description="Export the active UV layer",
+            default=True,
+            )
+    use_colors = BoolProperty(
+            name="Vertex Colors",
+            description="Export the active vertex color layer",
+            default=True,
+            )
+
+    global_scale = FloatProperty(
+            name="Scale",
+            min=0.01, max=1000.0,
+            default=1.0,
+            )
+
+    @classmethod
+    def poll(cls, context):
+        return context.active_object is not None
+
+    def execute(self, context):
+        from . import export_ply_soc
+
+        from mathutils import Matrix
+
+        keywords = self.as_keywords(ignore=("axis_forward",
+                                            "axis_up",
+                                            "global_scale",
+                                            "check_existing",
+                                            "filter_glob",
+                                            ))
+        global_matrix = axis_conversion(to_forward=self.axis_forward,
+                                        to_up=self.axis_up,
+                                        ).to_4x4() * Matrix.Scale(self.global_scale, 4)
+        keywords["global_matrix"] = global_matrix
+
+        filepath = self.filepath
+        filepath = bpy.path.ensure_ext(filepath, self.filename_ext)
+
+        return export_ply_soc.save(self, context, **keywords)
+
+    def draw(self, context):
+        layout = self.layout
+
+        row = layout.row()
+        row.prop(self, "use_mesh_modifiers")
+        row.prop(self, "use_normals")
+        row = layout.row()
+        row.prop(self, "use_uv_coords")
+        row.prop(self, "use_colors")
+
+        layout.prop(self, "axis_forward")
+        layout.prop(self, "axis_up")
+        layout.prop(self, "global_scale")
+
+
+def menu_func_import(self, context):
+    self.layout.operator(SocImportPLY.bl_idname, text="Stanford (.ply)")
+
+
+def menu_func_export(self, context):
+    self.layout.operator(SocExportPLY.bl_idname, text="Stanford (.ply)")
+
+
+classes = (
+    SocImportPLY,
+    SocExportPLY,
+    )
+
+
+def register():
+    for cls in classes:
+        bpy.utils.register_class(cls)
+
+    bpy.types.INFO_MT_file_import.append(menu_func_import)
+    bpy.types.INFO_MT_file_export.append(menu_func_export)
+
+
+def unregister():
+    for cls in classes:
+        bpy.utils.unregister_class(cls)
+
+    bpy.types.INFO_MT_file_import.remove(menu_func_import)
+    bpy.types.INFO_MT_file_export.remove(menu_func_export)
+
+if __name__ == "__main__":
+    register()
diff --git a/release/scripts/startup/io_mesh_ply_soc/export_ply_soc.py b/release/scripts/startup/io_mesh_ply_soc/export_ply_soc.py
new file mode 100644
index 00000000000..8c60d3baae7
--- /dev/null
+++ b/release/scripts/startup/io_mesh_ply_soc/export_ply_soc.py
@@ -0,0 +1,228 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8-80 compliant>
+
+"""
+This script exports Stanford PLY files from Blender. It supports normals,
+colors, and texture coordinates per face or per vertex.
+Only one mesh can be exported at a time.
+"""
+
+import bpy
+import os
+
+
+def save_mesh(filepath,
+              mesh,
+              use_normals=True,
+              use_uv_coords=True,
+              use_colors=True,
+              ):
+
+    def rvec3d(v):
+        return round(v[0], 6), round(v[1], 6), round(v[2], 6)
+
+    def rvec2d(v):
+        return round(v[0], 6), round(v[1], 6)
+
+    file = open(filepath, "w", encoding="utf8", newline="\n")
+    fw = file.write
+
+    # Be sure tessface & co are available!
+    if not mesh.tessfaces and mesh.polygons:
+        mesh.calc_tessface()
+
+    has_uv = bool(mesh.tessface_uv_textures)
+    has_vcol = bool(mesh.tessface_vertex_colors)
+
+    if not has_uv:
+        use_uv_coords = False
+    if not has_vcol:
+        use_colors = False
+
+    if not use_uv_coords:
+        has_uv = False
+    if not use_colors:
+        has_vcol = False
+
+    if has_uv:
+        active_uv_layer = mesh.tessface_uv_textures.active
+        if not active_uv_layer:
+            use_uv_coords = False
+            has_uv = False
+        else:
+            active_uv_layer = active_uv_layer.data
+
+    if has_vcol:
+        active_col_layer = mesh.tessface_vertex_colors.active
+        if not active_col_layer:
+            use_colors = False
+            has_vcol = False
+        else:
+            active_col_layer = active_col_layer.data
+
+    # in case
+    color = uvcoord = uvcoord_key = normal = normal_key = None
+
+    mesh_verts = mesh.vertices  # save a lookup
+    ply_verts = []  # list of dictionaries
+    # vdict = {} # (index, normal, uv) -> new index
+    vdict = [{} for i in range(len(mesh_verts))]
+    ply_faces = [[] for f in range(len(mesh.tessfaces))]
+    vert_count = 0
+    for i, f in enumerate(mesh.tessfaces):
+
+        smooth = not use_normals or f.use_smooth
+        if not smooth:
+            normal = f.normal[:]
+            normal_key = rvec3d(normal)
+
+        if has_uv:
+            uv = active_uv_layer[i]
+            uv = uv.uv1, uv.uv2, uv.uv3, uv.uv4
+        if has_vcol:
+            col = active_col_lay

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list