MoI discussion forum
MoI discussion forum

Full Version: The script for chain

Show messages:  1-12  13-32  33-52  53-72  73-80

From: bemfarmer
12 Aug 2013   [#33] In reply to [#32]
Thank you Michael :-)

I've still got ideas to try. I may try dividing up the leftover curve of ArrayGem...sounds sort of iterative.
Sounds like a bunch of spheres touching.

Then again, a rigid flow may be good enough for nice drawings. The artist can adjust his spacing...

- Brian
From: bemfarmer
15 Aug 2013   [#34]
Spent a lot of time trying out ArrayGem.
I've concluded that for a 3D curve, ArrayGem requires a matching surface (always or usually).

Flow rigid works well also.

-Brian
From: Michael Gibson
15 Aug 2013   [#35] In reply to [#34]
Hi Brian, yeah ArrayGem needs both a curve and a surface that the curve is on - the surface normal is used to control rotation of the items so that the initial "up" direction of the base circle maps to the surface normal direction.

- Michael
From: bemfarmer
18 Aug 2013   [#36]
Did some more work on the chain script.
Copied link1 to link2 and rotated 90 degrees.
Created Flow baseline. These were fairly easy as they just follow the same pattern as the previous factories.

Currently bogged down with trying to get "Array Dir" factory to work in script.
Not sure if the Array output is a list of multiple chain links or ...?
Still fuzzy on objects versus object lists, and object lists with one object, and how to concatenate
link1 and link2 with .addobject...etc...

Then will have to get the Flow factory to work in script...

- Brian :-)
From: bemfarmer
18 Aug 2013   [#37] In reply to [#36]
Tried some array permutations this morning, changing the objectlist formation. Array dir script still not working.
Maybe my Mode string is wrong, or the ObjectList is wrong.
Not sure how foreign languages figure in to the Mode string, maybe have to look at CSS or something...?

Are Array Dir, or Flow factories asynchronous?
Is there a list of asynchronous factories?

- Brian
From: Michael Gibson
18 Aug 2013   [#38] In reply to [#36]
Hi Brian,

> Currently bogged down with trying to get "Array Dir" factory to work in script.

Array dir's inputs are like this:

index 0 = object list - objects to be arrayed.
index 1 = integer - number of items to make in the array (the original object is included in this count, so for example num items = 3 will actually make 2 copies).
index 2 = point - base point
index 3 = point - offset point
index 4 = point - extent point
index 5 = string - can be one of: "Offset, Count" or "Extent, Count" or "Offset, Extent"

How the points are interpreted depends on the mode, the most simple mode is "Offset, Count" mode that will be where only the base point and offset point are set and that defines a distance that is used for each generated copy.



> Not sure if the Array output is a list of multiple chain links or ...?

Which method are you using for generatring the output, is it factory.calculate() ? That method always generates an object list for its output. For array dir it will be all the copied objects that were generated.


> Still fuzzy on objects versus object lists, and object lists with one object, and how to
> concatenate link1 and link2 with .addobject...etc...

Yeah the "object list of a single object" can be kind of awkward, that comes into play though when you use some general purpose interface that is set up to be flexible so that it handles both commands that generate one object and also commands that generate multiple objects with a common way of operating. So for example the .calculate() method is like that it always returns an object list with the objects that were generated in it, that way it behaves the same way for all factories instead of returning different things depending on whether the factory made only one object versus a bunch of them.

For concatenating 2 lists together, you need to do something like this

var list1, list2;

...

// Combine list2 into list1
for ( var i = 0; i < list2.length; ++i )
{
var obj = list2.item(i);
list1.addObject( obj );
}

If you need to do this a lot, make a helper function that will do that task for you so you can call your function to do it when you need it.


And one thing to note is that the geometry database is not exactly the same thing as an object list, although the geometry database contains within it a list of objects, it has its own interface for dealing with it and has some additional methods like addObjects() that takes an object list. Currently an object list itself does not have a method that adds another object list to it, it only has an addObject() function.

- Michael
From: Michael Gibson
18 Aug 2013   [#39] In reply to [#37]
Hi Brian,

> Not sure how foreign languages figure in to the Mode string, maybe have
> to look at CSS or something...?

Localization does not affect the mode string that is passed into code, it only changes the displayed UI part of stuff.

Things like those modes are usually set by a <select> or <moi:select> element, and the options within the select have 2 parts, a "value" property which is always in english and that's what is passed into the acutal code, and then an inner text or a textid (text id for a look up into the current language string table) that controls only what is displayed in the UI when that option is active.

So for example if you want to know what values the array dir command can take, open up ArrayDir.htm and look at the control for <moi:Select id="Mode"> , the value="" properties on the child options there have the different string values that the code will actually recognize.



> Are Array Dir, or Flow factories asynchronous?
> Is there a list of asynchronous factories?

Array dir is not asynchronous. Usually it's the ones that need to do some more in depth calculations that are asynchronous. Here's a quick list of async ones:
ArrayGem, Blend, Booleans, Intersect, Project, Silhouette, Flow, Twist, Extrude, Fillet, Chamfer, Join, Loft, Offset, Shell, Inset, Network , Nsided, Revolve, RailRevolve, Sweep, Text.

- Michael
From: bemfarmer
18 Aug 2013   [#40] In reply to [#38]
Thank you Michael.
My problem was with improper list creation of link1 and link2.
Now have array working with offset, extent.
On to Flow factory...
I'll post an update later.
From: bemfarmer
18 Aug 2013   [#41] In reply to [#40]
Latest ChainMaker script.
Array Dir works to array the links on a base line.
Still cannot get Flow to work. One of the inputs must be wrong. It gets to a point were I run out of things to try.
From: BurrMan
18 Aug 2013   [#42] In reply to [#41]
Hey Bem,
Thats a great result already. Unwrapping the flow curve and leaving it allows to just run a rigid flow with the 2 curves quickly and get a result.

I suppose if you automate the flow it will be complete, but it's already a great command...

Thanks.
From: BurrMan
18 Aug 2013   [#43] In reply to [#42]
I wonder if you can just get to that point there, Have the end of your command select all solids, then launch the regular flow command? Pick the curves and done.
From: BurrMan
18 Aug 2013   [#44] In reply to [#43]
So for instance, I just made a copy of the flow command and named it ChainFlow, then I copied the code for ChainMaker js and htm to the top part of the new ChainFlow.

It "looks" like it could work, but both commands are running at the same time.

Is there a "pause here until finished" that could be added? The flow is waiting while chainmaker is running. Once chanmaker is done, it accepts the input curve, but wont pick the target. So they need to be seperated...

Michael,
Can a js call "DoChainMaker();" wait, then call "DoFlow();"? (Or "Function DoChain, FunctionDoFlow) with includes or something like that?
From: bemfarmer
18 Aug 2013   [#45] In reply to [#43]
Thank you Burr :-)
From: Michael Gibson
18 Aug 2013   [#46] In reply to [#44]
Hi Burr,

> Michael,
> Can a js call "DoChainMaker();" wait, then call "DoFlow();"? (Or "Function DoChain, FunctionDoFlow)
> with includes or something like that?

Not really just by including just the existing flow command, because usually the regular commands are pretty intertwined with their UI as well.

- Michael
From: Michael Gibson
18 Aug 2013   [#47] In reply to [#41]
Hi Brian, so I looked into why Flow is not working, and one thing is for flow input index 1, the base curve that should be a curve object and not an object list, so these lines:

code:
	factory.setInput( 0, chainobj );
//	var baseline = baselineobj.item(0);
	factory.setInput( 1, baselineobj );
	factory.setInput( 2, targetCurve );


should have these 2 lines changed like this:

code:
	factory.setInput( 0, chainobj );
	var baseline = baselineobj.item(0);   // <<< enable this line that you tried before.
	factory.setInput( 1, baseline );       // <<< put in the curve, not the object list here.
	factory.setInput( 2, targetCurve );



But then there's an additional problem which is that the results from arraydir are not returned back to you - that's because of a mechanism in the array commands where during calls to .update(), they don't actually create full object copies and instead make a special lightweight "proxy" object (sort of like an instance) that can be constructed more quickly than an actual full object copy and so that keeps the display more interactive while doing some large number of arrayed items and placing points around. But it's messing up your script in this case because at the time the script calls getCreatedObjects() the system doesn't think any full objects have been created yet because of this special proxy object creation being done instead.

Proxy making is turned off when you do a .commit() but then also at that point the factory considers itself to be completely finished and clears its created object list at that time so you can't call .getCreatedObjects() at that time. Proxy generation is also turned off though if you call .calculate() so for now the solution will be to call .calculate() on the arraydir factory rather than update/getCreatedObjects/commit and also you'll need to add the results of calculate into the geometry database so they will work with the async flow factory.

So that means changing the array section from this:
code:
	var arrayfactory = moi.command.createFactory( 'arraydir' );
	arrayfactory.setInput( 0, linklist1 );
//	arrayfactory.setInput( 1, 5 );
	arrayfactory.setInput( 2, baseStartPt );
	arrayfactory.setInput( 3, offsetPt2 );
	arrayfactory.setInput( 4, baseExtentEndPt );
	arrayfactory.setInput( 5, "Offset, Extent" );
	arrayfactory.update();
	var chainobj = arrayfactory.getCreatedObjects();
//	var chain = chainobj.item(0);  This line does not help.
	arrayfactory.commit();
	factories.push( arrayfactory );	


To this instead:

code:
	var arrayfactory = moi.command.createFactory( 'arraydir' );
	arrayfactory.setInput( 0, linklist1 );
//	arrayfactory.setInput( 1, 5 );
	arrayfactory.setInput( 2, baseStartPt );
	arrayfactory.setInput( 3, offsetPt2 );
	arrayfactory.setInput( 4, baseExtentEndPt );
	arrayfactory.setInput( 5, "Offset, Extent" );
	var chainobj = arrayfactory.calculate();   // <<<<<
	moi.geometryDatabase.addObjects( chainobj ); // <<<<<


After those 2 changes then the flow part should work.

- Michael
From: bemfarmer
18 Aug 2013   [#48] In reply to [#47]
Thank you again Michael.

I started a text file of a bunch of your script explanations. It is good for review and recollection.

There is no way I would ever have figured it out!

Installed the changes, and Flow does work! It took about 3.5 seconds.

Some tentative observations:
The first two links are missing...I think.
I think end selection of the target curve selection is not working either.

I think there is some cleanup to do on the script also.
Undo leaves link2 persisting...

More work to do tomorrow.

:-)

-Brian
From: Michael Gibson
19 Aug 2013   [#49] In reply to [#48]
Hi Brian, yeah really the whole current system is tuned more for a combination of some script more for "control flow" plus some C++ backend that does the actual geometry creation. It's not really specifically tuned for someone who's doing all script for everything as you've been doing.

I had been originally hoping that just one "factory" mechanism would work for everything but I think it's getting fairly clear that it would be better for larger scripts to have their own methods to call like createLine( start, end ) and stuff like that rather than running everything through the factory mechanism. The factory mechanism has some complexity to it since it's tuned for generating each thing in an interactive way like how the line command runs rather than just creating a specific line for example.

- Michael
From: bemfarmer
19 Aug 2013   [#50] In reply to [#49]
Good morning Michael.
Thank you again for all of your help with this scripting.
Your MoI interactive programming is top knotch. To me the interactive programming seems
that it must have been ten times harder to do and understand than doing these bulk scripts, which work pretty well,
once the inputs are figured out.


Last night, I tried to attach or append link1 and link2 to the array chainobj, but was unable to do it properly, so this morning
I moved the flow base line over to the right by 2 links, to get around the array "leaving out" link1 and link2, and now the
flow works properly, starting from the start of the target curve.

The flow takes about 3 seconds for a 15 link chain, which is normal.

Have not done a twisted chainlink option yet. Undo leaves a link2 residue.
Need to clean up the script a bit also. Factories are not needed.

Note that this script does not adjust the chain length, nor the link length, to match the endpoint. So there is
"left over" chain link portion at the end.

Edit: Hmm, Rigid is not working...

- Brian
From: Michael Gibson
19 Aug 2013   [#51] In reply to [#50]
Hi Brian, re: rigid not working -

The factory is expecting a boolean true/false property for that parameter, not a string, so change:

factory.setInput( 5, 'rigid' );

to instead be:

factory.setInput( 5, true );


If you see in the UI that it's using a checkbox control hooked into the property, that's going to give a true/false value out of it.

- Michael
From: bemfarmer
19 Aug 2013   [#52] In reply to [#51]
:-)

Show messages:  1-12  13-32  33-52  53-72  73-80