# 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) |
|
#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;
} |
|
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);
}
}
}
} |
|
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();
});
});
});
});
});
}); |
|
|