This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Viewport Shortcuts, Blender add-on that contains shortcuts of viewport render settings. | |
# Copyright (C) 2024 Spencer Magnusson | |
# | |
# 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 3 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
class SimpleOperator(bpy.types.Operator): | |
bl_idname = "mesh.align_transform_to_selected_face" | |
bl_label = "Align Rotation to Selected Face" | |
@classmethod | |
def poll(cls, context): | |
return context.active_object is not None and any(p.select for p in context.active_object.data.polygons) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import math | |
from mathutils import Matrix, Vector | |
from mathutils.geometry import box_fit_2d | |
def get_box(vertices, normal): | |
"""Given a set of vertices and normals (both mapped to world space), | |
:param vertices: list of vertices mapped to world space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
from bpy_extras import view3d_utils | |
import gpu | |
from gpu_extras.batch import batch_for_shader | |
from mathutils import Vector | |
def draw(shade, bat): | |
shade.bind() | |
shade.uniform_float("color", (1, 0, 0, 0.25)) | |
bat.draw(shade) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
from mathutils import Vector | |
# prereq: go into your object's edit mode | |
context = bpy.context | |
mesh = context.edit_object.data | |
verts = [v.co for v in mesh.vertices] | |
edges = [[v for v in e.vertices] for e in mesh.edges] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import bmesh | |
from mathutils import Vector | |
obj = bpy.context.active_object | |
me = obj.data | |
# cannot access color attributes within bmesh, | |
# so we will create a dict of indices to access the linked edges in object mode | |
bpy.ops.object.mode_set(mode='EDIT') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ast | |
import os | |
import zipfile | |
allowed_file_extensions = {'.py', '.md', 'LICENSE'} | |
exclude_folders = {'doc', 'venv', '.git', '.idea'} | |
def zipdir(path, ziph: zipfile.ZipFile, zip_subdir_name): | |
for root, dirs, files in os.walk(path): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def coll_iter(curr_coll): | |
""" | |
Iterate through hierarchy of collections | |
:param curr_coll: current collection | |
:return: generator of collections | |
""" | |
yield curr_coll | |
for child in curr_coll.children: | |
yield from coll_iter(child) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import blf | |
import bpy | |
def wrap_text(text: str, context): | |
return_text = [] | |
row_text = '' | |
width = context.region.width | |
system = context.preferences.system | |
ui_scale = system.ui_scale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mathutils.geometry import normal | |
from mathutils import Vector | |
from bpy import context | |
def camera_as_planes(scene, obj): | |
""" | |
Return planes in world-space which represent the camera view bounds. | |
""" | |
camera = obj.data |
NewerOlder