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.

Newcomers DBPro Corner / Memblock Mesh tutorial

Author
Message
Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 20th Aug 2006 06:31 Edited at: 21st Aug 2006 20:58
Ok maybe this isnt for newcomers but here it is anyway. I am not the best at memblock meshs but hopefully this could get some poeple on there way to learning about them

Memblock Mesh Tutorial

Ok we will do a little setup to make sure we have a steady sync rate and the camera doesnt move
while we make new objects by using the sync and autocam commands


You may be wondering what are faces and vertices. Faces and vertices are what make the object and faces
can be any 2D shape. It can be a tri, quad, oct, ect. To make faces it has to have vertices and the vertices
connect to make a face. Simple isn't it.

We will start by making a plain. A plain has two sides and four corners so you think we only need 2 faces
that are quads. No because DBpro triangulates all models so it will have 4 faces instead. This will be the
same with a memblock mesh.

Have you ever seen the make memblock from mesh command and thought huh. Well the to put it as simple as
I can I'll write out.

fvf format -dword
fvf size -dword
vertices in mesh -dword
model's vertex position x -float
model's vertex position y -float
model's vertex position z -float
model's vertex normal x -float
model's vertex normal y -float
model's vertex normal z -float
vertex diffuse color -dword
u vertex data -float
v vertex data -float


If you don't know what a float is it is a number that can have decimals and takes up 4 bytes. A dword is almost the same as a float but can't have a decimal
This is the 338 fvf format so it will be different for other fvf formats such as 274 which doesnt have
vertex diffuse color dword. Now to explain what each one does. The fvf format is the format you have
to follow. Throughout the tutorial I will be using the 338 fvf format. The fvf size is how big the
format is and every dword and float is 4 bytes. To find out what it is you count how many bytes are
in the format excluding the first three dword becuase they only need to be in the memblock once at
the top. The verticies in mesh dword is how many vertices are in the mesh and since one vertex is
36 bytes we subtract the memblock size(using get memblock size()) by 12(first three dwords) then
divide it by three.

Now the vetex data. The Model's vertex positions x/y/z are the position in model space meanning
it is relative to the models position. So to get the 3D world space you add the vertexs position
by the objects position. The model's vertex normal x/y/z is how it is rendered although I have
no idea how to calculate it xD. Vertex Diffuse color is how the light affects the color of the
object. Just like the set object diffuse except on a vertex. UV vertex data is the position on
an image(I will explain more in the tutorial).

Now that I explained everything we will start by making a simple face. It would be extreamly long
If we wrote out everything so we will make a function called create_vertex. It has to include
everything in the format so we will make a skeleton as I like to call it.


It has to except input and we need to input the memblock number, vertex, vertex position, diffuse color, and uv data
Then we have to write it in the memblock so now it should look like this



We have to put color as dword becuase the it will automaticaly be declared as an integer and
we dont want that.

Now we want to make a function that makes the correct kind of memblock for us. That can set
how many vertices we have, the memblock size, fvf format, and size



The input is the memblock number and vertices in the object. This will be used with the
create_vertex() command. But there is one last thing how do we make a memblock into a
mesh. This is simple but to make it even simplier we will also create another function
for it. To create a memblock into an object we first have to make a mesh and make that
mesh into an object. So here it is



You can just set the imgnum to 0 for now thats only if you want an image for your object.

Although I have no idea how to set a normal we have to set it to something otherwise the
vertex diffuse wont work so we will make a new function.


Ok now to test what we made. First we need to use the create_memblockobject() function we made.
We will use memblock 1 and we will make a triangle with two sides so that means 6 vertices. Now
your thinking why 6 vertices why not 3? This is becuase you have to make a new vertex for each
face and since we are making two faces that would be 6 vertices. Next we need to create 6 vertices.
Now think like its on a grid. We want one vertex up a to create the tip and two for the sides. We
will also color each vertex a different color to tell which one is which. So you should have this.


As you can see we wont need the uv data so it has been set to 0 and the vericies start at 0. You can
change this in the function if you want doing something like inc v but we will leave it like this
for now.

We also have to make the backface but how. To make a face look at the direction you want them
all you have to do is either make them clockwise or counter clockwise. Clockwise is facing the
front and counter clockwise is facing the back so all we have to do is make the same verticies
but backwards. It should be this



Do you remember why we made the set_normal function so it was to make the diffuse vertex color to work.
So now we have to set the normal of the face. Since I have no idea how to calculate it which I said
multiple times we will just set it to a number between 0 and 1 like 0.2. So now you should have this



Now to make an object using our simple make_object() command. Which should be
something like make_object(1,1,1,0)

To see our newly created object we will position the camera out by 20 using position camera.
We will also use a loop to constantly view our object and let us rotate our object to view
all sides. Which should be along the lines of this



Our final code should now be



Here is what you will get in the end


Test it out and see what you can make!

Hope this is of any use to anyone and if you want me to add something tell me. Oh and if anyone knows how to calculate an angle tell me that too because I have no idea how.

Naruto is the ninja...not really

Attachments

Login to view attachments
Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 20th Aug 2006 06:35
Here is the project so you can download it

Naruto is the ninja...not really

Attachments

Login to view attachments
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 21st Aug 2006 11:37
This has a lot of good information. I think it could be expanded into an even better tutorial. I know you say at the beginning it's really not for noobs, but with a little more detail, and even more explanation like what's a float (number with a decimal, real - whatever), what's a dword, what does fvf mean... just some simple things that help when someone has no clue.

I think you did a really good job though!

Enjoy your day.
Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 21st Aug 2006 20:51
Thanks I only did it in one day but I will expand on it where I can

Naruto is the ninja...not really

Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 21st Aug 2006 23:49
Great tutorial!

I have already used your functions here to change a matrix into a mesh.

I found that it is easiest not to worry about the normals when it is a mesh, and to just use "set object normals" once the object is created.

Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 22nd Aug 2006 21:39
Quote: "I have already used your functions here to change a matrix into a mesh."


Glad there being used somewhere

Quote: "I found that it is easiest not to worry about the normals when it is a mesh, and to just use "set object normals" once the object is created."


Never noticed that command before. I'll try it out

Naruto is the ninja...not really

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 28th Sep 2006 11:48
Hi Slayer93,

I recently created a direct x exporter in DB Classic that will export a mesh into a .x file using memblocks. While this works ok if I make a memblock from mesh from an object, I was taking the process a step further by creating an object builder - where you could start from scratch without an initial object.

I was wondering, If I wanted to add UV coordinates, how would I do that? If I'm building the mesh basically from the vertices up, how can I determine what the UV coordinates are?

Enjoy your day.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Sep 2006 17:38
Nice tutorial, broken down well into understandable sections

One thing though - I would change this...

Quote: "If you don't know what a float is it is a number that can have decimals and takes up 4 bytes"


to...

Quote: "If you don't know what a float is, come back in 6 months and try again."




Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 28th Sep 2006 19:31
That is one awesome tutorial! I have always wondered how to do this! You rule.

Login to post a reply

Server time is: 2024-11-26 09:29:48
Your offset time is: 2024-11-26 09:29:48