블렌더 2.6x 용 간단한 JSON 내보내기 도구를 작성하려고합니다. (http://code.google.com/p/blender-machete/) 2.6에서 작동하지 않습니다. 블렌더에서 정점, 법선 및 인덱스를 얻는 데 아무런 문제가 없었지만 가능한 한 시도해 보았습니다. 왜 텍스처 좌표가 잘못 나오는 지 알 수 없습니다. 텍스처는 단순한 큐브의면을 가로 질러 대각선으로 기울어 진 것처럼 보입니다. 그리고 쭉 뻗었습니다. 정말 못 생겼고 잘못되었습니다. 나는 공식적인 수출업자들을 위해 온라인을 통해 소스를 찾고 있었지만 아직도 그것을 이해할 수 없기 때문에 누군가가 나에게 약간의 힌트 나 해결책을 줄 수 있기를 바랬다.블렌더 2.6 JSON 내보내기, 텍스처 좌표 문제
내가 텍스처 좌표에 액세스하는 데 사용하고 코드의 조각은 이것이다 :
# add texture coordinates to scene_data structure
m = bpy.context.active_object.to_mesh(bpy.context.scene, True, 'PREVIEW')
for j in range(len(m.tessfaces)):
if len(m.tessface_uv_textures) > 0:
scene_data[mesh_number]["tex_coords"].append(m.tessface_uv_textures.active.data[j].uv1.x)
scene_data[mesh_number]["tex_coords"].append(m.tessface_uv_textures.active.data[j].uv1.y)
scene_data[mesh_number]["tex_coords"].append(m.tessface_uv_textures.active.data[j].uv2.x)
scene_data[mesh_number]["tex_coords"].append(m.tessface_uv_textures.active.data[j].uv2.y)
scene_data[mesh_number]["tex_coords"].append(m.tessface_uv_textures.active.data[j].uv3.x)
scene_data[mesh_number]["tex_coords"].append(m.tessface_uv_textures.active.data[j].uv3.y)
이유로 인해 잘못된 때문에, 이것은 나에게 텍스처 좌표의 목록을 제공하고 있습니다 만, 어떻게 든 내가 잘못하고 있어요 위에서 설명한대로 텍스처의 모양.
내가해야 할 다른 무엇을 알고 있지만 내가 지금 여기에 위의 코드 조각은 함수의, 내가 생각할 수있는 모든 방법으로 주위를 변경하려 했으므로 코드를 표시하지 않습니다:
def get_json(objects, scene):
""" Currently only supports one scene.
Exports with -Z forward, Y up. """
scene_data = []
mesh_number = -1
# iterate over each mesh
for i in range(len(bpy.data.objects)):
if bpy.data.objects[i].type == 'MESH':
mesh_number += 1
bpy.ops.object.mode_set(mode='OBJECT')
# convert all the mesh's faces to triangles
bpy.data.objects[i].select = True
bpy.context.scene.objects.active = bpy.data.objects[i]
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.quads_convert_to_tris()
bpy.context.scene.update()
bpy.ops.object.mode_set(mode='OBJECT')
bpy.data.objects[i].select = False
# add data to scene_data structure
scene_data.append({
"name" : bpy.data.objects[i].name,
"vertices" : [],
"indices" : [],
"normals" : [],
"tex_coords" : []
})
# iterate over all the vertices in the mesh
for j in range(len(bpy.data.objects[i].data.vertices)):
# add vertex to scene_data structure
scene_data[mesh_number]["vertices"].append(bpy.data.objects[i].data.vertices[j].co.x + bpy.data.objects[i].location.x)
scene_data[mesh_number]["vertices"].append(bpy.data.objects[i].data.vertices[j].co.z + bpy.data.objects[i].location.z)
scene_data[mesh_number]["vertices"].append(-(bpy.data.objects[i].data.vertices[j].co.y + bpy.data.objects[i].location.y))
# add vertex normal to scene_data structure
scene_data[mesh_number]["normals"].append(bpy.data.objects[i].data.vertices[j].normal.x)
scene_data[mesh_number]["normals"].append(bpy.data.objects[i].data.vertices[j].normal.z)
scene_data[mesh_number]["normals"].append(-(bpy.data.objects[i].data.vertices[j].normal.y))
# iterate over each face in the mesh
for j in range(len(bpy.data.objects[i].data.polygons)):
verts_in_face = bpy.data.objects[i].data.polygons[j].vertices[:]
# iterate over each vertex in the face
for k in range(len(verts_in_face)):
# twiddle index for -Z forward, Y up
index = k
if index == 1: index = 2
elif index == 2: index = 1
# twiddle index so we draw triangles counter-clockwise
if index == 0: index = 2
elif index == 2: index = 0
# add index to scene_data structure
scene_data[mesh_number]["indices"].append(verts_in_face[index])
# add texture coordinates to scene_data structure
m = bpy.context.active_object.to_mesh(bpy.context.scene, True, 'PREVIEW')
for j in range(len(m.tessfaces)):
if len(m.tessface_uv_textures) > 0:
scene_data[mesh_number]["tex_coords"].append(m.tessface_uv_textures.active.data[j].uv1.x)
scene_data[mesh_number]["tex_coords"].append(m.tessface_uv_textures.active.data[j].uv1.y)
scene_data[mesh_number]["tex_coords"].append(m.tessface_uv_textures.active.data[j].uv2.x)
scene_data[mesh_number]["tex_coords"].append(m.tessface_uv_textures.active.data[j].uv2.y)
scene_data[mesh_number]["tex_coords"].append(m.tessface_uv_textures.active.data[j].uv3.x)
scene_data[mesh_number]["tex_coords"].append(m.tessface_uv_textures.active.data[j].uv3.y)
return json.dumps(scene_data, indent=4)
가
누군가 내가 잘못하고있는 것을 알려주시겠습니까? 나는 지금 아무런 진전없이 며칠 동안이 일을 해왔다. 추가 연구, 내가 문제를 알고 있다고 생각하지만, 나는 이것에 대해 잘 모르겠어요시