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 / I need more information about MESH in MEMBLOCK.

Author
Message
Leonid
User Banned
Posted: 31st Jul 2012 14:00 Edited at: 31st Jul 2012 14:01
I need more information about MESH in MEMBLOCK.
I do not understand what is polygon, vertex and some other things. Tutorial pictures will be better than text.
James H
19
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 31st Jul 2012 22:32 Edited at: 31st Jul 2012 22:36
I can only hope the following is both accurate enough(am sure innaccuracies will be spotted by others if there are any) and suitable enough for you:



First before you delve into memblock meshes you need to ensure you understand a few things so that you can understand the contents of a memblock mesh in terms of data of what the data relates to. First of all, memblocks arent restricted to be used just for meshes, if you havent already, look through the contents of helpfile for memblocks to see their uses.

Objects are made up of 1 mesh or more - each mesh is called a limb. Each object has a root limb - this is limb 0, additional limbs can also be created. When using memblocks to create meshes, the mesh(once created) can be used to create an object(see helpfiles description for make object) or they can be added to an existing object(see helpfiles description of add limb)though new limbs must be numbered sequentially. Once a limb has been created you can assign it as the child limb to a parent limb(see helpfiles for link limb description).

Moving on, lets take a look now at the actual memblock that will hold the mesh data;
First of all you will need to understand data types - this information can also be found in the helpfiles under the "Principles" section headed "Data types and variables".
A memblock is just a line of data, its size defined in bytes - when creating a memblock for a mesh you must know the exact size the memblock must be, to know this you will need to determine the components required for vertex data and the number of vertices required for the mesh, in memblocks every 3 vertices determines 1 triangle, the order of them and their positional data will determine which side of the triangle the face is drawn - the face being the area you see when you look at an objects mesh when rendered. Once these values have been determined you can add 12 bytes to account for the following information
In the memblock the first dword (totals 4 bytes) is the fvf format - fvf is abbreviation for flexible vertex format, this format reference code a description to your computer telling it what commponents exist within every vertex have a look a the following which was provided to the community by another member whom I unfortunately cannot remember the name of though its I altered it somewhat in minor ways;

Format component => Dword value ;
FVF_XYZ => 2
FVF_XYZRHW => 4
FVF_XYZB1 => 6
FVF_XYZB2 => 8
FVF_XYZB3 => 10
FVF_XYZB4 => 12
FVF_XYZB5 => 14
FVF_NORMAL => 16
FVF_PSIZE => 32
FVF_DIFFUSE => 64
FVF_SPECULAR => 128
FVF_TEX0 => 0
FVF_TEX1 => 256
FVF_TEX2 => 512
FVF_TEX3 => 768
FVF_TEX4 => 1024
FVF_TEX5 => 1280
FVF_TEX6 => 1536
FVF_TEX7 => 1792
FVF_TEX8 => 2048
So FVF 338 would be
FVF_TEX1 => 256
FVF_DIFFUSE => 64
FVF_NORMAL => 16
FVF_XYZ => 2
Sum = 338
If you remove the diffuse from fvf 338 (FVF_DIFFUSE => 64) just subtract 64 from 338 and you get 274.

This information shows how to determine what fvf code to use based on what components of the vertices you wish to include in the end format, the provided example matches the fvf format described in the helpfiles in the description of the command make mesh from memblock

So fvf code sorted, we can look at the second dword of the memblock - the size in bytes of each vertex, in the case of fvf code 338 it is 36 bytes, broken down as follows and should be written into the memblock in the same order;
Positional data XYZ are 3 float values , each float being 4 bytes totaling 12 bytes
Normal data also 3 float values - also 12 bytes
Now comes diffuse component which is dword so 4 more bytes
Finally comes texture coords which are UV data - 2 float values, so this is another 8 bytes
...12+12+4+8=36 bytes per vertex

*Note*
Position x,y z are local coords to the object as opposed to world coords and are any value within the range of a real number
Normals describe direction to take light from - a float3 vector - so they are representative between 0.0 and 1.0
The diffuse color is dword and so for example red you could use..
diff as dword
diff=rgb(255,0,0)
..to determine the correct value
U & V data are also representative floats between 0.0 and 1.0, though values greater could be used to scale a texture, ie 2.0 for U and 2.0 for V would double the scale of texture

Now moving on to the third dword of the memblock - the number of vertices required for the mesh - very easy - number of triangles * 3

The rest of the data in the memblock is the list of vertices and there component data written in the order previously detailed.
Leonid
User Banned
Posted: 20th Aug 2012 11:42
I can not make a color for triangle (diffuse)
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 20th Aug 2012 12:59 Edited at: 20th Aug 2012 13:00
(12+0*4+0*36) is wrong... should be:

( 12 + ( 0 * 4 ) + ( 0 * 36 ) )

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 20th Aug 2012 14:12
Why on earth are you putting that in a main loop with two sync commands and making 4 vertices even though the FVF only supports 3?

You may want to have a better structure or your code could get messy pretty quickly. Something like this:



If you want to change the data at real time you'll have to use vertexdata commands because making the object over and over again is REALLY SLOW. The following will change it's diffuse value so it's blue:



TheComet

"if you don't understand recursion than you probably don't understand recursion." ~Jerico2day
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 20th Aug 2012 16:22
@WLGfx
Those two are exactly the same...

[b]

Login to post a reply

Server time is: 2026-07-21 20:39:50
Your offset time is: 2026-07-21 20:39:50