Skip to content

Commit

Permalink
Add 'Create Rivet' tool.
Browse files Browse the repository at this point in the history
The Create Rivet tool supports both "mesh two edges" and "point on poly
constraint" styles of rivets.
  • Loading branch information
david-cattermole committed Dec 29, 2023
1 parent 267bcd0 commit 9e5a1eb
Show file tree
Hide file tree
Showing 15 changed files with 876 additions and 2 deletions.
13 changes: 13 additions & 0 deletions docs/source/mmSolver.tools.createrivet.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mmSolver.tools.createrivet
==========================

.. automodule:: mmSolver.tools.createrivet
:members:
:undoc-members:

Tools
+++++

.. automodule:: mmSolver.tools.createrivet.tool
:members:
:undoc-members:
1 change: 1 addition & 0 deletions docs/source/mmSolver.tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mmSolver.tools
mmSolver.tools.createlens
mmSolver.tools.createline
mmSolver.tools.createmarker
mmSolver.tools.createrivet
mmSolver.tools.createskydome
mmSolver.tools.deformmarker
mmSolver.tools.duplicatemarker
Expand Down
25 changes: 23 additions & 2 deletions docs/source/mmSolver.utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ Load File
:members:
:undoc-members:


Load Marker
+++++++++++

Expand Down Expand Up @@ -131,7 +130,7 @@ Formats
.. automodule:: mmSolver.utils.loadmarker.formats.uvtrack
:members:
:undoc-members:

Node
++++

Expand Down Expand Up @@ -167,6 +166,28 @@ Re-Project
:members:
:undoc-members:

Rivet
+++++

.. automodule:: mmSolver.utils.rivet.meshtwoedge
:members:
:undoc-members:

.. automodule:: mmSolver.utils.rivet.nearestpointonmesh
:members:
:undoc-members:

.. automodule:: mmSolver.utils.rivet.pointonpoly
:members:
:undoc-members:

Selection
+++++++++

.. automodule:: mmSolver.utils.selection
:members:
:undoc-members:

Smooth
++++++

Expand Down
48 changes: 48 additions & 0 deletions docs/source/tools_generaltools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,54 @@ version 1, use this python code to run it.
# Remove selected Controller
tool.remove()
.. _create-rivet-tool-ref:

Create Rivet
------------

Create a transform locator node that follows the surface of a Mesh, i.e. the
transform is 'riveted' to the mesh.

There are two types of rivet types currently supported:

- **Mesh Two Edges** rivets are created from 2 Mesh shape edge
components, the same as using the classic `rivet.mel`_ script. If
the topology of the underlying mesh changes, the rivet will move
across the surface.

- **Point On Poly Constraint** rivets are created at selected
vertices and can be moved along the surface with the UV
coordinates. If the UV coordinates of the underlying mesh changes,
the rivet may move. This rivet-style will not work with UV
coordinates outside the regular 0.0 to 1.0 UV space as is commonly
used with texture UDIMs.

Usage:

1) Select a Maya Mesh components.

- Select Mesh Vertices to create **Point On Poly Constraint**
rivets.

- Select 2 Mesh Edges to create a single **Mesh Two Edges** rivet.

2) Run tool.

- A rivet locator will be created.

- For a **Point On Poly Constraint** rivet, you can adjust the `U`
and `V` coordinates from the rivet locator, if needed.

To run the tool, use this Python command:

.. code:: python
import mmSolver.tools.createrivet.tool as tool
tool.main()
.. _rivet.mel:
https://www.highend3d.com/maya/script/rivet-button-for-maya

.. _marker-bundle-rename-tool-ref:

Marker Bundle Rename
Expand Down
20 changes: 20 additions & 0 deletions python/mmSolver/tools/createrivet/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (C) 2023 David Cattermole.
#
# This file is part of mmSolver.
#
# mmSolver is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# mmSolver is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
#
"""
Create a Rivet on a surface.
"""
92 changes: 92 additions & 0 deletions python/mmSolver/tools/createrivet/tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Copyright (C) 2014, 2023 David Cattermole.
#
# This file is part of mmSolver.
#
# mmSolver is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# mmSolver is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
#
"""
The Create Rivet tool.
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import maya.cmds

import mmSolver.logger
import mmSolver.utils.rivet.meshtwoedge as utils_rivet_meshtwoedge
import mmSolver.utils.rivet.pointonpoly as utils_rivet_pointonpoly
import mmSolver.utils.selection as utils_selection


LOG = mmSolver.logger.get_logger()


def _create_mesh_two_edge_rivet(edges):
assert len(edges) == 2
edge_a = edges[0]
edge_b = edges[1]
mesh_shape = edges[0].partition('.')[0]
assert maya.cmds.objExists(mesh_shape)
rivet = utils_rivet_meshtwoedge.create(mesh_shape, edge_a, edge_b)
return [rivet.rivet_transform]


def _create_point_on_poly_rivets(vertices):
assert len(vertices) > 0
select_nodes = []
for vertex in vertices:
mesh_shape = vertex.partition('.')[0]
mesh_transform = maya.cmds.listRelatives(
mesh_shape, parent=True, fullPath=True, type='transform'
)[0]
vertex_world_position = maya.cmds.xform(
vertex, query=True, worldSpace=True, translation=True
)
rivet = utils_rivet_pointonpoly.create(
mesh_transform, mesh_shape, in_position=vertex_world_position
)
select_nodes.append(rivet.rivet_transform)
return select_nodes


def main():
"""
Create Rivet(s) from the selected mesh components.
If 2 edges are selected, this tool will create a two-edge rivet,
like the 'rivet.mel'.
"""
error_msg = 'Please select Mesh Vertices or 2 Mesh Edges.'
selection = maya.cmds.ls(selection=True, long=True) or []
if len(selection) == 0:
LOG.error(error_msg)
return

vertices = utils_selection.filter_mesh_vertex_selection(selection)
edges = utils_selection.filter_mesh_edge_selection(selection)
if len(vertices + edges) == 0:
LOG.error(error_msg)
return

if len(vertices) > 0:
select_nodes = _create_point_on_poly_rivets(vertices)
maya.cmds.select(select_nodes, replace=True)
elif len(edges) == 2:
select_nodes = _create_mesh_two_edge_rivet(edges)
maya.cmds.select(select_nodes, replace=True)
else:
LOG.error(error_msg)
return
20 changes: 20 additions & 0 deletions python/mmSolver/utils/rivet/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (C) 2023 David Cattermole.
#
# This file is part of mmSolver.
#
# mmSolver is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# mmSolver is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
#
"""
Rivet utilities.
"""
Loading

0 comments on commit 9e5a1eb

Please sign in to comment.