Commit 2b678201 authored by Stefan Göbel's avatar Stefan Göbel

Initial commit

* Version 0.2
parents
This diff is collapsed.
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
CPP = g++-4.1
CPPFLAGS1 = -c -m64 -O3 -pthread -pipe
CPPFLAGS1 += -I/usr/autodesk/maya2009-x64/include -I/usr/X11R6/include
CPPFLAGS1 += -D_BOOL -DLINUX_64 -DREQUIRE_IOSTREAM
CPPFLAGS1 += -fPIC -Wno-deprecated -fno-gnu-keywords
CPPFLAGS2 = -shared -m64 -O3 -pthread -pipe -Bsymbolic
CPPFLAGS2 += -D_BOOL -DLINUX -DREQUIRE_IOSTREAM
CPPFLAGS2 += -Wno-deprecated -fno-gnu-keywords -Wl
CPPFLAGS2 += -L/usr/autodesk/maya2009-x64/lib -lOpenMaya -lFoundation
all: oppositeFace
oppositeFace.o: oppositeFace.cpp
$(CPP) $(CPPFLAGS1) oppositeFace.cpp
oppositeFace: oppositeFace.o
$(CPP) $(CPPFLAGS2) -o oppositeFace.so oppositeFace.o
clean:
rm -f *.o *.so
oppositeFace 0.2
========================================================================
Autodesk Maya plugin to find opposite faces in a polygon mesh.
Note: This plugin was developed for Autodesk Maya 2009, and only tested
with this version. It is likely to work with any later version, though,
the relevant APIs seem to be unchanged.
This plugin provides the following function:
oppositeFace
------------------------------------------------------------------------
Find the opposite face to the selected face in the same polygon mesh.
Parameters:
-offset (-o) default: 0.01
-tolerance (-t) default: 1e-6
-distance (-d) default: 1000
It seems that all values have to be specified in cm no matter what the
current unit is set to. This may be the case only for specific versions
of Autodesk Maya.
Usage:
Select a face of a polygon mesh and run the oppositeFace command. The
return value of the command will be a list with this information:
[ face_number, distance, hit_point_x, hit_point_y, hit_point_z ]
face_number - the index of the opposite face
distance - distance between the two faces
hit_point_* - x, y and z coordinates of the hit point
All the list elements are strings, you need to explicitely convert the
values if required!
The function will start the search for an opposite face at a point
located in -offset distance from the center of the selected face (in
negative face normal direction), the search will continue in negative
normal direction until a face of the same (!) polygon mesh is hit. The
point hit on that polygon will be returned in hit_point_x, hit_point_y
and hit_point_z (ie. the last three elements of the result list). These
are world space coordinates.
The -distance parameter specifies the maximum distance within which hits
will be considered.
The -tolerance parameter is directly passed to the API function
MFnMesh::closestIntersection, please consult the API documentation for
more details:
<http://download.autodesk.com/us/maya/2009help/API/class_m_fn_mesh.html>
If no face was found face_number will be "-1", all other values will be
"0".
Compiling
------------------------------------------------------------------------
Modify the Makefile according to your needs, then run
make
You need to copy the compiled plugin to an appropriate directory so it
can be accessed by Maya. Please see the Maya documentation for details.
Copyright And License
------------------------------------------------------------------------
Copyright 2009, 2014 Stefan Göbel - <oppositeface -at- subtype -dot- de>
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
/*********************************************************************************************
Copyright 2009, 2014 Stefan Goebel - <oppositeFace -at- subtype -dot- de>
This program 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.
This program 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 this
program. If not, see <http://www.gnu.org/licenses/>.
**********************************************************************************************
oppositeFace 0.2 - Autodesk Maya plugin to find a polygon face opposing the selected face.
Usage: * Make sure the plugin is loaded in the plugin manager.
* Select a face of a polygon mesh.
* Run the 'oppositeFace' MEL command.
* The return value of the command is a list with the following information:
[ face_number, distance, hit_point_x, hit_point_y, hit_point_z ]
* All these values are strings, so you need to explicitely convert them if required!
* The face_number specifies the opposing face, the distance is the distance of the
center point of the selected face to the opposing face in negative polygon normal
direction, the hit_point coordinates are the coordinates where the line starting
from the center of the selected face in negative normal direction intersects the
opposing face, these are world space coordinates.
* If no opposing face is found, the face_number will be "-1", all other return values
will be "0".
* The search for the face will actually start at a point a bit away from the face's
center point (default value is a distance of 0.01) to avoid hitting the selected
face itself. You can change the start distance with the -o parameter.
* The tolerance (see MFnMesh::closestIntersection in the API guide) can be changed
with the -t parameter (default value is 1e-6).
* The maximum search distance can be changed with the -d parameter, default value is
1000.
* All these values must be specified in cm.
Todo: * Add possibility to query only specific information (eg. only the face number).
* Add caching of the results, to query additional information without recalculation.
*********************************************************************************************/
#include <maya/MArgDatabase.h>
#include <maya/MArgList.h>
#include <maya/MFloatPoint.h>
#include <maya/MFloatVector.h>
#include <maya/MDagPath.h>
#include <maya/MGlobal.h>
#include <maya/MItMeshPolygon.h>
#include <maya/MItSelectionList.h>
#include <maya/MFnMesh.h>
#include <maya/MFnPlugin.h>
#include <maya/MPxCommand.h>
#include <maya/MSelectionList.h>
#include <maya/MString.h>
#include <maya/MSyntax.h>
#define VERSION "0.2"
#define API "Any"
#define offsetFlag "-o"
#define offsetFlagLong "-offset"
#define toleranceFlag "-t"
#define toleranceFlagLong "-tolerance"
#define distanceFlag "-d"
#define distanceFlagLong "-distance"
class oppositeFace: public MPxCommand {
public:
MStatus doIt (const MArgList&);
static void* creator ();
bool isUndoable () const;
static MSyntax newSyntax ();
};
MStatus oppositeFace::doIt (const MArgList& args) {
MStatus stat;
double offset = 0.01;
double tolerance = 1e-6;
double maxDistance = 1000;
MArgDatabase argData (syntax (), args, &stat);
if (stat != MS::kSuccess) {
displayError ("One or more invalid arguments!");
return stat;
}
if (argData.isFlagSet (offsetFlag)) {
argData.getFlagArgument (offsetFlag, 0, offset);
}
if (argData.isFlagSet (toleranceFlag)) {
argData.getFlagArgument (toleranceFlag, 0, tolerance);
}
if (argData.isFlagSet (distanceFlag)) {
argData.getFlagArgument (distanceFlag, 0, maxDistance);
}
MSelectionList selList;
stat = MGlobal::getActiveSelectionList (selList);
if (stat != MS::kSuccess) {
displayError ("Error getting selection list: " + stat.errorString ());
return stat;
}
MItSelectionList itSelList (selList, MFn::kMeshPolygonComponent, &stat);
if (stat != MS::kSuccess) {
displayError ("Error iterating selection list: " + stat.errorString ());
return stat;
}
MObject obj;
MDagPath dagPath;
stat = itSelList.getDagPath (dagPath, obj);
if (stat != MS::kSuccess || obj.isNull ()) {
displayError ("No faces selected!");
return MS::kFailure;
}
MFnMesh mesh (dagPath, &stat);
if (stat != MS::kSuccess) {
displayError ("Could not get mesh: " + stat.errorString ());
return stat;
}
MItMeshPolygon itMeshPoly (dagPath, obj, &stat);
if (stat != MS::kSuccess) {
displayError ("Error iterating polygons: " + stat.errorString ());
return stat;
}
if (selList.length () != 1 || itMeshPoly.count () != 1) {
displayError ("Please select one (and only one) face!");
return MS::kFailure;
}
MPoint center = itMeshPoly.center (MSpace::kWorld, &stat);
if (stat != MS::kSuccess) {
displayError ("Error getting center of face: " + stat.errorString ());
return stat;
}
MVector normal;
stat = itMeshPoly.getNormal (normal, MSpace::kWorld);
if (stat != MS::kSuccess) {
displayError ("Could not get face normal: " + stat.errorString ());
return stat;
}
MFloatPoint fCenter (center);
MFloatVector fNormal (normal * -1);
MFloatPoint hitPoint;
float distance;
int face;
fNormal.normalize ();
fCenter += fNormal * offset;
bool hit = mesh.anyIntersection (
fCenter,
fNormal,
NULL,
NULL,
false,
MSpace::kWorld,
maxDistance,
false,
NULL,
hitPoint,
&distance,
&face,
NULL,
NULL,
NULL,
tolerance,
&stat
);
if (stat != MS::kSuccess) {
displayError ("Error getting intersection: " + stat.errorString ());
return stat;
}
if (hit) {
distance += offset;
MString result;
result += face; appendToResult (result); result.clear ();
result += distance; appendToResult (result); result.clear ();
result += hitPoint.x; appendToResult (result); result.clear ();
result += hitPoint.y; appendToResult (result); result.clear ();
result += hitPoint.z; appendToResult (result); result.clear ();
}
else {
appendToResult ("-1");
for (int i = 0; i < 5; i++) appendToResult ("0");
}
return MS::kSuccess;
}
void* oppositeFace::creator () {
return new oppositeFace;
}
bool oppositeFace::isUndoable () const {
return false;
}
MSyntax oppositeFace::newSyntax () {
MSyntax syntax;
syntax.addFlag (offsetFlag, offsetFlagLong, MSyntax::kDouble);
syntax.addFlag (toleranceFlag, toleranceFlagLong, MSyntax::kDouble);
syntax.addFlag (distanceFlag, distanceFlagLong, MSyntax::kDouble);
return syntax;
}
MStatus initializePlugin (MObject obj) {
MStatus stat;
MFnPlugin plugin (obj, "Stefan Goebel", VERSION, API, &stat);
if (stat == MS::kSuccess) {
stat = plugin.setName ("oppositeFace", true);
if (stat == MS::kSuccess) {
stat = plugin.registerCommand (
"oppositeFace",
oppositeFace::creator,
oppositeFace::newSyntax
);
}
}
return stat;
}
MStatus uninitializePlugin (MObject obj) {
MFnPlugin plugin (obj);
return plugin.deregisterCommand ("oppositeFace");
}
// :indentSize=8:tabSize=8:noTabs=true:mode=c++:maxLineLen=94:
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment