Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sjirka authored Apr 20, 2018
1 parent 781b551 commit dad9f35
Show file tree
Hide file tree
Showing 7 changed files with 450 additions and 315 deletions.
10 changes: 10 additions & 0 deletions PluginMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "StitchEasyCtxCmd.h"
#include "SeamsEasyManip.h"
#include "SeamsEasyManipContainer.h"
#include "SeamsEasyData.h"

#include <maya\MFnPlugin.h>

Expand All @@ -14,6 +15,12 @@ MStatus initializePlugin(MObject object) {
MFnPlugin fnPlugin(object, "Stepan Jirka", "1.0", "Any", &status);
CHECK_MSTATUS_AND_RETURN_IT(status);

status = fnPlugin.registerData(
SeamsEasyData::typeName,
SeamsEasyData::id,
SeamsEasyData::creator);
CHECK_MSTATUS_AND_RETURN_IT(status);

status = fnPlugin.registerNode(
"stitchEasy",
StitchEasyNode::id,
Expand Down Expand Up @@ -90,5 +97,8 @@ MStatus uninitializePlugin(MObject object) {
status = fnPlugin.deregisterNode(SeamsEasyManipContainer::id);
CHECK_MSTATUS_AND_RETURN_IT(status);

status = fnPlugin.deregisterData(SeamsEasyData::id);
CHECK_MSTATUS_AND_RETURN_IT(status);

return MS::kSuccess;
}
21 changes: 16 additions & 5 deletions SeamsEasyCmd.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "SeamsEasyCmd.h"
#include "StitchEasyNode.h"
#include "SeamsEasyData.h"

#include <maya\MSyntax.h>
#include <maya\MSelectionList.h>
Expand Down Expand Up @@ -95,6 +96,10 @@ MStatus SeamsEasyCmd::doIt(const MArgList& args)
MPlug
pOutputMesh;

SSeamMesh sMesh(m_path.node());
sMesh.setActiveEdges(component);
std::vector <SEdgeLoop> *loopsPtr = sMesh.activeLoopsPtr();

MPlugArray incomingConnections;
bool connected = fnMesh.findPlug("inMesh").connectedTo(incomingConnections, true, false);
if(connected)
Expand Down Expand Up @@ -159,12 +164,18 @@ MStatus SeamsEasyCmd::doIt(const MArgList& args)
status = m_dagMod.connect(fnNode.findPlug(SeamsEasyNode::aOutMesh), fnMesh.findPlug("inMesh"));
CHECK_MSTATUS_AND_RETURN_IT(status);

MFnComponentListData compData;
MObject compList = compData.create();
compData.add(component);

status = m_dagMod.newPlugValue(fnNode.findPlug(SeamsEasyNode::aSelectedEdges), compList);
unsigned i = 0;
MPlug loopPlug = fnNode.findPlug(SeamsEasyNode::aEdgeLoops, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
for (auto &data : *loopsPtr) {
SeamsEasyData *seamsData = new SeamsEasyData;
seamsData->edgeLoop = data;

MPlug loopElPlug = loopPlug.elementByLogicalIndex(i++, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
status = loopElPlug.setValue(seamsData);
CHECK_MSTATUS_AND_RETURN_IT(status);
}
}

if (isQuery || isEdit) {
Expand Down
149 changes: 149 additions & 0 deletions SeamsEasyData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#include "SeamsEasyData.h"

#include <maya\MArgList.h>

const MTypeId SeamsEasyData::id(0x0012789D);
const MString SeamsEasyData::typeName("seamsEasyData");

SeamsEasyData::SeamsEasyData(){
}

SeamsEasyData::~SeamsEasyData(){
}

void *SeamsEasyData::creator()
{
return new SeamsEasyData;
}

MTypeId SeamsEasyData::typeId() const {
return SeamsEasyData::id;
}

MString SeamsEasyData::name() const {
return SeamsEasyData::typeName;
}


MStatus SeamsEasyData::writeASCII(std::ostream &out)
{
out << edgeLoop.isReversed() << " ";
if (out.fail())
return MStatus::kFailure;

unsigned numberOfEdges = edgeLoop.numEdges();
out << numberOfEdges << " ";
if (out.fail())
return MStatus::kFailure;

for (unsigned i = 0; i < numberOfEdges; i++)
{
out << edgeLoop[i] << " ";
if (out.fail())
return MS::kFailure;

out << edgeLoop.isFlipped(i) << " ";
if (out.fail())
return MS::kFailure;
}

return MS::kSuccess;
}

MStatus SeamsEasyData::readASCII(const MArgList& args, unsigned int &end){
MStatus status;

bool isReversed = args.asBool(end++, &status);
edgeLoop.setReversed(isReversed);

unsigned numberOfEdges = (unsigned)args.asInt(end++, &status);
unsigned int numberOfArguments = args.length() - end;

if (numberOfEdges*2 != numberOfArguments)
return MS::kUnknownParameter;

for (unsigned i = 0; i < numberOfEdges; i++)
{
int index = args.asInt(end++, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
bool isFlipped = args.asBool(end++, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);

edgeLoop.pushBack(index, isFlipped);
}

return MS::kSuccess;
}

MStatus SeamsEasyData::writeBinary(std::ostream &out){

bool isReversed = edgeLoop.isReversed();
out.write((char*)&isReversed, sizeof(isReversed));
if (out.fail())
return MStatus::kFailure;

unsigned numberOfEdges = edgeLoop.numEdges();
out.write((char*)&numberOfEdges, sizeof(numberOfEdges));
if (out.fail())
return MStatus::kFailure;

for (unsigned i = 0; i < numberOfEdges; i++)
{
unsigned index = edgeLoop[i];
out.write((char*)&index, sizeof(index));
if (out.fail())
return MS::kFailure;

unsigned isFlipped = edgeLoop.isFlipped(i);
out.write((char*)&isFlipped, sizeof(isFlipped));
if (out.fail())
return MS::kFailure;
}

return MS::kSuccess;
}

MStatus SeamsEasyData::readBinary(std::istream &in, unsigned int length)
{
MStatus status;

if (length == 0)
return MS::kSuccess;

bool isReversed;
in.read((char*)&isReversed, sizeof(isReversed));
if (in.fail())
return MS::kFailure;
edgeLoop.setReversed(isReversed);

unsigned numberOfEdges;
in.read((char*)&numberOfEdges, sizeof(numberOfEdges));
if (in.fail())
return MS::kFailure;

for (unsigned i = 0; i < numberOfEdges; i++)
{
unsigned index;
in.read((char*)&index, sizeof(index));
if (in.fail())
return MS::kFailure;

bool isFlipped;
in.read((char*)&isFlipped, sizeof(isFlipped));
if (in.fail())
return MS::kFailure;

edgeLoop.pushBack(index, isFlipped);
}

return MS::kSuccess;
}

void SeamsEasyData::copy(const MPxData &other) {

if (this->typeId() != other.typeId())
return;

const SeamsEasyData &otherData = (const SeamsEasyData&)other;
this->edgeLoop = otherData.edgeLoop;
}
28 changes: 28 additions & 0 deletions SeamsEasyData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once
#include <maya\MPxData.h>
#include <maya\MTypeId.h>
#include <maya\MString.h>
#include "SEdgeLoop.h"


class SeamsEasyData : public MPxData{
public:
SeamsEasyData();
virtual ~SeamsEasyData();
static void * creator();

virtual MStatus readASCII(const MArgList& argList, unsigned int &idx);
virtual MStatus readBinary(istream& in, unsigned int length);
virtual MStatus writeASCII(ostream& out);
virtual MStatus writeBinary(ostream& out);

virtual void copy(const MPxData&);

virtual MTypeId typeId() const;
virtual MString name() const;

static const MString typeName;
static const MTypeId id;

SEdgeLoop edgeLoop;
};
Loading

0 comments on commit dad9f35

Please sign in to comment.