PDA

View Full Version : Selecting Surface of Mesh in Layout



faulknermano
01-08-2009, 08:06 AM
just an experimentation trying to get around the limitations of LScript.

personally, i know of no way to use the polygon id as returned by:



mesh = Mesh(0);
poly = mesh.polygons[1];


though the poly var indicates an index number it does not appear to be truly a Polygon OA. if i use:



srf = poly.surface;


i only get unknown data member errors for that. in modeler, the surface data member is recognised, so i hit upon an idea of utilising ModCommands. the idea of the script is that Layout calls on a Modeler script, which supposedly puts it into a state that makes some LScript funcs work. this Modeler script stores the surface name via registry, and the Layout script, still in execution, retrieves the name and puts the appropriate command over to CommandInput().

here is the Modeler script:



// this script is the modeler counterpart of SelectSurfaceOfMeshGN.ls
main
{
pc = editbegin();
mesh = Mesh(0);
poly = polygons[1];
srf = poly.surface;
editend();
globalstore("SelectSurfaceOfMeshGN_surfacename",srf);
}


here is the Layout script:


generic
{
mesh = Scene().firstSelect();
CommandInput("ModCommand_SelectSurfaceOfMeshMODGN");
srf = globalrecall("SelectSurfaceOfMeshGN_surfacename","");
if(srf)
{
str = string("Surf_SetSurf \"",srf,"\" \"",mesh.filename,"\"");
CommandInput(str);

}
}


both scripts must be added as plugins for it to work. also, you only need to run the Layout script.

(though i may have used the ComRing to communicate between Layout and Modeler, i am still not familiar with it; so i used globalstore() / globalrecall() for this experiment.)

adamredwoods
01-08-2009, 11:05 PM
Clever!

Does Modeler have to be open to work?

faulknermano
01-08-2009, 11:08 PM
nope. :)

adamredwoods
01-09-2009, 02:10 PM
Do you know which Modeler functions don't work? Can I create new geometry?

faulknermano
01-09-2009, 07:35 PM
i haven't specifically experimented on ModCommands, so i'm not sure which ones work in Layout. as with all i'm experimenting as i go.

Cageman
01-09-2009, 10:39 PM
Hmm...

So this means that Janus may be updated to support individual surface overrides? :)

faulknermano
01-10-2009, 07:34 AM
Hmm...

So this means that Janus may be updated to support individual surface overrides? :)

ah, it already does. :)

no, this technique does not necessarily help in such measures when dealing with Janus. the problem with any feature that is attached to a plugin like Janus is how it is implemented both programmatically, and user-friendliness, or user-logical-ness. :)

Alexx
03-31-2010, 08:44 AM
Hi,

Great idea :)
By the way, where did you get informations about this ModCommand stuff ??

I'm always amazed by people showing LScript functions coming from nowhere (at least not the official manual)

faulknermano
04-01-2010, 05:16 PM
I believe I got it from just saving out the Layout command list. When I noticed that there was a ModCommand section, I kind of figured that it was related to Modeler, and tried to experiment to what degree can Modeler commands affect the state in Layout.

Alexx
04-01-2010, 09:33 PM
I believe I got it from just saving out the Layout command list. When I noticed that there was a ModCommand section, I kind of figured that it was related to Modeler, and tried to experiment to what degree can Modeler commands affect the state in Layout.

ok, thanks, I'll investigate this ;)

Alexx
04-16-2010, 01:18 PM
Hi,

This trick seems to not work on mac os :(

the globalrecall function can't find the value saved by globalstore...

faulknermano
04-16-2010, 06:33 PM
I can't confirm because I don't have access to a Mac, but you can always use files to write out the same information out.

Danner
04-16-2010, 10:05 PM
sorry if this is a bit off topic. But found this thread and thought you guys might know.

On the link below there is a Modeler Plugin called SelectSurface, one keystroke and it opens the surface editor and automatically finds and selects the surface of the highlighted polygon.

http://www.lwplugindb.com/Search.aspx?Tag=Select

I have grown so used to this (and so lazy in naming my surfaces because of it) that it's an unbearable pain to use modeler64 in complex scenes. Is there any Lightscript or alternative for 64bits?

you just made a chair and want to add a similar surface from an existing door knob to the legs of a chair.

With awSelectSurface.p:
Click on the knob, hit shortcut for SS, copy, click on the legs, SS, paste.

Without the plugin:
"how did I name that surface? door knob? chrome? shinny? hmm.. let me try this one.. hmm no, that's not it.. searching on my list of 75 textures.. ok I give up.. I'll select part of the knob, hide everything else, check on the statistics pannel. ahh it's called silver doh.. open surface editor, look for silver. copy. good thing I just created the chair legs surface.. so I know it's called... where is it? ah there it is.. paste.


Of course this was just a fictional example. (maybe) :D

Alexx
04-17-2010, 01:09 AM
I can't confirm because I don't have access to a Mac, but you can always use files to write out the same information out.

I'll try, but I'm not sure it will be fast enough to get the info back in the layout script, maybe using a sleep() command will do the trick...

evenflcw
04-17-2010, 08:18 AM
sleep() won't (shouldn't!) help because lscript has no multithreading. So sleep() won't be called until the previous operation (globalstore or whatnot) is done anyway. Writing two scripts thinking it will give you two threads likely won't work either as I think LWs overall architecture is linear aswell. It wont process two script simultaneously. So one doesn't need to wait for the other. It will process them in a predefined linear order.

