Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "cgcmake"]
path = cgcmake
url = git@github.com:chadmv/cgcmake.git
url = https://github.com/chadmv/cgcmake.git
2 changes: 1 addition & 1 deletion cgcmake
34 changes: 24 additions & 10 deletions scripts/cvwrap/bindui.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from __future__ import absolute_import
from __future__ import print_function

import maya.cmds as cmds


if cmds.about(api=True) >= 201700:
from PySide2 import QtWidgets as QtGui
else:
Expand All @@ -7,6 +12,8 @@
from maya.app.general.mayaMixin import MayaQWidgetBaseMixin

_win = None


def show():
global _win
if _win == None:
Expand All @@ -27,34 +34,40 @@ def __init__(self, parent=None):
hbox = QtGui.QHBoxLayout()
vbox.addLayout(hbox)
label = QtGui.QLabel('Components to rebind:')
label.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
label.setSizePolicy(QtGui.QSizePolicy.Preferred,
QtGui.QSizePolicy.Fixed)
label.setMinimumWidth(label_width)
label.setMaximumWidth(label_width)
hbox.addWidget(label)
self.components_to_rebind = QtGui.QLineEdit()
self.components_to_rebind.textChanged.connect(self.populate_cvwrap_dropdown)
self.components_to_rebind.textChanged.connect(
self.populate_cvwrap_dropdown)
hbox.addWidget(self.components_to_rebind)
button = QtGui.QPushButton('Set Components')
button.released.connect(partial(self.set_selected_text, widget=self.components_to_rebind))
button.released.connect(
partial(self.set_selected_text, widget=self.components_to_rebind))
hbox.addWidget(button)

hbox = QtGui.QHBoxLayout()
vbox.addLayout(hbox)
label = QtGui.QLabel('Faces to rebind to:')
label.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
label.setSizePolicy(QtGui.QSizePolicy.Preferred,
QtGui.QSizePolicy.Fixed)
label.setMinimumWidth(label_width)
label.setMaximumWidth(label_width)
hbox.addWidget(label)
self.target_faces = QtGui.QLineEdit()
hbox.addWidget(self.target_faces)
button = QtGui.QPushButton('Set Faces')
button.released.connect(partial(self.set_selected_text, widget=self.target_faces))
button.released.connect(partial(self.set_selected_text,
widget=self.target_faces))
hbox.addWidget(button)

hbox = QtGui.QHBoxLayout()
vbox.addLayout(hbox)
label = QtGui.QLabel('cvWrap node:')
label.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
label.setSizePolicy(QtGui.QSizePolicy.Preferred,
QtGui.QSizePolicy.Fixed)
label.setMinimumWidth(label_width)
label.setMaximumWidth(label_width)
hbox.addWidget(label)
Expand All @@ -64,7 +77,8 @@ def __init__(self, parent=None):
hbox = QtGui.QHBoxLayout()
vbox.addLayout(hbox)
label = QtGui.QLabel('Sample radius:')
label.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
label.setSizePolicy(QtGui.QSizePolicy.Preferred,
QtGui.QSizePolicy.Fixed)
label.setMinimumWidth(label_width)
label.setMaximumWidth(label_width)
hbox.addWidget(label)
Expand Down Expand Up @@ -106,7 +120,8 @@ def rebind(self):
faces = self.target_faces.text().split()
wrap_node = self.cvwrap_combo.currentText()
radius = self.sample_radius.value()
# Make sure the faces are actual faces. If they are not, convert to faces.
# Make sure the faces are actual faces.
# If they are not, convert to faces.
cmds.select(faces)
cmds.ConvertSelectionToFaces()
faces = cmds.ls(sl=True)
Expand All @@ -115,5 +130,4 @@ def rebind(self):
cmds.ConvertSelectionToVertices()
cmds.select(faces, add=True)
cmds.cvWrap(rb=wrap_node, radius=radius)
print 'Rebounded vertices'

print('Rebounded vertices')
33 changes: 21 additions & 12 deletions scripts/cvwrap/menu.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import maya.cmds as cmds
import maya.mel as mel
import maya.OpenMayaUI as OpenMayaUI
from __future__ import absolute_import
from __future__ import print_function

import os

import maya.mel as mel
import maya.cmds as cmds
# import maya.OpenMayaUI as OpenMayaUI

if cmds.about(api=True) >= 201700:
from PySide2 import QtGui
else:
Expand Down Expand Up @@ -54,9 +59,9 @@ def create_menuitems():
sourceType='python', parent=submenu)
MENU_ITEMS.append(item)
elif menu_label == 'Cluster' and section == 'Paint Weights':
item = cmds.menuItem(label="cvWrap", command=paint_cvwrap_weights,
sourceType='python', insertAfter=item, parent=menu)
MENU_ITEMS.append(item)
item = cmds.menuItem(label="cvWrap", command=paint_cvwrap_weights,
sourceType='python', insertAfter=item, parent=menu)
MENU_ITEMS.append(item)


