我试图编写Maya c++插件,但遇到了一些麻烦。
我只想创建一个相机,然后在视口(viewport)中移动它。我有:
MObject camera;
MDagPath cameraPath;
// create new camera
MFnCamera fnCamera;
fnCamera.create(camera);
fnCamera.getPath(cameraPath);
MFnTransform fn(camera);
MVector trans(12, 12, 12);
fn.setTranslation(trans, MSpace::kWorld);
这样可以很好地创建相机,但不会移动它。翻译创建的对象时我缺少什么?谢谢。
最佳答案
啊,我做错了。这有效:
MDagModifier dagModifier;
//Create the camera transform node.
MObject cameraTransformObj = dagModifier.createNode("transform");
dagModifier.renameNode(cameraTransformObj, "myCameraTransform");
//Create the camera shape node as a child of the camera transform node.
MObject cameraShapeObj = dagModifier.createNode("camera", cameraTransformObj);
dagModifier.renameNode(cameraShapeObj, "myCameraShape");
dagModifier.doIt();
MFnTransform transformFn(cameraTransformObj);
transformFn.setTranslation(MVector(0, 5, 30), MSpace::kTransform);