Exemple #1
0
        void OnDeleteChannel(object index)
        {
            SplineMesh extruder = (SplineMesh)target;

            extruder.RemoveChannel((int)index);
            Repaint();
        }
Exemple #2
0
    private int MaxSegmentCount( )
    {
        int unusedVertices = 65000;

        SplineMesh splineMesh = target as SplineMesh;

        if (splineMesh.spline == null)
        {
            return(unusedVertices);
        }
        else if (splineMesh.baseMesh == null)
        {
            return(unusedVertices);
        }

        if (splineMesh.startBaseMesh != null && splineMesh.splineSegment <= 0)
        {
            unusedVertices -= splineMesh.startBaseMesh.vertexCount;
        }

        if (splineMesh.endBaseMesh != null && (splineMesh.splineSegment == -1 || splineMesh.splineSegment == splineMesh.spline.SegmentCount - 1))
        {
            unusedVertices -= splineMesh.endBaseMesh.vertexCount;
        }

        return((unusedVertices - (unusedVertices % splineMesh.baseMesh.vertexCount)) / splineMesh.baseMesh.vertexCount);
    }
Exemple #3
0
    private void ConvertJson(string info, int count)
    {
        GameObject baseObj = new GameObject();

        baseObj.name = "BaseSplines";
        Dictionary <string, object> table = MiniJSON.Json.Deserialize(info) as Dictionary <string, object>;
        //Object pathPref = Resources.Load("Prefabs/PathExample", typeof(GameObject));
        GameObject pathPref = EditorGUIUtility.Load("PathExample.prefab") as GameObject;

        foreach (string key in table.Keys)
        {
            GameObject pathObj = Instantiate(pathPref) as GameObject;
            pathObj.name             = key;
            pathObj.transform.parent = baseObj.transform;
            Spline        spline     = pathObj.GetComponent <Spline>();
            SplineMesh    splineMesh = pathObj.GetComponent <SplineMesh>();
            List <object> singlePath = table[key] as List <object>;
            foreach (object point in singlePath)
            {
                Dictionary <string, object> pathPoint = point as Dictionary <string, object>;
                float      x             = float.Parse(pathPoint["x"].ToString());
                float      y             = float.Parse(pathPoint["y"].ToString());
                GameObject newSplineNode = spline.AddSplineNode();
                newSplineNode.transform.position = new Vector3(x, y, 0);
                newSplineNode.transform.parent   = pathObj.transform;
                splineMesh.segmentCount         += 3;
            }
        }
    }
Exemple #4
0
        void OnMoveChannelDown(object index)
        {
            SplineMesh extruder = (SplineMesh)target;

            extruder.SwapChannels((int)index, ((int)index) + 1);
            Repaint();
        }
        protected override void Awake()
        {
            SplineMesh       = this.MakeSplineMesh(InterpolationSteps, Vector3.one * lineDiameter);
            LinearSplineMesh = new SplineMesh(new LinearInterpolationSpline(), Vector3.one * lineDiameter);

            setUpOriginalMaterialAndMeshRenderer();
        }
Exemple #6
0
        public void Awake()
        {
            gameObject.layer = Globals.LayerNumScenery;
            SplineNode1      = gameObject.CreateChild("Node1");
            SplineNode2      = gameObject.CreateChild("Node2");

            SplineNode sp1 = SplineNode1.gameObject.AddComponent <SplineNode>();
            SplineNode sp2 = SplineNode2.gameObject.AddComponent <SplineNode>();

            sp1.tension = 1f;
            sp1.normal  = Vector3.up;
            sp1.transform.localPosition = new Vector3(1f, 1f, 1f);

            sp2.tension = 1f;
            sp2.normal  = Vector3.up;
            sp2.transform.localPosition = new Vector3(-1f, -1f, -1f);

            spline            = gameObject.AddComponent <Spline>();
            spline.updateMode = Spline.UpdateMode.DontUpdate;

            PathMesh                     = gameObject.AddComponent <SplineMesh>();
            PathMesh.spline              = spline;
            PathMesh.startBaseMesh       = Meshes.Get.GroundPathPlane;
            PathMesh.baseMesh            = Meshes.Get.GroundPathPlane;
            PathMesh.endBaseMesh         = Meshes.Get.GroundPathPlane;
            PathRenderer                 = gameObject.AddComponent <MeshRenderer>();
            PathRenderer.sharedMaterials = new Material [] { Mats.Get.WorldPathGroundMaterial };
            PathRenderer.enabled         = false;

            spline.splineNodesArray.Add(sp1);
            spline.splineNodesArray.Add(sp2);
        }
Exemple #7
0
        void OnRenameChannel(object index)
        {
            SplineMesh extruder = (SplineMesh)target;

            renameChannel = extruder.GetChannel((int)index);
            Repaint();
        }
