├── arrayNodes.mod ├── arrayNodes ├── plug-ins │ ├── linux-maya2014 │ │ └── arrayNodes.so │ ├── linux-maya2015 │ │ └── arrayNodes.so │ ├── linux-maya2016 │ │ └── arrayNodes.so │ ├── windows-maya2014 │ │ └── arrayNodes.mll │ ├── windows-maya2015 │ │ └── arrayNodes.mll │ ├── windows-maya2016 │ │ └── arrayNodes.mll │ └── macos-maya2017 │ │ └── arrayNodes.bundle └── scripts │ └── AEremapArrayValuesTemplate.mel ├── README.md ├── src ├── utils.h ├── n_iterAngle.h ├── n_chain.h ├── n_iter.h ├── n_clamp.h ├── n_normalize.h ├── n_ctorAngle.h ├── n_ctor.h ├── n_slice.h ├── utils.cpp ├── n_modify.h ├── n_reduce.h ├── n_remap.h ├── n_iter.cpp ├── n_multi.h ├── n_scalar.h ├── n_iterAngle.cpp ├── n_chain.cpp ├── n_ctor.cpp ├── n_clamp.cpp ├── n_ctorAngle.cpp ├── n_reduce.cpp ├── n_slice.cpp ├── n_scalar.cpp ├── n_normalize.cpp ├── n_modify.cpp ├── n_multi.cpp ├── n_remap.cpp └── pluginMain.cpp ├── CMakeLists.txt ├── LICENSE └── .gitignore /arrayNodes.mod: -------------------------------------------------------------------------------- 1 | + arrayNodes 1.0.0 ${MAYA_MODULE_PATH}/arrayNodes 2 | [r] scripts: scripts 3 | plug-ins: plug-ins -------------------------------------------------------------------------------- /arrayNodes/plug-ins/linux-maya2014/arrayNodes.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yantor3d/arrayNodes/HEAD/arrayNodes/plug-ins/linux-maya2014/arrayNodes.so -------------------------------------------------------------------------------- /arrayNodes/plug-ins/linux-maya2015/arrayNodes.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yantor3d/arrayNodes/HEAD/arrayNodes/plug-ins/linux-maya2015/arrayNodes.so -------------------------------------------------------------------------------- /arrayNodes/plug-ins/linux-maya2016/arrayNodes.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yantor3d/arrayNodes/HEAD/arrayNodes/plug-ins/linux-maya2016/arrayNodes.so -------------------------------------------------------------------------------- /arrayNodes/plug-ins/windows-maya2014/arrayNodes.mll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yantor3d/arrayNodes/HEAD/arrayNodes/plug-ins/windows-maya2014/arrayNodes.mll -------------------------------------------------------------------------------- /arrayNodes/plug-ins/windows-maya2015/arrayNodes.mll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yantor3d/arrayNodes/HEAD/arrayNodes/plug-ins/windows-maya2015/arrayNodes.mll -------------------------------------------------------------------------------- /arrayNodes/plug-ins/windows-maya2016/arrayNodes.mll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yantor3d/arrayNodes/HEAD/arrayNodes/plug-ins/windows-maya2016/arrayNodes.mll -------------------------------------------------------------------------------- /arrayNodes/plug-ins/macos-maya2017/arrayNodes.bundle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yantor3d/arrayNodes/HEAD/arrayNodes/plug-ins/macos-maya2017/arrayNodes.bundle -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #### arrayNodes (version 1.0.0) 2 | Maya plugin with nodes for performing calculates on sets of values in a single node. 3 | 4 | #### Description 5 | See the [Wiki](https://github.com/yantor3d/arrayNodes/wiki) for full details. 6 | 7 | ## Plugin Contents 8 | ### Nodes 9 | - arrayAngleCtor 10 | - arrayAngleIter 11 | - arrayCtor 12 | - arrayIter 13 | - arrayMultiOp 14 | - arrayScalarOp 15 | - chainArray 16 | - clampArray 17 | - modifyArray 18 | - normalizeArray 19 | - remapArrayValues 20 | - reduceArray 21 | - sliceArray 22 | -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Ryan Porter 3 | */ 4 | 5 | #ifndef n_arrayNodeUtils_H 6 | #define n_arrayNodeUtils_H 7 | 8 | const short kNO_OP = 0; 9 | const short kSUM = 1; 10 | const short kDIFFERENCE = 2; 11 | const short kAVERAGE = 3; 12 | const short kPRODUCT = 4; 13 | const short kQUOTIENT = 5; 14 | const short kEXPONENT = 6; 15 | const short kMIN = 7; 16 | const short kMAX = 8; 17 | 18 | #include 19 | #include 20 | 21 | double computeOutput(double &lhs, double &rhs, short &operation, MStatus &status); 22 | void reportComputeError(MPxNode *node, short &operation); 23 | #endif -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | 3 | # Download Chad Vernon's cgcmake package (https://github.com/chadmv/cgcmake/) 4 | # and make sure your CMAKE_MODULES_PATH environment variable points at it. 5 | 6 | set(CMAKE_MODULE_PATH "$ENV{CMAKE_MODULE_PATH}") 7 | 8 | project(arrayNodes) 9 | file(GLOB SOURCE_FILES "src/*.cpp" "src/*.h") 10 | find_package(Maya REQUIRED) 11 | 12 | include_directories(${MAYA_INCLUDE_DIR}) 13 | link_directories(${MAYA_LIBRARY_DIR}) 14 | 15 | add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES}) 16 | target_link_libraries(${PROJECT_NAME} ${MAYA_LIBRARIES}) 17 | 18 | MAYA_PLUGIN(${PROJECT_NAME}) -------------------------------------------------------------------------------- /arrayNodes/scripts/AEremapArrayValuesTemplate.mel: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (c) 2016 Ryan Porter - arrayNodes 3 | You may use, distribute, or modify this code under the terms of the MIT license. 4 | */ 5 | 6 | global proc AEremapArrayValuesTemplate( string $nodeName ) 7 | { 8 | editorTemplate -beginScrollLayout; 9 | 10 | AEaddRampControl ($nodeName + ".values"); 11 | 12 | editorTemplate -beginLayout "Input And Output Ranges" -collapse 0; 13 | editorTemplate -addControl "inputMin"; 14 | editorTemplate -addControl "inputMax"; 15 | editorTemplate -addControl "outputMin"; 16 | editorTemplate -addControl "outputMax"; 17 | editorTemplate -endLayout; 18 | 19 | AEdependNodeTemplate $nodeName; 20 | 21 | editorTemplate -addExtraControls; 22 | editorTemplate -endScrollLayout; 23 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Ryan Porter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/n_iterAngle.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Ryan Porter 3 | */ 4 | 5 | /** 6 | This node sets the values of each index in the input array to the index of the multi-index output, as an angle. 7 | 8 | ## Attributes 9 | 10 |
Attribute Name Short Name Attribute Type 11 |
input i doubleArray 12 |
The values that will be unpacked to individual outputs. 13 |
output o doubleAngle[] 14 |
The individual values of the `input` array. 15 |
16 | */ 17 | 18 | #ifndef n_iterAngleArray_H 19 | #define n_iterAngleArray_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | class ArrayAngleIteratorNode : public MPxNode 28 | { 29 | public: 30 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 31 | virtual void postConstructor(); 32 | static void* creator(); 33 | static MStatus initialize(); 34 | 35 | public: 36 | static MTypeId kNODE_ID; 37 | static MString kNODE_NAME; 38 | 39 | static MObject aInput; 40 | static MObject aOutput; 41 | }; 42 | 43 | #endif -------------------------------------------------------------------------------- /src/n_chain.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Ryan Porter 3 | */ 4 | 5 | /** 6 | This node concatenates the input arrays and outputs a single array. 7 | 8 | ## Attributes 9 | 10 |
Attribute Name Short Name Attribute Type 11 |
input i doubleArray[] 12 |
List of input arrays that will be chained together to produce the output. 13 |
output o doubleArray 14 |
A single array containing all the values of the input arrays. 15 |
16 | */ 17 | 18 | #ifndef n_chainArrays_H 19 | #define n_chainArrays_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | class ChainArraysNode : public MPxNode 28 | { 29 | public: 30 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 31 | virtual void postConstructor(); 32 | static void* creator(); 33 | static MStatus initialize(); 34 | 35 | public: 36 | static MTypeId kNODE_ID; 37 | static MString kNODE_NAME; 38 | 39 | static MObject aInput; 40 | static MObject aOutput; 41 | }; 42 | 43 | #endif -------------------------------------------------------------------------------- /src/n_iter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Ryan Porter 3 | */ 4 | 5 | /** 6 | This node sets the values of each index in the input array to the index of the multi-index output. 7 | 8 | ## Attributes 9 | 10 |
Attribute Name Short Name Attribute Type 11 |
input i doubleArray 12 |
The values that will be unpacked to individual outputs. 13 |
output o double[] 14 |
The individual values of the `input` array. 15 |
16 | */ 17 | 18 | #ifndef n_iterArray_H 19 | #define n_iterArray_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | class ArrayIteratorNode : public MPxNode 28 | { 29 | public: 30 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 31 | virtual void postConstructor(); 32 | static void* creator(); 33 | static MStatus initialize(); 34 | 35 | public: 36 | static MTypeId kNODE_ID; 37 | static MString kNODE_NAME; 38 | 39 | static MObject aInput; 40 | static MObject aOutput; 41 | }; 42 | 43 | #endif -------------------------------------------------------------------------------- /src/n_clamp.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Ryan Porter 3 | */ 4 | 5 | /** 6 | This node clamps the values of the input array within a specified range. 7 | 8 | ## Attributes 9 | 10 |
Attribute Name Short Name Attribute Type 11 |
input i doubleArray 12 |
Input values. 13 |
min mn double 14 |
Values in `output` will not be less than this value. 15 |
max mn double 16 |
Values in `output` will not be greater than this value. 17 |
output o doubleArray 18 |
Output values. 19 |
20 | */ 21 | 22 | #ifndef n_clampArray_H 23 | #define n_clampArray_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | class ClampArrayNode : public MPxNode 32 | { 33 | public: 34 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 35 | virtual void postConstructor(); 36 | static void* creator(); 37 | static MStatus initialize(); 38 | 39 | public: 40 | static MTypeId kNODE_ID; 41 | static MString kNODE_NAME; 42 | 43 | static MObject aInput; 44 | static MObject aMin; 45 | static MObject aMax; 46 | static MObject aOutput; 47 | }; 48 | 49 | #endif -------------------------------------------------------------------------------- /src/n_normalize.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Ryan Porter 3 | */ 4 | 5 | /** 6 | This node calculates the normalized value of each value in the input arrays. 7 | 8 | ## Attributes 9 | 10 |
Attribute Name Short Name Attribute Type 11 |
input i doubleArray[] 12 |
List of input values that will be normalized. The sum of normalized values is always 1.0. 13 |
elementwise ew bool 14 |
If True, the input values will be normalized by row. If False, the input values will be normalized by column. 15 |
output o doubleArray[] 16 |
The normalized values. 17 |
18 | */ 19 | 20 | #ifndef n_arrayNormalize_H 21 | #define n_arrayNormalize_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | class NormalizeArrayNode : public MPxNode 30 | { 31 | public: 32 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 33 | virtual void postConstructor(); 34 | static void* creator(); 35 | static MStatus initialize(); 36 | 37 | public: 38 | static MTypeId kNODE_ID; 39 | static MString kNODE_NAME; 40 | 41 | static MObject aInput; 42 | static MObject aElementwise; 43 | static MObject aOutput; 44 | }; 45 | 46 | #endif -------------------------------------------------------------------------------- /src/n_ctorAngle.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Ryan Porter 3 | */ 4 | 5 | /** 6 | This node constructs an array from the indices of the multi-index input. 7 | 8 | ## Attributes 9 | 10 |
Attribute Name Short Name Attribute Type 11 |
input i doubleAngle[] 12 |
13 | The individual values that will be used to construct the `output` array. 14 | The logical indices of the input values are preserved - missing indices will be filled in with 0.0. 15 |
size s int 16 |
17 | The size of the output array. If there are too few inputs, the remaining indices will be filled in with 0.0. 18 |
output o doubleArray 19 |
An array constructed from the `input` values. 20 |
21 | */ 22 | 23 | #ifndef n_arrayAngleCtor_H 24 | #define n_arrayAngleCtor_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | class ArrayAngleConstructorNode : public MPxNode 33 | { 34 | public: 35 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 36 | virtual void postConstructor(); 37 | static void* creator(); 38 | static MStatus initialize(); 39 | 40 | public: 41 | static MTypeId kNODE_ID; 42 | static MString kNODE_NAME; 43 | 44 | static MObject aSize; 45 | static MObject aInput; 46 | static MObject aOutput; 47 | }; 48 | 49 | #endif -------------------------------------------------------------------------------- /src/n_ctor.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Ryan Porter 3 | */ 4 | 5 | /** 6 | This node constructs an array from the indices of the multi-index input. 7 | 8 | ## Attributes 9 | 10 |
Attribute Name Short Name Attribute Type 11 |
input i double[] 12 |
13 | The individual values that will be used to construct the `output` array. 14 | The logical indices of the input values are preserved - missing indices will be filled in with 0.0. 15 |
size s int 16 |
17 | The size of the output array. If there are too few inputs, the remaining indices will be filled in with 0.0. 18 |
output o doubleArray 19 |
An array constructed from the `input` values. 20 |
21 | */ 22 | 23 | #ifndef n_arrayCtor_H 24 | #define n_arrayCtor_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | class ArrayConstructorNode : public MPxNode 33 | { 34 | public: 35 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 36 | virtual void postConstructor(); 37 | static void* creator(); 38 | static MStatus initialize(); 39 | 40 | public: 41 | static MTypeId kNODE_ID; 42 | static MString kNODE_NAME; 43 | 44 | static MObject aSize; 45 | static MObject aInput; 46 | static MObject aOutput; 47 | }; 48 | 49 | #endif -------------------------------------------------------------------------------- /src/n_slice.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Ryan Porter 3 | */ 4 | 5 | /** 6 | This node creates an output array from a slice of the input array. 7 | 8 | ## Attributes 9 | 10 |
Attribute Name Short Name Attribute Type 11 |
input i doubleArray 12 |
Input array that will be sliced to produce the output. 13 |
start st int 14 |
15 | Index in the input array from which to start the slice. 16 | If start is negative, the slice will start that many indices from the end of the input array. 17 |
stop sp int 18 |
19 | Index in the input array at which to end the slice. 20 | If stop is negative, the slice will end that many indices from end of the input array. 21 |
step ss int 22 |
23 | Stride of each step of the slice. 24 | If step is 1, every index from start to stop will be returned. 25 | Step may not be 0. 26 |
output o doubleArray 27 |
An array containing the values sliced from the `input` array. 28 |
29 | */ 30 | 31 | #ifndef n_sliceArray_H 32 | #define n_sliceArray_H 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | class SliceArrayNode : public MPxNode 41 | { 42 | public: 43 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 44 | virtual void postConstructor(); 45 | static void* creator(); 46 | static MStatus initialize(); 47 | 48 | public: 49 | static MTypeId kNODE_ID; 50 | static MString kNODE_NAME; 51 | 52 | static MObject aInput; 53 | static MObject aStartIndex; 54 | static MObject aStopIndex; 55 | static MObject aStepSize; 56 | static MObject aOutput; 57 | }; 58 | 59 | #endif -------------------------------------------------------------------------------- /src/utils.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (c) 2016 Ryan Porter - arrayNodes 3 | You may use, distribute, or modify this code under the terms of the MIT license. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "utils.h" 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #define ALMOST_ZERO 1e-5 17 | 18 | using namespace std; 19 | 20 | double computeOutput(double &lhs, double &rhs, short &operation, MStatus &status) 21 | { 22 | double result = 0.0; 23 | 24 | switch (operation) 25 | { 26 | case kNO_OP: 27 | result = lhs; 28 | break; 29 | 30 | case kSUM: 31 | result = lhs + rhs; 32 | break; 33 | 34 | case kDIFFERENCE: 35 | result = lhs - rhs; 36 | break; 37 | 38 | case kAVERAGE: 39 | result = lhs + rhs; 40 | break; 41 | 42 | case kPRODUCT: 43 | result = lhs * rhs; 44 | break; 45 | 46 | case kQUOTIENT: 47 | if (abs(rhs) < ALMOST_ZERO) 48 | { 49 | result = DBL_MAX; 50 | status = MS::kFailure; 51 | } else { 52 | result = lhs / rhs; 53 | } 54 | break; 55 | 56 | case kEXPONENT: 57 | if (rhs > 0.0 && rhs < 1.0 && lhs < 0.0) 58 | { 59 | result = NAN; 60 | status = MS::kFailure; 61 | } else { 62 | result = pow(lhs, rhs); 63 | } 64 | break; 65 | 66 | case kMIN: 67 | result = min(lhs, rhs); 68 | break; 69 | 70 | case kMAX: 71 | result = max(lhs, rhs); 72 | break; 73 | } 74 | 75 | return result; 76 | } 77 | 78 | void reportComputeError(MPxNode *node, short &operation) 79 | { 80 | switch (operation) 81 | { 82 | case kQUOTIENT: 83 | MGlobal::displayWarning(node->name() + " - basicExpression has encountered a divide by zero. Result is unpredictable."); 84 | break; 85 | case kEXPONENT: 86 | MGlobal::displayWarning(node->name() + " - negative number cannot be raised to a fractional power."); 87 | break; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/n_modify.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Ryan Porter 3 | */ 4 | 5 | /** 6 | This node applies a function to the input array and outputs the result. 7 | 8 | ## Attributes 9 | 10 |
Attribute Name Short Name Attribute Type 11 |
input i doubleArray 12 |
List of input values that will be normalized. The sum of normalized values is always 1.0. 13 |
operation op enum 14 |
The operation that will be applied to the `input` values. 15 | @param "No Operation" Output will be identical to the input. 16 | @param Sort Output will contain all the values of the input, sorted by value. 17 | @param "Reflect Left" Output will be the input reflected across the first value. 18 | \n For example: : [0, 1, 2, 3, 4] -> [4, 3, 2, 1, 0, 1, 2, 3, 4] 19 | @param "Reflect Right" Output will be the input reflected across the last value. 20 | \n For example: [0, 1, 2, 3, 4] -> [0, 1, 2, 3, 4, 3, 2, 1, 0] 21 |
reverse rev bool 22 |
23 | If `True`, the values will be output in reverse order. 24 |
output o doubleArray 25 |
The result of the operation. 26 |
27 | */ 28 | 29 | #ifndef n_modifyArray_H 30 | #define n_modifyArray_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | class ModifyArrayNode : public MPxNode 39 | { 40 | public: 41 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 42 | virtual void postConstructor(); 43 | static void* creator(); 44 | static MStatus initialize(); 45 | 46 | public: 47 | static MTypeId kNODE_ID; 48 | static MString kNODE_NAME; 49 | 50 | static MObject aInput; 51 | static MObject aOperation; 52 | static MObject aReverse; 53 | static MObject aOutput; 54 | }; 55 | 56 | #endif -------------------------------------------------------------------------------- /src/n_reduce.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Ryan Porter 3 | */ 4 | 5 | /** 6 | This node applies an accumulating function to the values of the input array and outputs a single value. 7 | 8 | ## Attributes 9 | 10 |
Attribute Name Short Name Attribute Type 11 |
input i doubleArray 12 |
Input values that will be reduced to a single value. 13 |
operation op enum 14 |
The operation that will be applied to the `input` values. 15 | @param "No Operation" Output will be 0.0. 16 | @param Sum Output will be the first value plus the remaining values. 17 | @param Difference Output will be the first value minus the remaining values. 18 | @param Average Output will be the average of the input values. 19 | @param Product Output will be the first value times the remaining values. 20 | @param Quotient Output will be the first value divided by the remaining values. 21 | @param Exponent Output will be the first value raised to the remaining values. 22 | @param Min Output will be the smallest value. 23 | @param Max Output will be the largest value. 24 | @param Length Output will be the number of values. 25 |
output o double 26 |
The result of the operation. 27 |
28 | */ 29 | 30 | #ifndef n_reduceArray_H 31 | #define n_reduceArray_H 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | class ReduceArrayNode : public MPxNode 40 | { 41 | public: 42 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 43 | virtual void postConstructor(); 44 | static void* creator(); 45 | static MStatus initialize(); 46 | 47 | public: 48 | static MTypeId kNODE_ID; 49 | static MString kNODE_NAME; 50 | 51 | static MObject aInput; 52 | static MObject aOperation; 53 | static MObject aOutput; 54 | }; 55 | 56 | #endif -------------------------------------------------------------------------------- /src/n_remap.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Ryan Porter 3 | */ 4 | 5 | /** 6 | This node remaps the values of the input array using a gradient. 7 | 8 | ## Attributes 9 | 10 |
Attribute Name Short Name Attribute Type 11 |
input i doubleArray[] 12 |
Values to be remapped. 13 |
inputMin imn double 14 |
This determines the value which maps to the left of the gradient. 15 |
inputMax imx double 16 |
This determines the value which maps to the right of the gradient. 17 |
outputMin omn double 18 |
This determines the output value at the bottom of the gradient. 19 |
outputMax omx double 20 |
This determines the output value at the top of the gradient. 21 |
values vl ramp attribute 22 |
Defines a range of values used to remap the values of the input array. 23 |
output o doubleArray 24 |
The remapped values. 25 |
26 | */ 27 | 28 | #ifndef n_remapArrayValues_H 29 | #define n_remapArrayValues_H 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | class RemapArrayValuesNode : public MPxNode 38 | { 39 | public: 40 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 41 | virtual void postConstructor(); 42 | virtual MStatus setInitialRampValues(); 43 | 44 | static void* creator(); 45 | static MStatus initialize(); 46 | static float remapValue(float inValue, float inputMin, float inputMax, float outputMin = 0.0, float outputMax = 1.0); 47 | 48 | public: 49 | static MTypeId kNODE_ID; 50 | static MString kNODE_NAME; 51 | 52 | static MObject aInput; 53 | static MObject aInputMin; 54 | static MObject aInputMax; 55 | static MObject aOutputMin; 56 | static MObject aOutputMax; 57 | static MObject aRamp; 58 | static MObject aOutput; 59 | 60 | }; 61 | 62 | #endif -------------------------------------------------------------------------------- /src/n_iter.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (c) 2016 Ryan Porter - arrayNodes 3 | You may use, distribute, or modify this code under the terms of the MIT license. 4 | */ 5 | /*----------------------------------------------------------------------------- 6 | arrayIter 7 | Sets each value in an input doubleArray to an index in the output attribute 8 | so that values can be passed to nodes that do not operate on doubleArray objects. 9 | 10 | Input Attributes 11 | - input (doubleArray) 12 | 13 | Output Attributes 14 | - output (double[]) 15 | -----------------------------------------------------------------------------*/ 16 | 17 | #include "n_iter.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | MObject ArrayIteratorNode::aInput; 29 | MObject ArrayIteratorNode::aOutput; 30 | 31 | void* ArrayIteratorNode::creator() 32 | { 33 | return new ArrayIteratorNode(); 34 | } 35 | 36 | MStatus ArrayIteratorNode::initialize() 37 | { 38 | MStatus status; 39 | 40 | MFnTypedAttribute T; 41 | MFnNumericAttribute N; 42 | 43 | aInput = T.create("input", "i", MFnData::kDoubleArray); 44 | T.setKeyable(false); 45 | T.setStorable(true); 46 | T.setWritable(true); 47 | 48 | aOutput = N.create("output", "o", MFnNumericData::kDouble); 49 | N.setKeyable(false); 50 | N.setChannelBox(false); 51 | N.setWritable(false); 52 | N.setStorable(false); 53 | N.setArray(true); 54 | N.setUsesArrayDataBuilder(true); 55 | 56 | addAttribute(aInput); 57 | addAttribute(aOutput); 58 | 59 | attributeAffects(aInput, aOutput); 60 | 61 | return MS::kSuccess; 62 | } 63 | 64 | void ArrayIteratorNode::postConstructor() 65 | { 66 | this->setExistWithoutOutConnections(true); 67 | } 68 | 69 | MStatus ArrayIteratorNode::compute(const MPlug& plug, MDataBlock& data) 70 | { 71 | if (plug != aOutput && plug.parent() != aOutput) 72 | return MS::kUnknownParameter; 73 | 74 | MFnDoubleArrayData inputData(data.inputValue(aInput).data()); 75 | 76 | MArrayDataHandle outputHandle = data.outputValue(aOutput); 77 | MArrayDataBuilder outputData = outputHandle.builder(); 78 | 79 | int size = inputData.length(); 80 | 81 | for (int i = 0; i < size; i++) 82 | { 83 | MDataHandle outHandle = outputData.addElement(i); 84 | outHandle.setDouble(inputData[i]); 85 | } 86 | 87 | outputHandle.set(outputData); 88 | outputHandle.setAllClean(); 89 | 90 | return MS::kSuccess; 91 | } -------------------------------------------------------------------------------- /src/n_multi.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Ryan Porter 3 | */ 4 | 5 | /** 6 | This node accumulates the values in the input arrays to a function and outputs the results. 7 | 8 | ## Attributes 9 | 10 |
Attribute Name Short Name Attribute Type 11 |
input i doubleArray 12 |
List of input values that will be used in the calculations. 13 |
operation op enum 14 |
The operation that will be applied to the `input` values. 15 | @param "No Operation" No calculations will be performed 16 | @param Sum Each output will be the sum of the input values. 17 | @param Difference Each output will be the difference between the input values. 18 | @param Average Each output will be the average of the input values. 19 | @param Product Each output will be the product of the input values. 20 | @param Quotient Each output will be the quotient of the input values. 21 | @param Expontent Each output will be the expontent of the input values. 22 |
elementwise ew enum 23 |
24 | If `True`, the output value at a given index will be calculated using the values at that index in the input arrays. 25 | Otherwise, the output value at a given index will be calculate using the values of the input array at that index. 26 |
output o doubleArray 27 |
The normalized values. 28 |
29 | */ 30 | 31 | #ifndef n_arrayMultiOp_H 32 | #define n_arrayMultiOp_H 33 | 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | class ArrayMultiOperatorNode : public MPxNode 44 | { 45 | public: 46 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 47 | virtual void postConstructor(); 48 | static void* creator(); 49 | static MStatus initialize(); 50 | 51 | public: 52 | static MTypeId kNODE_ID; 53 | static MString kNODE_NAME; 54 | 55 | static MObject aInput; 56 | static MObject aOperation; 57 | static MObject aElementwise; 58 | static MObject aOutput; 59 | 60 | static bool sortByLength(const MDoubleArray &lhs, const MDoubleArray &rhs) { return lhs.length() > rhs.length(); } 61 | }; 62 | 63 | #endif -------------------------------------------------------------------------------- /src/n_scalar.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Ryan Porter 3 | */ 4 | 5 | /** 6 | This node calculates a binary operation between each value in the input array and the scalar value and outputs the results. 7 | 8 | ## attributes 9 | 10 |
Attribute Name Short Name Attribute Type 11 |
input i doubleArray 12 |
Input values that will be applied to the operation with the `scalar` value. 13 |
scalar s double 14 |
The scalar value that will be applied to the operation with each value of `input`. 15 |
operation op enum 16 |
The operation that will be applied to the `input` values. 17 | @param "No Operation" Each output will be the same as the input 18 | @param Add Each output will be the sum of the input and the scalar. 19 | @param Subtract Each output will be the difference between the input and the scalar. 20 | @param Multiply Each output will be the product of the input and the scalar. 21 | @param Divide Each output will be the quotient of the input and the scalar. 22 | @param Power Each output will be the expontent of the input and the scalar. 23 |
argumentOrder op enum 24 |
The order in which the arguments will be passed to the operation. 25 | @param "Element First" Each element in the `input` array is the left hand operand. 26 | @param "Scalar First" The `scalar` value is the left hand operand. 27 |
output op doubleArray 28 |
The result of the calculations. 29 |
30 | */ 31 | 32 | #ifndef n_arrayScalarOp_H 33 | #define n_arrayScalarOp_H 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | class ArrayScalarOperationNode : public MPxNode 42 | { 43 | public: 44 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 45 | virtual void postConstructor(); 46 | static void* creator(); 47 | static MStatus initialize(); 48 | 49 | public: 50 | static MTypeId kNODE_ID; 51 | static MString kNODE_NAME; 52 | 53 | static MObject aInput; 54 | static MObject aScalar; 55 | static MObject aOperation; 56 | static MObject aOrder; 57 | static MObject aOutput; 58 | }; 59 | 60 | #endif -------------------------------------------------------------------------------- /src/n_iterAngle.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (c) 2016 Ryan Porter - arrayNodes 3 | You may use, distribute, or modify this code under the terms of the MIT license. 4 | */ 5 | 6 | /*----------------------------------------------------------------------------- 7 | arrayAngleIter 8 | Sets each value in an input doubleArray to an index in the output attribute as 9 | a doubleAngle so that values can be passed to attributes that expected angles 10 | without a unitConversion node. 11 | 12 | Input Attributes 13 | - input (doubleArray) 14 | 15 | Output Attributes 16 | - output (doubleAngle[]) 17 | -----------------------------------------------------------------------------*/ 18 | 19 | #include "n_iterAngle.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | MObject ArrayAngleIteratorNode::aInput; 33 | MObject ArrayAngleIteratorNode::aOutput; 34 | 35 | void* ArrayAngleIteratorNode::creator() 36 | { 37 | return new ArrayAngleIteratorNode(); 38 | } 39 | 40 | MStatus ArrayAngleIteratorNode::initialize() 41 | { 42 | MStatus status; 43 | 44 | MFnTypedAttribute T; 45 | MFnNumericAttribute N; 46 | MFnUnitAttribute U; 47 | 48 | aInput = T.create("input", "i", MFnData::kDoubleArray); 49 | T.setKeyable(false); 50 | T.setStorable(true); 51 | T.setWritable(true); 52 | 53 | aOutput = U.create("output", "o", MFnUnitAttribute::kAngle); 54 | U.setKeyable(false); 55 | U.setChannelBox(false); 56 | U.setWritable(false); 57 | U.setStorable(false); 58 | U.setArray(true); 59 | U.setUsesArrayDataBuilder(true); 60 | 61 | addAttribute(aInput); 62 | addAttribute(aOutput); 63 | 64 | attributeAffects(aInput, aOutput); 65 | 66 | return MS::kSuccess; 67 | } 68 | 69 | void ArrayAngleIteratorNode::postConstructor() 70 | { 71 | this->setExistWithoutOutConnections(true); 72 | } 73 | 74 | MStatus ArrayAngleIteratorNode::compute(const MPlug& plug, MDataBlock& data) 75 | { 76 | if (plug != aOutput && plug.parent() != aOutput) 77 | return MS::kUnknownParameter; 78 | 79 | MFnDoubleArrayData inputData(data.inputValue(aInput).data()); 80 | 81 | MArrayDataHandle outputHandle = data.outputValue(aOutput); 82 | MArrayDataBuilder outputData = outputHandle.builder(); 83 | 84 | int size = inputData.length(); 85 | 86 | MAngle::Unit uiUnit = MAngle::uiUnit(); 87 | 88 | for (int i = 0; i < size; i++) 89 | { 90 | MDataHandle outHandle = outputData.addElement(i); 91 | outHandle.setMAngle(MAngle(inputData[i], uiUnit)); 92 | } 93 | 94 | outputHandle.set(outputData); 95 | outputHandle.setAllClean(); 96 | 97 | return MS::kSuccess; 98 | } -------------------------------------------------------------------------------- /src/n_chain.cpp: -------------------------------------------------------------------------------- 1 | /** Copyright (c) 2016 Ryan Porter - arrayNodes 2 | You may use, distribute, or modify this code under the terms of the MIT license. 3 | */ 4 | 5 | #include 6 | 7 | #include "n_chain.h" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | using namespace std; 18 | 19 | MObject ChainArraysNode::aInput; 20 | MObject ChainArraysNode::aOutput; 21 | 22 | void* ChainArraysNode::creator() 23 | { 24 | return new ChainArraysNode(); 25 | } 26 | 27 | MStatus ChainArraysNode::initialize() 28 | { 29 | MStatus status; 30 | 31 | MFnTypedAttribute T; 32 | 33 | aInput = T.create("input", "i", MFnData::kDoubleArray); 34 | T.setKeyable(false); 35 | T.setStorable(true); 36 | T.setWritable(true); 37 | T.setArray(true); 38 | 39 | aOutput = T.create("output", "o", MFnData::kDoubleArray); 40 | T.setKeyable(false); 41 | T.setChannelBox(false); 42 | T.setWritable(false); 43 | T.setStorable(false); 44 | 45 | addAttribute(aInput); 46 | addAttribute(aOutput); 47 | 48 | attributeAffects(aInput, aOutput); 49 | 50 | return MS::kSuccess; 51 | } 52 | 53 | void ChainArraysNode::postConstructor() 54 | { 55 | this->setExistWithoutOutConnections(true); 56 | } 57 | 58 | MStatus ChainArraysNode::compute(const MPlug& plug, MDataBlock& data) 59 | { 60 | if (plug != aOutput) 61 | return MS::kUnknownParameter; 62 | 63 | MStatus status; 64 | 65 | MArrayDataHandle inputArrayHandle = data.inputArrayValue(aInput); 66 | int numInputs = inputArrayHandle.elementCount(); 67 | int outputSize = 0; 68 | 69 | vector inputData = vector(numInputs); 70 | 71 | for (int i = 0; i < numInputs; i++) 72 | { 73 | MDataHandle inputHandle = inputArrayHandle.inputValue(); 74 | MFnDoubleArrayData data(inputHandle.data(), &status); 75 | data.copyTo(inputData[i]); 76 | 77 | outputSize += data.length(); 78 | 79 | if (!inputArrayHandle.next()) break; 80 | } 81 | 82 | MDoubleArray outputArray(outputSize); 83 | 84 | int index = 0; 85 | for (int i = 0; i < numInputs; i++) 86 | { 87 | outputSize = inputData[i].length(); 88 | 89 | for (int j = 0; j < outputSize; j++) 90 | { 91 | outputArray[index] = inputData[i][j]; 92 | index++; 93 | } 94 | } 95 | 96 | MDataHandle outputHandle = data.outputValue(aOutput); 97 | MFnDoubleArrayData output; 98 | MObject outputData = output.create(outputArray); 99 | 100 | outputHandle.setMObject(outputData); 101 | outputHandle.setClean(); 102 | 103 | return MS::kSuccess; 104 | } -------------------------------------------------------------------------------- /src/n_ctor.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (c) 2016 Ryan Porter - arrayNodes 3 | You may use, distribute, or modify this code under the terms of the MIT license. 4 | */ 5 | 6 | #include "n_ctor.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | MObject ArrayConstructorNode::aSize; 19 | MObject ArrayConstructorNode::aInput; 20 | MObject ArrayConstructorNode::aOutput; 21 | 22 | void* ArrayConstructorNode::creator() 23 | { 24 | return new ArrayConstructorNode(); 25 | } 26 | 27 | MStatus ArrayConstructorNode::initialize() 28 | { 29 | MStatus status; 30 | 31 | MFnNumericAttribute N; 32 | MFnTypedAttribute T; 33 | 34 | aSize = N.create("size", "size", MFnNumericData::kInt, 8.0, &status); 35 | N.setKeyable(true); 36 | N.setStorable(true); 37 | N.setWritable(true); 38 | N.setDefault(8); 39 | 40 | aInput = N.create("input", "i", MFnNumericData::kDouble, 0.0, &status); 41 | N.setKeyable(false); 42 | N.setStorable(true); 43 | N.setWritable(true); 44 | N.setArray(true); 45 | 46 | aOutput = T.create("output", "o", MFnData::kDoubleArray, &status); 47 | T.setKeyable(false); 48 | T.setChannelBox(false); 49 | T.setWritable(false); 50 | T.setStorable(false); 51 | 52 | addAttribute(aSize); 53 | addAttribute(aInput); 54 | addAttribute(aOutput); 55 | 56 | attributeAffects(aSize, aOutput); 57 | attributeAffects(aInput, aOutput); 58 | 59 | return MS::kSuccess; 60 | } 61 | 62 | void ArrayConstructorNode::postConstructor() 63 | { 64 | this->setExistWithoutOutConnections(true); 65 | } 66 | 67 | MStatus ArrayConstructorNode::compute(const MPlug& plug, MDataBlock& data) 68 | { 69 | if (plug != aOutput) 70 | return MS::kUnknownParameter; 71 | 72 | MStatus status; 73 | 74 | int index; 75 | 76 | MArrayDataHandle inputArrayHandle = data.inputArrayValue(aInput); 77 | int inputSize = inputArrayHandle.elementCount(); 78 | int outputSize = data.inputValue(aSize).asInt(); 79 | 80 | MDoubleArray outputArray(outputSize); 81 | 82 | for (int i = 0; i < inputSize; i++) 83 | { 84 | index = inputArrayHandle.elementIndex(); 85 | 86 | if (index >= outputSize) break; 87 | 88 | outputArray[index] = inputArrayHandle.inputValue().asDouble(); 89 | 90 | if (!inputArrayHandle.next()) break; 91 | } 92 | 93 | MFnDoubleArrayData outputArrayData; 94 | MObject outputData = outputArrayData.create(outputArray, &status); 95 | CHECK_MSTATUS_AND_RETURN_IT(status); 96 | 97 | MDataHandle outputHandle = data.outputValue(aOutput); 98 | outputHandle.setMObject(outputData); 99 | outputHandle.setClean(); 100 | 101 | return MS::kSuccess; 102 | } -------------------------------------------------------------------------------- /src/n_clamp.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (c) 2016 Ryan Porter - arrayNodes 3 | You may use, distribute, or modify this code under the terms of the MIT license. 4 | */ 5 | 6 | #include 7 | 8 | #include "n_clamp.h" 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | using namespace std; 19 | 20 | MObject ClampArrayNode::aInput; 21 | MObject ClampArrayNode::aMin; 22 | MObject ClampArrayNode::aMax; 23 | MObject ClampArrayNode::aOutput; 24 | 25 | void* ClampArrayNode::creator() 26 | { 27 | return new ClampArrayNode(); 28 | } 29 | 30 | MStatus ClampArrayNode::initialize() 31 | { 32 | MStatus status; 33 | 34 | MFnTypedAttribute T; 35 | MFnNumericAttribute N; 36 | 37 | aInput = T.create("input", "i", MFnData::kDoubleArray); 38 | T.setKeyable(false); 39 | T.setStorable(true); 40 | T.setWritable(true); 41 | 42 | aMin = N.create("min", "mn", MFnNumericData::kDouble); 43 | N.setKeyable(true); 44 | N.setStorable(true); 45 | N.setWritable(true); 46 | N.setDefault(0.0); 47 | 48 | aMax = N.create("max", "max", MFnNumericData::kDouble); 49 | N.setKeyable(true); 50 | N.setStorable(true); 51 | N.setWritable(true); 52 | N.setDefault(1.0); 53 | 54 | aOutput = T.create("output", "o", MFnData::kDoubleArray); 55 | T.setKeyable(false); 56 | T.setChannelBox(false); 57 | T.setWritable(false); 58 | T.setStorable(false); 59 | 60 | addAttribute(aInput); 61 | addAttribute(aMin); 62 | addAttribute(aMax); 63 | addAttribute(aOutput); 64 | 65 | attributeAffects(aInput, aOutput); 66 | attributeAffects(aMin, aOutput); 67 | attributeAffects(aMax, aOutput); 68 | 69 | return MS::kSuccess; 70 | } 71 | 72 | void ClampArrayNode::postConstructor() 73 | { 74 | this->setExistWithoutOutConnections(true); 75 | } 76 | 77 | MStatus ClampArrayNode::compute(const MPlug& plug, MDataBlock& data) 78 | { 79 | if (plug != aOutput) 80 | return MS::kUnknownParameter; 81 | 82 | MStatus status; 83 | 84 | double mn = data.inputValue(aMin).asDouble(); 85 | double mx = data.inputValue(aMax).asDouble(); 86 | 87 | MDataHandle inputHandle = data.inputValue(aInput); 88 | MFnDoubleArrayData inputArrayData(inputHandle.data()); 89 | MDoubleArray inputArray = inputArrayData.array(); 90 | 91 | int numValues = inputArrayData.length(); 92 | 93 | MDoubleArray outputArray(numValues); 94 | 95 | double value; 96 | 97 | for (int i = 0; i < numValues; i++) 98 | { 99 | value = inputArray[i]; 100 | value = max(mn, min(value, mx)); 101 | outputArray.set(value, i); 102 | } 103 | 104 | MDataHandle outputHandle = data.outputValue(aOutput); 105 | 106 | MFnDoubleArrayData outputArrayData; 107 | MObject outputData = outputArrayData.create(outputArray); 108 | 109 | outputHandle.setMObject(outputData); 110 | outputHandle.setClean(); 111 | 112 | return MS::kSuccess; 113 | } -------------------------------------------------------------------------------- /src/n_ctorAngle.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (c) 2016 Ryan Porter - arrayNodes 3 | You may use, distribute, or modify this code under the terms of the MIT license. 4 | */ 5 | 6 | #include "n_ctorAngle.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | MObject ArrayAngleConstructorNode::aSize; 21 | MObject ArrayAngleConstructorNode::aInput; 22 | MObject ArrayAngleConstructorNode::aOutput; 23 | 24 | void* ArrayAngleConstructorNode::creator() 25 | { 26 | return new ArrayAngleConstructorNode(); 27 | } 28 | 29 | MStatus ArrayAngleConstructorNode::initialize() 30 | { 31 | MStatus status; 32 | 33 | MFnNumericAttribute N; 34 | MFnTypedAttribute T; 35 | MFnUnitAttribute U; 36 | 37 | aSize = N.create("size", "size", MFnNumericData::kInt, 8.0, &status); 38 | N.setKeyable(true); 39 | N.setStorable(true); 40 | N.setWritable(true); 41 | N.setDefault(8); 42 | 43 | aInput = U.create("input", "i", MFnUnitAttribute::kAngle, 0.0, &status); 44 | U.setKeyable(false); 45 | U.setStorable(true); 46 | U.setWritable(true); 47 | U.setArray(true); 48 | 49 | aOutput = T.create("output", "o", MFnData::kDoubleArray, &status); 50 | T.setKeyable(false); 51 | T.setChannelBox(false); 52 | T.setWritable(false); 53 | T.setStorable(false); 54 | 55 | addAttribute(aSize); 56 | addAttribute(aInput); 57 | addAttribute(aOutput); 58 | 59 | attributeAffects(aSize, aOutput); 60 | attributeAffects(aInput, aOutput); 61 | 62 | return MS::kSuccess; 63 | } 64 | 65 | void ArrayAngleConstructorNode::postConstructor() 66 | { 67 | this->setExistWithoutOutConnections(true); 68 | } 69 | 70 | MStatus ArrayAngleConstructorNode::compute(const MPlug& plug, MDataBlock& data) 71 | { 72 | if (plug != aOutput) 73 | return MS::kUnknownParameter; 74 | 75 | MStatus status; 76 | 77 | int index; 78 | 79 | MArrayDataHandle inputArrayHandle = data.inputArrayValue(aInput); 80 | int inputSize = inputArrayHandle.elementCount(); 81 | int outputSize = data.inputValue(aSize).asInt(); 82 | 83 | MDoubleArray outputArray(outputSize); 84 | 85 | MAngle::Unit uiUnit = MAngle::uiUnit(); 86 | 87 | for (int i = 0; i < inputSize; i++) 88 | { 89 | index = inputArrayHandle.elementIndex(); 90 | 91 | if (index >= outputSize) break; 92 | 93 | if (uiUnit == MAngle::kRadians) 94 | { 95 | outputArray[index] = inputArrayHandle.inputValue().asAngle().asRadians(); 96 | } else { 97 | outputArray[index] = inputArrayHandle.inputValue().asAngle().asDegrees(); 98 | } 99 | 100 | if (!inputArrayHandle.next()) break; 101 | } 102 | 103 | MFnDoubleArrayData outputArrayData; 104 | MObject outputData = outputArrayData.create(outputArray, &status); 105 | CHECK_MSTATUS_AND_RETURN_IT(status); 106 | 107 | MDataHandle outputHandle = data.outputValue(aOutput); 108 | outputHandle.setMObject(outputData); 109 | outputHandle.setClean(); 110 | 111 | return MS::kSuccess; 112 | } -------------------------------------------------------------------------------- /src/n_reduce.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (c) 2016 Ryan Porter - arrayNodes 3 | You may use, distribute, or modify this code under the terms of the MIT license. 4 | */ 5 | 6 | #include 7 | 8 | #include "n_reduce.h" 9 | #include "utils.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace std; 23 | 24 | MObject ReduceArrayNode::aInput; 25 | MObject ReduceArrayNode::aOperation; 26 | MObject ReduceArrayNode::aOutput; 27 | 28 | const short kLENGTH = 9; 29 | 30 | void* ReduceArrayNode::creator() 31 | { 32 | return new ReduceArrayNode(); 33 | } 34 | 35 | MStatus ReduceArrayNode::initialize() 36 | { 37 | MStatus status; 38 | 39 | MFnTypedAttribute T; 40 | MFnNumericAttribute N; 41 | MFnEnumAttribute E; 42 | 43 | aInput = T.create("input", "i", MFnData::kDoubleArray); 44 | T.setKeyable(false); 45 | T.setChannelBox(false); 46 | T.setStorable(true); 47 | T.setWritable(true); 48 | 49 | aOutput = N.create("output", "o", MFnNumericData::kDouble, 0.0); 50 | N.setKeyable(false); 51 | N.setChannelBox(false); 52 | N.setWritable(false); 53 | N.setStorable(false); 54 | 55 | aOperation = E.create("operation", "operation"); 56 | E.addField("No Operation", kNO_OP); 57 | E.addField("Sum", kSUM); 58 | E.addField("Difference", kDIFFERENCE); 59 | E.addField("Average", kAVERAGE); 60 | E.addField("Product", kPRODUCT); 61 | E.addField("Quotient", kQUOTIENT); 62 | E.addField("Exponent", kEXPONENT); 63 | E.addField("Minimum", kMIN); 64 | E.addField("Maximum", kMAX); 65 | E.addField("Length", kLENGTH); 66 | E.setKeyable(true); 67 | E.setStorable(true); 68 | E.setWritable(true); 69 | 70 | addAttribute(aOperation); 71 | addAttribute(aInput); 72 | addAttribute(aOutput); 73 | 74 | attributeAffects(aOperation, aOutput); 75 | attributeAffects(aInput, aOutput); 76 | 77 | return MS::kSuccess; 78 | } 79 | 80 | void ReduceArrayNode::postConstructor() 81 | { 82 | this->setExistWithoutOutConnections(true); 83 | } 84 | 85 | MStatus ReduceArrayNode::compute(const MPlug& plug, MDataBlock& data) 86 | { 87 | if (plug != aOutput) 88 | return MS::kUnknownParameter; 89 | 90 | MStatus status; 91 | 92 | MDataHandle inputHandle = data.inputValue(aInput, &status); 93 | CHECK_MSTATUS_AND_RETURN_IT(status); 94 | 95 | MFnDoubleArrayData inputArrayData(inputHandle.data()); 96 | MDoubleArray inputArray = inputArrayData.array(); 97 | int numInputs = inputArray.length(); 98 | 99 | short operation = data.inputValue(aOperation).asShort(); 100 | 101 | double output = numInputs > 0 ? inputArray[0] : 0.0; 102 | 103 | if (operation == kLENGTH) 104 | { 105 | output = double(numInputs); 106 | } else { 107 | for (int i = 1; i < numInputs; i++) 108 | { 109 | output = computeOutput(output, inputArray[i], operation, status); 110 | 111 | if (!status) 112 | { 113 | reportComputeError(this, operation); 114 | break; 115 | } 116 | } 117 | 118 | if (operation == kAVERAGE && numInputs > 0) 119 | output /= double(numInputs); 120 | } 121 | 122 | MDataHandle outputHandle = data.outputValue(this->aOutput); 123 | outputHandle.setDouble(output); 124 | outputHandle.setClean(); 125 | 126 | return MS::kSuccess; 127 | } -------------------------------------------------------------------------------- /src/n_slice.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (c) 2016 Ryan Porter - arrayNodes 3 | You may use, distribute, or modify this code under the terms of the MIT license. 4 | */ 5 | 6 | #include 7 | 8 | #include "n_slice.h" 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | using namespace std; 20 | 21 | MObject SliceArrayNode::aInput; 22 | MObject SliceArrayNode::aStartIndex; 23 | MObject SliceArrayNode::aStopIndex; 24 | MObject SliceArrayNode::aStepSize; 25 | MObject SliceArrayNode::aOutput; 26 | 27 | void* SliceArrayNode::creator() 28 | { 29 | return new SliceArrayNode(); 30 | } 31 | 32 | MStatus SliceArrayNode::initialize() 33 | { 34 | MStatus status; 35 | 36 | MFnTypedAttribute T; 37 | MFnNumericAttribute N; 38 | 39 | aInput = T.create("input", "i", MFnData::kDoubleArray); 40 | T.setKeyable(false); 41 | T.setStorable(true); 42 | T.setWritable(true); 43 | 44 | aStartIndex = N.create("start", "st", MFnNumericData::kInt); 45 | N.setKeyable(true); 46 | N.setStorable(true); 47 | N.setWritable(true); 48 | 49 | aStopIndex = N.create("stop", "sp", MFnNumericData::kInt, -1); 50 | N.setKeyable(true); 51 | N.setStorable(true); 52 | N.setWritable(true); 53 | N.setDefault(-1); 54 | 55 | aStepSize = N.create("step", "ss", MFnNumericData::kInt, 1); 56 | N.setKeyable(true); 57 | N.setStorable(true); 58 | N.setWritable(true); 59 | N.setDefault(1); 60 | 61 | aOutput = T.create("output", "o", MFnData::kDoubleArray); 62 | T.setKeyable(false); 63 | T.setChannelBox(false); 64 | T.setWritable(false); 65 | T.setStorable(false); 66 | 67 | addAttribute(aInput); 68 | addAttribute(aStartIndex); 69 | addAttribute(aStopIndex); 70 | addAttribute(aStepSize); 71 | addAttribute(aOutput); 72 | 73 | attributeAffects(aInput, aOutput); 74 | attributeAffects(aStartIndex, aOutput); 75 | attributeAffects(aStopIndex, aOutput); 76 | attributeAffects(aStepSize, aOutput); 77 | 78 | return MS::kSuccess; 79 | } 80 | 81 | void SliceArrayNode::postConstructor() 82 | { 83 | this->setExistWithoutOutConnections(true); 84 | } 85 | 86 | MStatus SliceArrayNode::compute(const MPlug& plug, MDataBlock& data) 87 | { 88 | if (plug != aOutput) 89 | return MS::kUnknownParameter; 90 | 91 | MStatus status; 92 | 93 | int start = data.inputValue(aStartIndex).asInt(); 94 | int stop = data.inputValue(aStopIndex).asInt(); 95 | int step = data.inputValue(aStepSize).asInt(); 96 | 97 | if (step == 0) 98 | { 99 | MGlobal::displayWarning(this->name() + " - slice step size cannot be zero."); 100 | return MS::kInvalidParameter; 101 | } 102 | 103 | MDataHandle inputHandle = data.inputValue(aInput); 104 | MFnDoubleArrayData inputArrayData(inputHandle.data()); 105 | 106 | int numInputs = inputArrayData.length(); 107 | 108 | vector slice = vector(); 109 | 110 | start = start >= 0 ? start : numInputs + start; 111 | stop = stop >= 0 ? stop : numInputs + stop; 112 | 113 | int index = start; 114 | 115 | while ((step > 0) ? (index < stop) : (index > stop)) 116 | { 117 | if (index >= 0 && index < numInputs) 118 | slice.push_back(index); 119 | 120 | index += step; 121 | } 122 | 123 | int outputSize = int(slice.size()); 124 | MDoubleArray outputArray(outputSize); 125 | 126 | for (int i = 0; i < outputSize; i++) 127 | { 128 | outputArray.set(inputArrayData[slice[i]], i); 129 | } 130 | 131 | MFnDoubleArrayData outputArrayData; 132 | MObject outputData = outputArrayData.create(outputArray); 133 | 134 | MDataHandle outputHandle = data.outputValue(aOutput); 135 | outputHandle.setMObject(outputData); 136 | outputHandle.setClean(); 137 | 138 | return MS::kSuccess; 139 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | .vscode 13 | 14 | # Build results 15 | [Bb]uild/ 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Tt]est/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # DNX 46 | project.lock.json 47 | artifacts/ 48 | 49 | *_i.c 50 | *_p.c 51 | *_i.h 52 | *.ilk 53 | *.meta 54 | *.obj 55 | *.pch 56 | *.pdb 57 | *.pgc 58 | *.pgd 59 | *.rsp 60 | *.sbr 61 | *.tlb 62 | *.tli 63 | *.tlh 64 | *.tmp 65 | *.tmp_proj 66 | *.log 67 | *.vspscc 68 | *.vssscc 69 | .builds 70 | *.pidb 71 | *.svclog 72 | *.scc 73 | *.vcxproj 74 | *.vcxproj.filters 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | 88 | # Visual Studio profiler 89 | *.psess 90 | *.vsp 91 | *.vspx 92 | *.sap 93 | 94 | # TFS 2012 Local Workspace 95 | $tf/ 96 | 97 | # Guidance Automation Toolkit 98 | *.gpState 99 | 100 | # ReSharper is a .NET coding add-in 101 | _ReSharper*/ 102 | *.[Rr]e[Ss]harper 103 | *.DotSettings.user 104 | 105 | # JustCode is a .NET coding add-in 106 | .JustCode 107 | 108 | # TeamCity is a build add-in 109 | _TeamCity* 110 | 111 | # DotCover is a Code Coverage Tool 112 | *.dotCover 113 | 114 | # NCrunch 115 | _NCrunch_* 116 | .*crunch*.local.xml 117 | nCrunchTemp_* 118 | 119 | # MightyMoose 120 | *.mm.* 121 | AutoTest.Net/ 122 | 123 | # Web workbench (sass) 124 | .sass-cache/ 125 | 126 | # Installshield output folder 127 | [Ee]xpress/ 128 | 129 | # doxygen files 130 | Doxy* 131 | 132 | # DocProject is a documentation generator add-in 133 | DocProject/buildhelp/ 134 | DocProject/Help/*.HxT 135 | DocProject/Help/*.HxC 136 | DocProject/Help/*.hhc 137 | DocProject/Help/*.hhk 138 | DocProject/Help/*.hhp 139 | DocProject/Help/Html2 140 | DocProject/Help/html 141 | 142 | # Click-Once directory 143 | publish/ 144 | 145 | # Publish Web Output 146 | *.[Pp]ublish.xml 147 | *.azurePubxml 148 | # TODO: Comment the next line if you want to checkin your web deploy settings 149 | # but database connection strings (with potential passwords) will be unencrypted 150 | *.pubxml 151 | *.publishproj 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Microsoft Azure ApplicationInsights config file 174 | ApplicationInsights.config 175 | 176 | # Windows Store app package directory 177 | AppPackages/ 178 | BundleArtifacts/ 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.pfx 193 | *.publishsettings 194 | node_modules/ 195 | orleans.codegen.cs 196 | 197 | # RIA/Silverlight projects 198 | Generated_Code/ 199 | 200 | # Backup & report files from converting an old project file 201 | # to a newer Visual Studio version. Backup files are not needed, 202 | # because we have git ;-) 203 | _UpgradeReport_Files/ 204 | Backup*/ 205 | UpgradeLog*.XML 206 | UpgradeLog*.htm 207 | 208 | # SQL Server files 209 | *.mdf 210 | *.ldf 211 | 212 | # Business Intelligence projects 213 | *.rdl.data 214 | *.bim.layout 215 | *.bim_*.settings 216 | 217 | # Microsoft Fakes 218 | FakesAssemblies/ 219 | 220 | # GhostDoc plugin setting file 221 | *.GhostDoc.xml 222 | 223 | # Node.js Tools for Visual Studio 224 | .ntvs_analysis.dat 225 | 226 | # Visual Studio 6 build log 227 | *.plg 228 | 229 | # Visual Studio 6 workspace options file 230 | *.opt 231 | 232 | # Visual Studio LightSwitch build output 233 | **/*.HTMLClient/GeneratedArtifacts 234 | **/*.DesktopClient/GeneratedArtifacts 235 | **/*.DesktopClient/ModelManifest.xml 236 | **/*.Server/GeneratedArtifacts 237 | **/*.Server/ModelManifest.xml 238 | _Pvt_Extensions 239 | 240 | # Paket dependency manager 241 | .paket/paket.exe 242 | 243 | # FAKE - F# Make 244 | .fake/ 245 | -------------------------------------------------------------------------------- /src/n_scalar.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (c) 2016 Ryan Porter - arrayNodes 3 | You may use, distribute, or modify this code under the terms of the MIT license. 4 | */ 5 | 6 | /*----------------------------------------------------------------------------- 7 | arrayScalarOp 8 | Performs an arithmetic operation on for each value of the input array with the 9 | value and a scalar value as the parameters. There is an option to toggle the 10 | order of the parameters - f(element, scalar) or f(scalar, element) 11 | 12 | Operations 13 | - Add 14 | - Subtract 15 | - Multiply 16 | - Divide 17 | - Power 18 | 19 | Input Attributes 20 | - input (doubleArray) 21 | - scalar (double) 22 | - order (enum) 23 | - operation (enum) 24 | 25 | Output Attributes 26 | - output (doubleArray) 27 | -----------------------------------------------------------------------------*/ 28 | 29 | #include "n_scalar.h" 30 | #include "utils.h" 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | MObject ArrayScalarOperationNode::aInput; 44 | MObject ArrayScalarOperationNode::aScalar; 45 | MObject ArrayScalarOperationNode::aOperation; 46 | MObject ArrayScalarOperationNode::aOrder; 47 | MObject ArrayScalarOperationNode::aOutput; 48 | 49 | const short ELEMENT_SCALAR = 0; 50 | const short SCALAR_ELEMENT = 1; 51 | 52 | #define ALMOST_ZERO 1e-5 53 | 54 | void* ArrayScalarOperationNode::creator() 55 | { 56 | return new ArrayScalarOperationNode(); 57 | } 58 | 59 | MStatus ArrayScalarOperationNode::initialize() 60 | { 61 | MStatus status; 62 | 63 | MFnTypedAttribute T; 64 | MFnNumericAttribute N; 65 | MFnEnumAttribute E; 66 | 67 | aInput = T.create("input", "i", MFnData::kDoubleArray); 68 | T.setKeyable(false); 69 | T.setChannelBox(false); 70 | T.setStorable(true); 71 | T.setWritable(true); 72 | 73 | aScalar = N.create("scalar", "s", MFnNumericData::kDouble); 74 | N.setKeyable(true); 75 | N.setChannelBox(true); 76 | N.setStorable(true); 77 | N.setWritable(true); 78 | 79 | aOutput = T.create("output", "o", MFnData::kDoubleArray); 80 | T.setKeyable(false); 81 | T.setChannelBox(false); 82 | T.setWritable(false); 83 | T.setStorable(false); 84 | 85 | aOperation = E.create("operation", "operation"); 86 | E.addField("No Operation", kNO_OP); 87 | E.addField("Sum", kSUM); 88 | E.addField("Difference", kDIFFERENCE), 89 | E.addField("Product", kPRODUCT); 90 | E.addField("Quotient", kQUOTIENT); 91 | E.addField("Exponent", kEXPONENT); 92 | E.setKeyable(true); 93 | E.setStorable(true); 94 | E.setWritable(true); 95 | 96 | aOrder = E.create("argumentOrder", "ao"); 97 | E.addField("Element First", 0); 98 | E.addField("Scalar First", 1); 99 | E.setKeyable(true); 100 | E.setStorable(true); 101 | E.setWritable(true); 102 | 103 | addAttribute(aOperation); 104 | addAttribute(aOrder); 105 | addAttribute(aInput); 106 | addAttribute(aScalar); 107 | addAttribute(aOutput); 108 | 109 | attributeAffects(aOperation, aOutput); 110 | attributeAffects(aOrder, aOutput); 111 | attributeAffects(aInput, aOutput); 112 | attributeAffects(aScalar, aOutput); 113 | 114 | return MS::kSuccess; 115 | } 116 | 117 | void ArrayScalarOperationNode::postConstructor() 118 | { 119 | this->setExistWithoutOutConnections(true); 120 | } 121 | 122 | MStatus ArrayScalarOperationNode::compute(const MPlug& plug, MDataBlock& data) 123 | { 124 | if (plug != aOutput) 125 | return MS::kUnknownParameter; 126 | 127 | MStatus status; 128 | 129 | MDataHandle inputHandle = data.inputValue(aInput, &status); 130 | CHECK_MSTATUS_AND_RETURN_IT(status); 131 | 132 | MFnDoubleArrayData input(inputHandle.data()); 133 | double scalar = data.inputValue(aScalar).asDouble(); 134 | short operation = data.inputValue(aOperation).asShort(); 135 | bool order = data.inputValue(aOrder).asShort() == ELEMENT_SCALAR; 136 | 137 | double output; 138 | double lhs; 139 | double rhs; 140 | 141 | int size = input.length(); 142 | MDoubleArray outputArray(size); 143 | 144 | for (int i = 0; i < size; i++) 145 | { 146 | lhs = order ? input[i] : scalar; 147 | rhs = order ? scalar : input[i]; 148 | 149 | output = computeOutput(lhs, rhs, operation, status); 150 | 151 | if (!status) { reportComputeError(this, operation); } 152 | 153 | outputArray.set(output, i); 154 | } 155 | 156 | MDataHandle outputHandle = data.outputValue(this->aOutput); 157 | MFnDoubleArrayData outputArrayData; 158 | MObject outputData = outputArrayData.create(outputArray); 159 | 160 | outputHandle.setMObject(outputData); 161 | outputHandle.setClean(); 162 | 163 | return MS::kSuccess; 164 | } -------------------------------------------------------------------------------- /src/n_normalize.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (c) 2016 Ryan Porter - arrayNodes 3 | You may use, distribute, or modify this code under the terms of the MIT license. 4 | */ 5 | 6 | #include "n_normalize.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | using namespace std; 26 | 27 | MObject NormalizeArrayNode::aInput; 28 | MObject NormalizeArrayNode::aElementwise; 29 | MObject NormalizeArrayNode::aOutput; 30 | 31 | #define TOLERANCE 1e-5 32 | 33 | void* NormalizeArrayNode::creator() 34 | { 35 | return new NormalizeArrayNode(); 36 | } 37 | 38 | MStatus NormalizeArrayNode::initialize() 39 | { 40 | MStatus status; 41 | 42 | MFnTypedAttribute T; 43 | MFnNumericAttribute N; 44 | 45 | aInput = T.create("input", "i", MFnData::kDoubleArray); 46 | T.setKeyable(false); 47 | T.setChannelBox(false); 48 | T.setStorable(true); 49 | T.setWritable(true); 50 | T.setArray(true); 51 | 52 | aElementwise = N.create("elementwise", "ew", MFnNumericData::kBoolean, 1.0); 53 | N.setKeyable(true); 54 | N.setChannelBox(true); 55 | N.setStorable(true); 56 | N.setWritable(true); 57 | 58 | aOutput = T.create("output", "o", MFnData::kDoubleArray); 59 | T.setKeyable(false); 60 | T.setChannelBox(false); 61 | T.setWritable(false); 62 | T.setStorable(false); 63 | T.setArray(true); 64 | T.setUsesArrayDataBuilder(true); 65 | 66 | addAttribute(aInput); 67 | addAttribute(aElementwise); 68 | addAttribute(aOutput); 69 | 70 | attributeAffects(aInput, aOutput); 71 | attributeAffects(aElementwise, aOutput); 72 | 73 | return MS::kSuccess; 74 | } 75 | 76 | void NormalizeArrayNode::postConstructor() 77 | { 78 | this->setExistWithoutOutConnections(true); 79 | } 80 | 81 | MStatus NormalizeArrayNode::compute(const MPlug& plug, MDataBlock& data) 82 | { 83 | if (plug != aOutput && plug.parent() != aOutput) 84 | return MS::kUnknownParameter; 85 | 86 | MStatus status; 87 | 88 | MArrayDataHandle inputArrayHandle = data.inputValue(aInput, &status); 89 | CHECK_MSTATUS_AND_RETURN_IT(status); 90 | 91 | int numElements = inputArrayHandle.elementCount(); 92 | bool elementwise = data.inputValue(aElementwise).asBool(); 93 | 94 | vector sizes = vector(numElements); 95 | vector indices = vector(numElements); 96 | vector inputs = vector(numElements); 97 | 98 | for (int i = 0; i < numElements; i++) 99 | { 100 | MDataHandle inputHnd = inputArrayHandle.inputValue(&status); 101 | CHECK_MSTATUS_AND_RETURN_IT(status); 102 | 103 | MFnDoubleArrayData inputArrayData(inputHnd.data()); 104 | MDoubleArray inputArray = inputArrayData.array(&status); 105 | 106 | inputs[i] = status ? MDoubleArray(inputArray) : MDoubleArray(); 107 | sizes[i] = int(inputArray.length()); 108 | indices[i] = inputArrayHandle.elementIndex(); 109 | 110 | if (!inputArrayHandle.next()) continue; 111 | } 112 | 113 | int numOutputs = elementwise ? *max_element(sizes.begin(), sizes.end()) : numElements; 114 | 115 | MArrayDataHandle outputHandle = data.outputValue(aOutput, &status); 116 | CHECK_MSTATUS_AND_RETURN_IT(status); 117 | 118 | vector sumsOfWeights = vector(numOutputs); 119 | 120 | for (int e = 0; e < numElements; e++) 121 | { 122 | for (int i = 0; i < sizes[e]; i++) 123 | { 124 | sumsOfWeights[elementwise ? i : e] += inputs[e][i]; 125 | } 126 | } 127 | 128 | for (int i = 0; i < numOutputs; i++) 129 | { 130 | sumsOfWeights[i] = abs(sumsOfWeights[i]) < TOLERANCE ? 0.0 : 1.0 / sumsOfWeights[i]; 131 | } 132 | 133 | vector outputs = vector(numElements); 134 | 135 | for (int i = 0; i < numElements; i++) 136 | { 137 | outputs[i] = MDoubleArray(elementwise ? numOutputs : sizes[i]); 138 | } 139 | 140 | for (int e = 0; e < numElements; e++) 141 | { 142 | for (int i = 0; i < sizes[e]; i++) 143 | { 144 | outputs[e][i] = inputs[e][i] * sumsOfWeights[elementwise ? i : e]; 145 | } 146 | } 147 | 148 | MArrayDataBuilder outputData = outputHandle.builder(&status); 149 | MFnDoubleArrayData outputArrayData; 150 | CHECK_MSTATUS_AND_RETURN_IT(status); 151 | 152 | for (int i = 0; i < numElements; i++) 153 | { 154 | MDataHandle outputHnd = outputData.addElement(indices[i], &status); 155 | CHECK_MSTATUS_AND_RETURN_IT(status); 156 | 157 | MObject data = outputArrayData.create(outputs[i], &status); 158 | CHECK_MSTATUS_AND_RETURN_IT(status); 159 | 160 | outputHnd.setMObject(data); 161 | } 162 | 163 | outputHandle.set(outputData); 164 | outputHandle.setAllClean(); 165 | 166 | return MS::kSuccess; 167 | } 168 | -------------------------------------------------------------------------------- /src/n_modify.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (c) 2016 Ryan Porter - arrayNodes 3 | You may use, distribute, or modify this code under the terms of the MIT license. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "n_modify.h" 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace std; 23 | 24 | MObject ModifyArrayNode::aInput; 25 | MObject ModifyArrayNode::aOperation; 26 | MObject ModifyArrayNode::aReverse; 27 | MObject ModifyArrayNode::aOutput; 28 | 29 | const short kNO_OP = 0; 30 | const short kSORT = 1; 31 | const short kABS = 2; 32 | const short kREFLECT_LEFT = 3; 33 | const short kREFLECT_RIGHT = 4; 34 | 35 | void* ModifyArrayNode::creator() 36 | { 37 | return new ModifyArrayNode(); 38 | } 39 | 40 | MStatus ModifyArrayNode::initialize() 41 | { 42 | MStatus status; 43 | 44 | MFnTypedAttribute T; 45 | MFnNumericAttribute N; 46 | MFnEnumAttribute E; 47 | 48 | aInput = T.create("input", "i", MFnData::kDoubleArray); 49 | T.setKeyable(false); 50 | T.setChannelBox(false); 51 | T.setStorable(true); 52 | T.setWritable(true); 53 | 54 | aOperation = E.create("operation", "operation"); 55 | E.addField("No Operation", kNO_OP); 56 | E.addField("Sort", kSORT); 57 | E.addField("Absolute Value", kABS); 58 | E.addField("Reflect Left", kREFLECT_LEFT); 59 | E.addField("Reflect Right", kREFLECT_RIGHT); 60 | E.setDefault(kNO_OP); 61 | E.setKeyable(true); 62 | E.setStorable(true); 63 | E.setWritable(true); 64 | 65 | aReverse = N.create("reverse", "rev", MFnNumericData::kBoolean); 66 | N.setKeyable(true); 67 | N.setChannelBox(true); 68 | N.setStorable(true); 69 | N.setWritable(true); 70 | 71 | aOutput = T.create("output", "o", MFnData::kDoubleArray); 72 | T.setKeyable(false); 73 | T.setChannelBox(false); 74 | T.setWritable(false); 75 | T.setStorable(false); 76 | 77 | addAttribute(aOperation); 78 | addAttribute(aInput); 79 | addAttribute(aReverse); 80 | addAttribute(aOutput); 81 | 82 | attributeAffects(aOperation, aOutput); 83 | attributeAffects(aInput, aOutput); 84 | attributeAffects(aReverse, aOutput); 85 | 86 | return MS::kSuccess; 87 | } 88 | 89 | void ModifyArrayNode::postConstructor() 90 | { 91 | this->setExistWithoutOutConnections(true); 92 | } 93 | 94 | MStatus ModifyArrayNode::compute(const MPlug& plug, MDataBlock& data) 95 | { 96 | if (plug != aOutput) 97 | return MS::kUnknownParameter; 98 | 99 | MStatus status; 100 | 101 | MFnDoubleArrayData inputArray(data.inputValue(aInput).data()); 102 | 103 | short op = data.inputValue(aOperation).asShort(); 104 | bool reverse = data.inputValue(aReverse).asBool(); 105 | 106 | int inputSize = int(inputArray.length()); 107 | int outputSize = 0; 108 | 109 | switch (op) 110 | { 111 | case kREFLECT_LEFT: 112 | case kREFLECT_RIGHT: 113 | outputSize = max(0, inputSize * 2 - 1); 114 | break; 115 | default: 116 | outputSize = inputSize; 117 | break; 118 | } 119 | 120 | std::vector values = std::vector(outputSize); 121 | MDoubleArray outputArray(outputSize); 122 | 123 | int index = 0; 124 | 125 | switch (op) 126 | { 127 | case kNO_OP: 128 | for (int i = 0; i < outputSize; i++) 129 | values[i] = inputArray[i]; 130 | break; 131 | case kSORT: 132 | for (int i = 0; i < outputSize; i++) 133 | values[i] = inputArray[i]; 134 | 135 | std::sort(values.begin(), values.end()); 136 | break; 137 | 138 | case kABS: 139 | for (int i = 0; i < outputSize; i++) 140 | values[i] = abs(inputArray[i]); 141 | break; 142 | 143 | case kREFLECT_LEFT: 144 | for (int i = inputSize - 1; i > 0; i--) 145 | { 146 | values[index] = inputArray[i]; 147 | index++; 148 | } 149 | 150 | for (int i = 0; i < inputSize; i++) 151 | { 152 | values[index] = inputArray[i]; 153 | index++; 154 | } 155 | break; 156 | 157 | case kREFLECT_RIGHT: 158 | for (int i = 0; i < inputSize - 1; i++) 159 | { 160 | values[index] = inputArray[i]; 161 | index++; 162 | } 163 | 164 | for (int i = inputSize - 1; i >= 0; i--) 165 | { 166 | values[index] = inputArray[i]; 167 | index++; 168 | } 169 | break; 170 | } 171 | 172 | for (int i = 0; i < outputSize; i++) 173 | { 174 | index = reverse ? outputSize - i - 1 : i; 175 | outputArray[i] = values[index]; 176 | } 177 | 178 | 179 | MDataHandle outputHandle = data.outputValue(this->aOutput); 180 | MFnDoubleArrayData output; 181 | MObject outputData = output.create(outputArray); 182 | 183 | outputHandle.setMObject(outputData); 184 | outputHandle.setClean(); 185 | 186 | return MS::kSuccess; 187 | } 188 | -------------------------------------------------------------------------------- /src/n_multi.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (c) 2016 Ryan Porter - arrayNodes 3 | You may use, distribute, or modify this code under the terms of the MIT license. 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | #include "n_multi.h" 10 | #include "utils.h" 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | using namespace std; 24 | 25 | MObject ArrayMultiOperatorNode::aInput; 26 | MObject ArrayMultiOperatorNode::aOperation; 27 | MObject ArrayMultiOperatorNode::aElementwise; 28 | MObject ArrayMultiOperatorNode::aOutput; 29 | 30 | void* ArrayMultiOperatorNode::creator() 31 | { 32 | return new ArrayMultiOperatorNode(); 33 | } 34 | 35 | MStatus ArrayMultiOperatorNode::initialize() 36 | { 37 | MStatus status; 38 | 39 | MFnEnumAttribute E; 40 | MFnNumericAttribute N; 41 | MFnTypedAttribute T; 42 | 43 | aInput = T.create("input", "i", MFnData::kDoubleArray); 44 | T.setKeyable(false); 45 | T.setChannelBox(false); 46 | T.setStorable(true); 47 | T.setWritable(true); 48 | T.setArray(true); 49 | 50 | aOperation = E.create("operation", "operation"); 51 | E.addField("No Operation", kNO_OP); 52 | E.addField("Sum", kSUM); 53 | E.addField("Difference", kDIFFERENCE); 54 | E.addField("Average", kAVERAGE); 55 | E.addField("Product", kPRODUCT); 56 | E.addField("Quotient", kQUOTIENT); 57 | E.addField("Exponent", kEXPONENT); 58 | E.setDefault(kSUM); 59 | E.setKeyable(true); 60 | E.setStorable(true); 61 | E.setWritable(true); 62 | 63 | aElementwise = N.create("elementwise", "ew", MFnNumericData::kBoolean); 64 | N.setDefault(true); 65 | N.setKeyable(true); 66 | N.setStorable(true); 67 | N.setWritable(true); 68 | 69 | aOutput = T.create("output", "o", MFnData::kDoubleArray); 70 | T.setKeyable(false); 71 | T.setChannelBox(false); 72 | T.setWritable(false); 73 | T.setStorable(false); 74 | 75 | addAttribute(aInput); 76 | addAttribute(aOperation); 77 | addAttribute(aElementwise); 78 | addAttribute(aOutput); 79 | 80 | attributeAffects(aOperation, aOutput); 81 | attributeAffects(aElementwise, aOutput); 82 | attributeAffects(aInput, aOutput); 83 | 84 | return MS::kSuccess; 85 | } 86 | 87 | void ArrayMultiOperatorNode::postConstructor() 88 | { 89 | this->setExistWithoutOutConnections(true); 90 | } 91 | 92 | MStatus ArrayMultiOperatorNode::compute(const MPlug& plug, MDataBlock& data) 93 | { 94 | if (plug != aOutput) 95 | return MS::kUnknownParameter; 96 | 97 | MStatus status; 98 | 99 | MArrayDataHandle inputArrayHandle = data.inputValue(aInput); 100 | 101 | short operation = data.inputValue(aOperation).asShort(); 102 | bool elementwise = data.inputValue(aElementwise).asBool(); 103 | 104 | int numInputs = inputArrayHandle.elementCount(); 105 | 106 | vector sizes = vector(numInputs); 107 | vector inputArrays = vector(numInputs); 108 | 109 | int numOutputs = 0; 110 | 111 | for (int i = 0; i < numInputs; i++) 112 | { 113 | MDataHandle inputHandle = inputArrayHandle.inputValue(); 114 | MFnDoubleArrayData inputArrayData(inputHandle.data()); 115 | MDoubleArray inputArray = inputArrayData.array(); 116 | 117 | numOutputs = max(int(inputArray.length()), numOutputs); 118 | 119 | inputArrays[i] = MDoubleArray(inputArray); 120 | 121 | if (!inputArrayHandle.next()) break; 122 | } 123 | 124 | numOutputs = elementwise ? numOutputs : numInputs; 125 | sort(inputArrays.begin(), inputArrays.end(), sortByLength); 126 | 127 | for (int i = 0; i < numInputs; i++) 128 | { 129 | sizes[i] = inputArrays[i].length(); 130 | } 131 | 132 | MDoubleArray outputArray(numOutputs); 133 | 134 | double value = 0.0; 135 | int numValues = 0; 136 | 137 | if (elementwise) 138 | { 139 | for (int i = 0; i < numOutputs; i++) 140 | { 141 | value = 0.0; 142 | numValues = 0; 143 | status = MS::kSuccess; 144 | 145 | if (int(inputArrays[0].length()) > i) { 146 | value = inputArrays[0][i]; 147 | 148 | for (int j = 1; j < numInputs; j++) 149 | { 150 | if (i >= sizes[j]) { break; } 151 | 152 | value = computeOutput(value, inputArrays[j][i], operation, status); 153 | numValues++; 154 | 155 | if (!status) { 156 | reportComputeError(this, operation); 157 | break; 158 | } 159 | } 160 | } 161 | 162 | if (operation == kAVERAGE && numValues > 0) 163 | value /= float(numValues + 1); 164 | 165 | outputArray.set(value, i); 166 | } 167 | } else { 168 | for (int i = 0; i < numInputs; i++) 169 | { 170 | value = sizes[i] > 0 ? inputArrays[i][0] : 0.0; 171 | numValues = 0; 172 | 173 | status = MS::kSuccess; 174 | 175 | for (int j = 1; j < sizes[i]; j++) 176 | { 177 | value = computeOutput(value, inputArrays[i][j], operation, status); 178 | numValues++; 179 | 180 | if (!status) 181 | { 182 | reportComputeError(this, operation); 183 | break; 184 | } 185 | } 186 | 187 | if (operation == kAVERAGE && numValues > 0) 188 | value /= float(numValues + 1); 189 | 190 | outputArray.set(value, i); 191 | } 192 | } 193 | 194 | MFnDoubleArrayData outputArrayData; 195 | MObject outputData = outputArrayData.create(outputArray); 196 | 197 | MDataHandle outputHandle = data.outputValue(aOutput); 198 | outputHandle.setMObject(outputData); 199 | outputHandle.setClean(); 200 | 201 | return MS::kSuccess; 202 | } -------------------------------------------------------------------------------- /src/n_remap.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (c) 2016 Ryan Porter - arrayNodes 3 | You may use, distribute, or modify this code under the terms of the MIT license. 4 | */ 5 | 6 | #include "n_remap.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | using namespace std; 29 | 30 | MObject RemapArrayValuesNode::aInput; 31 | MObject RemapArrayValuesNode::aInputMin; 32 | MObject RemapArrayValuesNode::aInputMax; 33 | MObject RemapArrayValuesNode::aOutputMin; 34 | MObject RemapArrayValuesNode::aOutputMax; 35 | MObject RemapArrayValuesNode::aRamp; 36 | MObject RemapArrayValuesNode::aOutput; 37 | 38 | void* RemapArrayValuesNode::creator() 39 | { 40 | return new RemapArrayValuesNode(); 41 | } 42 | 43 | MStatus RemapArrayValuesNode::initialize() 44 | { 45 | MStatus status; 46 | 47 | MFnCompoundAttribute C; 48 | MFnTypedAttribute T; 49 | MFnNumericAttribute N; 50 | MFnEnumAttribute E; 51 | 52 | aInput = T.create("input", "i", MFnData::kDoubleArray, &status); 53 | CHECK_MSTATUS_AND_RETURN_IT(status); 54 | T.setKeyable(false); 55 | T.setChannelBox(false); 56 | T.setStorable(true); 57 | T.setWritable(true); 58 | 59 | aInputMin = N.create("inputMin", "imn", MFnNumericData::kDouble, 0.0, &status); 60 | CHECK_MSTATUS_AND_RETURN_IT(status); 61 | N.setKeyable(true); 62 | N.setChannelBox(true); 63 | N.setStorable(true); 64 | N.setWritable(true); 65 | 66 | aInputMax = N.create("inputMax", "imx", MFnNumericData::kDouble, 0.0, &status); 67 | CHECK_MSTATUS_AND_RETURN_IT(status); 68 | N.setKeyable(true); 69 | N.setChannelBox(true); 70 | N.setStorable(true); 71 | N.setWritable(true); 72 | N.setDefault(1.0); 73 | 74 | aOutputMin = N.create("outputMin", "omn", MFnNumericData::kDouble, 0.0, &status); 75 | CHECK_MSTATUS_AND_RETURN_IT(status); 76 | N.setKeyable(true); 77 | N.setChannelBox(true); 78 | N.setStorable(true); 79 | N.setWritable(true); 80 | 81 | aOutputMax = N.create("outputMax", "omx", MFnNumericData::kDouble, 0.0, &status); 82 | CHECK_MSTATUS_AND_RETURN_IT(status); 83 | N.setKeyable(true); 84 | N.setChannelBox(true); 85 | N.setStorable(true); 86 | N.setWritable(true); 87 | N.setDefault(1.0); 88 | 89 | aRamp = MRampAttribute::createCurveRamp("values", "vl", &status); 90 | CHECK_MSTATUS_AND_RETURN_IT(status); 91 | 92 | aOutput = T.create("output", "o", MFnData::kDoubleArray, &status); 93 | CHECK_MSTATUS_AND_RETURN_IT(status); 94 | T.setKeyable(false); 95 | T.setChannelBox(false); 96 | T.setWritable(false); 97 | T.setStorable(false); 98 | 99 | addAttribute(aInput); 100 | addAttribute(aInputMin); 101 | addAttribute(aInputMax); 102 | addAttribute(aOutputMin); 103 | addAttribute(aOutputMax); 104 | addAttribute(aRamp); 105 | addAttribute(aOutput); 106 | 107 | attributeAffects(aInput, aOutput); 108 | attributeAffects(aInputMin, aOutput); 109 | attributeAffects(aInputMax, aOutput); 110 | attributeAffects(aOutputMin, aOutput); 111 | attributeAffects(aOutputMax, aOutput); 112 | attributeAffects(aRamp, aOutput); 113 | 114 | return MS::kSuccess; 115 | } 116 | 117 | void RemapArrayValuesNode::postConstructor() 118 | { 119 | this->setExistWithoutOutConnections(true); 120 | this->setInitialRampValues(); 121 | } 122 | 123 | MStatus RemapArrayValuesNode::setInitialRampValues() 124 | { 125 | MStatus status; 126 | 127 | MRampAttribute ramp(thisMObject(), aRamp); 128 | 129 | MFloatArray positions(1); 130 | positions.set(1.0, 0); 131 | 132 | MFloatArray values(1); 133 | values.set(1.0, 0); 134 | 135 | MIntArray interps(1); 136 | interps.set(1, 0); 137 | 138 | ramp.addEntries(positions, values, interps, &status); 139 | CHECK_MSTATUS_AND_RETURN_IT(status); 140 | 141 | return MS::kSuccess; 142 | } 143 | 144 | MStatus RemapArrayValuesNode::compute(const MPlug& plug, MDataBlock& data) 145 | { 146 | if (plug != aOutput) 147 | return MS::kUnknownParameter; 148 | 149 | MStatus status; 150 | 151 | MFnDoubleArrayData input(data.inputValue(aInput).data()); 152 | float inputMin = float(data.inputValue(aInputMin).asDouble()); 153 | float inputMax = float(data.inputValue(aInputMax).asDouble()); 154 | float outputMin = float(data.inputValue(aOutputMin).asDouble()); 155 | float outputMax = float(data.inputValue(aOutputMax).asDouble()); 156 | 157 | int size = input.length(); 158 | MDoubleArray outputArray(size); 159 | 160 | MRampAttribute ramp(thisMObject(), aRamp, &status); 161 | CHECK_MSTATUS_AND_RETURN_IT(status); 162 | 163 | MFloatArray positions; 164 | MFloatArray values; 165 | MIntArray interps; 166 | MIntArray indices; 167 | 168 | ramp.getEntries(indices, positions, values, interps); 169 | 170 | int numIndices = indices.length(); 171 | 172 | float inValue = 0.0; 173 | float outValue = 0.0; 174 | 175 | for (int i = 0; i < size; i++) 176 | { 177 | inValue = float(input[i]); 178 | 179 | inValue = remapValue(inValue, inputMin, inputMax); 180 | 181 | if (numIndices > 0) 182 | { 183 | ramp.getValueAtPosition(inValue, outValue, &status); 184 | CHECK_MSTATUS_AND_RETURN_IT(status); 185 | } else { 186 | outValue = inValue; 187 | } 188 | 189 | outValue = remapValue(outValue, 0.0, 1.0, outputMin, outputMax); 190 | 191 | outputArray.set(double(outValue), i); 192 | } 193 | 194 | MDataHandle outputHandle = data.outputValue(aOutput); 195 | MFnDoubleArrayData output; 196 | MObject outputData = output.create(outputArray); 197 | 198 | outputHandle.setMObject(outputData); 199 | outputHandle.setClean(); 200 | 201 | return MS::kSuccess; 202 | } 203 | 204 | float RemapArrayValuesNode::remapValue(float inValue, float inputMin, float inputMax, float outputMin, float outputMax) 205 | { 206 | float d = (inputMax - inputMin); 207 | float result = 0.0; 208 | 209 | if (abs(d) > FLT_EPSILON) 210 | { 211 | result = outputMin + ((inValue - inputMin) * (outputMax - outputMin) / d); 212 | } else { 213 | result = outputMin; 214 | } 215 | 216 | return result; 217 | } 218 | -------------------------------------------------------------------------------- /src/pluginMain.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (c) 2016 Ryan Porter 3 | */ 4 | 5 | /* 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | /** 26 | @mainpage Array Nodes 27 | 28 | @author: Ryan Porter 29 | @version: 1.0.0 30 | 31 | @sa https://github.com/yantor3d 32 | 33 | ## Description 34 | A set of nodes for performing calculates on sets of values in a single 35 | node rather than in dozens or hundreds of nodes. This allows for the 36 | construction of a more compact node graph that won't get bogged down by 37 | tens or hundreds of identical sub-graphs. 38 | 39 | ## Nodes 40 | - arrayCtor 41 | - arrayAngleCtor 42 | - arrayIter 43 | - arrayAngleIter 44 | - arrayMultiOp 45 | - arrayScalarOp 46 | - chainArray 47 | - clampArray 48 | - modifyArray 49 | - normalizeArray 50 | - reduceArray 51 | - remapArrayValues 52 | - sliceArray 53 | 54 | ## Commands 55 | - n/a 56 | */ 57 | 58 | #include "n_chain.h" 59 | #include "n_clamp.h" 60 | #include "n_ctor.h" 61 | #include "n_ctorAngle.h" 62 | #include "n_iter.h" 63 | #include "n_iterAngle.h" 64 | #include "n_modify.h" 65 | #include "n_multi.h" 66 | #include "n_normalize.h" 67 | #include "n_reduce.h" 68 | #include "n_remap.h" 69 | #include "n_scalar.h" 70 | #include "n_slice.h" 71 | 72 | #include 73 | #include 74 | #include 75 | 76 | const char* kAUTHOR = "Ryan Porter"; 77 | const char* kVERSION = "1.0.1"; 78 | const char* kREQUIRED_API_VERSION = "Any"; 79 | 80 | MTypeId ArrayConstructorNode::kNODE_ID = 0x00126b00; 81 | MString ArrayConstructorNode::kNODE_NAME = "arrayCtor"; 82 | 83 | MTypeId ArrayAngleConstructorNode::kNODE_ID = 0x00126b0a; 84 | MString ArrayAngleConstructorNode::kNODE_NAME = "arrayAngleCtor"; 85 | 86 | MTypeId ArrayIteratorNode::kNODE_ID = 0x00126b01; 87 | MString ArrayIteratorNode::kNODE_NAME = "arrayIter"; 88 | 89 | MTypeId ArrayAngleIteratorNode::kNODE_ID = 0x00126b0c; 90 | MString ArrayAngleIteratorNode::kNODE_NAME = "arrayAngleIter"; 91 | 92 | MTypeId ArrayMultiOperatorNode::kNODE_ID = 0x00126b02; 93 | MString ArrayMultiOperatorNode::kNODE_NAME = "arrayMultiOp"; 94 | 95 | MTypeId ArrayScalarOperationNode::kNODE_ID = 0x00126b03; 96 | MString ArrayScalarOperationNode::kNODE_NAME = "arrayScalarOp"; 97 | 98 | MTypeId ModifyArrayNode::kNODE_ID = 0x00126b04; 99 | MString ModifyArrayNode::kNODE_NAME = "modifyArray"; 100 | 101 | MTypeId NormalizeArrayNode::kNODE_ID = 0x00126b05; 102 | MString NormalizeArrayNode::kNODE_NAME = "normalizeArray"; 103 | 104 | MTypeId RemapArrayValuesNode::kNODE_ID = 0x00126b06; 105 | MString RemapArrayValuesNode::kNODE_NAME = "remapArrayValues"; 106 | 107 | MTypeId ClampArrayNode::kNODE_ID = 0x00126b07; 108 | MString ClampArrayNode::kNODE_NAME = "clampArray"; 109 | 110 | MTypeId SliceArrayNode::kNODE_ID = 0x00126b08; 111 | MString SliceArrayNode::kNODE_NAME = "sliceArray"; 112 | 113 | MTypeId ChainArraysNode::kNODE_ID = 0x00126b09; 114 | MString ChainArraysNode::kNODE_NAME = "chainArrays"; 115 | 116 | MTypeId ReduceArrayNode::kNODE_ID = 0x00126b10; 117 | MString ReduceArrayNode::kNODE_NAME = "reduceArray"; 118 | 119 | #define REGISTER_NODE(NODE) \ 120 | status = fnPlugin.registerNode( \ 121 | NODE::kNODE_NAME, \ 122 | NODE::kNODE_ID, \ 123 | NODE::creator, \ 124 | NODE::initialize \ 125 | ); \ 126 | CHECK_MSTATUS_AND_RETURN_IT(status); \ 127 | 128 | #define DEREGISTER_NODE(NODE) \ 129 | status = fnPlugin.deregisterNode( \ 130 | NODE::kNODE_ID \ 131 | ); \ 132 | CHECK_MSTATUS_AND_RETURN_IT(status); \ 133 | 134 | MStatus initializePlugin(MObject obj) 135 | { 136 | MStatus status; 137 | MFnPlugin fnPlugin(obj, kAUTHOR, kVERSION, kREQUIRED_API_VERSION); 138 | 139 | REGISTER_NODE(ArrayConstructorNode); 140 | REGISTER_NODE(ArrayAngleConstructorNode); 141 | REGISTER_NODE(ArrayMultiOperatorNode); 142 | REGISTER_NODE(ArrayIteratorNode); 143 | REGISTER_NODE(ArrayAngleIteratorNode); 144 | REGISTER_NODE(ArrayScalarOperationNode); 145 | REGISTER_NODE(ModifyArrayNode); 146 | REGISTER_NODE(ChainArraysNode); 147 | REGISTER_NODE(ClampArrayNode); 148 | REGISTER_NODE(NormalizeArrayNode); 149 | REGISTER_NODE(ReduceArrayNode); 150 | REGISTER_NODE(RemapArrayValuesNode); 151 | REGISTER_NODE(SliceArrayNode); 152 | 153 | return MS::kSuccess; 154 | } 155 | 156 | MStatus uninitializePlugin(MObject obj) 157 | { 158 | MStatus status; 159 | MFnPlugin fnPlugin(obj, kAUTHOR, kVERSION, kREQUIRED_API_VERSION); 160 | 161 | DEREGISTER_NODE(ArrayConstructorNode); 162 | DEREGISTER_NODE(ArrayAngleConstructorNode); 163 | DEREGISTER_NODE(ArrayMultiOperatorNode); 164 | DEREGISTER_NODE(ArrayIteratorNode); 165 | DEREGISTER_NODE(ArrayAngleIteratorNode); 166 | DEREGISTER_NODE(ArrayScalarOperationNode); 167 | DEREGISTER_NODE(ModifyArrayNode); 168 | DEREGISTER_NODE(ChainArraysNode); 169 | DEREGISTER_NODE(ClampArrayNode); 170 | DEREGISTER_NODE(NormalizeArrayNode); 171 | DEREGISTER_NODE(ReduceArrayNode); 172 | DEREGISTER_NODE(RemapArrayValuesNode); 173 | DEREGISTER_NODE(SliceArrayNode); 174 | 175 | return MS::kSuccess; 176 | } --------------------------------------------------------------------------------