Skip to content

Commit

Permalink
Merge pull request #5 from yamahigashi/develop
Browse files Browse the repository at this point in the history
Added Collision mode Kernel VS Kernel
  • Loading branch information
yamahigashi authored Aug 6, 2023
2 parents 99b2b47 + ab2cf75 commit 5e37881
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 96 deletions.
68 changes: 68 additions & 0 deletions scripts/AEintersectionMarkerTemplate.mel
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
proc _registerNodeHelp(string $type, string $cmd)
{
global string $gAttributeEditorNodeTypeArray[];
global string $gAttributeEditorHelpCommandArray[];

int $idx, $len = size($gAttributeEditorNodeTypeArray);
for ($idx = 0; $idx < $len; ++$idx) {
if ($type == $gAttributeEditorNodeTypeArray[$idx]) break;
}

if ($idx < $len) {
$gAttributeEditorHelpCommandArray[$idx] = $cmd;
} else {
$gAttributeEditorNodeTypeArray[$idx] = $type;
$gAttributeEditorHelpCommandArray[$idx] = $cmd;
}
}


global proc AEintersectionMarkerTemplate(string $nodename)
{
editorTemplate -beginLayout "Intersection Marker Attributes" -collapse 0;

{
string $url = "https://github.com/yamahigashi/MayaIntersectionMarker";
_registerNodeHelp("intersectionMarker", "showHelp -a \""+ $url +"\"");

// editorTemplate -beginLayout "Mesh Inputs" -collapse 0;
// editorTemplate -addControl "meshA";
// editorTemplate -addControl "meshB";
// editorTemplate -endLayout;
//
// editorTemplate -beginLayout "Offset Matrices" -collapse 0;
// editorTemplate -addControl "offsetMatrixA";
// editorTemplate -addControl "offsetMatrixB";
// editorTemplate -endLayout;

editorTemplate -beginLayout "Display Options" -collapse 0;
editorTemplate -addControl "showMeshA";
editorTemplate -addControl "showMeshB";
// editorTemplate -addControl "restIntersected";
editorTemplate -endLayout;

editorTemplate -beginLayout "Checksums" -collapse 0;
editorTemplate -addControl "vertexChecksumA";
editorTemplate -addControl "vertexChecksumB";
editorTemplate -endLayout;

editorTemplate -beginLayout "Kernel Options" -collapse 0;
editorTemplate -addControl "kernel";
editorTemplate -addControl "collisionMode";
editorTemplate -endLayout;

// editorTemplate -beginLayout "Output" -collapse 0;
// editorTemplate -addControl "outputIntersected";
// editorTemplate -endLayout;
}

// End layout for IntersectionMarkerNode
editorTemplate -endLayout;

AEdependNodeTemplate($nodename);

editorTemplate("-addExtraControls");
editorTemplate("-endScrollLayout");
}

