public void ResetCamera()
        {
            //<PerspectiveCamera UpDirection="0,1,0" Position="1,1,1" LookDirection="-1,-1,-1" FieldOfView="45" />
            MDagPath cameraPath;

            try {
                // Try with a Maya host first
                cameraPath = M3dView.active3dView.Camera;
            } catch {
                // We are in standalone mode (WPF application)
                MSelectionList list = new MSelectionList();
                list.add("persp");
                cameraPath = new MDagPath();
                list.getDagPath(0, cameraPath);
            }

            MFnCamera fnCamera = new MFnCamera(cameraPath);
            MPoint    eyePoint = fnCamera.eyePoint(MSpace.Space.kWorld);
            MPoint    centerOfInterestPoint = fnCamera.centerOfInterestPoint(MSpace.Space.kWorld);
            MVector   direction             = centerOfInterestPoint.minus(eyePoint);
            MVector   upDirection           = fnCamera.upDirection(MSpace.Space.kWorld);

            camera.Position      = new Point3D(eyePoint.x, eyePoint.y, eyePoint.z);
            camera.LookDirection = new Vector3D(direction.x, direction.y, direction.z);
            MAngle fieldOfView = new MAngle(fnCamera.verticalFieldOfView);              //verticalFieldOfView / horizontalFieldOfView

            camera.FieldOfView       = fieldOfView.asDegrees;
            camera.UpDirection       = new Vector3D(upDirection.x, upDirection.y, upDirection.z);
            camera.NearPlaneDistance = fnCamera.nearClippingPlane;
            camera.FarPlaneDistance  = fnCamera.farClippingPlane;
            camera.Transform         = new Transform3DGroup();
            (camera.Transform as Transform3DGroup).Children.Add(new TranslateTransform3D(new Vector3D()));
        }
Beispiel #2
0
		public override void undoIt()
		//
		// Description
		//     the undo routine
		//
		// Note
		//     The undoIt method should undo the actual work, based on the
		//     internal data only.
		//
		{
			MFnCamera fnCamera = new MFnCamera( camera );
            fnCamera.focalLength /= 2.0;
			return;
		}
Beispiel #3
0
		public override void redoIt()
		//
		// Description
		//     Doubles the focal length of current camera
		//
		// Note
		//     The redoIt method should do the actual work, based on the
		//     internal data only.
		//
		{
			MFnCamera fnCamera = new MFnCamera( camera );
			fnCamera.focalLength *= 2.0;
			return;
		}
Beispiel #4
0
        public override void undoIt()
        //
        // Description
        //     the undo routine
        //
        // Note
        //     The undoIt method should undo the actual work, based on the
        //     internal data only.
        //
        {
            MFnCamera fnCamera = new MFnCamera(camera);

            fnCamera.focalLength /= 2.0;
            return;
        }
Beispiel #5
0
        public override void redoIt()
        //
        // Description
        //     Doubles the focal length of current camera
        //
        // Note
        //     The redoIt method should do the actual work, based on the
        //     internal data only.
        //
        {
            MFnCamera fnCamera = new MFnCamera(camera);

            fnCamera.focalLength *= 2.0;
            return;
        }
