Merge branch 'master' into animation-support

This commit is contained in:
Swann Martinez 2019-12-02 17:36:59 +01:00
commit d12fe9dd70
No known key found for this signature in database
GPG Key ID: 414CCAFD8DA720E1
8 changed files with 229 additions and 17 deletions

View File

@ -14,8 +14,11 @@ __all__ = [
'bl_armature', 'bl_armature',
'bl_action', 'bl_action',
'bl_world', 'bl_world',
'bl_metaball' 'bl_metaball',
] 'bl_lattice',
'bl_lightprobe',
'bl_speaker'
] # Order here defines execution order
from . import * from . import *
from ..libs.replication.replication.data import ReplicatedDataFactory from ..libs.replication.replication.data import ReplicatedDataFactory

View File

@ -43,6 +43,13 @@ class BlCurve(BlDatablock):
spline_data['bezier_points'] = dumper.dump(spline.bezier_points) spline_data['bezier_points'] = dumper.dump(spline.bezier_points)
spline_data['type'] = dumper.dump(spline.type) spline_data['type'] = dumper.dump(spline.type)
data['splines'][index] = spline_data data['splines'][index] = spline_data
if isinstance(pointer,'TextCurve'):
data['type'] = 'TEXT'
if isinstance(pointer,'SurfaceCurve'):
data['type'] = 'SURFACE'
if isinstance(pointer,'TextCurve'):
data['type'] = 'CURVE'
return data return data
def resolve(self): def resolve(self):

View File

@ -0,0 +1,54 @@
import bpy
import mathutils
from .. import utils
from .bl_datablock import BlDatablock
class BlLattice(BlDatablock):
def load(self, data, target):
utils.dump_anything.load(target, data)
for point in data['points']:
utils.dump_anything.load(target.points[point], data["points"][point])
def construct(self, data):
return bpy.data.lattices.new(data["name"])
def dump(self, pointer=None):
assert(pointer)
dumper = utils.dump_anything.Dumper()
dumper.depth = 3
dumper.include_filter = [
"name",
'type',
'points_u',
'points_v',
'points_w',
'interpolation_type_u',
'interpolation_type_v',
'interpolation_type_w',
'use_outside',
'points',
'co',
'weight_softbody',
'co_deform'
]
data = dumper.dump(pointer)
return data
def resolve(self):
self.pointer = utils.find_from_attr('uuid', self.uuid, bpy.data.lattices)
def is_valid(self):
return bpy.data.lattices.get(self.data['name'])
bl_id = "lattices"
bl_class = bpy.types.Lattice
bl_rep_class = BlLattice
bl_delay_refresh = 1
bl_delay_apply = 1
bl_automatic_push = True
bl_icon = 'LATTICE_DATA'

View File

@ -0,0 +1,49 @@
import bpy
import mathutils
from .. import utils
from .bl_datablock import BlDatablock
class BlLightProbe(BlDatablock):
def load(self, data, target):
utils.dump_anything.load(target, data)
def construct(self, data):
return bpy.data.lightprobes.new(data["name"])
def dump(self, pointer=None):
assert(pointer)
dumper = utils.dump_anything.Dumper()
dumper.depth = 1
dumper.include_filter = [
"name",
'influence_type',
'influence_distance',
'falloff',
'intensity',
'clip_start',
'clip_end',
'visibility_collection',
'use_custom_parallax',
'parallax_type',
'parallax_distance',
]
return dumper.dump(pointer)
def resolve(self):
self.pointer = utils.find_from_attr('uuid', self.uuid, bpy.data.lattices)
def is_valid(self):
return bpy.data.lattices.get(self.data['name'])
bl_id = "lightprobes"
bl_class = bpy.types.LightProbe
bl_rep_class = BlLightProbe
bl_delay_refresh = 1
bl_delay_apply = 1
bl_automatic_push = True
bl_icon = 'LIGHTPROBE_GRID'

View File

@ -62,6 +62,14 @@ class BlObject(BlDatablock):
pointer = bpy.data.grease_pencils[data["data"]] pointer = bpy.data.grease_pencils[data["data"]]
elif data["data"] in bpy.data.curves.keys(): elif data["data"] in bpy.data.curves.keys():
pointer = bpy.data.curves[data["data"]] pointer = bpy.data.curves[data["data"]]
elif data["data"] in bpy.data.lattices.keys():
pointer = bpy.data.lattices[data["data"]]
elif data["data"] in bpy.data.speakers.keys():
pointer = bpy.data.speakers[data["data"]]
elif data["data"] in bpy.data.lightprobes.keys():
pass
# bpy need to support correct lightprobe creation from python
# pointer = bpy.data.lightprobes[data["data"]]
instance = bpy.data.objects.new(data["name"], pointer) instance = bpy.data.objects.new(data["name"], pointer)
instance.uuid = self.uuid instance.uuid = self.uuid

View File

@ -0,0 +1,50 @@
import bpy
import mathutils
from .. import utils
from .bl_datablock import BlDatablock
class BlSpeaker(BlDatablock):
def load(self, data, target):
utils.dump_anything.load(target, data)
def construct(self, data):
return bpy.data.speakers.new(data["name"])
def dump(self, pointer=None):
assert(pointer)
dumper = utils.dump_anything.Dumper()
dumper.depth = 1
dumper.include_filter = [
"muted",
'volume',
'name',
'pitch',
'volume_min',
'volume_max',
'attenuation',
'distance_max',
'distance_reference',
'cone_angle_outer',
'cone_angle_inner',
'cone_volume_outer'
]
return dumper.dump(pointer)
def resolve(self):
self.pointer = utils.find_from_attr('uuid', self.uuid, bpy.data.lattices)
def is_valid(self):
return bpy.data.lattices.get(self.data['name'])
bl_id = "speakers"
bl_class = bpy.types.Speaker
bl_rep_class = BlSpeaker
bl_delay_refresh = 1
bl_delay_apply = 1
bl_automatic_push = True
bl_icon = 'SPEAKER'

