3434#include < maya/MFnNumericData.h>
3535#include < maya/MFnMatrixData.h>
3636#include < maya/MStreamUtils.h>
37+ #include < maya/MTransformationMatrix.h>
38+ #include < maya/MEulerRotation.h>
3739
3840// Utilities
3941#include < utilities/debugUtils.h>
@@ -96,6 +98,36 @@ getPoint2DAttrValue(
9698}
9799
98100
101+ MStatus
102+ getVector3DAttrValue (
103+ MDataBlock &data,
104+ MObject &attr_x,
105+ MObject &attr_y,
106+ MObject &attr_z,
107+ mmdata::Vector3D &output)
108+ {
109+ MStatus status = MS::kUnknownParameter ;
110+
111+ MDataHandle xHandle = data.inputValue (
112+ attr_x, &status);
113+ CHECK_MSTATUS_AND_RETURN_IT (status);
114+ double x = xHandle.asDouble ();
115+
116+ MDataHandle yHandle = data.inputValue (
117+ attr_y, &status);
118+ CHECK_MSTATUS_AND_RETURN_IT (status);
119+ double y = yHandle.asDouble ();
120+
121+ MDataHandle zHandle = data.inputValue (
122+ attr_z, &status);
123+ CHECK_MSTATUS_AND_RETURN_IT (status);
124+ double z = zHandle.asDouble ();
125+
126+ output = mmdata::Vector3D (x, y, z);
127+ return MS::kSuccess ;
128+ }
129+
130+
99131MTypeId MMCameraCalibrateNode::m_id (MM_CAMERA_CALIBRATE_TYPE_ID);
100132
101133// Input Attributes
@@ -116,10 +148,11 @@ MObject MMCameraCalibrateNode::a_originPoint;
116148MObject MMCameraCalibrateNode::a_originPointX;
117149MObject MMCameraCalibrateNode::a_originPointY;
118150
119- MObject MMCameraCalibrateNode::a_orientationPlane;
120- MObject MMCameraCalibrateNode::a_axisFlipX;
121- MObject MMCameraCalibrateNode::a_axisFlipY;
122- MObject MMCameraCalibrateNode::a_axisFlipZ;
151+ MObject MMCameraCalibrateNode::a_rotatePlane;
152+ MObject MMCameraCalibrateNode::a_rotatePlaneX;
153+ MObject MMCameraCalibrateNode::a_rotatePlaneY;
154+ MObject MMCameraCalibrateNode::a_rotatePlaneZ;
155+ MObject MMCameraCalibrateNode::a_rotateOrder;
123156
124157#ifdef WITH_PRINCIPAL_POINT
125158MObject MMCameraCalibrateNode::a_principalPoint;
@@ -276,31 +309,25 @@ MStatus MMCameraCalibrateNode::compute(const MPlug &plug, MDataBlock &data) {
276309 originPoint));
277310
278311 // /////////////////////////////
279- MDataHandle orientPlaneHandle = data.inputValue (
280- a_orientationPlane,
281- &status);
282- CHECK_MSTATUS_AND_RETURN_IT (status);
283- auto orientPlane =
284- static_cast <calibrate::OrientationPlane>(
285- orientPlaneHandle.asShort ());
286-
287- MDataHandle axisFlipXHandle = data.inputValue (
288- a_axisFlipX,
289- &status);
290- CHECK_MSTATUS_AND_RETURN_IT (status);
291- bool axisFlipX = axisFlipXHandle.asBool ();
292-
293- MDataHandle axisFlipYHandle = data.inputValue (
294- a_axisFlipY,
295- &status);
296- CHECK_MSTATUS_AND_RETURN_IT (status);
297- bool axisFlipY = axisFlipYHandle.asBool ();
312+ auto rotatePlane = mmdata::Vector3D ();
313+ CHECK_MSTATUS_AND_RETURN_IT (
314+ getVector3DAttrValue (
315+ data,
316+ a_rotatePlaneX,
317+ a_rotatePlaneY,
318+ a_rotatePlaneZ,
319+ rotatePlane));
320+ rotatePlane.x_ *= DEGREES_TO_RADIANS;
321+ rotatePlane.y_ *= DEGREES_TO_RADIANS;
322+ rotatePlane.z_ *= DEGREES_TO_RADIANS;
298323
299- MDataHandle axisFlipZHandle = data.inputValue (
300- a_axisFlipZ,
324+ // /////////////////////////////
325+ MDataHandle rotateOrderHandle = data.inputValue (
326+ a_rotateOrder,
301327 &status);
302328 CHECK_MSTATUS_AND_RETURN_IT (status);
303- bool axisFlipZ = axisFlipZHandle.asBool ();
329+ auto rotateOrderValue = rotateOrderHandle.asShort ();
330+ auto rotateOrder = static_cast <MEulerRotation::RotationOrder>(rotateOrderValue);
304331
305332 // /////////////////////////////
306333 auto principalPoint = mmdata::Point2D ();
@@ -367,10 +394,6 @@ MStatus MMCameraCalibrateNode::compute(const MPlug &plug, MDataBlock &data) {
367394 filmBackWidth_mm,
368395 filmBackHeight_mm,
369396 originPoint,
370- orientPlane,
371- axisFlipX,
372- axisFlipY,
373- axisFlipZ,
374397 principalPoint,
375398 vanishingPointA,
376399 horizonPointA,
@@ -404,10 +427,6 @@ MStatus MMCameraCalibrateNode::compute(const MPlug &plug, MDataBlock &data) {
404427 filmBackWidth_mm,
405428 filmBackHeight_mm,
406429 originPoint,
407- orientPlane,
408- axisFlipX,
409- axisFlipY,
410- axisFlipZ,
411430 principalPoint,
412431 vanishingPointA,
413432 horizonPointA,
@@ -425,10 +444,6 @@ MStatus MMCameraCalibrateNode::compute(const MPlug &plug, MDataBlock &data) {
425444 filmBackWidth_mm,
426445 filmBackHeight_mm,
427446 originPoint,
428- orientPlane,
429- axisFlipX,
430- axisFlipY,
431- axisFlipZ,
432447 principalPoint,
433448 vanishingPointA,
434449 vanishingPointB,
@@ -445,8 +460,21 @@ MStatus MMCameraCalibrateNode::compute(const MPlug &plug, MDataBlock &data) {
445460 << static_cast <int >(calibrationMode)
446461 << ' \n ' ;
447462 }
463+ auto cameraMatrix = convertToMMatrix (outCameraParameters.transformMatrix_ );
464+
465+ // Rotate the matrix.
466+ auto rotation = MEulerRotation (
467+ rotatePlane.x_ ,
468+ rotatePlane.y_ ,
469+ rotatePlane.z_ ,
470+ rotateOrder);
471+ auto orientTfmMatrix = MTransformationMatrix ();
472+ auto space = MSpace::Space::kWorld ;
473+ orientTfmMatrix.rotateBy (rotation, space, &status);
474+ CHECK_MSTATUS (status);
475+ auto orientMatrix = orientTfmMatrix.asMatrix ();
448476
449- auto outMatrix = convertToMMatrix (outCameraParameters. transformMatrix_ ) ;
477+ auto outMatrix = cameraMatrix * orientMatrix ;
450478 auto outMatrixInverse = outMatrix.inverse ();
451479#ifdef MM_DEBUG
452480 MStreamUtils::stdErrorStream ()
@@ -711,54 +739,55 @@ MStatus MMCameraCalibrateNode::initialize() {
711739 CHECK_MSTATUS (addAttribute (a_originPoint));
712740 }
713741
714- // ////////////////////////////////////////////////////////////////////////
715-
716742 {
717- // Orientation Plane
718- auto zxMode = static_cast <short >(calibrate::OrientationPlane::ZX);
719- auto zyMode = static_cast <short >(calibrate::OrientationPlane::ZY);
720- auto xzMode = static_cast <short >(calibrate::OrientationPlane::XZ);
721- auto xyMode = static_cast <short >(calibrate::OrientationPlane::XY);
722- auto yxMode = static_cast <short >(calibrate::OrientationPlane::YX);
723- auto yzMode = static_cast <short >(calibrate::OrientationPlane::YZ);
724- a_orientationPlane = enumAttr.create (
725- " orientationPlane" , " ornttpln" ,
726- zxMode,
727- &status);
728- CHECK_MSTATUS (status);
729- CHECK_MSTATUS (enumAttr.addField (" Z forward | X side | Y up" , zxMode));
730- CHECK_MSTATUS (enumAttr.addField (" X forward | Z side | Y up" , xzMode));
731- CHECK_MSTATUS (enumAttr.addField (" X forward | Y side | Z up" , xyMode));
732- CHECK_MSTATUS (enumAttr.addField (" Y forward | X side | Z up" , yxMode));
733- CHECK_MSTATUS (enumAttr.addField (" Z forward | Y side | X up" , zyMode));
734- CHECK_MSTATUS (enumAttr.addField (" Y forward | Z side | X up" , yzMode));
735- CHECK_MSTATUS (enumAttr.setStorable (true ));
736- CHECK_MSTATUS (enumAttr.setKeyable (true ));
737- CHECK_MSTATUS (addAttribute (a_orientationPlane));
738-
739- // Flip X Axis
740- a_axisFlipX = numericAttr.create (
741- " axisFlipX" , " axsflpx" ,
742- MFnNumericData::kBoolean , false );
743+ a_rotatePlaneX = numericAttr.create (
744+ " rotatePlaneX" , " rotplnx" ,
745+ MFnNumericData::kDouble , 0.0 );
743746 CHECK_MSTATUS (numericAttr.setStorable (true ));
744747 CHECK_MSTATUS (numericAttr.setKeyable (true ));
745- CHECK_MSTATUS (addAttribute (a_axisFlipX));
746748
747- // Flip Y Axis
748- a_axisFlipY = numericAttr.create (
749- " axisFlipY" , " axsflpy" ,
750- MFnNumericData::kBoolean , false );
749+ a_rotatePlaneY = numericAttr.create (
750+ " rotatePlaneY" , " rotplny" ,
751+ MFnNumericData::kDouble , 0.0 );
751752 CHECK_MSTATUS (numericAttr.setStorable (true ));
752753 CHECK_MSTATUS (numericAttr.setKeyable (true ));
753- CHECK_MSTATUS (addAttribute (a_axisFlipY));
754754
755- // Flip Z Axis
756- a_axisFlipZ = numericAttr.create (
757- " axisFlipZ" , " axsflpz" ,
758- MFnNumericData::kBoolean , false );
755+ a_rotatePlaneZ = numericAttr.create (
756+ " rotatePlaneZ" , " rotplnz" ,
757+ MFnNumericData::kDouble , 0.0 );
759758 CHECK_MSTATUS (numericAttr.setStorable (true ));
760759 CHECK_MSTATUS (numericAttr.setKeyable (true ));
761- CHECK_MSTATUS (addAttribute (a_axisFlipZ));
760+
761+ a_rotatePlane = compoundAttr.create (
762+ " rotatePlane" , " rotpln" ,
763+ &status);
764+ CHECK_MSTATUS (status);
765+ compoundAttr.addChild (a_rotatePlaneX);
766+ compoundAttr.addChild (a_rotatePlaneY);
767+ compoundAttr.addChild (a_rotatePlaneZ);
768+ CHECK_MSTATUS (addAttribute (a_rotatePlane));
769+
770+ // Rotate Order
771+ auto xyzMode = static_cast <short >(MEulerRotation::kXYZ );
772+ auto yzxMode = static_cast <short >(MEulerRotation::kYZX );
773+ auto zxyMode = static_cast <short >(MEulerRotation::kZXY );
774+ auto xzyMode = static_cast <short >(MEulerRotation::kXZY );
775+ auto yxzMode = static_cast <short >(MEulerRotation::kYXZ );
776+ auto zyxMode = static_cast <short >(MEulerRotation::kZYX );
777+ a_rotateOrder = enumAttr.create (
778+ " rotateOrder" , " rotordr" ,
779+ xyzMode,
780+ &status);
781+ CHECK_MSTATUS (status);
782+ CHECK_MSTATUS (enumAttr.addField (" XYZ" , xyzMode));
783+ CHECK_MSTATUS (enumAttr.addField (" YZX" , yzxMode));
784+ CHECK_MSTATUS (enumAttr.addField (" ZXY" , zxyMode));
785+ CHECK_MSTATUS (enumAttr.addField (" XZY" , xzyMode));
786+ CHECK_MSTATUS (enumAttr.addField (" YXZ" , yxzMode));
787+ CHECK_MSTATUS (enumAttr.addField (" ZYX" , zyxMode));
788+ CHECK_MSTATUS (enumAttr.setStorable (true ));
789+ CHECK_MSTATUS (enumAttr.setKeyable (true ));
790+ CHECK_MSTATUS (addAttribute (a_rotateOrder));
762791 }
763792
764793 // ////////////////////////////////////////////////////////////////////////
@@ -1065,10 +1094,11 @@ MStatus MMCameraCalibrateNode::initialize() {
10651094 inputAttrs.append (a_originPointX);
10661095 inputAttrs.append (a_originPointY);
10671096
1068- inputAttrs.append (a_orientationPlane);
1069- inputAttrs.append (a_axisFlipX);
1070- inputAttrs.append (a_axisFlipY);
1071- inputAttrs.append (a_axisFlipZ);
1097+ inputAttrs.append (a_rotatePlane);
1098+ inputAttrs.append (a_rotatePlaneX);
1099+ inputAttrs.append (a_rotatePlaneY);
1100+ inputAttrs.append (a_rotatePlaneZ);
1101+ inputAttrs.append (a_rotateOrder);
10721102
10731103#ifdef WITH_PRINCIPAL_POINT
10741104 inputAttrs.append (a_principalPoint);
0 commit comments