@@ -84,22 +84,22 @@ def calc_vertex_transform_world(pos, norm):
8484 m = mT @ mR
8585 return m
8686
87- #Calc matrix that maps from world space to a particular vertex on mesh
88- #coord - vertex position in local space
89- #normal - vertex normal in local space
90- def calc_vertex_transform (obj , coord , normal ):
91- pos = obj .matrix_world @ coord
92-
93- #Transform normal into world space
94- norm = mathutils .Vector ((normal .x , normal .y , normal .z , 0 ))
95- mIT = obj .matrix_world .copy ()
96- mIT .invert ()
97- mIT .transpose ()
98- norm = mIT @ norm
99- norm .resize_3d ()
100- norm .normalize ()
101-
102- return calc_vertex_transform_world (pos , norm )
87+ # # Calc matrix that maps from world space to a particular vertex on mesh
88+ # # coord - vertex position in local space
89+ # # normal - vertex normal in local space
90+ # def calc_vertex_transform(obj, coord, normal):
91+ # pos = obj.matrix_world @ coord
92+
93+ # # Transform normal into world space
94+ # norm = mathutils.Vector((normal.x, normal.y, normal.z, 0))
95+ # mIT = obj.matrix_world.copy()
96+ # mIT.invert()
97+ # mIT.transpose()
98+ # norm = mIT @ norm
99+ # norm.resize_3d()
100+ # norm.normalize()
101+
102+ # return calc_vertex_transform_world(pos, norm)
103103
104104def draw_callback (self , context ):
105105# if True:
@@ -138,8 +138,6 @@ def draw_callback(self, context):
138138 gpu .matrix .pop ()
139139
140140
141-
142-
143141 bgl .glDisable (bgl .GL_DEPTH_TEST )
144142
145143class UvTracker :
@@ -357,16 +355,25 @@ def dab_brush(self, context, event):
357355 if self .edit_object == None :
358356 hit_object , location , normal , face_index , object , matrix = ray_cast_scene (context , viewlayer , ray_origin , view_vector )
359357 else :
358+ l2w = self .edit_object .matrix_world
359+ w2l = l2w .inverted ()
360+ local_ray_origin = w2l @ ray_origin
361+ local_view_vector = mul_vector (w2l , view_vector )
362+
360363 if self .edit_object .mode == 'OBJECT' :
361- hit_object , location , normal , index = self .edit_object .ray_cast (ray_origin , view_vector )
364+ hit_object , location , normal , index = self .edit_object .ray_cast (local_ray_origin , local_view_vector )
362365 object = self .edit_object
366+
367+ location = l2w @ location
368+
363369 if self .edit_object .mode == 'EDIT' :
364370 bm = bmesh .from_edit_mesh (self .edit_object .data )
365371 tree = mathutils .bvhtree .BVHTree .FromBMesh (bm )
366- location , normal , index , distance = tree .ray_cast (ray_origin , view_vector )
372+ location , normal , index , distance = tree .ray_cast (local_ray_origin , local_view_vector )
367373 hit_object = location != None
368374 object = self .edit_object
369375
376+ location = l2w @ location
370377
371378
372379# print("hit obj:%s" % (str(hit_object)))
@@ -482,7 +489,6 @@ def dab_brush(self, context, event):
482489 elif self .edit_object .mode == 'OBJECT' :
483490 bm .to_mesh (mesh )
484491 bm .free ()
485-
486492
487493 if hit_object :
488494 self .stroke_trail .append (location )
@@ -672,6 +678,8 @@ def register():
672678def unregister ():
673679 bpy .utils .unregister_class (UvBrushToolSettings )
674680 bpy .utils .unregister_class (UvBrushToolOperator )
681+
682+ del bpy .types .Scene .uv_brush_props
675683
676684
677685if __name__ == "__main__" :
0 commit comments