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 / Splitting 1 object into 2 along a plane

Author
Message
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 4th May 2011 05:14
I mean the normals of the vertices. And I don't quite get the purpose of vertex normals since I thought only the "facing in or out" of the faces matters.
Also I got some code that adds vertices by memblocks however the code ends up getting rid of all the indices in the mesh. I don't have the code with me atm because it's on another computer, will post it asap.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th May 2011 13:15
Quote: "And I don't quite get the purpose of vertex normals since I thought only the "facing in or out" of the faces matters."


It depends on what kind of object you have. If it has sharp edges like a crystal then you want face normals, but if you want a smooth curved surface like a sphere then the vertex normals have to be some sort of average of neighbouring face normals so each vertex of a face will have different normals. This allows the lighting calculations to give a smooth transition across the edges of the faces.
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 5th May 2011 01:53 Edited at: 5th May 2011 01:54
Found this image to demonstrate normals:


All the objects have the same vertices and faces, but one has smoothed normals (ie. vertex normals) and one just has flat normals (ie. face normals). You can see it makes a big difference for curved objects. The middle one is half and half.

[b]
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 5th May 2011 02:24
TBH, if you have a triangle, and you know what side the normal direction is, then you can calculate that face normal, and then you can calculate each vertex normal. HOWEVER this is annoying to calculate, and results in longer loading times. It's a lot faster but uses more memory and is way more convenient than recalculating everything all the time.


Tell me if there's a broken link to images in a thread I post, and I'll fix 'em.
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 5th May 2011 13:53
Ok, so thanks for the info on vertex normals.
So here's the code I have so far but it's not working properly. It should add 3 vertices to the object however it isn't working properly. It seems to delete all the indices and add 15 vertices.


Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 7th May 2011 21:05
C'mon, does anyone have any advice on making objects with memblocks??

Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 7th May 2011 21:44
Quote: " ...it's not working properly."
Quote: " It seems to delete all the indices..."

Memblocks don't contain indices, only vertices. When you convert the object to memblock you lose all the index data. Since the object can't have indices when stored as memblock, it needs to be converted to vertexdata only so there's no shared vertices -> thats probably the reason of 15 additional vertices you reported.

example: Let's say you have a box
Before converting to memblock box will have 24 vertices and 36 indices.
After converting to memblock box will have 36 vertices and 0 indices.

If you need indices for you code to work you'll have to use vertexdata and not memblocks.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 8th May 2011 00:40
Ok thanks for that info, that explains a lot. So my code is actually working but not to the right intension. I need indices so I guess I'll just use ian's command and fill the newly created object with data. But how fast is it in real time to create a complete new object and fill it with vertices?
I'll get to coding and will post back with any problems I run into.

Jimpo
21
Years of Service
User Offline
Joined: 9th Apr 2005
Location:
Posted: 8th May 2011 01:44
Quote: "C'mon, does anyone have any advice on making objects with memblocks??"

Don't do it? The vertexdata commands will do everything you need, produce cleaner easier to understand code, and you can edit an object in real time without having to convert from memblock to mesh.

If you want to add vertices to an object using vertexdata, just use the add mesh to vertexdata command.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th May 2011 14:20
The vertexdata commands should be at least as fast as memblocks, maybe very marginally faster.

There may be a difference in using different lock modes (which will occur when unlocking), but you'll have to experiment with that.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 10th May 2011 13:47
Ok, got a question. Is it posible to lock multiple mesh's vertexdata at once or do I have to lock one mesh, copy 1 part of data such as x,y,and z positions, unlock it, lock the other mesh, paste that data to it, then unlock that, and repeat that entire process for each vertex?

Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 10th May 2011 15:25
Quote: "Is it posible to lock multiple mesh's vertexdata at once"

no

Quote: "or do I have to lock one mesh, copy 1 part of data such as x,y,and z positions, unlock it, lock the other mesh, paste that data to it, then unlock that, and repeat that entire process for each vertex?
"

you can do that or you can lock one mesh, copy all it's data to array and then lock other mesh and paste that data from the array. That way you will have to lock and unlock vertexdata only twice.

Locking and unlocking for every vertex could be slow on a meshes with lots of vertices and indices.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 12th May 2011 05:19
Ok, so this is my code so far. It copies the old mesh into the new mesh correctly but the face that the function is supposed to add doesnt show up. Also, what is the unit for vertex positions? Is it just dbpro units or is it out of 1.0?


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th May 2011 12:17
Are you sure the face isn't there? Could it just be facing the wrong way? Try turning off culling to see if this is the problem.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th May 2011 15:23
Haven't tested the code, but this seems wrong:
Inds=GEt vertexdata vertex count()

Shouldn't that be:
Inds=GEt vertexdata index count()

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 13th May 2011 00:33
Whoops, that was a mistake when i was cleaning up the code. But it doesnt matter since it was tested befor that mistake.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th May 2011 01:08
I've taken a little more time to read your code, and it seems like you are making your code more complex than it really needs to be.

I think what you are trying to accomplish is to have a function that you can use to add a new face to an existing object on demand.

Here's how I'd do it:


If it needs to be faster then I'd consider keeping a mesh permanently in place that can be edited and added to the target object on demand rather than create it and delete it each time as I have here.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 13th May 2011 05:23
What if I have a pre existing object like a cube with 24 vertices? Will it still add the 3 vertices to make that object have 27 vertices or will it see that the pre existing vertices is less than the vertices with the 3 new ones and not add them at all?

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th May 2011 08:17
It will add - it will always add 3 vertices and 3 indices. It won't do anything about avoiding duplicate vertices, that's for you to add to this code if it's important to you.

The only requirement that this code has is that the object you are adding to must be using indexes, as that seems to be what you wanted.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 15th May 2011 05:44
Is there any specific advantages to using "lock vertexdata for limb" as apposed to locking it for a mesh?
Also I tried recoding your working code Iam because I learn best from doing that but my code isn't working. What mistakes have I made?


IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th May 2011 10:44
Quote: "Is there any specific advantages to using "lock vertexdata for limb" as apposed to locking it for a mesh?"

No, can't think of any. In fact, it might be faster to manipulate the mesh than the object - try it and see.

Quote: "What mistakes have I made?"

You aren't setting any index data. Your additional 'mesh' is using only the first vertex you've added, making a face from a single point - obviously nothing will show for a zero-sized face.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 15th May 2011 15:45 Edited at: 15th May 2011 15:52
Thanks for that info. I got it working now.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 17th May 2011 13:56
So now that I can create faces, I need to be able to make a loop cut using that. Is there any specific algorithm I should follow?

Login to post a reply

Server time is: 2026-07-10 18:02:24
Your offset time is: 2026-07-10 18:02:24