View Categories

V-Ray Sahne Dosyalarını Dışa Aktarma

3 dakika okuma

Bu sayfa, V-Ray Sahne Dosyaları ( .vrscene ) hakkında bilgi vermektedir; bu dosyaların diğer iş akışlarında kullanılabilmesi için nasıl dışa aktarılacağı açıklanmaktadır.

Genel Bakış #


.vrscene dosya formatı App SDK ve V-Ray kullanan diğer platformlardan dışa aktarılabilecek bir ASCII dosyasıdır. Geometri, ışıklar ve gölgelendiriciler gibi sahneyle ilgili tüm bilgileri içerir ve V -Ray Standalone ile işlenebilir . Bu işlev, ışıkları ve tüm varlıkları dokuları ve malzemeleriyle birlikte V-Ray platformları arasında aktarabilir. Animasyon da dahildir.

V-Ray Sahne Dosyalarını Dışa Aktarma #


.vrscene dosyası , VRayRenderer’ın ilgili yöntemini çağırarak dışa aktarılabilir. Çeşitli seçeneklerle özelleştirilebilir, örneğin:

  • Sıkıştırılmış – büyük veri dizilerinin zlib ile sıkıştırılmasını sağlar (hexArrays==true gerektirir)

  • hexArrays – veri dizileri onaltılık formatta kodlanacaktır.

  • hexTransforms – dönüşümler onaltılık sayı sisteminde kodlanacaktır (çoğunlukla büyük örnekleyicilerde kullanışlıdır).

  • renderElementsSeparateFolders – SettingsOutput.relements_separateFolders’ın varsayılan değerini kontrol eder.

  • printHeader – sürüm ve zaman bilgilerini içeren yorum bölümünün yazılıp yazılmayacağı.

  • currentFrameOnly – eğer true ise yalnızca geçerli kare dışa aktarılır, aksi takdirde tüm zaman çizelgesi dışa aktarılır.

  • artımlı – yalnızca currentFrameOnly=true ve appendFrameSuffix=false olduğunda geçerlidir – ilk dışa aktarmadan sonra anahtar kare verilerini artımlı olarak eklemek için true olarak ayarlayın (false ile).

  • appendFrameSuffix – yalnızca currentFrameOnly=true olduğunda geçerlidir – dosya adına %04d kare numarasını ekler.

  • stripPaths – Etkinleştirilirse, bitmap dokularının ve diğer harici dosyaların yolları dosyadan kaldırılır, böylece yalnızca dosya adları kalır.

  • leftInterval – Yalnızca currentFrameOnly=true olduğunda geçerlidir. Anahtar karelerin dahil edileceği mevcut zamanın solundaki (kapalı) zaman aralığı – yani [sol, sağ). 0.0 değeri, FPS’ye bağlı olarak otomatik 1 kare anlamına gelir.

  • rightInterval – Yalnızca currentFrameOnly=true olduğunda geçerlidir. Anahtar karelerin dahil edileceği geçerli zamanın sağındaki (açık) zaman aralığı – yani [sol, sağ). 0.0 değeri, FPS’ye bağlı olarak otomatik 1 kare anlamına gelir.

  • subFileInfos – Eklenti türüne bağlı olarak sahneyi bölmek için kullanılacak dosyaların listesi. SubFileInfo türüyle ilgili yorumlara bakın.

  • pluginExportList – Bu alan boş değilse, sahnedeki tüm eklentiler yerine yalnızca bu eklentiler dışa aktarılacaktır.

  • additionalIncludeFiles – Ana vrscene’in sonunda #include edilecek dosyaların isteğe bağlı listesi

  • hostAppString – Ana uygulamayı, sürümünü vb. tanımlayan isteğe bağlı bir dize.

  • vrdataExport – vrdata dosya yazımını etkinleştirir veya devre dışı bırakır.

  • vrdataSmallBufferSizeLimit – Tamponun minimum boyutu için bir sınır belirleyin. Tampon daha küçükse, vrdata dosyasına yazılmaz.

  • vrdataFileSizeLimitMiB – vrdata dosyasının boyutunu sınırlandırır. Bu sınıra ulaşıldığında başka bir dosya başlatılır.

  • vrfilesExport – vrfiles dosya yazma özelliğini etkinleştirir veya devre dışı bırakır.

  • sceneBasePath – .vrfiles dosyası için göreceli yolları çözümlemek amacıyla kullanılabilen isteğe bağlı mutlak sahne temel yolu.

  • vrfilesComputeHashes – Çözümlenen her varlık dosyası için MD5 ve SHA256 özetlerinin hesaplanıp .vrfiles dosyasına yazılmasını isteyip istemediğinizi belirtir (True değeri).