Beispiel #6
0
        public override void doPress(MEvent eventArg)
        {
            base.doPress(eventArg);

            // If we are not in selecting mode (i.e. an object has been selected)
            // then set up for the translation.
            if (!_isSelecting())
            {
                eventArg.getPosition(ref startPos_x, ref startPos_y);

                view = M3dView.active3dView;

                MDagPath  camera   = view.Camera;
                MFnCamera fnCamera = new MFnCamera(camera);
                MVector   upDir    = fnCamera.upDirection(MSpace.Space.kWorld);
                MVector   rightDir = fnCamera.rightDirection(MSpace.Space.kWorld);

                // Determine the camera used in the current view
                if (fnCamera.isOrtho)
                {
                    if (upDir.isEquivalent(MVector.zNegAxis, 1e-3))
                    {
                        currWin = 0;                         // TOP
                    }
                    else if (rightDir.isEquivalent(MVector.xAxis, 1e-3))
                    {
                        currWin = 1;                         // FRONT
                    }
                    else
                    {
                        currWin = 2;                         // SIDE
                    }
                }
                else
                {
                    currWin = 3;                     // PERSP
                    MGlobal.displayWarning("moveTool only works in top, front and side views");
                }

                // Create an instance of the move tool command.
                cmd = _newToolCommand() as moveCmd;
                cmd.setVector(0.0, 0.0, 0.0);
            }
        }
        protected void initTests(MPx3dModelView view)
        {
            MGlobal.displayInfo("exampleCameraSetViewCmd::initTests");

            clearResults(view);

            //	Add every camera into the scene. Don't change the main camera,
            //	it is OK that it gets reused.
            //
            MFnCameraSet cstFn      = new MFnCameraSet();
            MObject      cstObj     = cstFn.create();
            MDagPath     cameraPath = null;

            MItDag dagIterator = new MItDag(MItDag.TraversalType.kDepthFirst, MFn.Type.kCamera);

            for (; !dagIterator.isDone; dagIterator.next())
            {
                cameraPath = new MDagPath();

                MFnCamera camera;

                try
                {
                    dagIterator.getPath(cameraPath);
                    camera = new MFnCamera(cameraPath);
                }
                catch (Exception)
                {
                    continue;
                }

                fCameraList.append(cameraPath);

                cstFn.appendLayer(cameraPath, MObject.kNullObj);

                MGlobal.displayInfo(camera.fullPathName());
            }

            view.setCameraSet(cstObj);
            view.refresh();
        }
		protected void initTests(MPx3dModelView view)
		{
			MGlobal.displayInfo("exampleCameraSetViewCmd::initTests");

			clearResults(view);

			//	Add every camera into the scene. Don't change the main camera,
			//	it is OK that it gets reused.
			//
			MFnCameraSet cstFn = new MFnCameraSet();
			MObject cstObj = cstFn.create();
			MDagPath cameraPath = null;
			
			MItDag dagIterator = new MItDag(MItDag.TraversalType.kDepthFirst, MFn.Type.kCamera);
			for (; !dagIterator.isDone; dagIterator.next())
			{
				cameraPath = new MDagPath();

				MFnCamera camera;

				try
				{
					dagIterator.getPath(cameraPath);
					camera = new MFnCamera(cameraPath);
				}
				catch (Exception)
				{
					continue;
				}

				fCameraList.append(cameraPath);

				cstFn.appendLayer(cameraPath, MObject.kNullObj);

				MGlobal.displayInfo(camera.fullPathName());
			}

			view.setCameraSet(cstObj);
			view.refresh();
		}
