Notifications
Clear all

[Closed] Explosion of sphere

Hi all,

I was hoping someone my be able to help me. I am currently studying Computer Animation and on of my assignments is to write some MaxScript which will explode an object. I have completed the following code and for what I can see there is nothing wrong with it. I am fairly new at MaxScript so any help would be appreicated greatly. The code I have written is below:

mysphere=sphere()

select mysphere
max backface

mysphereconvert=converttopoly mysphere
mysphereconvert.numverts
mysphereconvert.numfaces

facearray=#()
trajectory=#()

for i=1 to mysphereconvert.numfaces do

([indent]facearray[i]=“nsphere”+i as string

polyop.detachfaces mysphereconvert #none asnode:true name:“facearray[i]”
print facearray[i]

)

selectsphere=$nsphere* as array

for i=1 to mysphereconvert.numfaces do

(append trajectory (polyop.getfacenormal selectsphere[i]1)

)

animateon

(for j=1 to 100 do

([indent]at time j

([indent]for i=1 to selectsphere.count do

([indent]select[i].pos=tracjectory[i]j5

)

[/indent])

[/indent])

[/indent])

[/indent]The error message I get when I run the script is:

– Argument count error: getFaceNormal wanted 2, got 1

I look forward to hearing from someone soon… TIA.

6 Replies

That is because you did not separate your arguments by a space

When I compile this script I get different errors

Looking over the code I can see numerous mistakes and inconsistent misspellings of variable names!

Thanks for your reply I have looked over the code and noticed these same inconsistencies. I have corrected them now but I wish to clarify one of your comments.

‘That is because you did not separate your arguments by a space’

I guess you mean a space after the [i] and before the ‘1’ like below:

append trajectory (polyop.getfacenormal selectsphere[i] 1)

I do appreicate your help / advice

yes, if you put a space betwen [i] and 1 it should work…
greetz TGM

Thank for the confirmation however it still has not worked I am getting another error message:
– Runtime error: EPoly operation on non-Editable Poly: undefined
Any idea on why this would be happening. As far as I can tell the error message is saying that the object (Sphere) is not an editable poly however I believe it is. My full code is shown below:

mysphere=sphere()
select mysphere
max backface
mysphereconvert=converttopoly mysphere
mysphereconvert.numverts
mysphereconvert.numfaces
facearray=#()
trajectory=#()

for i=1 to mysphereconvert.numfaces do
(
facearray[i]=“nsphere”+i as string
polyop.detachfaces mysphereconvert #none asnode:true name:“facearray[i]”
print facearray[i]
)
selectsphere=$nsphere* as array

for i=1 to mysphereconvert.numfaces do
(
append trajectory (polyop.getfacenormal selectsphere[i] 1)
)

animate on
(
for j=1 to 100 do
(
[indent]at time j
(
[indent]for i=1 to selectsphere.count do
(
[indent]select[i].pos=trajectory [i]j5
)
[/indent])
[/indent])
[/indent])

Hi!

You could probably simplfy your code greatly by using a mapped function:


   (
   -- Create sphere and convert to poly
   obj = sphere()
   convertToPoly obj
   -- Go through each face and detatch to element
   for f in (obj.faces as bitarray) do polyop.detachFaces obj f
   
   -- Mapped function will move each face in the object 100 units along it's normal
   mapped fn moveFace f =
   (
   	obj.selectedFaces = #{f}
   	fNormal = polyop.getFaceNormal obj f
   	fCenter = polyop.getFaceCenter obj f
   	move obj.selectedFaces (fCenter+(fNormal*100))
   )
   
   -- Set a key at frame 100 for all the faces in one go.  Send all the faces you want to move to the function as an array, in this case all of them.
   animate on at time 100 moveFace ((obj.faces as bitarray) as array)
   )
   

Hope that helps, good luck with your project!

Thanks for post, I know you said I could simplify my code like yours in the post however I really new at this coding and I can’t follow your code all that well. Is there any chance you could point me in the right direction regarding the code I posted. I need to know why it is coming up with the error as I can’t figure it out. I’ve tried looking in the help files, online and the forums are the only other resource I can think of.

Once again I appreciate your comments and I will look into your code and try and figure it out in my head if you know what I mean.