void OnEnable()
    {
        temp = target as Branch_Mono;
        sim  = temp.GetSimulation;
        if (sim == null)
        {
            BinaryTree.ResetParams(temp.length);
            temp.ResetForm();
            this.sim = temp.GetSimulation;
        }
        else
        {
            //Branch.lengthExit = temp.lengthExit;
            BinaryTree.angleOffsetMax         = temp.angleOffsetMax;
            BinaryTree.angleOffsetMin         = temp.angleOffsetMin;
            BinaryTree.lengthMax1             = temp.lengthMax1;
            BinaryTree.lengthMax2             = temp.lengthMax2;
            BinaryTree.lengthMin1             = temp.lengthMin1;
            BinaryTree.lengthMin2             = temp.lengthMin2;
            BinaryTree.lengthBranchAThreshold = temp.lengthBranchAThreshold;
            BinaryTree.lengthBranchBThreshold = temp.lengthBranchBThreshold;
            //Branch.lengthExitRatio = temp.lengthExitRatio;
            //Branch.lengthExit = temp.lengthExitRatio * temp.length;
            BinaryTree.maxDepth = temp.maxDepth;
        }

        lastPMode           = Tools.pivotMode;
        lastRMode           = Tools.pivotRotation;
        Tools.pivotMode     = PivotMode.Pivot;
        Tools.pivotRotation = PivotRotation.Local;
    }
Beispiel #2
0
    void RotateSide(List <GameObject> side, float angle)
    {
        // automatically rotate the side by the angle
        PivotRotation pr = side[4].transform.parent.GetComponent <PivotRotation>();

        pr.StartAutoRotate(side, angle);
    }
Beispiel #3
0
 bool TogglePivotRotation()
 {
     m_PivotRotation = m_PivotRotation == PivotRotation.Global ? PivotRotation.Local : PivotRotation.Global;
     UpdatePivotRotationAction();
     UpdateCurrentManipulator();
     return(true);
 }
        // Sync ProBuilder HandleOrientation to the current Tools.PivotRotation
        static void SyncPivotRotation()
        {
            if (s_PivotRotation != Tools.pivotRotation)
            {
                s_HandleOrientation.SetValue(Tools.pivotRotation == PivotRotation.Global
                    ? HandleOrientation.World
                    : HandleOrientation.ActiveObject);
                s_PivotRotation = Tools.pivotRotation;
                MeshSelection.InvalidateElementSelection();
                return;
            }

            var value = s_HandleOrientation.value;
            var unity = value == HandleOrientation.ActiveObject ? PivotRotation.Local : PivotRotation.Global;

            if (value != HandleOrientation.ActiveElement)
            {
                if (unity != Tools.pivotRotation)
                {
                    s_HandleOrientation.SetValue(Tools.pivotRotation == PivotRotation.Global
                            ? HandleOrientation.World
                            : HandleOrientation.ActiveObject,
                                                 true);
                    MeshSelection.InvalidateElementSelection();
                }
            }
        }
Beispiel #5
0
        private void DoPivotButtons(Rect rect)
        {
            Tools.pivotMode = (PivotMode)EditorGUI.CycleButton(new Rect(rect.x, rect.y, rect.width / 2f, rect.height), (int)Tools.pivotMode, Toolbar.s_PivotIcons, "ButtonLeft");
            if (Tools.current == Tool.Scale && Selection.transforms.Length < 2)
            {
                GUI.enabled = false;
            }
            PivotRotation pivotRotation = (PivotRotation)EditorGUI.CycleButton(new Rect(rect.x + rect.width / 2f, rect.y, rect.width / 2f, rect.height), (int)Tools.pivotRotation, Toolbar.s_PivotRotation, "ButtonRight");

            if (Tools.pivotRotation != pivotRotation)
            {
                Tools.pivotRotation = pivotRotation;
                if (pivotRotation == PivotRotation.Global)
                {
                    Tools.ResetGlobalHandleRotation();
                }
            }
            if (Tools.current == Tool.Scale)
            {
                GUI.enabled = true;
            }
            if (GUI.changed)
            {
                Tools.RepaintAllToolViews();
            }
        }
        protected virtual void OnSceneGUI()
        {
            spline          = target as SplinePath;
            handleTransform = spline.transform;

            if (currentTool != Tools.current ||
                currentPivotRotation != Tools.pivotRotation)
            {
                ResetHandleSettings();
                currentTool          = Tools.current;
                currentPivotRotation = Tools.pivotRotation;
            }

            Vector3 p0 = ShowPoint(0);

            for (int i = 1; i < spline.ControlPointCount; i += 3)
            {
                Vector3 p1 = ShowPoint(i);
                Vector3 p2 = ShowPoint(i + 1);
                Vector3 p3 = ShowPoint(i + 2);

                Handles.color = Color.gray;
                Handles.DrawLine(p0, p1);
                Handles.DrawLine(p2, p3);

                Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f);
                p0 = p3;
            }

            ShowDirections();
        }
Beispiel #7
0
    void RotateSide(List <GameObject> side, float angle)
    {
        //자동회전
        PivotRotation pr = side[4].transform.parent.GetComponent <PivotRotation>();

        pr.StartAutoRotate(side, angle);
    }
        internal static void DoBuiltinToolSettings(Rect rect, GUIStyle buttonLeftStyle, GUIStyle buttonRightStyle)
        {
            GUI.SetNextControlName("ToolbarToolPivotPositionButton");
            Tools.pivotMode = (PivotMode)EditorGUI.CycleButton(new Rect(rect.x, rect.y, rect.width / 2, rect.height), (int)Tools.pivotMode, s_PivotIcons, buttonLeftStyle);
            if (Tools.current == Tool.Scale && Selection.transforms.Length < 2)
            {
                GUI.enabled = false;
            }
            GUI.SetNextControlName("ToolbarToolPivotOrientationButton");
            PivotRotation tempPivot = (PivotRotation)EditorGUI.CycleButton(new Rect(rect.x + rect.width / 2, rect.y, rect.width / 2, rect.height), (int)Tools.pivotRotation, s_PivotRotation, buttonRightStyle);

            if (Tools.pivotRotation != tempPivot)
            {
                Tools.pivotRotation = tempPivot;
                if (tempPivot == PivotRotation.Global)
                {
                    Tools.ResetGlobalHandleRotation();
                }
            }

            if (Tools.current == Tool.Scale)
            {
                GUI.enabled = true;
            }

            if (GUI.changed)
            {
                Tools.RepaintAllToolViews();
            }
        }
 private static void CatchToolTipChange()
 {
     if (Tools.pivotRotation != _pivotRotation)
     {
         OnToolRotationChange?.Invoke(Tools.pivotRotation);
     }
     _pivotRotation = Tools.pivotRotation;
 }
Beispiel #10
0
    private void SwitchPivotRotation()
    {
        if (m_Mode == TransformMode.Direct)
        {
            return;
        }

        m_PivotRotation = m_PivotRotation == PivotRotation.Global ? PivotRotation.Local : PivotRotation.Global;
        UpdateCurrentManipulator();
    }
Beispiel #11
0
    /// <summary>
    /// Method intended to be invoked before Drawing GUI
    /// </summary>
    void CheckSelectedMode()
    {
        _selectedMode = GetCurrentMode();

        // if selected item was changed, research colliders
        if (_selectedMode != _lastSelectedMode |
            _lastPivotMode != Tools.pivotMode |
            _lastPivotRotation != Tools.pivotRotation)
        {
            _lastSelectedMode  = _selectedMode;
            _lastPivotMode     = Tools.pivotMode;
            _lastPivotRotation = Tools.pivotRotation;
        }
    }
Beispiel #12
0
    // Draw splines and handles
    private void OnSceneGUI()
    {
        component          = target as SplineComponent;
        componentTransform = component.transform;
        componentRotation  = Tools.pivotRotation == PivotRotation.Local ? componentTransform.rotation : Quaternion.identity;

        DrawBeziers();

        if (Tools.pivotRotation != currentPivotRotation)
        {
            currentPivotRotation = Tools.pivotRotation;
            handleRotation       = Quaternion.identity;
            if (activeSpline >= 0 && selectedIndex >= 0)
            {
                pointRotation = component.GetRotation(activeSpline, selectedIndex);
            }
        }
    }
Beispiel #13
0
        /// <summary>
        /// Method intended to be invoked before Drawing GUI
        /// </summary>
        void CheckSelectedMode()
        {
            bool selectionChanged =
                _lastSelectedMode != _selectedMode |
                _lastPivotMode != Tools.pivotMode |
                _lastPivotRotation != Tools.pivotRotation;

            // if selected item was changed, research colliders
            if (selectionChanged)
            {
                Tools.hidden = _selectedMode != SelectedMode.Ragdoll;

                _lastSelectedMode  = _selectedMode;
                _lastPivotMode     = Tools.pivotMode;
                _lastPivotRotation = Tools.pivotRotation;
                FindColliders();
                SceneView.RepaintAll();
            }
        }
Beispiel #14
0
        private void DoToolButtons()
        {
            GUI.changed = false;
            int num = (int)((!Tools.viewToolActive) ? Tools.current : Tool.View);

            for (int i = 1; i < 5; i++)
            {
                Toolbar.s_ShownToolIcons[i]         = Toolbar.s_ToolIcons[i - 1 + ((i != num) ? 0 : 4)];
                Toolbar.s_ShownToolIcons[i].tooltip = Toolbar.s_ToolIcons[i - 1].tooltip;
            }
            Toolbar.s_ShownToolIcons[0] = Toolbar.s_ViewToolIcons[(int)(Tools.viewTool + ((num != 0) ? 0 : 4))];
            num = GUI.Toolbar(new Rect(10f, 5f, 160f, 24f), num, Toolbar.s_ShownToolIcons, "Command");
            if (GUI.changed)
            {
                Tools.current = (Tool)num;
            }
            Tools.pivotMode = (PivotMode)EditorGUI.CycleButton(new Rect(190f, 8f, 64f, 18f), (int)Tools.pivotMode, Toolbar.s_PivotIcons, "ButtonLeft");
            if (Tools.current == Tool.Scale && Selection.transforms.Length < 2)
            {
                GUI.enabled = false;
            }
            PivotRotation pivotRotation = (PivotRotation)EditorGUI.CycleButton(new Rect(254f, 8f, 64f, 18f), (int)Tools.pivotRotation, Toolbar.s_PivotRotation, "ButtonRight");

            if (Tools.pivotRotation != pivotRotation)
            {
                Tools.pivotRotation = pivotRotation;
                if (pivotRotation == PivotRotation.Global)
                {
                    Tools.ResetGlobalHandleRotation();
                }
            }
            if (Tools.current == Tool.Scale)
            {
                GUI.enabled = true;
            }
            if (GUI.changed)
            {
                Tools.RepaintAllToolViews();
            }
        }
Beispiel #15
0
        protected virtual void OnSceneGUI()
        {
            spline          = target as SplinePath;
            handleTransform = spline.transform;

            if (currentTool != Tools.current ||
                currentPivotRotation != Tools.pivotRotation)
            {
                currentTool          = Tools.current;
                currentPivotRotation = Tools.pivotRotation;

                ResetHandleSettings();
            }

            Vector3 p0 = ShowPoint(0);

            for (int i = 1; i < spline.ControlPointCount; i += 3)
            {
                Vector3 p1 = ShowPoint(i);
                Vector3 p2 = ShowPoint(i + 1);
                Vector3 p3 = ShowPoint(i + 2);

                Handles.color = Color.gray;
                Handles.DrawLine(p0, p1);
                Handles.DrawLine(p2, p3);

                Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f);
                p0 = p3;
            }

            Handles.color = Color.green.SetA(0.3f);
            Handles.SphereHandleCap(0, spline.GetPoint(0f), Quaternion.identity, 0.1f, EventType.Repaint);

            Handles.color = Color.red.SetA(0.3f);
            Handles.SphereHandleCap(0, spline.GetPoint(1f), Quaternion.identity, 0.1f, EventType.Repaint);

            if (spline.NormalType == NormalType.Perpendicular)
            {
                for (int i = 0; i < spline.Normals.Length; i++)
                {
                    if (i % 3 == 0)
                    {
                        Vector3 pos    = spline.GetControlPoint(i);
                        Vector3 normal = spline.GetControlNormal(i);

                        Handles.color = Color.red;
                        Handles.DrawLine(pos, pos + normal * 0.8f);
                    }
                }
            }

            int numIterations = 10 * spline.ControlPointCount;

            for (int i = 1; i < numIterations; i++)
            {
                float alpha = i / (float)numIterations;

                Vector3 pos    = spline.GetPoint(alpha);
                Vector3 normal = spline.GetNormal(alpha);

                Handles.color = Color.green;
                Handles.DrawLine(pos, pos + normal * 0.4f);
            }
        }
Beispiel #16
0
        protected virtual void OnSceneGUI()
        {
            linePath        = target as LinePath;
            handleTransform = linePath.transform;

            if (currentTool != Tools.current ||
                currentPivotRotation != Tools.pivotRotation)
            {
                currentTool          = Tools.current;
                currentPivotRotation = Tools.pivotRotation;

                ResetHandleSettings();
            }

            for (int i = 0; i < linePath.PointCount; i++)
            {
                ShowPoint(i);
            }

            for (int i = 1; i < linePath.PointCount; i++)
            {
                Handles.color = Color.white;
                Handles.DrawLine(
                    linePath.transform.TransformPoint(linePath.Points[i]),
                    linePath.transform.TransformPoint(linePath.Points[i - 1]));
            }

            if (linePath.Loop)
            {
                Handles.DrawLine(
                    linePath.transform.TransformPoint(linePath.Points[0]),
                    linePath.transform.TransformPoint(linePath.Points[linePath.Points.Length - 1]));
            }

            Handles.color = Color.green.SetA(0.3f);
            Handles.SphereHandleCap(0, linePath.GetPoint(0f), Quaternion.identity, 0.1f, EventType.Repaint);

            Handles.color = Color.red.SetA(0.3f);
            Handles.SphereHandleCap(0, linePath.GetPoint(1f), Quaternion.identity, 0.1f, EventType.Repaint);

            if (linePath.NormalType == NormalType.Perpendicular)
            {
                for (int i = 0; i < linePath.Normals.Length; i++)
                {
                    Vector3 pos    = linePath.GetPoint(i);
                    Vector3 normal = linePath.GetNormal(i);

                    Handles.color = Color.red;
                    Handles.DrawLine(pos, pos + normal * 0.8f);
                }
            }

            int numIterations = 10 * linePath.PointCount;

            for (int i = 1; i < numIterations; i++)
            {
                float alpha = i / (float)numIterations;

                Vector3 pos    = linePath.GetPoint(alpha);
                Vector3 normal = linePath.GetNormal(alpha);

                Handles.color = Color.green;
                Handles.DrawLine(pos, pos + normal * 0.4f);
            }
        }
Beispiel #17
0
 void Start()
 {
     _pivotRotation = GetComponent <PivotRotation>();
 }
Beispiel #18
0
        void Update()
        {
            if (Selection.transforms.Length <= 0)
            {
                return;
            }
            Transform first = Selection.transforms[0];

            if (!SnapEnabled)
            {
                UpdateLastSelection(first);
                return;
            }

            bool changed = false;

            if (Selection.transforms.Length != selectionBefore.Length)
            {
                changed = true;
            }
            else
            {
                for (int i = 0; i < selectionBefore.Length; i++)
                {
                    if (Selection.transforms[i] != selectionBefore[i])
                    {
                        changed = true;
                        break;
                    }
                }
            }

            if (changed)
            {
                UpdateLastSelection(first);
            }

            switch (Tools.current)
            {
            case Tool.Move:
            case Tool.Rect:
                if (posBefore != first.position)
                {
                    SnapToGrid(Selection.transforms);
                    posBefore = first.position;
                }
                break;

            case Tool.Scale:
                if (scaleBefore != first.localScale)
                {
                    ScaleToGrid(Selection.transforms);
                    scaleBefore = first.localScale;
                }
                break;

            case Tool.Rotate:
                if (rotBefore != first.rotation)
                {
                    RotateToAngle(Selection.transforms);
                    rotBefore = first.rotation;
                }
                break;
            }

            if (Tools.current == Tool.Rotate)
            {
                if (!forceRotationMode)
                {
                    rotationModeBefore  = Tools.pivotRotation;
                    Tools.pivotRotation = PivotRotation.Local;
                    forceRotationMode   = true;
                }
            }
            else if (forceRotationMode)
            {
                forceRotationMode   = false;
                Tools.pivotRotation = rotationModeBefore;
            }
        }
        private void CreateParticle(Vector3D interpolatedEffectPosition)
        {
            MyAnimatedParticle particle = MyTransparentGeometry.AddAnimatedParticle();

            if (particle == null)
            {
                return;
            }

            particle.Type = (MyParticleTypeEnum)ParticleType.GetValue <int>();

            MyUtils.AssertIsValid(m_effect.WorldMatrix);

            Vector3D startOffset;

            m_emitter.CalculateStartPosition(m_effect.GetElapsedTime(), MatrixD.CreateWorld(interpolatedEffectPosition, m_effect.WorldMatrix.Forward, m_effect.WorldMatrix.Up), m_effect.UserEmitterScale * m_effect.UserAxisScale, m_effect.UserEmitterScale * m_effect.UserScale, out startOffset, out particle.StartPosition);

            Vector3D particlePosition = particle.StartPosition;

            m_AABB = m_AABB.Include(ref particlePosition);

            Life.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out particle.Life);
            float lifeVar = LifeVar;

            if (lifeVar > 0)
            {
                particle.Life = MathHelper.Max(MyUtils.GetRandomFloat(particle.Life - lifeVar, particle.Life + lifeVar), 0.1f);
            }

            Vector3 vel;

            Velocity.GetInterpolatedValue <Vector3>(m_effect.GetElapsedTime(), out vel);
            vel.X            *= m_effect.UserScale;
            vel.Y            *= m_effect.UserScale;
            vel.Z            *= m_effect.UserScale;
            particle.Velocity = vel;

            if (VelocityDir == MyVelocityDirEnum.FromEmitterCenter)
            {
                if (!MyUtils.IsZero(startOffset - particle.StartPosition))
                {
                    float length = particle.Velocity.Length();
                    particle.Velocity = MyUtils.Normalize(particle.StartPosition - (Vector3D)startOffset) * length;
                }
            }
            particle.Velocity = Vector3D.TransformNormal(particle.Velocity, GetEffect().WorldMatrix);

            Angle.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out particle.Angle);
            float angleVar = AngleVar;

            if (angleVar > 0)
            {
                particle.Angle = MyUtils.GetRandomFloat(particle.Angle - AngleVar, particle.Angle + AngleVar);
            }

            RotationSpeed.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out particle.RotationSpeed);
            float rotationSpeedVar = RotationSpeedVar;

            if (rotationSpeedVar > 0)
            {
                particle.RotationSpeed = MyUtils.GetRandomFloat(particle.RotationSpeed - RotationSpeedVar, particle.RotationSpeed + RotationSpeedVar);
            }

            float radiusVar;

            RadiusVar.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out radiusVar);
            float lodRadius = 1.0f;

            if (GetEffect().EnableLods)
            {
                LODRadius.GetInterpolatedValue <float>(GetEffect().Distance, out lodRadius);
            }

            Radius.GetInterpolatedKeys(m_effect.GetElapsedTime(),
                                       radiusVar,
                                       (EnableCustomRadius.GetValue <bool>() ? m_effect.UserRadiusMultiplier : 1.0f)
                                       * lodRadius
                                       * GetEffect().UserScale,
                                       particle.Radius);

            if (particle.Type != MyParticleTypeEnum.Point)
            {
                Thickness.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out particle.Thickness);
            }

            particle.Thickness *= lodRadius;

            float colorVar;

            ColorVar.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out colorVar);
            Color.GetInterpolatedKeys(m_effect.GetElapsedTime(), colorVar, 1.0f, particle.Color);
            ColorIntensity.GetInterpolatedValue <float>(m_effect.GetElapsedTime(), out particle.ColorIntensity);

            Material.GetInterpolatedKeys(m_effect.GetElapsedTime(), 0, 1.0f, particle.Material);

            particle.Flags  = 0;
            particle.Flags |= BlendTextures.GetValue <bool>() ? MyAnimatedParticle.ParticleFlags.BlendTextures : 0;

            if (PivotRotation.GetKeysCount() > 0 && PivotDistance.GetKeysCount() > 0)
            {
                particle.PivotDistance = new MyAnimatedPropertyFloat(PivotDistance.Name);
                particle.PivotRotation = new MyAnimatedPropertyVector3(PivotRotation.Name);
                PivotDistance.GetInterpolatedKeys(m_effect.GetElapsedTime(), PivotDistVar, 1.0f, particle.PivotDistance);
                PivotRotation.GetInterpolatedKeys(m_effect.GetElapsedTime(), 1.0f, particle.PivotRotation);
            }

            if (Acceleration.GetKeysCount() > 0)
            {
                particle.Acceleration = new MyAnimatedPropertyVector3(Acceleration.Name);
                float multiplier = MyUtils.GetRandomFloat(1 - AccelerationVar, 1 + AccelerationVar);
                Acceleration.GetInterpolatedKeys(m_effect.GetElapsedTime(), multiplier, particle.Acceleration);
            }

            if (AlphaCutout.GetKeysCount() > 0)
            {
                particle.AlphaCutout = new MyAnimatedPropertyFloat(AlphaCutout.Name);
                AlphaCutout.GetInterpolatedKeys(m_effect.GetElapsedTime(), 0, 1, particle.AlphaCutout);
            }

            particle.Start(this);

            m_particles.Add(particle);
        }
Beispiel #20
0
        void Update()
        {
            if (!snapEnabled) return;
            if (Selection.transforms.Length <= 0) return;
            Transform first = Selection.transforms[0];

            if (posBefore != first.position)
            {
                SnapToGrid(Selection.transforms);
                posBefore = first.position;
            }

            if (scaleBefore != first.localScale)
            {
                ScaleToGrid(Selection.transforms);
                scaleBefore = first.localScale;
            }

            if (Tools.current == Tool.Rotate)
            {
                if (!forceRotationMode)
                {
                    rotationModeBefore = Tools.pivotRotation;
                    Tools.pivotRotation = PivotRotation.Local;
                    forceRotationMode = true;
                }
            }
            else if (forceRotationMode)
            {
                forceRotationMode = false;
                Tools.pivotRotation = rotationModeBefore;
            }

            if (rotBefore != first.rotation)
            {
                RotateToAngle(Selection.transforms);
                rotBefore = first.rotation;
            }
        }
 static CallBackToolRotationEditor()
 {
     _pivotRotation            = Tools.pivotRotation;
     EditorApplication.update += CatchToolTipChange;
 }