Beispiel #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mDagPath">DAG path to the transform above camera</param>
        /// <param name="babylonScene"></param>
        /// <returns></returns>
        private BabylonNode ExportCamera(MDagPath mDagPath, BabylonScene babylonScene)
        {
            RaiseMessage(mDagPath.partialPathName, 1);

            // Transform above camera
            MFnTransform mFnTransform = new MFnTransform(mDagPath);

            // Camera direct child of the transform
            MFnCamera mFnCamera = null;

            for (uint i = 0; i < mFnTransform.childCount; i++)
            {
                MObject childObject = mFnTransform.child(i);
                if (childObject.apiType == MFn.Type.kCamera)
                {
                    var _mFnCamera = new MFnCamera(childObject);
                    if (!_mFnCamera.isIntermediateObject)
                    {
                        mFnCamera = _mFnCamera;
                    }
                }
            }
            if (mFnCamera == null)
            {
                RaiseError("No camera found has child of " + mDagPath.fullPathName);
                return(null);
            }


            // --- prints ---
            #region prints

            RaiseVerbose("BabylonExporter.Camera | mFnCamera data", 2);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.eyePoint(MSpace.Space.kWorld).toString()=" + mFnCamera.eyePoint(MSpace.Space.kTransform).toString(), 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.viewDirection(MSpace.Space.kWorld).toString()=" + mFnCamera.viewDirection(MSpace.Space.kTransform).toString(), 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.upDirection(MSpace.Space.kWorld).toString()=" + mFnCamera.upDirection(MSpace.Space.kTransform).toString(), 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.rightDirection(MSpace.Space.kWorld).toString()=" + mFnCamera.rightDirection(MSpace.Space.kTransform).toString(), 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.centerOfInterestPoint(MSpace.Space.kWorld).toString()=" + mFnCamera.centerOfInterestPoint(MSpace.Space.kTransform).toString(), 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.centerOfInterest=" + mFnCamera.centerOfInterest, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.aspectRatio=" + mFnCamera.aspectRatio, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.horizontalFieldOfView=" + mFnCamera.horizontalFieldOfView, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.verticalFieldOfView=" + mFnCamera.verticalFieldOfView, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.horizontalFieldOfView / mFnCamera.verticalFieldOfView=" + mFnCamera.horizontalFieldOfView / mFnCamera.verticalFieldOfView, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.focalLength=" + mFnCamera.focalLength, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.nearFocusDistance=" + mFnCamera.nearFocusDistance, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.nearClippingPlane=" + mFnCamera.nearClippingPlane, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.unnormalizedNearClippingPlane=" + mFnCamera.unnormalizedNearClippingPlane, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.farFocusDistance=" + mFnCamera.farFocusDistance, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.farClippingPlane=" + mFnCamera.farClippingPlane, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.unnormalizedFarClippingPlane=" + mFnCamera.unnormalizedFarClippingPlane, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.isClippingPlanes=" + mFnCamera.isClippingPlanes, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.isIntermediateObject=" + mFnCamera.isIntermediateObject, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.focusDistance=" + mFnCamera.focusDistance, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.isStereo=" + mFnCamera.isStereo, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.eyeOffset=" + mFnCamera.eyeOffset, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.shutterAngle=" + mFnCamera.shutterAngle, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.isDepthOfField=" + mFnCamera.isDepthOfField, 3);
            RaiseVerbose("BabylonExporter.Camera | mFnCamera.renderPanZoom=" + mFnCamera.renderPanZoom, 3);

            Print(mFnTransform, 2, "Print ExportCamera mFnTransform");

            Print(mFnCamera, 2, "Print ExportCamera mFnCamera");

            #endregion

            if (IsCameraExportable(mFnCamera, mDagPath) == false)
            {
                return(null);
            }

            var babylonCamera = new BabylonCamera {
                name = mFnTransform.name, id = mFnTransform.uuid().asString()
            };

            // Hierarchy
            ExportHierarchy(babylonCamera, mFnTransform);

            // Position / rotation
            RaiseVerbose("BabylonExporter.Camera | ExportTransform", 2);
            float[] position           = null;
            float[] rotationQuaternion = null;
            float[] rotation           = null;
            float[] scaling            = null;
            GetTransform(mFnTransform, ref position, ref rotationQuaternion, ref rotation, ref scaling);
            babylonCamera.position = position;
            if (_exportQuaternionsInsteadOfEulers)
            {
                babylonCamera.rotationQuaternion = rotationQuaternion;
            }
            babylonCamera.rotation = rotation;

            // Field of view of babylon is the vertical one
            babylonCamera.fov = (float)mFnCamera.verticalFieldOfView;

            // Clipping planes
            babylonCamera.minZ = (float)mFnCamera.nearClippingPlane;
            babylonCamera.maxZ = (float)mFnCamera.farClippingPlane;
            // Constraints on near clipping plane
            if (babylonCamera.minZ == 0.0f)
            {
                babylonCamera.minZ = 0.1f;
            }

            // TODO - Retreive from Maya
            //// Type
            //babylonCamera.type = cameraNode.MaxNode.GetStringProperty("babylonjs_type", "FreeCamera");

            //// Control
            //babylonCamera.speed = cameraNode.MaxNode.GetFloatProperty("babylonjs_speed", 1.0f);
            //babylonCamera.inertia = cameraNode.MaxNode.GetFloatProperty("babylonjs_inertia", 0.9f);

            //// Collisions
            //babylonCamera.checkCollisions = cameraNode.MaxNode.GetBoolProperty("babylonjs_checkcollisions");
            //babylonCamera.applyGravity = cameraNode.MaxNode.GetBoolProperty("babylonjs_applygravity");
            //babylonCamera.ellipsoid = cameraNode.MaxNode.GetVector3Property("babylonjs_ellipsoid");

            // Target
            MFnTransform target            = null;
            MObject      cameraGroupObject = mFnCamera.findPlug("centerOfInterest").source.node;
            if (cameraGroupObject.apiType == MFn.Type.kLookAt)
            {
                MFnDependencyNode cameraGroup = new MFnDependencyNode(cameraGroupObject);

                // Retreive the camera aim transform
                MPlugArray connections = new MPlugArray();
                cameraGroup.getConnections(connections);
                foreach (MPlug connection in connections)
                {
                    if (connection.name.EndsWith("targetParentMatrix")) // ugly
                    {
                        MObject connectionSourceObject = connection.source.node;
                        target = new MFnTransform(connectionSourceObject);
                        break;
                    }
                }
            }
            if (target != null)
            {
                babylonCamera.lockedTargetId = target.uuid().asString();
            }

            //// TODO - Check if should be local or world
            //var vDir = new MVector(0, 0, -1);
            //var transformationMatrix = new MTransformationMatrix(mFnTransform.transformationMatrix);
            //vDir *= transformationMatrix.asMatrix(1);
            //vDir = vDir.Add(position);
            //babylonCamera.target = new[] { vDir.X, vDir.Y, vDir.Z };

            // Animations
            if (target == null)
            {
                ExportNodeAnimation(babylonCamera, mFnTransform);
            }
            else
            {
                ExportNodeAnimationFrameByFrame(babylonCamera, mFnTransform);
            }

            babylonScene.CamerasList.Add(babylonCamera);
            RaiseMessage("BabylonExporter.Camera | done", 2);

            return(babylonCamera);
        }
