Mass feature update:

- added more user configurable options
- ensured that user can not render without configuring
- finally linked rendering
This commit is contained in:
Hansly Saw 2022-05-08 11:50:53 +08:00
parent bfb1fc3583
commit bdebfd3591

View file

@ -3,17 +3,6 @@
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "view-in-github"
},
"source": [
"[View in Colaboratory](https://colab.research.google.com/github/aniquetahir/Colaboratory/blob/master/BlenderRender.ipynb)"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "IK9lYTykdbtt"
},
"source": [
@ -27,8 +16,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "F5vZwPfYenN8"
},
"outputs": [],
@ -75,33 +62,45 @@
" \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; if not os.system('cat ' + str(what)): info.warning('File does not exist.'); 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 = False #@param [True, False]\n",
" #@markdown Run this cell to upload the Blender file. \n",
" if upload_new == True: blendFile = UploadBlendFile()\n",
" upload_new = 0 #@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",
"\n",
" if getExtension(blend_fileName) != '.blend': blend_fileName = (str(blend_fileName) + '.blend')\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"
" 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": 2,
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 293
},
"colab_type": "code",
"id": "8szOTQ7TTgNm",
"outputId": "1800f449-7495-4b7f-acea-72ab19720fc3"
},
@ -145,25 +144,20 @@
" bold = '\\033[1m'\n",
" underline = '\\033[4m'\n",
"\n",
"## Define screen functions. \n",
"def clear(): \n",
" from IPython.display import clear_output; return clear_output()\n",
"\n",
"class info: # screen messages\n",
" def status(message):\n",
" print(formatting.font.bold + 'Status: \\t' + formatting.clear + message)\n",
" def err(message):\n",
" print(formatting.font.bold + formatting.color.red + 'Error: \\t' + formatting.clear + formatting.clear + message)\n",
" def warning(message):\n",
" print(formatting.font.bold + formatting.color.yellow + 'Warning: \\t' + formatting.clear + formatting.clear + message)\n",
" def success(message):\n",
" print(formatting.font.bold + formatting.color.green + 'Success: \\t' + formatting.clear + formatting.clear + message)\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:\n",
" from google.colab import files\n",
" except:\n",
" raise TypeError(\"No! Please run this in \" + formatting.font.bold + 'Google CoLab' + formatting.clear + '. ')\n",
"def check_prevRun(): # 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",
" return True\n",
"\n",
"def install(what, isCritical = False):\n",
" if what == \"required\":\n",
@ -183,23 +177,50 @@
" else: \n",
" os.system('apt clean && apt autoremove -y')\n",
" info.success('Installed '+ what + '.')\n",
" clear()\n",
"\n",
"def render(): \n",
" def confirmUserWantsNoValidUpload(): # 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",
"\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",
"def main():\n",
" check_compatibility()\n",
" install(\"required\")\n",
" check_prevRun();\n",
" install(\"required\");\n",
" start_render();\n",
"\n",
"main()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 8614
},
"colab_type": "code",
"id": "Hk2D1RK3WqVV",
"outputId": "88afd501-be4c-46ef-8162-cde3e88b7fae"
},
@ -679,21 +700,19 @@
}
],
"source": [
"# Command line arguments from here: https://urlzs.com/MiUkt\n",
"# Some explanation here: https://urlzs.com/au5z7\n",
"\n",
"!blender -b $filename -noaudio -o ./test_ -E $renderer -x 1"
"\n",
"!blender -b $filename -o ./test_ -E $renderer -x 1"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 557
},
"colab_type": "code",
"id": "ilwDQe4gb3O5",
"outputId": "8d38304b-87c8-4887-94ae-8104865d8148"
},
@ -721,21 +740,19 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "Kvv_WzdIf1CA"
},
"outputs": [],
"source": []
"source": [
""
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"include_colab_link": true,
"name": "BlenderRender.ipynb",
"provenance": [],
"version": "0.3.2"
"provenance": []
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
@ -749,4 +766,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}