PDA

View Full Version : Where to begin?



Frigo
03-19-2003, 03:48 AM
Hi all, this is my first thread on this forum, i'd like to say hallo to all of u first, now the questions:

1-Where do i have to begin? :-)))
2-Does script control any part of 3d stuff? This is because i need a resource that does not exist, a something that unwrap my mesh on a single plane without distortion.

thx

faulknermano
03-19-2003, 05:59 AM
1.) download and read the LScript User Guide. great place to start. if you need more introductory info, look at:

http://members.shaw.ca/lightwavetutorials/

under Programming.


2.) doesnt Unwrap do that? at any rate, that sounds like an ambitious project.. ambitious enough for me at least. :) good luck.

Frigo
03-19-2003, 06:23 AM
Thx, for the suggestion. Unwrap only paint an image based on an existent uv. The only thing that is similar to what i want to make is "polygon normal uv" plugin, but the polygons are all detached and one over the other. I saw that for 3ds max there is a freeware plugin called chilli skinner that to exactly what i want. I give u the link, so u can see if it is possible to do with lw script:
http://www.chilliweb.co.uk/chilliskinner/index.htm

Tom Speed
03-19-2003, 08:23 AM
Hi,

To be honest I think Modeler has all the basic UV tools you really need. Also there's some nice free UV plugins for Modeler available to aid in creating / editing them.

When you come to create UVs, everyone will have their own ideas on how their UVs should look, so any 'smart UV tools' won't make everyone happy, and I've yet to see any that produce results that I find acceptible, or don't require at least some editing afterwards.

If I were you, I'd check some of the many LW UV tutorials that are about, and refine your workflow. Practice on various shapes, and after a while you'll be able to look at any model and immediately know how to tackle it :)

Access to UVs, or any 'VMAP' type for that matter, is good in LScript. I still consider myself an amateur LScripter (my general programming style is messy!), but I have managed to script some UV related tools for specific tasks.

Any questions, fire away and we'll try and help :)

Cya!
Tom

Frigo
03-19-2003, 08:52 AM
Ok, lets see the image at this link:

http://www.fabioannunziata.com/images/unwrap_workflow.jpg

this is a perfect unwrap of an object (i mean without polys distortion) using standard modeler tools. Here's the workflow:

1-Build the mesh
2-Edit standard UV for paint a texture
3-Apply your texture on the mesh
4-Use Polygon normal UVs plugin to create another texture without distortion
5-All the polygons on the new UV are now overlapping so you have to manually adjust them
6-In layout bake the texture on the new perfect UV

what the plugin i have in my mind have to do is to automatically execute the point 5 of this workflow. Do you think is possible?

whattawa
03-19-2003, 12:20 PM
For those that do complex models with UVs, LW will be found lacking. If you want a way to have no distortion in the unwrap, DeepUV is the way to go.

Sure, you could use current UV tools and try to get it just right, but when you have a program that has a 'relax' function where it resizes all the polys that you have projected so that they are the same size as the physical polys (in relation to eachother) you get little or no distortion. There is still the need for the user to know how to unwrap a model, where to put the seams, etc. But, after you have unwrapped it, you 'relax' it and there won't be distortion.

I would think, then, that your ideal situation would be to find a way to program a relax plugin that would do what I just mentioned. It would be very difficult because of the intense math that must be done to compute all that, but it might be possible if you have time and patience.

Tom Speed
03-20-2003, 01:55 PM
Hi,

I had a little mess about with this stuff. What I have so far is just a UV spacing type tool. No scaling is taken into account so it's very simplistic. I've commented along the way so hopefuly you'll understand what & how I'm trying to do :)

I've attatched a picture showing a 'before & after' result of using it.

PLEASE BACKUP ANY WORK BEFORE USING!



// Script to evenly space Normalised UVs without distortion.
//
// Created as a test in response to Frigos querey regarding overlapping UVs after using
// the 'Polygon Normal UVs' command in Modeler.
//
// Limitations:
//
// Your mesh must be unwelded
// Every point must be mapped
// It doesn't take size difference into account
// It's only a test / experiment!
//
// Tom

@warnings
@version 2.6
@script modeler
@name Even Space UVs


main
{
selmode(USER); // Work with ONLY the selected Polys
uvmap=VMap(VMTEXTURE,0) || error("No UV Map selected"); // Grab currently selected UV map

data=polycount(); // data[] now has various info about the Polys
PolyCount=data[1]; // data[1] has the actual Poly count

// find the smallest grid all the Polys will fit in
// i.e a grid of 5*5 would fit 25 polys
m=1;
while(m*m < PolyCount)
m++;

GridScale=1/m; // the size of our grid squares
gx=0; // our grid x and y starting coordinates
gy=0;

editbegin(); // start mesh edit session
foreach(Pol,polygons) // traverse each Poly
{
u=v=PolPntID=poldata=nil; // kill u[], v[] & PolPntID[] arrays

poldata=polyinfo(Pol); // poldata[] now equals: surface name, Point1 ID, Point2 ID, Point3 ID ..e.t.c
PolPntCnt=poldata.size() - 1; // how many Points in this poly
// (-1 because the 1st element is a surface name which we don't need)

for(n=1;n<=PolPntCnt;n++)
{
PolPntID[n]=poldata[n+1]; // load PolPntID array with just the Polys Point IDs
values=uvmap.getValue(PolPntID[n]); // get U & V values for this Point
u[n]=values[1]; // U value for Point 'n'
v[n]=values[2]; // V value for Point 'n'
}

// we now have to scale all the U & V values down to fit in 1 square of our grid
// start by finding the size of this Polys UVs
// use first Points values as a start, and compare against the remaining values

MinU=u[1];
MaxU=u[1];
MinV=v[1];
MaxV=v[1];

for(n=2;n<=PolPntCnt;n++) // start checking from 2
{
if(u[n] < MinU)
MinU=u[n];

if(u[n] > MaxU)
MaxU=u[n];

if(v[n] < MinV)
MinV=v[n];

if(v[n] > MaxV)
MaxV=v[n];
}

// MinU,MaxU,MinV,MaxV are now the boundaries of this Polys UVs
// we don't want to distort the Polys UV shape (we want to scale it down evenly to fit in a square)
// we use the larger of the UVs width or height to determine the size of the 'square' it will fit in

USize=MaxU - MinU;
VSize=MaxV - MinV;
UVSize=max(USize,VSize);

DownScale=GridScale / UVSize; // the value
DownScale *= .95; // contract the UV inwards to avoid possible pixel blending
mx= 0 - MinU;
my= 0 - MinV;

// test to see if the Polys UV is flipped/reversed
// probably not needed as Polygon Normal UVs seems to create correct facing UVs
norm=cross3d(normalize(<u[2],v[2],0> - <u[1],v[1],0>),normalize(<u[3],v[3],0> - <u[1],v[1],0>));
if(norm.z >= 0)
facewrong += Pol; // if it is, add this poly to a list

for(n=1;n<=PolPntCnt;n++)
{
// mx & my are values to add to this polys UVs to move it to very bottom left corner
// we add these to each UV like so: 'u[n]+mx' now we multiply this value by the DownScale
// '(u[n]+mx) * DownScale )' this will make this poly fit neatly within 1 of our 'grid'
// squares with no distortion, now me move it to the appropriate position on the grid
// '+gx' and +gy'

values[1]=((u[n]+mx) * DownScale ) + gx + .0025;
values[2]=((v[n]+my) * DownScale ) + gy + .0025;
uvmap.setValue(PolPntID[n],values); // set the new UV values for this Point

}

gx=gx + GridScale; // move to next square on our grid
if(gx >= (1 - GridScale) + .0025) // if we're at the end of this row (measurements taken from Left side)
{
gx=0; // move row back to 0
gy=gy + GridScale; // move column up 1
}

}
editend(); // end of Mesh edit session, all UV editing gets updated in Modeler

if(facewrong) // if any flipped UVs were found, select the offending Poly
{
selmode(USER);
foreach(f,facewrong)
selpolygon(SET,POLYID,f);
}

//
}


Have fun!
Tom

Frigo
03-20-2003, 06:02 PM
Thx a lot Tom, this will be very useful. The only thing that i need now is something that "snap" the polygons each other on the uv window, 'cause at now i must zoom in very close to two polys to reduce the gap, and this is a very tedious work. Do u think is possible to select two polys and let a script snap the two points that those triangles have in common? I know im askin' a lot and u should think "why the hell this man dont just sit there and map his mesh as all the others do???"... eheh, because i need to build my mesh for real, i mean print the opened mesh on paper and build my model as the one planned in Lightwave...

thx again