Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update LoL to Blender API changes; bugfix; temporary LoL server #954

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 17 additions & 33 deletions draw/lol/viewport.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#
# #####

import bgl, blf
import blf
import bpy
import gpu
import math
Expand All @@ -49,6 +49,7 @@ def draw_progress(x, y, text='', percent=None, color=(0, 1, 0, 1)):


def draw_rect(x, y, width, height, color):
gpu.state.blend_set('ALPHA')
xmax = x + width
ymax = y + height
points = [[x, y], # [x, y]
Expand All @@ -58,13 +59,13 @@ def draw_rect(x, y, width, height, color):
]
indices = ((0, 1, 2), (2, 3, 0))

shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
shader = gpu.shader.from_builtin('UNIFORM_COLOR')
batch = batch_for_shader(shader, 'TRIS', {"pos": points}, indices=indices)

shader.bind()
shader.uniform_float("color", color)
bgl.glEnable(bgl.GL_BLEND)
batch.draw(shader)
gpu.state.blend_set('NONE')


def draw_line2d(x1, y1, x2, y2, width, color):
Expand All @@ -73,31 +74,28 @@ def draw_line2d(x1, y1, x2, y2, width, color):

indices = (
(0, 1),)
bgl.glEnable(bgl.GL_BLEND)
bgl.glEnable(bgl.GL_LINE_SMOOTH)

shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
gpu.state.blend_set('ALPHA')
shader = gpu.shader.from_builtin('UNIFORM_COLOR')
batch = batch_for_shader(shader, 'LINES', {"pos": coords}, indices=indices)
shader.bind()
shader.uniform_float("color", color)
batch.draw(shader)
gpu.state.blend_set('NONE')


def draw_lines(vertices, indices, color):
bgl.glEnable(bgl.GL_BLEND)
bgl.glEnable(bgl.GL_LINE_SMOOTH)
bgl.glLineWidth(2)

shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
gpu.state.blend_set('ALPHA')
shader = gpu.shader.from_builtin('UNIFORM_COLOR')
batch = batch_for_shader(shader, 'LINES', {"pos": vertices}, indices=indices)
shader.bind()
shader.uniform_float("color", color)
batch.draw(shader)

gpu.state.blend_set('NONE')

