Skip to content

Commit

Permalink
Cython: TargetMeshAccel, added use_symmetry and view_dir (current vec…
Browse files Browse the repository at this point in the history
… forward) attributes, as well as method to set/update symmetry. (view_dir is updated from existing _update_view method)
  • Loading branch information
jfranmatheu committed Mar 6, 2025
1 parent 2be3489 commit 29b0ba5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
7 changes: 6 additions & 1 deletion retopoflow/cy/target_accel.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ from cpython.object cimport PyObject
from .bl_types.bmesh_types cimport BMVert, BMEdge, BMFace, BMesh, BMesh, BMHeader
from .bl_types.bmesh_py_wrappers cimport BPy_BMesh
from .bl_types cimport ARegion, RegionView3D
from .vector_utils cimport bVec3


cdef enum SelectionState:
Expand All @@ -28,6 +29,7 @@ cdef enum SelectionState:
cdef struct View3D:
float[4][4] proj_matrix
float[3] view_pos
float[3] view_dir
bint is_persp

cdef enum GeomType:
Expand Down Expand Up @@ -64,7 +66,9 @@ cdef class TargetMeshAccel:
BMesh* bmesh
ARegion* region
RegionView3D* rv3d

int selected_only
bVec3 use_symmetry

float[4][4] matrix_world
float[3][3] matrix_normal
Expand Down Expand Up @@ -121,7 +125,7 @@ cdef class TargetMeshAccel:
cdef void _find_nearest_k(self, float x, float y, int k, float max_dist,
GeomType filter_type, vector[GeomElement]* results) noexcept nogil

cdef void _update_view(self, const float[:, ::1] proj_matrix, const float[::1] view_pos, bint is_perspective) nogil
cdef void _update_view(self, const float[:, ::1] proj_matrix, const float[::1] view_pos, const float[::1] view_dir, bint is_perspective) nogil
cdef void _update_object_transform(self, const float[:, ::1] matrix_world, const float[:, ::1] matrix_normal) nogil
cdef void _reset(self, bint dirty=*) noexcept nogil
cdef void set_dirty(self) noexcept nogil
Expand Down Expand Up @@ -154,6 +158,7 @@ cdef class TargetMeshAccel:

cpdef void py_set_dirty_accel(self)
cpdef void py_set_dirty_geom_vis(self)
cpdef void py_set_symmetry(self, bint x, bint y, bint z)

cpdef void py_update_object(self, object py_target_object)
cpdef void py_update_region(self, object py_region)
Expand Down
18 changes: 16 additions & 2 deletions retopoflow/cy/target_accel.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ from .bl_types.bmesh_flags cimport BMElemHFlag, BM_elem_flag_test
from .bl_types cimport ARegion, RegionView3D
from .utils cimport vec3_normalize, vec3_dot

import mathutils

# ctypedef np.uint8_t uint8

cdef float finf = <float>1e1000
Expand Down Expand Up @@ -66,6 +68,8 @@ cdef class TargetMeshAccel:
self.last_totedge = 0
self.last_totface = 0

self.use_symmetry = bVec3(False, False, False)

def __init__(self,
object py_object,
object py_bmesh,
Expand Down Expand Up @@ -107,7 +111,7 @@ cdef class TargetMeshAccel:

self.set_dirty()

cdef void _update_view(self, const float[:, ::1] proj_matrix, const float[::1] view_pos, bint is_perspective) nogil:
cdef void _update_view(self, const float[:, ::1] proj_matrix, const float[::1] view_pos, const float[::1] view_dir, bint is_perspective) nogil:
cdef:
int i, j

Expand All @@ -118,6 +122,7 @@ cdef class TargetMeshAccel:

for i in range(3):
self.view3d.view_pos[i] = view_pos[i]
self.view3d.view_dir[i] = view_dir[i]

self.view3d.is_persp = is_perspective

Expand Down Expand Up @@ -961,6 +966,13 @@ cdef class TargetMeshAccel:
self.is_dirty_geom_vis = True
self.is_dirty_accel = True

cpdef void py_set_symmetry(self, bint x, bint y, bint z):
if self.use_symmetry.x != x or self.use_symmetry.y != y or self.use_symmetry.z != z:
self.use_symmetry.x = x
self.use_symmetry.y = y
self.use_symmetry.z = z
self.py_set_dirty_accel()

cpdef void py_update_bmesh(self, object py_bmesh):
if not hasattr(self, 'py_bmesh') or id(self.py_bmesh) != id(py_bmesh):
self.py_bmesh = py_bmesh
Expand Down Expand Up @@ -998,8 +1010,10 @@ cdef class TargetMeshAccel:
view_pos = np.array(view_matrix.inverted().translation, dtype=np.float32)
else:
view_pos = np.array(view_matrix.inverted().col[2].xyz, dtype=np.float32)

view_dir = np.array(view_matrix.to_3x3().inverted_safe() @ mathutils.Vector((0,0,-1)), dtype=np.float32)

self._update_view(proj_matrix, view_pos, <bint>is_perspective)
self._update_view(proj_matrix, view_pos, view_dir, <bint>is_perspective)

cpdef bint py_update_geometry_visibility(self):
if not self.is_dirty_geom_vis:
Expand Down

0 comments on commit 29b0ba5

Please sign in to comment.