|
@@ -12,6 +12,18 @@ from . import object as object_
|
|
|
from .. import constants, utilities, logger, exceptions
|
|
|
|
|
|
|
|
|
+# flips vectors
|
|
|
+
|
|
|
+#TODO: add these strings into constants.py
|
|
|
+
|
|
|
+def flip_axes (v, dir="XYZ"):
|
|
|
+
|
|
|
+ if dir == "XZ_Y":
|
|
|
+ v = (v.x, v.z, -v.y)
|
|
|
+
|
|
|
+ return v
|
|
|
+
|
|
|
+
|
|
|
def _mesh(func):
|
|
|
"""
|
|
|
|
|
@@ -107,7 +119,7 @@ def bones(mesh, options):
|
|
|
|
|
|
|
|
|
@_mesh
|
|
|
-def buffer_normal(mesh):
|
|
|
+def buffer_normal(mesh, options):
|
|
|
"""
|
|
|
|
|
|
:param mesh:
|
|
@@ -122,10 +134,37 @@ def buffer_normal(mesh):
|
|
|
msg = "Non-triangulated face detected"
|
|
|
raise exceptions.BufferGeometryError(msg)
|
|
|
|
|
|
- for vertex_index in face.vertices:
|
|
|
- normal = mesh.vertices[vertex_index].normal
|
|
|
- vector = (normal.x, normal.y, normal.z) if face.use_smooth else (face.normal.x, face.normal.y, face.normal.z)
|
|
|
- normals_.extend(vector)
|
|
|
+ # using Object Loader with skinned mesh
|
|
|
+ if options.get(constants.SCENE, True) and _armature(mesh):
|
|
|
+
|
|
|
+ for vertex_index in face.vertices:
|
|
|
+ normal = mesh.vertices[vertex_index].normal
|
|
|
+ vector = (normal.x, normal.z, -normal.y) if face.use_smooth else (face.normal.x, face.normal.z, -face.normal.y)
|
|
|
+ normals_.extend(vector)
|
|
|
+
|
|
|
+ # using Object Loader with static mesh
|
|
|
+ elif options.get(constants.SCENE, True) and not _armature(mesh):
|
|
|
+
|
|
|
+ for vertex_index in face.vertices:
|
|
|
+ normal = mesh.vertices[vertex_index].normal
|
|
|
+ vector = (normal.x, normal.y, normal.z) if face.use_smooth else (face.normal.x, face.normal.y, face.normal.z)
|
|
|
+ normals_.extend(vector)
|
|
|
+
|
|
|
+ # using JSON Loader with skinned mesh
|
|
|
+ elif not options.get(constants.SCENE, True) and _armature(mesh):
|
|
|
+
|
|
|
+ for vertex_index in face.vertices:
|
|
|
+ normal = mesh.vertices[vertex_index].normal
|
|
|
+ vector = (normal.x, normal.y, normal.z) if face.use_smooth else (face.normal.x, face.normal.y, face.normal.z)
|
|
|
+ normals_.extend(vector)
|
|
|
+
|
|
|
+ # using JSON Loader with static mesh
|
|
|
+ else:
|
|
|
+
|
|
|
+ for vertex_index in face.vertices:
|
|
|
+ normal = mesh.vertices[vertex_index].normal
|
|
|
+ vector = (normal.x, normal.y, normal.z) if face.use_smooth else (face.normal.x, face.normal.y, face.normal.z)
|
|
|
+ normals_.extend(vector)
|
|
|
|
|
|
return normals_
|
|
|
|
|
@@ -146,10 +185,37 @@ def buffer_position(mesh):
|
|
|
msg = "Non-triangulated face detected"
|
|
|
raise exceptions.BufferGeometryError(msg)
|
|
|
|
|
|
- for vertex_index in face.vertices:
|
|
|
- vertex = mesh.vertices[vertex_index]
|
|
|
- vector = (vertex.co.x, vertex.co.y, vertex.co.z)
|
|
|
- position.extend(vector)
|
|
|
+ # using Object Loader with skinned mesh
|
|
|
+ if options.get(constants.SCENE, True) and _armature(mesh):
|
|
|
+
|
|
|
+ for vertex_index in face.vertices:
|
|
|
+ vertex = mesh.vertices[vertex_index]
|
|
|
+ vector = (vertex.co.x, vertex.co.z, -vertex.co.y)
|
|
|
+ position.extend(vector)
|
|
|
+
|
|
|
+ # using Object Loader with static mesh
|
|
|
+ elif options.get(constants.SCENE, True) and not _armature(mesh):
|
|
|
+
|
|
|
+ for vertex_index in face.vertices:
|
|
|
+ vertex = mesh.vertices[vertex_index]
|
|
|
+ vector = (vertex.co.x, vertex.co.y, vertex.co.z)
|
|
|
+ position.extend(vector)
|
|
|
+
|
|
|
+ # using JSON Loader with skinned mesh
|
|
|
+ elif not options.get(constants.SCENE, True) and _armature(mesh):
|
|
|
+
|
|
|
+ for vertex_index in face.vertices:
|
|
|
+ vertex = mesh.vertices[vertex_index]
|
|
|
+ vector = (vertex.co.x, vertex.co.y, vertex.co.z)
|
|
|
+ position.extend(vector)
|
|
|
+
|
|
|
+ # using JSON Loader with static mesh
|
|
|
+ else:
|
|
|
+
|
|
|
+ for vertex_index in face.vertices:
|
|
|
+ vertex = mesh.vertices[vertex_index]
|
|
|
+ vector = (vertex.co.x, vertex.co.y, vertex.co.z)
|
|
|
+ position.extend(vector)
|
|
|
|
|
|
return position
|
|
|
|
|
@@ -293,7 +359,7 @@ def faces(mesh, options, material_list=None):
|
|
|
logger.debug("Normals enabled = %s", opt_normals)
|
|
|
|
|
|
uv_indices = _uvs(mesh)[1] if opt_uvs else None
|
|
|
- vertex_normals = _normals(mesh) if opt_normals else None
|
|
|
+ vertex_normals = _normals(mesh, options) if opt_normals else None
|
|
|
vertex_colours = vertex_colors(mesh) if opt_colours else None
|
|
|
|
|
|
faces_data = []
|
|
@@ -307,9 +373,34 @@ def faces(mesh, options, material_list=None):
|
|
|
normal_indices = {}
|
|
|
if vertex_normals:
|
|
|
logger.debug("Indexing normals")
|
|
|
- for index, normal in enumerate(vertex_normals):
|
|
|
- normal = (normal[0], normal[2], -normal[1])
|
|
|
- normal_indices[str(normal)] = index
|
|
|
+
|
|
|
+ # using Object Loader with skinned mesh
|
|
|
+ if options.get(constants.SCENE, True) and _armature(mesh):
|
|
|
+
|
|
|
+ for index, normal in enumerate(vertex_normals):
|
|
|
+ normal = (normal[0], -normal[2], normal[1])
|
|
|
+ normal_indices[str(normal)] = index
|
|
|
+
|
|
|
+ # using Object Loader with static mesh
|
|
|
+ elif options.get(constants.SCENE, True) and not _armature(mesh):
|
|
|
+
|
|
|
+ for index, normal in enumerate(vertex_normals):
|
|
|
+ normal = (normal[0], normal[1], normal[2])
|
|
|
+ normal_indices[str(normal)] = index
|
|
|
+
|
|
|
+ # using JSON Loader with skinned mesh
|
|
|
+ elif not options.get(constants.SCENE, True) and _armature(mesh):
|
|
|
+
|
|
|
+ for index, normal in enumerate(vertex_normals):
|
|
|
+ normal = (normal[0], normal[1], normal[2])
|
|
|
+ normal_indices[str(normal)] = index
|
|
|
+
|
|
|
+ # using JSON Loader with static mesh
|
|
|
+ else:
|
|
|
+
|
|
|
+ for index, normal in enumerate(vertex_normals):
|
|
|
+ normal = (normal[0], normal[1], normal[2])
|
|
|
+ normal_indices[str(normal)] = index
|
|
|
|
|
|
logger.info("Parsing %d faces", len(mesh.tessfaces))
|
|
|
for face in mesh.tessfaces:
|
|
@@ -355,11 +446,46 @@ def faces(mesh, options, material_list=None):
|
|
|
mask[constants.UVS] = True
|
|
|
|
|
|
if vertex_normals:
|
|
|
- for vertex in face.vertices:
|
|
|
- normal = mesh.vertices[vertex].normal
|
|
|
- normal = (normal.x, normal.z, -normal.y) if face.use_smooth else (face.normal.x, face.normal.z, -face.normal.y)
|
|
|
- face_data.append(normal_indices[str(normal)])
|
|
|
- mask[constants.NORMALS] = True
|
|
|
+
|
|
|
+ # using Object Loader with skinned mesh
|
|
|
+ if options.get(constants.SCENE, True) and _armature(mesh):
|
|
|
+
|
|
|
+ for vertex in face.vertices:
|
|
|
+ normal = mesh.vertices[vertex].normal
|
|
|
+ normal = (normal.x, normal.y, normal.z) if face.use_smooth else (face.normal.x, face.normal.y, face.normal.z)
|
|
|
+
|
|
|
+ face_data.append(normal_indices[str(normal)])
|
|
|
+ mask[constants.NORMALS] = True
|
|
|
+
|
|
|
+ # using Object Loader with static mesh
|
|
|
+ elif options.get(constants.SCENE, True) and not _armature(mesh):
|
|
|
+
|
|
|
+ for vertex in face.vertices:
|
|
|
+ normal = mesh.vertices[vertex].normal
|
|
|
+ normal = (normal.x, normal.y, normal.z) if face.use_smooth else (face.normal.x, face.normal.y, face.normal.z)
|
|
|
+
|
|
|
+ face_data.append(normal_indices[str(normal)])
|
|
|
+ mask[constants.NORMALS] = True
|
|
|
+
|
|
|
+ # using JSON Loader with skinned mesh
|
|
|
+ elif not options.get(constants.SCENE, True) and _armature(mesh):
|
|
|
+
|
|
|
+ for vertex in face.vertices:
|
|
|
+ normal = mesh.vertices[vertex].normal
|
|
|
+ normal = (normal.x, normal.y, normal.z) if face.use_smooth else (face.normal.x, face.normal.y, face.normal.z)
|
|
|
+
|
|
|
+ face_data.append(normal_indices[str(normal)])
|
|
|
+ mask[constants.NORMALS] = True
|
|
|
+
|
|
|
+ # using JSON Loader with static mesh
|
|
|
+ else:
|
|
|
+
|
|
|
+ for vertex in face.vertices:
|
|
|
+ normal = mesh.vertices[vertex].normal
|
|
|
+ normal = (normal.x, normal.y, normal.z) if face.use_smooth else (face.normal.x, face.normal.y, face.normal.z)
|
|
|
+
|
|
|
+ face_data.append(normal_indices[str(normal)])
|
|
|
+ mask[constants.NORMALS] = True
|
|
|
|
|
|
if vertex_colours:
|
|
|
colours = mesh.tessface_vertex_colors.active.data[face.index]
|
|
@@ -403,8 +529,29 @@ def morph_targets(mesh, options):
|
|
|
morphs.append([])
|
|
|
vertices_ = object_.extract_mesh(obj, options).vertices[:]
|
|
|
|
|
|
- for vertex in vertices_:
|
|
|
- morphs[-1].extend([vertex.co.x, vertex.co.y, vertex.co.z])
|
|
|
+ # using Object Loader with skinned mesh
|
|
|
+ if options.get(constants.SCENE, True) and _armature(mesh):
|
|
|
+
|
|
|
+ for vertex in vertices_:
|
|
|
+ morphs[-1].extend([vertex.co.x, vertex.co.z, -vertex.co.y])
|
|
|
+
|
|
|
+ # using Object Loader with static mesh
|
|
|
+ elif options.get(constants.SCENE, True) and not _armature(mesh):
|
|
|
+
|
|
|
+ for vertex in vertices_:
|
|
|
+ morphs[-1].extend([vertex.co.x, vertex.co.y, vertex.co.z])
|
|
|
+
|
|
|
+ # using JSON Loader with skinned mesh
|
|
|
+ elif not options.get(constants.SCENE, True) and _armature(mesh):
|
|
|
+
|
|
|
+ for vertex in vertices_:
|
|
|
+ morphs[-1].extend([vertex.co.x, vertex.co.y, vertex.co.z])
|
|
|
+
|
|
|
+ # using JSON Loader with static mesh
|
|
|
+ else:
|
|
|
+
|
|
|
+ for vertex in vertices_:
|
|
|
+ morphs[-1].extend([vertex.co.x, vertex.co.y, vertex.co.z])
|
|
|
|
|
|
context.scene.frame_set(original_frame, 0.0)
|
|
|
morphs_detected = False
|
|
@@ -605,7 +752,7 @@ def materials(mesh, options):
|
|
|
|
|
|
|
|
|
@_mesh
|
|
|
-def normals(mesh):
|
|
|
+def normals(mesh, options):
|
|
|
"""
|
|
|
|
|
|
:param mesh:
|
|
@@ -615,7 +762,7 @@ def normals(mesh):
|
|
|
logger.debug("mesh.normals(%s)", mesh)
|
|
|
normal_vectors = []
|
|
|
|
|
|
- for vector in _normals(mesh):
|
|
|
+ for vector in _normals(mesh, options):
|
|
|
normal_vectors.extend(vector)
|
|
|
|
|
|
return normal_vectors
|
|
@@ -752,7 +899,7 @@ def vertex_colors(mesh):
|
|
|
|
|
|
|
|
|
@_mesh
|
|
|
-def vertices(mesh):
|
|
|
+def vertices(mesh, options):
|
|
|
"""
|
|
|
|
|
|
:param mesh:
|
|
@@ -762,8 +909,29 @@ def vertices(mesh):
|
|
|
logger.debug("mesh.vertices(%s)", mesh)
|
|
|
vertices_ = []
|
|
|
|
|
|
- for vertex in mesh.vertices:
|
|
|
- vertices_.extend((vertex.co.x, vertex.co.y, vertex.co.z))
|
|
|
+ # using Object Loader with skinned mesh
|
|
|
+ if options.get(constants.SCENE, True) and _armature(mesh):
|
|
|
+
|
|
|
+ for vertex in mesh.vertices:
|
|
|
+ vertices_.extend((vertex.co.x, vertex.co.z, -vertex.co.y))
|
|
|
+
|
|
|
+ # using Object Loader with static mesh
|
|
|
+ elif options.get(constants.SCENE, True) and not _armature(mesh):
|
|
|
+
|
|
|
+ for vertex in mesh.vertices:
|
|
|
+ vertices_.extend((vertex.co.x, vertex.co.y, vertex.co.z))
|
|
|
+
|
|
|
+ # using JSON Loader with skinned mesh
|
|
|
+ elif not options.get(constants.SCENE, True) and _armature(mesh):
|
|
|
+
|
|
|
+ for vertex in mesh.vertices:
|
|
|
+ vertices_.extend((vertex.co.x, vertex.co.y, vertex.co.z))
|
|
|
+
|
|
|
+ # using JSON Loader with static mesh
|
|
|
+ else:
|
|
|
+
|
|
|
+ for vertex in mesh.vertices:
|
|
|
+ vertices_.extend((vertex.co.x, vertex.co.y, vertex.co.z))
|
|
|
|
|
|
return vertices_
|
|
|
|
|
@@ -892,7 +1060,7 @@ def _diffuse_map(mat):
|
|
|
return diffuse
|
|
|
|
|
|
|
|
|
-def _normals(mesh):
|
|
|
+def _normals(mesh, options):
|
|
|
"""
|
|
|
|
|
|
:param mesh:
|
|
@@ -904,16 +1072,57 @@ def _normals(mesh):
|
|
|
vectors_ = {}
|
|
|
for face in mesh.tessfaces:
|
|
|
|
|
|
- for vertex_index in face.vertices:
|
|
|
- normal = mesh.vertices[vertex_index].normal
|
|
|
- vector = (normal.x, normal.y, normal.z) if face.use_smooth else (face.normal.x, face.normal.y, face.normal.z)
|
|
|
+ if options.get(constants.SCENE, True) and _armature(mesh):
|
|
|
+
|
|
|
+ for vertex_index in face.vertices:
|
|
|
+ normal = mesh.vertices[vertex_index].normal
|
|
|
+ vector = (normal.x, normal.z, -normal.y) if face.use_smooth else (face.normal.x, face.normal.z, -face.normal.y)
|
|
|
+
|
|
|
+ str_vec = str(vector)
|
|
|
+ try:
|
|
|
+ vectors_[str_vec]
|
|
|
+ except KeyError:
|
|
|
+ vectors.append(vector)
|
|
|
+ vectors_[str_vec] = True
|
|
|
+
|
|
|
+ elif options.get(constants.SCENE, True) and not _armature(mesh):
|
|
|
+
|
|
|
+ for vertex_index in face.vertices:
|
|
|
+ normal = mesh.vertices[vertex_index].normal
|
|
|
+ vector = (normal.x, normal.y, normal.z) if face.use_smooth else (face.normal.x, face.normal.y, face.normal.z)
|
|
|
+
|
|
|
+ str_vec = str(vector)
|
|
|
+ try:
|
|
|
+ vectors_[str_vec]
|
|
|
+ except KeyError:
|
|
|
+ vectors.append(vector)
|
|
|
+ vectors_[str_vec] = True
|
|
|
+
|
|
|
+ elif not options.get(constants.SCENE, True) and _armature(mesh):
|
|
|
+
|
|
|
+ for vertex_index in face.vertices:
|
|
|
+ normal = mesh.vertices[vertex_index].normal
|
|
|
+ vector = (normal.x, normal.y, normal.z) if face.use_smooth else (face.normal.x, face.normal.y, face.normal.z)
|
|
|
+
|
|
|
+ str_vec = str(vector)
|
|
|
+ try:
|
|
|
+ vectors_[str_vec]
|
|
|
+ except KeyError:
|
|
|
+ vectors.append(vector)
|
|
|
+ vectors_[str_vec] = True
|
|
|
|
|
|
- str_vec = str(vector)
|
|
|
- try:
|
|
|
- vectors_[str_vec]
|
|
|
- except KeyError:
|
|
|
- vectors.append(vector)
|
|
|
- vectors_[str_vec] = True
|
|
|
+ else:
|
|
|
+
|
|
|
+ for vertex_index in face.vertices:
|
|
|
+ normal = mesh.vertices[vertex_index].normal
|
|
|
+ vector = (normal.x, normal.y, normal.z) if face.use_smooth else (face.normal.x, face.normal.y, face.normal.z)
|
|
|
+
|
|
|
+ str_vec = str(vector)
|
|
|
+ try:
|
|
|
+ vectors_[str_vec]
|
|
|
+ except KeyError:
|
|
|
+ vectors.append(vector)
|
|
|
+ vectors_[str_vec] = True
|
|
|
|
|
|
return vectors
|
|
|
|