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 / Welding Vertex Data?

Author
Message
Alquerian
19
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 18th Apr 2007 03:27
Is anyone familiar with a way to weld vertex data in dbp? Of course you can do it in external modeling apps, but is there a codewise method of doing this?

If I am not mistaken all of the mesh/memblock commands do not allow you to do this.

Anyone have any obvious or unusual suggestions?

Visit the Wip!
The ARRAYinator
19
Years of Service
User Offline
Joined: 13th Aug 2005
Location:
Posted: 18th Apr 2007 03:46
I don't believe it is natively possible. I assume its impossible to do it with memblocks because there is not even the ability to make shared verts so that being said its safe to assume its probaly not possible without maybe a plugin(I don't even know how this would work,lol). Hope this helps and please correct me if im wrong because I hope its possible too



Milkman
19
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 18th Apr 2007 04:26
Of course this is possible! You just need to figure out the correct algorithm to build the necessary new triangles. If i have some spare time, i'll work on this.

Who needs a signature?
david w
19
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 18th Apr 2007 05:29
I have been thinking about this also, and it may be possible. I think you would have to build an array of the points that contain the same info. like a lookup table, and then share them in that sort of a fashion. Does that make sense, cause it does to me. LOL.........
Ron Erickson
Moderator
22
Years of Service
User Offline
Joined: 6th Dec 2002
Location: Pittsburgh, PA, USA
Posted: 18th Apr 2007 06:31
I just wrote a routine that does this for a contract job. It's not for DBpro, but the concept would be similar.
I have though about writing a "Mesh Tools" plugin for DBpro. I'm too busy at the moment though. It could become an interesting secondary project.

The best way to do this would be to access the mesh data in c++. For welding the vertices, you would want to look for verts that are within a threshold distance of each other and have similar UV coordinate data. You would create a new vertex list by running through each vert. If the vert that you are checking is unique, you add it to the new list. If you find a vert with similar criterea, then you have to average the 2 verts normals and change any poly indice reference of the vert to the "existing" vert.

When your new vert list is built, then you would have to change the pointer of the mesh's vert list to the "new" vert list, then delete the old vert list. Simple as that lol

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Apr 2007 13:05
Quote: "then you would have to change the pointer of the mesh's vert list to the "new" vert list,"


How do you do that in DBP?

I've already implemented the first part of your suggestion in a prototype object editor of mine - but couldn't see how to get the object itself to use the unique vertex list directly via either memblocks or vertexdata commands. Is that where C++ comes in?
Ron Erickson
Moderator
22
Years of Service
User Offline
Joined: 6th Dec 2002
Location: Pittsburgh, PA, USA
Posted: 18th Apr 2007 13:43
Quote: "Is that where C++ comes in? "

Yes. I don't think there would be any other way to do it other than accessing the object format through C++. I would suggest that the entire process be done through C++ for the most efficient results.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Apr 2007 15:33
You do have access to the vertex and index data for all of your objects, so you can do most of the job in DBPro - you can't change the number of vertices or indices directly though, which is a shame. I'm also unsure if all objects have indices or not - that's something to find out.

So, if all object have indices, and you can get to the size value for each mesh in the object, it should be possible to do this completely within DBPro.

A little experimentation is required I think ...

Ron Erickson
Moderator
22
Years of Service
User Offline
Joined: 6th Dec 2002
Location: Pittsburgh, PA, USA
Posted: 18th Apr 2007 15:47
Quote: "So, if all object have indices, and you can get to the size value for each mesh in the object, it should be possible to do this completely within DBPro."

Maybe, but why? It would be much easier and more efficient to do something like this from C++. When working on something this iterative, I would imagine ANY fraction of performance increas would be very beneficial.

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 18th Apr 2007 15:49
However, one does question the point of welding the vertices at run-time?

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
Alquerian
19
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 18th Apr 2007 18:07
Quote: "However, one does question the point of welding the vertices at run-time?"


One may question it all they want. DBP isn't just for games.

