Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sakana3 committed Aug 24, 2019
2 parents 65caf19 + 2221a19 commit 80bd707
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 32 deletions.
5 changes: 3 additions & 2 deletions Addons/PolyQuilt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
bl_info = {
"name" : "PolyQuilt",
"author" : "Sakana3",
"version": (1, 0, 8),
"version": (1, 0, 9),
"blender" : (2, 80, 0),
"location": "View3D > Mesh > PolyQuilt",
"description": "Lowpoly Tool",
Expand All @@ -25,7 +25,7 @@

import bpy
from bpy.utils.toolsystem import ToolDef
from .pq_operator import MESH_OT_poly_quilt
from .pq_operator import MESH_OT_poly_quilt , MESH_OT_poly_quilt_hold_lock
from .pq_operator_add_empty_object import *
from .pq_icon import *
from .pq_tool import ToolPolyQuilt , tool_poly_quilt , register_keymaps , unregister_keymaps
Expand All @@ -38,6 +38,7 @@
PQ_Gizmo_Preselect ,
PQ_GizmoGroup_Preselect ,
MESH_OT_poly_quilt ,
MESH_OT_poly_quilt_hold_lock ,
PQ_OT_SetupUnityLikeKeymap ,
PolyQuiltPreferences ,
PQ_OT_CheckAddonUpdate ,
Expand Down
45 changes: 45 additions & 0 deletions Addons/PolyQuilt/pq_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ class MESH_OT_poly_quilt(bpy.types.Operator):
default='LOWPOLY',
)

lock_hold : bpy.props.BoolProperty(
name = "Lock Hold" ,
default = False ,
description="Lock HOLD",
)

geometry_type : bpy.props.EnumProperty(
name="Geometry Type",
description="Geometry Type.",
Expand All @@ -97,6 +103,21 @@ class MESH_OT_poly_quilt(bpy.types.Operator):
description="Fix X=0",
)

loopcut_mode : bpy.props.EnumProperty(
name="LoopCut Mode",
description="LoopCut Mode",
items=[('EQUAL' , "Equal", "" ),
('EVEN' , "Even", "" ) ],
default='EQUAL',
)
loopcut_division : bpy.props.IntProperty(
name="LoopCut DIVISON",
description="LoopCut Division",
min = 0,
max = 16,
default=1,
)

def __del__(self):
MESH_OT_poly_quilt.handle_remove()

Expand Down Expand Up @@ -265,3 +286,27 @@ def RemoveTimerEvent( cls , context ) :
if cls.__timer_handle is not None:
context.window_manager.event_timer_remove(cls.__timer_handle)
cls.__timer_handle = None

is_lock_hold = False
def is_hold(self , hold : bool ) -> bool :
if self.is_lock_hold :
return True
if self.lock_hold :
return True
return hold

class MESH_OT_poly_quilt_hold_lock(bpy.types.Operator):
"""PolyQuilt hold lock"""
bl_idname = "mesh.poly_quilt_hold_lock"
bl_label = "PolyQuiltHoldLock"
bl_options = {'REGISTER' }

def invoke(self, context, event):
if MESH_OT_poly_quilt.is_lock_hold :
MESH_OT_poly_quilt.is_lock_hold = False
self.report({'INFO'}, "Unlock Hold" )
else :
MESH_OT_poly_quilt.is_lock_hold = True
self.report({'INFO'}, "Lock Hold" )
print (MESH_OT_poly_quilt.is_lock_hold)
return {'FINISHED'}
8 changes: 8 additions & 0 deletions Addons/PolyQuilt/pq_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def get_shading():
layout.prop(context.active_object.data, "use_mirror_x", toggle = toggle , icon_only = False , icon = "MOD_MIRROR" )
layout.prop(props, "fix_to_x_zero" ,text = "Fix X=0", toggle = toggle , icon_only = False, icon_value = custom_icon("icon_opt_x0") )

row = layout.row(align=True)
row.prop(props, "loopcut_mode" , text = "LOOPCUT" , expand = True )
row.prop(props, "loopcut_division" , text = "Div" , expand = True )


# shading = get_shading()
# if shading.type == 'SOLID':
# layout.prop( shading , "show_backface_culling", icon_value = custom_icon("icon_opt_backcull"))
Expand Down Expand Up @@ -134,6 +139,9 @@ def km_3d_view_tool_snap_utilities_line(tool_mouse):
{"properties": [("tool_mode", 'LOWPOLY')]}),
("mesh.poly_quilt", {"type": tool_mouse, "value": 'PRESS' , "ctrl": True},
{"properties": [("tool_mode", 'EXTRUDE')]}),
("mesh.poly_quilt", {"type": tool_mouse, "value": 'PRESS' , "alt": True},
{"properties": [("lock_hold", True)]}),
("mesh.poly_quilt_hold_lock", {"type": 'LEFT_ALT', "value": 'DOUBLE_CLICK' } , {} ),
]},
)

