2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
|
|
// with the following modification; you may not use this file except in
|
|
|
|
// compliance with the Apache License and the following modification to it:
|
|
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 6. Trademarks. This License does not grant permission to use the trade
|
|
|
|
// names, trademarks, service marks, or product names of the Licensor
|
|
|
|
// and its affiliates, except as required to comply with Section 4(c) of
|
|
|
|
// the License and to reproduce the content of the NOTICE file.
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the Apache License with the above modification is
|
|
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
|
|
// language governing permissions and limitations under the Apache License.
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#ifndef _EXAMPLE_MAYA_UTIL_H_
|
|
|
|
#define _EXAMPLE_MAYA_UTIL_H_
|
|
|
|
|
|
|
|
#include <maya/MColor.h>
|
|
|
|
#include <maya/MFloatVector.h>
|
|
|
|
#include <maya/MFnDependencyNode.h>
|
|
|
|
#include <maya/MFnNumericData.h>
|
|
|
|
#include <maya/MMatrix.h>
|
|
|
|
#include <maya/MPlug.h>
|
|
|
|
#include <maya/MString.h>
|
|
|
|
#include <maya/MVector.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define CHECK_GL_ERROR(...) \
|
|
|
|
if (GLuint err = glGetError()) { \
|
|
|
|
fprintf(stderr, "GL error %x :", err); \
|
|
|
|
fprintf(stderr, "%s", __VA_ARGS__); \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define MERROR(status, msg) \
|
|
|
|
{ \
|
|
|
|
MGlobal::displayError(MString(msg)); \
|
|
|
|
fprintf(stderr, "%s [ %s:%d ]\n", msg, __FILE__, __LINE__); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MCHECK_PRINT(status, msg) \
|
|
|
|
if (status.error()) \
|
|
|
|
{ \
|
|
|
|
MGlobal::displayError(MString(msg)); \
|
|
|
|
fprintf(stderr, "%s [ %s:%d ]\n", msg, __FILE__, __LINE__); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MCHECK_RETURN(status, msg) \
|
|
|
|
if (status.error()) \
|
|
|
|
{ \
|
|
|
|
MGlobal::displayError(MString(msg)); \
|
|
|
|
fprintf(stderr, "%s [ %s:%d ]\n", msg, __FILE__, __LINE__); \
|
|
|
|
return status; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Templated funtions able to retrieve any attribute that
|
|
|
|
// can be retrieved via the overloaded MPlug::getValue()
|
|
|
|
// methods. Any attributes that need MPlug::getData()
|
|
|
|
// Need to use non-templated functions below
|
|
|
|
//
|
|
|
|
template<class T> static int
|
|
|
|
findAttribute( MFnDependencyNode &depFn, const char *attr, T *val )
|
|
|
|
{
|
|
|
|
MStatus stat;
|
|
|
|
MPlug plug;
|
|
|
|
T tmp;
|
|
|
|
|
|
|
|
// careful version - returns -1 if attribute missing
|
|
|
|
plug = depFn.findPlug(attr, &stat);
|
|
|
|
if (stat != MS::kSuccess) return -1;
|
|
|
|
|
|
|
|
stat = plug.getValue(tmp);
|
|
|
|
if ( stat != MS::kSuccess ) return -1;
|
|
|
|
|
|
|
|
*val = tmp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class T> static void
|
|
|
|
getAttribute( MObject& object, MObject& attr, T *val )
|
|
|
|
{
|
|
|
|
// fast version - crash & burn if attribute missing
|
|
|
|
MPlug plug(object, attr);
|
|
|
|
plug.getValue(*val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static MColor
|
|
|
|
getColor(MObject object, MObject attr)
|
|
|
|
{
|
|
|
|
MPlug plug(object, attr);
|
|
|
|
MObject data;
|
|
|
|
plug.getValue(data);
|
|
|
|
MFnNumericData numFn(data);
|
|
|
|
float color[3];
|
|
|
|
numFn.getData(color[0], color[1], color[2]);
|
|
|
|
return MColor(color[0], color[1], color[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static MFloatVector
|
|
|
|
getVector(MObject object, MObject attr)
|
|
|
|
{
|
|
|
|
MPlug plug(object, attr);
|
|
|
|
MObject data;
|
|
|
|
plug.getValue(data);
|
|
|
|
MFnNumericData numFn(data);
|
|
|
|
float color[3];
|
|
|
|
numFn.getData(color[0], color[1], color[2]);
|
|
|
|
return MVector(color[0], color[1], color[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
// reverse to dst,src ?
|
|
|
|
setMatrix(const MMatrix &mat, float *dst)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
for (int j = 0; j < 4; ++j)
|
|
|
|
dst[i*4+j] = float(mat(i, j));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _EXAMPLE_MAYA_UTIL_H_
|
|
|
|
|