This is a mostly-vibe-coded add-on for Blender that allows for visualizing magnetic fields and simulating magnetic forces. It operates entirely off the assumption that the magnets in scenes are dipoles.
It is highly optimized (multicore) with CUDA support for performing parallel field line tracing on thousands of lines at once across hundreds of magnets.
What it is NOT is a system for doing real, practical physics simulation of true environments; you can use this to toy around and look at field lines (and it's plenty accurate for that) but it's not an engineering tool whatsoever.
You'll get the most out of this add-on if you have an nvidia GPU and install pycuda within your Blender python path, and you may need to build Bullet if you want to run the kinematic magnetic force simulations.
The long and short of it is that, with the add-on installed, you can:
- Select a Blender mesh object
- Go to Properties -> Physics and click "Magnetic Source"
- Pow! Now you can see the field lines.
Not enough magnet with one? Just add more (duplicate the object, or just add the magnetic properties to another magnet). Not enough field lines? There are a few ways to do it, but you can increase the global field line count by hitting N and popping open the "Magnetics" tab. You can also go under "Ring Settings" for any given magnet and adjust how the field line trace seeds spawn.
One of the goals I had in making this was to simulate a k=2 spherical Halbach array, which this did, but I had to add a lot of optimizations in order to make the line traces and field calculations actually run in a reasonable amount of time.
The long and short of it is that you'll want to install pycuda (assuming you have an nvidia GPU) but it must be done along Blender's python instance. I'll add some more detailed instructions on how to do that later.
The current add-on is split into three broad layers:
- Blender integration
- registration, UI panels, operators, handlers, and Blender data properties
- Solver
- Blender-independent math, source models, dipole field evaluation, and streamline tracing
- Visualization
- conversion of solver output into viewport draw batches
The intent is to keep Blender-specific concerns out of the solver as much as possible. That makes the core logic easier to test outside Blender and leaves room to accelerate the expensive parts later without rewriting the UI layer. The same separation should also preserve a path to future force/torque queries for moving magnetic bodies rather than only viewport drawing.
The field-line preview currently works like this:
- A Blender object is tagged as a magnet source.
- Scene and object properties are converted into
MagnetSourcerecords. - The preview builder creates seed points near the enabled poles of each source.
- North-side seeds trace with the field toward south-side sinks, while south-side seeds trace in reverse toward north-side sinks.
- The preview builder caches raw trace steps by stable logical trace ids when the sources and trace settings are compatible.
- Seed-count growth only appends the newly introduced traces, while seed-count reduction hides a prefix of the existing trace order instead of rebuilding the whole seed layout.
- Ring-cap changes or source-local seed-frame changes only retrace the traces whose seed positions actually moved.
- Sink changes reclip those cached raw traces and only request more steps when a previously blocked line can continue.
- The current visible polylines and flattened geometry are reused when the sink layout, seed layout, and max-step visibility state are still compatible.
- The viewport module converts that snapshot into a GPU line batch and draws it in the 3D View.
This is intentionally simple; there are no field calculations done at any points other than where the line traces go, and only when those traces go there.
A Bullet physics-based kinematics simulation is here, and it is used instead of Blender's native rigid-body physics largely because Blender doesn't have a nice way of doing multi-force physics simulations (you can't just "inject force" apparently).
If you have Bullet physics in place, then you should be able to trigger basic physics simulations by:
- Pressing N, then going to Magnetics, then under Magnetic Simulation, check Enable Magnetic Simulation.
- Going to each of the magnet objects you have, then checking "Simulate Body".
- Tuning the various parameters as needed (dipole moment, mass, etc)
It's getting close to the point where fluid interactions can be there too, but not just yet.