Beispiel #10
0
        public override void draw(M3dView view, MDagPath path, M3dView.DisplayStyle style, M3dView.DisplayStatus status)
        {
            // Are we in the right view
            MDagPath dpath = new MDagPath();

            view.getCamera(dpath);
            MFnCamera viewCamera = new MFnCamera(dpath);
            string    nameBuffer = viewCamera.name;

            if (nameBuffer == null)
            {
                return;
            }
            if (nameBuffer.IndexOf("persp") == -1 && nameBuffer.IndexOf("front") == -1)
            {
                return;
            }
            //
            bool rightLine = !affectTranslate;

            // Populate the point arrays which are in local space
            MPoint top    = lineGeometry.topPoint();
            MPoint bottom = lineGeometry.bottomPoint();

            // Depending on what's active, we modify the
            // end points with mouse deltas in local
            // space
            uint active = 0;

            try
            {
                glActiveName(ref active);
            }
            catch (System.Exception)
            {
                return;
            }

            if (active == lineName && active != 0)
            {
                top[0]    += (float)mousePointGlName.x; top[1] += (float)mousePointGlName.y; top[2] += (float)mousePointGlName.z;
                bottom[0] += (float)mousePointGlName.x; bottom[1] += (float)mousePointGlName.y; bottom[2] += (float)mousePointGlName.z;
            }

            // Begin the drawing
            view.beginGL();

            // Get the starting value of the pickable items
            uint glPickableItem = 0;

            glFirstHandle(ref glPickableItem);

            // Top
            lineName = glPickableItem;
            // Place before you draw the manipulator component that can
            // be pickable.
            colorAndName(view, glPickableItem, true, mainColor());
            OpenGL.glBegin((uint)libOpenMayaRenderNet.MGL_LINES);
            OpenGL.glVertex3d(top.x, top.y, top.z);
            OpenGL.glVertex3d(bottom.x, bottom.y, bottom.z);
            OpenGL.glEnd();

            // End the drawing
            view.endGL();
        }