Exemple #8
0
        void OnDuplicateChannel(object index)
        {
            SplineMesh extruder = (SplineMesh)target;

            SplineMesh.Channel source     = extruder.GetChannel((int)index);
            SplineMesh.Channel newChannel = extruder.AddChannel(source.name);
            source.CopyTo(newChannel);
        }
	public override Vector3 ModifyVertex( SplineMesh splineMesh, Vector3 vertex, float splineParam )
	{
		//In order to avoid redundant calculations in ModifyNormal( ) and ModifyTangent( ), we store the
		//generated quaternion in a lokal variable.
		//This is possible, because ModifyVertex( ) is called before all other Modify**( )-functions.
		rotationQuaternion = Quaternion.Euler( Vector3.forward * (splineParam-twistOffset) * 360f * twistCount );
		
		return rotationQuaternion * vertex;
	}
    public override Vector3 ModifyVertex(SplineMesh splineMesh, Vector3 vertex, float splineParam)
    {
        //In order to avoid redundant calculations in ModifyNormal( ) and ModifyTangent( ), we store the
        //generated quaternion in a lokal variable.
        //This is possible, because ModifyVertex( ) is called before all other Modify**( )-functions.
        rotationQuaternion = Quaternion.Euler(Vector3.forward * (splineParam - twistOffset) * 360f * twistCount);

        return(rotationQuaternion * vertex);
    }
        private void OnEnable()
        {
            splineMesh       = target as SplineMesh;
            initializeStyles = true;

            if (MeshEditorState.IsAnyDebugModeViewVisible() && !MeshEditorState.IsDebugModeView(splineMesh))
            {
                MeshEditorState.RestoreSavedDebugMaterial();
            }
        }
Exemple #12
0
    // Start is called before the first frame update
    void Start()
    {
        meshFilter   = GetComponent <MeshFilter>();
        meshCollider = GetComponent <MeshCollider>();

        SplineMesh       = new SplineMesh(new KochanekBartelsSpline(), meshFilter);
        LinearSplineMesh = new SplineMesh(new LinearInterpolationSpline(), meshFilter);

        meshCollider.sharedMesh = meshFilter.sharedMesh;
    }
Exemple #13
0
        protected override void onExit(TBTWorkingData wData, int runningStatus)
        {
            base.onExit(wData, runningStatus);
            SceneEffectManager.Instance.DestroySceneEffect(ref param);
            GameObject splineMeshGO = m_SplineMesh.gameObject;

            ResNode.DestroyRes(ref splineMeshGO);
            m_MainHeroTrans = null;
            m_SplineMesh    = null;
            m_Prefab        = null;
        }
        protected override void Awake()
        {
            meshFilter   = GetComponent <MeshFilter>();
            meshCollider = GetComponent <MeshCollider>();

            SplineMesh       = this.MakeSplineMesh(InterpolationSteps, Vector3.one * lineDiameter);
            LinearSplineMesh = new SplineMesh(new LinearInterpolationSpline(), Vector3.one * lineDiameter);

            meshCollider.sharedMesh = meshFilter.sharedMesh;
            setUpOriginalMaterialAndMeshRenderer();
        }
Exemple #15
0
    static public void CreateSplineGameobject()
    {
        GameObject go     = new GameObject("SplineObject");
        Transform  _trans = go.transform;

        _trans.localPosition = Vector3.zero;
        _trans.localRotation = Quaternion.identity;

        Spline sp = go.AddComponent <Spline>();

        sp.interpolationMode = Spline.InterpolationMode.Hermite;
        sp.rotationMode      = Spline.RotationMode.Tangent;
        sp.tangentMode       = Spline.TangentMode.UseNodeForwardVector;
        sp.perNodeTension    = false;
        sp.tension           = 3.0f;
        sp.updateMode        = Spline.UpdateMode.DontUpdate;


        List <SplineNode> nodeList = new List <SplineNode>();

        for (int i = 0; i < 7; ++i)
        {
            GameObject node = new GameObject();
            node.transform.parent        = _trans;
            node.transform.localRotation = Quaternion.identity;
            node.name = i.ToString("D4");

            SplineNode spn = node.AddComponent <SplineNode>();

            nodeList.Add(spn);
        }

        for (int index = 0; index < nodeList.Count; ++index)
        {
            nodeList[index].transform.localPosition = new Vector3(0, 0, index * 2);
        }

        sp.splineNodesArray = nodeList;


        SplineMesh sm = go.AddComponent <SplineMesh>();

        sm.spline       = sp;
        sm.updateMode   = SplineMesh.UpdateMode.WhenSplineChanged;
        sm.uvMode       = SplineMesh.UVMode.InterpolateV;
        sm.uvScale      = Vector2.one;
        sm.xyScale      = Vector2.one;
        sm.segmentCount = 100;
        sm.splitMode    = SplineMesh.SplitMode.DontSplit;

        MeshRenderer mr = go.AddComponent <MeshRenderer>();
    }
