PDA

View Full Version : I need a simple planar uv script



Dennik
02-28-2011, 01:03 PM
I've no idea where to begin, but I need to make a simple script that takes the selected points and applies a planar uv along z axis.
That is without requester boxes, and the texture map can be any name.
I have to do this many times so I'd rather assign this to a shortcut that points to that script instead of going through the create uv map procedure every time.
Same as with new UV map procedure, top vertex should have a v=1 value and bottom vertex should have v=0.
I don't care about the U values, they can all be zero.

Can someone please help me with this?
Thanks a bunch!

Dennik
02-28-2011, 02:38 PM
Ok I'm moving very very slowly by myself as I have no lscript experience, but I'd like to have this ready hopefully soon.

I'll be adding some code slowly as I progress.



main
{
selmode(USER);
pntCnt = pointcount();
if(pntCnt == 0)
error("No points selected.");

info (pntCnt);//number of points selected.
}

next would be finding highest and lowest Y point values to be able to normalize each point within the UV range.

Dennik
02-28-2011, 08:46 PM
Ok I decided to apply a weight map on these points instead. That was actually my intention for this, so the whole deal is to just normalize the selected points y values and apply those as % weight map on each point. I was originally doing this through uv2weight but since I can do it directly that's even better!


@version 2.6
@warnings
@script modeler

main
{

selmode(USER);
pntCnt = pointcount();
if(pntCnt == 0)
error("No points selected.");

editbegin();
myVmap = VMap(VMWEIGHT,"weight1",1);
hi_y=0.0;
lo_y=0.0;
for (currPnt=1;currPnt<=pntCnt;currPnt++)
{
point_c=pointinfo(points[currPnt]).y;//find coordinates of current point
if (hi_y<point_c)
{
hi_y=point_c;
}
if (lo_y>point_c)
{
lo_y=point_c;
}
}

editend();
info (hi_y);

}

Ok here is the min max calculation so far. Seems to be working.

Dennik
02-28-2011, 09:18 PM
Well its late and I have no idea how to create a new weight map or set its value for each point. I hope someone can give me a hint tomorrow!

Svenart
03-01-2011, 02:00 AM
Im not very sure, but maybe this can help:

The VMap Object Agent can also create user-defined vertex maps
in Modeler. The method used is nearly identical to the method for
creating a new vertex map from a pre-defined type. To generate a
custom vertex map, you must provide a custom map type instead
of a pre-defined type identifier. Custom map types are a unique
four-character sequence, housed in an initialization block.
For example, to generate a vertex map of type NMBK, named
my_normals, with two data elements per point, you use the
following code:

@define VMAP_NMBK @'N','M','B','K'@

normMap = VMap(VMAP_NMBK,"my_normals",2);

this is from the lscriptreference.pdf site 133

Dodgy
03-01-2011, 05:40 AM
http://www.mikegreen.name/Lscripts.html#Images_To_Planes

This has some example code for creating a vmap from scratch. It used to be the case you had to create the Vmap in a separate editbegin() session to modifying it to have it work (hence how my code does it), but they fixed that in a later 9 release.

Dennik
03-01-2011, 06:28 AM
Thank you both for your suggestions!
I have to do some reading. Still very new to this... Before I learn anything much I'll probably have to scrap it and move to Python in the next release. hehe.

Dennik
03-01-2011, 08:06 AM
Well, that was easier than what I expected. Done!

Again, what this does is to create a gradient weight based on point selection normalized y values. Couldn't find a plugin that does exactly that so I made one!


main
{

selmode(USER);
pntCnt = pointcount();
if(pntCnt == 0)
error("No points selected.");

editbegin();
myVmap = VMap(VMWEIGHT,"weight1",1);
hi_y=pointinfo(points[1]).y;
lo_y=hi_y;
for (currPnt=1;currPnt<=pntCnt;currPnt++)//loop to find min max Y values
{
point_c=pointinfo(points[currPnt]).y;//find coordinates of current point
if (hi_y<point_c)
{
hi_y=point_c;
}
if (lo_y>point_c)
{
lo_y=point_c;
}
}

for (currPnt=1;currPnt<=pntCnt;currPnt++)//Loop to set weight map values
{
vmapvalue=(pointinfo(points[currPnt]).y-lo_y)*(1/(hi_y-lo_y));
myVmap.setValue(points[currPnt],vmapvalue);
}

editend();

}