MoI discussion forum
MoI discussion forum

Full Version: Moi + Affinity : Moi for 2D workflows

Show messages:  1-7  8-27  28-47  48-67  68-87  88-90

From: mkdm
4 Nov 2017   [#48]
Hi Michael.

I'm pretty sure that you already answered me a long time ago, about this question, but I don't remember where is your answer.
I've searched trough the forum by I didn't find what I'm looking for.

The question is this :

If we simply take into account the "speed of execution" factor, can we state that the code executed inside a the "hmtl" page of a command
or inside a script placed into the "scripts" folder, is faster (and many times faster) the the execution of "js code" present in the "js" counterpart of command's html ?

I ask you this because I have in mind to turn the next version of my "script for 2D workflow" from "script" into "command" just in order to
handle more easily the various working mode of that scripts.

For what I've experienced and learned I've seen that the "js" code executed inside the Hml file of command is much more faster that the counterpart executed into the "js" file of the command :

For example consider the "ScaleIndividual" commands that Max wrote times ago :

1) the original version of Max Smirnov :
get it at https://drive.google.com/open?id=1waO3TgOQSUl2ZIBJ8adixPz5Qes_ja21

2) A version that I have modified and that do the main task into the "js" code inside the Html file of the command :
get it at https://drive.google.com/open?id=1N6qWe_lzyJA-aTOrmESLRPhzky_XHhoB


Why the 2nd version, is much more faster than the first (to make a good test you have to select many objects, I tested with hundreds) ?


This is the code of the original version of ScaleIndividual.js and ScaleIndividual.htm :

code:
#include "GetObjects.js"
#include "WaitForDialogDone.js"

function ScaleObject( obj, factor )
{
	var center = obj.getBoundingBox().center;
	var list = moi.geometryDatabase.createObjectList();
	list.addObject( obj );

	var factory = moi.command.createFactory( 'scale' );
	factory.setInput( 0, list );
	factory.setInput( 1, center );
	factory.setInput( 2, factor );
	factory.commit();
}

function DoIndividualScale()
{
	var objectpicker = moi.ui.createObjectPicker();
	if ( !GetObjects( objectpicker ) )
		return;
		
	var objects = objectpicker.objects;
		
	moi.ui.beginUIUpdate();
	moi.ui.hideUI( 'SelectPrompt' );
	moi.ui.showUI( 'OptionsPrompt' );
	moi.ui.showUI( 'options' );
	moi.ui.endUIUpdate();
	
	if ( !WaitForDialogDone() )
		return;
		
	var scalefactor = moi.ui.commandUI.factor.value;
		
	for ( var i = 0; i < objects.length; ++i )
	{
		var obj = objects.item(i);
		ScaleObject( obj, scalefactor );
	}
}

DoIndividualScale();


code:
<html>
	<body class="commandbody">
		<div class="commandheader">
			<div id="SelectPrompt" class="commandprompt">Select objects to scale</div>
			<div id="OptionsPrompt" class="hiddencommandprompt">Scale options</div>
		</div>
		
		<div id="options" class="hiddencommandoptions">
			<table>
				<tr>
					<td>Scale factor:</td>
					<td><moi:NumericInput id="factor"/></td>
				</tr>		
			</table>
		</div>

		<moi:CommandDoneCancel />
	</body>
</html>



And this is the code of my modified version of ScaleIndividualMainThread.js and ScaleIndividualMainThread.htm :

code:
#include "GetObjects.js"
#include "WaitForDialogDone.js"

function DoIndividualScaleInit() {
	var objectpicker = moi.ui.createObjectPicker();
	if ( !GetObjects( objectpicker ) )
		return;
		
	var objects = objectpicker.objects;
		
	moi.ui.beginUIUpdate();
	moi.ui.hideUI( 'SelectPrompt' );
	moi.ui.showUI( 'OptionsPrompt' );
	moi.ui.showUI( 'options' );
	moi.ui.endUIUpdate();
	
	if ( !WaitForDialogDone() )
		return;
	
	moi.ui.commandUI.DoIndividualScale(objects);
}

DoIndividualScaleInit();


