Skip to content

Instantly share code, notes, and snippets.

@jtmkrueger
Created March 31, 2016 21:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtmkrueger/1ca122de2f8a96e7e9a2b2fbc1388b55 to your computer and use it in GitHub Desktop.
Save jtmkrueger/1ca122de2f8a96e7e9a2b2fbc1388b55 to your computer and use it in GitHub Desktop.
Batch export all objects in the scene as seperate three.js json files
import bpy
import os
# Batch exporting of all objects in the scene into separate json files
# access the scene
scene = bpy.context.scene
# get the current path and make a new folder for the exported meshes
path = bpy.path.abspath('//' + bpy.path.basename(bpy.context.blend_data.filepath) + '_jsonexport/')
# if the directory to dump the files in doesn't exist yet, create it
if not os.path.exists(path):
os.makedirs(path)
# deselect all meshes
bpy.ops.object.select_all(action='DESELECT')
for ob in scene.objects:
# select this object
scene.objects.active = ob
ob.select = True
# export object with its name as file name
fPath = str((path + ob.name + '.json'))
#bpy.context.active_object = ob
bpy.ops.export.three(filepath=fPath,
check_existing=False,
option_vertices=True,
option_faces=True,
option_normals=True,
option_colors=True,
option_mix_colors=True,
option_uv_coords=True,
option_materials=True,
option_face_materials=True,
option_maps=False,
option_skinning=True,
option_bones=False,
option_extra_vgroups="",
option_apply_modifiers=True,
option_index_type='Uint16Array',
option_scale=0.04,
option_round_off=True,
option_round_value=6,
option_logging='disabled',
option_geometry_type='geometry',
option_export_scene=False,
option_embed_animation=False,
option_copy_textures=True,
option_texture_folder="",
option_lights=False,
option_cameras=False,
option_hierarchy=False,
option_animation_morph=False,
option_blend_shape=False,
option_animation_skeletal='off',
option_keyframes=False,
option_frame_index_as_time=False,
option_frame_step=1,
option_indent=True,
option_compression='None',
option_influences=2)
# deselect this object again
ob.select = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment