Skip to content

Commit

Permalink
Merge branch 'v3.2.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
vxlcoder committed Mar 4, 2022
2 parents 3d8b3a4 + f98772e commit 2e76744
Show file tree
Hide file tree
Showing 89 changed files with 1,357 additions and 502 deletions.
25 changes: 22 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

NAME = RetopoFlow

VERSION = "v3.2.5"
VERSION = "v3.2.6"

# NOTE: one of the following must be uncommented
# RELEASE = "alpha"
Expand Down Expand Up @@ -81,15 +81,34 @@ thumbnails:
# create thumbnails
cd help && python3 $(CREATE_THUMBNAILS)

build: check
build-github: check
mkdir -p $(BUILD_DIR)
mkdir -p $(BUILD_DIR)/$(NAME)

# copy files over to build folder
# note: rsync flag -a == archive (same as -rlptgoD)
rsync -av --progress . $(BUILD_DIR)/$(NAME) --exclude-from="Makefile_excludes"
# touch file so that we know it was packaged by us
cd $(BUILD_DIR) && echo "This file indicates that CG Cookie built this version of RetopoFlow." > $(CGCOOKIE_BUILT)
cd $(BUILD_DIR) && echo "This file indicates that CG Cookie built this version of RetopoFlow for release on GitHub." > $(CGCOOKIE_BUILT)
# run debug cleanup
cd $(BUILD_DIR) && python3 $(DEBUG_CLEANUP) "YES!"
# create thumbnails
cd $(BUILD_DIR)/$(NAME)/help && python3 $(CREATE_THUMBNAILS)
# zip it!
cd $(BUILD_DIR) && zip -r $(ZIP_FILE) $(NAME)

@echo
@echo $(NAME)" "$(VERSION)" is ready"

build-blendermarket: check
mkdir -p $(BUILD_DIR)
mkdir -p $(BUILD_DIR)/$(NAME)

# copy files over to build folder
# note: rsync flag -a == archive (same as -rlptgoD)
rsync -av --progress . $(BUILD_DIR)/$(NAME) --exclude-from="Makefile_excludes"
# touch file so that we know it was packaged by us
cd $(BUILD_DIR) && echo "This file indicates that CG Cookie built this version of RetopoFlow for release on Blender Market." > $(CGCOOKIE_BUILT)
# run debug cleanup
cd $(BUILD_DIR) && python3 $(DEBUG_CLEANUP) "YES!"
# create thumbnails
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ All mesh generation is quad-based (unless you explicitly create other ngons) and

