Notifications
Clear all
[Closed] Rotate intersecting trees
Dec 08, 2009 4:51 pm
This is my first undertaking with maxscript, and I’m in over my head. I’m converting a scene for a game which has ~17k trees (2 plane objects). The problem is that the game’s engine doesn’t handle intersecting trees very well and I get flickering and other z-buffer issues. I mashed together a script that compares two trees and if they collide it rotates one of them on the x-axis. (not very useful when you have this many trees)
fn SetRotation obj rx ry rz =
(
local translateMat = transMatrix obj.transform.pos
local scaleMat = scaleMatrix obj.transform.scale
obj.transform = scaleMat * translateMat
rotate obj (angleaxis rx [1,0,0])
rotate obj (angleaxis ry [0,1,0])
rotate obj (angleaxis rz
[0,0,1])
)
------------------------------------------------------
objs = selection as array
for i = 1 to objs.count do
(
for j = i+1 to objs.count do
(
if (intersects objs[i] objs[j]) then
SetRotation objs[i] 30 0 0
)
)
Is there a way to make something like this work if I multiple objects are selected? What I mean is, if I select say 1000 trees, have the script find the colliding trees and then rotate them?
Thanks for helping out a noob.
1 Reply
Dec 08, 2009 4:51 pm
hmm… Maybe you should try this way around
for geo in selection do
(
for me in selection where (me != geo) do
(
if ((intersects geo me ) == true) then
(
geo.position = [0,0,0] --Write your action here
)
)
)