Compare commits
2 Commits
eec1d3c501
...
fca531bf35
Author | SHA1 | Date |
---|---|---|
pullusb | fca531bf35 | |
pullusb | b65a60126d |
|
@ -1,7 +1,7 @@
|
||||||
bl_info = {
|
bl_info = {
|
||||||
"name": "gp interpolate",
|
"name": "gp interpolate",
|
||||||
"author": "Christophe Seux, Samuel Bernou",
|
"author": "Christophe Seux, Samuel Bernou",
|
||||||
"version": (0, 7, 3),
|
"version": (0, 7, 4),
|
||||||
"blender": (3, 6, 0),
|
"blender": (3, 6, 0),
|
||||||
"location": "Sidebar > Gpencil Tab > Interpolate",
|
"location": "Sidebar > Gpencil Tab > Interpolate",
|
||||||
"description": "Interpolate Grease pencil strokes over 3D",
|
"description": "Interpolate Grease pencil strokes over 3D",
|
||||||
|
|
|
@ -3,7 +3,7 @@ import numpy as np
|
||||||
from time import perf_counter, time, sleep
|
from time import perf_counter, time, sleep
|
||||||
from mathutils import Vector, Matrix
|
from mathutils import Vector, Matrix
|
||||||
|
|
||||||
from gp_interpolate.utils import (matrix_transform,
|
from ..utils import (matrix_transform,
|
||||||
plane_on_bone,
|
plane_on_bone,
|
||||||
ray_cast_point,
|
ray_cast_point,
|
||||||
obj_ray_cast,
|
obj_ray_cast,
|
||||||
|
|
67
utils.py
67
utils.py
|
@ -35,12 +35,30 @@ class attr_set():
|
||||||
|
|
||||||
# --- Vector
|
# --- Vector
|
||||||
|
|
||||||
def triangle_normal(a, b, c):
|
def triangle_normal(p1, p2, p3):
|
||||||
x = a[1] * b[2] - a[2] * b[1]
|
"""
|
||||||
y = a[2] * b[0] - a[0] * b[2]
|
Calculate the normal of a triangle given its three vertices.
|
||||||
z = a[0] * b[1] - a[1] * b[0]
|
|
||||||
|
Parameters:
|
||||||
return np.array([x, y, z], dtype='float64')
|
p1, p2, p3: the 3 vertices of the triangle
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
mathutils.Vector: The normalized normal vector of the triangle.
|
||||||
|
"""
|
||||||
|
## Get edge vectors
|
||||||
|
edge1 = Vector(p2) - Vector(p1)
|
||||||
|
edge2 = Vector(p3) - Vector(p1)
|
||||||
|
## Get normal (Cross product of the edge vectors)
|
||||||
|
normal = edge1.cross(edge2)
|
||||||
|
normal.normalize()
|
||||||
|
return normal
|
||||||
|
|
||||||
|
## Bad normal calculation !!
|
||||||
|
# def triangle_normal(a, b, c):
|
||||||
|
# x = a[1] * b[2] - a[2] * b[1]
|
||||||
|
# y = a[2] * b[0] - a[0] * b[2]
|
||||||
|
# z = a[0] * b[1] - a[1] * b[0]
|
||||||
|
# return np.array([x, y, z], dtype='float64')
|
||||||
|
|
||||||
def plane_coords(size=1):
|
def plane_coords(size=1):
|
||||||
v = size * 0.5
|
v = size * 0.5
|
||||||
|
@ -84,6 +102,20 @@ def get_tri_from_face(hit_location, face_index, object_hit, depsgraph):
|
||||||
return tri, tri_indices
|
return tri, tri_indices
|
||||||
|
|
||||||
def ray_cast_point(point, origin, depsgraph):
|
def ray_cast_point(point, origin, depsgraph):
|
||||||
|
'''Return object hit by ray cast, hit location and triangle vertices coordinates and indices
|
||||||
|
|
||||||
|
point: point coordinate in world space
|
||||||
|
origin: origin of the ray in world space
|
||||||
|
depsgraph: current depsgraph (use bpy.context.evaluated_depsgraph_get())
|
||||||
|
|
||||||
|
return:
|
||||||
|
object_hit (object): Object that was hit
|
||||||
|
hit_location (Vector3, as np.array): Location Vector of the hit
|
||||||
|
tri (list(Vector)): List of Vector3 world space coordinate of hitten triangle (tesselated from face if needed)
|
||||||
|
tri_indices (list(int)): List of vertices index corresponding to tri coordinates
|
||||||
|
|
||||||
|
if nothing hit. return None, None, None, None
|
||||||
|
'''
|
||||||
ray = (point - origin)
|
ray = (point - origin)
|
||||||
hit, hit_location, normal, face_index, object_hit, matrix = bpy.context.scene.ray_cast(depsgraph, origin, ray)
|
hit, hit_location, normal, face_index, object_hit, matrix = bpy.context.scene.ray_cast(depsgraph, origin, ray)
|
||||||
|
|
||||||
|
@ -479,4 +511,25 @@ def index_list_from_bools(bool_list) -> list:
|
||||||
## -- animation
|
## -- animation
|
||||||
|
|
||||||
def is_animated(obj):
|
def is_animated(obj):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
## -- regions operations
|
||||||
|
|
||||||
|
def location_to_region(worldcoords) -> Vector:
|
||||||
|
'''Get a world 3d coordinate and return 2d region coordinate
|
||||||
|
|
||||||
|
return: 2d vector in region space
|
||||||
|
'''
|
||||||
|
from bpy_extras import view3d_utils
|
||||||
|
return view3d_utils.location_3d_to_region_2d(bpy.context.region, bpy.context.space_data.region_3d, worldcoords)
|
||||||
|
|
||||||
|
def region_to_location(viewcoords, depthcoords) -> Vector:
|
||||||
|
'''Get 3d world coordinate from viewport region 2d coordianate
|
||||||
|
viewcoords (Vector2): 2d region vector coordinate
|
||||||
|
depthcoords (Vector3): 3d coordinate to define the depth
|
||||||
|
|
||||||
|
return: Vector3 of the placed location
|
||||||
|
'''
|
||||||
|
from bpy_extras import view3d_utils
|
||||||
|
return view3d_utils.region_2d_to_location_3d(bpy.context.region, bpy.context.space_data.region_3d, viewcoords, depthcoords)
|
Loading…
Reference in New Issue