Skip to content

Commit

Permalink
Adding Jayanam feedback (#7)
Browse files Browse the repository at this point in the history
* Adding Jayanam feedback

* Adding suggestions plus version fixing

* Adding Blender exact version for download

* Bumping up version
  • Loading branch information
UncleFirefox authored Mar 7, 2021
1 parent c2d7d08 commit 139d484
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 41 deletions.
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

This Blender addon is intended to accelearate the creation of measures for an Avatar.

## Running locally
The plugin requires the following tools to run:
## Features
- Circular measures using bisection
- Segments along the surface using Geodesic Path (WIP)

- [Blender 2.9+](https://www.blender.org/download/)
## Developing the plugin
Install the following tools:

- [Blender 2.90](https://download.blender.org/release/Blender2.90/) **Other versions won't work**
- [Visual Studio Code](https://code.visualstudio.com/)
- [Python for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
- [Blender Development](https://marketplace.visualstudio.com/items?itemName=JacquesLucke.blender-development)
Expand All @@ -19,6 +23,8 @@ Follow the instructions of the Blender Development plugin setup to connect to yo
## Installing in Blender
If you simply want to test how the addon works, get the latest version of the addon from the [releases page](https://github.com/UncleFirefox/Measures-Addon-For-Blender/releases).

**Remember, only Blender 2.90 works with this plugin**

Inside Blender go to: `Edit > Preferences`, go the the `Add-ons` section in the left menu, hit the `Install...` button and select the file you donwloaded.

Now at the top of the section in the search box if you type `Measures` the plugin should appear.
Expand All @@ -27,9 +33,16 @@ Now at the top of the section in the search box if you type `Measures` the plugi
<img src="screenshots/plugininstalled.jpg" width="80%">
</div>

You can install different versions of the plugin and activate the one you want to try.

<div style="text-align: center">
<img src="screenshots/versioncoexist.jpg" width="80%">
</div>

## Useful Links:
- [Blender Python API docs](https://docs.blender.org/api/current/)
- [Blender's Scripting for Artists Youtube Channel](https://www.youtube.com/watch?v=opZy2OJp8co&list=PLa1F2ddGya_8acrgoQr1fTeIuQtkSd6BW)
- [Jayanam Python for Blender Youtube Series](https://www.youtube.com/watch?v=ajPl4Kcv8tk&list=PLboXykqtm8dyUUJ6bZZFmFijFWpZzKx6F)
- [Blender Python Tutorial, Youtube series by Darkfall](https://www.youtube.com/watch?v=cyt0O7saU4Q&list=PLFtLHTf5bnym_wk4DcYIMq1DkjqB7kDb-&index=1)
- [Blender Python Addon Development with ST3, Udemy Course](https://www.udemy.com/course/st3-addon-course/)

More coming soon...
- [Curtis Holt Crash Course](https://www.youtube.com/watch?v=XqX5wh4YeRw)
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "Albert Rodriguez",
"description": "Tools to take measures for Avatar",
"blender": (2, 90, 0),
"version": (0, 3, 5),
"version": (0, 3, 8),
"location": "View3D > Toolshelf",
"warning": "This plugin is only compatible with Blender 2.90",
"category": "Add measures",
Expand Down
2 changes: 1 addition & 1 deletion addon/operator/geopath_datastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def get_whole_path(self):
# 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.pop()
pts.append(self.seed_loc)
pts.reverse()
return pts
6 changes: 3 additions & 3 deletions addon/operator/measures_circular_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def execute(self, context):
)

# Bisection cleanup
closest_edge = self.find_closest_edge(bm)
closest_edge = self.find_closest_edge(bm, self.hit_point)

# Could be that the angle of plane finds
# no vertices after bisection
Expand Down Expand Up @@ -160,12 +160,12 @@ def get_reachable_vertices(self, closest_edge):

return vertex_list

def find_closest_edge(self, bm: BMesh):
def find_closest_edge(self, bm: BMesh, hit_point: Vector):
result = None
min_dist = 9999.99
for e in bm.edges:
for v in e.verts:
dist = (v.co - self.hit_point).magnitude
dist = (v.co - hit_point).magnitude
if dist < min_dist:
result = e
min_dist = dist
Expand Down
22 changes: 14 additions & 8 deletions addon/operator/measures_geodesic_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
import bmesh
import traceback

from enum import Enum
from ..utility.draw import draw_quad, draw_text, get_blf_text_dims
from ..utility.addon import get_prefs
from ..utility.ray import mouse_raycast_to_scene
from .geopath_datastructure import GeoPath


class Geodesic_State(Enum):
MAIN = 1
GRAB = 2


class MEASURES_GEODESIC_OT(bpy.types.Operator):
bl_label = "Create Geodesic Measure"
bl_idname = 'measures.create_geodesic'
Expand All @@ -20,7 +26,7 @@ def poll(cls, context):
if context.mode != 'OBJECT':
return False

if context.object is not None and context.object.type != 'MESH':
if context.object is None or context.object.type != 'MESH':
return False

return True
Expand All @@ -30,7 +36,7 @@ def invoke(self, context, event):
# Initialize some props
self.hit_point = None
self.geopath = GeoPath(context, context.object)
self.state = 'main'
self.state = Geodesic_State.MAIN

# Do some setup
self.draw_handle = bpy.types.SpaceView3D.draw_handler_add(
Expand All @@ -44,9 +50,9 @@ def modal(self, context, event):
if event.type == 'MOUSEMOVE':
self.detect_collision(context, event)

if self.state == 'main':
if self.state == Geodesic_State.MAIN:
return self.handle_main(context, event)
elif self.state == 'grab':
elif self.state == Geodesic_State.GRAB:
return self.handle_grab(context, event)

return {"RUNNING_MODAL"} # Should not get here but you never know
Expand All @@ -64,7 +70,7 @@ def handle_main(self, context, event):
# Grab initiating
elif event.type == 'G' and event.value == 'PRESS':
if self.geopath.grab_initiate():
self.state = 'grab' # Do grab mode
self.state = Geodesic_State.GRAB # Do grab mode

# Adding points
elif event.type == 'LEFTMOUSE' and event.value == 'PRESS':
Expand Down Expand Up @@ -100,18 +106,18 @@ def handle_grab(self, context, event):
# confirm location
if event.type == 'LEFTMOUSE' and event.value == 'PRESS':
self.geopath.grab_confirm()
self.state = 'main'
self.state = Geodesic_State.MAIN

# put it back!
elif event.type in {'RIGHTMOUSE', 'ESC'} and event.value == 'PRESS':
self.geopath.grab_cancel()
self.state = 'main'
self.state = Geodesic_State.MAIN

# update the b_pt location
if event.type == 'MOUSEMOVE':
x, y = (event.mouse_region_x, event.mouse_region_y)
self.geopath.grab_mouse_move(context, x, y)
self.state = 'grab'
self.state = Geodesic_State.GRAB

context.area.tag_redraw()
return {'RUNNING_MODAL'}
Expand Down
8 changes: 3 additions & 5 deletions addon/property/__init__.py → addon/preferences/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import bpy

from .addon import MEASURES_Props
from .color import MEASURES_Color
from .settings import MEASURES_Settings
Expand All @@ -12,13 +10,13 @@
)


def register_properties():
def register_preferences():
from bpy.utils import register_class
for cls in classes:
register_class(cls)


def unregister_properties():
def unregister_preferences():
from bpy.utils import unregister_class
for cls in reversed(classes):
unregister_class(cls)
unregister_class(cls)
1 change: 0 additions & 1 deletion addon/property/addon.py → addon/preferences/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class MEASURES_Props(bpy.types.AddonPreferences):
color: PointerProperty(type=MEASURES_Color)
settings: PointerProperty(type=MEASURES_Settings)


def draw(self, context):

prefs = get_prefs()
Expand Down
12 changes: 6 additions & 6 deletions addon/property/color.py → addon/preferences/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
class MEASURES_Color(bpy.types.PropertyGroup):

font_color: FloatVectorProperty(
name = 'Font Color', description = 'Color of the modal font',
size = 4, min = 0, max = 1,
subtype='COLOR', default = (1, 1, 1, 1))
name='Font Color', description='Color of the modal font',
size=4, min=0, max=1,
subtype='COLOR', default=(1, 1, 1, 1))

bg_color: FloatVectorProperty(
name = 'BG Color', description = 'Color of the background',
size = 4, min = 0, max = 1,
subtype='COLOR', default = (0, 0, 0, .75))
name='BG Color', description='Color of the background',
size=4, min=0, max=1,
subtype='COLOR', default=(0, 0, 0, .75))


def draw_color(prefs, layout):
Expand Down
4 changes: 2 additions & 2 deletions addon/property/settings.py → addon/preferences/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
class MEASURES_Settings(bpy.types.PropertyGroup):

font_size: IntProperty(
name = 'Font Size', description = 'Font Size',
min = 10, max = 32, default = 24)
name='Font Size', description='Font Size',
min=10, max=32, default=24)


def draw_settings(prefs, layout):
Expand Down
14 changes: 7 additions & 7 deletions addon/register/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
def register_addon():

# Properties
from ..property import register_properties
register_properties()
# Preferences
from ..preferences import register_preferences
register_preferences()

# Menus
# from ..menu import register_menus
Expand All @@ -23,10 +23,10 @@ def register_addon():

def unregister_addon():

# Properties
from ..property import unregister_properties
unregister_properties()
# Preferences
from ..preferences import unregister_preferences
unregister_preferences()

# Menus
# from ..menu import unregister_menus
# unregister_menus()
Expand Down
4 changes: 2 additions & 2 deletions addon/register/keymap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import bpy
# import bpy

# TODO: Register keymaps here when necessary, left an example just in case

Expand All @@ -21,4 +21,4 @@
# for km, kmi in keys:
# km.keymap_items.remove(kmi)

# keys.clear()
# keys.clear()
1 change: 1 addition & 0 deletions addon/utility/mouse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

PADDING = 80


def mouse_warp(context, event):
'''Warp the mouse in the screen region.'''

Expand Down
Binary file modified screenshots/headerimage.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/plugininstalled.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/versioncoexist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 139d484

Please sign in to comment.