protected override bool Initialize() { if (ResolutionPerUnitLength < 1.0 - 6f) { Debug.LogWarning("Cable resolution is too low: " + ResolutionPerUnitLength + " segments per unit length. Ignoring cable.", this); } try { if (Route.NumNodes < 2) { throw new Exception("Invalid number of nodes. Minimum number of route nodes is two."); } var cable = RouteAlgorithm == RouteType.Segmenting ? new agxCable.Cable(Convert.ToDouble(Radius), Convert.ToDouble(ResolutionPerUnitLength)) : new agxCable.Cable(Convert.ToDouble(Radius), new agxCable.IdentityRoute(ResolutionPerUnitLength)); cable.addComponent(new agxCable.CablePlasticity()); cable.getCablePlasticity().setYieldPoint(double.PositiveInfinity, agxCable.Direction.ALL_DIRECTIONS); CableRouteNode prev = null; foreach (var node in Route) { bool tooClose = prev != null && Vector3.Distance(prev.Position, node.Position) < 0.5f / ResolutionPerUnitLength; if (!tooClose && !cable.add(node.GetInitialized <CableRouteNode>().Native)) { throw new Exception("Unable to add node to cable."); } if (tooClose) { Debug.LogWarning("Ignoring route node with index: " + Route.IndexOf(node) + ", since it's too close to its neighbor.", this); } prev = node; } Native = cable; } catch (Exception e) { Debug.LogException(e, this); return(false); } Native.setName(name); GetSimulation().add(Native); SynchronizeProperties(); return(true); }
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); SynchronizeProperties(); return(true); }