HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HOM/SOP_HOMWaveNumpy.py
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 SOP provides an example of a SOP implemented in Python and accelerated
27 # with Python's numpy module.
28 #
29 
30 """This is the equivalent of SOP_HOMWave.py but uses numpy to speed it up.
31 
32 To use this code,
33  1) In Houdini, choose File -> New Operator Type
34  2) Choose "Python Type"
35  3) Choose the network type as "Geometry Operator"
36  4) Paste this code in the "Code" tab of the type properties.
37 
38 @see @ref HOM/SOP_HOMWave.py, @ref HOM/SOP_HOMWaveInlinecpp.py, @ref HOM/SOP_HOMWave.C, @ref SOP/SOP_CPPWave.C, @ref SOP/SOP_VEXWave.vfl
39 """
40 
41 import numpy
42 
43 geo = hou.pwd().geometry()
44 positions = numpy.frombuffer(
45  geo.pointFloatAttribValuesAsString("P"), dtype="f4,f4,f4").copy()
46 positions.dtype.names = ("x", "y", "z")
47 
48 positions["y"] = numpy.sin(
49  positions["x"] * 0.2 + positions["z"] * 0.3 + hou.frame() * 0.03)
50 geo.setPointFloatAttribValuesFromString("P", positions)
51