Jump to content
  • Advertisement
Sign in to follow this  
BaSSraf

Path trace / extrusion / tesselation problem

This topic is 5392 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey there, if you dont feel like reading the usage description skip between ***** ********* I'm using a font outline (GDI, BeginPath etc) to tesselate (GLU) the font's faces. After that, I create the sides of the (now extruded) font. Ok, the problem i'm having is with beveling the font, at first I just scaled the path I use for the outline and connected the samller version of the path to the bigger version, that seemed to work, until I noticed (and it makes sense) that scaling doesnt always work since some points shouldnt be scaled from the center of the letter, for example imagine the letter S, a simply downscaled version of that same S wouldnt fit inside a bigger version. (the ends of the letter would not be in the middle of its bigger version, and so the bevel wouldnt be evenly distributed/centered) The only way I think I can solve this problem is by tracing the outline from the "inside" (at a distance) so it would give me a smaller but fitting and centered path. ********* My problem is, I cant seem to find a clean solution to trace/follow the path I get from the GDI functions (which are just connected line coords) into a smaller version of the path. for info on the 'paths' I use i'm talking about the GDI paths, for reference: http://www.mvps.org/EDais/Tutorials/GDI/DC/DCch7.html Anyone dealt with something like this before? or any other way to get a nice bevel on the edges of my meshes (3D letters) ? ANY hints, tips, tricks, approaches are welcome, its taking me ages already :) Thanks guys.

Share this post


Link to post
Share on other sites
Advertisement
Thinking about it, my problem would be solved if I knew how to "trace" a parallel path on the inside of the known path.
(i'll go fiddling with that, any help still welcome)

Share this post


Link to post
Share on other sites
At each vertex of the font outline, where two edges meet, you need to find the vector that bisects those two edges. There are a few ways to do this, one way is to take a cross product of each edge and a vector in the z direction (0,0,1), and then average that result.

After you have a vector pointing outwards (or inwards), you just have to move your vertex along that vector an appropriate distance.

This however, will not solve problems where a self intersecting polygon will be produced. Serif's on fonts will produce these prolems very quickly. If these are a problem for you, you'll need to find some algorithms to detect self intersections, and remove them.

- Phil

Share this post


Link to post
Share on other sites
thx Phil, call me a dumbass, but is this the way to go:

I calculate the normals of the two meeting edges by adding a vertex in Z to each edge's 2 vectors (to make triangles), I crossproduct each, so I have two normals, and then average these normals, and move the mid vertex of the two edges along this resulting average normal ?

Like that? (thx in advance phil)

Share this post


Link to post
Share on other sites
Thats pretty much it, but heres some diagrams to go along with it this time.

B------C
|
|
|
A


And we want to move the point A inwards.

so we go:
Normal = (0,0,1)
direction = 0.5 * ((B-A) cross Normal + (C-B) cross Normal)

Now we need to calculate how far it needs to move. If all the edges need to be moved inwards X units, then the distance that each point will move will be slightly different, because all the angles at each point will differ.

How is your trigonometry?

Share this post


Link to post
Share on other sites
Thanks Phil,

My trigonometry is OLD but things fell into place, and I got it working now :)
I only have some weird things happening in a few corners but I think I can tackle that in a few minutes.

Again, thanks a lot and best regards,

Bas

Share this post


Link to post
Share on other sites
Ok, maybe not.. :)

I still have a problem which I cant seem to resolve..

Look at the images below, the first is the original outline (tesselated) and the second is my smaller, incorrect version.





(1) For each line segment, I calculate the normal by adding a vector (0,0,1) to the 2 line segment vectors.

(2) Once I have all segment normals, I average 2 line segment normals to get the correct normals for each corner-point of the segments, afterwards I normalize these averaged normals.
cornernormal = normalize((normal1 + normal2) / 2)

(3) I run through the original outline segments and add the normal values multiplied by an offset, so the original points move inwards.

It seems to work a little, but as you can see at picture 2, not all lines are parallel to its original...

I have 2 clues but cant seem to work out any of then, clue 1: adding 0,0,1 as an intermediate vector is incorrect, clue 2: i'm not combining the 2 segment normals correctly so the resulting vector is "pointing" in the wrong direction and hence the incorrect placement of the new point.


Any clues?, thanks a lot, Bas :)

Share this post


Link to post
Share on other sites
Quote:
Thinking about it, my problem would be solved if I knew how to "trace" a parallel path on the inside of the known path.
(i'll go fiddling with that, any help still welcome)


As i understand, the problem is:

you have a poligonal closed path with vertices V1...Vn
, in 2D, (you probably can project your 3D to 2D)
, winded clockwise(and our coordinate plane have x to right, y pointinh to up),

you want to, for each vertice V calculate a vertice V' that is "inside" the path, at distance r from path.

First, let's define
vec2 perpn(vec2 a){return normalized(vec2(a.y,-a.x));}

Let V'=V+D

I can see that what you need is D so

DotProd(D,perpn(V-V[i-1]))=r
DotProd(D,perpn(V[i+1]-V))=r
where r it's distance you want.

Warning: this may NOT work for some shapes and too big r *.

It gives us simple system of linear equations

D.x*perpn(V-V[i-1]).x+D.y*perpn(V-V[i-1]).y=r
D.x*perpn(V[i+1]-V).x+D.y*perpn(V[i+1]-V).y=r

Solving it for D left as exercise of the reader ;-).

****
* for some shapes problem is kinda harder - after moving vertices by D 'em may become too close to other line segments... it can be solved. But probably you'll not have this problem.

Share this post


Link to post
Share on other sites
Thanks for your reply Dmytry,

Isnt that in fact what i'm already doing?, as far as I can see, i'm doing exactly that, but in addition I average the normals I get from each segment so the placement of the V' is evenly distributed in each corner (at least thats the plan..)

if I read your proposal correctly, it looks like you're only creating a parallel to the vector not taking the corners into account?

Thanks, Bas

Share this post


Link to post
Share on other sites
Quote:
Original post by BaSSraf
Isnt that in fact what i'm already doing?


Not quite. It is almost the same, but the final step that you're missing is being able to account for the different angles at each corner, something that solving for D will automatically account for.

I'll whip up some diagrams now, and post them shortly.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!