PointPicker scripting

Next
 From:  bemfarmer
10802.1 
PointPicker scripting

Hi Michael,

I have been studying hard about pointpicker and frames and cplanes and world and local coordinates, and CPlane.evaluate, distancex, etc.

The MoI API of Dave Morril shows 26 properties, and 34 methods for pointpicker WaitableObject.
MoI4 added about 4 properties, and about 1 method.

*****My question is how to create cPlane2 from cPlane1?*****
***** probably using pointpicker method .setBasePt(newBasePt);*****

Remark: cPlane1 is not a CPlane, it is actually a ptframe. 2D or 3d or pseudo 2D ???
also, cPlane2 is actually a ptframe.
cPlane2 will be used as the Frame for a rotate factory.
cPlane2 has base point a small X distance away from base point of cPlane1.
cPlane2 is to have the same "grid plane" as cPlane1, (or slightly moved???)
Note: "grid plane" is different in Top, Front, and Right Views, but shows up as local (X,Y) axes in cPlane1.

code:
function DoElastica()
{
//	User selects a point in any one of MoI's seven Views.
	var pointpicker = moi.ui.createPointPicker();
	if ( !GetPoint( pointpicker ) ) return;
	var refPt = pointpicker.pt;	// World coordinates. (refPt is not used)
	var cPlane1 = pointpicker.ptframe; // GOOD code, cPlane1 works for Mirror.
//	var vpName = moi.ui.getActiveViewport().name;
//	moi.ui.alert( 'viewportName = ' + vpName );
//  ...More code here...

	var curvefactory = Update(cPlane1, pointpicker); // Call Update function.

//  More code in the Update(cPlane1, pointpicker) function:
//	In a loop, Calculate multiple 2d points using mathematics.  (z = 0)
		var pt = cPlane1.evaluate( x, y, z ); // World coordinates.
//	locallastPt would = above (x,y,z) in local coordinates.		
	
		curvefactory.createInput( 'point' );
		curvefactory.setInput( curvefactory.numInputs - 1, pt );	
	} //End of Loop.
	var lastPt = pt; // World coordinates.
	curvefactory.update(); // Probably delete this.
	// initialCurve is the initial halfLobe curve.
	var initialCurve = curvefactory.calculate();
	
**********What is the correct code for the next code line???*********
	var cPlane2 = pointpicker.ptframe.setBasePt(lastPt); //This code throws error, Not a constructor.<<<<<<<<<<<

	
	// Maybe an alert message: 'New Base Pt' = pointpicker.ptframe.relocatedBasePt
	


// Or should the setBasePt point be in local coordinates???


Thank you,

-Brian

EDITED: 4 Aug 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10802.2 In reply to 10802.1 
The following appears to be working the first time through.
Note, I switched from setBasePt() to setPt().

code:
	var lastPt = pt;

		pointpicker.setPt(lastPt);		
		var cPlane2 = pointpicker.ptframe


But for a second time through, if Updating (Changing) the shape, a different error appears: (Click on a pushbutton to change shape.)

The error is TypeError:undefined is not an object
(evaluating 'pointpicker.setPt')
_Elastica3.js line 363
363 >> pointpicker.setPt(lastPt);

Right clicking and running the script again produces the correct new curve.

- Brian

I could post the latest _Elastica3 script, a work in progress...
I attached the August 4th 2022 draft. It is mostly converted from script in html, to script in .js, but still needs some work.
Proper rotate and join will be done, once the cPlane2 is sorted out.
Edit: deleted draft script.

EDITED: 4 Aug 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10802.3 In reply to 10802.1 
Hi Brian,

> Remark: cPlane1 is not a CPlane, it is actually a ptframe. 2D or 3d or pseudo 2D ???

"cplane" and "ptframe" are not distinct object types, they are both instances of a MoiCoordinateFrame object that contains an origin point and x/y/z axis directions forming a coordinate system.

When you access the pointpicker.cplane property, that will return a MoiCoordinateFrame object set to the local cplane for the viewport that the mouse was clicked in. That's the same as the grid you see inside of a viewport.