def draw_rect_3d(coords, color):
indices = [(0, 1, 2), (2, 3, 0)]
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
shader = gpu.shader.from_builtin('UNIFORM_COLOR')
batch = batch_for_shader(shader, 'TRIS', {"pos": coords}, indices=indices)
shader.uniform_float("color", color)
batch.draw(shader)
Expand Down Expand Up @@ -146,8 +144,6 @@ def draw_bbox(location, rotation, bbox_min, bbox_max, progress=None, color=(0, 1


def draw_image(x, y, width, height, image, transparency, crop=(0, 0, 1, 1)):
# draw_rect(x,y, width, height, (.5,0,0,.5))

coords = [
(x, y), (x + width, y),
(x, y + height), (x + width, y + height)]
Expand All @@ -160,32 +156,20 @@ def draw_image(x, y, width, height, image, transparency, crop=(0, 0, 1, 1)):

indices = [(0, 1, 2), (2, 1, 3)]

shader = gpu.shader.from_builtin('2D_IMAGE')
gpu.state.blend_set('ALPHA')
shader = gpu.shader.from_builtin('IMAGE')
batch = batch_for_shader(shader, 'TRIS',
{"pos": coords,
"texCoord": uvs},
indices=indices)

# send image to gpu if it isn't there already
if image.gl_load():
raise Exception()

# texture identifier on gpu
texture_id = image.bindcode

# in case someone disabled it before
bgl.glEnable(bgl.GL_BLEND)

# bind texture to image unit 0
bgl.glActiveTexture(bgl.GL_TEXTURE0)
bgl.glBindTexture(bgl.GL_TEXTURE_2D, texture_id)
texture = gpu.texture.from_image(image)

shader.bind()
# tell shader to use the image that is bound to image unit 0
shader.uniform_int("image", 0)
shader.uniform_sampler("image", texture)
batch.draw(shader)

bgl.glDisable(bgl.GL_TEXTURE_2D)
gpu.state.blend_set('NONE')


def draw_downloader(x, y, percent=0, img=None):
Expand All @@ -205,7 +189,7 @@ def draw_text(text, x, y, size, color=(1, 1, 1, 0.5)):
# bgl.glColor4f(*color)
blf.color(font_id, color[0], color[1], color[2], color[3])
blf.position(font_id, x, y, 0)
blf.size(font_id, size, 72)
blf.size(font_id, size)
blf.draw(font_id, text)


Expand Down
4 changes: 2 additions & 2 deletions handlers/draw_imageeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _draw_rect(x, y, width, height, color, view_to_region):
co = ((x1, y1), (x2, y2), (x3, y3), (x4, y4))
indices = ((0, 1), (1, 2), (2, 3), (3, 0))

shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
shader = gpu.shader.from_builtin('UNIFORM_COLOR')
batch = batch_for_shader(shader, 'LINES', {"pos": co}, indices=indices)
shader.bind()
shader.uniform_float("color", color)
Expand All @@ -105,5 +105,5 @@ def _draw_text(text, x, y, color, view_to_region):
r, g, b, a = color
blf.position(font_id, pixelpos_x + offset, pixelpos_y + offset, 0)
blf.color(font_id, r,g,b,a)
blf.size(font_id, text_size, dpi)
blf.size(font_id, text_size)
blf.draw(font_id, text)
6 changes: 3 additions & 3 deletions operators/lol/add_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def render_thumbnail(args):
from ...utils.compatibility import run
(context, assetfile, asset_type) = args

name = basename(dirname(dirname(dirname(__file__))))
name = 'bl_ext.user_default.' + basename(dirname(dirname(dirname(__file__))))
user_preferences = context.preferences.addons[name].preferences


Expand Down Expand Up @@ -131,7 +131,7 @@ def execute(self, context):
ui_props = scene.luxcoreOL.ui
upload_props = scene.luxcoreOL.upload

name = basename(dirname(dirname(dirname(__file__))))
name = 'bl_ext.user_default.' + basename(dirname(dirname(dirname(__file__))))
user_preferences = context.preferences.addons[name].preferences

if len(context.selected_objects) == 0:
Expand Down Expand Up @@ -243,7 +243,7 @@ def execute(self, context):
ui_props = scene.luxcoreOL.ui
upload_props = scene.luxcoreOL.upload

name = basename(dirname(dirname(dirname(__file__))))
name = 'bl_ext.user_default.' + basename(dirname(dirname(dirname(__file__))))
user_preferences = context.preferences.addons[name].preferences
assetpath = join(user_preferences.global_dir, ui_props.asset_type.lower(), 'local')

Expand Down
2 changes: 1 addition & 1 deletion operators/lol/update_ToC.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def execute(self, context):
scene = context.scene
ui_props = scene.luxcoreOL.ui

name = basename(dirname(dirname(dirname(__file__))))
name = 'bl_ext.user_default.' + basename(dirname(dirname(dirname(__file__))))
user_preferences = context.preferences.addons[name].preferences

filepath = join(user_preferences.global_dir, 'assets_model_blendermarket.json')
Expand Down
2 changes: 1 addition & 1 deletion operators/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class LUXCORE_MT_node_tree:
bl_idname = "LUXCORE_MT_node_tree"
bl_label = "Select Node Tree"
bl_description = "Select a node tree"
bl_options = {"UNDO"}
# bl_options = {"UNDO"}

def draw(self, context):
# Has to be present for class registration
Expand Down
4 changes: 2 additions & 2 deletions scripts/LOL/render_thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def calc_bbox(context, objects):
def render_material_thumbnail(assetname, blendfile, thumbnail, samples):
context = bpy.context
scene = context.scene
name = basename(dirname(dirname(dirname(__file__))))
name = 'bl_ext.user_default.' + basename(dirname(dirname(dirname(__file__))))
user_preferences = context.preferences.addons[name].preferences

with bpy.data.libraries.load(blendfile, link=True) as (mat_from, mat_to):
Expand Down Expand Up @@ -69,7 +69,7 @@ def render_material_thumbnail(assetname, blendfile, thumbnail, samples):
def render_model_thumbnail(assetname, blendfile, thumbnail, samples):
context = bpy.context
scene = context.scene
name = basename(dirname(dirname(dirname(__file__))))
name = 'bl_ext.user_default.' + basename(dirname(dirname(dirname(__file__))))
user_preferences = context.preferences.addons[name].preferences

with bpy.data.libraries.load(blendfile, link=True) as (data_from, data_to):
Expand Down
16 changes: 11 additions & 5 deletions utils/lol/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
from ...utils import get_addon_preferences, compatibility


LOL_HOST_URL = "https://luxcorerender.org/lol"
#LOL_HOST_URL = "https://luxcorerender.org/lol"
# Temporary alternative host
LOL_HOST_URL = "https://www.sciencehooligans.de/lol"
LOL_VERSION = "v2.5"

download_threads = []
Expand All @@ -54,7 +56,7 @@ def load_local_TOC(context, asset_type):

assets = []

name = basename(dirname(dirname(dirname(__file__))))
name = 'bl_ext.user_default.' + basename(dirname(dirname(dirname(__file__))))
user_preferences = context.preferences.addons[name].preferences

filepath = join(user_preferences.global_dir, 'local_assets_' + asset_type.lower() + '.json')
Expand All @@ -72,7 +74,7 @@ def load_local_TOC(context, asset_type):


def load_patreon_assets(context):
name = basename(dirname(dirname(dirname(__file__))))
name = 'bl_ext.user_default.' + basename(dirname(dirname(dirname(__file__))))
user_preferences = context.preferences.addons[name].preferences

#check if local file is available
Expand Down Expand Up @@ -120,7 +122,7 @@ def download_table_of_contents(context):
global bg_threads
scene = context.scene
ui_props = context.scene.luxcoreOL.ui
name = basename(dirname(dirname(dirname(__file__))))
name = 'bl_ext.user_default.' + basename(dirname(dirname(dirname(__file__))))
user_preferences = context.preferences.addons[name].preferences

try:
Expand Down Expand Up @@ -605,10 +607,14 @@ def clean_previmg(fullsize=False):


def load_previews(context, asset_type):
bg_load_previews(context, asset_type)
# The following code did not seem to be thread safe regarding deleting and accessing preview images. Leaving in here for future reference regarding performance optimization
"""
global bg_threads
bg_task = Thread(target=bg_load_previews, args=(context, asset_type))
bg_threads.append(["bg_load_previews", bg_task])
bg_task.start()
"""


def bg_load_previews(context, asset_type):
Expand Down Expand Up @@ -689,7 +695,7 @@ def bg_download_thumbnails(context, download_queue):
from requests import Session
session = Session()

name = basename(dirname(dirname(dirname(__file__))))
name = 'bl_ext.user_default.' + basename(dirname(dirname(dirname(__file__))))
user_preferences = context.preferences.addons[name].preferences

while not download_queue.empty():
Expand Down
Loading