[Closed] Simple Mod memory issue
Hi Guys and Gals,
I’m creating a simple modifier that twists my geometry. The eventual aim is to have the amount of twist at each point in the model be defined by a curve control.
I’m at proof of concept stage at the moment, but with a few lines of code I’m getting
>> MAXScript Scripted Plugin Handler Exception: – Runtime error: Out of scripter memory – use options to increase <<
I have a feeling that it may be something to do with the matrix transformations that transform the points. The basic gist is that each point on the geometry is rotated around the pivot point of the object, which creates the twist effect.
The question is – could/should I be doing this more efficiently?
It’s a real shame it’s not working, and I’m surprised I’ve got as far as I have. Any help would really be appreciated, as I have to get this plugin working for the project I’m about to work on.
Thanks so much,
Dave
plugin simpleMod twist2
name:"Twist 2"
classID:#(0xadd2234, 0x41d27996)
version:1
(
local mx
local iy
parameters main rollout:params
(
amount type:#integer ui:amtTwist default:20
)
rollout params "Parameters"
(
spinner amtTwist "Twist: " type:#integer range:[0,1000,20]
)
on map i p do
(
-- ratio of how far along geometry the point is
iy = p.y / extent.y
-- a matrix 3 for the point
mx = matrix3 [1,0,0] [0,1,0] [0,0,1] p
-- rotate the point
rotateY mx (amount * iy)
-- grab the rotated position
mx.translationPart
)
)
You could rotate the point without using matrices. That way the script will consume less memory:
plugin simpleMod twist2
name:"Twist 2"
classID:#(0xadd2234, 0x41d27996)
version:1
(
local misc = [0,0,0,0] -- x = iy; y = angle; z = cosb; w = sinb
local newPoint = [0,0,0]
parameters main rollout:params (
amount type:#integer ui:amtTwist default:20
)
rollout params "Parameters" (
spinner amtTwist "Twist: " type:#integer range:[-1000,1000,20]
)
on map i p do (
-- Ratio of how far along geometry the point is
misc.x = p.y / extent.y
-- Angle
misc.y = amount * misc.x
-- Cosine and sine
misc.z = cos misc.y
misc.w = sin misc.y
-- Rotate point around Y axis
newPoint.x = misc.z * p.x - misc.w * p.z
newPoint.y = p.y
newPoint.z = misc.w * p.x + misc.z * p.z
return newPoint
)
)
Hope that helps.
Hi Jonathon,
Yep – that’s what I did in the end:
val = amount * iy
p.x = cos(val) * x - sin(val) * z
p.z = cos(val) * z + sin(val) * x
And it works fine.
By the way – you don’t know how to store curve control data in scripted plugins do you!?
Cheers,
Dave
Do you mean using the curve control?.
I think there’s no flexible way to do that.
One possible way could be declare arrays for the parameters of the curve points. For example:
parameters main rollout:params (
cPointValues type:#point3Tab tabSizeVariable:true
cInOutTangents type:#point4Tab tabSizeVariable:true
cPointTypes type:#intTab tabSizeVariable:true
)
And each time a curve point is changed/added/deleted, modify those arrays. And then, when the rollout is opened, build the curve based on this arrays.
But I haven’t tried that so don’t know if it works.
Yup… been testing it and it’s looking good so far. I’ll post back when I’m done.
Thanks for the input,
Cheers,
Dave
One of the problems with the Curve Control that I have found is you can’t get information from it when it is not open. So if you are trying to get values from it along the curve you can’t unless you store the settings and do the calculations your self. That is what I had to resort to.
Interesting tool that you are writting here. I tried running it and it just crashed Max so I might not have added the new code that you posted correctly.
Hi Paul,
Well a day of coding yesterday and I reckon it’s done. However, SimpleMod seems to be so SLOW on anything but low poly counts, and max crashes so frequently, that I’m throwing in the towel on this one. I don’t know C++ so there’s no way for me to solve these problems.
However, a lot of useful code has come out of it, so I’m uploading the source and if anyone wants to have a crack at pushing it on they are more than welcome. It would be especially suitable for a C++ implimentation (hint, hint, any C++ coders!)!
The source code can be found here:
http://discussion.autodesk.com/thread.jspa?threadID=510014
It’s broken up into 2 files :
1 – the twist profile modifier
2 – a curve control rollout and editing controls
Goodnight, and God bless, as they say
Cheers,
Dave
I have to tell you Dave that I have tried to use SimpleMod many times to do mesh manipulations and always failed because of speed, memory and crashing issues. It was sounding like you had solved some of them but I guess not.
It is time to learn C++, I have started into it several times but I just don’t have the time to get all the way in. Most of what I do and get paid for I don’t need it so I don’t have time to learn it while working. I guess I will have to sell the kids and rent out the wife so that I can get some free time on the weekends to dig into it.
I’ve taken a look at the maxsdk and all the source code is in there for the bend modifier, which subclasses SimpleMod2, a C++ modifier base class. So at some point I will definately have a crack and recooding it to put in the very basic maths that manipulates the verts to do my twist. I’m sure once I get familiar with class hieracrchy and the ins and outs of C++ it could be very rewarding, as the SDK help looks fantastic.
That’ll be sometime in 2008 then!!!
Good luck in the meantime with renting out the wife and selling the kids.
Cheers,
Dave
Hi Dave.
I’ve disposed of some free time and I’ve created a C++ plugin (this was a good excuse to improve my knowledge about the C++ SDK :)) that does basically the same thing than the script, but obviously a lot more fast. It’s not finished yet, though.
Take a look at it and tell me if you need the same functionality as the standard plugin plus the profile thing or you need something different…
Greets.
OH MY GOD!! Jonathan – I am STUNNED! I’ll happily take the plugin any way you can manage it, but I’ll let you know my intentions so you can see how I was planning to use it
At the moment I am building and animating a rollercoaster for Fox Kids. I’m using path deform to make the track wrap to a crazy 3D spline which is great until you work out that there’s no way to actually twist the geometry as it goes along, and the decisions path deform makes are next to useless once you have a few crazy vertical curves.
So … my key objective was to have as much control as possible in the Edit Profile graph, with no Angle spinner at all, as follows:
X-axis – The distance along spline:
Ideally, in real world units, but for the time being 0-100% woudl work.
Y-axis – the amount of twist, in degrees:
Both negative and positive, with no limits.
Ability to manipulate tangents:
Basic tools, such as align, average, flatten. Important so that straight (non twisting) sections can be modelled correctly.
The actual curve:
I wanted to be able to have the curve reflect real-world space, as opposed to a 0-100% ratio, as when the spline was lengthened, the animation would stay the same. But this is quite a lot extra work, multiplying point and tangent values, checking against the x-axis limits, etc, etc.
But even what you’ve done now is great! Having a negative amount of twist and no limits would be preferable though.
I am in your debt! Project still on though, so anything I can do, just name it!
I’ve attached a scene so you can see the kinds of things I’m looking at.
Cheers,
Dave