You may purchase RetopoFlow on the [Blender Market](https://blendermarket.com/products/retopoflow/)

Purchasing a license entitles you to tool support and helps ensure RetopoFlows continued development.
Purchasing a copy entitles you to tool support and helps ensure RetopoFlows continued development.


## Getting Support
Expand Down
10 changes: 8 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"author": "Jonathan Denning, Jonathan Lampel, Jonathan Williamson, Patrick Moore, Patrick Crawford, Christopher Gearhart",
"location": "View 3D > Header",
"blender": (2, 93, 0),
"version": (3, 2, 5),
"version": (3, 2, 6),
# "warning": "Alpha", # used for warning icon and text in addons panel
# "warning": "Beta",
# "warning": "Release Candidate 1",
Expand Down Expand Up @@ -390,9 +390,15 @@ def in_quadview(context):
return False


rf_label_extra = " (?)"
if configoptions.retopoflow_version_git: rf_label_extra = " (git)"
elif not configoptions.retopoflow_cgcookie_built: rf_label_extra = " (self)"
elif configoptions.retopoflow_github: rf_label_extra = " (github)"
elif configoptions.retopoflow_blendermarket: rf_label_extra = ""

class VIEW3D_PT_RetopoFlow(Panel):
"""RetopoFlow Blender Menu"""
bl_label = f'RetopoFlow {retopoflow_version}{" (git)" if configoptions.retopoflow_version_git else " (self)" if not configoptions.retopoflow_cgcookie_built else ""}'
bl_label = f'RetopoFlow {retopoflow_version}{rf_label_extra}'
bl_space_type = 'VIEW_3D'
bl_region_type = 'HEADER'
# bl_ui_units_x = 100
Expand Down
50 changes: 38 additions & 12 deletions addon_common/common/bmesh_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,14 @@ def triangulateFace(verts):
from gpu_extras.batch import batch_for_shader
from .shaders import Shader

Drawing.glCheckError(f'Pre-compile check: bmesh render shader')
verts_vs, verts_fs = Shader.parse_file('bmesh_render_verts.glsl', includeVersion=False)
verts_shader = gpu.types.GPUShader(verts_vs, verts_fs)
edges_vs, edges_fs = Shader.parse_file('bmesh_render_edges.glsl', includeVersion=False)
edges_shader = gpu.types.GPUShader(edges_vs, edges_fs)
faces_vs, faces_fs = Shader.parse_file('bmesh_render_faces.glsl', includeVersion=False)
faces_shader = gpu.types.GPUShader(faces_vs, faces_fs)
Drawing.glCheckError(f'Compiled bmesh render shader')


class BufferedRender_Batch:
Expand All @@ -147,43 +149,58 @@ def __init__(self, drawtype):
self.batch = None
self._quarantine.setdefault(self.shader, set())

def buffer(self, pos, norm, sel, warn):
def buffer(self, pos, norm, sel, warn, pin, seam):
if self.shader == None: return
if self.shader_type == 'POINTS':
data = {
# repeat each value 6 times
'vert_pos': [p for p in pos for __ in range(6)],
'vert_norm': [n for n in norm for __ in range(6)],
'selected': [s for s in sel for __ in range(6)],
'warning': [w for w in warn for __ in range(6)],
'pinned': [p for p in pin for __ in range(6)],
'seam': [p for p in seam for __ in range(6)],
'vert_offset': [o for _ in pos for o in [(0,0), (1,0), (0,1), (0,1), (1,0), (1,1)]],
}
elif self.shader_type == 'LINES':
data = {
'vert_pos0': [p0 for (p0,p1) in zip(pos[0::2], pos[1::2] ) for __ in range(6)],
'vert_pos1': [p1 for (p0,p1) in zip(pos[0::2], pos[1::2] ) for __ in range(6)],
'vert_norm': [n0 for (n0,n1) in zip(norm[0::2],norm[1::2]) for __ in range(6)],
'selected': [s0 for (s0,s1) in zip(sel[0::2], sel[1::2] ) for __ in range(6)],
'warning': [s0 for (s0,s1) in zip(warn[0::2], warn[1::2] ) for __ in range(6)],
# repeat each value 6 times
# 'vert_pos0': [p0 for (p0,p1) in zip( pos[0::2], pos[1::2]) for __ in range(6)],
# 'vert_pos1': [p1 for (p0,p1) in zip( pos[0::2], pos[1::2]) for __ in range(6)],
# 'vert_norm': [n0 for (n0,n1) in zip(norm[0::2], norm[1::2]) for __ in range(6)],
# 'selected': [s0 for (s0,s1) in zip( sel[0::2], sel[1::2]) for __ in range(6)],
# 'warning': [s0 for (s0,s1) in zip(warn[0::2], warn[1::2]) for __ in range(6)],
# 'pinned': [s0 for (s0,s1) in zip( pin[0::2], pin[1::2]) for __ in range(6)],
# 'seam': [s0 for (s0,s1) in zip(seam[0::2], seam[1::2]) for __ in range(6)],
'vert_pos0': [p0 for p0 in pos[ 0::2] for __ in range(6)],
'vert_pos1': [p1 for p1 in pos[ 1::2] for __ in range(6)],
'vert_norm': [n for n in norm[0::2] for __ in range(6)],
'selected': [s for s in sel[ 0::2] for __ in range(6)],
'warning': [w for w in warn[0::2] for __ in range(6)],
'pinned': [p for p in pin[ 0::2] for __ in range(6)],
'seam': [s for s in seam[0::2] for __ in range(6)],
'vert_offset': [o for _ in pos[0::2] for o in [(0,0), (0,1), (1,1), (0,0), (1,1), (1,0)]],
}
elif self.shader_type == 'TRIS':
data = {
'vert_pos': pos,
'vert_norm': norm,
'selected': sel,
'pinned': pin,
# 'seam': seam,
}
else: assert False, 'BufferedRender_Batch.buffer: Unhandled type: ' + self.shader_type
self.batch = batch_for_shader(self.shader, 'TRIS', data) # self.shader_type, data)
self.batch = batch_for_shader(self.shader, 'TRIS', data)
self.count = len(pos)

def set_options(self, prefix, opts):
if not opts: return
shader = self.shader

prefix = '%s ' % prefix if prefix else ''
prefix = f'{prefix} ' if prefix else ''

def set_if_set(opt, cb):
opt = '%s%s' % (prefix, opt)
opt = f'{prefix}{opt}'
if opt not in opts: return
cb(opts[opt])
Drawing.glCheckError('setting %s to %s' % (str(opt), str(opts[opt])))
Expand All @@ -193,6 +210,8 @@ def set_if_set(opt, cb):
set_if_set('color', lambda v: self.uniform_float('color', v))
set_if_set('color selected', lambda v: self.uniform_float('color_selected', v))
set_if_set('color warning', lambda v: self.uniform_float('color_warning', v))
set_if_set('color pinned', lambda v: self.uniform_float('color_pinned', v))
set_if_set('color seam', lambda v: self.uniform_float('color_seam', v))
set_if_set('hidden', lambda v: self.uniform_float('hidden', v))
set_if_set('offset', lambda v: self.uniform_float('offset', v))
set_if_set('dotoffset', lambda v: self.uniform_float('dotoffset', v))
Expand Down Expand Up @@ -237,16 +256,23 @@ def draw(self, opts):
self.uniform_float('color', (1,1,1,0.5))
self.uniform_float('color_selected', (0.5,1,0.5,0.5))
self.uniform_float('color_warning', (1.0,0.5,0.0,0.5))
self.uniform_float('color_pinned', (1.0,0.0,0.5,0.5))
self.uniform_float('color_seam', (1.0,0.0,0.5,0.5))
self.uniform_float('hidden', 0.9)
self.uniform_float('offset', 0)
self.uniform_float('dotoffset', 0)
self.uniform_float('vert_scale', (1, 1, 1))
self.uniform_float('radius', 1) #random.random()*10)

nosel = opts.get('no selection', False)
nowarn = opts.get('no warning', False)
nosel = opts.get('no selection', False)
nowarn = opts.get('no warning', False)
nopin = opts.get('no pinned', False)
noseam = opts.get('no seam', False)

self.uniform_bool('use_selection', [not nosel]) # must be a sequence!?
self.uniform_bool('use_warning', [not nowarn]) # must be a sequence!?
self.uniform_bool('use_pinned', [not nopin]) # must be a sequence!?
self.uniform_bool('use_seam', [not noseam]) # must be a sequence!?
self.uniform_bool('use_rounding', [self.drawtype == self.POINTS]) # must be a sequence!?

self.uniform_float('matrix_m', opts['matrix model'])
Expand Down Expand Up @@ -298,7 +324,7 @@ def draw(self, opts):
self._draw(1, 1, 1)

if opts['draw mirrored'] and (mx or my or mz):
self.set_options('%s mirror' % self.options_prefix, opts)
self.set_options(f'{self.options_prefix} mirror', opts)
if mx: self._draw(-1, 1, 1)
if my: self._draw( 1, -1, 1)
if mz: self._draw( 1, 1, -1)
Expand Down
151 changes: 86 additions & 65 deletions addon_common/common/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
from .functools import find_fns


# the following line suppresses a Blender 3.1.0 bug
# https://developer.blender.org/T95592
bgl.glGetError()


class Cursors:
# https://docs.blender.org/api/current/bpy.types.Window.html#bpy.types.Window.cursor_set
_cursors = {
Expand Down Expand Up @@ -117,70 +122,6 @@ def warp(x, y): bpy.context.window.cursor_warp(x, y)




if bversion() >= "2.80":
import gpu
from gpu.types import GPUShader
from gpu_extras.batch import batch_for_shader

# https://docs.blender.org/api/blender2.8/gpu.html#triangle-with-custom-shader

def create_shader(fn_glsl):
path_here = os.path.dirname(os.path.realpath(__file__))
path_shaders = os.path.join(path_here, 'shaders')
path_glsl = os.path.join(path_shaders, fn_glsl)
txt = open(path_glsl, 'rt').read()
vert_source, frag_source = Shader.parse_string(txt)
try:
return GPUShader(vert_source, frag_source)
except Exception as e:
print('ERROR WHILE COMPILING SHADER %s' % fn_glsl)
assert False

# 2D point
shader_2D_point = create_shader('point_2D.glsl')
batch_2D_point = batch_for_shader(shader_2D_point, 'TRIS', {"pos": [(0,0), (1,0), (1,1), (0,0), (1,1), (0,1)]})

# 2D line segment
shader_2D_lineseg = create_shader('lineseg_2D.glsl')
batch_2D_lineseg = batch_for_shader(shader_2D_lineseg, 'TRIS', {"pos": [(0,0), (1,0), (1,1), (0,0), (1,1), (0,1)]})

# 2D circle
shader_2D_circle = create_shader('circle_2D.glsl')
# create batch to draw large triangle that covers entire clip space (-1,-1)--(+1,+1)
cnt = 100
pts = [
p for i0 in range(cnt)
for p in [
((i0+0)/cnt,0), ((i0+1)/cnt,0), ((i0+1)/cnt,1),
((i0+0)/cnt,0), ((i0+1)/cnt,1), ((i0+0)/cnt,1),
]
]
batch_2D_circle = batch_for_shader(shader_2D_circle, 'TRIS', {"pos": pts})

# 3D circle
shader_3D_circle = create_shader('circle_3D.glsl')
# create batch to draw large triangle that covers entire clip space (-1,-1)--(+1,+1)
cnt = 100
pts = [
p for i0 in range(cnt)
for p in [
((i0+0)/cnt,0), ((i0+1)/cnt,0), ((i0+1)/cnt,1),
((i0+0)/cnt,0), ((i0+1)/cnt,1), ((i0+0)/cnt,1),
]
]
batch_3D_circle = batch_for_shader(shader_3D_circle, 'TRIS', {"pos": pts})

# 3D triangle
shader_3D_triangle = create_shader('triangle_3D.glsl')
batch_3D_triangle = batch_for_shader(shader_3D_triangle, 'TRIS', {'pos': [(1,0), (0,1), (0,0)]})

# 3D triangle
shader_2D_triangle = create_shader('triangle_2D.glsl')
batch_2D_triangle = batch_for_shader(shader_2D_triangle, 'TRIS', {'pos': [(1,0), (0,1), (0,0)]})



class Drawing:
_instance = None
_dpi_mult = 1
Expand Down Expand Up @@ -569,7 +510,15 @@ def glCheckError(title):
traceback.print_stack()
return True

def get_view_origin(self, *, orthographic_distance=1000):
focus = self.r3d.view_location
rot = self.r3d.view_rotation
dist = self.r3d.view_distance if self.r3d.is_perspective else orthographic_distance
return focus + (rot @ Vector((0, 0, dist)))

# # the following fails in weird ways when in orthographic projection
# center = Point2D((self.area.width / 2, self.area.height / 2))
# return Point(region_2d_to_origin_3d(self.rgn, self.r3d, center))

def Point2D_to_Ray(self, p2d):
o = Point(region_2d_to_origin_3d(self.rgn, self.r3d, p2d))
Expand Down Expand Up @@ -824,8 +773,80 @@ def draw(self, draw_type:"CC_DRAW"):
self.glCheckError('done with draw')
self._draw = None


Drawing.glCheckError(f'pre-init check: Drawing')
Drawing.initialize()
Drawing.glCheckError(f'post-init check: Drawing')




if bversion() >= "2.80":
import gpu
from gpu.types import GPUShader
from gpu_extras.batch import batch_for_shader

# https://docs.blender.org/api/blender2.8/gpu.html#triangle-with-custom-shader

def create_shader(fn_glsl):
path_here = os.path.dirname(os.path.realpath(__file__))
path_shaders = os.path.join(path_here, 'shaders')
path_glsl = os.path.join(path_shaders, fn_glsl)
txt = open(path_glsl, 'rt').read()
vert_source, frag_source = Shader.parse_string(txt)
try:
Drawing.glCheckError(f'pre-compile check: {fn_glsl}')
ret = GPUShader(vert_source, frag_source)
Drawing.glCheckError(f'post-compile check: {fn_glsl}')
return ret
except Exception as e:
print('ERROR WHILE COMPILING SHADER %s' % fn_glsl)
assert False

Drawing.glCheckError(f'Pre-compile check: point, lineseg, circle, triangle shaders')

# 2D point
shader_2D_point = create_shader('point_2D.glsl')
batch_2D_point = batch_for_shader(shader_2D_point, 'TRIS', {"pos": [(0,0), (1,0), (1,1), (0,0), (1,1), (0,1)]})

# 2D line segment
shader_2D_lineseg = create_shader('lineseg_2D.glsl')
batch_2D_lineseg = batch_for_shader(shader_2D_lineseg, 'TRIS', {"pos": [(0,0), (1,0), (1,1), (0,0), (1,1), (0,1)]})

# 2D circle
shader_2D_circle = create_shader('circle_2D.glsl')
# create batch to draw large triangle that covers entire clip space (-1,-1)--(+1,+1)
cnt = 100
pts = [
p for i0 in range(cnt)
for p in [
((i0+0)/cnt,0), ((i0+1)/cnt,0), ((i0+1)/cnt,1),
((i0+0)/cnt,0), ((i0+1)/cnt,1), ((i0+0)/cnt,1),
]
]
batch_2D_circle = batch_for_shader(shader_2D_circle, 'TRIS', {"pos": pts})

# 3D circle
shader_3D_circle = create_shader('circle_3D.glsl')
# create batch to draw large triangle that covers entire clip space (-1,-1)--(+1,+1)
cnt = 100
pts = [
p for i0 in range(cnt)
for p in [
((i0+0)/cnt,0), ((i0+1)/cnt,0), ((i0+1)/cnt,1),
((i0+0)/cnt,0), ((i0+1)/cnt,1), ((i0+0)/cnt,1),
]
]
batch_3D_circle = batch_for_shader(shader_3D_circle, 'TRIS', {"pos": pts})

# 3D triangle
shader_3D_triangle = create_shader('triangle_3D.glsl')
batch_3D_triangle = batch_for_shader(shader_3D_triangle, 'TRIS', {'pos': [(1,0), (0,1), (0,0)]})

# 3D triangle
shader_2D_triangle = create_shader('triangle_2D.glsl')
batch_2D_triangle = batch_for_shader(shader_2D_triangle, 'TRIS', {'pos': [(1,0), (0,1), (0,0)]})

Drawing.glCheckError(f'Compiled point, lineseg, circle shaders')


######################################################################################################
Expand Down
Loading

0 comments on commit 2e76744

Please sign in to comment.