[Closed] Scatter
so ive built a pile of letters using scatter, but want to have something come in and fall in to the pile and push them away etc. Is there anyway i can do this using the scatter pile or do i have to start from scratch using reactor? also anyone know of a good way to achieve this using particle system ie. a pile of particles get pushed by another spray coming into them?
Do the papers need to be pushed away, or blown? If blown, I’d use a particle system, and setup a wind that goes off and blows the papers right when the object lands.
Overall, I’d probably use particles, or use what you have, but break the seperate papers into individual objects and then try using reactor on them.
- Neil
particle flow is a possibility but I don’t particularly like the way it handles node orientation and random rotations (oh and Directx materials), though you can steal some of it’s core methods…
maxsdk\samples\ParticleFlow\Actions\PFActions_GlobalFunctions.cpp
the helpful functions (among others) are
bool ClosestPointOnMesh(const Point3& toPoint, Mesh* mesh, Point3& worldLocation, Point2& localCoords, int& faceIndex, float& dist2)
bool IsPointInsideMesh(Mesh* mesh, Point3 p)
though c++ they pretty easy to port to mxs if you need to…
other approaches you could consider is using some kind of voxel ray thing with [color=white]RayMeshGridIntersect
[/color]as for avoiding collisions thats a tough one and potentially very slow. particle flow lets you set a min separation distance which is the most simple method available, which is fine with stuff like hair or grass as you will never be close enough to tell if things are slightly amiss.
Hi, there is an algorithm called stochastic search. You can use the simplest stochastic search to avoid collisions. After the code allocates positions you can write the part of the code that rotates your object. The following code allocates positions for boxes inside a user defined grid. For an arbitrary surface you have to write something more versatile, but the logic of the placement could still be useful. It is also recursive so be careful:
seed = 12345
myBoxes = #()
num = 20
tolerance = 1.0
for i in 1 to num do
(
myBoxes[i] = box width:2 height:2 length:2;
b = myBoxes[i];
b.name = "MyBox_" + i as string
sv = 0 -- safety valve to avoid infinite loops
range1 = 50--user defined range for the grid
range2 = 50 --user defined range for the grid
overlap = true -- examines weather a box overlaps with another
while overlap do
(
NewPosX = random -range1 range1 --get a random x position
NewPosY = random -range2 range2 --get a random y postition
overlap = false
for j in 1 to i do --looping back to the objects already created
(
b.name = "MyBox_" + j as string
OldPosX = execute ("$'" + b.name +"'.pos.x") --get the x location of the previous
OldPosY = execute ("$'" + b.name +"'.pos.y") --get the y location of the previous
diffX = abs(NewPosX - OldPosX) as integer
diffY = abs(NewPosY - OldPosY) as integer
if (diffX < tolerance and diffY< tolerance) do overlap = true --tolerance for overlaping
)
if (overlap ==false) do --if there is no overlap
(
b.pos = [NewPosX, NewPosY, 0] --move the box created in the new position
)
sv = sv + 1 if sv>500 then break() -- after 500 tries break
)
)