protected override bool Initialize() { if (Native != null) { return(true); } RigidBody rb = Parent != null?Parent.GetInitializedComponentInParent <RigidBody>() : null; agx.Vec3 position = rb != null && Type == Cable.NodeType.BodyFixedNode ? CalculateLocalPosition(rb.gameObject).ToHandedVec3() : Position.ToHandedVec3(); agx.Quat rotation = rb != null && Type == Cable.NodeType.BodyFixedNode ? CalculateLocalRotation(rb.gameObject).ToHandedQuat() : Rotation.ToHandedQuat(); if (Type == Cable.NodeType.BodyFixedNode) { Native = new agxCable.BodyFixedNode(rb != null ? rb.Native : null, new agx.AffineMatrix4x4(rotation, position)); } else if (Type == Cable.NodeType.FreeNode) { Native = new agxCable.FreeNode(position); Native.getRigidBody().setRotation(Rotation.ToHandedQuat()); } else { return(false); } foreach (var attachment in m_attachments) { var attachmentRb = attachment.Parent?.GetInitializedComponentInParent <RigidBody>(); var attachmentPosition = attachmentRb != null?CalculateLocalPosition(attachmentRb.gameObject).ToHandedVec3() : attachment.Position.ToHandedVec3(); var attachmentRotation = attachmentRb != null?CalculateLocalRotation(attachmentRb.gameObject).ToHandedQuat() : attachment.Rotation.ToHandedQuat(); agxCable.SegmentAttachment nativeAttachment = null; if (attachment.Type == CableAttachment.AttachmentType.Ball) { nativeAttachment = new agxCable.PointSegmentAttachment(attachmentRb?.Native, attachmentPosition); } else if (attachment.Type == CableAttachment.AttachmentType.Rigid) { nativeAttachment = new agxCable.RigidSegmentAttachment(attachmentRb?.Native, new agx.AffineMatrix4x4(attachmentRotation, attachmentPosition)); } if (nativeAttachment == null) { Debug.LogWarning("Unknown cable node attachment type. Ignored attachment."); } else { Native.add(nativeAttachment); } } return(true); }
/**---------------------------------------From agx.Quat to UnityEngine.Quaternion-------------------------------------*/ public static Quaternion FromAgxQuat(agx.Quat quat) { return(new Quaternion((double)quat.x, (double)quat.y, (double)quat.z, (double)quat.w)); }