Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update testing README #96

Merged
merged 9 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 44 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ git clone https://github.com/UCL/Blender_Randomiser.git
- This will zip the `randomiser` subdirectory, open the `sample.blend` file with Blender, and use Blender's Python interpreter to execute the `install_and_enable_addons.py` script.
- The `install_and_enable_addons.py` script installs and enables any add-ons that are passed as command line arguments (add-ons can be passed as a path to a single Python file, or as a zip file)

> [!NOTE] `source ~/.bash_profile` is used in the bash script to create an alias for blender with the following line in the bash_profile:
> [!NOTE]
> `source ~/.bash_profile` is used in the bash script to create an alias for blender with the following line in the bash_profile:
> `alias blender=/Applications/Blender.app/Contents/MacOS/Blender`

> **Advanced Usage**
**Advanced Usage**

> In step 3, run the [randomisation_seed.sh](/randomisation_seed.sh) bash script instead which has optional inputs:
> - `--seed 32` which is an input to Blender
> - `--input ./input_bounds.json` (input to `install_and_enable_addons.py`)
Expand All @@ -66,24 +68,46 @@ Alternatively, install [manually](/docs/Install_addon_manually.md) via Blender s


> [!NOTE]
> Only relevant if you are wanting to run the tests.
> The tests make use of the [pytest-blender plugin](https://github.com/mondeja/pytest-blender#pytest-blender), which has `pytest` and other packages as dependencies (e.g. `pytest-cov`). These need to be installed in the site-packages directory of Blender's Python. The pytest-blender repo provides some guidance for this [here](https://github.com/mondeja/pytest-blender#usage). It is important to make sure you use Blender's Python interpreter and Blender's pip when installing `pytest` and its dependencies. Below are some tips on how to do this in Linux and MacOS.

> **Linux**
> An easy way to install these dependencies correctly in Linux is to run the following code in [Blender's Python scripting window](https://docs.blender.org/api/current/info_quickstart.html):
> `import pip `
`pip.main(["install", "pytest", "--user"])`
`pip.main(["install", "pytest-cov", "--user"])`
`pip.main(["install", "pytest-blender", "--user"])`


> [!CAUTION]
> **MacOS**
> Installing Blender in an isolated environment may be preferable. We occasionally found some issues with the `pytest` installation for Blender, where it seemed that running pytest from a different environment would use the `pytest` installed in the Blender environment. To troubleshoot this, it may be useful to run `which pytest`from the active environment: if all is working fine, that should point to the `pytest` of the active environment. One can also force to run the `pytest` installation of the active environment by running `python -m pytest`.
> The following steps were needed to install these dependencies correctly on MacOS:
> - `get-pip.py` downloaded (this step may not be needed since newer versions of Blender have pip installed already in the Blender python)
> - Changing Mac permissions to grant full disk access from where you're running pytest i.e. VS code or terminal
> - `/Applications/Blender.app/Contents/Resources/3.4/python/bin/python3.10 -m pip install pytest -t "/Applications/Blender.app/Contents/Resources/3.4/python/lib/python3.10/site-packages"` the target flag -t makes sure that the installation ends up in the correct place
The tests make use of the [pytest-blender plugin](https://github.com/mondeja/pytest-blender#pytest-blender), which has `pytest` and other packages as dependencies (e.g. `pytest-cov`). These need to be installed in the site-packages directory of Blender's Python. The pytest-blender repo provides some guidance for this [here](https://github.com/mondeja/pytest-blender#usage). It is important to make sure you use Blender's Python interpreter and Blender's pip when installing `pytest` and its dependencies. Below are some tips on how to do this in Linux and MacOS.

**Installing Pytest in Python**

The following steps were needed to install these dependencies (tested in MacOS only):
```
# create and activate conda environment:
conda create -n blender-dev python=3.10 -y
conda activate blender-dev

# install pytest-blender:
pip install pytest-blender
pip install pytest-cov

# Get path to the Python interpreter that ships with Blender - this may take a long time:
blender_python="$(pytest-blender)"

# from the `Blender_Randomiser` directory, install the randomiser package with dev dependencies by running:
$blender_python -m pip install ".[dev]"

#Run pytest:
python -m pytest tests

## ~/.local/bin may need to be added to path
```

**Installing Pytest in Blender's Python**

An easy way to install these dependencies (tested in Linux only) is to run the following code in [Blender's Python scripting window](https://docs.blender.org/api/current/info_quickstart.html#running-scripts):
```
import pip
pip.main(["install", "pytest", "--user"])
pip.main(["install", "pytest-cov", "--user"])
pip.main(["install", "pytest-blender", "--user"])
```
ruaridhg marked this conversation as resolved.
Show resolved Hide resolved

Then outside of Blender, run the following command:
```
<path_to_blender_python> -m pytest --blender-executable <path-to-blender-executable>
```

## Contributions

Expand Down
4 changes: 4 additions & 0 deletions docs/Materials_geometry_panel.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Adding materials and geometry panels

Materials and geometry panels are added to the UI if the node to be randomised is renamed with a prefix of "random". The node is then added to the panel and the user can select the min and max values for the randomisation. The user can also select the nodes to be randomised and the output file will contain the parameters that have been randomised.

## Materials
![Materials_panel](/docs/images/Materials_panel.png)
- A panel to randomise properties relative to the material nodes:
Expand Down
2 changes: 2 additions & 0 deletions docs/input_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The input file is read into the [install_and_enable_addons.py script](/install_a
- "Values Geometry Nodes.001RandomSize.001"
- "Values MaterialRandomMetallic"

The node names that appear in the panels for geometry and materials nodes can be randomised and saved as in the output .json file. The names in this output file can then be used to specify the names of the geometry and materials nodes in the input file.

> [!NOTE]
> The install_and_enable_addons.py script could be extended in the future to use parameter names from the [output .json file](/output_randomisations_per_frame1697116725.310647.json) to specify the key names for geometry, materials and user-defined properties panels.

Expand Down
Loading