2013-05-26 21:44:07 +00:00
|
|
|
# blender CAM utils.py (c) 2012 Vilem Novak
|
|
|
|
#
|
|
|
|
# ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
# ***** END GPL LICENCE BLOCK *****
|
|
|
|
|
2013-06-13 23:32:08 +00:00
|
|
|
import bpy, os,pickle,time
|
|
|
|
import sys # to get command line args
|
|
|
|
import argparse # to parse options for us and print a nice help message
|
2013-05-29 23:07:59 +00:00
|
|
|
|
|
|
|
def getCachePath(o):
|
|
|
|
fn=bpy.data.filepath
|
|
|
|
l=len(bpy.path.basename(fn))
|
|
|
|
bn=bpy.path.basename(fn)[:-6]
|
2023-04-28 09:30:38 +00:00
|
|
|
|
2013-06-03 11:58:31 +00:00
|
|
|
try:
|
2013-06-04 11:55:48 +00:00
|
|
|
os.mkdir(fn[:-l]+'temp_cam')
|
2013-06-03 11:58:31 +00:00
|
|
|
except:
|
|
|
|
pass;
|
2013-05-29 23:07:59 +00:00
|
|
|
iname=fn[:-l]+'temp_cam'+os.sep+bn+'_'+o.name
|
|
|
|
return iname
|
|
|
|
|
2013-06-13 23:32:08 +00:00
|
|
|
def calculatePath(op):
|
|
|
|
s=bpy.context.scene
|
|
|
|
o=s.cam_operations[op]
|
|
|
|
s.cam_active_operation=op
|
2013-10-01 13:48:24 +00:00
|
|
|
bpy.ops.object.calculate_cam_path()
|
2013-06-13 23:32:08 +00:00
|
|
|
|
|
|
|
p=getCachePath(o)+'.blend'
|
|
|
|
picklepath=getCachePath(o)+'.pickle'
|
|
|
|
f=open(picklepath,'wb')
|
|
|
|
d={}
|
2023-04-28 09:30:38 +00:00
|
|
|
|
|
|
|
d['duration']=o.info.duration
|
2023-04-26 08:12:57 +00:00
|
|
|
d['warnings']=o.info.warnings
|
2023-04-28 09:30:38 +00:00
|
|
|
|
2013-06-13 23:32:08 +00:00
|
|
|
#pickle path...
|
|
|
|
oname="cam_path_"+o.name
|
|
|
|
if oname in s.objects:
|
|
|
|
mesh=s.objects[oname].data
|
|
|
|
verts=[]
|
|
|
|
for v in mesh.vertices:
|
|
|
|
verts.append((v.co.x,v.co.y,v.co.z))
|
|
|
|
d['path']=verts
|
|
|
|
pickle.dump(d,f)
|
|
|
|
f.close()
|
|
|
|
#bpy.ops.wm.save_mainfile(filepath=p)
|
|
|
|
#f=open(picklepath,'wb')
|
|
|
|
passed=False
|
|
|
|
while not passed:
|
|
|
|
try:
|
|
|
|
f=open(picklepath,'rb')
|
|
|
|
d=pickle.load(f)
|
|
|
|
f.close()
|
|
|
|
passed=True
|
|
|
|
except:
|
|
|
|
print('sleep')
|
|
|
|
time.sleep(1)
|
|
|
|
sys.stdout.write('progress{%s}\n' % ('finished'))
|
|
|
|
sys.stdout.flush()
|
2023-04-28 09:30:38 +00:00
|
|
|
|
2013-06-13 23:32:08 +00:00
|
|
|
#parse arguments here
|
|
|
|
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", "--operation", dest="op", type=int, required=True,
|
|
|
|
help="Index of the operation to calculate")
|
|
|
|
'''
|
|
|
|
parser.add_argument("-s", "--save", dest="save_path", metavar='FILE',
|
|
|
|
help="Save the generated file to the specified path")
|
|
|
|
parser.add_argument("-r", "--render", dest="render_path", metavar='FILE',
|
|
|
|
help="Render an image to the specified path")
|
|
|
|
'''
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
calculatePath(args.op)
|