bugfix: absolute image url path in Max Collada exporter

The Max Collada export script fails (in my opinion) generate a valid absolute URL for image files. The URLs are missing the ‘file://’ prefix.

In addition I don’t think removing the path from the image filename, if it is located in one of the user’s or max’s map paths is a good idea if you want to use the collada file with another package (e.g. Maya). To make the Collada import work on these packages you would have to tell it to look in the same paths as Max would. So I think an absolute URL is safest in this case.

Here is a fix that will solve both problems:

fn Make_Valid_URI_Filename string_in =
(

local_string_in = copy string_in -- copy it so we do not change the original string

– for i=1 to mappaths.count() do – note mappaths is a maxscript global that is valid for bitmaps and xrefs
– (
– this_path = mappaths.get i
– this_path = this_path + “\” – add a trailing slash to compare against string_in

– starting_index = findstring local_string_in this_path

– if (starting_index != undefined) then – this path is a root for this bitmap
– (

– – note we add 2 to this_path.count because we need to skip the last character in the match string
– local_string_in = (substring local_string_in (this_path.count+1) -1) – remove prefix
– local_string_in = str_replace_char local_string_in “\” “/” – swap with proper slash
– local_string_in = str_replace_char local_string_in " " “_” – NEW:swap with underscore for blankspace
– local_string_in = str_replace_char local_string_in “:” “$” – swap with “$” for “:” as in “C:”

– return ( local_string_in )
– )
– )

– the above code strips the path if the texture is within one of the user’s or max’s map paths.
– But what if you want to import this file into Maya? It will not be able to find those textures.

-- else, if we get this far, return the input string as a relative path with a "file:///" indicator at the very top
local_string_in = str_replace_char local_string_in "\\" "/"			 	 -- swap with proper slash
local_string_in = str_replace_char local_string_in ":" "$"				 -- swap with "$" for ":" as in "C:"
local_string_in = str_replace_char local_string_in "&" "&" 		 -- Replace '&' by '&' Thx kevt!!!

local_string_in = "file://" + local_string_in 

gc() -- do some garbage collection here for maxscript, just in case

return (local_string_in)

)

Another fix.

In the above change this line:

local_string_in = str_replace_char local_string_in “:” “$” --swap with “$” for “:” as in “C:”

to:

local_string_in = str_replace_char local_string_in “:” “|” --swap with “|” for “:” as in “C:”

Windows explorer will not accept URLs of the form:
[file://c$/test](file://c$/test) for c: est but will accept [file://c|](file://c|) est for c: est