Skip to content

Commit

Permalink
Moved addons and added VSCode setting and app launcher scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-yao91 committed Jul 11, 2024
1 parent 2a1df4d commit 0b375cf
Show file tree
Hide file tree
Showing 127 changed files with 614 additions and 84 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# GITHUB_USERNAME=
# GITHUB_TOKEN=
# BLENDER_EXE_PATH=
# UNREAL_EXE_PATH=
# UNREAL_PROJECT_PATH=
2 changes: 1 addition & 1 deletion .github/workflows/re-use-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
source .venv/bin/activate
export GITHUB_TOKEN=${{ secrets.GH_PAT }}
export TEST_ENVIRONMENT=1
export DOCKER_ENVIRONMENT=yes
export UNREAL_VERSION=${{ inputs.unreal-version }}
export BLENDER_VERSION=${{ inputs.blender-version }}
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*~
*.swp
/venv/*
.vscode
release/*
venv
.env
Expand All @@ -17,8 +16,6 @@ results
release
site
scratches
scripts/resources
launch.py
tests/test_files/data
tests/test_files/unreal_projects/**/DefaultInput.ini
tests/test_files/blender_files/textures
96 changes: 96 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"configurations": [
{
"name": "Run Active Python File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"envFile": "${workspaceFolder}/.env",
"justMyCode": false
},
{
"name": "Python Debugger: Attach Blender",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
}
},
{
"name": "Python Debugger: Attach Unreal",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5679
}
},
{
"name": "Run All Tests",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/tests/run_tests.py",
"console": "integratedTerminal",
"envFile": "${workspaceFolder}/.env",
"cwd": "${workspaceFolder}/tests",
"justMyCode": false,
"env": {
"DOCKER_ENVIRONMENT": "${input:docker-environment}"
}
},
{
"name": "Run Specific Tests",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/tests/run_tests.py",
"console": "integratedTerminal",
"envFile": "${workspaceFolder}/.env",
"cwd": "${workspaceFolder}/tests",
"justMyCode": false,
"env": {
"EXCLUSIVE_TEST_FILES": "${input:test-file}",
"EXCLUSIVE_TESTS": "${input:test-name}",
"DOCKER_ENVIRONMENT": "${input:docker-environment}"
}
},
],
"inputs": [
{
"id": "test-file",
"type": "pickString",
"default": "test_send2ue_core.py",
"options": [
"test_send2ue_core.py",
"test_send2ue_cubes.py",
"test_send2ue_extension_affixes.py",
"test_send2ue_extension_combine_assets.py",
"test_send2ue_extension_create_post_import_assets_for_groom.py",
"test_send2ue_extension_example.py",
"test_send2ue_extension_instance_assets.py",
"test_send2ue_extension_use_collections_as_folders.py",
"test_send2ue_extension_use_immediate_parent_name.py",
"test_send2ue_mannequins.py",
"test_ue2rigify_core.py",
"test_ue2rigify_mannequins.py"
],
"description": "Which test file to run"
},
{
"id": "docker-environment",
"type": "pickString",
"default": "",
"options": [
"no",
"yes"
],
"description": "Run in docker environment?"
},
{
"id": "test-name",
"type": "promptString",
"description": "The name of the specific test to run"
}
]
}
2 changes: 2 additions & 0 deletions .vscode/python.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PYTHONPATH=';./.venv/Lib/site-packages'
PYTHONUNBUFFERED=1
82 changes: 82 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"files.eol": "\n",
"python.pythonPath": "${workspaceFolder}/.venv/Lib/site-packages",
"python.terminal.activateEnvironment": true,
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/Scripts/python.exe",
"python.envFile": "${workspaceFolder}/.vscode/python.env",
"python.analysis.typeCheckingMode": "basic",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.languageServer": "Pylance",
"editor.tabCompletion": "on",
// "python.analysis.disabled": ["unresolved-import"],
"python.autoComplete.extraPaths": [
"${workspaceFolder}/admin/packages"
],
"python.analysis.extraPaths": [
"${workspaceFolder}/admin/packages"
],
"cSpell.ignorePaths": [
"${workspaceFolder}/.venv",
"${workspaceFolder}/.linux-venv",
"${workspaceFolder}/.py3.10-venv",
"${workspaceFolder}/.unreal-venv",
"${workspaceFolder}/build",
"${workspaceFolder}/scratches",
"${workspaceFolder}/reports"
],
"cSpell.words": [
"autoexec",
"compileshaders",
"debugpy",
"dotenv",
"epicgames",
"everytime",
"eyeshell",
"fcurve",
"fcurves",
"fontawesome",
"forcelogflush",
"idname",
"inlinehilite",
"kwargs",
"levelno",
"linenums",
"LODS",
"mathutils",
"mikepenz",
"Mkdocs",
"mklink",
"noloadstartuppackages",
"nopause",
"nosplash",
"nullrhi",
"nytimes",
"outliner",
"POLYHAMMER",
"pygments",
"Pylance",
"pymdownx",
"pytest",
"PYTHONUNBUFFERED",
"quickstart",
"retarget",
"retargeting",
"Rigify",
"runas",
"skincache",
"staticmethod",
"superfences",
"teleporting",
"termynal",
"TOPBAR",
"Unregisters",
"uproject",
"venv"
],
"editor.rulers": [
80,
120
],
"jupyter.notebookFileRoot": "${workspaceFolder}"
}
90 changes: 90 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"label": "launch blender",
"command": "python ${workspaceFolder}/scripts/launch.py blender ${input:blender-version} ${input:blender-debug}",
"type": "shell",
"group": {
"kind": "build"
},
"presentation": {
"reveal": "always",
"panel": "shared",
"focus": true
}
},
{
"label": "launch unreal",
"command": "python ${workspaceFolder}/scripts/launch.py unreal ${input:unreal-version} ${input:unreal-debug}",
"type": "shell",
"group": {
"kind": "build"
},
"presentation": {
"reveal": "always",
"panel": "shared",
"focus": true
}
},
{
"label": "Serve Docs",
"command": "mkdocs serve",
"type": "shell",
"group": {
"kind": "build"
},
"presentation": {
"reveal": "always",
"panel": "shared",
"focus": true
}
}
],
"inputs": [
{
"id": "blender-version",
"type": "pickString",
"default": "4.1",
"options": [
"3.6",
"4.0",
"4.1",
"4.2",
],
"description": "What blender version to launch"
},
{
"id": "blender-debug",
"type": "pickString",
"default": "no",
"options": [
"no",
"yes"
],
"description": "Should use debugger?"
},
{
"id": "unreal-version",
"type": "pickString",
"default": "5.4",
"options": [
"5.3",
"5.4"
],
"description": "What unreal version to launch"
},
{
"id": "unreal-debug",
"type": "pickString",
"default": "no",
"options": [
"no",
"yes"
],
"description": "Should use debugger?"
}
]
}
67 changes: 30 additions & 37 deletions docs/contributing/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,56 +32,49 @@ cd BlenderTools
git checkout some-task-branch
```

## Testing your changes
## VSCode
The repo contains the tasks, launch actions, and settings for for developing with vscode. To get setup do the following:

### Setup
1. Install the VSCode profile under `scripts/resources/profiles/dev.code-profile`. You can do this by typing `> Profile Import Profile` in the command pallette. This will give you all the vscode extensions you will need.
1. Close and re-open VSCode
1. Type `> Python: Create Environment`, hit enter and chose `Venv` and choose your Python 3.11 installation, then check the box to install the `requirements.txt`
1. Close and re-open your integrated terminal in vscode and ensure that you now have a `(.venv)` prefixing your shell. If you do, you are all setup and ready to go!

### Build Tasks
The VSCode project has build tasks for launch your apps. It is highly recommended that you launch blender and unreal through these, since they will ensure you have the dev dependencies in your python environment for reloading code and debugging. To do this move your cursor over the integrate terminal and press the hot keys `CTRL+SHIFT+B`.

![2.1](./images/development/2.1.gif)

!!! note
If you choose yes to debug, the app will hang until you attach to it via debugpy in VSCode. (See Launch Actions)

!!! note
The launch scripts look for the unreal and blender executables in their default locations. You can override the exe paths by setting
the `UNREAL_EXE_PATH`and `BLENDER_EXE_PATH` variables in a `.env` file in the repo root.

### Launch Actions
Several launch actions have been created for debugging. Use the `Python Debugger: Attach Blender` or `Python Debugger: Attach Unreal` to attach to the apps after they have been launched from the build tasks and have logged that they are waiting for the debugger to attach. There are also a few other debug configurations for the test cases as well.

![2.2](./images/development/2.2.png)

## Reloading your changes
While developing, you will want to be able to rapidly test your new changes. You can do this by running this script in
the Blender Script Editor.

!!! note

You need to change `<your-repo-location>` to match the absolute path to the scripts folder in your local project. Running this script installs and reloads the tool.
If your didn't launch from VSCode, You need to change `<your-repo-location>` to match the absolute path to the scripts folder in your local project. Running this script reloads the addon code.


```python
import bpy
import sys
sys.path.append(r'C:\<your-repo-location>\BlenderTools\scripts')
import dev_helpers

