Skip to content

Commit

Permalink
Add distance math node (AcademySoftwareFoundation#1333)
Browse files Browse the repository at this point in the history
Adding distance math node to measure the distance between two points.
  • Loading branch information
Cinifreak authored May 23, 2023
1 parent 7b229d1 commit d49f7af
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
20 changes: 20 additions & 0 deletions libraries/stdlib/stdlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,26 @@
<output name="out" type="float" default="0.0" />
</nodedef>

<!--
Node: <distance>
Measures the distance between two points in 2D, 3D, or 4D.
-->
<nodedef name="ND_distance_vector2" node="distance" nodegroup="math">
<input name="in1" type="vector2" uiname="in1" value="0.0, 0.0" />
<input name="in2" type="vector2" uiname="in2" value="0.0, 0.0" />
<output name="out" type="float" />
</nodedef>
<nodedef name="ND_distance_vector3" node="distance" nodegroup="math">
<input name="in1" type="vector3" uiname="in1" value="0.0, 0.0, 0.0" />
<input name="in2" type="vector3" uiname="in2" value="0.0, 0.0, 0.0" />
<output name="out" type="float" />
</nodedef>
<nodedef name="ND_distance_vector4" node="distance" nodegroup="math">
<input name="in1" type="vector4" uiname="in1" value="0.0, 0.0, 0.0, 0.0" />
<input name="in2" type="vector4" uiname="in2" value="0.0, 0.0, 0.0, 0.0" />
<output name="out" type="float" />
</nodedef>

<!--
Node: <dotproduct>
Perform a dot product of two 2-4 channel vectors
Expand Down
35 changes: 35 additions & 0 deletions libraries/stdlib/stdlib_ng.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,41 @@
<output name="out" type="vector2" nodename="N_switch_operationorder" />
</nodegraph>

<!--
Node: <distance>
Measures the distance between two points in 2D, 3D, or 4D.
-->
<nodegraph name="NG_distance_vector2" nodedef="ND_distance_vector2">
<subtract name="N_mtlxsubtract" type="vector2">
<input name="in1" type="vector2" interfacename="in1" />
<input name="in2" type="vector2" interfacename="in2" />
</subtract>
<magnitude name="N_mtlxmagnitude" type="float">
<input name="in" type="vector2" nodename="N_mtlxsubtract" />
</magnitude>
<output name="out" type="float" nodename="N_mtlxmagnitude" />
</nodegraph>
<nodegraph name="NG_distance_vector3" nodedef="ND_distance_vector3">
<subtract name="N_mtlxsubtract" type="vector3">
<input name="in1" type="vector3" interfacename="in1" />
<input name="in2" type="vector3" interfacename="in2" />
</subtract>
<magnitude name="N_mtlxmagnitude" type="float">
<input name="in" type="vector3" nodename="N_mtlxsubtract" />
</magnitude>
<output name="out" type="float" nodename="N_mtlxmagnitude" />
</nodegraph>
<nodegraph name="NG_distance_vector4" nodedef="ND_distance_vector4">
<subtract name="N_mtlxsubtract" type="vector4">
<input name="in1" type="vector4" interfacename="in1" />
<input name="in2" type="vector4" interfacename="in2" />
</subtract>
<magnitude name="N_mtlxmagnitude" type="float">
<input name="in" type="vector4" nodename="N_mtlxsubtract" />
</magnitude>
<output name="out" type="float" nodename="N_mtlxmagnitude" />
</nodegraph>

<!-- ======================================================================== -->
<!-- Adjustment nodes -->
<!-- ======================================================================== -->
Expand Down

0 comments on commit d49f7af

Please sign in to comment.