示例#1
0
    /// <summary>
    /// Select the block I am hitting.
    /// </summary>
    /// <param name="hit">Raycast hit.</param>
    private PRGeo UpdateSelection(RaycastHit hit)
    {
        Debug.Log("HitTag: " + hit.collider.tag);
        Debug.Log("HitName: " + hit.collider.name);
        // Check if Gizmo is hit.
        if (IsGizmoHit())
        {
            return(SelectedGeoCO);
        }

        if (hit.collider.tag == "PRCube")
        {
            PRGeo geo = hit.collider.gameObject.GetComponent <PRGeo>();
            // If there is a Active block and user selects another one, deselect the already Active one.
            if (!SelectedGeoCO)
            {
                geo.SelectCube(SelectedMaterial);
                StartCoroutine(SelectedGeoCO.TurnOnCube());
                return(SelectedGeoCO);
            }
            else
            {
                // Select the new geometry if the selected is not the same as the hit object.
                if (geo.GetInstanceID() != SelectedGeoCO.GetInstanceID())
                {
                    SelectedGeoCO.DeselectCube(UnselectedMaterial);
                    geo.SelectCube(SelectedMaterial);
                    StartCoroutine(SelectedGeoCO.TurnOnCube());
                    return(SelectedGeoCO);
                }
                // If any of the transform mode exept GeometryMode is active, do nothing.
                else if (SelectedGeoCO.VertexModeActive ||
                         SelectedGeoCO.EdgeModeActive ||
                         SelectedGeoCO.VertexModeActive)
                {
                    return(SelectedGeoCO);
                }
            }
            return(geo);
        }
        else if (hit.collider.tag == "ContexMenu" || hit.collider.tag == "CMSubmenu" ||
                 hit.collider.tag == "PREdge" || hit.collider.tag == "PRFace" ||
                 hit.collider.tag == "PRVertex")
        {
            return(SelectedGeoCO);
        }
        else
        {
            Debug.Log("I don't know what are u hitting.");
            if (SelectedGeoCO)
            {
                // Make sure all the all transformation modes are off.
                StartCoroutine(SelectedGeoCO.TurnOffAllModes());
                // Deselect cube.
                SelectedGeoCO.DeselectCube(UnselectedMaterial);
            }

            return(null);
        }
    }
示例#2
0
 //---------------------------------------------HOLOLENS INPUTS------------------------------------------------------
 public void OnInputDownLocal()
 {
     InputDown = true;
     if (IS_HIT)
     {
         PRGeo geo = UpdateSelection(HIT);
     }
 }
示例#3
0
 private void Awake()
 {
     // Makes sure that I use always a game control even if my next scence already has one.
     // The instance of the object from the scene that is current will persist in the next scene.
     if (Instance == null)
     {
         DontDestroyOnLoad(gameObject);
         Instance = this;
     }
     CountAndStoreBlocks();
     SelectedGeoCO = null;
 }