Beispiel #11
0
		public override void draw(M3dView view, MDagPath path, M3dView.DisplayStyle style, M3dView.DisplayStatus status)
		{
			// Are we in the right view
			MDagPath dpath = new MDagPath();
			view.getCamera(dpath);
			MFnCamera viewCamera = new MFnCamera(dpath);
			string nameBuffer = viewCamera.name;
			if (nameBuffer == null)
				return;
			if (nameBuffer.IndexOf("persp") == -1 && nameBuffer.IndexOf("front") == -1)
				return;
			//
			bool rightLine = !affectTranslate;

			// Populate the point arrays which are in local space
			MPoint top = lineGeometry.topPoint();
			MPoint bottom = lineGeometry.bottomPoint();

			// Depending on what's active, we modify the
			// end points with mouse deltas in local
			// space
			uint active = 0;
			try
			{
				glActiveName(ref active);
			}
			catch (System.Exception)
			{
				return;
			}

			if (active == lineName && active != 0)
			{
				top[0] += (float)mousePointGlName.x; top[1] += (float)mousePointGlName.y; top[2] += (float)mousePointGlName.z;
				bottom[0] += (float)mousePointGlName.x; bottom[1] += (float)mousePointGlName.y; bottom[2] += (float)mousePointGlName.z;
			}

			// Begin the drawing
			view.beginGL();

			// Get the starting value of the pickable items
			uint glPickableItem = 0;
			glFirstHandle(ref glPickableItem);

			// Top
			lineName = glPickableItem;
			// Place before you draw the manipulator component that can
			// be pickable.
			colorAndName(view, glPickableItem, true, mainColor());
			OpenGL.glBegin((uint)libOpenMayaRenderNet.MGL_LINES);
			OpenGL.glVertex3d(top.x, top.y, top.z);
			OpenGL.glVertex3d(bottom.x, bottom.y, bottom.z);
			OpenGL.glEnd();

			// End the drawing
			view.endGL();
		}
Beispiel #12
0
		public override void doPress(MEvent eventArg)
		{
			base.doPress (eventArg) ;
			
			// If we are not in selecting mode (i.e. an object has been selected)
			// then set up for the translation.
			if ( !_isSelecting () ) {
				eventArg.getPosition (ref startPos_x, ref startPos_y) ;

				view = M3dView.active3dView;

				MDagPath camera = view.Camera ;
				MFnCamera fnCamera =new MFnCamera (camera) ;
				MVector upDir =fnCamera.upDirection (MSpace.Space.kWorld) ;
				MVector rightDir =fnCamera.rightDirection (MSpace.Space.kWorld) ;

				// Determine the camera used in the current view
				if ( fnCamera.isOrtho ) {
					if ( upDir.isEquivalent (MVector.zNegAxis, 1e-3) )
						currWin =0 ; // TOP
					else if ( rightDir.isEquivalent (MVector.xAxis, 1e-3) )
						currWin =1 ; // FRONT
					else
						currWin =2 ; // SIDE
				} else {
					currWin =3 ; // PERSP
					MGlobal.displayWarning ("moveTool only works in top, front and side views") ;
				}

				// Create an instance of the move tool command.
				cmd = _newToolCommand () as moveCmd;
				cmd.setVector (0.0, 0.0, 0.0) ;
			}
		}
