00001 /* 00002 * Copyright (c) 2012 00003 * Side Effects Software Inc. All rights reserved. 00004 * 00005 * Redistribution and use of Houdini Development Kit samples in source and 00006 * binary forms, with or without modification, are permitted provided that the 00007 * following conditions are met: 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 2. The name of Side Effects Software may not be used to endorse or 00011 * promote products derived from this software without specific prior 00012 * written permission. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS 00015 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00017 * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 00018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00019 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00020 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00021 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00022 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00023 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 * 00025 *---------------------------------------------------------------------------- 00026 * This is a sample procedural DSO 00027 */ 00028 00029 #include <GU/GU_Detail.h> 00030 #include "VRAY_DemoBox.h" 00031 00032 using namespace HDK_Sample; 00033 00034 static VRAY_ProceduralArg theArgs[] = { 00035 // Default minimum bound is {-1,-1,-1} 00036 VRAY_ProceduralArg("minbound", "real", "-1 -1 -1"), 00037 // Default maximum bound is {1,1,1} 00038 VRAY_ProceduralArg("maxbound", "real", "1 1 1"), 00039 VRAY_ProceduralArg() 00040 }; 00041 00042 VRAY_Procedural * 00043 allocProcedural(const char *) 00044 { 00045 return new VRAY_DemoBox(); 00046 } 00047 00048 const VRAY_ProceduralArg * 00049 getProceduralArgs(const char *) 00050 { 00051 return theArgs; 00052 } 00053 00054 VRAY_DemoBox::VRAY_DemoBox() 00055 { 00056 myBox.initBounds(0, 0, 0); 00057 } 00058 00059 VRAY_DemoBox::~VRAY_DemoBox() 00060 { 00061 } 00062 00063 const char * 00064 VRAY_DemoBox::getClassName() 00065 { 00066 return "VRAY_DemoBox"; 00067 } 00068 00069 int 00070 VRAY_DemoBox::initialize(const UT_BoundingBox *) 00071 { 00072 fpreal val[3]; 00073 00074 // Import the minbound parameter. This will pick up parameters passed on 00075 // the procedural line in the IFD, or the default value from the 00076 // VRAY_ProceduralArg. 00077 val[0] = val[1] = val[2] = -1; 00078 import("minbound", val, 3); 00079 myBox.initBounds(val[0], val[1], val[2]); 00080 00081 val[0] = val[1] = val[2] = 1; 00082 import("maxbound", val, 3); 00083 myBox.enlargeBounds(val[0], val[1], val[2]); 00084 00085 // The bounding box has been initialized. The geometry generated must like 00086 // within the bounds. 00087 return 1; 00088 } 00089 00090 void 00091 VRAY_DemoBox::getBoundingBox(UT_BoundingBox &box) 00092 { 00093 // Return the bounding box of the geometry 00094 box = myBox; 00095 } 00096 00097 void 00098 VRAY_DemoBox::render() 00099 { 00100 GU_Detail *gdp; 00101 00102 /// Allocate geometry. 00103 /// NOTE: Do not simply construct a GU_Detail. 00104 /// @see VRAY_Procedural::allocateGeometry(). 00105 gdp = allocateGeometry(); 00106 00107 /// Call the GU_Detail::cube() method to create a cube 00108 gdp->cube(myBox.vals[0][0], myBox.vals[0][1], 00109 myBox.vals[1][0], myBox.vals[1][1], 00110 myBox.vals[2][0], myBox.vals[2][1]); 00111 00112 // Create a geometry object in mantra 00113 openGeometryObject(); 00114 // Add the geometry 00115 addGeometry(gdp, 0); 00116 // Change the surface shader setting 00117 changeSetting("surface", "constant Cd ( 1 0 0 )", "object"); 00118 closeObject(); 00119 }
1.5.9