示例#4
0
        IEnumerator PRTransform()
        {
            _isTransforming          = true;
            TransformationHandleName = Manager.Instance.GET_COLLIDER_NAME;
            // Define what axis to project on
            string     transformType         = Manager.Instance.GET_COLLIDER_TAG;
            Vector3    translateAxis         = GetTranslateAxis();
            Plane      translatePlane        = GetTranslatePlane();
            Vector3    savedProjectedOnPlane = translatePlane.ClosestPointOnPlane(_savedHitLoc);
            Quaternion quaSavedRotation      = mainTargetRoot.localRotation;
            // Scale save
            Vector3    savedScale     = mainTargetRoot.localScale;
            Vector3    scaleAxis      = GetScaleAxis();
            Vector3    scaleAxisLocal = GetScaleAxisLocal();
            GameObject scaleCube      = null;
            Vector3    scaleCubeLoc   = Vector3.zero;
            Vector3    scaleCubeScale = Vector3.zero;
            // Edges and Vertices.
            PRGeo geo = mainTargetRoot.gameObject.GetComponent <PRGeo>();

            if (Manager.Instance.GET_COLLIDER_TAG == "GizmoScale" ||
                Manager.Instance.GET_COLLIDER_TAG == "GizmoScaleCenter")
            {
                scaleCube      = Manager.Instance.GET_COLLIDER_GO;
                scaleCubeLoc   = scaleCube.transform.position;
                scaleCubeScale = scaleCube.transform.localScale;
                // Unparent the edges to avoid deforming the edges whne the geometry is scaled.
                geo.PR_EDGE_GO.GetComponent <ParentEdge>().UnparentEdges();
                // Unparent vertices
                geo.PR_VERTEX_GO.GetComponent <ParentVertex>().UnparentVertices();
            }
            while (!InputUp)
            {
                if (transformType == "GizmoMove")
                {
                    //Debug.Log("Move");
                    // Project
                    float moveAmount = ExtVector3.MagnitudeInDirection(manipulationVec, translateAxis) *
                                       MoveMultiplier;
                    for (int i = 0; i < targetRootsOrdered.Count; i++)
                    {
                        Transform target = targetRootsOrdered[i];
                        // Save target position, in worder to add the movement Vector. Translate gives a continuos transformation.
                        Vector3 targetSavedPos = targetRootsOrderedSavedPos[i];
                        target.position = targetSavedPos + translateAxis * moveAmount;
                        if (target.tag == "PREdge" || target.tag == "PRFace" ||
                            target.tag == "PRVertex")
                        {
                            target.transform.parent.parent.GetComponent <PRGeo>().EdgeDimTempParet.SetActive(true);
                        }
                    }
                }
                else if (transformType == "GizmoPlaneMove")
                {
                    //Debug.Log("PlaneMove");
                    // Project the Manipulation vector onto the plane.
                    Vector3 projectedOnPlane = Vector3.ProjectOnPlane(manipulationVec, translatePlane.normal);
                    // Apply the projected manipulation vector for movement.
                    for (int i = 0; i < targetRootsOrdered.Count; i++)
                    {
                        Transform target = targetRootsOrdered[i];
                        // Save target position, in worder to add the movement Vector. Translate gives a continuos transformation.
                        Vector3 targetSavedPos = targetRootsOrderedSavedPos[i];
                        target.position = targetSavedPos + projectedOnPlane * MoveMultiplier;
                    }
                }
                else if (transformType == "GizmoRotate" &&
                         Manager.Instance.SelectedGeoCO.GeoModeActive)
                {
                    // Don't allow any rotation if I am not in the GeoMode.

                    //Debug.Log("Rotate");
                    // Get the world location of the manipolation in respect to the savedHit location.
                    Vector3 worldManip = savedProjectedOnPlane + manipulationVec;
                    // Project the worlManip to the translatePlane which has Gizmo coordinates.
                    Vector3 projectedOnPlane = translatePlane.ClosestPointOnPlane(worldManip);
                    // Get the quaterion with rotation between the savedHit and the actualHit that have the origin as the 0,0,0 coordinate, and not the gizmo.
                    Quaternion quaRotation = Quaternion.FromToRotation(savedProjectedOnPlane - GizmoGo.transform.position, projectedOnPlane - GizmoGo.transform.position);
                    // Apply quaternion.
                    for (int i = 0; i < targetRootsOrdered.Count; i++)
                    {
                        Transform target = targetRootsOrdered[i];
                        if (space == TransformSpace.Global)
                        {
                            target.rotation = quaRotation * quaSavedRotation;
                            // Update the Gizmo rotation while doing the global rotation.
                            GizmoGo.transform.rotation = quaRotation;
                        }
                        else if (space == TransformSpace.Local)
                        {
                            target.localRotation = quaRotation * quaSavedRotation;
                        }
                    }
                }
                else if (transformType == "GizmoScale")
                {
                    //Debug.Log("Scale");
                    float scaleAmount = ExtVector3.MagnitudeInDirection(manipulationVec, scaleAxis) *
                                        ScaleMultiplier;
                    for (int i = 0; i < targetRootsOrdered.Count; i++)
                    {
                        Transform target = targetRootsOrdered[i];
                        target.localScale = savedScale + scaleAxis * scaleAmount;
                        // Update the Gizmo position for scale cubes and scale rects.
                        scaleCube.transform.position = scaleCubeLoc + (scaleAxisLocal * scaleAmount);
                    }
                    // Turn ON edge dimentions
                    geo.EdgeDimTempParet.SetActive(true);
                }
                else if (transformType == "GizmoScaleCenter")
                {
                    // Get the porjection of the manipulation vector on the predifined plane during manipulation start.
                    Vector3 closest  = _scale3DPlane.ClosestPointOnPlane(GizmoGo.transform.position + manipulationVec);
                    float   magScale = 0;
                    // To have the scale go both ways (larger and smaller) check the angle between manipulation vector and plane normal.
                    if (Vector3.Angle(_scale3DPlane.normal, manipulationVec) < 90)
                    {
                        magScale = (closest - (GizmoGo.transform.position + manipulationVec)).magnitude * ScaleMultiplier;
                    }
                    else
                    {
                        magScale = -(closest - (GizmoGo.transform.position + manipulationVec)).magnitude * ScaleMultiplier;
                    }
                    for (int i = 0; i < targetRootsOrdered.Count; i++)
                    {
                        Transform target = targetRootsOrdered[i];
                        target.localScale = savedScale + new Vector3(magScale, magScale, magScale);
                        // Update the Gizmo position for scale cubes and scale rects.
                        scaleCube.transform.localScale = scaleCubeScale + new Vector3(magScale, magScale, magScale) * 2;
                    }
                    // Turn ON edge dimentions
                    geo.EdgeDimTempParet.SetActive(true);
                }
                // Update the Gizmo location while doing the global rotation.
                GizmoGo.transform.position = mainTargetRoot.transform.position;
                yield return(null);
            }
            // Reset scale elements.
            if (scaleCube)
            {
                // Turn ON edge dimentions
                geo.EdgeDimTempParet.SetActive(false);
                // Parent the edges and vertices back to the geometry, after the scale is finished.
                geo.PR_EDGE_GO.GetComponent <ParentEdge>().ParentEdges();
                geo.PR_VERTEX_GO.GetComponent <ParentVertex>().ParentVertices();
                scaleCube.transform.position   = scaleCubeLoc;
                scaleCube.transform.localScale = scaleCubeScale;
            }
            if (mainTargetRoot.tag == "PREdge" || mainTargetRoot.tag == "PRFace" ||
                mainTargetRoot.tag == "PRVertex")
            {
                mainTargetRoot.transform.parent.parent.GetComponent <PRGeo>().EdgeDimTempParet.SetActive(false);
            }

            _isTransforming = false;
        }