Fix per vertex normals and colors import #6

Merged
Cedric Steiert merged 10 commits from Hombre57/io_scene_x3d:per-vertex_normals_and_colors into main 2024-08-07 12:04:13 +02:00
Showing only changes of commit 790902323c - Show all commits

View File

@ -1954,6 +1954,8 @@ def importMesh_IndexedFaceSet(geom, ancestry):
vectors = normals.getFieldAsArray('vector', 3, ancestry)
normal_index = geom.getFieldAsArray('normalIndex', 0, ancestry)
if per_vertex:
if len(normal_index) == 0:
normal_index = index
co = [co for f in processPerVertexIndex(normal_index)
for v in f
for co in vectors[v]]
@ -1980,7 +1982,6 @@ def importMesh_IndexedFaceSet(geom, ancestry):
color_per_vertex = geom.getFieldAsBool('colorPerVertex', True, ancestry)
color_index = geom.getFieldAsArray('colorIndex', 0, ancestry)
d = bpymesh.vertex_colors.new().data
if color_per_vertex:
cco = [cco for f in processPerVertexIndex(color_index)
for v in f
@ -1994,11 +1995,12 @@ def importMesh_IndexedFaceSet(geom, ancestry):
cco = [cco for (i, f) in enumerate(faces)
for j in f
for cco in rgb[color_index[i]]]
bpymesh.vertex_colors.new().data.foreach_set('color', cco) # deprecated
else: # Color per face without index
cco = [cco for (i, f) in enumerate(faces)
for j in f
for cco in rgb[i]]
d.foreach_set('color', cco)
bpymesh.vertex_colors.new().data.foreach_set('color', cco) # deprecated
# Texture coordinates (UVs)
tex_coord = geom.getChildBySpec('TextureCoordinate')
@ -2063,8 +2065,6 @@ def importMesh_IndexedFaceSet(geom, ancestry):
bpymesh.attributes["temp_custom_colors"].data.foreach_get("color", cco2)
bpymesh.color_attributes["Col"].data.foreach_set("color", cco2)
bpymesh.attributes.remove(bpymesh.attributes["temp_custom_colors"])
else:
bpymesh.validate()
bpymesh.update()
return bpymesh
@ -2739,7 +2739,7 @@ def appearance_CreateMaterial(vrmlname, mat, ancestry, is_vcol):
if is_vcol:
node_vertex_color = bpymat.node_tree.nodes.new("ShaderNodeVertexColor")
node_vertex_color.location = (-200, 300)
node_vertex_color.layer_name = "Col"
node_vertex_color.layer_name = "ColorPerCoin"
bpymat.node_tree.links.new(
bpymat_wrap.node_principled_bsdf.inputs["Base Color"],
@ -3038,7 +3038,7 @@ def importShape_ProcessObject(
# solid, as understood by the spec, is always true in Blender
# solid=false, we don't support it yet.
creaseAngle = geom.getFieldAsFloat('creaseAngle', None, ancestry)
if creaseAngle is not None:
if creaseAngle is not None and not bpydata.has_custom_normals:
bpydata.set_sharp_from_angle(angle=creaseAngle)
else:
bpydata.polygons.foreach_set("use_smooth", [False] * len(bpydata.polygons))