コード例 #1
0
ファイル: moveTool.cs プロジェクト: venerin/Maya-devkit
        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);
            }
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: moveTool.cs プロジェクト: meshdgp/MeshDGP
		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) ;
			}
		}