FBX IO: Vertex position access with attributes #104647
@ -894,12 +894,10 @@ def fbx_data_mesh_elements(root, me_obj, scene_data, done_meshes):
|
|||||||
attributes = me.attributes
|
attributes = me.attributes
|
||||||
|
|
||||||
# Vertex cos.
|
# Vertex cos.
|
||||||
co_bl_dtype = np.single
|
pos_fbx_dtype = np.float64
|
||||||
co_fbx_dtype = np.float64
|
t_pos = MESH_ATTRIBUTE_POSITION.to_ndarray(attributes)
|
||||||
t_co = np.empty(len(me.vertices) * 3, dtype=co_bl_dtype)
|
elem_data_single_float64_array(geom, b"Vertices", vcos_transformed(t_pos, geom_mat_co, pos_fbx_dtype))
|
||||||
me.vertices.foreach_get("co", t_co)
|
del t_pos
|
||||||
elem_data_single_float64_array(geom, b"Vertices", vcos_transformed(t_co, geom_mat_co, co_fbx_dtype))
|
|
||||||
del t_co
|
|
||||||
|
|
||||||
# Polygon indices.
|
# Polygon indices.
|
||||||
#
|
#
|
||||||
@ -2662,10 +2660,10 @@ def fbx_data_from_scene(scene, depsgraph, settings):
|
|||||||
# Get and cache only the cos that we need
|
# Get and cache only the cos that we need
|
||||||
@cache
|
@cache
|
||||||
def sk_cos(shape_key):
|
def sk_cos(shape_key):
|
||||||
_cos = np.empty(len(me.vertices) * 3, dtype=co_bl_dtype)
|
|
||||||
if shape_key == sk_base:
|
if shape_key == sk_base:
|
||||||
me.vertices.foreach_get("co", _cos)
|
_cos = MESH_ATTRIBUTE_POSITION.to_ndarray(me.attributes)
|
||||||
else:
|
else:
|
||||||
|
_cos = np.empty(len(me.vertices) * 3, dtype=co_bl_dtype)
|
||||||
shape_key.data.foreach_get("co", _cos)
|
shape_key.data.foreach_get("co", _cos)
|
||||||
return vcos_transformed(_cos, geom_mat_co, co_fbx_dtype)
|
return vcos_transformed(_cos, geom_mat_co, co_fbx_dtype)
|
||||||
|
|
||||||
|
@ -1452,8 +1452,6 @@ def blen_read_geom(fbx_tmpl, fbx_obj, settings):
|
|||||||
fbx_polys = elem_prop_first(elem_find_first(fbx_obj, b'PolygonVertexIndex'))
|
fbx_polys = elem_prop_first(elem_find_first(fbx_obj, b'PolygonVertexIndex'))
|
||||||
fbx_edges = elem_prop_first(elem_find_first(fbx_obj, b'Edges'))
|
fbx_edges = elem_prop_first(elem_find_first(fbx_obj, b'Edges'))
|
||||||
|
|
||||||
bl_vcos_dtype = np.single
|
|
||||||
|
|
||||||
# The dtypes when empty don't matter, but are set to what the fbx arrays are expected to be.
|
# The dtypes when empty don't matter, but are set to what the fbx arrays are expected to be.
|
||||||
fbx_verts = parray_as_ndarray(fbx_verts) if fbx_verts else np.empty(0, dtype=data_types.ARRAY_FLOAT64)
|
fbx_verts = parray_as_ndarray(fbx_verts) if fbx_verts else np.empty(0, dtype=data_types.ARRAY_FLOAT64)
|
||||||
fbx_polys = parray_as_ndarray(fbx_polys) if fbx_polys else np.empty(0, dtype=data_types.ARRAY_INT32)
|
fbx_polys = parray_as_ndarray(fbx_polys) if fbx_polys else np.empty(0, dtype=data_types.ARRAY_INT32)
|
||||||
@ -1474,12 +1472,12 @@ def blen_read_geom(fbx_tmpl, fbx_obj, settings):
|
|||||||
|
|
||||||
if tot_verts:
|
if tot_verts:
|
||||||
if geom_mat_co is not None:
|
if geom_mat_co is not None:
|
||||||
fbx_verts = vcos_transformed(fbx_verts, geom_mat_co, bl_vcos_dtype)
|
fbx_verts = vcos_transformed(fbx_verts, geom_mat_co, MESH_ATTRIBUTE_POSITION.dtype)
|
||||||
else:
|
else:
|
||||||
fbx_verts = fbx_verts.astype(bl_vcos_dtype, copy=False)
|
fbx_verts = fbx_verts.astype(MESH_ATTRIBUTE_POSITION.dtype, copy=False)
|
||||||
|
|
||||||
mesh.vertices.add(tot_verts)
|
mesh.vertices.add(tot_verts)
|
||||||
mesh.vertices.foreach_set("co", fbx_verts.ravel())
|
MESH_ATTRIBUTE_POSITION.foreach_set(attributes, fbx_verts.ravel())
|
||||||
|
|
||||||
if tot_loops:
|
if tot_loops:
|
||||||
bl_loop_start_dtype = bl_loop_vertex_index_dtype = np.uintc
|
bl_loop_start_dtype = bl_loop_vertex_index_dtype = np.uintc
|
||||||
@ -1596,9 +1594,7 @@ def blen_read_shapes(fbx_tmpl, fbx_data, objects, me, scene):
|
|||||||
# No shape key data. Nothing to do.
|
# No shape key data. Nothing to do.
|
||||||
return
|
return
|
||||||
|
|
||||||
bl_vcos_dtype = np.single
|
me_vcos = MESH_ATTRIBUTE_POSITION.to_ndarray(me.attributes)
|
||||||
me_vcos = np.empty(len(me.vertices) * 3, dtype=bl_vcos_dtype)
|
|
||||||
me.vertices.foreach_get("co", me_vcos)
|
|
||||||
me_vcos_vector_view = me_vcos.reshape(-1, 3)
|
me_vcos_vector_view = me_vcos.reshape(-1, 3)
|
||||||
|
|
||||||
objects = list({node.bl_obj for node in objects})
|
objects = list({node.bl_obj for node in objects})
|
||||||
@ -3530,19 +3526,18 @@ def load(operator, context, filepath="",
|
|||||||
if fbx_obj.props[-1] == b'Mesh':
|
if fbx_obj.props[-1] == b'Mesh':
|
||||||
mesh = fbx_item[1]
|
mesh = fbx_item[1]
|
||||||
|
|
||||||
if decal_offset != 0.0:
|
num_verts = len(mesh.vertices)
|
||||||
|
if decal_offset != 0.0 and num_verts > 0:
|
||||||
for material in mesh.materials:
|
for material in mesh.materials:
|
||||||
if material in material_decals:
|
if material in material_decals:
|
||||||
num_verts = len(mesh.vertices)
|
blen_norm_dtype = np.single
|
||||||
blen_cos_dtype = blen_norm_dtype = np.single
|
vcos = MESH_ATTRIBUTE_POSITION.to_ndarray(mesh.attributes)
|
||||||
vcos = np.empty(num_verts * 3, dtype=blen_cos_dtype)
|
|
||||||
vnorm = np.empty(num_verts * 3, dtype=blen_norm_dtype)
|
vnorm = np.empty(num_verts * 3, dtype=blen_norm_dtype)
|
||||||
mesh.vertices.foreach_get("co", vcos)
|
|
||||||
mesh.vertex_normals.foreach_get("vector", vnorm)
|
mesh.vertex_normals.foreach_get("vector", vnorm)
|
||||||
|
|
||||||
vcos += vnorm * decal_offset
|
vcos += vnorm * decal_offset
|
||||||
|
|
||||||
mesh.vertices.foreach_set("co", vcos)
|
MESH_ATTRIBUTE_POSITION.foreach_set(mesh.attributes, vcos)
|
||||||
break
|
break
|
||||||
|
|
||||||
for obj in (obj for obj in bpy.data.objects if obj.data == mesh):
|
for obj in (obj for obj in bpy.data.objects if obj.data == mesh):
|
||||||
|
Loading…
Reference in New Issue
Block a user