Commit e189ec0d authored by Gert De Roost's avatar Gert De Roost

EWOCprojects stuff

parent 9d66afed
# ##### 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 #####
# Contributed to by
# meta-androcto #
bl_info = {
"name": "EWOCprojects tools",
"author": "Gert De Roost - paleajed",
"version": (1, 0, 0),
"blender": (2, 6, 3),
"location": "View3D > Toolbar and View3D > Specials (W-key)",
"description": "Edit mode tools - contrib version",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Mesh"}
if "bpy" in locals():
import imp
imp.reload(mesh_edgetune)
imp.reload(mesh_quadder)
imp.reload(mesh_paredge)
imp.reload(mesh_edgegrow)
imp.reload(mesh_fanconnect)
imp.reload(mesh_filletplus)
imp.reload(object_fastorigin)
imp.reload(mesh_laprelax)
imp.reload(mesh_innerweld)
imp.reload(mesh_straightenplus)
imp.reload(mesh_floodsel)
imp.reload(mesh_deathguppie)
imp.reload(mesh_selproject)
else:
from . import mesh_edgetune
from . import mesh_quadder
from . import mesh_paredge
from . import mesh_edgegrow
from . import mesh_fanconnect
from . import mesh_filletplus
from . import object_fastorigin
from . import mesh_laprelax
from . import mesh_innerweld
from . import mesh_straightenplus
from . import mesh_floodsel
from . import mesh_deathguppie
from . import mesh_selproject
import bpy
class VIEW3D_MT_edit_mesh_paleajed(bpy.types.Menu):
# Define the "Extras" menu
bl_idname = "VIEW3D_MT_edit_mesh_paleajed"
bl_label = "EWOCprojects tools"
def draw(self, context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator("mesh.edgetune",
text="EdgeTune")
layout.operator("mesh.quadder",
text="Quadder")
layout.operator("mesh.paredge",
text="ParEdge")
layout.operator("mesh.edgegrow",
text="EdgeGrow")
layout.operator("mesh.fanconnect",
text="FanConnect")
layout.operator("f.op0_id",
text="FilletPlus")
layout.operator("object.fastorigin",
text="FastOrigin")
layout.operator("mesh.laprelax",
text="LapRelax")
layout.operator("mesh.polyredux",
text="PolyRedux")
layout.operator("mesh.innerweld",
text="InnerWeld")
layout.operator("mesh.straightenplus",
text="StraightenPlus")
layout.operator("mesh.floodsel",
text="FloodSel")
layout.operator("mesh.deathguppie",
text="DeathGuppie")
layout.operator("mesh.selproject",
text="SelProject")
class PaleajedPanel(bpy.types.Panel):
bl_label = 'EWOCprojects tools'
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
def draw(self, context):
scn = bpy.context.scene
layout = self.layout
layout.operator('mesh.edgetune')
layout.operator('mesh.quadder')
layout.operator('mesh.paredge')
if mesh_paredge.started:
layout.prop(scn, 'Distance')
layout.prop(scn, 'Both')
if scn.Both:
layout.prop(scn, 'Cap')
mesh_paredge.parchange = 1
bpy.context.region.tag_redraw()
layout.operator('mesh.edgegrow')
layout.operator('mesh.fanconnect')
layout.operator('f.op0_id', text="FIlletPlus")
layout.operator('object.fastorigin')
layout.operator('mesh.laprelax')
layout.operator('mesh.innerweld')
if not(mesh_straightenplus.started):
layout.operator("mesh.straightenplus")
else:
layout.label(text="ENTER or leftmouse to confirm")
layout.label(text="RightMouse or ESC to cancel")
layout.prop(scn, "Percentage")
if mesh_straightenplus.started and scn.Percentage != mesh_straightenplus.oldperc:
mesh_straightenplus.do_straighten()
mesh_straightenplus.oldperc = scn.Percentage
layout.prop(scn, "CancelAxis")
layout.operator("mesh.floodsel", text="Flood Sel")
if mesh_floodsel.started:
layout.prop(scn, "Multiple")
layout.prop(scn, "Preselection")
layout.prop(scn, "Diagonal")
layout.operator('mesh.deathguppie')
layout.prop(scn, "Smooth")
layout.prop(scn, "Inner")
if not(mesh_selproject.activated):
self.layout.operator("selproject.activate", text="Activate SelProject")
else:
if not(mesh_selproject.started):
self.layout.operator("mesh.selproject", text="Start SelProject")
if context.mode == "EDIT_MESH":
self.layout.prop(scn, "UseSel")
if not(scn.UseSel):
self.layout.prop(scn, "FromObject")
else:
mesh_selproject.fromobj = bpy.context.active_object.name
mesh_selproject.redomenus = 1
context.region.tag_redraw()
else:
self.layout.prop(scn, "FromObject")
self.layout.prop(scn, "ToObject")
else:
self.layout.label(text="ENTER to confirm")
if scn.FromObject != mesh_selproject.oldfromobj:
mesh_selproject.oldfromobj = scn.FromObject
mesh_selproject.redomenus = 1
context.region.tag_redraw()
mesh_selproject.redomenus = 1
# Register all operators and panels
# Define "Extras" menu
def menu_func(self, context):
self.layout.menu("VIEW3D_MT_edit_mesh_paleajed", icon="PLUGIN")
def register():
bpy.utils.register_module(__name__)
# Add "Extras" menu to the "Add Mesh" menu
bpy.types.VIEW3D_MT_edit_mesh_specials.prepend(menu_func)
def unregister():
bpy.utils.unregister_module(__name__)
# Remove "Extras" menu from the "Add Mesh" menu.
bpy.types.VIEW3D_MT_edit_mesh_specials.remove(menu_func)
if __name__ == "__main__":
register()
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
# ##### 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 #####
__bpydoc__ = """\
The FanConnect addon connects multiple selected verts to one single other vert.
Documentation
First go to User Preferences->Addons and enable the ParEdge addon in the Mesh category.
Go to EditMode, select all verts (including the vert to connect to) and invoke
the addon (button in the Mesh Tool panel).
Now leftclick (this will work with pre-selection highlighting) the single vert to connect to et voila...
"""
bl_info = {
"name": "FanConnect",
"author": "Gert De Roost",
"version": (0, 1, 2),
"blender": (2, 6, 3),
"location": "View3D > Tools",
"description": "Connects multiple selected verts to one single other vert.",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Mesh"}
if "bpy" in locals():
import imp
import bpy
from bpy_extras import *
from bgl import *
import bmesh
from mathutils import *
class FanConnect(bpy.types.Operator):
bl_idname = "mesh.fanconnect"
bl_label = "Fan Connect"
bl_description = "Connects multiple selected verts to one single other vert"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
obj = context.active_object
return (obj and obj.type == 'MESH' and context.mode == 'EDIT_MESH')
def invoke(self, context, event):
self.save_global_undo = bpy.context.user_preferences.edit.use_global_undo
bpy.context.user_preferences.edit.use_global_undo = False
do_fanconnect(self)
context.window_manager.modal_handler_add(self)
if eval(str(bpy.app.build_revision)[2:7]) >= 53207:
self._handle = bpy.types.SpaceView3D.draw_handler_add(redraw, (), 'WINDOW', 'POST_PIXEL')
else:
self._handle = context.region.callback_add(redraw, (), 'POST_PIXEL')
return {'RUNNING_MODAL'}
def modal(self, context, event):
global bm, mesh
global viewchange
global vertlist, hoververt
if event.type == "LEFTMOUSE":
# do connection
if hoververt != None:
vertlist.pop(vertlist.index(hoververt))
for v in vertlist:
for f in hoververt.link_faces:
if v in f.verts:
# when already face: split it
bmesh.utils.face_split(f, v, hoververt)
for v in vertlist:
v2 = None
for e in v.link_edges:
vertl = e.verts[:]
vertl.pop(vertl.index(v))
if vertl[0] in vertlist:
v2 = vertl[0]
if v2 != None:
already = 0
for f in hoververt.link_faces:
if v in f.verts and v2 in f.verts:
already = 1
break
# if no face already between to first and selected vert: make it
if already == 0:
bm.faces.new([v, hoververt, v2])
bm.free()
if eval(str(bpy.app.build_revision)[2:7]) >= 53207:
bpy.types.SpaceView3D.draw_handler_remove(self._handle, "WINDOW")
else:
context.region.callback_remove(self._handle)
bpy.context.user_preferences.edit.use_global_undo = self.save_global_undo
bpy.ops.object.editmode_toggle()
bpy.ops.object.editmode_toggle()
return {'FINISHED'}
elif event.type in ["MIDDLEMOUSE"]:
# user transforms view
viewchange = 1
return {"PASS_THROUGH"}
elif event.type in ["WHEELDOWNMOUSE", "WHEELUPMOUSE"]:
# user transforms view
viewchange = 1
return {"PASS_THROUGH"}
elif event.type == "MOUSEMOVE":
mx = event.mouse_region_x
my = event.mouse_region_y
# check for vert mouse hovers over
hoververt = None
for v in vertlist:
x, y, dummy = getscreencoords(v.co)
# max distance 5 pixels
if abs(mx - x) < 5 and abs(my - y) < 5:
hoververt = v
break
region.tag_redraw()
return {'RUNNING_MODAL'}
return {'RUNNING_MODAL'}
def panel_func(self, context):
self.layout.label(text="FanConnect:")
self.layout.operator("mesh.fanconnect", text="Connect mult")
def register():
bpy.utils.register_module(__name__)
bpy.types.VIEW3D_PT_tools_meshedit.append(panel_func)
def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.VIEW3D_PT_tools_meshedit.remove(panel_func)
if __name__ == "__main__":
register()
def adapt():
global matrix, selobj
# Rotating / panning / zooming 3D view is handled here.
# Creates a matrix.
if selobj.rotation_mode == "AXIS_ANGLE":
# object rotationmode axisangle
ang, x, y, z = selobj.rotation_axis_angle
matrix = Matrix.Rotation(-ang, 4, Vector((x, y, z)))
elif selobj.rotation_mode == "QUATERNION":
# object rotationmode euler
w, x, y, z = selobj.rotation_quaternion
x = -x
y = -y
z = -z
quat = Quaternion([w, x, y, z])
matrix = quat.to_matrix()
matrix.resize_4x4()
else:
# object rotationmode euler
ax, ay, az = selobj.rotation_euler
mat_rotX = Matrix.Rotation(-ax, 4, 'X')
mat_rotY = Matrix.Rotation(-ay, 4, 'Y')
mat_rotZ = Matrix.Rotation(-az, 4, 'Z')
if selobj.rotation_mode == "XYZ":
matrix = mat_rotX * mat_rotY * mat_rotZ
elif selobj.rotation_mode == "XZY":
matrix = mat_rotX * mat_rotZ * mat_rotY
elif selobj.rotation_mode == "YXZ":
matrix = mat_rotY * mat_rotX * mat_rotZ
elif selobj.rotation_mode == "YZX":
matrix = mat_rotY * mat_rotZ * mat_rotX
elif selobj.rotation_mode == "ZXY":
matrix = mat_rotZ * mat_rotX * mat_rotY
elif selobj.rotation_mode == "ZYX":
matrix = mat_rotZ * mat_rotY * mat_rotX
# handle object scaling
sx, sy, sz = selobj.scale
mat_scX = Matrix.Scale(sx, 4, Vector([1, 0, 0]))
mat_scY = Matrix.Scale(sy, 4, Vector([0, 1, 0]))
mat_scZ = Matrix.Scale(sz, 4, Vector([0, 0, 1]))
matrix = mat_scX * mat_scY * mat_scZ * matrix
def getscreencoords(vector):
# calculate screencoords of given Vector
region = bpy.context.region
rv3d = bpy.context.space_data.region_3d
pvector = vector * matrix
pvector = pvector + selobj.location
svector = view3d_utils.location_3d_to_region_2d(region, rv3d, pvector)
if svector == None:
return [0, 0 ,0]
else:
return [svector[0], svector[1], pvector[2]]
def do_fanconnect(self):
global bm, mesh, selobj, region
global vertlist, viewchange
# main operation
context = bpy.context
region = context.region
selobj = bpy.context.active_object
mesh = selobj.data
bm = bmesh.from_edit_mesh(mesh)
area = bpy.context.area
vertlist = []
for v in bm.verts:
if v.select:
vertlist.append(v)
adapt()
viewchange = 0
def redraw():
global viewchange
if viewchange:
adapt()
viewchange = 0
# Draw mouseover highlighting.
# Draw single verts as boxes.
glColor3f(1.0,1.0,0)
if hoververt != None:
glBegin(GL_POLYGON)
x, y, dummy = getscreencoords(hoververt.co)
glVertex2f(x-4, y-4)
glVertex2f(x-4, y+4)
glVertex2f(x+4, y+4)
glVertex2f(x+4, y-4)
glEnd()
# -*- coding: utf-8 -*-
# ***** 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 *****
# ------ ------
bl_info = {
'name': 'FilletPlus',
'author': 'Gert De Roost - original by zmj100',
'version': (0, 4, 3),
'blender': (2, 6, 1),
'api': 43085,
'location': 'View3D > Tool Shelf',
'description': '',
'warning': '',
'wiki_url': '',
'tracker_url': '',
'category': 'Mesh' }
# ------ ------
import bpy
from bpy.props import FloatProperty, IntProperty, BoolProperty
import bmesh
from mathutils import Matrix
from math import cos, pi, degrees, sin, tan
def list_clear_(l):
l[:] = []
return l
def get_adj_v_(list_):
tmp = {}
for i in list_:
try: tmp[i[0]].append(i[1])
except KeyError: tmp[i[0]] = [i[1]]
try: tmp[i[1]].append(i[0])
except KeyError: tmp[i[1]] = [i[0]]
return tmp
# ------ ------
class FPbuffer():
an = 0
# ------ ------
def f_(list_0, startv, vertlist, face, adj, n, out, flip, radius):
dict_0 = get_adj_v_(list_0)
list_1 = [[dict_0[i][0], i, dict_0[i][1]] for i in dict_0 if (len(dict_0[i]) == 2)][0]
list_3 = []
for elem in list_1:
list_3.append(bm.verts[elem])
list_2 = []
p_ = list_3[1]
p = (list_3[1].co).copy()
p1 = (list_3[0].co).copy()
p2 = (list_3[2].co).copy()
vec1 = p - p1
vec2 = p - p2
ang = vec1.angle(vec2, any)
FPbuffer.an = round(degrees(ang))
# -- -- -- --
if FPbuffer.an == 180 or FPbuffer.an == 0.0:
return
# -- -- -- --
opp = adj
if radius == False:
h = adj * (1 / cos(ang * 0.5))
adj_ = adj
elif radius == True:
h = opp / sin(ang * 0.5)
adj_ = opp / tan(ang * 0.5)
p3 = p - (vec1.normalized() * adj_)
p4 = p - (vec2.normalized() * adj_)
rp = p - ((p - ((p3 + p4) * 0.5)).normalized() * h)
vec3 = rp - p3
vec4 = rp - p4
axis = vec1.cross(vec2)
if out == False:
if flip == False:
rot_ang = vec3.angle(vec4)
elif flip == True:
rot_ang = vec1.angle(vec2)
elif out == True:
rot_ang = (2 * pi) - vec1.angle(vec2)
for j in range(n + 1):
new_angle = rot_ang * j / n
mtrx = Matrix.Rotation(new_angle, 3, axis)
if out == False:
if flip == False:
tmp = p4 - rp
tmp1 = mtrx * tmp
tmp2 = tmp1 + rp
elif flip == True:
p3 = p - (vec1.normalized() * opp)
tmp = p3 - p
tmp1 = mtrx * tmp
tmp2 = tmp1 + p
elif out == True:
p4 = p - (vec2.normalized() * opp)
tmp = p4 - p
tmp1 = mtrx * tmp