Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

V-Ray Scene Files Version 2

...

Starting with V-Ray 6.1, a new version of the the .vrscene format format is available. The new version 2 .vrscene format is smaller in size and optimized for more efficient upload. It has features which aim to make it easier for rendering on a machine different from the one it has been 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

Tabs Container
directionhorizontal
Tabs Page
titlePython
Code Block
languagepy
# Compatibility with Python 2.7.
from __future__ import print_function
import sys, os
import vrfiles_parser as parser

# The directory containing the vray shared object should be present in the PYTHONPATH environment variable.
# Try to import the vray module from VRAY_SDK/python, if it is not in PYTHONPATH
VRAY_SDK = os.environ.get('VRAY_SDK')
if VRAY_SDK:
    sys.path.append(os.path.join(VRAY_SDK, 'python'))
import vray

SCENE_PATH = os.path.join(VRAY_SDK, 'scenes')

# The name of the scene to be loaded
sceneName = 'cornell_new'
# The suffix to distinguish the exported file
exportedSuffix = '_sidecar'
# The name of the folder for storing the copied assets
resourcesName = 'resources'

# Change process working directory to SCENE_PATH in order to be able to load relative scene resources.
os.chdir(SCENE_PATH)

# Create an instance of VRayRenderer with default options.
# The renderer is automatically closed after the `with` block.
with vray.VRayRenderer() as renderer:
    # Register a simple log callback. Always useful for debugging.
    def dumpMsg(renderer, message, level, instant):
        if level == vray.LOGLEVEL_ERROR:
            print("[ERROR]", message)
        elif level == vray.LOGLEVEL_WARNING:
            print("[Warning]", message)
        elif level == vray.LOGLEVEL_INFO:
            print("[info]", message)
        # Uncomment for testing, but you might want to ignore these in real code
        # else: print("[debug]", message)

    renderer.setOnLogMessage(dumpMsg)
    # Load scene from a file.
    renderer.load(sceneName + parser.vrsceneExt)

    # Export with settings for companion (sidecar) files - vrdata and vrfiles
    # It is particularly useful when we have a vrscene containing:
    # - large data buffers, which could possibly be duplicated between the plugins
    # - various absolute or relative paths to referenced files - textures, OCIO configs, meshes, materials, etc.
    #   The files existing on the machine, which did the export, may not exist on another machine
    settings = {}

    # Enable vrdata files to be exported (default is false)
    settings['vrdataExport'] = True
    # If the buffer size in bytes is smaller than this value, it is not written to the vrdata file. (default is 2048 bytes)
    settings['vrdataSmallBufferSizeLimit'] = 2048
    # Limit the size (MiB) of the vrdata file. If this limit is reached another file is started. (default is 0 - no limit)
    settings['vrdataFileSizeLimitMiB'] = 0
    # Enable vrfiles files to be exported (default is false)
    settings['vrfilesExport'] = True
    # Enable computation and writing to the vfiles of MD5 and SHA256 hashes for each resolved asset file (default is false)
    settings['vrfilesComputeHashes'] = True
    # Optional absolute scene base path that can be used for resolving relative paths for the vrfiles file.
    settings['sceneBasePath'] = SCENE_PATH

    # Export the scene - the following directive is written in the beginning the vrscene file 
    # #version 2
    exportedScene = sceneName + exportedSuffix
    success = renderer.export(exportedScene + parser.vrsceneExt, settings)
    if success:
        # Copies all assets and files related to the exportedScene to the destFolder
        # and rewrites the absolute actual paths in the vrfiles to relative ones
        parser.packExportedVrscene(exportedScene, sceneName, resourcesName)
        # The destFolder could be then packed and sent for rendering on another machine
        # We could also load it locally and start rendering
        os.chdir(sceneName)
        renderer.load(exportedScene + parser.vrsceneExt)
        renderer.start()
        renderer.waitForRenderEnd(15000)
Tabs Page
titleC++
Code Block
languagecpp
#define VRAY_RUNTIME_LOAD_PRIMARY
#include "vraysdk.hpp"
#include "vrayplugins.hpp"
#include "vrfiles_parser.h"

using namespace VRay;
using namespace VRay::Plugins;
using namespace std;

const char *BASE_PATH = getenv("VRAY_SDK");
const string SCENE_PATH = (BASE_PATH ? string(BASE_PATH) : string(".")) + PATH_DELIMITER + "scenes";

// The name of the scene to be loaded
static const string sceneName = "cornell_new";
// The suffix to distinguish the exported file
static const string exportedSuffix = "_sidecar";
// The name of the folder for storing the copied assets
static const string resourcesName = "resources";

