This page provides information on V-Ray Scene Files (.vrscene) - how to export them so that they could be used in other workflows.
Overview The .vrscene file format is an ASCII file that can be exported from App SDK and other platforms that use V-Ray. It contains all the information about the scene such as geometry, lights, and shaders, and can be rendered with the V-Ray Standalone . This functionality can transfer lights and entire assets with their textures and materials between V-Ray platforms. Animation is also included.
Exporting V-Ray Scene Files The .vrscene file could be exported by invoking the corresponding method of the VRayRenderer. It could be customized with various options, such as:
compressed - enables zlib compression of large data arrays (requires hexArrays==true) hexArrays - data arrays will be encoded in hex hexTransforms - transforms will be encoded in hex (mainly useful with large instancers) renderElementsSeparateFolders - controls the default value of SettingsOutput.relements_separateFolders printHeader - whether to write the comment section with version and time info currentFrameOnly - if true only the current keyframe is exported, otherwise the whole timeline incremental - valid only when currentFrameOnly=true && appendFrameSuffix=false - set to true to incrementally append keyframe data after initial export with false appendFrameSuffix - valid only when currentFrameOnly=true - appends a %04d frame number to the file name stripPaths - If enabled, the paths for bitmap textures and other external files are stripped from the file so that only the filenames remain. leftInterval - Valid only when currentFrameOnly=true. The (closed) time interval left of the current time in which to include keyframes - i.e. [left, right). Value 0.0 means automatic 1 frame based on FPS. rightInterval - Valid only when currentFrameOnly=true. The (open) time interval right of the current time in which to include keyframes - i.e. [left, right). Value 0.0 means automatic 1 frame based on FPS. subFileInfos - A list of files to split the scene into, based on plugin type. See SubFileInfo type comments. pluginExportList - If this is not empty, only these plugins will be exported instead of all plugins in the scene. additionalIncludeFiles - Optional list of files to #include at the end of the main vrscene hostAppString - An optional string identifying the host application, version, etc. vrdataExport - Enable or disable vrdata file writing. vrdataSmallBufferSizeLimit - Set a limit for the min size of the buffer. If the buffer is smaller it is not written to the vrdata file. vrdataFileSizeLimitMiB - Limit the size of the vrdata file. If this limit is reached another file is started. vrfilesExport - Enable or disable vrfiles file writing. sceneBasePath - Optional absolute scene base path that can be used for resolving relative paths for the .vrfiles file. vrfilesComputeHashes - True if MD5 and SHA256 hashes should be computed and written in the .vrfiles file for each resolved asset file. Code example Here is a sample usage of the export functionality:
Python <code data-v-c2b1f83f=""><span data-v-c2b1f83f="" class="line"># Compatibility with Python 2.7.</span><span data-v-c2b1f83f="" class="line">from __future__ import print_function</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"># The directory containing the vray shared object should be</span><span data-v-c2b1f83f="" class="line"># present in the PYTHONPATH environment variable.</span><span data-v-c2b1f83f="" class="line"># Try to import the vray module from VRAY_SDK/python, if it is not in PYTHONPATH</span><span data-v-c2b1f83f="" class="line">import sys, os</span><span data-v-c2b1f83f="" class="line">VRAY_SDK = os.environ.get('VRAY_SDK')</span><span data-v-c2b1f83f="" class="line">if VRAY_SDK:</span><span data-v-c2b1f83f="" class="line"> sys.path.append(os.path.join(VRAY_SDK, 'python'))</span><span data-v-c2b1f83f="" class="line">import vray</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">SCENE_PATH = os.path.join(VRAY_SDK, 'scenes')</span><span data-v-c2b1f83f="" class="line"># Change process working directory to SCENE_PATH in order to be able to load relative scene resources.</span><span data-v-c2b1f83f="" class="line">os.chdir(SCENE_PATH)</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"># Create an instance of VRayRenderer with default options.</span><span data-v-c2b1f83f="" class="line"># The renderer is automatically closed after the `with` block.</span><span data-v-c2b1f83f="" class="line">with vray.VRayRenderer() as renderer:</span><span data-v-c2b1f83f="" class="line"> # Register a simple log callback. Always useful for debugging.</span><span data-v-c2b1f83f="" class="line"> def dumpMsg(renderer, message, level, instant):</span><span data-v-c2b1f83f="" class="line"> if level == vray.LOGLEVEL_ERROR:</span><span data-v-c2b1f83f="" class="line"> print("[ERROR]", message)</span><span data-v-c2b1f83f="" class="line"> elif level == vray.LOGLEVEL_WARNING:</span><span data-v-c2b1f83f="" class="line"> print("[Warning]", message)</span><span data-v-c2b1f83f="" class="line"> elif level == vray.LOGLEVEL_INFO:</span><span data-v-c2b1f83f="" class="line"> print("[info]", message)</span><span data-v-c2b1f83f="" class="line"> # Uncomment for testing, but you might want to ignore these in real code</span><span data-v-c2b1f83f="" class="line"> # else: print("[debug]", message)</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> renderer.setOnLogMessage(dumpMsg)</span><span data-v-c2b1f83f="" class="line"> globalExportSettings = {}</span><span data-v-c2b1f83f="" class="line"> # Enable compression of large data arrays.</span><span data-v-c2b1f83f="" class="line"> globalExportSettings["hexArrays"] = True</span><span data-v-c2b1f83f="" class="line"> globalExportSettings["compressed"] = True</span><span data-v-c2b1f83f="" class="line"> # Keep transforms in human readable format</span><span data-v-c2b1f83f="" class="line"> globalExportSettings["hexTransforms"] = False</span><span data-v-c2b1f83f="" class="line"> # Print header to the export file</span><span data-v-c2b1f83f="" class="line"> globalExportSettings["printHeader"] = True</span><span data-v-c2b1f83f="" class="line"> # Export only the current frame.</span><span data-v-c2b1f83f="" class="line"> globalExportSettings["currentFrameOnly"] = True</span><span data-v-c2b1f83f="" class="line"> # Keep incremental off for the first frame so all plugins are exporeted properly.</span><span data-v-c2b1f83f="" class="line"> globalExportSettings["incremental"] = False</span><span data-v-c2b1f83f="" class="line"> # Separate the views and nodes in different files</span><span data-v-c2b1f83f="" class="line"> viewSubFileInfo = {"type": 'view', "suffix": 'view'}</span><span data-v-c2b1f83f="" class="line"> nodeSubFileInfo = {"type": 'nodes', "suffix": 'nodes'}</span><span data-v-c2b1f83f="" class="line"> globalExportSettings["subFileInfos"] = [viewSubFileInfo, nodeSubFileInfo]</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> firstFrame = True</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> def stateChanged(renderer, oldState, newState, instant):</span><span data-v-c2b1f83f="" class="line"> global firstFrame</span><span data-v-c2b1f83f="" class="line"> global globalExportSettings</span><span data-v-c2b1f83f="" class="line"> if newState == vray.RENDERER_STATE_IDLE_FRAME_DONE:</span><span data-v-c2b1f83f="" class="line"> renderer.export("export.vrscene", globalExportSettings)</span><span data-v-c2b1f83f="" class="line"> print("Frame", renderer.frame, "exported")</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> if firstFrame:</span><span data-v-c2b1f83f="" class="line"> globalExportSettings["incremental"] = True</span><span data-v-c2b1f83f="" class="line"> firstFrame = False</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> renderer.continueSequence()</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> renderer.setOnStateChanged(stateChanged)</span><span data-v-c2b1f83f="" class="line"> # Load scene from a file.</span><span data-v-c2b1f83f="" class="line"> renderer.load(os.path.join(SCENE_PATH, "animation.vrscene"))</span><span data-v-c2b1f83f="" class="line"> # Maximum paths per pixel for interactive mode. Set a low sample level to complete rendering faster.</span><span data-v-c2b1f83f="" class="line"> renderer.setInteractiveSampleLevel(5)</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> # Export just the plugins associated with the cube.</span><span data-v-c2b1f83f="" class="line"> settings = {}</span><span data-v-c2b1f83f="" class="line"> settings["pluginExportList"] = [</span><span data-v-c2b1f83f="" class="line"> renderer.plugins['pCubeShape1@node'],</span><span data-v-c2b1f83f="" class="line"> renderer.plugins['pCubeShape1@mesh5'],</span><span data-v-c2b1f83f="" class="line"> renderer.plugins['VRayMtl1@material'],</span><span data-v-c2b1f83f="" class="line"> renderer.plugins['VRayMtl1@diffuse']]</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> renderer.export("export_cube.vrscene", settings)</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> # Start the sequence.</span><span data-v-c2b1f83f="" class="line"> renderer.renderSequence()</span><span data-v-c2b1f83f="" class="line"> # Wait for the renderer to finish.</span><span data-v-c2b1f83f="" class="line"> renderer.waitForSequenceEnd()</span></code>
C++ <code data-v-c2b1f83f=""><span data-v-c2b1f83f="" class="line">#define VRAY_RUNTIME_LOAD_PRIMARY</span><span data-v-c2b1f83f="" class="line">#include "vraysdk.hpp"</span><span data-v-c2b1f83f="" class="line">#include "vrayplugins.hpp"</span><span data-v-c2b1f83f="" class="line">#include "utils.h"</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">using namespace VRay;</span><span data-v-c2b1f83f="" class="line">using namespace VRay::Plugins;</span><span data-v-c2b1f83f="" class="line">using namespace std;</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">const char *BASE_PATH = getenv("VRAY_SDK");</span><span data-v-c2b1f83f="" class="line">string SCENE_PATH = (BASE_PATH ? string(BASE_PATH) : string(".")) + PATH_DELIMITER + "scenes";</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">VRayExportSettings globalExportSettings;</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">void stateChanged(VRayRenderer &renderer, RendererState oldState, RendererState newState, double instant, void* data){</span><span data-v-c2b1f83f="" class="line"> if (newState == RendererState::IDLE_FRAME_DONE) {</span><span data-v-c2b1f83f="" class="line"> static bool firstFrame = true;</span><span data-v-c2b1f83f="" class="line"> // Export the current frame</span><span data-v-c2b1f83f="" class="line"> renderer.exportScene("export.vrscene", globalExportSettings);</span><span data-v-c2b1f83f="" class="line"> printf("Frame %d exported\</span><span data-v-c2b1f83f="" class="line">", renderer.getCurrentFrame());</span><span data-v-c2b1f83f="" class="line"> // Turn the incremental option on to append each frame to the same file.</span><span data-v-c2b1f83f="" class="line"> if (firstFrame) {</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.incremental = true;</span><span data-v-c2b1f83f="" class="line"> firstFrame = false;</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line"> renderer.continueSequence();</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line">}</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">int main() {</span><span data-v-c2b1f83f="" class="line"> // Change process working directory to SCENE_PATH in order to be able to</span><span data-v-c2b1f83f="" class="line"> // load relative scene resources.</span><span data-v-c2b1f83f="" class="line"> changeCurrentDir(SCENE_PATH.c_str());</span><span data-v-c2b1f83f="" class="line"> // Load V-Ray SDK library.</span><span data-v-c2b1f83f="" class="line"> VRayInit init(NULL, true);</span><span data-v-c2b1f83f="" class="line"> // Create an instance of VRayRenderer with default options.</span><span data-v-c2b1f83f="" class="line"> // The renderer is automatically closed at the end of the current scope.</span><span data-v-c2b1f83f="" class="line"> VRayRenderer renderer;</span><span data-v-c2b1f83f="" class="line"> // It's recommended to always have a console log</span><span data-v-c2b1f83f="" class="line"> renderer.setOnLogMessage(logMessage);</span><span data-v-c2b1f83f="" class="line"> // Enable compression of large data arrays.</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.hexArrays = true;</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.compressed = true;</span><span data-v-c2b1f83f="" class="line"> // Keep transforms in human readable format</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.hexTransforms = false;</span><span data-v-c2b1f83f="" class="line"> // Print header to the export file</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.printHeader = true;</span><span data-v-c2b1f83f="" class="line"> // Export only the current frame.</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.currentFrameOnly = true;</span><span data-v-c2b1f83f="" class="line"> // Keep incremental off for the first frame so all plugins are exported properly.</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.incremental = false;</span><span data-v-c2b1f83f="" class="line"> // Separate the views and nodes in different files</span><span data-v-c2b1f83f="" class="line"> SubFileInfo views = { "view", "view" };</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.subFileInfos.push_back(views);</span><span data-v-c2b1f83f="" class="line"> SubFileInfo nodes = { "nodes", "nodes" };</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.subFileInfos.push_back(nodes);</span><span data-v-c2b1f83f="" class="line"> renderer.setOnStateChanged(stateChanged);</span><span data-v-c2b1f83f="" class="line"> // Load scene from a file.</span><span data-v-c2b1f83f="" class="line"> renderer.load("animation.vrscene");</span><span data-v-c2b1f83f="" class="line"> // Maximum paths per pixel for interactive mode. Set a low sample level to complete rendering faster.</span><span data-v-c2b1f83f="" class="line"> renderer.setInteractiveSampleLevel(5);</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // Export just the plugins associated with the cube.</span><span data-v-c2b1f83f="" class="line"> VRayExportSettings settings;</span><span data-v-c2b1f83f="" class="line"> settings.pluginExportList.push_back(renderer.getPlugin("pCubeShape1@node"));</span><span data-v-c2b1f83f="" class="line"> settings.pluginExportList.push_back(renderer.getPlugin("pCubeShape1@mesh5"));</span><span data-v-c2b1f83f="" class="line"> settings.pluginExportList.push_back(renderer.getPlugin("VRayMtl1@material"));</span><span data-v-c2b1f83f="" class="line"> settings.pluginExportList.push_back(renderer.getPlugin("VRayMtl1@diffuse"));</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> renderer.exportScene("export_cube.vrscene", settings);</span><span data-v-c2b1f83f="" class="line"> </span><span data-v-c2b1f83f="" class="line"> // Start the sequence.</span><span data-v-c2b1f83f="" class="line"> renderer.renderSequence();</span><span data-v-c2b1f83f="" class="line"> // Wait for the renderer to finish.</span><span data-v-c2b1f83f="" class="line"> renderer.waitForSequenceEnd();</span><span data-v-c2b1f83f="" class="line"> return 0;</span><span data-v-c2b1f83f="" class="line">}</span></code>
C#.NET <code data-v-c2b1f83f=""><span data-v-c2b1f83f="" class="line">using System;</span><span data-v-c2b1f83f="" class="line">using System.Collections.Generic;</span><span data-v-c2b1f83f="" class="line">using System.IO;</span><span data-v-c2b1f83f="" class="line">using System.Linq;</span><span data-v-c2b1f83f="" class="line">using System.Text;</span><span data-v-c2b1f83f="" class="line">using System.Threading.Tasks;</span><span data-v-c2b1f83f="" class="line">using VRay;</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">class Program</span><span data-v-c2b1f83f="" class="line">{ </span><span data-v-c2b1f83f="" class="line"> static void Main(string[] args)</span><span data-v-c2b1f83f="" class="line"> {</span><span data-v-c2b1f83f="" class="line"> string SCENE_PATH = Path.Combine(Environment.GetEnvironmentVariable("VRAY_SDK"), "scenes");</span><span data-v-c2b1f83f="" class="line"> ExportSettings globalExportSettings = new ExportSettings();</span><span data-v-c2b1f83f="" class="line"> // Change process working directory to SCENE_PATH in order to be able to load relative scene resources.</span><span data-v-c2b1f83f="" class="line"> Directory.SetCurrentDirectory(SCENE_PATH);</span><span data-v-c2b1f83f="" class="line"> // Create an instance of VRayRenderer with default options.</span><span data-v-c2b1f83f="" class="line"> // The renderer is automatically closed after the `using` block.</span><span data-v-c2b1f83f="" class="line"> using (VRayRenderer renderer = new VRayRenderer())</span><span data-v-c2b1f83f="" class="line"> {</span><span data-v-c2b1f83f="" class="line"> // Add a listener for any type of log message.</span><span data-v-c2b1f83f="" class="line"> renderer.LogMessage += new EventHandler<MessageEventArgs>((source, e) =></span><span data-v-c2b1f83f="" class="line"> {</span><span data-v-c2b1f83f="" class="line"> // You can remove the if for testing, but you might want to ignore Debug in real code</span><span data-v-c2b1f83f="" class="line"> if (e.LogLevel != LogLevelType.Debug)</span><span data-v-c2b1f83f="" class="line"> {</span><span data-v-c2b1f83f="" class="line"> Console.WriteLine(String.Format("[{0}] {1}", e.LogLevel.ToString(), e.Message));</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line"> });</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // Enable compression of large data arrays.</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.HexArrays = true;</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.Compressed = true;</span><span data-v-c2b1f83f="" class="line"> // Keep transforms in human readable format</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.HexTransforms = false;</span><span data-v-c2b1f83f="" class="line"> // Print header to the export file</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.PrintHeader = true;</span><span data-v-c2b1f83f="" class="line"> // Export only the current frame.</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.CurrentFrameOnly = true;</span><span data-v-c2b1f83f="" class="line"> // Keep incremental off for the first frame so all plugins are exporeted properly.</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.Incremental = false;</span><span data-v-c2b1f83f="" class="line"> // Separate the views and nodes in different files</span><span data-v-c2b1f83f="" class="line"> SubFileInfo views = new SubFileInfo(SubFileInfo.PluginType.View, "views");</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.AddSubFileInfo(views);</span><span data-v-c2b1f83f="" class="line"> SubFileInfo nodes = new SubFileInfo(SubFileInfo.PluginType.Node, "nodes");</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.AddSubFileInfo(nodes);</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> bool firstFrame = true;</span><span data-v-c2b1f83f="" class="line"> renderer.StateChanged += new EventHandler<StateChangedEventArgs>((source, e) =></span><span data-v-c2b1f83f="" class="line"> {</span><span data-v-c2b1f83f="" class="line"> if(e.NewState == VRayRenderer.RendererState.IDLE_FRAME_DONE)</span><span data-v-c2b1f83f="" class="line"> { </span><span data-v-c2b1f83f="" class="line"> // Export the current frame</span><span data-v-c2b1f83f="" class="line"> renderer.Export("export.vrscene", globalExportSettings);</span><span data-v-c2b1f83f="" class="line"> Console.WriteLine("Frame {0} exported\</span><span data-v-c2b1f83f="" class="line">", renderer.Frame);</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // Turn the incremental option on to append each frame to the same file. </span><span data-v-c2b1f83f="" class="line"> if (firstFrame)</span><span data-v-c2b1f83f="" class="line"> {</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.Incremental = true;</span><span data-v-c2b1f83f="" class="line"> firstFrame = false;</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line"> renderer.ContinueSequence();</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line"> });</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // Load scene from a file.</span><span data-v-c2b1f83f="" class="line"> renderer.Load("animation.vrscene");</span><span data-v-c2b1f83f="" class="line"> // Maximum paths per pixel for interactive mode. Set a low sample level to complete rendering faster.</span><span data-v-c2b1f83f="" class="line"> renderer.SetInteractiveSampleLevel(5);</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // Export just the plugins associated with the cube.</span><span data-v-c2b1f83f="" class="line"> ExportSettings settings = new ExportSettings();</span><span data-v-c2b1f83f="" class="line"> settings.PluginExportList.Add(renderer.GetPlugin("pCubeShape1@node"));</span><span data-v-c2b1f83f="" class="line"> settings.PluginExportList.Add(renderer.GetPlugin("pCubeShape1@mesh5"));</span><span data-v-c2b1f83f="" class="line"> settings.PluginExportList.Add(renderer.GetPlugin("VRayMtl1@material"));</span><span data-v-c2b1f83f="" class="line"> settings.PluginExportList.Add(renderer.GetPlugin("VRayMtl1@diffuse"));</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> renderer.Export("export_cube.vrscene", settings);</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // Start the sequence.</span><span data-v-c2b1f83f="" class="line"> renderer.RenderSequence();</span><span data-v-c2b1f83f="" class="line"> // Wait for the renderer to finish.</span><span data-v-c2b1f83f="" class="line"> renderer.WaitForSequenceEnd();</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line">}</span></code>
Node.js <code data-v-c2b1f83f=""><span data-v-c2b1f83f="" class="line">var path = require("path");</span><span data-v-c2b1f83f="" class="line">var vray = require(path.join(process.env.VRAY_SDK, "node", "vray"));</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">var SCENE_PATH = path.join(process.env.VRAY_SDK, "scenes");</span><span data-v-c2b1f83f="" class="line">// Change process working directory to SCENE_PATH in order to be able to load relative scene resources.</span><span data-v-c2b1f83f="" class="line">process.chdir(SCENE_PATH);</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">// Create an instance of VRayRenderer with default options.</span><span data-v-c2b1f83f="" class="line">var renderer = vray.VRayRenderer();</span><span data-v-c2b1f83f="" class="line">// It's recommended to always have a console log callback</span><span data-v-c2b1f83f="" class="line">renderer.on("logMessage", function(message, level, instant) {</span><span data-v-c2b1f83f="" class="line"> if (level == vray.LOGLEVEL_ERROR)</span><span data-v-c2b1f83f="" class="line"> console.log("[ERROR] ", message);</span><span data-v-c2b1f83f="" class="line"> else if (level == vray.LOGLEVEL_WARNING)</span><span data-v-c2b1f83f="" class="line"> console.log("[Warning] ", message);</span><span data-v-c2b1f83f="" class="line"> else if (level == vray.LOGLEVEL_INFO)</span><span data-v-c2b1f83f="" class="line"> console.log("[info] ", message);</span><span data-v-c2b1f83f="" class="line"> // Uncomment for testing, but you might want to ignore these in real code</span><span data-v-c2b1f83f="" class="line"> //else console.log("[debug] ", message);</span><span data-v-c2b1f83f="" class="line">});</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">var globalExportSettings = {};</span><span data-v-c2b1f83f="" class="line">// Enable compression of large data arrays.</span><span data-v-c2b1f83f="" class="line">globalExportSettings.hexArrays = true;</span><span data-v-c2b1f83f="" class="line">globalExportSettings.compressed = true;</span><span data-v-c2b1f83f="" class="line">// Keep transforms in human readable format</span><span data-v-c2b1f83f="" class="line">globalExportSettings.hexTransforms = false;</span><span data-v-c2b1f83f="" class="line">// Print header to the export file</span><span data-v-c2b1f83f="" class="line">globalExportSettings.printHeader = true;</span><span data-v-c2b1f83f="" class="line">// Export only the current frame.</span><span data-v-c2b1f83f="" class="line">globalExportSettings.currentFrameOnly = true;</span><span data-v-c2b1f83f="" class="line">// Keep incremental off for the first frame so all plugins are exporeted properly.</span><span data-v-c2b1f83f="" class="line">globalExportSettings.incremental = false;</span><span data-v-c2b1f83f="" class="line">// Separate the views and nodes in different files</span><span data-v-c2b1f83f="" class="line">var viewSubFileInfo = {type: "view", suffix: "view"};</span><span data-v-c2b1f83f="" class="line">var nodeSubFileInfo = {type: "nodes", suffix: "nodes"};</span><span data-v-c2b1f83f="" class="line">globalExportSettings.subFileInfos = [viewSubFileInfo, nodeSubFileInfo];</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">var firstFrame = true;</span><span data-v-c2b1f83f="" class="line">renderer.on("stateChanged", function(oldState, newState, instant) {</span><span data-v-c2b1f83f="" class="line"> if (newState == 'idleFrameDone') {</span><span data-v-c2b1f83f="" class="line"> // Export the current frame</span><span data-v-c2b1f83f="" class="line"> renderer.export("export.vrscene", globalExportSettings, function(err) {</span><span data-v-c2b1f83f="" class="line"> if (err) throw err;</span><span data-v-c2b1f83f="" class="line"> console.log("Frame ", renderer.frame, " exported");</span><span data-v-c2b1f83f="" class="line"> </span><span data-v-c2b1f83f="" class="line"> if(firstFrame) {</span><span data-v-c2b1f83f="" class="line"> globalExportSettings.incremental = true;</span><span data-v-c2b1f83f="" class="line"> firstFrame = false;</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line"> renderer.continueSequence();</span><span data-v-c2b1f83f="" class="line"> }); </span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line">});</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">// Load scene from a file.</span><span data-v-c2b1f83f="" class="line">renderer.load("animation.vrscene", function(err){</span><span data-v-c2b1f83f="" class="line"> if (err) throw err;</span><span data-v-c2b1f83f="" class="line"> // Maximum paths per pixel for interactive mode. Set a low sample level to complete rendering faster.</span><span data-v-c2b1f83f="" class="line"> renderer.setInteractiveSampleLevel(5);</span><span data-v-c2b1f83f="" class="line"> // Export just the plugins associated with the cube.</span><span data-v-c2b1f83f="" class="line"> var settings = {};</span><span data-v-c2b1f83f="" class="line"> settings.pluginExportList = [</span><span data-v-c2b1f83f="" class="line"> renderer.plugins["pCubeShape1@node"],</span><span data-v-c2b1f83f="" class="line"> renderer.plugins["pCubeShape1@mesh5"],</span><span data-v-c2b1f83f="" class="line"> renderer.plugins["VRayMtl1@material"],</span><span data-v-c2b1f83f="" class="line"> renderer.plugins["VRayMtl1@diffuse"]];</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> renderer.export("export_cube.vrscene", settings, function(err){</span><span data-v-c2b1f83f="" class="line"> if (err) throw err;</span><span data-v-c2b1f83f="" class="line"> // Start the sequence.</span><span data-v-c2b1f83f="" class="line"> renderer.renderSequence();</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // Wait for the renderer to finish.</span><span data-v-c2b1f83f="" class="line"> renderer.waitForSequenceEnd(function() {</span><span data-v-c2b1f83f="" class="line"> // Closes the renderer.</span><span data-v-c2b1f83f="" class="line"> // The renderer object is unusable after closing since its resources</span><span data-v-c2b1f83f="" class="line"> // are freed. It should be released for garbage collection.</span><span data-v-c2b1f83f="" class="line"> renderer.close();</span><span data-v-c2b1f83f="" class="line"> });</span><span data-v-c2b1f83f="" class="line"> });</span><span data-v-c2b1f83f="" class="line">});</span></code>
V-Ray Scene Files Version 2 Starting with V-Ray 6.1, a new version of the .vrscene format is available. The new version 2 .vrscene format is smaller in size and optimized for more efficient upload. It has features that aim to make it easier to render on a machine different from the one it was exported from. Version 1 format contains only the .vrscene file. A version 2 scene differs from version 1 as it has at least three files - a .vrscene, a .vrdata and a .vrfiles file.
If V-Ray scenes are distributed between different machines, which could not have all necessary assets in the scene, or a rendering job is submitted to Chaos Cloud, a functionality similar to the pack command of the Chaos Cloud Client would be useful.
A detailed example how to pack a version 2 .vrscene file with its companion (sidecar) files is available in examples/{language}/advanced/12-sidecar-scene-export
Python <code data-v-c2b1f83f=""><span data-v-c2b1f83f="" class="line"># Compatibility with Python 2.7.</span><span data-v-c2b1f83f="" class="line">from __future__ import print_function</span><span data-v-c2b1f83f="" class="line">import sys, os</span><span data-v-c2b1f83f="" class="line">import vrfiles_parser as parser</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"># The directory containing the vray shared object should be present in the PYTHONPATH environment variable.</span><span data-v-c2b1f83f="" class="line"># Try to import the vray module from VRAY_SDK/python, if it is not in PYTHONPATH</span><span data-v-c2b1f83f="" class="line">VRAY_SDK = os.environ.get('VRAY_SDK')</span><span data-v-c2b1f83f="" class="line">if VRAY_SDK:</span><span data-v-c2b1f83f="" class="line"> sys.path.append(os.path.join(VRAY_SDK, 'python'))</span><span data-v-c2b1f83f="" class="line">import vray</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">SCENE_PATH = os.path.join(VRAY_SDK, 'scenes')</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"># The name of the scene to be loaded</span><span data-v-c2b1f83f="" class="line">sceneName = 'cornell_new'</span><span data-v-c2b1f83f="" class="line"># The suffix to distinguish the exported file</span><span data-v-c2b1f83f="" class="line">exportedSuffix = '_sidecar'</span><span data-v-c2b1f83f="" class="line"># The name of the folder for storing the copied assets</span><span data-v-c2b1f83f="" class="line">resourcesName = 'resources'</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"># Change process working directory to SCENE_PATH in order to be able to load relative scene resources.</span><span data-v-c2b1f83f="" class="line">os.chdir(SCENE_PATH)</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"># Create an instance of VRayRenderer with default options.</span><span data-v-c2b1f83f="" class="line"># The renderer is automatically closed after the `with` block.</span><span data-v-c2b1f83f="" class="line">with vray.VRayRenderer() as renderer:</span><span data-v-c2b1f83f="" class="line"> # Register a simple log callback. Always useful for debugging.</span><span data-v-c2b1f83f="" class="line"> def dumpMsg(renderer, message, level, instant):</span><span data-v-c2b1f83f="" class="line"> if level == vray.LOGLEVEL_ERROR:</span><span data-v-c2b1f83f="" class="line"> print("[ERROR]", message)</span><span data-v-c2b1f83f="" class="line"> elif level == vray.LOGLEVEL_WARNING:</span><span data-v-c2b1f83f="" class="line"> print("[Warning]", message)</span><span data-v-c2b1f83f="" class="line"> elif level == vray.LOGLEVEL_INFO:</span><span data-v-c2b1f83f="" class="line"> print("[info]", message)</span><span data-v-c2b1f83f="" class="line"> # Uncomment for testing, but you might want to ignore these in real code</span><span data-v-c2b1f83f="" class="line"> # else: print("[debug]", message)</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> renderer.setOnLogMessage(dumpMsg)</span><span data-v-c2b1f83f="" class="line"> # Load scene from a file.</span><span data-v-c2b1f83f="" class="line"> renderer.load(sceneName + parser.vrsceneExt)</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> # Export with settings for companion (sidecar) files - vrdata and vrfiles</span><span data-v-c2b1f83f="" class="line"> # It is particularly useful when we have a vrscene containing:</span><span data-v-c2b1f83f="" class="line"> # - large data buffers, which could possibly be duplicated between the plugins</span><span data-v-c2b1f83f="" class="line"> # - various absolute or relative paths to referenced files - textures, OCIO configs, meshes, materials, etc.</span><span data-v-c2b1f83f="" class="line"> # The files existing on the machine, which did the export, may not exist on another machine</span><span data-v-c2b1f83f="" class="line"> settings = {}</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> # Enable vrdata files to be exported (default is false)</span><span data-v-c2b1f83f="" class="line"> settings['vrdataExport'] = True</span><span data-v-c2b1f83f="" class="line"> # If the buffer size in bytes is smaller than this value, it is not written to the vrdata file. (default is 2048 bytes)</span><span data-v-c2b1f83f="" class="line"> settings['vrdataSmallBufferSizeLimit'] = 2048</span><span data-v-c2b1f83f="" class="line"> # Limit the size (MiB) of the vrdata file. If this limit is reached another file is started. (default is 0 - no limit)</span><span data-v-c2b1f83f="" class="line"> settings['vrdataFileSizeLimitMiB'] = 0</span><span data-v-c2b1f83f="" class="line"> # Enable vrfiles files to be exported (default is false)</span><span data-v-c2b1f83f="" class="line"> settings['vrfilesExport'] = True</span><span data-v-c2b1f83f="" class="line"> # Enable computation and writing to the vfiles of MD5 and SHA256 hashes for each resolved asset file (default is false)</span><span data-v-c2b1f83f="" class="line"> settings['vrfilesComputeHashes'] = True</span><span data-v-c2b1f83f="" class="line"> # Optional absolute scene base path that can be used for resolving relative paths for the vrfiles file.</span><span data-v-c2b1f83f="" class="line"> settings['sceneBasePath'] = SCENE_PATH</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> # Export the scene - the following directive is written in the beginning the vrscene file </span><span data-v-c2b1f83f="" class="line"> # #version 2</span><span data-v-c2b1f83f="" class="line"> exportedScene = sceneName + exportedSuffix</span><span data-v-c2b1f83f="" class="line"> success = renderer.export(exportedScene + parser.vrsceneExt, settings)</span><span data-v-c2b1f83f="" class="line"> if success:</span><span data-v-c2b1f83f="" class="line"> # Copies all assets and files related to the exportedScene to the destFolder</span><span data-v-c2b1f83f="" class="line"> # and rewrites the absolute actual paths in the vrfiles to relative ones</span><span data-v-c2b1f83f="" class="line"> parser.packExportedVrscene(exportedScene, sceneName, resourcesName)</span><span data-v-c2b1f83f="" class="line"> # The destFolder could be then packed and sent for rendering on another machine</span><span data-v-c2b1f83f="" class="line"> # We could also load it locally and start rendering</span><span data-v-c2b1f83f="" class="line"> os.chdir(sceneName)</span><span data-v-c2b1f83f="" class="line"> renderer.load(exportedScene + parser.vrsceneExt)</span><span data-v-c2b1f83f="" class="line"> renderer.start()</span><span data-v-c2b1f83f="" class="line"> renderer.waitForRenderEnd(15000)</span></code>
C++ <code data-v-c2b1f83f=""><span data-v-c2b1f83f="" class="line">#define VRAY_RUNTIME_LOAD_PRIMARY</span><span data-v-c2b1f83f="" class="line">#include "vraysdk.hpp"</span><span data-v-c2b1f83f="" class="line">#include "vrayplugins.hpp"</span><span data-v-c2b1f83f="" class="line">#include "vrfiles_parser.h"</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">using namespace VRay;</span><span data-v-c2b1f83f="" class="line">using namespace VRay::Plugins;</span><span data-v-c2b1f83f="" class="line">using namespace std;</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">const char *BASE_PATH = getenv("VRAY_SDK");</span><span data-v-c2b1f83f="" class="line">const string SCENE_PATH = (BASE_PATH ? string(BASE_PATH) : string(".")) + PATH_DELIMITER + "scenes";</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">// The name of the scene to be loaded</span><span data-v-c2b1f83f="" class="line">static const string sceneName = "cornell_new";</span><span data-v-c2b1f83f="" class="line">// The suffix to distinguish the exported file</span><span data-v-c2b1f83f="" class="line">static const string exportedSuffix = "_sidecar";</span><span data-v-c2b1f83f="" class="line">// The name of the folder for storing the copied assets</span><span data-v-c2b1f83f="" class="line">static const string resourcesName = "resources";</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">int main() {</span><span data-v-c2b1f83f="" class="line"> // Change process working directory to SCENE_PATH in order to be able to load relative scene resources.</span><span data-v-c2b1f83f="" class="line"> changeCurrentDir(SCENE_PATH.c_str());</span><span data-v-c2b1f83f="" class="line"> // Load V-Ray SDK library.</span><span data-v-c2b1f83f="" class="line"> VRayInit init(NULL, true);</span><span data-v-c2b1f83f="" class="line"> // Create an instance of VRayRenderer with default options.</span><span data-v-c2b1f83f="" class="line"> VRayRenderer renderer;</span><span data-v-c2b1f83f="" class="line"> // It's recommended to always have a console log</span><span data-v-c2b1f83f="" class="line"> renderer.setOnLogMessage(logMessage);</span><span data-v-c2b1f83f="" class="line"> // Load scene from a file.</span><span data-v-c2b1f83f="" class="line"> renderer.load(sceneName + vrsceneExt);</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // Export with settings for companion (sidecar) files - vrdata and vrfiles</span><span data-v-c2b1f83f="" class="line"> // It is particularly useful when we have a vrscene containing:</span><span data-v-c2b1f83f="" class="line"> // - large data buffers, which could possibly be duplicated between the plugins</span><span data-v-c2b1f83f="" class="line"> // - various absolute or relative paths to referenced files - textures, OCIO configs, meshes, materials, etc.</span><span data-v-c2b1f83f="" class="line"> // The files existing on the machine, which did the export, may not exist on another machine</span><span data-v-c2b1f83f="" class="line"> VRayExportSettings settings;</span><span data-v-c2b1f83f="" class="line"> // Enable vrdata files to be exported (default is false)</span><span data-v-c2b1f83f="" class="line"> settings.vrdataExport = true;</span><span data-v-c2b1f83f="" class="line"> // If the buffer size in bytes is smaller than this value, it is not written to the vrdata file. (default is 2048 bytes)</span><span data-v-c2b1f83f="" class="line"> settings.vrdataSmallBufferSizeLimit = 2048;</span><span data-v-c2b1f83f="" class="line"> // Limit the size (MiB) of the vrdata file. If this limit is reached another file is started. (default is 0 - no limit)</span><span data-v-c2b1f83f="" class="line"> settings.vrdataFileSizeLimitMiB = 0;</span><span data-v-c2b1f83f="" class="line"> // Enable vrfiles files to be exported (default is false)</span><span data-v-c2b1f83f="" class="line"> settings.vrfilesExport = true;</span><span data-v-c2b1f83f="" class="line"> // Enable computation and writing to the vfiles of MD5 and SHA256 hashes for each resolved asset file (default is false)</span><span data-v-c2b1f83f="" class="line"> settings.vrfilesComputeHashes = true;</span><span data-v-c2b1f83f="" class="line"> // Optional absolute scene base path that can be used for resolving relative paths for the vrfiles file.</span><span data-v-c2b1f83f="" class="line"> settings.sceneBasePath = SCENE_PATH;</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // Export the scene - the following directive is written in the beginning the vrscene file </span><span data-v-c2b1f83f="" class="line"> // #version 2</span><span data-v-c2b1f83f="" class="line"> string exportedScene = sceneName + exportedSuffix;</span><span data-v-c2b1f83f="" class="line"> int err = renderer.exportScene(exportedScene + vrsceneExt, settings);</span><span data-v-c2b1f83f="" class="line"> if (!err) {</span><span data-v-c2b1f83f="" class="line"> // Copies all assets and files related to the exportedScene to the destFolder</span><span data-v-c2b1f83f="" class="line"> // and rewrites the absolute actual paths in the vrfiles to relative ones</span><span data-v-c2b1f83f="" class="line"> VRFilesParser::packExportedVrscene(exportedScene, sceneName, resourcesName);</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // The destFolder could be then packed and sent for rendering on another machine</span><span data-v-c2b1f83f="" class="line"> // We could also load it locally and start rendering</span><span data-v-c2b1f83f="" class="line"> changeCurrentDir(sceneName.c_str());</span><span data-v-c2b1f83f="" class="line"> renderer.load(exportedScene + vrsceneExt);</span><span data-v-c2b1f83f="" class="line"> renderer.startSync();</span><span data-v-c2b1f83f="" class="line"> renderer.waitForRenderEnd(15000);</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line"> return 0;</span><span data-v-c2b1f83f="" class="line">}</span></code>
C#.NET <code data-v-c2b1f83f=""><span data-v-c2b1f83f="" class="line">using System;</span><span data-v-c2b1f83f="" class="line">using System.IO;</span><span data-v-c2b1f83f="" class="line">using VRay;</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">class Program</span><span data-v-c2b1f83f="" class="line">{</span><span data-v-c2b1f83f="" class="line"> // The name of the scene to be loaded</span><span data-v-c2b1f83f="" class="line"> const string sceneName = "cornell_new";</span><span data-v-c2b1f83f="" class="line"> // The suffix to distinguish the exported file</span><span data-v-c2b1f83f="" class="line"> const string exportedSuffix = "_sidecar";</span><span data-v-c2b1f83f="" class="line"> // The name of the folder for storing the copied assets</span><span data-v-c2b1f83f="" class="line"> const string resourcesName = "resources";</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> static void Main(string[] args)</span><span data-v-c2b1f83f="" class="line"> {</span><span data-v-c2b1f83f="" class="line"> string SCENE_PATH = Path.Combine(Environment.GetEnvironmentVariable("VRAY_SDK"), "scenes");</span><span data-v-c2b1f83f="" class="line"> // Change process working directory to SCENE_PATH in order to be able to load relative scene resources.</span><span data-v-c2b1f83f="" class="line"> Directory.SetCurrentDirectory(SCENE_PATH);</span><span data-v-c2b1f83f="" class="line"> // Create an instance of VRayRenderer with default options.</span><span data-v-c2b1f83f="" class="line"> // The renderer is automatically closed after the `using` block.</span><span data-v-c2b1f83f="" class="line"> using (VRayRenderer renderer = new VRayRenderer())</span><span data-v-c2b1f83f="" class="line"> {</span><span data-v-c2b1f83f="" class="line"> // Add a listener for any type of log message.</span><span data-v-c2b1f83f="" class="line"> renderer.LogMessage += new EventHandler<MessageEventArgs>((source, e) =></span><span data-v-c2b1f83f="" class="line"> {</span><span data-v-c2b1f83f="" class="line"> // You can remove the if for testing, but you might want to ignore Debug in real code</span><span data-v-c2b1f83f="" class="line"> if (e.LogLevel != LogLevelType.Debug)</span><span data-v-c2b1f83f="" class="line"> {</span><span data-v-c2b1f83f="" class="line"> Console.WriteLine(String.Format("[{0}] {1}", e.LogLevel.ToString(), e.Message));</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line"> });</span><span data-v-c2b1f83f="" class="line"> // Load scene from a file.</span><span data-v-c2b1f83f="" class="line"> renderer.Load(sceneName + VRFilesParser.VrsceneExt);</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // Export with settings for companion (sidecar) files - vrdata and vrfiles</span><span data-v-c2b1f83f="" class="line"> // It is particularly useful when we have a vrscene containing:</span><span data-v-c2b1f83f="" class="line"> // - large data buffers, which could possibly be duplicated between the plugins</span><span data-v-c2b1f83f="" class="line"> // - various absolute or relative paths to referenced files - textures, OCIO configs, meshes, materials, etc.</span><span data-v-c2b1f83f="" class="line"> // The files existing on the machine, which did the export, may not exist on another machine</span><span data-v-c2b1f83f="" class="line"> ExportSettings settings = new ExportSettings();</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // Enable vrdata files to be exported (default is false)</span><span data-v-c2b1f83f="" class="line"> settings.VrdataExport = true;</span><span data-v-c2b1f83f="" class="line"> // If the buffer size in bytes is smaller than this value, it is not written to the vrdata file. (default is 2048 bytes)</span><span data-v-c2b1f83f="" class="line"> settings.VrdataSmallBufferSizeLimit = 2048;</span><span data-v-c2b1f83f="" class="line"> // Limit the size (MiB) of the vrdata file. If this limit is reached another file is started. (default is 0 - no limit)</span><span data-v-c2b1f83f="" class="line"> settings.VrdataFileSizeLimitMiB = 0;</span><span data-v-c2b1f83f="" class="line"> // Enable vrfiles files to be exported (default is false)</span><span data-v-c2b1f83f="" class="line"> settings.VrfilesExport = true;</span><span data-v-c2b1f83f="" class="line"> // Enable computation and writing to the vfiles of MD5 and SHA256 hashes for each resolved asset file (default is false)</span><span data-v-c2b1f83f="" class="line"> settings.VrfilesComputeHashes = true;</span><span data-v-c2b1f83f="" class="line"> // Optional absolute scene base path that can be used for resolving relative paths for the vrfiles file.</span><span data-v-c2b1f83f="" class="line"> settings.SceneBasePath = SCENE_PATH;</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // Export the scene - the following directive is written in the beginning the vrscene file </span><span data-v-c2b1f83f="" class="line"> // #version 2</span><span data-v-c2b1f83f="" class="line"> string exportedScene = sceneName + exportedSuffix;</span><span data-v-c2b1f83f="" class="line"> bool success = renderer.Export(exportedScene + VRFilesParser.VrsceneExt, settings);</span><span data-v-c2b1f83f="" class="line"> if (success)</span><span data-v-c2b1f83f="" class="line"> {</span><span data-v-c2b1f83f="" class="line"> // Copies all assets and files related to the exportedScene to the destFolder</span><span data-v-c2b1f83f="" class="line"> // and rewrites the absolute actual paths in the vrfiles to relative ones</span><span data-v-c2b1f83f="" class="line"> VRFilesParser.PackExportedVrscene(exportedScene, sceneName, resourcesName);</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // The destFolder could be then packed and sent for rendering on another machine</span><span data-v-c2b1f83f="" class="line"> // We could also load it locally and start rendering</span><span data-v-c2b1f83f="" class="line"> Directory.SetCurrentDirectory(sceneName);</span><span data-v-c2b1f83f="" class="line"> renderer.Load(exportedScene + VRFilesParser.VrsceneExt);</span><span data-v-c2b1f83f="" class="line"> renderer.StartSync();</span><span data-v-c2b1f83f="" class="line"> renderer.WaitForRenderEnd(15000);</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line"> }</span><span data-v-c2b1f83f="" class="line">}</span></code>
Node.js <code data-v-c2b1f83f=""><span data-v-c2b1f83f="" class="line">const parser = require("./vrfiles_parser");</span><span data-v-c2b1f83f="" class="line">const vray = require(parser.path.join(process.env.VRAY_SDK, "node", "vray"));</span><span data-v-c2b1f83f="" class="line">const SCENE_PATH = parser.path.join(process.env.VRAY_SDK, "scenes");</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">// The name of the scene to be loaded</span><span data-v-c2b1f83f="" class="line">const sceneName = "cornell_new";</span><span data-v-c2b1f83f="" class="line">// The suffix to distinguish the exported file</span><span data-v-c2b1f83f="" class="line">const exportedSuffix = "_sidecar";</span><span data-v-c2b1f83f="" class="line">// The name of the folder for storing the copied assets</span><span data-v-c2b1f83f="" class="line">const resourcesName = "resources";</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">// Change process working directory to SCENE_PATH in order to be able to load relative scene resources.</span><span data-v-c2b1f83f="" class="line">process.chdir(SCENE_PATH);</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">// Create an instance of VRayRenderer with default options.</span><span data-v-c2b1f83f="" class="line">var renderer = vray.VRayRenderer();</span><span data-v-c2b1f83f="" class="line">// It's recommended to always have a console log callback</span><span data-v-c2b1f83f="" class="line">renderer.on("logMessage", function (message, level, instant) {</span><span data-v-c2b1f83f="" class="line"> if (level == vray.LOGLEVEL_ERROR)</span><span data-v-c2b1f83f="" class="line"> console.log("[ERROR] ", message);</span><span data-v-c2b1f83f="" class="line"> else if (level == vray.LOGLEVEL_WARNING)</span><span data-v-c2b1f83f="" class="line"> console.log("[Warning] ", message);</span><span data-v-c2b1f83f="" class="line"> else if (level == vray.LOGLEVEL_INFO)</span><span data-v-c2b1f83f="" class="line"> console.log("[info] ", message);</span><span data-v-c2b1f83f="" class="line"> // Uncomment for testing, but you might want to ignore these in real code</span><span data-v-c2b1f83f="" class="line"> //else console.log("[debug] ", message);</span><span data-v-c2b1f83f="" class="line">});</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line">// Load scene from a file.</span><span data-v-c2b1f83f="" class="line">renderer.load(sceneName + parser.vrsceneExt, function (err) {</span><span data-v-c2b1f83f="" class="line"> if (err) throw err;</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // Export with settings for companion (sidecar) files - vrdata and vrfiles</span><span data-v-c2b1f83f="" class="line"> // It is particularly useful when we have a vrscene containing:</span><span data-v-c2b1f83f="" class="line"> // - large data buffers, which could possibly be duplicated between the plugins</span><span data-v-c2b1f83f="" class="line"> // - various absolute or relative paths to referenced files - textures, OCIO configs, meshes, materials, etc.</span><span data-v-c2b1f83f="" class="line"> // The files existing on the machine, which did the export, may not exist on another machine</span><span data-v-c2b1f83f="" class="line"> var settings = {};</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // Enable vrdata files to be exported (default is false)</span><span data-v-c2b1f83f="" class="line"> settings.vrdataExport = true;</span><span data-v-c2b1f83f="" class="line"> // If the buffer size in bytes is smaller than this value, it is not written to the vrdata file. (default is 2048 bytes)</span><span data-v-c2b1f83f="" class="line"> settings.vrdataSmallBufferSizeLimit = 2048;</span><span data-v-c2b1f83f="" class="line"> // Limit the size (MiB) of the vrdata file. If this limit is reached another file is started. (default is 0 - no limit)</span><span data-v-c2b1f83f="" class="line"> settings.vrdataFileSizeLimitMiB = 0;</span><span data-v-c2b1f83f="" class="line"> // Enable vrfiles files to be exported (default is false)</span><span data-v-c2b1f83f="" class="line"> settings.vrfilesExport = true;</span><span data-v-c2b1f83f="" class="line"> // Enable computation and writing to the vfiles of MD5 and SHA256 hashes for each resolved asset file (default is false)</span><span data-v-c2b1f83f="" class="line"> settings.vrfilesComputeHashes = true;</span><span data-v-c2b1f83f="" class="line"> // Optional absolute scene base path that can be used for resolving relative paths for the vrfiles file.</span><span data-v-c2b1f83f="" class="line"> settings.sceneBasePath = SCENE_PATH;</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // Export the scene - the following directive is written in the beginning the vrscene file </span><span data-v-c2b1f83f="" class="line"> // #version 2</span><span data-v-c2b1f83f="" class="line"> var exportedScene = sceneName + exportedSuffix;</span><span data-v-c2b1f83f="" class="line"> renderer.export(exportedScene + parser.vrsceneExt, settings, function (err) {</span><span data-v-c2b1f83f="" class="line"> if (err) throw err;</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // Copies all assets and files related to the exportedScene to the destFolder</span><span data-v-c2b1f83f="" class="line"> // and rewrites the absolute actual paths in the vrfiles to relative ones</span><span data-v-c2b1f83f="" class="line"> parser.packExportedVrscene(exportedScene, sceneName, resourcesName, function(err) {</span><span data-v-c2b1f83f="" class="line"> if (err) throw err;</span><span data-v-c2b1f83f="" class="line"></span><span data-v-c2b1f83f="" class="line"> // The destFolder could be then packed and sent for rendering on another machine</span><span data-v-c2b1f83f="" class="line"> // We could also load it locally and start rendering</span><span data-v-c2b1f83f="" class="line"> process.chdir(sceneName);</span><span data-v-c2b1f83f="" class="line"> renderer.load(exportedScene + parser.vrsceneExt, function (err) {</span><span data-v-c2b1f83f="" class="line"> if (err) throw err;</span><span data-v-c2b1f83f="" class="line"> renderer.start(function (err) {</span><span data-v-c2b1f83f="" class="line"> if (err) throw err;</span><span data-v-c2b1f83f="" class="line"> renderer.waitForRenderEnd(15000, function () {</span><span data-v-c2b1f83f="" class="line"> // Closes the renderer.</span><span data-v-c2b1f83f="" class="line"> // The renderer object is unusable after closing since its resources</span><span data-v-c2b1f83f="" class="line"> // are freed. It should be released for garbage collection.</span><span data-v-c2b1f83f="" class="line"> renderer.close();</span><span data-v-c2b1f83f="" class="line"> });</span><span data-v-c2b1f83f="" class="line"> });</span><span data-v-c2b1f83f="" class="line"> });</span><span data-v-c2b1f83f="" class="line"> });</span><span data-v-c2b1f83f="" class="line"> });</span><span data-v-c2b1f83f="" class="line">});</span></code>