When you access the pointpicker.ptframe property, that returns a MoiCoordinateFrame object that has the x/y/z axis directions of the viewport's cplane but it's origin point is placed at the picked point. It's the same as if you used pointpicker.cplane but then set the .origin property of that frame to the picked point (pointpicker.pt).

re:
code:
var cPlane2 = pointpicker.ptframe.setBasePt(lastPt); //This code throws error, Not a constructor.<<<<<<<<<<<


So the reason why this throws an error is that you'll be getting a MoiCoordinateFrame object returned back from the pointpicker.ptframe part of the code, and then you're trying to call a function setBasePt on it. But there is no function setBasePt on a MoiCoordinateFrame object, it's the pointpicker that has a setBasePt() function in it.

The pointpicker setBasePt() takes a point in world coordinates to use as the base point for the current pick. Things like straight snap use the base point, it's usually set in things like drawing a line for the 2nd pick of the line. The point from the first pick is set at the base point and that will then set up straight snaps which go through the base point.

Does any of that help? I'm not really sure what it is that you're trying to do at that point in the script so it's a little difficult for me to tell you exactly what the code is supposed to be right there.

But if it's the second point of a picking sequence that is meant to behave like the line command with straight snaps active from the previous point pick, that's what you would use setBasePt() on the pointpicker to set up.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10802.4 In reply to 10802.2 
Hi Brian,

re:
> The following appears to be working the first time through.
> Note, I switched from setBasePt() to setPt().

The .setPt() function on the pointpicker is a way for a script to set the picked point itself. It's something that might be used in a snapping function callback, where some script wants to trigger the point pick to be finished and to have a specific point value.

It's not likely to be relevant to what you're doing.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
10802.5 In reply to 10802.4 
Thank you Michael.
I'll study your responses tonight.
I seem to be making a little bit of progress:-)

- Brian


So I can either convert cPlane1 to cPlane2 with a new base point, which I still do not know how to do.?
cPlane2 needs the same grid, with a new base point.

Or else, I can open a 2nd pointpicker, and feed the new base point to it by script, not by manual pick, and get the cPlane2 from the second pointpicker.ptframe.?

EDITED: 4 Aug 2022 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10802.6 In reply to 10802.5 
Hi Brian,

re:
> So I can either convert cPlane1 to cPlane2 with a new base point, which I still do not know how to do.?

I'm a little confused by your question, are you maybe getting the "base point" for the pointpicker mixed up with the origin point of a MoiCoordinateFrame object? Those are different things.

You can set the origin of a MoiCoordinateFrame object like this:
cPlane2.origin = pt;


> Or else, I can open a 2nd pointpicker, and feed the new base point to it by script, not by manual pick,
> and get the cPlane2 from the second pointpicker.ptframe.?

I may need you to describe a little more about what you're trying to do with cPlane2.

Is the confusing part maybe that you're trying to use cPlane1 and cPlane2 for separate things but they are both referring to the same MoiCoordinateFrame object?

If you want an independent frame try creating a new one using:

var cPlane2 = moi.vectorMath.createFrame();

cPlane2.xaxis = cPlane1.xaxis;
cPlane2.yaxis = cPlane1.yaxis;
cPlane2.zaxis = cPlane1.zaxis;
cPlane2.origin = pt;

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  bemfarmer
10802.7 In reply to 10802.6 
Thank you Michael,

I have been a lot confused.

But your last response about "If you want an independent frame try creating a new one using:"
is exactly what I need for the script!

So the cPlane1.xaxis; and cPlane1.yaxis; and cPlane1.zaxis; are not locked to a specific point in 3D space, because they are Vectors,
but they commonly are thought of as emanating from the local Origin, which is located at the world coordinate point pt.
And the three axes do correspond with the grid axes of the particular View, so the 2D points, (or possibly 3D points), can be plotted.
The world coordinate point pt, will establish the local Origin of the frame. The local Origin point is ( 0, 0, 0 )

My cPlane2 origin will be in a different location than the cPlane1 origin.

Again,
Thank you very much.

- Brian

I should not have been talking about BasePt, when I should have meant origin point.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All