# 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(os.environ.get('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)
# Load scene from a file.
renderer.load(os.path.join(SCENE_PATH, 'cornell_new.vrscene'))
# A reference to the Node plugin of one of the spheres in the scene
sphereNode = renderer.plugins['Sphere0Shape2@node']
# Create a GeomHair plugin
# It References another mesh plugin (usually GeomStaticMesh) and generates hair (can be tweaked for fur, grass, shaggy rug etc.) on it.
# Has many parameters for the size, shape and distribution of strands.
hairMesh = renderer.classes.GeomHair()
hairMesh.mesh = sphereNode.geometry # Attach a geometry to the hair
hairMesh.length_base = 20 # The base hair length.
hairMesh.length_var = 5 # The hair length variation.
hairMesh.thickness_base = 0.2 # The base hair thickness.
hairMesh.thickness_var = 0.1 # The hair thickness variation.
hairMesh.curl_enabled = True # Apply curl to the hair
hairMesh.curl_radius_var = 20 # The curl radius variation.
hairMesh.curl_angle = 20 # The angle of the curl applied at each knot. (degrees)
hairMesh.hair_knots = 20 # Number of segments along the length of a single hair.
hairMesh.bend = 0.25 # The amount of hair bending. (relative)
hairMesh.perFace = 20 # Number of hairs per face with the default distribution value
hairMesh.gravity_vector = vray.Vector(0.0, 0.0, -1.0) # The gravity force direction vector.
# Create a new hair BRDF plugin instance and set several parameters.
hairBrdf = renderer.classes.BRDFHair3()
hairBrdf.diffuse_color = vray.AColor(0.1, 0.05, 0.025, 1)
hairBrdf.primary_specular = vray.AColor(0.7, 0.6, 0.5, 1)
hairBrdf.secondary_specular = vray.AColor(0.3, 0.2, 0.1, 1)
hairBrdf.transmission = vray.AColor(0.3, 0.2, 0.1, 1)
hairBrdf.transmission_glossiness_length = 0.5
hairBrdf.transmission_glossiness_width = 0.5
# Create a new material plugin instance using the hair BRDF.
hairMaterial = renderer.classes.MtlSingleBRDF()
hairMaterial.brdf = hairBrdf
# Create a node for the GeomHair
hairNode = renderer.classes.Node()
# The GeomHair should be attached just as a usual geometry to the node
hairNode.geometry = hairMesh
hairNode.material = hairMaterial
hairNode.transform = sphereNode.transform
# Start rendering.
renderer.startSync()
# Wait for rendering to end.
renderer.waitForRenderEnd() |
|
#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";
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);
// Load scene from a file.
renderer.load("cornell_new.vrscene");
// A reference to the Node plugin of one of the spheres in the scene
Node sphereNode = renderer.getPlugin<Node>("Sphere0Shape2@node");
// Create a GeomHair plugin
// It References another mesh plugin (usually GeomStaticMesh) and generates hair (can be tweaked for fur, grass, shaggy rug etc.) on it.
// Has many parameters for the size, shape and distribution of strands.
GeomHair hairMesh = renderer.newPlugin<GeomHair>();
hairMesh.set_mesh(sphereNode.get_geometry()); // Attach a geometry to the hair
hairMesh.set_length_base(20); // The base hair length.
hairMesh.set_length_var(5); // The hair length variation.
hairMesh.set_thickness_base(0.2f); // The base hair thickness.
hairMesh.set_thickness_var(0.1f); // The hair thickness variation.
hairMesh.set_curl_enabled(true); // Apply curl to the hair
hairMesh.set_curl_radius_var(20); // The curl radius variation.
hairMesh.set_curl_angle(20); // The angle of the curl applied at each knot. (degrees)
hairMesh.set_hair_knots(20); // Number of segments along the length of a single hair.
hairMesh.set_bend(0.25f); // The amount of hair bending. (relative)
hairMesh.set_perFace(20); // Number of hairs per face with the default distribution value
hairMesh.set_gravity_vector(Vector(0.0, 0.0, -1.0)); // The gravity force direction vector.
// Create a new hair BRDF plugin instance and set several parameters.
BRDFHair3 hairBrdf = renderer.newPlugin<BRDFHair3>();
hairBrdf.set_diffuse_color(AColor(0.1, 0.05, 0.025, 1));
hairBrdf.set_primary_specular(AColor(0.7, 0.6, 0.5, 1));
hairBrdf.set_secondary_specular(AColor(0.3, 0.2, 0.1, 1));
hairBrdf.set_transmission(AColor(0.3, 0.2, 0.1, 1));
hairBrdf.set_transmission_glossiness_length(0.5);
hairBrdf.set_transmission_glossiness_width(0.5);
// Create a new material plugin instance using the hair BRDF.
MtlSingleBRDF hairMaterial = renderer.newPlugin<MtlSingleBRDF>();
hairMaterial.set_brdf(hairBrdf);
// Create a node for the GeomHair
Node hairNode = renderer.newPlugin<Node>();
// The GeomHair should be attached just as a usual geometry to the node
hairNode.set_geometry(hairMesh);
hairNode.set_material(hairMaterial);
hairNode.set_transform(sphereNode.get_transform());
// Start rendering.
renderer.startSync();
// Wait for rendering to end.
renderer.waitForRenderEnd();
return 0;
} |
|
using System;
using System.IO;
using VRay;
using VRay.Plugins;
namespace _geom_hair
{
class Program
{
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("cornell_new.vrscene");
// A reference to the Node plugin of one of the spheres in the scene
Node sphereNode = renderer.GetPlugin<Node>("Sphere0Shape2@node");
// Create a GeomHair plugin
// It References another mesh plugin (usually GeomStaticMesh) and generates hair (can be tweaked for fur, grass, shaggy rug etc.) on it.
// Has many parameters for the size, shape and distribution of strands.
GeomHair hairMesh = renderer.NewPlugin<GeomHair>();
hairMesh.Mesh = sphereNode.Geometry; // Attach a geometry to the hair
hairMesh.LengthBase = 20; // The base hair length.
hairMesh.LengthVar = 5; // The hair length variation.
hairMesh.ThicknessBase = 0.2f; // The base hair thickness.
hairMesh.ThicknessVar = 0.1f; // The hair thickness variation.
hairMesh.CurlEnabled = true; // Apply curl to the hair
hairMesh.CurlRadiusVar = 20; // The curl radius variation.
hairMesh.CurlAngle = 20; // The angle of the curl applied at each knot. (degrees)
hairMesh.HairKnots = 20; // Number of segments along the length of a single hair.
hairMesh.Bend = 0.25f; // The amount of hair bending. (relative)
hairMesh.PerFace = 20; // Number of hairs per face with the default distribution value
hairMesh.GravityVector = new Vector(0.0, 0.0, -1.0); // The gravity force direction vector.
// Create a new hair BRDF plugin instance and set several parameters.
BRDFHair3 hairBrdf = renderer.NewPlugin<BRDFHair3>();
hairBrdf.DiffuseColor = new AColor(0.1, 0.05, 0.025, 1);
hairBrdf.PrimarySpecular = new AColor(0.7, 0.6, 0.5, 1);
hairBrdf.SecondarySpecular = new AColor(0.3, 0.2, 0.1, 1);
hairBrdf.Transmission = new AColor(0.3, 0.2, 0.1, 1);
hairBrdf.TransmissionGlossinessLength = 0.5;
hairBrdf.TransmissionGlossinessWidth = 0.5;
// Create a new material plugin instance using the hair BRDF.
MtlSingleBRDF hairMaterial = renderer.NewPlugin<MtlSingleBRDF>();
hairMaterial.Brdf = hairBrdf;
// Create a node for the GeomHair
Node hairNode = renderer.NewPlugin<Node>();
// The GeomHair should be attached just as a usual geometry to the node
hairNode.Geometry = hairMesh;
hairNode.Material = hairMaterial;
hairNode.Transform = sphereNode.Transform;
// Start rendering.
renderer.StartSync();
// Wait for rendering to end.
renderer.WaitForRenderEnd();
}
}
}
} |
|
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);
});
// Load scene from a file asynchronously.
renderer.load("cornell_new.vrscene", function(err) {
if (err) throw err;
// A reference to the Node plugin of one of the spheres in the scene
var sphereNode = renderer.plugins["Sphere0Shape2@node"];
// Create a GeomHair plugin
// It References another mesh plugin (usually GeomStaticMesh) and generates hair (can be tweaked for fur, grass, shaggy rug etc.) on it.
// Has many parameters for the size, shape and distribution of strands.
var hairMesh = renderer.classes.GeomHair();
hairMesh.mesh = sphereNode.geometry; // Attach a geometry to the hair
hairMesh.length_base = 20; // The base hair length.
hairMesh.length_var = 5; // The hair length variation.
hairMesh.thickness_base = 0.2; // The base hair thickness.
hairMesh.thickness_var = 0.1; // The hair thickness variation.
hairMesh.curl_enabled = true; // Apply curl to the hair
hairMesh.curl_radius_var = 20; // The curl radius variation.
hairMesh.curl_angle = 20; // The angle of the curl applied at each knot. (degrees)
hairMesh.hair_knots = 20; // Number of segments along the length of a single hair.
hairMesh.bend = 0.25; // The amount of hair bending. (relative)
hairMesh.perFace = 20; // Number of hairs per face with the default distribution value
hairMesh.gravity_vector = vray.Vector(0.0, 0.0, -1.0); // The gravity force direction vector.
// Create a new hair BRDF plugin instance and set several parameters.
var hairBrdf = renderer.classes.BRDFHair3();
hairBrdf.diffuse_color = vray.AColor(0.1, 0.05, 0.025, 1);
hairBrdf.primary_specular = vray.AColor(0.7, 0.6, 0.5, 1);
hairBrdf.secondary_specular = vray.AColor(0.3, 0.2, 0.1, 1);
hairBrdf.transmission = vray.AColor(0.3, 0.2, 0.1, 1);
hairBrdf.transmission_glossiness_length = 0.5;
hairBrdf.transmission_glossiness_width = 0.5;
// Create a new material plugin instance using the hair BRDF.
var hairMaterial = renderer.classes.MtlSingleBRDF();
hairMaterial.brdf = hairBrdf;
// Create a node for the GeomHair
var hairNode = renderer.classes.Node();
// The GeomHair should be attached just as a usual geometry to the node
hairNode.geometry = hairMesh;
hairNode.material = hairMaterial;
hairNode.transform = sphereNode.transform;
// Start rendering.
renderer.start(function(err) {
if (err) throw err;
// Wait for rendering to end.
renderer.waitForRenderEnd(function() {
// Closes the renderer.
renderer.close();
});
});
}); |
|
|