import { defineProps } from '../types.js';

class SpringBoneChainConfig {
    startBone;
    endBone;
    constructor(startBone = '', endBone = ''){
        this.startBone = startBone;
        this.endBone = endBone;
    }
}
class SpringColliderConfig {
    type;
    enabled;
    bone;
    offsetX;
    offsetY;
    offsetZ;
    endOffsetX;
    endOffsetY;
    endOffsetZ;
    radius;
    normalX;
    normalY;
    normalZ;
    constructor(type = 'sphere'){
        this.type = type;
        this.enabled = true;
        this.bone = '';
        this.offsetX = 0;
        this.offsetY = 0;
        this.offsetZ = 0;
        this.endOffsetX = 0;
        this.endOffsetY = 0.2;
        this.endOffsetZ = 0;
        this.radius = 0.15;
        this.normalX = 0;
        this.normalY = 1;
        this.normalZ = 0;
    }
}
class SpringScriptConfig {
    enabled;
    chainDamping;
    chainStiffness;
    gravityX;
    gravityY;
    gravityZ;
    iterations;
    enableInertialForces;
    centrifugalScale;
    coriolisScale;
    solver;
    poseFollow;
    poseFollowRoot;
    poseFollowTip;
    poseFollowExponent;
    maxPoseOffset;
    maxPoseOffsetRoot;
    maxPoseOffsetTip;
    modifierWeight;
    chains;
    colliders;
    constructor(){
        this.enabled = true;
        this.chainDamping = 0.9;
        this.chainStiffness = 0.82;
        this.gravityX = 0;
        this.gravityY = -9.8;
        this.gravityZ = 0;
        this.iterations = 6;
        this.enableInertialForces = true;
        this.centrifugalScale = 2;
        this.coriolisScale = 1;
        this.solver = 'xpbd';
        this.poseFollow = 0.3;
        this.poseFollowRoot = 0.15;
        this.poseFollowTip = 0.05;
        this.poseFollowExponent = 1.6;
        this.maxPoseOffset = 0.3;
        this.maxPoseOffsetRoot = 0.2;
        this.maxPoseOffsetTip = 0.4;
        this.modifierWeight = 1;
        this.chains = defaultSpringChains();
        this.colliders = [];
    }
}
function defaultSpringChains() {
    return [
        new SpringBoneChainConfig('joint2', 'joint11'),
        new SpringBoneChainConfig('joint13', 'joint22'),
        new SpringBoneChainConfig('joint24', 'joint34'),
        new SpringBoneChainConfig('joint36', 'joint44'),
        new SpringBoneChainConfig('joint58', 'joint67'),
        new SpringBoneChainConfig('joint69', 'joint76'),
        new SpringBoneChainConfig('joint78', 'joint88'),
        new SpringBoneChainConfig('joint101', 'joint109'),
        new SpringBoneChainConfig('joint111', 'joint119'),
        new SpringBoneChainConfig('joint121', 'joint130'),
        new SpringBoneChainConfig('joint132', 'joint138')
    ];
}
function getSpringBoneChainConfigClass() {
    return {
        ctor: SpringBoneChainConfig,
        name: 'SpringBoneChain',
        noTitle: true,
        createFunc () {
            return {
                obj: new SpringBoneChainConfig()
            };
        },
        getProps () {
            return defineProps([
                {
                    name: 'StartBone',
                    type: 'string',
                    options: {
                        label: 'Start'
                    },
                    get (value) {
                        value.str[0] = this.startBone;
                    },
                    set (value) {
                        this.startBone = value.str[0] ?? '';
                    }
                },
                {
                    name: 'EndBone',
                    type: 'string',
                    options: {
                        label: 'End'
                    },
                    get (value) {
                        value.str[0] = this.endBone;
                    },
                    set (value) {
                        this.endBone = value.str[0] ?? '';
                    }
                }
            ]);
        }
    };
}
function getSpringColliderConfigClass() {
    return {
        ctor: SpringColliderConfig,
        name: 'SpringColliderConfig',
        noTitle: true,
        createFunc () {
            return {
                obj: new SpringColliderConfig()
            };
        },
        getProps () {
            return defineProps([
                {
                    name: 'Type',
                    type: 'string',
                    options: {
                        group: 'Shape',
                        enum: {
                            labels: [
                                'Sphere',
                                'Capsule',
                                'Plane'
                            ],
                            values: [
                                'sphere',
                                'capsule',
                                'plane'
                            ]
                        }
                    },
                    get (value) {
                        value.str[0] = this.type;
                    },
                    set (value) {
                        this.type = value.str[0] ?? 'sphere';
                    }
                },
                {
                    name: 'Enabled',
                    type: 'bool',
                    options: {
                        group: 'General'
                    },
                    get (value) {
                        value.bool[0] = this.enabled;
                    },
                    set (value) {
                        this.enabled = !!value.bool[0];
                    }
                },
                {
                    name: 'Bone',
                    type: 'string',
                    options: {
                        group: 'General'
                    },
                    get (value) {
                        value.str[0] = this.bone;
                    },
                    set (value) {
                        this.bone = value.str[0] ?? '';
                    }
                },
                {
                    name: 'Offset',
                    type: 'vec3',
                    options: {
                        group: 'Shape'
                    },
                    get (value) {
                        value.num[0] = this.offsetX;
                        value.num[1] = this.offsetY;
                        value.num[2] = this.offsetZ;
                    },
                    set (value) {
                        this.offsetX = value.num[0];
                        this.offsetY = value.num[1];
                        this.offsetZ = value.num[2];
                    }
                },
                {
                    name: 'EndOffset',
                    type: 'vec3',
                    options: {
                        group: 'Shape'
                    },
                    isValid () {
                        return this.type === 'capsule';
                    },
                    get (value) {
                        value.num[0] = this.endOffsetX;
                        value.num[1] = this.endOffsetY;
                        value.num[2] = this.endOffsetZ;
                    },
                    set (value) {
                        this.endOffsetX = value.num[0];
                        this.endOffsetY = value.num[1];
                        this.endOffsetZ = value.num[2];
                    }
                },
                {
                    name: 'Radius',
                    type: 'float',
                    options: {
                        group: 'Shape',
                        minValue: 0
                    },
                    isValid () {
                        return this.type === 'sphere' || this.type === 'capsule';
                    },
                    get (value) {
                        value.num[0] = this.radius;
                    },
                    set (value) {
                        this.radius = value.num[0];
                    }
                },
                {
                    name: 'Normal',
                    type: 'vec3',
                    options: {
                        group: 'Shape'
                    },
                    isValid () {
                        return this.type === 'plane';
                    },
                    get (value) {
                        value.num[0] = this.normalX;
                        value.num[1] = this.normalY;
                        value.num[2] = this.normalZ;
                    },
                    set (value) {
                        this.normalX = value.num[0];
                        this.normalY = value.num[1];
                        this.normalZ = value.num[2];
                    }
                }
            ]);
        }
    };
}
function getSpringScriptConfigClass() {
    return {
        ctor: SpringScriptConfig,
        name: 'SpringScriptConfig',
        noTitle: true,
        createFunc () {
            return {
                obj: new SpringScriptConfig()
            };
        },
        getProps () {
            return defineProps([
                {
                    name: 'Enabled',
                    type: 'bool',
                    options: {
                        group: 'General'
                    },
                    get (value) {
                        value.bool[0] = this.enabled;
                    },
                    set (value) {
                        this.enabled = !!value.bool[0];
                    }
                },
                {
                    name: 'ModifierWeight',
                    type: 'float',
                    options: {
                        group: 'General',
                        minValue: 0,
                        maxValue: 1
                    },
                    get (value) {
                        value.num[0] = this.modifierWeight;
                    },
                    set (value) {
                        this.modifierWeight = value.num[0];
                    }
                },
                {
                    name: 'Damping',
                    type: 'float',
                    options: {
                        group: 'Chain',
                        minValue: 0,
                        maxValue: 1
                    },
                    get (value) {
                        value.num[0] = this.chainDamping;
                    },
                    set (value) {
                        this.chainDamping = value.num[0];
                    }
                },
                {
                    name: 'Stiffness',
                    type: 'float',
                    options: {
                        group: 'Chain',
                        minValue: 0,
                        maxValue: 1
                    },
                    get (value) {
                        value.num[0] = this.chainStiffness;
                    },
                    set (value) {
                        this.chainStiffness = value.num[0];
                    }
                },
                {
                    name: 'BoneChains',
                    type: 'object_array',
                    options: {
                        group: 'Chain',
                        objectTypes: [
                            SpringBoneChainConfig
                        ]
                    },
                    get (value) {
                        value.object = this.chains;
                    },
                    set (value) {
                        this.chains = value.object ?? [];
                    },
                    add (value, index) {
                        this.chains.splice(index ?? this.chains.length, 0, value.object[0]);
                    },
                    delete (index) {
                        this.chains.splice(index, 1);
                    },
                    create () {
                        return new SpringBoneChainConfig();
                    }
                },
                {
                    name: 'Gravity',
                    type: 'vec3',
                    options: {
                        group: 'Simulation'
                    },
                    get (value) {
                        value.num[0] = this.gravityX;
                        value.num[1] = this.gravityY;
                        value.num[2] = this.gravityZ;
                    },
                    set (value) {
                        this.gravityX = value.num[0];
                        this.gravityY = value.num[1];
                        this.gravityZ = value.num[2];
                    }
                },
                {
                    name: 'Iterations',
                    type: 'int',
                    options: {
                        group: 'Simulation',
                        minValue: 1,
                        maxValue: 32
                    },
                    get (value) {
                        value.num[0] = this.iterations;
                    },
                    set (value) {
                        this.iterations = value.num[0];
                    }
                },
                {
                    name: 'EnableInertialForces',
                    type: 'bool',
                    options: {
                        group: 'Simulation'
                    },
                    get (value) {
                        value.bool[0] = this.enableInertialForces;
                    },
                    set (value) {
                        this.enableInertialForces = !!value.bool[0];
                    }
                },
                {
                    name: 'CentrifugalScale',
                    type: 'float',
                    options: {
                        group: 'Simulation'
                    },
                    get (value) {
                        value.num[0] = this.centrifugalScale;
                    },
                    set (value) {
                        this.centrifugalScale = value.num[0];
                    }
                },
                {
                    name: 'CoriolisScale',
                    type: 'float',
                    options: {
                        group: 'Simulation'
                    },
                    get (value) {
                        value.num[0] = this.coriolisScale;
                    },
                    set (value) {
                        this.coriolisScale = value.num[0];
                    }
                },
                {
                    name: 'Solver',
                    type: 'string',
                    options: {
                        group: 'Simulation',
                        enum: {
                            labels: [
                                'XPBD',
                                'Verlet'
                            ],
                            values: [
                                'xpbd',
                                'verlet'
                            ]
                        }
                    },
                    get (value) {
                        value.str[0] = this.solver;
                    },
                    set (value) {
                        this.solver = value.str[0] ?? 'xpbd';
                    }
                },
                {
                    name: 'PoseFollow',
                    type: 'float',
                    options: {
                        group: 'PoseFollow'
                    },
                    get (value) {
                        value.num[0] = this.poseFollow;
                    },
                    set (value) {
                        this.poseFollow = value.num[0];
                    }
                },
                {
                    name: 'PoseFollowRoot',
                    type: 'float',
                    options: {
                        group: 'PoseFollow'
                    },
                    get (value) {
                        value.num[0] = this.poseFollowRoot;
                    },
                    set (value) {
                        this.poseFollowRoot = value.num[0];
                    }
                },
                {
                    name: 'PoseFollowTip',
                    type: 'float',
                    options: {
                        group: 'PoseFollow'
                    },
                    get (value) {
                        value.num[0] = this.poseFollowTip;
                    },
                    set (value) {
                        this.poseFollowTip = value.num[0];
                    }
                },
                {
                    name: 'PoseFollowExponent',
                    type: 'float',
                    options: {
                        group: 'PoseFollow'
                    },
                    get (value) {
                        value.num[0] = this.poseFollowExponent;
                    },
                    set (value) {
                        this.poseFollowExponent = value.num[0];
                    }
                },
                {
                    name: 'MaxPoseOffset',
                    type: 'float',
                    options: {
                        group: 'PoseFollow'
                    },
                    get (value) {
                        value.num[0] = this.maxPoseOffset;
                    },
                    set (value) {
                        this.maxPoseOffset = value.num[0];
                    }
                },
                {
                    name: 'MaxPoseOffsetRoot',
                    type: 'float',
                    options: {
                        group: 'PoseFollow'
                    },
                    get (value) {
                        value.num[0] = this.maxPoseOffsetRoot;
                    },
                    set (value) {
                        this.maxPoseOffsetRoot = value.num[0];
                    }
                },
                {
                    name: 'MaxPoseOffsetTip',
                    type: 'float',
                    options: {
                        group: 'PoseFollow'
                    },
                    get (value) {
                        value.num[0] = this.maxPoseOffsetTip;
                    },
                    set (value) {
                        this.maxPoseOffsetTip = value.num[0];
                    }
                },
                {
                    name: 'Colliders',
                    type: 'object_array',
                    options: {
                        group: 'Collider',
                        objectTypes: [
                            SpringColliderConfig
                        ]
                    },
                    get (value) {
                        value.object = this.colliders;
                    },
                    set (value) {
                        this.colliders = value.object ?? [];
                    },
                    add (value, index) {
                        this.colliders.splice(index ?? this.colliders.length, 0, value.object[0]);
                    },
                    delete (index) {
                        this.colliders.splice(index, 1);
                    },
                    create () {
                        return new SpringColliderConfig();
                    }
                }
            ]);
        }
    };
}

export { SpringBoneChainConfig, SpringColliderConfig, SpringScriptConfig, defaultSpringChains, getSpringBoneChainConfigClass, getSpringColliderConfigClass, getSpringScriptConfigClass };
//# sourceMappingURL=spring_script.js.map
