示例#1
0
 private Node GetOrCreateCable(agxCable.Cable cable)
 {
     return(GetOrCreateNode(NodeType.Cable,
                            cable.getUuid(),
                            true,
                            () => m_cables.Add(cable.getUuid(), cable)));
 }
        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();
        }
示例#3
0
        private agxCable.Cable CreateNative(float resolutionPerUnitLength)
        {
            var native = new agxCable.Cable(Radius, new agxCable.IdentityRoute(resolutionPerUnitLength));

            native.addComponent(new agxCable.CablePlasticity());
            native.getCablePlasticity().setYieldPoint(double.PositiveInfinity, agxCable.Direction.ALL_DIRECTIONS);

            return(native);
        }
示例#4
0
        public void RestoreLocalDataFrom(agxCable.Cable native)
        {
            if (native == null)
            {
                return;
            }

            Radius = Convert.ToSingle(native.getRadius());
            ResolutionPerUnitLength = Convert.ToSingle(native.getResolution());
            LinearVelocityDamping   = Convert.ToSingle(native.getLinearVelocityDamping().maxComponent());
            AngularVelocityDamping  = Convert.ToSingle(native.getAngularVelocityDamping().maxComponent());
        }
示例#5
0
        protected override bool Initialize()
        {
            try {
                if (Route.NumNodes < 2)
                {
                    throw new Exception("Invalid number of nodes. Minimum number of route nodes is two.");
                }

                agxCable.Cable cable = null;
                if (RouteAlgorithm == RouteType.Segmenting)
                {
                    var result = SynchronizeRoutePointCurve();
                    if (!result.Successful)
                    {
                        throw new Exception("Invalid cable route. Unable to initialize cable with " +
                                            Route.NumNodes +
                                            " nodes and resolution/length = " + ResolutionPerUnitLength + ".");
                    }

                    cable = CreateNative(result.NumSegments / Route.TotalLength);

                    var handledNodes = new HashSet <CableRouteNode>();
                    var success      = TraverseRoutePoints(routePointData =>
                    {
                        var routeNode      = CableRouteNode.Create(NodeType.FreeNode, routePointData.CurrNode.Parent);
                        routeNode.Position = routePointData.Position;
                        routeNode.Rotation = routePointData.Rotation;

                        var attachmentNode = routePointData.SegmentType == PointCurve.SegmentType.First && routePointData.CurrNode.Type != NodeType.FreeNode ?
                                             routePointData.CurrNode :
                                             routePointData.SegmentType == PointCurve.SegmentType.Last && routePointData.NextNode.Type != NodeType.FreeNode ?
                                             routePointData.NextNode :
                                             routePointData.SegmentType == PointCurve.SegmentType.Intermediate && routePointData.CurrNode.Type != NodeType.FreeNode ?
                                             routePointData.CurrNode :
                                             null;

                        if (attachmentNode != null && !handledNodes.Contains(attachmentNode))
                        {
                            handledNodes.Add(attachmentNode);
                            routeNode.Add(CableAttachment.AttachmentType.Rigid,
                                          attachmentNode.Parent,
                                          attachmentNode.LocalPosition,
                                          attachmentNode.LocalRotation);
                        }

                        if (!cable.add(routeNode.GetInitialized <CableRouteNode>().Native))
                        {
                            throw new Exception("Unable to add node to cable.");
                        }
                    });

                    if (!success)
                    {
                        throw new Exception(string.Format("Invalid route - unable to find segment length given resolution/length = {0}",
                                                          ResolutionPerUnitLength));
                    }
                }
                else
                {
                    cable = CreateNative(ResolutionPerUnitLength);
                    foreach (var node in Route)
                    {
                        if (!cable.add(node.GetInitialized <CableRouteNode>().Native))
                        {
                            throw new Exception("Unable to add node to cable.");
                        }
                    }
                }

                Native = cable;
            }
            catch (Exception e) {
                Debug.LogException(e, this);

                return(false);
            }

            Native.setName(name);

            GetSimulation().add(Native);

            if (Properties != null)
            {
                Properties.GetInitialized <CableProperties>();
            }

            SynchronizeProperties();

            return(true);
        }