var e, i, t, s, n = arequire("../@babel/runtime/helpers/get"), o = arequire("../@babel/runtime/helpers/getPrototypeOf"), a = arequire("../@babel/runtime/helpers/classCallCheck"), l = arequire("../@babel/runtime/helpers/createClass"), r = arequire("../@babel/runtime/helpers/inherits"), h = arequire("../@babel/runtime/helpers/createSuper");

e = window.TY.Cannon = window.TY.Cannon || {}, i = function(e) {
    r(t, e);
    var i = h(t);
    function t() {
        return a(this, t), i.apply(this, arguments);
    }
    return l(t, [ {
        key: "angularVelocity",
        set: function(e) {
            if (this._angularVelocity = e, this._btColliderObject) {
                var i = this.btColliderObject.angularVelocity;
                i.set(e.x, e.y, e.z), this.btColliderObject.angularVelocity = i;
            }
        }
    } ]), t;
}(Laya.CannonRigidbody3D), t = function() {
    function e(i) {
        a(this, e), this.radius = 1, this.axleLocal = new CANNON.Vec3(1, 0, 0), this.suspensionStiffness = 30, 
        this.suspensionRestLength = .8, this.frictionSlip = 5, this.dampingRelaxation = 2.3, 
        this.dampingCompression = 4.4, this.maxSuspensionForce = 1e5, this.rollInfluence = .001, 
        this.maxSuspensionTravel = .3, this.customSlidingRotationalSpeed = -30, this.useCustomSlidingRotationalSpeed = !0, 
        this.chassisConnectionPointLocal = new CANNON.Vec3(), this.directionLocal = new CANNON.Vec3(0, -1, 0), 
        this.childId = 0, i && (i.radius && (this.radius = i.radius), i.axleLocal && (this.axleLocal = new CANNON.Vec3(i.axleLocal[0], i.axleLocal[1], i.axleLocal[2])), 
        i.chassisConnectionPointLocal && (this.chassisConnectionPointLocal = new CANNON.Vec3(i.chassisConnectionPointLocal[0], i.chassisConnectionPointLocal[1], i.chassisConnectionPointLocal[2])), 
        i.suspensionStiffness && (this.suspensionStiffness = i.suspensionStiffness), i.suspensionRestLength && (this.suspensionRestLength = i.suspensionRestLength), 
        i.frictionSlip && (this.frictionSlip = i.frictionSlip), i.dampingRelaxation && (this.dampingRelaxation = i.dampingRelaxation), 
        i.dampingCompression && (this.dampingCompression = i.dampingCompression), i.maxSuspensionForce && (this.maxSuspensionForce = i.maxSuspensionForce), 
        i.rollInfluence && (this.rollInfluence = i.rollInfluence), i.maxSuspensionTravel && (this.maxSuspensionTravel = i.maxSuspensionTravel), 
        i.customSlidingRotationalSpeed && (this.customSlidingRotationalSpeed = i.customSlidingRotationalSpeed), 
        i.useCustomSlidingRotationalSpeed && (this.useCustomSlidingRotationalSpeed = i.useCustomSlidingRotationalSpeed), 
        i.childId && (this.childId = i.childId));
    }
    return l(e, [ {
        key: "clone",
        value: function() {
            var i = new e(null);
            i.radius = this.radius, i.axleLocal = this.axleLocal.clone(), i.suspensionStiffness = this.suspensionStiffness, 
            i.suspensionRestLength = this.suspensionRestLength, i.frictionSlip = this.frictionSlip, 
            i.dampingRelaxation = this.dampingRelaxation, i.dampingCompression = this.dampingCompression, 
            i.maxSuspensionForce = this.maxSuspensionForce, i.rollInfluence = this.rollInfluence, 
            i.maxSuspensionTravel = this.maxSuspensionTravel, i.customSlidingRotationalSpeed = this.customSlidingRotationalSpeed, 
            i.useCustomSlidingRotationalSpeed = this.useCustomSlidingRotationalSpeed, i.chassisConnectionPointLocal = this.chassisConnectionPointLocal.clone(), 
            i.directionLocal = this.directionLocal.clone(), i.childId = this.childId;
        }
    } ]), e;
}(), s = function(e) {
    r(s, e);
    var i = h(s);
    function s() {
        var e, t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : -1, n = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : Laya.Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER;
        return a(this, s), (e = i.call(this, t, n)).wheels = [], e.wheelSprites = [], e._controlBySimulation = !0, 
        e;
    }
    return l(s, [ {
        key: "currentVehicleSpeedKmHour",
        get: function() {
            return this.vehicle.currentVehicleSpeedKmHour;
        }
    }, {
        key: "colliderObject",
        get: function() {
            return this._btColliderObject;
        }
    }, {
        key: "velocity",
        get: function() {
            return this.vehicle.chassisBody.velocity;
        }
    }, {
        key: "hold",
        value: function() {
            this.vehicle.chassisBody.velocity.set(0, 0, 0);
        }
    }, {
        key: "_onShapeChange",
        value: function(e) {
            n(o(s.prototype), "_onShapeChange", this).call(this, e), this._updateMass(this._mass);
        }
    }, {
        key: "_onScaleChange",
        value: function(e) {
            n(o(s.prototype), "_onScaleChange", this).call(this, e), this._updateMass(this._mass);
        }
    }, {
        key: "_derivePhysicsTransformation",
        value: function(e) {
            this._innerDerivePhysicsTransformation(this.colliderObject, e);
        }
    }, {
        key: "mass",
        get: function() {
            return this._mass;
        },
        set: function(e) {
            e = Math.max(e, 1e-7), this._mass = e, this._updateMass(e);
        }
    }, {
        key: "_updateMass",
        value: function(e) {
            this.colliderObject && this.colliderShape && (this.colliderObject.mass = e, this.colliderObject.updateMassProperties(), 
            this.colliderObject.updateSolveMassProperties());
        }
    }, {
        key: "_onAdded",
        value: function() {
            this.mass = this._mass;
            var e = new CANNON.Body();
            e.material = new CANNON.Material(), e.layaID = this.id, e.type = CANNON.Body.DYNAMIC, 
            e.collisionFilterGroup = this.collisionGroup, e.collisionFilterMask = this._canCollideWith, 
            this._btColliderObject = e, e.mass = this.mass, this.vehicle = new CANNON.RaycastVehicle({
                chassisBody: this.colliderObject,
                indexRightAxis: 0,
                indexUpAxis: 1,
                indexForwardAxis: 2
            }), n(o(s.prototype), "_onAdded", this).call(this);
        }
    }, {
        key: "_parse",
        value: function(e, i) {
            n(o(s.prototype), "_parse", this).call(this, e, i);
            var a = e.rig;
            if (a) {
                if (this.mass = a.mass, n(o(s.prototype), "_parseShape", this).call(this, a.shapes), 
                !e.wheelInfo) throw "车轮没找到？？？？";
                i.component.push(this), i.data.push(e);
                for (var l = 0; l < e.wheelInfo.length; l++) {
                    var r = e.wheelInfo[l], h = new t(r);
                    this.vehicle.addWheel(h);
                }
            } else this.mass = 1;
        }
    }, {
        key: "_parseInteractive",
        value: function(e) {
            var i = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : null;
            n(o(s.prototype), "_parseInteractive", this).call(this, e, i);
            for (var t = 0; t < e.wheelInfo.length; t++) {
                var a = e.wheelInfo[t];
                this.wheelSprites.push(this.owner.getChildAt(a.childId));
            }
        }
    }, {
        key: "_addToSimulation",
        value: function() {
            console.log("添加车", this.vehicle), this.vehicle && this.vehicle.addToWorld(this.simulation._btDiscreteDynamicsWorld);
        }
    }, {
        key: "_removeFromSimulation",
        value: function() {
            this.vehicle && this.vehicle.removeFromWorld(this.simulation._btDiscreteDynamicsWorld);
        }
    }, {
        key: "_updateTransformComponent",
        value: function(e) {
            if (this.vehicle) for (var i = 0; i < this.vehicle.wheelInfos.length; i++) {
                this.vehicle.updateWheelTransform(i);
                var t = this.vehicle.wheelInfos[i].worldTransform, a = this.wheelSprites[i].transform.position;
                a.setValue(t.position.x, t.position.y, t.position.z), this.wheelSprites[i].transform.position = a;
                var l = this.wheelSprites[i].transform.rotation;
                l.x = t.quaternion.x, l.y = t.quaternion.y, l.z = t.quaternion.z, l.w = t.quaternion.w, 
                this.wheelSprites[i].transform.rotation = l;
            }
            n(o(s.prototype), "_updateTransformComponent", this).call(this, e);
        }
    }, {
        key: "brake",
        value: function(e) {
            var i = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : -1;
            if (-1 == i) {
                if (this.vehicle) for (var t = 0; t < this.vehicle.wheelInfos.length; t++) this.vehicle.setBrake(e, t);
            } else this.vehicle.setBrake(e, i);
        }
    }, {
        key: "applyEngineForce",
        value: function(e, i) {
            this.vehicle && this.vehicle.applyEngineForce(e, i);
        }
    }, {
        key: "steeringValue",
        value: function(e, i) {
            if (this.vehicle.wheelInfos.length <= i) throw "车轮胎有问题" + this.owner + "/index" + i;
            this.vehicle && this.vehicle.setSteeringValue(e, i);
        }
    }, {
        key: "_cloneTo",
        value: function(e) {}
    } ], [ {
        key: "__init__",
        value: function() {
            s._btTempVector30 = new CANNON.Vec3(), s._btTempVector31 = new CANNON.Vec3();
        }
    } ]), s;
}(Laya.CannonPhysicsComponent), e.CannonPhysicsComponentExtension = function(e) {
    r(t, e);
    var i = h(t);
    function t() {
        return a(this, t), i.apply(this, arguments);
    }
    return l(t, null, [ {
        key: "_creatShape",
        value: function(e) {
            var i;
            switch (e.type) {
              case "CapsuleColliderShape":
              default:
                i = spuer._creatShape(e);
            }
            return i;
        }
    } ]), t;
}(Laya.CannonPhysicsComponent), e.CannonRigidbodyExtension = i, e.CannonUtils = function() {
    function e() {
        a(this, e);
    }
    return l(e, null, [ {
        key: "init",
        value: function(e) {
            var t = Laya.CannonPhysicsComponent.prototype._parse;
            Laya.CannonPhysicsComponent.prototype._parse = function(i, s) {
                t(i, s);
                var n = this.owner;
                this.collisionGroup = 1 << n.layer;
                var o = -1;
                e && (o = e.get3dCollisionMask(n.layer)), this.canCollideWith = o;
            }, Laya.ClassUtils.regClass("Rigidbody3D", i), Laya.ClassUtils.regClass("TY.RaycastVehicle", s), 
            Laya.ClassUtils.regClass("PhysicsCollider", Laya.CannonPhysicsCollider), this.set_parseShape(), 
            Laya.CannonPhysicsSimulation.prototype.World = function() {
                return this._btDiscreteDynamicsWorld;
            }, Laya.CannonPhysicsSimulation.prototype._simulate = function(e) {
                this._updatedRigidbodies = 0, this._btDiscreteDynamicsWorld && (this._btDiscreteDynamicsWorld.callBackBody.length = 0, 
                this._btDiscreteDynamicsWorld.allContacts.length = 0, this._btDiscreteDynamicsWorld.step(this.fixedTimeStep));
                for (var i = this._btDiscreteDynamicsWorld.callBackBody, t = 0, s = i.length; t < s; t++) {
                    var n = i[t], o = Laya.CannonPhysicsComponent._physicObjectsMap[n.layaID];
                    o._simulation._updatedRigidbodies++, o._updateTransformComponent(o._btColliderObject);
                }
            };
        }
    }, {
        key: "set_parseShape",
        value: function() {
            var e = Laya.CannonPhysicsComponent.prototype._parseShape;
            Laya.CannonPhysicsComponent.prototype._parseShape = function(i) {
                var t = i.length;
                if (1 === t) e.call(this, i); else {
                    for (var s = new Laya.CannonCompoundColliderShape(), n = 0; n < t; n++) {
                        var o = Laya.CannonPhysicsComponent._creatShape(i[n]);
                        s.addChildShape(o, o.localOffset);
                    }
                    this.colliderShape = s;
                }
            };
        }
    } ]), e;
}(), e.CannonWheelCollider = t, e.CanonRayCastVehicle = s, Object.defineProperty(e, "__esModule", {
    value: !0
});