Exemple #16
0
    public void ApplyChangesToTarget(Object targetObject)
    {
        Spline spline = targetObject as Spline;

        spline.UpdateSpline( );

        SplineMesh splineMesh = spline.GetComponent <SplineMesh>( );

        if (splineMesh != null)
        {
            splineMesh.UpdateMesh( );
        }
    }
        public void SplineMesh_AddControlPoint_Performance([NUnit.Framework.Range(9, 99, 10)] int length)
        {
            SplineMesh splineMesh = null;

            Measure.Method(() =>
            {
                splineMesh.AddControlPoint(new Vector3(length + 1, 0, 0));
            })
            .SetUp(() => {
                splineMesh = new SplineMesh(new KochanekBartelsSpline());
                splineMesh.SetControlPoints(GenerateControlPoints(length).ToArray());
            })
            .Run();
        }
    // Start is called before the first frame update
    void Start()
    {
        ControlPoints = new Vector3[ControlPointObjects.Length];
        for (int i = 0; i < ControlPointObjects.Length; i++)
        {
            ControlPoints[i] = ControlPointObjects[i].transform.position;
        }

        SplineMesh = new SplineMesh(new KochanekBartelsSpline());
        GetComponent <MeshFilter>().mesh = SplineMesh.SetControlPoints(ControlPoints);
        //SplineMesh.deleteControlPoint(9);
        //SplineMesh.addControlPoint(extraControlPoint.transform.position);
        //SplineMesh.insertControlPoint(1, extraControlPoint.transform.position);
    }
        /// <summary>
        /// Set the number of interpolation steps between two control points.
        /// A higher number makes the line smoother.
        /// </summary>
        /// <param name="steps"></param>
        public virtual void SetInterpolationSteps(int steps)
        {
            this.InterpolationSteps = steps;
            List <Vector3> controlPoints = this.GetControlPoints();

            this.SplineMesh.GetCrossSectionShape(out List <Vector3> CurrentCrossSectionShape, out List <Vector3> CurrentCrossSectionNormals);
            //SplineMesh = new SplineMesh(new KochanekBartelsSpline(steps), this.lineDiameter * Vector3.one);
            SplineMesh = this.MakeSplineMesh(steps, this.lineDiameter * Vector3.one);
            this.SetLineCrossSection(CurrentCrossSectionShape, CurrentCrossSectionNormals, this.lineDiameter);
            if (controlPoints.Count != 0)
            {
                this.SetControlPointsLocalSpace(controlPoints);
            }
        }
Exemple #20
0
 internal void Init(SplineMesh e, SplineMesh.Channel.MeshDefinition d)
 {
     minSize    = new Vector2(482, 180);
     extrude    = e;
     definition = d;
     if (definition.mesh != null)
     {
         titleContent = new GUIContent("Configure " + definition.mesh.name);
     }
     else
     {
         titleContent = new GUIContent("Configure Mesh");
     }
 }
 private void StartJob(GenerateMeshJob generateMeshJob, SplineMesh splineMesh, Mesh mesh, Action <Mesh> onMeshGenerated, bool immediate)
 {
     if (immediate)
     {
         generateMeshJob.ScheduleAndComplete(generateMeshJob.Positions.Length, JobBatchSize,
                                             (generateMeshJob) =>
         {
             OnJobCompleted(ref generateMeshJob, mesh);
             onMeshGenerated?.Invoke(mesh);
             isJobScheduled = false;
         });
     }
     else
     {
         StartJobCoroutine(generateMeshJob, splineMesh, mesh, onMeshGenerated);
     }
 }
    private void StartJobCoroutine(GenerateMeshJob generateMeshJob, SplineMesh splineMesh, Mesh mesh, Action <Mesh> onMeshGenerated)
    {
        generateMeshCoroutine = generateMeshJob.ScheduleAndCompleteAsync(generateMeshJob.Positions.Length, JobBatchSize, splineMesh,
                                                                         (jobHandle) =>
        {
            ongoingJobHandle = jobHandle;
        },
                                                                         (generateMeshJob) =>
        {
            OnJobCompleted(ref generateMeshJob, mesh);
            onMeshGenerated?.Invoke(mesh);
            isJobScheduled = false;

            if (scheduleNextJob)
            {
                splineMesh.GenerateMesh();
            }
        });
    }
