Wings 3D Development Forum
how to make plugins from the command line - Printable Version

+- Wings 3D Development Forum (https://www.wings3d.com/forum)
+-- Forum: Wings 3D (https://www.wings3d.com/forum/forumdisplay.php?fid=1)
+--- Forum: Programming (https://www.wings3d.com/forum/forumdisplay.php?fid=7)
+--- Thread: how to make plugins from the command line (/showthread.php?tid=2681)



how to make plugins from the command line - hartsantler - 09-08-2018

I am trying to figure out how to create simple shapes from the command line (using expressions and not compiling it as a plugin), here is what i have so far that is not working yet.

Code:
BuildShape = fun(Prefix, Fs, Vs, PostFix) ->
    We = wings_we:build(Fs, Vs),
    Name = Prefix++PostFix,
    St = wpa:get_state(),
    Shapes0 = element(1, St),
    Shapes = gb_trees:insert(0, We, Shapes0),
    erlang:setelement(1, St, Shapes) end.

Tetrahedron = fun(L, PostFix) ->
    Xi = L/2.0,
    Hp = math:sqrt(3.0),
    Li = Xi*Hp,
    Zi = Xi/Hp,
    Yi = L * math:sqrt(2.0/3.0),
    Yf = Yi / 3.0,

    Fs = [[2,1,0],[1,2,3],[1,3,0],[3,2,0]],
    Vs0 = [{ 0.0,  Yi-Yf,  0.0},
       { 0.0, -Yf,   Li-Zi},
       { -Xi, -Yf,     -Zi},
       {  Xi, -Yf,     -Zi}],
    BuildShape("tetrahedron", Fs, Vs0, PostFix) end.

Tetrahedron(1.0, "1").

The error i get is:
Code:
** exception error: no function clause matching
                    gb_trees:insert(0,
                                    {we,undefined,0,[],
                                     {array,6,10,undefined,
                                      {{edge,0,1,2,0,4,2,1,3},
                                       {edge,0,2,0,3,3,0,2,5},
                                       {edge,0,3,3,2,5,1,0,4},
                                       {edge,1,2,1,0,5,4,0,1},
                                       {edge,1,3,2,1,2,0,3,5},
                                       {edge,2,3,1,3,4,3,1,2},
                                       undefined,undefined,undefined,
                                       undefined}},
                                     none,none,
                                     {4,
                                      {2,0,
                                       {1,3,{0,0,nil,nil},nil},
                                       {3,1,nil,nil}}},
                                     {0,nil},
                                     {array,4,10,undefined,
                                      {0,0,1,2,undefined,undefined,undefined,
                                       undefined,undefined,undefined}},
                                     {array,4,10,undefined,
                                      {{0.0,0.5443310539518174,0.0},
                                       {0.0,-0.2721655269759087,
                                        0.5773502691896257},
                                       {-0.5,-0.2721655269759087,
                                        -0.2886751345948129},
                                       {0.5,-0.2721655269759087,
                                        -0.2886751345948129},
                                       undefined,undefined,undefined,
                                       undefined,undefined,undefined}},
                                     {0,nil},
                                     default,6,none,none,[]},
                                    st) (gb_trees.erl, line 276)



RE: how to make plugins from the command line - micheus - 09-08-2018

I think it can be related to the same problem you have been experiencing in the other topic. Anyway, did you already took a look at this article: http://scorpius.github.io/tut-wings-shell.htm
If not, maybe it can help you.


RE: how to make plugins from the command line - hartsantler - 09-20-2019

Im still interested in automating Wings from the command line, but didn't have any luck hacking the source code directly. It would be great to have support for a simple macro language that could be used to generate models from the command line. Something like:
wings.exe --script "make_cube(x,y,z);scale(x,y,z);move_point(index,x,y,z);color_face(index,r,g,b);save_as('foo.wings');"


RE: how to make plugins from the command line - micheus - 09-20-2019

Hi hartsantler
Did you already checked the erlang script that dgud included in the sources? It's called wings_convert.erl and there is some conversation about it in this feature request post.

I think that may help you, but please let we know if not.


RE: how to make plugins from the command line - hartsantler - 09-21-2019

i saw that post, and have read wings_convert.erl. And that solution would work fine for me locally on my machine, but what about windows users? Its too much to ask them to install an erlang environment.


RE: how to make plugins from the command line - micheus - 09-21-2019

Understood.

I did a test here and I got a code working using my dev environment (MSys), but not using the built version.
I use this command line:
werl +S1 -pa /F/unixlike/src/wings/ebin -run wings_start start -extra --script 'make_cube(x,y,z);scale(x,y,z);move_point(index,x,y,z);color_face(index,r,g,b);save_as(foo.wings);'

But, a Windows shortcut adjusted to use the werl.exe under Wings3D install dir didn't work. Only dgud can help with that because it's beyond my erlang knowledge. Smile

If the any parameter would be catch by Wings3D, then you can just write a plugin to handle your script.
I added the code below to my w.i.p. plugin:
PHP Code:
init() ->
    
Script pick_script(init:get_plain_arguments()),
    
io:format("\nScript: ~p\nCommands:\n",[Script]),
    
Commands string:split(Script,";",all),
    [
io:format(" => ~s\n",[Cmd]) || Cmd <- Commands,  string:trim(Cmd)=/=""],
    ...
    
true.

pick_script([]) -> [];
pick_script(["script"|Params]) ->
    [
Script|_] = Params,
    
Script;
pick_script([_|Params]) ->
    
pick_script(Params). 

and the log got this printed out:
Code:
Script: "make_cube(x,y,z);scale(x,y,z);move_point(index,x,y,z);color_face(index,r,g,b);save_as(foo.wings);"
Commands:
=> make_cube(x,y,z)
=> scale(x,y,z)
=> move_point(index,x,y,z)
=> color_face(index,r,g,b)
=> save_as(foo.wings)



RE: how to make plugins from the command line - dgud - 09-23-2019

I have added the needed things to the wings installer so (after next release) you should be able to run,
the wings_convert script from command line without installing erlang, if I have done it correct :-)

Some hacks are involved, so to run other scripts you will have to run:
wings/bin/escript.exe <your_escript>


RE: how to make plugins from the command line - hartsantler - 09-24-2019

@micheus and @dgud, you guys are awesome!


RE: how to make plugins from the command line - dgud - 12-09-2019

Please test, 2.2.5 :-)