├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── plug-ins ├── linux-maya2014 │ └── angularNodes.so ├── linux-maya2015 │ └── angularNodes.so ├── linux-maya2016 │ └── angularNodes.so ├── linux-maya2017 │ └── angularNodes.so ├── windows-maya2014 │ └── angularNodes.mll ├── windows-maya2015 │ └── angularNodes.mll ├── windows-maya2016 │ └── angularNodes.mll ├── windows-maya2017 │ └── angularNodes.mll └── windows-maya2019 │ └── angularNodes.mll └── src ├── n_angleBinaryOp.cpp ├── n_angleBinaryOp.h ├── n_angleMultiOp.cpp ├── n_angleMultiOp.h ├── n_angleScalarOp.cpp ├── n_angleScalarOp.h ├── n_angleUnaryOp.cpp ├── n_angleUnaryOp.h ├── n_clampAngle.cpp ├── n_clampAngle.h ├── node.h └── pluginMain.cpp /.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 | .vscode 10 | 11 | # User-specific files (MonoDevelop/Xamarin Studio) 12 | *.userprefs 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 | 26 | # Visual Studio 2015 cache/options directory 27 | .vs/ 28 | # Uncomment if you have tasks that create the project's static files in wwwroot 29 | #wwwroot/ 30 | 31 | # MSTest test Results 32 | [Tt]est[Rr]esult*/ 33 | [Bb]uild[Ll]og.* 34 | 35 | # NUNIT 36 | *.VisualState.xml 37 | TestResult.xml 38 | 39 | # Build Results of an ATL Project 40 | [Dd]ebugPS/ 41 | [Rr]eleasePS/ 42 | dlldata.c 43 | 44 | # DNX 45 | project.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | *.vcxproj 73 | *.vcxproj.filters 74 | 75 | # Chutzpah Test files 76 | _Chutzpah* 77 | 78 | # Visual C++ cache files 79 | ipch/ 80 | *.aps 81 | *.ncb 82 | *.opendb 83 | *.opensdf 84 | *.sdf 85 | *.cachefile 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # doxygen files 129 | Doxy* 130 | 131 | # DocProject is a documentation generator add-in 132 | DocProject/buildhelp/ 133 | DocProject/Help/*.HxT 134 | DocProject/Help/*.HxC 135 | DocProject/Help/*.hhc 136 | DocProject/Help/*.hhk 137 | DocProject/Help/*.hhp 138 | DocProject/Help/Html2 139 | DocProject/Help/html 140 | 141 | # Click-Once directory 142 | publish/ 143 | 144 | # Publish Web Output 145 | *.[Pp]ublish.xml 146 | *.azurePubxml 147 | # TODO: Comment the next line if you want to checkin your web deploy settings 148 | # but database connection strings (with potential passwords) will be unencrypted 149 | *.pubxml 150 | *.publishproj 151 | 152 | # NuGet Packages 153 | *.nupkg 154 | # The packages folder can be ignored because of Package Restore 155 | **/packages/* 156 | # except build/, which is used as an MSBuild target. 157 | !**/packages/build/ 158 | # Uncomment if necessary however generally it will be regenerated when needed 159 | #!**/packages/repositories.config 160 | # NuGet v3's project.json files produces more ignoreable files 161 | *.nuget.props 162 | *.nuget.targets 163 | 164 | # Microsoft Azure Build Output 165 | csx/ 166 | *.build.csdef 167 | 168 | # Microsoft Azure Emulator 169 | ecf/ 170 | rcf/ 171 | 172 | # Microsoft Azure ApplicationInsights config file 173 | ApplicationInsights.config 174 | 175 | # Windows Store app package directory 176 | AppPackages/ 177 | BundleArtifacts/ 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # RIA/Silverlight projects 197 | Generated_Code/ 198 | 199 | # Backup & report files from converting an old project file 200 | # to a newer Visual Studio version. Backup files are not needed, 201 | # because we have git ;-) 202 | _UpgradeReport_Files/ 203 | Backup*/ 204 | UpgradeLog*.XML 205 | UpgradeLog*.htm 206 | 207 | # SQL Server files 208 | *.mdf 209 | *.ldf 210 | 211 | # Business Intelligence projects 212 | *.rdl.data 213 | *.bim.layout 214 | *.bim_*.settings 215 | 216 | # Microsoft Fakes 217 | FakesAssemblies/ 218 | 219 | # GhostDoc plugin setting file 220 | *.GhostDoc.xml 221 | 222 | # Node.js Tools for Visual Studio 223 | .ntvs_analysis.dat 224 | 225 | # Visual Studio 6 build log 226 | *.plg 227 | 228 | # Visual Studio 6 workspace options file 229 | *.opt 230 | 231 | # Visual Studio LightSwitch build output 232 | **/*.HTMLClient/GeneratedArtifacts 233 | **/*.DesktopClient/GeneratedArtifacts 234 | **/*.DesktopClient/ModelManifest.xml 235 | **/*.Server/GeneratedArtifacts 236 | **/*.Server/ModelManifest.xml 237 | _Pvt_Extensions 238 | 239 | # Paket dependency manager 240 | .paket/paket.exe 241 | 242 | # FAKE - F# Make 243 | .fake/ 244 | -------------------------------------------------------------------------------- /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(angularNodes) 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}) -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #### angularNodes (version 1.0.1) 2 | Maya plugin with nodes for performing calculates on doubleAngle values without polluting the scene with unitConversion nodes. 3 | 4 | #### Description 5 | See the [Wiki](https://github.com/yantor3d/angularNodes/wiki) for full details. 6 | 7 | ## Plugin Contents 8 | ### Nodes 9 | - angleBinaryOp 10 | - angleMultiOp 11 | - angleScalarOp 12 | - angleUnaryOp 13 | - clampAngle 14 | -------------------------------------------------------------------------------- /plug-ins/linux-maya2014/angularNodes.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yantor3d/angularNodes/6107c6c4457420f0f99c1e930e39ccb88d4c8ae7/plug-ins/linux-maya2014/angularNodes.so -------------------------------------------------------------------------------- /plug-ins/linux-maya2015/angularNodes.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yantor3d/angularNodes/6107c6c4457420f0f99c1e930e39ccb88d4c8ae7/plug-ins/linux-maya2015/angularNodes.so -------------------------------------------------------------------------------- /plug-ins/linux-maya2016/angularNodes.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yantor3d/angularNodes/6107c6c4457420f0f99c1e930e39ccb88d4c8ae7/plug-ins/linux-maya2016/angularNodes.so -------------------------------------------------------------------------------- /plug-ins/linux-maya2017/angularNodes.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yantor3d/angularNodes/6107c6c4457420f0f99c1e930e39ccb88d4c8ae7/plug-ins/linux-maya2017/angularNodes.so -------------------------------------------------------------------------------- /plug-ins/windows-maya2014/angularNodes.mll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yantor3d/angularNodes/6107c6c4457420f0f99c1e930e39ccb88d4c8ae7/plug-ins/windows-maya2014/angularNodes.mll -------------------------------------------------------------------------------- /plug-ins/windows-maya2015/angularNodes.mll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yantor3d/angularNodes/6107c6c4457420f0f99c1e930e39ccb88d4c8ae7/plug-ins/windows-maya2015/angularNodes.mll -------------------------------------------------------------------------------- /plug-ins/windows-maya2016/angularNodes.mll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yantor3d/angularNodes/6107c6c4457420f0f99c1e930e39ccb88d4c8ae7/plug-ins/windows-maya2016/angularNodes.mll -------------------------------------------------------------------------------- /plug-ins/windows-maya2017/angularNodes.mll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yantor3d/angularNodes/6107c6c4457420f0f99c1e930e39ccb88d4c8ae7/plug-ins/windows-maya2017/angularNodes.mll -------------------------------------------------------------------------------- /plug-ins/windows-maya2019/angularNodes.mll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yantor3d/angularNodes/6107c6c4457420f0f99c1e930e39ccb88d4c8ae7/plug-ins/windows-maya2019/angularNodes.mll -------------------------------------------------------------------------------- /src/n_angleBinaryOp.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 | // angleUnaryOp node 8 | // 9 | // Performs a binary operation with two input values. 10 | // No Operation - Returns the input value. 11 | // Add - Returns the sum of the input values. 12 | // Subtract - Returns the difference between the input values. 13 | // Multiply - Returns the product of the input values. 14 | // Divide - Returns the quotient of the input values. 15 | // Power - Returns the exponent of the input values. 16 | //----------------------------------------------------------------------------- 17 | 18 | #include "n_angleBinaryOp.h" 19 | #include "node.h" 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | MObject AngleBinaryOpNode::aInput1; 32 | MObject AngleBinaryOpNode::aInput2; 33 | MObject AngleBinaryOpNode::aOperation; 34 | MObject AngleBinaryOpNode::aOutput; 35 | 36 | const short NO_OP = 0; 37 | const short ADD = 1; 38 | const short SUBTRACT = 2; 39 | const short MULTIPLY = 3; 40 | const short DIVIDE = 4; 41 | const short POWER = 5; 42 | 43 | void* AngleBinaryOpNode::creator() 44 | { 45 | return new AngleBinaryOpNode(); 46 | } 47 | 48 | MStatus AngleBinaryOpNode::initialize() 49 | { 50 | MStatus status; 51 | 52 | MFnUnitAttribute u; 53 | MFnEnumAttribute e; 54 | 55 | aInput1 = u.create("input1", "i1", MFnUnitAttribute::kAngle, 0.0, &status); 56 | __CHECK_STATUS(status); 57 | MAKE_INPUT_ATTR(u); 58 | 59 | aInput2 = u.create("input2", "i2", MFnUnitAttribute::kAngle, 0.0, &status); 60 | __CHECK_STATUS(status); 61 | MAKE_INPUT_ATTR(u); 62 | 63 | aOperation = e.create("operation", "op", ADD, &status); 64 | __CHECK_STATUS(status); 65 | MAKE_INPUT_ATTR(e); 66 | 67 | e.addField("No Operation", NO_OP); 68 | e.addField("Add", ADD); 69 | e.addField("Subtract", SUBTRACT); 70 | e.addField("Multiply", MULTIPLY); 71 | e.addField("Divide", DIVIDE); 72 | e.addField("Power", POWER); 73 | 74 | aOutput = u.create("output", "o", MFnUnitAttribute::kAngle, 0.0, &status); 75 | __CHECK_STATUS(status); 76 | MAKE_OUTPUT_ATTR(u) 77 | 78 | addAttribute(aInput1); 79 | addAttribute(aInput2); 80 | addAttribute(aOperation); 81 | addAttribute(aOutput); 82 | 83 | attributeAffects(aInput1, aOutput); 84 | attributeAffects(aInput2, aOutput); 85 | attributeAffects(aOperation, aOutput); 86 | 87 | return MS::kSuccess; 88 | } 89 | 90 | MStatus AngleBinaryOpNode::compute(const MPlug& plug, MDataBlock& data) 91 | { 92 | if (plug != aOutput) 93 | { 94 | return MS::kUnknownParameter; 95 | } 96 | 97 | double input1 = data.inputValue(aInput1).asAngle().asDegrees(); 98 | double input2 = data.inputValue(aInput2).asAngle().asDegrees(); 99 | short operation = data.inputValue(aOperation).asShort(); 100 | 101 | double result = input1; 102 | 103 | switch (operation) 104 | { 105 | case ADD: 106 | result = input1 + input2; 107 | break; 108 | 109 | case SUBTRACT: 110 | result = input1 - input2; 111 | break; 112 | 113 | case MULTIPLY: 114 | result = input1 * input2; 115 | break; 116 | 117 | case DIVIDE: 118 | result = input2 == 0.0 ? 10000.0 : input1 / input2; 119 | break; 120 | 121 | case POWER: 122 | result = pow(input1, input2); 123 | break; 124 | } 125 | 126 | MDataHandle output = data.outputValue(aOutput); 127 | output.setMAngle(MAngle(result, MAngle::kDegrees)); 128 | output.setClean(); 129 | 130 | return MS::kSuccess; 131 | } 132 | -------------------------------------------------------------------------------- /src/n_angleBinaryOp.h: -------------------------------------------------------------------------------- 1 | #ifndef N_ANGLE_BINARY_OP_H 2 | #define N_ANGLE_BINARY_OP_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class AngleBinaryOpNode : public MPxNode 11 | { 12 | public: 13 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 14 | static void* creator(); 15 | static MStatus initialize(); 16 | 17 | public: 18 | static MTypeId kNODE_ID; 19 | static MString kNODE_NAME; 20 | 21 | static MObject aInput1; 22 | static MObject aInput2; 23 | static MObject aOperation; 24 | static MObject aOutput; 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /src/n_angleMultiOp.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 | // angleUnaryOp node 8 | // 9 | // Performs a reducing operation with the input values 10 | // No Operation - Returns zero. 11 | // Sum - Returns the sum of the input values. 12 | // Difference - Returns the difference of the input values. 13 | // Product - Returns the product of the input values. 14 | // Minimum - Returns the smallest input value. 15 | // Maximum - Returns the largest input value. 16 | //----------------------------------------------------------------------------- 17 | 18 | #include "n_angleMultiOp.h" 19 | #include "node.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | MObject AngleMultiOpNode::aInput; 34 | MObject AngleMultiOpNode::aOperation; 35 | MObject AngleMultiOpNode::aOutput; 36 | 37 | const short NO_OP = 0; 38 | const short SUM = 1; 39 | const short DIFF = 2; 40 | const short PRODUCT = 3; 41 | const short MIN_ = 4; 42 | const short MAX_ = 5; 43 | 44 | void* AngleMultiOpNode::creator() 45 | { 46 | return new AngleMultiOpNode(); 47 | } 48 | 49 | MStatus AngleMultiOpNode::initialize() 50 | { 51 | MStatus status; 52 | 53 | MFnUnitAttribute u; 54 | MFnEnumAttribute e; 55 | 56 | aInput = u.create("input", "i", MFnUnitAttribute::kAngle, 0.0, &status); 57 | __CHECK_STATUS(status); 58 | MAKE_INPUT_ATTR(u); 59 | u.setArray(true); 60 | 61 | aOperation = e.create("operation", "op", SUM, &status); 62 | __CHECK_STATUS(status); 63 | MAKE_INPUT_ATTR(e); 64 | 65 | e.addField("No Operation", NO_OP); 66 | e.addField("Sum", SUM); 67 | e.addField("Difference", DIFF); 68 | e.addField("Product", PRODUCT); 69 | e.addField("Minimum", MIN_); 70 | e.addField("Maximum", MAX_); 71 | 72 | aOutput = u.create("output", "o", MFnUnitAttribute::kAngle, 0.0, &status); 73 | __CHECK_STATUS(status); 74 | MAKE_OUTPUT_ATTR(u) 75 | 76 | addAttribute(aInput); 77 | addAttribute(aOperation); 78 | addAttribute(aOutput); 79 | 80 | attributeAffects(aInput, aOutput); 81 | attributeAffects(aOperation, aOutput); 82 | 83 | return MS::kSuccess; 84 | } 85 | 86 | MStatus AngleMultiOpNode::compute(const MPlug& plug, MDataBlock& data) 87 | { 88 | if (plug != aOutput) 89 | { 90 | return MS::kUnknownParameter; 91 | } 92 | 93 | MArrayDataHandle inputArrayHandle = data.inputValue(aInput); 94 | 95 | unsigned numInputs = inputArrayHandle.elementCount(); 96 | std::vector inputs(numInputs); 97 | 98 | for (unsigned i = 0; i < numInputs; i++) 99 | { 100 | inputs[i] = inputArrayHandle.inputValue().asAngle().asDegrees(); 101 | if (!inputArrayHandle.next()) continue; 102 | } 103 | 104 | short operation = data.inputValue(aOperation).asShort(); 105 | 106 | double result = 0; 107 | 108 | switch (operation) 109 | { 110 | case SUM: 111 | result = std::accumulate(inputs.begin(), inputs.end(), 0.0, std::plus()); 112 | break; 113 | 114 | case DIFF: 115 | result = std::accumulate(inputs.begin(), inputs.end(), 0.0, std::minus()); 116 | break; 117 | 118 | case PRODUCT: 119 | result = std::accumulate(inputs.begin(), inputs.end(), 1.0, std::multiplies()); 120 | break; 121 | 122 | case MIN_: 123 | result = *std::min_element(inputs.begin(), inputs.end()); 124 | break; 125 | 126 | case MAX_: 127 | result = *std::max_element(inputs.begin(), inputs.end()); 128 | break; 129 | } 130 | 131 | MDataHandle output = data.outputValue(aOutput); 132 | output.setMAngle(MAngle(result, MAngle::kDegrees)); 133 | output.setClean(); 134 | 135 | return MS::kSuccess; 136 | } -------------------------------------------------------------------------------- /src/n_angleMultiOp.h: -------------------------------------------------------------------------------- 1 | #ifndef N_ANGLE_MULTI_OP_H 2 | #define N_ANGLE_MULTI_OP_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class AngleMultiOpNode : public MPxNode 11 | { 12 | public: 13 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 14 | static void* creator(); 15 | static MStatus initialize(); 16 | 17 | public: 18 | static MTypeId kNODE_ID; 19 | static MString kNODE_NAME; 20 | 21 | static MObject aInput; 22 | static MObject aOperation; 23 | static MObject aOutput; 24 | }; 25 | 26 | #endif -------------------------------------------------------------------------------- /src/n_angleScalarOp.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 | // angleScalarOp node 8 | // 9 | // Performs a binary operation with an input value and a scalar. 10 | // No Operation - Returns the input value. 11 | // Add - Returns the sum of the input values. 12 | // Subtract - Returns the difference between the input values. 13 | // Multiply - Returns the product of the input values. 14 | // Divide - Returns the quotient of the input values. 15 | // Power - Returns the exponent of the input values. 16 | //----------------------------------------------------------------------------- 17 | 18 | #include "n_angleScalarOp.h" 19 | #include "node.h" 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | MObject AngleScalarOpNode::aInput; 33 | MObject AngleScalarOpNode::aScalar; 34 | MObject AngleScalarOpNode::aOperation; 35 | MObject AngleScalarOpNode::aOutput; 36 | 37 | const short NO_OP = 0; 38 | const short ADD = 1; 39 | const short SUBTRACT = 2; 40 | const short MULTIPLY = 3; 41 | const short DIVIDE = 4; 42 | const short POWER = 5; 43 | 44 | void* AngleScalarOpNode::creator() 45 | { 46 | return new AngleScalarOpNode(); 47 | } 48 | 49 | MStatus AngleScalarOpNode::initialize() 50 | { 51 | MStatus status; 52 | 53 | MFnEnumAttribute e; 54 | MFnNumericAttribute n; 55 | MFnUnitAttribute u; 56 | 57 | aInput = u.create("input", "i", MFnUnitAttribute::kAngle, 0.0, &status); 58 | __CHECK_STATUS(status); 59 | MAKE_INPUT_ATTR(u); 60 | 61 | aScalar = n.create("scalar", "sc", MFnNumericData::kDouble, 0.0, &status); 62 | __CHECK_STATUS(status); 63 | MAKE_INPUT_ATTR(n); 64 | 65 | aOperation = e.create("operation", "op", ADD, &status); 66 | __CHECK_STATUS(status); 67 | MAKE_INPUT_ATTR(e); 68 | 69 | e.addField("No Operation", NO_OP); 70 | e.addField("Add", ADD); 71 | e.addField("Subtract", SUBTRACT); 72 | e.addField("Multiply", MULTIPLY); 73 | e.addField("Divide", DIVIDE); 74 | e.addField("Power", POWER); 75 | 76 | aOutput = u.create("output", "o", MFnUnitAttribute::kAngle, 0.0, &status); 77 | __CHECK_STATUS(status); 78 | MAKE_OUTPUT_ATTR(u) 79 | 80 | addAttribute(aInput); 81 | addAttribute(aScalar); 82 | addAttribute(aOperation); 83 | addAttribute(aOutput); 84 | 85 | attributeAffects(aInput, aOutput); 86 | attributeAffects(aScalar, aOutput); 87 | attributeAffects(aOperation, aOutput); 88 | 89 | return MS::kSuccess; 90 | } 91 | 92 | MStatus AngleScalarOpNode::compute(const MPlug& plug, MDataBlock& data) 93 | { 94 | if (plug != aOutput) 95 | { 96 | return MS::kUnknownParameter; 97 | } 98 | 99 | double input1 = data.inputValue(aInput).asAngle().asDegrees(); 100 | double input2 = data.inputValue(aScalar).asDouble(); 101 | short operation = data.inputValue(aOperation).asShort(); 102 | 103 | double result = input1; 104 | 105 | switch (operation) 106 | { 107 | case ADD: 108 | result = input1 + input2; 109 | break; 110 | 111 | case SUBTRACT: 112 | result = input1 - input2; 113 | break; 114 | 115 | case MULTIPLY: 116 | result = input1 * input2; 117 | break; 118 | 119 | case DIVIDE: 120 | result = input2 == 0.0 ? 100000.0 : input1 / input2; 121 | break; 122 | 123 | case POWER: 124 | result = pow(input1, input2); 125 | break; 126 | } 127 | 128 | MDataHandle output = data.outputValue(aOutput); 129 | output.setMAngle(MAngle(result, MAngle::kDegrees)); 130 | output.setClean(); 131 | 132 | return MS::kSuccess; 133 | } 134 | -------------------------------------------------------------------------------- /src/n_angleScalarOp.h: -------------------------------------------------------------------------------- 1 | #ifndef N_ANGLE_SCALAR_OP_H 2 | #define N_ANGLE_SCALAR_OP_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class AngleScalarOpNode : public MPxNode 11 | { 12 | public: 13 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 14 | static void* creator(); 15 | static MStatus initialize(); 16 | 17 | public: 18 | static MTypeId kNODE_ID; 19 | static MString kNODE_NAME; 20 | 21 | static MObject aInput; 22 | static MObject aScalar; 23 | static MObject aOperation; 24 | static MObject aOutput; 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /src/n_angleUnaryOp.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 | // angleUnaryOp node 8 | // 9 | // Performs a unary operation on an input value 10 | // No Operation - Returns the input value 11 | // Negate - Returns the input value with the sign inverted 12 | // Sign - Returns +1.0 if the input value is positive, otherwise -1.0 13 | // Inverse - Returns the reciprocal value if the input. 14 | // Floor - Returns the value rounded down to the nearest whole number. 15 | // Ceiling - Returns the value rounded up to the nearest whole number. 16 | //----------------------------------------------------------------------------- 17 | 18 | #include "n_angleUnaryOp.h" 19 | #include "node.h" 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | const short NO_OP = 0; 33 | const short SIGN = 1; 34 | const short NEGATE = 2; 35 | const short RECIPROCAL = 3; 36 | const short FLOOR = 4; 37 | const short CEILING = 5; 38 | const short ABSOLUTE_VALUE = 6; 39 | 40 | MObject AngleUnaryOpNode::aInput; 41 | MObject AngleUnaryOpNode::aOperation; 42 | MObject AngleUnaryOpNode::aOutput; 43 | 44 | void* AngleUnaryOpNode::creator() 45 | { 46 | return new AngleUnaryOpNode(); 47 | } 48 | 49 | MStatus AngleUnaryOpNode::initialize() 50 | { 51 | MStatus status; 52 | 53 | MFnUnitAttribute u; 54 | MFnEnumAttribute e; 55 | 56 | aInput = u.create("input", "i", MFnUnitAttribute::kAngle, 0.0, &status); 57 | __CHECK_STATUS(status); 58 | MAKE_INPUT_ATTR(u); 59 | 60 | aOperation = e.create("operation", "op", SIGN, &status); 61 | __CHECK_STATUS(status); 62 | MAKE_INPUT_ATTR(e); 63 | 64 | e.addField("No Operation", NO_OP); 65 | e.addField("Sign", SIGN); 66 | e.addField("Negate", NEGATE); 67 | e.addField("Reciprocal", RECIPROCAL); 68 | e.addField("Floor", FLOOR); 69 | e.addField("Ceiling", CEILING); 70 | e.addField("Absolute Value", ABSOLUTE_VALUE); 71 | 72 | aOutput = u.create("output", "o", MFnUnitAttribute::kAngle, 0.0, &status); 73 | __CHECK_STATUS(status); 74 | MAKE_OUTPUT_ATTR(u) 75 | 76 | addAttribute(aInput); 77 | addAttribute(aOperation); 78 | addAttribute(aOutput); 79 | 80 | attributeAffects(aInput, aOutput); 81 | attributeAffects(aOperation, aOutput); 82 | 83 | return MS::kSuccess; 84 | } 85 | 86 | MStatus AngleUnaryOpNode::compute(const MPlug& plug, MDataBlock& data) 87 | { 88 | if (plug != aOutput) 89 | { 90 | return MS::kUnknownParameter; 91 | } 92 | 93 | double input = data.inputValue(aInput).asAngle().asDegrees(); 94 | short operation = data.inputValue(aOperation).asShort(); 95 | 96 | double result = input; 97 | 98 | switch (operation) 99 | { 100 | case SIGN: 101 | result = input >= 0.0 ? 1.0 : -1.0; 102 | break; 103 | 104 | case ABSOLUTE_VALUE: 105 | result = abs(input); 106 | break; 107 | 108 | case NEGATE: 109 | result = -input; 110 | break; 111 | 112 | case RECIPROCAL: 113 | result = input == 0.0 ? 10000.0 : 1.0 / input; 114 | break; 115 | 116 | case FLOOR: 117 | result = floor(input); 118 | break; 119 | 120 | case CEILING: 121 | result = ceil(input); 122 | break; 123 | } 124 | 125 | MDataHandle output = data.outputValue(aOutput); 126 | output.setMAngle(MAngle(result, MAngle::kDegrees)); 127 | output.setClean(); 128 | 129 | return MS::kSuccess; 130 | } 131 | -------------------------------------------------------------------------------- /src/n_angleUnaryOp.h: -------------------------------------------------------------------------------- 1 | #ifndef N_ANGLE_UNARY_OP_H 2 | #define N_ANGLE_UNARY_OP_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class AngleUnaryOpNode : public MPxNode 11 | { 12 | public: 13 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 14 | static void* creator(); 15 | static MStatus initialize(); 16 | 17 | public: 18 | static MTypeId kNODE_ID; 19 | static MString kNODE_NAME; 20 | 21 | static MObject aInput; 22 | static MObject aOperation; 23 | static MObject aOutput; 24 | }; 25 | 26 | #endif -------------------------------------------------------------------------------- /src/n_clampAngle.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 | // clampAngle node 8 | // 9 | // Restricts the value of an input angle to between a minimum and maximum value. 10 | //----------------------------------------------------------------------------- 11 | 12 | #define NOMINMAX 13 | #define _USE_MATH_DEFINES 14 | 15 | #include "n_clampAngle.h" 16 | #include "node.h" 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | MObject ClampAngleNode::aInput; 30 | MObject ClampAngleNode::aMin; 31 | MObject ClampAngleNode::aMax; 32 | MObject ClampAngleNode::aOutput; 33 | 34 | void* ClampAngleNode::creator() 35 | { 36 | return new ClampAngleNode(); 37 | } 38 | 39 | MStatus ClampAngleNode::initialize() 40 | { 41 | MStatus status; 42 | MFnUnitAttribute u; 43 | 44 | aInput = u.create("input", "i", MFnUnitAttribute::kAngle, 0.0, &status); 45 | __CHECK_STATUS(status); 46 | MAKE_INPUT_ATTR(u); 47 | 48 | aMin = u.create("min", "mn", MFnUnitAttribute::kAngle, 0.0, &status); 49 | __CHECK_STATUS(status); 50 | MAKE_INPUT_ATTR(u); 51 | 52 | aMax = u.create("max", "mx", MFnUnitAttribute::kAngle, M_PI / 2.0, &status); 53 | __CHECK_STATUS(status); 54 | MAKE_INPUT_ATTR(u); 55 | 56 | aOutput = u.create("output", "o", MFnUnitAttribute::kAngle, 0.0, &status); 57 | __CHECK_STATUS(status); 58 | MAKE_OUTPUT_ATTR(u); 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 | MStatus ClampAngleNode::compute(const MPlug& plug, MDataBlock& data) 73 | { 74 | if (plug != aOutput) 75 | { 76 | return MS::kUnknownParameter; 77 | } 78 | 79 | double input = data.inputValue(aInput).asAngle().asDegrees(); 80 | double mn = data.inputValue(aMin).asAngle().asDegrees(); 81 | double mx = data.inputValue(aMax).asAngle().asDegrees(); 82 | 83 | double result = std::max(std::min(input, mx), mn); 84 | 85 | MDataHandle outputHandle = data.outputValue(aOutput); 86 | outputHandle.setMAngle(MAngle(result, MAngle::kDegrees)); 87 | outputHandle.setClean(); 88 | 89 | return MS::kSuccess; 90 | } -------------------------------------------------------------------------------- /src/n_clampAngle.h: -------------------------------------------------------------------------------- 1 | #ifndef N_CLAMP_ANGLES_OP_H 2 | #define N_CLAMP_ANGLES_OP_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class ClampAngleNode : public MPxNode 11 | { 12 | public: 13 | virtual MStatus compute(const MPlug& plug, MDataBlock& data); 14 | static void* creator(); 15 | static MStatus initialize(); 16 | 17 | public: 18 | static MTypeId kNODE_ID; 19 | static MString kNODE_NAME; 20 | 21 | static MObject aInput; 22 | static MObject aMin; 23 | static MObject aMax; 24 | static MObject aOutput; 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /src/node.h: -------------------------------------------------------------------------------- 1 | #ifndef N_NODE_H 2 | #define N_NODE_H 3 | 4 | #define MAKE_INPUT_ATTR(fnAttr) \ 5 | fnAttr.setKeyable(true); \ 6 | fnAttr.setChannelBox(true); \ 7 | fnAttr.setStorable(true); \ 8 | fnAttr.setWritable(true); \ 9 | 10 | #define MAKE_OUTPUT_ATTR(fnAttr) \ 11 | fnAttr.setKeyable(false); \ 12 | fnAttr.setChannelBox(false); \ 13 | fnAttr.setStorable(false); \ 14 | fnAttr.setWritable(false); 15 | 16 | #ifdef _DEBUG 17 | #define __CHECK_STATUS(status) CHECK_MSTATUS_AND_RETURN_IT(status); 18 | #else 19 | #define __CHECK_STATUS(status) ; 20 | #endif 21 | 22 | #endif -------------------------------------------------------------------------------- /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 | angularNodes 27 | 28 | Maya math nodes operate on double values. This means that Maya must create a 29 | unit conversion node when connecting to or from a doubleAngle value, such as 30 | the rotate attributes of a transform. This quickly pollutes a scene with these 31 | unitConversion nodes, which have a negative measurable effect on rig performance. 32 | 33 | These nodes operation on doubleAngle values as inputs and outputs, eliminating 34 | the need for a unit conversion node in most cases. 35 | */ 36 | 37 | #include "n_angleBinaryOp.h" 38 | #include "n_angleMultiOp.h" 39 | #include "n_angleScalarOp.h" 40 | #include "n_angleUnaryOp.h" 41 | #include "n_clampAngle.h" 42 | 43 | #include 44 | #include 45 | #include 46 | 47 | const char* kAUTHOR = "Ryan Porter"; 48 | const char* kVERSION = "1.0.1"; 49 | const char* kREQUIRED_API_VERSION = "Any"; 50 | 51 | MString ClampAngleNode::kNODE_NAME = "clampAngle"; 52 | MString AngleBinaryOpNode::kNODE_NAME = "angleBinaryOp"; 53 | MString AngleMultiOpNode::kNODE_NAME = "angleMultiOp"; 54 | MString AngleScalarOpNode::kNODE_NAME = "angleScalarOp"; 55 | MString AngleUnaryOpNode::kNODE_NAME = "angleUnaryOp"; 56 | 57 | MTypeId AngleBinaryOpNode::kNODE_ID = 0x00126b12; 58 | MTypeId AngleMultiOpNode::kNODE_ID = 0x00126b13; 59 | MTypeId AngleScalarOpNode::kNODE_ID = 0x00126b14; 60 | MTypeId AngleUnaryOpNode::kNODE_ID = 0x00126b15; 61 | MTypeId ClampAngleNode::kNODE_ID = 0x00126b16; 62 | 63 | #define REGISTER_NODE(NODE) \ 64 | status = fnPlugin.registerNode( \ 65 | NODE::kNODE_NAME, \ 66 | NODE::kNODE_ID, \ 67 | NODE::creator, \ 68 | NODE::initialize \ 69 | ); \ 70 | CHECK_MSTATUS_AND_RETURN_IT(status); \ 71 | 72 | #define DEREGISTER_NODE(NODE) \ 73 | status = fnPlugin.deregisterNode( \ 74 | NODE::kNODE_ID \ 75 | ); \ 76 | CHECK_MSTATUS_AND_RETURN_IT(status); \ 77 | 78 | MStatus initializePlugin(MObject obj) 79 | { 80 | MStatus status; 81 | MFnPlugin fnPlugin(obj, kAUTHOR, kVERSION, kREQUIRED_API_VERSION); 82 | 83 | REGISTER_NODE(AngleMultiOpNode); 84 | REGISTER_NODE(AngleBinaryOpNode); 85 | REGISTER_NODE(AngleScalarOpNode); 86 | REGISTER_NODE(AngleUnaryOpNode); 87 | REGISTER_NODE(ClampAngleNode); 88 | 89 | return MS::kSuccess; 90 | } 91 | 92 | MStatus uninitializePlugin(MObject obj) 93 | { 94 | MStatus status; 95 | MFnPlugin fnPlugin(obj, kAUTHOR, kVERSION, kREQUIRED_API_VERSION); 96 | 97 | DEREGISTER_NODE(AngleMultiOpNode); 98 | DEREGISTER_NODE(AngleBinaryOpNode); 99 | DEREGISTER_NODE(AngleScalarOpNode); 100 | DEREGISTER_NODE(AngleUnaryOpNode); 101 | DEREGISTER_NODE(ClampAngleNode); 102 | 103 | return MS::kSuccess; 104 | } 105 | --------------------------------------------------------------------------------