Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Generating backfaces

Author
Message
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 14th Jun 2011 13:08
I'm trying to generate backfaces (I believe that to be the correct term at least; what I want to do is make single-sided triangles double sided) for a mesh using the vertexdata commands. I've come up with the following function, which doesn't quite work, and was wondering if anybody could give me a nudge in the right direction.


The reason I'm trying to achieve this is so that I can raycast from within a mesh to get its average size at certain points.


Thanks for any advice,
Rudolpho


"Why do programmers get Halloween and Christmas mixed up?"
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 14th Jun 2011 13:24
Won't you have to invert those normals to turn the polygons into backfaces?

Wondering though, why you don't just double up the intersection checks, like swap the sets of coordinates to detect backfaces instead, if the first check fails then check again with the coordinates switched. Works for me, I'm using Sparky's collision to vertex lightmap a bunch of objects.

Health, Ammo, and bacon and eggs!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Jun 2011 16:46 Edited at: 14th Jun 2011 17:09
Edit:

Oops!! I can't read. I'll post again when I've cleaned my glasses.

Edit2

Quote: "Won't you have to invert those normals to turn the polygons into backfaces?"


I'm not 100% sure but I think the problem is that each face has been welded to its backface in that code so they use the same vertexdata - and hence each face has the same normal as its backface. In other words inverting the normals won't help you.

I think one solution is to create a second set of vertices as well as indexdata. Also, what happens if the object doesn't have index data?
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 14th Jun 2011 17:50
Ohh, that's no good!

Maybe it would be better to keep the objects seperate, like have a standard visible object, plus an inverted one, check collision on both to allow for backfaces, but on display the standard one.

Or just swap the intersection check coordinates to allow for backfaces - I'm sure there's an easy way around all this backface tomfoolery.

Health, Ammo, and bacon and eggs!
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 14th Jun 2011 18:02
Quote: "...swap the sets of coordinates to detect backfaces instead"

Do you mean the arguments to the raycast function? If so, that's what I did at first. However, that only works if the mesh doesn't "go around itself". For example, consider the point of origin lies within a character's upper arm / shoulder. One of the casts from the side will be thoroughly wrong as it will hit the torso (or even the other arm) instead. If you meant it any other way, would you please elaborate?

Quote: "I think one solution is to create a second set of vertices as well as indexdata."

That's worth trying.

Quote: "Also, what happens if the object doesn't have index data?"

I know it currently only supports meshes with index data, but it's still in the early stages, so I'll get to that later

Quote: "Maybe it would be better to keep the objects seperate, like have a standard visible object, plus an inverted one, check collision on both to allow for backfaces, but on display the standard one."

I thought about that on my way home too. Seems like the easiest thing to do, especially since this will only be used in a editor-like application with rather few such objects, so there shouldn't be any overhead tradeoffs worth considering. I'll try that out after supper.

Thanks both of you.


"Why do programmers get Halloween and Christmas mixed up?"
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 14th Jun 2011 18:38
I take it your using built in collision?

I would consider giving Sparky's a try - it can find all the collision points - so even if it goes through 'layers' of polygons, it will return the closest one, or them all, then you could step through them. Sparky's won't detect collisions on backfaces, but it works out if it's a backface depending on the origin of the collision check. So, a sphere would not register a collision if it goes from it's center then outside the sphere, but it would detect a collision going outside, then to the center.

Health, Ammo, and bacon and eggs!
Matty H
17
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 14th Jun 2011 18:52
I know scaling a sphere by a negative value will turn it inside out, would that help at all here?

Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 14th Jun 2011 21:41 Edited at: 14th Jun 2011 21:43
I'm actually using Sparky's, although it didn't spring to mind that it could do that (even though I know I've seen it in the documentation now that you say it).
Works a charm, thank you very much

As for setting the mesh to a negative scale, no, that doesn't quite work (for one thing it will be mirrored along all three axis' as well). Maybe with some tweaking though, haven't really tried it.


"Why do programmers get Halloween and Christmas mixed up?"
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 14th Jun 2011 22:48
I don't know if this helps, but I believe that doing set object <obj>,1,1,0 makes DBP set all faces of the object to be 2-sided, and it should accept ray casts in that state. Correct me if I'm wrong

TheComet

Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 15th Jun 2011 09:51
I think that's disabling culling, so I'm not sure that'll make much difference - as Sparky's takes the object and breaks it down into it's own format. So even though the backfaces are showing, I don't think collision will be affected.

Health, Ammo, and bacon and eggs!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 15th Jun 2011 23:05 Edited at: 15th Jun 2011 23:07
No I've tried allowing (cull) the backfaces to show and they don't affect collision. I'm assuming it's the orientation of the face that makes the difference.

EDIT: Maybe to gen a backface would just be to dupe each tri/face and reverse it's order. The same would possibly go for the normals and uv.

Warning! May contain Nuts!
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 16th Jun 2011 00:37
Quote: "Maybe to gen a backface would just be to dupe each tri/face and reverse it's order."

One would think that should work. It's what I tried in my original code snippet up in the opening post. Doesn't quite work however.
It might be that one would have to duplicate the vertex data as well and not just the indices, as GG suggested.


"Why do programmers get Halloween and Christmas mixed up?"
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 16th Jun 2011 05:24
wait, so you what VanB said doesn't solve your problem?

one thing you could try: Scale the object by a negative value, DBPro recalculate normals, then scale it negative again. Might work.


Why does blue text appear every time you are near?
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 16th Jun 2011 11:46
Yes, it did solve it.
Then people keep on hijacking my thread...


"Why do programmers get Halloween and Christmas mixed up?"
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Jun 2011 14:53
Quote: "Yes, it did solve it.
Then people keep on hijacking my thread"


Now I'm confused.

If it solved it why is there still a problem?

Also, I can't see anyone hijacking your thread. They all seem to be trying to help.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 16th Jun 2011 15:08
Yes, and how did you solve it. It would be interesting to see how that was done...

Warning! May contain Nuts!
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 16th Jun 2011 15:13
Haha, no, it is indeed solved.
Hijacking might not be the correct term, but what I meant is that people kept on feeding me solutions even after Van B's approach did the trick for me (post 6 from the top), which apparently led to people thinking it was still an unresolved issue

Quote: "If it solved it why is there still a problem?"

My point exactly, there is no problem any longer.


"Why do programmers get Halloween and Christmas mixed up?"
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Jun 2011 15:29
Quote: "after Van B's approach did the trick for me (post 6 from the top), "


Ah! You mean the collision thing not his first suggestion?

Quote: "My point exactly, there is no problem any longer."


Good.

Looks like a simple misunderstanding to me. This statement led me to think there was still a problem:

Quote: "It might be that one would have to duplicate the vertex data as well and not just the indices, as GG suggested."

Login to post a reply

Server time is: 2026-07-10 22:55:11
Your offset time is: 2026-07-10 22:55:11