This file contains hidden or 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 argparse | |
import sys | |
import numpy as np | |
from pathlib import Path | |
from PIL import Image | |
from insightface.app import FaceAnalysis | |
def run_face_search(query_face_image: Path, target_search_dir: Path, |
This file contains hidden or 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 numpy.random import uniform | |
def rand_camera_loc(camera, xloc_range, yloc_range, zloc_range): | |
""" Randomize camera location for each axis based on the provided ranges """ | |
new_loc = camera.location | |
new_loc[0] = uniform(low=xloc_range[0], high=xloc_range[1]) | |
new_loc[1] = uniform(low=yloc_range[0], high=yloc_range[1]) | |
new_loc[2] = uniform(low=zloc_range[0], high=zloc_range[1]) | |
camera.location = new_loc |
This file contains hidden or 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 numpy as np | |
import bpy | |
from mathutils import Vector | |
from math import sin, cos, pi, copysign | |
def randomize_pos(obj, min, max): | |
axis = np.random.randint(0, 3) | |
new_axis_pos = np.random.uniform(min, max) | |
# x axis | |
if axis == 0: |
This file contains hidden or 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 math import sin, cos | |
def rotate_stroke(stroke, angle, axis='z'): | |
# Define rotation matrix based on axis | |
if axis.lower() == 'x': | |
transform_matrix = np.array([[1, 0, 0], | |
[0, cos(angle), -sin(angle)], | |
[0, sin(angle), cos(angle)]]) | |
elif axis.lower() == 'y': | |
transform_matrix = np.array([[cos(angle), 0, -sin(angle)], |
This file contains hidden or 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 draw_line(gp_frame, p0: tuple, p1: tuple): | |
# Init new stroke | |
gp_stroke = gp_frame.strokes.new() | |
gp_stroke.display_mode = '3DSPACE' # allows for editing | |
# Define stroke geometry | |
gp_stroke.points.add(count=2) | |
gp_stroke.points[0].co = p0 | |
gp_stroke.points[1].co = p1 | |
return gp_stroke |
This file contains hidden or 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 draw_circle(gp_frame, center: tuple, radius: float, segments: int): | |
# Init new stroke | |
gp_stroke = gp_frame.strokes.new() | |
gp_stroke.display_mode = '3DSPACE' # allows for editing | |
gp_stroke.draw_cyclic = True # closes the stroke | |
# Define stroke geometry | |
angle = 2*math.pi/segments # angle in radians | |
gp_stroke.points.add(count=segments) | |
for i in range(segments): |
This file contains hidden or 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 | |
NUM_FRAMES = 30 | |
FRAMES_SPACING = 1 # distance between frames | |
bpy.context.scene.frame_start = 0 | |
bpy.context.scene.frame_end = NUM_FRAMES*FRAMES_SPACING | |
for frame in range(NUM_FRAMES): | |
gp_frame = gp_layer.frames.new(frame*FRAMES_SPACING) | |
# do something with your frame |
This file contains hidden or 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 | |
def get_grease_pencil(gpencil_obj_name='GPencil') -> bpy.types.GreasePencil: | |
""" | |
Return the grease-pencil object with the given name. Initialize one if not already present. | |
:param gpencil_obj_name: name/key of the grease pencil object in the scene | |
""" | |
# If not present already, create grease pencil object | |
if gpencil_obj_name not in bpy.context.scene.objects: |
This file contains hidden or 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 sublime | |
import sublime_plugin | |
import http.client | |
host = "127.0.0.1" | |
port = "9000" | |
conn = http.client.HTTPConnection("{}:{}".format(host, port)) | |
class TextGenCommand(sublime_plugin.TextCommand): | |
def run(self, edit, model_id, min_nb_words=5): |
This file contains hidden or 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 sys | |
from mathutils import Vector | |
import numpy as np | |
class ConwayGOL_2D: | |
def __init__(self, N): | |
""" | |
2D Conway Game of Life | |
:param N: grid side size (resulting grid will be a NxN matrix) |
NewerOlder