OLD | NEW |
(Empty) | |
| 1 //-***************************************************************************** |
| 2 // |
| 3 // Copyright (c) 2009-2011, |
| 4 // Sony Pictures Imageworks, Inc. and |
| 5 // Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. |
| 6 // |
| 7 // All rights reserved. |
| 8 // |
| 9 // Redistribution and use in source and binary forms, with or without |
| 10 // modification, are permitted provided that the following conditions are |
| 11 // met: |
| 12 // * Redistributions of source code must retain the above copyright |
| 13 // notice, this list of conditions and the following disclaimer. |
| 14 // * Redistributions in binary form must reproduce the above |
| 15 // copyright notice, this list of conditions and the following disclaimer |
| 16 // in the documentation and/or other materials provided with the |
| 17 // distribution. |
| 18 // * Neither the name of Sony Pictures Imageworks, nor |
| 19 // Industrial Light & Magic nor the names of their contributors may be used |
| 20 // to endorse or promote products derived from this software without specific |
| 21 // prior written permission. |
| 22 // |
| 23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 27 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 28 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 29 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 30 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 31 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 33 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 34 // |
| 35 //-***************************************************************************** |
| 36 |
| 37 #include <maya/MObject.h> |
| 38 #include <maya/MFnTransform.h> |
| 39 #include <maya/MString.h> |
| 40 #include <maya/MVector.h> |
| 41 #include <maya/MGlobal.h> |
| 42 #include <maya/MDagModifier.h> |
| 43 |
| 44 #include "util.h" |
| 45 #include "LocatorHelper.h" |
| 46 #include "NodeIteratorVisitorHelper.h" |
| 47 |
| 48 |
| 49 MObject create(Alembic::AbcGeom::IXform & iLocator, |
| 50 MObject & iParent, |
| 51 Alembic::Abc::IScalarProperty & iLocProp, |
| 52 MDagPath & oCurrentDagNode) |
| 53 { |
| 54 MStatus status = MS::kSuccess; |
| 55 MObject locatorObj = MObject::kNullObj; |
| 56 |
| 57 MString name(iLocator.getName().c_str()); |
| 58 |
| 59 MDagModifier modifier; |
| 60 locatorObj = modifier.createNode("locator", iParent, &status); |
| 61 status = modifier.doIt(); |
| 62 if (status != MS::kSuccess) |
| 63 { |
| 64 MString theError("Failed to create locator node "); |
| 65 theError += name; |
| 66 printError(theError); |
| 67 return locatorObj; |
| 68 } |
| 69 |
| 70 MFnDagNode fnLocator(locatorObj); |
| 71 fnLocator.setName(name); |
| 72 |
| 73 if (iLocProp.isConstant()) |
| 74 { |
| 75 // read the value from iLocProp |
| 76 double oSample[6]; |
| 77 iLocProp.get(oSample, 0); |
| 78 |
| 79 // set the plugs and be done |
| 80 MPlug dstPlug; |
| 81 dstPlug = fnLocator.findPlug("localPositionX"); |
| 82 dstPlug.setValue(oSample[0]); |
| 83 dstPlug = fnLocator.findPlug("localPositionY"); |
| 84 dstPlug.setValue(oSample[1]); |
| 85 dstPlug = fnLocator.findPlug("localPositionZ"); |
| 86 dstPlug.setValue(oSample[2]); |
| 87 dstPlug = fnLocator.findPlug("localScaleX"); |
| 88 dstPlug.setValue(oSample[3]); |
| 89 dstPlug = fnLocator.findPlug("localScaleY"); |
| 90 dstPlug.setValue(oSample[4]); |
| 91 dstPlug = fnLocator.findPlug("localScaleZ"); |
| 92 dstPlug.setValue(oSample[5]); |
| 93 } |
| 94 |
| 95 fnLocator.getPath(oCurrentDagNode); |
| 96 |
| 97 return locatorObj; |
| 98 } |
| 99 |
| 100 void read(double iFrame, |
| 101 Alembic::AbcGeom::IXform & iLocator, |
| 102 std::vector< double > & oArray) |
| 103 { |
| 104 oArray.resize(6); |
| 105 |
| 106 Alembic::Abc::ICompoundProperty props = iLocator.getProperties(); |
| 107 Alembic::Abc::IScalarProperty locProp(props, "locator"); |
| 108 |
| 109 Alembic::AbcCoreAbstract::index_t index, ceilIndex; |
| 110 double alpha = getWeightAndIndex(iFrame, |
| 111 locProp.getTimeSampling(), |
| 112 locProp.getNumSamples(), |
| 113 index, |
| 114 ceilIndex); |
| 115 double samp[6]; |
| 116 locProp.get(samp, index); |
| 117 |
| 118 if (fabs(alpha) > 1e-6) // interpolation |
| 119 { |
| 120 double ceilSamp[6]; |
| 121 locProp.get(ceilSamp, ceilIndex); |
| 122 for (unsigned int i = 0; i < 6; i++) |
| 123 oArray[i] = simpleLerp< double >(alpha, samp[i], ceilSamp[i]); |
| 124 } |
| 125 else |
| 126 { |
| 127 for (unsigned int i = 0; i < 6; i++) |
| 128 oArray[i] = samp[i]; |
| 129 } |
| 130 } |
OLD | NEW |