Improve filename handling

This commit is contained in:
Lubos Lenco 2017-05-13 17:17:43 +02:00
parent e9bfdab2b0
commit 419b3a999c
16 changed files with 111 additions and 109 deletions

View file

@ -734,7 +734,7 @@ class Cycles {
}
static function res_var_name(node:TNode, socket:TNodeSocket):String {
return node_name(node) + '_' + safe_source_name(socket.name) + '_res';
return node_name(node) + '_' + safesrc(socket.name) + '_res';
}
static function write_result(l:TNodeLink):String {
@ -781,7 +781,7 @@ class Cycles {
}
// def touniform(inp):
// uname = c_state.safe_source_name(inp.node.name) + c_state.safe_source_name(inp.name)
// uname = c_state.safesrc(inp.node.name) + c_state.safesrc(inp.name)
// curshader.add_uniform(glsltype(inp.type) + ' ' + uname)
// return uname
@ -877,7 +877,7 @@ class Cycles {
var varname = store_var_name(node);
return '$varname.rgb';
}
var tex_name = safe_source_name(node.name);
var tex_name = safesrc(node.name);
var tex = make_texture(node, tex_name);
if (tex != null) {
var to_linear = parsing_basecol;// && !tex['file'].endswith('.hdr');
@ -1451,7 +1451,7 @@ class Cycles {
// # Already fetched
// if res_var_name(node, node.outputs[0]) in parsed:
// return '{0}.a'.format(store_var_name(node))
// tex_name = c_state.safe_source_name(node.name)
// tex_name = c_state.safesrc(node.name)
// tex = c_state.make_texture(node, tex_name)
// if tex != None:
// return '{0}.a'.format(texture_store(node, tex, tex_name))
@ -1645,13 +1645,13 @@ class Cycles {
}
static function node_name(node:TNode):String {
var s = safe_source_name(node.name) + node.id;
var s = safesrc(node.name) + node.id;
// if len(parents) > 0:
// s = c_state.safe_source_name(parents[-1].name) + '_' + s
// s = c_state.safesrc(parents[-1].name) + '_' + s
return s;
}
static function safe_source_name(s:String):String {
static function safesrc(s:String):String {
return StringTools.replace(s, ' ', '');
}
@ -1678,7 +1678,7 @@ class Cycles {
// Reference image name
// tex.file = extract_filename(image.filepath);
// tex.file = safefilename(tex.file);
// tex.file = safestr(tex.file);
tex.file = image_node.buttons[0].default_value;
@ -1714,7 +1714,7 @@ class Cycles {
// assets.add(unpack_filepath)
// else:
// if not os.path.isfile(arm.utils.safe_assetpath(image.filepath)):
// if not os.path.isfile(arm.utils.asset_path(image.filepath)):
// log.warn('Material ' + matname + '/' + image.name + ' - file not found(' + image.filepath + ')')
// return None
@ -1729,9 +1729,9 @@ class Cycles {
// TODO: Khamake converts .PNG to .jpg? Convert ext to lowercase on windows
// if arm.utils.get_os() == 'win':
// s = image.filepath.rsplit('.', 1)
// assets.add(arm.utils.safe_assetpath(s[0] + '.' + s[1].lower()))
// assets.add(arm.utils.asset_path(s[0] + '.' + s[1].lower()))
// else:
// assets.add(safe_assetpath(image.filepath));
// assets.add(asset_path(image.filepath));
// if image_format != 'RGBA32':
@ -1793,18 +1793,18 @@ class Cycles {
return ((num & (num - 1)) == 0) && num != 0;
}
static function safe_assetpath(s:String):String {
static function asset_path(s:String):String {
// return s[2:] if s[:2] == '//' else s # Remove leading '//';
return s;
}
static function extract_filename(s:String):String {
// return os.path.basename(safe_assetpath(s));
// return os.path.basename(asset_path(s));
var ar = s.split(".");
return ar[ar.length - 2] + "." + ar[ar.length - 1];
}
static function safefilename(s:String):String {
static function safestr(s:String):String {
// for c in r'[]/\;,><&*:%=+@!#^()|?^':
// s = s.replace(c, '-')
return s;

View file

@ -1234,6 +1234,8 @@ class ArmoryExporter:
# Export the object reference and material references
objref = bobject.data
if objref != None:
objname = self.asset_name(objref)
# Lods
if bobject.type == 'MESH' and hasattr(objref, 'my_lodlist') and len(objref.my_lodlist) > 0:
@ -1247,14 +1249,6 @@ class ArmoryExporter:
o['lods'].append(lod)
if objref.lod_material:
o['lod_material'] = True
# Remove unsafe chars from data names
if objref != None:
safe = arm.utils.safefilename(objref.name)
if objref.name != safe:
objref.name = safe
objname = self.asset_name(objref)
if type == NodeTypeMesh:
if not objref in self.meshArray:
@ -1262,7 +1256,7 @@ class ArmoryExporter:
else:
self.meshArray[objref]["objectTable"].append(bobject)
oid = arm.utils.safe_filename(self.meshArray[objref]["structName"])
oid = arm.utils.safestr(self.meshArray[objref]["structName"])
if ArmoryExporter.option_mesh_per_file:
ext = ''
if self.is_compress(objref):
@ -1365,7 +1359,7 @@ class ArmoryExporter:
# Bone export
armatureid = self.asset_name(bdata)
armatureid = arm.utils.safe_filename(armatureid)
armatureid = arm.utils.safestr(armatureid)
ext = ''
if self.is_compress(bdata):
ext = '.zip'
@ -1733,7 +1727,7 @@ class ArmoryExporter:
def do_export_mesh(self, objectRef, scene):
# This function exports a single mesh object
bobject = objectRef[1]["objectTable"][0]
oid = arm.utils.safe_filename(objectRef[1]["structName"])
oid = arm.utils.safestr(objectRef[1]["structName"])
# Check if mesh is using instanced rendering
is_instanced, instance_offsets = self.object_process_instancing(bobject, objectRef[1]["objectTable"])
@ -2155,10 +2149,9 @@ class ArmoryExporter:
assets.add(unpack_filepath)
# External
else:
assets.add(arm.utils.safe_assetpath(objref.sound.filepath)) # Link sound to assets
assets.add(arm.utils.asset_path(objref.sound.filepath)) # Link sound to assets
o['sound'] = arm.utils.extract_filename(objref.sound.filepath)
o['sound'] = arm.utils.safe_filename(o['sound'])
else:
o['sound'] = ''
o['muted'] = objref.muted
@ -2415,7 +2408,7 @@ class ArmoryExporter:
self.process_skinned_meshes()
self.output['name'] = arm.utils.safe_filename(self.scene.name)
self.output['name'] = arm.utils.safestr(self.scene.name)
if self.filepath.endswith('.zip'):
self.output['name'] += '.zip'
@ -2463,7 +2456,7 @@ class ArmoryExporter:
if self.scene.camera != None:
self.output['camera_ref'] = self.scene.camera.name
else:
if arm.utils.safe_filename(self.scene.name) == arm.utils.get_project_scene_name():
if self.scene.name == arm.utils.get_project_scene_name():
print('Armory Warning: No camera found in active scene')
self.output['material_datas'] = []
@ -2718,12 +2711,12 @@ class ArmoryExporter:
x = {}
if t.type_prop == 'Logic Nodes' and t.nodes_name_prop != '':
x['type'] = 'Script'
x['class_name'] = bpy.data.worlds['Arm'].arm_project_package + '.node.' + arm.utils.safe_source_name(t.nodes_name_prop)
x['class_name'] = arm.utils.safestr(bpy.data.worlds['Arm'].arm_project_package) + '.node.' + arm.utils.safesrc(t.nodes_name_prop)
elif t.type_prop == 'JS Script' or t.type_prop == 'Python Script':
basename = t.jsscript_prop.split('.')[0]
x['type'] = 'Script'
x['class_name'] = 'armory.trait.internal.JSScript'
x['parameters'] = [arm.utils.safe_filename(basename)]
x['parameters'] = [basename]
scriptspath = arm.utils.get_fp() + '/build/compiled/scripts/'
if not os.path.exists(scriptspath):
os.makedirs(scriptspath)
@ -2787,7 +2780,7 @@ class ArmoryExporter:
f.write(" %d" % (i + 1))
f.write("\n")
else:
trait_prefix = bpy.data.worlds['Arm'].arm_project_package + '.'
trait_prefix = arm.utils.safestr(bpy.data.worlds['Arm'].arm_project_package) + '.'
x['class_name'] = trait_prefix + t.class_name_prop
if len(t.my_paramstraitlist) > 0:
x['parameters'] = []
@ -2948,7 +2941,7 @@ class ArmoryExporter:
bgcol[i] = pow(bgcol[i], 1.0 / 2.2)
o['background_color'] = arm.utils.color_to_int(bgcol)
wmat_name = arm.utils.safe_filename(world.name) + '_material'
wmat_name = arm.utils.safestr(world.name) + '_material'
o['material_ref'] = wmat_name + '/' + wmat_name + '/world'
o['probes'] = []
# Main probe

View file

@ -12,7 +12,7 @@ class CallGroupNode(Node, ArmLogicTreeNode):
@property
def property0(self):
return bpy.data.worlds['Arm'].arm_project_package + '.node.' + arm.utils.safe_source_name(self.property0_)
return arm.utils.safestr(bpy.data.worlds['Arm'].arm_project_package) + '.node.' + arm.utils.safe_source_name(self.property0_)
property0_ = StringProperty(name='Group', default='')

View file

@ -87,7 +87,7 @@ def export_data(fp, sdk_path, is_play=False, is_publish=False, in_viewport=False
for scene in bpy.data.scenes:
if scene.game_export:
ext = '.zip' if (scene.data_compressed and is_publish) else '.arm'
asset_path = 'build/compiled/Assets/' + arm.utils.safe_filename(scene.name) + ext
asset_path = 'build/compiled/Assets/' + arm.utils.safestr(scene.name) + ext
exporter.execute(bpy.context, asset_path, scene=scene)
if physics_found == False and ArmoryExporter.export_physics:
physics_found = True
@ -226,7 +226,7 @@ def build_project(is_play=False, is_publish=False, in_viewport=False, target=Non
os.chdir(fp)
# Create directories
sources_path = 'Sources/' + wrd.arm_project_package
sources_path = 'Sources/' + arm.utils.safestr(wrd.arm_project_package)
if not os.path.exists(sources_path):
os.makedirs(sources_path)
@ -253,7 +253,7 @@ def build_project(is_play=False, is_publish=False, in_viewport=False, target=Non
# Save internal Haxe scripts
for text in bpy.data.texts:
if text.filepath == '' and text.name[-3:] == '.hx':
with open('Sources/' + bpy.data.worlds['Arm'].arm_project_package + '/' + text.name, 'w') as f:
with open('Sources/' + arm.utils.safestr(wrd.arm_project_package) + '/' + text.name, 'w') as f:
f.write(text.as_string())
# Export data
@ -357,7 +357,7 @@ def play_project(in_viewport):
state.last_in_viewport = state.in_viewport
# Trait sources modified
script_path = arm.utils.get_fp() + '/Sources/' + wrd.arm_project_package
script_path = arm.utils.get_fp() + '/Sources/' + arm.utils.safestr(wrd.arm_project_package)
if os.path.isdir(script_path):
for fn in glob.iglob(os.path.join(script_path, '**', '*.hx'), recursive=True):
mtime = os.path.getmtime(fn)
@ -409,7 +409,7 @@ def on_compiled(mode): # build, play, play_viewport, publish
elif target_name == 'windows':
print('VisualStudio 2015 project files are located in ' + files_path + '-build')
elif target_name == 'android-native':
print('Android Studio project files are located in ' + files_path + '-build/' + arm.utils.safefilename(wrd.arm_project_name))
print('Android Studio project files are located in ' + files_path + '-build/' + arm.utils.safestr(wrd.arm_project_name))
else:
print('Makefiles are located in ' + files_path + '-build')
return
@ -481,7 +481,7 @@ def clean_project():
shutil.rmtree('build')
# Remove compiled nodes
nodes_path = 'Sources/' + wrd.arm_project_package.replace('.', '/') + '/node/'
nodes_path = 'Sources/' + arm.utils.safestr(wrd.arm_project_package).replace('.', '/') + '/node/'
if os.path.isdir(nodes_path):
shutil.rmtree(nodes_path)

View file

@ -11,7 +11,7 @@ def build_node_trees():
os.chdir(arm.utils.get_fp())
# Make sure package dir exists
nodes_path = 'Sources/' + bpy.data.worlds['Arm'].arm_project_package.replace(".", "/") + "/node"
nodes_path = 'Sources/' + arm.utils.safestr(bpy.data.worlds['Arm'].arm_project_package).replace(".", "/") + "/node"
if not os.path.exists(nodes_path):
os.makedirs(nodes_path)
@ -28,11 +28,12 @@ def build_node_tree(node_group):
parsed_labels = dict()
root_nodes = get_root_nodes(node_group)
path = 'Sources/' + bpy.data.worlds['Arm'].arm_project_package.replace('.', '/') + '/node/'
group_name = arm.utils.safe_source_name(node_group.name)
pack_path = arm.utils.safestr(bpy.data.worlds['Arm'].arm_project_package)
path = 'Sources/' + pack_path.replace('.', '/') + '/node/'
group_name = arm.utils.safesrc(node_group.name)
with open(path + group_name + '.hx', 'w') as f:
f.write('package ' + bpy.data.worlds['Arm'].arm_project_package + '.node;\n\n')
f.write('package ' + pack_path + '.node;\n\n')
f.write('import armory.logicnode.*;\n\n')
f.write('@:keep class ' + group_name + ' extends armory.logicnode.LogicTree {\n\n')
f.write('\tpublic function new() { super(); notifyOnAdd(add); }\n\n')
@ -50,7 +51,7 @@ def build_node(node, f):
return build_node(node.inputs[0].links[0].from_node, f)
# Get node name
name = '_' + arm.utils.safe_source_name(node.name)
name = '_' + arm.utils.safesrc(node.name)
# Link nodes using labels
if node.label != '':

View file

@ -30,7 +30,8 @@ def build_node_tree(world):
output = {}
dat = {}
output['material_datas'] = [dat]
dat['name'] = arm.utils.safe_filename(world.name) + '_material'
wname = arm.utils.safestr(world.name)
dat['name'] = wname + '_material'
context = {}
dat['contexts'] = [context]
context['name'] = 'world'
@ -52,9 +53,9 @@ def build_node_tree(world):
wrd.world_defs += '_EnvCol'
# Irradiance json file name
world.world_envtex_name = world.name
world.world_envtex_irr_name = world.name
write_probes.write_color_irradiance(world.name, world.world_envtex_color)
world.world_envtex_name = wname
world.world_envtex_irr_name = wname
write_probes.write_color_irradiance(wname, world.world_envtex_color)
# Clouds enabled
if wrd.generate_clouds:
@ -169,7 +170,7 @@ def parse_color(world, node, context, envmap_strength_const):
image = node.image
filepath = image.filepath
if image.packed_file == None and not os.path.isfile(arm.utils.safe_assetpath(filepath)):
if image.packed_file == None and not os.path.isfile(arm.utils.asset_path(filepath)):
log.warn(world.name + ' - unable to open ' + image.filepath)
return
@ -181,7 +182,6 @@ def parse_color(world, node, context, envmap_strength_const):
# Reference image name
tex['file'] = arm.utils.extract_filename(image.filepath)
tex['file'] = arm.utils.safe_filename(tex['file'])
base = tex['file'].rsplit('.', 1)
ext = base[1].lower()
@ -225,7 +225,7 @@ def parse_color(world, node, context, envmap_strength_const):
assets.add(converted_path)
else:
# Link image path to assets
assets.add(arm.utils.safe_assetpath(image.filepath))
assets.add(arm.utils.asset_path(image.filepath))
# Generate prefiltered envmaps
world.world_envtex_name = tex['file']
@ -272,11 +272,10 @@ def parse_color(world, node, context, envmap_strength_const):
assets.add(unpack_filepath)
else:
# Link image path to assets
assets.add(arm.utils.safe_assetpath(image.filepath))
assets.add(arm.utils.asset_path(image.filepath))
# Reference image name
tex['file'] = arm.utils.extract_filename(image.filepath)
tex['file'] = arm.utils.safe_filename(tex['file'])
# Append sky define
@ -298,8 +297,9 @@ def parse_color(world, node, context, envmap_strength_const):
world.world_envtex_ground_albedo = node.ground_albedo
# Irradiance json file name
world.world_envtex_irr_name = world.name
write_probes.write_sky_irradiance(world.name)
wname = arm.utils.safestr(world.name)
world.world_envtex_irr_name = wname
write_probes.write_sky_irradiance(wname)
# Radiance
if wrd.generate_radiance_sky and wrd.generate_radiance and wrd.generate_irradiance:

View file

@ -335,7 +335,7 @@ def parse_displacement_input(inp):
return None
def res_var_name(node, socket):
return node_name(node.name) + '_' + c_state.safe_source_name(socket.name) + '_res'
return node_name(node.name) + '_' + c_state.safesrc(socket.name) + '_res'
def write_result(l):
res_var = res_var_name(l.from_node, l.from_socket)
@ -373,7 +373,7 @@ def glsltype(t):
return 'float'
def touniform(inp):
uname = c_state.safe_source_name(inp.node.name) + c_state.safe_source_name(inp.name)
uname = c_state.safesrc(inp.node.name) + c_state.safesrc(inp.name)
curshader.add_uniform(glsltype(inp.type) + ' ' + uname)
return uname
@ -461,7 +461,7 @@ def parse_rgb(node, socket):
# Already fetched
if res_var_name(node, node.outputs[1]) in parsed:
return '{0}.rgb'.format(store_var_name(node))
tex_name = c_state.safe_source_name(node.name)
tex_name = c_state.safesrc(node.name)
tex = c_state.make_texture(node, tex_name)
if tex != None:
to_linear = parsing_basecol and not tex['file'].endswith('.hdr')
@ -1015,7 +1015,7 @@ def parse_value(node, socket):
# Already fetched
if res_var_name(node, node.outputs[0]) in parsed:
return '{0}.a'.format(store_var_name(node))
tex_name = c_state.safe_source_name(node.name)
tex_name = c_state.safesrc(node.name)
tex = c_state.make_texture(node, tex_name)
if tex != None:
return '{0}.a'.format(texture_store(node, tex, tex_name))
@ -1189,7 +1189,7 @@ def socket_index(node, socket):
return i
def node_name(s):
s = c_state.safe_source_name(s)
s = c_state.safesrc(s)
if len(parents) > 0:
s = c_state.safe_source_name(parents[-1].name) + '_' + s
s = c_state.safesrc(parents[-1].name) + '_' + s
return s

View file

@ -12,8 +12,8 @@ def get_rp_renderer():
def get_arm_export_tangents():
return bpy.data.worlds['Arm'].arm_export_tangents
def safe_source_name(name):
return arm.utils.safe_source_name(name)
def safesrc(name):
return arm.utils.safesrc(name)
def get_sdk_path():
return arm.utils.get_sdk_path()

View file

@ -51,7 +51,7 @@ def parse(material, mat_data, mat_users, mat_armusers, rid):
c['bind_textures'] = []
for node in material.node_tree.nodes:
if node.type == 'TEX_IMAGE':
tex_name = arm.utils.safe_source_name(node.name)
tex_name = arm.utils.safesrc(node.name)
tex = make_texture.make(node, tex_name)
if tex == None: # Empty texture
tex = {}
@ -63,7 +63,7 @@ def parse(material, mat_data, mat_users, mat_armusers, rid):
for node in material.node_tree.nodes:
for inp in node.inputs:
if inp.is_uniform:
uname = arm.utils.safe_source_name(inp.node.name) + arm.utils.safe_source_name(inp.name) # Merge with cycles
uname = arm.utils.safesrc(inp.node.name) + arm.utils.safesrc(inp.name) # Merge with cycles
const = {}
const['name'] = uname
const[glsltype(inp.type)] = glslvalue(inp.default_value)

View file

@ -32,7 +32,7 @@ def build(material, mat_users, mat_armusers, rid):
wrd = bpy.data.worlds['Arm']
rpasses = mat_utils.get_rpasses(material)
matname = arm.utils.safe_source_name(material.name)
matname = arm.utils.safesrc(material.name)
rel_path = 'build/compiled/ShaderRaws/' + matname
full_path = arm.utils.get_fp() + '/' + rel_path
if not os.path.exists(full_path):
@ -107,7 +107,7 @@ def write_shaders(rel_path, con, rpass):
def write_shader(rel_path, shader, ext, rpass, keep_cache=True):
if shader == None:
return
shader_rel_path = rel_path + '/' + arm.utils.safe_source_name(mat_state.material.name) + '_' + rpass + '.' + ext + '.glsl'
shader_rel_path = rel_path + '/' + arm.utils.safesrc(mat_state.material.name) + '_' + rpass + '.' + ext + '.glsl'
shader_path = arm.utils.get_fp() + '/' + shader_rel_path
assets.add_shader(shader_rel_path)
if not os.path.isfile(shader_path) or not keep_cache:

View file

@ -5,12 +5,12 @@ import arm.utils
import arm.assets as assets
import arm.material.mat_state as mat_state
import arm.make_state as state
import shutil
def make(image_node, tex_name, matname=None):
wrd = bpy.data.worlds['Arm']
tex = {}
tex['name'] = tex_name
tex['file'] = ''
image = image_node.image
if matname == None:
matname = mat_state.material.name
@ -23,8 +23,9 @@ def make(image_node, tex_name, matname=None):
return None
# Reference image name
tex['file'] = arm.utils.extract_filename(image.filepath)
tex['file'] = arm.utils.safefilename(tex['file'])
texpath = arm.utils.asset_path(image.filepath)
texfile = arm.utils.extract_filename(image.filepath)
tex['file'] = arm.utils.safestr(texfile)
s = tex['file'].rsplit('.', 1)
if len(s) == 1:
@ -37,8 +38,8 @@ def make(image_node, tex_name, matname=None):
tex['file'] = tex['file'].rsplit('.', 1)[0] + '.jpg'
# log.warn(matname + '/' + image.name + ' - image format is not (jpg/png/hdr), converting to jpg.')
if image.packed_file != None:
# Extract packed data
if image.packed_file != None or not is_ascii(texfile):
# Extract packed data / copy non-ascii texture
unpack_path = arm.utils.get_fp() + '/build/compiled/Assets/unpacked'
if not os.path.exists(unpack_path):
os.makedirs(unpack_path)
@ -47,16 +48,22 @@ def make(image_node, tex_name, matname=None):
if do_convert:
if not os.path.isfile(unpack_filepath):
arm.utils.write_image(image, unpack_filepath)
# Write bytes if size is different or file does not exist yet
elif os.path.isfile(unpack_filepath) == False or os.path.getsize(unpack_filepath) != image.packed_file.size:
with open(unpack_filepath, 'wb') as f:
f.write(image.packed_file.data)
else:
# Write bytes if size is different or file does not exist yet
if image.packed_file != None:
if not os.path.isfile(unpack_filepath) or os.path.getsize(unpack_filepath) != image.packed_file.size:
with open(unpack_filepath, 'wb') as f:
f.write(image.packed_file.data)
# Copy non-ascii texture
else:
if not os.path.isfile(unpack_filepath) or os.path.getsize(unpack_filepath) != os.path.getsize(texpath):
shutil.copy(texpath, unpack_filepath)
assets.add(unpack_filepath)
else:
if not os.path.isfile(arm.utils.safe_assetpath(image.filepath)):
if not os.path.isfile(arm.utils.asset_path(image.filepath)):
log.warn('Material ' + matname + '/' + image.name + ' - file not found(' + image.filepath + ')')
return None
@ -71,9 +78,9 @@ def make(image_node, tex_name, matname=None):
# TODO: Khamake converts .PNG to .jpg? Convert ext to lowercase on windows
if arm.utils.get_os() == 'win':
s = image.filepath.rsplit('.', 1)
assets.add(arm.utils.safe_assetpath(s[0] + '.' + s[1].lower()))
assets.add(arm.utils.asset_path(s[0] + '.' + s[1].lower()))
else:
assets.add(arm.utils.safe_assetpath(image.filepath))
assets.add(arm.utils.asset_path(image.filepath))
# if image_format != 'RGBA32':
@ -123,3 +130,6 @@ def make(image_node, tex_name, matname=None):
def is_pow(num):
return ((num & (num - 1)) == 0) and num != 0
def is_ascii(s):
return len(s) == len(s.encode())

View file

@ -9,7 +9,7 @@ class ShaderData:
self.sd = {}
self.data = {}
self.data['shader_datas'] = [self.sd]
self.matname = arm.utils.safe_source_name(material.name)
self.matname = arm.utils.safesrc(material.name)
self.sd['name'] = self.matname + '_data'
self.sd['vertex_structure'] = []
self.sd['contexts'] = []
@ -58,7 +58,7 @@ class ShaderContext:
self.tesc = None
self.tese = None
self.material = material
self.matname = arm.utils.safe_source_name(material.name)
self.matname = arm.utils.safesrc(material.name)
self.shader_data = shader_data
self.data = {}
self.data['name'] = props['name']

View file

@ -160,8 +160,9 @@ class ArmoryEditScriptButton(bpy.types.Operator):
def execute(self, context):
project_path = arm.utils.get_fp()
item = context.object.my_traitlist[context.object.traitlist_index]
hx_path = project_path + '/Sources/' + bpy.data.worlds['Arm'].arm_project_package + '/' + item.class_name_prop + '.hx'
item = context.object.my_traitlist[context.object.traitlist_index]
pkg = arm.utils.safestr(bpy.data.worlds['Arm'].arm_project_package)
hx_path = project_path + '/Sources/' + pkg + '/' + item.class_name_prop + '.hx'
sdk_path = arm.utils.get_sdk_path()
if arm.utils.get_os() == 'win':
@ -184,7 +185,7 @@ class ArmoryEditBundledScriptButton(bpy.types.Operator):
def execute(self, context):
sdk_path = arm.utils.get_sdk_path()
project_path = arm.utils.get_fp()
pkg = bpy.data.worlds['Arm'].arm_project_package
pkg = arm.utils.safestr(bpy.data.worlds['Arm'].arm_project_package)
item = context.object.my_traitlist[context.object.traitlist_index]
source_hx_path = sdk_path + '/armory/Sources/armory/trait/' + item.class_name_prop + '.hx'
target_hx_path = project_path + '/Sources/' + pkg + '/' + item.class_name_prop + '.hx'

View file

@ -123,7 +123,7 @@ def fetch_script_names():
return
wrd = bpy.data.worlds['Arm']
wrd.scripts_list.clear()
sources_path = get_fp() + '/Sources/' + wrd.arm_project_package
sources_path = get_fp() + '/Sources/' + safestr(wrd.arm_project_package)
if os.path.isdir(sources_path):
os.chdir(sources_path)
for file in glob.glob('*.hx'):
@ -136,25 +136,22 @@ def to_hex(val):
def color_to_int(val):
return (int(val[3] * 255) << 24) + (int(val[0] * 255) << 16) + (int(val[1] * 255) << 8) + int(val[2] * 255)
def safe_filename(s):
return s
def safefilename(s):
for c in r'[]/\;,><&*:%=+@!#^()|?^':
s = s.replace(c, '-')
return s
def safe_source_name(s):
s = safefilename(s).replace('.', '_').replace('-', '_').replace(' ', '')
def safesrc(s):
s = safestr(s).replace('.', '_').replace('-', '_').replace(' ', '')
if s[0].isdigit():
s = '_' + s
return s
def safe_assetpath(s):
def safestr(s):
for c in r'[]/\;,><&*:%=+@!#^()|?^':
s = s.replace(c, '_')
return ''.join([i if ord(i) < 128 else '_' for i in s])
def asset_path(s):
return s[2:] if s[:2] == '//' else s # Remove leading '//'
def extract_filename(s):
return os.path.basename(safe_assetpath(s))
return os.path.basename(asset_path(s))
def get_render_resolution(scene):
render = scene.render
@ -164,9 +161,9 @@ def get_render_resolution(scene):
def get_project_scene_name():
wrd = bpy.data.worlds['Arm']
if wrd.arm_play_active_scene:
return safe_filename(bpy.context.screen.scene.name)
return bpy.context.screen.scene.name
else:
return safe_filename(wrd.arm_project_scene)
return wrd.arm_project_scene
def get_active_scene():
wrd = bpy.data.worlds['Arm']

View file

@ -37,7 +37,7 @@ def write_khafilejs(is_play, export_physics, export_navigation, dce_full=False):
with open('khafile.js', 'w') as f:
f.write(
"""// Auto-generated
let project = new Project('""" + arm.utils.safefilename(wrd.arm_project_name) + """');
let project = new Project('""" + arm.utils.safestr(wrd.arm_project_name) + """');
project.addSources('Sources');
""")
@ -152,14 +152,14 @@ def write_main(is_play, in_viewport, is_publish):
"""// Auto-generated
package ;
class Main {
public static inline var projectName = '""" + wrd.arm_project_name + """';
public static inline var projectPackage = '""" + wrd.arm_project_package + """';
public static inline var projectName = '""" + arm.utils.safestr(wrd.arm_project_name) + """';
public static inline var projectPackage = '""" + arm.utils.safestr(wrd.arm_project_package) + """';
public static inline var projectAssets = """ + str(len(assets.assets)) + """;
static inline var projectWidth = """ + str(resx) + """;
static inline var projectHeight = """ + str(resy) + """;
static inline var projectSamplesPerPixel = """ + str(int(wrd.arm_samples_per_pixel)) + """;
static inline var projectVSync = """ + ('true' if wrd.arm_vsync else 'false') + """;
static inline var projectScene = '""" + scene_name + scene_ext + """';
static inline var projectScene = '""" + arm.utils.safestr(scene_name) + scene_ext + """';
static var state:Int;
#if js
static function loadLib(name:String) {
@ -173,7 +173,7 @@ class Main {
public static function main() {
iron.system.CompileTime.importPackage('armory.trait');
iron.system.CompileTime.importPackage('armory.renderpath');
iron.system.CompileTime.importPackage('""" + wrd.arm_project_package + """');
iron.system.CompileTime.importPackage('""" + arm.utils.safestr(wrd.arm_project_package) + """');
state = 1;
#if (js && arm_physics) state++; loadLib("ammo.js"); #end
#if (js && arm_navigation) state++; loadLib("recast.js"); #end
@ -389,12 +389,12 @@ const vec3 voxelgiDimensions = ivec3(""" + str(round(wrd.generate_voxelgi_dimens
def write_traithx(class_name):
wrd = bpy.data.worlds['Arm']
package_path = arm.utils.get_fp() + '/Sources/' + wrd.arm_project_package
package_path = arm.utils.get_fp() + '/Sources/' + arm.utils.safestr(wrd.arm_project_package)
if not os.path.exists(package_path):
os.makedirs(package_path)
with open(package_path + '/' + class_name + '.hx', 'w') as f:
f.write(
"""package """ + wrd.arm_project_package + """;
"""package """ + arm.utils.safestr(wrd.arm_project_package) + """;
class """ + class_name + """ extends armory.Trait {
public function new() {

View file

@ -53,7 +53,7 @@ def write_probes(image_filepath, disable_hdr, cached_num_mips, generate_radiance
kraffiti_path = '"' + sdk_path + '/linux64/Kha/Kore/Tools/kraffiti/kraffiti-linux64"'
output_gama_numerator = '1.0' if disable_hdr else '2.2'
input_file = arm.utils.safe_assetpath(image_filepath)
input_file = arm.utils.asset_path(image_filepath)
# Scale map
wrd = bpy.data.worlds['Arm']