Did you try the regular store() and recall()? Globalstore() save values between LW sessions, whereas store() are only valid for the duration of the current session. It doesn't seem like you really need to store with "global". On windows the globalstore values are stored in the windows registry. On mac, I don't know. I don't know were the store() values are stored.

evenflcw
04-17-2010, 09:10 AM
Danner

A quick script. Bottom of page. PickSurface. Modeler only. Opens the surface editor and picks the surface of the last selected polygon. And btw there does not appear to be a way to pick multiple surfaces.
http://people.dsv.su.se/~dan-dulb/evenflow3d/index.php

Also, I'm not sure if the L in LScript actually stands for Light. I think the name is simply LScript. Ie, nothing is abbreviated. If anything I'd think the L stood for Lightwave.

Alexx
04-17-2010, 09:29 AM
sleep() won't (shouldn't!) help because lscript has no multithreading. So sleep() won't be called until the previous operation (globalstore or whatnot) is done anyway. Writing two scripts thinking it will give you two threads likely won't work either as I think LWs overall architecture is linear aswell. It wont process two script simultaneously. So one doesn't need to wait for the other. It will process them in a predefined linear order.

I'll try anyway that way, in modeler script :

write data to a file
sleep(100);

layout script :

commandinput(-> modeler script)
sleep(100);
read data from file created by modeler script

that way, I hope it will let enough time to the hard drive to write down the data and let the layout script read it juste after




Did you try the regular store() and recall()? Globalstore() save values between LW sessions, whereas store() are only valid for the duration of the current session. It doesn't seem like you really need to store with "global". On windows the globalstore values are stored in the windows registry. On mac, I don't know. I don't know were the store() values are stored.

store() and recall() are 'local' to the script, the data written in the registry are associated with the script name

globalstore() and globalrecall() are not linked with the script, so these datas can be shared between different scripts

evenflcw
04-17-2010, 09:37 AM
store() and recall() are 'local' to the script, the data written in the registry are associated with the script name
globalstore() and globalrecall() are not linked with the script, so these datas can be shared between different scripts

Ah. I never quite remember all the differences and always find them not exactly what I want or need. You get this, but not that, and unfortunately you get this too. :)

Other than that. Try you might and should. That seems to be what 80% of my lscript dev time is all about. Testing to see if things work as I think they will/should.

Maybe I should start taking notes?

Danner
04-17-2010, 10:42 PM
Evenflcw

You just made my day, so I hope my little donation made your day.

=)

evenflcw
04-17-2010, 11:16 PM
Thanks Danner! That was very nice of you. I think you may indeed have made my day! :king: I've been coding some other stuff all through the night and this gives a nice boost to continue the work. Maybe I can skip sleep today! :help:

Thanks for the donation and thanks for suggesting the script.

evenflcw
04-18-2010, 12:16 AM
I had another look at the script. Felt I had to after that response! I did some needed testing and found three situations were the script failed. The script is now updated. 2 out of 3 found bugs fixed. The third one even AWs version seems to suffers from. Likely nobody noticed or bothered because it's a rare case. But I think it can be solved.

evenflcw
04-18-2010, 04:46 AM
Script was updated again (v1.3). Third bug taken care of, I hope. Now it's able to figure out whats what even when multiple objects are in the foreground. It's abit slower than AWs plugin, but, for now, it's more reliable. I hope.

Scripters: Is there any way to get the identifier of a selected polygon without entering (full) meshdataedit mode? There's no recent speedup version? I think the main thing that is slowing the script down is the enumeration of point/polygon elements (on calling mesheditbegin()). There might be no way of avoiding that though.

Danner
04-18-2010, 09:58 AM
:thumbsup: makes adjusting surfaces in modeler so fast and easy I truly think everyone should use it.

faulknermano
04-18-2010, 08:04 PM
Script was updated again (v1.3). Third bug taken care of, I hope. Now it's able to figure out whats what even when multiple objects are in the foreground. It's abit slower than AWs plugin, but, for now, it's more reliable. I hope.

Scripters: Is there any way to get the identifier of a selected polygon without entering (full) meshdataedit mode? There's no recent speedup version? I think the main thing that is slowing the script down is the enumeration of point/polygon elements (on calling mesheditbegin()). There might be no way of avoiding that though.

You can try selhide(UNSELECTED), and then call editbegin(). That _may_ bypass the enumeration.

evenflcw
04-19-2010, 06:42 AM
Very sneaky! It does indeed appear to work. But it seems enumeration is limited with explicit selection and selmode(USER) and selmode(DIRECT) aswell. Makes sense, but I never tested that. Hiding seems to limit the same way (you can enter selmode(GLOBAL) before meshdataedit and it will be limited like under selmode(USER)). selhide() might still offers an extra speed boost, but it is too small to notice or its eaten up by the hide/unhide operation itself. I'll guess I'll have to be content it can't be instant feedback in every situation. Thanks for the suggestion Lernie.

faulknermano
04-19-2010, 01:47 PM
Ah! selmode(DIRECT) is a good idea. Besides selhide() is not good practice because the user might have hidden something beforehand, and if you try to revert back by using selunhide() it may not be what the user expects.

evenflcw
04-19-2010, 01:56 PM
Yup. I figured that too. One should be watchful in changing the state of an object for somewhat arbitrary reason (read:for a hack). Sometimes you have to though.