PDA

View Full Version : Simple Mod memory issue


davestewart
09-29-2006, 11:10 AM
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
)
)

HalfVector
09-29-2006, 12:15 PM
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.

davestewart
09-29-2006, 12:57 PM
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

HalfVector
09-29-2006, 04:06 PM
By the way - you don't know how to store curve control data in scripted plugins do you!?
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.

davestewart
09-29-2006, 04:58 PM
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

PEN
09-29-2006, 05:20 PM
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.

davestewart
10-01-2006, 11:20 AM
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

And it looks like this: http://discussion.autodesk.com/servlet/JiveServlet/download/217-510014-5346559-125032/twist-profile.gif

Goodnight, and God bless, as they say :)

Cheers,
Dave

PEN
10-02-2006, 12:42 PM
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.

davestewart
10-02-2006, 12:58 PM
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

HalfVector
10-05-2006, 07:48 PM
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.

davestewart
10-06-2006, 01:03 PM
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

HalfVector
10-06-2006, 01:11 PM
Ok, I'll see what I can do!.

davestewart
10-06-2006, 02:56 PM
You are da man :) :) :)

Of course, the only other thing I forgot to mention was a radiobutton set for the primary axis. Should just be a simple case of swapping the sin/cos x,y,z around, but I understand if you have more pressing things to think about!

Feel free to nab the functions in the curve control ms I published before.

Thanks again, you really have rescued me from the depths of disappointment!

Cheers,
Dave

HalfVector
10-06-2006, 05:00 PM
Hi.

I've done some of the modifications you've mentioned.

Now there's no limit in the Y axis (which now defines the angle), the X axis ranges from 0 to 100 and I've added the radio buttons to choose the rotation axis.

So the next thing should be set the curve X axis range to [0, length_of_the_spline]. The problem then is that the modifier happens to be too specific. A button to attach a spline would be needed so any time the length of the spline changes, the X range would be updated automatically. Another option would be adding custom controls in the curve editor like "take length from spline" or the tangent controls you mentioned.

But I have to take a look at that because creating a custom curve editor in C++ is different from MAXScript.

Anyway hope that helps!.

PS: obviously scenes with the previous version won't work properly so you'll have to reassign the modifier.

davestewart
10-06-2006, 07:34 PM
Hi Jonathon,
What can I say? Thank you very much!! The difference that this will make on this project is absolutely massive. I thought I had wasted 2 days on a lame duck, but it appears that with your help it looks like I will be able to snatch victory from the jaws of defeat!

I do hope that you found it a good learning experience as you hoped. I certainly enjoyed what has now turned out to be "prototyping" it!

I'll check it out in the scenes I'm modeling and get back to you. It's so nice to have it working quickly! It really makes it really easy to assess what works, both from a plugin point of view, and from a scene point of view.

From a quick look I would agree with you that changing the spline length interpretation may be a tricky one. The tangent tools would certainly be worthwhile; I found them so even with the prototype that it was a intuitive way to edit the curve quickly.

At some point I have to make the leap to C++. Hopefully my friend will give me some tuition on making the leap. And there's also the wealth of talent here in the forum to support my endeavours.

My best regards for now!
Dave

HalfVector
10-07-2006, 07:43 PM
Hi.

I've implemented all the features you've got in the script.

I wasn't able to create custom controls inside the actual window of the curve editor so I've created an additional dialog box and I've attached to the editor window:

http://img108.imageshack.us/img108/6200/curveeditorth9.jpg

So every time you move or resize the curve editor window, the dialog box will be moved/resized in consequence.

There's one thing though. I've not implemented scrolling yet so if you resize down the curve editor window past the dialog box width, you won't be able to see the cut parts of the dialog box. The only way is to resize the curve editor window again so the entire dialog box can be seen.

The first thing I'll try to fix this, is create a rollout page so you can use the standard scrolling method in MAX. But I don't know if it's possible to scroll horizontally. The other obvious way is creating standard scrolling bars.

Here's the TODO list:

Implement scrolling for the curve tools dialog box.
Fix a problem with auto-zoom when the curve editor window is maximized.
Fix a problem with auto-zoom when the curve editor window is restored.
I've set the minimun length for the tangents to 1.0 because otherwise occurred unexpected results, maybe due to a division by zero (I have to check this with more time).
Right now seems like you can't specify the lengths for the in/out tangent (for bezier-corner points) at the same time when the "Lock" checkbox is checked. I have to fix it!


I think the plugin is totally functional now but obviously it's not tested enough so could exists more bugs!. :)

Greets.

davestewart
10-08-2006, 02:26 PM
Hi Jonathon,
Wow! Amazing stuff. Brilliant. Fantastic. I'm loving it!
I'll take a look and get back to you with some thoughts and feedback.
In the meantime, take care!
Dave

davestewart
10-10-2006, 08:05 PM
Hi Jonathon,
OK - generally, the modifier is flawless. It works great on high-face count models (I haven't tested on pollies) apart from the odd crash when clicking "Edit Profile", but my max crashes so much anyway that it's indistinguishable.

Regarding the UI, a couple of things are different to the prototype:

1 - Align First / Last.
These should align the selection to the first or last point in the selection, rather than the whole curve. This makes it useful to line up flat bits of the profile accurately

2 - Flatten
This appears to convert the end points to corners, rather than flattened bezier corners.


One thing I have been thinking is how to get a better feel for where the twist is happening on the geometry. As you know, I'm ultimately deforming the geometry along a path, and it can be quite difficult to assess exactly where twists shoud start and end. I've been using an animated helper to show me exactly where the twist point I'm editing will be:

For example, I decide to twist my mesh at a certain point along the spline; its at the apex of a rollercoaster loop. I set my helper's position along the path to co-incide with this, and it happens to be 42% along the path. Thus, I know that point on the Edit Profile graph should be at 43 on the X axis, and I can intuitively edit the curve!

A wish-list item might be that if you picked a point in the Edit Profile curve, some kind of viewport feedback (a marker / some text, for instance) would highligh the point visually. As you dragged the point, the viewport marker might update.

I originally played with manipulators to get the twist's deforms, but dropped them in favour of the curve. An interesting idea though!



Thank you so much for your help on this.

The project (a TV promo for Jetix) is looking really good so far. I have yet to track some 2D characters to the coaster cars, but I couldn't have come this far without the power of C++ and your generosity!

Immage attached; much obliged,
Dave

HalfVector
10-10-2006, 09:53 PM
apart from the odd crash when clicking "Edit Profile", but my max crashes so much anyway that it's indistinguishable.
Hmmm I don't know if we are talking about the same thing but I've just discovered that if you press the "Edit profile" button when the window is already opened, MAX crash. I've solved that with this new release.

Regarding the UI, a couple of things are different to the prototype:

1 - Align First / Last.
These should align the selection to the first or last point in the selection, rather than the whole curve. This makes it useful to line up flat bits of the profile accurately

2 - Flatten
This appears to convert the end points to corners, rather than flattened bezier corners.
Yeah, I missed that. I think it works now.

A wish-list item might be that if you picked a point in the Edit Profile curve, some kind of viewport feedback (a marker / some text, for instance) would highligh the point visually. As you dragged the point, the viewport marker might update.
Yes, that would be great. But I think for this we need to specify a spline to calculate the position of the point we are working on. It's is something similar to the problem we were talking earlier about using real world units for the X axis.

I say that because we can calculate the position in the local space of the modifier but what we want is the final position in world space (imagine we have a bend modifier after the twist), and for this we need to evaluate the stack of modifiers for this point. The problem is that I don't know if that's possible.

I'll take a look at that, though.

The project (a TV promo for Jetix) is looking really good so far. I have yet to track some 2D characters to the coaster cars, but I couldn't have come this far without the power of C++ and your generosity!

Nice!. I am glad this is working for you. :)

davestewart
10-11-2006, 09:20 PM
Awesome stuff :)

CGTalk Moderation
10-11-2006, 09:20 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.