Beispiel #13
0
        private void doScan(MItDag.TraversalType traversalType, MFn.Type filter, bool quiet)
        {
            MItDag dagIterator = new MItDag(traversalType, filter);

            //	Scan the entire DAG and output the name and depth of each node

            if (traversalType == MItDag.TraversalType.kBreadthFirst)
            {
                if (!quiet)
                {
                    MGlobal.displayInfo(Environment.NewLine + "Starting Breadth First scan of the Dag");
                }
                else
                if (!quiet)
                {
                    MGlobal.displayInfo(Environment.NewLine + "Starting Depth First scan of the Dag");
                }
            }

            switch (filter)
            {
            case MFn.Type.kCamera:
                if (!quiet)
                {
                    MGlobal.displayInfo(": Filtering for Cameras\n");
                }
                break;

            case MFn.Type.kLight:
                if (!quiet)
                {
                    MGlobal.displayInfo(": Filtering for Lights\n");
                }
                break;

            case MFn.Type.kNurbsSurface:
                if (!quiet)
                {
                    MGlobal.displayInfo(": Filtering for Nurbs Surfaces\n");
                }
                break;

            default:
                MGlobal.displayInfo(Environment.NewLine);
                break;
            }


            int objectCount = 0;

            for ( ; !dagIterator.isDone; dagIterator.next())
            {
                MDagPath dagPath = new MDagPath();

                try
                {
                    dagIterator.getPath(dagPath);
                }
                catch (System.Exception)
                {
                    continue;
                }

                MFnDagNode dagNode = null;
                try
                {
                    dagNode = new MFnDagNode(dagPath);
                }
                catch (System.Exception)
                {
                    continue;
                }

                if (!quiet)
                {
                    MGlobal.displayInfo(dagNode.name + ": " + dagNode.typeName + Environment.NewLine);
                }

                if (!quiet)
                {
                    MGlobal.displayInfo("  dagPath: " + dagPath.fullPathName + Environment.NewLine);
                }

                objectCount += 1;
                if (dagPath.hasFn(MFn.Type.kCamera))
                {
                    MFnCamera camera = null;
                    try
                    {
                        camera = new MFnCamera(dagPath);
                    }
                    catch (System.Exception)
                    {
                        continue;
                    }

                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);

                    // Extract some interesting Camera data
                    //
                    if (!quiet)
                    {
                        MGlobal.displayInfo("  eyePoint: " + MPointToString(camera.eyePoint(MSpace.Space.kWorld)) + Environment.NewLine);

                        MGlobal.displayInfo("  upDirection: " + MVectorToString(camera.upDirection(MSpace.Space.kWorld)) + Environment.NewLine);

                        MGlobal.displayInfo("  viewDirection: " + MVectorToString(camera.viewDirection(MSpace.Space.kWorld)) + Environment.NewLine);

                        MGlobal.displayInfo("  aspectRatio: " + Convert.ToString(camera.aspectRatio) + Environment.NewLine);

                        MGlobal.displayInfo("  horizontalFilmAperture: " + Convert.ToString(camera.horizontalFilmAperture) + Environment.NewLine);

                        MGlobal.displayInfo("  verticalFilmAperture: " + Convert.ToString(camera.verticalFilmAperture) + Environment.NewLine);
                    }
                }
                else if (dagPath.hasFn(MFn.Type.kLight))
                {
                    MFnLight light = null;
                    try
                    {
                        light = new MFnLight(dagPath);
                    }
                    catch (System.Exception)
                    {
                        continue;
                    }

                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);

                    // Extract some interesting Light data
                    //
                    MColor color = light.color;
                    if (!quiet)
                    {
                        MGlobal.displayInfo(string.Format("  color: [%f, %f, %f]\n", color.r, color.g, color.b));
                    }
                    color = light.shadowColor;
                    if (!quiet)
                    {
                        MGlobal.displayInfo(string.Format("  shadowColor: [%f, %f, %f]\n", color.r, color.g, color.b));
                        MGlobal.displayInfo("  intensity: " + Convert.ToString(light.intensity) + Environment.NewLine);
                    }
                }
                else if (dagPath.hasFn(MFn.Type.kNurbsSurface))
                {
                    MFnNurbsSurface surface = null;
                    try
                    {
                        surface = new MFnNurbsSurface(dagPath);
                    }
                    catch (System.Exception)
                    {
                        continue;
                    }

                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);

                    // Extract some interesting Surface data
                    //
                    if (!quiet)
                    {
                        MGlobal.displayInfo(string.Format("  numCVs: %d * %s", surface.numCVsInU, surface.numCVsInV) + Environment.NewLine);
                        MGlobal.displayInfo(string.Format("  numKnots: %d * %s\n", surface.numKnotsInU, surface.numKnotsInV) + Environment.NewLine);
                        MGlobal.displayInfo(string.Format("  numSpans: %d * %s\n", surface.numSpansInU, surface.numSpansInV) + Environment.NewLine);
                    }
                }
                else
                {
                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);
                }
            }

            setResult(objectCount);
        }
