HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RAY_DemoBox.C
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  * This is a sample procedural DSO
27  */
28 
29 #include <UT/UT_DSOVersion.h>
30 #include <GU/GU_Detail.h>
31 #include "RAY_DemoBox.h"
33 
34 using namespace HDK_Sample;
35 
36 static RAY_ProceduralArg theArgs[] = {
37  // Default minimum bound is {-1,-1,-1}
38  RAY_ProceduralArg("minbound", "real", "-1 -1 -1"),
39  // Default maximum bound is {1,1,1}
40  RAY_ProceduralArg("maxbound", "real", "1 1 1"),
42 };
43 
45 {
46 public:
48  : RAY_ProceduralFactory::ProcDefinition("demobox")
49  {
50  }
51  virtual RAY_Procedural *create() const { return new RAY_DemoBox(); }
52  virtual RAY_ProceduralArg *arguments() const { return theArgs; }
53 };
54 
55 void
57 {
58  factory->insert(new ProcDef);
59 }
60 
62 {
63  myBox.initBounds(0, 0, 0);
64 }
65 
67 {
68 }
69 
70 const char *
72 {
73  return "RAY_DemoBox";
74 }
75 
76 int
78 {
79  fpreal val[3];
80 
81  // Import the minbound parameter. This will pick up parameters passed on
82  // the procedural line in the IFD, or the default value from the
83  // RAY_ProceduralArg.
84  val[0] = val[1] = val[2] = -1;
85  import("minbound", val, 3);
86  myBox.initBounds(val[0], val[1], val[2]);
87 
88  val[0] = val[1] = val[2] = 1;
89  import("maxbound", val, 3);
90  myBox.enlargeBounds(val[0], val[1], val[2]);
91 
92  // The bounding box has been initialized. The geometry generated must like
93  // within the bounds.
94  return 1;
95 }
96 
97 void
99 {
100  // Return the bounding box of the geometry
101  box = myBox;
102 }
103 
104 void
106 {
107  /// Allocate geometry.
108  /// NOTE: Do not simply construct a GU_Detail.
109  /// @see RAY_Procedural::createGeometry().
111 
112  /// Call the GU_Detail::cube() method to create a cube
113  geo->cube(myBox.vals[0][0], myBox.vals[0][1],
114  myBox.vals[1][0], myBox.vals[1][1],
115  myBox.vals[2][0], myBox.vals[2][1]);
116 
117  // Create a geometry object in mantra
119  obj->addGeometry(geo);
120  // Change the surface shader setting
121  obj->changeSetting("surface", "constant Cd ( 1 0 0 )", "object");
122 }
RAY_ProceduralGeo createGeometry() const
Allocate geometry for this procedural.
virtual int initialize(const UT_BoundingBox *)
Definition: RAY_DemoBox.C:77
Procedural primitive for mantra (RAY)
bool insert(ProcDefinition *def, bool replace_existing=true)
virtual void getBoundingBox(UT_BoundingBox &box)
The bounding box is the "object space" bounds of the procedural.
Definition: RAY_DemoBox.C:98
RAY_ProceduralChildPtr createChild() const
void enlargeBounds(const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
Parameter definition for arguments to RAY_Procedural.
virtual RAY_ProceduralArg * arguments() const
Provide a const reference to the arguments for the procedural.
Definition: RAY_DemoBox.C:52
double fpreal
Definition: SYS_Types.h:270
GU_PrimPoly * cube(float xmin=-1, float xmax=1, float ymin=-1, float ymax=1, float zmin=-1, float zmax=1, int xdiv=0, int ydiv=0, int zdiv=0, int enforcementBars=0, int doConsolidatePoints=0)
A very simple mantra procedural to render a box.
Definition: RAY_DemoBox.h:38
GLuint GLfloat * val
Definition: glcorearb.h:1607
SYS_FORCE_INLINE void initBounds()
virtual const char * className() const
Definition: RAY_DemoBox.C:71
void registerProcedural(RAY_ProceduralFactory *factory)
Modern interface to register procedurals.
Definition: RAY_DemoBox.C:56
virtual void render()
Definition: RAY_DemoBox.C:105
virtual RAY_Procedural * create() const
Create a procedural, and pass ownership of the instance to mantra.
Definition: RAY_DemoBox.C:51
Class to create a procedural.