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", "cell_type": "markdown",
"metadata": { "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" "id": "IK9lYTykdbtt"
}, },
"source": [ "source": [
@ -27,8 +16,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"colab": {},
"colab_type": "code",
"id": "F5vZwPfYenN8" "id": "F5vZwPfYenN8"
}, },
"outputs": [], "outputs": [],
@ -75,33 +62,45 @@
" \n", " \n",
" return uploaded_file\n", " return uploaded_file\n",
"\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", "\n",
"class configuration: \n", "class configuration: \n",
" #@markdown ### Input\n", " #@markdown ### Input\n",
" \n", " \n",
" upload_new = False #@param [True, False]\n", " upload_new = 0 #@param {type:\"slider\", min:0, max:1, step:1}\n",
" #@markdown Run this cell to upload the Blender file. \n", " if upload_new == True: UploadBlendFile()\n",
" if upload_new == True: blendFile = UploadBlendFile()\n",
"\n", "\n",
" # user preferred file name\n",
" blend_fileName = '' #@param {type: \"string\"}\n", " blend_fileName = '' #@param {type: \"string\"}\n",
"\n", " if getExtension(blend_fileName) != '.blend': blend_fileName = (str(blend_fileName) + '.blend'); checkValidUpload(blend_fileName)\n",
" if getExtension(blend_fileName) != '.blend': blend_fileName = (str(blend_fileName) + '.blend')\n",
"\n", "\n",
" #@markdown ### Processing\n", " #@markdown ### Processing\n",
" renderer = \"CYCLES\" #@param [\"CYCLES\", \"BLENDER_EEVEE\", \"BLENDER_WORKBENCH\"]\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_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", "cell_type": "code",
"execution_count": 2, "execution_count": null,
"metadata": { "metadata": {
"colab": { "colab": {
"base_uri": "https://localhost:8080/", "base_uri": "https://localhost:8080/",
"height": 293 "height": 293
}, },
"colab_type": "code",
"id": "8szOTQ7TTgNm", "id": "8szOTQ7TTgNm",
"outputId": "1800f449-7495-4b7f-acea-72ab19720fc3" "outputId": "1800f449-7495-4b7f-acea-72ab19720fc3"
}, },
@ -145,25 +144,20 @@
" bold = '\\033[1m'\n", " bold = '\\033[1m'\n",
" underline = '\\033[4m'\n", " underline = '\\033[4m'\n",
"\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", "class info: # screen messages\n",
" def status(message):\n", " def status(message): print(formatting.font.bold + 'Status: \\t' + formatting.clear + message)\n",
" 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 err(message):\n", " def warning(message): print(formatting.font.bold + formatting.color.yellow + 'Warning: \\t' + formatting.clear + formatting.clear + message)\n",
" print(formatting.font.bold + formatting.color.red + 'Error: \\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",
" 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",
"\n", "\n",
"def check_compatibility(): \n", "def check_prevRun(): # Make sure that the user has run the previous cell. \n",
" try:\n", " try: \n",
" from google.colab import files\n", " clear()\n",
" except:\n", " except: \n",
" raise TypeError(\"No! Please run this in \" + formatting.font.bold + 'Google CoLab' + formatting.clear + '. ')\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", "\n",
"def install(what, isCritical = False):\n", "def install(what, isCritical = False):\n",
" if what == \"required\":\n", " if what == \"required\":\n",
@ -183,23 +177,50 @@
" else: \n", " else: \n",
" os.system('apt clean && apt autoremove -y')\n", " os.system('apt clean && apt autoremove -y')\n",
" info.success('Installed '+ what + '.')\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", "\n",
"def main():\n", "def main():\n",
" check_compatibility()\n", " check_prevRun();\n",
" install(\"required\")\n", " install(\"required\");\n",
" start_render();\n",
"\n", "\n",
"main()" "main()"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": null,
"metadata": { "metadata": {
"colab": { "colab": {
"base_uri": "https://localhost:8080/", "base_uri": "https://localhost:8080/",
"height": 8614 "height": 8614
}, },
"colab_type": "code",
"id": "Hk2D1RK3WqVV", "id": "Hk2D1RK3WqVV",
"outputId": "88afd501-be4c-46ef-8162-cde3e88b7fae" "outputId": "88afd501-be4c-46ef-8162-cde3e88b7fae"
}, },
@ -679,21 +700,19 @@
} }
], ],
"source": [ "source": [
"# Command line arguments from here: https://urlzs.com/MiUkt\n",
"# Some explanation here: https://urlzs.com/au5z7\n",
"\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", "cell_type": "code",
"execution_count": 8, "execution_count": null,
"metadata": { "metadata": {
"colab": { "colab": {
"base_uri": "https://localhost:8080/", "base_uri": "https://localhost:8080/",
"height": 557 "height": 557
}, },
"colab_type": "code",
"id": "ilwDQe4gb3O5", "id": "ilwDQe4gb3O5",
"outputId": "8d38304b-87c8-4887-94ae-8104865d8148" "outputId": "8d38304b-87c8-4887-94ae-8104865d8148"
}, },
@ -721,21 +740,19 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"colab": {},
"colab_type": "code",
"id": "Kvv_WzdIf1CA" "id": "Kvv_WzdIf1CA"
}, },
"outputs": [], "outputs": [],
"source": [] "source": [
""
]
} }
], ],
"metadata": { "metadata": {
"accelerator": "GPU", "accelerator": "GPU",
"colab": { "colab": {
"include_colab_link": true,
"name": "BlenderRender.ipynb", "name": "BlenderRender.ipynb",
"provenance": [], "provenance": []
"version": "0.3.2"
}, },
"kernelspec": { "kernelspec": {
"display_name": "Python 3 (ipykernel)", "display_name": "Python 3 (ipykernel)",