int main() {
	// Change process working directory to SCENE_PATH in order to be able to load relative scene resources.
	changeCurrentDir(SCENE_PATH.c_str());
	// Load V-Ray SDK library.
	VRayInit init(NULL, true);
	// Create an instance of VRayRenderer with default options.
	VRayRenderer renderer;
	// It's recommended to always have a console log
	renderer.setOnLogMessage(logMessage);
	// Load scene from a file.
	renderer.load(sceneName + vrsceneExt);

	// Export with settings for companion (sidecar) files - vrdata and vrfiles
	// It is particularly useful when we have a vrscene containing:
	// - large data buffers, which could possibly be duplicated between the plugins
	// - various absolute or relative paths to referenced files - textures, OCIO configs, meshes, materials, etc.
	//   The files existing on the machine, which did the export, may not exist on another machine
	VRayExportSettings settings;
	// Enable vrdata files to be exported (default is false)
	settings.vrdataExport = true;
	// If the buffer size in bytes is smaller than this value, it is not written to the vrdata file. (default is 2048 bytes)
	settings.vrdataSmallBufferSizeLimit = 2048;
	// Limit the size (MiB) of the vrdata file. If this limit is reached another file is started. (default is 0 - no limit)
	settings.vrdataFileSizeLimitMiB = 0;
	// Enable vrfiles files to be exported (default is false)
	settings.vrfilesExport = true;
	// Enable computation and writing to the vfiles of MD5 and SHA256 hashes for each resolved asset file (default is false)
	settings.vrfilesComputeHashes = true;
	// Optional absolute scene base path that can be used for resolving relative paths for the vrfiles file.
	settings.sceneBasePath = SCENE_PATH;

	// Export the scene - the following directive is written in the beginning the vrscene file 
	// #version 2
	string exportedScene = sceneName + exportedSuffix;
	int err = renderer.exportScene(exportedScene + vrsceneExt, settings);
	if (!err) {
		// Copies all assets and files related to the exportedScene to the destFolder
		// and rewrites the absolute actual paths in the vrfiles to relative ones
		VRFilesParser::packExportedVrscene(exportedScene, sceneName, resourcesName);

		// The destFolder could be then packed and sent for rendering on another machine
		// We could also load it locally and start rendering
		changeCurrentDir(sceneName.c_str());
		renderer.load(exportedScene + vrsceneExt);
		renderer.startSync();
		renderer.waitForRenderEnd(15000);
	}
	return 0;
}
Tabs Page
titleC#.NET
Code Block
languagec#
using System;
using System.IO;
using VRay;

class Program
{
	// The name of the scene to be loaded
	const string sceneName = "cornell_new";
	// The suffix to distinguish the exported file
	const string exportedSuffix = "_sidecar";
	// The name of the folder for storing the copied assets
	const string resourcesName = "resources";

	static void Main(string[] args)
	{
		string SCENE_PATH = Path.Combine(Environment.GetEnvironmentVariable("VRAY_SDK"), "scenes");
		// Change process working directory to SCENE_PATH in order to be able to load relative scene resources.
		Directory.SetCurrentDirectory(SCENE_PATH);
		// Create an instance of VRayRenderer with default options.
		// The renderer is automatically closed after the `using` block.
		using (VRayRenderer renderer = new VRayRenderer())
		{
			// Add a listener for any type of log message.
			renderer.LogMessage += new EventHandler<MessageEventArgs>((source, e) =>
			{
				// You can remove the if for testing, but you might want to ignore Debug in real code
				if (e.LogLevel != LogLevelType.Debug)
				{
					Console.WriteLine(String.Format("[{0}] {1}", e.LogLevel.ToString(), e.Message));
				}
			});
			// Load scene from a file.
			renderer.Load(sceneName + VRFilesParser.VrsceneExt);

			// Export with settings for companion (sidecar) files - vrdata and vrfiles
			// It is particularly useful when we have a vrscene containing:
			// - large data buffers, which could possibly be duplicated between the plugins
			// - various absolute or relative paths to referenced files - textures, OCIO configs, meshes, materials, etc.
			//   The files existing on the machine, which did the export, may not exist on another machine
			ExportSettings settings = new ExportSettings();

			// Enable vrdata files to be exported (default is false)
			settings.VrdataExport = true;
			// If the buffer size in bytes is smaller than this value, it is not written to the vrdata file. (default is 2048 bytes)
			settings.VrdataSmallBufferSizeLimit = 2048;
			// Limit the size (MiB) of the vrdata file. If this limit is reached another file is started. (default is 0 - no limit)
			settings.VrdataFileSizeLimitMiB = 0;
			// Enable vrfiles files to be exported (default is false)
			settings.VrfilesExport = true;
			// Enable computation and writing to the vfiles of MD5 and SHA256 hashes for each resolved asset file (default is false)
			settings.VrfilesComputeHashes = true;
			// Optional absolute scene base path that can be used for resolving relative paths for the vrfiles file.
			settings.SceneBasePath = SCENE_PATH;

			// Export the scene - the following directive is written in the beginning the vrscene file 
			// #version 2
			string exportedScene = sceneName + exportedSuffix;
			bool success = renderer.Export(exportedScene + VRFilesParser.VrsceneExt, settings);
			if (success)
			{
				// Copies all assets and files related to the exportedScene to the destFolder
				// and rewrites the absolute actual paths in the vrfiles to relative ones
				VRFilesParser.PackExportedVrscene(exportedScene, sceneName, resourcesName);

				// The destFolder could be then packed and sent for rendering on another machine
				// We could also load it locally and start rendering
				Directory.SetCurrentDirectory(sceneName);
				renderer.Load(exportedScene + VRFilesParser.VrsceneExt);
				renderer.StartSync();
				renderer.WaitForRenderEnd(15000);
			}
		}
	}
}
Tabs Page
titleNode.js
Code Block
languagejs
const parser = require("./vrfiles_parser");
const vray = require(parser.path.join(process.env.VRAY_SDK, "node", "vray"));
const SCENE_PATH = parser.path.join(process.env.VRAY_SDK, "scenes");

