Skip to content

Commit

Permalink
Geodesic mesaure export (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleFirefox authored Mar 5, 2021
1 parent e95a790 commit c2d7d08
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
15 changes: 14 additions & 1 deletion addon/operator/geopath_datastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def click_add_target(self, context, x, y):

self.geo_data = [geos, fixed, close, far]

print(self.path)
# print(self.path)

return

Expand All @@ -192,3 +192,16 @@ def draw(self, context):
mx = self.cut_ob.matrix_world
draw.draw_3d_points(
context, [mx @ self.target_loc], 8, color=(0, 1, 0, 1))

def get_whole_path(self):
pts = []
pts.append(self.target_loc)
pts.extend(self.path)
pts.remove(pts[1])
# This will remove what will end up being
# the first element of the path which is not where you clicked
# deleting for now
#pts.pop()
pts.append(self.seed_loc)
pts.reverse()
return pts
5 changes: 4 additions & 1 deletion addon/operator/measures_circular_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def invoke(self, context, event):
# Running in loop until we leave the modal
def modal(self, context, event):
# Free navigation
if event.type == 'MIDDLEMOUSE':
if event.type in {
'MIDDLEMOUSE', 'WHEELUPMOUSE', 'WHEELDOWNMOUSE',
'WHEELINMOUSE', 'WHEELOUTMOUSE'
}:
return {'PASS_THROUGH'}

# Confirm
Expand Down
45 changes: 37 additions & 8 deletions addon/operator/measures_geodesic_operator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import bpy
import bmesh
import traceback

from ..utility.draw import draw_quad, draw_text, get_blf_text_dims
Expand Down Expand Up @@ -75,6 +76,7 @@ def handle_main(self, context, event):

# Confirm path an exit gracefully
elif event.type == 'RET' and event.value == 'PRESS':
self.execute(context)
self.remove_shaders(context)
return {'FINISHED'}

Expand Down Expand Up @@ -129,8 +131,31 @@ def draw(self, context):
# layout.prop(self, 'plane_rotation')

def execute(self, context):
# scene = context.scene
# ob = scene.objects.get("Avatar")

mx = context.object.matrix_world
path = [mx @ v for v in self.geopath.get_whole_path()]

if len(path) == 0:
return {'FINISHED'}

bm = bmesh.new()
vertices = []
edges = []
for vert in path:
vertices.append(bm.verts.new(vert))

for i in range(1, len(path)):
edges.append(bm.edges.new((vertices[i-1], vertices[i])))
# print("adding {:3f} - {:3f}".format(i-1, i))

me = bpy.data.meshes.new("GeodesicPath")
bm.to_mesh(me)
obj = bpy.data.objects.new("GeodesicPath", me)
context.collection.objects.link(obj)
obj.select_set(True)

bm.free()

return {'FINISHED'}

def remove_shaders(self, context):
Expand Down Expand Up @@ -195,17 +220,21 @@ def draw_debug_panel(self, context):
# Draw path
text = ""

mx = context.object.matrix_world

if self.geopath.seed_loc is not None:
seed = mx @ self.geopath.seed_loc
text += "START: ({:.3f}, {:.3f}, {:.3f}) ".format(
self.geopath.seed_loc.x,
self.geopath.seed_loc.y,
self.geopath.seed_loc.z)
seed.x,
seed.y,
seed.z)

if self.geopath.target_loc is not None:
target = mx @ self.geopath.target_loc
text += "END: ({:.3f}, {:.3f}, {:.3f})".format(
self.geopath.target_loc.x,
self.geopath.target_loc.y,
self.geopath.target_loc.z)
target.x,
target.y,
target.z)

if len(text) != 0:
draw_text(
Expand Down

0 comments on commit c2d7d08

Please sign in to comment.