// AEIntersectionMarkerNodeTemplate($gAECurrentTab);
18 changes: 14 additions & 4 deletions src/intersectionMarkerDrawOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ MUserData* IntersectionMarkerDrawOverride::prepareForDraw(
prevChecksum = newChecksum;

MFnMesh meshAFn;
MFnMesh meshBFn;
status = node->getInputDagMesh(node->meshA, meshAFn);
CHECK_MSTATUS_AND_RETURN_DATA("prepareForDraw: meshAFn is null");

MFnMesh meshBFn;
status = node->getInputDagMesh(node->meshB, meshBFn);
CHECK_MSTATUS_AND_RETURN_DATA("prepareForDraw: meshBFn is null");

Expand All @@ -122,8 +122,18 @@ MUserData* IntersectionMarkerDrawOverride::prepareForDraw(
node->getOffsetMatrix(node->offsetMatrixA, outMatrixA);
node->getOffsetMatrix(node->offsetMatrixB, outMatrixB);

addIntersectedVertices(meshAFn, data, node->intersectedFaceIdsA, outMatrixA);
addIntersectedVertices(meshBFn, data, node->intersectedFaceIdsB, outMatrixB);
MPlug showMeshAPlug = depNodeFn.findPlug("showMeshA", false, &status);
bool showMeshA = showMeshAPlug.asBool();
MPlug showMeshBPlug = depNodeFn.findPlug("showMeshB", false, &status);
bool showMeshB = showMeshBPlug.asBool();

if (showMeshA) {
addIntersectedVertices(meshAFn, data, node->intersectedFaceIdsA, outMatrixA);
}

if (showMeshB) {
addIntersectedVertices(meshBFn, data, node->intersectedFaceIdsB, outMatrixB);
}

return data;
}
Expand Down Expand Up @@ -183,7 +193,7 @@ void IntersectionMarkerDrawOverride::addUIDrawables(
// cast the user data back to our to our struct
const IntersectionMarkerData* markerData = dynamic_cast<const IntersectionMarkerData*>(data);
if (!markerData) {
MGlobal::displayInfo("addUIDrawables: markerData is null");
// MGlobal::displayInfo("addUIDrawables: markerData is null");
return;
}

Expand Down
39 changes: 38 additions & 1 deletion src/intersectionMarkerNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ MObject IntersectionMarkerNode::restIntersected;

MObject IntersectionMarkerNode::vertexChecksumA;
MObject IntersectionMarkerNode::vertexChecksumB;
MObject IntersectionMarkerNode::showMeshA;
MObject IntersectionMarkerNode::showMeshB;
MObject IntersectionMarkerNode::kernelType;
MObject IntersectionMarkerNode::collisionMode;

Expand Down Expand Up @@ -96,6 +98,23 @@ MStatus IntersectionMarkerNode::initialize()
status = addAttribute(offsetMatrixB);
CHECK_MSTATUS_AND_RETURN_IT(status);

// Showing Result of Intersection
showMeshA = nAttr.create(SHOW_MESH_A, SHOW_MESH_A, MFnNumericData::kBoolean, 1);
status = addAttribute(showMeshA);
nAttr.setStorable(true);
nAttr.setWritable(true);
nAttr.setReadable(false);
nAttr.setKeyable(true);
CHECK_MSTATUS_AND_RETURN_IT(status);

showMeshB = nAttr.create(SHOW_MESH_B, SHOW_MESH_B, MFnNumericData::kBoolean, 1);
status = addAttribute(showMeshB);
nAttr.setStorable(true);
nAttr.setWritable(true);
nAttr.setReadable(false);
nAttr.setKeyable(true);
CHECK_MSTATUS_AND_RETURN_IT(status);

// Initialize Rest Intersected
restIntersected = nAttr.create(REST_INTERSECTED, REST_INTERSECTED, MFnNumericData::kInt, -1);
nAttr.setStorable(true);
Expand Down Expand Up @@ -157,6 +176,8 @@ MStatus IntersectionMarkerNode::initialize()
status = attributeAffects(offsetMatrixB, outputIntersected);
status = attributeAffects(meshA, outputIntersected);
status = attributeAffects(meshB, outputIntersected);
status = attributeAffects(showMeshA, outputIntersected);
status = attributeAffects(showMeshB, outputIntersected);
CHECK_MSTATUS_AND_RETURN_IT(status);

status = attributeAffects(kernelType, outputIntersected);
Expand Down Expand Up @@ -190,6 +211,10 @@ MStatus IntersectionMarkerNode::preEvaluation(
CHECK_MSTATUS_AND_RETURN_IT(status);

dirty = dirty || evaluationNode.dirtyPlugExists(collisionMode, &status);
dirty = dirty || evaluationNode.dirtyPlugExists(showMeshA, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);

dirty = dirty || evaluationNode.dirtyPlugExists(showMeshB, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);

if (dirty) {
Expand Down Expand Up @@ -222,7 +247,9 @@ MStatus IntersectionMarkerNode::postEvaluation(
(evaluationNode.dirtyPlugExists(offsetMatrixA, &status) && status ) ||
(evaluationNode.dirtyPlugExists(offsetMatrixB, &status) && status ) ||
(evaluationNode.dirtyPlugExists(kernelType, &status) && status ) ||
(evaluationNode.dirtyPlugExists(collisionMode, &status) && status )
(evaluationNode.dirtyPlugExists(collisionMode, &status) && status ) ||
(evaluationNode.dirtyPlugExists(showMeshA, &status) && status ) ||
(evaluationNode.dirtyPlugExists(showMeshB, &status) && status )
) {
MDataBlock block = forceCache();
MDataHandle meshAHandle = block.inputValue(meshA, &status);
Expand Down Expand Up @@ -277,6 +304,13 @@ MStatus IntersectionMarkerNode::compute(const MPlug &plug, MDataBlock &dataBlock
MMatrix offsetA = offsetAHandle.asMatrix();
MMatrix offsetB = offsetBHandle.asMatrix();

MDataHandle showMeshAHandle = dataBlock.inputValue(showMeshA);
MDataHandle showMeshBHandle = dataBlock.inputValue(showMeshB);
bool showA = showMeshAHandle.asBool();
bool showB = showMeshBHandle.asBool();
showMeshAHandle.setClean();
showMeshBHandle.setClean();

// -------------------------------------------------------------------------------------------
// update checksums
// MGlobal::displayInfo("update checksums...");
Expand All @@ -288,12 +322,15 @@ MStatus IntersectionMarkerNode::compute(const MPlug &plug, MDataBlock &dataBlock

int checkA = vertexChecksumAHandle.asInt();
int checkB = vertexChecksumBHandle.asInt();
newCheckA = newCheckA ^ int(showA);
newCheckB = newCheckB ^ int(showB);

// If the checksums are the same, then we don't need to do anything
// because the meshes have not changed.
if (checkA == newCheckA && checkB == newCheckB) {
vertexChecksumAHandle.setClean();
vertexChecksumBHandle.setClean();

return MS::kSuccess;
}

Expand Down
4 changes: 4 additions & 0 deletions src/intersectionMarkerNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#define REST_INTERSECTED "restIntersected"
#define VERTEX_CHECKSUM_A "vertexChecksumA"
#define VERTEX_CHECKSUM_B "vertexChecksumB"
#define SHOW_MESH_A "showMeshA"
#define SHOW_MESH_B "showMeshB"

#define KERNEL "kernel"
#define COLLISION_MODE "collisionMode"
Expand Down Expand Up @@ -153,6 +155,8 @@ std::shared_ptr<SpatialDivisionKernel> getActiveKernel() const;

static MObject vertexChecksumA;
static MObject vertexChecksumB;
static MObject showMeshA;
static MObject showMeshB;
static MObject kernelType;
static MObject collisionMode;

Expand Down
Loading

0 comments on commit 5e37881

Please sign in to comment.