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 */ 00027 00028 /// @file TS_cosKernel.C 00029 /// @brief Sample metaball kernel function 00030 /// 00031 /// This file demonstrates how to add a custom metaball kernel function that 00032 /// will show up in all the Kernel Function parameter menus. 00033 /// 00034 /// Once this file is compiled, register this dso into a @c MetaKernels text 00035 /// file that is found in your HOUDINI_PATH environment variable. For example: 00036 /// - <tt>$HOME/Library/Preferences/houdini/X.Y/MetaKernels</tt> <b>(OSX)</b> 00037 /// - <tt>$HOME/houdiniX.Y/MetaKernels</tt> <b>(other platforms)</b> 00038 /// 00039 /// The @c MetaKernels file should contain a list of .so/.dll paths that are 00040 /// located relative to the search paths in the HOUDINI_DSO_PATH environment 00041 /// variable. For example: 00042 /// @code 00043 /// # MetaKernels : Kernel extension table 00044 /// TS_MyKernel.so 00045 /// @endcode 00046 /// In this case, you should install the TS_MyKernel.so file into the @c dso 00047 /// subdirectory under where @c MetaKernels is found. 00048 /// 00049 #include <UT/UT_DSOVersion.h> 00050 #include <TS/TS_Expression.h> 00051 00052 #include <TS/TS_KernelList.h> 00053 00054 static float 00055 evalPosition(float t) 00056 { 00057 // Since distance passed in is squared, we must take the root... 00058 t = sqrt(t); 00059 return cos(t*M_PI)*.5 + .5; 00060 } 00061 00062 static float 00063 evalGradient(float t) 00064 { 00065 t = sqrt(t); 00066 return .5*sin(t*M_PI); 00067 } 00068 00069 static float 00070 cosFunc(float t) 00071 { 00072 if (t <= 0) return 1; 00073 if (t >= 1) return 0; 00074 return evalPosition(t); 00075 } 00076 00077 static UT_Interval 00078 cosFuncRange(const UT_Interval &t) 00079 { 00080 if (t.max <= 0) return UT_Interval(1, 1); 00081 if (t.min >= 1) return UT_Interval(0, 0); 00082 00083 float min = cosFunc(t.max); 00084 float max = cosFunc(t.min); 00085 return (min > max) ? UT_Interval(max, min) : UT_Interval(min, max); 00086 } 00087 00088 static float 00089 cosDFunc(float t) 00090 { 00091 if (t <= 0) return 0; 00092 if (t >= 1) return 0; 00093 return evalGradient(t); 00094 } 00095 00096 static UT_Interval 00097 cosDFuncRange(const UT_Interval &t) 00098 { 00099 if (t.max <= 0 || t.min >= 1) return UT_Interval(0, 0); 00100 float min = cosDFunc(t.min); 00101 float max = cosDFunc(t.max); 00102 return (min > max) ? UT_Interval(max, min) : UT_Interval(min, max); 00103 } 00104 00105 /// The kernel table definition 00106 static TS_MetaKernel cosKernel = { 00107 "cosine", // Token 00108 "Half Cosine", // Label 00109 cosFunc, 00110 cosFuncRange, 00111 cosDFunc, 00112 cosDFuncRange 00113 }; 00114 00115 /// Registration function which installs the kernel 00116 void 00117 newMetaKernel() 00118 { 00119 TS_KernelList::getList()->addKernel(&cosKernel); 00120 } 00121
1.5.9