Esempio n. 1
0
    public void drawPin(HoudiniInstancerOverrideInfo override_info)
    {
        // TODO: This code should be on the companion Editor class, not here!

        float handle_size = HandleUtility.GetHandleSize(override_info.translate);

        Matrix4x4 old_handles_mat = Handles.matrix;
        Matrix4x4 mat             = new Matrix4x4();

        mat.m00 = 1; mat.m11 = 1; mat.m22 = 1; mat.m33 = 1;

        mat.SetColumn(3, new Vector4(override_info.translate.x,
                                     override_info.translate.y,
                                     override_info.translate.z, 1));
        Handles.matrix = mat;

        const float scale_factor_tweak1 = 0.17f;
        const float scale_factor_tweak2 = 0.2f;

        float scale_factor = scale_factor_tweak1 * handle_size;

        if (scale_factor < scale_factor_tweak1)
        {
            scale_factor = scale_factor_tweak1;
        }

        scale_factor *= HoudiniHost.prPinSize;

        Handles.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);


        const float vertical_scale          = 14.0f;
        float       pin_sphere_displacement = 14.0f * scale_factor * scale_factor_tweak2;

        mat            = Handles.matrix;
        mat.m11        = vertical_scale;
        Handles.matrix = mat;

        Vector3 position = new Vector3(0, 0, 0);

        position.y = 0.5f * pin_sphere_displacement / vertical_scale;

        Handles.CylinderCap(override_info.instancePointNumber,
                            position,
                            Quaternion.Euler(new Vector3(90, 0, 0)),
                            scale_factor * scale_factor_tweak2);


        mat.m11        = 1.0f;
        Handles.matrix = mat;

        Handles.color = HoudiniHost.prPinColour;
        position.y    = pin_sphere_displacement;
        Handles.SphereCap(override_info.instancePointNumber,
                          position,
                          Quaternion.Euler(new Vector3(90, 0, 0)),
                          scale_factor * 1.3f);

        Handles.matrix = old_handles_mat;
    }
 void SecondWindow2(int unusedWindowID)
 {
     capSize  = EditorGUILayout.IntField("尺寸:", capSize);
     capEuler = EditorGUILayout.Vector3Field("testVector3:", capEuler);
     if (GUILayout.Button("关闭绘制图形"))
     {
         secondWindow2 = false;
     }
     Handles.color = Color.red;
     Handles.DrawLine(new Vector2(75, 100), new Vector3(150, 200));
     Handles.CircleCap(1, new Vector2(300, 150), Quaternion.identity, capSize);
     Handles.color = Color.green;
     Handles.SphereCap(2, new Vector2(100, 250), Quaternion.Euler(capEuler), capSize);
     Handles.CubeCap(3, new Vector2(300, 250), Quaternion.Euler(capEuler), capSize);
     Handles.color = Color.blue;
     Handles.CylinderCap(4, new Vector2(100, 350), Quaternion.Euler(capEuler), capSize);
     Handles.ConeCap(5, new Vector2(300, 350), Quaternion.Euler(capEuler), capSize);
     GUI.DragWindow();//画出子窗口
 }
Esempio n. 3
0
    void OnSceneGUI()
    {
        Color c = Handles.color;

        Handles.color = Color.red;

        Handles.Label(_myTarget.transform.position, "Town Manager");

        _myTarget._heroBornPoint = Handles.PositionHandle(_myTarget._heroBornPoint, Quaternion.identity);
        Handles.CubeCap(0, _myTarget._heroBornPoint, Quaternion.identity, 1.0f);
        Handles.Label(_myTarget._heroBornPoint, "hero");
        Handles.color = Color.blue;
        int pindex = 0;

        foreach (Vector3 p in _myTarget._friendBornPoints)
        {
            _myTarget._friendBornPoints[pindex] = Handles.PositionHandle(p, Quaternion.identity);
            Handles.CylinderCap(0, p, Quaternion.AngleAxis(90.0f, Vector3.left), 0.5f);
            Handles.Label(p, "friend" + (pindex + 1));
            ++pindex;
        }

        Handles.color = c;
    }
