Skip to content

Instantly share code, notes, and snippets.

@blender8r
blender8r / gp_stroke_intersection.py
Created November 9, 2023 12:50
Finds the intersection point between two grease pencil strokes in Blender
import bpy
from math import pi, sin, cos
def ellipse(gp_frame, center, radius_x, radius_z, num_points):
gp_stroke = gp_frame.strokes.new()
gp_stroke.line_width = 30
gp_stroke.use_cyclic = True
gp_stroke.points.add(count=num_points)
@blender8r
blender8r / gp_parallel_lines.py
Created November 9, 2023 12:47
Creates two grease pencil lines in Blender
import bpy
def line(gp_frame, start_pos, end_pos, num_pts):
gp_stroke = gp_frame.strokes.new()
gp_stroke.line_width = 30
gp_stroke.points.add(count=num_pts)
start_x = start_pos[0]
@blender8r
blender8r / get_and_select.py
Created September 18, 2023 13:00
Blender & Python: Getting and Selecting Objects
###########################################
# SNIPPETS: GETTING AND SELECTING OBJECTS #
# [email protected] #
###########################################
# Get a list of objects in the scene
objects = bpy.data.objects
for object in objects:
print(object.name)
@blender8r
blender8r / gpdof.py
Created July 13, 2023 14:58
Blender script to add depth of field effect to grease pencil objects
import bpy
from mathutils import Vector
def duplicate(obj, data=True, actions=True, collection=None):
obj_copy = obj.copy()
if data:
obj_copy.data = obj_copy.data.copy()
if actions and obj_copy.animation_data.action:
obj_copy.animation_data.action = obj_copy.animation_data.action.copy()
@blender8r
blender8r / ghibli_shader_full.py
Created May 25, 2023 12:51
Creates a Blender cel shader with the controls gathered into one group
import bpy
IMAGE = None
TEXTURE_PATH = 'D:\\images\\textures\\hatch_1.jpg'
for i in bpy.data.images:
if i.filepath == TEXTURE_PATH:
IMAGE = i
@blender8r
blender8r / ghibli_shader_basic.py
Created May 4, 2023 13:07
Python code for Blender that reproduces the Ghibli Shader technique by Kristof Dedene
import bpy
IMAGE = None
TEXTURE_PATH = 'D:\\images\\textures\\hatch_1.jpg'
for i in bpy.data.images:
if i.filepath == TEXTURE_PATH:
IMAGE = i
@blender8r
blender8r / gp_palette_to_material.py
Last active June 1, 2023 14:26
Converts the colors in a Blender Palette to individual Grease Pencil materials per-color
import bpy
from mathutils import Color
palette_name = bpy.context.tool_settings.gpencil_paint.palette.name
def create_palette_materials(gp, palette_name):
palette = bpy.data.palettes.get(palette_name)
if palette:
i = 0
while i < len(palette.colors):
@blender8r
blender8r / gpfog.py
Created January 11, 2023 14:43
Simulates volumetric fog on Blender grease pencil objects
import bpy
from mathutils import Vector
min_dist = 10.0
max_dist = 120.0
fog_color = (1.0, 0.9, 0.7, 1.0)
fog_mult = 1.0
final_fog = (fog_color[0]*fog_mult, fog_color[1]*fog_mult, fog_color[2]*fog_mult)
falloff = 3.0
@blender8r
blender8r / gp_basic.py
Created January 5, 2023 00:20
Framework for accessing grease pencil data in Blender using Python
import bpy
sel_obj = None
sel_objs = bpy.context.selected_objects
if sel_objs:
sel_obj = sel_objs[0]
if sel_obj and sel_obj.type=='GPENCIL':
import bpy
from math import tau, pi, sin, cos, ceil
import random
import time
t = time.perf_counter()
num_points = 48
center = (0.0, 0.0, 0.0)