LightWrap++
AC++wrapperfortheLightWave3DSDK
nodes.h
Go to the documentation of this file.
1 #ifndef LWPP_NODES_H
2 #define LWPP_NODES_H
3 
4 #include <lwpp/global.h>
5 #include <lwpp/vparm.h>
6 #include <lwnodes.h>
7 
8 namespace lwpp
9 {
10  class NodeHandler;
11 
14  {
15  protected:
17  public:
22  virtual int operator()(LWItemID light, const LWDVector lightDir, const LWDVector lightColour ) = 0;
23  lwpp::Vector3d GetShading() const {return colour;}
24  void setValue(lwpp::NodeHandler *node, NodeValue value);
25  };
27 
37  int IlluminationSampler( void *data, LWItemID light, const LWDVector dir, const LWDVector color );
38 
39  extern const char inFuncs[];
40  extern const char inFuncs2[];
41 
43 
47  class LWNodeInput // : protected GlobalBase<LWNodeInputFuncs>
48  {
49  private:
50  LWNodeInputFuncs *globPtr;
51  NodeID node_id;
52  NodeInputID id;
53  bool do_destroy;
54 
55  int evaluate(LWNodalAccess*na, void* value )
56  {
57  return globPtr->evaluate(id, na, value);
58  }
59  void init();
60  public:
61  LWNodeInput(NodeID _id, ConnectionType type, const std::string name, NodeInputEvent* inp_event, bool _destroy = true)
62  : do_destroy(_destroy),
63  node_id(_id)
64  {
65  init();
66  id = globPtr->create(node_id, type, name.c_str(), inp_event);
67  }
68  LWNodeInput(NodeInputID _id, bool _destroy = false)
69  : do_destroy(_destroy),
70  node_id(0),
71  id(_id)
72  {
73  init();
74  }
75 
77  {
78  if (do_destroy) globPtr->destroy(node_id, id);
79  }
80 
81  NodeInputID getID(void) const {return id;}
82 
83  int evaluate(LWNodalAccess*na, LWDVector *value )
84  {
85  return evaluate(na, static_cast<void *>(value));
86  }
87 
88  int evaluate(LWNodalAccess*na, double *value )
89  {
90  return evaluate(na, static_cast<void *>(value));
91  }
92 
93  int evaluate(LWNodalAccess*na, lwpp::Vector3d &value )
94  {
95  return evaluate(na, static_cast<void *>(value.asLWVector()));
96  }
97 
98  int evaluate(LWNodalAccess*na, int *value )
99  {
100  return evaluate(na, static_cast<void *>(value));
101  }
102 
103  int evaluate(LWNodalAccess*na, bool *value )
104  {
105  int i = *value;
106  int ret = evaluate(na, &i);
107  *value = (i != 0);
108  return ret;
109  }
110 
111  int evaluate(LWNodalAccess*na, lwpp::VParm *vparm)
112  {
113  return evaluate(na, static_cast<void *>(vparm->asLWVector()));
114  }
115 
116  int evaluate(LWNodalAccess*na, LWNodalMaterial *mat)
117  {
118  return evaluate(na, static_cast<void *>(mat));
119  }
120 
121  /*
122  template<class T>
123  int evaluate(LWNodalAccess &na, T *value )
124  {
125  return evaluate(&na, value);
126  }
127  */
128 
129  bool check(void)
130  {
131  return (globPtr->check(id) != 0);
132  }
133  bool isConnected(void) {return check();}
134  NodeID node(void) {return globPtr->node(id);}
135  void disconnect (NodeID nid) {globPtr->disconnect(nid, id);}
136  NodeInputID next() {return globPtr->next(id);}
137  NodeInputID previous() {return globPtr->previous(id);}
138 
139  };
140 
141  typedef std::auto_ptr<LWNodeInput> auto_NodeInput;
142 
145  class LWNodeOutput: protected GlobalBase<LWNodeOutputFuncs>
146  {
147  private:
148  NodeID node_id;
149  NodeOutputID id;
150  bool do_destroy;
151 
152  public:
153  LWNodeOutput(NodeID _id, ConnectionType type, std::string name, bool _destroy = true)
154  : do_destroy(_destroy),
155  node_id(_id),
156  id(0)
157  {
158  id = globPtr->create(node_id, type, name.c_str());
159  }
160 
162  {
163  if (do_destroy) globPtr->destroy(node_id, id);
164  }
165  NodeID node(void) {return globPtr->node(id);}
166  NodeOutputID next(void) {return globPtr->next(id);}
167  NodeOutputID previous(void) {return globPtr->previous(id);}
168  NodeOutputID getID(void) const {return id;}
169  bool isID(const NodeOutputID _id) const {return id == _id;}
170  };
171 
172  typedef std::auto_ptr<LWNodeOutput> auto_NodeOutput;
173 
175  {
176 
177  virtual LWNodeInput *addInput(ConnectionType type, const std::string name, NodeInputEvent* inp_event) = 0;
178  public:
183  LWNodeInput *addColorInput(const std::string name ="Color", NodeInputEvent* inp_event = 0)
184  {
185  return addInput(NOT_COLOR, name, inp_event);
186  }
187  LWNodeInput *addColourInput(const std::string name = "Colour", NodeInputEvent* inp_event = 0)
188  {
189  return addColorInput(name, inp_event);
190  }
191  LWNodeInput *addScalarInput(const std::string name = "Scalar", NodeInputEvent* inp_event = 0)
192  {
193  return addInput(NOT_SCALAR, name, inp_event);
194  }
195  LWNodeInput *addVectorInput(const std::string name = "Vector", NodeInputEvent* inp_event = 0)
196  {
197  return addInput(NOT_VECTOR, name, inp_event);
198  }
199  LWNodeInput *addIntegerInput(const std::string name = "Integer", NodeInputEvent* inp_event = 0)
200  {
201  return addInput(NOT_INTEGER, name, inp_event);
202  }
203  LWNodeInput *addFunctionInput(const std::string name = "Function", NodeInputEvent* inp_event = 0)
204  {
205  return addInput(NOT_FUNCTION, name, inp_event);
206  }
207  LWNodeInput *addMaterialInput(const std::string name = "Material", NodeInputEvent* inp_event = 0)
208  {
209  return addInput(NOT_MATERIAL, name, inp_event);
210  }
212  };
213 
216  class LWNode : private GlobalBase<LWNodeFuncs>, public NodeInputHelper
217  {
218  private:
219  NodeID id;
220  LWNodeInputFuncs *inF;
222 
223  virtual LWNodeInput *addInput(ConnectionType type, const std::string name, NodeInputEvent* inp_event)
224  {
225  return new LWNodeInput(id, type, name.c_str(), inp_event);
226  }
227 
228  LWNodeOutput *addOutput(ConnectionType type, const std::string name)
229  {
230  return new LWNodeOutput(id, type, name.c_str());
231  }
232  void setValue( NodeValue val, void *v) {outF->setValue(val, v);}
233  void disconnect (NodeInputID nid) {inF->disconnect(id, nid);}
234 
235  public:
236  LWNode(NodeID _id = 0);
237  virtual ~LWNode();
238 
239  void setID(NodeID _id) {id = _id;}
240  NodeID getID(void) {return id;}
241 
242  const char *nodeName() {return globPtr->nodeName(id);}
243  const char *serverUserName() {return globPtr->serverUserName(id);}
244  LWChanGroupID chanGrp() {return globPtr->chanGrp(id);}
245 
247  void setNodeColor(int col[3]) {globPtr->setNodeColor(id, col);}
249  void setNodeColor(int r, int g, int b) {globPtr->setNodeColor3(id, r, g, b);}
250 
251  void setNodePreviewType(NodePreviewType type) {globPtr->setNodePreviewType(id, type);}
252 
254  void UpdateNodePreview() {globPtr->UpdateNodePreview(id);}
255 
256  NodeInputID firstInput(void) {return inF->first(id);}
257  int numInputs(void) {return inF->numInputs(id);}
258  NodeInputID inputByIndex (int n ) {return inF->byIndex(id, n);}
259  int inputGetIndex (NodeInputID nid) {return inF->getIndex(id, nid);}
260 
261  void disconnect (LWNodeInput *nid) {inF->disconnect(id, nid->getID());}
262 
267  LWNodeOutput *addColorOutput(const std::string name ="Color")
268  {
269  return addOutput(NOT_COLOR, name);
270  }
271  LWNodeOutput *addColourOutput(const std::string name = "Colour")
272  {
273  return addColorOutput(name);
274  }
275  LWNodeOutput *addScalarOutput(const std::string name ="Scalar")
276  {
277  return addOutput(NOT_SCALAR, name);
278  }
279  LWNodeOutput *addVectorOutput(const std::string name ="Vector")
280  {
281  return addOutput(NOT_VECTOR, name);
282  }
283  LWNodeOutput *addIntegerOutput(const std::string name ="Integer")
284  {
285  return addOutput(NOT_INTEGER, name);
286  }
287  LWNodeOutput *addFunctionOutput(const std::string name ="Function")
288  {
289  return addOutput(NOT_FUNCTION, name);
290  }
291  LWNodeOutput *addMaterialOutput(const std::string name = "Material")
292  {
293  return addOutput(NOT_MATERIAL, name);
294  }
295  // @}
300  auto_NodeOutput autoColorOutput(const std::string name ="Color")
301  {
302  return auto_NodeOutput(addOutput(NOT_COLOR, name));
303  }
304  auto_NodeOutput autoColourOutput(const std::string name = "Colour")
305  {
306  return auto_NodeOutput(addColorOutput(name));
307  }
308  auto_NodeOutput autoScalarOutput(const std::string name ="Scalar")
309  {
310  return auto_NodeOutput(addOutput(NOT_SCALAR, name));
311  }
312  auto_NodeOutput autoVectorOutput(const std::string name ="Vector")
313  {
314  return auto_NodeOutput(addOutput(NOT_VECTOR, name));
315  }
316  auto_NodeOutput autoIntegerOutput(const std::string name ="Integer")
317  {
318  return auto_NodeOutput(addOutput(NOT_INTEGER, name));
319  }
320  auto_NodeOutput autoFunctionOutput(const std::string name ="Function")
321  {
322  return auto_NodeOutput(addOutput(NOT_FUNCTION, name));
323  }
324  auto_NodeOutput autoMaterialOutput(const std::string name = "Material")
325  {
326  return auto_NodeOutput(addOutput(NOT_MATERIAL, name));
327  }
328  // @}
329 
330  NodeOutputID firstOutput(void) {return outF->first(id);}
331  int numOutputs(void) {return outF->numInputs(id);}
332  NodeOutputID outputByIndex (int n ) {return outF->byIndex(id, n);}
333  int outputGetIndex (NodeOutputID nid) {return outF->getIndex(id, nid);}
334 
335  ConnectionType getType( NodeValue val) {return outF->getType(val);}
340  void setValue(NodeValue val, double *v)
341  {
342  setValue(val, static_cast<void *>(v));
343  }
344  void setValue(NodeValue val, LWDVector *v)
345  {
346  setValue(val, static_cast<void *>(v));
347  }
348  void setValue(NodeValue val, double a, double b, double c)
349  {
350  double v[3];
351  v[0] = a;
352  v[1] = b;
353  v[2] = c;
354  setValue(val, static_cast<void *>(v));
355  }
356  void setValue(NodeValue val, float v[3])
357  {
358  setValue(val, static_cast<double>(v[0]), static_cast<double>(v[1]), static_cast<double>(v[2]));
359  }
360 
361  void setValue(NodeValue val, float v)
362  {
363  double d = v;
364  setValue(val, &d);
365  }
366 
367  void setValue(NodeValue val, double v)
368  {
369  setValue(val, &v);
370  }
371 
372 
373  void setValue(NodeValue val, int *v)
374  {
375  setValue(val, static_cast<void *>(v));
376  }
377 
378  void setValue(NodeValue val, unsigned int *v)
379  {
380  unsigned int i = *v;
381  setValue(val, static_cast<void *>(&i));
382  }
383 
384  void setValue(NodeValue val, bool v)
385  {
386  int i = v;
387  setValue(val, static_cast<void *>(&i));
388  }
389 
390  void setValue(NodeValue val, LWNodalMaterial *material)
391  {
392  setValue(val, static_cast<void *>(material));
393  }
394 
395  void setValue(NodeValue val, Vector3d &v)
396  {
397  setValue(val, v.asLWVector());
398  }
400 
401  void *getValue( NodeValue val) {return outF->getValue(val);}
402  };
403 
406  class LWNodeUtility : protected GlobalBase<LWNodeUtilityFuncs>
407  {
408  public:
410  {;}
411  static void Blend ( LWDVector result, LWDVector bg, LWDVector fg, double alpha, BlendingMode mode)
412  {
413  globPtr->Blend(result, bg, fg, alpha, mode);
414  }
415  static void NodeAutosize( NodeID id, LWDVector scale, LWDVector position )
416  {
417  globPtr->NodeAutosize(id, scale, position);
418  }
419  };
420 
421 /*
422 typedef struct LWNodeUtilityFuncs_t {
423 
424  void (*PlanarMapping)( LWDVector tPos, int axis, double *u, double *v );
425  void (*SphericalMapping)( LWDVector tPos, int axis, double *u, double *v );
426  void (*CylindricalMapping)( LWDVector tPos, int axis, double *u, double *v );
427  void (*CubicMapping)( LWDVector tPos, int axis, double *u, double *v );
428  // The axis for cubic mapping is the major axis the surface normal points to.
429  void (*FrontMapping)( LWDVector tPos, double pixelAspect, double *u, double *v, double cameraMatrix[4][4] );
430  void (*ReflectionMapping)( double seamAngle, LWDVector direction, double *u, double *v );
431  int (*UVMapping)( const char* UVMapName, LWNodalAccess*, double *u, double *v );
432  // Returns true if succesful.
433  void (*BuildCameraMatrix)( LWTime time, LWItemId cameraID, double cameraMatrix[4][4] );
434  // Build the transformation matrix for front projection mapping to use.
435 
436 } LWNodeUtilityFuncs;
437 */
438 
439 }
440 
441 #endif // LWPP_NODES_H