Exemple #23
0
    public void CreateLegs()
    {
        leftLegSpline = new SplineMesh(6, CharacterSettings.LegResolution)
        {
            Thickness        = CharacterSettings.LegThickness,
            ThicknessCurve   = CharacterSettings.LegThicknessCurve,
            ResolutionSpread = CharacterSettings.ResolutionSpread,
            Material         = CharacterSettings.MainMaterial,
            Parent           = transform
        };

        rightLegSpline = new SplineMesh(6, CharacterSettings.LegResolution)
        {
            Thickness        = CharacterSettings.LegThickness,
            ThicknessCurve   = CharacterSettings.LegThicknessCurve,
            ResolutionSpread = CharacterSettings.ResolutionSpread,
            Material         = CharacterSettings.MainMaterial,
            Parent           = transform
        };
        drawables.Add(leftLegSpline);
        drawables.Add(rightLegSpline);
    }
Exemple #24
0
    private void CreateArms()
    {
        leftArmSpline = new SplineMesh(6, CharacterSettings.ArmResolution)
        {
            Thickness        = CharacterSettings.ArmThickness,
            ThicknessCurve   = CharacterSettings.ArmThicknessCurve,
            ResolutionSpread = CharacterSettings.ResolutionSpread,
            Material         = CharacterSettings.MainMaterial,
            Parent           = transform
        };

        rightArmSpline = new SplineMesh(6, CharacterSettings.ArmResolution)
        {
            Thickness        = CharacterSettings.ArmThickness,
            ThicknessCurve   = CharacterSettings.ArmThicknessCurve,
            ResolutionSpread = CharacterSettings.ResolutionSpread,
            Material         = CharacterSettings.MainMaterial,
            Parent           = transform
        };
        drawables.Add(leftArmSpline);
        drawables.Add(rightArmSpline);
    }
Exemple #25
0
    private void DrawMeshTools( )
    {
        EditorGUILayout.BeginHorizontal( );

        GUILayout.Space(15);

        SplineMesh sMesh = target as SplineMesh;

        if (GUILayout.Button("Export Mesh", GetLeftButtonGUIStyle( ), GUILayout.Height(23f)))
        {
            string filePath = EditorUtility.SaveFilePanelInProject("Export Spline Mesh", "Spline Mesh (" + target.name + ")", "asset", "");

            if (filePath.Trim( ) != "")
            {
                Mesh mesh = new Mesh( );

                mesh.vertices = sMesh.BentMesh.vertices;
                mesh.normals  = sMesh.BentMesh.normals;
                mesh.tangents = sMesh.BentMesh.tangents;
                mesh.uv       = sMesh.BentMesh.uv;

                mesh.triangles = sMesh.BentMesh.triangles;

                AssetDatabase.CreateAsset(mesh, filePath);
                AssetDatabase.SaveAssets( );

                mesh.hideFlags = HideFlags.HideAndDontSave;
            }
        }

        if (GUILayout.Button("View Mesh", GetRightButtonGUIStyle( ), GUILayout.Height(23f)))
        {
            Selection.activeObject = sMesh.BentMesh;
        }

        EditorGUILayout.EndHorizontal( );
    }
Exemple #26
0
        public void InitSplineMesh()
        {
            if (m_SplineMesh != null)
            {
                return;
            }

            param = new SceneEffectParamBase((int)ESceneEffectID.SE_Guide_PathMesh, null, _bAutoPlay: false);
            SceneEffectManager.Instance.CreateSceneEffect(ref param);
            param.ReturnComponent.transform.position = new Vector3(999, 999, 999);
            m_Prefab = param.ReturnComponent.gameObject;


            GameObject pathGO = new GameObject("PathMesh");

            m_SplineMesh = pathGO.AddComponent <SplineMesh>();
            m_SplineMesh.IsAutoUpdateMesh  = false;
            m_SplineMesh.MeshDistanceDelta = 4f;
            m_SplineMesh.MeshPrefab        = m_Prefab;

            m_SplineMesh.transform.position = m_MainHeroTrans != null ? m_MainHeroTrans.position : Vector3.zero;

            m_SplineMesh.gameObject.SetActive(false);
        }
