private void Render()
        {
            if (m_segmentSpawner == null)
            {
                return;
            }

            agxCable.Cable native = Cable.Native;
            if (native == null)
            {
                if (m_segmentSpawner != null)
                {
                    m_segmentSpawner.Destroy();
                    m_segmentSpawner = null;
                }
                return;
            }

            m_segmentSpawner.Begin();
            try {
                agxCable.CableIterator it    = native.begin();
                agxCable.CableIterator endIt = native.end();
                float radius = Cable.Radius;
                while (!it.EqualWith(endIt))
                {
                    m_segmentSpawner.CreateSegment(it.getBeginPosition().ToHandedVector3(), it.getEndPosition().ToHandedVector3(), radius);
                    it.inc();
                }
            }
            catch (System.Exception e) {
                Debug.LogException(e, this);
            }
            m_segmentSpawner.End();
        }
Beispiel #2
0
        protected override void OnDestroy()
        {
            if (m_segmentSpawner != null)
            {
                m_segmentSpawner.Destroy();
            }
            m_segmentSpawner = null;

            base.OnDestroy();
        }
Beispiel #3
0
    public void InitializeRenderer( bool destructLast = false )
    {
      if ( m_segmentSpawner != null ) {
        m_segmentSpawner.Destroy();
        m_segmentSpawner = null;
      }

      m_segmentSpawner = new SegmentSpawner( GetComponent<Cable>(), @"Cable/CableSegment", @"Cable/CableSegmentBegin" );
      m_segmentSpawner.Initialize( gameObject );
    }
Beispiel #4
0
    protected override void OnDestroy()
    {
      if ( m_segmentSpawner != null )
        m_segmentSpawner.Destroy();
      m_segmentSpawner = null;

      if ( Simulation.HasInstance )
        Simulation.Instance.StepCallbacks.PostStepForward -= Render;

      base.OnDestroy();
    }
Beispiel #5
0
        private void Render(Wire wire)
        {
            if (wire.Native == null)
            {
                if (m_segmentSpawner != null)
                {
                    m_segmentSpawner.Destroy();
                    m_segmentSpawner = null;
                }
                return;
            }

            List <Vector3> positions = new List <Vector3>();

            positions.Capacity = 256;
            agxWire.RenderIterator it    = wire.Native.getRenderBeginIterator();
            agxWire.RenderIterator endIt = wire.Native.getRenderEndIterator();
            while (!it.EqualWith(endIt))
            {
                positions.Add(it.get().getWorldPosition().ToHandedVector3());
                it.inc();
            }

            m_segmentSpawner.Begin();

            try {
                for (int i = 0; i < positions.Count - 1; ++i)
                {
                    Vector3 curr       = positions[i];
                    Vector3 next       = positions[i + 1];
                    Vector3 currToNext = next - curr;
                    float   distance   = currToNext.magnitude;
                    currToNext /= distance;
                    int   numSegments = Convert.ToInt32(distance * NumberOfSegmentsPerMeter + 0.5f);
                    float dl          = distance / numSegments;
                    for (int j = 0; j < numSegments; ++j)
                    {
                        next = curr + dl * currToNext;

                        m_segmentSpawner.CreateSegment(curr, next, wire.Radius);
                        curr = next;
                    }
                }
            }
            catch (System.Exception e) {
                Debug.LogException(e);
            }

            m_segmentSpawner.End();
        }