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 / Any tutorial about mesh strucutre?

Author
Message
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 9th Oct 2003 15:46
Is there any tutorial that is available regarding the how mesh is represented in memblocks? I need a way to low level access those mesh information, e.g. vertex buffer, normals. etc. I guest the only way I can do this is make a memblock from a mesh. But I don't know how those mesh information are organized in memblocks.

Any pointers is appreciated. Or is there any other way to do this besides get my hand dirty via memblocks.

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Beta 1
22
Years of Service
User Offline
Joined: 27th Aug 2003
Location:
Posted: 9th Oct 2003 17:28
look in the command description of make memblock from mesh and you'll see how a mesh is laid out in a memblock.

try making something simple like a single untextured uncolored triangle to start with and then see what else you can do from there.

Also try searching back a few pages. this has come up a couple of times recently.

One thing that always confuses people is that the default FVF format that you get when using make memblock from mesh is not the one it says in the description BUT if you use the layout and number from the description to make mesh from memblock it does work.
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 9th Oct 2003 20:51
bulleyes checkout my codebase should be helpful to you

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Oct 2003 22:30
There's also some code that I posted in the Program Announcements forum in the Array Plugin post that simplifies mesh creation drastically (create a nmesh from an array) - but I haven't yet got code that goes in the opposite direction (ie create an array from a mesh)
Sonic
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: UK
Posted: 10th Oct 2003 05:22
From the docs:

The first DWORD is the FVF Format, which controls which components each
vertex of your mesh will contain. The default FVF Format is 338. The second
DWORD is the FVF Size, which is the size in bytes of a single vertex
element. This size is respective of the FVF Format you specified, which has
a default of 36.

The third DWORD is the number of Vertices in your mesh. The remainder of the
memblock contains mesh data. The mesh data is a sequential list of vertices,
containing the component data arranged as specified by the FVF Format. The
default FVF Format would specify the following arrangement of data within
the vertex element, which is duplicated for every vertex specified in the
memblock. Each grouping of three vertices makes a polygon. Given the default
FVF Format of 338, the first three FLOAT values (12 bytes) of the vertex
element would be the XYZ coordinates in model space. The second three FLOAT
values (12 bytes) of the vertex element would be the normals coordinates in
model space. The next DWORD is a diffuse colour component that specifies the
colour of the vertex. The last two FLOATS are UV texture coordinates for the
vertex. This adds up to 36 bytes which is the size of a single vertex.
Multiply 36 by the number of vertices in the mesh and you get the overall
size of the mesh data.


So to grab vertex data (when passed a memblock):

DARKDLL DWORD CreateCollisionObjectPro(DWORD *ptrMesh)
{
using ios::out;

VEC3D vecTemp;
int i = 0;
int FVFFormat = ptrMesh[0];
int FVFSize = ptrMesh[1]/4;
num_verts = ptrMesh[2];
int vert_data_start = 3;

// this just states how many vertices we are going to use in the global
variable - it gets the arrays ready to use
DefineVerts(num_verts);


for (i = 0; i < num_verts; i++){
vecTemp.x = *((float*)&ptrMesh[vert_data_start+(i*FVFSize)]);
vecTemp.y = *((float*)&ptrMesh[vert_data_start+(i*FVFSize)+1]);
vecTemp.z = *((float*)&ptrMesh[vert_data_start+(i*FVFSize)+2]);
CreateCollisionVertex(vecTemp.x, vecTemp.y, vecTemp.z);
}


return *((DWORD*)&i);

}

"My ignorance amuses me..."
http://www.victory-road.co.uk
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 10th Oct 2003 14:59
Will the way that the mesh vertices data are organized change, if a mesh with different FVF is used?

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Oct 2003 15:40
Absolutely, however you can force DBPro to use your specific FVF format using the CONVERT OBJECT FVF command.
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 10th Oct 2003 16:58
Whenever I load a .X file via LOAD OBJECT, will DBpro always use the default FVF format of 338? I wanna create a function that alter the mesh vertices in certain way, thus I need a general way to know how to access the vertices data given any mesh object.

Another thing is, whenever I create a mesh via MAKE MESH FROM OBJECT, and access the mesh data via memblock, will any changes that I have done on the mesh will directly affect the actual OBJECT appearance? Or the MAKE MESH FROM OBJECT just create a new copy of MESH based on the specified object.

Thanks!

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Oct 2003 20:37
The basic flow is this:

LOAD OBJECT
CONVERT OBJECT FVF (to optionally convert to your fave fvf format)
MAKE MESH FROM OBJECT
MAKE MEMBLOCK FROM MESH
do your memblock/mesh stuff here
CHANGE MESH FROM MEMBLOCK
CHANGE MESH
job done!

Login to post a reply

Server time is: 2026-07-26 05:03:58
Your offset time is: 2026-07-26 05:03:58