Last active
May 15, 2017 20:18
-
-
Save jazzyjackson/694dddb622ff1e4dafa9b709ebba0bea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Imports OBJ meshes, about 2 MB each, and then duplicates the meshes, inserting keyframes for each object | |
# resulting file is > 100 MB | |
import bpy, numpy | |
from mathutils import * | |
radius = 50 | |
n_samples = 25 | |
bpy.ops.import_scene.obj(filepath="./woman_standing.obj") | |
bpy.ops.group.create(name="woman") | |
bpy.ops.import_scene.obj(filepath="./man_standing.obj") | |
bpy.ops.group.create(name="man") | |
samples = numpy.random.multivariate_normal([-0.5, -0.5], [[radius, 0],[0, radius]], n_samples) | |
for point in range(len(samples)): | |
locX = samples[point][0] | |
locY = samples[point][1] | |
if(numpy.random.sample() > 0.5): | |
bpy.ops.object.group_instance_add(group='woman',location=(locX,locY,0)) | |
else: | |
bpy.ops.object.group_instance_add(group='man',location=(locX,locY,0)) | |
allObjects = bpy.data.objects | |
allObjects = [x for x in allObjects if "man" in x.name] | |
numpy.random.shuffle(allObjects) | |
print(len(allObjects)) | |
for blues in range(5): | |
thisFigurine = allObjects[blues] | |
firstPos = thisFigurine.location | |
thisFigurine.keyframe_insert('location',frame=0) | |
thisFigurine.location = Vector(((-blues * 6) - 10,0,35)) | |
thisFigurine.keyframe_insert('location',frame=30) | |
for reds in range(5,10): | |
thisFigurine = allObjects[reds] | |
firstPos = thisFigurine.location | |
thisFigurine.keyframe_insert('location',frame=31) | |
thisFigurine.location = Vector((((reds - 4) * 6) + 10,0,35)) | |
thisFigurine.keyframe_insert('location',frame=60) | |
bpy.ops.export_scene.fbx(filepath="./25peopleShortAnim.fbx",version="ASCII6100") # ascii compatible with 3D Viewer | |
bpy.ops.wm.save_as_mainfile(filepath="./25peopleShortAnim.blend") | |
# bpy.ops.export_scene.fbx(filepath="./binout.fbx") # ascii compatible with 3D Viewer | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment