Texturing with CreateMesh

Blitz3D Forums/Blitz3D Beginners Area/Texturing with CreateMesh

fox95871(Posted 2008) [#1]
I'm really confused about to how to do this. I understand how the 00 10 01 11 system works - top left, top right, bottom left, bottom right - corners of the texture corrosponding to the corners of the mesh, but short of having 6 separate surfaces for a cube, how on Earth are you supposed to get the same image on each face? And if it can be done, and with only one surface and one texture, how are you supposed to figure out how to wrap it, when that - ow - really makes my brain hurt :D

If someone could download, modify, and repost this please, that would really help me a lot:
http://h1.ripway.com/fox95871/index.html


GIB3D(Posted 2008) [#2]
ScaleTexture probably

Edit: Oh I see you problem now, I've made a thing that creates 5 sided cubes with the same texture on each side, didn't know it could give anyone that big of a problem though lol.

Here's is code I'm using in my Gorilla game, the back of the cube has no face on it because it's a side scrolling game so I didn't need it. I also had to scale the texture by .5 on the Y axis to fit because of the way I set up the cube creation. The textures I'm using in my game are 512,1024 so I had to set the cubes so the fit a certain of the texture. Feel free to change it.






Matty(Posted 2008) [#3]
mesh=createmesh()
entityfx mesh,1+16 ;because I can't remember if blitz renders triangle vertices clockwise or anticlockwise
surf=createsurface(mesh)

;Side Back
v0=addvertex(surf,-1,-1,-1,0,0)
v1=addvertex(surf,-1,1,-1,0,1)
v2=addvertex(surf,1,1,-1,1,1)
v3=addvertex(surf,1,-1,-1,1,0)
addtriangle surf,v0,v1,v2
addtriangle surf,v2,v3,v0

;Side Front

v0=addvertex(surf,-1,-1,1,0,0)
v1=addvertex(surf,-1,1,1,0,1)
v2=addvertex(surf,1,1,1,1,1)
v3=addvertex(surf,1,-1,1,1,0)
addtriangle surf,v0,v1,v2
addtriangle surf,v2,v3,v0

;Side Top

v0=addvertex(surf,-1,1,-1,0,0)
v1=addvertex(surf,-1,1,1,0,1)
v2=addvertex(surf,1,1,1,1,1)
v3=addvertex(surf,1,1,-1,1,0)
addtriangle surf,v0,v1,v2
addtriangle surf,v2,v3,v0


;Side Bottom

v0=addvertex(surf,-1,-1,-1,0,0)
v1=addvertex(surf,-1,-1,1,0,1)
v2=addvertex(surf,1,-1,1,1,1)
v3=addvertex(surf,1,-1,-1,1,0)
addtriangle surf,v0,v1,v2
addtriangle surf,v2,v3,v0

;Side Left

v0=addvertex(surf,-1,-1,-1,0,0)
v1=addvertex(surf,-1,-1,1,0,1)
v2=addvertex(surf,-1,1,1,1,1)
v3=addvertex(surf,-1,1,-1,1,0)
addtriangle surf,v0,v1,v2
addtriangle surf,v2,v3,v0


;Side Right

v0=addvertex(surf,1,-1,-1,0,0)
v1=addvertex(surf,1,-1,1,0,1)
v2=addvertex(surf,1,1,1,1,1)
v3=addvertex(surf,1,1,-1,1,0)
addtriangle surf,v0,v1,v2
addtriangle surf,v2,v3,v0

entitytexture mesh,"yourtexturehandlehere" ;replace the "yourtexturehandlehere" with your texture handle.
'1 mesh, 6 sides, all 1 surface.




Can't test as I'm doing this from memory, don't have blitz in front of me but play around with it..


Stevie G(Posted 2008) [#4]
Blitz's native createcube already allows you to have the SAME texture on each cube face. It contains no shared vertices across each face ( i.e. 24 vertices , 12 triangles ) so should work just fine as is. Is there something I'm missing?


fox95871(Posted 2009) [#5]
Yeah um, about that...my game engine sorta has some...Maya type features. Heh. So though it may appear to start as a cube, I'll be expecting more from it than just that. Currenly I have it working so each vertex can be manipulated with the mouse (yes, that was a mountain of code!) What isn't working is getting each side textured right. I realize I could do that with CreateCube, but of course that strips away the ability to manipulate each vertex.

Well I'm looking forward to trying all your suggestions so far, thanks!


Stevie G(Posted 2009) [#6]

I realize I could do that with CreateCube, but of course that strips away the ability to manipulate each vertex.



Not really, just find all the vertices which are under your cursor and move all 3 together.

You need unwelded vertices to texture each correctly I'm afraid so you have no option other than this.

Stevie


fox95871(Posted 2009) [#7]
Sorry Gia, that was way over my head! Well, I still use that camera fixer you made for me. Thanks for trying to help anyway :)

Matty, I understand yours, but doesn't the method you're using make it impossible to use VertexCoords on anything but the most recently finished side? I mean, what you're doing is essentially like using a cement form. You reuse it on each newly created side, but you can't go back and "edit" already finished sides, right? Only the last one that was last created. I need to keep track of all vertexes, but also have the vertex and surface count be as small as possible, because my engine's already pretty huge with 32 elements to manage.

You can use any wallish texture for this example, just make sure it's named elementtexture and has the right extension. I think if I could get this to work pretty much like it does now, but so it affects three corners instead of just one, I could probably figure out the rest from there. Sorry for turning your v0s 1s 2s and 3s into vertex1s 2s 3s and 4s, but that's just more understandable for me!




Matty(Posted 2009) [#8]
No, you can still access the vertices using the countvertices() command and iterating through each of the vertices attached to the surface.


fox95871(Posted 2009) [#9]
Got it. Well, not what you just said, but I'll try that tonight. But I wrote this last night. You just need a wall texture to run it, like the last one.



Okay, here's the thing. I don't actually mind writing tedious code like this believe it or not. I like getting a good coffee buzz on and basically just duplicating everything over and over til it's done. The only thing I'm worried about is, the above code is for just one level element, and my engine will have 32, plus a few more to be used as area change triggers, door openers, etc., all told about 50 elements. Like I said, I don't mind coding all that, but wouldn't all that create some lag? Or is 1200 vertexes 1200 vertexes either way? What I mean is, is there a difference in speed between a level made up of normal meshes totaling 1200, and one made up of highly editable ones like mine totaling 1200? The reason I'm wondering that is not so much because I'm worried about slowdown while editing, but because when an area's done and being played, the vertexes and surfaces would all still have the same long names. I like them to be descriptive since there's so much to keep track of, but would all those names piled up cause problems, or is that nothing to a processor?

Okay, this concludes my embarrassing post for today! :)


Matty(Posted 2009) [#10]
The PC cares not for your lengthy variable names - it does not matter what you name your variables the PC doesn't notice any difference whether I call something "x" or "thisisthexvariable" and so on.


fox95871(Posted 2009) [#11]
Great. Always wondered about that.