forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
50
leenkx/blender/lnx/lightmapper/operators/__init__.py
Normal file
50
leenkx/blender/lnx/lightmapper/operators/__init__.py
Normal file
@ -0,0 +1,50 @@
|
||||
import bpy
|
||||
from bpy.utils import register_class, unregister_class
|
||||
from . import tlm, installopencv, imagetools
|
||||
|
||||
classes = [
|
||||
tlm.TLM_BuildLightmaps,
|
||||
tlm.TLM_CleanLightmaps,
|
||||
tlm.TLM_ExploreLightmaps,
|
||||
tlm.TLM_EnableSet,
|
||||
tlm.TLM_DisableSelection,
|
||||
tlm.TLM_RemoveLightmapUV,
|
||||
tlm.TLM_SelectLightmapped,
|
||||
tlm.TLM_ToggleTexelDensity,
|
||||
installopencv.TLM_Install_OpenCV,
|
||||
tlm.TLM_AtlasListNewItem,
|
||||
tlm.TLM_AtlastListDeleteItem,
|
||||
tlm.TLM_AtlasListMoveItem,
|
||||
tlm.TLM_PostAtlasListNewItem,
|
||||
tlm.TLM_PostAtlastListDeleteItem,
|
||||
tlm.TLM_PostAtlasListMoveItem,
|
||||
tlm.TLM_StartServer,
|
||||
tlm.TLM_BuildEnvironmentProbes,
|
||||
tlm.TLM_CleanBuildEnvironmentProbes,
|
||||
tlm.TLM_PrepareUVMaps,
|
||||
tlm.TLM_LoadLightmaps,
|
||||
tlm.TLM_DisableSpecularity,
|
||||
tlm.TLM_DisableMetallic,
|
||||
tlm.TLM_RemoveEmptyImages,
|
||||
tlm.TLM_AddCollectionsPost,
|
||||
tlm.TLM_AddSelectedCollectionsPost,
|
||||
tlm.TLM_PostAtlasSpecialsMenu,
|
||||
tlm.TLM_AddCollections,
|
||||
tlm.TLM_AddSelectedCollections,
|
||||
tlm.TLM_AtlasSpecialsMenu,
|
||||
tlm.TLM_Reset,
|
||||
tlm.TLM_CalcTexDex,
|
||||
imagetools.TLM_ImageUpscale,
|
||||
imagetools.TLM_ImageDownscale,
|
||||
tlm.TLM_AddGLTFNode,
|
||||
tlm.TLM_ShiftMultiplyLinks
|
||||
|
||||
]
|
||||
|
||||
def register():
|
||||
for cls in classes:
|
||||
register_class(cls)
|
||||
|
||||
def unregister():
|
||||
for cls in classes:
|
||||
unregister_class(cls)
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
193
leenkx/blender/lnx/lightmapper/operators/imagetools.py
Normal file
193
leenkx/blender/lnx/lightmapper/operators/imagetools.py
Normal file
@ -0,0 +1,193 @@
|
||||
import bpy, os, time, importlib
|
||||
|
||||
class TLM_ImageUpscale(bpy.types.Operator):
|
||||
bl_idname = "tlm.image_upscale"
|
||||
bl_label = "Upscale image"
|
||||
bl_description = "Upscales the image to double resolution"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
|
||||
cv2 = importlib.util.find_spec("cv2")
|
||||
|
||||
if cv2 is None:
|
||||
print("CV2 not found - Ignoring filtering")
|
||||
return 0
|
||||
else:
|
||||
cv2 = importlib.__import__("cv2")
|
||||
|
||||
for area in bpy.context.screen.areas:
|
||||
if area.type == "IMAGE_EDITOR":
|
||||
active_image = area.spaces.active.image
|
||||
|
||||
if active_image.source == "FILE":
|
||||
img_path = active_image.filepath_raw
|
||||
filename = os.path.basename(img_path)
|
||||
|
||||
basename = os.path.splitext(filename)[0]
|
||||
extension = os.path.splitext(filename)[1]
|
||||
|
||||
size_x = active_image.size[0]
|
||||
size_y = active_image.size[1]
|
||||
|
||||
dir_path = os.path.dirname(os.path.realpath(img_path))
|
||||
|
||||
#newfile = os.path.join(dir_path, basename + "_" + str(size_x) + "_" + str(size_y) + extension)
|
||||
newfile = os.path.join(dir_path, basename + extension)
|
||||
os.rename(img_path, newfile)
|
||||
|
||||
basefile = cv2.imread(newfile, cv2.IMREAD_UNCHANGED)
|
||||
|
||||
scale_percent = 200 # percent of original size
|
||||
width = int(basefile.shape[1] * scale_percent / 100)
|
||||
height = int(basefile.shape[0] * scale_percent / 100)
|
||||
dim = (width, height)
|
||||
|
||||
if active_image.TLM_ImageProperties.tlm_image_scale_method == "Nearest":
|
||||
interp = cv2.INTER_NEAREST
|
||||
elif active_image.TLM_ImageProperties.tlm_image_scale_method == "Area":
|
||||
interp = cv2.INTER_AREA
|
||||
elif active_image.TLM_ImageProperties.tlm_image_scale_method == "Linear":
|
||||
interp = cv2.INTER_LINEAR
|
||||
elif active_image.TLM_ImageProperties.tlm_image_scale_method == "Cubic":
|
||||
interp = cv2.INTER_CUBIC
|
||||
elif active_image.TLM_ImageProperties.tlm_image_scale_method == "Lanczos":
|
||||
interp = cv2.INTER_LANCZOS4
|
||||
|
||||
resized = cv2.resize(basefile, dim, interpolation = interp)
|
||||
|
||||
#resizedFile = os.path.join(dir_path, basename + "_" + str(width) + "_" + str(height) + extension)
|
||||
resizedFile = os.path.join(dir_path, basename + extension)
|
||||
|
||||
cv2.imwrite(resizedFile, resized)
|
||||
|
||||
active_image.filepath_raw = resizedFile
|
||||
bpy.ops.image.reload()
|
||||
|
||||
print(newfile)
|
||||
print(img_path)
|
||||
|
||||
else:
|
||||
|
||||
print("Please save image")
|
||||
|
||||
print("Upscale")
|
||||
|
||||
return {'RUNNING_MODAL'}
|
||||
|
||||
class TLM_ImageDownscale(bpy.types.Operator):
|
||||
bl_idname = "tlm.image_downscale"
|
||||
bl_label = "Downscale image"
|
||||
bl_description = "Downscales the image to double resolution"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
|
||||
cv2 = importlib.util.find_spec("cv2")
|
||||
|
||||
if cv2 is None:
|
||||
print("CV2 not found - Ignoring filtering")
|
||||
return 0
|
||||
else:
|
||||
cv2 = importlib.__import__("cv2")
|
||||
|
||||
for area in bpy.context.screen.areas:
|
||||
if area.type == "IMAGE_EDITOR":
|
||||
active_image = area.spaces.active.image
|
||||
|
||||
if active_image.source == "FILE":
|
||||
img_path = active_image.filepath_raw
|
||||
filename = os.path.basename(img_path)
|
||||
|
||||
basename = os.path.splitext(filename)[0]
|
||||
extension = os.path.splitext(filename)[1]
|
||||
|
||||
size_x = active_image.size[0]
|
||||
size_y = active_image.size[1]
|
||||
|
||||
dir_path = os.path.dirname(os.path.realpath(img_path))
|
||||
|
||||
#newfile = os.path.join(dir_path, basename + "_" + str(size_x) + "_" + str(size_y) + extension)
|
||||
newfile = os.path.join(dir_path, basename + extension)
|
||||
os.rename(img_path, newfile)
|
||||
|
||||
basefile = cv2.imread(newfile, cv2.IMREAD_UNCHANGED)
|
||||
|
||||
scale_percent = 50 # percent of original size
|
||||
width = int(basefile.shape[1] * scale_percent / 100)
|
||||
height = int(basefile.shape[0] * scale_percent / 100)
|
||||
dim = (width, height)
|
||||
|
||||
if dim[0] > 1 or dim[1] > 1:
|
||||
|
||||
if active_image.TLM_ImageProperties.tlm_image_scale_method == "Nearest":
|
||||
interp = cv2.INTER_NEAREST
|
||||
elif active_image.TLM_ImageProperties.tlm_image_scale_method == "Area":
|
||||
interp = cv2.INTER_AREA
|
||||
elif active_image.TLM_ImageProperties.tlm_image_scale_method == "Linear":
|
||||
interp = cv2.INTER_LINEAR
|
||||
elif active_image.TLM_ImageProperties.tlm_image_scale_method == "Cubic":
|
||||
interp = cv2.INTER_CUBIC
|
||||
elif active_image.TLM_ImageProperties.tlm_image_scale_method == "Lanczos":
|
||||
interp = cv2.INTER_LANCZOS4
|
||||
|
||||
resized = cv2.resize(basefile, dim, interpolation = interp)
|
||||
|
||||
#resizedFile = os.path.join(dir_path, basename + "_" + str(width) + "_" + str(height) + extension)
|
||||
resizedFile = os.path.join(dir_path, basename + extension)
|
||||
|
||||
cv2.imwrite(resizedFile, resized)
|
||||
|
||||
active_image.filepath_raw = resizedFile
|
||||
bpy.ops.image.reload()
|
||||
|
||||
print(newfile)
|
||||
print(img_path)
|
||||
|
||||
else:
|
||||
|
||||
print("Please save image")
|
||||
|
||||
print("Upscale")
|
||||
|
||||
return {'RUNNING_MODAL'}
|
||||
|
||||
class TLM_ImageSwitchUp(bpy.types.Operator):
|
||||
bl_idname = "tlm.image_switchup"
|
||||
bl_label = "Quickswitch Up"
|
||||
bl_description = "Switches to a cached upscaled image"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
|
||||
for area in bpy.context.screen.areas:
|
||||
if area.type == "IMAGE_EDITOR":
|
||||
active_image = area.spaces.active.image
|
||||
|
||||
if active_image.source == "FILE":
|
||||
img_path = active_image.filepath_raw
|
||||
filename = os.path.basename(img_path)
|
||||
|
||||
print("Switch up")
|
||||
|
||||
return {'RUNNING_MODAL'}
|
||||
|
||||
class TLM_ImageSwitchDown(bpy.types.Operator):
|
||||
bl_idname = "tlm.image_switchdown"
|
||||
bl_label = "Quickswitch Down"
|
||||
bl_description = "Switches to a cached downscaled image"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
|
||||
for area in bpy.context.screen.areas:
|
||||
if area.type == "IMAGE_EDITOR":
|
||||
active_image = area.spaces.active.image
|
||||
|
||||
if active_image.source == "FILE":
|
||||
img_path = active_image.filepath_raw
|
||||
filename = os.path.basename(img_path)
|
||||
|
||||
print("Switch Down")
|
||||
|
||||
return {'RUNNING_MODAL'}
|
81
leenkx/blender/lnx/lightmapper/operators/installopencv.py
Normal file
81
leenkx/blender/lnx/lightmapper/operators/installopencv.py
Normal file
@ -0,0 +1,81 @@
|
||||
import bpy, math, os, platform, subprocess, sys, re, shutil
|
||||
|
||||
def ShowMessageBox(message = "", title = "Message Box", icon = 'INFO'):
|
||||
|
||||
def draw(self, context):
|
||||
self.layout.label(text=message)
|
||||
|
||||
bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)
|
||||
|
||||
class TLM_Install_OpenCV(bpy.types.Operator):
|
||||
"""Install OpenCV"""
|
||||
bl_idname = "tlm.install_opencv_lightmaps"
|
||||
bl_label = "Install OpenCV"
|
||||
bl_description = "Install OpenCV"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def execute(self, context):
|
||||
|
||||
scene = context.scene
|
||||
cycles = bpy.data.scenes[scene.name].cycles
|
||||
|
||||
print("Module OpenCV")
|
||||
|
||||
if (2, 91, 0) > bpy.app.version:
|
||||
pythonbinpath = bpy.app.binary_path_python
|
||||
else:
|
||||
pythonbinpath = sys.executable
|
||||
|
||||
if platform.system() == "Windows":
|
||||
pythonlibpath = os.path.join(os.path.dirname(os.path.dirname(pythonbinpath)), "lib")
|
||||
else:
|
||||
pythonlibpath = os.path.join(os.path.dirname(os.path.dirname(pythonbinpath)), "lib", os.path.basename(pythonbinpath))
|
||||
|
||||
ensurepippath = os.path.join(pythonlibpath, "ensurepip")
|
||||
|
||||
cmda = [pythonbinpath, ensurepippath, "--upgrade", "--user"]
|
||||
pip = subprocess.run(cmda)
|
||||
cmdc = [pythonbinpath, "-m", "pip", "install", "--upgrade", "pip"]
|
||||
pipc = subprocess.run(cmdc)
|
||||
|
||||
if pip.returncode == 0:
|
||||
print("Sucessfully installed pip!\n")
|
||||
else:
|
||||
|
||||
try:
|
||||
import pip
|
||||
module_pip = True
|
||||
except ImportError:
|
||||
#pip
|
||||
module_pip = False
|
||||
|
||||
if not module_pip:
|
||||
print("Failed to install pip!\n")
|
||||
if platform.system() == "Windows":
|
||||
ShowMessageBox("Failed to install pip - Please start Blender as administrator", "Restart", 'PREFERENCES')
|
||||
else:
|
||||
ShowMessageBox("Failed to install pip - Try starting Blender with SUDO", "Restart", 'PREFERENCES')
|
||||
return{'FINISHED'}
|
||||
|
||||
cmdb = [pythonbinpath, "-m", "pip", "install", "opencv-python"]
|
||||
|
||||
#opencv = subprocess.run(cmdb, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
opencv = subprocess.run(cmdb)
|
||||
|
||||
if opencv.returncode == 0:
|
||||
print("Successfully installed OpenCV!\n")
|
||||
else:
|
||||
print("Failed to install OpenCV!\n")
|
||||
|
||||
if platform.system() == "Windows":
|
||||
ShowMessageBox("Failed to install opencv - Please start Blender as administrator", "Restart", 'PREFERENCES')
|
||||
else:
|
||||
ShowMessageBox("Failed to install opencv - Try starting Blender with SUDO", "Restart", 'PREFERENCES')
|
||||
|
||||
return{'FINISHED'}
|
||||
|
||||
module_opencv = True
|
||||
print("Sucessfully installed OpenCV!\n")
|
||||
ShowMessageBox("Please restart blender to enable OpenCV filtering", "Restart", 'PREFERENCES')
|
||||
|
||||
return{'FINISHED'}
|
1731
leenkx/blender/lnx/lightmapper/operators/tlm.py
Normal file
1731
leenkx/blender/lnx/lightmapper/operators/tlm.py
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user