{"id":23132574,"url":"https://github.com/bigroy/nodex","last_synced_at":"2025-08-17T08:32:34.054Z","repository":{"id":24330637,"uuid":"27727775","full_name":"BigRoy/nodex","owner":"BigRoy","description":"This package defines a wrapping functionality to create and manage mathematical node connections in Maya through Python scripting. The ease of access and method of using this will help to write readable and maintainable code for node based graphs that require a lot of mathematical processing.","archived":false,"fork":false,"pushed_at":"2015-02-16T21:37:15.000Z","size":588,"stargazers_count":30,"open_issues_count":0,"forks_count":7,"subscribers_count":8,"default_branch":"master","last_synced_at":"2023-08-05T20:42:33.087Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BigRoy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-08T18:04:09.000Z","updated_at":"2023-08-05T20:42:33.087Z","dependencies_parsed_at":"2022-08-18T21:51:47.269Z","dependency_job_id":null,"html_url":"https://github.com/BigRoy/nodex","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BigRoy%2Fnodex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BigRoy%2Fnodex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BigRoy%2Fnodex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BigRoy%2Fnodex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BigRoy","download_url":"https://codeload.github.com/BigRoy/nodex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230106154,"owners_count":18174010,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-17T11:19:10.271Z","updated_at":"2024-12-17T11:19:10.939Z","avatar_url":"https://github.com/BigRoy.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nodex\n\nThis package defines a wrapping functionality to create and manage mathematical\nnode connections in Maya through Python scripting. The ease of access and method of using this\nwill help to write readable and maintainable code for node based graphs that require\na lot of mathematical processing.\n\n![Nodex Logo](static/images/nodex_logo_256.png)\n\n# Documentation\n\n### Full documentation for Nodex:\n\n- [http://www.colorbleed.nl/docs/nodex/master/](http://www.colorbleed.nl/docs/nodex/master/)\n\n# Brief docs\n\n## Node expressions for Maya\n\nThe core concept of the Nodex is that each node in the graph can have multiple inputs, but has a\nsingle important output. This way the algorithm can be written as a single line of chained commands.\n\nThe process works by using an object called the ``Nodex``.\n\nUpon initializing a Nodex you reference a value (its first argument). Since the Nodex has a magic initialization \n(factory within __new__) it will become the relevant datatype for the data you're referencing.\n\nThen you can perform mathematical operations upon this Nodex with another\nNodex (thus other attributes/numbers) and it will automatically return a Nodex that references\nthe output attribute resulting from the created node graph.\n\nPerformable operations include mathematical operators that act directly on the Nodex instance, like:\n\n- +, -, /, *, ^ for addition, subtraction, division, multiplication and power.\n- ==, !=, \u003e, \u003e=, \u003c, \u003c= that will result in a 'condition' node.\n\nYet there's no boundary on what arguments one of the Nodex' inherited methods have so those could also\ninclude easing the workflow for much more complex operations than those already provided.\n\nThat's why you'll also see (among others) **dot-product** and **cross-product** implementations work when dealing with\nVectors.\n\n## Features\n\n\n#### Returns the smallest calculated resulting attribute (3-Vector \u003e 2-Vector \u003e Scalar)\n\nThe Nodex will try to minimize the result/output based on the inputs. This means that when\nyou add two integers it will give you the output attribute (as Nodex) for a single float\nattribute (output1D). But if you add two vectors together it will return the output3D from the\nused plusMinusAverage node.\n\nNote: This is of course only a valid statement for where this conversion is possible with the given\n      Maya graph nodes.\n\n#### Chain, chainery, chain-chain-cheroo\n\nSince the output of each calculation with Nodex instances returns a new Nodex wrapping the calculation's output\nattribute you can write a chain of calculations. Of course you're free to stop take the resulting node midway, store\nit in a variable and use it's output for a multitude of node trees.\n\n#### Smart set/connect for attributes\n\nUsing an input value or attribute it will try to guess how to connect it to the input attributes\nfor a mathemical node based on the smaller input element (in dimensions) similar to above.\nThis means adding together a float attribute with a vector attribute will actually result in\na Vector where each component has the scalar added like this:\n\n    float + vector        = vector + vector                   = vector output\n    0.5 + [0.3, -1, 10.1] = [0.5, 0.5, 0.5] + [0.3, -1, 10.1] = [0.8, -0.5, 10.6]\n\n\n## Code Samples\n\nMultiply two attributes and connect the output value\n\n```python\nmult = Nodex(\"pSphere1.translateX\") * Nodex(\"pSphere1.translateY\")\nmult.connectTo( Nodex(\"pSphere1.translateZ\") )\n```\n\n---\n\nAdd together multiple attributes (sum more than two values) and connect the result\n\n```python\nresult = Math.sum(\"pSphere1.translateX\", \"pSphere1.translateY\", \"pSphere1.translateZ\", 1.0)\nresult.connectTo( Nodex(\"pSphere1.scaleX\") )\n```\n\n---\n\nClamp an attribute and connect it\n\n```python\nNodex.clamp(\"pSphere1.translateX\", min=0, max=1, output=\"pSphere1.translateY\")\n```\n\n---\n\nComplex operations become a bit more readable\n\n```python\n(Nodex(\"pSphere.translateX\") * 2) + 0.5\n```\n\n---\n\nUsing the Nodex's mixed array instantiation\n\n```python\nnodex = Nodex([1, 0, \"pSphere1.translateX\"]) * 3\nprint nodex.value()\n```\n\nThis will print `[3, 0, 15]` if *pSphere1.translateX* is a value of 5.\n\n---\n\nOr perform a calculation through Maya nodes and clean up the Nodex tree afterwards\n\n```python\n# The *MayaDeleteNewNodes* context manager is not included in the Nodex package but should be trivial to implement\nwith MayaDeleteNewNodes():\n    nodex = (Nodex(1) + Nodex(\"pSphere1.translateX\")) / Nodex(\"pSphere2.translateY\")\n    value = nodex.value()\n```\n\n---\n\n### Matrix Datatype\n\n##### (\u003e0.2.0) Matrix node creations in Maya are possible with Python using Nodex\n\nNo more choosing which pill to take; take both red and blue.\n\n```python\nmatrix = pymel.core.datatypes.Matrix()\nnodex = Nodex(matrix)\n\n# Convert the matrix into the local space of object `redPill`\nredPill_matrix = Nodex(\"redPill.worldMatrix[0]\")\nlocal_mat = matrix * redPill_matrix.inverse()\n\n# Decompose and directly connect to object `bluePill`\nlocal_mat.decompose(translate=\"bluePill.translate\",\n                    rotate=\"bluePill.rotate\",\n                    scale=\"bluePill.scale\")\n```\n\n---\n\n##### Setting up a simple *Matrix constraint* relationship between two objects with Nodex\n\nSnap the `src` object to the `target` object. \nThis will also work if they are NOT under the same parent.\n\n```python\nsel = pymel.core.ls(selection=True)\ntarget = sel[0]\nsrc = sel[1] # this will move towards the target\n\ntargetMat = Nodex(target.attr(\"worldMatrix[0]\"))\nsrcParentInvMat = Nodex(src.attr(\"parentInverseMatrix[0]\"))\n\nlocalMat = targetMat * srcParentInvMat\nlocalMat.decompose(translate=src.attr('translate'), \n                   rotate=src.attr('rotate'),\n                   scale=src.attr('scale'))\n```\n---\n\n### Vector datatype\n\n##### (\u003e0.2.1) Vector math in Maya with nodes is possible with Python using Nodex\n\nHave a blast *normalizing* your vectors!\n\n```python\nvector = pymel.core.datatypes.Vector(10, 10, 0)\nv = Nodex(vector)\n\n# Let's get a point on the unit sphere.\nv = v.normal()\n\n# Let's put that point on a sphere of radius 5\nv *= [5.0, 5.0, 5.0]\n\n# Let's offset it by the translate of another node\nv += Nodex('otherNode.translate')\n\n# And use it to drive this node.\nv.connect('thisNode.translate')\n```\n\n##### The available methods for the Vector datatype are (outside of those inherited from Array):\n\n```python\n# cross product with another vector\nvector.cross(otherVector) \n\n# dot product with another vector\nvector.dot(otherVector) \n\n# normalize the vector\nvector.normal()\n\n# angle between two vectors\nvector.angleTo(otherVector)\n\n# distance between two vectors (as points)\nvector.distanceTo(otherVector)\n\n# length of the vector\nvector.length()\n\n# squared length of the vector (uses two nodes)\nvector.squareLength()\n```\n\n---","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigroy%2Fnodex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbigroy%2Fnodex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigroy%2Fnodex/lists"}