Expand Down
10 changes: 4 additions & 6 deletions Addons/PolyQuilt/subtools/subtool_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SubToolDefault(SubTool) :
def __init__(self,op,currentTarget) :
super().__init__(op)
self.currentTarget = currentTarget
self.LMBEvent = ButtonEventUtil('LEFTMOUSE' , self , SubToolDefault.LMBEventCallback , op.preferences )
self.LMBEvent = ButtonEventUtil('LEFTMOUSE' , self , SubToolDefault.LMBEventCallback , op , True )
self.isExit = False

def is_animated( self , context ) :
Expand All @@ -47,10 +47,8 @@ def is_animated( self , context ) :
@staticmethod
def LMBEventCallback(self , event ):
self.debugStr = str(event.type)
if event.type == MBEventType.Down :
pass

elif event.type == MBEventType.Release :
if event.type == MBEventType.Release :
self.isExit = True

elif event.type == MBEventType.Click :
Expand All @@ -72,7 +70,7 @@ def LMBEventCallback(self , event ):
if self.currentTarget.isEdge :
tools = []
if len(self.currentTarget.element.link_faces) > 0 :
tools.append(SubToolEdgeSlice(self.operator,self.currentTarget.element))
tools.append(SubToolEdgeSlice(self.operator,self.currentTarget))
if SubToolEdgeloopCut.Check(self.currentTarget) :
tools.append(SubToolEdgeloopCut(self.operator,self.currentTarget))
if SubToolEdgeExtrude.Check(self.currentTarget) :
Expand Down Expand Up @@ -115,7 +113,7 @@ def OnDraw( self , context ) :
def OnDraw3D( self , context ) :
if self.currentTarget.isNotEmpty :
color = self.color_highlight()
if self.LMBEvent.presureComplite :
if self.LMBEvent.is_hold :
color = self.color_delete()
self.currentTarget.Draw( self.bmo.obj , color , self.preferences )

Expand Down
37 changes: 29 additions & 8 deletions Addons/PolyQuilt/subtools/subtool_edge_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ class SubToolEdgeSlice(SubTool) :

def __init__(self,op, target ) :
super().__init__(op)
self.currentEdge = target
self.currentEdge = target.element
l0 = (self.bmo.local_to_world_pos(target.element.verts[0].co) - target.hitPosition).length
l1 = (self.bmo.local_to_world_pos(target.element.verts[1].co) - target.hitPosition).length
self.reference_point = 0 if l0 > l1 else 1
self.draw_deges = []
self.split_deges = []
self.endTriangles = {}
Expand Down Expand Up @@ -78,19 +81,40 @@ def OnDraw3D( self , context ) :
if self.draw_deges :
lines = []
for cuts in self.draw_deges :
v0 = cuts[0].verts[0].co.lerp( cuts[0].verts[1].co , self.sliceRate if cuts[2] == 0 else 1.0 - self.sliceRate )
v1 = cuts[1].verts[0].co.lerp( cuts[1].verts[1].co , self.sliceRate if cuts[3] == 0 else 1.0 - self.sliceRate )
v0 = cuts[0].verts[0].co.lerp( cuts[0].verts[1].co , self.calc_slice_rate( cuts[0] , cuts[2] , self.sliceRate ) )
v1 = cuts[1].verts[0].co.lerp( cuts[1].verts[1].co , self.calc_slice_rate( cuts[1] , cuts[3] , self.sliceRate ) )
v0 = self.bmo.local_to_world_pos( v0 )
v1 = self.bmo.local_to_world_pos( v1 )
lines.append(v0)
lines.append(v1)
draw_util.draw_lines3D( context , lines , self.color_split() , self.preferences.highlight_line_width , 1.0 , primitiveType = 'LINES' )

for i in range(self.operator.loopcut_division ) :
r = (i+1.0) / (self.operator.loopcut_division + 1.0)
v = self.bmo.local_to_world_pos( self.currentEdge.verts[0].co.lerp( self.currentEdge.verts[1].co , r) )
draw_util.draw_pivots3D( (v,) , self.preferences.highlight_vertex_size / 2 , self.color_split(0.5) )

def calc_slice_rate( self , edge , refarence , rate ) :
if self.operator.loopcut_mode == 'EVEN' :
len0 = self.currentEdge.calc_length()
len1 = edge.calc_length()
if self.reference_point == 0 :
rate = 1 - max( min( ( (len0 / len1) * (1-rate) ) , 1.0 ) , 0.0 )
else :
rate = max( min( ( len0 / len1 * rate ) , 1.0 ) , 0.0 )
return rate if refarence == 0 else 1.0 - rate

def CalcSplitRate( self , context ,coord , baseEdge ) :
p0 = baseEdge.verts[0].co
p1 = baseEdge.verts[1].co
for i in range(self.operator.loopcut_division ) :
r = (i+1.0) / (self.operator.loopcut_division + 1.0)
v = self.bmo.local_to_2d( p0 + ( p1 - p0 ) * r)
if ( coord - v ).length <= self.preferences.distance_to_highlight* dpm() :
return r

