Getting started with NSI

Discussions about 3Delight and the Open Shading Language.

Filip
Member
Posts: 108
Joined: Thu Jun 05, 2008 2:07 am
Location: Sweden

Getting started with NSI

Postby Filip » Tue Jun 20, 2017 6:09 am

Hi!
I have started experimenting with building scenes in NSI, trying to create a minimal working example. The C++ example below compiles fine, but when I run it I get this error message:

Code: Select all

3DL ERROR E6025 outputlayer node 'layer' is missing required attributes
3DL ERROR E6029 no image will be rendered because no cameras have been provided


I have tried to fill all attributes of the outputlayer node, and I believe that my camera node should be connected to the root.

Any suggestions on what I am doing wrong?

Thanks
/Filip

Code: Select all

#include "nsi.hpp"

int main() {

   NSI::Context ctx;

   ctx.Create("cam", "perspectivecamera");
   ctx.Create("cam_transform", "transform");
   ctx.Create("layer", "outputlayer", (
            NSI::StringArg("variablename", "Ci"),
            NSI::StringArg("layername", "test"),
            NSI::StringArg("layertype", "color"),
            NSI::StringArg("variablesource", "shader"),
            NSI::StringArg("scalarformat", "uint8"),
            NSI::IntegerArg("sortkey",0),
            NSI::StringArg("filter", "gaussian")
      ));

   ctx.Create("driver", "outputdriver",(
         NSI::StringArg("drivername", "framebuffer"),
         NSI::StringArg("imagefilename", "test_output")
      ));

   ctx.Connect("driver", "", "layer", "outputdrivers");
   ctx.Connect("layer", "", "cam", "outputlayers");
   ctx.Connect("cam", "", "cam_transform", "objects");
   ctx.Connect("cam_transform", "", ".root", "objects");
   
   ctx.RenderControl(NSI::StringArg("action", "start"));

   return 0;
}

olivier
3Delight Developer
Posts: 2147
Joined: Tue Jan 09, 2007 1:27 pm

Re: Getting started with NSI

Postby olivier » Tue Jun 20, 2017 8:46 am

The arguments you give NSICreate() are not attributes for the node. They are meant to eventually give control over the behavior of create (eg. you might want it to erase an existing node first). For now, there are no supported parameters. You need to use NSISetAttribute() instead to set your layer and driver attributes.

Filip
Member
Posts: 108
Joined: Thu Jun 05, 2008 2:07 am
Location: Sweden

Re: Getting started with NSI

Postby Filip » Tue Jun 20, 2017 8:57 am

Thanks Olivier! Got it working now.

Here is the corrected code snippet, as a reference for other people getting started with NSI:

Code: Select all

#include "nsi.hpp"

int main() {

   NSI::Context ctx;

   ctx.Create("cam", "perspectivecamera");
   ctx.Create("cam_transform", "transform");
   ctx.Create("layer", "outputlayer");
   
   ctx.SetAttribute("layer",(
            NSI::StringArg("variablename", "Ci"),
            NSI::StringArg("layername", "test"),
            NSI::StringArg("layertype", "color"),
            NSI::StringArg("variablesource", "shader"),
            NSI::StringArg("scalarformat", "uint8"),
            NSI::IntegerArg("sortkey",0),
            NSI::StringArg("filter", "gaussian")
      ));



   ctx.Create("driver", "outputdriver");
   ctx.SetAttribute("driver", (
         NSI::StringArg("drivername", "idisplay"),
         NSI::StringArg("imagefilename", "test_output")
      ));

   ctx.Connect("driver", "", "layer", "outputdrivers");
   ctx.Connect("layer", "", "cam", "outputlayers");
   ctx.Connect("cam", "", "cam_transform", "objects");
   ctx.Connect("cam_transform", "", ".root", "objects");
   
   ctx.RenderControl(NSI::StringArg("action", "start"));

   return 0;
}

fleabay
Member
Posts: 35
Joined: Tue Mar 19, 2013 12:32 am

Re: Getting started with NSI

Postby fleabay » Thu Oct 19, 2017 7:07 am

I removed the 'action start' line as suggested in another thread and was able to compile and run this.

Can you tell me what this program does because I get no output or generated file.

Also looking for more examples. Trying to figure this out from the pdf has me questioning my intelligence.

Filip
Member
Posts: 108
Joined: Thu Jun 05, 2008 2:07 am
Location: Sweden

Re: Getting started with NSI

Postby Filip » Thu Oct 19, 2017 9:19 am

Hi Fleabay,
This program is just a minimal example, and there is no geometry defined in the scene. So if I recall correctly it should just open Idisplay but render nothing.

Any specific examples you would like to see? I have quite a lot of C++ code using the NSI API, but it is embedded as a plugin for a host application, so it is not that easy to extract complete, easy-to-read examples.

Best regards
/Filip

fleabay
Member
Posts: 35
Joined: Tue Mar 19, 2013 12:32 am

Re: Getting started with NSI

Postby fleabay » Fri Oct 20, 2017 4:03 pm

I've probably learned more about 3Delight in general from struggling with this than otherwise. I've set it aside for a few days but intend on making do with the information (or lack thereof) available. For sure I'll have a better assessment of the situation after I've put some more time into it. I hope you're not going anywhere though. ;)