blockbench/lib/wintersky.umd.js

2 lines
62 KiB
JavaScript
Raw Normal View History

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("three"),require("molangjs"),require("tinycolor2")):"function"==typeof define&&define.amd?define(["three","molangjs","tinycolor2"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).Wintersky=t(e.THREE,e.Molang,e.tinycolor)}(this,(function(e,t,i){"use strict";function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=a(t),s=a(i),o={};o.Scene=class{constructor(t={}){this.emitters=[],this.space=new e.Object3D,this._fetchTexture=t.fetchTexture,this.global_options={max_emitter_particles:t.max_emitter_particles||3e4,tick_rate:t.tick_rate||30,loop_mode:t.loop_mode||"auto",parent_mode:t.parent_mode||"world",ground_collision:0!=t.ground_collision,_scale:1},Object.defineProperty(this.global_options,"scale",{get:()=>this.global_options._scale,set:e=>{this.global_options._scale=e,this.emitters.forEach((t=>{t.local_space.scale.set(e,e,e),t.global_space.scale.set(e,e,e)}))}})}fetchTexture(e){if("function"==typeof this._fetchTexture)return this._fetchTexture(e)}updateFacingRotation(e){this.emitters.forEach((t=>{t.updateFacingRotation(e)}))}};const n="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QcKDTg2HKzkwgAAAFBJREFUOMtjvHDhwn8GCgALAwMDg4iICFma37x5w8DEQCEg2gBpaWkGaWlp8g2g2AVDyABcgTUwXiDGNQMfiCzoAk+fPiXIpr4L3rx5Q7YBAOhLE0zw8k9cAAAAAElFTkSuQmCC";function l(e){if("string"==typeof e&&"#"==e[0])e.length<9&&(e="#ff"+e.substr(1,6));else{if(e instanceof Array)return new s.default({r:255*(e[0]||0),g:255*(e[1]||0),b:255*(e[2]||0),a:"number"==typeof e[3]?e[3]:1}).toHex8String();e=new s.default(e).toHex8String()}return"#"+e.substr(3,6)+e.substr(1,2)}class c{constructor(t,i,a=0){this.scene=t,this.texture=new e.Texture(new Image),this.texture.image.onload=()=>{this.texture.needsUpdate=!0,"function"==typeof this.onTextureUpdate&&this.onTextureUpdate()},this.reset(),this.onTextureUpdate=null,a.path&&this.set("file_path",a.path),i&&i.particle_effect?this.setFromJSON(i):"object"==typeof i&&Object.assign(this,i)}reset(){for(var t in this.texture.image.src=n,this.texture.magFilter=e.NearestFilter,this.texture.minFilter=e.NearestFilter,c.types){var i,a=c.types[t];switch(a.type){case"string":case"molang":i="";break;case"number":i=0;break;case"boolean":i=!1;break;case"color":i="#ffffff";break;case"object":i={}}if(a.array){if(this[t]=[],a.dimensions)for(var r=0;r<a.dimensions;r++)"object"==a.type&&(i={}),this[t].push(i)}else this[t]=i}return this.emitter_rate_mode="steady",this.emitter_lifetime_mode="looping",this.emitter_shape_mode="point",this.particle_appearance_material="particles_alpha",this.particle_appearance_facing_camera_mode="rotate_xyz",this.particle_appearance_direction_mode="derive_from_velocity",this.particle_appearance_speed_threshold=.01,this.particle_direction_mode="outwards",this.particle_motion_mode="dynamic",this.particle_rotation_mode="dynamic",this.particle_texture_mode="static",this.particle_color_mode="static",this.particle_color_interpolant="v.particle_age / v.particle_lifetime",this.particle_color_range=1,this.emitter_rate_rate="4",this.emitter_rate_amount="1",this.emitter_rate_maximum="100",this.emitter_lifetime_active_time="1",this.particle_appearance_size=["0.2","0.2"],this.particle_lifetime_max_lifetime="1",this.particle_texture_size=[16,16],this}set(e,t){if(null!=c.types[e]&&null!=t&&null!=t)return c.types[e].array&&t instanceof Array?("molang"==c.types[e].type&&(t=t.map((e=>e.toString()))),this[e].splice(0,1/0,...t)):"string"==typeof this[e]?this[e]=t.toString():"number"==c.types[e].type&&"number"==typeof t?this[e]=t:"boolean"==c.types[e].type&&(this[e]=!!t),this}setFromJSON(e){var t=e.particle_effect.components,i=e.particle_effect.curves,a=e.particle_effect.description;if(a&&a.identifier&&(this.identifier=a.identifier),a&&a.basic_render_parameters&&(this.set("particle_texture_path",a.basic_render_parameters.texture),this.set("particle_appearance_material",a.basic_render_parameters.material)),i)for(var r in i){var o=i[r],n={