ray = pqutil.Ray.from_screen( context , coord ).world_to_object( self.bmo.obj )
dist = self.preferences.distance_to_highlight* dpm()

d = pqutil.CalcRateEdgeRay( self.bmo.obj , context , baseEdge , baseEdge.verts[0] , coord , ray , dist )

self.is_forcus = d > 0 and d < 1
Expand Down Expand Up @@ -166,10 +190,7 @@ def DoSlice( self , startEdge , sliceRate ) :
_slice = {}
for split_dege in self.split_deges :
edges.append( split_dege[0] )
if( split_dege[1] == 0 ) :
_slice[ split_dege[0] ] = sliceRate
else :
_slice[ split_dege[0] ] = 1.0 - sliceRate
_slice[ split_dege[0] ] = self.calc_slice_rate( split_dege[0] , split_dege[1] , sliceRate )

ret = bmesh.ops.subdivide_edges(
self.bmo.bm ,
Expand Down
2 changes: 1 addition & 1 deletion Addons/PolyQuilt/subtools/subtool_makepoly.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __init__(self,op,startElement , mouse_pos ) :
self.PlanlagtePos = self.calc_planned_construction_position()
self.targetElement = None
self.isEnd = False
self.LMBEvent = ButtonEventUtil('LEFTMOUSE' , self , SubToolMakePoly.LMBEventCallback , op.preferences )
self.LMBEvent = ButtonEventUtil('LEFTMOUSE' , self , SubToolMakePoly.LMBEventCallback , op )
self.mode = op.geometry_type
self.EdgeLoops = None
self.VertLoops = None
Expand Down
12 changes: 3 additions & 9 deletions Addons/PolyQuilt/utils/draw_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,25 @@
}
'''

class draw_batchs :
batchs = []
resources = []


def begin_draw() :
draw_batchs.batchs = []
draw_batchs.resources = []
pass

def end_draw() :
pass

def clear_draw() :
draw_batchs.batchs = []
pass

def batch_draw( shader , primitiveType , content , indices = None ) :
cnt = copy.deepcopy(content )
draw_batchs.resources.append(cnt)
if indices :
idx = copy.deepcopy(indices)
draw_batchs.resources.append(idx)
batch = batch_for_shader(shader, primitiveType , cnt , indices=idx )
else :
batch = batch_for_shader(shader, primitiveType , cnt )
batch.draw(shader)
draw_batchs.batchs.append(batch_draw)
return batch

#shader2D = gpu.types.GPUShader(vertex_shader, fragment_shader)
Expand Down
22 changes: 16 additions & 6 deletions Addons/PolyQuilt/utils/mouse_event_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class MBEventType(Enum) :
Release = auto()

class ButtonEventUtil :
def __init__( self , button : str , cls , func , preferences ) :
def __init__( self , button : str , cls , func , op , use_hold_lock = False ) :
self.op = op
self.button : str = button
self.eventFunc = func
self.eventClass = cls
Expand All @@ -45,11 +46,13 @@ def __init__( self , button : str , cls , func , preferences ) :
self.event = None
self.PressPos = mathutils.Vector((0.0,0.0))
self.presureCompOnce = False
self.preferences = preferences

self.preferences = op.preferences
self.use_hold_lock = use_hold_lock
@property
def presureValue(self) -> float :
if self.Presure == False :
if self.use_hold_lock and self.op.lock_hold :
return 0.0
elif self.Presure == False :
return 0.0
else :
lpt = self.preferences.longpress_time
Expand All @@ -66,6 +69,13 @@ def presureComplite(self) -> bool :
def isPresure(self) -> bool :
return self.presureValue >= 0.0001

@property
def is_hold(self) -> bool :
hold = self.presureCompOnce
if self.use_hold_lock :
hold = self.op.is_hold(hold)
return hold

def is_animated( self ) :
if self.Presure and not self.presureCompOnce :
return True
Expand All @@ -88,7 +98,7 @@ def Update( self , context , event ) :
if self.presureComplite :
self.presureCompOnce = True
if self.Presure :
if self.presureComplite :
if self.is_hold :
self.OnEvent( event , MBEventType.LongClick )
else :
self.OnEvent( event , MBEventType.Click )
Expand All @@ -107,7 +117,7 @@ def Update( self , context , event ) :
if (time.time()-self.PressTime ) > 0.15 and (self.mouse_pos-self.PressPos ).length > drag_threshold:
self.Presure = False
if self.Presure is False :
if self.presureCompOnce :
if self.is_hold :
self.OnEvent( event , MBEventType.LongPressDrag )
else :
self.OnEvent( event , MBEventType.Drag )
Expand Down

0 comments on commit 80bd707

Please sign in to comment.