feat(rcf): now having correct world coordinates
This commit is contained in:
parent
aaba2a8773
commit
363b33cbae
29
net_ui.py
29
net_ui.py
@ -1,6 +1,7 @@
|
|||||||
import bpy
|
import bpy
|
||||||
from . import net_components
|
from . import net_components
|
||||||
from . import net_operators
|
from . import net_operators
|
||||||
|
import mathutils
|
||||||
import gpu
|
import gpu
|
||||||
from gpu_extras.batch import batch_for_shader
|
from gpu_extras.batch import batch_for_shader
|
||||||
from bpy_extras import view3d_utils
|
from bpy_extras import view3d_utils
|
||||||
@ -13,10 +14,14 @@ def view3d_find():
|
|||||||
for region in area.regions:
|
for region in area.regions:
|
||||||
if region.type == 'WINDOW':
|
if region.type == 'WINDOW':
|
||||||
return area, region, rv3d
|
return area, region, rv3d
|
||||||
|
|
||||||
|
break
|
||||||
return None, None, None
|
return None, None, None
|
||||||
|
|
||||||
|
def get_target(region, rv3d,coord):
|
||||||
|
view_vector = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord)
|
||||||
|
ray_origin = view3d_utils.region_2d_to_origin_3d(region, rv3d, coord)
|
||||||
|
return ray_origin +view_vector
|
||||||
|
|
||||||
class DrawClient(bpy.types.Operator):
|
class DrawClient(bpy.types.Operator):
|
||||||
bl_idname = "session.draw"
|
bl_idname = "session.draw"
|
||||||
@ -42,17 +47,15 @@ class DrawClient(bpy.types.Operator):
|
|||||||
area, region, rv3d = view3d_find()
|
area, region, rv3d = view3d_find()
|
||||||
width = region.width
|
width = region.width
|
||||||
height = region.height
|
height = region.height
|
||||||
|
depth = mathutils.Vector((rv3d.view_distance,rv3d.view_distance,rv3d.view_distance))
|
||||||
|
vec = view3d_utils.region_2d_to_vector_3d(region, rv3d, (0,0))
|
||||||
|
|
||||||
v1 = view3d_utils.region_2d_to_location_3d(region,rv3d,(0,0),(0,0,rv3d.view_distance))
|
v1 = get_target(region,rv3d,(0,0))
|
||||||
v3 = view3d_utils.region_2d_to_location_3d(region,rv3d,(0,height),(0,0,rv3d.view_distance))
|
v3 = get_target(region,rv3d,(0,height))
|
||||||
v2 = view3d_utils.region_2d_to_location_3d(region,rv3d,(width,height),(0,0,rv3d.view_distance))
|
v2 = get_target(region,rv3d,(width,height))
|
||||||
v4 = view3d_utils.region_2d_to_location_3d(region,rv3d,(width,0),(0,0,rv3d.view_distance))
|
v4 = get_target(region,rv3d,(width,0))
|
||||||
|
|
||||||
# v1 = view3d_utils.region_2d_to_vector_3d(region,rv3d,(0,0))
|
|
||||||
# v3 = view3d_utils.region_2d_to_vector_3d(region,rv3d,(0,height))
|
|
||||||
# v2 = view3d_utils.region_2d_to_vector_3d(region,rv3d,(width,height))
|
|
||||||
# v4 = view3d_utils.region_2d_to_vector_3d(region,rv3d,(width,0))
|
|
||||||
|
|
||||||
|
print("{}".format(rv3d.view_distance))
|
||||||
self.coords = (v1, v2, v3, v4)
|
self.coords = (v1, v2, v3, v4)
|
||||||
|
|
||||||
|
|
||||||
@ -72,6 +75,7 @@ class DrawClient(bpy.types.Operator):
|
|||||||
|
|
||||||
def unregister_handlers(self):
|
def unregister_handlers(self):
|
||||||
bpy.types.SpaceView3D.draw_handler_remove(self.draw_handle,"WINDOW")
|
bpy.types.SpaceView3D.draw_handler_remove(self.draw_handle,"WINDOW")
|
||||||
|
self.draw_handle = None
|
||||||
|
|
||||||
def create_batch(self):
|
def create_batch(self):
|
||||||
self.shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
|
self.shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
|
||||||
@ -86,9 +90,12 @@ class DrawClient(bpy.types.Operator):
|
|||||||
if context.area:
|
if context.area:
|
||||||
context.area.tag_redraw()
|
context.area.tag_redraw()
|
||||||
|
|
||||||
|
|
||||||
if event.type in {"ESC"}:
|
if event.type in {"ESC"}:
|
||||||
self.unregister_handlers()
|
self.unregister_handlers()
|
||||||
return {"CANCELLED"}
|
return {"CANCELLED"}
|
||||||
|
# if self.draw_handle:
|
||||||
|
# self.finish()
|
||||||
|
|
||||||
return {"PASS_THROUGH"}
|
return {"PASS_THROUGH"}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user