Changeset View
Changeset View
Standalone View
Standalone View
io_scene_vrml2/export_vrml2.py
| Context not available. | |||||
| def save_bmesh(fw, bm, | def save_bmesh(fw, bm, | ||||
| use_color, color_type, material_colors, | use_color, color_type, materials, | ||||
| use_uv, uv_image, | use_uv, uv_image, | ||||
| path_mode, copy_set): | path_mode, copy_set): | ||||
| base_src = os.path.dirname(bpy.data.filepath) | base_src = os.path.dirname(bpy.data.filepath) | ||||
| base_dst = os.path.dirname(fw.__self__.name) | base_dst = os.path.dirname(fw.__self__.name) | ||||
| if color_type == 'MATERIAL' and len(materials) == 1: | |||||
| use_vrml_material = True | |||||
| use_color = False | |||||
| else: | |||||
| use_vrml_material = False | |||||
| fw('Shape {\n') | fw('Shape {\n') | ||||
| fw('\tappearance Appearance {\n') | fw('\tappearance Appearance {\n') | ||||
| if use_uv: | if use_uv: | ||||
| Context not available. | |||||
| del images | del images | ||||
| del filepath_ref, filepath_base, filepath_full, filepath | del filepath_ref, filepath_base, filepath_full, filepath | ||||
| fw('\t\t}\n') # end 'ImageTexture' | fw('\t\t}\n') # end 'ImageTexture' | ||||
| elif use_vrml_material: | |||||
| fw('\t\tmaterial Material {\n') | |||||
| fw('\t\t\tdiffuseColor %.6f %.6f %.6f\n' % materials[0].diffuse_color[:]) | |||||
| fw('\t\t\temissiveColor %.6f %.6f %.6f\n' % tuple([materials[0].emit * i for i in materials[0].diffuse_color])) | |||||
| fw('\t\t\tspecularColor %.6f %.6f %.6f\n' % materials[0].specular_color[:]) | |||||
| fw('\t\t\tambientIntensity %.6f\n' % materials[0].ambient) | |||||
| fw('\t\t\ttransparency %.6f\n' % (1.0 - materials[0].alpha)) | |||||
| fw('\t\t\tshininess %.6f\n' % materials[0].specular_intensity) | |||||
| fw('\t\t}\n') # end 'Material' | |||||
| else: | else: | ||||
| fw('\t\tmaterial Material {\n') | fw('\t\tmaterial Material {\n') | ||||
| fw('\t\t}\n') # end 'Material' | fw('\t\t}\n') # end 'Material' | ||||
| Context not available. | |||||
| fw('\t\tcolorPerVertex FALSE\n') | fw('\t\tcolorPerVertex FALSE\n') | ||||
| fw('\t\tcolor Color {\n') | fw('\t\tcolor Color {\n') | ||||
| fw('\t\t\tcolor [ ') | fw('\t\t\tcolor [ ') | ||||
| material_colors = [ | |||||
| "%.2f %.2f %.2f " % (m.diffuse_color[:] if m else (1.0, 1.0, 1.0)) | |||||
| for m in materials] | |||||
| c = None | c = None | ||||
| for c in material_colors: | for c in material_colors: | ||||
| fw(c) | fw(c) | ||||
| Context not available. | |||||
| bm.transform(global_matrix * obj.matrix_world) | bm.transform(global_matrix * obj.matrix_world) | ||||
| # default empty | # default empty | ||||
| material_colors = [] | |||||
| uv_image = None | uv_image = None | ||||
| if use_color: | if use_color: | ||||
| Context not available. | |||||
| if color_type == 'MATERIAL': | if color_type == 'MATERIAL': | ||||
| if not me.materials: | if not me.materials: | ||||
| use_color = False | use_color = False | ||||
| else: | |||||
| material_colors = [ | |||||
| "%.2f %.2f %.2f " % (m.diffuse_color[:] if m else (1.0, 1.0, 1.0)) | |||||
| for m in me.materials] | |||||
| assert(color_type in {'VERTEX', 'MATERIAL'}) | assert(color_type in {'VERTEX', 'MATERIAL'}) | ||||
| if use_uv: | if use_uv: | ||||
| Context not available. | |||||
| use_uv = False | use_uv = False | ||||
| save_bmesh(fw, bm, | save_bmesh(fw, bm, | ||||
| use_color, color_type, material_colors, | use_color, color_type, me.materials, | ||||
| use_uv, uv_image, | use_uv, uv_image, | ||||
| path_mode, copy_set) | path_mode, copy_set) | ||||
| Context not available. | |||||