PDA

View Full Version : point and poly normals

fortress
12-19-2003, 06:54 AM
ok heres a question how to get the point and/or poly normal

mattbolton
12-19-2003, 11:06 AM
From page 81 and 82 of the LScript Reference Manual.

polynormal
polynormal() returns a vector that represents the surface normal of the specified polygon.

prototype: &nbsp;&nbsp; status polynormal(polygon) (MD)

status &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; boolean; if the operation succeeded.
polygon &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; polygon id; the polygon to change.
surface &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string; surface name to which polygon is now assigned.

I wish I could help more, but I've never used it myself. Knowing where to find the answer is half the battle.

fortress
12-19-2003, 08:16 PM
well duh
heheh thanks missed that one in the docs

CroDude
12-28-2003, 04:41 PM
Here it is about point normals ... You get'em by adding all normals of polys that have 'guilty' point in it and divide it by polycount (numbers of polygons that have point You are interested).

Here is a bit of code I used for this. Originally You can find it in a NormalBaker.ls that come with a LW if I can recollect for certain :

// Get the point normal
numPolys = size(vtxPolygons);

for(k = 1;k <= numPolys;k++)
{
workVal = polynormal(vtxPolygons[k]);
pointNorm += workVal;
}

pointNorm.x /= numPolys;
pointNorm.y /= numPolys;
pointNorm.z /= numPolys;

numPolys is the array with poly IDs that have the point in it.
You can get those by :

pnt = points[i];
vtxPolygons = pnt.polygon();

Hope this helps.

See ya! D ;)

CroDude
12-28-2003, 04:43 PM
Ups! Sorry ...

vtxPolygons is the array containing polygon IDs.

evenflcw
12-28-2003, 10:58 PM
I think you might have been in a bit of a hurry, CroDude. Although someome lines are fine, some doesn't work and an important one was omitted.

When working with normals it is of great importance that you normalize created values:
PntNormal = normalize(AvgeragedSumOfPolyNormals);

If you don't, operations such as pointmove(pnt, PntLoc + PntNormal*Distance), while still moving points along the normals, will not move them the correct distance! Normalizing ensures the values get the correct "scale".

CroDude
12-29-2003, 10:57 AM
Ups again! I forgot to cut it out !

Here it is :

// Normalize point normal vector
pointNormN = normalize(pointNorm);

That one goes to the end...

Hope this helps.

fortress
12-30-2003, 07:13 AM
thanks for all the replys guys
i just got back from a short vacation so ill get a chance to start on this asap
thanks again and happy holidays

fortress
01-10-2004, 05:09 PM
well i looked at that normal baker plugin and that is really going to help alot and save me a lot of time :)

one question i had is would i still need to normalize the point normal if i am just exporting the data to be used in a game

fortress
01-12-2004, 02:22 AM
well hit a big road block i guess i should have said from a layout lscript

i have tried useing the code form this thread and from normalbaker

but it seems like the polynormal function cant be accesed from layout

any other ideas

fortress
01-12-2004, 06:06 PM
well so far the only thing i can think of for a work around is to have ascript that runs in modeler to find the normals of the points

so the next question i hae is it possable to invoke a script from a script (im sure it is but never have done it)

and is it possable to pass data between a modeler and layoput script

fortress
01-13-2004, 04:17 PM
well a easy out is to run normalbaker on the model first then save the model and search for the custom vmap type the normal baker looks for

so that works for me :) until i found a better way or automate that part

thanks again guys for the help

fortress
01-20-2004, 02:29 PM
i had a question as far as normalizing the normals
and getting the normals for points does that take smoothing groups into account

fortress
01-20-2004, 02:37 PM
a better question would be how do you calculate a point normal while to include the smoothing angle as well?

fortress
01-31-2004, 11:37 PM
ok i found where and how to get the smoothing angle of a surface

so the next question is how do you include the smoothing angle in the point normal calculation?

or do you even have to

Lynx3d
02-01-2004, 04:43 AM
What do you need the point normals for actually?

For a displacement plugin it would be useless to include smoothing angle since you can't "split" the points.
For shading that's obviously a different thing.

If you understand C check the scenescan example of the SDK (the "objectdb.c" to be more specific), it calculates the points normals for each polygon seperately, also calculates the poly normals before.
It's a pretty handy example, i based my own normal displacement on it (since LWs is slow and buggy, or i'm to stupid to use it, who knows)

fortress
02-02-2004, 02:14 PM
i need the point normals for an exporter im working on to export from lw to hl1 and hl2 it is part of the hl smd file
as far as i know it is used for shading

ill look into the scene scan plug tonight
i can get the normal fine im just not sure if it is taking the smoothing angle into account

Titus
02-02-2004, 04:08 PM
Some RenderMan primitives need the average point normal for smooth shading, this is more common than you think, in this case when I programmed my LW-RendeMan exporter.

fortress
02-03-2004, 07:46 AM
ok titus may i ask how you et a point normal with the smooth angle taken into account :)

3Demon
02-18-2004, 11:29 AM
cross-posting, hijacking post has been removed.
AAAND...at no extra charge, this user has been banned. ;)