fix wrl files with pixel image textures not importing correctly #4
@ -1,7 +1,7 @@
|
||||
schema_version = "1.0.0"
|
||||
id = "web3d_x3d_vrml2_format"
|
||||
name = "Web3D X3D/VRML2 format"
|
||||
version = "2.3.3"
|
||||
version = "2.3.4"
|
||||
tagline = "Import-Export X3D, Import VRML2"
|
||||
maintainer = "Community"
|
||||
type = "add-on"
|
||||
|
@ -1879,6 +1879,10 @@ def importMesh_IndexedFaceSet(geom, ancestry):
|
||||
|
||||
ccw = geom.getFieldAsBool('ccw', True, ancestry)
|
||||
coord = geom.getChildBySpec('Coordinate')
|
||||
|
||||
if coord is None:
|
||||
return None
|
||||
|
||||
if coord.reference:
|
||||
points = coord.getRealNode().parsed
|
||||
# We need unflattened coord array here, while
|
||||
@ -1976,16 +1980,37 @@ def importMesh_IndexedFaceSet(geom, ancestry):
|
||||
|
||||
color_per_vertex = geom.getFieldAsBool('colorPerVertex', True, ancestry)
|
||||
color_index = geom.getFieldAsArray('colorIndex', 0, ancestry)
|
||||
has_color_index = len(color_index) != 0
|
||||
has_valid_color_index = index.count(-1) == color_index.count(-1)
|
||||
|
||||
d = bpymesh.vertex_colors.new().data
|
||||
if color_per_vertex:
|
||||
|
||||
# rebuild a corrupted colorIndex field (assuming the end of face markers -1 are missing)
|
||||
if has_color_index and not has_valid_color_index:
|
||||
# remove all -1 beforehand to ensure clean working copy
|
||||
color_index = [x for x in color_index if x != -1]
|
||||
# copy all -1 from coordIndex to colorIndex
|
||||
for i, v in enumerate(index):
|
||||
if v == -1:
|
||||
color_index.insert(i, -1)
|
||||
|
||||
if color_per_vertex and has_color_index: # Color per vertex with index
|
||||
cco = [cco for f in processPerVertexIndex(color_index)
|
||||
for v in f
|
||||
for cco in rgb[v]]
|
||||
for v in f
|
||||
for cco in rgb[v]]
|
||||
elif color_per_vertex: # Color per vertex without index
|
||||
cco = [cco for f in faces
|
||||
for (i, v) in enumerate(f)
|
||||
for cco in rgb[i]]
|
||||
elif color_index: # Color per face with index
|
||||
cco = [cco for (i, f) in enumerate(faces)
|
||||
for j in f
|
||||
for cco in rgb[color_index[i]]]
|
||||
elif len(faces) > len(rgb): # Static color per face without index, when all faces have the same color.
|
||||
# Exported from SOLIDWORKS, see: `blender/blender-addons#105398`.
|
||||
cco = [cco for (i, f) in enumerate(faces)
|
||||
for j in f
|
||||
for cco in rgb[0]]
|
||||
else: # Color per face without index
|
||||
cco = [cco for (i, f) in enumerate(faces)
|
||||
for j in f
|
||||
@ -3160,6 +3185,10 @@ def importShape(bpycollection, node, ancestry, global_matrix):
|
||||
if geom_fn is not None:
|
||||
bpydata = geom_fn(geom, ancestry)
|
||||
|
||||
if bpydata is None:
|
||||
print('ImportX3D warning: empty shape, skipping node "%s"' % vrmlname)
|
||||
return
|
||||
|
||||
# There are no geometry importers that can legally return
|
||||
# no object. It's either a bpy object, or an exception
|
||||
importShape_ProcessObject(
|
||||
|
Loading…
Reference in New Issue
Block a user