Skip to content
Snippets Groups Projects
Commit dcfaadf5 authored by Julien Duroure's avatar Julien Duroure
Browse files

glTF: fix vertex color import + export option tweaks

parent 9fcbabfc
No related branches found
No related tags found
No related merge requests found
......@@ -94,13 +94,6 @@ class ExportGLTF2_Base:
default=False
)
export_strip: BoolProperty(
name='Strip Whitespace',
description='Makes JSON portion of export more compact, but harder to' \
' read and edit by hand',
default=False
)
export_indices: EnumProperty(
name='Maximum Indices Type',
items=(('UNSIGNED_BYTE', 'Unsigned Byte', ''),
......@@ -132,7 +125,7 @@ class ExportGLTF2_Base:
export_tangents: BoolProperty(
name='Tangents',
description='Export vertex tangents with meshes',
default=True
default=False
)
export_materials: BoolProperty(
......@@ -153,13 +146,6 @@ class ExportGLTF2_Base:
default=False
)
export_camera_infinite: BoolProperty(
name='Infinite Perspective',
description='Sets perspective cameras to use infinite perspective' \
' projections',
default=False
)
export_selected: BoolProperty(
name='Selected Objects',
description='Export selected objects only',
......@@ -262,7 +248,7 @@ class ExportGLTF2_Base:
export_morph_tangent: BoolProperty(
name='Shape Key Tangents',
description='Export vertex tangents with shape keys (morph targets)',
default=True
default=False
)
export_lights: BoolProperty(
......@@ -335,7 +321,6 @@ class ExportGLTF2_Base:
export_settings['gltf_copyright'] = self.export_copyright
export_settings['gltf_embed_buffers'] = self.export_embed_buffers
export_settings['gltf_embed_images'] = self.export_embed_images
export_settings['gltf_strip'] = self.export_strip
export_settings['gltf_indices'] = self.export_indices
export_settings['gltf_force_indices'] = self.export_force_indices
export_settings['gltf_texcoords'] = self.export_texcoords
......@@ -344,10 +329,6 @@ class ExportGLTF2_Base:
export_settings['gltf_materials'] = self.export_materials
export_settings['gltf_colors'] = self.export_colors
export_settings['gltf_cameras'] = self.export_cameras
if self.export_cameras:
export_settings['gltf_camera_infinite'] = self.export_camera_infinite
else:
export_settings['gltf_camera_infinite'] = False
export_settings['gltf_selected'] = self.export_selected
export_settings['gltf_layers'] = True #self.export_layers
export_settings['gltf_extras'] = self.export_extras
......@@ -402,7 +383,6 @@ class ExportGLTF2_Base:
if self.export_format == 'ASCII':
col.prop(self, 'export_embed_buffers')
col.prop(self, 'export_embed_images')
col.prop(self, 'export_strip')
col = layout.box().column()
col.label(text='Nodes:') # , icon='OOPS')
......@@ -428,8 +408,6 @@ class ExportGLTF2_Base:
col = layout.box().column()
col.label(text='Objects:') # , icon='OBJECT_DATA')
col.prop(self, 'export_cameras')
if self.export_cameras:
col.prop(self, 'export_camera_infinite')
col = layout.box().column()
col.label(text='Materials:') # , icon='MATERIAL_DATA')
......
......@@ -40,7 +40,6 @@ BINARY_FILENAME = 'gltf_binaryfilename'
YUP = 'gltf_yup'
MORPH = 'gltf_morph'
INDICES = 'gltf_indices'
CAMERA_INFINITE = 'gltf_camera_infinite'
BAKE_SKINS = 'gltf_bake_skins'
TEX_COORDS = 'gltf_texcoords'
COLORS = 'gltf_colors'
......
......@@ -106,9 +106,7 @@ def __gather_perspective(blender_object, export_settings):
perspective.yfov = 2.0 * math.atan(math.tan(blender_camera.angle * 0.5) / perspective.aspectRatio)
perspective.znear = blender_camera.clip_start
if not export_settings[gltf2_blender_export_keys.CAMERA_INFINITE]:
perspective.zfar = blender_camera.clip_end
perspective.zfar = blender_camera.clip_end
return perspective
return None
......
......@@ -143,7 +143,7 @@ class BlenderMesh():
if 'COLOR_0' in prim.attributes.keys():
# Create vertex color, once only per object
if vertex_color is None:
vertex_color = obj.data.vertex_colors.new("COLOR_0")
vertex_color = obj.data.vertex_colors.new(name="COLOR_0")
color_data = BinaryData.get_data_from_accessor(gltf, prim.attributes['COLOR_0'])
......@@ -152,7 +152,11 @@ class BlenderMesh():
vert_idx = mesh.loops[loop_idx].vertex_index
if vert_idx in range(offset, offset + prim.vertices_length):
cpt_idx = vert_idx - offset
vertex_color.data[loop_idx].color = color_data[cpt_idx][0:3]
# TODO : no alpha in vertex color
# check dimension, and add alpha if needed
if len(color_data[cpt_idx]) == 3:
vertex_color_data = color_data[cpt_idx] + (1.0,)
else:
vertex_color_data = color_data[cpt_idx]
vertex_color.data[loop_idx].color = vertex_color_data
offset = offset + prim.vertices_length
......@@ -32,7 +32,7 @@ def save_gltf(glTF, export_settings, encoder, glb_buffer):
indent = None
separators = separators = (',', ':')
if export_settings['gltf_format'] == 'ASCII' and not export_settings['gltf_strip']:
if export_settings['gltf_format'] == 'ASCII':
indent = 4
# The comma is typically followed by a newline, so no trailing whitespace is needed on it.
separators = separators = (',', ' : ')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment