Clara.io, Vray and vrmat

Clara.io and Vray

Recently I’ve built a tool which syncs 3ds Max and Clara.io. Check it out here. Within Clara.io you can render your scenes with Vray. This triggered the vrmat feature. It’s now possible to send your models to Clara.io and keep your Vray shaders intact! How cool is that?
Get the script right here

vrmat

vrmats are a new feature introduced in Vray 3.0 for 3ds Max. Read more about them on the vray website. A vrmat is a generic description of a material compatible with Vray in several 3D packages. It allows you to move Vray materials between maya, 3ds Max, blender etcetera. Now Clara.io also supports this. Keep in mind only Vray 3.0 and up generate vrmats in 3ds Max.

The script helps you to determine if you can actually export vrmats. And even if you can, you can choose not to.

The script helps you with the vrmats
The script helps you with the vrmats

Embedded rendering

Combine this seamless translation with the new embedded rendering feature and you get near instant rendering of scenes setup with Vray, online with hardly any loss of information. This is a huge boost to communicating 3D designs and presenting realistic yet interactive content. Below is an iframe with a realtime rendered 3D model. You can orbit, pan and zoom this model and the image keeps refreshing. If you like this and want to bring interactivity to your 3D model catalog, do get in touch.

You can orbit, pan and zoom this model and the image keeps refreshing.

Tech background

Creating the vrmats in an automated fashion is not that hard. Vray supplies a bunch of scripts to make this happen which you can call from your own scripts. Check them out here:

  • C:Program FilesAutodesk3ds Max 2014scriptsstartupvrvismatconvertor.ms
  • C:Program FilesAutodesk3ds Max 2014scriptsstartupvraymtlexport.ms
  • C:Users[USERNAME]AppDataLocalAutodesk3dsMax2014 – 64bitENUusermacrosVRay-VRayVismatConverter.mcr

However, creating a vrmat with these scripts is very slow. A vrmat file is some sort of an xml-type file but the scripts by Vray write them line by line. To speed this up I wrote the vrmat to a stringstream in memory instead. After that’s done, the stringstream is written to disk with a .NET method.

Another edit I had to make, relates to material ID’s. The exported model is an fbx. Apparently the fbx exporter decreases all material ID’s of multi/sub materials and the corresponding meshes by 1. The vrmats aren’t affected by this which means after the export the material ID’s between the meshes and vrmats are out of sync. I’ve worked around this by editing the vrmat file and decreasing the material ID’s in multi/sub materials by 1. Here’s the method to do these things

function fn_exportMtlToVrmat theMtl thePath decreaseMtlID:true =
(
    /*<FUNCTION>
    Description
        Exports a single material to a vrmat and stores in in a specific folder
        Also edits the vrmat by decreasing material-ID's of multimaterials by 1. This has to be done to
        ensure compatibility with the exported fbx where this is done automatically by the fbx exporter.
    Arguments
        <material> theMtl: the material we need to convert
        <string> thePath: the folder where the vrmat is stored
        <boolean> decreaseMtlID: set to false if you don't want to decrease the mtl ID's of multimtls by 1
    Return
        <string> the path where the vrmat with its textures are stored
    <FUNCTION>*/

    local vrmatRootPath = thePath + @"vrmatroot" --create a root path for all vrmats
    makeDir vrmatRootPath all:true
    local vrmatPath = ""
    local vrmatFileName = ""
    if vrmatRootPath != undefined AND theMtl != undefined do
    (
        --each vrmat is stored in its own unique folder
        vrmatPath = vrmatRootPath + theMtl.name + @""
        makeDir vrmatPath all:true
        vrmatFileName = vrmatPath + theMtl.name + ".vrmat"
        local theOutStream = "" as stringStream

        --instead of giving these methods a filestream to write to, we give them a stringstream
        clearArrBitMapTxtPaths()
        openVismatTag theOutStream
        dumpSelectedMaterial theMtl theOutStream
        closeVismatTag theOutStream
        createBmpFilesInVismatFolder vrmatPath

        --writing the stringstream with dotnet methods to a file is about 10 times as fast
        local theFile = (dotNetClass "system.IO.File").CreateText vrmatFileName --a dotnet textfile to write to
        theFile.write (theOutStream as string)
        theFile.flush()
        theFile.close()            
    )

    --edit material ID's in the vrmat
    if decreaseMtlID do
    (
        local xmlDoc = dotNetObject "system.xml.xmlDocument"
        xmlDoc.load vrmatFileName

        --this is the xpath to the list of material ID's 
        local xpath = "//vrayplugin[@name='MtlMulti']/parameters/parameter[@name='ids_list']/value/list/entry"
        local entryNodes = xmlDoc.selectNodes xpath
        if entryNodes.count > 0 do
        (
            --loop over all entries and decrease them by 1
            for i = 0 to entryNodes.count-1 do
            (
                local theID = entryNodes.itemOf[i].innerText as integer
                entryNodes.itemOf[i].innerText = (theID-1) as string
            )
            xmlDoc.save vrmatFileName
        )
    )
    vrmatPath
)

This section of the above method call the methods from Vray. They’re available if you’ve got Vray 3.0 installed.

        clearArrBitMapTxtPaths()
        openVismatTag theOutStream
        dumpSelectedMaterial theMtl theOutStream
        closeVismatTag theOutStream
        createBmpFilesInVismatFolder vrmatPath


5 comments

Pieter Vandenbulcke

Very nice,
how did you get the player render the live render?
Mine shows only the realistic view.

You need to add something extra to the url you use in the iframe: ?renderer=vray&location=server
So, in my case the url in the iframe is this: src="http://clara.io/embed/6f1f1d4a-d432-453d-bc97-30f0f640dc61?renderer=vray&location=server"

Pieter Vandenbulcke

Wow, thnx klaas.

Dan

— Unable to convert: undefined to type: FileName
is the error I get when trying to send my scene to clara.io

Klaas Nienhuis

Hi Dan, I’ve written this script quite a while ago and the clara.io platform has also evolved. I’m not sure how to solve an issue like this from the top of my head.
You can go to the helpdesk here: https://klaasnienhuis.freshdesk.com/support/home and post a support ticket with more details

Leave a Reply

* Will not be published