Esempio n. 4
0
    void DrawGizmoAxis(AXIS drawAxis, bool bLocal, float fLineLen, float fCapSize)
    {
        Transform selTrans  = m_SelectedTransform.transform;
        Vector3   vecEuler  = Vector3.zero;
        Vector3   vecDirect = Vector3.zero;

        // set color
        if (m_nActiveAxis != drawAxis || m_bActiveLocal != bLocal)
        {
            switch (drawAxis)
            {
            case AXIS.X: Handles.color = Color.red;                 break;

            case AXIS.Y: Handles.color = Color.green;               break;

            case AXIS.Z: Handles.color = Color.blue;                break;
            }
        }
        else
        {
            Handles.color = Color.white;
        }
        if (((GIZMO_TYPE)m_nGizmoTypeIndex) == GIZMO_TYPE.HAND)
        {
            Handles.color = new Color(Handles.color.r, Handles.color.g, Handles.color.b, m_fHandAlpha);
        }

        // axis color
        Gizmos.color = Handles.color;

        vecDirect = GetDirect(selTrans, drawAxis, bLocal);
        vecEuler  = GetEuler(selTrans, drawAxis, bLocal);

        // draw line
//		Handles.DrawLine(GetPosition(selTrans), GetPosition(selTrans) + vecDirect * fLineLen);
        if (((GIZMO_TYPE)m_nGizmoTypeIndex) == GIZMO_TYPE.SCALE)
        {
            float scale = 1;
            if (m_bClick)
            {
                switch (drawAxis)
                {
                case AXIS.X: scale = selTrans.localScale.x / m_OldOriScale.x; break;

                case AXIS.Y: scale = selTrans.localScale.y / m_OldOriScale.y; break;

                case AXIS.Z: scale = selTrans.localScale.z / m_OldOriScale.z; break;
                }
            }

            Gizmos.DrawRay(GetPosition(selTrans), vecDirect * fLineLen * scale);
        }
        else
        {
            Gizmos.DrawRay(GetPosition(selTrans), vecDirect * fLineLen);
        }

        // draw cap
        switch (((GIZMO_TYPE)m_nGizmoTypeIndex))
        {
        case GIZMO_TYPE.POSITION:       Handles.ConeCap(0, GetPosition(selTrans) + vecDirect * fLineLen, Quaternion.Euler(vecEuler), fCapSize * 1.6f);            break;

        case GIZMO_TYPE.ROTATION:       Handles.CylinderCap(0, GetPosition(selTrans) + vecDirect * fLineLen, Quaternion.Euler(vecEuler), fCapSize * 2f);          break;

        case GIZMO_TYPE.SCALE:          Handles.CubeCap(0, GetPosition(selTrans) + vecDirect * fLineLen, Quaternion.Euler(vecEuler), fCapSize);                         break;
        }

//      // draw rot line
//      if (((GIZMO_TYPE)m_nGizmoTypeIndex) == GIZMO_TYPE.ROTATION)
//      {
//          if (m_bClick)
//          {
//				transform.position	= GetPosition(selTrans);
//				transform.rotation	= Quaternion.Euler(m_SaveRotate);
//
//              switch (drawAxis)
//              {
//                  case AXIS.X: Gizmos.color = Color.red;		Gizmos.DrawLine(GetPosition(selTrans), selTrans.right		* fLineLen * 1.3f);	break;
//                  case AXIS.Y: Gizmos.color = Color.green;	Gizmos.DrawLine(GetPosition(selTrans), selTrans.up			* fLineLen * 1.3f);	break;
//                  case AXIS.Z: Gizmos.color = Color.blue;		Gizmos.DrawLine(GetPosition(selTrans), selTrans.forward		* fLineLen * 1.3f);	break;
//              }
//              if (m_nActiveAxis != drawAxis && m_bActiveLocal == bLocal)
//              {
//                  Gizmos.color = Color.white;
//                  switch (drawAxis)
//                  {
//                      case AXIS.X: Gizmos.DrawLine(transform.position, transform.right	* fLineLen * 2);	break;
//                      case AXIS.Y: Gizmos.DrawLine(transform.position, transform.up		* fLineLen * 2);	break;
//                      case AXIS.Z: Gizmos.DrawLine(transform.position, transform.forward	* fLineLen * 2);	break;
// //						case AXIS.X: Handles.DrawSolidArc(transform.position, transform.right, -transform.up, m_SaveRotate.z, fCapSize*10); break;
//                  }
//              }
//          }
//      }
    }
