Skip to content

New shape to load 3D objects#159

Merged
JonathanMaes merged 18 commits into
devfrom
feature/obj-shape
Jun 5, 2026
Merged

New shape to load 3D objects#159
JonathanMaes merged 18 commits into
devfrom
feature/obj-shape

Conversation

@JonathanMaes
Copy link
Copy Markdown
Contributor

@JonathanMaes JonathanMaes commented Jun 5, 2026

This PR adds a new Shape, which can load a 3D object from STL, PLY, OBJ or GLTF/GLB files.
This ObjShape takes quite a few arguments:

  • The name of the file to be loaded
  • Exactly 2 of the following parameters to define the object's bounding box: min_point, max_point, center, scale and size. The last two of these parameters are mutually exclusive.
  • Optional:
    • keep_aspect (default False): expand to the bounding box defined by the previous parameters without distortion.
    • repair (default False): try to make the shape watertight if it is not. A simply-connected object is assumed.
    • rotate_z_up (default True): most 3D objects use the y-axis as the vertical direction, while in mumax this is the z-axis.

Example: magnetization of a teapot

from mumaxplus import Ferromagnet, World, Grid
from mumaxplus.util import show_field_3D, ObjShape

N, L = 64, 512e-9
shape = ObjShape("teapot.obj", (0, 0, 0), size=(L, L, L), keep_aspect=True, rotate_z_up=True)
world = World(cellsize=(L/N, L/N, L/N))
magnet = Ferromagnet(world, Grid((N, N, N)), geometry=shape)
magnet.msat = 800e3
magnet.aex = 13e-12
magnet.relax()
show_field_3D(magnet.magnetization, enable_quiver=False)
image

Other changes

  • Renamed the 'show' optional dependency group to '3D' and added trimesh and networkx to it. These optional dependencies should therefore now be installable alongside mumax⁺ with pip install mumaxplus[3D]
  • Initializing a geometry now uses the shape_func directly if it is already vectorized, otherwise it falls back to _np.vectorize like before
  • Added this shape to examples/shape.ipynb, where the quintessential teapot is loaded
  • Fixed formatting in Torus and repeat documentation

Comment thread mumaxplus/magnet.py
Comment thread examples/shape.ipynb
Comment thread mumaxplus/util/shape.py
Comment thread mumaxplus/util/shape.py Outdated
Comment thread mumaxplus/util/shape.py Outdated
Comment thread mumaxplus/util/shape.py
Comment thread mumaxplus/util/shape.py Outdated
Comment thread mumaxplus/util/shape.py
Copy link
Copy Markdown
Contributor

@DiegoDeGusem DiegoDeGusem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
Image

@JonathanMaes JonathanMaes requested a review from ilateur June 5, 2026 13:42
@JonathanMaes JonathanMaes merged commit d344b29 into dev Jun 5, 2026
@JonathanMaes JonathanMaes deleted the feature/obj-shape branch June 5, 2026 13:47
@ilateur ilateur mentioned this pull request Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants