(window.webpackJsonp=window.webpackJsonp||[]).push([[15],{456:function(t,i,e){"use strict";var s;e.d(i,"a",(function(){return s})),function(t){t[t.Little=0]="Little",t[t.Big=1]="Big"}(s||(s={}))},466:function(t,i,e){"use strict";e.d(i,"a",(function(){return r}));var s=e(486);class r extends s.a{constructor(t,i,e=0,s=t.byteLength-e){super(i,e),this._size=s,this.backing_buffer=t,this.dv=new DataView(t,0,t.byteLength)}get size(){return this._size}set size(t){if(t>this.backing_buffer.byteLength-this.offset)throw new Error(`Size ${t} is out of bounds.`);this._size=t}take(t){const i=this.offset+this.position,e=new r(this.backing_buffer,this.endianness,i,t);return this._position+=t,e}}},481:function(t,i,e){"use strict";e.d(i,"a",(function(){return r})),e.d(i,"b",(function(){return n}));var s=e(2);function r(t){return new Promise(i=>{var e,r,n,o;const a=Object(s.m)({type:"file"});a.accept=null!=(r=null===(e=t)||void 0===e?void 0:e.accept)?r:"",a.multiple=null!=(o=null===(n=t)||void 0===n?void 0:n.multiple)&&o,a.onchange=()=>{a.files&&a.files.length?i([...a.files]):i([])},a.click()})}function n(t){return new Promise((i,e)=>{const s=new FileReader;s.addEventListener("loadend",()=>{s.result instanceof ArrayBuffer?i(s.result):e(new Error("Couldn't read file."))}),s.readAsArrayBuffer(t)})}},482:function(t,i,e){"use strict";e.d(i,"a",(function(){return r}));var s=e(486);class r extends s.a{constructor(t,i,e=0,s=t.size-e){if(e<0||e>t.size)throw new Error(`Offset ${e} is out of bounds.`);if(s<0||e+s>t.size)throw new Error(`Size ${s} is out of bounds.`);super(i,e),this.buffer=t,this._size=s}get size(){return this._size}set size(t){t>this._size?this.ensure_size(t-this.position):this._size=t}get backing_buffer(){return this.buffer.backing_buffer}get dv(){return this.buffer.view}take(t){this.check_size("size",t,t);const i=this.offset+this.position,e=new r(this.buffer,this.endianness,i,t);return this._position+=t,e}ensure_size(t,i=this.position){const e=i+t-this._size;e>0&&(this._size+=e,this.buffer.sizethis.size)throw new Error(`Offset ${t} is out of bounds.`);return this._position=t,this}seek_end(t){if(t<0||t>this.size)throw new Error(`Offset ${t} is out of bounds.`);return this._position=this.size-t,this}u8(){return this.u8_at(this._position++)}u8_at(t){return this.check_offset(t,1),this.dv.getUint8(this.offset+t)}u16(){const t=this.u16_at(this.position);return this._position+=2,t}u16_at(t){return this.check_offset(t,2),this.dv.getUint16(this.offset+t,this.little_endian)}u32(){const t=this.u32_at(this.position);return this._position+=4,t}u32_at(t){return this.check_offset(t,4),this.dv.getUint32(this.offset+t,this.little_endian)}i8(){return this.i8_at(this._position++)}i8_at(t){return this.check_offset(t,1),this.dv.getInt8(this.offset+t)}i16(){const t=this.i16_at(this.position);return this._position+=2,t}i16_at(t){return this.check_offset(t,2),this.dv.getInt16(this.offset+t,this.little_endian)}i32(){const t=this.i32_at(this.position);return this._position+=4,t}i32_at(t){return this.check_offset(t,4),this.dv.getInt32(this.offset+t,this.little_endian)}f32(){const t=this.f32_at(this.position);return this._position+=4,t}f32_at(t){return this.check_offset(t,4),this.dv.getFloat32(this.offset+t,this.little_endian)}u8_array(t){this.check_size("n",t,t);const i=[];for(let e=0;ethis.size-this.position)throw new Error(`${t} ${i} is out of bounds.`)}check_offset(t,i){if(t<0||t+i>this.size)throw new Error(`Offset ${t} is out of bounds.`)}}e.d(i,"a",(function(){return n}));class n extends r{write_u8(t){return this.write_u8_at(this.position,t),this._position+=1,this}write_u16(t){return this.write_u16_at(this.position,t),this._position+=2,this}write_u32(t){return this.write_u32_at(this.position,t),this._position+=4,this}write_i8(t){return this.write_i8_at(this.position,t),this._position+=1,this}write_i16(t){return this.write_i16_at(this.position,t),this._position+=2,this}write_i32(t){return this.write_i32_at(this.position,t),this._position+=4,this}write_f32(t){return this.write_f32_at(this.position,t),this._position+=4,this}write_u8_array(t){return this.write_u8_array_at(this.position,t),this._position+=t.length,this}write_u16_array(t){return this.write_u16_array_at(this.position,t),this._position+=2*t.length,this}write_u32_array(t){return this.write_u32_array_at(this.position,t),this._position+=4*t.length,this}write_i32_array(t){return this.write_i32_array_at(this.position,t),this._position+=4*t.length,this}write_vec2_f32(t){return this.write_vec2_f32_at(this.position,t),this._position+=8,this}write_vec3_f32(t){return this.write_vec3_f32_at(this.position,t),this._position+=12,this}write_cursor(t){const i=t.size-t.position;return this.ensure_size(i),t.copy_to_uint8_array(new Uint8Array(this.backing_buffer,this.offset+this.position,i),i),this._position+=i,this}write_string_ascii(t,i){return this.write_string_ascii_at(this.position,t,i),this._position+=i,this}write_string_utf16(t,i){return this.write_string_utf16_at(this.position,t,i),this._position+=i,this}write_u8_at(t,i){return this.ensure_size(1,t),this.dv.setUint8(t,i),this}write_u16_at(t,i){return this.ensure_size(2,t),this.dv.setUint16(t,i,this.little_endian),this}write_u32_at(t,i){return this.ensure_size(4,t),this.dv.setUint32(t,i,this.little_endian),this}write_i8_at(t,i){return this.ensure_size(1,t),this.dv.setInt8(t,i),this}write_i16_at(t,i){return this.ensure_size(2,t),this.dv.setInt16(t,i,this.little_endian),this}write_i32_at(t,i){return this.ensure_size(4,t),this.dv.setInt32(t,i,this.little_endian),this}write_f32_at(t,i){return this.ensure_size(4,t),this.dv.setFloat32(t,i,this.little_endian),this}write_u8_array_at(t,i){return this.ensure_size(i.length,t),new Uint8Array(this.backing_buffer,this.offset+t).set(new Uint8Array(i)),this}write_u16_array_at(t,i){this.ensure_size(2*i.length,t);const e=i.length;for(let s=0;se)throw new Error(`${t} Bytes required but only ${e} available.`)}}},496:function(t,i,e){"use strict";e.d(i,"a",(function(){return s}));class s{constructor(t=8192){this._size=0,this._buffer=new ArrayBuffer(t),this._data_view=new DataView(this._buffer)}get size(){return this._size}set size(t){if(t<0)throw new Error("Size should be non-negative.");this.ensure_capacity(t),this._size=t}get capacity(){return this._buffer.byteLength}get backing_buffer(){return this._buffer}get view(){return this._data_view}sub_view(t,i){return new DataView(this._buffer,t,i)}ensure_capacity(t){if(t>this.capacity){let i=this.capacity||t;do{i*=2}while(it.type===h||t.type===_)}function f(t){const i=Object(s.a)(t);if(!i.success)return i;const e=Object(n.b)(a);e.add_result(i);const r=i.value,u=r.find(t=>t.type===h),f=u&&function(t){return{texture_count:t.u16()}}(u.data),l=r.filter(t=>t.type===_).map(t=>(function(t){const i=t.u32(),e=t.u32(),s=t.u32(),r=t.u16(),n=t.u16(),o=t.u32();return t.seek(36),{id:s,format:[i,e],width:r,height:n,size:o,data:t.array_buffer(o)}})(t.data));return f||0!==l.length?(f&&f.texture_count!==l.length&&e.add_problem(o.b.Warning,"Corrupted XVM file.",`Found ${l.length} textures instead of ${f.texture_count} as defined in the header.`),e.success({textures:l})):(e.add_problem(o.b.Error,"Corrupted XVM file.","No header and no XVRT chunks found."),e.failure())}},544:function(t,i,e){"use strict";e.d(i,"a",(function(){return o}));var s=e(482),r=e(496);const n=e(23).a.get("core/data_formats/compression/prs/decompress");function o(t){const i=new a(t);for(;;)if(1===i.read_flag_bit())i.copy_u8();else{let t,e;if(0===i.read_flag_bit())t=i.read_flag_bit()<<1,t|=i.read_flag_bit(),t+=2,e=i.read_u8()-256;else{if(e=i.read_u16(),0===e)break;t=7&e,e>>>=3,0===t?(t=i.read_u8(),t+=1):t+=2,e-=8192}i.offset_copy(e,t)}return i.dst.seek_start(0)}class a{constructor(t){this.src=t,this.dst=new s.a(new r.a(Math.floor(1.5*t.size)),t.endianness),this.flags=0,this.flag_bits_left=0}read_flag_bit(){0===this.flag_bits_left&&(this.flags=this.read_u8(),this.flag_bits_left=8);const t=1&this.flags;return this.flags>>>=1,this.flag_bits_left-=1,t}copy_u8(){this.dst.write_u8(this.read_u8())}read_u8(){return this.src.u8()}read_u16(){return this.src.u16()}offset_copy(t,i){(t<-8192||t>0)&&n.error(`offset was ${t}, should be between -8192 and 0.`),(i<1||i>256)&&n.error(`length was ${i}, should be between 1 and 256.`);const e=Math.min(-t,i);this.dst.seek(t);const s=this.dst.take(e);this.dst.seek(-t-e);for(let t=0;tt.size)i.add_problem(n.b.Warning,`AFS file entry ${r} is invalid.`,`Invalid file offset ${e} for entry ${r}.`);else if(e+o>t.size)i.add_problem(n.b.Warning,`AFS file entry ${r} is invalid.`,`File size ${o} (offset: ${e}) of entry ${r} too large.`);else{const i=t.position;t.seek_start(e),s.push(t.array_buffer(o)),t.seek_start(i)}}return i.success(s)}},827:function(t,i,e){"use strict";e.r(i),e.d(i,"ModelToolBarController",(function(){return g}));var s=e(138),r=e(481),n=e(466),o=e(456),a=e(485),h=e(545),_=e(516),u=e(546),f=e(23),l=e(544),c=e(457),d=e(26),p=e(14),b=function(t,i,e,s){return new(e||(e=Promise))((function(r,n){function o(t){try{h(s.next(t))}catch(t){n(t)}}function a(t){try{h(s.throw(t))}catch(t){n(t)}}function h(t){var i;t.done?r(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(o,a)}h((s=s.apply(t,i||[])).next())}))};const w=f.a.get("viewer/controllers/model/ModelToolBarController");class g extends s.a{constructor(t){super(),this.store=t,this._result_dialog_visible=Object(p.e)(!1),this._result=Object(p.e)(void 0),this._result_problems_message=Object(p.e)(""),this._result_error_message=Object(p.e)(""),this.result_dialog_visible=this._result_dialog_visible,this.result=this._result,this.result_problems_message=this._result_problems_message,this.result_error_message=this._result_error_message,this.set_show_skeleton=t=>{this.store.set_show_skeleton(t)},this.set_animation_playing=t=>{this.store.set_animation_playing(t)},this.set_animation_frame_rate=t=>{this.store.set_animation_frame_rate(t)},this.set_animation_frame=t=>{this.store.set_animation_frame(t)},this.load_file=t=>b(this,void 0,void 0,(function*(){this._result_problems_message.val=`Encountered some problems while opening "${t.name}".`,this._result_error_message.val=`Couldn't open "${t.name}".`;try{const i=yield Object(r.b)(t),e=new n.a(i,o.a.Little);if(t.name.endsWith(".nj")){const t=Object(a.c)(e);this.set_result(t),t.success&&this.store.set_current_nj_object(t.value[0])}else if(t.name.endsWith(".xj")){const t=Object(a.d)(e);this.set_result(t),t.success&&this.store.set_current_nj_object(t.value[0])}else if(t.name.endsWith(".njm")){this.store.set_current_animation(void 0),this.store.set_current_nj_motion(void 0);const t=this.store.current_nj_object.val;t?(this.set_animation_playing(!0),this.store.set_current_nj_motion(Object(h.c)(e,t.bone_count())),this.set_result(Object(c.c)(void 0))):this.set_result(Object(c.a)([{severity:d.b.Error,ui_message:"No model to animate"}]))}else if(t.name.endsWith(".xvm")){const t=Object(_.b)(e);this.set_result(t),t.success?this.store.set_current_textures(t.value.textures):this.store.set_current_textures([])}else if(t.name.endsWith(".afs")){const t=Object(c.b)(w),i=Object(u.a)(e);if(t.add_result(i),i.success){const e=i.value.flatMap(i=>{var e,s,r,a;const h=new n.a(i,o.a.Little);if(Object(_.a)(h)){const i=Object(_.b)(h);return t.add_result(i),null!=(s=null===(e=i.value)||void 0===e?void 0:e.textures)?s:[]}{const i=Object(_.b)(Object(l.a)(h.seek_start(0)));return t.add_result(i),null!=(a=null===(r=i.value)||void 0===r?void 0:r.textures)?a:[]}});e.length?this.set_result(t.success(e)):this.set_result(t.failure()),this.store.set_current_textures(e)}else this.set_result(t.failure())}else w.debug(`Unsupported file extension in filename "${t.name}".`),this.set_result(Object(c.a)([{severity:d.b.Error,ui_message:"Unsupported file type."}]))}catch(t){w.error("Couldn't read file.",t),this.set_result(Object(c.a)())}})),this.dismiss_result_dialog=()=>{this._result_dialog_visible.val=!1},this.show_skeleton=t.show_skeleton,this.animation_frame_count=t.animation_frame_count,this.animation_frame_count_label=t.animation_frame_count.map(t=>`/ ${t}`),this.animation_controls_enabled=t.current_nj_motion.map(t=>null!=t),this.animation_playing=t.animation_playing,this.animation_frame_rate=t.animation_frame_rate,this.animation_frame=t.animation_frame.map(t=>Math.round(t))}set_result(t){this._result.val=t,t.problems.length&&(this._result_dialog_visible.val=!0)}}}}]);