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B,KAAK,YAAc,EACnB,KAAK,WAAY,CACrB,EACA,EAAe,UAAU,MAAQ,WAC7B,KAAK,WAAY,CACrB,EACA,EAAe,UAAU,MAAQ,WAC7B,KAAK,gBAAgB,KAAK,eAC1B,KAAK,cAAgB,EACzB,EACA,EAAe,UAAU,KAAO,WAC5B,KAAK,QACL,KAAK,OACT,EACO,CACX,CA5ImC,GA6InC,QAAQ,QAAU","file":"/npm/three-particle-system@1.0.12/lib/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/three-particle-system@1.0.12/lib/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar THREE = require(\"three\");\r\nvar random_1 = require(\"./utils/random\");\r\nvar three_1 = require(\"three\");\r\nvar plane_1 = require(\"./shapes/plane\");\r\nvar typeCheck_1 = require(\"./utils/typeCheck\");\r\nvar ParticleSystem = /** @class */ (function () {\r\n    function ParticleSystem(target, options) {\r\n        this.color = 0xedaa67;\r\n        this.duration = 2000; // in MS\r\n        this.elapsedTime = 0;\r\n        this.initialRotationRange = [\r\n            // one of tuple of vec3<float> or vec3<float>. Values in radians\r\n            new THREE.Vector3(0, 0, 0),\r\n            new THREE.Vector3(Math.PI * 2, Math.PI * 2, Math.PI * 2),\r\n        ];\r\n        this.isPlaying = true;\r\n        this.loop = true;\r\n        this.maxParticleSize = 0.1;\r\n        this.maxParticles = 100;\r\n        this.minParticleSize = 0.1;\r\n        this.particleLifetime = 2000; // in MS\r\n        this.particleQueue = [];\r\n        this.particleVelocity = 1; // units per second\r\n        this.particlesPerSecond = 50;\r\n        this.playOnLoad = true;\r\n        this.radius = new THREE.Vector3(1, 1, 1);\r\n        this.rotationRate = 0; // in radians\r\n        this.scene = null;\r\n        this.shape = new plane_1.default();\r\n        this.worldSpace = true;\r\n        // User Defined Values\r\n        this.color = options.color || this.color;\r\n        this.duration = options.duration || this.duration;\r\n        this.initialRotationRange = options.initialRotationRange || this.initialRotationRange;\r\n        this.isPlaying = typeCheck_1.isBool(options.playOnLoad) ? options.playOnLoad || false : this.isPlaying;\r\n        this.loop = typeCheck_1.isBool(options.loop) ? options.playOnLoad || false : this.loop;\r\n        this.maxParticleSize = options.maxParticleSize || options.minParticleSize || 0.1;\r\n        this.maxParticles = options.maxParticles || this.maxParticles;\r\n        this.minParticleSize = options.minParticleSize || options.maxParticleSize || this.minParticleSize;\r\n        this.particleLifetime = options.particleLifetime || this.particleLifetime;\r\n        this.particleVelocity = options.particleVelocity || this.particleVelocity;\r\n        this.particlesPerSecond = options.particlesPerSecond || this.particlesPerSecond;\r\n        this.radius = options.radius || this.radius;\r\n        this.rotationRate = options.rotationRate || this.rotationRate;\r\n        this.shape = options.shape || this.shape;\r\n        this.target = target;\r\n        this.worldSpace = typeCheck_1.isBool(options.worldSpace) ? options.worldSpace || false : this.worldSpace;\r\n        if (this.worldSpace)\r\n            this.findSceneObject();\r\n        // Member Variables\r\n        this.startTime = Date.now();\r\n    }\r\n    ParticleSystem.prototype.createPaticle = function () {\r\n        var size = random_1.randomBoundedInt(this.minParticleSize, this.maxParticleSize);\r\n        var geometry = new THREE.BoxGeometry(size, size, size);\r\n        var material = new THREE.MeshBasicMaterial({ color: this.color });\r\n        var newParticle = new THREE.Mesh(geometry, material);\r\n        var _a = this.shape.getVertex(), u = _a[0], v = _a[1];\r\n        // todo: get and set global rotation\r\n        newParticle.rotation.x = random_1.randomBoundedFloat(this.initialRotationRange[0].x, this.initialRotationRange[1].x);\r\n        newParticle.rotation.y = random_1.randomBoundedFloat(this.initialRotationRange[0].y, this.initialRotationRange[1].y);\r\n        newParticle.rotation.z = random_1.randomBoundedFloat(this.initialRotationRange[0].z, this.initialRotationRange[1].z);\r\n        if (this.worldSpace && this.scene) {\r\n            var pos = new three_1.Vector3();\r\n            this.target.getWorldPosition(pos);\r\n            pos.add(u);\r\n            newParticle.position.set(pos.x, pos.y, pos.z);\r\n            this.scene.add(newParticle);\r\n        }\r\n        else {\r\n            newParticle.position.set(u.x, u.y, u.z);\r\n            this.target.add(newParticle);\r\n        }\r\n        this.particleQueue.push([Date.now(), newParticle]);\r\n    };\r\n    ParticleSystem.prototype.findSceneObject = function () {\r\n        var cur = this.target;\r\n        while (cur.parent)\r\n            cur = cur.parent;\r\n        this.scene = cur;\r\n    };\r\n    ParticleSystem.prototype.removeParticles = function (particles) {\r\n        for (var _i = 0, particles_1 = particles; _i < particles_1.length; _i++) {\r\n            var _a = particles_1[_i], timestamp = _a[0], mesh = _a[1];\r\n            if (this.worldSpace && this.scene)\r\n                this.scene.remove(mesh);\r\n            else\r\n                this.target.remove(mesh);\r\n        }\r\n    };\r\n    ParticleSystem.prototype.update = function (deltaTime /* 50fps */) {\r\n        var _this = this;\r\n        if (deltaTime === void 0) { deltaTime = 0.02; }\r\n        if (!this.isPlaying)\r\n            return;\r\n        if (!this.loop && this.elapsedTime > this.duration && !this.particleQueue.length) {\r\n            // No more particles being produced\r\n            this.stop();\r\n            return;\r\n        }\r\n        // create new particles\r\n        if (this.loop || this.elapsedTime < this.duration) {\r\n            for (var i = 0; i < this.particlesPerSecond * deltaTime; i++) {\r\n                this.createPaticle();\r\n            }\r\n        }\r\n        // cull old particles\r\n        var timeThreshold = Date.now() - this.particleLifetime;\r\n        for (var i = 0; i < this.particleQueue.length; i++) {\r\n            if (this.particleQueue[i][0] < timeThreshold) {\r\n                var removed = this.particleQueue.splice(0, i + 1);\r\n                this.removeParticles(removed);\r\n            }\r\n        }\r\n        // cull excess particles\r\n        var overThreshold = this.particleQueue.length - this.maxParticles;\r\n        if (overThreshold > 0) {\r\n            var removed = this.particleQueue.splice(0, overThreshold);\r\n            this.removeParticles(removed);\r\n        }\r\n        // update current particles\r\n        this.particleQueue.forEach(function (_a) {\r\n            var timestamp = _a[0], mesh = _a[1];\r\n            mesh.getWorldPosition(mesh.position);\r\n            mesh.position.y += _this.particleVelocity * deltaTime;\r\n        });\r\n        this.elapsedTime = Date.now() - this.startTime;\r\n    };\r\n    ParticleSystem.prototype.play = function () {\r\n        this.startTime = Date.now();\r\n        this.elapsedTime = 0;\r\n        this.isPlaying = true;\r\n    };\r\n    ParticleSystem.prototype.pause = function () {\r\n        this.isPlaying = false;\r\n    };\r\n    ParticleSystem.prototype.clear = function () {\r\n        this.removeParticles(this.particleQueue);\r\n        this.particleQueue = [];\r\n    };\r\n    ParticleSystem.prototype.stop = function () {\r\n        this.pause();\r\n        this.clear();\r\n    };\r\n    return ParticleSystem;\r\n}());\r\nexports.default = ParticleSystem;\r\n"]}