Kod örneği #


İşte dışa aktarma işlevinin örnek bir kullanımı:

# Compatibility with Python 2.7.
from __future__ import print_function
 
# 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
import sys, os
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')
# 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)
    globalExportSettings = {}
    # Enable compression of large data arrays.
    globalExportSettings["hexArrays"] = True
    globalExportSettings["compressed"] = True
    # Keep transforms in human readable format
    globalExportSettings["hexTransforms"] = False
    # Print header to the export file
    globalExportSettings["printHeader"] = True
    # Export only the current frame.
    globalExportSettings["currentFrameOnly"] = True
    # Keep incremental off for the first frame so all plugins are exporeted properly.
    globalExportSettings["incremental"] = False
    # Separate the views and nodes in different files
    viewSubFileInfo = {"type": 'view', "suffix": 'view'}
    nodeSubFileInfo = {"type": 'nodes', "suffix": 'nodes'}
    globalExportSettings["subFileInfos"] = [viewSubFileInfo, nodeSubFileInfo]
 
    firstFrame = True
 
    def stateChanged(renderer, oldState, newState, instant):
        global firstFrame
        global globalExportSettings
        if newState == vray.RENDERER_STATE_IDLE_FRAME_DONE:
            renderer.export("export.vrscene", globalExportSettings)
            print("Frame", renderer.frame, "exported")
 
            if firstFrame:
                globalExportSettings["incremental"] = True
                firstFrame = False
 
            renderer.continueSequence()
 
    renderer.setOnStateChanged(stateChanged)
    # Load scene from a file.
    renderer.load(os.path.join(SCENE_PATH, "animation.vrscene"))
    # Maximum paths per pixel for interactive mode. Set a low sample level to complete rendering faster.
    renderer.setInteractiveSampleLevel(5)
 
    # Export just the plugins associated with the cube.
    settings = {}
    settings["pluginExportList"] = [
        renderer.plugins['pCubeShape1@node'],
        renderer.plugins['pCubeShape1@mesh5'],
        renderer.plugins['VRayMtl1@material'],
        renderer.plugins['VRayMtl1@diffuse']]
 
    renderer.export("export_cube.vrscene", settings)
 
    # Start the sequence.
    renderer.renderSequence()
    # Wait for the renderer to finish.
    renderer.waitForSequenceEnd()
#define VRAY_RUNTIME_LOAD_PRIMARY
#include "vraysdk.hpp"
#include "vrayplugins.hpp"
#include "utils.h"
 
using namespace VRay;
using namespace VRay::Plugins;
using namespace std;
 
const char *BASE_PATH = getenv("VRAY_SDK");
string SCENE_PATH = (BASE_PATH ? string(BASE_PATH) : string(".")) + PATH_DELIMITER + "scenes";
 
VRayExportSettings globalExportSettings;
 