// The name of the scene to be loaded
const sceneName = "cornell_new";
// The suffix to distinguish the exported file
const exportedSuffix = "_sidecar";
// The name of the folder for storing the copied assets
const resourcesName = "resources";

// Change process working directory to SCENE_PATH in order to be able to load relative scene resources.
process.chdir(SCENE_PATH);

// Create an instance of VRayRenderer with default options.
var renderer = vray.VRayRenderer();
// It's recommended to always have a console log callback
renderer.on("logMessage", function (message, level, instant) {
	if (level == vray.LOGLEVEL_ERROR)
		console.log("[ERROR] ", message);
	else if (level == vray.LOGLEVEL_WARNING)
		console.log("[Warning] ", message);
	else if (level == vray.LOGLEVEL_INFO)
		console.log("[info] ", message);
	// Uncomment for testing, but you might want to ignore these in real code
	//else console.log("[debug] ", message);
});

// Load scene from a file.
renderer.load(sceneName + parser.vrsceneExt, function (err) {
	if (err) throw err;

	// Export with settings for companion (sidecar) files - vrdata and vrfiles
	// It is particularly useful when we have a vrscene containing:
	// - large data buffers, which could possibly be duplicated between the plugins
	// - various absolute or relative paths to referenced files - textures, OCIO configs, meshes, materials, etc.
	//   The files existing on the machine, which did the export, may not exist on another machine
	var settings = {};

	// Enable vrdata files to be exported (default is false)
	settings.vrdataExport = true;
	// If the buffer size in bytes is smaller than this value, it is not written to the vrdata file. (default is 2048 bytes)
	settings.vrdataSmallBufferSizeLimit = 2048;
	// Limit the size (MiB) of the vrdata file. If this limit is reached another file is started. (default is 0 - no limit)
	settings.vrdataFileSizeLimitMiB = 0;
	// Enable vrfiles files to be exported (default is false)
	settings.vrfilesExport = true;
	// Enable computation and writing to the vfiles of MD5 and SHA256 hashes for each resolved asset file (default is false)
	settings.vrfilesComputeHashes = true;
	// Optional absolute scene base path that can be used for resolving relative paths for the vrfiles file.
	settings.sceneBasePath = SCENE_PATH;

	// Export the scene - the following directive is written in the beginning the vrscene file 
	// #version 2
	var exportedScene = sceneName + exportedSuffix;
	renderer.export(exportedScene + parser.vrsceneExt, settings, function (err) {
		if (err) throw err;

		// Copies all assets and files related to the exportedScene to the destFolder
		// and rewrites the absolute actual paths in the vrfiles to relative ones
		parser.packExportedVrscene(exportedScene, sceneName, resourcesName, function(err) {
			if (err) throw err;

			// The destFolder could be then packed and sent for rendering on another machine
			// We could also load it locally and start rendering
			process.chdir(sceneName);
			renderer.load(exportedScene + parser.vrsceneExt, function (err) {
				if (err) throw err;
				renderer.start(function (err) {
					if (err) throw err;
					renderer.waitForRenderEnd(15000, function () {
						// Closes the renderer.
						// The renderer object is unusable after closing since its resources
						// are freed. It should be released for garbage collection.
						renderer.close();
					});
				});
			});
		});
	});
});