<commit_before>Object.assign(pc, function () {
    var mat4 = new pc.Mat4();
    var vec3 = new pc.Vec3();
    var quat = new pc.Quat();

    var _schema = [
        'enabled',
        'type',
        'halfExtents',
        'radius',
        'axis',
        'height',
        'asset',
        'shape',
        'model'
    ];

    // Collision system implementations
    var CollisionSystemImpl = function (system) {
        this.system = system;
    };

    Object.assign(CollisionSystemImpl.prototype, {
        // Called before the call to system.super.initializeComponentData is made
        beforeInitialize: function (component, data) {
            data.shape = null;

            data.model = new pc.Model();
            data.model.graph = new pc.GraphNode();
        },

        // Called after the call to system.super.initializeComponentData is made
        afterInitialize: function (component, data) {
            this.recreatePhysicalShapes(component);
            component.data.initialized = true;
        },

        // Called when a collision component changes type in order to recreate debug and physical shapes
        reset: function (component, data) {
            this.beforeInitialize(component, data);
            this.afterInitialize(component, data);
        },

        // Re-creates rigid bodies / triggers
        recreatePhysicalShapes: function (component) {
            var entity = component.entity;
            var data = component.data;

            if (typeof Ammo !== 'undefined') {
                if (entity.trigger) {
                    entity.trigger.destroy();
                    delete entity.trigger;
                }

                if (data.shape) {
                    if (component._compoundParent) {
                        this.system._removeCompoundChild(component._compoundParent, data.shape);

                        if (component._compoundParent.entity.rigidbody)
                            component._compoundParent.entity.rigidbody.activate();
                    }

                    Ammo.destroy(data.shape);
                    data.shape = null;
                }

                data.shape = this.createPhysicalShape(component.entity, data);

                if (data.type === 'compound' && (! component._compoundParent || component === component._compoundParent)) {
                    component._compoundParent = component;

                    entity.forEach(this._addEachDescendant, component);
                } else if (data.type !== 'compound') {
                    if (component._compoundParent && component === component._compoundParent) {
                        entity.forEach(this.system.implementations.compound._updateEachDescendant, component);
                    }

                    if (! component.rigidbody) {
                        component._compoundParent = null;
                        var parent = entity.parent;
                        while (parent) {
                            if (parent.collision && parent.collision.type === 'compound') {
                                component._compoundParent = parent.collision;
                                break;
                            }
                            parent = parent.parent;
                        }
                    }
                }

                if (component._compoundParent) {
                    if (component !== component._compoundParent) {
                        this.system.updateCompoundChildTransform(entity);

                        if (component._compoundParent.entity.rigidbody)
                            component._compoundParent.entity.rigidbody.activate();
                    }
                }

                if (entity.rigidbody) {
                    entity.rigidbody.disableSimulation();
                    entity.rigidbody.createBody();

                    if (entity.enabled && entity.rigidbody.enabled) {
                        entity.rigidbody.enableSimulation();
                    }<commit_msg>[FIX] Compound collision component initialized wrong (#1783)<commit_after>Object.assign(pc, function () {
    var mat4 = new pc.Mat4();
    var vec3 = new pc.Vec3();
    var quat = new pc.Quat();

    var _schema = [
        'enabled',
        'type',
        'halfExtents',
        'radius',
        'axis',
        'height',
        'asset',
        'shape',
        'model'
    ];

    // Collision system implementations
    var CollisionSystemImpl = function (system) {
        this.system = system;
    };

    Object.assign(CollisionSystemImpl.prototype, {
        // Called before the call to system.super.initializeComponentData is made
        beforeInitialize: function (component, data) {
            data.shape = null;

            data.model = new pc.Model();
            data.model.graph = new pc.GraphNode();
        },

        // Called after the call to system.super.initializeComponentData is made
        afterInitialize: function (component, data) {
            this.recreatePhysicalShapes(component);
            component.data.initialized = true;
        },

        // Called when a collision component changes type in order to recreate debug and physical shapes
        reset: function (component, data) {
            this.beforeInitialize(component, data);
            this.afterInitialize(component, data);
        },

        // Re-creates rigid bodies / triggers
        recreatePhysicalShapes: function (component) {
            var entity = component.entity;
            var data = component.data;

            if (typeof Ammo !== 'undefined') {
                if (entity.trigger) {
                    entity.trigger.destroy();
                    delete entity.trigger;
                }

                if (data.shape) {
                    if (component._compoundParent) {
                        this.system._removeCompoundChild(component._compoundParent, data.shape);

                        if (component._compoundParent.entity.rigidbody)
                            component._compoundParent.entity.rigidbody.activate();
                    }

                    Ammo.destroy(data.shape);
                    data.shape = null;
                }

                data.shape = this.createPhysicalShape(component.entity, data);

                var firstCompoundChild = ! component._compoundParent;

                if (data.type === 'compound' && (! component._compoundParent || component === component._compoundParent)) {
                    component._compoundParent = component;

                    entity.forEach(this._addEachDescendant, component);
                } else if (data.type !== 'compound') {
                    if (component._compoundParent && component === component._compoundParent) {
                        entity.forEach(this.system.implementations.compound._updateEachDescendant, component);
                    }

                    if (! component.rigidbody) {
                        component._compoundParent = null;
                        var parent = entity.parent;
                        while (parent) {
                            if (parent.collision && parent.collision.type === 'compound') {
                                component._compoundParent = parent.collision;
                                break;
                            }
                            parent = parent.parent;
                        }
                    }
                }

                if (component._compoundParent) {
                    if (component !== component._compoundParent) {
                        if (firstCompoundChild && component._compoundParent.shape.getNumChildShapes() === 0) {
                            this.system.recreatePhysicalShapes(component._compoundParent);
                        } else {
                            this.system.updateCompoundChildTransform(entity);

                            if (component._compoundParent.entity.rigidbody)
                                component._compoundParent.entity.rigidbody.activate();
                        }
                    }
                }

                if (entity.rigidbody) {
                    entity.rigidbody.disableSimulation();
                    entity.rigidbody.createBody();

                    if (entity.enabled && entity.rigidbody.enabled) {
                        entity.rigidbody.enableSimulation();
                    }
{'fraction_non_alphanumeric': 0.09209744503862151, 'fraction_numerical': 0.0015448603683897802, 'mean_word_length': 1.3787450537026569, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2641070', 'n_tokens_mistral': 1997, 'n_tokens_neox': 1863, 'n_words': 385}