Skip to content

Instantly share code, notes, and snippets.

@hugoledoux
Created August 15, 2019 10:09
Show Gist options
  • Save hugoledoux/723a542247b9dc1c3e3586c9f758fac0 to your computer and use it in GitHub Desktop.
Save hugoledoux/723a542247b9dc1c3e3586c9f758fac0 to your computer and use it in GitHub Desktop.
Blender move to origin
from random import random
def move_obj(infile, outfile, translate=(0,0,0), delimiter=' ', standard_building_height=None):
tx,ty,tz = translate
with open(outfile,'w') as fo:
with open(infile,'r') as f:
for i, line in enumerate(f):
if line.startswith('v'):
columns = line.split(delimiter)
x = float(columns[1])
y = float(columns[2])
z = float(columns[3])
if standard_building_height is not None and z == 0.:
z+= standard_building_height# + random()*4
fo.write("v {} {} {}\n".format(x+tx, y+ty, z+tz))
else:
fo.write(line)
t = (-84514.52210, -447501.65660, 0.)
# move_obj('r.obj', 'r_origin.obj', t)
move_obj('kinderboek.obj', 'kinderboek_origin.obj', t, standard_building_height=9.0)
# move_obj('rtw.obj', 'rtw_origin.obj', t)
# move_obj('t.obj', 't_origin.obj', t)
# move_obj('w.obj', 'w_origin.obj', t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment