Show messages:
1-5
6-25
26
From: bemfarmer
I've go a new script working well with the "standard" .js and .htm method, but it is very slow.
While trying the Gear type of scripting, using an alert message function in the .htm file is giving
"Range error maximum call stack size exceeded" message.
I guess it is from the ongoing timing loop...
The faster "Gear" method is not working yet, so I'm going to switch to the "older" .htm speedup method.
- Brian
Image Attachments:
RangeErrorStackSizeExceeded.PNG
From: Michael Gibson
Hi Brian, change that to instead be:
code:
function alert( msg )
{
moi.ui.alert( msg );
}
The one you have there right now has moi.ui.
commandUI.alert() - commandUI is a way for a script to access the global object of the loaded .htm file, and doing commandUI.alert() means it is looking for a function alert() in that .htm file which is the very same function so it's calling itself over and over again in a recursive loop.
- Michael
From: bemfarmer
Thank you Michael
Alert is working.
(Now to get the bugs out of my script...)
- Brian
From: bemfarmer
The Elastica2 script has some sort of Bug. (MoI5beta)
Selection of points in 3D View can result in curves in two different planes.
Something to do with cplane and Frames, or cplane z points, I guess.
It is an 8 year old script. Back when much script was placed in .htm file, for speed. (No longer necessary.)
The script seems to work fine in Top, Front and Right views.
When using the following code in 3D view:
var cplane = pointpicker.ptframe;
what orientation is used for cplane?
Still studying...
Will try it in MoI4 tonight...
- Brian
It is probably NOT a MoI bug (?)
From: Michael Gibson
Hi Brian,
re:
> When using the following code in 3D view:
> var cplane = pointpicker.ptframe;
> what orientation is used for cplane?
It should be the same as Top view. Unless you have set a custom cplane using View > CPlane.
- Michael
From: bemfarmer
The Elastica2 script works well in 3D, Top, Front, and Right views, when the selected point has the 3rd coordinate = 0. (z=0 in Top View, or 3D View)
In 3D View, when z is non-zero, the first Mirror is OK. The second Mirror (and Rotate?), go off at strange angles.
The first quarter of the final curve is created with a cplane, from multiple x and y, with z = 0, points, then evaluated to world coordinates.
The first mirror of the curve seems to work fine, because it uses the same cplane:
code:
var mirror1 = factory( 'mirror', curve, cplane, cplane.evaluate( 0.0, 1.0, 0.0 ) );
The problem is that the second Mirror is using World coordinates, instead of cplane coordinates.
It is confusing...
I need to create cplane2, located at end point, given in World coordinates, of the first quarter curve, in the current View, the same View as the original cplane, in order to do mirror2 and rotate...
But the view could be in any of the 4 views.
Michaels recent post of code:
moi.view.setCPlane( Frame, ApplyToAllViews, OrientOrthoViews ); - takes a required coordinate frame parameter, optional boolean parameter for whether to apply to all views or 3d view only, and optional boolean parameter for whether to orient ortho views or keep them in world.
- Brian
From: bemfarmer
I do have endPt of the initial quarter curve, in cplane coordinates, (raw_x, raw_y, z=0).
Need to create cplane2 from these.
[Note: The point (raw_x, raw_y, z=0), in Front and Right Views, would represent (Y2,Z2,X2) and (X3,Z3,Y3), respectively.
I think that I did cplane2 = Frame2, back in 2013:
code:
var FrameOrigin = ptRaw;//ptRaw is the last point of the "half" curve
var x2 = raw_x + 1.0; // raw_z=0
var FrameXAxis = cplane.evaluate( x2, raw_y, raw_z );
var y2 = raw_y + 1.0;
var FrameYAxis = cplane.evaluate( raw_x, y2, raw_z );
var Frame2 = moi.vectorMath.createFrame( FrameOrigin, FrameXAxis, FrameYAxis );
Maybe need to get rid of cplane.evaluate above...?
But qtr curve is in World coordinates...Need Frame2 in World coordinates for Mirror2 and rotate...
I hope some of this makes sense. It is confusing to me.
Will try again tonight...
- Brian
cplane and Frame are related, but are not the same thing?
cplane converts World coordinates to local coordinates? Or vice versa...? evaluate...
code:
//Convert to cplane frame.
var base_x = cplane.distancex( BasePt );
var base_y = cplane.distancey( BasePt );
Frame provides orientations for commands like Mirror and Rotate?
From: Michael Gibson 10 May 2013 (8 of 35)
5878.8 In reply to 5878.6
Hi Brian, ok so I think the problem is the script is not quite getting the correct 2D coordinates for doing your calculations.
At the start of your function buildClothoid you've got some calls to cplane.evaluate() there - but that's probably not right, you use cplane.evaluate() for converting from the frame's "local coordinates" into world coordinates.
At that point in the script for buildClothoid() you actually need the reverse I think - the points given to you by the pointpicker are in world coordinates and you want to get them into 2D coordinates within that cplane's local coordinate system before you start doing calculations with them. Then when you're done doing your calculations that's when you want to use cplane.evaluate() to convert from 2D local cplane coordinates back into world coordinates.
The .evaluate() call is only for doing the last part (2D local into 3D world conversion) - you need something different for the first part (3D world into 2D local cplane conversion).
For doing the 3D world into 2D local conversion you can get the local 2D plane coordinate from a 3D world coordinate by doing cplane.distancex() and cplane.distancey() which get the signed distance of the given 3D point from the x-axis plane and y-axis plane of the frame, something like this:
var localx = cplane.distancex( worldpt );
var localy = cplane.distancey( worldpt );
So if you use that in the start of buildClothoid() it should then give you uniform behavior in all views, here's an updated buildClothoid function that should work:
From: Matadem
Good day.
I get invalid function argument line 0 Error
When I try to use this script in an existing drawing.
When I start with a blank new file it works :/
From: bemfarmer
Hi Matadem,
Yes, there is a bug (or two?), when cplane z equivalent from pointpicker is nonzero.
I am looking into it.
It should be a script bug, not a MoI bug :-)
-Brian
From: bemfarmer
The line0 error shows up in MoI4 and MoI5 beta, when the figure8 elastica has been selected and the script re-ran, ( with z equivalent not zero.)
Sometimes this bug also occurs in Top View...With z = 0.
MoI3 shows a different looking similar error, in the .js file.- perhaps more useful.
MoI3 also shows the bug with mirror2 at strange angle.
- Brian
From: bemfarmer
I may try doing Mirror and Rotate for each View on a case by case basis.
3D, Top, Front, Right Views.
- Brian
From: bemfarmer
Organizing thoughts:
Notes on bug(s) in Elastica2 script.
The Elastica2 script creates 7 of the 9 elastica curves.
The circle, and the line elastica are not created by the script.
The elastica curve created is based upon the Shape parameter, U.value.
The Shape slider ranges from -2 to 0.99999.
A circle would need a U.value of -infinity,
and a line would need a U.value of 1.0. But max U.value is set to 0.99999.
Based upon the Shape parameter, U.value, the
script mathematics culminates in an initial curve, with final point:
var pt = cplane.evaluate( x, y, z ); in world coordinates.
Except for the (half) curve created by U.value of -1.0, the initial curve
is one quarter of the final elastica curve.
The U.value of -0.65223... creates a "figure 8" final elastica curve.
The initial quarter curve can be created in any one of the 7 MoI views,
3D, Top, Bottom, Front, Back, Right, Left.
Using two mirrors, and/or rotation, the initial curve becomes 4 curves, which are joined to become one final elastica curve.
One bug results in an error message, re: Frames in MoI3, for some point selections at some U.values. (Especially for a point with 2 equal
coordinate values.) (Does not always happen. Might be a cleanup problem?)
The second bug has half of the final curve at strange angles, mostly for
points with non-zero third coordinate value. (Occasionally for third coordinate of zero. The strange angles are not the same for different
positions of the initial picked point.
The 3D view has characteristics like a Top View.
Top, Front, and Right views have different x, y, and z axis pairs,
So World coordinate Frames for mirror1 and mirror2, and rotate will be set up for each View Case.
Using Cases should eliminate the bugs.
Another goal is to revert most of the javascript code to the .js file, from the .htm file. (An old Max technique.)
Beginning with MoI4, the .js file is as fast as placing script in the .htm file.
mirror1 Frame is done with base point at the initial picked point.
mirror2 Frame is done with base point at the quarter curve end point.
rotate Frame is done with base point at the initial picked point.
join is also done.
- Brian
From: bemfarmer
This has been partly mentioned above.
Let "a" be a number representing a coordinate.
The _Elastica2 script displays an error message, in all 4 views, for a center point with ( x, y, z ) coordinates ( a, -a, 0 ) or ( -a, a, 0 ).
The error message in MoI3 shows a line in the Script section of the _Elastica2.htm file:
code:
var Frame = moi.vectorMath.createFrame( FrameOrigin, FrameXAxis, FrameYAxis );
The error message in MoI4, or MoI5beta, is the previously posted:
Script error
Invalid function argument
line 0
OK button.
- Brian
For nonzero z, coordinates ( a, -a, z ) or ( -a, a, z ) creates a curve, but with the strange angle mirror2 bug.
Will try some different code tonight or tomorrow, with better understanding of cplanes and Frames.
From: Michael Gibson
Hi Brian,
re exception here:
code:
var Frame = moi.vectorMath.createFrame( FrameOrigin, FrameXAxis, FrameYAxis );
In order to form a coordinate system the given xaxis and yaxis can't be parallel to one another.
Ideally they should be at a 90 degree angle to each other so they directly form an orthonormal frame. But it will tolerate if they are not 90 degrees to each other but they can't be parallel because they need to have a z axis direction formed by the cross product between them.
So if the angle between them is less than 2 degrees it will throw an "Invalid argument" exception.
- Michael
From: bemfarmer
Thank you Michael.
Your help, and Cross product information makes sense.
I'll be doing some corrections to the elastica2 script over the next few days, as work and energy level allows :-)
- Brian
From: bemfarmer
The string name of the current Viewport, in which a point was just picked.
Result is one of ( 3D, Top, Bottom, Front, Back, Right, Left )
code fragment in _Elastica2Test script.
code:
var pointpicker = moi.ui.createPointPicker();
if ( !GetPoint( pointpicker ) ) return;
moi.ui.commandUI.cplane = pointpicker.ptframe;
moi.ui.commandUI.referencePt = pointpicker.pt;
var vpName = moi.ui.getActiveViewport().name;
moi.ui.alert( 'viewportName = ' + vpName );
- Brian
From: bemfarmer
_Elastica3Aug5_OK_Draft is a pretty good version of _Elastica3 script.
It is not finished.
Should add rudimentary extrude (?), using Max S techniques, if this is possible.
Should add Help File, or else Help PDF.
Crucial help from Michael enabled the creation of the cPlane2 frame, for rotation and mirror2.
The user selects a reference point in one of the 7 MoI viewport Views, and the resulting 2D Elastica curve appears.
Looking at this curve in another View looks as expected, a Top or Front, or Right appearance, etc.
Running the script again, and selecting another point in any other of the 7 Views, with the same shape parameter,
produces an Elastica curve with the same appearance as the first selection in the other view.
This is due to using cPlane1 frame from pointpicker.
The Script has nearly all of the code in the .js file, not in .htm file.
Said goodbye to DarkGoldenRod color, for the pushButtons.
The DarkGoldenRod color for pushButton text was Okay, but the look of the theme text color for Default and Dark Themes is a bit better.
The pushButtons show elastica curve for 7 values of shape parameter.
The shape slider produces a near continuous progression of shapes.
The script works in MoI3 (slight delay), and also in MoI4, and MoI5beta.
I believe that the bugs of _Elastica2 are gone.
Number of points should be relatively high.
A trial of a Control point curve had a poor look between the two joined halves, so InterpCurve was used instead.
One curiosity is that the intersection of the "figure 8" elastica, when zoomed way way in, appears offset from the reference picked point.
But the distance of the offset from the reference point shows up as 000000.
Earlier trials had the join(s) eliminating the visual offset, but that is no longer happening, with the current join order.
The value of shape = 0.65223 was calculated in the source paper, and is not exact.
- Brian
Attachments:
Elastica3Aug5_OK_Draft.zip
From: bemfarmer
After doing some testing, I have come to the conclusion that the MoI Rebuild command (refit mode) does not work for the figure 8 elastica, a closed curve.
(Tested in MoI4, and MoI5beta.)
The Rebuild, # Points option worked.
Rebuild works for an open, almost figure 8 curve.
Is this a "bug" in Rebuild, or a result of the closed geometry of the figure 8? Tolerance calculation?
In other discoveries, a point count of 2 tends to make a zig zag curve.
A point count of 3 makes some different curves.
A point count of only 10 makes some fairly decent curves.
Added a help window, and cleaned up the .htm file a bit. (q.v.)
Now to tackle the rudimentary extrusion...
Name: ...Aug6Draft
- Brian
Attachments:
Elastica3Aug6Draft.zip
From: Frenchy Pilou (PILOU)
French Version! :)
https://moiscript.weebly.com/bemfarmer-2.html
From: Michael Gibson
Hi Brian,
re:
> Is this a "bug" in Rebuild, or a result of the closed geometry of the figure 8? Tolerance calculation?
Looks like a bug, I will investigate.
Thanks, - Michael
Show messages:
1-5
6-25
26