Skip to content

Commit

Permalink
Merge pull request #6 from sketchfab/feature/cycles
Browse files Browse the repository at this point in the history
Feature/cycles
  • Loading branch information
Cedric Pinson committed Feb 10, 2015
2 parents 5685208 + 2eede3e commit ccfbd46
Show file tree
Hide file tree
Showing 22 changed files with 1,423 additions and 898 deletions.
39 changes: 29 additions & 10 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,40 @@ Follow instruction from github to get the repository

https://github.com/cedricpinson/osgexport

Blender 2.5+
## Installation (blender 2.5+)

To install last version of the exporter go in user preference, then 'install addons' with the zip from https://github.com/cedricpinson/osgexport/tree/master/blender-2.5/build


How to report a bug:
send a minimal blender file that produce the problem, https://github.com/cedricpinson/osgexport/issues
## Command line usage

`osgexport` needs to inject the path to exporter modules into PYTHONPATH. The injection is done by reading the value of the `BlenderExporter` environment variable (see [__init__.py](https://github.com/sketchfab/osgexport/blob/feature/cycles/blender-2.5/exporter/osg/__init__.py#L46-51)).

```shell

$ BlenderExporter="/path-to-osgexport/blender-2.5/exporter" blender \
-b "input.blend" \
-P "${BlenderExporter}/osg/__init__.py" \
-- --output="output.osgt" \
[--apply-modifiers] [--enable-animation] [--json-materials]
```

## How to report a bug

Open an [issue](https://github.com/cedricpinson/osgexport/issues/new) and send a minimal blender file that produce the problem.


## Tests

To run tests:

To execute test you will need to install twisted
```shell

Test blender 2.5
mkdir build-2.5
cd build-2.5
cmake ../blender-2.5 -DBLENDER="blender2.5"
make
mkdir tests && cd tests
cmake ../blender-2.5 -DBLENDER:FILEPATH="/my/path/to/blender" -DTEST=ON
make # runs test building osgt files for models in blender-2.xx/data/
make test # runs python test located in blender-2.xx/test/

```

Cedric
To troubleshoot python tests: `ctest --debug` or `ctest --output-on-failure`
4 changes: 2 additions & 2 deletions blender-2.5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ SET(CPACK_SOURCE_IGNORE_FILES
SET(OSGEXPORTER_VERSION "0.0.1")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "osgexporter-${OSGEXPORTER_VERSION}")

OPTION(BLENDER "blender" "blender")
SET(EXPORTER "exporter")
SET(BLENDER "blender" CACHE FILEPATH "(Absolute) path to blender binary")
SET(EXPORTER "${PROJECT_SOURCE_DIR}/exporter" CACHE FILEPATH "(Absolute) path to exporter modules")
OPTION(TEST "Enable test" OFF)
OPTION(BUILD_DATA "Build data" ON)

Expand Down
7 changes: 4 additions & 3 deletions blender-2.5/CMakeModules/MacroUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


MACRO(BUILD_DATA)
find_program (BASH_PROGRAM bash)

IF (${ARGC} EQUAL 1)
SET(flags "${ARGV0}")
Expand All @@ -29,9 +30,9 @@ MACRO(BUILD_DATA)
# need DATA_SOURCE and DATA_TARGET
SET(DATA_TARGETNAME ${DATA_TARGET}.osgt)
ADD_CUSTOM_COMMAND (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${DATA_TARGETNAME}
COMMAND ${BLENDER}
ARGS --background ${DATA_SOURCE} --python osg/__init__.py -- --output="${CMAKE_CURRENT_BINARY_DIR}/${DATA_TARGET}" "${flags}"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/${EXPORTER}
COMMAND ${BLENDER} --background ${DATA_SOURCE} --python osg/__init__.py -- --output="${CMAKE_CURRENT_BINARY_DIR}/${DATA_TARGET}" "${flags}"
COMMAND ${BASH_PROGRAM} -c "[ -f ${CMAKE_CURRENT_BINARY_DIR}/${DATA_TARGETNAME} ]"
WORKING_DIRECTORY ${EXPORTER}
DEPENDS ${DATA_SOURCE}
COMMENT "build data from ${DATA_SOURCE}"
)
Expand Down
17 changes: 9 additions & 8 deletions blender-2.5/data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@

INCLUDE(MacroUtils)

ADD_SUBDIRECTORY(avatar)
ADD_SUBDIRECTORY(bees)
ADD_SUBDIRECTORY(normalmap)
ADD_SUBDIRECTORY(ipos)
ADD_SUBDIRECTORY(bignathan)
ADD_SUBDIRECTORY(car)
ADD_SUBDIRECTORY(robot)
ADD_SUBDIRECTORY(cycles)
ADD_SUBDIRECTORY(example)
ADD_SUBDIRECTORY(walker)
ADD_SUBDIRECTORY(avatar)
ADD_SUBDIRECTORY(nathan)
ADD_SUBDIRECTORY(bignathan)
ADD_SUBDIRECTORY(multimaterial)
ADD_SUBDIRECTORY(ipos)
ADD_SUBDIRECTORY(lights)
ADD_SUBDIRECTORY(multimaterial)
ADD_SUBDIRECTORY(nathan)
ADD_SUBDIRECTORY(normalmap)
ADD_SUBDIRECTORY(robot)
ADD_SUBDIRECTORY(walker)
22 changes: 22 additions & 0 deletions blender-2.5/data/car/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (C) 2008 Cedric Pinson
#
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Authors:
# Cedric Pinson <[email protected]>

SET ( DATA_SOURCE ${PROJECT_SOURCE_DIR}/data/car/BMW-MikePan2.blend )
SET ( DATA_TARGET car )
BUILD_DATA()
23 changes: 23 additions & 0 deletions blender-2.5/data/cycles/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (C) 2014 Cedric Pinson
#
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Authors:
# Cedric Pinson <[email protected]>


SET ( DATA_SOURCE ${PROJECT_SOURCE_DIR}/data/cycles/cycles.blend )
SET ( DATA_TARGET cycles )
BUILD_DATA()
Binary file added blender-2.5/data/cycles/cycles.blend
Binary file not shown.
82 changes: 50 additions & 32 deletions blender-2.5/exporter/osg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
#
# ##### END GPL LICENSE BLOCK #####

import imp
import sys
import os
import bpy
import pickle
import argparse


bl_info = {
"name": "Export OSG format (.osgt)",
"author": "Cedric Pinson, Jeremy Moles, Peter Amstutz",
"version": (0,14,2),
"version": (0, 14, 2),
"blender": (2, 6, 3),
"email": "[email protected], [email protected], [email protected]",
"api": 36339,
Expand All @@ -36,32 +37,32 @@
"tracker_url": "http://github.com/cedricpinson/osgexport",
"category": "Import-Export"}

__url__ = bl_info["wiki_url"]
__email__ = bl_info["email"]
__author__ = bl_info["author"]
__bpydoc__ = bl_info["description"]
__version__ = bl_info["version"]
__author__ = bl_info["author"]
__email__ = bl_info["email"]
__url__ = bl_info["wiki_url"]
__bpydoc__ = bl_info["description"]

sys.path.insert(0, "./")
BlenderExporterDir = os.getenv("BlenderExporter", os.path.join(bpy.context.user_preferences.filepaths.script_directory,"blenderExporter"))
BlenderExporterDir = os.getenv("BlenderExporter",
os.path.join(bpy.context.user_preferences.filepaths.script_directory,
"blenderExporter"))
print("BlenderExporter directory ", BlenderExporterDir)
sys.path.insert(0,BlenderExporterDir)
sys.path.insert(0, BlenderExporterDir)

import bpy
import osg
from osg import osgdata
from osg import osgconf


def OpenSceneGraphExport(config=None):
export = osg.osgdata.Export(config)
print("....................", config.filename)
export.process()
export.write()

def main():
import sys # to get command line args
import argparse # to parse options for us and print a nice help message

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
Expand All @@ -72,44 +73,55 @@ def main():
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]"
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_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")
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("-m", "--apply-modifiers", dest="apply_modifiers", action="store_true", default=False,
help="Apply modifiers before exporting")
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")

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

if args.save_path == None:
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.apply_modifiers = args.apply_modifiers
config.scene = bpy.context.scene
config.json_materials = args.json_materials
config.json_shaders = args.json_shaders
OpenSceneGraphExport(config)

if __name__ == "__main__":
main()


def menu_export_osg_model(self, context):
#import os
#default_path = os.path.splitext(bpy.data.filepath)[0] + "_" + bpy.context.scene.name
#default_path = default_path.replace('.', '_')
#self.layout.operator(OSGGUI.bl_idname, text="OSG Model(.osg)").filepath = default_path
self.layout.operator(OSGGUI.bl_idname, text="OSG Model(.osgt)")
# import os
# default_path = os.path.splitext(bpy.data.filepath)[0] + "_" + bpy.context.scene.name
# default_path = default_path.replace('.', '_')
# self.layout.operator(OSGGUI.bl_idname, text="OSG Model(.osg)").filepath = default_path
self.layout.operator(OSGGUI.bl_idname, text="OSG Model(.osgt)")


def register():
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_file_export.append(menu_export_osg_model)


def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_file_export.remove(menu_export_osg_model)
Expand All @@ -121,17 +133,17 @@ def unregister():
print("Use old import path - your blender is not the latest version")
except:
from bpy_extras.io_utils import ExportHelper
#print("Use new import path")
# print("Use new import path")


build = 'unknown'
if hasattr(bpy.app, 'build_hash'):
build = bpy.app.build_hash
# Property subtype constant changed with r50938
if "FILE_PATH" in bpy.types.Property.bl_rna.properties['subtype'].enum_items.keys():
FILE_NAME = "FILE_PATH"
elif "FILE_NAME" in bpy.types.Property.bl_rna.properties['subtype'].enum_items.keys():
FILE_NAME = "FILE_NAME"
else:
build = bpy.app.build_revision
FILE_NAME = "FILENAME"

# Property subtype constant changed with r50938
FILE_NAME = "FILE_NAME" if build >= b'50938' else "FILENAME"

class OSGGUI(bpy.types.Operator, ExportHelper):
'''Export model data to an OpenSceneGraph file'''
Expand All @@ -152,6 +164,8 @@ class OSGGUI(bpy.types.Operator, ExportHelper):
EXPORTANIM = BoolProperty(name="Export animations", description="Export animation yes/no", default=True)
APPLYMODIFIERS = BoolProperty(name="Apply Modifiers", description="Apply modifiers before exporting yes/no", default=True)
LOG = BoolProperty(name="Write log", description="Write log file yes/no", default=False)
JSON_MATERIALS = BoolProperty(name="JSON Materials", description="Export materials into JSON userdata.", default=False)
JSON_SHADERS = BoolProperty(name="JSON shaders", description="Export shader graphs into JSON userdata.", default=False)
BAKE_CONSTRAINTS = BoolProperty(name="Bake Constraints", description="Bake constraints into actions", default=True)
BAKE_FRAME_STEP = IntProperty(name="Bake frame step", description="Frame step when baking actions", default=1, min=1, max=30)
OSGCONV_TO_IVE = BoolProperty(name="Convert to IVE (uses osgconv)", description="Use osgconv to convert to IVE", default=False)
Expand All @@ -176,6 +190,8 @@ def draw(self, context):
layout.row(align=True).prop(self, "APPLYMODIFIERS")
layout.row(align=True).prop(self, "BAKE_CONSTRAINTS")
layout.row(align=True).prop(self, "LOG")
layout.row(align=True).prop(self, "JSON_MATERIALS")
layout.row(align=True).prop(self, "JSON_SHADERS")
layout.row(align=True).prop(self, "ZERO_TRANSLATIONS")
layout.row(align=True).prop(self, "ANIMFPS")
layout.row(align=True).prop(self, "BAKE_FRAME_STEP")
Expand Down Expand Up @@ -220,6 +236,8 @@ def invoke(self, context, event):
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
Expand All @@ -245,7 +263,7 @@ def execute(self, context):
self.config.selected = "ALL"
self.config.indent = self.INDENT
self.config.only_visible = self.ONLY_VISIBLE
self.config.float_precision = self.FLOATPRE
self.config.float_precision = self.FLOATPRE
self.config.anim_fps = self.ANIMFPS
self.config.export_anim = self.EXPORTANIM
self.config.apply_modifiers = self.APPLYMODIFIERS
Expand Down
Loading

0 comments on commit ccfbd46

Please sign in to comment.