(window.webpackJsonp=window.webpackJsonp||[]).push([[2],{472:function(e,t,r){"use strict";var n;r.d(t,"d",(function(){return n})),r.d(t,"b",(function(){return o})),r.d(t,"a",(function(){return i})),r.d(t,"c",(function(){return s})),r.d(t,"f",(function(){return a})),r.d(t,"e",(function(){return c})),r.d(t,"g",(function(){return _})),function(e){e[e.PosNorm=0]="PosNorm",e[e.PosTex=1]="PosTex",e[e.PosNormTex=2]="PosNormTex"}(n||(n={}));const o=0,i=1,s=2;function a(e){switch(e){case n.PosNorm:return 24;case n.PosTex:return 16;case n.PosNormTex:return 28}}function c(e){switch(e){case n.PosTex:return-1;case n.PosNorm:case n.PosNormTex:return 12}}function _(e){switch(e){case n.PosNorm:return-1;case n.PosTex:return 12;case n.PosNormTex:return 24}}},496:function(e,t,r){"use strict";var n;r.d(t,"b",(function(){return n})),r.d(t,"a",(function(){return o})),function(e){e[e.RGBA_S3TC_DXT1=0]="RGBA_S3TC_DXT1",e[e.RGBA_S3TC_DXT3=1]="RGBA_S3TC_DXT3"}(n||(n={}));class o{constructor(e,t,r,n,o){this.gfx=e,this.format=t,this.width=r,this.height=n,this.data=o}upload(){null==this.gfx_texture&&(this.gfx_texture=this.gfx.create_texture(this.format,this.width,this.height,this.data))}destroy(){this.gfx.destroy_texture(this.gfx_texture)}}},519:function(e,t,r){"use strict";r.d(t,"a",(function(){return o})),r.d(t,"b",(function(){return i}));var n=r(463);class o{constructor(){this.root_node=new i(void 0,n.a.identity())}traverse(e,t){this.traverse_node(this.root_node,e,t)}traverse_node(e,t,r){const n=t(e,r);for(const r of e.children)this.traverse_node(r,t,n)}}class i{constructor(e,t,...r){this.mesh=e,this.transform=t,this._children=r}get children(){return this._children}add_child(e){this._children.push(e)}clear_children(){this._children.splice(0)}}},638:function(e,t,r){"use strict";r.d(t,"a",(function(){return s}));var n=r(519),o=r(594),i=r(463);class s{constructor(e){this.width=800,this.height=600,this.scene=new n.a,this.canvas_element=document.createElement("canvas"),this.schedule_render=()=>{null==this.animation_frame&&(this.animation_frame=requestAnimationFrame(this.call_render))},this.call_render=()=>{this.animation_frame=void 0,this.render()},this.mousedown=e=>{this.pointer_pos=new i.b(e.clientX,e.clientY),window.addEventListener("mousemove",this.mousemove),window.addEventListener("mouseup",this.mouseup),window.addEventListener("contextmenu",this.contextmenu)},this.mousemove=e=>{const t=new i.b(e.clientX,e.clientY),r=Object(i.g)(t,this.pointer_pos);1===e.buttons?this.camera.pan(-r.x,r.y,0):2===e.buttons&&this.camera.rotate(-r.x/(20*Math.PI),-r.y/(20*Math.PI)),this.pointer_pos=t,this.schedule_render()},this.mouseup=e=>{e.preventDefault(),this.pointer_pos=void 0,window.removeEventListener("mousemove",this.mousemove),window.removeEventListener("mouseup",this.mouseup)},this.wheel=e=>{switch(this.camera.projection){case o.b.Orthographic:e.deltaY<0?this.camera.zoom(1.1):this.camera.zoom(.9);break;case o.b.Perspective:e.deltaY<0?this.camera.pan(0,0,-2):this.camera.pan(0,0,2)}this.schedule_render()},this.contextmenu=e=>{e.preventDefault(),window.removeEventListener("contextmenu",this.contextmenu)},this.canvas_element.width=this.width,this.canvas_element.height=this.height,this.canvas_element.addEventListener("mousedown",this.mousedown),this.canvas_element.addEventListener("wheel",this.wheel,{passive:!0}),this.camera=new o.a(this.width,this.height,e)}dispose(){this.destroy_scene()}set_size(e,t){this.width=e,this.height=t,this.camera.set_viewport(e,t),this.schedule_render()}start_rendering(){this.schedule_render()}stop_rendering(){null!=this.animation_frame&&cancelAnimationFrame(this.animation_frame),this.animation_frame=void 0}destroy_scene(){this.scene.traverse(e=>{var t,r,n;null===(t=e.mesh)||void 0===t||t.destroy(this.gfx),null===(n=null===(r=e.mesh)||void 0===r?void 0:r.texture)||void 0===n||n.destroy(),e.mesh=void 0},void 0),this.scene.root_node.clear_children(),this.scene.root_node.transform=i.a.identity()}}},903:function(e,t,r){"use strict";r.r(t),r.d(t,"WebglRenderer",(function(){return d}));var n=r(463),o=r(472);class i{constructor(e,t,r){this.gl=e;const n=e.createProgram();if(null==n)throw new Error("Failed to create program.");this.program=n;let i=null,a=null;try{if(i=s(e,e.VERTEX_SHADER,t),e.attachShader(n,i),a=s(e,e.FRAGMENT_SHADER,r),e.attachShader(n,a),e.bindAttribLocation(n,o.b,"pos"),e.bindAttribLocation(n,o.a,"normal"),e.bindAttribLocation(n,o.c,"tex"),e.linkProgram(n),!e.getProgramParameter(n,e.LINK_STATUS)){const t=e.getProgramInfoLog(n);throw new Error("Shader linking failed. Program log:\n"+t)}this.mat_projection_loc=this.get_required_uniform_location(n,"mat_projection"),this.mat_model_view_loc=this.get_required_uniform_location(n,"mat_model_view"),this.mat_normal_loc=e.getUniformLocation(n,"mat_normal"),this.tex_sampler_loc=e.getUniformLocation(n,"tex_sampler"),e.detachShader(n,i),e.detachShader(n,a)}catch(t){throw e.deleteProgram(n),t}finally{e.deleteShader(i),e.deleteShader(a)}}set_mat_projection_uniform(e){this.gl.uniformMatrix4fv(this.mat_projection_loc,!1,e.data)}set_mat_model_view_uniform(e){this.gl.uniformMatrix4fv(this.mat_model_view_loc,!1,e.data)}set_mat_normal_uniform(e){this.gl.uniformMatrix3fv(this.mat_normal_loc,!1,e.data)}set_texture_uniform(e){this.gl.uniform1i(this.tex_sampler_loc,e-this.gl.TEXTURE0)}bind(){this.gl.useProgram(this.program)}unbind(){this.gl.useProgram(null)}delete(){this.gl.deleteProgram(this.program)}get_required_uniform_location(e,t){const r=this.gl.getUniformLocation(e,t);if(null==r)throw new Error(`Couldn't get ${t} uniform location.`);return r}}function s(e,t,r){const n=e.createShader(t);if(null==n)throw new Error(`Failed to create shader of type ${t}.`);if(e.shaderSource(n,r),e.compileShader(n),!e.getShaderParameter(n,e.COMPILE_STATUS)){const t=e.getShaderInfoLog(n);throw e.deleteShader(n),new Error("Vertex shader compilation failed. Shader log:\n"+t)}return n}var a="#version 300 es\r\n\r\nprecision mediump float;\r\n\r\nuniform mat4 mat_projection;\r\nuniform mat4 mat_model_view;\r\nuniform mat3 mat_normal;\r\n\r\nin vec4 pos;\r\nin vec3 normal;\r\n\r\nout vec3 frag_normal;\r\n\r\nvoid main() {\r\n gl_Position = mat_projection * mat_model_view * pos;\r\n frag_normal = normalize(mat_normal * normal);\r\n}\r\n",c="#version 300 es\r\n\r\nprecision mediump float;\r\n\r\nconst vec3 light_pos = normalize(vec3(-1, 1, 1));\r\nconst vec4 sky_color = vec4(1, 1, 1, 1);\r\nconst vec4 ground_color = vec4(0.1, 0.1, 0.1, 1);\r\n\r\nin vec3 frag_normal;\r\n\r\nout vec4 frag_color;\r\n\r\nvoid main() {\r\n float cos0 = dot(frag_normal, light_pos);\r\n float a = 0.5 + 0.5 * cos0;\r\n float a_back = 1.0 - a;\r\n\r\n if (gl_FrontFacing) {\r\n frag_color = mix(ground_color, sky_color, a);\r\n } else {\r\n frag_color = mix(ground_color, sky_color, a_back);\r\n }\r\n}\r\n",_="#version 300 es\r\n\r\nprecision mediump float;\r\n\r\nuniform mat4 mat_projection;\r\nuniform mat4 mat_model_view;\r\n\r\nin vec4 pos;\r\nin vec2 tex;\r\n\r\nout vec2 f_tex;\r\n\r\nvoid main() {\r\n gl_Position = mat_projection * mat_model_view * pos;\r\n f_tex = tex;\r\n}\r\n",m="#version 300 es\r\n\r\nprecision mediump float;\r\n\r\nuniform sampler2D tex_sampler;\r\n\r\nin vec2 f_tex;\r\n\r\nout vec4 frag_color;\r\n\r\nvoid main() {\r\n frag_color = texture(tex_sampler, f_tex);\r\n}\r\n",l=r(638),h=r(496);class u{constructor(e){this.gl=e}create_gfx_mesh(e,t,r,n){const i=this.gl;let s=null,a=null,c=null;try{if(s=i.createVertexArray(),null==s)throw new Error("Failed to create VAO.");if(a=i.createBuffer(),null==a)throw new Error("Failed to create vertex buffer.");if(c=i.createBuffer(),null==c)throw new Error("Failed to create index buffer.");i.bindVertexArray(s),i.bindBuffer(i.ARRAY_BUFFER,a),i.bufferData(i.ARRAY_BUFFER,t,i.STATIC_DRAW);const _=Object(o.f)(e);i.vertexAttribPointer(o.b,3,i.FLOAT,!0,_,0),i.enableVertexAttribArray(o.b);const m=Object(o.e)(e);-1!==m&&(i.vertexAttribPointer(o.a,3,i.FLOAT,!0,_,m),i.enableVertexAttribArray(o.a));const l=Object(o.g)(e);return-1!==l&&(i.vertexAttribPointer(o.c,2,i.UNSIGNED_SHORT,!0,_,l),i.enableVertexAttribArray(o.c)),i.bindBuffer(i.ARRAY_BUFFER,null),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,c),i.bufferData(i.ELEMENT_ARRAY_BUFFER,r,i.STATIC_DRAW),i.bindVertexArray(null),null==n||n.upload(),{vao:s,vertex_buffer:a,index_buffer:c}}catch(e){throw i.deleteVertexArray(s),i.deleteBuffer(a),i.deleteBuffer(c),e}}destroy_gfx_mesh(e){if(e){const t=this.gl;t.deleteVertexArray(e.vao),t.deleteBuffer(e.vertex_buffer),t.deleteBuffer(e.index_buffer)}}create_texture(e,t,r,n){const o=this.gl,i=o.getExtension("WEBGL_compressed_texture_s3tc");if(!i)throw new Error("Extension WEBGL_compressed_texture_s3tc not supported.");const s=o.createTexture();if(null==s)throw new Error("Failed to create texture.");let a;switch(e){case h.b.RGBA_S3TC_DXT1:a=i.COMPRESSED_RGBA_S3TC_DXT1_EXT;break;case h.b.RGBA_S3TC_DXT3:a=i.COMPRESSED_RGBA_S3TC_DXT3_EXT}return o.bindTexture(o.TEXTURE_2D,s),o.compressedTexImage2D(o.TEXTURE_2D,0,a,t,r,0,new Uint8Array(n)),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),o.bindTexture(o.TEXTURE_2D,null),s}destroy_texture(e){null!=e&&this.gl.deleteTexture(e)}}class d extends l.a{constructor(e){super(e);const t=this.canvas_element.getContext("webgl2");if(null==t)throw new Error("Failed to initialize webgl2 context.");this.gl=t,this.gfx=new u(t),t.enable(t.DEPTH_TEST),t.clearColor(.1,.1,.1,1),this.shader_programs=[],this.shader_programs[o.d.PosNorm]=new i(t,a,c),this.shader_programs[o.d.PosTex]=new i(t,_,m),this.set_size(800,600)}dispose(){for(const e of this.shader_programs)e.delete();super.dispose()}set_size(e,t){this.canvas_element.width=e,this.canvas_element.height=t,this.gl.viewport(0,0,e,t),super.set_size(e,t)}render(){const e=this.gl;e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT),this.scene.traverse((t,r)=>{var o;const i=Object(n.e)(r,t.transform);if(t.mesh){const r=this.shader_programs[t.mesh.format];r.bind(),r.set_mat_projection_uniform(this.camera.projection_matrix),r.set_mat_model_view_uniform(i),r.set_mat_normal_uniform(i.normal_mat3()),(null===(o=t.mesh.texture)||void 0===o?void 0:o.gfx_texture)&&(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,t.mesh.texture.gfx_texture),r.set_texture_uniform(e.TEXTURE0));const n=t.mesh.gfx_mesh;e.bindVertexArray(n.vao),e.drawElements(e.TRIANGLES,t.mesh.index_count,e.UNSIGNED_SHORT,0),e.bindVertexArray(null),e.bindTexture(e.TEXTURE_2D,null),r.unbind()}return i},this.camera.view_matrix)}render_node(e,t){var r;const o=this.gl,i=Object(n.e)(t,e.transform);if(e.mesh){const t=this.shader_programs[e.mesh.format];t.bind(),t.set_mat_projection_uniform(this.camera.projection_matrix),t.set_mat_model_view_uniform(i),t.set_mat_normal_uniform(i.normal_mat3()),(null===(r=e.mesh.texture)||void 0===r?void 0:r.gfx_texture)&&(o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,e.mesh.texture.gfx_texture),t.set_texture_uniform(o.TEXTURE0));const n=e.mesh.gfx_mesh;o.bindVertexArray(n.vao),o.drawElements(o.TRIANGLES,e.mesh.index_count,o.UNSIGNED_SHORT,0),o.bindVertexArray(null),o.bindTexture(o.TEXTURE_2D,null),t.unbind()}for(const t of e.children)this.render_node(t,i)}}}}]);