There may be methods that doesn't require aniamtion nodes, I will test that later. but here is what I thought at the most beginning and has been proven to be working:
Theory: using locations of particles as a guide for rigid body objects to set in their places. The intersection will be prevented by rigid body dynamics.
- Add a particle system to a mesh. (This mesh and particles system should not be rendered at the end, you can just emit hallo or none. Hide the whole thing is also an option)
- Uncheck gravity options so that generated particles don't fall with gravity.
- birth should all be at 1 frame.
- set source type to "volume". Change the velocity acoordingly (0, since the point is not to emit particles but keep them in the volume of mesh)
- Finish modeling your "particle object" (preferably a single object). It can be "donut" or whatever stuff, add a rigid body dynamics to that. (Preferrably, you should also add materials at this stage. For reasons, please see the end of this answer)
- go to animation nodes panel, the tree should look like this. The principle is stated in the theory. Caution, a check in "copy full object" is very important, It copies things such as modifier, physics and material. Each time you add additional thing to the original mesh, and you want to update it to the instancers, you have to do that again.
Up to this part this is basically done. There are several additional points to that.
- if you want to randomize rotation or scales, use "random euler" (for rotation) and ["random number" + "vector from value"] nodes (for scale). ("Scale" is a vector, you can also use "random vector" for random number in each X, Y and Z. But by using random number + vector from value, X,Y,Z are uniform and I think this is what's expected most of time)
Due to rigid body, objects will firstly being pushed apart with a high speed. To pull objects back, easiest way I think is to add a force field, and set the strength to as negative as -1000 or even higher. You will see the effect that pulls objects back.
Some issues to be cautious with. If you rechecked the "copy full objects" for whatever reasons, the originally instanced meshes won't actually disappear automatically (This is different from normal circumstances). you have to manually delete them. Since everything is generated within "AN collection", simply lock all other collection, and shift + A to delete all meshes in AN. Don't worry, as soon as AN updates, the expected meshes will be generated by the node tree again.
let me know if you have any question.
for more information about AN, please go to mannual: https://animation-nodes-manual.readthedocs.io/en/latest/