trouble creating meshes from scratch in B3d
Blitz3D Forums/Blitz3D Programming/trouble creating meshes from scratch in B3d
| ||
I've managed to make a simple cube, using create mesh( I know I can create a cube createCube, but that's not the point)I've got the vertex and the triangles, I can see the cube, but one I can see the triangles slightly (shading) and I can't seem to attach a texture(It just changes colour) Help please. |
| ||
have you set your texture coords and normals? |
| ||
Hmm, duno, I'm beginning suspect it has to do with addvertex... |
| ||
could you post some code, i would be happy to take a look if you want :D |
| ||
Well, got it working. Dunno if it's the right way to do it. You need to set the U V clamps for the vertex, and also each side needs its own 4 vertexes(I was reusing the ones thet are in the same pos, but this mucks up the texture) Here is the code for those interested (Only 3 sides of the cube are done) Graphics3D 640,480 SetBuffer BackBuffer() mesh = CreateMesh() surf = CreateSurface(mesh) ;front v00=AddVertex(surf,-3,-3,-3, 0,1);BL v01=AddVertex(surf, 3,-3,-3, 1,1);BR v02=AddVertex(surf,-3, 3,-3, 0,0);TL v03=AddVertex(surf, 3, 3,-3, 1,0);TR ;leftside v06=AddVertex(surf,-3,-3,-3, 1,1);BR v07=AddVertex(surf,-3, 3,-3, 1,0);TR v04=AddVertex(surf,-3,-3, 3, 0,1);BL v05=AddVertex(surf,-3, 3, 3, 0,0);TL ;back v08=AddVertex(surf,-3,-3, 3, 1,1);BR v09=AddVertex(surf,-3, 3, 3, 1,0);TR v10=AddVertex(surf, 3,-3, 3, 0,1);Bl v11=AddVertex(surf, 3, 3, 3, 0,0);Tl tri=AddTriangle(surf,v00,v02,v01);down tri=AddTriangle(surf,v02,v03,v01);up tri=AddTriangle(surf,v04,v05,v06) tri=AddTriangle(surf,v05,v07,v06) tri=AddTriangle(surf,v10,v11,v08) tri=AddTriangle(surf,v11,v09,v08) tex=LoadTexture("oldbric.bmp",1) EntityTexture mesh,tex cam = CreateCamera() MoveEntity cam, 0,0,-10 UpdateNormals mesh While Not KeyDown( 1 ) If KeyDown(19) Then TurnEntity mesh,0,1,0 RenderWorld ;Text 0,0,TrisRendered() Flip Wend End |
| ||
is this what you wanted it to doGraphics3D 640,480 SetBuffer BackBuffer() mesh = CreateMesh() surf = CreateSurface(mesh) ;front v00=AddVertex(surf,-3,-3,-3, 0,0);BL v01=AddVertex(surf, 3,-3,-3, 1,0);BR v02=AddVertex(surf,-3, 3,-3, 0,1);TL v03=AddVertex(surf, 3, 3,-3, 1,1);TR ;leftside v06=AddVertex(surf,-3,-3,-3, 0,0);BR v07=AddVertex(surf,-3, 3,-3, 0,1);TR v04=AddVertex(surf,-3,-3, 3, 1,0);BL v05=AddVertex(surf,-3, 3, 3, 1,1);TL ;back v08=AddVertex(surf,-3,-3, 3, 0,0);BR v09=AddVertex(surf,-3, 3, 3, 0,1);TR v10=AddVertex(surf, 3,-3, 3, 1,0);Bl v11=AddVertex(surf, 3, 3, 3, 1,1);Tl tri=AddTriangle(surf,v00,v02,v01);down tri=AddTriangle(surf,v02,v03,v01);up tri=AddTriangle(surf,v04,v05,v06) tri=AddTriangle(surf,v05,v07,v06) tri=AddTriangle(surf,v11,v09,v08) tri=AddTriangle(surf,v10,v11,v08) tex=LoadTexture("coolgrass2.bmp",1) EntityTexture mesh,tex cam = CreateCamera() MoveEntity cam, 0,0,-10 l = CreateLight UpdateNormals mesh While Not KeyDown( 1 ) If KeyDown(19) Then TurnEntity mesh,0,1,0 RenderWorld ;Text 0,0,TrisRendered() Flip Wend End |
| ||
SSS >> Why did you post my code again? Is this some kind of practical joke? MadMax scratches his head, wondering... |
| ||
this code works... copy and paste it, the problem was ur texture coords & vertice orderings, unless you didnt have a problem? |
| ||
OK, I'll quote myself; Well, got it working. Dunno if it's the right way to do it. You need to set the U V clamps for the vertex, and also each side needs its own 4 vertexes(I was reusing the ones thet are in the same pos, but this mucks up the texture) Here is the code for those interested (Only 3 sides of the cube are done) As you can see, I did have a problem, but I sorted it out. I posted the answer just in case someone reading the post had a similar problem. Anyway your modification mirrors the texture upwards, use a texture with letters to see what I mean (Interesting though, might come in handy sometime). Thanks anyway for your help. |
| ||
oh didnt read ur post sry |