UPDATE
Here another example in order to clarify this question, I did a video in order to resume the problem https://www.youtube.com/watch?v=yShhJOzkJBk:
here the addon working without the BGL CODE.... as you see the properties are working too:
but if I allow the BGL code many strange things happen:
- properties unavailable
- the mesh deforms uncontrollably
- in some cases blender crash
what I'm doing wrong?
here the full code of this test:
'''
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
END GPL LICENCE BLOCK
'''
bl_info = {
"name": "Test bgl + joinmeshr",
"author": "Diego Quevedo ( http://doshape.com/ )",
"version": (1, 0),
"blender": (2, 7 , 3),
"location": "View3D > EditMode > ToolShelf",
"description": "Testing bgl",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Mesh"}
import bpy
import bmesh
import mathutils
import math
from bpy_extras import view3d_utils
import time
import sys
import bgl
import blf
def draw_callback_px(self, context):
oa = bpy.context.active_object
obj = bpy.context.object
me = obj.data
bm = bmesh.from_edit_mesh(me)
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
override = bpy.context.copy()
viewport = area.regions[4]
v_m = area.spaces[0].region_3d.view_matrix #orientation matrix
vertices= [v for v in bm.verts if (v.select == True and v.hide == False)]
vn1 = vertices[0]
vn2 = bm.verts.new(vn1.co)
vn3 = bm.verts.new(vn1.co)
#vector conversion from view space to world space
vn1.select = False
vn2.select = True
vn3.select = False
bm.select_history.active
values = mathutils.Vector((1,0,0))*v_m
#the translation is done in global orientation without any constraints
bpy.ops.transform.translate(value=values)
#bpy.context.object.location += values #another way to translate
vn1.select = False
vn2.select = False
vn3.select = True
bm.select_history.active
values = mathutils.Vector((0,1,0))*v_m
bpy.ops.transform.translate(value=values)
vn3.select=False
vn1.select = True
bm.select_history.active
vn2.select = True
vn3.select = True
font_id = 0 # XXX, need to find out how best to get this.
# draw some text
#blf.position(font_id, 0, 0, 0)
#blf.size(font_id, 20, 72)
#blf.draw(font_id, oa.name)
# 50% alpha, 2 pixel width line
bgl.glEnable(bgl.GL_BLEND)
bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
bgl.glLineWidth(2)
bgl.glBegin(bgl.GL_LINE_STRIP)
bgl.glVertex3f(*vn1.co)
bgl.glVertex3f(*vn2.co)
bgl.glBegin(bgl.GL_LINE_STRIP)
bgl.glVertex3f(*vn1.co)
bgl.glVertex3f(*vn3.co)
#bgl.glVertex3f(*ob.matrix_world.translation)
#bgl.glVertex3f(*context.scene.cursor_location)
bgl.glEnd()
# restore opengl defaults
bgl.glLineWidth(1)
bgl.glDisable(bgl.GL_BLEND)
bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
#SEND TO CUT
#calcularangulos1(v1, v3, v2,angle)
listabasuravertices0= [vn2,vn3]
bmesh.ops.delete(bm, geom= listabasuravertices0, context=1)
bmesh.update_edit_mesh(me, True)
################################################################################
###### testbgl##########################################
################################################################################
class testbglOperator(bpy.types.Operator):
"testbgl"
bl_idname = 'mesh.testbgl'
bl_label = 'testbgl'
bl_description = "test bgl"
bl_options = {'REGISTER', 'UNDO'}
chboxjoin0 = bpy.props.BoolProperty(
name="Join",
default= True
)
chboxVert1 = bpy.props.BoolProperty(
name="Select",
default= True
)
def main(self, context, chboxjoin0, chboxVert1):
#almacena caras
obj = bpy.context.object
me = obj.data
bm = bmesh.from_edit_mesh(me)
v1, v2= [v for v in bm.verts if (v.select == True and v.hide == False)]
if chboxjoin0:
bpy.ops.mesh.vert_connect_path()
if chboxVert1:
v1.select = True
v2.select= True
else:
v1.select = False
v2.select= False
bmesh.update_edit_mesh(me, True)
@classmethod
def poll(self, context):
obj = context.active_object
return all([obj is not None, obj.type == 'MESH', obj.mode == 'EDIT'])
'''
def execute(self, context):
self.main(context, self.chboxjoin0, self.chboxVert1)
#bisectoroperator(self)
return {'FINISHED'}
'''
def modal(self, context, event):
context.area.tag_redraw()
if event.type in {'RIGHTMOUSE', 'ESC'}:
bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
return {'CANCELLED'}
return {'PASS_THROUGH'}
def invoke(self, context, event):
#self.main(context, self.chboxjoin0, self.chboxVert1)
if context.area.type == 'VIEW_3D':
# the arguments we pass the the callback
args = (self, context)
# Add the region OpenGL drawing callback
# draw in view space with 'POST_VIEW' and 'PRE_VIEW'
self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_px, args, 'WINDOW', 'POST_VIEW')
self.mouse_path = []
context.window_manager.modal_handler_add(self)
self.main(context, self.chboxjoin0, self.chboxVert1)
return {'RUNNING_MODAL'}
else:
self.report({'WARNING'}, "View3D not found, cannot run operator")
return {'CANCELLED'}
class TestbglOperatorPanel(bpy.types.Panel):
#bl_category = "Bisector"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
#bl_context = "editmode"
bl_label = " Test bgl"
@classmethod
def poll(cls, context):
return (context.mode == 'EDIT_MESH')
def draw(self, context):
layout = self.layout
row = layout.row(align=True)
row.operator(testbglOperator.bl_idname) #testbgl
def register():
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()
---------------------------
*I'm making some bgl test, but I have for example this problem:
In this case I have the template operator_modal_draw
and I want to add some int property
in order to change the line width... something like:
width = bpy.props.IntProperty(
name="line width",
default=10,
description="",
min=2
)
I did a lot of test but I don't have any good result
do you have some ideas?
draw_callback_px
, i can read the code, but you need to explain what you think it should be doing. Avoid mixing bmesh operations inside your bgl callback. if you want to define drawing characteristics for your bgl, then create a panel and use scene properties. As it stands I think the question is too broad. and the code far too long to be considered a condensed demo. $\endgroup$