예제 #1
0
        /// <summary>
        /// 创建摄像机
        /// </summary>
        public static ModelingView CreateCamera(ViewType viewType, double[] martrix)
        {
            var     viewName    = Enum.GetName(viewType.GetType(), viewType);
            Session theSession  = Session.GetSession();
            Part    workPart    = theSession.Parts.Work;
            Part    displayPart = theSession.Parts.Display;
            var     or          = new Snap.Orientation(
                new Snap.Vector(martrix[0], martrix[1], martrix[2])
                , new Snap.Vector(martrix[3], martrix[4], martrix[5]));

            var modelingView = workPart.ModelingViews.ToArray().FirstOrDefault(u => u.Name == viewName);
            var camera       = workPart.Cameras.ToArray().FirstOrDefault(u => u.Name == viewName);

            if (modelingView != null && camera != null)
            {
                Snap.NX.NXObject.Wrap(camera.Tag).Delete();
                Snap.NX.NXObject.Wrap(modelingView.Tag).Delete();
            }

            {
                var ufSession = NXOpen.UF.UFSession.GetUFSession();
                var ds        = new List <double>();
                ds.AddRange(or.AxisX.Array);
                ds.AddRange(or.AxisY.Array);
                SnapEx.Ex.UC6434("", 4, NXOpen.Tag.Null, ds.ToArray());
                //ufSession.View.SetViewMatrix("", 4, NXOpen.Tag.Null, martrix);

                #region createCamera Code
                NXOpen.Tag workView;
                ufSession.View.AskWorkView(out workView);
                string workViewName;
                ufSession.Obj.AskName(workView, out workViewName);

                SnapEx.Ex.UC6450(workViewName, viewName, 0, 0);
                SnapEx.Ex.UC6449(workViewName);
                #endregion

                modelingView = workPart.ModelingViews.ToArray().FirstOrDefault(u => u.Name == viewName);
            }



            return(modelingView);
        }
예제 #2
0
        /// <summary>
        /// 创建摄像机
        /// </summary>
        public static ModelingView CreateCamera(ViewType viewType, double[] martrix)
        {
            var     viewName    = Enum.GetName(viewType.GetType(), viewType);
            Session theSession  = Session.GetSession();
            Part    workPart    = theSession.Parts.Work;
            Part    displayPart = theSession.Parts.Display;

            var modelingView = workPart.ModelingViews.ToArray().FirstOrDefault(u => u.Name == viewName);

            if (modelingView == null)
            {
                var ufSession = NXOpen.UF.UFSession.GetUFSession();
                ufSession.View.SetViewMatrix("", 4, NXOpen.Tag.Null, martrix);

                #region createCamera Code
                NXOpen.Tag workView;
                ufSession.View.AskWorkView(out workView);
                string workViewName;
                ufSession.Obj.AskName(workView, out workViewName);

                SnapEx.Ex.UC6450(workViewName, viewName, 0, 0);
                SnapEx.Ex.UC6449(workViewName);

                //NXOpen.Display.Camera nullDisplay_Camera = null;
                //NXOpen.Display.CameraBuilder cameraBuilder1;
                //cameraBuilder1 = workPart.Cameras.CreateCameraBuilder(nullDisplay_Camera);
                //cameraBuilder1.Commit();
                //cameraBuilder1.CameraName = viewName;
                //cameraBuilder1.CameraNameChar = viewName;
                //cameraBuilder1.Commit();
                //cameraBuilder1.Destroy();
                #endregion
            }

            modelingView = workPart.ModelingViews.ToArray().FirstOrDefault(u => u.Name == viewName);

            return(modelingView);
        }
