Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add distance math node #1333

Merged
merged 14 commits into from
May 23, 2023
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