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 Discussion / Vertex Manipulation With Memblocks

Author
Message
Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 29th Jun 2003 18:17
The only example I've seen of this is in the DB help files, although it isn't really that helpful because it doesn't explain anything. I was hoping that someone could explain the basics of memblocks and vertex manipulation with them (I've never used memblocks before), maybe just an example where you choose a vertex and move it, that simple. I just want to know how to access the coordinate information for each vertex and change it at the moment, to deform an object. Thanks in advance !
cuRant PRogekt: a three-de map editer
Why the hell'd you ask me for crying out loud!?!
Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
ReD_eYe
22
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 29th Jun 2003 18:22
i think chiwawa's post in the code snippets board(modeler) uses this memblocks for vertext manipulation

hi guys
andrew11
22
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 29th Jun 2003 18:29
You can see mine too
http://www.darkbasicpro.com/apollo/view.php?t=11300&b=6

It's similar to chiawawa's, but made in DBPro. You can still get some ideas from it though.

"All programmers are playwrites and all computers are lousy actors" -Anon
Click Here!!!
Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 29th Jun 2003 18:37
Thanks, but like I said, I have never used memblocks, I was hoping someone could just give h=me a brief demonstration on how to move one vertex, and what each bit of the code means. I presume the vertices are numbered 0-n and the position is an offset from the object origin? I just want to know how to change the position of it.

Thanks for those examples, I will look at them and try and see what is happening.

cuRant PRogekt: a three-de map editer
Why the hell'd you ask me for crying out loud!?!
Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
andrew11
22
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 29th Jun 2003 20:30 Edited at: 29th Jun 2003 20:32
Here is a quick explanation. With this and the examples, you should hopefully be able to figure it out.



"All programmers are playwrites and all computers are lousy actors" -Anon
Click Here!!!
Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 29th Jun 2003 21:25
Thanks, that got me somewhere, I managed to move a vertex, but only by copying stuff from the examples. I really haven't used anything to do with memblocks, I don't know anything about how they work or store data. The thing that really throws me is what values I need to put in place of 'n'...

memblock dword(1,n)

I see that it has something to do with the number of bytes each value takes up, but I don't have a clue how to use this to find out the value to access different vertices' values. Thanks!

cuRant PRogekt: a three-de map editer
Why the hell'd you ask me for crying out loud!?!
Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
andrew11
22
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 29th Jun 2003 21:32
I'm busy now. I have to go. I'll explain it later, unless someone else does it first.

"All programmers are playwrites and all computers are lousy actors" -Anon
Click Here!!!
The Darthster
22
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 30th Jun 2003 02:27
Ok, hamish, a brief explanation of memblocks containing meshes. I guess you're using DBC, so I'll use that format.

After taking a quick look at the help files, it turns out I've never used the DBC memblock mesh commands anyway, so I'll just have to make it up as I go along.

Ok, the first 32 bytes in the memblock is the header, which contains:

(0) Number of vertices
(4) Byte offset to vertex data
(8) Number of normals
(12)Byte offset to normal data
(16)Number of faces
(20)Byte offset to face data
(24)Size of all face data
(28)Offset to texture coordinates

All these values are 4 bytes (dwords), that is how they are read and written. Having never used the commands before, I can't tell you if the byte offset is from zero or 32 or what, you can probably establish that from experimenting. The numbers in brackets are the positions in the memblock in which you write the data.

Now, the data after that is what you use to create your mesh. You can set any number of vertices, and link up three at a time to make a face. Each vertex in a face has a normal, but the vertices and normals are kept as separate data. The normal of the face is probably calculated based on the average normals of the vertices making up that face. Now, starting at position 32, you can input vertex data, as 4 byte floats. You input 3 floats per vertex, to hold the X, Y and Z positions of the vertex.

'n'th vertex:

(32+(n*12)+0) X position
(32+(n*12)+4) Y position
(32+(n*12)+8) Z position

You can input as many of these as you like, just make sure to put the appropriate offset in the header.

Now, you can create some normals to help light your mesh. A normal is basically a vector that points outwards from the surface of the mesh. (I hope you know what a normal is, that explanation was rubbish). You can set the X, Y and Z components of a normalised normal vector in the memblock.

'n'th normal:

(32+normal offset+(n*12)+0) X component
(32+normal offset+(n*12)+4) Y component
(32+normal offset+(n*12)+8) Z component

These are all 4 byte floats. Again you can add as many as you like, providing you set the correct offsets in the header.

Now, face data. Each face consists of three vertices, and three normals. Also a number of vertices used, but that should always be set to 3. Now, there is an inconsistency in the help files here. It says the face data should be 2 byte dwords. Now this should either be 4 byte dwords or 2 byte words, I'm not sure which, having never used the commands before. As such, the number in the expression for the memblock position to write to should be (n*14) or (n*28) appropriately. Likewise y should increment in steps of 2 or 4 respectively, like in the previous examples.