Exemple #27
0
    public static void drawStreetNetwork()
    {
        polygons = new List <Vector3[]>();

        bool linearOption = true;

        int laneCounter        = 0;
        int streetLightCounter = 0;


        // (1) Draw all Edges ------------------------------------
        MonoBehaviour.print("Inserting 3d Streets");

        foreach (NetFileEdge e in edges.Values)
        {
            int        edgeCounter = 0;
            GameObject spline      = new GameObject("StreetSegment_" + laneCounter++);
            spline.transform.SetParent(network.transform);

            Spline splineObject = spline.AddComponent <Spline>();

            if (linearOption)
            {
                splineObject.interpolationMode = Spline.InterpolationMode.Linear;
            }
            else
            {
                splineObject.interpolationMode = Spline.InterpolationMode.BSpline;
            }

            foreach (NetFileLane l in e.getLanes())
            {
                foreach (double[] coordPair in l.shape)
                {
                    // Add Node
                    GameObject splineNode = new GameObject("Node_" + edgeCounter++);
                    splineNode.transform.SetParent(spline.transform);
                    SplineNode splineNodeObject = splineNode.AddComponent <SplineNode>();
                    splineNode.transform.position = new Vector3((float)coordPair[0] - xmin, 0, (float)coordPair[1] - ymin);
                    splineObject.splineNodesArray.Add(splineNodeObject);
                }

                // Add meshes
                Material     material  = AssetDatabase.LoadAssetAtPath <Material>(PathConstants.pathRoadMaterial);
                MeshRenderer mRenderer = mRenderer = spline.GetComponent <MeshRenderer>();
                if (mRenderer == null)
                {
                    mRenderer = spline.AddComponent <MeshRenderer>();
                }
                mRenderer.material = material;


                SplineMesh sMesh = spline.AddComponent <SplineMesh>();
                sMesh.spline        = splineObject;
                sMesh.baseMesh      = AssetDatabase.LoadAssetAtPath <Mesh>(PathConstants.pathSuperSplinesBox);
                sMesh.startBaseMesh = AssetDatabase.LoadAssetAtPath <Mesh>(PathConstants.pathSuperSplinesBox);
                sMesh.endBaseMesh   = AssetDatabase.LoadAssetAtPath <Mesh>(PathConstants.pathSuperSplinesBox);
                sMesh.uvScale       = new Vector2(uvScaleU, uvScaleV);
                sMesh.xyScale       = new Vector2(meshScaleX, 0);


                // (1.1) Add Lanes to polygon list for tree placement check
                for (int i = 0; i < l.shape.Count - 1; i++)
                {
                    double length = Math.Sqrt(Math.Pow(l.shape[i][0] - xmin - (l.shape[i + 1][0] - xmin), 2) + Math.Pow(l.shape[i][1] - ymin - (l.shape[i + 1][1] - ymin), 2));
                    // Calc the position (in line with the lane)
                    float  x1 = (float)l.shape[i][0] - xmin;
                    float  y1 = (float)l.shape[i][1] - ymin;
                    float  x2 = (float)l.shape[i + 1][0] - xmin;
                    float  y2 = (float)l.shape[i + 1][1] - ymin;
                    double Dx = x2 - x1;
                    double Dy = y2 - y1;
                    double D  = Math.Sqrt(Dx * Dx + Dy * Dy);
                    double W  = 10;
                    Dx = 0.5 * W * Dx / D;
                    Dy = 0.5 * W * Dy / D;
                    Vector3[] polygon = new Vector3[] { new Vector3((float)(x1 - Dy), 0, (float)(y1 + Dx)),
                                                        new Vector3((float)(x1 + Dy), 0, (float)(y1 - Dx)),
                                                        new Vector3((float)(x2 + Dy), 0, (float)(y2 - Dx)),
                                                        new Vector3((float)(x2 - Dy), 0, (float)(y2 + Dx)) };
                    polygons.Add(polygon);


                    // (2) Add Street Lamps (only if long enough)
                    if (length >= minLengthForStreetLamp)
                    {
                        float angle = Mathf.Atan2(y2 - y1, x2 - x1) * 180 / Mathf.PI;

                        // Allway located at the middle of a street
                        double ratioRotPoint = 0.5;
                        double ratio         = 0.5 + streeLampDistance / length;

                        float xDest = (float)((1 - ratio) * x1 + ratio * x2);
                        float yDest = (float)((1 - ratio) * y1 + ratio * y2);

                        float xRotDest = (float)((1 - ratioRotPoint) * x1 + ratioRotPoint * x2);
                        float yRotDest = (float)((1 - ratioRotPoint) * y1 + ratioRotPoint * y2);

                        GameObject streetLampPrefab = AssetDatabase.LoadMainAssetAtPath(PathConstants.pathLaterne) as GameObject;
                        GameObject streetLamp       = GameObject.Instantiate(streetLampPrefab, new Vector3(xDest, 0, yDest), Quaternion.Euler(new Vector3(0, 0, 0)));
                        streetLamp.name = "StreetLight_" + streetLightCounter++;
                        streetLamp.transform.SetParent(network.transform);
                        streetLamp.transform.RotateAround(new Vector3(xRotDest, 0, yRotDest), Vector3.up, -90.0f);
                        streetLamp.transform.Rotate(Vector3.up, -angle);
                    }
                }
            }
        }

        // (3) Draw all Junction areas ------------------------------------
        MonoBehaviour.print("Inserting 3d Junctions");

        int junctionCounter = 0;

        foreach (NetFileJunction j in junctions.Values)
        {
            List <int> indices = new List <int>();

            Vector2[] vertices2D = new Vector2[j.shape.Count];
            for (int i = 0; i < j.shape.Count; i++)
            {
                vertices2D[i] = new Vector3((float)(j.shape[i])[0] - xmin, (float)(j.shape[i])[1] - ymin);
            }

            // Use the triangulator to get indices for creating triangles
            Triangulator tr            = new Triangulator(vertices2D);
            List <int>   bottomIndices = new List <int>(tr.Triangulate());
            indices.AddRange(bottomIndices);


            // Create the Vector3 vertices
            Vector3[] vertices = new Vector3[vertices2D.Length];
            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i] = new Vector3(vertices2D[i].x, 0, vertices2D[i].y);
            }

            Mesh mesh = new Mesh();
            mesh.Clear();
            mesh.vertices  = vertices;
            mesh.triangles = indices.ToArray();
            mesh.RecalculateNormals();
            mesh.RecalculateBounds();

            Bounds    bounds = mesh.bounds;
            Vector2[] uvs    = new Vector2[vertices.Length];
            for (int i = 0; i < vertices.Length; i++)
            {
                uvs[i] = new Vector2(vertices[i].x / bounds.size.x, vertices[i].z / bounds.size.z);
            }
            mesh.uv = uvs;
            mesh.RecalculateNormals();
            mesh.RecalculateBounds();

            // Set up game object with mesh;
            GameObject   junction3D = new GameObject("junction_" + junctionCounter++);
            MeshRenderer r          = (MeshRenderer)junction3D.AddComponent(typeof(MeshRenderer));
            Material     material   = Resources.Load <Material>(PathConstants.pathJunctionMaterial);
            r.material = material;
            MeshFilter filter = junction3D.AddComponent(typeof(MeshFilter)) as MeshFilter;
            filter.mesh = mesh;
            junction3D.transform.SetParent(network.transform);

            // (3.1) Add junctions to polygon list for tree placement check
            polygons.Add(vertices);
        }

        // (4) Draw Traffic Lights
        MonoBehaviour.print("Inserting 3d Traffic Lights");

        foreach (NetFileJunction j in junctions.Values)
        {
            if (j.type == junctionTypeType.traffic_light)
            {
                int index = 0;
                foreach (NetFileLane l in j.incLanes)
                {
                    // Calc the position (in line with the lane)
                    float x1     = (float)l.shape[0][0] - xmin;
                    float y1     = (float)l.shape[0][1] - ymin;
                    float x2     = (float)l.shape[1][0] - xmin;
                    float y2     = (float)l.shape[1][1] - ymin;
                    float length = (float)Math.Sqrt(Math.Pow(y2 - y1, 2) + Math.Pow(x2 - x1, 2));
                    float angle  = Mathf.Atan2(y2 - y1, x2 - x1) * 180 / Mathf.PI;

                    double ratio = (length - trafficLightDistance) / length;

                    float xDest = (float)((1 - ratio) * x1 + ratio * x2);
                    float yDest = (float)((1 - ratio) * y1 + ratio * y2);

                    // Insert the 3d object, rotate from lane 90° to the right side and then orientate the traffic light towards the vehicles
                    GameObject trafficLightPrefab = AssetDatabase.LoadMainAssetAtPath(PathConstants.pathTrafficLight) as GameObject;
                    GameObject trafficLight       = GameObject.Instantiate(trafficLightPrefab, new Vector3(xDest, 0, yDest), Quaternion.Euler(new Vector3(0, 0, 0)));
                    trafficLight.name = "TrafficLight_" + j.id;
                    trafficLight.transform.SetParent(network.transform);
                    trafficLight.transform.RotateAround(new Vector3(x2, 0, y2), Vector3.up, -90.0f);
                    trafficLight.transform.Rotate(Vector3.up, -angle);

                    // Insert traffic light index as empty GameObject into traffic light
                    GameObject TLindex    = new GameObject("index");
                    GameObject TLindexVal = new GameObject(Convert.ToString(index++));
                    TLindexVal.transform.SetParent(TLindex.transform);
                    TLindex.transform.SetParent(trafficLight.transform);
                }
            }
        }
    }
 public override Vector4 ModifyTangent(SplineMesh splineMesh, Vector4 tangent, float splineParam)
 {
     return(tangent);
 }
 public override Vector3 ModifyNormal(SplineMesh splineMesh, Vector3 normal, float splineParam)
 {
     return(normal);
 }
 public override Vector2 ModifyUV(SplineMesh splineMesh, Vector2 uvCoord, float splineParam)
 {
     return(uvCoord);
 }
	public AnimationCurve scaleCurve;		///< The AnimationCurve representing the scale of the mesh
	
	public override Vector3 ModifyVertex( SplineMesh splineMesh, Vector3 vertex, float splineParam )
	{
		return vertex * scaleCurve.Evaluate( splineParam );
	}
	public override Vector2 ModifyUV( SplineMesh splineMesh, Vector2 uvCoord, float splineParam )
	{
		return uvCoord;
	}
	public override Vector3 ModifyNormal( SplineMesh splineMesh, Vector3 normal, float splineParam )
	{
		return rotationQuaternion * normal;
		//return Quaternion.Euler( Vector3.forward * (splineParam-twistOffset) * 360f * twistCount ) * normal;
	}
	public override Vector3 ModifyNormal( SplineMesh splineMesh, Vector3 normal, float splineParam )
	{
		return normal;
	}
	//use the override keyword to implement the abstract methods of the SplineMeshModifier-class
	public override Vector3 ModifyVertex( SplineMesh splineMesh, Vector3 vertex, float splineParam )
	{
		return vertex;
	}
	/// <summary>
	/// Modifies the UV coordinates of a vertex.
	/// </summary>
	/// <returns>
	/// The modified UV coordinates of a vertex.
	/// </returns>
	/// <param name='splineMesh'>
	/// The SplineMesh-class that called this function.
	/// </param>
	/// <param name='uvCoord'>
	/// The UV coordinates of a vertex.
	/// </param>
	/// <param name='splineParam'>
	/// The current spline parameter.
	/// </param>
	public abstract Vector2 ModifyUV( SplineMesh splineMesh, Vector2 uvCoord, float splineParam );
	/// <summary>
	/// Modifies the vertex position.
	/// </summary>
	/// <returns>
	/// The modified  vertex position.
	/// </returns>
	/// <param name='splineMesh'>
	/// The SplineMesh-class that called this function.
	/// </param>
	/// <param name='vertex'>
	/// The vertex position.
	/// </param>
	/// <param name='splineParam'>
	/// The current spline parameter.
	/// </param>
	public abstract Vector3 ModifyVertex( SplineMesh splineMesh, Vector3 vertex, float splineParam );
	/// <summary>
	/// Modifies the vertex tangent.
	/// </summary>
	/// <returns>
	/// The modified tangent.
	/// </returns>
	/// <param name='splineMesh'>
	/// The SplineMesh-class that called this function.
	/// </param>
	/// <param name='tangent'>
	/// The vertex Tangent.
	/// </param>
	/// <param name='splineParam'>
	/// The current spline parameter.
	/// </param>
	public abstract Vector4 ModifyTangent( SplineMesh splineMesh, Vector4 tangent, float splineParam );
	/// <summary>
	/// Modifies the vertex normal.
	/// </summary>
	/// <returns>
	/// The modified normal.
	/// </returns>
	/// <param name='splineMesh'>
	/// The SplineMesh-class that called this function.
	/// </param>
	/// <param name='normal'>
	/// The vertex normal.
	/// </param>
	/// <param name='splineParam'>
	/// The current spline parameter.
	/// </param>
	public abstract Vector3 ModifyNormal( SplineMesh splineMesh, Vector3 normal, float splineParam );
	public override Vector4 ModifyTangent( SplineMesh splineMesh, Vector4 tangent, float splineParam )
	{
		return tangent;
	}
	public override Vector4 ModifyTangent( SplineMesh splineMesh, Vector4 tangent, float splineParam )
	{
		return rotationQuaternion * tangent;
		//return Quaternion.Euler( Vector3.forward * (splineParam-twistOffset) * 360f * twistCount ) * tangent;
	}
    public override void OnInspectorGUI( )
    {
        SplineMesh mesh = (SplineMesh)target;

        EditorGUILayout.BeginVertical( );

        EditorGUILayout.Space( );
        spline   = (Spline)EditorGUILayout.ObjectField("   Spline", mesh.spline, typeof(Spline), true);
        baseMesh = (Mesh)EditorGUILayout.ObjectField("   Base Mesh", mesh.baseMesh, typeof(Mesh), false);
        int materialCount = (int)EditorGUILayout.IntField("   Materials Count", mesh.materials.Length);

        if (materials == null || materialCount != materials.Length)
        {
            materials = new Material[materialCount];
        }
        for (int q = 0; q < materialCount; ++q)
        {
            materials[q] = (q < mesh.materials.Length)? mesh.materials[q]: null;
            materials[q] = (Material)EditorGUILayout.ObjectField("   Material " + q, materials[q], typeof(Material), false);
        }
        EditorGUILayout.Space();

        uMode = (Spline.UpdateMode)EditorGUILayout.EnumPopup("   Update Mode", mesh.uMode);

        if (uMode == Spline.UpdateMode.EveryXFrames)
        {
            deltaFrames = EditorGUILayout.IntField("   Delta Frames", mesh.deltaFrames);
        }
        else if (uMode == Spline.UpdateMode.EveryXSeconds)
        {
            deltaSeconds = EditorGUILayout.FloatField("   Delta Seconds", mesh.deltaSeconds);
        }

        uvWrapAt = EditorGUILayout.FloatField("   UV Wrap", mesh.uvWrapAt);

        segmentCount = Mathf.Max(EditorGUILayout.IntField("   Segment Count", mesh.segmentCount), 1);

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel("   Offset");
        xyOffset.x = EditorGUILayout.FloatField(mesh.xyOffset.x, GUILayout.MinWidth(10));
        xyOffset.y = EditorGUILayout.FloatField(mesh.xyOffset.y, GUILayout.MinWidth(10));
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal( );
        EditorGUILayout.PrefixLabel("   Scale");
        xyScale.x = EditorGUILayout.FloatField(mesh.xyScale.x, GUILayout.MinWidth(10));
        xyScale.y = EditorGUILayout.FloatField(mesh.xyScale.y, GUILayout.MinWidth(10));
        EditorGUILayout.EndHorizontal( );

        EditorGUILayout.BeginHorizontal( );
        EditorGUILayout.PrefixLabel("   UV-Scale");
        uvScale.x = EditorGUILayout.FloatField(mesh.uvScale.x, GUILayout.MinWidth(10));
        uvScale.y = EditorGUILayout.FloatField(mesh.uvScale.y, GUILayout.MinWidth(10));
        EditorGUILayout.EndHorizontal( );

        swapUV    = EditorGUILayout.Toggle("   Swap UV", mesh.swapUV);
        splitMesh = EditorGUILayout.Toggle("   Split Mesh", mesh.splitMesh);



        EditorGUILayout.Space();

        // lightprobes
        lightProbeSegmentCount = Mathf.Max(EditorGUILayout.IntField("   Light Volume Count", mesh.lightProbeSegmentCount), 0);

        EditorGUILayout.BeginHorizontal( );
        EditorGUILayout.PrefixLabel("   Light Volume Extrude");
        lightProbeExtrude.x = EditorGUILayout.FloatField(mesh.lightProbeExtrude.x, GUILayout.MinWidth(10));
        lightProbeExtrude.y = EditorGUILayout.FloatField(mesh.lightProbeExtrude.y, GUILayout.MinWidth(10));
        EditorGUILayout.EndHorizontal( );

        lightProbeHeight = EditorGUILayout.FloatField("   Light Volume Height", mesh.lightProbeHeight);

        EditorGUILayout.Space();

        persistent = EditorGUILayout.Toggle("   Persistent Mesh", mesh.persistent);
        if (persistent)
        {
            uMode = Spline.UpdateMode.DontUpdate;
        }

        EditorGUILayout.Space();


        EditorGUILayout.EndVertical( );

        bool rebuild = GUILayout.Button("Rebuild");

        if (GUI.changed)
        {
            Undo.RegisterUndo(target, "Change Spline Mesh Settings");
            EditorUtility.SetDirty(target);
        }

        if (GUI.changed || rebuild)
        {
            if (baseMesh == null)
            {
                Debug.LogWarning("There is no base mesh assigned to your spline mesh! Check the inspector to assign it!", mesh.gameObject);
            }

            mesh.uMode                  = uMode;
            mesh.spline                 = spline;
            mesh.swapUV                 = swapUV;
            mesh.uvWrapAt               = uvWrapAt;
            mesh.xyOffset               = xyOffset;
            mesh.xyScale                = xyScale;
            mesh.uvScale                = uvScale;
            mesh.baseMesh               = baseMesh;
            mesh.materials              = materials;
            mesh.deltaFrames            = deltaFrames;
            mesh.deltaSeconds           = deltaSeconds;
            mesh.segmentCount           = segmentCount;
            mesh.lightProbeSegmentCount = lightProbeSegmentCount;
            mesh.lightProbeExtrude      = lightProbeExtrude;
            mesh.lightProbeHeight       = lightProbeHeight;
            mesh.persistent             = persistent;
            mesh.splitMesh              = splitMesh;


            if (mesh.persistent)
            {
                foreach (var m in mesh.BentMeshes)
                {
                    AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(m));
                }
            }

            mesh.UpdateMesh();

            if (mesh.persistent)
            {
                foreach (var m in mesh.BentMeshes)
                {
                    var assetPath = AssetHelper.GetPathForGeneratedAsset(m, mesh.gameObject);

                    Debug.Log("PATH: " + assetPath);
                    AssetDatabase.CreateAsset(m, assetPath);
                    AssetDatabase.SaveAssets();
                }
            }
        }
    }
	public float sinOffset = .25f;			///< Y offset of the sine function
	
	public override Vector3 ModifyVertex( SplineMesh splineMesh, Vector3 vertex, float splineParam )
	{
		return vertex * (Mathf.Pow( Mathf.Sin( splineParam * frequency + offset ), 2 ) * sinMultiplicator + sinOffset);
	}