Check canvas alignement
1.6.5 - feat: check canvas alignement of the Gp object compare to chosen draw axis
This commit is contained in:
@@ -253,24 +253,28 @@ def remapping(value, leftMin, leftMax, rightMin, rightMax):
|
||||
|
||||
#### GP funcs
|
||||
|
||||
def get_gp_draw_plane(context):
|
||||
def get_gp_draw_plane(context, obj=None):
|
||||
''' return tuple with plane coordinate and normal
|
||||
of the curent drawing accordign to geometry'''
|
||||
|
||||
settings = context.scene.tool_settings
|
||||
orient = settings.gpencil_sculpt.lock_axis#'VIEW', 'AXIS_Y', 'AXIS_X', 'AXIS_Z', 'CURSOR'
|
||||
loc = settings.gpencil_stroke_placement_view3d#'ORIGIN', 'CURSOR', 'SURFACE', 'STROKE'
|
||||
mat = context.object.matrix_world if context.object else None
|
||||
orient = settings.gpencil_sculpt.lock_axis #'VIEW', 'AXIS_Y', 'AXIS_X', 'AXIS_Z', 'CURSOR'
|
||||
loc = settings.gpencil_stroke_placement_view3d #'ORIGIN', 'CURSOR', 'SURFACE', 'STROKE'
|
||||
if obj:
|
||||
mat = obj.matrix_world
|
||||
else:
|
||||
mat = context.object.matrix_world if context.object else None
|
||||
|
||||
# -> placement
|
||||
if loc == "CURSOR":
|
||||
plane_co = context.scene.cursor.location
|
||||
else:#ORIGIN (also on origin if set to 'SURFACE', 'STROKE')
|
||||
|
||||
else: # ORIGIN (also on origin if set to 'SURFACE', 'STROKE')
|
||||
if not context.object:
|
||||
plane_co = None
|
||||
else:
|
||||
plane_co = context.object.matrix_world.to_translation()# context.object.location
|
||||
|
||||
|
||||
# -> orientation
|
||||
if orient == 'VIEW':
|
||||
#only depth is important, no need to get view vector
|
||||
@@ -294,6 +298,41 @@ def get_gp_draw_plane(context):
|
||||
|
||||
return plane_co, plane_no
|
||||
|
||||
def check_angle_from_view(obj=None, plane_no=None, context=None):
|
||||
'''Return angle to obj according to chosen drawing axis'''
|
||||
import math
|
||||
from bpy_extras import view3d_utils
|
||||
|
||||
if not context:
|
||||
context = bpy.context
|
||||
|
||||
if not plane_no:
|
||||
_plane_co, plane_no = get_gp_draw_plane(context, obj=obj)
|
||||
view_direction = view3d_utils.region_2d_to_vector_3d(context.region, context.region_data, (context.region.width/2.0, context.region.height/2.0))
|
||||
|
||||
angle = math.degrees(view_direction.angle(plane_no))
|
||||
|
||||
# correct angle value when painting from other side (seems a bit off...)
|
||||
if angle > 90:
|
||||
angle = abs(90 - (angle - 90))
|
||||
|
||||
# over angle warning
|
||||
if angle > 75:
|
||||
return angle, 'ERROR', f"Canvas not aligned at all! (angle: {angle:.2f}°), use Realign GP or change draw axis"
|
||||
|
||||
if angle > 6:
|
||||
return angle, 'ERROR', f'Canvas not aligned! angle: {angle:.2f}°, use Realign GP'
|
||||
|
||||
if angle > 3: # below 3 is reasonable (camera seem to view induce error !)
|
||||
return angle, 'INFO', f'Canvas almost aligned (angle: {angle:.2f}°)'
|
||||
|
||||
if angle == 0:
|
||||
return angle, 'INFO', f'Canvas perfectly aligned (angle: {angle:.2f}°)'
|
||||
|
||||
# below 1 consider aligned
|
||||
return angle, 'INFO', f'Canvas alignement seem ok (angle: {angle:.2f}°)'
|
||||
|
||||
|
||||
## need big update
|
||||
def create_gp_palette(gp_data_block,info) :
|
||||
palette = gp_data_block.palettes.active
|
||||
|
||||
Reference in New Issue
Block a user