예제 #1
0
        /// <summary>
        /// Creates native instance given current properties.
        /// </summary>
        /// <returns>Native instance of this node.</returns>
        protected override bool Initialize()
        {
            RigidBody rb = null;

            Collide.Shape shape = null;
            if (Parent != null)
            {
                rb    = Parent.GetInitializedComponentInParent <RigidBody>();
                shape = Parent.GetInitializedComponentInParent <Collide.Shape>();
            }

            // We don't know if the parent is the rigid body.
            // It could be a mesh, or some other object.
            // Also - use world position if Type == FreeNode.
            agx.Vec3 point = rb != null && Type != Wire.NodeType.FreeNode ?
                             CalculateLocalPosition(rb.gameObject).ToHandedVec3() :
                             Position.ToHandedVec3();

            agx.RigidBody nativeRb = rb != null ? rb.Native : null;
            if (Type == Wire.NodeType.BodyFixedNode)
            {
                Native = new agxWire.BodyFixedNode(nativeRb, point);
            }
            // Create a free node if type is contact and shape == null.
            else if (Type == Wire.NodeType.FreeNode || (Type == Wire.NodeType.ContactNode && shape == null))
            {
                Native = new agxWire.FreeNode(point);
            }
            else if (Type == Wire.NodeType.ConnectingNode)
            {
                Native = new agxWire.ConnectingNode(nativeRb, point, double.PositiveInfinity);
            }
            else if (Type == Wire.NodeType.EyeNode)
            {
                Native = new agxWire.EyeNode(nativeRb, point);
            }
            else if (Type == Wire.NodeType.ContactNode)
            {
                Native = new agxWire.ContactNode(shape.NativeGeometry, CalculateLocalPosition(shape.gameObject).ToHandedVec3());
            }
            else if (Type == Wire.NodeType.WinchNode)
            {
                if (m_winch == null)
                {
                    throw new AgXUnity.Exception("No reference to a wire winch component in the winch node.");
                }

                m_winch.GetInitialized <WireWinch>();

                Native = m_winch.Native != null?m_winch.Native.getStopNode() : null;
            }

            return(Native != null);
        }
예제 #2
0
        private Data CollectData(bool propagateToChildren)
        {
            Data data = new Data();

            RigidBody rb = GetComponent <RigidBody>();

            Collide.Shape shape = rb != null                  ? null                 : GetComponent <Collide.Shape>();
            Wire          wire  = rb != null || shape != null ? null                 : GetComponent <Wire>();
            Cable         cable = rb != null || shape != null || wire != null ? null : GetComponent <Cable>();

            bool allPredefinedAreNull = rb == null && shape == null && wire == null && cable == null;

            if (allPredefinedAreNull && propagateToChildren)
            {
                data.Shapes = GetComponentsInChildren <Collide.Shape>();
                data.Wires  = GetComponentsInChildren <Wire>();
                data.Cables = GetComponentsInChildren <Cable>();
            }
            // A wire is by definition independent of PropagateToChildren, since
            // it's not defined to add children to a wire game object.
            else if (wire != null)
            {
                data.Wires = new Wire[] { wire };
            }
            // Same logics for Cable.
            else if (cable != null)
            {
                data.Cables = new Cable[] { cable };
            }
            // Bodies have shapes so if 'rb' != null we should collect all shape children
            // independent of 'propagate' flag.
            // If 'shape' != null and propagate is true we have the same condition as for bodies.
            else if (rb != null || shape != null || (rb == null && shape == null && propagateToChildren))
            {
                data.Shapes = shape != null && !propagateToChildren?GetComponents <Collide.Shape>() :
                                  shape != null || rb != null?GetComponentsInChildren <Collide.Shape>() :
                                      // Both shape and rb == null and PropagateToChildren == true.
                                      GetComponentsInChildren <Collide.Shape>();
            }
            else
            {
                // These groups has no effect.
                Debug.LogWarning("Collision groups has no effect. Are you missing a PropagateToChildren = true?", this);
            }

            return(data);
        }