{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "IK9lYTykdbtt" }, "source": [ "

BlendererOnline

\n", "Uses some codes of BlenderRender by aniquetahir.\n", "\n", "

Render Blender files online, for free.

" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "F5vZwPfYenN8", "cellView": "form" }, "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", "def getExtension(fileName): \n", " import os\n", " fileName_split = os.path.splitext(fileName)\n", "\n", " return fileName_split[1].lower()\n", "\n", "def UploadBlendFile(): # Make sure that the file is actually a Blender file. \n", " check_compatibility()\n", "\n", " import pathlib; from google.colab import files\n", " uploaded_file = files.upload()\n", " \n", " return uploaded_file\n", "\n", "def checkValidUpload(what): # Make sure that the user has that file uploaded when specifying the name. \n", " 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", "\n", "def properlySetFrames(frame_start, frame_end): \n", " if frame_start == frame_end: return frame_end\n", " else: return False\n", "\n", "class configuration: \n", " #@markdown ### Input\n", " \n", " upload_new = 1 #@param {type:\"slider\", min:0, max:1, step:1}\n", " if upload_new == True: UploadBlendFile()\n", "\n", " # user preferred file name\n", " blend_fileName = '' #@param {type: \"string\"}\n", " 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", "\n", " #@markdown ### Processing\n", " renderer = \"CYCLES\" #@param [\"CYCLES\", \"BLENDER_EEVEE\", \"BLENDER_WORKBENCH\"]\n", " device = \"CPU\" #@param [\"CPU\", 'CUDA', 'OPTIX', 'HIP', 'METAL']\n", "\n", " #@markdown ### Animation\n", " frame_start = 1 #@param {type: \"number\"}\n", " 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" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "8szOTQ7TTgNm", "cellView": "form" }, "outputs": [], "source": [ "#@title Render\n", "\n", "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", " 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_fieldsFilled(): # Make sure that the user has run the previous cell. \n", " 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", " if configuration.blend_fileName == None: \n", " raise ImportError(formatting.font.bold + 'The file name for the Blender file is missing. ' + formatting.clear + 'It is a required field. ')\n", " else: \n", " return True\n", "\n", "def install(what, isCritical = False):\n", " if what == \"required\":\n", " install(\"blender\", True)\n", " install(\"libboost-all-dev\")\n", " install(\"libgl1-mesa-dev\")\n", " clear()\n", " 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", "\n", "def render(): \n", " def checkInvalidUploadProceed(): # Make sure user is sure that the file does exist. \n", " clear()\n", " if not(checkValidUpload(configuration.blend_fileName)): \n", " 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", " else: return True\n", "\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", " if not(configuration.frame): \n", " !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", "\n", " info.status('Render of file ' + configuration.blend_fileName + ' has completed.')\n", "\n", " if checkInvalidUploadProceed(): \n", " start_render()\n", "\n", "def main():\n", " check_fieldsFilled();\n", " install(\"required\");\n", " render();\n", "\n", "main()" ] }, { "cell_type": "markdown", "metadata": { "id": "bpxn20vTIuVi" }, "source": [ "

Utilities

" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "ilwDQe4gb3O5", "cellView": "form" }, "outputs": [], "source": [ "#@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", " image_fileName = image_fileName.strip()\n", "\n", "def fixFormatImage(): \n", " ## Give file format of png if the user didn't give any. Of course they should put it. \n", " if getExtension(fileViewer.image_fileName) == None: fileViewer.image_fileName = (str(fileViewer.image_fileName) + '.png')\n", "\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", " if fileViewer.image_fileName: fixFormatImage(); preview()\n", " else: clear()\n", "\n", "main()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "id": "AjdMaDLYIuVk" }, "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", " video_fileName = video_fileName.strip()\n", "\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", " if fileViewer.video_fileName: fixFormatVideo(); preview()\n", " else: clear()\n", "\n", "main()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "Kvv_WzdIf1CA" }, "outputs": [], "source": [ "" ] } ], "metadata": { "accelerator": "GPU", "colab": { "name": "BlenderRender.ipynb", "provenance": [] }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.10.4" } }, "nbformat": 4, "nbformat_minor": 0 }