Announcement

Collapse
No announcement yet.

scripted vrmat creation speedup

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • scripted vrmat creation speedup

    Hi,
    for a recent scripting project I had to create vrmats. Since the vrmat converter that ships with vray 3.0 is a script itself, I've used parts of that script to build mine. You can find the main script used to convert vrmats here: C:\Program Files\Autodesk\3ds Max 2014\scripts\startup\vrvismatconvertor.ms
    The bare-bone version of such a conversion is:
    Code:
    local f = openFile fileName mode:"w"
    
    clearArrBitMapTxtPaths()
    openVismatTag f
    dumpSelectedMaterial mtl f
    closeVismatTag f
    createBmpFilesInVismatFolder saveDir
    
    flush f
    close f
    Where mtl is the material you want to convert, savedir is the directory you're copying the bitmaps to and filename is the place you're storing the actual vrmat file in.

    I've noticed however that writing a single vrmat to disk took quite a while, like up to ten seconds. This is not workable if you're exporting a scene with multiple vrmats. It appears that the script writes the vrmat line by line to a filestream. This can be sped up considerably by using .net methods to write the file to disk. Like so:
    Code:
    local s = "" as stringStream
    
    clearArrBitMapTxtPaths()
    openVismatTag s
    dumpSelectedMaterial mtl s
    closeVismatTag s
    createBmpFilesInVismatFolder saveDir
    
    local theFile = (dotNetClass "system.IO.File").CreateText fileName --a dotnet textfile to write to
    theFile.write (s as string)
    theFile.flush()
    theFile.close()
    Notice that the methods provided by vray haven't changed (doing that would be way to complicated). Instead of giving these methods a filestream to write to they now write to a stringstream, essentially building the vrmat in memory. After the vray methods have finished, we use a .net method to write the stringstream to disk.
    On my system this made a huge difference. Hopefully other people can benefit from this.
    Check out the project this was used for here: http://www.klaasnienhuis.nl/2014/03/...ray-and-vrmat/
    Klaas
    Klaas Nienhuis
    Projects of the third kind
    twitter linkedin
Working...
X