void stateChanged(VRayRenderer &renderer, RendererState oldState, RendererState newState, double instant, void* data){
if (newState == RendererState::IDLE_FRAME_DONE) {
static bool firstFrame = true;
// Export the current frame
renderer.exportScene("export.vrscene", globalExportSettings);
printf("Frame %d exported\
", renderer.getCurrentFrame());
// Turn the incremental option on to append each frame to the same file.
if (firstFrame) {
globalExportSettings.incremental = true;
firstFrame = false;
}
renderer.continueSequence();
}
}
 
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.
// The renderer is automatically closed at the end of the current scope.
VRayRenderer renderer;
// It's recommended to always have a console log
renderer.setOnLogMessage(logMessage);
// Enable compression of large data arrays.
globalExportSettings.hexArrays = true;
globalExportSettings.compressed = true;
// Keep transforms in human readable format
globalExportSettings.hexTransforms = false;
// Print header to the export file
globalExportSettings.printHeader = true;
// Export only the current frame.
globalExportSettings.currentFrameOnly = true;
// Keep incremental off for the first frame so all plugins are exported properly.
globalExportSettings.incremental = false;
// Separate the views and nodes in different files
SubFileInfo views = { "view", "view" };
globalExportSettings.subFileInfos.push_back(views);
SubFileInfo nodes = { "nodes", "nodes" };
globalExportSettings.subFileInfos.push_back(nodes);
renderer.setOnStateChanged(stateChanged);
// Load scene from a file.
renderer.load("animation.vrscene");
// Maximum paths per pixel for interactive mode. Set a low sample level to complete rendering faster.
renderer.setInteractiveSampleLevel(5);
 
// Export just the plugins associated with the cube.
VRayExportSettings settings;
settings.pluginExportList.push_back(renderer.getPlugin("pCubeShape1@node"));
settings.pluginExportList.push_back(renderer.getPlugin("pCubeShape1@mesh5"));
settings.pluginExportList.push_back(renderer.getPlugin("VRayMtl1@material"));
settings.pluginExportList.push_back(renderer.getPlugin("VRayMtl1@diffuse"));
 
renderer.exportScene("export_cube.vrscene", settings);
 
// Start the sequence.
renderer.renderSequence();
// Wait for the renderer to finish.
renderer.waitForSequenceEnd();
return 0;
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VRay;
 
class Program
{
static void Main(string[] args)
{
string SCENE_PATH = Path.Combine(Environment.GetEnvironmentVariable("VRAY_SDK"), "scenes");
ExportSettings globalExportSettings = new ExportSettings();
// 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));
}
});
 
// Enable compression of large data arrays.
globalExportSettings.HexArrays = true;
globalExportSettings.Compressed = true;
// Keep transforms in human readable format
globalExportSettings.HexTransforms = false;
// Print header to the export file
globalExportSettings.PrintHeader = true;
// Export only the current frame.
globalExportSettings.CurrentFrameOnly = true;
// Keep incremental off for the first frame so all plugins are exporeted properly.
globalExportSettings.Incremental = false;
// Separate the views and nodes in different files
SubFileInfo views = new SubFileInfo(SubFileInfo.PluginType.View, "views");
globalExportSettings.AddSubFileInfo(views);
SubFileInfo nodes = new SubFileInfo(SubFileInfo.PluginType.Node, "nodes");
globalExportSettings.AddSubFileInfo(nodes);
 
bool firstFrame = true;
renderer.StateChanged += new EventHandler<StateChangedEventArgs>((source, e) =>
{
if(e.NewState == VRayRenderer.RendererState.IDLE_FRAME_DONE)
{
// Export the current frame
renderer.Export("export.vrscene", globalExportSettings);
Console.WriteLine("Frame {0} exported\
", renderer.Frame);
 
// Turn the incremental option on to append each frame to the same file.
if (firstFrame)
{
globalExportSettings.Incremental = true;
firstFrame = false;
}
renderer.ContinueSequence();
}
});
 
// Load scene from a file.
renderer.Load("animation.vrscene");
// Maximum paths per pixel for interactive mode. Set a low sample level to complete rendering faster.
renderer.SetInteractiveSampleLevel(5);
 
// Export just the plugins associated with the cube.
ExportSettings settings = new ExportSettings();
settings.PluginExportList.Add(renderer.GetPlugin("pCubeShape1@node"));
settings.PluginExportList.Add(renderer.GetPlugin("pCubeShape1@mesh5"));
settings.PluginExportList.Add(renderer.GetPlugin("VRayMtl1@material"));
settings.PluginExportList.Add(renderer.GetPlugin("VRayMtl1@diffuse"));
 
