HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RAY_DemoVolumeSphere.C
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024
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 to generate a volumetric sphere
27  */
28 
29 #include "RAY_DemoVolumeSphere.h"
30 #include <UT/UT_DSOVersion.h>
31 #include <UT/UT_Vector3.h>
32 #include <UT/UT_FloatArray.h>
33 #include <UT/UT_IntArray.h>
34 #include <UT/UT_Array.h>
35 #include <UT/UT_StringArray.h>
36 #include <VGEO/VGEO_Volume.h>
38 
39 //
40 // ray_VolumeSphere
41 //
42 
43 namespace HDK_Sample {
44 
45 /// @brief Volume primitive used by @ref RAY/RAY_DemoVolumeSphere.C
47 {
48 public:
49  float getNativeStepSize() const override { return 0.1F; }
51  float radius,
52  float dbound,
53  float zerothreshold) const override;
55  UT_IntArray &sizes) const override;
56  void evaluate(const UT_Vector3 &pos,
57  const UT_Filter &filter,
58  float radius, float time,
59  int idx, float *data) const override;
60  UT_Vector3 gradient(const UT_Vector3 &pos,
61  const UT_Filter &filter,
62  float radius, float time,
63  int idx) const override;
64 };
65 
66 }
67 
68 using namespace HDK_Sample;
69 
70 void
72  float,
73  float dbound,
74  float) const
75 {
76  // For this example, we simply create a single box which contains the unit
77  // sphere which. It's important to account for the displacement bound
78  // (dbound)
79  boxes.append(UT_BoundingBox(-1-dbound, -1-dbound, -1-dbound,
80  1+dbound, 1+dbound, 1+dbound));
81 }
82 
83 void
85  UT_IntArray &sizes) const
86 {
87  // These are the "VEX" variables we provide to shaders.
88  // "density[1]" represents the density of the sphere (1 inside, 0 outside)
89  // "radius[1]" is the distance from the origin
90  // Both are "float" types.
91  //
92  // The order in which they are added is used in the evaluate() method below
93  names.append("density");
94  sizes.append(1);
95  names.append("radius");
96  sizes.append(1);
97 }
98 
99 void
101  const UT_Filter &,
102  float, float,
103  int idx, float *data) const
104 {
105  switch (idx)
106  {
107  // 0 == "density"
108  case 0: data[0] = (pos.length2() < 1.0F) ? 1.0F : 0.0F; break;
109  // 1 == "radius"
110  case 1: data[0] = pos.length(); break;
111 
112  default: UT_ASSERT(0 && "Invalid attribute evaluation");
113  }
114 }
115 
118  const UT_Filter &,
119  float, float,
120  int) const
121 {
122  return UT_Vector3(0, 0, 0);
123 }
124 
125 //
126 // RAY_DemoVolumeSphere
127 //
129 {
130 public:
132  : RAY_ProceduralFactory::ProcDefinition("demovolume")
133  {
134  }
135  RAY_Procedural *create() const override
136  { return new RAY_DemoVolumeSphere(); }
137  RAY_ProceduralArg *arguments() const override { return nullptr; }
138 };
139 
140 void
142 {
143  factory->insert(new ProcDef);
144 }
145 
147 {
148 }
149 
151 {
152 }
153 
154 int
156 {
157  myBox = UT_BoundingBox(-1, -1, -1, 1, 1, 1);
158  if (box)
159  myBox.enlargeBounds(*box);
160 
161  return 1;
162 }
163 
164 void
166 {
167  box = myBox;
168 }
169 
170 void
172 {
174  obj->addVolume(new ray_VolumeSphere, 0.0F);
175 }
constexpr SYS_FORCE_INLINE T length2() const noexcept
Definition: UT_Vector3.h:356
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: glcorearb.h:2621
void getAttributeBinding(UT_StringArray &names, UT_IntArray &sizes) const override
GT_API const UT_StringHolder time
UT_Vector3T< float > UT_Vector3
Base class for volume primitives in mantra.
Definition: VGEO_Volume.h:41
Procedural primitive for mantra (RAY)
bool insert(ProcDefinition *def, bool replace_existing=true)
constexpr SYS_FORCE_INLINE T length() const noexcept
Definition: UT_Vector3.h:361
UT_Vector3 gradient(const UT_Vector3 &pos, const UT_Filter &filter, float radius, float time, int idx) const override
float getNativeStepSize() const override
UT_BoundingBoxT< float > UT_BoundingBox
Definition: GEO_Detail.h:41
void getBoundingBox(UT_BoundingBox &box) override
The bounding box is the "object space" bounds of the procedural.
void registerProcedural(RAY_ProceduralFactory *factory)
Modern interface to register procedurals.
void getBoxes(UT_Array< UT_BoundingBox > &boxes, float radius, float dbound, float zerothreshold) const override
RAY_ProceduralChildPtr createChild() const
void enlargeBounds(const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
int initialize(const UT_BoundingBox *box) override
exint append()
Definition: UT_Array.h:142
Parameter definition for arguments to RAY_Procedural.
Volume primitive used by RAY/RAY_DemoVolumeSphere.C.
RAY_ProceduralArg * arguments() const override
Provide a const reference to the arguments for the procedural.
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
RAY_Procedural * create() const override
Create a procedural, and pass ownership of the instance to mantra.
void evaluate(const UT_Vector3 &pos, const UT_Filter &filter, float radius, float time, int idx, float *data) const override
Class to create a procedural.
Definition: format.h:895
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297
Example of a custom volume primitive.