View File

@ -20,7 +20,11 @@ from . import bl_types, delayable, environment, presence, ui, utils
from .libs.replication.replication.data import ReplicatedDataFactory from .libs.replication.replication.data import ReplicatedDataFactory
from .libs.replication.replication.exception import NonAuthorizedOperationError from .libs.replication.replication.exception import NonAuthorizedOperationError
from .libs.replication.replication.interface import Session from .libs.replication.replication.interface import Session
from .libs.replication.replication.constants import FETCHED from .libs.replication.replication.constants import (
STATE_ACTIVE,
STATE_INITIAL,
STATE_SYNCING,
FETCHED)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR) logger.setLevel(logging.ERROR)
@ -376,6 +380,12 @@ classes = (
SessionCommit, SessionCommit,
ApplyArmatureOperator, ApplyArmatureOperator,
) )
@persistent
def load_pre_handler(dummy):
global client
if client and client.state in [STATE_ACTIVE, STATE_SYNCING]:
bpy.ops.session.stop()
def register(): def register():
@ -383,6 +393,10 @@ def register():
for cls in classes: for cls in classes:
register_class(cls) register_class(cls)
<<<<<<< HEAD
=======
bpy.app.handlers.load_pre.append(load_pre_handler)
>>>>>>> master
def unregister(): def unregister():
global client global client
@ -395,6 +409,8 @@ def unregister():
for cls in reversed(classes): for cls in reversed(classes):
unregister_class(cls) unregister_class(cls)
bpy.app.handlers.load_pre.remove(load_pre_handler)
if __name__ == "__main__": if __name__ == "__main__":
register() register()

View File

@ -56,6 +56,18 @@ def get_target_far(region, rv3d, coord, distance):
return [target.x, target.y, target.z] return [target.x, target.y, target.z]
def get_default_bbox(obj, radius):
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)]
base = obj.matrix_world
bbox_corners = [base @ mathutils.Vector(corner) for corner in coords]
return [(point.x, point.y, point.z)
for point in bbox_corners]
def get_client_cam_points(): def get_client_cam_points():
area, region, rv3d = view3d_find() area, region, rv3d = view3d_find()
@ -131,7 +143,7 @@ class User():
def update_presence(self, context): def update_presence(self, context):
global renderer global renderer
if 'renderer' in globals(): if 'renderer' in globals() and hasattr(renderer, 'run'):
if self.enable_presence: if self.enable_presence:
renderer.run() renderer.run()
else: else:
@ -183,7 +195,7 @@ class DrawFactory(object):
self.d3d_items.clear() self.d3d_items.clear()
self.d2d_items.clear() self.d2d_items.clear()
def flush_selection(self, user): def flush_selection(self, user=None):
key_to_remove = [] key_to_remove = []
select_key = "{}_select".format(user) if user else "select" select_key = "{}_select".format(user) if user else "select"
for k in self.d3d_items.keys(): for k in self.d3d_items.keys():
@ -213,35 +225,45 @@ class DrawFactory(object):
for select_ob in client_selection: for select_ob in client_selection:
drawable_key = "{}_select_{}".format(client_uuid, select_ob) drawable_key = "{}_select_{}".format(client_uuid, select_ob)
indices = (
(0, 1), (1, 2), (2, 3), (0, 3), ob = utils.find_from_attr("uuid", select_ob, bpy.data.objects)
(4, 5), (5, 6), (6, 7), (4, 7),
(0, 4), (1, 5), (2, 6), (3, 7)
)
ob = utils.find_from_attr("uuid",select_ob,bpy.data.objects)
if not ob: if not ob:
return return
item_to_draw = []
if ob.type == 'EMPTY': if ob.type == 'EMPTY':
# Child case # TODO: Child case
# Collection instance case # Collection instance case
if ob.instance_collection: if ob.instance_collection:
for obj in ob.instance_collection.objects: for obj in ob.instance_collection.objects:
if obj.type == 'MESH': if obj.type == 'MESH':
self.append_3d_item( self.append_3d_item(
drawable_key, drawable_key,
client_color, client_color,
get_bb_coords_from_obj(obj, parent=ob), get_bb_coords_from_obj(obj, parent=ob),
indices) indices)
if ob.type == 'MESH': if ob.type in ['MESH','META']:
indices = (
(0, 1), (1, 2), (2, 3), (0, 3),
(4, 5), (5, 6), (6, 7), (4, 7),
(0, 4), (1, 5), (2, 6), (3, 7))
self.append_3d_item( self.append_3d_item(
drawable_key, drawable_key,
client_color, client_color,
get_bb_coords_from_obj(ob), get_bb_coords_from_obj(ob),
indices) indices)
else:
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))
self.append_3d_item(
drawable_key,
client_color,
get_default_bbox(ob, ob.scale.x),
indices)
def append_3d_item(self,key,color, coords, indices): def append_3d_item(self,key,color, coords, indices):
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR') shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
@ -279,6 +301,9 @@ class DrawFactory(object):
def draw3d_callback(self): def draw3d_callback(self):
bgl.glLineWidth(1.5) bgl.glLineWidth(1.5)
bgl.glEnable(bgl.GL_DEPTH_TEST) bgl.glEnable(bgl.GL_DEPTH_TEST)
bgl.glEnable(bgl.GL_BLEND)
bgl.glEnable(bgl.GL_LINE_SMOOTH)
try: try:
for shader, batch, color in self.d3d_items.values(): for shader, batch, color in self.d3d_items.values():
shader.bind() shader.bind()