code:
<html>
	<head>
		<script>		
			function ScaleObject( obj, factor ) {
				var center = obj.getBoundingBox().center;
				var list = moi.geometryDatabase.createObjectList();
				list.addObject( obj );

				var factory = moi.command.createFactory( 'scale' );
				factory.setInput( 0, list );
				factory.setInput( 1, center );
				factory.setInput( 2, factor );
				factory.commit();
			}

			function DoIndividualScale(objects) {
				var scalefactor = moi.ui.commandUI.factor.value;
					
				for ( var i = 0; i < objects.length; ++i ) {
					var obj = objects.item(i);
					ScaleObject( obj, scalefactor );
				}
			}
		</script>
	</head>
	<body class="commandbody">
		<div class="commandheader">
			<div id="SelectPrompt" class="commandprompt">Select objects to scale</div>
			<div id="OptionsPrompt" class="hiddencommandprompt">Scale options</div>
		</div>
		
		<div id="options" class="hiddencommandoptions">
			<table>
				<tr>
					<td>Scale factor:</td>
					<td><moi:NumericInput id="factor"/></td>
				</tr>		
			</table>
		</div>

		<moi:CommandDoneCancel />
	</body>
</html>



Thanks a lot for the support :)

Have a nice day.

Ciao!

Marco (mkdm)
From: mkdm
4 Nov 2017   [#49]
P.S. Michael, I will read your answer in five-six hours because now I have to go :)