Beispiel #14
0
 //
 // Description
 //     the undo routine
 //
 // Note
 //     The undoIt method should undo the actual work, based on the
 //     internal data only.
 //
 public override void undoIt()
 {
     MFnCamera fnCamera = new MFnCamera( camera );
     fnCamera.focalLength /= 2.0;
     return;
 }
        public void ResetCamera()
        {
            //<PerspectiveCamera UpDirection="0,1,0" Position="1,1,1" LookDirection="-1,-1,-1" FieldOfView="45" />
            MDagPath cameraPath ;
            try {
                // Try with a Maya host first
                cameraPath =M3dView.active3dView.Camera ;
            } catch {
                // We are in standalone mode (WPF application)
                MSelectionList list =new MSelectionList () ;
                list.add ("persp") ;
                cameraPath =new MDagPath () ;
                list.getDagPath (0, cameraPath) ;
            }

            MFnCamera fnCamera =new MFnCamera (cameraPath) ;
            MPoint eyePoint =fnCamera.eyePoint (MSpace.Space.kWorld) ;
            MPoint centerOfInterestPoint =fnCamera.centerOfInterestPoint (MSpace.Space.kWorld) ;
            MVector direction =centerOfInterestPoint.minus (eyePoint) ;
            MVector upDirection =fnCamera.upDirection (MSpace.Space.kWorld) ;

            camera.Position =new Point3D (eyePoint.x, eyePoint.y, eyePoint.z) ;
            camera.LookDirection =new Vector3D (direction.x, direction.y, direction.z) ;
            MAngle fieldOfView =new MAngle (fnCamera.verticalFieldOfView) ; //verticalFieldOfView / horizontalFieldOfView
            camera.FieldOfView =fieldOfView.asDegrees ;
            camera.UpDirection =new Vector3D (upDirection.x, upDirection.y, upDirection.z) ;
            camera.NearPlaneDistance =fnCamera.nearClippingPlane ;
            camera.FarPlaneDistance =fnCamera.farClippingPlane ;
            camera.Transform =new Transform3DGroup () ;
            (camera.Transform as Transform3DGroup).Children.Add (new TranslateTransform3D (new Vector3D ())) ;
        }