Visit the Wip!
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 18th Apr 2007 19:32
Wrong answer - if you look closer you'll see that what I posted was a question. My point is that if the use of it isn't in real-time then performance isn't so much of a factor. Of course, there are uses for real-time applications, such as in a terrain editor, I am interested to see if any others have ideas for uses of it.

Quote: "DBP isn't just for games."

Well done, however I wasn't implying that it isn't. Moreover, while I acknowledge that it has other uses, I do feel that it doesn't excel in applications as much as it does in games. Of course, this has nothing to do with the topic at hand so let's not discuss our opinions on this.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
Alquerian
19
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 18th Apr 2007 19:40
In a way I understand your point[s], however welded vs. non-welded vertices do have an impact on performance. Take an object with half a million polys with welded vertices and take an object with half a million non-welded vertices and you will see a difference in real-time applications. Additionally, it makes it easier to modify vertex data where you can modify 1 vertex and it alters multiple polys where with non welded, you would need to resize/shape your polys individually.

I hope that clarifies it for you.

Visit the Wip!
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 18th Apr 2007 19:42 Edited at: 18th Apr 2007 19:45
Quote: "however welded vs. non-welded vertices do have an impact on performance"

Agreed - in a test I did with a 20k poly mesh I got about a 50% increase by using welded vertices. However, this is not what I'm talking about. I'm talking about doing the welding in real-time, and the applications of it. For example a game doesn't need to do the welding, as the models should be pre-welded before loading.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Apr 2007 19:45
@WOLF & Benjamin,
Sure, it's going to be slower than doing it in C++, but what if performance isn't an issue? What if runtime isn't in the middle of a game, but in other utilities for the preparation of media - for example, it's a simple method to make some objects use less space, will make them render more efficiently, and provides smoothing if the normals are averaged.

