2022-05-07 02:27:06 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "IK9lYTykdbtt"
},
"source": [
2022-05-08 04:10:39 +00:00
"<h1>BlendererOnline</h1>\n",
"<small><i>Uses some codes of <a href='https://urlzs.com/4hkfp' target='_blank' rel='noopener'>BlenderRender</a> by <a href='https://urlzs.com/ToHpE' target='_blank' rel='noopener'>aniquetahir</a>.</i></small>\n",
2022-05-07 03:03:51 +00:00
"\n",
2022-05-08 04:10:39 +00:00
"<p>Render Blender files online, for free. </p>"
2022-05-07 02:27:06 +00:00
]
},
{
"cell_type": "code",
2022-05-09 00:13:23 +00:00
"execution_count": null,
2022-05-07 02:27:06 +00:00
"metadata": {
2022-05-09 00:13:23 +00:00
"id": "F5vZwPfYenN8",
"cellView": "form"
2022-05-07 02:27:06 +00:00
},
"outputs": [],
"source": [
"#@title Configuration\n",
"class formatting:\n",
" clear = '\\033[0m'\n",
" class color: \n",
" purple = '\\033[95m'\n",
" cyan = '\\033[96m'\n",
" cyan_dark = '\\033[36m'\n",
" blue = '\\033[94m'\n",
" green = '\\033[92m'\n",
" yellow = '\\033[93m'\n",
" red = '\\033[91m'\n",
" class font:\n",
" bold = '\\033[1m'\n",
" underline = '\\033[4m'\n",
"\n",
"## Define screen functions. \n",
"def clear(): from IPython.display import clear_output; return clear_output()\n",
"\n",
"class info: # screen messages\n",
" def status(message): print(formatting.font.bold + 'Status: \\t' + formatting.clear + message)\n",
" def err(message): print(formatting.font.bold + formatting.color.red + 'Error: \\t' + formatting.clear + formatting.clear + message)\n",
" def warning(message): print(formatting.font.bold + formatting.color.yellow + 'Warning: \\t' + formatting.clear + formatting.clear + message)\n",
" def success(message): print(formatting.font.bold + formatting.color.green + 'Success: \\t' + formatting.clear + formatting.clear + message)\n",
"\n",
"def check_compatibility(): \n",
" try: from google.colab import files\n",
" except: raise TypeError(\"No! Please run this in \" + formatting.font.bold + 'Google CoLab' + formatting.clear + '. ')\n",
"\n",
2022-05-07 04:58:09 +00:00
"def getExtension(fileName): \n",
" import os\n",
" fileName_split = os.path.splitext(fileName)\n",
"\n",
" return fileName_split[1].lower()\n",
"\n",
2022-05-07 02:27:06 +00:00
"def UploadBlendFile(): # Make sure that the file is actually a Blender file. \n",
" check_compatibility()\n",
2022-05-07 04:58:09 +00:00
"\n",
" import pathlib; from google.colab import files\n",
2022-05-07 02:27:06 +00:00
" uploaded_file = files.upload()\n",
" \n",
" return uploaded_file\n",
"\n",
2022-05-08 03:50:53 +00:00
"def checkValidUpload(what): # Make sure that the user has that file uploaded when specifying the name. \n",
2022-05-08 04:10:39 +00:00
" import os\n",
" if not(os.system('cat ' + str(what))):\n",
" info.warning('File does not exist.')\n",
" return (not(os.system('cat ' + str(what))))\n",
2022-05-08 03:50:53 +00:00
"\n",
"def properlySetFrames(frame_start, frame_end): \n",
" if frame_start == frame_end: return frame_end\n",
" else: return False\n",
2022-05-07 04:58:09 +00:00
"\n",
2022-05-07 02:27:06 +00:00
"class configuration: \n",
" #@markdown ### Input\n",
2022-05-07 04:58:09 +00:00
" \n",
2022-05-09 00:13:23 +00:00
" upload_new = 1 #@param {type:\"slider\", min:0, max:1, step:1}\n",
2022-05-08 03:50:53 +00:00
" if upload_new == True: UploadBlendFile()\n",
2022-05-07 04:58:09 +00:00
"\n",
2022-05-08 03:50:53 +00:00
" # user preferred file name\n",
2022-05-09 00:13:23 +00:00
" blend_fileName = '' #@param {type: \"string\"}\n",
2022-05-08 04:10:39 +00:00
" blend_fileName = blend_fileName.strip()\n",
" if blend_fileName != None: \n",
" if getExtension(blend_fileName) != '.blend' : blend_fileName = (str(blend_fileName) + '.blend'); checkValidUpload(blend_fileName)\n",
2022-05-07 02:27:06 +00:00
"\n",
2022-05-07 04:58:09 +00:00
" #@markdown ### Processing\n",
2022-05-07 02:27:06 +00:00
" renderer = \"CYCLES\" #@param [\"CYCLES\", \"BLENDER_EEVEE\", \"BLENDER_WORKBENCH\"]\n",
2022-05-08 03:50:53 +00:00
" device = \"CPU\" #@param [\"CPU\", 'CUDA', 'OPTIX', 'HIP', 'METAL']\n",
"\n",
" #@markdown ### Animation\n",
2022-05-07 04:58:09 +00:00
" frame_start = 1 #@param {type: \"number\"}\n",
2022-05-08 03:50:53 +00:00
" frame_end = 1 #@param {type: \"number\"}\n",
"\n",
" frame = properlySetFrames(frame_start, frame_end)\n",
"\n",
" #@markdown ### Output\n",
" output_fileFormat = 'JPEG' #@param ['TGA', 'RAWTGA', 'JPEG', 'IRIS', 'IRIZ', 'AVIRAW', 'AVIJPEG', 'PNG', 'BMP']\n"
2022-05-07 02:27:06 +00:00
]
},
{
"cell_type": "code",
2022-05-09 00:13:23 +00:00
"execution_count": null,
2022-05-07 02:27:06 +00:00
"metadata": {
"id": "8szOTQ7TTgNm",
2022-05-09 00:13:23 +00:00
"cellView": "form"
2022-05-07 02:27:06 +00:00
},
2022-05-09 00:13:23 +00:00
"outputs": [],
2022-05-07 02:27:06 +00:00
"source": [
2022-05-09 00:13:23 +00:00
"#@title Render\n",
"\n",
2022-05-07 02:27:06 +00:00
"import os\n",
"\n",
"class formatting:\n",
" clear = '\\033[0m'\n",
" class color: \n",
" purple = '\\033[95m'\n",
" cyan = '\\033[96m'\n",
" cyan_dark = '\\033[36m'\n",
" blue = '\\033[94m'\n",
" green = '\\033[92m'\n",
" yellow = '\\033[93m'\n",
" red = '\\033[91m'\n",
" class font:\n",
" bold = '\\033[1m'\n",
" underline = '\\033[4m'\n",
"\n",
"class info: # screen messages\n",
2022-05-08 03:50:53 +00:00
" def status(message): print(formatting.font.bold + 'Status: \\t' + formatting.clear + message)\n",
" def err(message): print(formatting.font.bold + formatting.color.red + 'Error: \\t' + formatting.clear + formatting.clear + message)\n",
" def warning(message): print(formatting.font.bold + formatting.color.yellow + 'Warning: \\t' + formatting.clear + formatting.clear + message)\n",
" def success(message): print(formatting.font.bold + formatting.color.green + 'Success: \\t' + formatting.clear + formatting.clear + message)\n",
2022-05-07 02:27:06 +00:00
"\n",
2022-05-08 04:10:39 +00:00
"def check_fieldsFilled(): # Make sure that the user has run the previous cell. \n",
2022-05-08 03:50:53 +00:00
" try: \n",
" clear()\n",
" except: \n",
" raise ImportError(formatting.font.bold + 'Please run the configurations cell before rendering. ' + formatting.clear + 'No default values are to be passed by this cell. ')\n",
" return False\n",
" else: \n",
2022-05-08 04:10:39 +00:00
" if configuration.blend_fileName == None: \n",
2022-05-08 12:55:48 +00:00
" raise ImportError(formatting.font.bold + 'The file name for the Blender file is missing. ' + formatting.clear + 'It is a required field. ')\n",
2022-05-08 04:10:39 +00:00
" else: \n",
" return True\n",
2022-05-07 02:27:06 +00:00
"\n",
"def install(what, isCritical = False):\n",
2022-05-07 03:03:51 +00:00
" if what == \"required\":\n",
" install(\"blender\", True)\n",
" install(\"libboost-all-dev\")\n",
" install(\"libgl1-mesa-dev\")\n",
2022-05-08 04:10:39 +00:00
" clear()\n",
2022-05-07 03:03:51 +00:00
" else:\n",
" info.status('Installing ' + what + '…')\n",
" try:\n",
" if os.system('apt install ' + what + ' -y') > 0: \n",
" if os.system('apt-get install ' + what + ' -y') > 0: \n",
" if os.system('apt install --fix-broken ' + what + ' -y'): raise\n",
" except:\n",
" errorMsg = (what + ' could not get installed. ')\n",
" if isCritical: raise SystemError(errorMsg + 'Unfortunately, this module is required. ')\n",
" else: info.err(errorMsg)\n",
" else: \n",
" os.system('apt clean && apt autoremove -y')\n",
" info.success('Installed '+ what + '.')\n",
2022-05-08 03:50:53 +00:00
"\n",
"def render(): \n",
2022-05-08 04:10:39 +00:00
" def checkInvalidUploadProceed(): # Make sure user is sure that the file does exist. \n",
2022-05-08 03:50:53 +00:00
" clear()\n",
2022-05-08 04:10:39 +00:00
" if not(checkValidUpload(configuration.blend_fileName)): \n",
2022-05-08 03:50:53 +00:00
" confirm_tries = 2; confirm_count = 0; \n",
" while confirm_count < confirm_tries: \n",
" try:\n",
" input('This will cause errors. Do you want to continue? \\n[\\tYes (⏎)\\t]')\n",
" except KeyboardInterrupt: \n",
" return False\n",
" else: \n",
" confirm_count = confirm_count + 1\n",
" if confirm_count == 2: return True\n",
2022-05-08 04:10:39 +00:00
" else: return True\n",
2022-05-08 03:50:53 +00:00
"\n",
"\n",
" def start_render(): \n",
" # Command line arguments from here: https://urlzs.com/MiUkt\n",
" # Simplified here: https://urlzs.com/au5z7\n",
"\n",
" info.status('Starting render of file ' + configuration.blend_fileName + '…')\n",
"\n",
2022-05-08 04:10:39 +00:00
" if not(configuration.frame): \n",
2022-05-08 03:50:53 +00:00
" !blender -b {configuration.blend_fileName} -o ./output_ -E {configuration.renderer} -F {configuration.output_fileFormat} -x 1 -s {configuration.frame_start} -e {configuration.frame_end} --cycles-device {configuration.device}\n",
" else: \n",
" !blender -b {configuration.blend_fileName} -o ./output_ -E {configuration.renderer} -F {configuration.output_fileFormat} -x 1 -f {configuration.frame} --cycles-device {configuration.device}\n",
2022-05-07 02:27:06 +00:00
"\n",
2022-05-08 12:55:48 +00:00
" info.status('Render of file ' + configuration.blend_fileName + ' has completed.')\n",
"\n",
2022-05-08 04:10:39 +00:00
" if checkInvalidUploadProceed(): \n",
" start_render()\n",
"\n",
2022-05-07 02:27:06 +00:00
"def main():\n",
2022-05-08 04:10:39 +00:00
" check_fieldsFilled();\n",
2022-05-08 03:50:53 +00:00
" install(\"required\");\n",
2022-05-08 04:10:39 +00:00
" render();\n",
2022-05-07 02:27:06 +00:00
"\n",
"main()"
]
},
{
2022-05-08 12:55:48 +00:00
"cell_type": "markdown",
2022-05-09 00:13:23 +00:00
"metadata": {
"id": "bpxn20vTIuVi"
},
2022-05-07 02:27:06 +00:00
"source": [
2022-05-09 07:27:29 +00:00
"## Utilities"
2022-05-07 02:27:06 +00:00
]
},
{
"cell_type": "code",
2022-05-08 03:50:53 +00:00
"execution_count": null,
2022-05-07 02:27:06 +00:00
"metadata": {
"id": "ilwDQe4gb3O5",
2022-05-09 00:13:23 +00:00
"cellView": "form"
2022-05-07 02:27:06 +00:00
},
2022-05-09 00:13:23 +00:00
"outputs": [],
2022-05-07 02:27:06 +00:00
"source": [
2022-05-08 12:55:48 +00:00
"#@title Picture Viewer\n",
"#@title Configuration\n",
"class formatting:\n",
" clear = '\\033[0m'\n",
" class color: \n",
" purple = '\\033[95m'\n",
" cyan = '\\033[96m'\n",
" cyan_dark = '\\033[36m'\n",
" blue = '\\033[94m'\n",
" green = '\\033[92m'\n",
" yellow = '\\033[93m'\n",
" red = '\\033[91m'\n",
" class font:\n",
" bold = '\\033[1m'\n",
" underline = '\\033[4m'\n",
"\n",
"## Define screen functions. \n",
"def clear(): from IPython.display import clear_output; return clear_output()\n",
"\n",
"class fileViewer: \n",
" image_fileName = '' #@param {type: \"string\"}\n",
2022-05-09 00:13:23 +00:00
" image_fileName = image_fileName.strip()\n",
2022-05-08 12:55:48 +00:00
"\n",
"def fixFormatImage(): \n",
" ## Give file format of png if the user didn't give any. Of course they should put it. \n",
2022-05-08 13:08:26 +00:00
" if getExtension(fileViewer.image_fileName) == None: fileViewer.image_fileName = (str(fileViewer.image_fileName) + '.png')\n",
2022-05-08 12:55:48 +00:00
"\n",
"def preview(): \n",
" clear()\n",
" try: \n",
" from IPython.display import Image\n",
" Image(filename=fileViewer.image_fileName)\n",
" except:\n",
" info.err(formatting.font.bold + 'Could not preview the image. ' + formatting.clear + 'Make sure that the file is present and that the file format is correct.')\n",
"\n",
"def main(): \n",
2022-05-09 00:13:23 +00:00
" if fileViewer.image_fileName: fixFormatImage(); preview()\n",
" else: clear()\n",
2022-05-08 12:55:48 +00:00
"\n",
"main()"
2022-05-07 02:27:06 +00:00
]
},
2022-05-08 13:08:26 +00:00
{
"cell_type": "code",
"execution_count": null,
2022-05-09 00:13:23 +00:00
"metadata": {
"cellView": "form",
"id": "AjdMaDLYIuVk"
},
2022-05-08 13:08:26 +00:00
"outputs": [],
"source": [
"#@title Video Viewer\n",
"#@title Configuration\n",
"class formatting:\n",
" clear = '\\033[0m'\n",
" class color: \n",
" purple = '\\033[95m'\n",
" cyan = '\\033[96m'\n",
" cyan_dark = '\\033[36m'\n",
" blue = '\\033[94m'\n",
" green = '\\033[92m'\n",
" yellow = '\\033[93m'\n",
" red = '\\033[91m'\n",
" class font:\n",
" bold = '\\033[1m'\n",
" underline = '\\033[4m'\n",
"\n",
"## Define screen functions. \n",
"def clear(): from IPython.display import clear_output; return clear_output()\n",
"\n",
"class fileViewer: \n",
" video_fileName = '' #@param {type: \"string\"}\n",
2022-05-09 00:13:23 +00:00
" video_fileName = video_fileName.strip()\n",
2022-05-08 13:08:26 +00:00
"\n",
"def fixFormatVideo(): \n",
" ## Give file format of png if the user didn't give any. Of course they should put it. \n",
" if (getExtension(fileViewer.video_fileName) == None or getExtension(fileViewer.video_fileName) == ''): fileViewer.video_fileName = (str(fileViewer.video_fileName) + '.avi')\n",
"\n",
"def preview(): \n",
" clear()\n",
" try: \n",
" from IPython.display import Video\n",
" Video(fileViewer.video_fileName, embed=True)\n",
" except:\n",
" info.err(formatting.font.bold + 'Could not preview the video. ' + formatting.clear + 'Make sure that the file is present and that the file format is correct.')\n",
"\n",
"def main(): \n",
2022-05-09 00:13:23 +00:00
" if fileViewer.video_fileName: fixFormatVideo(); preview()\n",
" else: clear()\n",
2022-05-08 13:08:26 +00:00
"\n",
"main()"
]
2022-05-07 02:27:06 +00:00
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"name": "BlenderRender.ipynb",
2022-05-08 03:50:53 +00:00
"provenance": []
2022-05-07 02:27:06 +00:00
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 0
2022-05-09 00:13:23 +00:00
}