예제 #3
0
        /// <summary>
        /// Sets the view type to the object with the specified type.
        /// </summary>
        /// <param name="type">The type of the ViewType which should be set.</param>
        /// <param name="immediateTransition">Should the ViewType be transitioned immediately?</param>
        public void SetViewType(System.Type type, bool immediateTransition)
        {
            if ((m_ViewType != null && m_ViewType.GetType() == type) || type == null)
            {
                return;
            }

            // The ViewTypes may not be deserialized yet.
            if (m_ViewTypeNameMap.Count == 0)
            {
                DeserializeViewTypes();
            }

            int index;

            if (!m_ViewTypeNameMap.TryGetValue(type.FullName, out index))
            {
                Debug.LogError("Error: Unable to find the view type with name " + type.FullName);
                return;
            }

            float pitch = 0f, yaw = 0f;
            var   characterRotation = Quaternion.identity;

            // ViewType will be null on startup.
            if (m_ViewType != null && m_Character != null && Application.isPlaying)
            {
                pitch             = m_ViewType.Pitch;
                yaw               = m_ViewType.Yaw;
                characterRotation = m_ViewType.CharacterRotation;
                m_ViewType.ChangeViewType(false, 0, yaw, characterRotation);

                EventHandler.ExecuteEvent(m_GameObject, "OnCameraChangeViewTypes", m_ViewType, false);
                if (m_OnChangeViewTypesEvent != null)
                {
                    m_OnChangeViewTypesEvent.Invoke(m_ViewType, false);
                }
            }

            var originalViewType = m_ViewType;

            m_ViewTypeFullName = type.FullName;
            m_ViewType         = m_ViewTypes[index];

            // Keep the first/third person view type updated to be able to switch back to the last active type.
            if (m_ViewType.FirstPersonPerspective)
            {
                m_FirstPersonViewTypeFullName = m_ViewTypeFullName;
                m_FirstPersonViewType         = m_ViewType;
            }
            else
            {
                m_ThirdPersonViewTypeFullName = m_ViewTypeFullName;
                m_ThirdPersonViewType         = m_ViewType;
            }

            // If the original view type is not null then the view type has been changed at runtime. Transition to that new view type.
            if (originalViewType != null && m_Character != null && Application.isPlaying)
            {
                m_ViewType.ChangeViewType(true, pitch, yaw, characterRotation);

                EventHandler.ExecuteEvent(m_GameObject, "OnCameraChangeViewTypes", m_ViewType, true);
                if (m_OnChangeViewTypesEvent != null)
                {
                    m_OnChangeViewTypesEvent.Invoke(m_ViewType, true);
                }
                if (originalViewType.FirstPersonPerspective != m_ViewType.FirstPersonPerspective)
                {
                    EventHandler.ExecuteEvent <bool>(m_Character, "OnCameraWillChangePerspectives", m_ViewType.FirstPersonPerspective);
                }

                // Use the transitioner if it exists.
                if (!immediateTransition && m_Transitioner != null)
                {
                    // StartTransition will return success if the transition is started.
                    if (m_Transitioner.StartTransition(originalViewType, m_ViewType))
                    {
                        return;
                    }
                    else if (m_Transitioner.IsTransitioning)
                    {
                        m_Transitioner.StopTransition(false);
                    }
                }
                else
                {
                    // If there isn't a transitioner then immediately move to the target position.
                    if (m_ViewType.RotatePriority)
                    {
                        KinematicObjectManager.SetCameraRotation(m_KinematicObjectIndex, m_ViewType.Rotate(0, 0, true));
                        KinematicObjectManager.SetCameraPosition(m_KinematicObjectIndex, m_ViewType.Move(true));
                    }
                    else
                    {
                        KinematicObjectManager.SetCameraPosition(m_KinematicObjectIndex, m_ViewType.Move(true));
                        KinematicObjectManager.SetCameraRotation(m_KinematicObjectIndex, m_ViewType.Rotate(0, 0, true));
                    }
                }

                // Execute the perspective event if the transitioner does not exist or is not active. The transitioner will execute this event when it finishes.
                if (originalViewType.FirstPersonPerspective != m_ViewType.FirstPersonPerspective)
                {
                    EventHandler.ExecuteEvent <bool>(m_Character, "OnCameraChangePerspectives", m_ViewType.FirstPersonPerspective);

                    if (m_OnChangePerspectivesEvent != null)
                    {
                        m_OnChangePerspectivesEvent.Invoke(m_ViewType.FirstPersonPerspective);
                    }
                }
            }
        }
예제 #4
0
 /// <summary>
 /// Returns the state index key for the specified view type.
 /// </summary>
 private string GetSelectedViewTypeStateIndexKey(ViewType viewType)
 {
     return(c_EditorPrefsSelectedViewTypeStateIndexKey + "." + target.GetType() + "." + target.name + "." + viewType.GetType());
 }