Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Upon further research, I think I might know the problem, but I'm not sure about this...</p> <p>From here: <a href="http://www.gamedev.net/topic/602169-opengl-drawing-cube-using-gldrawelements-and-gltexcoordpointer/page__p__4811454#entry4811454" rel="nofollow">http://www.gamedev.net/topic/602169-opengl-drawing-cube-using-gldrawelements-and-gltexcoordpointer/page_<em>p</em>_4811454#entry4811454</a></p> <blockquote> <p>This is a classical example of when you cannot use shared vertices. As soon as you introduce a vertex attribute other than position, the cube is required to have 24 vertices, not 8. The corners of a cube are not shared vertices, because they don't have the same texture coordinates.</p> <p>For example, the first two triangles are made up of the indices [0, 1, 2, 0, 2, 3], and if you reference the vertex and texture coordinate arrays, that face is fine. The second two triangles are made up of the indices [0, 4, 5, 0, 5, 1], and while the vertex array is referenced correct to make second face of the cube, the resulting texture coordinates are entirely broken.</p> </blockquote> <p>Am I right about this being my problem, or am I way off?</p> <p><strong>Edit:</strong> Almost got textures working by using more vertex positions. Now the only problem is that one face of a simple cube will be warped and diagonal to its correct position. All other faces are looking good. </p> <p>Here's the function that's almost working:</p> <pre><code>def get_json(objects, scene): """ Currently only supports one scene. Exports with -Z forward, Y up. """ object_number = -1 scene_data = [] # for every object in the scene for object in bpy.context.scene.objects: # if the object is a mesh if object.type == 'MESH': object_number += 1 # convert all the mesh's faces to triangles bpy.ops.object.mode_set(mode='OBJECT') object.select = True bpy.context.scene.objects.active = object # triangulate using new Blender 2.65 Triangulate modifier bpy.ops.object.modifier_add(type='TRIANGULATE') object.modifiers["Triangulate"].use_beauty = False bpy.ops.object.modifier_apply(apply_as="DATA", modifier="Triangulate") bpy.ops.object.mode_set(mode='OBJECT') object.select = False # add data to scene_data structure scene_data.append({ "name" : object.name, "vertices" : [], "indices" : [], "normals" : [], "tex_coords" : [] }) vertex_number = -1 # for each face in the object for face in object.data.polygons: vertices_in_face = face.vertices[:] # for each vertex in the face for vertex in vertices_in_face: vertex_number += 1 # store vertices in scene_data structure scene_data[object_number]["vertices"].append( object.data.vertices[vertex].co.x + object.location.x ) scene_data[object_number]["vertices"].append( object.data.vertices[vertex].co.z + object.location.z ) scene_data[object_number]["vertices"].append( -(object.data.vertices[vertex].co.y + object.location.y) ) # store normals in scene_data structure scene_data[object_number]["normals"].append( object.data.vertices[vertex].normal.x ) scene_data[object_number]["normals"].append( object.data.vertices[vertex].normal.z ) scene_data[object_number]["normals"].append( -(object.data.vertices[vertex].normal.y) ) # store indices in scene_data structure scene_data[object_number]["indices"].append(vertex_number) # texture coordinates # bug: for a simple cube, one face's texture is warped mesh = object.to_mesh(bpy.context.scene, True, 'PREVIEW') if len(mesh.tessface_uv_textures) &gt; 0: for data in mesh.tessface_uv_textures.active.data: scene_data[object_number]["tex_coords"].append( data.uv1.x ) scene_data[object_number]["tex_coords"].append( data.uv1.y ) scene_data[object_number]["tex_coords"].append( data.uv2.x ) scene_data[object_number]["tex_coords"].append( data.uv2.y ) scene_data[object_number]["tex_coords"].append( data.uv3.x ) scene_data[object_number]["tex_coords"].append( data.uv3.y ) return json.dumps(scene_data, indent=4) </code></pre> <p>I'm wondering what could be the cause of only one face's texture being warped? I'm almost there, but can't seem to figure this one out.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload