diff --git a/tools/blender/mitsuba/export/__init__.py b/tools/blender/mitsuba/export/__init__.py index 5bcb0ced..3627fe7f 100644 --- a/tools/blender/mitsuba/export/__init__.py +++ b/tools/blender/mitsuba/export/__init__.py @@ -18,6 +18,86 @@ import os +# From collada_internal.cpp + +translate_start_name_map = list(map(chr, [ + 95, 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, 75, 76, 77, 78, 79, 80, + 81, 82, 83, 84, 85, 86, 87, 88, + 89, 90, 95, 95, 95, 95, 95, 95, + 97, 98, 99, 100, 101, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, 117, 118, 119, 120, + 121, 122, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 192, + 193, 194, 195, 196, 197, 198, 199, 200, + 201, 202, 203, 204, 205, 206, 207, 208, + 209, 210, 211, 212, 213, 214, 95, 216, + 217, 218, 219, 220, 221, 222, 223, 224, + 225, 226, 227, 228, 229, 230, 231, 232, + 233, 234, 235, 236, 237, 238, 239, 240, + 241, 242, 243, 244, 245, 246, 95, 248, + 249, 250, 251, 252, 253, 254, 255])) + +translate_name_map = list(map(chr, [ + 95, 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 45, 95, 95, 48, + 49, 50, 51, 52, 53, 54, 55, 56, + 57, 95, 95, 95, 95, 95, 95, 95, + 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, 75, 76, 77, 78, 79, 80, + 81, 82, 83, 84, 85, 86, 87, 88, + 89, 90, 95, 95, 95, 95, 95, 95, + 97, 98, 99, 100, 101, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, 117, 118, 119, 120, + 121, 122, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 183, 95, + 95, 95, 95, 95, 95, 95, 95, 192, + 193, 194, 195, 196, 197, 198, 199, 200, + 201, 202, 203, 204, 205, 206, 207, 208, + 209, 210, 211, 212, 213, 214, 95, 216, + 217, 218, 219, 220, 221, 222, 223, 224, + 225, 226, 227, 228, 229, 230, 231, 232, + 233, 234, 235, 236, 237, 238, 239, 240, + 241, 242, 243, 244, 245, 246, 95, 248, + 249, 250, 251, 252, 253, 254, 255])) + +def translate_id(name): + # Doesn't handle duplicates at the moment + result = "" + if len(name) == 0: + return name + result += translate_start_name_map[ord(name[0])] + for i in range(1, len(name)): + result += translate_name_map[ord(name[i])] + return result + class ParamSetItem(list): type = None type_name = None @@ -46,9 +126,9 @@ class ParamSetItem(list): def to_string_ref(self): if self.type == "reference_texture" or self.type == "reference_material": if self.name == "": - return '\t\t\n' % self.value + return '\t\t\n' % translate_id(self.value) else: - return '\t\t\n' % (self.name, self.value) + return '\t\t\n' % (self.name, translate_id(self.value)) else: return "" diff --git a/tools/blender/mitsuba/export/adjustments.py b/tools/blender/mitsuba/export/adjustments.py index 1d6c3504..6c24ab0f 100644 --- a/tools/blender/mitsuba/export/adjustments.py +++ b/tools/blender/mitsuba/export/adjustments.py @@ -21,6 +21,7 @@ import os, math, mathutils import bpy from extensions_framework import util as efutil +from mitsuba.export import translate_id class MtsAdjustments: ''' @@ -134,7 +135,7 @@ class MtsAdjustments: if p.type == 'reference_texture': self.export_texture(adjfile, self.find_texture(p.value)) - adjfile.write('\t\n' % (mat.name, mat.mitsuba_texture.type)) + adjfile.write('\t\n' % (translate_id(mat.name), mat.mitsuba_texture.type)) adjfile.write(params.to_string()) adjfile.write(params.to_string_ref()) adjfile.write('\t\n') @@ -151,7 +152,7 @@ class MtsAdjustments: elif p.type == 'reference_texture': self.export_texture(adjfile, self.find_texture(p.value)) - adjfile.write('\t\n' % (mat.name, mat.mitsuba_material.type)) + adjfile.write('\t\n' % (translate_id(mat.name), mat.mitsuba_material.type)) adjfile.write(params.to_string()) adjfile.write(params.to_string_ref()) adjfile.write('\t\n')