feat: progress on draw
This commit is contained in:
@ -4,6 +4,7 @@ import mathutils
|
||||
from .. import utils
|
||||
from ..presence import User
|
||||
from ..libs.replication.data import ReplicatedDatablock
|
||||
from ..libs.debug import draw_point
|
||||
|
||||
class BlUser(ReplicatedDatablock):
|
||||
def __init__(self, *args, **kwargs):
|
||||
@ -11,15 +12,14 @@ class BlUser(ReplicatedDatablock):
|
||||
|
||||
self.icon = 'CON_ARMATURE'
|
||||
|
||||
#TODO: investigate on empty buffer...
|
||||
if self.buffer:
|
||||
self.load(self.buffer, self.pointer)
|
||||
|
||||
def construct(self, name):
|
||||
return User()
|
||||
|
||||
def load(self, data, target):
|
||||
# target.name = data['name']
|
||||
target.name = data['name']
|
||||
target.location = data['location']
|
||||
utils.dump_anything.load(target, data)
|
||||
|
||||
def dump(self,pointer=None):
|
||||
|
23
delayable.py
23
delayable.py
@ -1,6 +1,8 @@
|
||||
import bpy
|
||||
from .libs.replication.constants import *
|
||||
from .libs import debug
|
||||
from . import operators
|
||||
from .bl_types.bl_user import BlUser
|
||||
|
||||
class Delayable():
|
||||
def register(self):
|
||||
@ -33,7 +35,10 @@ class Timer(Delayable):
|
||||
def unregister(self):
|
||||
"""Unnegister the timer of the blender timer system
|
||||
"""
|
||||
try:
|
||||
bpy.app.timers.unregister(self.execute)
|
||||
except:
|
||||
print("timer already unregistered")
|
||||
|
||||
class ApplyTimer(Timer):
|
||||
def __init__(self, timout=1,target_type=None):
|
||||
@ -64,8 +69,11 @@ class Draw(Delayable):
|
||||
raise NotImplementedError()
|
||||
|
||||
def unregister(self):
|
||||
try:
|
||||
bpy.types.SpaceView3D.draw_handler_remove(
|
||||
self._handler, "WINDOW")
|
||||
except:
|
||||
print("draw already unregistered")
|
||||
|
||||
class ClientUpdate(Draw):
|
||||
def __init__(self, client_uuid=None):
|
||||
@ -75,5 +83,16 @@ class ClientUpdate(Draw):
|
||||
|
||||
def execute(self):
|
||||
if hasattr(operators,"client"):
|
||||
operators.client.get(self._client_uuid).pointer.update_location()
|
||||
print("update! ")
|
||||
client = operators.client.get(self._client_uuid)
|
||||
|
||||
if client:
|
||||
client.pointer.update_location()
|
||||
|
||||
|
||||
class DrawClients(Draw):
|
||||
def execute(self):
|
||||
if operators.client:
|
||||
users = operators.client.list(filter=BlUser)
|
||||
|
||||
[debug.draw_point(location=operators.client.get(u).buffer['location']) for u in users if operators.client.get(u)]
|
||||
|
||||
|
125
libs/debug.py
Normal file
125
libs/debug.py
Normal file
@ -0,0 +1,125 @@
|
||||
import bpy
|
||||
import bgl
|
||||
import gpu
|
||||
from gpu_extras.batch import batch_for_shader
|
||||
import numpy
|
||||
|
||||
|
||||
DEFAULT_COORDS = [(0.0, 0.0, 0.0)]
|
||||
DEFAULT_INDICES = [(0)]
|
||||
|
||||
|
||||
def refresh_viewport():
|
||||
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
|
||||
|
||||
|
||||
class Drawable():
|
||||
"""Drawable base class in charge to hanfle the drawing pipline.
|
||||
|
||||
:param coords: list of vertices
|
||||
:type coords: list of tuples. ex: [(x,y,z),...]
|
||||
:param indices: list of vertices index to structure geometry
|
||||
:type indices: list of tuples.
|
||||
:param location: suited location in world space.
|
||||
:type location: tuple, (x,y,z)
|
||||
:param mode: primitive drawing mode.
|
||||
:type mode: string in ['POINTS','LINES','TRIS'], default: "POINTS".
|
||||
:param color: primitive color
|
||||
:type color: tuple, (r,g,b,a)
|
||||
:param duration: lifetime of the primitive in seconds
|
||||
:type duration: float
|
||||
"""
|
||||
|
||||
def __init__(self, coords=DEFAULT_COORDS, indices=DEFAULT_INDICES, location=(0.0, 0.0, 0.0), mode='POINTS', color=(1, 0, 0, 1), duration=1):
|
||||
self._duration = duration
|
||||
self._color = color
|
||||
self._coord = [tuple(numpy.add(c,location)) for c in coords]
|
||||
self.shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
|
||||
self.batch = batch_for_shader(
|
||||
self.shader, mode, {"pos": self._coord}, indices=indices)
|
||||
|
||||
# Bind the drawing function
|
||||
self._handler = bpy.types.SpaceView3D.draw_handler_add(
|
||||
self.draw, (), 'WINDOW', 'POST_VIEW')
|
||||
# Bind the callback
|
||||
self._timer = bpy.app.timers.register(
|
||||
self.clear, first_interval=duration)
|
||||
|
||||
def draw(self):
|
||||
self.shader.bind()
|
||||
self.shader.uniform_float("color", self._color)
|
||||
self.batch.draw(self.shader)
|
||||
|
||||
def clear(self):
|
||||
"""Remove the drawable object from the viewport
|
||||
"""
|
||||
bpy.types.SpaceView3D.draw_handler_remove(self._handler, 'WINDOW')
|
||||
|
||||
|
||||
def draw_point(location=(0, 0, 0), color=(1, 0, 0, 1), duration=1):
|
||||
"""Draw a point
|
||||
|
||||
:param location: suited location in world space.
|
||||
:type location: tuple, (x,y,z)
|
||||
:param color: primitive color
|
||||
:type color: tuple, (r,g,b,a)
|
||||
:param duration: lifetime of the primitive in seconds
|
||||
:type duration: float
|
||||
"""
|
||||
return Drawable(location=location, color=color, duration=duration)
|
||||
|
||||
|
||||
def draw_line(a=(0, 0, 0), b=(0, 1, 0), color=(1, 0, 0, 1), duration=1):
|
||||
""" Draw a line from a given point A to the point B.
|
||||
|
||||
:param a: point A location in world space.
|
||||
:type a: tuple, (x,y,z)
|
||||
:param b: point B location in world space.
|
||||
:type b: tuple, (x,y,z)
|
||||
:param color: primitive color
|
||||
:type color: tuple, (r,g,b,a)
|
||||
:param duration: lifetime of the primitive in seconds
|
||||
:type duration: float
|
||||
"""
|
||||
return Drawable(coords=[a, b], indices=[(0, 1)], mode='LINES', color=color, duration=duration)
|
||||
|
||||
|
||||
def draw_cube(radius=1, location=(0, 0, 0), color=(1, 0, 0, 1), duration=1):
|
||||
""" Draw a cube.
|
||||
|
||||
:param radius: size of the cube.
|
||||
:type radius: float
|
||||
:param location: suited location in world space.
|
||||
:type location: tuple, (x,y,z)
|
||||
:param color: primitive color
|
||||
:type color: tuple, (r,g,b,a)
|
||||
:param duration: lifetime of the primitive in seconds
|
||||
:type duration: float
|
||||
"""
|
||||
coords = (
|
||||
(-radius, -radius, -radius), (+radius, -radius, -radius),
|
||||
(-radius, +radius, -radius), (+radius, +radius, -radius),
|
||||
(-radius, -radius, +radius), (+radius, -radius, +radius),
|
||||
(-radius, +radius, +radius), (+radius, +radius, +radius))
|
||||
|
||||
indices = (
|
||||
(0, 1), (0, 2), (1, 3), (2, 3),
|
||||
(4, 5), (4, 6), (5, 7), (6, 7),
|
||||
(0, 4), (1, 5), (2, 6), (3, 7))
|
||||
|
||||
return Drawable(coords=coords, mode='LINES', indices=indices, location=location, color=color, duration=duration)
|
||||
|
||||
def draw_custom(coords=DEFAULT_COORDS, indices=DEFAULT_INDICES, mode='LINES',location=(0, 0, 0), color=(1, 0, 0, 1), duration=1):
|
||||
""" Draw a user defined polygon shape.
|
||||
|
||||
:param coords: list of vertices
|
||||
:type coords: list of tuples. ex: [(x,y,z),...]
|
||||
:param indices: list of vertices index to structure geometry
|
||||
:type indices: list of tuples.
|
||||
:param location: suited location in
|
||||
:param color: primitive color
|
||||
:type color: tuple, (r,g,b,a)
|
||||
:param duration: lifetime of the primitive in seconds
|
||||
:type duration: float
|
||||
"""
|
||||
return Drawable(coords=coords, indices=indices, mode=mode, location=location, color=color, duration=duration)
|
Submodule libs/replication updated: 673844e476...acc074e3a0
@ -124,16 +124,12 @@ class SessionStartOperator(bpy.types.Operator):
|
||||
)
|
||||
|
||||
settings.user_uuid = client.add(usr)
|
||||
|
||||
delayables.append(delayable.DrawClients())
|
||||
delayables.append(delayable.ClientUpdate(client_uuid=settings.user_uuid))
|
||||
# Push all added values
|
||||
client.push()
|
||||
|
||||
|
||||
# settings.is_running = True
|
||||
# bpy.ops.session.refresh()
|
||||
# register_ticks()
|
||||
|
||||
# Launch drawing module
|
||||
# if settings.enable_presence:
|
||||
# presence.renderer.run()
|
||||
@ -162,6 +158,8 @@ class SessionStopOperator(bpy.types.Operator):
|
||||
|
||||
for d in delayables:
|
||||
d.unregister()
|
||||
|
||||
|
||||
# del client_instance
|
||||
|
||||
# unregister_ticks()
|
||||
|
@ -7,8 +7,11 @@ import mathutils
|
||||
from bpy_extras import view3d_utils
|
||||
from gpu_extras.batch import batch_for_shader
|
||||
|
||||
global renderer
|
||||
# from .libs import debug
|
||||
# from .bl_types.bl_user import BlUser
|
||||
# from .delayable import Draw
|
||||
|
||||
global renderer
|
||||
|
||||
def view3d_find():
|
||||
for area in bpy.data.window_managers[0].windows[0].screen.areas:
|
||||
|
3
ui.py
3
ui.py
@ -163,6 +163,7 @@ class SESSION_PT_user(bpy.types.Panel):
|
||||
area_msg = col.row(align = True)
|
||||
item_box = area_msg.box()
|
||||
client = operators.client.get(key).buffer
|
||||
pointer = operators.client.get(key).pointer
|
||||
info = ""
|
||||
|
||||
detail_item_row = item_box.row(align = True)
|
||||
@ -177,7 +178,7 @@ class SESSION_PT_user(bpy.types.Panel):
|
||||
|
||||
detail_item_row.label(
|
||||
text="{} {}".format(username, info))
|
||||
|
||||
detail_item_row.label(text=str(pointer))
|
||||
if not is_local_user:
|
||||
detail_item_row.operator(
|
||||
"session.snapview", text="", icon='VIEW_CAMERA').target_client = key
|
||||
|
Reference in New Issue
Block a user