Beispiel #16
0
        private void doScan(MItDag.TraversalType traversalType, MFn.Type filter, bool quiet)
        {
            MItDag dagIterator = new MItDag(traversalType, filter);

            //	Scan the entire DAG and output the name and depth of each node

            if (traversalType == MItDag.TraversalType.kBreadthFirst)
                if (!quiet)
                    MGlobal.displayInfo(Environment.NewLine + "Starting Breadth First scan of the Dag");
            else
                if (!quiet)
                    MGlobal.displayInfo(Environment.NewLine + "Starting Depth First scan of the Dag");

            switch (filter)
            {
                case MFn.Type.kCamera:
                    if (!quiet)
                        MGlobal.displayInfo( ": Filtering for Cameras\n");
                    break;
                case MFn.Type.kLight:
                    if (!quiet)
                        MGlobal.displayInfo(": Filtering for Lights\n");
                    break;
                case MFn.Type.kNurbsSurface:
                    if (!quiet)
                        MGlobal.displayInfo(": Filtering for Nurbs Surfaces\n");
                    break;
                default:
                    MGlobal.displayInfo(Environment.NewLine);
                    break;
            }

            int objectCount = 0;
            for ( ; !dagIterator.isDone; dagIterator.next() ) {

                MDagPath dagPath = new MDagPath();

                try
                {
                    dagIterator.getPath(dagPath);
                }
                catch (System.Exception )
                {
                    continue;
                }

                MFnDagNode dagNode = null;
                try
                {
                    dagNode = new MFnDagNode(dagPath);
                }
                catch (System.Exception )
                {
                    continue;
                }

                if (!quiet)
                    MGlobal.displayInfo(dagNode.name + ": " + dagNode.typeName + Environment.NewLine);

                if (!quiet)
                    MGlobal.displayInfo( "  dagPath: " + dagPath.fullPathName + Environment.NewLine);

                objectCount += 1;
                if (dagPath.hasFn(MFn.Type.kCamera))
                {
                    MFnCamera camera  =  null;
                    try
                    {
                        camera  = new MFnCamera(dagPath);
                    }
                    catch (System.Exception)
                    {
                        continue;
                    }

                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);

                    // Extract some interesting Camera data
                    //
                    if (!quiet)
                    {

                        MGlobal.displayInfo("  eyePoint: " + MPointToString(camera.eyePoint(MSpace.Space.kWorld)) + Environment.NewLine);

                        MGlobal.displayInfo("  upDirection: " + MVectorToString( camera.upDirection(MSpace.Space.kWorld)) + Environment.NewLine);

                        MGlobal.displayInfo("  viewDirection: " + MVectorToString( camera.viewDirection(MSpace.Space.kWorld)) + Environment.NewLine);

                        MGlobal.displayInfo("  aspectRatio: " + Convert.ToString( camera.aspectRatio ) + Environment.NewLine);

                        MGlobal.displayInfo("  horizontalFilmAperture: " + Convert.ToString(camera.horizontalFilmAperture ) + Environment.NewLine);

                        MGlobal.displayInfo("  verticalFilmAperture: " + Convert.ToString(camera.verticalFilmAperture ) + Environment.NewLine);
                    }
                }
                else if (dagPath.hasFn(MFn.Type.kLight))
                {
                    MFnLight light = null;
                    try
                    {
                        light = new MFnLight(dagPath);
                    }
                    catch (System.Exception)
                    {
                        continue;
                    }

                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);

                    // Extract some interesting Light data
                    //
                    MColor color = light.color;
                    if (!quiet)
                    {
                        MGlobal.displayInfo(string.Format("  color: [%f, %f, %f]\n", color.r, color.g, color.b));
                    }
                    color = light.shadowColor;
                    if (!quiet)
                    {

                        MGlobal.displayInfo(string.Format("  shadowColor: [%f, %f, %f]\n", color.r, color.g, color.b));
                        MGlobal.displayInfo("  intensity: "+Convert.ToString(light.intensity) + Environment.NewLine);

                    }
                }
                else if (dagPath.hasFn(MFn.Type.kNurbsSurface))
                {
                    MFnNurbsSurface surface= null;
                    try
                    {
                        surface = new MFnNurbsSurface(dagPath);
                    }
                    catch (System.Exception )
                    {
                        continue;
                    }

                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);

                    // Extract some interesting Surface data
                    //
                    if (!quiet)
                    {
                        MGlobal.displayInfo(string.Format("  numCVs: %d * %s", surface.numCVsInU, surface.numCVsInV) + Environment.NewLine);
                        MGlobal.displayInfo(string.Format("  numKnots: %d * %s\n", surface.numKnotsInU, surface.numKnotsInV) + Environment.NewLine);
                        MGlobal.displayInfo(string.Format("  numSpans: %d * %s\n", surface.numSpansInU, surface.numSpansInV) + Environment.NewLine);
                    }
                } else
                {
                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);
                }
            }

            setResult(objectCount);
        }