Hi Max,
re:
> I tested my Cloth script today.
> It hangs on infinite loop at line 75:
> code:
>
> while ( moi.ui.commandUI.runAnimation ) { moi.ui.commandUI.calcFrame(); }
>
>
> Interface is inactive, viewports not updating.
> Should I add something like moi.ui.update() inside the loop, or rewrite this script using setInterval function?
Yeah this is because of the change in threading model - previously the .js code would run in a separate moi_commandprocessor process and use interprocess communication when your script called any property or method on a MoI object. This has some overhead but protected against the script consuming a lot of CPU or running an infinite loop. The command could be torn down without any cooperation from the script itself. But the interprocess communication overhead was pretty costly for performance, it's why code would run faster if you moved it over into the .htm file since code there ran inside the main process and on the main thread so no interprocess communication needed. For v4 the .js code runs on the main thread now so it won't be necessary anymore to move it over into the .htm file for added speed but the downside is that the script is much more in full control of MoI and if it spins an infinite loop that will lock up MoI now.
So yes in v4 for something with animation setInterval would be the way to go, I should probably add one into MoI's own object model so you don't have to get it from the web browser environment but that will work for right now.
In order to avoid locking up the whole program the script will need to have an event loop where it calls waitForEvent, just spinning an infinite loop with no event loop like the Cloth script was doing previously isn't going to be supported anymore. The plus side of this is you don't need to move code over into the .htm file to gain performance anymore.
Hope that makes sense for what you saw here.
> In fact I would like to read files from any user directory, but I think its impossible in MacOS.
Yes, I guess not unless the process has elevated superuser privileges.
>
moi://appdata is a good idea
I'll add that in for the next beta. Maybe it would be convenient if I also made some of the filesystem functions be able to optionally take
moi:// URLs for paths or filenames too so you could do something like if ( moi.filesystem.dirExists( 'moi://appdata/Objects' ) ) { } , would that be of any use? That way you might not need to glue together pieces of paths quite as much.
Another thing that I think I forgot to mention is that you should now be able to index directly off an object list similar to how JS arrays work like should be able to do curves[2] now instead of needing curves.item(2) .
Thanks, - Michael