PDA

View Full Version : Explosion of sphere


hollingd
03-14-2006, 09:47 PM
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


(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



(at time j



(for i=1 to selectsphere.count do



(select[i].pos=tracjectory[i]*j*5


)


)


)


)


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.

stuh505
03-15-2006, 02:11 AM
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!

hollingd
03-15-2006, 10:00 AM
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

TheGameMaker
03-15-2006, 04:59 PM
yes, if you put a space betwen [i] and 1 it should work....
greetz TGM

hollingd
03-15-2006, 06:14 PM
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
(
at time j
(
for i=1 to selectsphere.count do
(
select[i].pos=trajectory [i]*j*5
)
)
)
)

Moosley
03-15-2006, 09:00 PM
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!

hollingd
03-15-2006, 10:09 PM
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.

CGTalk Moderation
03-15-2006, 10:09 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.