renderer.Export("export_cube.vrscene", settings);
 
// Start the sequence.
renderer.RenderSequence();
// Wait for the renderer to finish.
renderer.WaitForSequenceEnd();
}
}
}
var path = require("path");
var vray = require(path.join(process.env.VRAY_SDK, "node", "vray"));
 
var SCENE_PATH = path.join(process.env.VRAY_SDK, "scenes");
// 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);
});
 
var globalExportSettings = {};
// Enable compression of large data arrays.
globalExportSettings.hexArrays = true;
globalExportSettings.compressed = true;
// Keep transforms in human readable format
globalExportSettings.hexTransforms = false;
// Print header to the export file
globalExportSettings.printHeader = true;
// Export only the current frame.
globalExportSettings.currentFrameOnly = true;
// Keep incremental off for the first frame so all plugins are exporeted properly.
globalExportSettings.incremental = false;
// Separate the views and nodes in different files
var viewSubFileInfo = {type: "view", suffix: "view"};
var nodeSubFileInfo = {type: "nodes", suffix: "nodes"};
globalExportSettings.subFileInfos = [viewSubFileInfo, nodeSubFileInfo];
 
var firstFrame = true;
renderer.on("stateChanged", function(oldState, newState, instant) {
if (newState == 'idleFrameDone') {
// Export the current frame
renderer.export("export.vrscene", globalExportSettings, function(err) {
if (err) throw err;
console.log("Frame ", renderer.frame, " exported");
 
if(firstFrame) {
globalExportSettings.incremental = true;
firstFrame = false;
}
renderer.continueSequence();
});
}
});
 
// Load scene from a file.
renderer.load("animation.vrscene", function(err){
if (err) throw err;
// Maximum paths per pixel for interactive mode. Set a low sample level to complete rendering faster.
renderer.setInteractiveSampleLevel(5);
// Export just the plugins associated with the cube.
var settings = {};
settings.pluginExportList = [
renderer.plugins["pCubeShape1@node"],
renderer.plugins["pCubeShape1@mesh5"],
renderer.plugins["VRayMtl1@material"],
renderer.plugins["VRayMtl1@diffuse"]];
 
renderer.export("export_cube.vrscene", settings, function(err){
if (err) throw err;
// Start the sequence.
renderer.renderSequence();
 
// Wait for the renderer to finish.
renderer.waitForSequenceEnd(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();
});
});
});

V-Ray Sahne Dosyaları Sürüm 2 #


V-Ray 6.1 ile birlikte, .vrscene formatının yeni bir sürümü kullanıma sunulmuştur. Yeni sürüm 2  .vrscene  formatı daha küçük boyutludur ve daha verimli yükleme için optimize edilmiştir. Dışa aktarıldığı makineden farklı bir makinede render işlemini kolaylaştırmayı amaçlayan özelliklere sahiptir. Sürüm 1 formatı yalnızca .vrscene dosyasını içerir. Bir sürüm 2 sahnesi, en az üç dosyaya sahip olmasıyla sürüm 1’den farklıdır: bir  .vrscene , bir  .vrdata  ve bir  .vrfiles  dosyası.

V-Ray sahneleri, sahnedeki tüm gerekli varlıklara sahip olmayabilecek farklı makineler arasında dağıtılıyorsa veya bir render işlemi Chaos Cloud’a gönderiliyorsa, Chaos Cloud İstemcisinin pack komutuna benzer bir işlevsellik faydalı olacaktır.

Sürüm 2 .vrscene dosyasını yardımcı (sidecar) dosyalarıyla birlikte nasıl paketleyeceğinize dair ayrıntılı bir örnek examples/{language}/advanced/12-sidecar-scene-export adresinde mevcuttur.

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

Tarafından desteklenmektedir BetterDocs

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir