Пример #1
0
        public static int Redraw(this RageSpline rageSpline, bool triangulate, bool calculateNormals, bool calculatePhysics, int startNormals, float percentNormals)
        {
            rageSpline.SetVertexCount(rageSpline.GetVertexCount());

            if (Mathf.Abs(rageSpline.gameObject.transform.localScale.x) <= 0f ||
                Mathf.Abs(rageSpline.gameObject.transform.localScale.y) <= 0f)
            {
                return(startNormals);
            }

            int points = rageSpline.GetVertexCount() + 1;
            int end    = (int)(points * percentNormals);

            if (end > points)
            {
                end = points;
            }

            if (calculateNormals)
            {
                ProgressivePrecalcNormals(rageSpline, startNormals, end);
            }

            GenerateMesh(rageSpline, triangulate);

            if (calculatePhysics)
            {
                rageSpline.RefreshPhysics();
            }

            return(end >= points ? 0 : end);
        }
Пример #2
0
        public static void ProgressivePrecalcNormals(RageSpline rageSpline, int start, int end)
        {
            int points = rageSpline.GetVertexCount() + 1;

            if (rageSpline.spline.precalcNormals == null ||
                rageSpline.spline.precalcNormals.Length != points)
            {
                rageSpline.spline.precalcNormals = new Vector3[points];
            }

            Vector3 up = new Vector3(0f, 0f, -1f);

            for (int i = start; i < end; i++)
            {
                rageSpline.spline.precalcNormals[i] = CalculateNormal(rageSpline, i / (float)(points - 1), up);
            }
        }
Пример #3
0
    public static void UpdateFarseerPhysics(RageSpline spline)
    {
#if !UNITY_FLASH
        var fsConcave = spline.GetComponent <FSConcaveShapeComponent>();
        if (fsConcave == null)
        {
            fsConcave = spline.gameObject.AddComponent <FSConcaveShapeComponent>();
        }
        var fsBody = spline.GetComponent <FSBodyComponent>();
        if (fsBody == null)
        {
            spline.gameObject.AddComponent <FSBodyComponent>();
        }
        fsConcave.PointInput = FSShapePointInput.Vector2List;
        var points = new List <Vector2>();
        if (spline.FarseerPhysicsPointsOnly)
        {
            for (int i = 0; i < spline.GetPointCount(); i++)
            {
                points.Add(spline.GetPosition(i));
            }
        }
        else
        {
            int splitCount = spline.LockPhysicsToAppearence ? spline.GetVertexCount() : spline.GetPhysicsColliderCount();
            for (int i = 0; i < splitCount; i++)
            {
                float   splinePos = (float)i / (float)splitCount;
                Vector3 normal    = spline.GetNormal(splinePos);
                points.Add(spline.GetPosition(splinePos) + normal * spline.GetPhysicsNormalOffset());
            }
        }
        fsConcave.PointsCoordinates = points.ToArray();
        fsConcave.ConvertToConvex();
#endif
    }
Пример #4
0
    private void GeneralSettings(RageSpline rageSpline)
    {
        EditorGUIUtility.LookLikeControls(170f, 10f);
        GuiExtensions.Vertical (GUI.skin.box, ( ) => {
            GuiExtensions.Horizontal (( ) => EditorGUILayout.LabelField ("   General:", ""));
            var vDensity = EditorGUILayout.IntField("      Vertex density", rageSpline.VertexDensity);
            if (_currentVertexDensity != vDensity) {
                _currentVertexDensity = vDensity;
                rageSpline.VertexDensity = vDensity;
            }

            var vCount = EditorGUILayout.IntField ("      Vertex count", !rageSpline.lowQualityRender
                                                                        ? rageSpline.GetVertexCount()
                                                                        : rageSpline.vertexCount);
            if (vCount != _currentVertexCount) {
                _currentVertexCount = vCount;
                rageSpline.SetVertexCount(vCount);
            }
            rageSpline.SetAntialiasingWidth (EditorGUILayout.FloatField ("      Anti-aliasing width", rageSpline.GetAntialiasingWidth()));
            rageSpline.SetOptimize (EditorGUILayout.Toggle ("      Optimize", rageSpline.GetOptimize()));
            if (rageSpline.GetOptimize())
                rageSpline.SetOptimizeAngle(EditorGUILayout.FloatField("      Optimize Angle", rageSpline.GetOptimizeAngle()));
            rageSpline.PerspectiveMode = EditorGUILayout.Toggle("      3D Mode", rageSpline.PerspectiveMode);
            if (rageSpline.CurrentPerspective != rageSpline.PerspectiveMode) {
                rageSpline.SwitchPerspectiveMode();
                EditorUtility.SetDirty(target);
                rageSpline.CurrentPerspective = rageSpline.PerspectiveMode;
                rageSpline.RefreshMeshInEditor(true,true,true);
            }

            displayOptions = EditorGUILayout.Foldout(displayOptions, "    Display Options");
            if (displayOptions) {
                rageSpline.showSplineGizmos = EditorGUILayout.Toggle("          Show spline gizmos", rageSpline.showSplineGizmos);
                rageSpline.showOtherGizmos = EditorGUILayout.Toggle("          Show other gizmos", rageSpline.showOtherGizmos);
                rageSpline.showWireFrameInEditor = EditorGUILayout.Toggle("          Show wireframe", rageSpline.showWireFrameInEditor);
                rageSpline.hideHandles = !(EditorGUILayout.Toggle("          Show handles", !rageSpline.hideHandles));
                rageSpline.ShowTriangleCount = EditorGUILayout.Toggle("          Show tri count", rageSpline.ShowTriangleCount);
                if (rageSpline.ShowTriangleCount)
                    EditorGUILayout.FloatField("      Triangle Count", rageSpline.GetTriangleCount());
            }
        });
        EditorGUILayout.Separator();
    }