PDA

View Full Version : How to determine if current object has a VMap of a particular type?



sami
06-23-2011, 06:56 PM
I'm working on some Lscripts for Lightwave to Unity workflow that I hope to give away for free if they are useful. Can anyone please help me with this? I've searched and experimented and don't know if it a bug or if I don't know how.

I'm trying to determine if the currently active Modeler object has weight maps of a particular type in it. I believe this is how you do it:


vmap = VMap(VMMORPH) || error("No morph maps in this mesh!");

And that sort of works but it reports as true even if another object has morphmaps but is not the currently active object, but just happens to be loaded in Modeler.

I've read the docs (assuming I have the latest ones) and I can't tell if the VMap agent returns all maps for all loaded objects or for just the currently active one.

I'm sure this is a quick n' easy one line response from all you killer LScripters out there. Any help would be greatly appreciated :)

sami
06-26-2011, 04:49 AM
I've searched through lots of scripts that use Vmaps, but my test scripts keep returning ALL available morphs in ANY open object.

How do I tell which of these are related to the currently active object open and visible in Modeler?? Is it something to do with the lyr layer commands?

any thoughts would be appreciated! :)

evenflcw
06-26-2011, 05:48 AM
Within the Modeler and Layout enviroment vertex maps are managed in a global list, shared by all objects (to my understanding). As such there is no quick way to determine what vmap is used in what layer or object, other than test all the layers/objects vertices. Hopefully LW10 will change odd design choice as we are not dealing with <100K objects anymore, and not just a few either.

The code you provided just gives you the first vmap of that type in the enviroment, from the shared list, not for the active layer or object.

Ps. I think the reference docs provide enough example code to show you how to check vertex map assignments, atleast for all continuous types (ie all but UVs).

sami
06-26-2011, 07:47 AM
Hi evenflcw,

Thanks for replying. Can you please elaborate on the algorithm you are talking about where you say "test all the layers/objects/vertices"?

How can I test the vertices of the object with the map? I mean if Object1 has a vertex at (1,2,3) but that vertex is not included in the map how can I tell if that map belongs to that object? plus similar geometrical objects would have the same vertices but be differnt objects with different maps.

Would another approach be to attempt to say "Apply Morph" or set a weight value for that map on the currently active object and test if that fails somehow and if not Undo?? and if it fails then the map is NOT part of the current object?

Any thoughts on the approach would be great.

Btw. Can you please give me a link to the LATEST LScript docs and/or tell me what the latest version is, and if there is a later version with LW 10 released. I could not tell by searching the forums. A new version of LScript would be a reason for me to upgrade from 9.6.1 to LW 10

thanks :)

evenflcw
06-26-2011, 10:24 AM
You can find the vmap value of any point by using the points identifier and ismapped() vmap object method. See below.

Empty vmaps, with no points assigned, belong to the environment only. These vmaps (handles) will eventually be garbage collected. Meshes do not hold references to unused vmaps. A vmap "belongs" to a mesh only if atleast one point is assigned to it and stops belonging if you remove all assignments.

You might be able to abuse existing functions like ApplyMorph. You'll have to try yourself. But I doubt you'd be able to get something out of it. Function calls like that rarely return a success or fail value, and any vmap (name) can be assigned to any vertex to any object, so you will never get a failed assignment unless your syntax or input is somehow faulty.

Docs (pdfs) can be found on the install cds (although broken on some), used to be on lightwaves webiste, likely on newteks ftp, and likely linked somewhere on the forum. You'll have to look for them yourself. These pdf have not been updated since first release. For some later updates to lscript you'll find release notes in the SDK documentation. This site contains info from original pdfs and some release notes http://www.mikegreen.name/Lscript/Lscript%20Index.html.

Some example code. This is a quite slow operation for a number of reasons. I ended up not using them for this reason. (It wasn't critical to my script; but would have been convenient).


GetUVMapsFromMeshA: mesh { //slower and crash prone?
maps= nil;
map = VMap(VMTEXTURE);
while(map && map.type == VMTEXTURE) {
all_maps += map;
map = map.next();
}
for(m=1; m<=all_maps.size(); m++) {
for(i=1; i<=mesh.pointCount(); i++) {
if(all_maps[m] && all_maps[m].isMapped(mesh.points[i])) {
maps += map;
break;
}
}
map = map.next();
}
return maps;
}
GetUVMapsFromMeshB: mesh {
maps=nil;
all_maps= nil;
map = VMap(VMTEXTURE);
while(map && map.type == VMTEXTURE) {
all_maps += map;
map = map.next();
}
for(i=1; i<=mesh.pointCount(); i++) {
for(m=1; m<=all_maps.size(); m++) {
if(all_maps[m] && all_maps[m].isMapped(mesh.points[i])) {
maps += all_maps[m];
all_maps[m]=nil;
break;
}
}
}
return maps;
}

sami
06-26-2011, 10:11 PM
This is disappointing for my script's performance and also a bummer assuming I wanted to create a "bulletproof" LScript that does 'error correction' for the user and check that everything is OK before proceeding.

But your reply is fantastic. Thank you for taking the time to explain it and give the example code. I very much appreciate your response! :)

I will have a look at doing it that way (maybe as a separate button on my interface) and maybe use the progress meters to see if this is viable. But with many maps loaded this would be rather impractical.