Beispiel #1
0
        /// <summary>
        /// Add route node given native node instance. If the node type is unsupported
        /// this method returns null, ignoring the node.
        /// </summary>
        /// <remarks>
        /// If the given node is a lumped node it will be assumed to be NodeType.FreeNode.
        /// </remarks>
        /// <param name="nativeNode">Native node instance.</param>
        /// <param name="parent">Parent game object as in nativeNode.getRigidBody().</param>
        /// <returns>Wire route node if added, otherwise null.</returns>
        public WireRouteNode Add(agxWire.Node nativeNode, GameObject parent)
        {
            if (nativeNode == null)
            {
                return(null);
            }

            var nodeType = Wire.Convert(nativeNode.getType());

            if (nodeType == Wire.NodeType.Unknown)
            {
                return(null);
            }

            // Assume free if lumped node.
            if (nodeType == Wire.NodeType.BodyFixedNode && agxWire.Wire.isLumpedNode(nativeNode.getRigidBody()))
            {
                nodeType = Wire.NodeType.FreeNode;
            }

            var node = WireRouteNode.Create(nodeType, parent);

            if (!Add(node))
            {
                return(null);
            }

            if (nodeType != Wire.NodeType.FreeNode)
            {
                node.LocalPosition = nativeNode.getPosition().ToHandedVector3();
            }
            else
            {
                node.Position = nativeNode.getWorldPosition().ToHandedVector3();
            }

            return(node);
        }
Beispiel #2
0
        protected override bool Initialize()
        {
            WireRoute.ValidatedRoute validatedRoute = Route.GetValidated();
            if (!validatedRoute.Valid)
            {
                Debug.LogError(validatedRoute.ErrorString, this);
                for (int i = 0; i < validatedRoute.Nodes.Count; ++i)
                {
                    if (!validatedRoute.Nodes[i].Valid)
                    {
                        Debug.LogError("[" + i + "]: " + validatedRoute.Nodes[i].ErrorString, this);
                    }
                }

                return(false);
            }

            try {
                Native   = new agxWire.Wire(Radius, ResolutionPerUnitLength);
                Material = m_material != null?m_material.GetInitialized <ShapeMaterial>() : null;

                int nodeCounter = 0;
                foreach (WireRouteNode routeNode in Route)
                {
                    agxWire.Node node = routeNode.GetInitialized <WireRouteNode>().Native;

                    bool success = true;
                    if (node.getType() == agxWire.Node.Type.CONNECTING)
                    {
                        // This is the first node, CM-node goes first.
                        if (nodeCounter == 0)
                        {
                            success = success && Native.add(node.getAsConnecting().getCmNode());
                            success = success && Native.add(node);
                        }
                        // This has to be the last node, CM-node goes last.
                        else
                        {
                            success = success && Native.add(node);
                            success = success && Native.add(node.getAsConnecting().getCmNode());
                        }
                    }
                    else if (routeNode.Type == NodeType.WinchNode)
                    {
                        if (node == null)
                        {
                            throw new AGXUnity.Exception("Unable to initialize wire winch.");
                        }

                        success = success && Native.add(routeNode.Winch.Native);
                    }
                    else
                    {
                        success = success && Native.add(node);
                    }

                    if (!success)
                    {
                        throw new AGXUnity.Exception("Unable to add node " + nodeCounter + ": " + routeNode.Type);
                    }

                    ++nodeCounter;
                }

                Native.setName(name);

                GetSimulation().add(Native);
                Simulation.Instance.StepCallbacks.PostStepForward += OnPostStepForward;
            }
            catch (System.Exception e) {
                Debug.LogException(e, this);
                return(false);
            }

            return(Native.initialized());
        }