def create_cvwrap(*args, **kwargs):
Expand All @@ -65,9 +70,10 @@ def create_cvwrap(*args, **kwargs):
if len(sel) >= 2:
kwargs = get_create_command_kwargs()
result = cmds.cvWrap(**kwargs)
print result
print(result)
else:
raise RuntimeError("Select at least one surface and one influence object.")
raise RuntimeError(
"Select at least one surface and one influence object.")


def get_create_command_kwargs():
Expand Down Expand Up @@ -98,7 +104,8 @@ def get_create_command_kwargs():
args['newBindMesh'] = True

if cmds.textFieldButtonGrp(BIND_FILE_WIDGET, exists=True):
bind_file = cmds.textFieldButtonGrp(BIND_FILE_WIDGET, q=True, text=True)
bind_file = cmds.textFieldButtonGrp(
BIND_FILE_WIDGET, q=True, text=True)
bind_file = os.path.expandvars(bind_file.strip())
if bind_file:
if os.path.exists(bind_file):
Expand Down Expand Up @@ -162,7 +169,9 @@ def close_option_box(*args, **kwargs):


def display_bind_file_dialog(*args, **kwargs):
"""Displays the dialog to choose the binding file with which to create the cvWrap deformer."""
"""Displays the dialog to choose the binding file with
which to create the cvWrap deformer.
"""
root_dir = cmds.workspace(q=True, rootDirectory=True)
start_directory = os.path.join(root_dir, 'data')
file_path = cmds.fileDialog2(fileFilter='*.wrap', dialogStyle=2, fileMode=1,
Expand Down Expand Up @@ -221,8 +230,8 @@ def get_wrap_node_from_selected():
if len(wrap_nodes) == 1:
return wrap_nodes[0]
else:
# Multiple wrap nodes are deforming the mesh. Let the user choose which one
# to use.
# Multiple wrap nodes are deforming the mesh.
# Let the user choose which one to use.
return QtGui.QInputDialog.getItem(None, 'Select cvWrap node', 'cvWrap node:', wrap_nodes)


Expand Down
80 changes: 40 additions & 40 deletions src/bindingio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ void ReadAttribute<double, MMatrix>(std::ifstream &in, MMatrix &matrix) {
MStatus BindingIO::ExportBinding(std::ofstream& out, MObject& oWrapNode) {
MStatus status;
MFnWeightGeometryFilter fnWrapNode(oWrapNode, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);

if (fnWrapNode.typeId() != CVWrap::id) {
MGlobal::displayError(fnWrapNode.name() + " is not a cvWrap node.");
CHECK_MSTATUS_AND_RETURN_IT(MS::kFailure);
CHECK_STATUS_AND_RETURN_IT(MS::kFailure);
}

out.write((char *)&kWrapFileVersion, sizeof(float));

MPlug plugBindData = fnWrapNode.findPlug(CVWrap::aBindData, false, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
// Get the input geometry so we can get the geometry indices
MObjectArray outputGeometry;
status = fnWrapNode.getOutputGeometry(outputGeometry);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
// Write the number of geometry
unsigned int geometryCount = outputGeometry.length();
out.write((char *)(&geometryCount), sizeof(geometryCount));
Expand All @@ -60,63 +60,63 @@ MStatus BindingIO::ExportBinding(std::ofstream& out, MObject& oWrapNode) {
unsigned int geomIndex = fnWrapNode.indexForOutputShape(outputGeometry[i], &status);
// Get the plugs to the binding attributes for this geometry
MPlug plugBind = plugBindData.elementByLogicalIndex(geomIndex, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MPlug plugSampleWeights = plugBind.child(CVWrap::aSampleWeights, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MPlug plugSampleVerts = plugBind.child(CVWrap::aSampleComponents, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MPlug plugSampleBindMatrix = plugBind.child(CVWrap::aBindMatrix, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MPlug plugTriangleVerts = plugBind.child(CVWrap::aTriangleVerts, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MPlug plugBarycentricWeights = plugBind.child(CVWrap::aBarycentricWeights, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);

unsigned int numElements = plugSampleWeights.numElements();
out.write((char *)(&numElements), sizeof(numElements));

for (unsigned int j = 0; j < numElements; ++j) {
// Write the logical index
MPlug plugSampleVertElement = plugSampleVerts.elementByPhysicalIndex(j, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
unsigned int logicalIndex = plugSampleVertElement.logicalIndex();
out.write((char *)(&logicalIndex), sizeof(logicalIndex));

// Export sample vertex ids
MObject oSampleIds = plugSampleVertElement.asMObject();
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MFnIntArrayData fnIntData(oSampleIds, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MIntArray sampleIds = fnIntData.array();
WriteAttribute<int, MIntArray>(out, sampleIds);

// Export sample weights
MObject oWeightData = plugSampleWeights.elementByPhysicalIndex(j, &status).asMObject();
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MFnDoubleArrayData fnDoubleData(oWeightData);
MDoubleArray weights = fnDoubleData.array();
WriteAttribute<double, MDoubleArray>(out, weights);

// Export bind matrix
MObject oBindMatrix = plugSampleBindMatrix.elementByPhysicalIndex(j, &status).asMObject();
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MFnMatrixData fnMatrixData(oBindMatrix, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
WriteAttribute<double, MMatrix>(out, fnMatrixData.matrix());

// Export triangle vertices
MObject oTriangleVerts = plugTriangleVerts.elementByPhysicalIndex(j, &status).asMObject();
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MFnNumericData fnNumericData(oTriangleVerts, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
fnNumericData.getData3Int(triangleVerts[0], triangleVerts[1], triangleVerts[2]);
WriteAttribute<int, MIntArray>(out, triangleVerts);

// Export the barycentric weights
MObject oBaryWeights = plugBarycentricWeights.elementByPhysicalIndex(j, &status).asMObject();
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MFnNumericData fnBaryData(oBaryWeights, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
fnBaryData.getData3Float(baryCoords[0], baryCoords[1], baryCoords[2]);
WriteAttribute<float, MFloatArray>(out, baryCoords);
}
Expand All @@ -133,9 +133,9 @@ MStatus BindingIO::ImportBinding(std::ifstream& in, MObject& oWrapNode) {
MStatus status;

MFnWeightGeometryFilter fnWrapNode(oWrapNode, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MPlug plugBindData = fnWrapNode.findPlug(CVWrap::aBindData, false, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);

float version;
in.read((char *)(&version), sizeof(float));
Expand All @@ -152,17 +152,17 @@ MStatus BindingIO::ImportBinding(std::ifstream& in, MObject& oWrapNode) {
for (unsigned int geomIndex = 0; geomIndex < geometryCount; ++geomIndex) {
// Get the plugs to the binding attributes for this geometry
MPlug plugBind = plugBindData.elementByLogicalIndex(geomIndex, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MPlug plugSampleWeights = plugBind.child(CVWrap::aSampleWeights, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MPlug plugSampleVerts = plugBind.child(CVWrap::aSampleComponents, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MPlug plugSampleBindMatrix = plugBind.child(CVWrap::aBindMatrix, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MPlug plugTriangleVerts = plugBind.child(CVWrap::aTriangleVerts, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
MPlug plugBarycentricWeights = plugBind.child(CVWrap::aBarycentricWeights, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);

unsigned int numElements = plugSampleWeights.numElements();
in.read((char *)(&numElements), sizeof(numElements));
Expand All @@ -174,46 +174,46 @@ MStatus BindingIO::ImportBinding(std::ifstream& in, MObject& oWrapNode) {
MIntArray sampleIds;
ReadAttribute<int, MIntArray>(in, sampleIds);
MObject oIntData = fnIntData.create(sampleIds, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
plugSampleVerts.elementByLogicalIndex(logicalIndex, &status).setMObject(oIntData);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);

// Sample weights
MDoubleArray weights;
ReadAttribute<double, MDoubleArray>(in, weights);
MObject oDoubleData = fnDoubleData.create(weights, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
plugSampleWeights.elementByLogicalIndex(logicalIndex, &status).setMObject(oDoubleData);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);

// Bind matrix
MMatrix bindMatrix;
ReadAttribute<double, MMatrix>(in, bindMatrix);
MObject oMatrixData = fnMatrixData.create(bindMatrix, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
plugSampleBindMatrix.elementByLogicalIndex(logicalIndex, &status).setMObject(oMatrixData);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);

// Triangle vertices
MIntArray triangleVertices;
ReadAttribute<int, MIntArray>(in, triangleVertices);
MObject oNumericData = fnNumericData.create(MFnNumericData::k3Int, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
status = fnNumericData.setData3Int(triangleVertices[0], triangleVertices[1],
triangleVertices[2]);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
plugTriangleVerts.elementByLogicalIndex(logicalIndex, &status).setMObject(oNumericData);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);

// Barycentric coordinates
MFloatArray coords;
ReadAttribute<float, MFloatArray>(in, coords);
oNumericData = fnNumericData.create(MFnNumericData::k3Float, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
status = fnNumericData.setData3Float(coords[0], coords[1], coords[2]);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
plugBarycentricWeights.elementByLogicalIndex(logicalIndex, &status).setMObject(oNumericData);
CHECK_MSTATUS_AND_RETURN_IT(status);
CHECK_STATUS_AND_RETURN_IT(status);
}
}
MGlobal::displayInfo("Wrap binding imported.");
Expand Down
Loading