add mesureit to release "warning temporary status" pending T48704

This commit is contained in:
Brendon Murphy 2016-08-03 10:47:46 +10:00
parent 5cd9040c99
commit cf4ac00ea0
4 changed files with 4157 additions and 0 deletions

403
measureit/__init__.py Normal file
View File

@ -0,0 +1,403 @@
# ##### 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 LICENSE BLOCK #####
# <pep8 compliant>
# ----------------------------------------------------------
# Author: Antonio Vazquez (antonioya)
# ----------------------------------------------------------
# ----------------------------------------------
# Define Addon info
# ----------------------------------------------
bl_info = {
"name": "MeasureIt",
"author": "Antonio Vazquez (antonioya)",
"location": "View3D > Tools Panel /Properties panel",
"version": (1, 6, 6),
"blender": (2, 7, 4),
"description": "Tools for measuring objects.",
'warning': 'Temporary: pending review fixes T48704',
"tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
"category": "3D View"}
import sys
import os
# ----------------------------------------------
# Add to Phyton path (once only)
# ----------------------------------------------
path = sys.path
flag = False
for item in path:
if "measureit" in item:
flag = True
if flag is False:
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'measureit'))
print("measureit: added to phytonpath")
# ----------------------------------------------
# Import modules
# ----------------------------------------------
if "bpy" in locals():
import imp
imp.reload(measureit_main)
print("measureit: Reloaded multifiles")
else:
import measureit_main
print("measureit: Imported multifiles")
# noinspection PyUnresolvedReferences
import bpy
# noinspection PyUnresolvedReferences
from bpy.props import *
# --------------------------------------------------------------
# Register all operators and panels
# --------------------------------------------------------------
def register():
bpy.utils.register_class(measureit_main.RunHintDisplayButton)
bpy.utils.register_class(measureit_main.AddSegmentButton)
bpy.utils.register_class(measureit_main.AddAreaButton)
bpy.utils.register_class(measureit_main.AddSegmentOrtoButton)
bpy.utils.register_class(measureit_main.AddAngleButton)
bpy.utils.register_class(measureit_main.AddArcButton)
bpy.utils.register_class(measureit_main.AddLabelButton)
bpy.utils.register_class(measureit_main.AddNoteButton)
bpy.utils.register_class(measureit_main.AddLinkButton)
bpy.utils.register_class(measureit_main.AddOriginButton)
bpy.utils.register_class(measureit_main.DeleteSegmentButton)
bpy.utils.register_class(measureit_main.DeleteAllSegmentButton)
bpy.utils.register_class(measureit_main.DeleteAllSumButton)
bpy.utils.register_class(measureit_main.MeasureitEditPanel)
bpy.utils.register_class(measureit_main.MeasureitMainPanel)
bpy.utils.register_class(measureit_main.MeasureitConfPanel)
bpy.utils.register_class(measureit_main.MeasureitRenderPanel)
bpy.utils.register_class(measureit_main.RenderSegmentButton)
# Define properties
bpy.types.Scene.measureit_default_color = bpy.props.FloatVectorProperty(
name="Default color",
description="Default Color",
default=(0.173, 0.545, 1.0, 1.0),
min=0.1,
max=1,
subtype='COLOR',
size=4)
bpy.types.Scene.measureit_font_size = bpy.props.IntProperty(name="Text Size",
description="Default text size",
default=14, min=10, max=150)
bpy.types.Scene.measureit_hint_space = bpy.props.FloatProperty(name='Separation', min=0, max=100, default=0.1,
precision=3,
description="Default distance to display measure")
bpy.types.Scene.measureit_gl_ghost = bpy.props.BoolProperty(name="All",
description="Display measures for all objects,"
" not only selected",
default=True)
bpy.types.Scene.measureit_gl_txt = bpy.props.StringProperty(name="Text", maxlen=256,
description="Short description (use | for line break)")
bpy.types.Scene.measureit_gl_precision = bpy.props.IntProperty(name='Precision', min=0, max=5, default=2,
description="Number of decimal precision")
bpy.types.Scene.measureit_gl_show_d = bpy.props.BoolProperty(name="ShowDist",
description="Display distances",
default=True)
bpy.types.Scene.measureit_gl_show_n = bpy.props.BoolProperty(name="ShowName",
description="Display texts",
default=False)
bpy.types.Scene.measureit_scale = bpy.props.BoolProperty(name="Scale",
description="Use scale factor",
default=False)
bpy.types.Scene.measureit_scale_factor = bpy.props.FloatProperty(name='Factor', min=0.001, max=9999999,
default=1.0,
precision=3,
description="Scale factor 1:x")
bpy.types.Scene.measureit_scale_color = bpy.props.FloatVectorProperty(name="Scale color",
description="Scale Color",
default=(1, 1, 0, 1.0),
min=0.1,
max=1,
subtype='COLOR',
size=4)
bpy.types.Scene.measureit_scale_font = bpy.props.IntProperty(name="Font",
description="Text size",
default=14, min=10, max=150)
bpy.types.Scene.measureit_scale_pos_x = bpy.props.IntProperty(name="Position X",
description="Margin on the X axis",
default=5,
min=0,
max=100)
bpy.types.Scene.measureit_scale_pos_y = bpy.props.IntProperty(name="Position Y",
description="Margin on the Y axis",
default=5,
min=0,
max=100)
bpy.types.Scene.measureit_gl_scaletxt = bpy.props.StringProperty(name="ScaleText", maxlen=48,
description="Scale title",
default="Scale:")
bpy.types.Scene.measureit_scale_precision = bpy.props.IntProperty(name='Precision', min=0, max=5, default=0,
description="Number of decimal precision")
bpy.types.Scene.measureit_ovr = bpy.props.BoolProperty(name="Override",
description="Override colors and fonts",
default=False)
bpy.types.Scene.measureit_ovr_font = bpy.props.IntProperty(name="Font",
description="Override text size",
default=14, min=10, max=150)
bpy.types.Scene.measureit_ovr_color = bpy.props.FloatVectorProperty(name="Override color",
description="Override Color",
default=(1, 0, 0, 1.0),
min=0.1,
max=1,
subtype='COLOR',
size=4)
bpy.types.Scene.measureit_ovr_width = bpy.props.IntProperty(name='Override width', min=1, max=10, default=1,
description='override line width')
bpy.types.Scene.measureit_units = bpy.props.EnumProperty(items=(('1', "Automatic", "Use scene units"),
('2', "Meters", ""),
('3', "Centimeters", ""),
('4', "Milimiters", ""),
('5', "Feet", ""),
('6', "Inches", "")),
name="Units",
default="2",
description="Units")
bpy.types.Scene.measureit_render = bpy.props.BoolProperty(name="Render",
description="Save an image with measures over"
" render image",
default=False)
bpy.types.Scene.measureit_render_type = bpy.props.EnumProperty(items=(('1', "*Current", "Use current render"),
('2', "OpenGL", ""),
('3', "Animation OpenGL", ""),
('4', "Image", ""),
('5', "Animation", "")),
name="Render type",
description="Type of render image")
bpy.types.Scene.measureit_sum = bpy.props.EnumProperty(items=(('99', "-", "Select a group for sum"),
('0', "A", ""),
('1', "B", ""),
('2', "C", ""),
('3', "D", ""),
('4', "E", ""),
('5', "F", ""),
('6', "G", ""),
('7', "H", ""),
('8', "I", ""),
('9', "J", ""),
('10', "K", ""),
('11', "L", ""),
('12', "M", ""),
('13', "N", ""),
('14', "O", ""),
('15', "P", ""),
('16', "Q", ""),
('17', "R", ""),
('18', "S", ""),
('19', "T", ""),
('20', "U", ""),
('21', "V", ""),
('22', "W", ""),
('23', "X", ""),
('24', "Y", ""),
('25', "Z", "")),
name="Sum in Group",
description="Add segment length in selected group")
bpy.types.Scene.measureit_rf = bpy.props.BoolProperty(name="render_frame",
description="Add a frame in render output",
default=False)
bpy.types.Scene.measureit_rf_color = bpy.props.FloatVectorProperty(name="Fcolor",
description="Frame Color",
default=(0.9, 0.9, 0.9, 1.0),
min=0.1,
max=1,
subtype='COLOR',
size=4)
bpy.types.Scene.measureit_rf_border = bpy.props.IntProperty(name='fborder ', min=1, max=1000, default=10,
description='Frame space from border')
bpy.types.Scene.measureit_rf_line = bpy.props.IntProperty(name='fline', min=1, max=10, default=1,
description='Line width for border')
bpy.types.Scene.measureit_glarrow_a = bpy.props.EnumProperty(items=(('99', "--", "No arrow"),
('1', "Line",
"The point of the arrow are lines"),
('2', "Triangle",
"The point of the arrow is triangle"),
('3', "TShape",
"The point of the arrow is a T")),
name="A end",
description="Add arrows to point A")
bpy.types.Scene.measureit_glarrow_b = bpy.props.EnumProperty(items=(('99', "--", "No arrow"),
('1', "Line",
"The point of the arrow are lines"),
('2', "Triangle",
"The point of the arrow is triangle"),
('3', "TShape",
"The point of the arrow is a T")),
name="B end",
description="Add arrows to point B")
bpy.types.Scene.measureit_glarrow_s = bpy.props.IntProperty(name="Size",
description="Arrow size",
default=15, min=6, max=500)
bpy.types.Scene.measureit_debug = bpy.props.BoolProperty(name="Debug",
description="Display information for debuging"
" (expand/collapse for enabling or disabling)"
" this information is only renderered for "
"selected objects",
default=False)
bpy.types.Scene.measureit_debug_select = bpy.props.BoolProperty(name="Selected",
description="Display information "
"for selected vertices/faces",
default=False)
bpy.types.Scene.measureit_debug_vertices = bpy.props.BoolProperty(name="Vertices",
description="Display vertex number",
default=True)
bpy.types.Scene.measureit_debug_location = bpy.props.BoolProperty(name="Location",
description="Display vertex location",
default=False)
bpy.types.Scene.measureit_debug_faces = bpy.props.BoolProperty(name="Faces",
description="Display face number",
default=False)
bpy.types.Scene.measureit_debug_normals = bpy.props.BoolProperty(name="Normals",
description="Display face normal "
"vector and creation order",
default=False)
bpy.types.Scene.measureit_debug_normal_details = bpy.props.BoolProperty(name="Details",
description="Display face normal details",
default=True)
bpy.types.Scene.measureit_debug_font = bpy.props.IntProperty(name="Font",
description="Debug text size",
default=14, min=10, max=150)
bpy.types.Scene.measureit_debug_color = bpy.props.FloatVectorProperty(name="Debug color",
description="Debug Color",
default=(1, 0, 0, 1.0),
min=0.1,
max=1,
subtype='COLOR',
size=4)
bpy.types.Scene.measureit_debug_color2 = bpy.props.FloatVectorProperty(name="Debug face color",
description="Debug face Color",
default=(0, 1, 0, 1.0),
min=0.1,
max=1,
subtype='COLOR',
size=4)
bpy.types.Scene.measureit_debug_color3 = bpy.props.FloatVectorProperty(name="Debug vector color",
description="Debug vector Color",
default=(1.0, 1.0, 0.1, 1.0),
min=0.1,
max=1,
subtype='COLOR',
size=4)
bpy.types.Scene.measureit_debug_normal_size = bpy.props.FloatProperty(name='Len', min=0.001, max=9,
default=0.5,
precision=2,
description="Normal arrow size")
bpy.types.Scene.measureit_debug_width = bpy.props.IntProperty(name='Debug width', min=1, max=10, default=2,
description='Vector line thickness')
bpy.types.Scene.measureit_debug_precision = bpy.props.IntProperty(name='Precision', min=0, max=5, default=1,
description="Number of decimal precision")
# OpenGL flag
wm = bpy.types.WindowManager
# register internal property
wm.measureit_run_opengl = bpy.props.BoolProperty(default=False)
def unregister():
bpy.utils.unregister_class(measureit_main.RunHintDisplayButton)
bpy.utils.unregister_class(measureit_main.AddSegmentButton)
bpy.utils.unregister_class(measureit_main.AddAreaButton)
bpy.utils.unregister_class(measureit_main.AddSegmentOrtoButton)
bpy.utils.unregister_class(measureit_main.AddAngleButton)
bpy.utils.unregister_class(measureit_main.AddArcButton)
bpy.utils.unregister_class(measureit_main.AddLabelButton)
bpy.utils.unregister_class(measureit_main.AddNoteButton)
bpy.utils.unregister_class(measureit_main.AddLinkButton)
bpy.utils.unregister_class(measureit_main.AddOriginButton)
bpy.utils.unregister_class(measureit_main.DeleteSegmentButton)
bpy.utils.unregister_class(measureit_main.DeleteAllSegmentButton)
bpy.utils.unregister_class(measureit_main.DeleteAllSumButton)
bpy.utils.unregister_class(measureit_main.MeasureitEditPanel)
bpy.utils.unregister_class(measureit_main.MeasureitMainPanel)
bpy.utils.unregister_class(measureit_main.MeasureitConfPanel)
bpy.utils.unregister_class(measureit_main.MeasureitRenderPanel)
bpy.utils.unregister_class(measureit_main.RenderSegmentButton)
# Remove properties
del bpy.types.Scene.measureit_default_color
del bpy.types.Scene.measureit_font_size
del bpy.types.Scene.measureit_hint_space
del bpy.types.Scene.measureit_gl_ghost
del bpy.types.Scene.measureit_gl_txt
del bpy.types.Scene.measureit_gl_precision
del bpy.types.Scene.measureit_gl_show_d
del bpy.types.Scene.measureit_gl_show_n
del bpy.types.Scene.measureit_scale
del bpy.types.Scene.measureit_scale_factor
del bpy.types.Scene.measureit_scale_color
del bpy.types.Scene.measureit_scale_font
del bpy.types.Scene.measureit_scale_pos_x
del bpy.types.Scene.measureit_scale_pos_y
del bpy.types.Scene.measureit_gl_scaletxt
del bpy.types.Scene.measureit_scale_precision
del bpy.types.Scene.measureit_ovr
del bpy.types.Scene.measureit_ovr_font
del bpy.types.Scene.measureit_ovr_color
del bpy.types.Scene.measureit_ovr_width
del bpy.types.Scene.measureit_units
del bpy.types.Scene.measureit_render
del bpy.types.Scene.measureit_render_type
del bpy.types.Scene.measureit_sum
del bpy.types.Scene.measureit_rf
del bpy.types.Scene.measureit_rf_color
del bpy.types.Scene.measureit_rf_border
del bpy.types.Scene.measureit_rf_line
del bpy.types.Scene.measureit_glarrow_a
del bpy.types.Scene.measureit_glarrow_b
del bpy.types.Scene.measureit_glarrow_s
del bpy.types.Scene.measureit_debug
del bpy.types.Scene.measureit_debug_select
del bpy.types.Scene.measureit_debug_vertices
del bpy.types.Scene.measureit_debug_faces
del bpy.types.Scene.measureit_debug_normals
del bpy.types.Scene.measureit_debug_normal_details
del bpy.types.Scene.measureit_debug_font
del bpy.types.Scene.measureit_debug_color
del bpy.types.Scene.measureit_debug_color2
del bpy.types.Scene.measureit_debug_color3
del bpy.types.Scene.measureit_debug_normal_size
del bpy.types.Scene.measureit_debug_width
del bpy.types.Scene.measureit_debug_precision
del bpy.types.Scene.measureit_debug_location
# remove OpenGL data
measureit_main.RunHintDisplayButton.handle_remove(measureit_main.RunHintDisplayButton, bpy.context)
wm = bpy.context.window_manager
p = 'measureit_run_opengl'
if p in wm:
del wm[p]
if __name__ == '__main__':
register()