Thanks.
From: Michael Gibson
4 Nov 2017   [#50] In reply to [#48]
Hi Marco,

> If we simply take into account the "speed of execution" factor, can we state that the code
> executed inside a the "hmtl" page of a command or inside a script placed into the "scripts"
> folder, is faster (and many times faster) the the execution of "js code" present in the "js"
> counterpart of command's html ?

For V3 yes that's true - the .js code is run in a separate process and uses inter-process communication on every MoI API call. The reason for this is it makes it impossible for the script to freeze MoI if it runs in an endless loop or something like that, the worker process can be torn down independently from the script's cooperation.

But the inter-process communication has a performance penalty. The regular default commands in MoI never use script to do heavy calculations in loops or things like that, and so are ok with that.

Code in the HTML side runs in the main process thread and so it doesn't have that same overhead.

For V4 this will be different though, in V4 the .js script will be run on the main thread and not on a worker thread anymore and so in v4 there won't be any difference for which file the code is contained in.

- Michael
From: mkdm
4 Nov 2017   [#51] In reply to [#50]
Thank you very much Michael for reminding me this behaviour.

Ciao :)
From: mkdm
11 Jul 2018   [#52]
Hello everyone!

I'm sorry for the uppercase but THIS IS THE LONG AWAITED DAY for all passionate pro artists/amateurs of 2D workflow/vector things!!

THE DAY has come :)

AFFINITY DESIGNER is ready for iOS!!!!!!

Still not of App Store but you can download here if you're on iPad: https://itunes.apple.com/us/app/affinity-designer/id1274090551?mt=8
From: Frenchy Pilou (PILOU)
11 Jul 2018   [#53]
Yep the challenger of Procreate! :)


Affinity Designer for iPad - official video from Affinity on Vimeo.
From: mkdm
11 Jul 2018   [#54] In reply to [#53]
This is a GREAT day for all the iPad crowd!!

Anyway, Procreate and Affinity Designer are not competitor at all.
They are focused on very different things.
But...what a wonderful DUO!!!!!
And don't forget Affinity Photo!

Great things for 2d graphics :)

These apps destroys everything on Android/Windows mobile side!
From: ycarry
13 Jul 2018   [#55]
Yes, its THE Adobe Illustrator challenger...
From: mkdm
13 Jul 2018   [#56] In reply to [#55]
But with the golden bonus that actually there isn't any iOS version of Adobe Illustrator!!

So actually Affinity Designer is the "Lion King" for vector things on iOS (and IMHO for mobile in general).

It was launched only some days ago so actually is still young and needs a certain amount of bug fixes obviously, and in fact I have already reported some bugs on Affinity Forum, but for what I've seen in the last three days of hard use it's really a game changer for all 2D graphics on mobile.

It's the missing link between Procreate and Affinity Photo.

Procreate (or Artstudio Pro) + Affinity Designer + Affinity Photo = almost ALL you need for a REAL professional 2D graphic pipeline on Mobile!

This is what I'm experiencing with my iPad Pro 12.9 2017.

Cheers.
From: Frenchy Pilou (PILOU)
13 Jul 2018   [#57]
...as third thief free Gravit Designer ;)
https://www.designer.io
From: mkdm
14 Jul 2018   [#58]
Hello Stefan and everyone!

This time I'm going to show you certainly nothing "never seen" or "new" or "special" but maybe a reminder of what we can do thanks with the "Flow" command, especially regardin my beloved "2D workflows" involving Moi and (not in this case) Affinity Designer.

I will play with a simple "Text curve" created with the "Text" command.
You can use any font.

The.3dm test file: http://take.ms/2BAlw

The video tutorial: http://take.ms/wzB6z



In the first part of the video I will use only simple curves, open and closed.
As you will see if we use a "closed" destination curve, sometimes we need to apply first the "Flip" command on the destination curve to get the correct result.

In the final part of the video I will show you some simple scenario with more complex deformations.
In that case I will not apply the "Flow" command directly on the source "Text" curve but on its "3D" counterpart.
I don in this way otherwise I will not get the correct result.

Then I will use the deformed 3D objesct to extract the resulting text curves.

Remember these two things when you have to play with the "Flow" command using surfaces for both "source" and "destination":

1) The "topology" of the surfaces.

2) We will get better results if we work on "trimmed" surfaces using the "ShrinktrimmedSrf" command.


I hope I made myself clear enough with these simple example :)
You can text on you r own more complex things.

Ciao!
From: amur (STEFAN)
14 Jul 2018   [#59]
Hi Marco,

very good! Thanks a lot!

Regards
Stefan
From: mkdm
14 Jul 2018   [#60] In reply to [#59]
My pleasure :)
That was only a very simple example of how Moi, used in the right way, can be a great helper for any professional 2D workflow and "vector related" things.
Consider that sometimes I leverage on Moi to create also "supporting graphics" for my digital painting experimemts.
This is something that it's hard to see "chained" with a 3D Nurbs modeler...

Marco (mkdm)
From: Frenchy Pilou (PILOU)
14 Jul 2018   [#61]
Cool tut...
Moi can do Texts also on 3D volume! ;)
From: mkdm
14 Jul 2018   [#62] In reply to [#61]
Yes!! :)
From: mkdm
14 Jul 2018   [#63]
Hello everyone!

Here's another funny use-case related on how to use Moi to easily create symmetry-stylish elements that we can easily "bring to life" in Affinity Designer.

Here's the video of the making-of: http://take.ms/rxAnc

From this:



To this!:




These are the custom commands that I have used:

FatLines by Max Smirnov
MirrorRotateHistoryArray by Michael

And these are the standard command that I have used:

ShrinkTrimmedSrf
planarsrf
BooleanUnion
sketchcurve


You can find the commands FatLines and MirrorRotateHistoryArray inside this archive: http://take.ms/GuQwX

Ciao!
From: amur (STEFAN)
15 Jul 2018   [#64]
Hi Marco,

very nice. I was also thinking yesterday about antique greek patterns... :-)

https://www.shutterstock.com/de/image-vector/circle-ornament-round-frame-rosette-ancient-155564927

Regards
Stefan
From: mkdm
15 Jul 2018   [#65] In reply to [#64]
Thanks Stefan!

Regarding "greek patterns" yes, Moi is very well suited for that kind of stuff :)

Imagination is the only limit!
From: amur (STEFAN)
15 Jul 2018   [#66]
Hi Marco,

i am already working on a math related pendant which will include such a greek pattern... :-)

Regards
Stefan
From: mkdm
15 Jul 2018   [#67] In reply to [#66]
Cool! I'm sure that it will be very nice.

Show messages:  1-7  8-27  28-47  48-67  68-87  88-90