Skip to content

Commit

Permalink
Merge pull request #175 from floesche/issue_174
Browse files Browse the repository at this point in the history
Issue 174
  • Loading branch information
schlegelp authored Dec 15, 2024
2 parents 6626109 + 196a3cd commit aba1df1
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 46 deletions.
78 changes: 43 additions & 35 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,47 @@ jobs:
# igraph: ["igraph", "no-igraph"]
steps:
# This cancels any such job that is still runnning
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Linux libraries
run: |
sudo apt-get update -y -qq
sudo apt-get install -y libdbus-1-3 libxkbcommon-x11-0 libxcb-icccm4 \
libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 \
libxcb-xinerama0 libxcb-xinput0 libxcb-xfixes0 graphviz graphviz-dev \
mesa-vulkan-drivers
- name: Install dependencies
run: |
pip install --upgrade pip
pip install zstandard==0.16.0
pip install numpy
pip install flybrains --no-deps
pip install git+https://github.com/siavashk/pycpd@master
pip install pyarrow
- name: Install navis
run: pip install -e .[dev,all]
# - run: pip install python-igraph
# if: ${{ matrix.igraph == 'igraph' }}
- name: Report dependency versions
run: pip freeze -r requirements.txt
- name: Test
uses: coactions/setup-xvfb@v1
with:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up Blender
run: |
export NAVIS_HEADLESS=TRUE
pytest --verbose
pwd
wget -qO- https://mirrors.iu13.net/blender/release/Blender4.2/blender-4.2.4-linux-x64.tar.xz | tar xJ
mv blender-4.2.4-linux-x64 ../
echo "PATH=../blender-4.2.4-linux-x64/:$PATH" >> $GITHUB_ENV
- name: Install Linux libraries
run: |
sudo apt-get update -y -qq
sudo apt-get install -y libdbus-1-3 libxkbcommon-x11-0 libxcb-icccm4 \
libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 \
libxcb-xinerama0 libxcb-xinput0 libxcb-xfixes0 graphviz graphviz-dev \
mesa-vulkan-drivers
- name: Install dependencies
run: |
pip install --upgrade pip
pip install zstandard==0.16.0
pip install numpy
pip install flybrains --no-deps
pip install git+https://github.com/siavashk/pycpd@master
pip install pyarrow
- name: Install navis
run: pip install -e .[dev,all]
# - run: pip install python-igraph
# if: ${{ matrix.igraph == 'igraph' }}
- name: Report dependency versions
run: |
which blender
pip freeze -r requirements.txt
- name: Test
uses: coactions/setup-xvfb@v1
with:
run: |
export NAVIS_HEADLESS=TRUE
pytest --verbose
10 changes: 10 additions & 0 deletions navis/meshes/b3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ def simplify_mesh_blender(x, F, inplace=False):
simp
Simplified mesh object.
Examples
--------
>>> import navis
>>> n = navis.example_neurons(1, kind="mesh")
>>> n_sm = simplify_mesh_blender(n,
... F=0.2,
... inplace=False)
>>> n.n_vertices > n_sm.n_vertices
True
"""
if not tm.interfaces.blender.exists:
raise ModuleNotFoundError('No Blender 3D unavailable (executable not found).')
Expand Down
34 changes: 23 additions & 11 deletions navis/meshes/templates/blender_decimate.py.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,29 @@ import os
if __name__ == '__main__':
# clear scene of default box
bpy.ops.wm.read_homefile()
try:
bpy.ops.object.mode_set(mode='OBJECT')
except BaseException:
pass
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=True)
if bpy.app.version > (3, 2, 0):
objs = [bpy.context.scene.objects['Camera'], bpy.context.scene.objects['Cube'], bpy.context.scene.objects['Light']]
with bpy.context.temp_override(selected_objects=objs):
bpy.ops.object.delete()
else:
try:
bpy.ops.object.mode_set(mode='OBJECT')
except BaseException:
pass
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=True)

# get temporary files from templated locations
mesh_pre = $MESH_PRE
mesh_post = os.path.abspath(r'$MESH_POST')

for filename in mesh_pre: # use data.objects instead of context.scene.objects
bpy.ops.import_mesh.stl(filepath=os.path.abspath(filename))

if bpy.app.version > (4, 0, 0):
bpy.ops.wm.stl_import(filepath=os.path.abspath(filename))
else:
bpy.ops.import_mesh.stl(filepath=os.path.abspath(filename))
mesh = bpy.data.objects[0]

# Make sure mesh is the active object
try:
# earlier than blender <2.8
Expand All @@ -29,13 +37,17 @@ if __name__ == '__main__':
bpy.context.view_layer.objects.active = mesh

# add decimate modifier

mod = mesh.modifiers.new('decimate', 'DECIMATE')
mod.decimate_type = 'COLLAPSE'
mod.ratio = $RATIO
mod.use_collapse_triangulate = True

bpy.ops.object.modifier_apply(modifier=mod.name)

bpy.ops.export_mesh.stl(
filepath=mesh_post,
use_mesh_modifiers=True)
if bpy.app.version > (4, 0, 0):
bpy.ops.wm.stl_export(filepath=mesh_post, apply_modifiers=True)
else:
bpy.ops.export_mesh.stl(
filepath=mesh_post,
use_mesh_modifiers=True)

0 comments on commit aba1df1

Please sign in to comment.