addons = ['send2ue', 'ue2rigify']

# installs the actual addons zips
#dev_helpers.reload_addon_zips(addons)

# reloads the code from your repo. A lot faster but doesn't load addon preferences
dev_helpers.reload_addon_source_code(addons)

# start blender and unreal rpc server for automated testing
#bpy.ops.send2ue.start_rpc_servers()
dev_helpers.reload_addon_source_code(['send2ue', 'ue2rigify'])
```

In most cases you can get away with running `dev_helpers.reload_addon_source_code`, which reloads very fast and any
stack traces get linked back to the repo code.

However, the true test is running `dev_helpers.reload_addon_zips` this actually zips up the code and installs the
addons. You will need to do this if you are testing features that rely on properties in the addon preferences.

`bpy.ops.send2ue.start_rpc_servers()` Ensures that both unreal and blender rpc servers are running. This is needed if
you want to run the unittests on the open app instances.

## Hot reloading from PyCharm
These steps must be completed in-order for the addons to hot-reload while you type in PyCharm.
1. If you have the addons already installed, uninstall them and shutdown Blender and PyCharm.
1. You must symlink the addon folders into the blender addon installation location. Then enable the addons

!!! Windows
Run this from a commandline launched as administrator. Swapping out the last path with your own.
```shell
mklink /D "%APPDATA%\Blender Foundation\Blender\3.6\scripts\addons\send2ue" "D:\repos\BlenderTools\send2ue"
```

1. You must install the `./scripts/addon-watcher.xml` in Pycharm by going to `Settings > Tools > File Watchers > Import`
1. And finally blender has to be running with the send2ue addon enabled and clicking `Pipeline > Utilities > Start RPC Servers`
Now PyCharm should reload your addons on file save events.
In most cases you can get away with running `dev_helpers.reload_addon_source_code`, which reloads your addon code without restarting blender.


## Code Structure
Expand Down
Binary file added docs/contributing/images/development/2.1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/contributing/images/development/2.2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0b375cf

Please sign in to comment.