'n'th face:
(32+face offset+(n*x)+y) Number of vertices (always 3)
(32+face offset+(n*x)+y) Vertex index A
(32+face offset+(n*x)+y) Normal index A
(32+face offset+(n*x)+y) Vertex index B
(32+face offset+(n*x)+y) Normal index B
(32+face offset+(n*x)+y) Vertex index C
(32+face offset+(n*x)+y) Normal index C

You can define a face by putting the indexes (not the memblock positions) of three vertices, and three normals to use with these vertices.

Lastly, you can input texture data. Each vertex has a U and V value for it's texture coordinates. These come right at the end of the memblock, and are 4 byte floats.

'n'th vertex's texture coordinate:
(32+texture coordinate offset+(n*8)+0) U coordinate
(32+texture coordinate offset+(n*8)+4) V coordinate

Hope that helped, I didn't explain it very well.

It's late now, but tomorrow I'll try to come up with an example program that creates a simple mesh using a memblock.

Once I was but the learner,
now, I am the Master.
andrew11
22
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 30th Jun 2003 04:28 Edited at: 30th Jun 2003 04:30
Oh I just got back. Thanks TheDarthster. It saved me from the typing. You explained it better than I could anyway. lol

"All programmers are playwrites and all computers are lousy actors" -Anon
Click Here!!!
Chiwawa
22
Years of Service
User Offline
Joined: 13th Oct 2002
Location: Canada
Posted: 30th Jun 2003 19:00
-The offset is from 0

then remove all the "32+" and it will be right
Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 30th Jun 2003 19:51
Thanks, that has really helped Darthster, hopefully with that, and andrew and chiwawas examples, I will be able to figure it out. I also look forward to seeing your example, although it doesn't matter if you don't have time .

A few things that I just have to get clear on....

- Vertex indexes? They are just a list of the vertices from 0-n, right?

- (32+(n*12)+0) X position...... 'n' starts at 0 for the first vertex, not 1?

- The offsets depend on the number of vertices and faces, etc, because you need more space to store extra information, therefore the memblock positions of the later info are pushed along?

- Chiwawa, if you take away 32, then you will be using the same memblock positions for the header data, as well as the vertex data. Is this correct? Do the different data types each get stored with a different set of memblock positions?

I do know what normals are Darthster, it was just the way the data was stored that was my problem, and now I pretty much understand, I will try later as I have coursework to do now , CYA!

cuRant PRogekt: a three-de map editer
Why the hell'd you ask me for crying out loud!?!
Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
Chiwawa
22
Years of Service
User Offline
Joined: 13th Oct 2002
Location: Canada
Posted: 30th Jun 2003 20:55 Edited at: 30th Jun 2003 21:00
ok first:

vertex:
(Vertex Offset+(n*12)+0) X position
(Vertex Offset+(n*12)+4) Y position
(Vertex Offset+(n*12)+8) Z position

BUT the vertex offset will ALWAYS be 32....cause it begin at the end of..header

second:
First Vertex ....begin ar 0

Third:
for the Vertex Index i dont know.... but i think you r right...

four:
im not english...im french ..then im not sure of the EXACT meaning of your question:
"The offsets depend on the number of vertices and faces, etc, because you need more space to store extra information, therefore the memblock positions of the later info are pushed along?"

to add some more vertice...and normal..it will be hard..you will need to manuelly move ALL the data who are after..to add some space where you need to put your ...vertice data... and normal data..and you will need to change your offset manuelly...

here a little..picture of what i mean:
original memblock (each "-" is a byte..or what ever..memory..):
--------------

if you want to add vertice you need to do that first(move all your data..to add space:
--- -----------

after you add your vertice data("_" mean new data):
---_-----------

but you will need to change your offset.....manuelly...


i dont know if i answered right at your question........but..
Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 1st Jul 2003 10:41
Thanks, that was my question, just checking to see if I'd understood, and I have !

cuRant PRogekt: a three-de map editer
Why the hell'd you ask me for crying out loud!?!
Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
The Darthster
22
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 1st Jul 2003 13:45
Here's some code:



This will convert an object to a mesh and put it into a memblock, then display all the memblock data. This should help you understand which pieces of data go where, and in what format. To display the data I used an array info$(), which unfortunately has some massive expressions to work out which array index a piece of data is to go into. You can ignore these, your main concern is what is put into the array, i.e. within the str$() command. You can use the arrowkeys to scroll through the data. You should be able to create or load any object and view its memblock, provided it isn't too high poly.

Once I was but the learner,
now, I am the Master.
Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 1st Jul 2003 18:30
Thanks v. much Darthster, you're really helpful, I appreciate it.

cuRant PRogekt: a three-de map editer
Why the hell'd you ask me for crying out loud!?!
Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM

Login to post a reply

Server time is: 2025-05-19 04:35:49
Your offset time is: 2025-05-19 04:35:49