Also, what if Alquerian wants to work out how to do it, without having to learn C++ (obviously, only if he doesn't already!), or learning how DBPro plug-ins work? Working out how to do it in DBPro is more useful in these forums than knowing how to do it in C++ anyway.

Anyway, I don't mean to be confrontational about it - it's an interesting exercise that others might get some mileage from

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 18th Apr 2007 19:48 Edited at: 18th Apr 2007 19:49
Quote: "Sure, it's going to be slower than doing it in C++, but what if performance isn't an issue?"

No, my point is that in applications such as games where you will only have to do the vertex welding at one time, there is little point doing it during execution, the model file should already contain the pre-calculated data. This, it doesn't matter whether it is done in DBP or C++, or how fast the calculation is (within reason).

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
Alquerian
19
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 18th Apr 2007 19:48
Quote: "I'm talking about doing the welding in real-time, and the applications of it."


It has many applications. It doesn't take much of an imaginative stretch to think of a few, so I am leaving that up to you.

Visit the Wip!
Alquerian
19
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 18th Apr 2007 19:50
Quote: "No, my point is that in applications such as games where you will only have to do the vertex welding at one time, there is little point doing it during execution, the model file should already contain the pre-calculated data."


This leads me back to my previous comment:

Quote: "DBP isn't just for games."


Visit the Wip!
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 18th Apr 2007 19:50 Edited at: 18th Apr 2007 19:53
Quote: "It has many applications. It doesn't take much of an imaginative stretch to think of a few, so I am leaving that up to you."

Right well what exactly was the point of your initial reply to me? To try to contest something I didn't say?

Quote: "This leads me back to my previous comment"

If you would stop trying to argue against what I'm saying, and properly read my posts, you'll see that I'm not implying doing it in real-time is useless. It has many uses, however what I am pointing out is that when it doesn't need to be done in real-time, there is no point doing it in real-time, and thus the language used doesn't matter as speed isn't an issue.

I'm not arguing about which language should be used, or whether it would be useful to do it in real-time or not, I'm simply stating a point.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
Alquerian
19
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 18th Apr 2007 19:55
Benjamin - Please quit littering this thread with witty quips and argumentative attitude. I do not know if you are having a bad day or whatever, but your questions and comments are not constructive in any way. I have no problem with you, please stop.

Visit the Wip!
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 18th Apr 2007 19:58 Edited at: 18th Apr 2007 20:00
Quote: "but your questions and comments are not constructive in any way"

Neither was your initial reply to me.

Quote: "Please quit littering this thread with witty quips"

Look, I can't help being extremely witty, but I'm not the only one littering this thread. I came and made a simple point and you gave a nonsense reply. Now, it's taken all of these posts to make you realise that I was just stating a simple point, let's let it rest.

Another thing, when you finally realise you make a mistake, don't tell the other person he is arguing and posting useless non-constructive comments on a thread, he is simply correcting you. I don't like arguing, but I must attest what I am saying.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
Alquerian
19
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 18th Apr 2007 20:03
Ben, check your mail, lets keep our differences off the forums.

Back on subject

Quote: "Also, what if Alquerian wants to work out how to do it, without having to learn C++ (obviously, only if he doesn't already!), or learning how DBPro plug-ins work? Working out how to do it in DBPro is more useful in these forums than knowing how to do it in C++ anyway.

Anyway, I don't mean to be confrontational about it - it's an interesting exercise that others might get some mileage from"


Ian, that is a perfect example of what I want to do. Having a dll do it would be great, but if it could be done in dbp it would be advantageous to many.

Visit the Wip!
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 18th Apr 2007 20:15
The biggest problem with doing it in DBP is that (as far as I know) there is no way to set the amount of vertices and indices you want. Once you've done this, it's possible using the vertexdata commands.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
Ron Erickson
Moderator
22
Years of Service
User Offline
Joined: 6th Dec 2002
Location: Pittsburgh, PA, USA
Posted: 18th Apr 2007 20:19 Edited at: 18th Apr 2007 20:20
I agree. It would be a useful learning tool for people wanting to dive into this kind of thing.
Good luck with it.
PS. Don't forget the vertex weighting info for mesh deformation!


If I ever do start to create a "mesh tools" plugin, this is something that I would definately include

Alquerian
19
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 18th Apr 2007 20:30
Quote: "PS. Don't forget the vertex weighting info for mesh deformation!"


What does this exactly mean? Do you mean when you modify a vertex, it modifies surrounding vertices as well?

Either way, it looks like I am in for a bit of a ride here. By the time I figure it out, I bet WOLF will have already finished his plugin

Visit the Wip!
Ron Erickson
Moderator
22
Years of Service
User Offline
Joined: 6th Dec 2002
Location: Pittsburgh, PA, USA
Posted: 18th Apr 2007 20:43 Edited at: 18th Apr 2007 20:44
Quote: "Either way, it looks like I am in for a bit of a ride here. By the time I figure it out, I bet WOLF will have already finished his plugin "


lol

Quote: "What does this exactly mean? Do you mean when you modify a vertex, it modifies surrounding vertices as well?"


For each vertex of a mesh, there is information (or could be information) stored about how it would follow the movement of each bone.

For instance, say you have an object with 3 limbs. Lets say it is a leg. The first limb is the upper leg bone. It has no mesh. The second limb is a lower leg bone. Again, it has no mesh. The third limb is the mesh. It contains all of the vertex and poly information. This mesh needs to know how to follow the upper and lower leg bones. The vertices that are near the top of the leg would completely follow the upper leg bone. The vertices that are near the bottom would need to completely follow the lower leg bone. The vertices that are near where the "knee" would be would need to proportionaly follow BOTH bones.
In short, each vertex carries information about how each bone influences it's position.

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 18th Apr 2007 22:24
Quote: "PS. Don't forget the vertex weighting info for mesh deformation!"

Not necessary for static meshes. I'd expect that if one wanted vertices welded in an animated object, they'd just have a modelling package do it. There may be exceptions of course..

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
Johaness
18
Years of Service
User Offline
Joined: 20th Sep 2006
Location:
Posted: 19th Apr 2007 06:59
Quote: "I'd expect that if one wanted vertices welded in an animated object, they'd just have a modelling package do it. There may be exceptions of course.."


Yeah. Like for player modified/customized characters. Right now my only solution is to replace entire mesh parts and/or glue add-ons. Can be rather limiting. If the verts could be welded while maintaing vertex weights....something I would love to have.

@WOLF: Weren't you working on something like that?
Cash Curtis II
20
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 19th Apr 2007 07:11
Alquerian is not using animated meshes. Specifically, he's trying to use this in his terrain editor. It shouldn't be nearly as complicated.


Come see the WIP!
Alquerian
19
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 19th Apr 2007 07:46
Right, I am not using it for animation at all. So my goal is actually relatively less lofty than one which would require animating. I am doubtful of my ability to achieve this natively in dbp, so I am forcing myself to relearn C++ so I can attempt to do this with the use of an external dll. I may fail miserably but at least I will have brushed up on my C++ in the process

Visit the Wip!
Lost in Thought
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 19th Apr 2007 13:21
So you are using this for terrain ... Have a look at the .x file format and write a manual exporter with shared verts(indices). The only way I can think of doing it in DBP would be to export the object and reload it. It will then have the shared vert/ indice info.

TinTin
19
Years of Service
User Offline
Joined: 16th May 2006
Location: BORG Drone Ship - Being Assimilated near Roda Beta (28)
Posted: 19th Apr 2007 14:39 Edited at: 19th Apr 2007 14:46
Here is a possible solution
First build an array containing all the verts then sort through them (see psuedo code)

Scan the array and remove all the merged verts.
once thats done rescan the original memblock and write a new memblock by compairing the reasigned verts and changing the values to match the merged vert.

it's so mutch clearer in my head....

Cyberspace was becoming overcrowded and slummy so I decided to move. These nice chaps gave me a lift.
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Apr 2007 20:05
Quote: "Scan the array and remove all the merged verts.
once thats done rescan the original memblock and write a new memblock by compairing the reasigned verts and changing the values to match the merged vert."


But you will be back where you started - lots of verts with identical XYZ data, etc. What is wanted is a means of changing ONE set of vertex values so that all the vertices which are really the same as that vertex get adjusted automatically without having to go through the memblock->mesh->object sequence. The vertexdata commands are somewhat easier - but if you are creating non-standard objects in DBP code (e.g. terrains) you still need to modify the shared vertices individually - unless I've missed something.
Alquerian
19
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 19th Apr 2007 21:08
Quote: "So you are using this for terrain ... Have a look at the .x file format and write a manual exporter with shared verts(indices). The only way I can think of doing it in DBP would be to export the object and reload it. It will then have the shared vert/ indice info."


I am doing this now, I am having a look at .X and .DBO. Once I come to grips with their data structure in C, I think I will have a way of reading and writing shared vertex data natively in DBP. Converting it from C to DBP will be a little work, but not too large to accomplish .

Visit the Wip!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Apr 2007 21:20
@Alquerian,
It turns out that this can all be done within DBPro, and without any plug-in assistance - I wasn't aware of the DELETE MESH FROM VERTEXDATA command until I studied Lee's original example code.

Here's the removal of duplicate vertices from a cube:


The undim's are at the start of the weld function so that the working data for the previous weld is available for re-use. You can move them to the end of the function if you want.

Let me know if you find any objects that this doesn't work for.

@TinTin,
The problem with your idea is that memblocks don't have a concept of an index to vertices, so you can't use a memblock to re-create the welded object. Anyway, it's a solved problem now

Alquerian
19
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 19th Apr 2007 21:24
@IanM - Outstanding, I am giving it a shot now and I will inform you of my results!

Visit the Wip!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Apr 2007 21:30
I forgot to mention - the matching of vertices is done simply by coordinate - You will need to change the function to take account of UV coordinates, and if you use diffuse in your objects then you might want to include that too.

Alquerian
19
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 19th Apr 2007 21:47
Thanks a million Ian! I got it to work with a little fiddling with the code I just had to rearrange a few commands and it worked.

I am going to try it out on more objects and then with multiple limbs to see what I come up with.

I would like to keep this thread going for everyone who is interested in furthering this discussion.

Thanks again Ian!

Visit the Wip!
Ron Erickson
Moderator
22
Years of Service
User Offline
Joined: 6th Dec 2002
Location: Pittsburgh, PA, USA
Posted: 19th Apr 2007 21:49
Nice work Ian!

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Apr 2007 22:33
Thanks guys. Although you'd think by now I'd have gotten out of the habit of making 'minor cosmetic changes' without testing before posting the code

I've found an improvement to make already.

The usage count in the first version was automatically set to 1 as I made an assumption that the object wouldn't already have the vertices welded.

In this new version, the usage count on each vertex is started at zero, and incremented only when an index references it. When a match is made, the entire usage count is transferred to the matching vertex. The normals transferred to the matching vertex are also weighted by the usage count being transferred across.

What this means is that the usage count is a true count for each vertex and that vertices that would not have been removed in the original code will be removed with this version.

Just the one function to replace:


To be honest, I'm not sure that I've got the averaging of the normals right, but apart from that, it continues to work well.

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Apr 2007 23:01
Quote: "unless I've missed something"


Looks like I did! Thanks for that demo IanM - I'm looking forward to giving it a go.

I can try it on DBP spheres (which have redundant polys).
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Apr 2007 23:17
There's something still not quite right there - I only get the top quarter of the sphere showing. Ah well, I'll pick it up again tomorrow.

david w
19
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 20th Apr 2007 00:14
omg this is great. I was gonna look into this on the weekend, but now I dont have to. Thanks a million, this is really gonna help me out.

Thank you.
Alquerian
19
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 20th Apr 2007 00:21
Quote: "There's something still not quite right there - I only get the top quarter of the sphere showing. Ah well, I'll pick it up again tomorrow."


I tried spheres and cylinders as well, and they did not work.. I suspect it is due to the way they are created (tri-strip method) which is causing the problems. Cubes and cones work great though I will give er a go with multiple triangles that I make and combine into a limb.

Visit the Wip!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Apr 2007 00:52
That could be it. It works if I add this to the start of the weld function:


I guess that making the object limb into a mesh causes it to be converted to standard poly's. I also found out that memblock meshes don't have any indices as I tried that first.

I've a few other ideas about this anyway - some of them might mean dipping into calling dlls though, which is a shame.

@Green Gandalf,
The poly's may seem redundant, but there should be an overall gain in speed from keeping everything in a strip (sphere) or a fan (I'm surprised that cones aren't fans). Or maybe with modern cards it doesn't really matter any more.

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Apr 2007 01:43
Quote: "The poly's may seem redundant"


Which ones? The ones at the poles (which I can understand) - or the ones along the "date-line" (which I don't).

Quote: "Or maybe with modern cards it doesn't really matter any more."


I confess I never checked that. Another job on my task list.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Apr 2007 01:47
Sometimes it's necessary with a strip to have one or two extra poly's at a change of direction, for example, to create another row around the sphere - I haven't studied DBPro's sphere format enough to tell if this actually is the case though.

Alquerian
19
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 20th Apr 2007 02:20 Edited at: 20th Apr 2007 02:33
I spent a few mins making a side-by-side comparison using welded and non-welded spheres in this little demo. Notice how the welded vertices accept light in a different manner. What do you make of that?



Visit the Wip!
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Apr 2007 02:41
I suspect the normal calculation.

This looks wrong for a start.



Where's the division?
Alquerian
19
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 20th Apr 2007 02:50
umm... dunno ask Ian

Visit the Wip!

Login to post a reply

Server time is: 2025-08-08 12:05:52
Your offset time is: 2025-08-08 12:05:52