Esempio n. 5
0
        //Plane3d dPlane = new Plane3d();
        public void OnSceneGUI()
        {
            if (spriteDeformerEditor.selectedPoints.Count <= 0)
            {
                return;
            }
            // dPlane = new Plane3d(spriteDeformerEditor.spriteDeformer.transform.position, spriteDeformerEditor.spriteDeformer.transform.rotation);
            CurrentTool nextTool                 = CurrentTool.NONE;
            float       newHandleSize            = HandleUtility.GetHandleSize(pos2Dto3D(pivot));
            Vector2     newPivotHandle           = pivot - oriantDirUp * newHandleSize / 3f;
            Vector2     newOriantHandle          = pivot + oriantDir * newHandleSize * 1.5f;
            float       newScaleStandartDistance = newHandleSize * 1.3f;
            Vector2     newScaleVerticalHandle   = pivot + oriantDirUp * newScaleStandartDistance;
            Vector2     newScaleHorizontalHandle = pivot + oriantDir * newScaleStandartDistance;
            Vector2     newRotateHandle          = pivot + oriantDirUp * newHandleSize * 1.5f;

            if (spriteDeformerEditor.currentTool == CurrentTool.NONE)
            {
                if (Vector3.Distance(Event.current.mousePosition, pos2DtoScreen(pivot)) < 7f)
                {
                    nextTool = CurrentTool.MOVE_POINTS;
                }
                else
                {
                    Vector2 l1Screen   = pos2DtoScreen(pivot);
                    Vector2 l2Screen   = pos2DtoScreen(pivot + oriantDir * newHandleSize);
                    Vector2 l2UpScreen = pos2DtoScreen(pivot + oriantDirUp * newHandleSize);
                    float   d          = Vector2.Distance(Line.ClosestPointOnSegment(l1Screen, l2Screen, Event.current.mousePosition), Event.current.mousePosition);
                    float   dUP        = Vector2.Distance(Line.ClosestPointOnSegment(l1Screen, l2UpScreen, Event.current.mousePosition), Event.current.mousePosition);
                    if (Mathf.Min(d, dUP) < 6f)
                    {
                        nextTool = d < dUP ? CurrentTool.MOVE_RIGHT : CurrentTool.MOVE_UP;
                    }
                    else if (Vector2.Distance(pos2DtoScreen(newPivotHandle), Event.current.mousePosition) < 6)
                    {
                        nextTool = CurrentTool.MOVE_PIVOT;
                    }
                    else if (Vector2.Distance(pos2DtoScreen(newScaleHorizontalHandle), Event.current.mousePosition) < 6)
                    {
                        nextTool = CurrentTool.SCALE_HORIZONTAL;
                        calculateLocalPositions();
                    }
                    else if (Vector2.Distance(pos2DtoScreen(newScaleVerticalHandle), Event.current.mousePosition) < 6)
                    {
                        nextTool = CurrentTool.SCALE_VERTICAL;
                        calculateLocalPositions();
                    }
                    else if (Vector2.Distance(pos2DtoScreen(newOriantHandle), Event.current.mousePosition) < 6)
                    {
                        nextTool = CurrentTool.ORIANT;
                    }
                    else if (Vector2.Distance(pos2DtoScreen(newRotateHandle), Event.current.mousePosition) < 6)
                    {
                        nextTool = CurrentTool.ROTATE;
                        calculateLocalPositions();
                    }
                }

                pivotDeltaClick = mouse2Dpos - pivot;
            }


            if (Event.current.type == EventType.MouseDown && nextTool != CurrentTool.NONE)
            {
                spriteDeformerEditor.currentTool = nextTool;
            }
            if (spriteDeformerEditor.currentTool == CurrentTool.MOVE_POINTS)
            {
                Vector2 newPos = mouse2Dpos - pivotDeltaClick;
                movePoints(pivot, newPos);
                pivot = newPos;
            }
            if (spriteDeformerEditor.currentTool == CurrentTool.MOVE_RIGHT || spriteDeformerEditor.currentTool == CurrentTool.MOVE_UP)
            {
                Vector2 cDir        = spriteDeformerEditor.currentTool == CurrentTool.MOVE_RIGHT ? oriantDir : oriantDirUp;
                Vector2 newPivotPos = Line3d.closestPointInLine(mouse2Dpos - pivotDeltaClick, pivot, pivot + cDir);
                movePoints(pivot, newPivotPos);
                pivot = newPivotPos;
            }
            if (spriteDeformerEditor.currentTool == CurrentTool.MOVE_PIVOT)
            {
                pivot = mouse2Dpos - pivotDeltaClick;
            }
            if (spriteDeformerEditor.currentTool == CurrentTool.SCALE_HORIZONTAL
                ||
                spriteDeformerEditor.currentTool == CurrentTool.SCALE_VERTICAL)
            {
                Vector2 lineStart = pivot;
                Vector2 line      = spriteDeformerEditor.currentTool == CurrentTool.SCALE_HORIZONTAL ? oriantDir : oriantDirUp;
                float   t         = Vector2.Dot(mouse2Dpos - lineStart, line);
                if (spriteDeformerEditor.currentTool == CurrentTool.SCALE_HORIZONTAL)
                {
                    newScaleHorizontalHandle = lineStart + line * t;
                    setPointsFromPointsInPivotLocal(new Vector2(t / newScaleStandartDistance, 1f));
                }
                else
                {
                    newScaleVerticalHandle = lineStart + line * t;
                    setPointsFromPointsInPivotLocal(new Vector2(1f, t / newScaleStandartDistance));
                }
            }
            if (spriteDeformerEditor.currentTool == CurrentTool.ORIANT)
            {
                Vector2 mlp = mouse2Dpos;
                oriant = Mathf.Atan2(mlp.y - pivot.y, mlp.x - pivot.x);
            }
            if (spriteDeformerEditor.currentTool == CurrentTool.ROTATE)
            {
                calculateLocalPositions();
                Vector2 mlp = mouse2Dpos;
                float   a   = Mathf.Atan2(mlp.y - pivot.y, mlp.x - pivot.x) - Mathf.PI / 2f;
                setPointsFromPointsInPivotLocal(new Vector2(1f, 1f), a - oriant);
                oriant = a;
            }


            Color overColor     = spriteDeformerEditor.colorSets[ColorSet.DEFORMER_TOOL].over;
            Color standartColor = spriteDeformerEditor.colorSets[ColorSet.DEFORMER_TOOL].standart;

            Handles.color = nextTool == CurrentTool.MOVE_RIGHT ? overColor : standartColor;
            List <CurrentTool> candraw = new List <CurrentTool>()
            {
                CurrentTool.NONE, CurrentTool.ORIANT, CurrentTool.MOVE_PIVOT, CurrentTool.MOVE_RIGHT, CurrentTool.ROTATE
            };

            if (candraw.Contains(spriteDeformerEditor.currentTool))
            {
                Handles.ArrowCap(15, pos2Dto3D(pivot), spriteDeformerEditor.spriteDeformer.transform.rotation * Quaternion.Euler(0 - oriant * Mathf.Rad2Deg, 90, 0), newHandleSize);
            }

            Handles.color = nextTool == CurrentTool.MOVE_UP ? overColor : standartColor;
            candraw       = new List <CurrentTool>()
            {
                CurrentTool.NONE, CurrentTool.ORIANT, CurrentTool.MOVE_PIVOT, CurrentTool.MOVE_UP, CurrentTool.ROTATE
            };
            if (candraw.Contains(spriteDeformerEditor.currentTool))
            {
                Handles.ArrowCap(15, pos2Dto3D(pivot), spriteDeformerEditor.spriteDeformer.transform.rotation * Quaternion.Euler(-90 - oriant * Mathf.Rad2Deg, 90, 0), newHandleSize);
            }

            Handles.color = nextTool == CurrentTool.MOVE_POINTS ? overColor : standartColor;
            Handles.CylinderCap(15, pos2Dto3D(pivot), spriteDeformerEditor.spriteDeformer.transform.rotation, newHandleSize / 5f);

            candraw = new List <CurrentTool>()
            {
                CurrentTool.NONE, CurrentTool.ORIANT, CurrentTool.MOVE_PIVOT, CurrentTool.MOVE_PIVOT
            };
            Handles.color = nextTool == CurrentTool.MOVE_PIVOT ? overColor : standartColor;
            if (candraw.Contains(spriteDeformerEditor.currentTool))
            {
                Handles.SphereCap(0, pos2Dto3D(newPivotHandle), Quaternion.identity, newHandleSize / 10f);
            }

            Handles.color = nextTool == CurrentTool.SCALE_HORIZONTAL ? overColor : standartColor;
            candraw       = new List <CurrentTool>()
            {
                CurrentTool.NONE, CurrentTool.ORIANT, CurrentTool.MOVE_PIVOT, CurrentTool.SCALE_HORIZONTAL
            };
            if (candraw.Contains(spriteDeformerEditor.currentTool))
            {
                Handles.CubeCap(0, pos2Dto3D(newScaleHorizontalHandle), spriteDeformerEditor.spriteDeformer.transform.rotation * Quaternion.Euler(0, 0, oriant * Mathf.Rad2Deg), newHandleSize / 7f);
            }

            Handles.color = nextTool == CurrentTool.SCALE_VERTICAL ? overColor : standartColor;
            candraw       = new List <CurrentTool>()
            {
                CurrentTool.NONE, CurrentTool.ORIANT, CurrentTool.MOVE_PIVOT, CurrentTool.SCALE_VERTICAL
            };
            if (candraw.Contains(spriteDeformerEditor.currentTool))
            {
                Handles.CubeCap(0, pos2Dto3D(newScaleVerticalHandle), spriteDeformerEditor.spriteDeformer.transform.rotation * Quaternion.Euler(0, 0, oriant * Mathf.Rad2Deg), newHandleSize / 7f);
            }

            Handles.color = nextTool == CurrentTool.ORIANT ? overColor : standartColor;
            candraw       = new List <CurrentTool>()
            {
                CurrentTool.NONE, CurrentTool.ORIANT, CurrentTool.MOVE_PIVOT, CurrentTool.MOVE_PIVOT
            };
            if (candraw.Contains(spriteDeformerEditor.currentTool))
            {
                Handles.ConeCap(0, pos2Dto3D(newOriantHandle), Quaternion.LookRotation(pos2Dto3D(newOriantHandle) - pos2Dto3D(pivot)), newHandleSize / 6f);
            }

            Handles.color = nextTool == CurrentTool.ROTATE ? overColor : standartColor;
            candraw       = new List <CurrentTool>()
            {
                CurrentTool.NONE, CurrentTool.ORIANT, CurrentTool.MOVE_PIVOT, CurrentTool.MOVE_PIVOT, CurrentTool.ROTATE
            };
            if (candraw.Contains(spriteDeformerEditor.currentTool))
            {
                Handles.ConeCap(0, pos2Dto3D(newRotateHandle), Quaternion.LookRotation(pos2Dto3D(newOriantHandle) - pos2Dto3D(pivot)), newHandleSize / 6f);
            }
        }