Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Hey, hello guys, I am trying to draw a simple 3D object generated by Google SketchUp 8 Pro onto my WebGL app, the model is a simple cylinder.

I opened the exported file and copied the vertices positions, indices, normals and texture coordinates into a .json file in order to be able to use it on javascript. Everything seems to work fine, execept for the texture coordinates which have some pretty big values, like 46.331676 and also negative values. Now I don't know if I am wrong, but isn't 2D texture coordinates supposed to be in a range from 0.0 to 1.0 only?

Well, drawing the model using these texture coordinates gives me a totally weird look, and I can only get to see the texture properly when I am very close (not really me, the cam) to the model, as if the texture has been insanely reduced in it's size and repeated infinitelly across the model's faces. (yeah, I am using GL_REPEAT on that texture wrap thing)

What I noticed is that if I get all these coordinates and divide them by 10 or 100 I get a much "normal" look, but still not in the 0.0 to 1.0 range.

Here's my json file: http://pastebin.com/Aa4wvGvv

Here are my GLSL Shaders: http://pastebin.com/DR4K37T9

And here is the .X file exported by SketchUp: http://pastebin.com/hmYAJZWE

I've also tried to draw this model using XNA, but still not working. Using this HLSL shaders: http://pastebin.com/RBgVFq08

I tried exporting the same model to different formats, collada, fbx, and x. All those yields the same thing.

For you to understand better what is going on see this screen shot: http://img97.imageshack.us/i/printwgl.png/

The cylinder on the right is the model I am refering to, the cubes, the floor and the skybox are models that I did myself "by hand". The cylinder is using the same texture as the other lower 2 boxes.

share|improve this question

4 Answers 4

up vote 5 down vote accepted

You are correct UV's typically go from 0-1 though as David X mentioned this isn't a requirement. In your case the issue is the frequency of the SketchUp generated UV coordinates. For example if your Y axis (V coordinate) goes from 0 to 46 then that texture, if wrapping is enabled, will repeat 46 times in the V direction. Wrapping also makes it look smaller because you have to duplicate the image many times across the same surface area. Re-exporting as FBX or Collada doesn't do anything to resolve the issue because it's the same UV's either way. To fix this you need to go back to SketchUp and change how it's generating UV's for the cylinder. Perhaps you can specify the UV range yourself or maybe you have to change how the geometry is parameterized. I've never used SketchUp so I don't know exactly how it handles those sorts of things.

Lastly it looks like the vertex winding of the cylinder may be the opposite of your cubes. Graphics API's like OpenGL and DirectX use triangle vertex winding to determine which direction the triangle is facing. This is how they perform backface culling - not rendering the triangles facing away from the camera as an optimization. In the case of your cylinder it appears that the view is looking into the cylinder because the triangles closest to the camera are facing the wrong direction. Once again this is an issue that would need to be resolved in SketchUp and it can be verified by looking at the direction of the face normal for each triangle (it should be pointing outward, not inward).

share|improve this answer

If you want your uv coordinates to be exactly between 0 and 1, you could use a scale matrix for your model.

So on loading your model, you could check for your max u and v coordinate and create a scaling matrix that will make it more "normal". So that will replace your manual scaling of 10 or 100. So to let it fit, you will need to scale your uv coordinates down to [0,1].

|1/uMax|0     |
|0     |1/vMax|

Of course this is just a workaround and you could better find a way to set Sketchup in the right settings (I think your exporter or Sketchup itself goes wrong here). But if it doesn't work out for you, create your post-loading-processor and save a texture scaling matrix.

share|improve this answer

Looks like SketchUp isn't normalizing your texture coordinates, or using a metric of its own. Having texcoords < 0 or > 1 and GL_REPEAT as texture wrapping means that the texture will be scaled down to fit the geometry and repeated horizontally and vertically.

Try importing the mesh in another modelling package (MilkShape, Blender) and fixing the uv map from there.

share|improve this answer
3  
Having texcoords < 0 or > 1 and GL_REPEAT as texture wrapping means that the texture will be [removed erroneous statement] repeated horizontally and vertically. –  Krom Stern Apr 4 '11 at 8:50

(Texture coordinates can definitely be outside of 0-1.) I think this is just OpenGL being weird. IIRC, Spheres use texture coordinates that put the 0-1 square on ~1/16 of the surface, and I wouldn't be suprised if Cylinders do something similar. Fix-wise, you might have to write your own cylinder code, issuing the appropiate texture coordinates.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.