File diff suppressed because it is too large Load Diff

2061
measureit/measureit_main.py Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,343 @@
# ##### 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 LICENSE BLOCK #####
# <pep8 compliant>
# ----------------------------------------------------------
# support routines for render measures in final image
# Author: Antonio Vazquez (antonioya)
#
# ----------------------------------------------------------
# noinspection PyUnresolvedReferences
import bpy
# noinspection PyUnresolvedReferences
import bgl
# noinspection PyUnresolvedReferences
import blf
# noinspection PyUnresolvedReferences
import mathutils
# noinspection PyUnresolvedReferences
import bmesh
import os
import sys
# noinspection PyUnresolvedReferences
import bpy_extras.image_utils as img_utils
# noinspection PyUnresolvedReferences
import bpy_extras.object_utils as object_utils
# noinspection PyUnresolvedReferences
from bpy_extras import view3d_utils
from math import ceil
from measureit_geometry import *
# -------------------------------------------------------------
# Render image main entry point
#
# -------------------------------------------------------------
def render_main(self, context, animation=False):
# noinspection PyBroadException,PyBroadException
# Save old info
settings = bpy.context.scene.render.image_settings
depth = settings.color_depth
settings.color_depth = '8'
# noinspection PyBroadException
try:
# Get visible layers
layers = []
scene = context.scene
for x in range(0, 20):
if scene.layers[x] is True:
layers.extend([x])
# Get object list
objlist = context.scene.objects
# --------------------
# Get resolution
# --------------------
scene = bpy.context.scene
render_scale = scene.render.resolution_percentage / 100
width = int(scene.render.resolution_x * render_scale)
height = int(scene.render.resolution_y * render_scale)
# ---------------------------------------
# Get output path
# ---------------------------------------
ren_path = bpy.context.scene.render.filepath
if len(ren_path) > 0:
if ren_path.endswith(os.path.sep):
initpath = os.path.realpath(ren_path) + os.path.sep
else:
(initpath, filename) = os.path.split(ren_path)
outpath = os.path.join(initpath, "measureit_tmp_render.png")
else:
self.report({'ERROR'},
"MeasureIt: Unable to save temporary render image. Define a valid render path")
settings.color_depth = depth
return False
# Get Render Image
img = get_render_image(outpath)
if img is None:
self.report({'ERROR'},
"MeasureIt: Unable to save temporary render image. Define a valid render path")
settings.color_depth = depth
return False
# -----------------------------
# Calculate rows and columns
# -----------------------------
tile_x = 240
tile_y = 216
row_num = ceil(height / tile_y)
col_num = ceil(width / tile_x)
print("MeasureIt: Image divided in " + str(row_num) + "x" + str(col_num) + " tiles")
# pixels out of visible area
cut4 = (col_num * tile_x * 4) - width * 4 # pixels aout of drawing area
totpixel4 = width * height * 4 # total pixels RGBA
viewport_info = bgl.Buffer(bgl.GL_INT, 4)
bgl.glGetIntegerv(bgl.GL_VIEWPORT, viewport_info)
# Load image on memory
img.gl_load(0, bgl.GL_NEAREST, bgl.GL_NEAREST)
# 2.77 API change
if bpy.app.version >= (2, 77, 0):
tex = img.bindcode[0]
else:
tex = img.bindcode
# --------------------------------------------
# Create output image (to apply texture)
# --------------------------------------------
if "measureit_output" in bpy.data.images:
out_img = bpy.data.images["measureit_output"]
if out_img is not None:
out_img.user_clear()
bpy.data.images.remove(out_img)
out = bpy.data.images.new("measureit_output", width, height)
tmp_pixels = [1] * totpixel4
# --------------------------------
# Loop for all tiles
# --------------------------------
for row in range(0, row_num):
for col in range(0, col_num):
buffer = bgl.Buffer(bgl.GL_FLOAT, width * height * 4)
bgl.glDisable(bgl.GL_SCISSOR_TEST) # if remove this line, get blender screenshot not image
bgl.glViewport(0, 0, tile_x, tile_y)
bgl.glMatrixMode(bgl.GL_PROJECTION)
bgl.glLoadIdentity()
# defines ortographic view for single tile
x1 = tile_x * col
y1 = tile_y * row
bgl.gluOrtho2D(x1, x1 + tile_x, y1, y1 + tile_y)
# Clear
bgl.glClearColor(0.0, 0.0, 0.0, 0.0)
bgl.glClear(bgl.GL_COLOR_BUFFER_BIT | bgl.GL_DEPTH_BUFFER_BIT)
bgl.glEnable(bgl.GL_TEXTURE_2D)
bgl.glBindTexture(bgl.GL_TEXTURE_2D, tex)
# defines drawing area
bgl.glBegin(bgl.GL_QUADS)
bgl.glColor3f(1.0, 1.0, 1.0)
bgl.glTexCoord2f(0.0, 0.0)
bgl.glVertex2f(0.0, 0.0)
bgl.glTexCoord2f(1.0, 0.0)
bgl.glVertex2f(width, 0.0)
bgl.glTexCoord2f(1.0, 1.0)
bgl.glVertex2f(width, height)
bgl.glTexCoord2f(0.0, 1.0)
bgl.glVertex2f(0.0, height)
bgl.glEnd()
# -----------------------------
# Loop to draw all lines
# -----------------------------
for myobj in objlist:
if myobj.hide is False:
if 'MeasureGenerator' in myobj:
# verify visible layer
for x in range(0, 20):
if myobj.layers[x] is True:
if x in layers:
op = myobj.MeasureGenerator[0]
draw_segments(context, myobj, op, None, None)
break
# -----------------------------
# Loop to draw all debug
# -----------------------------
if scene.measureit_debug is True:
selobj = bpy.context.selected_objects
for myobj in selobj:
if scene.measureit_debug_vertices is True:
draw_vertices(context, myobj, None, None)
if scene.measureit_debug_faces is True or scene.measureit_debug_normals is True:
draw_faces(context, myobj, None, None)
if scene.measureit_rf is True:
bgl.glColor3f(1.0, 1.0, 1.0)
rfcolor = scene.measureit_rf_color
rfborder = scene.measureit_rf_border
rfline = scene.measureit_rf_line
bgl.glLineWidth(rfline)
bgl.glColor4f(rfcolor[0], rfcolor[1], rfcolor[2], rfcolor[3])
x1 = rfborder
x2 = width - rfborder
y1 = int(math.ceil(rfborder / (width / height)))
y2 = height - y1
draw_rectangle((x1, y1), (x2, y2))
# --------------------------------
# copy pixels to temporary area
# --------------------------------
bgl.glFinish()
bgl.glReadPixels(0, 0, width, height, bgl.GL_RGBA, bgl.GL_FLOAT, buffer) # read image data
for y in range(0, tile_y):
# final image pixels position
p1 = (y * width * 4) + (row * tile_y * width * 4) + (col * tile_x * 4)
p2 = p1 + (tile_x * 4)
# buffer pixels position
b1 = y * width * 4
b2 = b1 + (tile_x * 4)
if p1 < totpixel4: # avoid pixel row out of area
if col == col_num - 1: # avoid pixel columns out of area
p2 -= cut4
b2 -= cut4
tmp_pixels[p1:p2] = buffer[b1:b2]
# -----------------------
# Copy temporary to final
# -----------------------
out.pixels = tmp_pixels[:] # Assign image data
img.gl_free() # free opengl image memory
# delete image
img.user_clear()
bpy.data.images.remove(img)
# remove temp file
os.remove(outpath)
# reset
bgl.glEnable(bgl.GL_SCISSOR_TEST)
# -----------------------
# restore opengl defaults
# -----------------------
bgl.glLineWidth(1)
bgl.glDisable(bgl.GL_BLEND)
bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
# Saves image
if out is not None and (scene.measureit_render is True or animation is True):
ren_path = bpy.context.scene.render.filepath
filename = "mit_frame"
if len(ren_path) > 0:
if ren_path.endswith(os.path.sep):
initpath = os.path.realpath(ren_path) + os.path.sep
else:
(initpath, filename) = os.path.split(ren_path)
ftxt = "%04d" % scene.frame_current
outpath = os.path.join(initpath, filename + ftxt + ".png")
save_image(self, outpath, out)
settings.color_depth = depth
return True
except:
settings.color_depth = depth
print("Unexpected error:" + str(sys.exc_info()))
self.report({'ERROR'}, "MeasureIt: Unable to create render image")
return False
# --------------------------------------------------------------------
# Get the final render image and return as image object
#
# return None if no render available
# --------------------------------------------------------------------
def get_render_image(outpath):
saved = False
# noinspection PyBroadException
try:
# noinspection PyBroadException
try:
result = bpy.data.images['Render Result']
if result.has_data is False:
# this save produce to fill data image
result.save_render(outpath)
saved = True
except:
print("No render image found")
return None
# Save and reload
if saved is False:
result.save_render(outpath)
img = img_utils.load_image(outpath)
return img
except:
print("Unexpected render image error")
return None
# -------------------------------------
# Save image to file
# -------------------------------------
def save_image(self, filepath, myimage):
# noinspection PyBroadException
try:
# Save old info
settings = bpy.context.scene.render.image_settings
myformat = settings.file_format
mode = settings.color_mode
depth = settings.color_depth
# Apply new info and save
settings.file_format = 'PNG'
settings.color_mode = "RGBA"
settings.color_depth = '8'
myimage.save_render(filepath)
print("MeasureIt: Image " + filepath + " saved")
# Restore old info
settings.file_format = myformat
settings.color_mode = mode
settings.color_depth = depth
except:
print("Unexpected error:" + str(sys.exc_info()))
self.report({'ERROR'}, "MeasureIt: Unable to save render image")
return