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 / What is the best way to make 2D level from mesh?

Author
Message
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 20th Oct 2014 23:13 Edited at: 20th Oct 2014 23:14
Hello!

I have a task for educational purposes (computer science section in high school) : build a simple platformer. It must be done with mesh and textures (atlas). Here is the plan:



On this plan you can see tiles layout design.

Mesh must be because of shaders (normal mapping). And water.

I am not experienced in creation mesh with code at all (only in 3d editors). So what is the best way to make this mesh: memblocks, vertexdata, or other? Also performance optimisation is important (like welding).

Any short guides are greatly appreciated!

If you can provide a link to other discussions or example snippets it would be great!!!

Attachments

Login to view attachments
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 21st Oct 2014 00:45
Can you use 3D plains and arrange them in tiles?

Otherwise, generating the mesh via vertexdata is probably the best method. There are some examples on the forums about vertex welding, try a google search.

I like offending people. People who get offended should be offended. -- Linus Torvalds
Sph!nx
16
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 21st Oct 2014 02:45
If you have to code it all, without the use of external editors, I would dive into the documentation. It got quite a few commands on creating and manipulating model/meshes (known as objects in the docs). There are also many libraries that could aid you with that. Check out the "DLL Talk" section for that or the main page for the official ones.

Otherwise, I would go with creating the level in a model program, with a UV map that could make use of atlas textures.

Just my two cents...

Regards Sph!nx
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 21st Oct 2014 10:34 Edited at: 21st Oct 2014 10:36
I'd use a memblock to build a single level object mesh, first count the number of polygons you need, then build a custom memblock for the map layout. That way, you just add the vertex data as you go, no complex creation of vertex lists for polygons - just 3 vertices per polygon, easy to make based on existing 2D map data.

The texture atlas is merely a tile sheet - you can just work out the current tiles UV coordinates based on its tile number.


But - does it really need to be 1 big object, or could it just be individual objects?
I'd be tempted to try making more elaborate tiles - maybe with some foliage or backdrop/foreground details. See, if each different block is a different mesh that you load in, they could all use the same texture. The nice thing though - is you can easily just add the individual tile mesh to a main object. This breaks down the limits somewhat, because you could use the 3D mesh for collision, and when you do that you instantly have the option to add more complicated tiles. Like Sonics massive loops for example - imagine trying to achieve that with individual tiles - now imagine it just being a 3D object that you can just plonk down and it works. You'd be able to use physics, shaders, and even individually animated tiles.

I guess it depends on what you need exactly, but there are a few options to achieve this... the way I see it, if your gonna use psuedo 2D for your level, why not go the whole hog and model the tiles and make full use of the 3D commands. I've made a couple of 2.5D games, and always use 3D - even just having bone animation can bring a lot.

I am the one who knocks...
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 21st Oct 2014 11:52
This is a demo of horizontal-only side scroller, so single level single should be cutted vertically into parts to hide off-screen pieces. Although we think to add second (and maybe third) layers as distant background, in addition to planned background clouds layer.

The goal is to give this example code to others to study the basics of programming to make similar demo "games".

I agree that using memblocks is a better way rather than ADD MESH TO VERTEXDATA. But also it is complicated way. I found this tutorial, now reading it.

Is it nessesary to create normals for 2D mesh that don't use normals?
Can I use SET OBJECT NORMALS, will it work on this flat grid?

I found this thread of welding but it uses vertexdata?

Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 21st Oct 2014 12:49
You can add a mesh as a limb to an existing object, then convert that existing object into a mesh, then convert that mesh back into an object for adding more mesh limbs - in other words, baking a mesh into an object until you end up with a single mesh made from several meshes. As long as the texture is the same, that would work great. Whenever you create a mesh from an object, the whole object is converted, including any added limbs.

I am the one who knocks...
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 21st Oct 2014 13:38
Quote: "hide off-screen pieces"


Not necessary, DBPro already culls them. You'll be wasting processing power.

Quote: "Is it nessesary to create normals for 2D mesh that don't use normals?"


Yes. Your shaders require the normals to properly calculate lighting. Since you're writing a 2D game and are using a flat object, you can just use [0,0,-1] (or whichever way your surfaces are pointing. For more complex objects there's a command in DBPro called set object normals which will calculate the normals for you.

I like offending people. People who get offended should be offended. -- Linus Torvalds
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 21st Oct 2014 22:01 Edited at: 21st Oct 2014 22:40
Van B
Wait. If I use memblock to make object, why any examples of welding are useing vertexdata(rebuild indexes)? Why not I should make mesh from plane and then just add it to itself with ADD MESH TO VERTEXDATA?

So I came up with the simple code:



How uncool is it? What cons? Pros: simple

Also, this is hidden knowledge for me - what is the difference between mesh made with MAKE MESH FROM MEMBLOCK and modified with it's clones generic plane using VERTEXDATA... ???

Quote: "set object normals which will calculate the normals for you"

How it knows the face direction? Even 3ds max makes errors on complex objects sometimes. And my object not even welded.

UPDATE: Diggsey said:
Quote: "you have to use a rather hacky (and slower) method of calling "add mesh to vertexdata" and "delete mesh from vertexdata"."

...hacky?

UPDATE: Van B said:
Quote: "Check the codebase for Kevin Verbeeks memblock tutorial, it's a memblock matrice, but is full of usefull bits - it's how I sussed them out.

What you do is make a memblock and set the format by writing data to it, then you add things like the vertice count, then the actual mesh data. It's not childsplay but worth taking time out to learn, you can do a helluva lot with memblock meshes."

...hm. So memblocks for creation and vertexdata for altering mesh (vertex colors, etc..)??? Right?

Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 22nd Oct 2014 09:57
Well a memblock would let you define the vertex colours as well - the main drawback with a memblock is it doesn't weld the vertices, so it's 3 vertices per polygon no matter what. But really that's not a big deal, how many PC's out there can't handle a few extra vertices!

The issue I have with adding a mesh like that, is you still have to reposition it, like every vertex you've added has to be offset to the relevant map location, and I think that would get a bit messy. Not only that, but you'd need to set the UV coordinates as well, and when you have to do all that, well you might as well use a memblock IMO.

I think the vertexdata commands would be more usefull for effects - like a vertex wave effect on water, or vertex lighting based on light sources.

I am the one who knocks...
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 22nd Oct 2014 18:07 Edited at: 22nd Oct 2014 18:08
Oh, so I get it:

1) I create mesh with memblock like a pro guy
2) I weld vertices using vertexdata as extra.
3) I use vertexdata for extra effects.

Also I want to admit, that welding does nothing if you use vertexdata, i.e. if you want to setup vertex colors you have the same amount of vertices as unwelded object, it just the 3D render boost. Sign

Login to post a reply

Server time is: 2025-05-13 13:39:11
Your offset time is: 2025-05-13 13:39:11