示例#1
0
	MStatus HelixBase_RemoveAllAimConstraints(MObject & helixBase, const char *type) {
		MStatus status;

		MFnDagNode this_dagNode(helixBase, &status);

		if (!status) {
			status.perror("MFnDagNode::#ctor");
			return status;
		}

		unsigned int this_childCount = this_dagNode.childCount(&status);
		bool foundAimConstraint = false;
		MDagModifier dagModifier;

		if (!status) {
			status.perror("MFnDagNode::childCount");
			return status;
		}

		for(unsigned int i = 0; i < this_childCount; ++i) {
			MObject child_object = this_dagNode.child(i, &status);

			if (!status) {
				if (status == MStatus::kInvalidParameter) {
					/*
					 * There seems to be a bug in Maya when opening an already existing file that nodes are reported to have children but the MFnDagNode::child will fail
					 */

					return MStatus::kSuccess;
				}
				status.perror("MFnDagNode::child");
				return status;
			}

			MFnDagNode child_dagNode(child_object, &status);

			if (!status) {
				status.perror("MFnDagNode::#ctor");
				return status;
			}

			if (child_dagNode.typeName() == "aimConstraint") {
				foundAimConstraint = true;
				//std::cerr << "Found an old aimconstraint to delete named: " << child_dagNode.name().asChar() << std::endl;

				// DEBUG:

				/*if (child_object.isNull()) {
					std::cerr << "The object is null! terminating!" << std::endl;
					return MStatus::kSuccess;
				}*/

				// This is the operation that crashes Maya when creating a "New scene"

				if (!(status = dagModifier.deleteNode(child_object))) {
					status.perror("MDagModifier::deleteNode");
					return status;
				}
			}
		}

		// Execute deletion and reset transformation into translation only

		if (foundAimConstraint) {
			if (!(status = dagModifier.doIt())) {
				status.perror("MDagModifier::doIt");
				return status;
			}

			MFnTransform this_transform(helixBase, &status);

			if (!status) {
				status.perror("MFnTransform::#ctor");
				return status;
			}

			double rotation[] = { 0.0, 0.0, 0.0 };
			if (!(status = this_transform.setRotation(rotation, MTransformationMatrix::kXYZ))) {
				status.perror("MFnTransform::setRotation");
				return status;
			}
		}

		return MStatus::kSuccess;
	}
示例#2
0
MObject create(Alembic::AbcGeom::ICamera & iNode, MObject & iParent)
{
    Alembic::AbcGeom::ICameraSchema schema = iNode.getSchema();
    MString name(iNode.getName().c_str());

    MFnCamera fnCamera;
    MObject obj = fnCamera.create(iParent);
    fnCamera.setName(name);

    // we need to read this to determine the film fit
    Alembic::AbcGeom::CameraSample samp;
    iNode.getSchema().get(samp);

    std::size_t numOps = samp.getNumOps();
    if (numOps > 0)
    {
        std::string hint = samp[0].getHint();
        if (hint == "filmFitFill")
        {
            fnCamera.setFilmFit(MFnCamera::kFillFilmFit);
        }
        else if (hint == "filmFitHorz")
        {
            fnCamera.setFilmFit(MFnCamera::kHorizontalFilmFit);
        }
        else if (hint == "filmFitVert")
        {
            fnCamera.setFilmFit(MFnCamera::kVerticalFilmFit);
        }
        else if (hint == "filmFitOver")
        {
            fnCamera.setFilmFit(MFnCamera::kOverscanFilmFit);
        }
    }

    if (schema.isConstant())
    {

        // no center of interest
        fnCamera.setFocalLength(samp.getFocalLength());
        fnCamera.setLensSqueezeRatio(samp.getLensSqueezeRatio());
        // camera scale might be in the 3x3

        // weirdo attrs that are in inches
        fnCamera.setHorizontalFilmAperture(samp.getHorizontalAperture()/2.54);
        fnCamera.setVerticalFilmAperture(samp.getVerticalAperture()/2.54);
        fnCamera.setHorizontalFilmOffset(samp.getHorizontalFilmOffset()/2.54);
        fnCamera.setVerticalFilmOffset(samp.getVerticalFilmOffset()/2.54);

        // film fit offset might be in the 3x3

        if (samp.getOverScanLeft() == samp.getOverScanRight() &&
            samp.getOverScanTop() == samp.getOverScanBottom() &&
            samp.getOverScanLeft() == samp.getOverScanTop())
        {
            fnCamera.setOverscan(samp.getOverScanLeft() + 1.0);
        }
        else
        {
            MString warn = iNode.getName().c_str();
            warn += " has unsupported overscan values.";
            MGlobal::displayWarning(warn);
        }

        fnCamera.setNearClippingPlane(samp.getNearClippingPlane());
        fnCamera.setFarClippingPlane(samp.getFarClippingPlane());

        // prescale, film translate H, V, roll pivot H,V, film roll value
        // post scale might be in the 3x3

        fnCamera.setFStop(samp.getFStop());
        fnCamera.setFocusDistance(samp.getFocusDistance());

        MTime sec(1.0, MTime::kSeconds);
        fnCamera.setShutterAngle(Alembic::AbcGeom::DegreesToRadians(
            360.0 * (samp.getShutterClose()-samp.getShutterOpen()) *
            sec.as(MTime::uiUnit()) ));

        for (std::size_t i = 0; i < numOps; ++i)
        {
            Alembic::AbcGeom::FilmBackXformOp & op = samp[i];
            if (op.getHint() == "filmFitOffs")
            {
                double val = op.getChannelValue(0) *
                    samp.getHorizontalAperture() / 5.08;

                if (val != 0.0)
                {
                    fnCamera.setFilmFitOffset(val);
                }
                else
                {
                    fnCamera.setFilmFitOffset(op.getChannelValue(1) *
                        samp.getHorizontalAperture() / 5.08);
                }
            }
            else if (op.getHint() == "preScale")
            {
                fnCamera.setPreScale(1.0/op.getChannelValue(0));
            }
            else if (op.getHint() == "filmTranslate")
            {
                fnCamera.setFilmTranslateH(op.getChannelValue(0));
                fnCamera.setFilmTranslateV(op.getChannelValue(1));
            }
            else if (op.getHint() == "postScale")
            {
                fnCamera.setPostScale(1.0/op.getChannelValue(0));
            }
            else if (op.getHint() == "cameraScale")
            {
                fnCamera.setCameraScale(op.getChannelValue(0));
            }
        }
    }

    // extra transform node is unfortuneatly automatically created above the
    // camera, let's do some reparenting and delete that extra transform
    MDagPath path;
    fnCamera.getPath(path);
    MObject camObj = path.node();

    MDagModifier dagMod;
    dagMod.reparentNode(camObj, iParent);
    dagMod.doIt();
    dagMod.deleteNode(obj);
    dagMod.doIt();

    return camObj;
}