[Closed] Mass (reactor) script
Hi
I will fragment an object and use reactor to simulate it
so it would be cool to have a script that can set the mass of a fragment
so a small fragment would get a small mass
and a big fragment would get a big mass
Sorry for my bad english
Ok, what you could do is get the volume of all the fragments (there is volume code in the maxScript reference) add them all together to get a total. Decide on a total mass and then for each fragment divide it’s volume by the total volume and multiply that by the total mass.
That should give you accurate results.
If you’d like actual code you need only ask
Thanks for the replay
Yeh that was my idea or something similar to that
If you could give me the code for that it would be so cool
Ok her is my code (not the real code only the idea)
mass_all = 1000 kg
do for i to allfragment // 20 fragments maybe so allfragment = 20
{
volume_all = volume.i + volume_all
}
do for i to allfragment
{
mass_x = ((mass_all * volume.i)/volume_all)
set mass_x to reactor mass for fragment.i
}
so i need the real maxcode for this
Sorry for the late reply, here is my code.
(
fn CalcVolume obj =
(
volume = 0.0
theMesh = snapshotasmesh obj
numFaces = theMesh.numfaces
for i = 1 to numFaces do
(
face = getFace theMesh i
v2 = getVert theMesh Face.z
v1 = getVert theMesh Face.y
v0 = getVert theMesh Face.x
dV = dot (cross (v1 - v0) (v2 - v0)) v0
Volume+= dV
)
delete theMesh
volume /= 6
volume
)
fn CalculateMasses totalMass =
(
local objs = $fragment* as array
local volumes = #()
local total = 0
for obj in objs do
(
vol = CalcVolume obj
append volumes vol
total += vol
)
local i = 1
for obj in objs do
(
setUserProp obj "mass" ((volumes[i]/total) * totalMass)
i+=1
)
)
CalculateMasses 1000
)
This works for me, so I hope it works for you
Hi,
There is also a replacement to the standard property editor called Rigid Body Pro with density capabilities.
Light
I downloaded your script, but didn’t know how to install it correctly. I tried to add it as a toolbar button, but when i clicked on it I got an error. Any help would be appreciated.
Ok I need to tweak the code a little bit
how can i make it that if the mass of an object is to small like maybe 0 or 0.0001 the script should delet this objects
i have the problem that reactor can`t handel very small objects
so i musst delet this
Ok, I haven’t tested this code and it isn’t as optimal as it could be, but it should work.
(
fn CalcVolume obj =
(
volume = 0.0
theMesh = snapshotasmesh obj
numFaces = theMesh.numfaces
for i = 1 to numFaces do
(
face = getFace theMesh i
v2 = getVert theMesh Face.z
v1 = getVert theMesh Face.y
v0 = getVert theMesh Face.x
dV = dot (cross (v1 - v0) (v2 - v0)) v0
Volume+= dV
)
delete theMesh
volume /= 6
volume
)
fn CalculateMasses totalMass minVolume =
(
local objs = $fragment* as array
local finObjs = #()
local delObjs = #()
local volumes = #()
local total = 0
for obj in objs do
(
vol = CalcVolume obj
if col > minVolume then
(
append volumes vol
append finObjs obj
total += vol
)
else
append delObjs obj
)
delete delObjs
local i = 1
for obj in finObjs do
(
setUserProp obj "mass" ((volumes[i]/total) * totalMass)
i+=1
)
)
CalculateMasses 1000 1
)