Versions Compared

Key

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

...

Code Block
languagecpp
themeMidnight
/** Turn our mesh into a subdivision surface */
nsi.SetAttribute( "simple polygon",
	NSI::CStringPArg("subdivision.scheme", "catmull-clark") );

...


Transforming Geometry

In NSI, a geometry is only considered if connected to the scene root (which has the special handle ".root"). It is possible to directly connect a geometry node (such as the simple polygon above) to scene's root but it wouldn't be very useful. It is common to place geometry using a transform and NSI has a special node for it.

Code Block
languagecpp
themeMidnight
nsi.Create( "translation", "transform" );
nsi.Connect( "translation", NSI_SCENE_ROOT );
nsi.Connect( "simple polygon", "", "translation", "objects" );

double trs[16] =
{
	1., 0., 0., 0.,
	0., 1., 0., 0.,
	0., 0., 1., 0.,
	0., 1., 0., 1. /* transalte 1 unit in Y */
};

nsi.SetAttribute( "translation",
	NSI::DoubleMatrixArg("transformationmatrix", trs) );


Assigning Shaders

Shaders are created as any other nodes using the NSICreate API call. They are not assigned directly on geometry but through an intermediate attributes nodes. Having an extra indirection allows for more flexible export as we will see in the following chapters.

Code Block
languagecpp
themeMidnight
/**
	Create a simple shader node using the standard OSL "emitter" shader.
	Set it's parameter to something different than defaults.
*/
nsi.Create( "simpleshader", "shader" );
float red[3] = {1,0,0};
nsi.SetAttribute( "simpleshader",
	(
		NSI::CStringPArg("shaderfilename", "emitter"),
		NSI::ColorArg( "Cs", red),
		NSI::FloatArg( "power", 4.f )
	) );

/** Create an attributes nodes and connect our shader to it */
nsi.Create( "attr", "attributes" );
nsi.Connect( "simpleshader", "", "attr", "surfaceshader" );

/* Connecting the attributes node to the mesh assign completes the assignment */
nsi.Connect( "attr", "", "simple mesh", "geometryattributes" );

...