Quick (hopefully!) question about Texturing Cubes
Blitz3D Forums/Blitz3D Beginners Area/Quick (hopefully!) question about Texturing Cubes
| ||
Hi all, How do you separately texture each side of a cube? Would I have to create the cube from 6 separate surfaces and texture each one individually? If it helps, imagine the sides on a Rubiks Cube.. ;) Cheers! M. |
| ||
You do not need to create 6 seperate surfaces but you need a program to unwrap the cube like a piece of paper. Check out this program which is excellent and check out the tutorial that just so happens to depict a rubiks cube. http://www.unwrap3d.com/tutorial_begin.aspx Jason. |
| ||
You don't need a program to do it though. You could do it in code with the UV coordinates. I mean you couldn't do it for a complex mesh, but you could for a cube. You probably already know this, but just in case. Don't reuse any vertices in other faces. Each of the six faces ( each consisting of two triangles ) should use four new vertices. Otherwise you won't be able to get nice crisp edges between the faces, you'll get yucky soft smoothing trying to make the edges go away. |
| ||
if you wanted a cube with a surface per side...Function createcube6() m = CreateMesh() s = CreateSurface(m) ;bottom face v0 = AddVertex(s,-1,+1,+1,0,1) v1 = AddVertex(s,+1,+1,+1,0,0) v2 = AddVertex(s,+1,+1,-1,1,0) v3 = AddVertex(s,-1,+1,-1,1,1) AddTriangle s,v0,v1,v2 AddTriangle s,v0,v2,v3 s1 = CreateSurface(m) ;top face v0 = AddVertex(s1,-1,-1,-1,1,0) v1 = AddVertex(s1,+1,-1,-1,1,1) v2 = AddVertex(s1,+1,-1,+1,0,1) v3 = AddVertex(s1,-1,-1,+1,0,0) AddTriangle s1,v0,v1,v2 AddTriangle s1,v0,v2,v3 s2 = CreateSurface(m) ;left face v0 = AddVertex(s2,-1,+1,+1,0,0) v1 = AddVertex(s2,-1,+1,-1,1,0) v2 = AddVertex(s2,-1,-1,-1,1,1) v3 = AddVertex(s2,-1,-1,+1,0,1) AddTriangle s2,v0,v1,v2 AddTriangle s2,v0,v2,v3 s3 = CreateSurface(m) ;right face v0 = AddVertex(s3,+1,+1,-1,0,0) v1 = AddVertex(s3,+1,+1,+1,1,0) v2 = AddVertex(s3,+1,-1,+1,1,1) v3 = AddVertex(s3,+1,-1,-1,0,1) AddTriangle s3,v0,v1,v2 AddTriangle s3,v0,v2,v3 s4 = CreateSurface(m) ; front face v0 = AddVertex(s4,-1,+1,-1,0,0) v1 = AddVertex(s4,+1,+1,-1,1,0) v2 = AddVertex(s4,+1,-1,-1,1,1) v3 = AddVertex(s4,-1,-1,-1,0,1) AddTriangle s4,v0,v1,v2 AddTriangle s4,v0,v2,v3 s5 = CreateSurface(m) ;back face v0 = AddVertex(s5,+1,+1,+1,0,0) v1 = AddVertex(s5,-1,+1,+1,1,0) v2 = AddVertex(s5,-1,-1,+1,1,1) v3 = AddVertex(s5,+1,-1,+1,0,1) AddTriangle s5,v0,v1,v2 AddTriangle s5,v0,v2,v3 UpdateNormals m Return m End Function |
| ||
Hi, I'm currently working on learning about vertexes and surfaces, so I've been trying to work out exactly what the code posted here does, and how it works. Unfortunatly it doesn't actually seem to work, any time I run it in blitz3d I get a memory acess violation at the UpdateNormals m when I put a ; in front of it, I instead get the error at my RenderWorld() in the rendering loop. Can someone fix it / tell me what's wrong with the above code so I can continue trying to use it to learn what I'm doing? |
| ||
The AddVertex() calls for the s3, s4, and s5 surfaces are adding vertices erroneously to s2. Looks like someone was cutting-and-pasting all sloppy-like. The errors you're getting are because triangles have been added to surfaces which have no vertices. Does that answer your questions? |
| ||
Hey, good stuff. The code all makes since now that I've changed it. Thanks for clearing that up |
| ||
Sorry was a quick hack. I have edited the code - should be fine now :-( |