BridgeMesh m_BridgeMesh;      // TODO: Move to bridge visualizer

        public BridgeManager()
        {
            m_FirstBridgePoint  = RawBridgePoint.INVALID;
            m_SecondBridgePoint = RawBridgePoint.INVALID;

            m_Bridge     = Bridge.INVALID;
            m_BridgeMesh = BridgeMesh.INVALID;
        }
        ////////////////////////////////////////////////////////////////
        // Private Helpers
        ////////////////////////////////////////////////////////////////

        void ResetBridgeAndBridgePoints()
        {
            Debug.Log("Reset Bridge Points");
            m_FirstBridgePoint  = RawBridgePoint.INVALID;
            m_SecondBridgePoint = RawBridgePoint.INVALID;

            m_Bridge     = Bridge.INVALID;
            m_BridgeMesh = BridgeMesh.INVALID;
        }
Exemple #3
0
        ////////////////////////////////////////////////////////////////

        void OnNewBridgeMesh(CreateBridgeEvent bridgeEvent)
        {
            // TODO: Blending & stuff.
            m_BridgeMeshData = bridgeEvent.BridgeMeshData;
            BuildMeshFromBridgeMeshData();


            // Save, for each bridge vertex, the vector towards the according bridge point inside its color (can it overflow 1? I twould need to).
            // Then, inside the bridges shader, use the vertex color and a slider 0 to 1 to fade in and out the bridge towards its bridge points.
            // Also use transparency if possible.
        }
Exemple #4
0
        void Start()
        {
            m_BridgeMeshData = BridgeMesh.INVALID;
            m_Mesh           = null;

            m_MeshRenderer = GetComponent <MeshRenderer>();
            m_MeshFilter   = GetComponent <MeshFilter>();

            Debug.Assert(m_MeshRenderer != null);
            Debug.Assert(m_MeshFilter != null);

            EventManager.Instance.AddListener <CreateBridgeEvent>(OnNewBridgeMesh);
        }
        ////////////////////////////////////////////////////////////////

        void UpdateBridgeMesh()
        {
            BridgeMesh bridgeMesh = BridgeCreator.CreateBridgeMesh(m_Bridge);

            EventManager.Instance.FireEvent <CreateBridgeEvent>(new CreateBridgeEvent(bridgeMesh));
        }
        public static BridgeMesh CreateBridgeMesh(Bridge bridge)
        {
            Debug.Assert(bridge.IsValid());

            // For each bridgePoint [e.g, 0 or 1], we want to add the two bridge vertices [L, R]
            //
            // L0------------------L1 -
            // |                   |  |
            // |                   |  < BridgeWidth / 2
            // |                   |  |
            // 0-------------------1  -
            // |                   |
            // |                   |
            // |                   |
            // R0------------------R1

            ////////////////////////////////////////////////////////////////

            int bridgePointCount = bridge.Points.Length;

            List <BridgeMeshVertex> vertices = new List <BridgeMeshVertex>();

            for (int i = 0; i < bridgePointCount; i++)
            {
                ValidBridgePoint bridgePoint = bridge.Points[i];

                ////////////////////////////////////////////////////////////////

                bool isEvenPoint = (i % 2 == 0);
                AppendBridgeMeshVertices(ref vertices, bridgePoint, isEvenPoint);
            }

            const int VERTS_PER_BRIDGEPOINT = 2;

            int        triangleCount = VERTS_PER_BRIDGEPOINT * bridgePointCount;
            List <int> indicies      = new List <int>();

            for (int segementID = 0; segementID < bridgePointCount - 1; segementID++)
            {
                int nextSegmentID = segementID + 1;

                int vertexIDThisSegmentLeft  = VERTS_PER_BRIDGEPOINT * segementID + 0;
                int vertexIDThisSegmentRight = VERTS_PER_BRIDGEPOINT * segementID + 1;
                int vertexIDNextSegmentLeft  = VERTS_PER_BRIDGEPOINT * nextSegmentID + 0;
                int vertexIDNextSegmentRight = VERTS_PER_BRIDGEPOINT * nextSegmentID + 1;

                // Triangle 1: R0, L0, L1
                indicies.Add(vertexIDThisSegmentRight);
                indicies.Add(vertexIDThisSegmentLeft);
                indicies.Add(vertexIDNextSegmentLeft);

                // Triangle 2: R0, L1, R1
                indicies.Add(vertexIDThisSegmentRight);
                indicies.Add(vertexIDNextSegmentLeft);
                indicies.Add(vertexIDNextSegmentRight);
            }

            BridgeMesh bridgeMesh = new BridgeMesh(vertices, indicies);

            return(bridgeMesh);
        }