Example #1
0
def main():
    # get the args passed to blender after "--", all of which are ignored by
    # blender so scripts may receive their own arguments
    argv = sys.argv

    if "--" not in argv:
        argv = []  # as if no args are passed
    else:
        argv = argv[argv.index("--") + 1:]  # get all args after "--"

    # When --help or no args are given, print this help
    usage_text = "Run blender in background mode with this script:" \
                 "blender --background --python {} -- [options]".format(__file__)

    parser = argparse.ArgumentParser(description=usage_text)

    # Example utility, add some text and renders or saves it (with options)
    # Possible types are: string, int, long, choice, float and complex.
    parser.add_argument("-o", "--output", dest="save_path", metavar='FILE|PATH',
                        help="Save the generated file to the specified path")
    parser.add_argument("-a", "--enable-animation", dest="enable_animation", action="store_true", default=False,
                        help="Enable saving of animations")
    parser.add_argument("-L", "--enable-level-of-detail", dest="enable_lod", action="store_true", default=True,
                        help="Export levels of detail")
    parser.add_argument("-d", "--max-lod-distance", dest="max_lod_distance", action="store_true", default=True,
                        help="Maximum LOD distance")
    parser.add_argument("-b", "--bake-all", dest="bake_all", action="store_true", default=False,
                        help="Force animation baking")
    parser.add_argument("-q", "--bake-quaternions", dest="use_quaternions", action="store_true", default=False,
                        help="Use quaternions for rotation baking")
    parser.add_argument("-m", "--apply-modifiers", dest="apply_modifiers", action="store_true", default=False,
                        help="Apply modifiers before exporting")
    parser.add_argument("-r", "--armature-rest", dest="arm_rest", action="store_true", default=False,
                        help="Export static armature in rest position")
    parser.add_argument("-j", "--json-materials", dest="json_materials", action="store_true", default=False,
                        help="Store materials into JSON format")
    parser.add_argument("-s", "--json-shaders", dest="json_shaders", action="store_true", default=False,
                        help="Store shader graphs into JSON format")
    parser.add_argument("--use-scene-fps", dest="use_scene_fps", action="store_true", default=False,
                        help="Use current scene FPS")

    args = parser.parse_args(argv)  # In this example we wont use the args

    if args.save_path is None:
        print("\n*** No output filename specified (use -o)")
    else:
        config = osgconf.Config()
        config.initFilePaths(args.save_path)
        config.export_anim = args.enable_animation
        config.export_lod = args.enable_lod
        config.bake_animations = args.bake_all
        config.use_quaternions = args.use_quaternions
        config.apply_modifiers = args.apply_modifiers
        config.arm_rest = args.arm_rest
        config.scene = bpy.context.scene
        config.json_materials = args.json_materials
        config.json_shaders = args.json_shaders
        if args.use_scene_fps:
            config.anim_fps = config.scene.render.fps
        OpenSceneGraphExport(config)
Example #2
0
def main():
    import sys  # to get command line args
    import argparse  # to parse options for us and print a nice help message

    # get the args passed to blender after "--", all of which are ignored by
    # blender so scripts may receive their own arguments
    argv = sys.argv

    if "--" not in argv:
        argv = []  # as if no args are passed
    else:
        argv = argv[argv.index("--") + 1:]  # get all args after "--"

    # When --help or no args are given, print this help
    usage_text = \
    "Run blender in background mode with this script:"
    "  blender --background --python " + __file__ + " -- [options]"

    parser = argparse.ArgumentParser(description=usage_text)

    # Example utility, add some text and renders or saves it (with options)
    # Possible types are: string, int, long, choice, float and complex.
    parser.add_argument("-o",
                        "--output",
                        dest="save_path",
                        metavar='FILE|PATH',
                        help="Save the generated file to the specified path")
    parser.add_argument("-a",
                        "--enable-animation",
                        dest="enable_animation",
                        action="store_const",
                        const=True,
                        default=False,
                        help="Enable saving of animations")
    parser.add_argument("-m",
                        "--apply-modifiers",
                        dest="apply_modifiers",
                        action="store_const",
                        const=True,
                        default=False,
                        help="Apply modifiers before exporting")

    args = parser.parse_args(argv)  # In this example we wont use the args

    if args.save_path == None:
        print("\n*** No output filename specified (use -o)")
    else:
        config = osgconf.Config()
        config.initFilePaths(args.save_path)
        config.export_anim = args.enable_animation
        config.apply_modifiers = args.apply_modifiers
        config.scene = bpy.context.scene
        OpenSceneGraphExport(config)
Example #3
0
    def invoke(self, context, event):
        print("config is " + bpy.utils.user_resource('CONFIG'))
        self.config = osgconf.Config()

        try:
            cfg = os.path.join(bpy.utils.user_resource('CONFIG'), "osgExport.cfg")
            if os.path.exists(cfg):
                with open(cfg, 'rb') as f:
                    self.config = pickle.load(f)
        except Exception:
            pass

        self.config.activate()

        self.SELECTED = (self.config.selected == "SELECTED_ONLY_WITH_CHILDREN")
        self.ONLY_VISIBLE = self.config.only_visible
        self.INDENT = self.config.indent
        self.FLOATPRE = self.config.float_precision
        self.ANIMFPS = context.scene.render.fps

        self.EXPORTANIM = self.config.export_anim
        self.EXPORTLOD = self.config.export_lod
        self.MAXLODDISTANCE = self.config.max_lod_distance
        self.APPLYMODIFIERS = self.config.apply_modifiers
        self.ZERO_TRANSLATIONS = self.config.zero_translations
        self.LOG = self.config.log
        self.BAKE_ALL = self.config.bake_animations
        self.USE_QUATERNIONS = self.config.use_quaternions
        self.BAKE_CONSTRAINTS = self.config.bake_constraints
        self.BAKE_FRAME_STEP = self.config.bake_frame_step
        self.ARMATURE_REST = self.config.arm_rest
        self.OSGCONV_TO_IVE = self.config.osgconv_to_ive
        self.OSGCONV_EMBED_TEXTURES = self.config.osgconv_embed_textures
        self.OSGCONV_PATH = self.config.osgconv_path
        self.OSGCONV_CLEANUP = self.config.osgconv_cleanup
        self.JSON_MATERIALS = self.config.json_materials
        self.JSON_SHADERS = self.config.json_shaders

        self.RUN_VIEWER = self.config.run_viewer
        self.VIEWER_PATH = self.config.viewer_path
        self.TEXTURE_PREFIX = self.config.texture_prefix
        self.EXPORT_ALL_SCENES = self.config.export_all_scenes

        if bpy.data.filepath in self.config.history:
            self.filepath = self.config.history[bpy.data.filepath]

        return super(OSGGUI, self).invoke(context, event)