text: (function(Z){function z(){}function M(){this.code="function update(dt) {\n\n}";this.exported_callbacks=[];this.extracode="";this.extra_methods=null}function Ka(a,b){this.name=a;this.macros={};this.hooks={};if(b)for(var c in b)this.macros[c]=b[c]}function Za(a){this.flag_id=-1;this.flag_mask=0;if(!a)throw"ShaderBlock must have a name";this.name=a;this.code_map=new Map}function s(a){this.uid=e.generateUId("MAT-");this._dirty=!0;this._color=new Float32Array([1,1,1,1]);this.createProperty("diffuse",new Float32Array([1,
  1,1]),"color");this.blend_mode=e.Blend.NORMAL;this.alpha_test_shadows=this.alpha_test=!1;this.uvs_matrix=new Float32Array([1,0,0,0,1,0,0,0,1]);this.textures={};this._query=new Ka;Object.defineProperty(this,"color",{get:function(){return this._color.subarray(0,3)},set:function(a){vec3.copy(this._color,a)},enumerable:!0});Object.defineProperty(this,"opacity",{get:function(){return this._color[3]},set:function(a){this._color[3]=a},enumerable:!0});a&&this.configure(a)}function P(a){s.call(this,null);
  this.shader_name="global";this.createProperty("ambient",new Float32Array([1,1,1]),"color");this.createProperty("emissive",new Float32Array(3),"color");this.backlight_factor=0;this._specular_data=vec2.fromValues(0.1,10);this.specular_ontop=!1;this.reflection_factor=0;this.reflection_fresnel=1;this.reflection_specular=this.reflection_additive=!1;this.createProperty("velvet",new Float32Array([0.5,0.5,0.5]),"color");this.velvet_exp=0;this.velvet_additive=!1;this._velvet_info=vec4.create();this._detail=
  new Float32Array([0,10,10]);this._extra_data=vec4.create();this.normalmap_factor=1;this.normalmap_tangent=!0;this.displacementmap_factor=0.1;this.bumpmap_factor=1;this.use_scene_ambient=!0;this.extra_surface_shader_code="";this.extra_uniforms={};a&&this.configure(a)}function $(a){s.call(this,null);this.shader_name="base";this.vs_code="";this.code="void surf(in Input IN, inout SurfaceOutput o) {\n\to.Albedo = vec3(1.0) * IN.color.xyz;\n\to.Normal = IN.worldNormal;\n\to.Emission = vec3(0.0);\n\to.Specular = 1.0;\n\to.Gloss = 40.0;\n\to.Reflectivity = 0.0;\n\to.Alpha = IN.color.a;\n}\n";
  this._uniforms={};this.properties=[];a&&this.configure(a);this.flags=0;this.computeCode()}function aa(a){s.call(this,null);this.shader_name="surface";this.vs_code="";this.code="void surf(in Input IN, inout SurfaceOutput o) {\n\to.Albedo = vec3(1.0) * IN.color.xyz;\n\to.Normal = IN.worldNormal;\n\to.Emission = vec3(0.0);\n\to.Specular = 1.0;\n\to.Gloss = 40.0;\n\to.Reflectivity = 0.0;\n\to.Alpha = IN.color.a;\n}\n";this._uniforms={};this._samplers=[];this.properties=[];a&&this.configure(a);this.flags=
  0;this.computeCode()}function ra(a){s.call(this,null);this._shader=null;this.flags=0;this._uniforms={};this._samplers=[];this._properties=[];this._properties_by_name={};a&&this.configure(a)}function sa(){this._components=[];this._missing_components=null}function W(){}function Aa(a){a&&this.configure(a)}function ta(){this._data=this.remotepath=this.fullpath=this.filename=null}function U(a){this.name="";this.takes={};a&&this.configure(a)}function ga(a){this.name=null;this.tracks=[];this.duration=e.Animation.DEFAULT_DURATION;
  a&&this.configure(a)}function T(a){this.enabled=!0;this.name="";this.type=null;this.interpolation=e.NONE;this.packed_data=this.looped=!1;this.value_size=0;this.data_table=this.data=null;Object.defineProperty(this,"_property",{value:"",enumerable:!1,writable:!0});Object.defineProperty(this,"_property_path",{value:[],enumerable:!1,writable:!0});a&&this.configure(a)}function ka(a){this.resource_names=[];this.prefab_data=this.prefab_json=null;this._resources_data={};a&&this.configure(a)}function Ba(a){this.resource_names=
  [];this._data={};this._resources_data={};a&&this.configure(a)}function R(a){this._init_function=this._code=null;this._global_uniforms={};this._code_parts={};this._subfiles={};this._compiled_shaders={};this._shaderblock_flags_num=0;this._shaderblock_flags={};a&&(this.code=a)}function la(){this.points=[];this.closed=!1;this.type=la.LINE}function ua(a){this.apply_fxaa=!1;this.filter=!0;this.fx=[];this._uniforms={u_aspect:1,u_viewport:vec2.create(),u_iviewport:vec2.create(),u_texture:0,u_texture_depth:1,
  u_random:vec2.create()};a&&this.configure(a)}function La(a){this.renderer_name=null;this.default_shadowmap_resolution=e.RenderSettings.default_shadowmap_resolution;this.linear_pipeline=this.keep_viewport=this.ignore_clear=this.ignore_viewports=!1;this.update_shadowmaps=this.shadows_enabled=!0;this.low_quality=this.lights_disabled=this.force_wireframe=this.update_all_shadowmaps=!1;this.render_helpers=this.render_gui=this.render_fx=this.render_all_cameras=this.update_materials=!0;this.layers=255;this.sort_instances_by_priority=
  this.sort_instances_by_distance=!0;this.z_pass=!1;this.depth_test=this.frustum_culling=!0;this.clipping_plane=null;this.in_player=!0;this.default_shader_id="global";this.default_low_shader_id="lowglobal";a&&this.configure(a)}function ba(a,b){this._key="";this.uid=e.generateUId("RINS");this.layers=3;this.index=-1;this.vertex_buffers={};this.wireframe_index_buffer=this.index_buffer=null;this.range=new Int32Array([0,-1]);this.primitive=gl.TRIANGLES;this.lod_mesh=this.collision_mesh=this.mesh=null;this.lod_vertex_buffers=
  {};this.lod_index_buffer=null;this.node=a;this.component=b;this.priority=10;this.flags=xa;this.blend_func=e.BlendFunctions.normal;this.matrix=mat4.create();this.normal_matrix=mat4.create();this.center=vec3.create();this.oobb=BBox.create();this.aabb=BBox.create();this.material=null;this.query=new e.ShaderQuery;this.uniforms={};this.samplers=[];this.shader_blocks=[];this._camera_visibility=0;this._is_visible=!1;this._dist=0;this._final_query=new e.ShaderQuery}function N(a){this.height=this.width=0;
  this.precision=N.DEFAULT_PRECISION;this.filter_texture=!0;this.use_depth_texture=!1;this.num_extra_textures=0;this.name=null;this.adjust_aspect=!1;this._depth_texture=this._color_texture=this._fbo=null;this._textures=[];a&&this.configure(a)}function Da(){this.debug_points=[];this._points=[];this._points_color=[];this._points_nodepth=[];this._points_color_nodepth=[];this._lines=[];this._lines_color=[];this._names=[];this.grid_texture_url="imgs/grid.png";this.camera2D=new e.Camera({eye:[0,0,0],center:[0,
  0,-1]});this.createMeshes();this.colors={selected:vec4.fromValues(1,1,1,1),node:vec4.fromValues(1,0.5,0,1),bone:vec4.fromValues(1,0,0.5,1)};this.settings={render_grid:!0,grid_scale:1,grid_alpha:0.5,grid_plane:"xz",render_names:!1,render_skeletons:!0,render_tree:!1,render_components:!0,render_null_nodes:!0,render_axis:!1,render_colliders:!0,render_paths:!0,render_origin:!0,render_colliders_aabb:!1}}function eb(){this.shader_block=null;this.macros={};this.uniforms={}}function ab(a,b,c,d,f){this.position=
  vec3.create();c&&this.position.set(c);this.node=a||null;this.instance=b||null;this.distance=d||0;this.normal=f}function Ca(a,b){this.uid=e.generateUId("PHSX");this.layers=3;this.type=Ca.BOX;this.mesh=null;this.node=a;this.component=b;this.matrix=mat4.create();this.center=vec3.create();this.oobb=BBox.create();this.aabb=BBox.create()}function w(a){this._data=new Float32Array(10);this._position=this._data.subarray(0,3);this._rotation=this._data.subarray(3,7);quat.identity(this._rotation);this._scaling=
  this._data.subarray(7,10);this._scaling[0]=this._scaling[1]=this._scaling[2]=1;this._local_matrix=mat4.create();this._global_matrix=mat4.create();this._must_update_matrix=!1;this._version=0;a&&this.configure(a)}function y(a){this.enabled=!0;this.layers=3;this.clear_depth=this.clear_color=!0;this._type=y.PERSPECTIVE;this._eye=vec3.fromValues(0,100,100);this._center=vec3.fromValues(0,0,0);this._up=vec3.fromValues(0,1,0);this._global_eye=vec3.fromValues(0,100,100);this._global_center=vec3.fromValues(0,
  0,0);this._global_up=vec3.fromValues(0,1,0);this._global_front=vec3.fromValues(0,0,-1);this._near=1;this._far=1E3;this._ortho=new Float32Array([-1,1,-1,1]);this._aspect=1;this._fov=45;this._frustum_size=50;this._final_aspect=1;this._viewport=new Float32Array([0,0,1,1]);this._viewport_in_pixels=vec4.create();this._background_color=vec4.fromValues(0,0,0,1);this._view_matrix=mat4.create();this._projection_matrix=mat4.create();this._viewprojection_matrix=mat4.create();this._model_matrix=mat4.create();
  this._previous_viewprojection_matrix=mat4.create();this._must_update_projection_matrix=this._must_update_view_matrix=!0;this._rendering_index=-1;this._frame=null;a&&this.configure(a);this._uniforms={u_view:this._view_matrix,u_viewprojection:this._viewprojection_matrix,u_camera_eye:this._global_eye,u_camera_front:this._global_front,u_camera_planes:vec2.fromValues(this.near,this.far),u_camera_perspective:vec3.create(),u_background_color:this._background_color,u_previous_viewprojection:this._previous_viewprojection_matrix};
  this.updateMatrices();this._frustum_planes=geo.extractPlanes(this._viewprojection_matrix)}function ca(a){this.enabled=!0;this.fx=new e.TextureFX(a?a.fx:null);this.frame=new e.RenderFrameContext;this.use_antialiasing=!1;this.shader_material=null;a&&this.configure(a)}function ma(a){this.enabled=!0;this.fx=new e.TextureFX(a?a.fx:null);this.frame=new e.RenderFrameContext;this.use_antialiasing=!1;this.shader_material=null;a&&this.configure(a)}function A(a){this._position=vec3.create();this._target=vec3.fromValues(0,
  0,1);this._up=vec3.fromValues(0,1,0);this.enabled=!0;this.near=1;this.far=500;this.angle=45;this.angle_end=60;this.constant_diffuse=!1;this.use_specular=!0;this.linear_attenuation=!1;this.range_attenuation=!0;this.att_start=0;this.att_end=1E3;this.offset=0;this.spot_cone=!0;this.projective_texture=null;this._attenuation_info=new Float32Array([this.att_start,this.att_end]);this.use_target=!1;this._color=vec3.fromValues(1,1,1);this.intensity=1;this.cast_shadows=!1;this.shadow_bias=0.05;this.shadowmap_resolution=
  0;this.type=A.OMNI;this.frustum_size=50;this.extra_texture=this.extra_light_shader_code=null;this._front=vec3.clone(A.FRONT_VECTOR);this._right=vec3.clone(A.RIGHT_VECTOR);this._top=vec3.clone(A.UP_VECTOR);this._query=new Ka;this._uniforms={};this._samplers=[];a&&(this.configure(a),void 0!==a.shadowmap_resolution&&(this.shadowmap_resolution=parseInt(a.shadowmap_resolution)))}function S(a){this.enabled=!0;this.lod_mesh=this.mesh=null;this.submesh_id=-1;this.material=null;this._primitive=-1;this.two_sided=
  !1;this.point_size=0.1;this.textured_points=!1;this.material=null;this._must_update_static=!0;this._transform_version=-1;this.use_submaterials=!1;this.submaterials=[];a&&this.configure(a);this._RI=new e.RenderInstance(null,this);S._identity||(S._identity=mat4.create())}function K(a){this.apply_skinning=this.enabled=!0;this.cpu_skinning=!1;this.lod_mesh=this.mesh=null;this.submesh_id=-1;this.material=null;this._primitive=-1;this.point_size=0.1;this.two_sided=!1;this.ignore_transform=!0;K.num_supported_uniforms||
  (K.num_supported_uniforms=gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS),K.num_supported_textures=gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS),K.num_supported_uniforms<3*K.MAX_BONES&&0==K.num_supported_textures&&(K.gpu_skinning_supported=!1));a&&this.configure(a);S._identity||(S._identity=mat4.create())}function L(a){this.enabled=!0;this.morph_targets=[];void 0===L.max_supported_vertex_attribs&&(L.max_supported_vertex_attribs=gl.getParameter(gl.MAX_VERTEX_ATTRIBS));void 0===L.max_supported_morph_targets&&
  (L.max_supported_morph_targets=(gl.getParameter(gl.MAX_VERTEX_ATTRIBS)-6)/2);a&&this.configure(a)}function B(a){this.enabled=!0;this.search_bones_in_parent=!1;this.skeleton_root_node=null;this.cpu_skinning=!1;this.ignore_transform=!0;this._mesh=null;B._initialized||(B.num_supported_uniforms=gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS),B.num_supported_textures=gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS),B.num_supported_uniforms<3*B.MAX_BONES&&0==B.num_supported_textures&&(B.gpu_skinning_supported=
  !1),B._initialized=!0);a&&this.configure(a)}function Ia(a){this.enabled=!0;this.texture=null;this.intensity=1;this.material=null;this.use_environment=!0;a&&this.configure(a)}function Ga(a){this.enabled=!0;this.texture=null;this.createProperty("color",vec3.fromValues(1,1,1),"color");this.opacity=1;this.blend_mode=va.NORMAL;this.material_name=null;a&&this.configure(a)}function ea(a){this.enabled=!0;this.shape=1;this.mesh=null;this.size=vec3.fromValues(0.5,0.5,0.5);this.center=vec3.create();this.use_mesh_bounding=
  !1;a&&this.configure(a)}function Ha(a){this.properties=[];a&&this.configure(a)}function Ea(a){this.enabled=!0;this.texture=null;this.blend_mode=e.Blend.ALPHA;this.size=vec2.fromValues(100,100);this.frame=null;this.flip_x=!1;this._atlas_component=this._atlas=null;a&&this.configure(a)}function ha(a){this.enabled=!0;this.texture=null;this.areas=[];this._sprites=[];this._max_sprites=256;a&&this.configure(a)}function ia(a){this.text="";this.notes=[];this._screen_pos=vec3.create();this._selected=null;this.configure(a)}
  function Ua(a){this.speed=10;this.axis=[0,1,0];this.local_space=!0;this.swing=!1;this.swing_amplitude=45;a&&this.configure(a)}function X(a){this.enabled=!0;this.speed=10;this.wheel_speed=this.rot_speed=1;this.smooth=!1;this.allow_panning=!0;this.mode=X.ORBIT;this._moving=vec3.fromValues(0,0,0);this._collision=vec3.create();this.configure(a)}function Ra(a){this.rot_speed=[1,1];this.smooth=!1;a&&this.configure(a)}function H(a){this.enabled=!0;this.node_id=null;this.cylindrical=this.face_camera=!1;this.front=
  H.NEGZ;this.up=H.POSY;this._target_position=vec3.create();a&&this.configure(a)}function fa(a){this.enabled=!0;this.start=100;this.end=1E3;this.density=0.001;this.type=fa.LINEAR;this.color=vec3.fromValues(0.5,0.5,0.5);a&&this.configure(a)}function Va(a){this.node_uid="";this.follow_camera=this.fixed_y=!1;a&&this.configure(a)}function J(a){this.enabled=!0;this.subdivisions=this.size=10;this.point_size=0.1;this._geometry=J.CUBE;this._primitive=-1;this.align_z=!1;a&&this.configure(a)}function wa(a){this.createProperty("ambient_color",
  wa.DEFAULT_AMBIENT_COLOR,"color");this._render_settings=new e.RenderSettings;this._textures={};a&&this.configure(a)}function na(a){this.enabled=!0;this.force_redraw=!1;this.on_event="update";if("undefined"==typeof LGraphTexture)return console.error("Cannot use GraphComponent if LiteGraph is not installed");this._graph=new LGraph;this._graph.getScene=function(){return this._scene||e.GlobalScene};a?this.configure(a):(a=this._default_node=LiteGraph.createNode("scene/node"),this._graph.add(a));LEvent.bind(this,
  "trigger",this.trigger,this)}function V(a){this.enabled=!0;this.frame=new e.RenderFrameContext;this.use_node_camera=this.use_antialiasing=!1;if("undefined"==typeof LGraphTexture)return console.error("Cannot use FXGraphComponent if LiteGraph is not installed");this._graph=new LGraph;this._graph.getScene=function(){return this._scene};a?this.configure(a):(this._graph_frame_node=LiteGraph.createNode("scene/frame","Rendered Frame"),this._graph_frame_node.ignore_remove=!0,this._graph_frame_node.ignore_rename=
  !0,this._graph.add(this._graph_frame_node),this._graph_viewport_node=LiteGraph.createNode("texture/toviewport","Viewport"),this._graph_viewport_node.pos[0]=500,this._graph.add(this._graph_viewport_node),this._graph_frame_node.connect(0,this._graph_viewport_node));null==V.high_precision_format&&(V.high_precision_format=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.float_ext?gl.FLOAT:gl.UNSIGNED_BYTE)}function $a(){this.id=0;this._pos=vec3.fromValues(0,0,0);this._vel=vec3.fromValues(0,0,0);this.life=1;this.angle=
  0;this.size=1;this.rot=0}function O(a){this.enabled=!0;this.max_particles=1024;this.warm_up_time=0;this.point_particles=!1;this.emissor_type=O.BOX_EMISSOR;this.emissor_rate=5;this.emissor_size=vec3.fromValues(10,10,10);this.emissor_mesh=null;this.particle_life=5;this.particle_speed=10;this.particle_size=5;this.particle_rotation=0;this.particle_size_curve=[[1,1]];this._particle_start_color=vec3.fromValues(1,1,1);this._particle_end_color=vec3.fromValues(1,1,1);this.particle_opacity_curve=[[0.5,1]];
  this.texture_grid_size=1;this._custom_update_code=this._custom_emissor_code=null;this.physics_gravity=[0,0,0];this.physics_friction=0;this.opacity=1;this.additive_blending=!1;this.texture=null;this.animation_fps=1;this.premultiplied_alpha=this.independent_color=this.loop_animation=this.animated_texture=this.use_node_material=this.soft_particles=!1;this.align_with_camera=!0;this.follow_emitter=this.align_always=!1;this.sort_in_z=!0;this.stop_update=!1;a&&this.configure(a);"number"==typeof this.emissor_size&&
  (this.emissor_size=[this.emissor_size,this.emissor_size,this.emissor_size]);this._emissor_pos=vec3.create();this._particles=[];this._visible_particles=this._remining_dt=0;this._min_particle_size=0.001;this._last_id=0;this.createMesh()}function Na(a){this.className=this.text="";this.use_html=!1;this._world_pos=vec3.create();this._screen_pos=vec3.create();this.configure(a)}function Q(a){this.enabled=!0;this.max_points=1024;this.mesh=null;this._points=[];this.texture_grid_size=this.size=1;this.texture=
  null;this.global_opacity=1;this.color=vec3.fromValues(1,1,1);this.sort_in_z=this.in_world_coordinates=this.premultiplied_alpha=this.use_node_material=this.additive_blending=!1;this.serialize_points=!0;a&&this.configure(a);this._last_id=0;this.createMesh()}function da(a){this.enabled=!0;this.max_lines=1024;this._lines=[];this.global_opacity=1;this.color=vec3.fromValues(1,1,1);this.in_world_coordinates=this.premultiplied_alpha=this.use_node_material=this.additive_blending=!1;a&&this.configure(a);this._last_id=
  0;this.createMesh()}function F(a){this.enabled=!0;this.animation="";this.take="default";this.root_node="@";this.playback_speed=1;this.mode=F.LOOP;this.playing=!0;this._last_time=this.current_time=0;this.range=null;this.disabled_tracks={};a&&this.configure(a)}function Oa(a){this.enabled=!0;this.texture_size=512;this.clip_offset=0.5;this.texture_name="";this.all_cameras=this.use_cubemap=!1;this.blur=0;this.use_mesh_info=this.generate_mipmaps=!1;this.offset=vec3.create();this.ignore_this_mesh=!0;this.high_precision=
  !1;this.refresh_rate=1;this.layers=255;this._textures={};a&&this.configure(a)}function x(a){this.enabled=!0;this.code=this.constructor.templates.component;this._script=new M;this._script.extra_methods={getComponent:function(){return this}.bind(this),getLocator:function(){return this.getComponent().getLocator()+"/context"},createProperty:e.Component.prototype.createProperty,createAction:e.Component.prototype.createAction,bind:e.Component.prototype.bind,unbind:e.Component.prototype.unbind,unbindAll:e.Component.prototype.unbindAll};
  this._script.onerror=this.onError.bind(this);this._script.exported_functions=[];this._last_error=null;a&&this.configure(a)}function oa(a){this.enabled=!0;this._filename="";this._script=new M;this._script.extra_methods={getComponent:function(){return this}.bind(this),getLocator:function(){return this.getComponent().getLocator()+"/context"},createProperty:e.Component.prototype.createProperty,createAction:e.Component.prototype.createAction,bind:e.Component.prototype.bind,unbind:e.Component.prototype.unbind,
  unbindAll:e.Component.prototype.unbindAll};this._script.onerror=this.onError.bind(this);this._script.exported_functions=[];this._last_error=null;a&&this.configure(a)}function ja(a){this.height=2;this.size=10;this.subdivisions=100;this.heightmap="";this._primitive=-1;this.auto_update=!0;this.action="Update";this._mesh=null;a&&this.configure(a)}function D(a){this.enabled=!0;this.createProperty("count",vec3.fromValues(10,1,1));this.createProperty("size",vec3.fromValues(100,100,100));this.material=this.lod_mesh=
  this.mesh=null;this.mode=D.GRID_MODE;a&&this.configure(a);D._identity||(D._identity=mat4.create())}function pa(a){this.enabled=!0;this._num_id=e._last_uid++;this.radius=10;this.center=vec3.create();this.factor=0.5;this._uniforms_code=pa._uniforms_code.replaceAll({"@":this._num_id});this._code=pa._code.replaceAll({"@":this._num_id});a&&this.configure(a)}function Ja(a){this.enabled=!0;this.eye_distance=1;a&&this.configure(a)}function Pa(a){this.poses={};a&&this.configure(a)}function ya(a){this.autoclear=
  this.enabled=!0;this._code=ya.default_code;"undefined"==typeof THREE?this.loadLibrary(function(){this.setupContext()}):this.setupContext();this._script=new M;this._script.catch_exceptions=!1;a&&this.configure(a)}function Y(a){this.enabled=!0;this.mode=Y.PICKING;this.layers=3;this._last_collision=null;a&&this.configure(a)}function C(){this.uid=e.generateUId("TREE-");this._root=new e.SceneNode("root");this._root.removeAllComponents();this._root._is_root=!0;this._root._in_tree=this;this._nodes=[this._root];
  this._nodes_by_name={root:this._root};this._nodes_by_uid={};this._nodes_by_uid[this._root.uid]=this._root;this._instances=[];this._lights=[];this._cameras=[];this._colliders=[];this.external_scripts=[];this.global_scripts=[];this.preloaded_resources={};this.animation=null;this._paths=[];this._local_resources={};this.layer_names=["main","secondary"];LEvent.bind(this,"treeItemAdded",this.onNodeAdded,this);LEvent.bind(this,"treeItemRemoved",this.onNodeRemoved,this);this.init()}function I(a){a&&a.constructor!==
  String&&(a=null,console.warn("SceneNode constructor first parameter must be a String with the name"));this._name=a||"node_"+(1E4*Math.random()).toFixed(0);this._uid=e.generateUId("NODE-");this._classList={};this.layers=3;this._material=this._prefab=this.node_type=null;this._components=[];this._in_tree=this._children=this._parentNode=this._missing_components=null;this.flags={visible:!0,is_static:!1,selectable:!0,two_sided:!1,flip_normals:!1,cast_shadows:!0,receive_shadows:!0,ignore_lights:!1,depth_test:!0,
  depth_write:!0};this.init(!1,!0)}function qa(a){this.options=a=a||{};if(!a.canvas){var b=a.container;a.container_id&&(b=document.getElementById(a.container_id));b||(console.log("No container specified in LS.Player, using BODY as container"),b=document.body);var c=document.createElement("canvas");c.width=b.offsetWidth;c.height=b.offsetHeight;c.width||(c.width=a.width||1);c.height||(c.height=a.height||1);b.appendChild(c);a.canvas=c}this.debug=!1;this.gl=GL.create(a);this.canvas=this.gl.canvas;this.render_settings=
  new e.RenderSettings;this.scene=e.GlobalScene;this.autoplay=void 0!==a.autoplay?a.autoplay:!0;a.debug?(this.debug=!0,this.enableDebug()):e.catch_exceptions=!0;a.resources?e.ResourcesManager.setPath(a.resources):console.warn("LS: no resources path specified");e.ShadersManager.init(a.shaders||"data/shaders.xml");a.shaders||console.warn("LS: no shaders folder specified, using default file.");a.proxy&&e.ResourcesManager.setProxy(a.proxy);if(a.filesystems)for(var d in a.filesystems)e.ResourcesManager.registerFileSystem(d,
  a.filesystems[d]);a.autoresize&&window.addEventListener("resize",function(){this.canvas.width=c.parentNode.offsetWidth;this.canvas.height=c.parentNode.offsetHeight}.bind(this));a.loadingbar&&(this.loading={visible:!0,scene_bar:0,resources_bar:0},LEvent.bind(e.ResourcesManager,"start_loading_resources",function(a,b){this.loading.resources_bar=0}.bind(this)),LEvent.bind(e.ResourcesManager,"loading_resources_progress",function(a,b){this.loading.resources_bar<b&&(this.loading.resources_bar=b)}.bind(this)),
  LEvent.bind(e.ResourcesManager,"end_loading_resources",function(a,b){this._total_loading=void 0;this.loading.resources_bar=1;this.loading.visible=!1}.bind(this)));e.Renderer.init();this.force_redraw=a.redraw||!1;this.state=e.Player.STOPPED;if(this.gl.ondraw)throw"There is already a litegl attached to this context";this.gl.ondraw=e.Player.prototype._ondraw.bind(this);this.gl.onupdate=e.Player.prototype._onupdate.bind(this);a=e.Player.prototype._onmouse.bind(this);this.gl.onmousedown=a;this.gl.onmousemove=
  a;this.gl.onmouseup=a;this.gl.onmousewheel=a;a=e.Player.prototype._onkey.bind(this);this.gl.onkeydown=a;this.gl.onkeyup=a;a=e.Player.prototype._ongamepad.bind(this);this.gl.ongamepadconnected=a;this.gl.ongamepaddisconnected=a;this.gl.ongamepadButtonDown=a;this.gl.ongamepadButtonUp=a;gl.captureMouse(!0);gl.captureKeys(!0);gl.captureGamepads(!0);e.Input.init();gl.animate()}z.classes={};z.HEADER_SIZE=64;z.FOUR_CC="WBIN";z.VERSION=0.3;z.CLASSNAME_SIZE=32;z.LUMPNAME_SIZE=54;z.LUMPHEADER_SIZE=10+z.LUMPNAME_SIZE;
  z.CODES={ArrayBuffer:"AB",Int8Array:"I1",Uint8Array:"i1",Int16Array:"I2",Uint16Array:"i2",Int32Array:"I4",Uint32Array:"i4",Float32Array:"F4",Float64Array:"F8",Object:"OB",WideObject:"WO",String:"ST",WideString:"WS",Number:"NU","null":"00"};z.REVERSE_CODES={};for(var bb in z.CODES)z.REVERSE_CODES[z.CODES[bb]]=bb;z.FULL_BINARY=1;z.isWBin=function(a){a=a.subarray(0,4);for(var b=0;b<a.length;b++)if(0!=a[b]&&a[b]!=z.FOUR_CC.charCodeAt(b))return!1;return!0};z.create=function(a,b){if(!a)throw"WBin null origin passed";
  var c=new Uint8Array([0,0]),d=new Uint8Array((new Float32Array([z.VERSION])).buffer);b=b||"";if(a.toBinary){var f=a.toBinary();if(!f)return null;if(f.constructor==ArrayBuffer){c[0]|=z.FULL_BINARY;var g=z.getObjectClassName(a),e=new Uint8Array(z.HEADER_SIZE+f.length);e.set(z.stringToUint8Array(z.FOUR_CC));e.set(d,4);e.set(c,8);e.set(z.stringToUint8Array(g,z.CLASSNAME_SIZE),14);e.set(f,z.HEADER_SIZE);return e}a=f}var k=z.HEADER_SIZE,f=[],m=0,l;for(l in a)if(e=a[l],null!=e){if(e.constructor===Blob||
  e.constructor===File)throw"Wbin does not allow Blobs or Files as data to store, conver to ArrayBuffer";g=z.getObjectClassName(e);(g=z.CODES[g])||(g="OB");"NU"==g?e=new Float64Array([e]):"OB"==g&&(e=JSON.stringify(e));var p=0;e&&e.constructor==String&&(e=z.stringToTypedArray(e),e.constructor===Uint16Array&&(g="OB"==g?"WO":"WS"));if(e.buffer&&e.buffer.constructor==ArrayBuffer)e=new Uint8Array(new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),p=e.byteLength;else if(e.constructor==ArrayBuffer)p=e.byteLength;
  else throw"WBin: cannot be anything different to ArrayBuffer";var n=l.substring(0,z.LUMPNAME_SIZE);n.length<l.length&&console.error("Lump name is too long (max is "+z.LUMPNAME_SIZE+"), it has been cut down, this could lead to an error in the future");f.push({code:g,name:n,data:e,start:m,size:p});m+=p;k+=z.LUMPHEADER_SIZE+p}e=new Uint8Array(k);e.set(z.stringToUint8Array(z.FOUR_CC));e.set(d,4);e.set(c,8);e.set(new Uint8Array((new Uint16Array([f.length])).buffer),10);b&&e.set(z.stringToUint8Array(b,
  z.CLASSNAME_SIZE),12);var c=z.HEADER_SIZE+f.length*z.LUMPHEADER_SIZE,d=z.HEADER_SIZE,q;for(q in f)l=f[q],k=new Uint8Array(z.LUMPHEADER_SIZE),k.set(new Uint8Array((new Uint32Array([l.start])).buffer),0),k.set(new Uint8Array((new Uint32Array([l.size])).buffer),4),k.set(z.stringToUint8Array(l.code,2),8),k.set(z.stringToUint8Array(l.name,z.LUMPNAME_SIZE),10),e.set(k,d),d+=z.LUMPHEADER_SIZE,k=new Uint8Array(l.data),e.set(k,c+l.start);return e};z.load=function(a,b){if(!a||a.constructor!==Uint8Array&&a.constructor!==
  ArrayBuffer)throw"WBin data must be ArrayBuffer or Uint8Array";a=new Uint8Array(a);var c=z.getHeaderInfo(a);if(!c)return console.error("Wrong WBin Header"),null;c.version>(new Float32Array([z.VERSION]))[0]&&console.log("ALERT: WBin version is higher that code version");var d=null,f;for(f in c.lumps){d||(d={});var g=c.lumps[f],e=c.lump_data.subarray(g.start,g.start+g.size);if(g.size!=e.length)throw"WBin: incorrect wbin lump size";var k=null,m=z.REVERSE_CODES[g.code];if(!m)throw"WBin: Incorrect data code";
  switch(m){case "null":break;case "WideString":e=new Uint16Array((new Uint8Array(e)).buffer);case "String":k=z.TypedArrayToString(e);break;case "Number":k=0.3>c.version?parseFloat(z.TypedArrayToString(e)):(new Float64Array(e.buffer))[0];break;case "WideObject":e=new Uint16Array((new Uint8Array(e)).buffer);case "Object":k=JSON.parse(z.TypedArrayToString(e));break;case "ArrayBuffer":k=(new Uint8Array(e)).buffer;break;default:e=new Uint8Array(e);k=z.classes[m]||window[m];if(!k)throw"WBin referenced class not found: "+
  m;if(0!=e.length/k.BYTES_PER_ELEMENT%1)throw"WBin: size do not match type";k=new k(e.buffer)}d[g.name]=k}if(!b&&c.classname){if((k=z.classes[c.classname]||window[c.classname])&&k.fromBinary)return k.fromBinary(d);if(k&&k.prototype.fromBinary)return c=new k,c.fromBinary(d),c;d["@classname"]=c.classname}return d};z.getHeaderInfo=function(a){for(var b=a.subarray(0,4),c=0;c<b.length;c++)if(0!=b[c]&&b[c]!=z.FOUR_CC.charCodeAt(c))return null;for(var b=z.readFloat32(a,4),d=new Uint8Array(a.subarray(8,10)),
  f=z.readUint16(a,10),g=z.TypedArrayToString(a.subarray(12,12+z.CLASSNAME_SIZE)),e=[],c=0;c<f;++c){var k=z.HEADER_SIZE+c*z.LUMPHEADER_SIZE,k=a.subarray(k,k+z.LUMPHEADER_SIZE),m={};m.start=z.readUint32(k,0);m.size=z.readUint32(k,4);m.code=z.TypedArrayToString(k.subarray(8,10));m.name=z.TypedArrayToString(k.subarray(10));e.push(m)}a=a.subarray(z.HEADER_SIZE+f*z.LUMPHEADER_SIZE);return{version:b,flags:d,classname:g,numlumps:f,lumps:e,lump_data:a}};z.getObjectClassName=function(a){if(a&&a.constructor&&
  a.constructor.toString&&(a=a.constructor.toString().match(/function\s*(\w+)/))&&2==a.length)return a[1]};z.stringToUint8Array=function(a,b){for(var c=new Uint8Array(b?b:a.length),d=!1,f=0;f<a.length;f++){var g=a.charCodeAt(f);255<g&&(d=!0);c[f]=g}d&&console.warn("WBin: there are characters in the string that cannot be encoded in 1 byte.");return c};z.TypedArrayToString=function(a,b){for(var c="",d=0;d<a.length;d++)if(0!=a[d]||b)c+=String.fromCharCode(a[d]);else break;return c};z.stringToTypedArray=
  function(a,b){for(var c=new Uint8Array(b?b:a.length),d=!1,f=0;f<a.length;f++){var g=a.charCodeAt(f);255<g&&(d=!0);c[f]=g}if(!d)return c;c=new Uint16Array(b?b:a.length);for(f=0;f<a.length;f++)g=a.charCodeAt(f),c[f]=g;return c};z.readUint16=function(a,b){var c=new Uint16Array(1);(new Uint8Array(c.buffer)).set(a.subarray(b,b+2));return c[0]};z.readUint32=function(a,b){var c=new Uint32Array(1);(new Uint8Array(c.buffer)).set(a.subarray(b,b+4));return c[0]};z.readFloat32=function(a,b){var c=new Float32Array(1);
  (new Uint8Array(c.buffer)).set(a.subarray(b,b+4));return c[0]};M.onerror=null;M.eval=function(a,b){return eval("(function("+a+"){\n"+b+"\n})")};M.catch_exceptions=!1;M.show_errors_in_console=!0;M.prototype.compile=function(a,b){var c=[],d=[];if(a)for(var f in a)c.push(f),d.push(a[f]);var c=c.join(","),g=this.code,g=M.expandCode(g),e="";for(f in this.exported_callbacks)var k=this.exported_callbacks[f],e=e+("\tif(typeof("+k+") != 'undefined' && "+k+' != window["'+k+'"] ) this.'+k+" = "+k+";\n");this._last_executed_code=
  g+=e;e=this._context;if(M.catch_exceptions)try{this._class=new Function(c,g),l=M.applyToConstructor(this._class,d,this.extra_methods),this._context=new l}catch(m){this._class||console.error("Parsing error in script\n"+m);this._context=this._class=null;M.show_errors_in_console&&(c=M.computeLineFromError(m),console.error("Error in script\n"+m),console.groupCollapsed?(console.groupCollapsed("Error line: "+c+" Watch code"),M.showCodeInConsole(this._last_executed_code,c),console.groupEnd()):console.error("Error line: "+
  c));if(this.onerror)this.onerror(m,this._last_executed_code);if(M.onerror)M.onerror(m,this._last_executed_code,this);return!1}else{this._class=new Function(c,g);var l=M.applyToConstructor(this._class,d,this.extra_methods);this._context=new l}if(b&&e)for(f in e)void 0===this._context[f]||!e[f]||e[f].constructor===Function||this._context[f]&&this._context[f].constructor===Function||(this._context[f]=e[f]);return!0};M.prototype.hasMethod=function(a){return this._context&&this._context[a]&&"function"==
  typeof this._context[a]?!0:!1};M.prototype.callMethod=function(a,b,c){if(this._context&&this._context[a]){if(!M.catch_exceptions)return b&&b.constructor===Array&&c?this._context[a].apply(this._context,b):this._context[a].call(this._context,b);try{return b&&b.constructor===Array&&c?this._context[a].apply(this._context,b):this._context[a].call(this._context,b)}catch(d){if(a=M.computeLineFromError(d),console.error("Error in function\n"+d),console.groupCollapsed?(console.groupCollapsed("Error line: "+
  a+" Watch code"),M.showCodeInConsole(this._last_executed_code,a),console.groupEnd()):console.error("Error line: "+a),this.onerror)this.onerror({error:d,msg:d.toString(),line:a,lscript:this,code:this._last_executed_code})}}};M.applyToConstructor=function(a,b,c){b=[null].concat(b);if(c)for(var d in c)Object.defineProperty(a.prototype,d,{value:c[d],enumerable:!0});return a.bind.apply(a,b)};M.showCodeInConsole=function(a,b){if(a)for(var c=a.split("\n"),d=0;d<c.length;d++)d==b?console.log("%c "+d+". "+
  c[d],"background-color: #A33; color: #FAA;"):console.log("%c "+d+". ","display: inline-block; width: 40px; background-color:#999; color: white;",c[d])};M.cleanCode=function(a){if(!a)return"";a=a.replace(/(\/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+\/)|(\/\/.*)/g,"");a=a.split("\n");for(var b=[],c=0;c<a.length;++c){var d=a[c],f=d.indexOf("//");-1!=f&&(d=a[c].substr(0,f));d=d.trim();d.length&&b.push(d)}return b.join("\n")};M.expandCode=function(a){if(!a)return"";if(-1!=a.indexOf("'''")){var b=a.split("'''");
  a="";for(var c=0;c<b.length;c++)a=0==c%2?a+b[c]:a+('"'+b[c].split("\n").join("\\n\\\n")+'"')}return a};M.computeLineFromError=function(a){if(void 0!==a.lineNumber)return a.lineNumber;if(a.stack){a=a.stack.split("\n")[1].trim();if(-1!=a.indexOf("(native)"))return-1;var b=a.split(" "),c=a.lastIndexOf(":"),d=a.lastIndexOf(":",c-1),d=parseInt(a.substr(d+1,c-d-1));parseInt(a.substr(c+1,a.length-2-c));if("Object.CodingModule.eval"==b[1])return-1;if(-1!=a.indexOf("LScript")||-1!=a.indexOf("<anonymous>"))d-=
  3;return d}return-1};Z.LScript=M;var Sa=window.console?console.log.bind(console):function(){};[Uint8Array,Int8Array,Uint16Array,Int16Array,Uint32Array,Int32Array,Float32Array,Float64Array].forEach(function(a){a.prototype.toJSON=function(){return Array.prototype.slice.call(this)}});var e={_last_uid:1,_uid_prefix:"@",debug:!1,allow_static:!0,Classes:{},ResourceClasses:{},Globals:{},_gui_element:null,_gui_style:null,generateUId:function(a,b){b=b||"";var c=this._uid_prefix+(a||"")+(window.navigator.userAgent.hashCode()%
  16777216).toString(16)+"-",c=c+((GL.getTime()|0).toString(16)+"-"),c=c+(Math.floor(16777216*(1+Math.random())).toString(16)+"-"),c=c+(this._last_uid++).toString(16);return c+b},validateName:function(a){return a.match(/^[a-z\s0-9-_.]+$/i)},valid_property_types:"String Number Boolean color vec2 vec3 vec4 quat mat3 mat4 Resource Animation Texture Prefab Mesh ShaderCode".split(" "),validatePropertyType:function(a){return-1==this.valid_property_types.indexOf(a)?(console.error(a+" is not a valid property value type."),
  !1):!0},_catch_exceptions:!1,Components:{},registerComponent:function(a){for(var b=0;b<arguments.length;++b){var c=arguments[b],d=e.getClassName(c);this.Components[d]=c;c.is_component=!0;c.resource_type="Component";!!c.prototype.onAddedToNode==!!c.prototype.onRemovedFromNode&&!!c.prototype.onAddedToScene==!!c.prototype.onRemovedFromScene||console.warn("%c Component could have a bug, check events: "+d,"font-size: 2em");c.actions||(c.actions={});e.extendClass(c,e.Component);Aa.addExtraMethods(c);LEvent.trigger(e,
  "component_registered",c)}},isClassComponent:function(a){a=this.getClassName(a);return!!this.Components[a]},replaceComponentClass:function(a,b,c){if(!e.Components[c])return!1;for(a=0;a<e.GlobalScene._nodes.length;++a){var d=e.GlobalScene._nodes[a];if(d.hasComponent(b,!0)){for(var f=d.serialize(),f={components:f.components},g=0;g<f.components.length;++g){var h=f.components[g];h[0]==b&&(h[0]=c)}d.removeAllComponents();d.configure(f)}}return!0},registerResourceClass:function(a){var b=e.getClassName(a);
  this.ResourceClasses[b]=a;this.Classes[b]=a;a.is_resource=!0},safeCall:function(a,b,c){if(!e.catch_exceptions)return a.apply(c,b);try{return a.apply(c,b)}catch(d){LEvent.trigger(e,"exception",d),console.error(d.stack)}},setTimeout:function(a,b){if(!e.catch_exceptions)return setTimeout(a,b);try{return setTimeout(a,b)}catch(c){LEvent.trigger(e,"exception",c)}},setInterval:function(a,b){if(!e.catch_exceptions)return setInterval(a,b);try{return setInterval(a,b)}catch(c){LEvent.trigger(e,"exception",c)}},
  extendClass:function(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=b[c]);if(b.prototype)for(c in b.prototype)b.prototype.hasOwnProperty(c)&&!a.prototype.hasOwnProperty(c)&&(b.prototype.__lookupGetter__(c)?a.prototype.__defineGetter__(c,b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__lookupSetter__(c)&&a.prototype.__defineSetter__(c,b.prototype.__lookupSetter__(c)))},cloneObject:function(a,b,c,d){if(void 0!==a){if(null===a)return null;switch(a.constructor){case String:case Number:case Boolean:return a}if(a.constructor.BYTES_PER_ELEMENT){if(!b)return new a.constructor(a);
  if(b.set)b.set(a);else if(b.construtor===Array)for(var f=0;f<a.length;++f)b[f]=a[f];else throw"cloneObject: target has no set method";return b}var g=b;if(void 0===g||null===g)g=a.constructor===Array?[]:{};for(f in a)if("@"!=f[0]&&"_"!=f[0]&&"jQuery"!=f.substr(0,6)&&(!d||void 0!==b[f])){var h=a[f];if(null==h)g[f]=null;else if(!isFunction(h))if(h.constructor===Number||h.constructor===String||h.constructor===Boolean)g[f]=h;else if(h.buffer&&h.byteLength&&h.buffer.constructor===ArrayBuffer)g[f]&&h&&d?
  g[f].length==h.length&&g[f].set(h):g[f]=new h.constructor(h);else if(h.constructor===Array)g[f]&&g[f].set&&g[f].length>=h.length?g[f].set(h):g[f]=JSON.parse(JSON.stringify(h));else if(h.toJSON)g[f]=h.toJSON();else if(c)g[f]=e.cloneObject(h,null,!0);else if(e.catch_exceptions)try{g[f]=JSON.parse(JSON.stringify(h))}catch(k){console.error(k)}else h.constructor!==Object&&e.Classes[e.getObjectClassName(h)]?console.warn("Cannot clone internal classes: "+e.getObjectClassName(h)):g[f]=JSON.parse(JSON.stringify(h))}return g}},
  clearUIds:function(a){a.uid&&delete a.uid;var b=a.components;!b&&a.getComponents&&(b=a.getComponents());if(b){if(b)for(var c in b){var d=b[c];d[1].uid&&delete d[1].uid;d[1]._uid&&delete d[1]._uid}b=a.children;!b&&a.getChildren&&(b=a.getChildren());if(b)for(c in b)e.clearUIds(b[c])}},getObjectClassName:function(a){if(a){if(a.constructor.fullname)return a.constructor.fullname;if(a.constructor.name)return a.constructor.name;if((a=a.constructor.toString().match(/function\s*(\w+)/))&&2==a.length)return a[1]}},
  getClassName:function(a){if(a){if(a.name)return a.name;if(a.toString&&(a=a.toString().match(/function\s*(\w+)/))&&2==a.length)return a[1]}},getObjectProperties:function(a){if(a.getPropertiesInfo)return a.getPropertiesInfo();var b=a.constructor;if(b.properties)return b.properties;var c={},d;for(d in a)if("_"!=d[0]&&"@"!=d[0]&&"jQuery"!=d.substr(0,6)){if(b!=Object){var f=b["@"+d];if(f&&f.type){c[d]=f.type;continue}}f=a[d];null==f?c[d]=null:isFunction(f)||(c[d]=f.constructor===Boolean?e.TYPES.BOOLEAN:
  f.constructor===Number?e.TYPES.NUMBER:f.constructor===String?e.TYPES.STRING:f.buffer&&f.buffer.constructor===ArrayBuffer?2==f.length?e.TYPES.VEC2:3==f.length?e.TYPES.VEC3:4==f.length?e.TYPES.VEC4:9==f.length?e.TYPES.MAT3:16==f.length?e.TYPES.MAT4:0:0)}return c},setObjectProperty:function(a,b,c){if(a.setProperty)return a.setProperty(b,c);a[b]=c;if(a.onPropertyChanged)a.onPropertyChanged(b,c)},queryString:function(){for(var a={},b=window.location.search.substring(1).split("&"),c=0;c<b.length;c++){var d=
  b[c].split("=");if("undefined"===typeof a[d[0]])a[d[0]]=decodeURIComponent(d[1]);else if("string"===typeof a[d[0]]){var f=[a[d[0]],decodeURIComponent(d[1])];a[d[0]]=f}else a[d[0]].push(decodeURIComponent(d[1]))}return a}(),MaterialClasses:{},registerMaterialClass:function(a){var b=e.getClassName(a);this.MaterialClasses[b]=a;this.Classes[b]=a;e.extendClass(a,s);LEvent.trigger(e,"materialclass_registered",a);a.resource_type="Material";a.is_material=!0},getScript:function(a){return(a=e.Script.active_scripts[a])?
  a.context:null},dispatchCodeError:function(a,b,c,d){a={error:a,line:b,resource:c,extra:d};console.error(a);LEvent.trigger(this,"code_error",a)},convertToString:function(a){if(!a)return"";if(a.constructor===String)return a;if(a.constructor===Object)return JSON.stringify(object.serialize?object.serialize():object);a.constructor===ArrayBuffer&&(a=new Uint8Array(a));return String.fromCharCode.apply(null,a)},stringToValue:function(a){var b=a;try{b=JSON.parse(a)}catch(c){console.error("Not a valid value: "+
  a)}return b},isValueOfType:function(a,b){if(null===a||void 0===a){switch(b){case "float":case "sampler2D":case "samplerCube":case e.TYPES.NUMBER:case e.TYPES.VEC2:case e.TYPES.VEC3:case e.TYPES.VEC4:case e.TYPES.COLOR:case e.TYPES.COLOR4:case "mat3":case "mat4":return!1}return!0}switch(b){case "float":case "sampler2D":case "samplerCube":case e.TYPES.NUMBER:return isNumber(a);case e.TYPES.VEC2:return 2===a.length;case e.TYPES.VEC3:return 3===a.length;case e.TYPES.VEC4:return 4===a.length;case e.TYPES.COLOR:return 3===
  a.length;case e.TYPES.COLOR4:return 4===a.length;case "mat3":return 9===a.length;case "mat4":return 16===a.length}return!0}};Object.defineProperty(e,"catch_exceptions",{set:function(a){this._catch_exceptions=a;M.catch_exceptions=a;M.catch_important_exceptions=a},get:function(){return this._catch_exceptions},enumerable:!0});e.Classes.WBin=e.WBin=z;var Wa={set:function(a,b,c){if(!c)e.GlobalScene.setPropertyValue(a,b);else if(c.constructor===e.SceneNode)return a=a.split("/"),(c=c.findNodeByUId(a[0]))?
  c.setPropertyValueFromPath(a.slice(1),b):null;scene.refresh()},get:function(a,b){var c;if(!b)c=e.GlobalScene.getPropertyInfo(a);else if(b.constructor===e.SceneNode){c=a.split("/");var d=b.findNodeByUId(c[0]);if(!d)return null;c=d.getPropertyInfoFromPath(c.slice(1))}return c?c.value:null},shortify:function(a){if(a){var b=a.split("/"),c=null;if(b[0][0]!=e._uid_prefix)return a;c=e.GlobalScene._nodes_by_uid[b[0]];if(!c)return a;b[0]=c.getPathName();b[1]&&b[1][0]==e._uid_prefix&&(a=c.getComponentByUId(b[1]))&&
  (b[1]=e.getObjectClassName(a));return b.join("/")}},setFromInfo:function(a,b){if(a&&a.target){var c=a.target;if(c.setPropertyValue&&!0===c.setPropertyValue(a.name,b))return c;void 0!==c[a.name]&&(c[a.name]=b)}},getFromInfo:function(a){if(a&&a.target){var b=a.target;a=a.name;var c=void 0;b.getPropertyValue&&(c=b.getPropertyValue(a));return void 0===c&&void 0===b[a]?null:void 0!==c?c:b[a]}}};Z.GL&&(e.registerResourceClass(GL.Mesh),e.registerResourceClass(GL.Texture));Z.LSQ=Wa;Z.trace=Sa;var va={AUTOMATIC:"automatic",
  NORMAL:"normal",ALPHA:"alpha",ADD:"add",MULTIPLY:"multiply",SCREEN:"screen",CUSTOM:"custom"};e.Blend=va;if("undefined"==typeof GL)throw"LiteSCENE requires to have litegl.js included before litescene.js";e.BlendFunctions={};e.BlendFunctions[va.AUTOMATIC]=[GL.ONE,GL.ZERO];e.BlendFunctions[va.NORMAL]=[GL.ONE,GL.ZERO];e.BlendFunctions[va.ALPHA]=[GL.SRC_ALPHA,GL.ONE_MINUS_SRC_ALPHA];e.BlendFunctions[va.ADD]=[GL.SRC_ALPHA,GL.ONE];e.BlendFunctions[va.MULTIPLY]=[GL.DST_COLOR,GL.ONE_MINUS_SRC_ALPHA];e.BlendFunctions[va.SCREEN]=
  [GL.SRC_ALPHA,GL.ONE];e.BlendFunctions[va.CUSTOM]=[GL.SRC_ALPHA,GL.ONE_MINUS_SRC_ALPHA];e.STOPPED=0;e.RUNNING=1;e.PAUSED=2;e.ZEROS=vec3.create();e.ONES=vec3.fromValues(1,1,1);e.TOP=vec3.fromValues(0,1,0);e.BOTTOM=vec3.fromValues(0,-1,0);e.RIGHT=vec3.fromValues(1,0,0);e.LEFT=vec3.fromValues(-1,0,0);e.FRONT=vec3.fromValues(0,0,-1);e.BACK=vec3.fromValues(0,0,1);e.IDENTITY=mat4.create();e.TYPES={BOOLEAN:"boolean",NUMBER:"number",STRING:"string",VEC2:"vec2",VEC3:"vec3",VEC4:"vec3",COLOR:"color",COLOR4:"color4",
  RESOURCE:"resource",TEXTURE:"texture",MESH:"mesh",SCENE:"scene",SCENENODE:"node",SCENENODE_ID:"node_id",COMPONENT:"component",MATERIAL:"material"};e.Network={default_dataType:"arraybuffer",request:function(a){if("string"===typeof a)throw"LS.Network.request expects object, not string. Use LS.Network.requestText or LS.Network.requestJSON";var b=a.dataType||this.default_dataType;if("json"==b)b="text";else if("xml"==b)b="text";else if("binary"==b)b="arraybuffer",a.mimeType="application/octet-stream";
  else if("image"==b)return b=new Image,b.onload=function(){a.success&&a.success.call(this)},b.onerror=a.error,b.src=a.url,b;var c=new XMLHttpRequest;c.open(a.data?"POST":"GET",a.url,!0);c.withCredentials=!0;b&&(c.responseType=b);a.mimeType&&c.overrideMimeType(a.mimeType);c.onload=function(b){b=this.response;if(this.status&&200!=this.status)b="Error "+this.status,a.error&&a.error(b);else{if("json"==a.dataType)try{b=JSON.parse(b)}catch(f){a.error&&a.error(f)}else if("xml"==a.dataType)try{b=(new DOMParser).parseFromString(b,
  "text/xml")}catch(g){a.error&&a.error(g)}if(e.catch_errors)try{a.success&&a.success.call(this,b),LEvent.trigger(c,"done",b)}catch(h){LEvent.trigger(e,"code_error",h)}else a.success&&a.success.call(this,b),LEvent.trigger(c,"done",b)}};c.onerror=function(b){a.error&&a.error(b);LEvent.trigger(this,"fail",b)};a.progress&&c.addEventListener("progress",a.progress);c.send(a.data);return c},requestText:function(a,b,c,d){"function"==typeof b&&(c=b);return e.Network.request({url:a,dataType:"text",success:c,
  error:d})},requestJSON:function(a,b,c,d){"function"==typeof b&&(c=b,b=null);return e.Network.request({url:a,data:b,dataType:"json",success:c,error:d})},requestFile:function(a,b,c,d){"function"==typeof b&&(c=b,b=null);return e.Network.request({url:a,data:b,success:c,error:d})},requestScript:function(a,b,c,d){"string"==typeof a&&(a=[a]);var f=a.length,g;for(g in a){var e=document.createElement("script");e.num=g;e.type="text/javascript";e.src=a[g];e.async=!1;e.onload=function(a){f--;f?d&&d(this.src,
  this.num):b&&b()};c&&(e.onerror=function(a){c(a,this.src,this.num)});document.getElementsByTagName("head")[0].appendChild(e)}},requestFont:function(a,b){if(!a||!b)throw"LS.Network.requestFont: Wrong font name or url";var c=this._loaded_fonts;c||(c=this._loaded_fonts={});if(c[a]!=b){c[a]=b;var d=document.getElementById("ls_fonts");d||(d=document.createElement("style"),d.id="ls_fonts",d.setAttribute("type","text/css"),document.head.appendChild(d));var f="",g;for(g in c)b=c[g],f+='@font-face {\n\tfont-family: "'+
  g+"\";\n\tsrc: url('"+b+"');\n}\n";d.innerHTML=f}}};e.Input={mapping:{A_BUTTON:0,B_BUTTON:1,X_BUTTON:2,Y_BUTTON:3,LB_BUTTON:4,RB_BUTTON:5,BACK_BUTTON:6,START_BUTTON:7,LS_BUTTON:8,RS_BUTTON:9,LX:0,LY:1,RX:2,RY:3,TRIGGERS:4,LEFT_TRIGGER:4,RIGHT_TRIGGER:5,JUMP:0,FIRE:1,LEFT:0,MIDDLE:1,RIGHT:2},Keyboard:[],Mouse:{},Gamepads:[],init:function(){this.Keyboard=gl.keys;this.Mouse=gl.mouse;this.Gamepads=gl.getGamepads()},reset:function(){this.Gamepads=gl.gamepads=[]},update:function(){this.Gamepads=gl.getGamepads()},
  isMouseInRect:function(a,b,c,d,f){return this.Mouse.isInsideRect(a,b,c,d,f)},getGamepad:function(a){return this.Gamepads[a||0]},getGamepadAxis:function(a,b,c){a=this.Gamepads[a];if(!a)return 0;var d=0,d=b&&b.constructor===String?this.mapping[b]:b;if(void 0===d)return 0;b=a.axes[d];return!c&&-0.1<b&&0.1>b?0:b},isGamepadButtonPressed:function(a,b){var c=this.Gamepads[a];if(!c)return null;var d=0,d=b&&b.constructor===String?this.mapping[b]:b;return void 0===d?0:(c=c.buttons[d])&&c.pressed},isMouseButtonPressed:function(a){var b=
  0,b=a&&a.constructor===String?this.mapping[a]:a;return void 0===b?!1:0!==(this.Mouse.buttons&1<<b)}};e.GUI={_root:null,getRoot:function(){if(this._root)return!this._root.parentNode&&gl.canvas.parentNode&&gl.canvas.parentNode.appendChild(a),this._root;e.GlobalScene._state!=e.RUNNING&&console.warn("GUI element created before the scene is playing. Only create the GUI elements from onStart or after, otherwise the GUI elements will be lost.");var a=document.createElement("div");a.className="litescene-gui";
  a.style.position="absolute";a.style.top="0";a.style.left="0";a.style.color="#999";a.style.font="20px Arial";a.style.width="100%";a.style.height="100%";a.style.overflow="hidden";a.style.pointerEvents="none";if(!this._style){var b=this._style=document.createElement("style");b.appendChild(document.createTextNode(""));document.head.appendChild(b);b.sheet.insertRule(".litescene-gui button, .litescene-gui input { pointer-events: auto; }",0)}gl.canvas.parentNode.appendChild(a);return this._root=a},createElement:function(a,
  b){var c=document.createElement(a||"div");c.style.pointerEvents="auto";return this.attach(c,b)},attach:function(a,b){if(a){a.style.position="absolute";b=b||"top-left";switch(b){case "bottom":case "bottom-left":a.style.bottom="0";a.style.left="0";break;case "bottom-right":a.style.bottom="0";a.style.right="0";break;case "bottom-middle":a.style.bottom="0";a.style.width="50%";a.style.margin="0 auto";break;case "right":case "top-right":a.style.top="0";a.style.right="0";break;case "top-middle":a.style.top=
  "0";a.style.width="50%";a.style.margin="0 auto";break;default:console.warn("invalid GUI anchor position: ",b);case "left":case "top":case "top-left":a.style.top="0",a.style.left="0"}this.getRoot().appendChild(a);return a}console.error("attachToGUI: element cannot be null")},detach:function(a){a&&a.parentNode&&a.parentNode.removeChild(a)},reset:function(){this._root&&(this._root.parentNode&&this._root.parentNode.removeChild(this._root),this._root=null,this._style&&(this._style.parentNode.removeChild(this._style),
  this._style=null))},show:function(){this._root&&(this._root.style.display="")},hide:function(){this._root&&(this._root.style.display="none")},load:function(a,b){e.ResourcesManager.load(a,function(a){var d=e.GUI.getRoot(),f=a.getAsHTML();f?(f.style.pointerEvents="none",f.style.width="100%",f.style.height="100%",d.appendChild(f),e.GUI.replaceHTMLSources(d),b&&b(f,a)):console.error("html resource is not a string")})},replaceHTMLSources:function(a){a=a.querySelectorAll("*[src]");for(var b=0;b<a.length;++b){var c=
  a[b],d=c.getAttribute("src");if(d&&"@"==d[0]){var d=d.substr(1),f=e.ResourcesManager.getResource(d),d=f&&f._local_url?f._local_url:e.ResourcesManager.getFullURL(d);c.setAttribute("src",d)}}}};var Qa={path:"",proxy:"",ignore_cache:!1,free_data:!1,keep_files:!1,keep_urls:!1,allow_base_files:!1,resources:{},meshes:{},textures:{},materials:{},materials_by_uid:{},resources_not_found:{},resources_being_loaded:{},resources_being_processed:{},resources_renamed_recently:{},num_resources_being_loaded:0,MAX_TEXTURE_SIZE:4096,
  resource_pre_callbacks:{},resource_post_callbacks:{},resource_once_callbacks:{},virtual_file_systems:{},skip_proxy_extensions:["mp3","wav","ogg"],getNoCache:function(a){return this.ignore_cache||a?"nocache="+getTime()+Math.floor(1E3*Math.random()):""},reset:function(){this.resources={};this.meshes={};this.textures={}},registerResourcePreProcessor:function(a,b,c,d){if(a){a=a.split(",");for(var f in a)c=a[f].toLowerCase(),this.resource_pre_callbacks[c]=b}},registerResourcePostProcessor:function(a,b){this.resource_post_callbacks[a]=
  b},getExtension:function(a,b){if(!a)return"";var c=a.indexOf("?");-1!=c&&(a=a.substr(0,c));c=b?a.indexOf("."):a.lastIndexOf(".");return-1==c?"":a.substr(c+1).toLowerCase()},removeExtension:function(a,b){if(!a)return"";var c=a.indexOf("?");-1!=c&&(a=a.substr(0,c));c=b?a.indexOf("."):a.lastIndexOf(".");return-1==c?a:a.substr(0,c)},getFilename:function(a){if(!a)return"";var b=a.lastIndexOf("/"),c=a.lastIndexOf("?"),c=(-1==c?a.length:c-1)-b;return a.substr(b+1,c)},getFolder:function(a){if(!a)return"";
  var b=a.lastIndexOf("/");return a.substr(0,b)},getBasename:function(a){if(!a)return"";a=this.getFilename(a);var b=a.indexOf(".");return-1==b?a:a.substr(0,b)},cleanFullpath:function(a){return a?-1==a.indexOf("//")?47==a.charCodeAt(0)?a.substr(1):a:-1==a.indexOf("://")?a.split("/").filter(function(a){return!!a}).join("/"):a:""},loadResources:function(a,b){if(a){for(var c in a)":"!=c[0]&&"_"!=c[0]&&this.load(c,b);this._total_resources_to_load=this.num_resources_being_loaded;LEvent.trigger(this,"start_loading_resources",
  this._total_resources_to_load)}},setPath:function(a){this.path=a},setProxy:function(a){a?-1!=a.indexOf("@")?this.proxy="http://"+a.replace("@",window.location.host):this.proxy=a:this.proxy=null},getFullURL:function(a,b){if(!a)return null;var c=a.substr(0,10).indexOf(":"),d="";-1!=c&&(d=a.substr(0,c));var f=this.path;b&&b.force_local_url&&(f=".");b&&b.local_repository&&(f=b.local_repository);if(d)switch(d){case "http":case "https":return c=this.getExtension(a).toLowerCase(),this.proxy&&-1==this.skip_proxy_extensions.indexOf(c)?
  this.proxy+a:a;case "blob":return a;case "":return a;default:return":"==a[0]||"_"==a[0]?a:(this.virtual_file_systems[d]||f)+"/"+a.substr(c+1)}else return f+"/"+a},registerFileSystem:function(a,b){this.virtual_file_systems[a]=b},getResource:function(a,b){if(!a)return null;a=this.cleanFullpath(a);if(!b)return this.resources[a];var c=this.resources[a];return c&&c.constructor===b?c:null},getResourceType:function(a){return a?a.object_type?a.object_type:a.constructor.resource_type?a.constructor.resource_type:
  e.getObjectClassName(a):null},getResourcesData:function(a,b){for(var c={},d=0;d<a.length;++d){var f=a[d],g=e.ResourcesManager.resources[f];if(g){var h=null;if(h=g._original_data?g._original_data:e.Resource.getDataToStore(g).data){if(h.constructor===Blob||h.constructor===File){if(!(b||h.data&&h.data.constructor===ArrayBuffer)){console.warn("Not support to store File or Blob, please, use ArrayBuffer");continue}h=h.data}c[f]=h}else console.warn("Wrong data in resource")}}return c},resourceModified:function(a){a&&
  (a.constructor===String?console.warn("resourceModified parameter must be a resource, not a string"):(delete a._original_data,delete a._original_file,a.remotepath&&(a._modified=!0),LEvent.trigger(this,"resource_modified",a),a.from_pack&&a.from_pack.constructor===String&&(a=e.ResourcesManager.getResource(a.from_pack))&&this.resourceModified(a)))},resourceSaved:function(a){a&&(delete a._modified,a.remotepath=a.fullpath,LEvent.trigger(this,"resource_saved",a))},load:function(a,b,c){b&&b.constructor===
  Function&&!c&&(c=b,b=null);var d=this.resources[a];if(null!=d&&!d.is_preview)return c&&c(d,a),!0;b=b||{};d=this.getExtension(a);if(!d)return console.warn("Cannot load a file without extension: "+a),!1;if(!this.resources_not_found[a])if(this.resources_being_loaded[a])this.resources_being_loaded[a].push({options:b,callback:c});else if(!this.resources_being_processed[a]){if(this.allow_base_files||-1!=a.indexOf("/")){this.resources_being_loaded[a]=[{options:b,callback:c}];LEvent.trigger(e.ResourcesManager,
  "resource_loading",a);this.num_resources_being_loaded++;c=this.getFullURL(a);var f=e.Formats.getFileFormatInfo(d);f&&f.has_preview&&!b.is_preview&&LEvent.trigger(this,"load_resource_preview",a);(f=this.getNoCache())&&(c+=(-1==c.indexOf("?")?"?":"&")+f);c={url:c,success:function(c){e.ResourcesManager.processResource(a,c,b,Qa._resourceLoadedEnd,!0)},error:function(b){e.ResourcesManager._resourceLoadedError(a,b)},progress:function(b){var c=0;b.total&&(c=b.loaded/b.total);LEvent.hasBind(e.ResourcesManager,
  "resource_loading_progress")&&LEvent.trigger(e.ResourcesManager,"resource_loading_progress",{url:a,event:b,progress:c});LEvent.hasBind(e.ResourcesManager,"loading_resources_progress")&&LEvent.trigger(e.ResourcesManager,"loading_resources_progress",1-(e.ResourcesManager.num_resources_being_loaded-c)/e.ResourcesManager._total_resources_to_load)}};(f=e.Formats.supported[d])&&f.dataType&&(c.dataType=f.dataType);e.Network.request(c);return!1}console.warn("Cannot load resource, filename has no folder and LS.ResourcesManager.allow_base_files is set to false: ",
  a)}},processResource:function(a,b,c,d,f){if((c=c||{})&&c.constructor!==Object)throw"processResource options must be object";if(null===b||void 0===b)throw"No data found when processing resource: "+a;var g=null,g=this.getExtension(a),h=function(a,c,g){c?(e.ResourcesManager.processFinalResource(a,c,g,d,f),!e.ResourcesManager.keep_files||b.constructor!=ArrayBuffer&&b.constructor!=String||c._original_data||c._original_file||(c._original_data=b)):e.ResourcesManager._resourceLoadedEnd(a,null)};this.resources_being_processed[a]=
  !0;if(!g)return this.processDataResource(a,b,c,h);var k=e.Formats.supported[g];if(g=this.resource_pre_callbacks[g.toLowerCase()])g=g(a,b,c,h),!0!==g&&(g?h(a,g,c):this._resourceLoadedError(a,"Resource couldnt be processed"));else if(k&&(k.type||k.parse)){g=null;switch(k.type){case "scene":g=e.ResourcesManager.processASCIIScene(a,b,c,h);break;case "mesh":g=e.ResourcesManager.processASCIIMesh(a,b,c,h);break;case "texture":case "image":g=e.ResourcesManager.processImage(a,b,c,h);break;default:k.parse?
  (g=k.parse(b))&&h(a,g,c):console.warn("Format Info without parse function")}g&&!0!==g&&h(a,g,c)}else{g=null;g=k&&k.resourceClass?new k.resourceClass:new e.Resource;if(g.setData)g.setData(b,!0);else throw"Resource without setData, cannot assign";g&&(g.filename=g.fullpath=a,h(a,g,c))}},processFinalResource:function(a,b,c,d,f){if(!b)return e.ResourcesManager._resourceLoadedError(a,"error processing the resource");b.filename=a;c.filename&&(b.filename=c.filename);c.is_local||(b.fullpath=a);c.from_prefab&&
  (b.from_prefab=c.from_prefab);c.from_pack&&(b.from_pack=c.from_pack);f&&(b.remotepath=a);c.is_preview&&(b.is_preview=!0);e.ResourcesManager.resources_being_processed[a]&&delete e.ResourcesManager.resources_being_processed[a];b.getResources&&Qa.loadResources(b.getResources({}));e.ResourcesManager.registerResource(a,b);c.preview_of&&e.ResourcesManager.registerResource(c.preview_of,b);d&&d(a,b,c)},registerResource:function(a,b){if(!a||!b)throw"registerResource missing filename or resource";a=this.cleanFullpath(a);
  if(!(this.resources[a]==b||b.is_preview&&this.resources[a])){b.filename=a;b.object_type||(b.object_type=e.getObjectClassName(b));var c=b.object_type;b.constructor.resource_type&&(c=b.constructor.resource_type);this.resources[a]=b;(c=this.resource_post_callbacks[c])&&c(a,b);b.is_preview||LEvent.trigger(this,"resource_registered",b);e.GlobalScene.refresh()}},unregisterResource:function(a){var b=this.resources[a];if(!b)return!1;delete this.resources[a];this.meshes[a]&&delete this.meshes[a];this.textures[a]&&
  delete this.textures[a];this.materials[a]&&delete this.materials[a];b.constructor!==e.Pack&&b.constructor!==e.Prefab||b.setResourcesLink(null);LEvent.trigger(this,"resource_unregistered",b);e.GlobalScene.refresh();return!0},getURLasFile:function(a,b){var c=new XMLHttpRequest;c.open("GET",this.getFullURL(a),!0);c.responseType="blob";c.onload=function(d){d=c.response;b&&b(d,a)};c.send()},renameResource:function(a,b,c){var d=this.resources[a];if(!d)return!1;d.filename=b;d.fullpath&&(d.fullpath=b);this.resources[b]=
  d;delete this.resources[a];c||this.sendResourceRenamedEvent(a,b,d);this.meshes[a]&&(delete this.meshes[a],this.meshes[b]=d);this.textures[a]&&(delete this.textures[a],this.textures[b]=d);this.materials[a]&&(delete this.materials[a],this.materials[b]=d);this.resources_renamed_recently[a]=b;return!0},isLoading:function(a){return a?this.resources_being_loaded[a]||this.resources_being_processed[a]?!0:!1:0<this.num_resources_being_loaded},clearNotFoundResources:function(){this.resources_not_found={}},
  computeImageMetadata:function(a){return{width:a.width,height:a.height}},getMesh:function(a){return a?a.constructor===String?this.meshes[a]:a.constructor===GL.Mesh?a:null:null},getTexture:function(a){return a?a.constructor===String?this.textures[a]:a.constructor===GL.Texture?a:null:null},getMaterial:function(a){if(a)return"@"==a[0]?this.materials_by_uid[a]:this.materials[a]},sendResourceRenamedEvent:function(a,b,c){for(var d=e.GlobalScene._nodes.concat(),f=0;f<d.length;f++){var g=d[f];g.prefab&&g.prefab===
  a&&(g.prefab=b);for(var h=0;h<g._components.length;h++){var k=g._components[h];if(k.onResourceRenamed)k.onResourceRenamed(a,b,c)}if(g.material&&g.material==a)g.material=b;else if((g=g.getMaterial())&&g.onResourceRenamed)g.onResourceRenamed(a,b,c)}},onceLoaded:function(a,b){var c=this.resource_once_callbacks[a];if(c){for(var d in c)if(c[d]==b)return;c.push(b)}else this.resource_once_callbacks[a]=[b]},_resourceLoadedEnd:function(a,b){e.ResourcesManager.debug&&console.log("RES: "+a+" ---\x3e "+e.ResourcesManager.num_resources_being_loaded);
  if(b){for(var c in e.ResourcesManager.resources_being_loaded[a])null!=e.ResourcesManager.resources_being_loaded[a][c].callback&&e.ResourcesManager.resources_being_loaded[a][c].callback(b,a);if(e.ResourcesManager.resource_once_callbacks[a]){var d=e.ResourcesManager.resource_once_callbacks[a];for(c in d)d[c](a,b);delete e.ResourcesManager.resource_once_callbacks[a]}}e.ResourcesManager.resources_being_loaded[a]&&(delete e.ResourcesManager.resources_being_loaded[a],e.ResourcesManager.num_resources_being_loaded--,
  b?LEvent.trigger(e.ResourcesManager,"resource_loaded",a):LEvent.trigger(e.ResourcesManager,"resource_problem_loading",a),LEvent.trigger(e.ResourcesManager,"loading_resources_progress",1-e.ResourcesManager.num_resources_being_loaded/e.ResourcesManager._total_resources_to_load),0==e.ResourcesManager.num_resources_being_loaded&&(LEvent.trigger(e.ResourcesManager,"end_loading_resources",!0),e.ResourcesManager._total_resources_to_load=0))},_resourceLoadedError:function(a,b){console.log("Error loading "+
  a);delete e.ResourcesManager.resources_being_loaded[a];delete e.ResourcesManager.resource_once_callbacks[a];e.ResourcesManager.resources_not_found[a]=!0;LEvent.trigger(e.ResourcesManager,"resource_not_found",a);e.ResourcesManager.num_resources_being_loaded--;0==e.ResourcesManager.num_resources_being_loaded&&LEvent.trigger(e.ResourcesManager,"end_loading_resources",!1)}};e.RM=e.ResourcesManager=Qa;e.getTexture=function(a){return e.ResourcesManager.getTexture(a)};e.ResourcesManager.registerResourcePreProcessor("wbin",
  function(a,b,c){return b=z.load(b)},"binary");e.ResourcesManager.registerResourcePreProcessor("json",function(a,b,c){c=b;b.constructor===String&&(b=JSON.parse(b));b.object_type&&!b.is_data?(a=e.Classes[b.object_type]||window[b.object_type])?a.prototype.configure?(c=new a,c.configure(b)):c=new a(b):console.warn("JSON object_type class not found: "+b.object_type):(c=new e.Resource,c.filename=a,c._data=b,c.type="json",c.category="json");return c});e.ResourcesManager.registerResourcePreProcessor("zip",
  function(a,b,c){if(!Z.JSZip)throw"JSZip not found. To use ZIPs you must have the JSZip.js library installed.";(new JSZip).loadAsync(b).then(function(a){a.forEach(function(a,b){var c=e.ResourcesManager.getExtension(a),c=e.Formats.supported[c];b.async(c&&"text"==c.dataType?"string":"arraybuffer").then(function(b){"scene.json"==a?e.GlobalScene.configure(JSON.parse(b)):e.ResourcesManager.processResource(a,b)})})});return!0},"binary");e.ResourcesManager.processDataResource=function(a,b,c,d){b.constructor===
  String&&(b=JSON.parse(b));if(b.constructor==ArrayBuffer)return g=z.load(b),d&&d(a,g,c),g;var f=b.object_type;if(f&&e.Classes[f]){var g=null;e.Classes[f].prototype.configure?(g=new e.Classes[f],g.configure(b)):g=new e.Classes[f](b);d&&d(a,g,c);return g}console.warn("Resource Class name unknown: "+f);return!1};e.ResourcesManager.processImage=function(a,b,c,d){function f(f){f&&e.ResourcesManager.keep_files&&(f._original_data=b);e.ResourcesManager.keep_urls?f._local_url=k:URL.revokeObjectURL(k);d&&d(a,
  f,c)}var g=e.ResourcesManager.getExtension(a),h="application/octet-stream";if("jpg"==g||"jpeg"==g)h="image/jpg";else if("webp"==g)h="image/webp";else if("gif"==g)h="image/gif";else if("png"==g)h="image/png";else if(g=e.Formats.supported[g],g.mimetype)h=g.mimetype;else{g=this.processImageNonNative(a,b,c);f(g);return}var g=new Blob([b],{type:h}),k=URL.createObjectURL(g),g=new Image;g.src=k;g.real_filename=a;g.onload=function(){var a=e.ResourcesManager.processTexture(this.real_filename,this,c);f(a)};
  g.onerror=function(b){URL.revokeObjectURL(k);d&&d(a,null,c);console.error("Error while loading image, file is not native image format: "+a)};return!0};e.ResourcesManager.processImageNonNative=function(a,b,c){b=(new Uint8Array(b)).buffer;c=e.Formats.parse(a,b,c);return c?c.constructor==GL.Texture?(c.filename=a,c._original_data=b,c):c=e.ResourcesManager.processTexture(a,c):(console.error("Cannot parse image format"),null)};e.ResourcesManager.processTexture=function(a,b,c){if(b.width==b.height/6||-1!=
  a.indexOf("CUBECROSS"))c={wrapS:gl.MIRROR,wrapT:gl.MIRROR,magFilter:gl.LINEAR,minFilter:gl.LINEAR_MIPMAP_LINEAR},-1!=a.indexOf("CUBECROSSL")&&(c.is_cross=1),c=GL.Texture.cubemapFromImage(b,c);else{c=gl.LINEAR;var d=gl.REPEAT,f=gl.LINEAR_MIPMAP_LINEAR;isPowerOfTwo(b.width)&&isPowerOfTwo(b.height)||(f=gl.LINEAR,d=gl.CLAMP_TO_EDGE);c=b.pixels?GL.Texture.fromMemory(b.width,b.height,b.pixels,{format:24==b.bpp?gl.RGB:gl.RGBA,no_flip:b.flipY,wrapS:d,wrapT:d,magFilter:c,minFilter:f}):GL.Texture.fromImage(b,
  {format:gl.RGBA,wrapS:d,wrapT:d,magFilter:c,minFilter:f})}if(c)return c.img=b,c.filename=a,c.generateMetadata(),c};e.ResourcesManager.processASCIIMesh=function(a,b,c){b=e.Formats.parse(a,b,c);return null==b?(console.error("Error parsing mesh: "+a),null):GL.Mesh.load(b)};e.ResourcesManager.processASCIIScene=function(a,b,c){b=e.Formats.parse(a,b,c);if(null==b)return console.error("Error parsing mesh: "+a),null;for(var d in b.meshes)e.ResourcesManager.processResource(d,b.meshes[d]);for(d in b.resources)e.ResourcesManager.processResource(d,
  b.resources[d]);for(d in b.materials)e.ResourcesManager.processResource(d,b.materials[d]);a=new e.SceneNode;a.configure(b.root);return a};e.ResourcesManager.registerResourcePostProcessor("Mesh",function(a,b){b.object_type="Mesh";b.metadata&&(b.metadata={},b.generateMetadata());b.bounding&&b.bounding.length==BBox.data_length||(b.bounding=null,b.updateBounding());b.getBuffer("normals")||b.computeNormals();e.ResourcesManager.free_data&&b.freeData();e.ResourcesManager.meshes[a]=b});e.ResourcesManager.registerResourcePostProcessor("Texture",
  function(a,b){e.ResourcesManager.textures[a]=b});e.ResourcesManager.registerResourcePostProcessor("Material",function(a,b){e.ResourcesManager.materials[a]=b;e.ResourcesManager.materials_by_uid[b.uid]=b;b.prepareMaterial(e.GlobalScene)});e.ResourcesManager.registerResourcePostProcessor("Pack",function(a,b){b.flagResources()});e.ResourcesManager.registerResourcePostProcessor("Prefab",function(a,b){b.applyToNodes()});e.ResourcesManager.registerResourcePostProcessor("ShaderCode",function(a,b){b.applyToMaterials()});
  var Xa={default_xml_url:"data/shaders.xml",snippets:{},shader_blocks:{},compiled_programs:{},compiled_shaders:{},global_shaders:{},templates:{},default_shader:null,dump_compile_errors:!0,on_compile_error:null,num_shaderblocks:0,init:function(a,b){this.default_shader=null;this.compiled_programs={};this.compiled_shaders={};this.global_shaders={};this.global_extra_code=String.fromCharCode(10)+"#define WEBGL"+String.fromCharCode(10);this.createDefaultShaders();this.default_shader=this.get("flat");this.last_shaders_url=
  a=a||this.default_xml_url;this.loadFromXML(a,!1,b)},reloadShaders:function(a){this.loadFromXML(this.last_shaders_url,!0,!0,a)},resolve:function(a){return this.get(a.name,a.macros)},clearCache:function(){this.compiled_programs={};this.compiled_shaders={}},get:function(a,b){if(!a)return this.default_shader;if(!b){var c=this.compiled_programs[a];if(c)return c}var d=this.global_shaders[a];if(null==d)return this.default_shader;var c=a+":",f="";if(0!=d.num_macros)for(var g in b)d.macros[g]&&(c+=g+"="+b[g]+
  ":",f+=String.fromCharCode(10)+"#define "+g+" "+b[g]+String.fromCharCode(10));g=c.hashCode();if(null!=this.compiled_programs[g])return this.compiled_programs[g];var e=0;this.debug&&(e=getTime());var k=f+d.vs_code,f=f+d.fs_code;if(d.imports)var m={},l=function(a){a=a.split('"')[1];if(m[a])return"//already imported: "+a+"\n";var b=Xa.snippets[a];m[a]=!0;return b?b.code:"//snippet not found: "+a+"\n"},k=k.replace(/#import\s+\"(\w+)\"\s*\n/g,l),m={},f=f.replace(/#import\s+\"(\w+)\"\s*\n/g,l);if(c=this.compileShader(k,
  f,c))c.global=d;this.debug&&console.log("Time creating shader:",(getTime()-e).toFixed(3),"ms");return this.registerCompiledShader(c,g,a)},getGlobalShaderInfo:function(a){return this.global_shaders[a]},compileShader:function(a,b,c){if(!c)throw"compileShader must have a name specified";if(!gl)return null;var d=null;try{a=this.global_extra_code+a;b=this.global_extra_code+b;var f=this.compiled_shaders[c+":VS"];f||(f=this.compiled_shaders[c+":VS"]=GL.Shader.compileSource(gl.VERTEX_SHADER,a));var g=this.compiled_shaders[c+
  ":FS"];g||(g=this.compiled_shaders[c+":FS"]=GL.Shader.compileSource(gl.FRAGMENT_SHADER,b));var e=getTime(),d=new GL.Shader(f,g);this.debug&&console.log("Shader compile time: ",(getTime()-e).toFixed(3),"ms");d.name=c}catch(k){this.dump_compile_errors&&(this.dumpShaderError(c,k,a,b),this.dump_compile_errors=!1);if(this.on_compile_error)this.on_compile_error(k);return null}return d},dumpShaderError:function(a,b,c,d){console.error("Error compiling shader: "+a);console.log(b);console.groupCollapsed("Vertex Shader Code");
  a=(this.global_extra_code+c).split("\n");for(var f in a)console.log(f+": "+a[f]);console.groupEnd();console.groupCollapsed("Fragment Shader Code");a=(this.global_extra_code+d).split("\n");for(f in a)console.log(f+": "+a[f]);console.groupEnd()},registerCompiledShader:function(a,b,c){if(null==a)return this.compiled_programs[b]=this.default_shader;a.id=c;a.key=b;return this.compiled_programs[b]=a},loadFromXML:function(a,b,c,d){c=c?"?nocache="+getTime()+Math.floor(1E3*Math.random()):"";e.Network.request({url:a+
  c,dataType:"xml",success:function(c){console.log("Shaders XML loaded: "+a);b&&(e.ShadersManager.global_shaders={},e.ShadersManager.compiled_programs={},e.ShadersManager.compiled_shaders={});e.ShadersManager.processShadersXML(c);d&&d()},error:function(a){console.log("Error parsing Shaders XML: "+a);throw"Error parsing Shaders XML: "+a;}})},processShadersXML:function(a){var b=a.querySelectorAll("shader"),c;for(c in b){var d=b[c];if(d&&d.attributes){var f=d.attributes.id;if(f){var f=f.value,g="",h="",
  h="";(g=d.attributes.macros)&&(h+=g.value);(g=d.querySelector("macros"))&&(h+=g.textContent);var h=h.split(","),k={};for(c in h)k[h[c].trim()]=!0;g=d.querySelector("code[type='vertex_shader']").textContent;h=d.querySelector("code[type='pixel_shader']").textContent;if(g&&h){var m={},l=d.getAttribute("multipass");l&&(m.multipass="1"==l||"true"==l);if(l=d.getAttribute("imports"))m.imports="1"==l||"true"==l;if(d=d.getAttribute("events"))m.events="1"==d||"true"==d;e.ShadersManager.registerGlobalShader(g,
  h,f,k,m)}else console.log("no code in shader: "+f)}}}b=a.querySelectorAll("snippet");for(c=0;c<b.length;++c)d=b[c],f=d.getAttribute("id"),this.registerSnippet(f,d.textContent);a=a.querySelectorAll("template");for(c=0;c<a.length;++c)b=a[c],f=b.getAttribute("id"),g=b.querySelector("code[type='vertex_shader']").textContent,h=b.querySelector("code[type='fragment_shader']").textContent,d=this.processTemplateCode(g),h=this.processTemplateCode(h),b[f]={id:f,vs_info:d,fs_info:h};this.ready=!0},registerGlobalShader:function(a,
  b,c,d,f){var g=0,h;for(h in d)g+=1;gl&&!gl.extensions.WEBGL_draw_buffers&&(b=b.replace("#extension GL_EXT_draw_buffers : enable",""));d={vs_code:a,fs_code:b,macros:d,num_macros:g};if(f){for(h in f)d[h]=f[h];f.events&&(f=function(a){a.split('"');return""},d.vs_code=a.replace(/#event\s+\"(\w+)\"\s*\n/g,f),d.fs_code=b.replace(/#event\s+\"(\w+)\"\s*\n/g,f))}this.global_shaders[c]=d;LEvent.trigger(e.ShadersManager,"newShader");return d},registerSnippet:function(a,b){this.snippets[a]={id:a,code:b}},getSnippet:function(a){return this.snippets[a]},
  registerShaderBlock:function(a,b){var c=-1;this.shader_blocks[a]?(console.warn("There is already a ShaderBlock with that name, replacing it: ",a),c=this.shader_blocks[a].flag_id):c=this.num_shaderblocks++;b.flag_id=c;b.flag_mask=1<<c;this.shader_blocks[a]=b},getShaderBlock:function(a,b){return this.shader_blocks[a]},common_vscode:"\n\t\tprecision mediump float;\n\t\tattribute vec3 a_vertex;\n\t\tattribute vec3 a_normal;\n\t\tattribute vec2 a_coord;\n\t\tuniform mat4 u_model;\n\t\tuniform mat4 u_viewprojection;\n\t",
  common_fscode:"\n\t\tprecision mediump float;\n\t",createDefaultShaders:function(){this.registerGlobalShader(this.common_vscode+"\t\t\tvoid main() {\t\t\t\tmat4 mvp = u_viewprojection * u_model;\t\t\t\tgl_Position = mvp * vec4(a_vertex,1.0);\t\t\t}\t\t\t",this.common_fscode+"\t\t\tuniform vec4 u_material_color;\t\t\tvoid main() {\t\t\t  gl_FragColor = vec4(u_material_color);\t\t\t}\t\t","flat");this.registerGlobalShader(this.common_vscode+"\t\t\tvarying vec2 v_uvs;\t\t\tvoid main() {\n\t\t\t\tv_uvs = a_coord;\n\t\t\t\tmat4 mvp = u_viewprojection * u_model;\t\t\t\tgl_Position = mvp * vec4(a_vertex,1.0);\t\t\t}\t\t\t",
  this.common_fscode+"\t\t\tuniform vec4 u_material_color;\t\t\tvarying vec2 v_uvs;\t\t\tuniform sampler2D texture;\t\t\tvoid main() {\t\t\t\tgl_FragColor = u_material_color * texture2D(texture,v_uvs);\t\t\t}\t\t","texture_flat");this.registerGlobalShader(this.common_vscode+"\t\t\tvarying vec2 coord;\t\t\tvoid main() {\t\t\tcoord = a_coord;\t\t\tgl_Position = vec4(coord * 2.0 - 1.0, 0.0, 1.0);\t\t}\t\t",this.common_fscode+"\t\t\tuniform sampler2D texture;\t\t\tuniform vec4 color;\t\t\tvarying vec2 coord;\t\t\tvoid main() {\t\t\tgl_FragColor = texture2D(texture, coord) * color;\t\t\t}\t\t",
  "screen")},processTemplateCode:function(a){a=a.replace(/(\/\*([\s\S]*?)\*\/)|(\/\/(.*)$)/gm,"");for(var b={},c=[],d=[],f=a.split("\n"),g=0;g<f.length;g++){var e=f[g].trim();if(e.length)if("#"!=e[0])d.push(e);else{var k=e.split(" ");if("#pragma"==k[0])switch(k[1]){case "import":d.length&&(c.push(["code",d.join("\n")]),d=[]);c.push(["import",k[3]]);break;case "hook":d.length&&(c.push(["code",d.join("\n")]),d=[]);void 0!==b[k[3]]&&console.warn("Hook already found in shader: "+k[3]);b[k[3]]=c.length;
  c.push(["hook",k[3]]);break;default:d.push(e)}else d.push(e)}}return{code:a,parts:c,hooks:b}}};e.SM=e.ShadersManager=Xa;Ka.prototype.clear=function(){this.macros={};this.hooks={}};Ka.prototype.add=function(a){if(a)for(var b in a.macros)this.macros[b]=a.macros[b]};Ka.prototype.setMacro=function(a,b){this.macros[a]=b||""};Ka.prototype.resolve=function(){return e.ShadersManager.resolve(this)};e.ShaderQuery=Ka;Za.prototype.addCode=function(a,b,c){this.code_map.set(a,{enabled:b||"",disabled:c||""})};Za.prototype.getCode=
  function(a,b){b=b||0;var c=this.code_map.get(a);return c?b|this.flag_mask?c.enabled:c.disabled:null};Za.prototype.register=function(){e.ShadersManager.registerShaderBlock(this.name,this)};e.ShaderBlock=Za;var Fa={ready:!1,images:{},image_last_id:1,onRequestFrame:null,reset_stack_on_reset:!0,init:function(){!this.ready&&gl&&(this.color=new Float32Array(4),this.color[3]=1,this.mvp_matrix=mat4.create(),this.temp_matrix=mat4.create(),this.point_size=2,this.stack=new Float32Array(512),this.model_matrix=
  new Float32Array(this.stack.buffer,0,16),mat4.identity(this.model_matrix),this.camera=null,this.camera_position=vec3.create(),this.view_matrix=mat4.create(),this.projection_matrix=mat4.create(),this.viewprojection_matrix=mat4.create(),this.camera_stack=[],this.quad_mesh=GL.Mesh.load({vertices:[[-1,1,0],[1,1,0],[1,-1,0],[-1,-1,0]],coords:[[0,1],[1,1],[1,0],[0,0]]}),this.shader=new Shader("\t\t\tprecision mediump float;\n\t\t\tattribute vec3 a_vertex;\n\t\t\t#ifdef USE_COLOR\n\t\t\t\tattribute vec4 a_color;\n\t\t\t\tvarying vec4 v_color;\n\t\t\t#endif\n\t\t\t#ifdef USE_TEXTURE\n\t\t\t\tattribute vec2 a_coord;\n\t\t\t\tvarying vec2 v_coord;\n\t\t\t#endif\n\t\t\t#ifdef USE_SIZE\n\t\t\t\tattribute float a_extra;\n\t\t\t#endif\n\t\t\tuniform mat4 u_mvp;\n\t\t\tuniform float u_point_size;\n\t\t\tvoid main() {\n\t\t\t\tgl_PointSize = u_point_size;\n\t\t\t\t#ifdef USE_SIZE\n\t\t\t\t\tgl_PointSize = a_extra;\n\t\t\t\t#endif\n\t\t\t\t#ifdef USE_TEXTURE\n\t\t\t\t\tv_coord = a_coord;\n\t\t\t\t#endif\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\tv_color = a_color;\n\t\t\t\t#endif\n\t\t\t\tgl_Position = u_mvp * vec4(a_vertex,1.0);\n\t\t\t}\t\t\t",
  "\t\t\tprecision mediump float;\n\t\t\tuniform vec4 u_color;\n\t\t\t#ifdef USE_COLOR\n\t\t\t\tvarying vec4 v_color;\n\t\t\t#endif\n\t\t\t#ifdef USE_TEXTURE\n\t\t\t\tvarying vec2 v_coord;\n\t\t\t\tuniform sampler2D u_texture;\n\t\t\t#endif\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = u_color;\n\t\t\t\t#ifdef USE_TEXTURE\n\t\t\t\t  color *= texture2D(u_texture, v_coord);\n\t\t\t\t  if(color.a < 0.1)\n\t\t\t\t\tdiscard;\n\t\t\t    #endif\n\t\t\t\t#ifdef USE_POINTS\n\t\t\t\t    float dist = length( gl_PointCoord.xy - vec2(0.5) );\n\t\t\t\t\tif( dist > 0.45 )\n\t\t\t\t\t\tdiscard;\n\t\t\t    #endif\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\tcolor *= v_color;\n\t\t\t\t#endif\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\t\t"),
  this.shader_color=new Shader("\t\t\tprecision mediump float;\n\t\t\tattribute vec3 a_vertex;\n\t\t\t#ifdef USE_COLOR\n\t\t\t\tattribute vec4 a_color;\n\t\t\t\tvarying vec4 v_color;\n\t\t\t#endif\n\t\t\t#ifdef USE_TEXTURE\n\t\t\t\tattribute vec2 a_coord;\n\t\t\t\tvarying vec2 v_coord;\n\t\t\t#endif\n\t\t\t#ifdef USE_SIZE\n\t\t\t\tattribute float a_extra;\n\t\t\t#endif\n\t\t\tuniform mat4 u_mvp;\n\t\t\tuniform float u_point_size;\n\t\t\tvoid main() {\n\t\t\t\tgl_PointSize = u_point_size;\n\t\t\t\t#ifdef USE_SIZE\n\t\t\t\t\tgl_PointSize = a_extra;\n\t\t\t\t#endif\n\t\t\t\t#ifdef USE_TEXTURE\n\t\t\t\t\tv_coord = a_coord;\n\t\t\t\t#endif\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\tv_color = a_color;\n\t\t\t\t#endif\n\t\t\t\tgl_Position = u_mvp * vec4(a_vertex,1.0);\n\t\t\t}\t\t\t",
  "\t\t\tprecision mediump float;\n\t\t\tuniform vec4 u_color;\n\t\t\t#ifdef USE_COLOR\n\t\t\t\tvarying vec4 v_color;\n\t\t\t#endif\n\t\t\t#ifdef USE_TEXTURE\n\t\t\t\tvarying vec2 v_coord;\n\t\t\t\tuniform sampler2D u_texture;\n\t\t\t#endif\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = u_color;\n\t\t\t\t#ifdef USE_TEXTURE\n\t\t\t\t  color *= texture2D(u_texture, v_coord);\n\t\t\t\t  if(color.a < 0.1)\n\t\t\t\t\tdiscard;\n\t\t\t    #endif\n\t\t\t\t#ifdef USE_POINTS\n\t\t\t\t    float dist = length( gl_PointCoord.xy - vec2(0.5) );\n\t\t\t\t\tif( dist > 0.45 )\n\t\t\t\t\t\tdiscard;\n\t\t\t    #endif\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\tcolor *= v_color;\n\t\t\t\t#endif\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\t\t",
  {USE_COLOR:""}),this.shader_texture=new Shader("\t\t\tprecision mediump float;\n\t\t\tattribute vec3 a_vertex;\n\t\t\t#ifdef USE_COLOR\n\t\t\t\tattribute vec4 a_color;\n\t\t\t\tvarying vec4 v_color;\n\t\t\t#endif\n\t\t\t#ifdef USE_TEXTURE\n\t\t\t\tattribute vec2 a_coord;\n\t\t\t\tvarying vec2 v_coord;\n\t\t\t#endif\n\t\t\t#ifdef USE_SIZE\n\t\t\t\tattribute float a_extra;\n\t\t\t#endif\n\t\t\tuniform mat4 u_mvp;\n\t\t\tuniform float u_point_size;\n\t\t\tvoid main() {\n\t\t\t\tgl_PointSize = u_point_size;\n\t\t\t\t#ifdef USE_SIZE\n\t\t\t\t\tgl_PointSize = a_extra;\n\t\t\t\t#endif\n\t\t\t\t#ifdef USE_TEXTURE\n\t\t\t\t\tv_coord = a_coord;\n\t\t\t\t#endif\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\tv_color = a_color;\n\t\t\t\t#endif\n\t\t\t\tgl_Position = u_mvp * vec4(a_vertex,1.0);\n\t\t\t}\t\t\t",
  "\t\t\tprecision mediump float;\n\t\t\tuniform vec4 u_color;\n\t\t\t#ifdef USE_COLOR\n\t\t\t\tvarying vec4 v_color;\n\t\t\t#endif\n\t\t\t#ifdef USE_TEXTURE\n\t\t\t\tvarying vec2 v_coord;\n\t\t\t\tuniform sampler2D u_texture;\n\t\t\t#endif\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = u_color;\n\t\t\t\t#ifdef USE_TEXTURE\n\t\t\t\t  color *= texture2D(u_texture, v_coord);\n\t\t\t\t  if(color.a < 0.1)\n\t\t\t\t\tdiscard;\n\t\t\t    #endif\n\t\t\t\t#ifdef USE_POINTS\n\t\t\t\t    float dist = length( gl_PointCoord.xy - vec2(0.5) );\n\t\t\t\t\tif( dist > 0.45 )\n\t\t\t\t\t\tdiscard;\n\t\t\t    #endif\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\tcolor *= v_color;\n\t\t\t\t#endif\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\t\t",
  {USE_TEXTURE:""}),this.shader_points=new Shader("\t\t\tprecision mediump float;\n\t\t\tattribute vec3 a_vertex;\n\t\t\t#ifdef USE_COLOR\n\t\t\t\tattribute vec4 a_color;\n\t\t\t\tvarying vec4 v_color;\n\t\t\t#endif\n\t\t\t#ifdef USE_TEXTURE\n\t\t\t\tattribute vec2 a_coord;\n\t\t\t\tvarying vec2 v_coord;\n\t\t\t#endif\n\t\t\t#ifdef USE_SIZE\n\t\t\t\tattribute float a_extra;\n\t\t\t#endif\n\t\t\tuniform mat4 u_mvp;\n\t\t\tuniform float u_point_size;\n\t\t\tvoid main() {\n\t\t\t\tgl_PointSize = u_point_size;\n\t\t\t\t#ifdef USE_SIZE\n\t\t\t\t\tgl_PointSize = a_extra;\n\t\t\t\t#endif\n\t\t\t\t#ifdef USE_TEXTURE\n\t\t\t\t\tv_coord = a_coord;\n\t\t\t\t#endif\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\tv_color = a_color;\n\t\t\t\t#endif\n\t\t\t\tgl_Position = u_mvp * vec4(a_vertex,1.0);\n\t\t\t}\t\t\t",
  "\t\t\tprecision mediump float;\n\t\t\tuniform vec4 u_color;\n\t\t\t#ifdef USE_COLOR\n\t\t\t\tvarying vec4 v_color;\n\t\t\t#endif\n\t\t\t#ifdef USE_TEXTURE\n\t\t\t\tvarying vec2 v_coord;\n\t\t\t\tuniform sampler2D u_texture;\n\t\t\t#endif\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = u_color;\n\t\t\t\t#ifdef USE_TEXTURE\n\t\t\t\t  color *= texture2D(u_texture, v_coord);\n\t\t\t\t  if(color.a < 0.1)\n\t\t\t\t\tdiscard;\n\t\t\t    #endif\n\t\t\t\t#ifdef USE_POINTS\n\t\t\t\t    float dist = length( gl_PointCoord.xy - vec2(0.5) );\n\t\t\t\t\tif( dist > 0.45 )\n\t\t\t\t\t\tdiscard;\n\t\t\t    #endif\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\tcolor *= v_color;\n\t\t\t\t#endif\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\t\t",
  {USE_POINTS:""}),this.shader_points_color=new Shader("\t\t\tprecision mediump float;\n\t\t\tattribute vec3 a_vertex;\n\t\t\t#ifdef USE_COLOR\n\t\t\t\tattribute vec4 a_color;\n\t\t\t\tvarying vec4 v_color;\n\t\t\t#endif\n\t\t\t#ifdef USE_TEXTURE\n\t\t\t\tattribute vec2 a_coord;\n\t\t\t\tvarying vec2 v_coord;\n\t\t\t#endif\n\t\t\t#ifdef USE_SIZE\n\t\t\t\tattribute float a_extra;\n\t\t\t#endif\n\t\t\tuniform mat4 u_mvp;\n\t\t\tuniform float u_point_size;\n\t\t\tvoid main() {\n\t\t\t\tgl_PointSize = u_point_size;\n\t\t\t\t#ifdef USE_SIZE\n\t\t\t\t\tgl_PointSize = a_extra;\n\t\t\t\t#endif\n\t\t\t\t#ifdef USE_TEXTURE\n\t\t\t\t\tv_coord = a_coord;\n\t\t\t\t#endif\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\tv_color = a_color;\n\t\t\t\t#endif\n\t\t\t\tgl_Position = u_mvp * vec4(a_vertex,1.0);\n\t\t\t}\t\t\t",
  "\t\t\tprecision mediump float;\n\t\t\tuniform vec4 u_color;\n\t\t\t#ifdef USE_COLOR\n\t\t\t\tvarying vec4 v_color;\n\t\t\t#endif\n\t\t\t#ifdef USE_TEXTURE\n\t\t\t\tvarying vec2 v_coord;\n\t\t\t\tuniform sampler2D u_texture;\n\t\t\t#endif\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = u_color;\n\t\t\t\t#ifdef USE_TEXTURE\n\t\t\t\t  color *= texture2D(u_texture, v_coord);\n\t\t\t\t  if(color.a < 0.1)\n\t\t\t\t\tdiscard;\n\t\t\t    #endif\n\t\t\t\t#ifdef USE_POINTS\n\t\t\t\t    float dist = length( gl_PointCoord.xy - vec2(0.5) );\n\t\t\t\t\tif( dist > 0.45 )\n\t\t\t\t\t\tdiscard;\n\t\t\t    #endif\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\tcolor *= v_color;\n\t\t\t\t#endif\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\t\t",
  {USE_COLOR:"",USE_POINTS:""}),this.shader_points_color_size=new Shader("\t\t\tprecision mediump float;\n\t\t\tattribute vec3 a_vertex;\n\t\t\t#ifdef USE_COLOR\n\t\t\t\tattribute vec4 a_color;\n\t\t\t\tvarying vec4 v_color;\n\t\t\t#endif\n\t\t\t#ifdef USE_TEXTURE\n\t\t\t\tattribute vec2 a_coord;\n\t\t\t\tvarying vec2 v_coord;\n\t\t\t#endif\n\t\t\t#ifdef USE_SIZE\n\t\t\t\tattribute float a_extra;\n\t\t\t#endif\n\t\t\tuniform mat4 u_mvp;\n\t\t\tuniform float u_point_size;\n\t\t\tvoid main() {\n\t\t\t\tgl_PointSize = u_point_size;\n\t\t\t\t#ifdef USE_SIZE\n\t\t\t\t\tgl_PointSize = a_extra;\n\t\t\t\t#endif\n\t\t\t\t#ifdef USE_TEXTURE\n\t\t\t\t\tv_coord = a_coord;\n\t\t\t\t#endif\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\tv_color = a_color;\n\t\t\t\t#endif\n\t\t\t\tgl_Position = u_mvp * vec4(a_vertex,1.0);\n\t\t\t}\t\t\t",
  "\t\t\tprecision mediump float;\n\t\t\tuniform vec4 u_color;\n\t\t\t#ifdef USE_COLOR\n\t\t\t\tvarying vec4 v_color;\n\t\t\t#endif\n\t\t\t#ifdef USE_TEXTURE\n\t\t\t\tvarying vec2 v_coord;\n\t\t\t\tuniform sampler2D u_texture;\n\t\t\t#endif\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = u_color;\n\t\t\t\t#ifdef USE_TEXTURE\n\t\t\t\t  color *= texture2D(u_texture, v_coord);\n\t\t\t\t  if(color.a < 0.1)\n\t\t\t\t\tdiscard;\n\t\t\t    #endif\n\t\t\t\t#ifdef USE_POINTS\n\t\t\t\t    float dist = length( gl_PointCoord.xy - vec2(0.5) );\n\t\t\t\t\tif( dist > 0.45 )\n\t\t\t\t\t\tdiscard;\n\t\t\t    #endif\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\tcolor *= v_color;\n\t\t\t\t#endif\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\t\t",
  {USE_COLOR:"",USE_SIZE:"",USE_POINTS:""}),this.shader_image=new Shader("\t\t\tprecision mediump float;\n\t\t\tattribute vec3 a_vertex;\n\t\t\tuniform mat4 u_mvp;\n\t\t\tuniform float u_point_size;\n\t\t\tvoid main() {\n\t\t\t\tgl_PointSize = u_point_size;\n\t\t\t\tgl_Position = u_mvp * vec4(a_vertex,1.0);\n\t\t\t}\t\t\t","\t\t\tprecision mediump float;\n\t\t\tuniform vec4 u_color;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tvoid main() {\n\t\t\t  vec4 tex = texture2D(u_texture, vec2(gl_PointCoord.x,1.0 - gl_PointCoord.y) );\n\t\t\t  if(tex.a < 0.1)\n\t\t\t\tdiscard;\n\t\t\t  gl_FragColor = u_color * tex;\n\t\t\t}\t\t"),
  this.shader_points_color_texture_size=new Shader("\t\t\tprecision mediump float;\n\t\t\tattribute vec3 a_vertex;\n\t\t\tattribute vec4 a_color;\n\t\t\tattribute float a_extra;\n\t\t\tuniform mat4 u_mvp;\n\t\t\tuniform float u_point_size;\n\t\t\tvarying vec4 v_color;\n\t\t\tvoid main() {\n\t\t\t\tv_color = a_color;\n\t\t\t\tgl_PointSize = u_point_size * a_extra;\n\t\t\t\tgl_Position = u_mvp * vec4(a_vertex,1.0);\n\t\t\t}\t\t\t","\t\t\tprecision mediump float;\n\t\t\tuniform vec4 u_color;\n\t\t\tvarying vec4 v_color;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tvoid main() {\n\t\t\t  vec4 tex = texture2D(u_texture, vec2(gl_PointCoord.x,1.0 - gl_PointCoord.y) );\n\t\t\t  if(tex.a < 0.1)\n\t\t\t\tdiscard;\n\t\t\t  vec4 color = u_color * v_color * tex;\n\t\t\t  gl_FragColor = color;\n\t\t\t}\t\t"),
  this.shader_phong=new Shader("\t\t\tprecision mediump float;\n\t\t\tattribute vec3 a_vertex;\n\t\t\tattribute vec3 a_normal;\n\t\t\tvarying vec3 v_pos;\n\t\t\tvarying vec3 v_normal;\n\t\t\tuniform mat4 u_model;\n\t\t\tuniform mat4 u_mvp;\n\t\t\tvoid main() {\n\t\t\t\tv_pos = (u_model * vec4(a_vertex,1.0)).xyz;\n\t\t\t\tv_normal = (u_model * vec4(a_vertex + a_normal,1.0)).xyz - v_pos;\n\t\t\t\tgl_Position = u_mvp * vec4(a_vertex,1.0);\n\t\t\t}\t\t\t","\t\t\tprecision mediump float;\n\t\t\tuniform vec3 u_ambient_color;\n\t\t\tuniform vec3 u_light_color;\n\t\t\tuniform vec3 u_light_dir;\n\t\t\tuniform vec4 u_color;\n\t\t\tvarying vec3 v_pos;\n\t\t\tvarying vec3 v_normal;\n\t\t\tvoid main() {\n\t\t\t\tvec3 N = normalize(v_normal);\n\t\t\t\tfloat NdotL = max(0.0, dot(N,u_light_dir));\n\t\t\t\tgl_FragColor = u_color * vec4(u_ambient_color + u_light_color * NdotL, 1.0);\n\t\t\t}\t\t"),
  this.shader_phong.uniforms({u_ambient_color:[0.1,0.1,0.1],u_light_color:[0.8,0.8,0.8],u_light_dir:[0,1,0]}),this.shader_depth=new Shader("\t\t\tprecision mediump float;\n\t\t\tattribute vec3 a_vertex;\n\t\t\tvarying vec4 v_pos;\n\t\t\tuniform mat4 u_model;\n\t\t\tuniform mat4 u_mvp;\n\t\t\tvoid main() {\n\t\t\t\tv_pos = u_model * vec4(a_vertex,1.0);\n\t\t\t\tgl_Position = u_mvp * vec4(a_vertex,1.0);\n\t\t\t}\t\t\t","\t\t\tprecision mediump float;\n\t\t\tvarying vec4 v_pos;\n\t\t\t\n\t\t\tvec4 PackDepth32(float depth)\n\t\t\t{\n\t\t\t\tconst vec4 bitSh  = vec4(   256*256*256, 256*256,   256,         1);\n\t\t\t\tconst vec4 bitMsk = vec4(   0,      1.0/256.0,    1.0/256.0,    1.0/256.0);\n\t\t\t\tvec4 comp;\n\t\t\t\tcomp\t= depth * bitSh;\n\t\t\t\tcomp\t= fract(comp);\n\t\t\t\tcomp\t-= comp.xxyz * bitMsk;\n\t\t\t\treturn comp;\n\t\t\t}\n\t\t\tvoid main() {\n\t\t\t\tfloat depth = (v_pos.z / v_pos.w) * 0.5 + 0.5;\n\t\t\t\tgl_FragColor = PackDepth32(depth);\n\t\t\t}\t\t"),
  this.ready=!0)},createSurfaceShader:function(a,b,c){-1==a.indexOf("surface_function")&&(a="vec4 surface_function( vec3 pos, vec3 normal, vec2 coord ) { "+a+"\n } ");if(b)if(b.constructor===String)a=b+";\n"+a;else for(var d in b)a+="uniform "+b[d]+" "+d+";\n";return new GL.Shader("\t\t\tprecision mediump float;\n\t\t\tattribute vec3 a_vertex;\n\t\t\tattribute vec3 a_normal;\n\t\t\tattribute vec2 a_coord;\n\t\t\tvarying vec2 v_coord;\n\t\t\tvarying vec3 v_pos;\n\t\t\tvarying vec3 v_normal;\n\t\t\tuniform mat4 u_mvp;\n\t\t\tuniform mat4 u_model;\n\t\t\tvoid main() {\n\t\t\t\tv_coord = a_coord;\n\t\t\t\tv_pos = (u_model * vec4(a_vertex,1.0)).xyz;\n\t\t\t\tv_normal = (u_model * vec4(a_normal,0.0)).xyz;\n\t\t\t\tgl_Position = u_mvp * vec4(a_vertex,1.0);\n\t\t\t}\t\t\t",
  "\t\t\tprecision mediump float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tvarying vec3 v_pos;\n\t\t\tvarying vec3 v_normal;\n\t\t\tuniform vec4 u_color;\n\t\t\tuniform vec3 u_camera_position;\n\t\t\tuniform sampler2D u_texture;\n\t\t\t"+a+"\n\t\t\tvoid main() {\n\t\t\t\tgl_FragColor = surface_function(v_pos,v_normal,v_coord);\n\t\t\t}\t\t",c)},reset:function(a){this.ready||this.init();a&&(this.images={});this.reset_stack_on_reset&&(this.model_matrix=new Float32Array(this.stack.buffer,0,16),mat4.identity(this.model_matrix))},
  setColor:function(a){for(var b=0;b<a.length;b++)this.color[b]=a[b]},setAlpha:function(a){this.color[3]=a},setPointSize:function(a){this.point_size=a},setCamera:function(a){this.camera=a;a.updateMatrices();vec3.copy(this.camera_position,a.getEye());mat4.copy(this.view_matrix,a._view_matrix);mat4.copy(this.projection_matrix,a._projection_matrix);mat4.copy(this.viewprojection_matrix,a._viewprojection_matrix)},setCameraPosition:function(a){vec3.copy(this.camera_position,a)},pushCamera:function(){this.camera_stack.push(mat4.create(this.viewprojection_matrix))},
  popCamera:function(){if(0==this.camera_stack.length)throw"too many pops";this.viewprojection_matrix.set(this.camera_stack.pop())},setViewProjectionMatrix:function(a,b,c){mat4.copy(this.view_matrix,a);mat4.copy(this.projection_matrix,b);c?mat4.copy(this.viewprojection_matrix,c):mat4.multiply(this.viewprojection_matrix,a,c)},setMatrix:function(a){mat4.copy(this.model_matrix,a)},multMatrix:function(a){mat4.multiply(this.model_matrix,a,this.model_matrix)},renderLines:function(a,b,c){if(a&&a.length){var d=
  null,d=a.constructor==Float32Array?a:this.linearize(a);b&&(b=b.constructor==Float32Array?b:this.linearize(b));b&&b.length/4!=d.length/3&&(b=null);a=this.toGlobalMesh({vertices:d,colors:b});return this.renderMesh(a,c?gl.LINE_STRIP:gl.LINES,b?this.shader_color:this.shader,void 0,0,d.length/3)}},renderPoints:function(a,b,c){if(a&&a.length){var d=null,d=a.constructor==Float32Array?a:a[0].length?this.linearize(a):new Float32Array(a);b&&b.constructor!=Float32Array&&(b=b.constructor===Array&&b[0].constructor===
  Number?new Float32Array(b):this.linearize(b));a=this.toGlobalMesh({vertices:d,colors:b});c||(c=b?this.shader_color:this.shader);return this.renderMesh(a,gl.POINTS,c,void 0,0,d.length/3)}},renderRoundPoints:function(a,b,c){if(a&&a.length){var d=null,d=a.constructor==Float32Array?a:a[0].length?this.linearize(a):new Float32Array(a);b&&(b=b.constructor==Float32Array?b:this.linearize(b));a=this.toGlobalMesh({vertices:d,colors:b});c||(c=b?this.shader_points_color:this.shader_points);return this.renderMesh(a,
  gl.POINTS,c,void 0,0,d.length/3)}},renderPointsWithSize:function(a,b,c,d,f){if(a&&a.length){var g=null,g=a.constructor==Float32Array?a:a[0].length?this.linearize(a):new Float32Array(a);if(!b)throw"colors required in Draw.renderPointsWithSize";b=b.constructor==Float32Array?b:this.linearize(b);if(!c)throw"sizes required in Draw.renderPointsWithSize";c=c.constructor==Float32Array?c:this.linearize(c);a=this.toGlobalMesh({vertices:g,colors:b,extra:c});f=f||(d?this.shader_points_color_texture_size:this.shader_points_color_size);
  return this.renderMesh(a,gl.POINTS,f,void 0,0,g.length/3)}},createRectangleMesh:function(a,b,c,d){var f=new Float32Array(12);c?f.set([0.5*-a,0,0.5*b,0.5*a,0,0.5*b,0.5*a,0,0.5*-b,0.5*-a,0,0.5*-b]):f.set([0.5*-a,0.5*b,0,0.5*a,0.5*b,0,0.5*a,0.5*-b,0,0.5*-a,0.5*-b,0]);return d?this.toGlobalMesh({vertices:f}):GL.Mesh.load({vertices:f})},renderRectangle:function(a,b,c){a=this.createRectangleMesh(a,b,c,!0);return this.renderMesh(a,gl.LINE_LOOP,void 0,void 0,0,this._global_mesh_last_size)},createCircleMesh:function(a,
  b,c,d){b=b||32;quat.create();for(var f=vec3.create(),g=new Float32Array(3*b),e=2*Math.PI/b,k=0;k<b;k++)f[0]=Math.sin(e*k)*a,c?(f[1]=0,f[2]=Math.cos(e*k)*a):(f[2]=0,f[1]=Math.cos(e*k)*a),g.set(f,3*k);return d?this.toGlobalMesh({vertices:g}):GL.Mesh.load({vertices:g})},renderCircle:function(a,b,c,d){a=this.createCircleMesh(a,b,c,!0);return this.renderMesh(a,d?gl.TRIANGLE_FAN:gl.LINE_LOOP,void 0,void 0,0,this._global_mesh_last_size)},renderSolidCircle:function(a,b,c){return this.renderCircle(a,b,c,!0)},
  createSphereMesh:function(a,b,c){b=b||100;quat.create();for(var d=vec3.create(),f=new Float32Array(18*b),g=1/b*Math.PI*2,e=0;e<b;e++)d.set([Math.sin(e*g)*a,Math.cos(e*g)*a,0]),f.set(d,18*e),d.set([Math.sin((e+1)*g)*a,Math.cos((e+1)*g)*a,0]),f.set(d,18*e+3),d.set([Math.sin(e*g)*a,0,Math.cos(e*g)*a]),f.set(d,18*e+6),d.set([Math.sin((e+1)*g)*a,0,Math.cos((e+1)*g)*a]),f.set(d,18*e+9),d.set([0,Math.sin(e*g)*a,Math.cos(e*g)*a]),f.set(d,18*e+12),d.set([0,Math.sin((e+1)*g)*a,Math.cos((e+1)*g)*a]),f.set(d,
  18*e+15);return c?this.toGlobalMesh({vertices:f}):GL.Mesh.load({vertices:f})},renderWireSphere:function(a,b){var c=this.createSphereMesh(a,b,!0);return this.renderMesh(c,gl.LINES,void 0,void 0,0,this._global_mesh_last_size)},createWireBoxMesh:function(a,b,c,d){a*=0.5;b*=0.5;c*=0.5;a=new Float32Array([-a,b,c,-a,b,-c,a,b,-c,a,b,c,-a,-b,c,-a,-b,-c,a,-b,-c,a,-b,c]);b=new Uint16Array([0,1,0,4,0,3,1,2,1,5,2,3,2,6,3,7,4,5,4,7,6,7,5,6]);return d?this.toGlobalMesh({vertices:a},b):GL.Mesh.load({vertices:a,
  lines:b})},renderWireBox:function(a,b,c){a=this.createWireBoxMesh(a,b,c,!0);return this.renderMesh(a,gl.LINES,void 0,"indices",0,this._global_mesh_last_size)},createSolidBoxMesh:function(a,b,c,d){a*=0.5;b*=0.5;c*=0.5;a=[-a,b,-c,-a,-b,+c,-a,b,c,-a,b,-c,-a,-b,-c,-a,-b,+c,a,b,-c,a,b,c,a,-b,+c,a,b,-c,a,-b,+c,a,-b,-c,-a,b,c,a,-b,c,a,b,c,-a,b,c,-a,-b,c,a,-b,c,-a,b,-c,a,b,-c,a,-b,-c,-a,b,-c,a,-b,-c,-a,-b,-c,-a,b,-c,a,b,c,a,b,-c,-a,b,-c,-a,b,c,a,b,c,-a,-b,-c,a,-b,-c,a,-b,c,-a,-b,-c,a,-b,c,-a,-b,c];return d?
  this.toGlobalMesh({vertices:a}):GL.Mesh.load({vertices:a})},renderSolidBox:function(a,b,c){a=this.createSolidBoxMesh(a,b,c,!0);return this.renderMesh(a,gl.TRIANGLES,void 0,void 0,0,this._global_mesh_last_size)},renderWireCube:function(a){return this.renderWireBox(a,a,a)},renderSolidCube:function(a){return this.renderSolidCube(a,a,a)},renderPlane:function(a,b,c,d){if(!a||!b)throw"LS.Draw.renderPlane param missing";this.push();this.translate(a);this.scale(b[0],b[1],1);c&&c.bind(0);!d&&c&&(d=this.shader_texture);
  this.renderMesh(this.quad_mesh,gl.TRIANGLE_FAN,d);c&&c.unbind(0);this.pop()},createGridMesh:function(a,b){a=a||20;b=b||10;for(var c=new Float32Array(12*(2*b+1)),d=0,f=-b;f<=b;f++)c.set([f*a,0,a*b],d),c.set([f*a,0,-a*b],d+3),c.set([a*b,0,f*a],d+6),c.set([-a*b,0,f*a],d+9),d+=12;return GL.Mesh.load({vertices:c})},renderGrid:function(a,b){var c=this.createGridMesh(a,b);return this.renderMesh(c,gl.LINES)},createConeMesh:function(a,b,c,d,f){var e=[0,1,0];c=c||100;var h=quat.create(),k=vec3.create(),m=new Float32Array(3*
  (c+2));m.set(d?[0,0,b]:[0,b,0],0);for(b=0;b<=c;b++)quat.setAxisAngle(h,e,b/c*Math.PI*2),vec3.transformQuat(k,[0,0,a],h),d&&vec3.set(k,k[0],k[2],k[1]),m.set(k,3*b+3);return f?this.toGlobalMesh({vertices:m}):GL.Mesh.load({vertices:m})},renderCone:function(a,b,c,d){a=this.createConeMesh(a,b,c,d,!0);return this.renderMesh(a,gl.TRIANGLE_FAN,void 0,void 0,0,this._global_mesh_last_size)},createCylinderMesh:function(a,b,c,d,f){d=[0,1,0];c=c||100;for(var e=quat.create(),h=vec3.create(),k=new Float32Array(6*
  (c+1)),m=0;m<=c;m++)quat.setAxisAngle(e,d,m/c*Math.PI*2),vec3.transformQuat(h,[0,0,a],e),k.set(h,6*m+3),h[1]=b,k.set(h,6*m);return f?this.toGlobalMesh({vertices:k}):GL.Mesh.load({vertices:k})},renderCylinder:function(a,b,c,d){a=this.createCylinderMesh(a,b,c,d,!0);return this.renderMesh(a,gl.TRIANGLE_STRIP,void 0,void 0,0,this._global_mesh_last_size)},renderImage:function(a,b,c,d){if(!a||!b)throw"LS.Draw.renderImage param missing";c=c||10;var f=null;if("string"==typeof b){f=this.images[b];if(null==
  f){Fa.images[b]=1;a=new Image;a.src=b;a.onload=function(){var a=GL.Texture.fromImage(this);Fa.images[b]=a;if(Fa.onRequestFrame)Fa.onRequestFrame()};return}if(1==f)return}else b.constructor==Image?(b.texture||(b.texture=GL.Texture.fromImage(this)),f=b.texture):b.constructor==Texture&&(f=b);f&&(d?(this.setPointSize(c),f.bind(0),this.renderPoints(a,null,this.shader_image)):(this.push(),this.billboard(a),this.scale(c,c,c),f.bind(0),this.renderMesh(this.quad_mesh,gl.TRIANGLE_FAN,this.shader_texture),this.pop()))},
  renderMesh:function(a,b,c,d,f,e){if(!this.ready)throw"Draw.js not initialized, call Draw.init()";if(!a)throw"LS.Draw.renderMesh mesh cannot be null";c||(c=a===this._global_mesh&&this._global_mesh_ignore_colors?this.shader:a.vertexBuffers.colors?this.shader_color:this.shader);mat4.multiply(this.mvp_matrix,this.viewprojection_matrix,this.model_matrix);c.uniforms({u_model:this.model_matrix,u_mvp:this.mvp_matrix,u_color:this.color,u_camera_position:this.camera_position,u_point_size:this.point_size,u_texture:0});
  void 0===f?c.draw(a,void 0===b?gl.TRIANGLES:b,d):c.drawRange(a,void 0===b?gl.TRIANGLES:b,f,e,d);this._last_mesh=a;this._last_primitive=b;this._last_shader=c;this._last_indices=d;this._last_range_start=f;this._last_range_length=e;return this.last_mesh=a},repeatLastRender:function(){this.renderMesh(this._last_mesh,this._last_primitive,this._last_shader,this._last_indices,this._last_range_start,this._last_range_length)},renderText:function(a){Fa.font_atlas||this.createFontAtlas();for(var b=this.font_atlas,
  c=a.length,d=b.atlas.char_size,f=b.atlas.spacing,e=0,h=0;h<c;++h)null!=b.atlas[a.charCodeAt(h)]&&e++;for(var k=new Float32Array(18*e),e=new Float32Array(12*e),m=0,l=0,p=0,h=0;h<c;++h){var n=b.atlas[a.charCodeAt(h)];n?(k.set([l,p,0],18*m),k.set([l,p+d,0],18*m+3),k.set([l+d,p+d,0],18*m+6),k.set([l+d,p,0],18*m+9),k.set([l,p,0],18*m+12),k.set([l+d,p+d,0],18*m+15),e.set([n[0],n[1]],12*m),e.set([n[0],n[3]],12*m+2),e.set([n[2],n[3]],12*m+4),e.set([n[2],n[1]],12*m+6),e.set([n[0],n[1]],12*m+8),e.set([n[2],
  n[3]],12*m+10),l+=f,++m):10==a.charCodeAt(h)?(l=0,p-=d):l+=d}a=this.toGlobalMesh({vertices:k,coords:e});b.bind(0);return this.renderMesh(a,gl.TRIANGLES,this.shader_texture,void 0,0,k.length/3)},createFontAtlas:function(){var a=createCanvas(512,512),b=0.09*a.width|0,c=0.1*a.width|0,d=a.getContext("2d");d.fillStyle="white";d.font=b+"px Courier New";d.textAlign="center";for(var f=0,e=0,b=-0.3*b,h={char_size:c,spacing:0.6*c},k=6;100>k;k++){var m=String.fromCharCode(k+27);h[k+27]=[f/a.width,1-(e+c)/a.height,
  (f+c)/a.width,1-e/a.height];d.fillText(m,Math.floor(f+0.5*c),Math.floor(e+c+b),c);f+=c;f+c>a.width&&(f=0,e+=c)}this.font_atlas=GL.Texture.fromImage(a,{magFilter:gl.NEAREST,minFilter:gl.LINEAR});this.font_atlas.atlas=h},linearize:function(a){for(var b=a[0].length,c=new Float32Array(a.length*b),d=a.length,f=0;f<d;++f)c.set(a[f],f*b);return c},push:function(){if(this.model_matrix.byteOffset>=this.stack.byteLength-64)throw"matrices stack overflow";var a=this.model_matrix;this.model_matrix=new Float32Array(this.stack.buffer,
  this.model_matrix.byteOffset+64,16);mat4.copy(this.model_matrix,a)},pop:function(){if(0==this.model_matrix.byteOffset)throw"too many pops";this.model_matrix=new Float32Array(this.stack.buffer,this.model_matrix.byteOffset-64,16)},identity:function(){mat4.identity(this.model_matrix)},scale:function(a,b,c){3==arguments.length?mat4.scale(this.model_matrix,this.model_matrix,[a,b,c]):a.length?mat4.scale(this.model_matrix,this.model_matrix,a):mat4.scale(this.model_matrix,this.model_matrix,[a,a,a])},translate:function(a,
  b,c){3==arguments.length?mat4.translate(this.model_matrix,this.model_matrix,[a,b,c]):mat4.translate(this.model_matrix,this.model_matrix,a)},rotate:function(a,b,c,d){4==arguments.length?mat4.rotate(this.model_matrix,this.model_matrix,a*DEG2RAD,[b,c,d]):mat4.rotate(this.model_matrix,this.model_matrix,a*DEG2RAD,b)},lookAt:function(a,b,c){mat4.lookAt(this.model_matrix,a,b,c);mat4.invert(this.model_matrix,this.model_matrix)},billboard:function(a){mat4.invert(this.model_matrix,this.view_matrix);mat4.setTranslation(this.model_matrix,
  a)},fromTranslationFrontTop:function(a,b,c){mat4.fromTranslationFrontTop(this.model_matrix,a,b,c)},project:function(a,b){b=b||vec3.create();return mat4.multiplyVec3(b,this.mvp_matrix,a)},getPhongShader:function(a,b,c){this.shader_phong.uniforms({u_ambient_color:a,u_light_color:b,u_light_dir:c});return this.shader_phong},getDepthShader:function(){return this.shader_depth},toGlobalMesh:function(a,b){this._global_mesh||(this._global_mesh_max_vertices=1024,this._global_mesh=new GL.Mesh({vertices:new Float32Array(3*
  this._global_mesh_max_vertices),normals:new Float32Array(3*this._global_mesh_max_vertices),coords:new Float32Array(2*this._global_mesh_max_vertices),colors:new Float32Array(4*this._global_mesh_max_vertices),extra:new Float32Array(1*this._global_mesh_max_vertices)},{indices:new Uint16Array(3*this._global_mesh_max_vertices)},{stream_type:gl.DYNAMIC_STREAM}));for(var c in a){var d=this._global_mesh.getBuffer(c);if(d){var f=a[c];f&&(f.buffer||(f=new Float32Array(f)),f.length>d.data.length&&(console.warn("Draw: data is too big, resizing"),
  this.resizeGlobalMesh(),d=this._global_mesh.getBuffer(c),f=f.subarray(0,d.data.length)),d.setData(f))}else console.warn("Draw: global mesh lacks one buffer: "+c)}this._global_mesh_ignore_colors=!a.colors;b?(d=this._global_mesh.getIndexBuffer("indices"),d.setData(b),this._global_mesh_last_size=b.length):this._global_mesh_last_size=a.vertices.length/3;return this._global_mesh},resizeGlobalMesh:function(){if(!this._global_mesh)throw"No global mesh to resize";this._global_mesh_max_vertices*=2;this._global_mesh.deleteBuffers();
  this._global_mesh=new GL.Mesh({vertices:new Float32Array(3*this._global_mesh_max_vertices),normals:new Float32Array(3*this._global_mesh_max_vertices),coords:new Float32Array(2*this._global_mesh_max_vertices),colors:new Float32Array(4*this._global_mesh_max_vertices),extra:new Float32Array(1*this._global_mesh_max_vertices)},{indices:new Uint16Array(3*this._global_mesh_max_vertices)},{stream_type:gl.DYNAMIC_STREAM})}};"undefined"!=typeof e&&(e.Draw=Fa);GL.Mesh.prototype.convertBonesToNames=function(a){if(!this.bones||
  !this.bones.length)return 0;for(var b=!1,c=0;c<this.bones.length;++c){var d=this.bones[c],f=d[0];if(f[0]==e._uid_prefix){var g=a?a.findNode(f):e.GlobalScene.getNode(f);g?(d[0]=g.name,b=!0):console.warn("Bone node not found: "+f)}}b&&e.RM.resourceModified(this)};GL.Mesh.fromBinary=function(a){var b=null,b=a.constructor==ArrayBuffer?z.load(a):a;a={};for(var c in b.vertex_buffers)a[b.vertex_buffers[c]]=b[b.vertex_buffers[c]];var d={};for(c in b.index_buffers)d[b.index_buffers[c]]=b[b.index_buffers[c]];
  a=new GL.Mesh(a,d);a.info=b.info;a.bounding=b.bounding;if(b.bones){a.bones=b.bones;for(c=0;c<a.bones.length;++c)a.bones[c][1]=mat4.clone(a.bones[c][1]);b.bind_matrix&&(a.bind_matrix=mat4.clone(b.bind_matrix))}return a};GL.Mesh.prototype.toBinary=function(){this.info||(this.info={});var a={object_type:"Mesh",info:this.info,groups:this.groups};if(this.bones){for(var b=[],c=0;c<this.bones.length;++c)b.push([this.bones[c][0],mat4.toArray(this.bones[c][1])]);a.bones=b;this.bind_matrix&&(a.bind_matrix=
  this.bind_matrix)}this.bounding||this.updateBounding();a.bounding=this.bounding;var b=[],d=[];for(c in this.vertexBuffers){var f=this.vertexBuffers[c];a[f.name]=f.data;b.push(f.name);"vertices"==f.name&&(a.info.num_vertices=f.data.length/3)}for(c in this.indexBuffers)f=this.indexBuffers[c],a[c]=f.data,d.push(c);a.vertex_buffers=b;a.index_buffers=d;return z.create(a,"Mesh")};s["@color"]={type:"color"};s["@blend_mode"]={type:"enum",values:e.Blend};s.icon="mini-icon-material.png";s.COLOR="color";s.OPACITY=
  "opacity";s.BLEND_MODE="blend_mode";s.SPECULAR_FACTOR="specular_factor";s.SPECULAR_GLOSS="specular_gloss";s.OPACITY_TEXTURE="opacity";s.COLOR_TEXTURE="color";s.AMBIENT_TEXTURE="ambient";s.SPECULAR_TEXTURE="specular";s.EMISSIVE_TEXTURE="emissive";s.ENVIRONMENT_TEXTURE="environment";s.COORDS_UV0="0";s.COORDS_UV1="1";s.COORDS_UV_TRANSFORMED="transformed";s.COORDS_SCREEN="screen";s.COORDS_SCREENCENTERED="screen_centered";s.COORDS_FLIPPED_SCREEN="flipped_screen";s.COORDS_POLAR="polar";s.COORDS_POLAR_REFLECTED=
  "polar_reflected";s.COORDS_POLAR_VERTEX="polar_vertex";s.COORDS_WORLDXZ="worldxz";s.COORDS_WORLDXY="worldxy";s.COORDS_WORLDYZ="worldyz";s.TEXTURE_COORDINATES=[s.COORDS_UV0,s.COORDS_UV1,s.COORDS_UV_TRANSFORMED,s.COORDS_SCREEN,s.COORDS_SCREENCENTERED,s.COORDS_FLIPPED_SCREEN,s.COORDS_POLAR,s.COORDS_POLAR_REFLECTED,s.COORDS_POLAR_VERTEX,s.COORDS_WORLDXY,s.COORDS_WORLDXZ,s.COORDS_WORLDYZ];s.DEFAULT_UVS={normal:s.COORDS_UV0,displacement:s.COORDS_UV0,environment:s.COORDS_POLAR_REFLECTED,irradiance:s.COORDS_POLAR};
  s.available_shaders="default global lowglobal phong_texture flat normal phong flat_texture cell_outline".split(" ");s.texture_channels=[];s.prototype.applyToRenderInstance=function(a){this.blend_mode!=e.Blend.NORMAL&&(a.flags|=Ya);a.blend_func=this.blend_mode==e.Blend.CUSTOM&&this.blend_func?this.blend_func:e.BlendFunctions[this.blend_mode]};s.prototype.fillShaderQuery=function(a){a=this._query;a.clear();for(var b in this.textures){var c=this.getTextureSampler(b);if(c){var d=c.uvs||s.DEFAULT_UVS[b]||
  "0";(c=s.getTextureFromSampler(c))&&(a.macros["USE_"+b.toUpperCase()+(c.texture_type==gl.TEXTURE_2D?"_TEXTURE":"_CUBEMAP")]="uvs_"+d)}}if(this.extra_macros)for(var f in this.extra_macros)a.macros[f]=this.extra_macros[f]};s.prototype.fillUniforms=function(a,b){var c={},d=[];c.u_material_color=this._color;c.u_ambient_color=a.info?a.info.ambient_color:this._diffuse;c.u_texture_matrix=this.uvs_matrix;c.u_specular=vec2.create([1,50]);var f=c.u_reflection=0,e;for(e in this.textures){var h=this.getTextureSampler(e);
  if(h){var k=s.getTextureFromSampler(h);k&&(d[f]=h,c[e+(k.texture_type==gl.TEXTURE_2D?"_texture":"_cubemap")]=f,f++)}}for(e in this.extra_uniforms)c[e]=this.extra_uniforms[e];this._uniforms=c;this._samplers=d};s.prototype.configure=function(a){for(var b in a)!this.setProperty(b,a[b])&&e.debug&&console.warn("Material property not assigned: "+b)};s.prototype.serialize=function(){var a=e.cloneObject(this);a.material_class=e.getObjectClassName(this);return a};s.prototype.clone=function(){var a=this.serialize();
  a.uid&&delete a.uid;return new this.constructor(JSON.parse(JSON.stringify(a)))};s.prototype.loadAndSetTexture=function(a,b,c){c=c||{};var d=this;if("string"===typeof b)":"!=b[0]?e.ResourcesManager.load(b,c,function(b){d.setTexture(a,b);if(c.on_complete)c.on_complete()}):this.setTexture(a,b);else if(this.setTexture(a,b),c.on_complete)c.on_complete()};s.prototype.getPropertiesInfo=function(){var a={color:"vec3",opacity:"number",blend_mode:"number",alpha_test:"boolean",alpha_test_shadows:"boolean",uvs_matrix:"mat3"},
  b=this.getTextureChannels(),c;for(c in b)a["tex_"+b[c]]="Texture";return a};s.prototype.getProperty=function(a){return"tex_"==a.substr(0,4)?this.textures[a.substr(4)]:this[a]};s.prototype.setProperty=function(a,b){if("tex_"==a.substr(0,4))return(!b||b.constructor!==String&&b.constructor!==GL.Texture)&&b||this.setTexture(a.substr(4),b),!0;switch(a){case "opacity":case "specular_factor":case "specular_gloss":case "reflection":b.constructor===Number&&(this[a]=b);break;case "alpha_test":case "alpha_test_shadows":case "blend_mode":this[a]=
  b;break;case "uvs_matrix":case "color":this[a].length==b.length&&this[a].set(b);break;case "textures":for(var c in b){var d=b[c];"string"==typeof d&&(d={texture:d,uvs:"0",wrap:0,minFilter:0,magFilter:0});this.textures[c]=d}break;case "transparency":this.opacity=1-b;break;default:return!1}return!0};s.prototype.setPropertyValueFromPath=function(a,b,c){c=c||0;a.length<c+1||this.setProperty(a[c],b)};s.prototype.getPropertyInfoFromPath=function(a){if(!(1>a.length)){a=a[0];var b=null;switch(a){case "opacity":case "transparency":case "specular_factor":case "specular_gloss":case "reflection":case "blend_mode":b=
  "number";break;case "alpha_test":case "alpha_test_shadows":b="boolean";break;case "uvs_matrix":b="mat3";break;case "color":b="vec3";break;case "textures":b="Texture";break;default:return null}return{node:this._root,target:this,name:a,value:this[a],type:b}}};s.prototype.getTextureChannels=function(){return this.constructor.texture_channels?this.constructor.texture_channels:[]};s.prototype.setTexture=function(a,b,c){if(!a)throw"Material.prototype.setTexture channel must be specified";if(b){var d=this.textures[a];
  if(d){if(d.texture==b)return d;d.texture=b}else this.textures[a]=d={texture:b,uvs:s.DEFAULT_UVS[a]||"0",wrap:0,minFilter:0,magFilter:0};if(c)for(var f in c)d[f]=c[f];b.constructor===String&&":"!=b[0]&&e.ResourcesManager.load(b);return d}delete this.textures[a]};s.prototype.setTextureProperty=function(a,b,c){var d=this.textures[a];d?d[b]=c:"texture"==b&&(this.textures[a]={texture:c,uvs:s.DEFAULT_UVS[a]||"0",wrap:0,minFilter:0,magFilter:0})};s.prototype.getTexture=function(a){a=a||s.COLOR_TEXTURE;a=
  this.textures[a];return a?a.constructor===String?e.ResourcesManager.textures[a]:(a=a.texture)?a.constructor===String?e.ResourcesManager.textures[a]:a.constructor==Texture?a:null:null:null};s.prototype.getTextureSampler=function(a){return this.textures[a]};s.getTextureFromSampler=function(a){a=a.constructor===String?a:a.texture;if(!a)return null;a.constructor===String&&(a=e.ResourcesManager.textures[a]);return a&&a.constructor==GL.Texture?a:null};s.prototype.setTextureSampler=function(a,b){if(!a)throw"Cannot call Material setTextureSampler without channel";
  b?this.textures[a]=b:delete this.textures[a]};s.prototype.getResources=function(a){for(var b in this.textures){var c=this.textures[b];c&&"string"==typeof c.texture&&(a[c.texture]=GL.Texture)}return a};s.prototype.onResourceRenamed=function(a,b,c){for(var d in this.textures)(c=this.textures[d])&&c.texture==a&&(c.texture=b)};s.prototype.loadTextures=function(){var a=this.getResources({}),b;for(b in a)e.ResourcesManager.load(b)};s.prototype.registerMaterial=function(a){this.name=a;e.ResourcesManager.registerResource(a,
  this);this.material=a};s.prototype.getCategory=function(){return this.category||"Material"};s.prototype.updatePreview=function(a,b){b=b||{};var c={};this.getResources(c);for(var d in c)if(!e.ResourcesManager.resources[d])return console.warn("Cannot generate preview with resources missing."),null;e.GlobalScene.info.textures.environment&&(b.environment=e.GlobalScene.info.textures.environment);if(c=e.Renderer.renderMaterialPreview(this,a||256,b))this.preview=c,c.toDataURL&&(this._preview_url=c.toDataURL("image/png"))};
  s.prototype.getLocator=function(){return this._root?this._root.uid+"/material":this.uid};s.processShaderCode=function(a){a=a.split("\n");for(var b in a)a[b]=a[b].split("//")[0];return(a=a.join(""))?a:null};s.prototype.createProperty=function(a,b,c,d){c&&(e.validatePropertyType(c),this.constructor["@"+a]={type:c});d&&(this.constructor["@"+a]||(this.constructor["@"+a]={}),e.cloneObject(d,this.constructor["@"+a]));b.constructor===Number||b.constructor===String||b.constructor===Boolean?this[a]=b:b.constructor===
  Float32Array&&(c="_"+a,b=new Float32Array(b),this[c]=b,Object.defineProperty(this,a,{get:function(){return b},set:function(a){b.set(a)},enumerable:!0}))};s.prototype.prepareMaterial=function(a){this._uniforms||(this._uniforms={},this._samplers=[]);this.fillShaderQuery(a);this.fillUniforms(a)};e.registerResourceClass(s);e.Material=s;Object.defineProperty(P.prototype,"detail_factor",{get:function(){return this._detail[0]},set:function(a){this._detail[0]=a},enumerable:!0});Object.defineProperty(P.prototype,
  "detail_scale",{get:function(){return this._detail.subarray(1,3)},set:function(a){this._detail[1]=a[0];this._detail[2]=a[1]},enumerable:!0});Object.defineProperty(P.prototype,"extra_factor",{get:function(){return this._extra_data[3]},set:function(a){this._extra_data[3]=a},enumerable:!0});Object.defineProperty(P.prototype,"extra_color",{get:function(){return this._extra_data.subarray(0,3)},set:function(a){this._extra_data.set(a)},enumerable:!0});Object.defineProperty(P.prototype,"specular_factor",
  {get:function(){return this._specular_data[0]},set:function(a){this._specular_data[0]=a},enumerable:!0});Object.defineProperty(P.prototype,"specular_gloss",{get:function(){return this._specular_data[1]},set:function(a){this._specular_data[1]=a},enumerable:!0});P.DETAIL_TEXTURE="detail";P.NORMAL_TEXTURE="normal";P.DISPLACEMENT_TEXTURE="displacement";P.BUMP_TEXTURE="bump";P.REFLECTIVITY_TEXTURE="reflectivity";P.IRRADIANCE_TEXTURE="irradiance";P.EXTRA_TEXTURE="extra";P.texture_channels=[s.COLOR_TEXTURE,
  s.OPACITY_TEXTURE,s.AMBIENT_TEXTURE,s.SPECULAR_TEXTURE,s.EMISSIVE_TEXTURE,P.DETAIL_TEXTURE,P.NORMAL_TEXTURE,P.DISPLACEMENT_TEXTURE,P.BUMP_TEXTURE,P.REFLECTIVITY_TEXTURE,s.ENVIRONMENT_TEXTURE,P.IRRADIANCE_TEXTURE,P.EXTRA_TEXTURE];P.available_shaders="default lowglobal phong_texture flat normal phong flat_texture".split(" ");P.coding_help="Input IN -> info about the mesh\nSurfaceOutput o -> info about the surface properties of this pixel\n\nstruct Input {\n\tvec4 color;\n\tvec3 vertex;\n\tvec3 normal;\n\tvec2 uv;\n\tvec2 uv1;\n\t\n\tvec3 camPos;\n\tvec3 viewDir;\n\tvec3 worldPos;\n\tvec3 worldNormal;\n\tvec4 screenPos;\n};\n\nstruct SurfaceOutput {\n\tvec3 Albedo;\n\tvec3 Normal;\n\tvec3 Ambient;\n\tvec3 Emission;\n\tfloat Specular;\n\tfloat Gloss;\n\tfloat Alpha;\n\tfloat Reflectivity;\n};\n";
  P.prototype.fillShaderQuery=function(a){a=this._query;a.clear();for(var b in this.textures){var c=this.getTextureSampler(b);if(c){var d=c.uvs||s.DEFAULT_UVS[b]||"0";if(c=s.getTextureFromSampler(c))"normal"==b?0!=this.normalmap_factor&&(!this.normalmap_tangent||this.normalmap_tangent&&gl.derivatives_supported)&&(a.macros.USE_NORMAL_TEXTURE="uvs_"+d,0!=this.normalmap_factor&&(a.macros.USE_NORMALMAP_FACTOR=""),this.normalmap_tangent&&gl.derivatives_supported&&(a.macros.USE_TANGENT_NORMALMAP="")):"displacement"==
  b?0!=this.displacementmap_factor&&gl.derivatives_supported&&(a.macros.USE_DISPLACEMENT_TEXTURE="uvs_"+d,1!=this.displacementmap_factor&&(a.macros.USE_DISPLACEMENTMAP_FACTOR="")):"bump"==b?0!=this.bump_factor&&gl.derivatives_supported&&(a.macros.USE_BUMP_TEXTURE="uvs_"+d,1!=this.bumpmap_factor&&(a.macros.USE_BUMP_FACTOR="")):a.macros["USE_"+b.toUpperCase()+(c.texture_type==gl.TEXTURE_2D?"_TEXTURE":"_CUBEMAP")]="uvs_"+d}}this.velvet&&this.velvet_exp&&(a.macros.USE_VELVET="");this.emissive_material&&
  (a.macros.USE_EMISSIVE_MATERIAL="");this.specular_ontop&&(a.macros.USE_SPECULAR_ONTOP="");this.specular_on_alpha&&(a.macros.USE_SPECULAR_ON_ALPHA="");this.reflection_specular&&(a.macros.USE_SPECULAR_IN_REFLECTION="");0.001<this.backlight_factor&&(a.macros.USE_BACKLIGHT="");0<this.reflection_factor&&(a.macros.USE_REFLECTION="");this.extra_surface_shader_code&&(b=null,this._last_extra_surface_shader_code!=this.extra_surface_shader_code?this._last_processed_extra_surface_shader_code=b=s.processShaderCode(this.extra_surface_shader_code):
  b=this._last_processed_extra_surface_shader_code,b&&(a.macros.USE_EXTRA_SURFACE_SHADER_CODE=b));if(this.extra_macros)for(var f in this.extra_macros)a.macros[f]=this.extra_macros[f]};P.prototype.fillUniforms=function(a,b){var c={},d=[];c.u_material_color=this._color;c.u_ambient_color=this.use_scene_ambient&&a.info&&!this.textures.ambient?vec3.fromValues(a.info.ambient_color[0]*this.ambient[0],a.info.ambient_color[1]*this.ambient[1],a.info.ambient_color[2]*this.ambient[2]):this.ambient;c.u_emissive_color=
  this.emissive||vec3.create();c.u_specular=this._specular_data;c.u_reflection_info=[this.reflection_additive?-this.reflection_factor:this.reflection_factor,this.reflection_fresnel];c.u_backlight_factor=this.backlight_factor;c.u_normalmap_factor=this.normalmap_factor;c.u_displacementmap_factor=this.displacementmap_factor;c.u_bumpmap_factor=this.bumpmap_factor;this._velvet_info.set(this.velvet);this._velvet_info[3]=this.velvet_additive?this.velvet_exp:-this.velvet_exp;c.u_velvet_info=this._velvet_info;
  c.u_detail_info=this._detail;c.u_extra_data=this._extra_data;c.u_texture_matrix=this.uvs_matrix;var f=0,g;for(g in this.textures){var h=this.getTextureSampler(g);if(h){var k=h.texture;if(k){if(k.constructor===String)k=e.ResourcesManager.textures[k];else if(k.constructor!=Texture)continue;k||(h={texture:":missing"});var m=f;"environment"==g?m=e.Renderer.ENVIRONMENT_TEXTURE_SLOT:"irradiance"==g?m=e.Renderer.IRRADIANCE_TEXTURE_SLOT:f++;d[m]=h;c[g+(k&&k.texture_type!=gl.TEXTURE_2D?"_cubemap":"_texture")]=
  m}}}for(g in this.extra_uniforms)c[g]=this.extra_uniforms[g];this._uniforms=c;this._samplers=d};P.prototype.setProperty=function(a,b){if(s.prototype.setProperty.call(this,a,b))return!0;switch(a){case "specular_factor":case "specular_gloss":case "backlight_factor":case "reflection_factor":case "reflection_fresnel":case "velvet_exp":case "velvet_additive":case "normalmap_tangent":case "normalmap_factor":case "displacementmap_factor":case "extra_factor":case "detail_factor":case "shader_name":case "specular_ontop":case "normalmap_tangent":case "reflection_specular":case "use_scene_ambient":case "extra_surface_shader_code":this[a]=
  b;break;case "ambient":case "emissive":case "velvet":case "detail_scale":case "extra_color":this[a].length==b.length&&this[a].set(b);break;case "extra_uniforms":this.extra_uniforms=e.cloneObject(b);break;default:return!1}return!0};P.prototype.getPropertiesInfo=function(){var a=s.prototype.getPropertiesInfo.call(this);a.merge({shader_name:e.TYPES.STRING,specular_factor:e.TYPES.NUMBER,specular_gloss:e.TYPES.NUMBER,backlight_factor:e.TYPES.NUMBER,reflection_factor:e.TYPES.NUMBER,reflection_fresnel:e.TYPES.NUMBER,
  velvet_exp:e.TYPES.NUMBER,normalmap_factor:e.TYPES.NUMBER,displacementmap_factor:e.TYPES.NUMBER,extra_factor:e.TYPES.NUMBER,extra_surface_shader_code:e.TYPES.STRING,ambient:e.TYPES.VEC3,emissive:e.TYPES.VEC3,velvet:e.TYPES.VEC3,extra_color:e.TYPES.VEC3,detail_factor:e.TYPES.NUMBER,detail_scale:e.TYPES.VEC2,specular_ontop:e.TYPES.BOOLEAN,normalmap_tangent:e.TYPES.BOOLEAN,reflection_specular:e.TYPES.BOOLEAN,use_scene_ambient:e.TYPES.BOOLEAN,velvet_additive:e.TYPES.BOOLEAN});return a};P.prototype.getPropertyInfoFromPath=
  function(a){if(!(1>a.length)){var b=s.prototype.getPropertyInfoFromPath.call(this,a);if(b)return b;a=a[0];switch(a){case "backlight_factor":case "reflection_factor":case "reflection_fresnel":case "velvet_exp":case "normalmap_factor":case "displacementmap_factor":case "extra_factor":case "detail_factor":type=e.TYPES.NUMBER;break;case "extra_surface_shader_code":type=e.TYPES.STRING;break;case "ambient":case "emissive":case "velvet":case "extra_color":type=e.TYPES.VEC3;break;case "detail_scale":type=
  e.TYPES.VEC2;break;case "specular_ontop":case "normalmap_tangent":case "reflection_specular":case "use_scene_ambient":case "velvet_additive":type=e.TYPES.BOOLEAN;break;default:return null}return{node:this._root,target:this,name:a,value:this[a],type:type}}};e.registerMaterialClass(P);e.StandardMaterial=P;$.icon="mini-icon-material.png";$.coding_help="struct Input {\n\tvec4 color;\n\tvec3 vertex;\n\tvec3 normal;\n\tvec2 uv;\n\tvec2 uv1;\n\t\n\tvec3 camPos;\n\tvec3 viewDir;\n\tvec3 worldPos;\n\tvec3 worldNormal;\n\tvec4 screenPos;\n};\n\nstruct SurfaceOutput {\n\tvec3 Albedo; /*store the color output here*/\n\tvec3 Normal;\n\tvec3 Emission;\n\tfloat Specular;\n\tfloat Gloss;\n\tfloat Alpha;\n\tfloat Reflectivity;\n};\n";
  $.prototype.onCodeChange=function(){this.computeCode()};$.prototype.getCode=function(){return this.code};$.prototype.computeCode=function(){for(var a="",b=0,c=this.properties.length;b<c;++b){var d="uniform ",f=this.properties[b];switch(f.type){case "number":d+="float ";break;case "vec2":d+="vec2 ";break;case "color":case "vec3":d+="vec3 ";break;case "color4":case "vec4":d+="vec4 ";break;case "texture":d+="sampler2D ";break;case "cubemap":d+="samplerCube ";break;default:continue}d+=f.name+";";a+=d}d=
  this.code.split("\n");b=0;for(c=d.length;b<c;++b)d[b]=d[b].split("//")[0];this.surf_code=a+d.join("")};$.prototype.onModifyQuery=function(a){this._ps_uniforms_code&&(a.macros.USE_PIXEL_SHADER_UNIFORMS=a.macros.USE_PIXEL_SHADER_UNIFORMS?a.macros.USE_PIXEL_SHADER_UNIFORMS+this._ps_uniforms_code:this._ps_uniforms_code);this._ps_functions_code&&(a.macros.USE_PIXEL_SHADER_FUNCTIONS=a.macros.USE_PIXEL_SHADER_FUNCTIONS?a.macros.USE_PIXEL_SHADER_FUNCTIONS+this._ps_functions_code:this._ps_functions_code);
  this._ps_code&&(a.macros.USE_PIXEL_SHADER_CODE=a.macros.USE_PIXEL_SHADER_CODE?a.macros.USE_PIXEL_SHADER_CODE+this._ps_code:this._ps_code);a.macros.USE_SURFACE_SHADER=this.surf_code};$.prototype.fillShaderQuery=function(a){a=this._query;a.clear();if(this.textures.environment){var b=this.textures.environment,c=e.getTexture(b.texture);c&&(a.macros["USE_ENVIRONMENT_"+(c.type==gl.TEXTURE_2D?"TEXTURE":"CUBEMAP")]=b.uvs)}};$.prototype.fillUniforms=function(a,b){for(var c=[],d=0,f=0,g=this.properties.length;f<
  g;++f){var h=this.properties[f];if("texture"==h.type||"cubemap"==h.type||"sampler"==h.type){if(h.value){var k=e.getTexture("sampler"==h.type?h.value.texture:h.value);k||(k=":missing");c[d]=k;this._uniforms[h.name]=d;d++}}else this._uniforms[h.name]=h.value}this._uniforms.u_material_color=this._color;this._samplers=c};$.prototype.configure=function(a){e.cloneObject(a,this);this.computeCode()};$.prototype.onResourceRenamed=function(a,b,c){s.prototype.onResourceRenamed.call(this,a,b,c);c=0;for(var d=
  this.properties.length;c<d;++c){var f=this.properties[c];f.value==a&&(f.value=b)}};$.prototype.getPropertiesInfo=function(){var a={color:e.TYPES.VEC3,opacity:e.TYPES.NUMBER,shader_name:e.TYPES.STRING,blend_mode:e.TYPES.NUMBER,code:e.TYPES.STRING},b;for(b in this.properties){var c=this.properties[b];a[c.name]=c.type}return a};$.prototype.getProperty=function(a){if(this[a])return this[a];if("tex_"==a.substr(0,4))return(a=this.textures[a.substr(4)])?a.texture:null;for(var b=0,c=this.properties.length;b<
  c;++b){var d=this.properties[b];if(d.name==a)return d.value}return null};$.prototype.setProperty=function(a,b){if(s.prototype.setProperty.call(this,a,b))return!0;for(var c=0,d=this.properties.length;c<d;++c){var f=this.properties[c];if(f.name==a)return f.value=b,!0}return!1};$.prototype.getPropertyInfoFromPath=function(a){if(!(1>a.length)){a=a[0];for(var b=0,c=this.properties.length;b<c;++b){var d=this.properties[b];if(d.name==a)return{node:this._root,target:this,name:d.name,value:d.value,type:d.type}}}};
  $.prototype.getTextureChannels=function(){for(var a=[],b=0,c=this.properties.length;b<c;++b){var d=this.properties[b];"texture"!=d.type&&"cubemap"!=d.type&&"sampler"!=d.type||a.push(d.name)}return a};$.prototype.setTexture=function(a,b,c){if(!a)throw"CustomMaterial.prototype.setTexture channel must be specified";var d=null;if("environment"==a)return s.prototype.setTexture.call(this,a,b,c);for(var f=0;f<this.properties.length;++f){var g=this.properties[f];if("texture"==g.type||"cubemap"==g.type||"sampler"==
  g.type)if(!a||g.name==a){(d=this.textures[a])||(d=this.textures[a]={texture:b,uvs:"0",wrap:0,minFilter:0,magFilter:0});if(c)for(f in c)d[f]=c[f];g.value="sampler"==g.type?d:b;break}}b&&b.constructor==String&&":"!=b[0]&&e.ResourcesManager.load(b);return d};$.prototype.getResources=function(a){for(var b=0,c=this.properties.length;b<c;++b){var d=this.properties[b];"texture"!=d.type&&"cubemap"!=d.type&&"sampler"!=d.type||!d.value||(d="sampler"==d.type?d.value.texture:d.value,"string"==typeof d&&(a[d]=
  GL.Texture))}return a};e.registerMaterialClass($);e.CustomMaterial=$;aa.icon="mini-icon-material.png";aa.coding_help="struct Input {\n\tvec4 color;\n\tvec3 vertex;\n\tvec3 normal;\n\tvec2 uv;\n\tvec2 uv1;\n\t\n\tvec3 camPos;\n\tvec3 viewDir;\n\tvec3 worldPos;\n\tvec3 worldNormal;\n\tvec4 screenPos;\n};\n\nstruct SurfaceOutput {\n\tvec3 Albedo;\n\tvec3 Normal;\n\tvec3 Emission;\n\tfloat Specular;\n\tfloat Gloss;\n\tfloat Alpha;\n\tfloat Reflectivity;\n};\n";aa.prototype.onCodeChange=function(){this.computeCode()};
  aa.prototype.getCode=function(){return this.code};aa.prototype.computeCode=function(){for(var a="",b=0,c=this.properties.length;b<c;++b){var d="uniform ",f=this.properties[b];switch(f.type){case "number":d+="float ";break;case "vec2":d+="vec2 ";break;case "color":case "vec3":d+="vec3 ";break;case "color4":case "vec4":d+="vec4 ";break;case "texture":d+="sampler2D ";break;case "cubemap":d+="samplerCube ";break;default:continue}d+=f.name+";";a+=d}d=this.code.split("\n");b=0;for(c=d.length;b<c;++b)d[b]=
  d[b].split("//")[0];this.surf_code=a+d.join("")};aa.prototype.onModifyQuery=function(a){this._ps_uniforms_code&&(a.macros.USE_PIXEL_SHADER_UNIFORMS=a.macros.USE_PIXEL_SHADER_UNIFORMS?a.macros.USE_PIXEL_SHADER_UNIFORMS+this._ps_uniforms_code:this._ps_uniforms_code);this._ps_functions_code&&(a.macros.USE_PIXEL_SHADER_FUNCTIONS=a.macros.USE_PIXEL_SHADER_FUNCTIONS?a.macros.USE_PIXEL_SHADER_FUNCTIONS+this._ps_functions_code:this._ps_functions_code);this._ps_code&&(a.macros.USE_PIXEL_SHADER_CODE=a.macros.USE_PIXEL_SHADER_CODE?
  a.macros.USE_PIXEL_SHADER_CODE+this._ps_code:this._ps_code);a.macros.USE_SURFACE_SHADER=this.surf_code};aa.prototype.fillShaderQuery=function(a){a=this._query;a.clear();if(this.textures.environment){var b=this.textures.environment,c=e.getTexture(b.texture);c&&(a.macros["USE_ENVIRONMENT_"+(c.type==gl.TEXTURE_2D?"TEXTURE":"CUBEMAP")]=b.uvs)}};aa.prototype.fillUniforms=function(a,b){for(var c=[],d=0,f=0,g=this.properties.length;f<g;++f){var h=this.properties[f];if("texture"==h.type||"cubemap"==h.type||
  "sampler"==h.type){if(h.value){var k=e.getTexture("sampler"==h.type?h.value.texture:h.value);k||(k=":missing");c[d]=k;this._uniforms[h.name]=d;d++}}else this._uniforms[h.name]=h.value}this._uniforms.u_material_color=this._color;this._samplers=c};aa.prototype.configure=function(a){e.cloneObject(a,this);this.computeCode()};aa.prototype.getPropertiesInfo=function(){var a={color:e.TYPES.VEC3,opacity:e.TYPES.NUMBER,shader_name:e.TYPES.STRING,blend_mode:e.TYPES.NUMBER,code:e.TYPES.STRING},b;for(b in this.properties){var c=
  this.properties[b];a[c.name]=c.type}return a};aa.prototype.onResourceRenamed=function(a,b,c){s.prototype.onResourceRenamed.call(this,a,b,c);c=0;for(var d=this.properties.length;c<d;++c){var f=this.properties[c];f.value==a&&(f.value=b)}};aa.prototype.getProperty=function(a){if(this[a])return this[a];if("tex_"==a.substr(0,4))return(a=this.textures[a.substr(4)])?a.texture:null;for(var b=0,c=this.properties.length;b<c;++b){var d=this.properties[b];if(d.name==a)return d.value}return null};aa.prototype.setProperty=
  function(a,b){if(s.prototype.setProperty.call(this,a,b))return!0;"shader_name"==a&&(this.shader_name=b);for(var c=0,d=this.properties.length;c<d;++c){var f=this.properties[c];if(f.name==a)return f.value=b,!0}return!1};aa.prototype.getPropertyInfoFromPath=function(a){if(!(1>a.length)){var b=s.prototype.getPropertyInfoFromPath.call(this,a);if(b)return b;a=a[0];for(var b=0,c=this.properties.length;b<c;++b){var d=this.properties[b];if(d.name==a)return{node:this._root,target:this,name:d.name,value:d.value,
  type:d.type}}}};aa.prototype.getTextureChannels=function(){for(var a=[],b=0,c=this.properties.length;b<c;++b){var d=this.properties[b];"texture"!=d.type&&"cubemap"!=d.type&&"sampler"!=d.type||a.push(d.name)}return a};aa.prototype.setTexture=function(a,b,c){if(!a)throw"SurfaceMaterial.prototype.setTexture channel must be specified";var d=null;if("environment"==a)return s.prototype.setTexture.call(this,a,b,c);for(var f=0;f<this.properties.length;++f){var g=this.properties[f];if("texture"==g.type||"cubemap"==
  g.type||"sampler"==g.type)if(!a||g.name==a){(d=this.textures[a])||(d=this.textures[a]={texture:b,uvs:"0",wrap:0,minFilter:0,magFilter:0});if(c)for(f in c)d[f]=c[f];g.value="sampler"==g.type?d:b;break}}b&&b.constructor==String&&":"!=b[0]&&e.ResourcesManager.load(b);return d};aa.prototype.getResources=function(a){for(var b=0,c=this.properties.length;b<c;++b){var d=this.properties[b];"texture"!=d.type&&"cubemap"!=d.type&&"sampler"!=d.type||!d.value||(d="sampler"==d.type?d.value.texture:d.value,"string"==
  typeof d&&(a[d]=GL.Texture))}return a};e.registerMaterialClass(aa);e.SurfaceMaterial=aa;Object.defineProperty(ra.prototype,"shader",{enumerable:!0,get:function(){return this._shader},set:function(a){a&&(a=e.ResourcesManager.cleanFullpath(a));this._shader!=a&&(this._shader=a,this.processShaderCode())}});Object.defineProperty(ra.prototype,"properties",{enumerable:!0,get:function(){return this._properties},set:function(a){if(a){this._properties=a;this._properties_by_name={};for(var b in this._properties)this._properties_by_name[this._properties[b].name]=
  this._properties[b]}}});ra.prototype.createUniform=function(a,b,c,d,f){if(!a||!b)throw"parameter missing in createUniform";c=c||"Number";d=d||0;if(c.constructor!==String)throw"type must be string";d&&d.length&&(d=new Float32Array(d));b={name:a,uniform:b,value:d,type:c,is_texture:0};if("texture"==c.toLowerCase()||"sampler2D"==c||"samplerCube"==c)b.is_texture="samplerCube"==c?2:1;if(f)for(var e in f)b[e]=f[e];this._properties.push(b);this._properties_by_name[a]=b};ra.prototype.setProperty=function(a,
  b){if(s.prototype.setProperty.call(this,a,b))return!0;if("shader"==a)this.shader=b;else if("properties"==a)this.properties=b;else if(this._properties_by_name[a]){var c=this._properties_by_name[a];c.value&&c.value.length?c.value.set(b):c.value=b}else return!1;return!0};ra.prototype.processShaderCode=function(){if(!this._shader)return this._properties=[],this._properties_by_name={},!1;var a=e.ResourcesManager.getResource(this.shader);if(!a||a.constructor!==e.ShaderCode)return!1;var b=this._properties_by_name;
  this._properties=[];this._properties_by_name={};for(var c in this)this.hasOwnProperty(c)&&this[c]&&this[c].constructor===Function&&delete this[c];a._init_function&&a._init_function.call(this);for(c in a._global_uniforms){var d=a._global_uniforms[c];d.disabled||this.createUniform(d.name,d.uniform,d.type,d.value,d.options)}this.assignOldProperties(b)};ra.prototype.assignOldProperties=function(a){var b=null,c=this.getShaderCode();c&&(b=c.getShader());for(c=0;c<this._properties.length;++c){var d=this._properties[c];
  if(a[d.name]){var f=a[d.name];if(void 0!==f.value){if(b){var e=b.uniformInfo[d.uniform];if(!e)continue;if(void 0!==d.value&&!GL.Shader.validateValue(d.value,e)){d.value=void 0;continue}}d.value&&d.value.set?f.value&&f.value.length&&d.value.length&&f.value.length<=d.value.length?d.value.set(f.value):d.value=f.value:d.value=f.value}}}};ra.prototype.renderInstance=function(a,b,c){if(!this.shader)return!1;c=a.computeShaderBlockFlags();var d=e.ResourcesManager.getResource(this.shader);if(!d||d.constructor!==
  e.ShaderCode)return!1;c=d.getShader(null,c);if(!c)return!1;var d=e.Renderer,f=e.Renderer._current_camera,g=e.Renderer._current_scene,h=a.matrix;a.flags&cb&&d._viewprojection_matrix.set(h);var k=e.Renderer._render_uniforms;k.u_model=h;k.u_normal_model=a.normal_matrix;d.enableInstanceFlags(a,b);this.blend_mode!==va.NORMAL?(gl.enable(gl.BLEND),a.blend_func&&gl.blendFunc(a.blend_func[0],a.blend_func[1])):gl.disable(gl.BLEND);this.fillUniforms();this.prepare_render&&this.prepare_render(a);e.Renderer.bindSamplers(this._samplers);
  c.uniformsArray([g._uniforms,f._uniforms,k,this._uniforms,a.uniforms]);a.render(c);d._rendercalls+=1;return!0};ra.prototype.fillUniforms=function(){var a=this._samplers;a.length=0;this._uniforms.u_material_color=this._color;for(var b=0;b<this._properties.length;++b){var c=this._properties[b];c.is_texture?(this._uniforms[c.uniform]=a.length,c.value?a.push(c.value):a.push(" ")):this._uniforms[c.uniform]=c.value}};ra.prototype.renderShadowInstance=function(a,b){return this.renderInstance(a,b)};ra.prototype.getResources=
  function(a){this.shader&&(a[this.shader]=e.ShaderCode);for(var b in this._properties){var c=this._properties[b];c.value&&c.is_texture&&(a[c.value]=GL.Texture)}return a};ra.prototype.getPropertyInfoFromPath=function(a){if(!(1>a.length)){var b=s.prototype.getPropertyInfoFromPath.call(this,a);if(b)return b;a=a[0];for(var b=0,c=this.properties.length;b<c;++b){var d=this.properties[b];if(d.name==a)return{node:this._root,target:this,name:d.name,value:d.value,type:d.type}}}};ra.prototype.getShaderCode=function(){var a=
  e.ResourcesManager.getResource(this.shader);return a&&a.constructor===e.ShaderCode?a:null};ra.prototype.applyToTexture=function(a,b){if(!this.shader||!a)return!1;var c=this.getShaderCode();if(!c)return!1;var d=c.getShader("fx");if(!d)return!1;this.fillUniforms();this._uniforms.u_time=e.GlobalScene._time;this._uniforms.u_viewport=gl.viewport_data;e.Renderer.bindSamplers(this._samplers);gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);b?b.drawTo(function(){a.toViewport(d,this._uniforms)}):a.toViewport(d,
  this._uniforms)};e.registerMaterialClass(ra);e.ShaderMaterial=ra;sa.prototype.configureComponents=function(a){if(a.components)for(var b=0,c=a.components.length;b<c;++b){var d=a.components[b],f=d[0],g=null;if("Transform"==f&&0==b&&this.transform)g=this.transform;else{g=e.Components[f];if(!g){console.error("Unknown component found: "+f);this._missing_components||(this._missing_components=[]);this._missing_components.push(d);continue}g=new g;this.addComponent(g)}g.configure(d[1]);d[1].editor&&(g._editor=
  d[1].editor);d[1].uid&&d[1].uid!==g.uid&&(g.uid=d[1].uid)}};sa.prototype.serializeComponents=function(a){if(this._components){a.components=[];for(var b=0,c=this._components.length;b<c;++b){var d=this._components[b];if(d.serialize){var f=d.serialize();d._editor&&(f.editor=d._editor);d.hasOwnProperty("uid")&&!f.uid&&(f.uid=d.uid);a.components.push([e.getObjectClassName(d),f])}}this._missing_components&&this._missing_components.length&&(a.components=a.components.concat(this._missing_components))}};sa.prototype.getComponents=
  function(a){if(a){var b=[];a.constructor===String&&(a=e.Components[a]);for(var c=0,d=this._components.length;c<d;++c){var f=this._components[c];f.constructor===a&&b.push(f)}return b}return this._components};sa.prototype.addComponent=function(a,b){if(!a)throw"addComponent cannot receive null";a._root=this;if(this.constructor==e.SceneNode&&a.onAddedToNode)a.onAddedToNode(this);if((this._in_tree||this.constructor==e.SceneTree)&&a.onAddedToScene)a.onAddedToScene(this.constructor==e.SceneTree?this:this._in_tree);
  this._components||Object.defineProperty(this,"_components",{value:[],enumerable:!1});if(-1!=this._components.indexOf(a))throw"inserting the same component twice";void 0!==b&&b<=this._components.length?this._components.splice(b,0,a):this._components.push(a);a.uid||(a.uid=e.generateUId("COMP-"));return a};sa.prototype.removeComponent=function(a){if(!a)throw"removeComponent cannot receive null";a._root=null;if(this.constructor==e.SceneNode&&a.onRemovedFromNode)a.onRemovedFromNode(this);if((this._in_tree||
  this.constructor==e.SceneTree)&&a.onRemovedFromScene)a.onRemovedFromScene(this.constructor==e.SceneTree?this:this._in_tree);LEvent.unbindAll(this,a);a=this._components.indexOf(a);-1!=a?this._components.splice(a,1):console.warn("removeComponent: Component not found in node")};sa.prototype.removeAllComponents=function(){for(;this._components.length;)this.removeComponent(this._components[0]);this._missing_components=null};sa.prototype.hasComponent=function(a,b){if(!this._components&&!this._missing_components)return!1;
  if(b&&this._missing_components&&this._missing_components.length){a.constructor!==String&&(a=e.getClassName(a));for(var c=0,d=this._missing_components.length;c<d;++c)if(this._missing_components[c][0]==a)return!0}if(a.constructor===String&&(a=e.Components[a],!a))return!1;c=0;for(d=this._components.length;c<d;++c)if(this._components[c].constructor===a)return!0;return!1};sa.prototype.getComponent=function(a,b){if(!this._components||!a)return null;if(a.constructor===String&&(a=e.Components[a],!a))return;
  for(var c=0,d=this._components.length;c<d;++c)if(this._components[c].constructor===a)if(void 0!==b&&0<b)b--;else return this._components[c];return null};sa.prototype.getComponentByUId=function(a){if(!this._components)return null;for(var b=0,c=this._components.length;b<c;++b)if(this._components[b].uid==a)return this._components[b];return null};sa.prototype.getIndexOfComponent=function(a){return this._components?this._components.indexOf(a):-1};sa.prototype.getComponentByIndex=function(a){return this._components?
  this._components[a]:null};sa.prototype.setComponentIndex=function(a,b){if(!this._components)return null;0>b&&(b=0);var c=this._components.indexOf(a);-1!=c&&(this._components.splice(c,1),b>=this._components.length?this._components.push(a):this._components.splice(b,0,a))};sa.prototype.processActionInComponents=function(a,b){if(this._components)for(var c=0,d=this._components.length;c<d;++c){var f=this._components[c];f[a]&&f[a].constructor===Function&&(b&&b.constructor===Array?f[a].apply(f,b):f[a].call(f,
  b))}};W.prototype.compositeCtor=function(){this._in_tree=this._children=this._parentNode=null};W.prototype.addChild=function(a,b,c){function d(a){if(a._children)for(var b in a._children){var c=a._children[b];c._in_tree||(LEvent.trigger(e,"treeItemAdded",c),c._in_tree=e);d(c)}}if(!a)throw"cannot addChild of null";for(var f=this;f._parentNode;){if(f==a)throw"addChild: Cannot insert a node as his own child";f=f._parentNode}a._parentNode&&a._parentNode.removeChild(a,c);a._parentNode=this;this._children?
  void 0==b?this._children.push(a):this._children.splice(b,0,a):this._children=[a];var e=this._in_tree;if(e&&a._in_tree&&a._in_tree!=e)throw"Cannot add a node that belongs to another scene tree";a._in_tree=e;this._onChildAdded&&this._onChildAdded(a,c);LEvent.trigger(this,"childAdded",a);e&&(LEvent.trigger(e,"treeItemAdded",a),d(a))};W.prototype.removeChild=function(a,b,c){function d(a){if(a._children)for(var b=0,c=a._children.length;b<c;++b){var f=a._children[b];f._in_tree&&(LEvent.trigger(f._in_tree,
  "treeItemRemoved",f),f._in_tree=null);d(f)}}if(!a)throw"cannot removeChild of null";if(!this._children||a._parentNode!=this||a._parentNode!=this)return!1;var f=this._children.indexOf(a);if(-1==f)return!1;this._children.splice(f,1);this._onChildRemoved&&this._onChildRemoved(a,b,c);LEvent.trigger(this,"childRemoved",a);a._in_tree&&(LEvent.trigger(a._in_tree,"treeItemRemoved",a),d(a));a._in_tree=null;return!0};W.prototype.removeAllChildren=function(a,b){if(this._children)for(;this._children.length;)this.removeChild(this._children[0],
  a,b)};W.prototype.serializeChildren=function(){var a=[];if(this._children)for(var b in this._children)a.push(this._children[b].serialize());return a};W.prototype.configureChildren=function(a){if(a.children)for(var b=0;b<a.children.length;++b){var c=a.children[b],d=new this.constructor(c.id);c.uid&&(d.uid=c.uid);c.editor&&(d._editor=c.editor);this.addChild(d);d.configure(c)}};W.prototype.getParent=function(){return this._parentNode};W.prototype.getChildren=function(){return this._children||[]};W.prototype.getChildIndex=
  function(a){return this._children?this._children.indexOf(a):-1};W.prototype.getChildByIndex=function(a){return this._children&&this._children.length>a?this._children[a]:null};W.prototype.getChildByName=function(a){if(!this._children)return null;for(var b=0;b<this._children.length;++b)if(this._children[b].name==a)return this._children[b];return null};W.prototype.getPathName=function(){if(!this._in_tree)return null;if(this===this._in_tree.root)return"";for(var a=this.name,b=this._parentNode;b;){if(b===
  this._in_tree.root)return a;a=b.name+"|"+a;b=b._parentNode}return null};Object.defineProperty(W.prototype,"childNodes",{enumerable:!0,get:function(){return this._children||[]},set:function(a){}});Object.defineProperty(W.prototype,"parentNode",{enumerable:!0,get:function(){return this._parentNode},set:function(a){}});Object.defineProperty(W.prototype,"scene",{enumerable:!0,get:function(){return this._in_tree},set:function(a){throw"Scene cannot be set, you must use addChild in parent";}});W.prototype.getDescendants=
  function(){if(!this._children||0==this._children.length)return[];for(var a=this._children.concat(),b=0;b<this._children.length;++b)a=a.concat(this._children[b].getDescendants());return a};W.prototype.moveBefore=function(a){if(!this._parentNode||a&&this._parentNode!==a._parentNode)return-1;var b=this._parentNode._children,c=b.indexOf(this);if(-1==c)throw"moveBefore node not found in parent, this is impossible";var d=c-1;if(a){d=b.indexOf(a);if(-1==d)return-1;d-=1}if(c==d||0>d)return d;b.splice(c,1);
  d>c&&(d-=1);b.splice(d,0,this);LEvent.trigger(this._in_tree,"node_rearranged",this);return d};W.prototype.moveAfter=function(a){if(!this._parentNode||a&&this._parentNode!==a._parentNode)return-1;var b=this._parentNode._children,c=b.indexOf(this);if(-1==c)throw"moveBefore node not found in parent, this is impossible";var d=c+1;if(a){d=b.indexOf(a);if(-1==d)return-1;d+=1}if(c==d||d>=b.length)return d;b.splice(c,1);d>c&&(d-=1);b.splice(d,0,this);LEvent.trigger(this._in_tree,"node_rearranged",this);return d};
  W.prototype.findNode=function(a){return""==a?this:a?a.charAt(0)!=e._uid_prefix?this.findNodeByName(a):this.findNodeByUId(a):null};W.prototype.findNodeByName=function(a){if(!a)return null;if(this.name==a)return this;var b=this._children;if(b)for(var c=0,d=b.length;c<d;++c){var f=b[c];if(f.name==a||f._children&&(f=f.findNodeByName(a)))return f}return null};W.prototype.findNodeByUId=function(a){if(!a)return null;if(this.uid==a)return this;var b=this._children;if(b)for(var c=0;c<b.length;++c){var d=b[c];
  if(d.uid==a||d._children&&(d=d.findNodeByUId(a)))return d}return null};Aa.prototype.getRootNode=function(){return this._root};Aa.prototype.configure=function(a){a&&(a.uid&&(this.uid=a.uid),e.cloneObject(a,this,!1,!0))};Aa.prototype.serialize=function(){var a=e.cloneObject(this);this.uid&&(a.uid=this.uid);return a};Aa.prototype.clone=function(){var a=this.serialize();a.uid=null;return new this.constructor(a)};Aa.prototype.createProperty=function(a,b,c,d,f){if(c){if("String"==c||"Number"==c||"Boolean"==
  c)console.warn("createProperty: Basic types must be in lowercase -> "+c),c=c.toLowerCase();this.constructor["@"+a]="object"==typeof c?c:{type:c}}if(null!==b&&void 0!==b&&b.constructor!==Number&&b.constructor!==String&&b.constructor!==Boolean||d||f){var e="_"+a;b&&b.constructor===Float32Array?(b=new Float32Array(b),this[e]=b,Object.defineProperty(this,a,{get:f||function(){return b},set:d||function(a){b.set(a)},enumerable:!0})):(Object.defineProperty(this,e,{value:b,enumerable:!1}),Object.defineProperty(this,
  a,{get:f||function(){return this[e]},set:d||function(a){this[e]=a},enumerable:!0}))}else this[a]=b};Aa.prototype.createAction=function(a,b,c){var d=a.replace(/ /gi,"_");this[d]=b;this.constructor["@"+d]=c||{type:"function",button_text:a,widget:"button",callback:b}};Aa.prototype.getLocator=function(a){return this._root?a?(void 0===this[a]&&console.warn("No property found in this component with that name:",a),this._root.uid+"/"+this.uid+"/"+a):this._root.uid+"/"+this.uid:""};Aa.prototype.bind=function(a,
  b,c){if(3<arguments.length)console.error("Component.bind cannot use a fourth parameter, all callbacks will be binded to the component");else if(a){if(c)return this.__targeted_instances||Object.defineProperty(this,"__targeted_instances",{value:[],enumerable:!1,writable:!0}),-1==this.__targeted_instances.indexOf(a)&&this.__targeted_instances.push(a),LEvent.bind(a,b,c,this);console.error("You cannot bind a method before defining it.")}else console.error("Cannot bind to null.")};Aa.prototype.unbind=function(a,
  b,c){b=LEvent.unbind(a,b,c,this);if(this.__targeted_instances){if(!LEvent.hasBindTo(a,this))return b;a=this.__targeted_instances.indexOf(a);-1==a&&this.__targeted_instances.splice(a,1);0==this.__targeted_instances.length&&delete this.__targeted_instances}return b};Aa.prototype.unbindAll=function(){if(this.__targeted_instances){for(var a=0;a<this.__targeted_instances.length;++a)LEvent.unbindAll(this.__targeted_instances[a],this);this.__targeted_instances=null}};Aa.addExtraMethods=function(a){Object.defineProperty(a.prototype,
  "uid",{set:function(a){a&&(a[0]!=e._uid_prefix&&(console.warn("Invalid UID, renaming it to: "+a),a=e._uid_prefix+a),a!=this._uid&&(this._uid=a))},get:function(){return this._uid},enumerable:!1});Object.defineProperty(a.prototype,"root",{set:function(a){throw"root cannot be set, call addComponent to the root";},get:function(){return this._root},enumerable:!1})};e.Component=Aa;Object.defineProperty(ta.prototype,"data",{set:function(a){this._data=a;this._modified=!0},get:function(){return this._data},
  enumerable:!0});ta.prototype.register=function(){e.ResourcesManager.registerResource(this.fullpath||this.filename,this)};Object.defineProperty(ta.prototype,"uid",{get:function(){return this.fullpath||this.filename},set:function(a){},enumerable:!0});ta.getDataToStore=function(a){var b=null,c="text",d="";a.getDataToStore?(b=a.getDataToStore())&&b.constructor==ArrayBuffer&&(c="binary"):a._original_file?((b=a._original_file)&&b.constructor!==File&&b.constructor!==Blob&&console.warn("Resource._original_file is not File or Blob"),
  c="file"):a._original_data?(b=a._original_data)&&b.constructor===ArrayBuffer&&(c="binary"):a.toBinary?(b=a.toBinary(),c="binary",d="wbin"):a.toBlob?(b=a.toBlob(),c="file"):a.toBase64?(b=a.toBase64(),c="base64"):a.serialize?(a=a.serialize(),delete a.filename,delete a.fullpath,delete a.remotepath,delete a.preview_url,b=JSON.stringify(a)):b=a.data?a.data:JSON.stringify(a);b.buffer&&b.buffer.constructor==ArrayBuffer&&(b=b.buffer);return{data:b,encoding:c,extension:d}};ta.prototype.getData=function(){return this._data};
  ta.prototype.setData=function(a,b){this._original_data&&(this._original_data=null);this._data=a;b||(this._modified=!0)};ta.prototype.getDataToStore=function(){var a=this.data||"";a.constructor===Object&&(a=JSON.stringify(a));return a};ta.prototype.clone=function(){var a=new e.Resource;a._data=this._data;return a};ta.prototype.getCategory=function(){return"js"==e.ResourcesManager.getExtension(this.fullpath||this.filename)?"Script":"Data"};ta.prototype.assignToNode=function(a){if(!a||"Script"!=this.getCategory())return!1;
  var b=new e.Components.ScriptFromFile({filename:this.fullpath||this.filename});a.addComponent(b);return!0};ta.prototype.getAsSubfiles=function(){return this._data?GL.processFileAtlas(this._data):null};ta.prototype.getAsHTML=function(){if(!this._data||this._data.constructor!==String)return null;var a=document.createElement("div");a.innerHTML=this._data;return a};ta.hasPreview=!1;e.Resource=ta;e.registerResourceClass(ta);e.NONE=0;e.LINEAR=1;e.TRIGONOMETRIC=2;e.BEZIER=3;e.SPLINE=4;U.DEFAULT_SCENE_NAME=
  "@scene";U.DEFAULT_DURATION=10;U.prototype.createTake=function(a,b){var c=new U.Take;c.name=a;c.duration=b||0;this.addTake(c);return c};U.prototype.addTake=function(a){return this.takes[a.name]=a};U.prototype.getTake=function(a){return this.takes[a]};U.prototype.getNumTakes=function(){var a=0,b;for(b in this.takes)a++;return a};U.prototype.addTrackToTake=function(a,b){var c=this.takes[a];c||(c=this.createTake(a));c.addTrack(b)};U.prototype.configure=function(a){a.name&&(this.name=a.name);if(a.takes){this.takes=
  {};for(var b in a.takes){var c=new e.Animation.Take(a.takes[b]);c.name?(this.addTake(c),c.loadResources()):console.warn("Take without name")}}};U.prototype.serialize=function(){return e.cloneObject(this,null,!0)};U.fromBinary=function(a){a.constructor==ArrayBuffer&&(a=z.load(a,!0));var b=a["@json"],c;for(c in b.takes){var d=b.takes[c],f;for(f in d.tracks){var g=d.tracks[f],h="@take_"+c+"_track_"+f;a[h]&&(g.data=a[h])}}return new e.Animation(b)};U.prototype.toBinary=function(){var a={},b=[],c;for(c in this.takes){var d=
  this.takes[c],f;for(f in d.tracks){var g=d.tracks[f];g.packData();if(g.packed_data){var h=g.data,k="@take_"+c+"_track_"+f;a[k]=h;g.data=null;b.push(h)}}}a["@json"]=e.cloneObject(this,null,!0);b=z.create(a,"Animation");for(c in this.takes)for(f in d=this.takes[c],d.tracks)g=d.tracks[f],k="@take_"+c+"_track_"+f,a[k]&&(g.data=a[k]);return b};U.prototype.convertIDstoNames=function(a,b){var c=0,d;for(d in this.takes)c+=this.takes[d].convertIDstoNames(a,b);return c};U.prototype.setTracksPacking=function(a){var b=
  0,c;for(c in this.takes)b+=this.takes[c].setTracksPacking(a);return b};U.prototype.optimizeTracks=function(){var a=0,b;for(b in this.takes)a+=this.takes[b].optimizeTracks();return a};e.Classes.Animation=e.Animation=U;ga.prototype.configure=function(a){a.name&&(this.name=a.name);if(a.tracks){this.tracks=[];for(var b in a.tracks){var c=new e.Animation.Track(a.tracks[b]);this.addTrack(c)}}a.duration&&(this.duration=a.duration)};ga.prototype.serialize=function(){return e.cloneObject(this,null,!0)};ga.prototype.createTrack=
  function(a){if(!a)throw"Data missing when creating track";var b=this.getTrack(a.property);if(b)return b;b=new e.Animation.Track(a);this.addTrack(b);return b};ga.prototype.applyTracks=function(a,b,c,d){for(var f=0;f<this.tracks.length;++f){var g=this.tracks[f];if(!1!==g.enabled&&g.data)if("events"==g.type){var h=g.getKeyframeByTime(a);if(!h||h[0]<b||h[0]>a)break;g=e.GlobalScene.getPropertyInfoFromPath(g._property_path);if(!g)break;var k=h[1];1==k[2]?g.node&&g.target&&g.target[k[0]]&&g.target[k[0]].call(g.target,
  k[1]):g.target?LEvent.trigger(g.target,h[1],h[1][1]):g.node&&LEvent.trigger(g.node,h[1][0],h[1][1])}else h=g.getSample(a,!c),void 0!==h&&(g._target=e.GlobalScene.setPropertyValueFromPath(g._property_path,h,d,0))}};ga.prototype.addTrack=function(a){this.tracks.push(a)};ga.prototype.getTrack=function(a){for(var b=0;b<this.tracks.length;++b)if(this.tracks[b].property==a)return this.tracks[b];return null};ga.prototype.removeTrack=function(a){for(var b=0;b<this.tracks.length;++b)if(this.tracks[b]==a){this.tracks.splice(b,
  1);break}};ga.prototype.getPropertiesSample=function(a,b){b=b||[];for(var c=0;c<this.tracks.length;++c){var d=this.tracks[c],f=d.getSample(a);b.push([d.property,f])}return b};ga.prototype.actionPerSample=function(a,b,c){for(var d=0;d<this.tracks.length;++d){var f=this.tracks[d],e=f.getSample(a,!0);c.disabled_tracks&&c.disabled_tracks[f.property]||b(f.property,e,c)}};ga.prototype.loadResources=function(){for(var a=0;a<this.tracks.length;++a){var b=this.tracks[a];if("texture"==b.type)for(var c=b.getNumberOfKeyframes(),
  d=0;d<c;++d){var f=b.getKeyframe(d);f&&f[1]&&":"!=f[1][0]&&e.ResourcesManager.load(f[1])}}};ga.prototype.convertIDstoNames=function(a,b){for(var c=0,d=0;d<this.tracks.length;++d)c+=this.tracks[d].convertIDtoName(a,b);return c};ga.prototype.setTracksPacking=function(a){for(var b=0,c=0;c<this.tracks.length;++c){var d=this.tracks[c];d.packed_data!=a&&(a?d.packData():d.unpackData(),b+=1)}return b};ga.prototype.optimizeTracks=function(){for(var a=0,b=new Float32Array(10),c=0;c<this.tracks.length;++c){var d=
  this.tracks[c];if(16==d.value_size){var f=d.property.split("/");if("matrix"==f[f.length-1])if(f[f.length-1]="Transform/data",d.property=f.join("/"),d.type="trans10",d.value_size=10,d.packed_data){for(var f=d.data,g=f.length/17,h=0;h<g;++h){var k=f.subarray(17*h+1,17*h+17);e.Transform.fromMatrix4ToTransformData(k,b);f[11*h]=f[17*h];f.set(b,11*h+1)}d.data=new Float32Array(f.subarray(0,11*g));a+=1}else console.warn("convertMatricesToData only works with packed data")}}return a};ga.prototype.matchTranslation=
  function(a){for(var b=0,c=0;c<this.tracks.length;++c){var d=this.tracks[c];if(("trans10"==d.type||"mat4"==d.type)&&d._property_path&&d._property_path.length){var f=Wa.get(d._property_path[0],a);if(f){var f=f.transform.position,e=d.value_size+1,h=d.data,k=h.length/e;if("trans10"==d.type)for(d=0;d<k;++d)h.set(f,d*e+1);else if("mat4"==d.type)for(d=0;d<k;++d)h.set(f,d*e+13);b+=1}}}return b};ga.prototype.onlyRotations=function(){for(var a=0,b=new Float32Array(10),c=b.subarray(3,7),d=0;d<this.tracks.length;++d){var f=
  this.tracks[d],g=f.property.split("/"),h=g[g.length-1],k=f.value_size;if("mat4"==f.type||"trans10"==f.type)if("matrix"==h?g[g.length-1]="Transform/rotation":"data"==h&&(g[g.length-1]="rotation"),f.property=g.join("/"),h=f.type,f.type="quat",f.value_size=4,f.packed_data){g=f.data;k=g.length/(k+1);if("mat4"==h)for(h=0;h<k;++h){var m=g.subarray(17*h+1,17*h+17);e.Transform.fromMatrix4ToTransformData(m,b);g[11*h]=g[17*h];g.set(c,5*h+1)}else if("trans10"==h)for(h=0;h<k;++h)m=g.subarray(11*h+4,11*h+8),g[5*
  h]=g[11*h],g.set(m,5*h+1);f.data=new Float32Array(g.subarray(0,5*k));a+=1}else console.warn("convertMatricesToData only works with packed data")}return a};ga.prototype.setInterpolationToAllTracks=function(a){for(var b=0,c=0;c<this.tracks.length;++c){var d=this.tracks[c];d.interpolation!=a&&(d.interpolation=a,b+=1)}return b};U.Take=ga;T.FRAMERATE=30;Object.defineProperty(T.prototype,"property",{set:function(a){this._property=a.trim();this._property_path=this._property.split("/")},get:function(){return this._property},
  enumerable:!0});T.prototype.configure=function(a){a.property||console.warn("Track with property name");void 0!==a.enabled&&(this.enabled=a.enabled);a.name&&(this.name=a.name);a.property&&(this.property=a.property);a.type&&(this.type=a.type);a.looped&&(this.looped=a.looped);this.interpolation=void 0!==a.interpolation?a.interpolation:e.LINEAR;a.data_table&&(this.data_table=a.data_table);a.value_size&&(this.value_size=a.value_size);a.data&&(this.data=a.data,this.packed_data=void 0===a.packed_data&&this.data.constructor!==
  Array?!0:!!a.packed_data,a.data.constructor==Array&&this.packed_data&&(this.data=new Float32Array(a.data)));a.interpolation&&!this.value_size&&(a.interpolation=e.NONE)};T.prototype.serialize=function(){var a={enabled:this.enabled,name:this.name,property:this.property,type:this.type,interpolation:this.interpolation,looped:this.looped,value_size:this.value_size,packed_data:this.packed_data,data_table:this.data_table};this.data&&(1>=this.value_size?a.data=this.data.concat():(this.packData(),a.data=new Float32Array(this.data),
  a.packed_data=this.packed_data));return a};T.prototype.toJSON=T.prototype.serialize;T.prototype.clear=function(){this.data=[];this.packed_data=!1};T.prototype.convertIDtoName=function(a,b){if(!this._property_path||!this._property_path.length||this._property_path[0][0]!==e._uid_prefix)return!1;var c=Wa.get(this._property_path[0],b);if(!c)return console.warn("convertIDtoName: node not found in LS.GlobalScene: "+this._property_path[0]),!1;if(!c.name)return console.warn("convertIDtoName: node without name?"),
  !1;this._property_path[0]=a?c.name:c.fullname;this._property=this._property_path.join("/");return!0};T.prototype.addKeyframe=function(a,b,c){1<this.value_size&&(b=new Float32Array(b));this.packed_data&&this.unpackData();this.data||(this.data=[]);for(var d=0;d<this.data.length;++d)if(!(this.data[d][0]<a))return this.data[d][0]!=a||c?this.data.splice(d,0,[a,b]):this.data[d][1]=b,d;this.data.push([a,b]);return this.data.length-1};T.prototype.getKeyframe=function(a){return 0>a||a>=this.data.length?(console.warn("keyframe index out of bounds"),
  null):this.packed_data?(a*=1+this.value_size,a>this.data.length-this.value_size?null:[this.data[a],this.data.subarray(a+1,a+this.value_size+1)]):this.data[a]};T.prototype.getKeyframeByTime=function(a){a=this.findTimeIndex(a);if(-1!=a)return this.getKeyframe(a)};T.prototype.moveKeyframe=function(a,b){if(this.packed_data)return console.warn("Cannot move keyframes if packed"),-1;if(0>a||a>=this.data.length)return console.warn("keyframe index out of bounds"),-1;var c=this.findTimeIndex(b),d=this.data[a],
  f=d[0];if(f==b)return a;d[0]=b;f>b&&(c+=1);if(a==c)return a;this.data.splice(a,1);a=this.addKeyframe(d[0],d[1],!0);this.sortKeyframes();return a};T.prototype.sortKeyframes=function(){this.packed_data&&(this.unpackData(),this.sortKeyframes(),this.packData());this.data.sort(function(a,b){return a[0]-b[0]})};T.prototype.removeKeyframe=function(a){this.packed_data&&this.unpackData();0>a||a>=this.data.length?console.warn("keyframe index out of bounds"):this.data.splice(a,1)};T.prototype.getNumberOfKeyframes=
  function(){return this.data&&0!=this.data.length?this.packed_data?this.data.length/(1+this.value_size):this.data.length:0};T.prototype.computeDuration=function(){if(!this.data||0==this.data.length)return 0;if(this.packed_data){var a=this.data[this.data.length-2-this.value_size];return this.duration=a}return(a=this.data[this.data.length-1])?a[0]:0};T.prototype.isInterpolable=function(){return 0<this.value_size||e.Interpolators[this.type]?!0:!1};T.prototype.packData=function(){if(!this.data||0==this.data.length)return 0;
  if(!this.packed_data&&0!=this.value_size){for(var a=this.value_size+1,b=this.data,c=new Float32Array(b.length*a),d=0;d<b.length;++d)c[d*a]=b[d][0],1==this.value_size?c[d*a+1]=b[d][1]:c.set(b[d][1],d*a+1);this.data=c;this.packed_data=!0}};T.prototype.unpackData=function(){if(!this.data||0==this.data.length)return 0;if(this.packed_data){for(var a=this.value_size+1,b=this.data,c=Array(b.length/a),d=0;d<b.length;d+=a)c[d/a]=[b[d],b.subarray(d+1,d+a)];this.data=c;this.packed_data=!1}};T.prototype.findTimeIndex=
  function(a){var b=this.data;if(!b||0==b.length)return-1;if(this.packed_data){var c=this.value_size+1,d=b.length/c,f=0,e=0,h=d;if(0==d)return-1;if(1==d)return 0;if(b[(h-1)*c]<a)return h-1;for(;h>=f;){e=0.5*(h+f)|0;d=b[e*c];if(d==a)break;if(f==h-1)return f;d<a?f=e:h=e}return e}d=b.length;e=f=0;h=d;if(0==d)return-1;if(1==d)return 0;if(b[h-1][0]<a)return h-1;for(;h>=f;){e=0.5*(h+f)|0;d=b[e][0];if(d==a)break;if(f==h-1)return f;d<a?f=e:h=e}return e};T.prototype.getSample=function(a,b,c){return this.data&&
  0!==this.data.length?this.packed_data?this.getSamplePacked(a,b,c):this.getSampleUnpacked(a,b,c):void 0};T.prototype.getSampleUnpacked=function(a,b,c){a=Math.clamp(a,0,this.duration);var d=this.findTimeIndex(a);-1===d&&(d=0);var f=d,g=d+1,h=this.data;b=b&&this.interpolation&&(0<this.value_size||e.Interpolators[this.type]);if(!b||1==h.length||g==h.length||0==f&&this.data[0][0]>a)return this.data[d][1];b=h[f];g=h[g];a=(g[0]-a)/(g[0]-b[0]);if(this.interpolation===e.LINEAR){if(0===this.value_size&&e.Interpolators[this.type])return c=
  e.Interpolators[this.type],this._last_value=c=c(b[1],g[1],a,this._last_value);if(1==this.value_size)return b[1]*a+g[1]*(1-a);c=c||this._result;c&&c.length==this.value_size||(c=this._result=new Float32Array(this.value_size));switch(this.type){case "quat":quat.slerp(c,b[1],g[1],a);quat.normalize(c,c);break;case "trans10":for(d=0;10>d;d++)c[d]=b[1][d]*a+g[1][d]*(1-a);b=b[1].subarray(3,7);g=g[1].subarray(3,7);d=c.subarray(3,7);quat.slerp(d,g,b,a);quat.normalize(d,d);break;default:for(d=0;d<this.value_size;d++)c[d]=
  b[1][d]*a+g[1][d]*(1-a)}return c}if(this.interpolation===e.BEZIER){if(0===this.value_size&&e.Interpolators[this.type])return c=e.Interpolators[this.type],this._last_value=c=c(b[1],g[1],a,this._last_value);f=0<d?h[d-1]:b;d=d<h.length-2?h[d+2]:g;if(1===this.value_size)return U.EvaluateHermiteSpline(b[1],g[1],f[1],d[1],1-a);c=c||this._result;c&&c.length==this.value_size||(c=this._result=new Float32Array(this.value_size));c=c||this._result;c=U.EvaluateHermiteSplineVector(b[1],g[1],f[1],d[1],1-a,c);"quat"==
  this.type?quat.normalize(c,c):"trans10"==this.type&&(a=c.subarray(3,7),quat.normalize(a,a));return c}return null};T.prototype.getSamplePacked=function(a,b,c){a=Math.clamp(a,0,this.duration);var d=this.findTimeIndex(a);-1==d&&(d=0);var f=this.value_size+1,g=d,h=d+1,k=this.data,m=k.length/f;b=b&&this.interpolation&&(0<this.value_size||e.Interpolators[this.type]);if(!b||1==m||h==m||0==g&&this.data[0]>a)return this.getKeyframe(d)[1];g=k.subarray(g*f,(g+1)*f);b=k.subarray(h*f,(h+1)*f);a=(b[0]-a)/(b[0]-
  g[0]);if(this.interpolation===e.LINEAR){if(1==this.value_size)return g[1]*a+b[1]*(1-a);if(e.Interpolators[this.type])return this._last_v=c=(0,e.Interpolators[this.type])(g[1],b[1],a,this._last_v);c=c||this._result;c&&c.length==this.value_size||(c=this._result=new Float32Array(this.value_size));switch(this.type){case "quat":quat.slerp(c,b.subarray(1,5),g.subarray(1,5),a);quat.normalize(c,c);break;case "trans10":for(f=0;10>f;f++)c[f]=g[1+f]*a+b[1+f]*(1-a);f=g.subarray(4,8);b=b.subarray(4,8);h=c.subarray(3,
  7);quat.slerp(h,b,f,a);quat.normalize(h,h);break;default:for(f=0;f<this.value_size;f++)c[f]=g[1+f]*a+b[1+f]*(1-a)}return c}if(this.interpolation===e.BEZIER){if(0===this.value_size)return g[1];d=0<d?k.subarray((d-1)*f,d*f):g;h=h<m-1?k.subarray((h+1)*f,(h+2)*f):b;if(1===this.value_size)return U.EvaluateHermiteSpline(g[1],b[1],d[1],h[1],1-a);c=c||this._result;c&&c.length==this.value_size||(c=this._result=new Float32Array(this.value_size));c=c||this._result;c=U.EvaluateHermiteSplineVector(g.subarray(1,
  f),b.subarray(1,f),d.subarray(1,f),h.subarray(1,f),1-a,c);"quat"==this.type?quat.normalize(c,c):"trans10"==this.type&&(a=c.subarray(3,7),quat.normalize(a,a));return c}return null};T.prototype.getPropertyInfo=function(){return e.GlobalScene.getPropertyInfo(this.property)};T.prototype.getSampledData=function(a,b,c){b=(b-a)/c;if(0>=b)return null;for(var d=[],f=0;f<c;++f){var e=this.getSample(f*b+a,!0);1<this.value_size&&(e=new e.constructor(e));d.push(e)}return d};U.Track=T;U.EvaluateHermiteSpline=function(a,
  b,c,d,f){var e=f*f,h=e*f;return(2*h-3*e+1)*a+(-2*h+3*e)*b+(h-2*e+f)*(b-c)+(h-e)*(d-a)};U.EvaluateHermiteSplineVector=function(a,b,c,d,f,e){e=e||new Float32Array(e.length);var h=f*f,k=h*f,m=2*k-3*h+1,l=-2*k+3*h;f=k-2*h+f;h=k-h;for(k=0;k<e.length;++k)e[k]=m*a[k]+l*b[k]+f*(b[k]-c[k])+h*(d[k]-a[k]);return e};e.registerResourceClass(U);e.Interpolators={};e.Interpolators.texture=function(a,b,c,d){var f=a?e.getTexture(a):null,g=b?e.getTexture(b):null;a&&!f&&":"!=a[0]&&e.ResourcesManager.load(a);b&&!g&&":"!=
  b[0]&&e.ResourcesManager.load(b);a=f||g;(b=gl.textures[":black"])||(b=gl.textures[":black"]=new GL.Texture(1,1,{format:gl.RGB,pixel_data:[0,0,0],filter:gl.NEAREST}));if(!a)return b;var h=a?a.width:256,k=a?a.height:256;f||(f=b);g||(g=b);d&&d.width==h&&d.height==k&&d.format==a.format||(d=new GL.Texture(h,k,{format:a.format,type:a.type,filter:gl.LINEAR}));var m=gl.shaders[":interpolate_texture"];m||(m=gl.shaders[":interpolate_texture"]=GL.Shader.createFX("color = mix( texture2D( u_texture_b, uv ), color , u_factor );",
  "uniform sampler2D u_texture_b; uniform float u_factor;"));gl.disable(gl.DEPTH_TEST);d.drawTo(function(){gl.clearColor(0,0,0,0);gl.clear(gl.COLOR_BUFFER_BIT);g.bind(1);f.toViewport(m,{u_texture_b:1,u_factor:c})});return d};ka.version="0.2";ka.prototype.configure=function(a){if(!a)throw"No prefab data found";if(a.hasOwnProperty("prefab_data"))this.prefab_data=a.prefab_data,this.prefab_json=a.prefab_json||JSON.stringify(this.prefab_data);else{var b=a["@json"];if(!b){console.warn("No JSON found in prefab");
  return}var c=a["@version"];this.prefab_json=b;this.prefab_data=JSON.parse(b)}if(this.resource_names=a["@resources_name"]||a.resource_names){var b={},d;for(d in this.resource_names)b[this.resource_names[d]]=c?a["@RES_"+d]:a[this.resource_names[d]];this._resources_data=b}this.processResources()};ka.fromBinary=function(a){a.constructor==ArrayBuffer&&(a=z.load(a,!0));return new e.Prefab(a)};ka.prototype.processResources=function(){if(this._resources_data){var a=this._resources_data,b;for(b in a)e.ResourcesManager.resources[b]||
  (e.ResourcesManager.resources_being_processed[b]=!0);for(b in a)if(!e.ResourcesManager.resources[b]){var c=a[b];c?e.ResourcesManager.processResource(b,c,{is_local:!0,from_prefab:!0}):console.warn("resource data in prefab is undefined, skipping it:"+b)}}};ka.prototype.createObject=function(){if(!this.prefab_json)throw"No prefab_json data found";var a=JSON.parse(this.prefab_json);if(!a)return console.error("Prefab data is null"),null;var b=new e.SceneNode;b.configure(a);e.ResourcesManager.loadResources(b.getResources({},
  !0));this.fullpath&&(b.prefab=this.fullpath);return b};ka.createPrefab=function(a,b,c){if(a){if(!b)throw"No node_data in prefab";a=a.replace(/ /gi,"_");c=c||[];b.object_type="SceneNode";var d=new e.Prefab;"wbin"!=e.ResourcesManager.getExtension(a)&&(a+=".wbin");d.filename=a;d.resource_names=c;d.prefab_data=b;d.prefab_json=JSON.stringify(d.prefab_data);a=e.Prefab.packResources(c,{"@json":d.prefab_json,"@version":ka.version});d._original_data=a;return d}};ka.packResources=function(a,b){var c=b||{},
  d=[];if(a&&a.length)for(var f=0;f<a.length;++f){var g=a[f],h=e.ResourcesManager.resources[g];if(h){var k=null;(k=h._original_data?h._original_data:e.Resource.getDataToStore(h).data)?k.constructor===Blob||k.constructor===File?console.warning("WBin does not support to store File or Blob, please convert to ArrayBuffer using FileReader"):(c["@RES_"+d.length]=k,d.push(g)):console.warning("Wrong data in resource")}}c["@resources_name"]=d;return z.create(c,"Prefab")};ka.prototype.containsResources=function(){return 0<
  this.resource_names.length};ka.prototype.updateFromNode=function(a,b){var c=a.serialize(!0);b&&e.clearUIds(c);this.prefab_data=c;this.prefab_json=JSON.stringify(c)};ka.prototype.flagResources=function(){if(this.resource_names)for(var a=0;a<this.resource_names.length;++a){var b=e.ResourcesManager.resources[this.resource_names[a]];b&&(b.from_prefab=this.fullpath||this.filename||!0)}};ka.prototype.setResourcesLink=function(a){for(var b=0;b<this.resource_names.length;++b){var c=e.ResourcesManager.resources[this.resource_names[b]];
  c&&(a?c.from_prefab=a:delete c.from_prefab)}};ka.prototype.applyToNodes=function(a){a=a||e.GlobalScene;for(var b=this.fullpath||this.filename,c=0;c<a._nodes.length;++c){var d=a._nodes[c];d.prefab==b&&d.reloadFromPrefab()}};ka.prototype.getDataToStore=function(){this.prefab_json=JSON.stringify(this.prefab_data);return e.Prefab.packResources(this.resource_names,{"@json":this.prefab_json,"@version":e.Prefab.version})};e.Prefab=ka;e.registerResourceClass(ka);Ba.version="0.2";Ba.prototype.configure=function(a){this._data=
  e.cloneObject(a);this.resource_names=a["@resource_names"];this._resources_data={};if(this.resource_names){delete this._data["@resource_names"];for(var b in this.resource_names)this._resources_data[this.resource_names[b]]=a["@RES_"+b],delete this._data["@RES_"+b]}this.processResources()};Object.defineProperty(Ba.prototype,"bindata",{set:function(a){throw"Pack bindata cannot be assigned";},get:function(){this._original_data||(this._original_data=e.Pack.packResources(this.resource_names,this._data));
  return this._original_data},enumerable:!0});Ba.fromBinary=function(a){a.constructor==ArrayBuffer&&(a=z.load(a,!0));return new e.Pack(a)};Ba.prototype.processResources=function(){if(this.resource_names){for(var a=0;a<this.resource_names.length;++a){var b=this.resource_names[a];e.ResourcesManager.resources[b]||(e.ResourcesManager.resources_being_processed[b]=!0)}for(a=0;a<this.resource_names.length;++a)if(b=this.resource_names[a],!e.ResourcesManager.resources[b]){var c=this._resources_data[b];c?e.ResourcesManager.processResource(b,
  c,{is_local:!0,from_pack:!0}):console.warn("resource data in Pack is undefined, skipping it:"+b)}}};Ba.prototype.setResources=function(a,b){this.resource_names=[];this._resources_data={};for(var c=0;c<a.length;++c){var d=a[c];if(-1==this.resource_names.indexOf(d)){var f=e.ResourcesManager.resources[d];f&&(b&&(f.from_pack=!0),this.resource_names.push(d))}}this._original_data=e.Pack.packResources(a,{"@metadata":JSON.stringify(this.metadata),"@version":e.Pack.version});this._modified=!0};Ba.prototype.setResourcesLink=
  function(a){for(var b=0;b<this.resource_names.length;++b){var c=e.ResourcesManager.resources[this.resource_names[b]];c&&(a?c.from_pack=a:delete c.from_pack)}};Ba.prototype.addResources=function(a,b){a&&(a.constructor!==Array&&(a=[a]),this.setResources(this.resource_names.concat(a),b))};Ba.createPack=function(a,b,c,d){if(a){if(!b||b.constructor!==Array)throw"Pack.createPack resources must be array with names";if(c&&c.constructor!==Object)throw"Pack.createPack extra_data must be an object with the chunks to store";
  a=a.replace(/ /gi,"_");var f=new e.Pack;f.filename=a+".wbin";c&&(f._data=c);f.resource_names=b;for(a=0;a<b.length;++a){var g=e.ResourcesManager.resources[b[a]];g&&d&&(g.from_pack=!0)}b=e.Pack.packResources(b,c);f._original_data=b;return f}};Ba.packResources=function(a,b){for(var c=b||{},d=[],f=0;f<a.length;++f){var g=a[f],h=e.ResourcesManager.resources[g];if(h){var k=null;if(k=h._original_data?h._original_data:e.Resource.getDataToStore(h).data){if(k.constructor===Blob||k.constructor===File){if(!k.data||
  k.data.constructor!==ArrayBuffer){console.warn("WBin does not support to store File or Blob, please, use ArrayBuffer");continue}k=k.data}c["@RES_"+d.length]=k;d.push(g)}else console.warn("Wrong data in resource")}}c["@resource_names"]=d;return z.create(c,"Pack")};Ba.prototype.flagResources=function(){if(this.resource_names)for(var a=0;a<this.resource_names.length;++a){var b=e.ResourcesManager.resources[this.resource_names[a]];b&&(b.from_pack=this.fullpath||this.filename||!0)}};e.Pack=Ba;e.registerResourceClass(Ba);
  R.CODE=1;R.PRAGMA=2;R.INCLUDE=1;R.SHADERBLOCK=2;Object.defineProperty(R.prototype,"code",{enumerable:!0,get:function(){return this._code},set:function(a){this._code!=a&&(this._code=a,this.processCode())}});R.prototype.processCode=function(){this._global_uniforms={};this._code_parts={};this._compiled_shaders={};this._init_function=null;this._shaderblock_flags_num=0;this._shaderblock_flags={};var a=GL.processFileAtlas(this._code);this._subfiles=a;var b=0,c=null,d;for(d in a){var f=d,g=a[d];b++;if(f)if("js"==
  f)c=g;else if("uniforms"==f)for(var g=g.split("/n"),h=0;h<g.length;++h){var f=g[h].trim(),k=f.split(" "),m=k[0],l=k[1],p=k[2],k=k[3];void 0!==k&&(k=e.stringToValue(k));var n=null,q=f.indexOf("{");-1!=q&&(n=e.stringToValue(f.substr(q)));this._global_uniforms[m]={name:m,uniform:l,type:p,value:k,options:n}}else if(h=e.ResourcesManager.removeExtension(f),f=e.ResourcesManager.getExtension(f),"vs"==f||"fs"==f)(m=this._code_parts[h])||(m=this._code_parts[h]={}),m[f]=this.parseGLSLCode(g)}a=this.getShader();
  if(c&&(c=e.ShaderCode.removeComments(c)))if(e.catch_exceptions)try{this._init_function=new Function(c)}catch(r){e.dispatchCodeError(r,M.computeLineFromError(r),this)}else this._init_function=new Function(c);this.validatePublicUniforms(a);LEvent.trigger(e.ShaderCode,"modified",this)};R.prototype.setData=function(a,b){this.code=a;b||(this._modified=!0)};R.prototype.getData=function(){return this._code};R.prototype.getDataToStore=function(){return this._code};R.prototype.getShader=function(a,b){a=a||
  "default";b=b||0;var c=this._compiled_shaders[a];if(c&&(c=c.get(b)))return c;var d=this._code_parts[a];if(!d)return null;c=null;if("fx"==a)c=GL.Shader.SCREEN_VERTEX_SHADER;else if(d.vs)c=this.getCodeFromSubfile(d.vs,GL.VERTEX_SHADER,b);else return null;if(d.fs){d=this.getCodeFromSubfile(d.fs,GL.FRAGMENT_SHADER,b);if(!c||!d)return null;c=this.compileShader(c,d);if(!c)return null;this._compiled_shaders[a]||(this._compiled_shaders[a]=new Map);this._compiled_shaders[a].set(b,c);return c}};R.prototype.compileShader=
  function(a,b){if(e.catch_exceptions)try{return new GL.Shader(a,b)}catch(c){e.ShadersManager.dumpShaderError(this.filename,c,a,b),e.dispatchCodeError(c)}else return new GL.Shader(a,b);return null};R.prototype.validatePublicUniforms=function(a){for(var b in this._global_uniforms)a.uniformInfo[this._global_uniforms[b].uniform]||(info.disabled=!0)};R.prototype.getCodeFromSubfile=function(a,b,c){if(!a.is_dynamic)return a.code;var d="";a=a.blocks;for(var f=0;f<a.length;++f){var g=a[f];if(g.type===R.CODE)d+=
  g.code;else if(g.include){var h=g.include;if(e.ResourcesManager.getExtension(h)){var k=e.ResourcesManager.getResource(h,e.ShaderCode);if(!k)return e.ResourcesManager.load(h),null;if(g.include_subfile){g=k._subfiles[g.include_subfile];if(void 0===g)return null;d+="\n"+g+"\n"}else d+="\n"+k._subfiles[""]+"\n"}else{g=e.ShadersManager.getSnippet(h);if(!g)return null;d+="\n"+g.code+"\n"}}else if(g.shader_block){h=e.ShadersManager.getShaderBlock(g.shader_block);if(!h)return console.error("Shader uses unknown ShaderBLock: ",
  g.shader_block),null;g=h.getCode(b,c);d+="\n"+g+"\n"}}return d};R.prototype.parseGLSLCode=function(a){a=a.replace(/(\/\*([\s\S]*?)\*\/)|(\/\/(.*)$)/gm,"");for(var b=[],c=[],d={},f={},e={},h={},k=!1,m=a.split("\n"),l=0;l<m.length;l++){var p=m[l].trim();if(p.length)if("#"!=p[0]){var n=p.split(" ");if("uniform"==n[0]){var q=n[2].split(";");f[q[0]]=n[1]}c.push(p)}else if(n=p.split(" "),"#pragma"==n[0]){b.push({type:R.CODE,code:c.join("\n")});k=!0;d[n[2]]=!0;q=n[1];c.length=0;p={type:R.PRAGMA,line:p,action:q,
  param:n[2]};if("include"==q){if(!n[2]){console.error("shader include without path");continue}p.action_type=R.INCLUDE;n=n[2].substr(1,n[2].length-2).split(":");q=n[1];p.include=n[0];p.include_subfile=q;e[p.include]=!0}else if("shaderblock"==q){if(!n[2]){console.error("#pragma shaderblock without name");continue}p.action_type=R.SHADERBLOCK;n=n[2].substr(1,n[2].length-2);p.shader_block=n;h[p.shader_block]=!0;p.shader_block_flag=this._shaderblock_flags_num;this._shaderblock_flags[n]=p.shader_block_flag;
  this._shaderblock_flags_num+=1}b.push(p)}else c.push(p)}c.length&&b.push({type:R.CODE,code:c.join("\n")});return{is_dynamic:k,code:a,blocks:b,pragmas:d,uniforms:f,includes:e,shader_blocks:h}};R.prototype.register=function(){e.ResourcesManager.registerResource(this.fullpath||this.filename,this)};R.prototype.applyToMaterials=function(a){a=this.fullpath||this.filename;for(var b in e.ResourcesManager.resources){var c=e.ResourcesManager.resources[b];c.constructor===e.ShaderMaterial&&c._shader==a&&c.processShaderCode()}c=
  e.GlobalScene.getNodes();for(b=0;b<c.length;++b){var d=c[b];d.material&&d.material.constructor===e.ShaderMaterial&&d.material._shader==a&&d.material.processShaderCode()}};R.removeComments=function(a){return a.replace(/(\/\*([\s\S]*?)\*\/)|(\/\/(.*)$)/gm,"")};R.examples={};R.examples.fx="\n\\fx.fs\n\tprecision highp float;\n\t\n\tuniform float u_time;\n\tuniform vec4 u_viewport;\n\tuniform sampler2D u_texture;\n\tvarying vec2 v_coord;\n\tvoid main() {\n\t\tgl_FragColor = texture2D( u_texture, v_coord );\n\t}\n";
  R.examples.color="\n\n\\default.vs\n\nprecision mediump float;\nattribute vec3 a_vertex;\nattribute vec3 a_normal;\nattribute vec2 a_coord;\n\n//varyings\nvarying vec3 v_pos;\nvarying vec3 v_normal;\nvarying vec2 v_uvs;\n\n//matrices\nuniform mat4 u_model;\nuniform mat4 u_normal_model;\nuniform mat4 u_view;\nuniform mat4 u_viewprojection;\n\n//globals\nuniform float u_time;\nuniform vec4 u_viewport;\nuniform float u_point_size;\n\n//camera\nuniform vec3 u_camera_eye;\nvoid main() {\n\t\n\tvec4 vertex4 = vec4(a_vertex,1.0);\n\tv_normal = a_normal;\n\tv_uvs = a_coord;\n\t\n\t//vertex\n\tv_pos = (u_model * vertex4).xyz;\n\t//normal\n\tv_normal = (u_normal_model * vec4(v_normal,1.0)).xyz;\n\tgl_Position = u_viewprojection * vec4(v_pos,1.0);\n}\n\n\\default.fs\n\nprecision mediump float;\n//varyings\nvarying vec3 v_pos;\nvarying vec3 v_normal;\nvarying vec2 v_uvs;\n//globals\nuniform vec4 u_clipping_plane;\nuniform float u_time;\nuniform vec3 u_background_color;\nuniform vec3 u_ambient_light;\n\n//material\nuniform vec4 u_material_color; //color and alpha\nvoid main() {\n\tgl_FragColor = u_material_color;\n}\n\n";
  e.ShaderCode=R;e.registerResourceClass(R);"undefined"!=typeof LiteGraph&&(Z.LGraphScene=function(){this.addOutput("Time","number");this._scene=null},LGraphScene.title="Scene",LGraphScene.desc="Scene",LGraphScene.getComponents=function(a,b){b=b||[];var c=a.getComponents();if(!c)return b;for(var d=0;d<c.length;++d){var f=e.getClassName(c[d].constructor);b.push([f,f])}return b},LGraphScene.prototype.onAdded=function(a){this.bindEvents(this.graph.getScene())},LGraphScene.prototype.onRemoved=function(){this.bindEvents(null)},
  LGraphScene.prototype.onConnectionsChange=function(){this.bindEvents(this.graph.getScene())},LGraphScene.prototype.bindEvents=function(a){this._scene&&LEvent.unbindAll(this._scene,this);if((this._scene=a)&&this.outputs&&this.outputs.length)for(a=0;a<this.outputs.length;++a){var b=this.outputs[a];b.type===LiteGraph.EVENT&&(b=b.name.substr(3),LEvent.bind(this._scene,b,this.onEvent,this))}},LGraphScene.prototype.onEvent=function(a,b){this.trigger("on_"+a,b)},LGraphScene.prototype.onExecute=function(){var a=
  this.graph.getScene();if(this.inputs)for(var b=0;b<this.inputs.length;++b)this.getInputData(b);if(this.outputs)for(b=0;b<this.outputs.length;++b){var c=this.outputs[b];if(c.links&&c.links.length&&c.type!=LiteGraph.EVENT){var d=null;switch(c.name){case "Time":d=a.getTime();break;case "Elapsed":d=null!=a._last_dt?a._last_dt:0;break;case "Frame":d=null!=a._frame?a._frame:0;break;default:d=a.root.getComponent(c.name)}this.setOutputData(b,d)}}},LGraphScene.prototype.onGetOutputs=function(){var a=[["Elapsed",
  "number"],["Frame","number"],["on_start",LiteGraph.EVENT],["on_finish",LiteGraph.EVENT]];return LGraphScene.getComponents(this.graph.getScene().root,a)},LiteGraph.registerNodeType("scene/scene",LGraphScene),Z.LGraphSceneNode=function(){this.properties={node_id:""};this.size=[100,20];this.addInput("node_id","string",{locked:!0});this._node=null},LGraphSceneNode.title="SceneNode",LGraphSceneNode.desc="Node on the scene",LGraphSceneNode.prototype.onRemoved=function(){this._node&&this.bindNodeEvents(null)},
  LGraphSceneNode.prototype.onConnectionsChange=function(){this.bindNodeEvents(this._component)},LGraphSceneNode.prototype.getNode=function(){var a=null;this.inputs&&this.inputs[0]&&(a=this.getInputData(0));a&&(this.properties.node_id=a);!a&&this.properties.node_id&&(a=this.properties.node_id);var b=this.graph.getScene();if(b){var c=null;a&&(c=b.getNode(a));this._node!=c&&this.bindNodeEvents(c);return c}},LGraphSceneNode.prototype.onExecute=function(){var a=this.getNode();if(a){if(this.inputs)for(var b=
  1;b<this.inputs.length;++b){var c=this.inputs[b];if(c.type!==LiteGraph.ACTION){var d=this.getInputData(b);if(void 0!==d)switch(c.name){case "Transform":a.transform.copyFrom(d);break;case "Material":a.material=d;break;case "Visible":a.flags.visible=d}}}if(this.outputs)for(b=0;b<this.outputs.length;++b)if(c=this.outputs[b],c.links&&c.links.length&&c.type!=LiteGraph.EVENT)switch(c.name){case "Material":this.setOutputData(b,a.getMaterial());break;case "Transform":this.setOutputData(b,a.transform);break;
  case "Mesh":this.setOutputData(b,a.getMesh());break;case "Visible":this.setOutputData(b,a.flags.visible);break;default:d=a.getComponentByUId(c.name);if(!d){var f=a.scene.findComponentByUId(c.name);f&&(d=e.getObjectClassName(f),d=a.getComponent(d))&&(c.name=d.uid)}this.setOutputData(b,d)}}},LGraphSceneNode.prototype.getComponents=function(a){a=a||[];var b=this.getNode();if(!b)return a;b=b.getComponents();if(!b)return a;for(var c=0;c<b.length;++c){var d=e.getClassName(b[c].constructor);a.push([b[c].uid,
  d,{label:d}])}return a},LGraphSceneNode.prototype.onDropItem=function(a){if(a=a.dataTransfer.getData("node_id"))return this.properties.node_id=a,this.onExecute(),!0},LGraphSceneNode.prototype.onPropertyChanged=function(a,b){"node_id"==a&&this.getNode()},LGraphSceneNode.prototype.bindNodeEvents=function(a){this._node&&LEvent.unbindAll(this._node,this);if((this._node=a)&&this.outputs&&this.outputs.length)for(a=0;a<this.outputs.length;++a){var b=this.outputs[a];b.type===LiteGraph.EVENT&&(b=b.name.substr(3),
  LEvent.bind(this._node,b,this.onNodeEvent,this))}},LGraphSceneNode.prototype.onNodeEvent=function(a,b){this.trigger("on_"+a,b)},LGraphSceneNode.prototype.onGetInputs=function(){return this.getComponents([["Visible","boolean"],["Material","Material"]])},LGraphSceneNode.prototype.onGetOutputs=function(){return this.getComponents([["Visible","boolean"],["Material","Material"],["on_clicked",LiteGraph.EVENT]])},LiteGraph.registerNodeType("scene/node",LGraphSceneNode),Z.LGraphComponent=function(){this.properties=
  {node_id:"",component_id:""};this._component=null},LGraphComponent.title="Component",LGraphComponent.desc="A component from a node",LGraphComponent.prototype.onRemoved=function(){this.bindComponentEvents(null)},LGraphComponent.prototype.onConnectionsChange=function(a){this.bindComponentEvents(this._component)},LGraphComponent.prototype.onInit=function(){var a=this.getComponent();a&&this.processOutputs(a)},LGraphComponent.prototype.processOutputs=function(a){if(this.outputs&&this.outputs.length)for(var b=
  0;b<this.outputs.length;b++){var c=this.outputs[b];c.links&&c.links.length&&c.type!=LiteGraph.EVENT&&("Component"==c.name?this.setOutputData(b,a):this.setOutputData(b,a[c.name]))}},LGraphComponent.prototype.onExecute=function(){var a=this.getComponent();if(a){if(this.inputs)for(var b=0;b<this.inputs.length;b++){var c=this.inputs[b];if(c.type!==LiteGraph.ACTION){var d=this.getInputData(b);void 0!==d&&e.setObjectProperty(a,c.name,d)}}this.processOutputs(a)}},LGraphComponent.updateOutputData=function(a){if(this.outputs&&
  !(a>=this.outputs.length)){var b=this.outputs[bb];if(b.links&&b.links.length&&b.type!=LiteGraph.EVENT){var c=this.getComponent();c&&("Component"==b.name?this.setOutputData(a,c):this.setOutputData(a,c[b.name]))}}},LGraphComponent.prototype.onDrawBackground=function(){var a=this.getComponent();a&&(this.title=e.getClassName(a.constructor))},LGraphComponent.prototype.getComponent=function(){var a=this.graph._scene;if(!a)return null;var b=this.properties.node_id;if(b){a=a.getNode(b);if(!a)return null;
  var b=this.properties.component_id,c=null;if("@"==b.charAt(0))c=a.getComponentByUId(b);else if(e.Components[b])c=a.getComponent(e.Components[b]);else return null;if(c&&!c.constructor.is_component)return null;this._component!=c&&this.bindComponentEvents(c);return this._component=c}},LGraphComponent.prototype.bindComponentEvents=function(a){this._component&&LEvent.unbindAll(this._component,this);if((this._component=a)&&this.outputs&&this.outputs.length)for(a=0;a<this.outputs.length;++a){var b=this.outputs[a];
  b.type===LiteGraph.EVENT&&(b=b.name.substr(3),LEvent.bind(this._component,b,this.onComponentEvent,this))}},LGraphComponent.prototype.onComponentEvent=function(a,b){this.trigger("on_"+a,b)},LGraphComponent.prototype.getComponentProperties=function(a,b){var c=this.getComponent();if(!c)return null;var d=null,d=c.getPropertiesInfo?c.getPropertiesInfo(a):e.getObjectProperties(c);b=b||[];for(var f in d)b.push([f,d[f]]);return b},LGraphComponent.prototype.onAction=function(a,b){if(a){var c=this.getComponent();
  if(c&&c[a])c[a]()}},LGraphComponent.prototype.onGetInputs=function(){var a=[];this.getComponentProperties("input",a);var b=this.getComponent();if(b&&b.getEventActions&&(b=b.getEventActions()))for(var c in b)a.push([c,LiteGraph.ACTION]);return a},LGraphComponent.prototype.onGetOutputs=function(){var a=[];a.push(["Component","Component"],null);this.getComponentProperties("output",a);var b=this.getComponent();if(b&&b.getEvents&&(b=b.getEvents()))for(var c in b)a.push(["on_"+c,LiteGraph.EVENT]);return a},
  LiteGraph.registerNodeType("scene/component",LGraphComponent),Z.LGraphTransform=function(){this.properties={node_id:""};LGraphSceneNode._current_node_id&&(this.properties.node=LGraphSceneNode._current_node_id);this.addInput("Transform","Transform",{locked:!0});this.addOutput("Position","vec3")},LGraphTransform.title="Transform",LGraphTransform.desc="Transform info of a node",LGraphTransform.prototype.onExecute=function(){var a=null;this.inputs&&this.inputs[0]&&(a=this.getInputData(0));if(!a){a=this.graph.getScene();
  if(!a)return;var b=this._node;if(this.properties.node&&(b=a.getNode(this.properties.node),!b))return;b||(b=this.graph._scenenode);a=b.transform}if(a){if(this.inputs)for(b=1;b<this.inputs.length;++b){var c=this.inputs[b],d=this.getInputData(b);if(void 0!==d)switch(c.name){case "x":a.x=d;break;case "y":a.y=d;break;case "z":a.z=d;break;case "Position":a.setPosition(d);break;case "Rotation":a.setRotation(d);break;case "Scale":a.setScale(d);break;case "Matrix":a.fromMatrix(d);break;case "Translate":a.translate(d);
  break;case "Translate Global":a.translateGlobal(d);break;case "RotateY":a.rotateY(d)}}if(this.outputs)for(b=0;b<this.outputs.length;++b)if(c=this.outputs[b],c.links&&c.links.length){d=void 0;switch(c.name){case "x":d=a.x;break;case "y":d=a.y;break;case "z":d=a.z;break;case "Position":d=a.position;break;case "Global Position":d=a.getGlobalPosition();break;case "Rotation":d=a.rotation;break;case "Global Rotation":d=a.getGlobalRotation();break;case "Scale":d=a.scaling;break;case "Matrix":d=a.getMatrix()}void 0!==
  d&&this.setOutputData(b,d)}}},LGraphTransform.prototype.onGetInputs=function(){return[["Position","vec3"],["Rotation","quat"],["Scale","number"],["x","number"],["y","number"],["z","number"],["Global Position","vec3"],["Global Rotation","quat"],["Matrix","mat4"],["Translate","vec3"],["Translate Local","vec3"],["RotateY","number"]]},LGraphTransform.prototype.onGetOutputs=function(){return[["Position","vec3"],["Rotation","quat"],["Scale","number"],["x","number"],["y","number"],["z","number"],["Global Position",
  "vec3"],["Global Rotation","quat"],["Matrix","mat4"]]},LiteGraph.registerNodeType("scene/transform",LGraphTransform),Z.LGraphMaterial=function(){this.properties={mat_name:""};this.addInput("Material","Material");this.size=[100,20]},LGraphMaterial.title="Material",LGraphMaterial.desc="Material of a node",LGraphMaterial.prototype.onExecute=function(){var a=this.getMaterial();if(a){for(var b=0;b<this.inputs.length;++b){var c=this.inputs[b],d=this.getInputData(b);void 0!==d&&"Material"!=c.name&&a.setProperty(c.name,
  d)}if(this.outputs)for(b=0;b<this.outputs.length;++b)c=this.outputs[b],c.links&&c.links.length&&(d=a.getProperty(c.name),this.setOutputData(b,d))}},LGraphMaterial.prototype.getMaterial=function(){var a=this.findInputSlot("Material");return-1!=a?this.getInputData(a):this.properties.mat_name?e.RM.materials[this.properties.mat_name]:null},LGraphMaterial.prototype.onGetInputs=function(){var a=this.getMaterial();if(a){var a=a.getPropertiesInfo(),b=[["Material","Material"]],c;for(c in a)b.push([c,a[c]]);
  return b}},LGraphMaterial.prototype.onGetOutputs=function(){var a=this.getMaterial();if(a){var a=a.getPropertiesInfo(),b=[["Material","Material"]],c;for(c in a)b.push([c,a[c]]);return b}},LiteGraph.registerNodeType("scene/material",LGraphMaterial),Z.LGraphMaterial=LGraphMaterial,Z.LGraphGlobal=function(){this.addOutput("Value");this.properties={name:"myvar",value:0,type:"number",min:0,max:1}},LGraphGlobal.title="Global",LGraphGlobal.desc="Global var for the graph",LGraphGlobal["@type"]={type:"enum",
  values:"number string node vec2 vec3 vec4 color texture".split(" ")},LGraphGlobal.prototype.onExecute=function(){this.properties.name&&this.setOutputData(0,this.properties.value)},LGraphGlobal.prototype.onDrawBackground=function(){this.outputs[0].label=this.properties.name},LiteGraph.registerNodeType("scene/global",LGraphGlobal),Z.LGraphLocatorProperty=function(){this.addInput("in");this.addOutput("out");this.size=[80,20];this.properties={locator:""}},LGraphLocatorProperty.title="Property",LGraphLocatorProperty.desc=
  "A property of a node or component of the scene specified by its locator string",LGraphLocatorProperty.prototype.getLocatorInfo=function(){var a=this.properties.locator;if(this.properties.locator)return this._locator_info=(this.graph.scene||e.GlobalScene).getPropertyInfo(a)},LGraphLocatorProperty.prototype.onExecute=function(){var a=this.getLocatorInfo();a&&a.target&&(this.title=a.name,this.inputs.length&&null!==this.inputs[0].link&&Wa.setFromInfo(a,this.getInputData(0)),this.outputs.length&&this.outputs[0].links&&
  this.outputs[0].links.length&&this.setOutputData(0,Wa.getFromInfo(a)))},LiteGraph.registerNodeType("scene/property",LGraphLocatorProperty),Z.LGraphToggleValue=function(){this.addInput("target","Component");this.addInput("toggle",LiteGraph.ACTION);this.properties={property_name:""}},LGraphToggleValue.title="Toggle",LGraphToggleValue.desc="Toggle a property value",LGraphToggleValue.prototype.onAction=function(a,b){var c=this.getInputData(0,!0);if(c){var d=this.properties.property_name;void 0!==c[d]&&
  (c[d]=!c[d])}},LiteGraph.registerNodeType("scene/toggle",LGraphToggleValue),Z.LGraphFrame=function(){this.addOutput("Color","Texture");this.addOutput("Depth","Texture");this.addOutput("Extra","Texture");this.addOutput("Camera","Camera");this.properties={}},LGraphFrame.title="Frame",LGraphFrame.desc="One frame rendered from the scene renderer",LGraphFrame.prototype.onExecute=function(){this.setOutputData(0,LGraphTexture.getTexture(this._color_texture));this.setOutputData(1,LGraphTexture.getTexture(this._depth_texture));
  this.setOutputData(2,LGraphTexture.getTexture(this._extra_texture));this.setOutputData(3,this._camera)},LGraphFrame.prototype.onDrawBackground=function(a){if(!(this.flags.collapsed||20>=this.size[1])&&this._color_texture&&a.webgl){if(this._last_preview_tex!=this._last_tex||!this._last_preview_tex)if(a.webgl&&this._canvas&&this._canvas.constructor===GL.Texture)this._canvas=this._last_tex;else{var b=LGraphTexture.getTexture(this._color_texture);if(!b)return;b=LGraphTexture.generateLowResTexturePreview(b);
  if(!b)return;this._last_preview_tex=this._last_tex;this._canvas=cloneCanvas(b)}if(this._canvas){a.save();if(!a.webgl){if(this._canvas.constructor===GL.Texture){this._canvas=null;return}a.translate(0,this.size[1]);a.scale(1,-1)}a.drawImage(this._canvas,0,0,this.size[0],this.size[1]);a.restore()}}},LiteGraph.registerNodeType("scene/frame",LGraphFrame));la.LINE=1;la.SPLINE=2;la.BEZIER=3;la.prototype.addPoint=function(a){var b=vec3.create();b[0]=a[0];b[1]=a[1];2<a.length&&(b[2]=a[2]);this.points.push(b)};
  la.prototype.getSegments=function(){var a=this.points.length;switch(this.type){case la.LINE:if(2>a)break;return a-1;case la.SPLINE:if(3>a)break;return(a-1)/3|0}return 0};la.prototype.computePoint=function(a,b){switch(this.type){case la.LINE:return this.getLinearPoint(a,b);default:return this.getSplinePoint(a,b)}};la.prototype.getLinearPoint=function(a,b){b=b||vec3.create();var c=this.points.length;if(2>c)return b;if(0>=a)return vec3.copy(b,this.points[0]);if(1<=a)return vec3.copy(b,this.points[c-
  1]);var c=(c-1)*a,d=c|0;return vec3.lerp(b,this.points[d],this.points[d+1],c-d)};la.prototype.getSplinePoint=function(a,b){b=b||vec3.create();var c=this.points.length;if(4>c)return b;c=3*((c-1)/3|0)+1;if(0>=a)return vec3.copy(b,this.points[0]);if(1<=a)return vec3.copy(b,this.points[c-1]);var c=(c-1)/3*a,d=c|0,f=c-d,c=this.points[d],e=this.points[d+1],h=this.points[d+2],d=this.points[d+3],k=(1-f)*(1-f)*(1-f),m=3*f*(1-f)*(1-f),l=3*f*f*(1-f),f=f*f*f;b[0]=c[0]*k+e[0]*m+h[0]*l+d[0]*f;b[1]=c[1]*k+e[1]*
  m+h[1]*l+d[1]*f;b[2]=c[2]*k+e[2]*m+h[2]*l+d[2]*f;return b};la.prototype.samplePoints=function(a){0>=a&&(a=this.getSegments(),a=this.type==e.Path.LINE?a+1:20*a);for(var b=Array(a),c=0;c<a;c++)b[c]=this.computePoint(c/(a-1));return b};la.prototype.serialize=function(){for(var a={},b=Array(3*this.points.length),c=0;c<this.points.length;c++){var d=this.points[c];b[3*c]=d[0];b[3*c+1]=d[1];b[3*c+2]=d[2]}a.points=b;a.type=this.type;a.closed=this.closed;return a};la.prototype.configure=function(a){this.type=
  a.type;this.closed=a.closed;if(a.points){this.points.length=a.points.length/3;a=a.points;for(var b=0;b<this.points.length;b++)this.points[b]=vec3.fromValues(a[3*b],a[3*b+1],a[3*b+2])}};e.Path=la;ua.available_fx={brightness_contrast:{name:"Brightness & Contrast",uniforms:{brightness:{name:"u_brightness",type:"float",value:1,step:0.01},contrast:{name:"u_contrast",type:"float",value:1,step:0.01}},code:"color.xyz = (color.xyz * u_brightness@ - vec3(0.5)) * u_contrast@ + vec3(0.5);"},invert:{name:"Invert color",
  code:"color.xyz = vec3(1.0) - color.xyz;"},threshold:{name:"Threshold",uniforms:{threshold:{name:"u_threshold",type:"float",value:0.5,min:0,max:2,step:0.01},threshold_width:{name:"u_threshold_width",type:"float",value:0.01,min:0,max:1,step:0.001}},code:"color.xyz = vec3( smoothstep( u_threshold@ - u_threshold_width@ * 0.5, u_threshold@ + u_threshold_width@ * 0.5,  length(color.xyz) ));"},colorize:{name:"Colorize",uniforms:{colorize:{name:"u_colorize",type:"color3",value:[1,1,1]},vibrance:{name:"u_vibrance",
  type:"float",value:0,min:0,max:2,step:0.01}},code:"color.xyz = color.xyz * (u_colorize@ + vec3(u_vibrance@ * 0.1)) * (1.0 + u_vibrance@);"},color_add:{name:"Color add",uniforms:{color_add:{name:"u_coloradd",type:"color3",value:[0.1,0.1,0.1]}},code:"color.xyz = color.xyz + u_coloradd@;"},vigneting:{name:"Vigneting",uniforms:{radius:{name:"u_radius",type:"float",value:1},intensity:{name:"u_vigneting",type:"float",value:1,min:0,max:2,step:0.01}},code:"color.xyz = mix( color.xyz * max( 1.0 - (dist_to_center * u_radius@ / 0.7071), 0.0), color.xyz, u_vigneting@);"},
  aberration:{name:"Chromatic Aberration",pass:"before",uniforms:{difraction:{name:"u_difraction",type:"float",value:1}},next_pass:!0,code:"color.x = texture2D(u_texture, uv - to_center * 0.001 * u_difraction@ ).x;color.z = texture2D(u_texture, uv + to_center * 0.001 * u_difraction@ ).z;"},halftone:{name:"Halftone",uniforms:{"Halftone angle":{name:"u_halftone_angle",type:"float",value:0,step:0.01},"Halftone size":{name:"u_halftone_size",type:"float",value:1,step:0.01}},functions:["pattern"],code:"color.x = ( (color.x * 10.0 - 5.0) + pattern( u_halftone_angle@, u_halftone_size@ ) );color.y = ( (color.y * 10.0 - 5.0) + pattern( u_halftone_angle@ + 0.167, u_halftone_size@ ) );color.z = ( (color.z * 10.0 - 5.0) + pattern( u_halftone_angle@ + 0.333, u_halftone_size@ ) );"},
  halftoneBN:{name:"Halftone B/N",uniforms:{"Halftone angle":{name:"u_halftone_angle",type:"float",value:0,step:0.01},"Halftone size":{name:"u_halftone_size",type:"float",value:1,step:0.01}},functions:["pattern"],code:"color.xyz = vec3( (length(color.xyz) * 10.0 - 5.0) + pattern( u_halftone_angle@, u_halftone_size@ ) );"},lens:{name:"Lens Distortion",uniforms:{lens_k:{name:"u_lens_k",type:"float",value:-0.15},lens_kcube:{name:"u_lens_kcube",type:"float",value:0.8},lens_scale:{name:"u_lens_scale",type:"float",
  value:1}},uv_code:"float r2 = u_aspect * u_aspect * (uv.x-0.5) * (uv.x-0.5) + (uv.y-0.5) * (uv.y-0.5); float distort@ = 1. + r2 * (u_lens_k@ + u_lens_kcube@ * sqrt(r2)); uv = vec2( u_lens_scale@ * distort@ * (uv.x-0.5) + 0.5, u_lens_scale@  * distort@ * (uv.y-0.5) + 0.5 );"},warp:{name:"Warp",uniforms:{warp_amp:{name:"u_warp_amp",type:"float",value:0.01,step:0.001},warp_texture:{name:"u_warp_texture",type:"sampler2D",widget:"Texture",value:""}},uv_code:"uv = uv + u_warp_amp@ * (texture2D( u_warp_texture@, uv ).xy - vec2(0.5));"},
  LUT:{name:"LUT",functions:["LUT"],uniforms:{lut_intensity:{name:"u_lut_intensity",type:"float",value:1,step:0.01},lut_texture:{name:"u_lut_texture",type:"sampler2D",filter:"nearest",wrap:"clamp",widget:"Texture",value:""}},code:"color.xyz = mix(color.xyz, LUT( color.xyz, u_lut_texture@ ), u_lut_intensity@);"},pixelate:{name:"Pixelate",uniforms:{width:{name:"u_width",type:"float",value:256,step:1,min:1},height:{name:"u_height",type:"float",value:256,step:1,min:1}},uv_code:"uv = vec2( floor(uv.x * u_width@) / u_width@, floor(uv.y * u_height@) / u_height@ );"},
  quantize:{name:"Quantize",uniforms:{levels:{name:"u_levels",type:"float",value:8,step:1,min:1}},code:"color.xyz = floor(color.xyz * u_levels@) / u_levels@;"},edges:{name:"Edges",uniforms:{"Edges factor":{name:"u_edges_factor",type:"float",value:1}},next_pass:!0,code:"vec4 color@ = texture2D(u_texture, uv );\n\t\t\t\tvec4 color_up@ = texture2D(u_texture, uv + vec2(0., u_iviewport.y));\n\t\t\t\tvec4 color_right@ = texture2D(u_texture, uv + vec2(u_iviewport.x,0.));\n\t\t\t\tvec4 color_down@ = texture2D(u_texture, uv + vec2(0., -u_iviewport.y));\n\t\t\t\tvec4 color_left@ = texture2D(u_texture, uv + vec2(-u_iviewport.x,0.));\n\t\t\t\tcolor = u_edges_factor@ * (abs(color@ - color_up@) + abs(color@ - color_down@) + abs(color@ - color_left@) + abs(color@ - color_right@));"},
  depth:{name:"Depth",uniforms:{near:{name:"u_near",type:"float",value:0.01,step:0.1},far:{name:"u_far",type:"float",value:1E3,step:1}},code:"color.xyz = vec3( (2.0 * u_near@) / (u_far@ + u_near@ - texture2D(u_texture_depth, uv ).x * (u_far@ - u_near@)) );"},logarithmic:{name:"Logarithmic",uniforms:{"Log. A Factor":{name:"u_logfactor_a",type:"float",value:2,step:0.01},"Log. B Factor":{name:"u_logfactor_b",type:"float",value:2,step:0.01}},code:"color.xyz = log( color.xyz * u_logfactor_a@ ) * u_logfactor_b@;"},
  ditherBN:{name:"dither B/N",functions:["dither"],uniforms:{},code:"color.xyz = vec3( dither( color.x ) );"},dither:{name:"Dither",functions:["dither"],uniforms:{},code:"color.xyz = vec3( dither( color.x ), dither( color.y ), dither( color.z ) );"},gamma:{name:"Gamma",uniforms:{Gamma:{name:"u_gamma",type:"float",value:2.2,step:0.01}},code:"color.xyz = pow( color.xyz, vec3( 1.0 / u_gamma@) );"},noiseBN:{name:"Noise B&N",functions:["noise"],uniforms:{noise:{name:"u_noise",type:"float",value:0.1,step:0.01}},
  code:"color.xyz += u_noise@ * vec3( noise( (u_random + v_coord) * u_viewport) );"}};ua.available_functions={pattern:"float pattern(float angle, float size) {\n\t\t\t\tfloat s = sin(angle * 3.1415), c = cos(angle * 3.1415);\n\t\t\t\tvec2 tex = v_coord * u_viewport.xy;\n\t\t\t\tvec2 point = vec2( c * tex.x - s * tex.y , s * tex.x + c * tex.y ) * size;\n\t\t\t\treturn (sin(point.x) * sin(point.y)) * 4.0;\n\t\t\t}\n\t\t",dither:"float dither(float v) {\n\t\t\t\tvec2 pixel = v_coord * u_viewport;\n\t\t\t\tint i = int(floor(clamp(v,0.0,1.0) * 16.0 + 0.5));\n\t\t\t\tif(i < 1)\n\t\t\t\t\treturn 0.0;\n\t\t\t\tif(i >= 15)\n\t\t\t\t\treturn 1.0;\n\t\t\t\tfloat x = floor(pixel.x);\n\t\t\t\tfloat y = floor(pixel.y);\n\t\t\t\tbool xmod4 = mod(x, 4.0) == 0.0;\n\t\t\t\tbool ymod4 = mod(y, 4.0) == 0.0;\n\t\t\t\tbool xmod2 = mod(x, 2.0) == 0.0;\n\t\t\t\tbool ymod2 = mod(y, 2.0) == 0.0;\n\t\t\t\tbool xmod4_2 = mod(x + 2.0, 4.0) == 0.0;\n\t\t\t\tbool ymod4_2 = mod(y + 2.0, 4.0) == 0.0;\n\t\t\t\tbool xmod2_1 = mod(x + 1.0, 2.0) == 0.0;\n\t\t\t\tbool ymod2_1 = mod(y + 1.0, 2.0) == 0.0;\n\t\t\t\tbool xmod4_1 = mod(x + 1.0, 4.0) == 0.0;\n\t\t\t\tbool ymod4_1 = mod(y + 1.0, 4.0) == 0.0;\n\t\t\t\tbool xmod4_3 = mod(x + 3.0, 4.0) == 0.0;\n\t\t\t\tbool ymod4_3 = mod(y + 3.0, 4.0) == 0.0;\n\t\t\t\t\n\t\t\t\tif(i < 9)\n\t\t\t\t{\n\t\t\t\t\tif(i >= 1 && xmod4 && ymod4 )\n\t\t\t\t\t\treturn 1.0;\n\t\t\t\t\tif(i >= 2 && xmod4_2 && ymod4_2)\n\t\t\t\t\t\treturn 1.0;\n\t\t\t\t\tif(i >= 3 && xmod4_2 && ymod2 )\n\t\t\t\t\t\treturn 1.0;\n\t\t\t\t\tif(i >= 4 && xmod2 && ymod2 )\n\t\t\t\t\t\treturn 1.0;\n\t\t\t\t\tif(i >= 5 && xmod4_1 && ymod4_1 )\n\t\t\t\t\t\treturn 1.0;\n\t\t\t\t\tif(i >= 6 && xmod4_3 && ymod4_3 )\n\t\t\t\t\t\treturn 1.0;\n\t\t\t\t\tif(i >= 7 && xmod4_1 && ymod4_3 )\n\t\t\t\t\t\treturn 1.0;\n\t\t\t\t\tif(i >= 8 && xmod4_3 && ymod4_1 )\n\t\t\t\t\t\treturn 1.0;\n\t\t\t\t\treturn 0.0;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif(i < 15 && xmod4_1 && ymod4 )\n\t\t\t\t\t\treturn 0.0;\n\t\t\t\t\tif(i < 14 && xmod4_3 && ymod4_2)\n\t\t\t\t\t\treturn 0.0;\n\t\t\t\t\tif(i < 13 && xmod4_3 && ymod2 )\n\t\t\t\t\t\treturn 0.0;\n\t\t\t\t\tif(i < 12 && xmod2_1 && ymod2 )\n\t\t\t\t\t\treturn 0.0;\n\t\t\t\t\tif(i < 11 && xmod4_2 && ymod4_1 )\n\t\t\t\t\t\treturn 0.0;\n\t\t\t\t\tif(i < 10 && xmod4 && ymod4_3 )\n\t\t\t\t\t\treturn 0.0;\n\t\t\t\t\treturn 1.0;\n\t\t\t\t}\n\t\t\t}\n\t\t",
  LUT:"vec3 LUT(in vec3 color, in sampler2D textureB) {\n\t\t lowp vec3 textureColor = clamp( color, vec3(0.0), vec3(1.0) );\n\t\t mediump float blueColor = textureColor.b * 63.0;\n\t\t mediump vec2 quad1;\n\t\t quad1.y = floor(floor(blueColor) / 8.0);\n\t\t quad1.x = floor(blueColor) - (quad1.y * 8.0);\n\t\t mediump vec2 quad2;\n\t\t quad2.y = floor(ceil(blueColor) / 8.0);\n\t\t quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n\t\t highp vec2 texPos1;\n\t\t texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t texPos1.y = 1.0 - ((quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t highp vec2 texPos2;\n\t\t texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t texPos2.y = 1.0 - ((quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t lowp vec3 newColor1 = texture2D(textureB, texPos1).xyz;\n\t\t lowp vec3 newColor2 = texture2D(textureB, texPos2).xyz;\n\t\t lowp vec3 newColor = mix(newColor1, newColor2, fract(blueColor));\n\t\t return newColor.rgb;\n\t }",
  noise:"\n\t\tfloat hash(float n) { return fract(sin(n) * 1e4); }\n\t\tfloat hash(vec2 p) { return fract(1e4 * sin(17.0 * p.x + p.y * 0.1) * (0.1 + abs(sin(p.y * 13.0 + p.x)))); }\n\t\tfloat noise(float x) {\n\t\t\tfloat i = floor(x);\n\t\t\tfloat f = fract(x);\n\t\t\tfloat u = f * f * (3.0 - 2.0 * f);\n\t\t\treturn mix(hash(i), hash(i + 1.0), u);\n\t\t}\n\t\tfloat noise(vec2 x) {\n\t\t\tvec2 i = floor(x);\n\t\t\tvec2 f = fract(x);\n\t\t\tfloat a = hash(i);\n\t\t\tfloat b = hash(i + vec2(1.0, 0.0));\n\t\t\tfloat c = hash(i + vec2(0.0, 1.0));\n\t\t\tfloat d = hash(i + vec2(1.0, 1.0));\n\t\t\tvec2 u = f * f * (3.0 - 2.0 * f);\n\t\t\treturn mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;\n\t\t}\n\t"};
  ua.prototype.configure=function(a){this.apply_fxaa=!!a.apply_fxaa;a.fx&&(this.fx=a.fx.concat())};ua.prototype.serialize=function(){return{apply_fxaa:this.apply_fxaa,fx:this.fx.concat()}};ua.prototype.getResources=function(a){return a};ua.prototype.addFX=function(a){a&&(ua.available_fx[a]?this.fx.push({name:a}):console.warn("TextureFX not found: "+a))};ua.prototype.getFX=function(a){return this.fx[a]};ua.prototype.moveFX=function(a,b){b=b||-1;var c=this.fx.indexOf(a);-1!=c&&(this.fx.splice(c,1),c+=
  b,0<=c&&c<this.fx.length?this.fx.splice(c,0,a):this.fx.push(a))};ua.prototype.removeFX=function(a){for(var b=0;b<this.fx.length;b++)if(this.fx[b]===a){this.fx.splice(b,1);break}};ua.prototype.applyFX=function(a,b,c){c=c.depth_texture;for(var d=this.fx,f="",e=!0,h=0;h<d.length;h++)f+=d[h].name+"|";f==this._last_shader_key&&(e=!1);this._last_shader_key=f;var k=f="",m={},l="",p=2,n=this._uniforms;n.u_viewport[0]=a.width;n.u_viewport[1]=a.height;n.u_iviewport[0]=1/a.width;n.u_iviewport[1]=1/a.height;
  n.u_aspect=a.width/a.height;n.u_random[0]=Math.random();n.u_random[1]=Math.random();for(var q=0,h=0;h<d.length;h++){var r=d[h],q=h,u=ua.available_fx[r.name];if(u){if(e){if(u.functions)for(var t in u.functions)m[u.functions[t]]=!0;u.code&&(k+=u.code.split("@").join(q)+";\n");u.uv_code&&(f+=u.uv_code.split("@").join(q)+";\n")}if(u.uniforms)for(var za in u.uniforms){var s=u.uniforms[za],G=s.name+q;e&&(l+="uniform "+s.type+" "+G+";\n");if("sampler2D"==s.type){if(n[G]=p,G=this.getTexture(r[za]))G.bind(p),
  "nearest"==s.filter&&(gl.texParameteri(G.texture_type,gl.TEXTURE_MAG_FILTER,gl.NEAREST),gl.texParameteri(G.texture_type,gl.TEXTURE_MIN_FILTER,gl.NEAREST)),"clamp"==s.wrap&&(gl.texParameteri(G.texture_type,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE),gl.texParameteri(G.texture_type,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE)),p++}else n[G]=void 0!==r[za]?r[za]:s.value}}}var E=null;if(e){t="";for(h in m)(za=ua.available_functions[h])?t+=za+"\n":console.error("TextureFX: Function not found: "+h);this._last_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,
  "\n\t\t\t#extension GL_OES_standard_derivatives : enable\n\t\t\tprecision highp float;\n\t\t\t#define color3 vec3\n\t\t\t#define color4 vec4\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_texture_depth;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform vec2 u_viewport;\n\t\t\tuniform vec2 u_iviewport;\n\t\t\tuniform float u_aspect;\n\t\t\tuniform vec2 u_random;\n\t\t\tvec2 uv;\n\t\t\t"+l+"\n\t\t\t"+t+"\n\t\t\tvoid main() {\n\t\t\t\tuv = v_coord;\n\t\t\t\tvec2 to_center = vec2(0.5) - uv;\n\t\t\t\tfloat dist_to_center = length(to_center);\n\t\t\t\t"+
  f+"\n\t\t\t\tvec4 color = texture2D(u_texture, uv);\n\t\t\t\tfloat temp = 0.0;\n\t\t\t\t"+k+"\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\n\t\t\t")}E=this._last_shader;E.hasUniform("u_texture_depth")&&c.bind(1);a.setParameter(gl.TEXTURE_MAG_FILTER,this.filter?gl.LINEAR:gl.NEAREST);a.setParameter(gl.TEXTURE_MIN_FILTER,gl.LINEAR);this.apply_fxaa?(this.temp_tex&&this.temp_tex.width==gl.viewport_data[2]&&this.temp_tex.height==gl.viewport_data[3]||(this.temp_tex=new GL.Texture(gl.viewport_data[2],gl.viewport_data[3])),
  this.temp_tex.drawTo(function(){a.toViewport(E,n)}),c=GL.Shader.getFXAAShader(),c.setup(),b?this.temp_tex.copyTo(b,c):this.temp_tex.toViewport(c)):(this.temp_tex=null,b?(E.uniforms(n),this.temp_tex.copyTo(b,E)):a.toViewport(E,n))};ua.prototype.getTexture=function(a){return e.ResourcesManager.getTexture(a)};e.TextureFX=ua;e.Tween={MAX_EASINGS:256,EASE_IN_QUAD:1,EASE_OUT_QUAD:2,EASE_IN_OUT_QUAD:3,QUAD:3,EASE_IN_CUBIC:4,EASE_OUT_CUBIC:5,EASE_IN_OUT_CUBIC:6,CUBIC:6,EASE_IN_QUART:7,EASE_OUT_QUART:8,EASE_IN_OUT_QUART:9,
  QUART:9,EASE_IN_SINE:10,EASE_OUT_SINE:11,EASE_IN_OUT_SINE:12,SINE:12,EASE_IN_EXPO:13,EASE_OUT_EXPO:14,EASE_IN_OUT_EXPO:15,EXPO:15,EASE_IN_BACK:16,EASE_OUT_BACK:17,EASE_IN_OUT_BACK:18,BACK:18,current_easings:[],_alife:[],reset:function(){this.current_easings=[];this._alife=[]},easeProperty:function(a,b,c,d,f,g,h){if(!a)throw"ease object cannot be null";if(void 0===c)throw"target vaue must be defined";if(void 0===a[b])throw"property not found in object, must be initialized to a value";if(this.current_easings.length)for(var k=
  0;k<this.current_easings.length;++k){var m=this.current_easings[k];if(m.object===a&&m.property==b){this.current_easings.splice(k,1);break}}f=f||this.EASE_IN_OUT_QUAD;k=null;k=b?e.cloneObject(a[b]):e.cloneObject(a);c=e.cloneObject(c);m=0;c.constructor===Number?m=-1:c&&void 0!==c.length&&(m=c.length);var l=null,p=a.constructor["@"+b];p&&(l=p.type);c={object:a,property:b,origin:k,target:c,current:0,time:d,easing:f,on_complete:g,on_progress:h,size:m,type:l};for(k=0;k<this.current_easings.length;++k)if(this.current_easings[k].object==
  a&&this.current_easings[k].property==b){this.current_easings[k]=c;break}this.current_easings.length>=this.MAX_EASINGS&&this.current_easings.shift();this.current_easings.push(c);return c},easeObject:function(a,b,c,d,f,g){if(!a||!b)throw"ease object cannot be null";d=d||this.EASE_IN_OUT_QUAD;var h=e.cloneObject(a);b=e.cloneObject(b);var k=0;void 0!==b.length&&(k=b.length);b={object:a,origin:h,target:b,current:0,time:c,easing:d,on_complete:f,on_progress:g,size:k};for(c=0;c<this.current_easings.length;++c)if(this.current_easings[c].object==
  a){this.current_easings[c]=b;break}this.current_easings.length>=this.MAX_EASINGS&&this.current_easings.shift();this.current_easings.push(b);return b},update:function(a){if(this.current_easings.length){var b=this.current_easings,c=this._alife;c.length=b.length;for(var d=0,f=0,e=b.length;f<e;++f){var h=b[f];h.current+=a;var k=1;h.current<h.time&&(k=h.current/h.time,c[d]=h,d+=1);var m=this.getEaseFactor(k,h.easing);if(h.size){if(-1==h.size)h.object[h.property]=h.target*m+h.origin*(1-m);else{var l=h.object[h.property];
  if(h.type&&"quat"==h.type)quat.slerp(l,h.origin,h.target,m);else for(var p=0;p<h.size;++p)l[p]=h.target[p]*m+h.origin[p]*(1-m)}void 0!==h.object.mustUpdate&&(h.object.mustUpdate=!0)}if(h.on_progress)h.on_progress(h);if(1==k&&h.on_complete)h.on_complete(h)}c.length=d;this.current_easings=c;this._alife=b}},getEaseFactor:function(a,b){1<a?a=1:0>a&&(a=0);var c=1.70158;b=b||this.QUAD;switch(b){case this.EASE_IN_QUAD:return a*a;case this.EASE_OUT_QUAD:return 1-a*a;case this.EASE_IN_OUT_QUAD:a*=2;if(1>a)return 0.5*
  a*a;a-=1;return-0.5*(a*(a-2)-1);case this.EASE_IN_CUBIC:return a*a*a;case this.EASE_OUT_CUBIC:return a-=1,a*a*a+1;case this.EASE_IN_OUT_CUBIC:a*=2;if(1>a)return 0.5*a*a*a;a-=2;return 0.5*(a*a*a+2);case this.EASE_IN_QUART:return a*a*a*a;case this.EASE_OUT_QUART:return a-=1,-(a*a*a*a-1);case this.EASE_IN_OUT_QUART:a*=2;if(1>a)return 0.5*a*a*a*a;a-=2;return-0.5*(a*a*a*a-2);case this.EASE_IN_SINE:return 1-Math.cos(a*Math.PI/2);case this.EASE_OUT_SINE:return Math.sin(a*Math.PI/2);case this.EASE_IN_OUT_SINE:return-0.5*
  (Math.cos(Math.PI*a)-1);case this.EASE_IN_EXPO:return 0==a?0:Math.pow(2,10*(a-1));case this.EASE_OUT_EXPO:return 1==a?1:1-Math.pow(2,-10*a);case this.EASE_IN_OUT_EXPO:if(0==a)return 0;if(1==a)return 1;a*=2;return 1>a?0.5*Math.pow(2,10*(a-1)):0.5*(-Math.pow(2,-10*(a-1))+2);case this.EASE_IN_BACK:return a*a*((c+1)*a-c);case this.EASE_OUT_BACK:return a*a*((c+1)*a+c)+1;case this.EASE_IN_OUT_BACK:a*=2;if(1>a)return c*=1.525,0.5*a*a*((c+1)*a-c);a-=2;c*=1.525;return 0.5*(a*a*((c+1)*a+c)+2)}return a}};La.default_shadowmap_resolution=
  1024;La["@default_shadowmap_resolution"]={widget:"combo",values:[0,256,512,1024,2048,4096]};La["@layers"]={type:"layers"};La.prototype.serialize=function(){return e.cloneObject(this)};La.prototype.configure=function(a){if(a)for(var b in a)this[b]=a[b];null===this.layers&&(this.layers=255)};La.prototype.toJSON=La.prototype.serialize;e.RenderSettings=La;var Ya=32,cb=8192,xa=781;ba.prototype.setMatrix=function(a,b){this.matrix.set(a);b?this.normal_matrix.set(b):this.computeNormalMatrix()};ba.prototype.computeNormalMatrix=
  function(){var a=mat4.invert(this.normal_matrix,this.matrix);a&&mat4.transpose(this.normal_matrix,a)};ba.prototype.setMaterial=function(a){(this.material=a)&&a.applyToRenderInstance(this)};ba.prototype.setMesh=function(a,b){if(-1==b||void 0===b)b=gl.TRIANGLES;this.primitive=b;a!=this.mesh&&(this.mesh=a,this.vertex_buffers={});for(var c in a.vertexBuffers)this.vertex_buffers[c]=a.vertexBuffers[c];switch(b){case gl.TRIANGLES:this.index_buffer=a.indexBuffers.triangles;break;case gl.LINES:this.index_buffer=
  a.indexBuffers.lines;break;case 10:this.primitive=gl.LINES;a.indexBuffers.wireframe||a.computeWireframe();this.index_buffer=a.indexBuffers.wireframe;break;default:this.index_buffer=null}a.bounding?(this.oobb.set(a.bounding),this.flags&=-2049):this.flags|=2048};ba.prototype.setLODMesh=function(a){if(a){a!=this.lod_mesh&&(this.lod_mesh=a,this.lod_vertex_buffers={});for(var b in a.vertexBuffers)this.lod_vertex_buffers[b]=a.vertexBuffers[b];switch(this.primitive){case gl.TRIANGLES:this.lod_index_buffer=
  a.indexBuffers.triangles;break;case gl.LINES:this.lod_index_buffer=a.indexBuffers.lines;break;case 10:a.indexBuffers.wireframe||a.computeWireframe();this.lod_index_buffer=a.indexBuffers.wireframe;break;default:this.lod_index_buffer=null}}else this.lod_index_buffer=this.lod_vertex_buffers=this.lod_mesh=null};ba.prototype.setRange=function(a,b){this.range[0]=a;this.range[1]=b};ba.prototype.applyNodeFlags=function(){var a=this.node.flags;this.layers=this.node.layers;this.flags=!0==a.two_sided?this.flags&
  -2:this.flags|1;this.flags=!0==a.flip_normals?this.flags|2:this.flags&-3;this.flags=!1==a.depth_test?this.flags&-5:this.flags|4;this.flags=!1==a.depth_write?this.flags&-9:this.flags|8;this.flags=!1==a.cast_shadows?this.flags&-257:this.flags|256;this.flags=!1==a.receive_shadows?this.flags&-513:this.flags|512};ba.prototype.enableFlag=function(a){this.flags|=a};ba.prototype.disableFlag=function(a){this.flags&=~a};ba.prototype.isFlag=function(a){return this.flags&a};ba.prototype.updateAABB=function(){BBox.transformMat4(this.aabb,
  this.oobb,this.matrix)};ba.prototype.update=function(){this.node&&this.node.transform&&this.setMatrix(this.node.transform._global_matrix)};ba.prototype.render=function(a){this.lod_mesh&&0.1>this.oobb[12]/Math.max(0.1,this._dist)?a.drawBuffers(this.lod_vertex_buffers,this.lod_index_buffer,this.primitive):a.drawBuffers(this.vertex_buffers,this.index_buffer,this.primitive,this.range[0],this.range[1])};ba.prototype.computeShaderBlockFlags=function(){for(var a=0,b=0;b<this.shader_blocks.length;++b)a|=
  this.shader_blocks[b].block.flag_mask;return a};ba.prototype.overlapsSphere=function(a,b){return this.flags&2048?!0:geo.testSphereBBox(a,b,this.aabb)};ba.prototype.wasVisibleByCamera=function(a){return a?this._camera_visibility|1<<a._rendering_index?!0:!1:0!=this._camera_visibility};e.RenderInstance=ba;N.DEFAULT_PRECISION=0;N.LOW_PRECISION=1;N.MEDIUM_PRECISION=2;N.HIGH_PRECISION=3;N.DEFAULT_PRECISION_WEBGL_TYPE=GL.UNSIGNED_BYTE;N["@width"]={type:"number",step:1,precision:0};N["@height"]={type:"number",
  step:1,precision:0};N["@precision"]={widget:"combo",values:{"default":N.DEFAULT_PRECISION,low:N.LOW_PRECISION,medium:N.MEDIUM_PRECISION,high:N.HIGH_PRECISION}};N["@num_extra_textures"]={type:"number",step:1,min:0,max:4,precision:0};N["@name"]={type:"string"};N.prototype.clear=function(){if(this.name){for(var a=0;a<this._textures.length;++a)delete e.ResourcesManager.textures[this.name+(1<a?a:"")];this._depth_texture&&delete e.ResourcesManager.textures[this.name+"_depth"]}this._fbo=null;this._textures=
  [];this._depth_textures=this._color_texture=null};N.prototype.configure=function(a){this.width=a.width||0;this.height=a.height||0;this.precision=a.precision||0;this.filter_texture=!!a.filter_texture;this.adjust_aspect=!!a.adjust_aspect;this.use_depth_texture=!!a.use_depth_texture;this.num_extra_textures=a.num_extra_textures||0;this.name=a.name};N.prototype.serialize=function(){return{width:this.width,height:this.height,filter_texture:this.filter_texture,precision:this.precision,adjust_aspect:this.adjust_aspect,
  use_depth_texture:this.use_depth_texture,num_extra_textures:this.num_extra_textures,name:this.name}};N.prototype.prepare=function(a,b){var c=this.width,d=this.height;0==c?c=a:0>c&&(c=a>>Math.abs(this.width));0==d?d=b:0>d&&(d=b>>Math.abs(this.height));var f=gl.RGBA,e=this.filter_texture?gl.LINEAR:gl.NEAREST,h=0;switch(this.precision){case N.LOW_PRECISION:h=gl.UNSIGNED_BYTE;break;case N.MEDIUM_PRECISION:h=gl.HIGH_PRECISION_FORMAT;break;case N.HIGH_PRECISION:h=gl.FLOAT;break;default:h=N.DEFAULT_PRECISION_WEBGL_TYPE}var k=
  this._textures;this._color_texture&&this._color_texture.width==c&&this._color_texture.height==d&&this._color_texture.type==h?this._color_texture.setParameter(gl.TEXTURE_MAG_FILTER,e):this._color_texture=new GL.Texture(c,d,{minFilter:gl.LINEAR,magFilter:e,format:f,type:h});k[0]=this._color_texture;for(var m=Math.min(this.num_extra_textures,4),l=0;l<m;++l){var p=k[1+l];p&&p.width==c&&p.height==d&&p.type==h?p.setParameter(gl.TEXTURE_MAG_FILTER,e):p=new GL.Texture(c,d,{minFilter:gl.LINEAR,magFilter:e,
  format:f,type:h});k[1+l]=p}!this.use_depth_texture||this._depth_texture&&this._depth_texture.width==c&&this._depth_texture.height==d||!gl.extensions.WEBGL_depth_texture?this.use_depth_texture||(this._depth_texture=null):this._depth_texture=new GL.Texture(c,d,{filter:gl.NEAREST,format:gl.DEPTH_COMPONENT,type:gl.UNSIGNED_INT});this._depth_texture&&!this._depth_texture.near_far_planes&&(this._depth_texture.near_far_planes=vec2.create());this._fbo||(this._fbo=new GL.FBO);k.length=1+m;this._fbo.setTextures(k,
  this._depth_texture)};N.prototype.enable=function(a,b){var c=e.Renderer._current_camera;b=b||gl.viewport_data;this.prepare(b[2],b[3]);this.enableFBO();this._depth_texture&&c&&(this._depth_texture.near_far_planes[0]=c.near,this._depth_texture.near_far_planes[1]=c.far)};N.prototype.disable=function(){this.disableFBO()};N.prototype.getColorTexture=function(a){return this._textures[a||0]};N.prototype.getDepthTexture=function(){return this._depth_texture};N.prototype.enableFBO=function(){if(!this._fbo)throw"No FBO created in RenderFrameContext";
  this._fbo.bind(!0);for(var a=0;a<this._textures.length;++a)this._textures[a]._locked=!0;this._depth_texture&&(this._depth_texture._locked=!0);e.Renderer._full_viewport.set(gl.viewport_data);this._old_aspect=e.Renderer.global_aspect;this.adjust_aspect&&(e.Renderer.global_aspect=gl.canvas.width/gl.canvas.height/(this._color_texture.width/this._color_texture.height))};N.prototype.disableFBO=function(){this._fbo.unbind();e.Renderer._full_viewport.set(this._fbo._old_viewport);e.Renderer.global_aspect=
  this._old_aspect;for(var a=0;a<this._textures.length;++a)this._textures[a]._locked=!1;this._depth_texture&&(this._depth_texture._locked=!1);if(this.name){for(a=0;a<this._textures.length;++a){var b=this.name+(0<a?a:"");this._textures[a].filename=b;e.ResourcesManager.textures[b]=this._textures[a]}this._depth_texture&&(b=this.name+"_depth",this._depth_texture.filename=b,e.ResourcesManager.textures[b]=this._depth_texture)}};N.prototype.show=function(a){var b=this._color_texture;if(a){a=GL.Shader.getFXAAShader();
  var c=gl.getViewport(),d=GL.Mesh.getScreenQuad();b.bind(0);a.uniforms({u_texture:0,uViewportSize:c.subarray(2,4),u_iViewportSize:[1/b.width,1/b.height]}).draw(d)}else b.toViewport()};e.RenderFrameContext=N;var db={default_render_settings:new e.RenderSettings,default_material:new e.StandardMaterial,render_passes:{},renderPassFunction:null,global_aspect:1,default_point_size:1,_global_viewport:vec4.create(),_full_viewport:vec4.create(),_current_scene:null,_current_render_settings:null,_current_camera:null,
  _current_target:null,_current_pass:null,_main_camera:null,_visible_cameras:null,_visible_lights:null,_visible_instances:null,_near_lights:[],_active_samples:[],_rendercalls:0,_rendered_instances:0,_frame:0,_collect_frequency:1,_view_matrix:mat4.create(),_projection_matrix:mat4.create(),_viewprojection_matrix:mat4.create(),_2Dviewprojection_matrix:mat4.create(),_temp_matrix:mat4.create(),_identity_matrix:mat4.create(),_render_uniforms:{},_reflection_probes:[],SHADOWMAP_TEXTURE_SLOT:6,ENVIRONMENT_TEXTURE_SLOT:5,
  IRRADIANCE_TEXTURE_SLOT:4,LIGHTPROJECTOR_TEXTURE_SLOT:3,LIGHTEXTRA_TEXTURE_SLOT:2,BONES_TEXTURE_SLOT:3,MORPHS_TEXTURE_SLOT:2,MORPHS_TEXTURE2_SLOT:1,init:function(){this._missing_texture=new GL.Texture(1,1,{pixel_data:[128,128,128,255]});e.Draw.init();e.Draw.onRequestFrame=function(){e.GlobalScene.refresh()};Z.enableWebGLCanvas&&!gl.canvas.canvas2DtoWebGL_enabled&&Z.enableWebGLCanvas(gl.canvas);this.registerRenderPass("color",{id:1,render_instance:this.renderColorPassInstance});this.registerRenderPass("shadow",
  {id:2,render_instance:this.renderShadowPassInstance});this.registerRenderPass("picking",{id:3,render_instance:this.renderPickingPassInstance});var a=this._max_texture_units=gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);this.SHADOWMAP_TEXTURE_SLOT=a-2;this.ENVIRONMENT_TEXTURE_SLOT=a-3;this.IRRADIANCE_TEXTURE_SLOT=a-4;this.LIGHTPROJECTOR_TEXTURE_SLOT=a-5;this.LIGHTEXTRA_TEXTURE_SLOT=a-6;this.BONES_TEXTURE_SLOT=a-7;this.MORPHS_TEXTURE_SLOT=a-8;this.MORPHS_TEXTURE2_SLOT=a-9;this._active_samples.length=
  a},reset:function(){},setFullViewport:function(a,b,c,d){a.constructor===Number?(this._full_viewport[0]=a,this._full_viewport[1]=b,this._full_viewport[2]=c,this._full_viewport[3]=d):a.length&&this._full_viewport.set(a)},render:function(a,b,c){e.ShadersManager.ready&&(this._current_render_settings=b=b||this.default_render_settings,this._current_scene=a,this._main_camera=c?c[0]:null,a._frame+=1,this._frame+=1,a._must_redraw=!1,this._rendered_instances=this._rendercalls=0,b.keep_viewport?this.setFullViewport(gl.viewport_data):
  (gl.viewport(0,0,gl.drawingBufferWidth,gl.drawingBufferHeight),this.setFullViewport(0,0,gl.drawingBufferWidth,gl.drawingBufferHeight)),this._global_viewport.set(gl.viewport_data),LEvent.trigger(a,"beforeRender",b),a.triggerInNodes("beforeRender",b),this.processVisibleData(a,b,c),this._visible_cameras=c=c||this._visible_cameras,this._main_camera=c[0],LEvent.trigger(a,"renderShadows",b),a.triggerInNodes("renderShadows",b),a.triggerInNodes("afterVisibility",b),LEvent.trigger(a,"renderReflections",b),
  a.triggerInNodes("renderReflections",b),LEvent.trigger(a,"beforeRenderMainPass",b),a.triggerInNodes("beforeRenderMainPass",b),this.custom_renderer&&this.custom_renderer.render&&b.custom_renderer?this.custom_renderer.render(c,b):(b.render_fx&&LEvent.trigger(a,"enableFrameContext",b),this.renderFrameCameras(c,b),b.keep_viewport&&gl.setViewport(this._global_viewport),b.render_fx&&LEvent.trigger(a,"showFrameContext",b)),b.render_gui&&LEvent.trigger(a,"renderGUI",b),LEvent.trigger(a,"afterRender",b),a.triggerInNodes("afterRender",
  b))},renderFrameCameras:function(a,b){for(var c=this._current_scene,d=0;d<a.length;++d){var f=a[d];LEvent.trigger(c,"beforeRenderFrame",b);LEvent.trigger(f,"beforeRenderFrame",b);LEvent.trigger(f,"enableFrameContext",b);this.renderFrame(f,b);LEvent.trigger(f,"showFrameContext",b);LEvent.trigger(f,"afterRenderFrame",b);LEvent.trigger(c,"afterRenderFrame",b)}},renderFrame:function(a,b,c){c&&this.processVisibleData(c,b);c=c||this._current_scene;this.enableCamera(a,b,b.skip_viewport);this.sortRenderInstances(a,
  b);this.clearBuffer(a,b);LEvent.trigger(c,"beforeRenderScene",a);c.triggerInNodes("beforeRenderScene",a);LEvent.trigger(this,"beforeRenderScene",a);this.renderInstances(b);LEvent.trigger(c,"afterRenderScene",a);c.triggerInNodes("afterRenderScene",a);LEvent.trigger(this,"afterRenderScene",a);b.render_helpers&&LEvent.trigger(this,"renderHelpers",a)},enableCamera:function(a,b,c){var d=this._current_scene;LEvent.trigger(a,"beforeEnabled",b);LEvent.trigger(d,"beforeCameraEnabled",a);var f=this._full_viewport[2],
  e=this._full_viewport[3],h=Math.floor(f*a._viewport[0]+this._full_viewport[0]),k=Math.floor(e*a._viewport[1]+this._full_viewport[1]),m=Math.ceil(f*a._viewport[2]),l=Math.ceil(e*a._viewport[3]);c||(b&&b.ignore_viewports?(a.final_aspect=f/e*a._aspect*this.global_aspect,gl.viewport(this._full_viewport[0],this._full_viewport[1],this._full_viewport[2],this._full_viewport[3])):(a.final_aspect=m/l*a._aspect*this.global_aspect,gl.viewport(h,k,m,l)));a.updateMatrices();mat4.copy(this._view_matrix,a._view_matrix);
  mat4.copy(this._projection_matrix,a._projection_matrix);mat4.copy(this._viewprojection_matrix,a._viewprojection_matrix);mat4.ortho(this._2Dviewprojection_matrix,-1,1,-1,1,1,-1);this._current_camera=a;Fa.reset();Fa.setCameraPosition(a.getEye());Fa.setViewProjectionMatrix(this._view_matrix,this._projection_matrix,this._viewprojection_matrix);LEvent.trigger(a,"afterEnabled",b);LEvent.trigger(d,"afterCameraEnabled",a)},clearBuffer:function(a,b){b.ignore_clear||!a.clear_color&&!a.clear_depth||(gl.scissor(gl.viewport_data[0],
  gl.viewport_data[1],gl.viewport_data[2],gl.viewport_data[3]),gl.enable(gl.SCISSOR_TEST),gl.clearColor(a.background_color[0],a.background_color[1],a.background_color[2],a.background_color[3]),gl.clear((a.clear_color?gl.COLOR_BUFFER_BIT:0)|(a.clear_depth?gl.DEPTH_BUFFER_BIT:0)),gl.disable(gl.SCISSOR_TEST))},sortRenderInstances:function(a,b){if(b.sort_instances_by_distance||b.sort_instances_by_priority){for(var c=this._opaque_instances,d=this._blend_instances,f=this._visible_instances,e=a.getEye(),h=
  0,k=f.length;h<k;++h){var m=f[h];m&&(m._dist=vec3.dist(m.center,e))}b.sort_instances_by_distance&&(c.sort(this._sort_near_to_far_func),d.sort(this._sort_far_to_near_func));b.sort_instances_by_priority&&(c.sort(this._sort_by_priority_and_near_to_far_func),d.sort(this._sort_by_priority_and_far_to_near_func));this._visible_instances=c.concat(d)}},_sort_far_to_near_func:function(a,b){return b._dist-a._dist},_sort_near_to_far_func:function(a,b){return a._dist-b._dist},_sort_by_priority_func:function(a,
  b){return b.priority-a.priority},_sort_by_priority_and_near_to_far_func:function(a,b){var c=b.priority-a.priority;return c?c:a._dist-b._dist},_sort_by_priority_and_far_to_near_func:function(a,b){var c=b.priority-a.priority;return c?c:b._dist-a._dist},resetGLState:function(a){a=a||this._current_render_settings;gl.enable(gl.CULL_FACE);a.depth_test?gl.enable(gl.DEPTH_TEST):gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);gl.depthFunc(gl.LESS);gl.depthMask(!0);gl.frontFace(gl.CCW);gl.blendFunc(gl.SRC_ALPHA,
  gl.ONE_MINUS_SRC_ALPHA)},renderInstances:function(a,b){var c=this._current_scene;if(!c)return console.warn("LS.Renderer.renderInstances: no scene found"),0;var d=this._current_pass,f=this._current_camera,e=-1!=f._rendering_index?1<<f._rendering_index:0,h=a.frustum_culling,k=f.updateFrustumPlanes(),m=f.layers&a.layers;LEvent.trigger(c,"beforeRenderInstances",a);c.triggerInNodes("beforeRenderInstances",a);this.fillSceneShaderQuery(c,a);this.fillSceneShaderUniforms(c,a);this.resetGLState(a);f=b||this._visible_instances;
  LEvent.trigger(c,"renderInstances",a);LEvent.trigger(this,"renderInstances",a);this.resetGLState(a);var l=d.render_instance;if(!l)return 0;for(var p=0,n=f.length;p<n;++p){var q=f[p],r=q.node.flags;q._is_visible=!1;!(2!=d.id||q.flags&256)||3==d.id&&!1===r.selectable||0===(m&q.layers)||q.onPreRender&&!1===q.onPreRender(a)||0>=q.material.opacity||h&&!(q.flags&2048)&&geo.frustumTestBox(k,q.aabb)==CLIP_OUTSIDE||(q._is_visible=!0,e&&(q._camera_visibility|=e))}d=this._rendered_instances;p=0;for(n=f.length;p<
  n;++p)if(q=f[p],q._is_visible&&q.mesh&&(this._rendered_instances+=1,l.call(this,q,a),q.onPostRender))q.onPostRender(a);LEvent.trigger(c,"renderScreenSpace",a);this.resetGLState(a);LEvent.trigger(c,"afterRenderInstances",a);c.triggerInNodes("afterRenderInstances",a);this.resetGLState(a);return this._rendered_instances-d},getNearLights:function(a,b){b=b||[];b.length=0;var c=this._visible_lights;if(!c||!c.length)return b;b.length=0;for(var d=c.length,f=0;f<d;f++){var e=c[f];if(0!=(e._root.layers&a.layers)&&
  0!=(e._root.layers&this._current_camera.layers)&&!(1E-4>e.computeLightIntensity())){var h=e.computeLightRadius(),k=e.position;(-1==h||a.overlapsSphere(k,h))&&b.push(e)}}return b},renderColorPassInstance:function(a,b){var c=!1;a.material&&a.material.renderInstance&&(c=a.material.renderInstance(a,b));c||this.renderStandardColorMultiPassLightingInstance(a,b)},renderShadowPassInstance:function(a,b){var c=!1;a.material&&a.material.renderShadowInstance&&(c=a.material.renderShadowInstance(a,b));c||this.renderStandardShadowPassInstance(a,
  b)},renderStandardColorMultiPassLightingInstance:function(a,b){var c=this._current_camera,d=a.node,f=a.material,g=this._current_scene,h=this._render_uniforms,k=a._final_query,m=this.getNearLights(a,this._near_lights);h.u_model=a.matrix;h.u_normal_model=a.normal_matrix;this.enableInstanceFlags(a,b);f.blend_mode!==va.NORMAL?(gl.enable(gl.BLEND),a.blend_func&&gl.blendFunc(a.blend_func[0],a.blend_func[1])):gl.disable(gl.BLEND);var l=[];this.mergeSamplers([g._samplers,f._samplers,a.samplers],l);l.length&&
  this.bindSamplers(l);l=b.default_shader_id;b.low_quality&&(l=b.default_low_shader_id);f.shader_name&&(l=f.shader_name);var p=m.length,n=d.flags.ignore_lights||!!(a.flags&1024)||b.lights_disabled;if(!p||n){var q=new e.ShaderQuery(l,{FIRST_PASS:"",LAST_PASS:"",USE_AMBIENT_ONLY:""});q.add(g._query);q.add(c._query);q.add(k);n&&q.setMacro("USE_IGNORE_LIGHTS");!b.clipping_plane||a.flags&16384||q.setMacro("USE_CLIPPING_PLANE");if(f.onModifyQuery)f.onModifyQuery(q);q=Xa.resolve(q);q.uniformsArray([g._uniforms,
  c._uniforms,f._uniforms,h,a.uniforms]);a.flags&cb&&q.setUniform("u_viewprojection",mat4.IDENTITY);a.render(q);this._rendercalls+=1}else for(n=0;n<p;n++){var r=m[n],q=new e.ShaderQuery(l);q.add(g._query);var u=r.getQuery(a,b);0===n&&q.setMacro("FIRST_PASS");n===p-1&&q.setMacro("LAST_PASS");q.add(u);q.add(k);!b.clipping_plane||a.flags&16384||q.setMacro("USE_CLIPPING_PLANE");if(f.onModifyQuery)f.onModifyQuery(q);q=e.ShadersManager.resolve(q);r._samplers.length&&this.bindSamplers(r._samplers);0<n&&(gl.enable(gl.BLEND),
  gl.blendFunc(gl.SRC_ALPHA,gl.ONE),b.depth_test&&(gl.depthFunc(gl.LEQUAL),d.flags.depth_test?gl.enable(gl.DEPTH_TEST):gl.disable(gl.DEPTH_TEST)));f.depth_func&&gl.depthFunc(gl[f.depth_func]);q.uniformsArray([g._uniforms,c._uniforms,r._uniforms,f._uniforms,h,a.uniforms]);a.render(q);this._rendercalls+=1;if(q.global&&!q.global.multipass)break}},renderStandardShadowPassInstance:function(a,b){var c=this._current_scene,d=this._current_camera,f=a.material,c=this._current_scene,e=this._render_uniforms;e.u_model=
  a.matrix;e.u_normal_model=a.normal_matrix;var h=a._final_query;this.enableInstanceFlags(a,b);var k=new Ka("depth");k.add(c._query);k.add(h);h=Xa.resolve(k);k=[];this.mergeSamplers([f._samplers,a.samplers],k);this.bindSamplers(k);h.uniformsArray([c._uniforms,d._uniforms,e,f._uniforms,a.uniforms]);a.render(h);this._rendercalls+=1},renderPickingPassInstance:function(a,b){var c=this._current_scene,d=this._current_camera,f=a.node,g=a.material,h=this._render_uniforms;h.u_model=a.matrix;h.u_normal_model=
  a.normal_matrix;var f=e.Picking.getNextPickingColor(f),k=new e.ShaderQuery("flat");k.add(c._query);k.add(a._final_query);k=Xa.resolve(k);k.uniformsArray([c._uniforms,d._uniforms,g._uniforms,h,a.uniforms]);k.uniforms({u_material_color:f});a.render(k)},mergeSamplers:function(a,b){b=b||[];b.length=this._max_texture_units;for(var c=0;c<b.length;++c)for(var d=a.length-1;0<=d;--d)if(a[d][c]){b[c]=a[d][c];break}return b},clearSamplers:function(){for(var a=0;a<this._max_texture_units;++a)gl.activeTexture(gl.TEXTURE0+
  a),gl.bindTexture(gl.TEXTURE_2D,null),gl.bindTexture(gl.TEXTURE_CUBE_MAP,null),this._active_samples[a]=null},bindSamplers:function(a){if(a)for(var b=0;b<a.length;++b){var c=a[b];if(c){var d=null;if(c.constructor===String||c.constructor===GL.Texture)d=c,c=null;else if(c.texture)d=c.texture;else continue;d.constructor===String&&(d=e.ResourcesManager.textures[d]);d||(d=this._missing_texture);d._locked&&(d=this._missing_texture);d.bind(b);this._active_samples[b]=d;c&&(c.minFilter&&gl.texParameteri(d.texture_type,
  gl.TEXTURE_MIN_FILTER,c.minFilter),c.magFilter&&gl.texParameteri(d.texture_type,gl.TEXTURE_MAG_FILTER,c.magFilter),c.wrap&&(gl.texParameteri(d.texture_type,gl.TEXTURE_WRAP_S,c.wrap),gl.texParameteri(d.texture_type,gl.TEXTURE_WRAP_T,c.wrap)))}}},fillSceneShaderQuery:function(a,b){var c=new e.ShaderQuery;1==this._current_pass.id&&b.linear_pipeline&&c.setMacro("USE_LINEAR_PIPELINE");this._current_renderframe&&this._current_renderframe.use_extra_texture&&gl.extensions.WEBGL_draw_buffers&&c.setMacro("USE_DRAW_BUFFERS");
  LEvent.trigger(a,"fillSceneQuery",c);a._query=c},fillSceneShaderUniforms:function(a,b){var c={u_point_size:this.default_point_size,u_time:a._time||0.001*getTime(),u_ambient_light:a.info.ambient_color,u_viewport:gl.viewport_data};b.clipping_plane&&(c.u_clipping_plane=b.clipping_plane);1==this._current_pass.id&&b.linear_pipeline&&(c.u_gamma=2.2);a._uniforms=c;a._samplers=a._samplers||[];a._samplers.length=0;for(var d in a.info.textures)if(c=e.getTexture(a.info.textures[d])){var f=0;if("environment"==
  d)f=e.Renderer.ENVIRONMENT_TEXTURE_SLOT;else if("irradiance"==d)f=e.Renderer.IRRADIANCE_TEXTURE_SLOT;else continue;var g=c.texture_type==gl.TEXTURE_2D?"_texture":"_cubemap";c.texture_type==gl.TEXTURE_2D&&(c.bind(0),c.setParameter(gl.TEXTURE_MIN_FILTER,gl.LINEAR));a._samplers[f]=c;a._uniforms[d+g]=f;a._query.macros["USE_"+(d+g).toUpperCase()]="uvs_polar_reflected"}LEvent.trigger(a,"fillSceneUniforms",a._uniforms)},enableInstanceFlags:function(a,b){var c=a.flags;c&1?gl.enable(gl.CULL_FACE):gl.disable(gl.CULL_FACE);
  b.depth_test&&(gl.depthFunc(gl.LEQUAL),c&4?gl.enable(gl.DEPTH_TEST):gl.disable(gl.DEPTH_TEST),c&8?gl.depthMask(!0):gl.depthMask(!1));var d=gl.CCW;c&2&&(d=gl.CW);b.reverse_backfacing&&(d=d==gl.CW?gl.CCW:gl.CW);gl.frontFace(d)},processVisibleData:function(a,b,c){0==this._frame%this._collect_frequency?a.collectData():a.updateCollectedData();LEvent.trigger(a,"afterCollectData",a);c=c||a._cameras;for(var d=0,f=c.length;d<f;++d){var g=c[d];g._rendering_index=d;g.prepare()}this._main_camera||(this._main_camera=
  c.length?c[0]:new e.Camera);for(var h=[],k=[],m={},l=a._instances,g=this._main_camera,p=g.getEye(),d=0,f=l.length;d<f;++d)if(g=l[d])if(g.mesh){g.material||(g.material=this.default_material);m[g.material.uid]=g.material;g._dist=vec3.dist(g.center,p);b.force_wireframe&&g.primitive!=gl.LINES&&(g.primitive=gl.LINES,g.mesh&&(g.mesh.indexBuffers.wireframe||g.mesh.computeWireframe(),g.index_buffer=g.mesh.indexBuffers.wireframe));g.flags&Ya?k.push(g):h.push(g);var n=g.query;g.flags&16||g.material.alpha_test?
  n.macros.USE_ALPHA_TEST="0.5":n.macros.USE_ALPHA_TEST&&delete n.macros.USE_ALPHA_TEST;var q=g.vertex_buffers;"normals"in q||(n.macros.NO_NORMALS="");"coords"in q||(n.macros.NO_COORDS="");"coords1"in q&&(n.macros.USE_COORDS1_STREAM="");"colors"in q&&(n.macros.USE_COLOR_STREAM="");"tangents"in q&&(n.macros.USE_TANGENT_STREAM="");g._camera_visibility=0}else console.warn("RenderInstance must have mesh");b.update_materials&&this._prepareMaterials(m,a);d=0;for(f=l.length;d<f;++d)g=l[d],p=g.node,q=g.material,
  g.index=d,n=g._final_query,n.clear(),n.add(p._query),n.add(q._query),n.add(g.query);this._opaque_instances=h;this._blend_instances=k;this._visible_instances=this._opaque_instances.concat(this._blend_instances);this._visible_lights=a._lights;this._visible_cameras=c;this._visible_materials=m;d=0;for(f=this._visible_lights.length;d<f;++d)this._visible_lights[d].prepare(b)},_prepareMaterials:function(a,b){for(var c in a)a[c].prepareMaterial(b)},renderInstancesToRT:function(a,b,c){function d(){e.Renderer.clearBuffer(a,
  c);e.Renderer.renderInstances(c)}c=c||this.default_render_settings;this._current_target=b;b._locked=!0;b.texture_type==gl.TEXTURE_2D?(this.enableCamera(a,c),b.drawTo(d)):b.texture_type==gl.TEXTURE_CUBE_MAP&&this.renderToCubemap(a.getEye(),b.width,b,c,a.near,a.far);this._current_target=null;b._locked=!1},renderToCubemap:function(a,b,c,d,f,g,h){b=b||256;f=f||1;g=g||1E3;c&&c.constructor==GL.Texture||(c=null);var k=this._cubemap_camera;k||(k=this._cubemap_camera=new e.Camera);k.configure({fov:90,aspect:1,
  near:f,far:g});this._current_target=c=c||new GL.Texture(b,b,{texture_type:gl.TEXTURE_CUBE_MAP,minFilter:gl.NEAREST});c.drawTo(function(b,c){var f=e.Camera.cubemap_camera_parameters[c];b._is_shadowmap||!h?gl.clearColor(0,0,0,0):gl.clearColor(h[0],h[1],h[2],h[3]);gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT);k.configure({eye:a,center:[a[0]+f.dir[0],a[1]+f.dir[1],a[2]+f.dir[2]],up:f.up});e.Renderer.enableCamera(k,d,!0);e.Renderer.renderInstances(d)});this._current_target=null;return c},renderMaterialPreview:function(a,
  b,c){c=c||{};var d=this._material_scene;if(!d){d=this._material_scene=new e.SceneTree;d.root.camera.background_color.set([0,0,0,0]);c.environment_texture&&(d.info.textures.environment=c.environment_texture);var f=new e.SceneNode("sphere"),g=new e.Components.GeometricPrimitive({size:40,subdivisions:50,geometry:e.Components.GeometricPrimitive.SPHERE});f.addComponent(g);d.root.addChild(f)}c.background_color&&d.root.camera.background_color.set(c.background_color);f=d.getNode("sphere");if(!f)return console.error("Node not found in Material Preview Scene"),
  null;c.rotate&&f.transform.rotateY(c.rotate);f.material=a;if(c.to_viewport)e.Renderer.renderFrame(d.root.camera,{skip_viewport:!0,render_helpers:!1,update_materials:!0},d);else return a=this._material_preview_texture||new GL.Texture(b,b),this._material_preview_texture||(this._material_preview_texture=a),a.drawTo(function(){e.Renderer.renderFrame(d.root.camera,{skip_viewport:!0,render_helpers:!1},d)}),a.toCanvas(null,!0)},getCameraAtPosition:function(a,b,c){c=c||this._visible_cameras;if(!c||!c.length)return null;
  for(var d=c.length-1;0<=d;--d){var f=c[d];if(f.enabled&&!f.render_to_texture&&f.isPointInCamera(a,b))return f}return null},setRenderPass:function(a){this._current_pass=this.render_passes[a]||this.render_passes.color},registerRenderPass:function(a,b){b.name=a;this.render_passes[a]=b;this._current_pass||(this._current_pass=b)}};e.Renderer=db;Da.prototype.enable=function(a){LEvent.bind(a,"afterRenderInstances",this.onRender,this)};Da.prototype.disable=function(a){LEvent.unbind(a,"afterRenderInstances",
  this.onRender,this)};Da.prototype.onRender=function(a,b){this.render(e.Renderer._current_camera)};Da.prototype.render=function(a,b){var c=this.settings;gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA);gl.enable(gl.DEPTH_TEST);gl.disable(gl.BLEND);gl.disable(gl.CULL_FACE);gl.depthFunc(gl.LEQUAL);var d=null;c.render_grid&&0<c.grid_alpha&&this.renderGrid();c.render_origin&&(e.Draw.setColor([0.2,0.2,0.2,1]),e.Draw.push(),e.Draw.scale(0.01,0.01,0.01),e.Draw.renderText("Origin"),e.Draw.pop());if(c.render_components)for(var f=
  0,g=e.GlobalScene._nodes.length;f<g;++f){var h=e.GlobalScene._nodes[f],k=h._is_selected,d=h;h.renderEditor&&h.renderEditor(k);for(var m=0,l=h._components.length;m<l;++m){var p=h._components[m],n=!1;b&&(n=b(p));p.renderEditor&&p.renderEditor(k,n)}}k=vec3.create();f=0;for(g=e.GlobalScene._nodes.length;f<g;++f)h=e.GlobalScene._nodes[f],h.transform&&(m=h.transform.getGlobalMatrixRef(),l=mat4.multiplyVec3(vec3.create(),m,k),c.render_null_nodes&&(h._is_selected?this.renderPoint(l,!0,this.colors.selected):
  h._is_bone?this.renderPoint(l,!0,this.colors.bone):this.renderPoint(l,!1,this.colors.node)),c.render_names&&this.renderText(l,h.name,h._is_selected?[0.94,0.8,0.4,1]:[0.8,0.8,0.8,0.9]),h._parentNode&&h._parentNode.transform&&(c.render_tree||c.render_skeletons&&h._is_bone&&h._parentNode._is_bone)&&this.renderLine(l,h._parentNode.transform.getGlobalPosition(),this.colors.bone),c.render_axis&&(e.Draw.push(),e.Draw.multMatrix(m),e.Draw.setColor([1,1,1,1]),e.Draw.renderMesh(this.axis_mesh,gl.LINES),e.Draw.pop()));
  c.render_colliders&&this.renderColliders();c.render_paths&&this.renderPaths();this._points.length&&(e.Draw.setPointSize(4),e.Draw.setColor([1,1,1,1]),e.Draw.renderPoints(this._points,this._points_color),this._points.length=0,this._points_color.length=0);this._points_nodepth.length&&(e.Draw.setPointSize(4),e.Draw.setColor([1,1,1,1]),gl.disable(gl.DEPTH_TEST),e.Draw.renderPoints(this._points_nodepth,this._points_color_nodepth),gl.enable(gl.DEPTH_TEST),this._points_nodepth.length=0,this._points_color_nodepth.length=
  0);this._lines.length&&(gl.disable(gl.DEPTH_TEST),e.Draw.setColor([1,1,1,1]),e.Draw.renderLines(this._lines,this._lines_color),gl.enable(gl.DEPTH_TEST),this._lines.length=0,this._lines_color.length=0);this.debug_points.length&&(e.Draw.setPointSize(5),e.Draw.setColor([1,0,1,1]),e.Draw.renderPoints(this.debug_points));if(c.render_names&&gl.start2D){gl.disable(gl.DEPTH_TEST);f=this.camera2D;g=gl.getViewport();f.setOrthographic(0,g[2],0,g[3],-1,1);f.updateMatrices();gl.start2D();gl.font="14px Arial";
  h=vec4.fromValues(0,0,0,0.5);for(f=0;f<this._names.length;++f)k=a.project(this._names[f][1]),0>k[2]||(k[2]=0,m=gl.measureText(this._names[f][0]),gl.fillColor=h,gl.fillRect(Math.floor(k[0]+10),g[3]-Math.floor(k[1]+8),m.width,m.height),gl.fillColor=this._names[f][2],gl.fillText(this._names[f][0],Math.floor(k[0]+10),g[3]-Math.floor(k[1]-4)));gl.finish2D();this._names.length=0}c.render_axis&&d&&(e.Draw.push(),c=d.transform.getGlobalRotation(),c=mat4.fromQuat(mat4.create(),c),e.Draw.setMatrix(c),e.Draw.setColor([1,
  1,1,1]),e.Draw.scale(10,10,10),e.Draw.renderMesh(this.axis_mesh,gl.LINES),e.Draw.pop());gl.depthFunc(gl.LESS)};Da.prototype.renderPoint=function(a,b,c){c=c||[1,1,1,1];b?(this._points_nodepth.push(a[0],a[1],a[2]),this._points_color_nodepth.push(c[0],c[1],c[2],c[3])):(this._points.push(a[0],a[1],a[2]),this._points_color.push(c[0],c[1],c[2],c[3]))};Da.prototype.renderLine=function(a,b,c){c=c||[1,1,1,1];this._lines.push(a,b);this._lines_color.push(c,c)};Da.prototype.renderText=function(a,b,c){c=c||[1,
  1,1,1];this._names.push([b,a,c])};Da.prototype.renderGrid=function(){var a=this.settings;this.grid_shader||(this.grid_shader=e.Draw.createSurfaceShader("vec2 f = vec2(1.0/64.0,-1.0/64.0); float brightness = texture2D(u_texture, pos.xz + f).x * 0.6 + texture2D(u_texture, pos.xz * 0.1 + f ).x * 0.3 + texture2D(u_texture, pos.xz * 0.01 + f ).x * 0.2; brightness /= max(1.0,0.001 * length(u_camera_position.xz - pos.xz));return u_color * vec4(vec3(1.0),brightness);"),this.grid_shader_xy=e.Draw.createSurfaceShader("vec2 f = vec2(1.0/64.0,-1.0/64.0); float brightness = texture2D(u_texture, pos.xy + f).x * 0.6 + texture2D(u_texture, pos.xy * 0.1 + f ).x * 0.3 + texture2D(u_texture, pos.xy * 0.01 + f ).x * 0.2; brightness /= max(1.0,0.001 * length(u_camera_position.xy - pos.xy));return u_color * vec4(vec3(1.0),brightness);"),
  this.grid_shader_yz=e.Draw.createSurfaceShader("vec2 f = vec2(1.0/64.0,-1.0/64.0); float brightness = texture2D(u_texture, pos.yz + f).x * 0.6 + texture2D(u_texture, pos.yz * 0.1 + f ).x * 0.3 + texture2D(u_texture, pos.yz * 0.01 + f ).x * 0.2; brightness /= max(1.0,0.001 * length(u_camera_position.yz - pos.yz));return u_color * vec4(vec3(1.0),brightness);"),this.grid_shader.uniforms({u_texture:0}),this.grid_texture=this.grid_img&&this.grid_img.loaded?GL.Texture.fromImage(this.grid_img,{format:gl.RGB,
  wrap:gl.REPEAT,anisotropic:4,minFilter:gl.LINEAR_MIPMAP_LINEAR}):GL.Texture.fromURL(this.grid_texture_url,{format:gl.RGB,wrap:gl.REPEAT,anisotropic:4,minFilter:gl.LINEAR_MIPMAP_LINEAR}));e.Draw.push();"xy"==a.grid_plane?e.Draw.rotate(90,1,0,0):"yz"==a.grid_plane&&e.Draw.rotate(90,0,0,1);this.grid_texture&&!1!==this.grid_texture.ready?(gl.enable(gl.BLEND),this.grid_texture.bind(0),gl.depthMask(!1),e.Draw.setColor([1,1,1,this.settings.grid_alpha]),e.Draw.translate(e.Draw.camera_position[0],0,e.Draw.camera_position[2]),
  e.Draw.scale(1E4,1E4,1E4),e.Draw.renderMesh(this.plane_mesh,gl.TRIANGLES,"xy"==a.grid_plane?this.grid_shader_xy:this.grid_shader),gl.depthMask(!0)):(e.Draw.setColor([0.2,0.2,0.2,0.75]),e.Draw.scale(1,1,1),e.Draw.renderMesh(this.grid_mesh,gl.LINES),e.Draw.scale(10,10,10),e.Draw.renderMesh(this.grid_mesh,gl.LINES));e.Draw.pop()};Da.prototype.renderColliders=function(){var a=e.GlobalScene;if(a._colliders){e.Draw.setColor([0.33,0.71,0.71,0.5]);for(var b=0;b<a._colliders.length;++b){var c=a._colliders[b],
  d=c.oobb;if(this.settings.render_colliders_aabb){var f=c.aabb;e.Draw.push();var g=BBox.getCenter(f),f=BBox.getHalfsize(f);e.Draw.translate(g);e.Draw.renderWireBox(2*f[0],2*f[1],2*f[2]);e.Draw.pop()}e.Draw.push();e.Draw.multMatrix(c.matrix);f=BBox.getHalfsize(d);c.type==e.PhysicsInstance.BOX?(e.Draw.translate(BBox.getCenter(d)),e.Draw.renderWireBox(2*f[0],2*f[1],2*f[2])):c.type==e.PhysicsInstance.SPHERE?(e.Draw.translate(BBox.getCenter(d)),e.Draw.renderWireSphere(f[0],20)):c.type==e.PhysicsInstance.MESH&&
  (c=c.mesh)&&(c.indexBuffers.wireframe||c.computeWireframe(),e.Draw.renderMesh(c,gl.LINES,null,"wireframe"));e.Draw.pop()}}};Da.prototype.renderPaths=function(){var a=e.GlobalScene;if(a._paths){e.Draw.setColor([0.7,0.6,0.3,0.5]);for(var b=0;b<a._paths.length;++b){var c=a._paths[b].samplePoints(0);e.Draw.renderLines(c,null,!0)}}};Da.prototype.createMeshes=function(){this.plane_mesh=GL.Mesh.plane({xz:!0});for(var a=10,b=[],c=-10;10>=c;c++)b.push([c*a,0,10*a]),b.push([c*a,0,10*-a]),b.push([10*a,0,c*a]),
  b.push([10*-a,0,c*a]);this.grid_mesh=GL.Mesh.load({vertices:b});b=new Float32Array([-1,1,1,-1,1,-1,1,1,-1,1,1,1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1]);c=new Uint16Array([0,1,0,4,0,3,1,2,1,5,2,3,2,6,3,7,4,5,4,7,6,7,5,6]);this.box_mesh=GL.Mesh.load({vertices:b,lines:c});this.circle_mesh=GL.Mesh.circle({size:1,slices:50});this.circle_empty_mesh=GL.Mesh.circle({size:1,slices:50,empty:1});this.sphere_mesh=GL.Mesh.icosahedron({size:1,subdivisions:3});b=[];b.push([0.5*-a,0,0],[0.5*+a,0,0]);b.push([0,0.5*-a,0],
  [0,0.5*+a,0]);b.push([0,0,0.5*-a],[0,0,0.5*+a]);this.dummy_mesh=GL.Mesh.load({vertices:b});b=[];b.push([-1,1,1],[1,1,1],[-1,1,-1],[1,1,-1],[-1,-1,1],[1,-1,1],[-1,-1,-1],[1,-1,-1]);b.push([1,-1,1],[1,1,1],[1,-1,-1],[1,1,-1],[-1,-1,1],[-1,1,1],[-1,-1,-1],[-1,1,-1]);b.push([1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]);this.cube_mesh=GL.Mesh.load({vertices:b});for(c=1;0<=c;c-=0.02)a=2*(1-0.001/c)-1,b.push([-1,1,a],[1,1,a],[-1,-1,a],[1,-1,a]),b.push([1,-1,a],[1,1,a],[-1,
  -1,a],[-1,1,a]);this.frustum_mesh=GL.Mesh.load({vertices:b});this.cylinder_mesh=GL.Mesh.cylinder({radius:10,height:2});b=[];c=[];a=2;b.push([0,0,0],[0.5*+a,0,0]);c.push([1,0,0,1],[1,0,0,1]);b.push([0,0,0],[0,0.5*+a,0]);c.push([0,1,0,1],[0,1,0,1]);b.push([0,0,0],[0,0,0.5*+a]);c.push([0,0,1,1],[0,0,1,1]);this.axis_mesh=GL.Mesh.load({vertices:b,colors:c});b=[];b.push([0,0,0],[0,0.5*+a,0]);b.push([0,0.5*+a,0],[0.1*a,0.4*+a,0]);b.push([0,0.5*+a,0],[-0.1*a,0.4*+a,0]);this.top_line_mesh=GL.Mesh.load({vertices:b});
  b=[];b.push([0,0,0],[0,0,0.5*+a]);b.push([0,0,0.5*+a],[0,0.1*a,0.4*+a]);b.push([0,0,0.5*+a],[0,-0.1*a,0.4*+a]);this.front_line_mesh=GL.Mesh.load({vertices:b})};e.DebugRender=Da;eb.prototype.applyByCPU=function(a,b){};e.Deformer=eb;var Ma={picking_color_offset:10,getNodeAtCanvasPosition:function(a,b,c,d,f){return(a=this.getInstanceAtCanvasPosition(a,b,c,d,f))?a.constructor==e.SceneNode?a:a._root&&a._root.constructor==e.SceneNode?a._root:a.node?a.node:null:null},getInstanceAtCanvasPosition:function(a,
  b,c,d,f){f=f||e.GlobalScene;c||(c=e.Renderer.getCameraAtPosition(a,b,f._cameras));if(!c)return null;this._picking_nodes={};this.getPickingColorFromBuffer(f,c,a,b,d);this._picking_color[3]=0;a=(new Uint32Array(this._picking_color.buffer))[0];a=this._picking_nodes[a];this._picking_nodes={};return a},getNextPickingColor:function(a){this._picking_next_color_id+=this.picking_color_offset;var b=new Uint32Array(1);b[0]=this._picking_next_color_id;b=new Uint8Array(b.buffer);this._picking_nodes[this._picking_next_color_id]=
  a;return vec4.fromValues(b[0]/255,b[1]/255,b[2]/255,1)},_pickingMap:null,_picking_color:new Uint8Array(4),_picking_depth:0,_picking_next_color_id:0,_picking_nodes:{},_picking_render_settings:new La,getPickingColorFromBuffer:function(a,b,c,d,f){if(null==this._pickingMap||this._pickingMap.width!=gl.canvas.width||this._pickingMap.height!=gl.canvas.height)this._pickingMap=new GL.Texture(gl.canvas.width,gl.canvas.height,{format:gl.RGBA,filter:gl.NEAREST}),this._pickingFBO=new GL.FBO([this._pickingMap]);
  e.Renderer._current_target=this._pickingMap;this._pickingFBO.bind();gl.scissor(c-1,d-1,2,2);gl.enable(gl.SCISSOR_TEST);this.renderPickingBuffer(a,b,f,[c,d]);gl.readPixels(c,d,1,1,gl.RGBA,gl.UNSIGNED_BYTE,this._picking_color);gl.disable(gl.SCISSOR_TEST);this._pickingFBO.unbind();e.Renderer._current_target=null;return this._picking_color},renderPickingBuffer:function(a,b,c,d){void 0===c&&(c=65535);var f=this._picking_render_settings;e.Renderer.enableCamera(b,this._picking_render_settings);gl.clearColor(0,
  0,0,0);gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT);this._picking_next_color_id=0;e.Renderer.setRenderPass("picking");f.layers=c;e.Renderer.renderInstances(f);LEvent.trigger(a,"renderPicking",d);LEvent.trigger(e.Renderer,"renderPicking",d);e.Renderer.setRenderPass("color")}};e.Picking=Ma;ab.isCloser=function(a,b){return a.distance-b.distance};e.Collision=ab;Ca.BOX=1;Ca.SPHERE=2;Ca.PLANE=3;Ca.CAPSULE=4;Ca.MESH=5;Ca.FUNCTION=6;Ca.prototype.updateAABB=function(){BBox.transformMat4(this.aabb,this.oobb,
  this.matrix)};Ca.prototype.setMesh=function(a){this.mesh=a;this.type=Ca.MESH;BBox.setCenterHalfsize(this.oobb,BBox.getCenter(a.bounding),BBox.getHalfsize(a.bounding))};e.PhysicsInstance=Ca;e.Physics={raycast:function(a,b,c){c=c||{};if(!a||!b)throw"Physics.raycast: origin or direction missing.";var d=c.layers;void 0===d&&(d=65535);var f=c.max_distance||Number.MAX_VALUE,g=c.scene||e.GlobalScene,h=c.first_collision,g=c.colliders||g._colliders,k=[];c=!!c.normal;if(!g)return null;for(var m=vec3.create(),
  l=vec3.create(),p=0;p<g.length;++p){var n=g[p];if(0!==(d&n.layers)){var q=vec3.create(),r=null;if(geo.testRayBBox(a,b,n.aabb,null,q,f)){var u=n.matrix;if(n.type==Ca.SPHERE){if(!geo.testRaySphere(a,b,n.center,n.oobb[3],q,f))continue;c&&(r=vec3.sub(vec3.create(),q,n.center))}else{var t=mat4.invert(mat4.create(),u);mat4.multiplyVec3(m,t,a);mat4.rotateVec3(l,t,b);if(!geo.testRayBBox(m,l,n.oobb,null,q,f))continue;if(n.type==Ca.MESH){t=n.mesh.octree;t||(t=n.mesh.octree=new GL.Octree(n.mesh));t=t.testRay(m,
  l,0,f);if(!t)continue;mat4.multiplyVec3(q,u,t.pos);c&&(r=mat4.rotateVec3(vec3.create(),u,t.normal))}else vec3.transformMat4(q,q,u)}u=vec3.distance(a,q);k.push(new e.Collision(n.node,n,q,u,r));if(h)return k}}}k.sort(ab.isCloser);return k},testSphere:function(a,b,c){c=c||{};var d=c.layers;void 0===d&&(d=65535);var f=c.scene||e.GlobalScene;c=c.colliders||f._colliders;f=vec3.create();if(!c)return null;for(var g=0;g<c.length;++g){var h=c[g];if(0!==(d&h.layers)&&geo.testSphereBBox(a,b,h.aabb)){var k=h.matrix,
  k=mat4.invert(mat4.create(),k);mat4.multiplyVec3(f,k,a);if(h.type==e.PhysicsInstance.SPHERE){if(vec3.distance(a,f)>b+BBox.getRadius(h.oobb))continue}else{if(!geo.testSphereBBox(f,b,h.oobb))continue;if(h.type==e.PhysicsInstance.MESH&&(k=h.mesh.octree,k||(k=h.mesh.octree=new GL.Octree(h.mesh)),!k.testSphere(f,b)))continue}return h}}return null},testCollision:function(a,b){return geo.testBBoxBBox(a.aabb,b.aabb)?!0:!1},testAllCollisions:function(a,b,c){void 0===b&&(b=65535);c=c||e.GlobalScene;c=c._colliders;
  for(var d=c.length,f=!1,g=0;g<d;++g){var h=c[g];if(0!==(b&h.layers))for(var k=g+1;k<d;++k){var m=c[k];0!==(b&m.layers)&&this.testCollision(h,m)&&(a&&a(h,m),f=!0)}}return f},raycastRenderInstances:function(a,b,c){c=c||{};var d=c.layers;void 0===d&&(d=65535);var f=c.max_distance||Number.MAX_VALUE,g=!!c.triangle_collision,h=!!c.first_collision,k=!!c.normal,m=!!c.ignore_transparent;c=(c.scene||e.GlobalScene)._instances;if(!c||!c.length)return null;for(var l=[],p=vec3.create(),n=vec3.create(),q=0,r=c.length;q<
  r;++q){var u=c[q];if(u.flags&65536&&0!==(d&u.layers)&&!(u.flags&Ya&&m)){var t=vec3.create();if(geo.testRayBBox(a,b,u.aabb,null,t,f)){var za=u.matrix,s=mat4.invert(mat4.create(),za);mat4.multiplyVec3(p,s,a);mat4.rotateVec3(n,s,b);if(geo.testRayBBox(p,n,u.oobb,null,t,f)){var G=u.collision_mesh,s=null;g&&(G=u.lod_mesh||u.mesh);if(G){var E=G.octree;E||(E=G.octree=new GL.Octree(G));G=E.testRay(p,n,0,f);if(!G)continue;mat4.multiplyVec3(t,za,G.pos);k&&(s=mat4.rotateVec3(vec3.create(),za,G.normal))}else vec3.transformMat4(t,
  t,za);za=vec3.distance(a,t);za<f&&l.push(new e.Collision(u.node,u,t,za,s));if(h)return l}}}}l.sort(e.Collision.isCloser);return l}};w.temp_matrix=mat4.create();w.icon="mini-icon-gizmo.png";w.ZERO=vec3.create();w.UP=vec3.fromValues(0,1,0);w.RIGHT=vec3.fromValues(1,0,0);w.FRONT=vec3.fromValues(0,0,-1);w["@position"]={type:"position"};w["@rotation"]={type:"quat"};w.properties={position:"vec3",scaling:"vec3",rotation:"quat"};w.prototype.onAddedToNode=function(a){a.transform||(a.transform=this)};w.prototype.onRemovedFromNode=
  function(a){a.transform==this&&delete a.transform};Object.defineProperty(w.prototype,"position",{get:function(){return this._position},set:function(a){this._position.set(a);this._must_update_matrix=!0},enumerable:!0});Object.defineProperty(w.prototype,"x",{get:function(){return this._position[0]},set:function(a){this._position[0]=a;this._must_update_matrix=!0},enumerable:!1});Object.defineProperty(w.prototype,"y",{get:function(){return this._position[1]},set:function(a){this._position[1]=a;this._must_update_matrix=
  !0},enumerable:!1});Object.defineProperty(w.prototype,"z",{get:function(){return this._position[2]},set:function(a){this._position[2]=a;this._must_update_matrix=!0},enumerable:!1});Object.defineProperty(w.prototype,"rotation",{get:function(){return this._rotation},set:function(a){this._rotation.set(a);this._must_update_matrix=!0},enumerable:!0});Object.defineProperty(w.prototype,"scaling",{get:function(){return this._scaling},set:function(a){a.constructor===Number?this._scaling[0]=this._scaling[1]=
  this._scaling[2]=a:this._scaling.set(a);this._must_update_matrix=!0},enumerable:!0});Object.defineProperty(w.prototype,"matrix",{get:function(){this._must_update_matrix&&this.updateMatrix();return this._local_matrix},set:function(a){this.fromMatrix(a)},enumerable:!0});Object.defineProperty(w.prototype,"data",{get:function(){return this._data},set:function(a){this._data.set(a);this._must_update_matrix=!0},enumerable:!1});Object.defineProperty(w.prototype,"xrotation",{get:function(){return 0},set:function(a){this.rotateX(a*
  DEG2RAD)},enumerable:!1});Object.defineProperty(w.prototype,"yrotation",{get:function(){return 0},set:function(a){this.rotateY(a*DEG2RAD)},enumerable:!1});Object.defineProperty(w.prototype,"zrotation",{get:function(){return 0},set:function(a){this.rotateZ(a*DEG2RAD)},enumerable:!1});Object.defineProperty(w.prototype,"globalPosition",{get:function(){return this.getGlobalPosition()},set:function(a){},enumerable:!0});Object.defineProperty(w.prototype,"globalMatrix",{get:function(){this.updateGlobalMatrix();
  return this._global_matrix},set:function(a){},enumerable:!0});Object.defineProperty(w.prototype,"mustUpdate",{get:function(){return this._must_update_matrix},set:function(a){this._must_update_matrix=!0},enumerable:!1});w.prototype.getPropertiesInfo=function(a){return"output"==a?{position:"vec3",scaling:"vec3",rotation:"quat",matrix:"mat4",globalPosition:"vec3",globalMatrix:"mat4"}:{position:"vec3",scaling:"vec3",rotation:"quat",matrix:"mat4"}};w.prototype.copyFrom=function(a){this.configure(a.serialize())};
  w.prototype.configure=function(a){a.uid&&(this.uid=a.uid);a.position&&this._position.set(a.position);a.scaling&&this._scaling.set(a.scaling);a.rotation&&4==a.rotation.length&&this._rotation.set(a.rotation);if(a.rotation&&3==a.rotation.length){quat.identity(this._rotation);var b=quat.setAngleAxis(quat.create(),[1,0,0],a.rotation[0]*DEG2RAD);quat.multiply(this._rotation,this._rotation,b);quat.setAngleAxis(b,[0,1,0],a.rotation[1]*DEG2RAD);quat.multiply(this._rotation,this._rotation,b);quat.setAngleAxis(b,
  [0,0,1],a.rotation[2]*DEG2RAD);quat.multiply(this._rotation,this._rotation,b)}this._must_update_matrix=!0;this.updateGlobalMatrix();this._on_change()};w.prototype.serialize=function(){return{uid:this.uid,position:[this._position[0],this._position[1],this._position[2]],rotation:[this._rotation[0],this._rotation[1],this._rotation[2],this._rotation[3]],scaling:[this._scaling[0],this._scaling[1],this._scaling[2]],matrix:Array.apply([],this._local_matrix)}};w.prototype.identity=function(){vec3.copy(this._position,
  e.ZEROS);quat.identity(this._rotation);vec3.copy(this._scaling,e.ONES);mat4.identity(this._local_matrix);mat4.identity(this._global_matrix);this._version+=1;this._must_update_matrix=!1};w.prototype.reset=w.prototype.identity;w.prototype.resetRotation=function(){quat.identity(this._rotation);this._version+=1;this._must_update_matrix=!0};w.prototype.resetPosition=function(){vec3.copy(this._position,e.ZEROS);this._version+=1;this._must_update_matrix=!0};w.prototype.resetScale=function(){vec3.copy(this._scaling,
  e.ONES);this._version+=1;this._must_update_matrix=!0};w.prototype.getPosition=function(a){a=a||vec3.create();a.set(this._position);return a};w.prototype.getGlobalPosition=function(a){a=a||vec3.create();return this._parent?mat4.multiplyVec3(a,this.getGlobalMatrix(),w.ZERO):vec3.copy(a,this._position)};w.prototype.getRotation=function(a){a=a||quat.create();return vec3.copy(a,this._rotation)};w.prototype.getGlobalRotation=function(a){a=a||quat.create();if(!this._parent)return quat.copy(a,this._rotation),
  a;var b=this._parent;for(quat.copy(a,this._rotation);b;)quat.multiply(a,b._rotation,a),b=b._parent;return a};w.prototype.getScale=function(a){a=a||vec3.create();return vec3.copy(a,this._scaling)};w.prototype.getGlobalScale=function(a){a=a||vec3.create();if(this._parent){var b=this;for(vec3.copy(a,this._scaling);b._parent;)vec3.multiply(a,a,b._scaling),b=b._parent;return a}return vec3.copy(a,this._scaling)};w.prototype.updateMatrix=function(){mat4.fromRotationTranslation(this._local_matrix,this._rotation,
  this._position);mat4.scale(this._local_matrix,this._local_matrix,this._scaling);this._must_update_matrix=!1;this._version+=1;this.updateDescendants()};w.prototype.updateLocalMatrix=w.prototype.updateMatrix;w.prototype.updateGlobalMatrix=function(a){this._must_update_matrix&&this.updateMatrix();this._parent?mat4.multiply(this._global_matrix,a?this._parent._global_matrix:this._parent.getGlobalMatrix(this._parent._global_matrix),this._local_matrix):this._global_matrix.set(this._local_matrix)};w.prototype.getMatrix=
  function(a){a=a||mat4.create();this._must_update_matrix&&this.updateMatrix();return mat4.copy(a,this._local_matrix)};w.prototype.getLocalMatrix=w.prototype.getMatrix;w.prototype.getLocalMatrixRef=function(){this._must_update_matrix&&this.updateMatrix();return this._local_matrix};w.prototype.getGlobalMatrix=function(a,b){this._must_update_matrix&&this.updateMatrix();a=a||mat4.create();this._parent?mat4.multiply(this._global_matrix,b?this._parent._global_matrix:this._parent.getGlobalMatrix(this._parent._global_matrix),
  this._local_matrix):mat4.copy(this._global_matrix,this._local_matrix);return mat4.copy(a,this._global_matrix)};w.prototype.getGlobalMatrixRef=function(){this.updateGlobalMatrix();return this._global_matrix};w.prototype.getAncestors=function(){for(var a=[this],b=this;b=b._parent;)a.unshift(b);return a};w.prototype.getGlobalTranslationMatrix=function(){var a=this.getGlobalPosition();return mat4.fromValues(1,0,0,0,0,1,0,0,0,0,1,0,a[0],a[1],a[2],1)};w.prototype.getGlobalRotationMatrix=function(a){a=a||
  mat4.create();if(!this._parent)return mat4.fromQuat(a,this._rotation);for(var b=mat4.create(),c=this;c;)mat4.fromQuat(b,c._rotation),mat4.multiply(a,a,b),c=c._parent;return a};w.prototype.getGlobalTranslationRotationMatrix=function(){var a=this.getGlobalPosition();return mat4.fromRotationTranslation(mat4.create(),this.getGlobalRotation(),a)};w.prototype.getGlobalMatrixWithoutScale=w.prototype.getGlobalTranslationRotationMatrix;w.prototype.getNormalMatrix=function(a){this._must_update_matrix&&this.updateMatrix();
  a=a||mat4.create();this._parent?mat4.multiply(this._global_matrix,this._parent.getGlobalMatrix(),this._local_matrix):a.set(this._local_matrix);return mat4.transpose(a,mat4.invert(a,a))};w.prototype.fromMatrix=function(){var a=mat4.create(),b=mat4.create(),c=mat3.create(),d=vec3.create();return function(f,g){if(g&&this._parent){mat4.copy(this._global_matrix,f);var h=this._parent.getGlobalMatrix(a);mat4.invert(h,h);f=mat4.multiply(this._local_matrix,h,f)}b.set(f);mat4.multiplyVec3(this._position,b,
  e.ZEROS);this._scaling[0]=vec3.length(mat4.rotateVec3(d,b,e.RIGHT));this._scaling[1]=vec3.length(mat4.rotateVec3(d,b,e.TOP));this._scaling[2]=vec3.length(mat4.rotateVec3(d,b,e.BACK));vec3.normalize(b.subarray(0,3),b.subarray(0,3));vec3.normalize(b.subarray(4,7),b.subarray(4,7));vec3.normalize(b.subarray(8,11),b.subarray(8,11));h=mat3.fromMat4(c,b);mat3.transpose(h,h);quat.fromMat3(this._rotation,h);quat.normalize(this._rotation,this._rotation);f!=this._local_matrix&&mat4.copy(this._local_matrix,f);
  this._must_update_matrix=!1;this._version+=1;this._on_change(!0)}}();w.fromMatrix4ToTransformData=function(){mat4.create();var a=mat4.create(),b=mat3.create(),c=vec3.create();return function(d,f){var g=f||new Float32Array(10),h=g.subarray(0,3),k=g.subarray(3,7);quat.identity(k);var m=g.subarray(7,10);a.set(d);mat4.multiplyVec3(h,a,e.ZEROS);m[0]=vec3.length(mat4.rotateVec3(c,a,e.RIGHT));m[1]=vec3.length(mat4.rotateVec3(c,a,e.TOP));m[2]=vec3.length(mat4.rotateVec3(c,a,e.BACK));vec3.normalize(a.subarray(0,
  3),a.subarray(0,3));vec3.normalize(a.subarray(4,7),a.subarray(4,7));vec3.normalize(a.subarray(8,11),a.subarray(8,11));h=mat3.fromMat4(b,a);mat3.transpose(h,h);quat.fromMat3(k,h);quat.normalize(k,k);return g}}();w.prototype.setRotationFromEuler=function(a){quat.fromEuler(this._rotation,a);this._must_update_matrix=!0;this._on_change()};w.prototype.setPosition=function(a,b,c){3==arguments.length?vec3.set(this._position,a,b,c):vec3.copy(this._position,a);this._must_update_matrix=!0;this._on_change()};
  w.prototype.setRotation=function(a,b){b?quat.setAxisAngle(this._rotation,b,a):quat.copy(this._rotation,a);this._must_update_matrix=!0;this._on_change()};w.prototype.setScale=function(a,b,c){3==arguments.length?vec3.set(this._scaling,a,b,c):vec3.set(this._scaling,a,a,a);this._must_update_matrix=!0;this._on_change()};w.prototype.translate=function(a,b,c){3==arguments.length?vec3.add(this._position,this._position,this.transformVector([a,b,c])):vec3.add(this._position,this._position,this.transformVector(a));
  this._must_update_matrix=!0;this._on_change()};w.prototype.translateGlobal=function(a,b,c){3==arguments.length?vec3.add(this._position,this._position,[a,b,c]):vec3.add(this._position,this._position,a);this._must_update_matrix=!0;this._on_change()};w.prototype.rotate=function(){var a=quat.create();return function(b,c){quat.setAxisAngle(a,c,0.0174532925*b);quat.multiply(this._rotation,this._rotation,a);this._must_update_matrix=!0;this._on_change()}}();w.prototype.rotateX=function(a){quat.rotateX(this._rotation,
  this._rotation,0.0174532925*a);this._must_update_matrix=!0;this._on_change()};w.prototype.rotateY=function(a){quat.rotateY(this._rotation,this._rotation,0.0174532925*a);this._must_update_matrix=!0;this._on_change()};w.prototype.rotateZ=function(a){quat.rotateZ(this._rotation,this._rotation,0.0174532925*a);this._must_update_matrix=!0;this._on_change()};w.prototype.rotateGlobal=function(a,b){var c=quat.setAxisAngle(quat.create(),b,0.0174532925*a);quat.multiply(this._rotation,c,this._rotation);this._must_update_matrix=
  !0;this._on_change()};w.prototype.rotateQuat=function(a){quat.multiply(this._rotation,this._rotation,a);this._must_update_matrix=!0;this._on_change()};w.prototype.rotateQuatGlobal=function(a){quat.multiply(this._rotation,a,this._rotation);this._must_update_matrix=!0;this._on_change()};w.prototype.scale=function(a,b,c){3==arguments.length?vec3.multiply(this._scaling,this._scaling,[a,b,c]):vec3.multiply(this._scaling,this._scaling,a);this._must_update_matrix=!0;this._on_change()};w.interpolate=function(a,
  b,c,d){vec3.lerp(d._scaling,a._scaling,b._scaling,c);vec3.lerp(d._position,a._position,b._position,c);quat.slerp(d._rotation,a._rotation,b._rotation,c);this._must_update_matrix=!0;this._on_change()};w.prototype.orbit=function(){var a=quat.create(),b=vec3.create();return function(c,d,f){if(!f)throw"Transform orbit requires a center";c=quat.setAxisAngle(a,d,0.0174532925*c);b.set(this._position);vec3.sub(b,b,f);vec3.transformQuat(b,b,c);vec3.add(b,b,f);this._position.set(b);this._must_update_matrix=
  !0}}();w.prototype.lookAt=function(){var a=mat4.create(),b=mat4.create(),c=vec3.create(),d=vec3.create(),f=vec3.create();return function(g,h,k,m){k=k||e.TOP;m&&this._parent?(this._parent.getGlobalMatrix(a),m=mat4.invert(a,a),mat4.multiplyVec3(c,m,g),mat4.multiplyVec3(d,m,h),mat4.rotateVec3(f,m,k)):(c.set(g),d.set(h),f.set(k));mat4.lookAt(b,c,d,f);quat.fromMat4(this._rotation,b);this._position.set(c);this._must_update_matrix=!0}}();w.prototype._on_change=function(a){a||(this._must_update_matrix=!0);
  LEvent.trigger(this,"changed",this);this._root&&LEvent.trigger(this._root,"transformChanged",this)};w.prototype.getFront=function(a){return vec3.transformQuat(a||vec3.create(),w.FRONT,this.getGlobalRotation())};w.prototype.getTop=function(a){return vec3.transformQuat(a||vec3.create(),w.UP,this.getGlobalRotation())};w.prototype.getRight=function(a){return vec3.transformQuat(a||vec3.create(),w.RIGHT,this.getGlobalRotation())};w.prototype.transformPoint=function(a,b){b=b||vec3.create();this._must_update_matrix&&
  this.updateMatrix();return mat4.multiplyVec3(b,this._local_matrix,a)};w.prototype.transformPointGlobal=function(a,b){b=b||vec3.create();this._must_update_matrix&&this.updateMatrix();return mat4.multiplyVec3(b,this.getGlobalMatrixRef(),a)};w.prototype.localToGlobal=w.prototype.transformPointGlobal;w.prototype.globalToLocal=function(){var a=mat4.create();return function(b,c){c=c||vec3.create();this._must_update_matrix&&this.updateMatrix();mat4.invert(a,this.getGlobalMatrixRef());return mat4.multiplyVec3(c,
  a,b)}}();w.prototype.transformVector=function(a,b){return vec3.transformQuat(b||vec3.create(),a,this._rotation)};w.prototype.transformVectorGlobal=function(a,b){return vec3.transformQuat(b||vec3.create(),a,this.getGlobalRotation())};w.prototype.localVectorToGlobal=w.prototype.transformVectorGlobal;w.prototype.globalVectorToLocal=function(a,b){var c=this.getGlobalRotation();quat.invert(c,c);return vec3.transformQuat(b||vec3.create(),a,c)};w.prototype.applyTransform=function(a,b,c){vec3.add(this._position,
  this._position,a._position);quat.multiply(this._rotation,this._rotation,a._rotation);vec3.multiply(this._scaling,this._scaling,a._scaling);this._must_update_matrix=!0};w.prototype.applyTransformMatrix=function(){var a=mat4.create(),b=vec3.create(),c=mat4.create();mat4.create();var d=mat4.create();return function(f,e,h){e&&(mat4.setTranslation(a,e),vec3.scale(b,e,-1),mat4.setTranslation(c,b),mat4.multiply(f,a,f),mat4.multiply(f,f,c));this._parent?(e=this.getGlobalMatrix(),h=this._parent._global_matrix,
  mat4.multiply(this._global_matrix,f,e),mat4.invert(d,h),mat4.multiply(this._local_matrix,d,this._global_matrix),this.fromMatrix(this._local_matrix)):this.applyLocalTransformMatrix(f)}}();w.prototype.applyLocalTransformMatrix=function(a){var b=vec3.create();vec3.transformMat4(this._position,this._position,a);mat4.rotateVec3(b,a,[1,0,0]);this._scaling[0]*=vec3.length(b);mat4.rotateVec3(b,a,[0,1,0]);this._scaling[1]*=vec3.length(b);mat4.rotateVec3(b,a,[0,0,1]);this._scaling[2]*=vec3.length(b);a=mat4.invert(mat4.create(),
  a);mat4.transpose(a,a);a=mat3.fromMat4(mat3.create(),a);a=quat.fromMat3(quat.create(),a);quat.normalize(a,a);quat.multiply(this._rotation,a,this._rotation);this._must_update_matrix=!0};w.prototype.updateDescendants=function(){if(this._root){var a=this._root._children;if(a)for(var b=0;b<a.length;++b){var c=a[b];c.transform&&(c.transform._must_update_matrix=!0,c.transform._version+=1,c._children&&c._children.length&&c.transform.updateDescendants())}}};e.registerComponent(w);e.Transform=w;y.icon="mini-icon-camera.png";
  y.PERSPECTIVE=1;y.ORTHOGRAPHIC=2;y.ORTHO2D=3;y["@type"]={type:"enum",values:{perspective:y.PERSPECTIVE,orthographic:y.ORTHOGRAPHIC,ortho2D:y.ORTHO2D}};y["@eye"]={type:"vec3",widget:"position"};y["@center"]={type:"vec3",widget:"position"};y["@layers"]={type:"layers"};y.cubemap_camera_parameters=[{name:"posx",dir:vec3.fromValues(1,0,0),up:vec3.fromValues(0,-1,0),crossx:2,crossy:1},{name:"negx",dir:vec3.fromValues(-1,0,0),up:vec3.fromValues(0,-1,0),crossx:0,crossy:1},{name:"posy",dir:vec3.fromValues(0,
  1,0),up:vec3.fromValues(0,0,1),crossx:1,crossy:0},{name:"negy",dir:vec3.fromValues(0,-1,0),up:vec3.fromValues(0,0,-1),crossx:1,crossy:2},{name:"posz",dir:vec3.fromValues(0,0,1),up:vec3.fromValues(0,-1,0),crossx:1,crossy:1},{name:"negz",dir:vec3.fromValues(0,0,-1),up:vec3.fromValues(0,-1,0),crossx:3,crossy:1}];y.prototype.getResources=function(a){return a};Object.defineProperty(y.prototype,"type",{get:function(){return this._type},set:function(a){this._type!=a&&(this._must_update_projection_matrix=
  this._must_update_view_matrix=!0);this._type=a},enumerable:!0});Object.defineProperty(y.prototype,"eye",{get:function(){return this._eye},set:function(a){this._eye.set(a);this._must_update_view_matrix=!0},enumerable:!0});Object.defineProperty(y.prototype,"center",{get:function(){return this._center},set:function(a){this._center.set(a);this._must_update_view_matrix=!0},enumerable:!0});Object.defineProperty(y.prototype,"focalLength",{get:function(){return vec3.distance(this._eye,this._center)},set:function(a){var b=
  vec3.create();vec3.sub(b,this._center,this._eye);vec3.normalize(b,b);vec3.scaleAndAdd(b,this._eye,b,a);this._center.set(b);this._must_update_view_matrix=!0},enumerable:!0});Object.defineProperty(y.prototype,"up",{get:function(){return this._up},set:function(a){this._up.set(a);this._must_update_view_matrix=!0},enumerable:!0});Object.defineProperty(y.prototype,"near",{get:function(){return this._near},set:function(a){this._near!=a&&(this._must_update_projection_matrix=!0);this._near=a},enumerable:!0});
  Object.defineProperty(y.prototype,"far",{get:function(){return this._far},set:function(a){this._far!=a&&(this._must_update_projection_matrix=!0);this._far=a},enumerable:!0});Object.defineProperty(y.prototype,"aspect",{get:function(){return this._aspect},set:function(a){this._aspect!=a&&(this._must_update_projection_matrix=!0);this._aspect=a},enumerable:!0});Object.defineProperty(y.prototype,"final_aspect",{get:function(){return this._final_aspect},set:function(a){this._final_aspect!=a&&(this._must_update_projection_matrix=
  !0);this._final_aspect=a},enumerable:!1});Object.defineProperty(y.prototype,"fov",{get:function(){return this._fov},set:function(a){this._fov!=a&&(this._must_update_projection_matrix=!0);this._fov=a},enumerable:!0});Object.defineProperty(y.prototype,"frustum_size",{get:function(){return this._frustum_size},set:function(a){this._frustum_size!=a&&(this._must_update_projection_matrix=!0,this._frustum_size=a)},enumerable:!0});Object.defineProperty(y.prototype,"viewport",{get:function(){return this._viewport},
  set:function(a){this._viewport.set(a)},enumerable:!0});Object.defineProperty(y.prototype,"viewport_offset",{get:function(){return this._viewport.subarray(0,2)},set:function(a){this._viewport.set(a)},enumerable:!0});Object.defineProperty(y.prototype,"viewport_size",{get:function(){return this._viewport.subarray(2,4)},set:function(a){this._viewport.set(a,2)},enumerable:!0});Object.defineProperty(y.prototype,"background_color",{get:function(){return this._background_color},set:function(a){this._background_color.set(a)},
  enumerable:!0});Object.defineProperty(y.prototype,"render_to_texture",{get:function(){return!!this._frame},set:function(a){a?this._frame||(this._frame=new e.RenderFrameContext):this._frame=null},enumerable:!0});Object.defineProperty(y.prototype,"mustUpdate",{get:function(){return this._must_update_projection_matrix||this._must_update_view_matrix},set:function(a){this._must_update_projection_matrix=this._must_update_view_matrix=a},enumerable:!0});y.prototype.onAddedToNode=function(a){a.camera||(a.camera=
  this)};y.prototype.onRemovedFromNode=function(a){a.camera==this&&delete a.camera};y.prototype.onAddedToScene=function(a){LEvent.bind(a,"collectCameras",this.onCollectCameras,this)};y.prototype.onRemovedFromScene=function(a){LEvent.unbind(a,"collectCameras",this.onCollectCameras,this);this._frame&&this._frame.clear();this._binded_render_frame&&(LEvent.unbind(this,"enableFrameContext",this.enableRenderFrameContext,this),LEvent.unbind(this,"showFrameContext",this.disableRenderFrameContext,this),this._binded_render_frame=
  !1)};y.prototype.isRenderedToTexture=function(){return this.enabled&&this.render_to_texture};y.prototype.onCollectCameras=function(a,b){this.enabled&&(this.isRenderedToTexture()?b.unshift(this):b.push(this),this._frame?this._binded_render_frame||(LEvent.bind(this,"enableFrameContext",this.enableRenderFrameContext,this),LEvent.bind(this,"showFrameContext",this.disableRenderFrameContext,this),this._binded_render_frame=!0):this._binded_render_frame&&(LEvent.unbind(this,"enableFrameContext",this.enableRenderFrameContext,
  this),LEvent.unbind(this,"showFrameContext",this.disableRenderFrameContext,this),this._binded_render_frame=!1))};y.prototype.lookAt=function(a,b,c){this._root&&this._root.transform?(this._root.transform.lookAt(a,b,c),this._eye.set(e.ZEROS),this.focalLength=vec3.distance(a,b)):(vec3.copy(this._eye,a),vec3.copy(this._center,b),vec3.copy(this._up,c));this._must_update_view_matrix=!0};y.prototype.updateMatrices=function(a){this._must_update_view_matrix=this._must_update_view_matrix||this._root&&!this._root._is_root;
  if(this._must_update_projection_matrix||this._must_update_view_matrix||a){if(this._must_update_projection_matrix||a)this.type==y.ORTHOGRAPHIC?mat4.ortho(this._projection_matrix,-this._frustum_size*this._final_aspect*0.5,this._frustum_size*this._final_aspect*0.5,0.5*-this._frustum_size,0.5*this._frustum_size,this._near,this._far):this.type==y.ORTHO2D?mat4.ortho(this._projection_matrix,this._ortho[0],this._ortho[1],this._ortho[2],this._ortho[3],this._near,this._far):mat4.perspective(this._projection_matrix,
  this._fov*DEG2RAD,this._final_aspect,this._near,this._far);if(this._must_update_view_matrix||a)this._root&&this._root._is_root?mat4.lookAt(this._view_matrix,this._eye,this._center,this._up):mat4.lookAt(this._view_matrix,this.getEye(this._global_eye),this.getCenter(this._global_center),this.getUp(this._global_up)),mat4.invert(this._model_matrix,this._view_matrix);mat4.multiply(this._viewprojection_matrix,this._projection_matrix,this._view_matrix);this._must_update_projection_matrix=this._must_update_view_matrix=
  !1}};y.prototype.updateFrustumPlanes=function(){geo.extractPlanes(this._viewprojection_matrix,this._frustum_planes);return this._frustum_planes};y.prototype.getModelMatrix=function(a){a=a||mat4.create();this._must_update_view_matrix&&this.updateMatrices();return mat4.copy(a,this._model_matrix)};y.prototype.getViewMatrix=function(a){a=a||mat4.create();this._must_update_view_matrix&&this.updateMatrices();return mat4.copy(a,this._view_matrix)};y.prototype.getProjectionMatrix=function(a){a=a||mat4.create();
  this._must_update_projection_matrix&&this.updateMatrices();return mat4.copy(a,this._projection_matrix)};y.prototype.getViewProjectionMatrix=function(a){a=a||mat4.create();(this._must_update_view_matrix||this._must_update_projection_matrix)&&this.updateMatrices();return mat4.copy(a,this._viewprojection_matrix)};y.prototype.getModelViewProjectionMatrix=function(a,b){b=b||mat4.create();(this._must_update_view_matrix||this._must_update_projection_matrix)&&this.updateMatrices();return mat4.multiply(b,
  this._viewprojection_matrix,a)};y.prototype.updateVectors=function(a){var b=vec3.subtract(vec3.create(),this._center,this._eye),b=vec3.length(b);this._eye=mat4.multiplyVec3(vec3.create(),a,vec3.create());this._center=mat4.multiplyVec3(vec3.create(),a,vec3.fromValues(0,0,-b));this._up=mat4.rotateVec3(vec3.create(),a,vec3.fromValues(0,1,0));this.updateMatrices()};y.prototype.getLocalPoint=function(a,b){b=b||vec3.create();if(this._root&&this._root.transform)return mat4.multiplyVec3(b,this._root.transform.getGlobalMatrixRef(),
  a);this._must_update_view_matrix&&this.updateMatrices();return mat4.multiplyVec3(b,this._model_matrix,a)};y.prototype.getLocalVector=function(a,b){b=b||vec3.create();if(this._root&&this._root.transform)return mat4.rotateVec3(b,this._root.transform.getGlobalMatrixRef(),a);this._must_update_view_matrix&&this.updateMatrices();return mat4.rotateVec3(b,this._model_matrix,a)};y.prototype.getEye=function(a){a=a||vec3.create();a.set(this._eye);return this._root&&this._root.transform?this._root.transform.getGlobalPosition(a):
  a};y.prototype.getCenter=function(a){a=a||vec3.create();if(this._root&&this._root.transform)return mat4.multiplyVec3(a,this._root.transform.getGlobalMatrixRef(),this._center);a.set(this._center);return a};y.prototype.getFront=function(a){a=a||vec3.create();if(this._root&&this._root.transform)return a[0]=a[1]=0,a[2]=-1,mat4.rotateVec3(a,this._root.transform.getGlobalMatrixRef(),a);vec3.sub(a,this._center,this._eye);return vec3.normalize(a,a)};y.prototype.getUp=function(a){a=a||vec3.create();a.set(this._up);
  return this._root&&this._root.transform?mat4.rotateVec3(a,this._root.transform.getGlobalMatrixRef(),a):a};y.prototype.getTop=function(a){a=a||vec3.create();var b=vec3.sub(vec3.create(),this._center,this._eye),c=vec3.cross(vec3.create(),this._up,b);a=vec3.cross(a,b,c);vec3.normalize(a,a);return this._root&&this._root.transform&&this._root._parent?mat4.rotateVec3(a,this._root.transform.getGlobalMatrixRef(),a):a};y.prototype.getRight=function(a){a=a||vec3.create();var b=vec3.sub(vec3.create(),this._center,
  this._eye);a=vec3.cross(a,this._up,b);vec3.normalize(a,a);return this._root&&this._root.transform&&this._root._parent?mat4.rotateVec3(a,this._root.transform.getGlobalMatrixRef(),a):a};y.prototype.setEye=function(a){this._eye.set(a);this._must_update_view_matrix=!0};y.prototype.setCenter=function(a){this._center.set(a);this._must_update_view_matrix=!0};y.prototype.setPerspective=function(a,b,c,d){this._fov=a;this._aspect=b;this._near=c;this._far=d;this._type=y.PERSPECTIVE;this._must_update_projection_matrix=
  !0};y.prototype.setOrthographic=function(a,b,c,d,f,e){this._near=f;this._far=e;this._ortho.set([a,b,c,d]);this._type=y.ORTHO2D;this._must_update_projection_matrix=!0};y.prototype.move=function(a){this._root&&this._root.transform?this._root.transform.move(a):(vec3.add(this._center,this._center,a),vec3.add(this._eye,this._eye,a));this._must_update_view_matrix=!0};y.prototype.rotate=function(){var a=quat.create(),b=vec3.create();return function(c,d,f){0!=c&&(this._root&&this._root.transform?this._root.transform.rotate(c,
  d,f):(f?this.getLocalVector(d,b):b.set(d),c=quat.setAxisAngle(a,b,0.0174532925*c),d=vec3.subtract(b,this._center,this._eye),vec3.transformQuat(d,d,c),vec3.add(this._center,this._eye,d)),this._must_update_view_matrix=!0)}}();y.prototype.orbit=function(){var a=quat.create(),b=vec3.create();return function(c,d,f){0!=c&&(this._root&&this._root.transform?this._root.transform.orbit(c,d,f||this.getCenter()):(f=f||this._center,c=quat.setAxisAngle(a,d,0.0174532925*c),d=vec3.subtract(b,this._eye,f),vec3.transformQuat(d,
  d,c),vec3.add(this._eye,f,d)),this._must_update_view_matrix=!0)}}();y.prototype.orbitDistanceFactor=function(a,b){b=b||this._center;var c=vec3.subtract(vec3.create(),this._eye,b);vec3.scale(c,c,a);vec3.add(this._eye,b,c);this._must_update_view_matrix=!0};y.prototype.setDistanceToCenter=function(a,b){if(this._root)console.warn("cannot use setDistanceToCenter in a camera attached to a node");else{var c=vec3.sub(vec3.create(),this._center,this._eye),d=vec3.length(c);b?vec3.scaleAndAdd(this._eye,this._center,
  c,-a/d):vec3.scaleAndAdd(this._center,this._eye,c,a/d);this._must_update_view_matrix=!0}};y.prototype.setOrientation=function(a,b){var c=this.getCenter(),d=this.getEye(),f=[0,1,0],c=vec3.sub(vec3.create(),c,d),c=vec3.length(c),e=null,e=vec3.fromValues(0,0,-c);b&&(vec3.rotateY(e,e,-0.5*Math.PI),vec3.rotateY(f,f,-0.5*Math.PI));vec3.transformQuat(e,e,a);vec3.transformQuat(f,f,a);b&&(vec3.rotateY(e,e,0.5*Math.PI),vec3.rotateY(f,f,0.5*Math.PI));this.center=vec3.add(vec3.create(),d,e);this.up=f;this._must_update_view_matrix=
  !0};y.prototype.setEulerAngles=function(a,b,c){var d=quat.create();quat.fromEuler(d,[a,b,c]);this.setOrientation(d)};y.prototype.fromViewmatrix=function(a){a=mat4.invert(mat4.create(),a);this.eye=vec3.transformMat4(vec3.create(),vec3.create(),a);this.center=vec3.transformMat4(vec3.create(),[0,0,-1],a);this.up=mat4.rotateVec3(vec3.create(),a,[0,1,0]);this._must_update_view_matrix=!0};y.prototype.setViewportInPixels=function(a,b,c,d){this._viewport[0]=a/gl.canvas.width;this._viewport[1]=b/gl.canvas.height;
  this._viewport[2]=c/gl.canvas.width;this._viewport[3]=d/gl.canvas.height};y.prototype.project=function(a,b,c,d){c=c||vec3.create();b=this.getLocalViewport(b);(this._must_update_view_matrix||this._must_update_projection_matrix)&&this.updateMatrices();vec3.project(c,a,this._viewprojection_matrix,b);d||(c[1]=b[3]-c[1]+2*b[1]);return c};y.prototype.unproject=function(a,b,c){b=this.getLocalViewport(b);(this._must_update_view_matrix||this._must_update_projection_matrix)&&this.updateMatrices();return vec3.unproject(c||
  vec3.create(),a,this._viewprojection_matrix,b)};y.prototype.getLocalViewport=function(a,b){b=b||vec4.create();if(!a)return b[0]=gl.canvas.width*this._viewport[0],b[1]=gl.canvas.height*this._viewport[1],b[2]=gl.canvas.width*this._viewport[2],b[3]=gl.canvas.height*this._viewport[3],b;b[0]=Math.floor(a[2]*this._viewport[0]+a[0]);b[1]=Math.floor(a[3]*this._viewport[1]+a[1]);b[2]=Math.ceil(a[2]*this._viewport[2]);b[3]=Math.ceil(a[3]*this._viewport[3]);return b};y.prototype.getRayInPixel=function(a,b,c,
  d){d||(c=this.getLocalViewport(c,this._viewport_in_pixels));(this._must_update_view_matrix||this._must_update_projection_matrix)&&this.updateMatrices();d=this.getEye();var f=vec3.unproject(vec3.create(),[a,b,1],this._viewprojection_matrix,c);this.type==y.ORTHOGRAPHIC&&(d=vec3.unproject(d,[a,b,0],this._viewprojection_matrix,c));a=vec3.subtract(f,f,d);vec3.normalize(a,a);return{origin:d,direction:a}};y.prototype.isPointInCamera=function(a,b,c){c=this.getLocalViewport(c,this._viewport_in_pixels);return a<
  c[0]||a>c[0]+c[2]||b<c[1]||b>c[1]+c[3]?!1:!0};y.prototype.configure=function(a){void 0!==a.uid&&(this.uid=a.uid);void 0!==a.layers&&(this.layers=a.layers);void 0!==a.enabled&&(this.enabled=a.enabled);void 0!==a.type&&(this._type=a.type);void 0!==a.eye&&this._eye.set(a.eye);void 0!==a.center&&this._center.set(a.center);void 0!==a.up&&this._up.set(a.up);void 0!==a.near&&(this._near=a.near);void 0!==a.far&&(this._far=a.far);void 0!==a.fov&&(this._fov=a.fov);void 0!==a.aspect&&(this._aspect=a.aspect);
  void 0!==a.final_aspect&&(this._final_aspect=a.final_aspect);void 0!==a.frustum_size&&(this._frustum_size=a.frustum_size);void 0!==a.viewport&&this._viewport.set(a.viewport);void 0!==a.background_color&&this._background_color.set(a.background_color);void 0!==a.render_to_texture&&(this.render_to_texture=a.render_to_texture);a.frame&&this._frame&&this._frame.configure(a.frame);this.updateMatrices(!0)};y.prototype.serialize=function(){return{uid:this.uid,layers:this.layers,enabled:this.enabled,type:this._type,
  eye:vec3.toArray(this._eye),center:vec3.toArray(this._center),up:vec3.toArray(this._up),near:this._near,far:this._far,fov:this._fov,aspect:this._aspect,background_color:vec4.toArray(this._background_color),frustum_size:this._frustum_size,viewport:Array.apply([],this._viewport),render_to_texture:this.render_to_texture,frame:this._frame?this._frame.serialize():null}};y.prototype.checkLayersVisibility=function(a){return 0!==(this.layers&a)};y.prototype.getLayers=function(){for(var a=[],b=0;32>b;++b)this.layers&
  1<<b&&a.push(this._root.scene.layer_names[b]||"layer"+b);return a};y.prototype.setLayer=function(a,b){var c=1<<a;this.layers&=~c;b&&(this.layers|=c)};y.prototype.isInLayer=function(a){return 0!==(this.layers&1<<a)};y.prototype.getTransformMatrix=function(a){if(this._root&&this._root.transform)return null;var b=null,b="center"==a?this._center:this._eye;a=mat4.create();mat4.setTranslation(a,b);return a};y.prototype.applyTransformMatrix=function(a,b,c){if(this._root&&this._root.transform)return!1;b=
  null;b="center"==c?this._center:this._eye;mat4.multiplyVec3(b,a,b);return this._must_update_view_matrix=!0};y.prototype.enableRenderFrameContext=function(){this._frame&&this._frame.enable()};y.prototype.disableRenderFrameContext=function(){this._frame&&this._frame.disable()};y.prototype.prepare=function(){this.updateMatrices();this._previous_viewprojection_matrix.set(this._viewprojection_matrix);this.fillShaderQuery();this.fillShaderUniforms()};y.prototype.fillShaderQuery=function(){var a=new e.ShaderQuery;
  this.type==y.ORTHOGRAPHIC&&a.setMacro("USE_ORTHOGRAPHIC_CAMERA");this._query=a};y.prototype.fillShaderUniforms=function(){var a=this._uniforms;a.u_camera_planes[0]=this.near;a.u_camera_planes[1]=this.far;this.type==e.Camera.PERSPECTIVE?a.u_camera_perspective.set([this.fov*DEG2RAD,512/Math.tan(this.fov*DEG2RAD)]):a.u_camera_perspective.set([this._frustum_size,512/this._frustum_size]);a.u_camera_perspective[2]=this._projection_matrix[5];this.getEye(a.u_camera_eye);this.getFront(a.u_camera_front);return a};
  e.registerComponent(y);e.Camera=y;ca.icon="mini-icon-fx.png";ca["@camera_uid"]={type:"String"};Object.defineProperty(ca.prototype,"use_antialiasing",{set:function(a){this.fx.apply_fxaa=a},get:function(){return this.fx.apply_fxaa},enumerable:!0});ca.prototype.configure=function(a){this.enabled=!!a.enabled;this.use_antialiasing=!!a.use_antialiasing;this.camera_uid=a.camera_uid;a.frame&&this.frame.configure(a.frame);a.fx&&this.fx.configure(a.fx)};ca.prototype.serialize=function(){return{enabled:this.enabled,
  use_antialiasing:this.use_antialiasing,frame:this.frame.serialize(),camera_uid:this.camera_uid,fx:this.fx.serialize()}};ca.prototype.getResources=function(a){return a};ca.prototype.addFX=function(a){this.fx.addFX(a)};ca.prototype.getFX=function(a){return this.fx.getFX(a)};ca.prototype.moveFX=function(a,b){return this.fx.moveFX(a,b)};ca.prototype.removeFX=function(a){return this.fx.removeFX(a)};ca.prototype.onAddedToScene=function(a){LEvent.bind(a,"enableFrameContext",this.onBeforeRender,this);LEvent.bind(a,
  "showFrameContext",this.onAfterRender,this)};ca.prototype.onRemovedFromScene=function(a){LEvent.unbind(a,"enableFrameContext",this.onBeforeRender,this);LEvent.unbind(a,"showFrameContext",this.onAfterRender,this);this._binded_camera&&(LEvent.unbindAll(this._binded_camera,this),this._binded_camera=null)};ca.prototype.onBeforeRender=function(a,b){if(this.enabled){var c=this._root.camera;this.camera_uid&&(c=this._binded_camera&&this._binded_camera.uid==this.camera_uid?e.GlobalScene.findComponentByUId(this.camera_uid):
  this._binded_camera);c?(c&&c!=this._binded_camera&&(this._binded_camera&&LEvent.unbindAll(this._binded_camera,this),LEvent.bind(c,"enableFrameContext",this.enableCameraFBO,this),LEvent.bind(c,"showFrameContext",this.showCameraFBO,this)),this._binded_camera=c):this._binded_camera&&(LEvent.unbindAll(this._binded_camera,this),this._binded_camera=null)}else this._binded_camera&&(LEvent.unbindAll(this._binded_camera,this),this._binded_camera=null)};ca.prototype.onAfterRender=function(a,b){};ca.prototype.enableCameraFBO=
  function(a,b){if(this.enabled){var c=this._viewport=this._binded_camera.getLocalViewport(null,this._viewport);this.frame.enable(b,c);b.ignore_viewports=!0}};ca.prototype.showCameraFBO=function(a,b){this.enabled&&(b.ignore_viewports=!1,this.showFBO())};ca.prototype.showFBO=function(){if(this.enabled)if(this.frame.disable(),this.shader_material){var a=e.ResourcesManager.getResource(this.shader_material),b=!1;a&&a.constructor===e.ShaderMaterial&&(b=a.applyToTexture(this.frame._color_texture));b||this.frame._color_texture.toViewport()}else this._viewport?
  (gl.setViewport(this._viewport),this.applyFX(),gl.setViewport(this.frame._fbo._old_viewport)):this.applyFX()};ca.prototype.applyFX=function(){var a=this.frame._color_texture,b=this.frame._depth_texture;this.fx.apply_fxaa=this.use_antialiasing;this.fx.filter=this.frame.filter_texture;this.fx.applyFX(a,null,{depth_texture:b})};e.registerComponent(ca);ma.icon="mini-icon-fx.png";ma.prototype.configure=function(a){this.enabled=!!a.enabled;this.use_viewport_size=!!a.use_viewport_size;this.use_antialiasing=
  !!a.use_antialiasing;this.shader_material=a.shader_material;a.fx&&this.fx.configure(a.fx);a.frame&&this.frame.configure(a.frame)};ma.prototype.serialize=function(){return{enabled:this.enabled,frame:this.frame.serialize(),shader_material:this.shader_material,use_antialiasing:this.use_antialiasing,use_viewport_size:this.use_viewport_size,fx:this.fx.serialize()}};ma.prototype.getResources=function(a){return a};ma.prototype.addFX=function(a){this.fx.addFX(a)};ma.prototype.getFX=function(a){return this.fx.getFX(a)};
  ma.prototype.moveFX=function(a,b){return this.fx.moveFX(a,b)};ma.prototype.removeFX=function(a){return this.fx.removeFX(a)};ma.prototype.onAddedToScene=function(a){LEvent.bind(a,"enableFrameContext",this.onBeforeRender,this);LEvent.bind(a,"showFrameContext",this.onAfterRender,this)};ma.prototype.onRemovedFromScene=function(a){LEvent.unbind(a,"enableFrameContext",this.onBeforeRender,this);LEvent.unbind(a,"showFrameContext",this.onAfterRender,this)};ma.prototype.onBeforeRender=function(a,b){this.enabled&&
  this.enableFrameFBO(b)};ma.prototype.onAfterRender=function(a,b){this.enabled&&this.showFBO()};ma.prototype.enableFrameFBO=function(a){this.enabled&&this.frame.enable(a)};ma.prototype.showFBO=function(){if(this.enabled)if(this.frame.disable(),this.shader_material){var a=e.ResourcesManager.getResource(this.shader_material),b=!1;a&&a.constructor===e.ShaderMaterial&&(b=a.applyToTexture(this.frame._color_texture));b||this.frame._color_texture.toViewport()}else this._viewport?(gl.setViewport(this._viewport),
  this.applyFX(),gl.setViewport(this.frame._fbo._old_viewport)):this.applyFX()};ma.prototype.applyFX=function(){var a=this.frame._color_texture,b=this.frame._depth_texture;this.fx.apply_fxaa=this.use_antialiasing;this.fx.filter=this.frame.filter_texture;this.fx.applyFX(a,null,{depth_texture:b})};e.registerComponent(ma);A["@projective_texture"]={type:"Texture"};A["@extra_texture"]={type:"Texture"};Object.defineProperty(A.prototype,"position",{get:function(){return this._position},set:function(a){this._position.set(a)},
  enumerable:!0});Object.defineProperty(A.prototype,"target",{get:function(){return this._target},set:function(a){this._target.set(a)},enumerable:!0});Object.defineProperty(A.prototype,"up",{get:function(){return this._up},set:function(a){this._up.set(a)},enumerable:!0});Object.defineProperty(A.prototype,"color",{get:function(){return this._color},set:function(a){this._color.set(a)},enumerable:!0});A.FRONT_VECTOR=new Float32Array([0,0,-1]);A.RIGHT_VECTOR=new Float32Array([1,0,0]);A.UP_VECTOR=new Float32Array([0,
  1,0]);A.OMNI=1;A.SPOT=2;A.DIRECTIONAL=3;A.DEFAULT_DIRECTIONAL_FRUSTUM_SIZE=50;A.shadowmap_depth_texture=!0;A.coding_help="LightInfo LIGHT -> light info before applying equation\nInput IN -> info about the mesh\nSurfaceOutput o -> info about the surface properties of this pixel\n\nstruct LightInfo {\n\tvec3 Color;\n\tvec3 Ambient;\n\tfloat Diffuse; //NdotL\n\tfloat Specular; //RdotL\n\tvec3 Emission;\n\tvec3 Reflection;\n\tfloat Attenuation;\n\tfloat Shadow; //1.0 means fully lit\n};\n\nstruct Input {\n\tvec4 color;\n\tvec3 vertex;\n\tvec3 normal;\n\tvec2 uv;\n\tvec2 uv1;\n\t\n\tvec3 camPos;\n\tvec3 viewDir;\n\tvec3 worldPos;\n\tvec3 worldNormal;\n\tvec4 screenPos;\n};\n\nstruct SurfaceOutput {\n\tvec3 Albedo;\n\tvec3 Normal;\n\tvec3 Ambient;\n\tvec3 Emission;\n\tfloat Specular;\n\tfloat Gloss;\n\tfloat Alpha;\n\tfloat Reflectivity;\n};\n";
  A.prototype.onAddedToNode=function(a){a.light||(a.light=this)};A.prototype.onRemovedFromNode=function(a){a.light==this&&delete a.light};A.prototype.onAddedToScene=function(a){LEvent.bind(a,"collectLights",this.onCollectLights,this)};A.prototype.onRemovedFromScene=function(a){LEvent.unbind(a,"collectLights",this.onCollectLights,this);e.ResourcesManager.unregisterResource(":shadowmap_"+this.uid)};A.prototype.onCollectLights=function(a,b){this.enabled&&b.push(this)};A._temp_matrix=mat4.create();A._temp2_matrix=
  mat4.create();A._temp3_matrix=mat4.create();A._temp_position=vec3.create();A._temp_target=vec3.create();A._temp_up=vec3.create();A._temp_front=vec3.create();A.prototype.updateLightCamera=function(){this._light_camera||(this._light_camera=new y);var a=this._light_camera;a.eye=this.getPosition(A._temp_position);a.center=this.getTarget(A._temp_target);var b=this.getUp(A._temp_up),c=this.getFront(A._temp_front);0.999<Math.abs(vec3.dot(c,b))&&vec3.set(b,0,0,1);a.up=b;a.type=this.type==A.DIRECTIONAL?y.ORTHOGRAPHIC:
  y.PERSPECTIVE;b=this.computeShadowmapFar();a.frustum_size=this.frustum_size||A.DEFAULT_DIRECTIONAL_FRUSTUM_SIZE;a.near=this.near;a.far=b;a.fov=this.angle_end||45;a.updateMatrices();this._light_matrix=a._viewprojection_matrix;return a};A.prototype.getLightCamera=function(){this._light_camera||this.updateLightCamera();return this._light_camera};A.prototype.updateVectors=function(){var a=vec3.create();return function(){if(this._root&&this._root.transform){var b=this._root.transform.getGlobalMatrixRef();
  mat4.getTranslation(this._position,b);this.use_target||mat4.multiplyVec3(this._target,b,A.FRONT_VECTOR);mat4.multiplyVec3(this._up,b,A.UP_VECTOR);mat4.rotateVec3(this._front,b,A.FRONT_VECTOR);mat4.rotateVec3(this._right,b,A.RIGHT_VECTOR);vec3.copy(this._top,this.up)}else vec3.subtract(this._front,this._target,this._position),vec3.normalize(this._front,this._front),vec3.normalize(a,this._up),vec3.cross(this._right,this._front,a),vec3.cross(this._top,this._right,this._front)}}();A.prototype.getPosition=
  function(a){a=a||vec3.create();if(this._root&&this._root.transform)return this._root.transform.getGlobalPosition(a);a.set(this._position);return a};A.prototype.getTarget=function(a){a=a||vec3.create();if(this._root&&this._root.transform&&!this.use_target)return this._root.transform.transformPointGlobal(A.FRONT_VECTOR,a);a.set(this._target);return a};A.prototype.getUp=function(a){a=a||vec3.create();if(this._root&&this._root.transform)return this._root.transform.transformVector(A.UP_VECTOR,a);a.set(this._up);
  return a};A.prototype.getFront=function(a){a=a||vec3.create();vec3.subtract(a,this.getPosition(),this.getTarget());vec3.normalize(a,a);return a};A.prototype.getLightRotationMatrix=function(){};A.prototype.getResources=function(a){this.projective_texture&&(a[this.projective_texture]=GL.Texture);this.extra_texture&&(a[this.extra_texture]=GL.Texture);return a};A.prototype.onResourceRenamed=function(a,b,c){this.projective_texture==a&&(this.projective_texture=b);this.extra_texture==a&&(this.extra_texture=
  b)};A.prototype.checkLayersVisibility=function(a){return this._root?0!==(this._root.layers&a):!1};A.prototype.isInLayer=function(a){return this._root?0!==(this._root.layers&1<<a):!1};A.prototype.prepare=function(a){var b=this._uniforms,c=this._samplers,d=this._query;d.clear();(this.projective_texture||this.cast_shadows)&&this.updateLightCamera();a.shadows_enabled&&this.cast_shadows||!this._shadowmap||(this._shadowmap=null,delete e.ResourcesManager.textures[":shadowmap_"+this.uid]);this.updateVectors();
  this.type==A.DIRECTIONAL?d.macros.USE_DIRECTIONAL_LIGHT="":this.type==A.SPOT?d.macros.USE_SPOT_LIGHT="":d.macros.USE_OMNI_LIGHT="";this.spot_cone&&(d.macros.USE_SPOT_CONE="");this.linear_attenuation&&(d.macros.USE_LINEAR_ATTENUATION="");this.range_attenuation&&(d.macros.USE_RANGE_ATTENUATION="");0.001<this.offset&&(d.macros.USE_LIGHT_OFFSET="");if(this.projective_texture){var f=this.projective_texture.constructor===String?e.ResourcesManager.textures[this.projective_texture]:this.projective_texture;
  f&&(f.texture_type==gl.TEXTURE_CUBE_MAP?d.macros.USE_LIGHT_CUBEMAP="":d.macros.USE_LIGHT_TEXTURE="")}this.extra_texture&&(f=this.extra_texture.constructor===String?e.ResourcesManager.textures[this.extra_texture]:this.extra_texture)&&(f.texture_type==gl.TEXTURE_CUBE_MAP?d.macros.USE_EXTRA_LIGHT_CUBEMAP="":d.macros.USE_EXTRA_LIGHT_TEXTURE="");if(this.type==A.DIRECTIONAL||this.type==A.SPOT)b.u_light_front=this._front;this.type==A.SPOT&&(b.u_light_angle=[this.angle*DEG2RAD,this.angle_end*DEG2RAD,Math.cos(this.angle*
  DEG2RAD*0.5),Math.cos(this.angle_end*DEG2RAD*0.5)]);b.u_light_position=this.position;b.u_light_color=vec3.scale(b.u_light_color||vec3.create(),this.color,this.intensity);this._attenuation_info[0]=this.att_start;this._attenuation_info[1]=this.att_end;b.u_light_att=this._attenuation_info;b.u_light_offset=this.offset;this.extra_light_shader_code?(d=null,this._last_extra_light_shader_code!=this.extra_light_shader_code&&(this._last_processed_extra_light_shader_code=d=e.Material.processShaderCode(this.extra_light_shader_code))):
  this._last_processed_extra_light_shader_code=null;if(a.update_shadowmaps&&a.shadows_enabled&&!a.lights_disabled&&!a.low_quality){d=e.Renderer._visible_cameras;f=!1;if(!a.update_all_shadowmaps&&d&&this.type==A.OMNI&&this.range_attenuation)for(var g=this.computeShadowmapFar(),h=0;h<d.length;h++){if(geo.frustumTestSphere(d[h]._frustum_planes,this.position,g)!=CLIP_OUTSIDE){f=!0;break}}else f=!0;f&&this.generateShadowmap(a)}this._shadowmap&&!this.cast_shadows&&(this._shadowmap=null);this._samplers.length=
  0;a=this.cast_shadows&&this._shadowmap&&null!=this._light_matrix&&!a.shadows_disabled;if(this.projective_texture){if(f=this.projective_texture.constructor===String?e.ResourcesManager.textures[this.projective_texture]:this.projective_texture)f.texture_type==gl.TEXTURE_CUBE_MAP?b.light_cubemap=e.Renderer.LIGHTPROJECTOR_TEXTURE_SLOT:b.light_texture=e.Renderer.LIGHTPROJECTOR_TEXTURE_SLOT;c[e.Renderer.LIGHTPROJECTOR_TEXTURE_SLOT]=f}else delete b.light_texture,delete b.light_cubemap;if(this.extra_texture){if(f=
  this.extra_texture.constructor===String?e.ResourcesManager.textures[this.extra_texture]:this.extra_texture)f.texture_type==gl.TEXTURE_CUBE_MAP?b.extra_light_cubemap=e.Renderer.LIGHTEXTRA_TEXTURE_SLOT:b.extra_light_texture=e.Renderer.LIGHTEXTRA_TEXTURE_SLOT;c[e.Renderer.LIGHTEXTRA_TEXTURE_SLOT]=f}else delete b.extra_light_texture,delete b.extra_light_cubemap;a?(g=this.computeShadowmapFar(),b.u_shadow_params=[1/this._shadowmap.width,this.shadow_bias,this.near,g],b.shadowmap=e.Renderer.SHADOWMAP_TEXTURE_SLOT,
  b.u_light_matrix=this._light_matrix,c[e.Renderer.SHADOWMAP_TEXTURE_SLOT]=this._shadowmap):(delete b.u_shadow_params,delete b.shadowmap)};A.prototype.getQuery=function(a,b){var c=this._query,d=this.cast_shadows&&this._shadowmap&&null!=this._light_matrix&&!b.shadows_disabled;this.constant_diffuse||a.material.constant_diffuse?delete c.macros.USE_DIFFUSE_LIGHT:c.macros.USE_DIFFUSE_LIGHT="";this.use_specular&&0<a.material.specular_factor?c.macros.USE_SPECULAR_LIGHT="":delete c.macros.USE_SPECULAR_LIGHT;
  d&&a.flags&512?(c.macros.USE_SHADOW_MAP="",this._shadowmap&&this._shadowmap.texture_type==gl.TEXTURE_CUBE_MAP&&(c.macros.USE_SHADOW_CUBEMAP=""),this.hard_shadows&&(c.macros.USE_HARD_SHADOWS=""),this._shadowmap&&this._shadowmap.format==gl.DEPTH_COMPONENT&&(c.macros.USE_SHADOW_DEPTH_TEXTURE=""),c.macros.SHADOWMAP_OFFSET=""):delete c.macros.USE_SHADOW_MAP;!this._last_processed_extra_light_shader_code||this.extra_texture&&!e.ResourcesManager.getTexture(this.extra_texture)?delete c.macros.USE_EXTRA_LIGHT_SHADER_CODE:
  c.macros.USE_EXTRA_LIGHT_SHADER_CODE=this._last_processed_extra_light_shader_code;return c};A.prototype.computeShadowmapFar=function(){var a=this.far;this.type==A.OMNI?this.range_attenuation&&this.att_end*Math.SQRT2<a&&(a=this.att_end/Math.SQRT2):this.range_attenuation&&this.att_end<a&&(a=this.att_end);return a};A.prototype.computeLightIntensity=function(){var a=Math.max(this.color[0],this.color[1],this.color[2]);return Math.max(0,a*this.intensity)};A.prototype.computeLightRadius=function(){return this.range_attenuation?
  this.type==A.OMNI?this.att_end*Math.SQRT2:this.att_end:-1};A.prototype.generateShadowmap=function(a){if(this.cast_shadows&&!(1E-4>this.computeLightIntensity())){var b=this.shadowmap_resolution;0==b&&(b=a.default_shadowmap_resolution);var c=this.type==A.OMNI?gl.TEXTURE_CUBE_MAP:gl.TEXTURE_2D;if(null==this._shadowmap||this._shadowmap.width!=b||this._shadowmap.texture_type!=c){var d=gl.UNSIGNED_BYTE,f=gl.RGBA;e.Light.shadowmap_depth_texture&&gl.extensions.WEBGL_depth_texture&&this.type!=e.Light.OMNI&&
  (f=gl.DEPTH_COMPONENT,d=gl.UNSIGNED_INT);this._shadowmap=new GL.Texture(b,b,{type:d,texture_type:c,format:f,magFilter:gl.NEAREST,minFilter:gl.NEAREST});e.ResourcesManager.textures[":shadowmap_"+this.uid]=this._shadowmap;this._shadowmap.texture_type==gl.TEXTURE_2D&&(this._fbo=f==gl.RGBA?new GL.FBO([this._shadowmap]):new GL.FBO(null,this._shadowmap))}e.Renderer.setRenderPass("shadow");e.Renderer._current_light=this;this.type==A.OMNI?(c=this.computeShadowmapFar(),this._shadowmap.unbind(),e.Renderer.renderToCubemap(this.getPosition(),
  b,this._shadowmap,a,this.near,c)):(b=this.getLightCamera(),e.Renderer.enableCamera(b,a,!0),this._shadowmap.unbind(),e.Renderer._current_target=this._shadowmap,this._fbo.bind(),gl.clearColor(0,0,0,0),gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT),e.Renderer.renderInstances(a),this._fbo.unbind(),e.Renderer._current_target=null);e.Renderer.setRenderPass("color");e.Renderer._current_light=null}};A.prototype.getTransformMatrix=function(a,b){if(this._root&&this._root.transform)return null;var c=null,
  c="target"==a?this.target:this.position,d=b||mat4.create();mat4.setTranslation(d,c);return d};A.prototype.applyTransformMatrix=function(a,b,c){if(this._root&&this._root.transform)return!1;b=null;b="target"==c?this.target:this.position;mat4.multiplyVec3(b,a,b);return!0};e.registerComponent(A);e.Light=A;Object.defineProperty(S.prototype,"primitive",{get:function(){return this._primitive},set:function(a){a=void 0===a||null===a?-1:a|0;-1>a||10<a||(this._primitive=a)},enumerable:!0});S.icon="mini-icon-teapot.png";
  S["@mesh"]={type:"mesh"};S["@lod_mesh"]={type:"mesh"};S["@material"]={type:"material"};S["@primitive"]={type:"enum",values:{Default:-1,Points:0,Lines:1,LineLoop:2,LineStrip:3,Triangles:4,TriangleStrip:5,TriangleFan:6,Wireframe:10}};S["@submesh_id"]={type:"enum",values:function(){var a=this.instance.getMesh();if(!(a&&a&&a.info&&a.info.groups)||2>a.info.groups.length)return null;for(var b={all:null},c=0;c<a.info.groups.length;++c)b[a.info.groups[c].name]=c;return b}};S["@use_submaterials"]={type:e.TYPES.BOOLEAN,
  widget:null};S["@submaterials"]={widget:null};S.prototype.onAddedToNode=function(a){a.meshrenderer||(a.meshrenderer=this);this._RI.node=a;LEvent.bind(a,"collectRenderInstances",this.onCollectInstances,this)};S.prototype.onRemovedFromNode=function(a){a.meshrenderer&&delete a.meshrenderer;LEvent.unbind(a,"collectRenderInstances",this.onCollectInstances,this)};S.prototype.configure=function(a){void 0!==a.enabled&&(this.enabled=a.enabled);this.mesh=a.mesh;this.lod_mesh=a.lod_mesh;this.submesh_id=a.submesh_id;
  this.primitive=a.primitive;this.two_sided=!!a.two_sided;this.material=a.material;this.use_submaterials=!!a.use_submaterials;a.submaterials&&(this.submaterials=a.submaterials);void 0!==a.point_size&&(this.point_size=a.point_size);this.textured_points=!!a.textured_points;a.material&&(this.material="string"==typeof a.material?a.material:new e.Material(a.material))};S.prototype.serialize=function(){var a={enabled:this.enabled,mesh:this.mesh,lod_mesh:this.lod_mesh};this.material&&(a.material="string"==
  typeof this.material?this.material:this.material.serialize());-1!=this.primitive&&(a.primitive=this.primitive);this.submesh_id&&(a.submesh_id=this.submesh_id);this.two_sided&&(a.two_sided=this.two_sided);this.use_submaterials&&(a.use_submaterials=this.use_submaterials);a.submaterials=this.submaterials;a.point_size=this.point_size;a.textured_points=this.textured_points;a.material=this.material;return a};S.prototype.getMesh=function(){return this.mesh?this.mesh.constructor===String?e.ResourcesManager.meshes[this.mesh]:
  this.mesh:null};S.prototype.getLODMesh=function(){return this.lod_mesh?this.lod_mesh.constructor===String?e.ResourcesManager.meshes[this.lod_mesh]:null:null};S.prototype.getAnyMesh=function(){return this.getMesh()||this.getLODMesh()};S.prototype.getResources=function(a){"string"==typeof this.mesh&&(a[this.mesh]=GL.Mesh);"string"==typeof this.lod_mesh&&(a[this.lod_mesh]=GL.Mesh);"string"==typeof this.material&&(a[this.material]=e.Material);if(this.use_submaterials)for(var b=0;b<this.submaterials.length;++b)this.submaterials[b]&&
  (a[this.submaterials[b]]=e.Material);return a};S.prototype.onResourceRenamed=function(a,b,c){this.mesh==a&&(this.mesh=b);this.lod_mesh==a&&(this.lod_mesh=b);if(this.morph_targets)for(var d in this.morph_targets)this.morph_targets[d].mesh==a&&(this.morph_targets[d].mesh=b)};S.prototype.onCollectInstances=function(a,b){if(this.enabled){var c=this.getAnyMesh();if(!c)return null;if(this._root)if(this.use_submaterials)this.onCollectInstancesSubmaterials(b);else{var d=this._RI,f=this._root.flags&&this._root.flags.is_static,
  g=this._root.transform;if(f&&e.allow_static&&!this._must_update_static&&(!g||g&&this._transform_version==g._version))return b.push(d);d.setMatrix(this._root.transform._global_matrix);mat4.multiplyVec3(d.center,d.matrix,vec3.create());d.flags=xa|65536;d.applyNodeFlags();this.two_sided&&(d.flags&=-2);var h=null,h=this.material?e.ResourcesManager.getResource(this.material):this._root.getMaterial();d.setMaterial(h);d.setMesh(c,this.primitive);-1!=this.submesh_id&&null!=this.submesh_id&&c.info&&c.info.groups?
  (h=c.info.groups[this.submesh_id])&&d.setRange(h.start,h.length):d.setRange(0,-1);this.lod_mesh?(d.collision_mesh=this.lod_mesh.constructor===String?e.ResourcesManager.resources[this.lod_mesh]:this.lod_mesh,d.setLODMesh(d.collision_mesh)):d.collision_mesh=c;this.primitive==gl.POINTS&&(d.uniforms.u_point_size=this.point_size,d.query.macros.USE_POINTS="",this.textured_points&&(d.query.macros.USE_TEXTURED_POINTS=""));!this.textured_points&&d.query.macros.USE_TEXTURED_POINTS&&delete d.query.macros.USE_TEXTURED_POINTS;
  f&&e.allow_static&&!this.isLoading()&&(this._must_update_static=!1,this._transform_version=g?g._version:0);b.push(d)}}};S.prototype.onCollectInstancesSubmaterials=function(a){this._RIs||(this._RIs=[]);var b=this.getMesh();if(b){var c=b.info.groups;if(c){var d=this._root.transform._global_matrix,f=vec3.create();mat4.multiplyVec3(f,d,e.ZEROS);for(var d=null,g=0;g<this.submaterials.length;++g){var h=this.submaterials[g];if(h){var k=c[g];if(k&&(h=e.ResourcesManager.getResource(h))){var m=this._RIs[g];
  m||(m=this._RIs[g]=new e.RenderInstance(this._root,this));d?m.setMatrix(d.matrix,d.normal_matrix):m.setMatrix(this._root.transform._global_matrix);m.center.set(f);m.flags=xa|65536;m.applyNodeFlags();this.two_sided&&(m.flags&=-2);m.setMaterial(h);m.setMesh(b,this.primitive);m.setRange(k.start,k.length);a.push(m);d||(d=m)}}}}}};S.prototype.isLoading=function(){return this.mesh&&e.ResourcesManager.isLoading(this.mesh)||this.lod_mesh&&e.ResourcesManager.isLoading(this.lod_mesh)||this.material&&e.ResourcesManager.isLoading(this.material)||
  this._root&&this._root.material&&this._root.material.constructor===String&&e.ResourcesManager.isLoading(this._root.material)?!0:!1};e.registerComponent(S);e.MeshRenderer=S;Object.defineProperty(K.prototype,"primitive",{get:function(){return this._primitive},set:function(a){a=void 0===a||null===a?-1:a|0;if(-1==a||0==a||1==a||4==a||10==a)this._primitive=a},enumerable:!0});K.MAX_BONES=64;K.gpu_skinning_supported=!0;K.icon="mini-icon-stickman.png";K["@mesh"]={widget:"mesh"};K["@lod_mesh"]={widget:"mesh"};
  K["@primitive"]={widget:"combo",values:{Default:null,Points:0,Lines:1,Triangles:4,Wireframe:10}};K["@submesh_id"]={widget:"combo",values:function(){var a=this.instance.getMesh();if(!(a&&a&&a.info&&a.info.groups)||2>a.info.groups.length)return null;for(var b={all:null},c=0;c<a.info.groups.length;++c)b[a.info.groups[c].name]=c;return b}};K.prototype.onAddedToNode=function(a){a.meshrenderer||(a.meshrenderer=this);LEvent.bind(a,"collectRenderInstances",this.onCollectInstances,this)};K.prototype.onRemovedFromNode=
  function(a){a.meshrenderer&&delete a.meshrenderer;LEvent.unbind(a,"collectRenderInstances",this.onCollectInstances,this)};K.prototype.configure=function(a){null!=a.enabled&&(this.enabled=!!a.enabled);this.cpu_skinning=!!a.cpu_skinning;this.ignore_transform=!!a.ignore_transform;this.mesh=a.mesh;this.lod_mesh=a.lod_mesh;this.submesh_id=a.submesh_id;this.primitive=a.primitive;this.two_sided=!!a.two_sided;void 0!==a.point_size&&(this.point_size=a.point_size);a.material&&(this.material="string"==typeof a.material?
  a.material:new s(a.material))};K.prototype.serialize=function(){var a={enabled:this.enabled,apply_skinning:this.apply_skinning,cpu_skinning:this.cpu_skinning,ignore_transform:this.ignore_transform,mesh:this.mesh,lod_mesh:this.lod_mesh,primitive:this.primitive,submesh_id:this.submesh_id,two_sided:this.two_sided,point_size:this.point_size};this.material&&(a.material="string"==typeof this.material?this.material:this.material.serialize());return a};K.prototype.getMesh=function(){return e.ResourcesManager.getMesh(this.mesh)};
  K.prototype.getLODMesh=function(){return e.ResourcesManager.getMesh(this.lod_mesh)};K.prototype.getResources=function(a){"string"==typeof this.mesh&&(a[this.mesh]=Mesh);"string"==typeof this.lod_mesh&&(a[this.lod_mesh]=Mesh);return a};K.prototype.onResourceRenamed=function(a,b,c){this.mesh==a&&(this.mesh=b);this.lod_mesh==a&&(this.lod_mesh=b)};K.prototype.getNodeMatrix=function(a){var b=this._root.scene;if(!b)return null;a=b.getNode(a);if(!a)return null;a._is_bone=!0;return a.transform.getGlobalMatrixRef()};
  K.prototype.getBoneMatrices=function(a){var b=this._last_bones;if(!this._last_bones||this._last_bones.length!=a.bones.length)for(var b=this._last_bones=[],c=0;c<a.bones.length;++c)b[c]=mat4.create();for(c=0;c<a.bones.length;++c){var d=b[c],f=a.bones[c],e=this.getNodeMatrix(f[0]);e?(mat4.multiply(d,e,f[1]),a.bind_matrix&&mat4.multiply(d,d,a.bind_matrix)):mat4.identity(d)}return b};K.prototype.onCollectInstances=function(a,b,c){if(this.enabled){c=this.getMesh();if(!c)return null;if(this._root&&(a=this._render_instance,
  a||(this._render_instance=a=new e.RenderInstance(this._root,this)),c.getBuffer("vertices")&&c.getBuffer("bone_indices"))){if(this.apply_skinning)if(K.gpu_skinning_supported&&!this.cpu_skinning){a.setMesh(c,this.primitive);a.query.macros.USE_SKINNING="";var d=this.getBoneMatrices(c),f=12*d.length,g=this._u_bones;g&&g.length==f||(this._u_bones=g=new Float32Array(f));for(var h=0;h<d.length;h++)mat4.transpose(d[h],d[h]),g.set(d[h].subarray(0,12),12*h,12*(h+1));K.num_supported_uniforms>=f?(a.uniforms.u_bones=
  g,d.length>K.MAX_BONES&&(a.query.macros.MAX_BONES=d.length.toString()),delete a.samplers.u_bones):0<K.num_supported_textures?(h=this._bones_texture,h||(h=this._bones_texture=new GL.Texture(1,3*d.length,{format:gl.RGBA,type:gl.FLOAT,filter:gl.NEAREST}),h._data=new Float32Array(h.width*h.height*4)),h._data.set(g),h.uploadData(h._data,{no_flip:!0}),e.RM.textures[":bones"]=h,a.query.macros.USE_SKINNING_TEXTURE="",a.samplers.u_bones=h,delete a.uniforms.u_bones):console.error("impossible to get here")}else{if(!this._skinned_mesh||
  this._skinned_mesh._reference!=c){this._skinned_mesh=new GL.Mesh;this._skinned_mesh._reference=c;d=c.getBuffer("vertices");g=c.getBuffer("normals");for(h in c.vertexBuffers)this._skinned_mesh.vertexBuffers[h]=c.vertexBuffers[h];for(h in c.indexBuffers)this._skinned_mesh.indexBuffers[h]=c.indexBuffers[h];this._skinned_mesh.createVertexBuffer("vertices","a_vertex",3,new Float32Array(d.data),gl.STREAM_DRAW);g&&this._skinned_mesh.createVertexBuffer("normals","a_normal",3,new Float32Array(g.data),gl.STREAM_DRAW)}this.applySkin(c,
  this._skinned_mesh);a.setMesh(this._skinned_mesh,this.primitive);delete a.query.macros.USE_SKINNING;delete a.query.macros.USE_SKINNING_TEXTURE;delete a.samplers.u_bones}else a.setMesh(c,this.primitive),delete a.query.macros.USE_SKINNING,delete a.query.macros.USE_SKINNING_TEXTURE,delete a.samplers.u_bones;this.ignore_transform?mat4.identity(a.matrix):this._root.transform.getGlobalMatrix(a.matrix);mat4.multiplyVec3(a.center,a.matrix,vec3.create());-1!=this.submesh_id&&null!=this.submesh_id&&c.info&&
  c.info.groups?(h=c.info.groups[this.submesh_id])&&a.setRange(h.start,h.length):a.setRange(0,-1);a.material=this.material||this._root.getMaterial();a.flags=xa;a.applyNodeFlags();this.two_sided&&(a.flags&=-2);this.apply_skinning&&(a.flags|=2048);this.primitive==gl.POINTS&&(a.uniforms.u_point_size=this.point_size,a.query.macros.USE_POINTS="");b.push(a)}}};K.zero_matrix=new Float32Array(16);K.prototype.applySkin=function(a,b){var c=a.getBuffer("vertices").data,d=null;a.getBuffer("normals")&&(d=a.getBuffer("normals").data);
  var f=a.getBuffer("weights").data,e=a.getBuffer("bone_indices").data,h=b.getBuffer("vertices"),k=h.data,m=null,l=null;d&&(m=b.getBuffer("normals"),l=m.data);var p=this.getBoneMatrices(a);if(0==p.length)return null;vec3.create();vec3.create();for(var n=mat4.create(),q=0,r=k.length/3;q<r;++q){c.subarray(3*q,3*q+3);var u=e.subarray(4*q,4*q+4),t=f.subarray(4*q,4*q+4),s=k.subarray(3*q,3*q+3),u=[p[u[0]],p[u[1]],p[u[2]],p[u[3]]];n.set(K.zero_matrix);mat4.scaleAndAdd(n,n,u[0],t[0]);0<t[1]&&mat4.scaleAndAdd(n,
  n,u[1],t[1]);0<t[2]&&mat4.scaleAndAdd(n,n,u[2],t[2]);0<t[3]&&mat4.scaleAndAdd(n,n,u[3],t[3]);mat4.multiplyVec3(s,n,c.subarray(3*q,3*q+3));l&&(t=l.subarray(3*q,3*q+3),mat4.rotateVec3(t,n,d.subarray(3*q,3*q+3)))}h.upload(gl.STREAM_DRAW);m&&m.upload(gl.STREAM_DRAW)};K.prototype.extractSkeleton=function(){};e.registerComponent(K);e.SkinnedMeshRenderer=K;L.icon="mini-icon-teapot.png";L.force_GPU=!0;L.prototype.onAddedToNode=function(a){LEvent.bind(a,"collectRenderInstances",this.onCollectInstances,this)};
  L.prototype.onRemovedFromNode=function(a){LEvent.unbind(a,"collectRenderInstances",this.onCollectInstances,this)};L.prototype.getResources=function(a){if(this.morph_targets.length)for(var b=0;b<this.morph_targets.length;++b)this.morph_targets[b].mesh&&(a[this.morph_targets[b].mesh]=GL.Mesh)};L.prototype.onResourceRenamed=function(a,b,c){if(this.morph_targets.length)for(c=0;c<this.morph_targets.length;++c)this.morph_targets[c].mesh==a&&(this.morph_targets[c].mesh=b)};L.prototype.onCollectInstances=
  function(a,b){if(b.length&&!(16>L.max_supported_vertex_attribs)){var c=this.enabled?b[b.length-1]:null;c!=this._last_RI&&this._last_RI&&this.disableMorphingGPU(this._last_RI);(this._last_RI=c)&&c.mesh&&(this._valid_morphs=this.computeValidMorphs(this._valid_morphs),void 0===this._morph_texture_supported&&(this._morph_texture_supported=void 0!==gl.extensions.OES_texture_float&&1<gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS)),0!=this._valid_morphs.length||L.force_GPU)&&(4>=this._valid_morphs.length?
  this.applyMorphTargetsByGPU(c,this._valid_morphs):this._morph_texture_supported?this.applyMorphUsingTextures(c,this._valid_morphs):this.applyMorphBySoftware(c,this._valid_morphs))}};L.prototype.computeValidMorphs=function(a){a=a||[];a.length=0;var b=this.morph_targets.concat();b.sort(function(a,b){return Math.abs(b.weight)-Math.abs(a.weight)});for(var c=0;c<b.length;++c){var d=b[c];if(d.mesh&&!(0.001>Math.abs(d.weight))){var f=e.ResourcesManager.resources[d.mesh];f&&f.constructor===GL.Mesh&&a.push({name:d.mesh,
  weight:d.weight,mesh:f})}}return a};L.prototype.applyMorphTargetsByGPU=function(a,b){for(var c=a.mesh,d=c.vertexBuffers.vertices,f={},g=[],h=0;h<b.length&&4>h;++h){var k=b[h],m=k.mesh,l=m.vertexBuffers.vertices;l&&l.data.length==d.data.length&&(m=m.vertexBuffers.normals)&&(l=l.clone(!0),m=m.clone(!0),l.attribute=null,m.attribute=null,f["a_vertex_morph"+h]=l,f["a_normal_morph"+h]=m,g.push(k.weight))}a.vertex_buffers={};for(h in c.vertexBuffers)a.vertex_buffers[h]=c.vertexBuffers[h];for(h in f)a.vertex_buffers[h]=
  f[h];a.query.macros.USE_MORPHING_STREAMS="";void 0!==a.query.macros.USE_MORPHING_TEXTURE&&(delete a.query.macros.USE_MORPHING_TEXTURE,delete a.uniforms.u_morph_vertices_texture,delete a.uniforms.u_morph_normals_texture,a.samplers[e.Renderer.MORPHS_TEXTURE_SLOT]=null,a.samplers[e.Renderer.MORPHS_TEXTURE2_SLOT]=null);(c=this._stream_weights)?c.fill(0):c=this._stream_weights=new Float32Array(4);c.set(g);a.uniforms.u_morph_weights=c};L.prototype.disableMorphingGPU=function(a){a&&a.query&&(void 0!==a.query.macros.USE_MORPHING_STREAMS&&
  (delete a.query.macros.USE_MORPHING_STREAMS,delete a.uniforms.u_morph_weights),void 0!==a.query.macros.USE_MORPHING_TEXTURE&&(delete a.query.macros.USE_MORPHING_TEXTURE,a.samplers[e.Renderer.MORPHS_TEXTURE_SLOT]=null,a.samplers[e.Renderer.MORPHS_TEXTURE2_SLOT]=null,delete a.uniforms.u_morph_vertices_texture,delete a.uniforms.u_morph_normals_texture))};L.prototype.applyMorphBySoftware=function(a,b){var c=a.mesh,d=c.vertexBuffers.vertices;this.disableMorphingGPU(a);for(var f="",d=0;d<b.length;++d)var e=
  b[d],f=f+(e.name+"|"+e.weight.toFixed(2)+"|");if(f==this._last_key)this._final_vertices_buffer&&(a.vertex_buffers.vertices=this._final_vertices_buffer),this._final_normals_buffer&&(a.vertex_buffers.normals=this._final_normals_buffer);else{this._last_key=f;d=c.vertexBuffers.vertices;f=d.data;c=c.vertexBuffers.normals.data;this._final_vertices&&this._final_vertices.length==f.length||(this._final_vertices=new Float32Array(f.length),this._final_vertices_buffer=new GL.Buffer(gl.ARRAY_BUFFER,this._final_vertices,
  3,gl.STREAM_DRAW),this._final_vertices_buffer.attribute="a_vertex");this._final_normals&&this._final_normals.length==c.length||(this._final_normals=new Float32Array(c.length),this._final_normals_buffer=new GL.Buffer(gl.ARRAY_BUFFER,this._final_normals,3,gl.STREAM_DRAW),this._final_normals_buffer.attribute="a_normal");var h=this._final_vertices,k=this._final_normals;h.set(f);k.set(c);for(var m=[],l=[],p=[],n=b.length,d=0;d<b.length;++d)e=b[d],m.push(e.mesh.vertexBuffers.vertices.data),l.push(e.mesh.vertexBuffers.normals.data),
  p.push(e.weight);d=0;for(e=h.length;d<e;d+=3)for(var q=h.subarray(d,d+3),r=k.subarray(d,d+3),u=0;u<n;++u){var t=m[u],s=l[u],w=p[u];q[0]+=(t[d]-f[d])*w;q[1]+=(t[d+1]-f[d+1])*w;q[2]+=(t[d+2]-f[d+2])*w;r[0]+=(s[d]-c[d])*w;r[1]+=(s[d+1]-c[d+1])*w;r[2]+=(s[d+2]-c[d+2])*w}this._final_vertices_buffer.upload(gl.STREAM_DRAW);this._final_normals_buffer.upload(gl.STREAM_DRAW);a.vertex_buffers.vertices=this._final_vertices_buffer;a.vertex_buffers.normals=this._final_normals_buffer}};L.prototype.applyMorphUsingTextures=
  function(a,b){var c=a.mesh,d=c.vertexBuffers.vertices,f=c.vertexBuffers.normals;d._texture||(d._texture=this.createGeometryTexture(d));f._texture||(f._texture=this.createGeometryTexture(f));var g=[];this._morphtarget_vertices_texture&&this._morphtarget_vertices_texture.height==d._texture.height||(this._morphtarget_vertices_texture=new GL.Texture(d._texture.width,d._texture.height,{format:gl.RGB,type:gl.FLOAT,filter:gl.NEAREST,wrap:gl.CLAMP_TO_EDGE,no_flip:!0}),this._morphtarget_normals_texture=new GL.Texture(f._texture.width,
  f._texture.height,{format:gl.RGB,type:gl.FLOAT,filter:gl.NEAREST,wrap:gl.CLAMP_TO_EDGE,no_flip:!0}),this._texture_size=vec4.fromValues(this._morphtarget_vertices_texture.width,this._morphtarget_vertices_texture.height,1/this._morphtarget_vertices_texture.width,1/this._morphtarget_vertices_texture.height));for(c=0;c<b.length;++c){var h=b[c],k=h.mesh,m=k.vertexBuffers.vertices;m&&m.data.length==d.data.length&&(k=k.vertexBuffers.normals)&&(m._texture||(m._texture=this.createGeometryTexture(m)),k._texture||
  (k._texture=this.createGeometryTexture(k)),g.push({weight:h.weight,vertices:m._texture,normals:k._texture}))}var l=this.getMorphTextureShader();l.uniforms({u_base_texture:0,u_morph_texture:1});gl.disable(gl.DEPTH_TEST);gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);d._texture.bind(0);var p=GL.Mesh.getScreenQuad();this._morphtarget_vertices_texture.drawTo(function(){gl.clearColor(0,0,0,0);gl.clear(gl.COLOR_BUFFER_BIT);for(var a=0;a<g.length;++a)g[a].vertices.bind(1),l.uniforms({u_weight:g[a].weight}),
  l.draw(p,gl.TRIANGLES)});f._texture.bind(0);this._morphtarget_normals_texture.drawTo(function(){gl.clearColor(0,0,0,0);gl.clear(gl.COLOR_BUFFER_BIT);for(var a=0;a<g.length;++a)g[a].normals.bind(1),l.uniforms({u_weight:g[a].weight}),l.draw(p,gl.TRIANGLES)});gl.disable(gl.BLEND);d=d.data.length/3;if(!this._ids_buffer||this._ids_buffer.data.length!=d){f=new Float32Array(d);for(c=0;c<d;++c)f[c]=c;this._ids_buffer=new GL.Buffer(gl.ARRAY_BUFFER,f,1,gl.STATIC_DRAW);this._ids_buffer.attribute="a_morphing_ids"}a.uniforms.u_morph_vertices_texture=
  e.Renderer.MORPHS_TEXTURE_SLOT;a.samplers[e.Renderer.MORPHS_TEXTURE_SLOT]=this._morphtarget_vertices_texture;a.uniforms.u_morph_normals_texture=e.Renderer.MORPHS_TEXTURE2_SLOT;a.samplers[e.Renderer.MORPHS_TEXTURE2_SLOT]=this._morphtarget_normals_texture;a.uniforms.u_morph_texture_size=this._texture_size;a.vertex_buffers.a_morphing_ids=this._ids_buffer;delete a.query.macros.USE_MORPHING_STREAMS;a.query.macros.USE_MORPHING_TEXTURE=""};L._blend_shader_fragment_code="\n\tprecision highp float;\n\tuniform sampler2D u_base_texture;\n\tuniform sampler2D u_morph_texture;\n\tuniform float u_weight;\n\tvarying vec2 v_coord;\n\tvoid main() {\n\t\tgl_FragColor = u_weight * ( texture2D(u_morph_texture, v_coord) - texture2D(u_base_texture, v_coord) );\n\t\tgl_FragColor.w = 1.0;\n\t}\n";
  L.prototype.getMorphTextureShader=function(){this._blend_shader||(this._blend_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,L._blend_shader_fragment_code));return this._blend_shader};L.prototype.createGeometryTexture=function(a){a=a.data;var b=gl.getParameter(gl.MAX_TEXTURE_SIZE),c=a.length/3,b=Math.min(b,c),c=Math.ceil(c/b),d=new Float32Array(b*c*3);d.set(a);return new GL.Texture(b,c,{format:gl.RGB,type:gl.FLOAT,filter:gl.NEAREST,wrap:gl.CLAMP_TO_EDGE,pixel_data:d,no_flip:!0})};L.prototype.setMorphMesh=
  function(a,b){a>=this.morph_targets.length||(this.morph_targets[a].mesh=b)};L.prototype.setMorphWeight=function(a,b){a>=this.morph_targets.length||(this.morph_targets[a].weight=b)};L.prototype.getPropertyInfoFromPath=function(a){if("morphs"==a[0]){if(1==a.length)return{node:this._root,target:this.morph_targets,type:"object"};var b=parseInt(a[1]);if(!(b>=this.morph_targets.length)&&(a=a[2],"mesh"==a||"weight"==a))return{node:this._root,target:this.morph_targets,name:a,value:void 0!==this.morph_targets[b][a]?
  this.morph_targets[b][a]:null,type:"mesh"==a?"mesh":"number"}}};L.prototype.setPropertyValueFromPath=function(a,b,c){c=c||0;if(!(a.length<c+1)&&"morphs"==a[c]){var d=parseInt(a[c+1]);d>=this.morph_targets.length||(this.morph_targets[d][a[c+2]]=b)}};L.prototype.setProperty=function(a,b){if("enabled"==a)this.enabled=b;else if("morph"==a.substr(0,5)){a=a.substr(5);var c=a.split("_"),d=parseInt(c[0]);d<this.morph_targets.length&&("weight"==c[1]?this.morph_targets[d].weight=b:"mesh"==c[1]&&(this.morph_targets[d].mesh=
  b))}};L.prototype.getPropertiesInfo=function(){for(var a={enabled:"boolean"},b=0;b<this.morph_targets.length;b++)a["morph"+b+"_weight"]="number",a["morph"+b+"_mesh"]="Mesh";return a};e.registerComponent(L);e.MorphDeformer=L;B.icon="mini-icon-stickman.png";B.MAX_BONES=64;B.MAX_TEXTURE_BONES=128;B.gpu_skinning_supported=!0;B.icon="mini-icon-stickman.png";B.apply_to_normals_by_software=!1;B["@skeleton_root_node"]={type:"node"};B.prototype.onAddedToNode=function(a){LEvent.bind(a,"collectRenderInstances",
  this.onCollectInstances,this)};B.prototype.onRemovedFromNode=function(a){LEvent.unbind(a,"collectRenderInstances",this.onCollectInstances,this)};B.prototype.getBoneNode=function(a){var b=this._root,c=b.scene;if(!c)return null;if(this.skeleton_root_node){if(b=c.getNode(this.skeleton_root_node))return b.findNodeByName(a)}else return this.search_bones_in_parent?b.parentNode.findNode(a):c.getNode(a);return null};B.prototype.getBoneMatrix=function(a){a=this.getBoneNode(a);if(!a)return null;a._is_bone=
  !0;return a.transform.getGlobalMatrixRef()};B.prototype.getBoneMatrices=function(a){var b=this._last_bones;if(!this._last_bones||this._last_bones.length!=a.bones.length)for(var b=this._last_bones=[],c=0;c<a.bones.length;++c)b[c]=mat4.create();for(c=0;c<a.bones.length;++c){var d=b[c],f=a.bones[c],e=this.getBoneMatrix(f[0]);e?(mat4.multiply(d,e,f[1]),a.bind_matrix&&mat4.multiply(d,d,a.bind_matrix)):mat4.identity(d)}return b};B.prototype.onCollectInstances=function(a,b){if(b.length){var c=b[b.length-
  1];this.enabled?this.applySkinning(c):this.disableSkinning(c)}};B.prototype.applySkinning=function(a){var b=a.mesh;this._mesh=b;if(b.getBuffer("vertices")&&b.getBuffer("bone_indices")){if(B.gpu_skinning_supported&&!this.cpu_skinning){a.query.macros.USE_SKINNING="";var c=this.getBoneMatrices(b),d=12*c.length,b=this._u_bones;b&&b.length==d||(this._u_bones=b=new Float32Array(d));for(var f=0;f<c.length;f++)mat4.transpose(c[f],c[f]),b.set(c[f].subarray(0,12),12*f,12*(f+1));B.num_supported_uniforms>=d?
  (a.uniforms.u_bones=b,c.length>B.MAX_BONES&&(a.query.macros.MAX_BONES=c.length.toString()),a.samplers[e.Renderer.BONES_TEXTURE_SLOT]=null,a.shader_blocks[0]={block:e.SkinDeformer.skinning_block,uniforms:{u_bones:b}}):0<B.num_supported_textures?(f=this._bones_texture,f||(f=this._bones_texture=new GL.Texture(1,3*B.MAX_TEXTURE_BONES,{format:gl.RGBA,type:gl.FLOAT,filter:gl.NEAREST}),f._data=new Float32Array(f.width*f.height*4)),f._data.set(b),f.uploadData(f._data,{no_flip:!0}),e.RM.textures[":bones_"+
  this.uid]=f,a.uniforms.u_bones=e.Renderer.BONES_TEXTURE_SLOT,a.query.macros.USE_SKINNING_TEXTURE="",a.samplers[e.Renderer.BONES_TEXTURE_SLOT]=f):console.error("impossible to get here")}else{if(!this._skinned_mesh||this._skinned_mesh._reference!=b){this._skinned_mesh=new GL.Mesh;this._skinned_mesh._reference=b;c=b.getBuffer("vertices");d=b.getBuffer("normals");for(f in b.vertexBuffers)this._skinned_mesh.vertexBuffers[f]=b.vertexBuffers[f];for(f in b.indexBuffers)this._skinned_mesh.indexBuffers[f]=
  b.indexBuffers[f];this._skinned_mesh.createVertexBuffer("vertices","a_vertex",3,new Float32Array(c.data),gl.STREAM_DRAW);d&&this._skinned_mesh.createVertexBuffer("normals","a_normal",3,new Float32Array(d.data),gl.STREAM_DRAW)}this.applySoftwareSkinning(b,this._skinned_mesh);a.setMesh(this._skinned_mesh,this.primitive);delete a.query.macros.USE_SKINNING;delete a.query.macros.USE_SKINNING_TEXTURE;a.samplers[e.Renderer.BONES_TEXTURE_SLOT]=null}this.ignore_transform?(mat4.identity(a.matrix),a.normal_matrix.set(a.matrix)):
  this._root.transform.getGlobalMatrix(a.matrix);mat4.multiplyVec3(a.center,a.matrix,vec3.create());a.flags|=2048}};B.prototype.disableSkinning=function(a){this._mesh=null;void 0!==a.query.macros.USE_SKINNING&&(delete a.query.macros.USE_SKINNING,delete a.query.macros.USE_SKINNING_TEXTURE,delete a.samplers.u_bones)};B.prototype.getMesh=function(){return this._mesh};B.prototype.applySoftwareSkinning=function(a,b){var c=a.getBuffer("vertices").data,d=null;a.getBuffer("normals")&&(d=a.getBuffer("normals").data);
  var f=a.getBuffer("weights").data,e=a.getBuffer("bone_indices").data,h=b.getBuffer("vertices"),k=h.data,m=null,l=null;B.zero_matrix||(B.zero_matrix=new Float32Array(16));var p=B.zero_matrix;d&&(m=b.getBuffer("normals"),l=m.data);var n=this.getBoneMatrices(a);if(0==n.length)return null;for(var q=vec3.create(),r=vec3.create(),u=mat4.create(),t=0,s=k.length/3;t<s;++t){c.subarray(3*t,3*t+3);var w=e.subarray(4*t,4*t+4),G=f.subarray(4*t,4*t+4),E=k.subarray(3*t,3*t+3),w=[n[w[0]],n[w[1]],n[w[2]],n[w[3]]];
  u.set(p);mat4.scaleAndAdd(u,u,w[0],G[0]);0<G[1]&&mat4.scaleAndAdd(u,u,w[1],G[1]);0<G[2]&&mat4.scaleAndAdd(u,u,w[2],G[2]);0<G[3]&&mat4.scaleAndAdd(u,u,w[3],G[3]);mat4.multiplyVec3(E,u,c.subarray(3*t,3*t+3));if(l){var x=l.subarray(3*t,3*t+3);mat4.rotateVec3(x,u,d.subarray(3*t,3*t+3))}if(B.apply_to_normals_by_software)for(E[0]=E[1]=E[2]=0,mat4.multiplyVec3(E,w[0],r),vec3.scale(E,E,G[0]),x=1;4>x;++x)0<G[x]&&(mat4.multiplyVec3(q,w[x],r),vec3.scaleAndAdd(E,E,q,G[x]))}h.upload(gl.STREAM_DRAW);m&&m.upload(gl.STREAM_DRAW)};
  B.prototype.extractSkeleton=function(){};B.prototype.getBones=function(){var a=this._mesh;if(!a&&!a.bones)return null;var b=[],c;for(c in a.bones){var d=this.getBoneNode(a.bones[c][0]);d&&b.push(d)}return b};e.registerComponent(B);e.SkinDeformer=B;B.skinning_enabled_shader_code="\n\t//Skinning ******************* \n\t#ifndef MAX_BONES\n\t\t#define MAX_BONES 64\n\t#endif\n\t#ifdef USE_SKINNING_TEXTURE\n\t\tuniform sampler2D u_bones;\n\t#else\n\t\tuniform vec4 u_bones[ MAX_BONES * 3];\n\t#endif\n\tattribute vec4 a_weights;\n\tattribute vec4 a_bone_indices;\n\t\n\tvoid getMat(int id, inout mat4 m) {\n\t\n\t\t#ifdef USE_SKINNING_TEXTURE\n\t\t\tfloat i_max_texture_bones_offset = 1.0 / (128.0 * 3.0);\n\t\t\tm[0] = texture2D( u_bones, vec2( 0.0, (float(id*3)+0.5) * i_max_texture_bones_offset ) ); \n\t\t\tm[1] = texture2D( u_bones, vec2( 0.0, (float(id*3+1)+0.5) * i_max_texture_bones_offset ) );\n\t\t\tm[2] = texture2D( u_bones, vec2( 0.0, (float(id*3+2)+0.5) * i_max_texture_bones_offset ) );\n\t\t#else\n\t\t\tm[0] = u_bones[ id * 3];\n\t\t\tm[1] = u_bones[ id * 3 + 1];\n\t\t\tm[2] = u_bones[ id * 3 + 2];\n\t\t#endif\n\t}\n\t\n\tmat3 mat3_emu(mat4 m4) {\n\t  return mat3(\n\t\t  m4[0][0], m4[0][1], m4[0][2],\n\t\t  m4[1][0], m4[1][1], m4[1][2],\n\t\t  m4[2][0], m4[2][1], m4[2][2]);\n\t}\n\t\n\tvoid applySkinning(inout vec4 position, inout vec3 normal)\n\t{\n\t\t//toji version seems faster\n\t\tmat4 bone_matrix = mat4(0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0, 0.0,0.0,0.0,1.0);\n\t\t\n\t\tgetMat( int(a_bone_indices.x), bone_matrix );\n\t\tmat4 result = a_weights.x * bone_matrix;\n\t\tgetMat( int(a_bone_indices.y), bone_matrix);\n\t\tresult = result + a_weights.y * bone_matrix;\n\t\tgetMat( int(a_bone_indices.z), bone_matrix);\n\t\tresult = result + a_weights.z * bone_matrix;\n\t\tgetMat( int(a_bone_indices.w), bone_matrix);\n\t\tresult = result + a_weights.w * bone_matrix;\n\t\t\n\t\tposition.xyz = (position * result).xyz;\n\t\tnormal = normal * mat3_emu(result);\n\t}\n";
  B.skinning_disabled_shader_code="\nvoid applySkinning( inout vec4 position, inout vec3 normal) {}\n";Ma=new e.ShaderBlock("skinning");Ma.addCode(GL.VERTEX_SHADER,B.skinning_enabled_shader_code,B.skinning_disabled_shader_code);Ma.register();B.skinning_block=Ma;Ma=new e.ShaderBlock("skinning_texture");Ma.addCode(GL.VERTEX_SHADER,"\n#define USE_SKINNING_TEXTURE\n"+B.skinning_enabled_shader_code,B.skinning_disabled_shader_code);Ma.register();B.skinning_texture_block=Ma;Ia.icon="mini-icon-dome.png";Ia["@material"]=
  {type:e.TYPES.MATERIAL};Ia["@texture"]={type:e.TYPES.TEXTURE};Ia.prototype.onAddedToNode=function(a){LEvent.bind(a,"collectRenderInstances",this.onCollectInstances,this)};Ia.prototype.onRemovedFromNode=function(a){LEvent.unbind(a,"collectRenderInstances",this.onCollectInstances,this)};Ia.prototype.getResources=function(a){"string"==typeof this.texture&&(a[this.texture]=GL.Texture);"string"==typeof this.material&&(a[this.material]=e.Material);return a};Ia.prototype.onResourceRenamed=function(a,b,c){this.texture==
  a&&(this.texture=b)};Ia.prototype.onCollectInstances=function(a,b){if(this._root&&this.enabled){var c=this._mesh;c||(c=this._mesh=GL.Mesh.cube({size:10}));var d=this._render_instance;d||(this._render_instance=d=new e.RenderInstance(this._root,this),d.priority=100,d.onPreRender=function(a){a=e.Renderer._current_camera.getEye();mat4.identity(this.matrix);mat4.setTranslation(this.matrix,a);if(this.node.transform){var b=this.node.transform.getGlobalRotationMatrix();mat4.multiply(this.matrix,this.matrix,
  b)}vec3.copy(this.center,a)});var f=null;if(this.material)f=e.ResourcesManager.getResource(this.material);else{var g=null,g=this.use_environment?e.Renderer._current_scene.info.textures.environment:this.texture;if(!g)return;g.constructor===String&&(g=e.ResourcesManager.textures[g]);if(!g)return;f=this._material;f||(f=this._material=new e.Material({use_scene_ambient:!1}));vec3.copy(f.color,[this.intensity,this.intensity,this.intensity]);var h=f.setTexture(e.Material.COLOR,g);g&&g.texture_type==gl.TEXTURE_2D?
  (h.uvs="polar_vertex",g.bind(0),g.setParameter(gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE),g.setParameter(gl.TEXTURE_MIN_FILTER,gl.LINEAR)):h.uvs="0"}d.setMesh(c);d.flags=xa;d.applyNodeFlags();d.enableFlag(19458);d.disableFlag(268);d.setMaterial(f);b.push(d)}};e.registerComponent(Ia);e.Skybox=Ia;Ga.icon="mini-icon-bg.png";Ga["@texture"]={type:"texture"};Ga["@material_name"]={type:"material"};Ga["@blend_mode"]={type:"enum",values:e.Blend};Ga["@opacity"]={type:"number",step:0.01};Ga.prototype.onAddedToNode=
  function(a){LEvent.bind(a,"collectRenderInstances",this.onCollectInstances,this)};Ga.prototype.onRemovedFromNode=function(a){LEvent.unbind(a,"collectRenderInstances",this.onCollectInstances,this)};Ga.prototype.getResources=function(a){"string"==typeof this.texture&&(a[this.texture]=GL.Texture);return a};Ga.prototype.onResourceRenamed=function(a,b,c){this.texture==a&&(this.texture=b)};Ga.prototype.onCollectInstances=function(a,b){if(this.enabled){var c=null;this.material_name&&(c=e.ResourcesManager.materials[this.material_name]);
  if(!c){var d=this.texture;if(!d)return;d.constructor===String&&(d=e.ResourcesManager.textures[d]);c=this._material?this._material:this._material=new e.Material({use_scene_ambient:!1});c.setTexture("color",d);c.color.set(this.color);c.opacity=this.opacity;c.blend_mode=this.blend_mode}d=this._mesh;d||(d=this._mesh=GL.Mesh.plane({size:2}));var f=this._render_instance;f||(this._render_instance=f=new e.RenderInstance(this._root,this),f.priority=100);f.setMesh(d);f.setMaterial(c);f.flags=xa;f.applyNodeFlags();
  f.disableFlag(256);f.enableFlag(1024);f.enableFlag(2);f.disableFlag(8);f.disableFlag(4);f.disableFlag(1);f.enableFlag(2048);f.enableFlag(cb);b.push(f)}};e.registerComponent(Ga);ea.icon="mini-icon-collider.png";ea.BOX=e.PhysicsInstance.BOX;ea.SPHERE=e.PhysicsInstance.SPHERE;ea.MESH=e.PhysicsInstance.MESH;ea["@size"]={type:"vec3",step:0.01};ea["@center"]={type:"vec3",step:0.01};ea["@mesh"]={type:"mesh"};ea["@shape"]={type:"enum",values:{Box:ea.BOX,Sphere:ea.SPHERE,Mesh:ea.MESH}};ea.prototype.onAddedToScene=
  function(a){LEvent.bind(a,"collectPhysicInstances",this.onGetColliders,this)};ea.prototype.onRemovedFromScene=function(a){LEvent.unbind(a,"collectPhysicInstances",this.onGetColliders,this)};ea.prototype.getMesh=function(){return"string"===typeof this.mesh?e.ResourcesManager.meshes[this.mesh]:this.mesh};ea.prototype.getResources=function(a){if(this.mesh)return"string"==typeof this.mesh&&(a[this.mesh]=Mesh),a};ea.prototype.onResourceRenamed=function(a,b,c){this.mesh==a&&(this.mesh=b)};ea.prototype.onGetColliders=
  function(a,b){if(this.enabled){var c=this._PI;c||(this._PI=c=new e.PhysicsInstance(this._root,this));this._root.transform&&c.matrix.set(this._root.transform._global_matrix);c.type=this.shape;c.layers=this._root.layers;var d=null;if(c.type===e.PhysicsInstance.MESH||this.use_mesh_bounding)d=this.getMesh();c.type===e.PhysicsInstance.SPHERE?d?BBox.copy(c.oobb,d.bounding):BBox.setCenterHalfsize(c.oobb,this.center,[this.size[0],this.size[0],this.size[0]]):c.type===e.PhysicsInstance.BOX&&(d?BBox.copy(c.oobb,
  d.bounding):BBox.setCenterHalfsize(c.oobb,this.center,this.size));d?vec3.copy(c.center,BBox.getCenter(d.bounding)):vec3.copy(c.center,this.center);vec3.transformMat4(c.center,c.center,c.matrix);if(c.type===e.PhysicsInstance.MESH){if(!d)return;c.setMesh(d)}b.push(c)}};e.registerComponent(ea);Ha.icon="mini-icon-bg.png";Ha.prototype.getResources=function(a){return a};Ha.prototype.addProperties=function(a){this.properties.push(a)};Ha.prototype.getProperty=function(a){for(var b=0;b<this.properties.length;b++)if(this.properties[b].name==
  a)return this.properties[b];return null};Ha.prototype.getPropertiesInfo=function(){return this.properties};Ha.prototype.updateProperty=function(a){};Ha.prototype.getPropertyInfoFromPath=function(a){a=a[0];var b=this.getProperty(a);return b?{node:this._root,target:this,name:a,value:b.value,type:b.type}:null};Ha.prototype.setPropertyValueFromPath=function(a,b,c){if(a=this.getProperty(a[c||0]))a.value&&a.value.set?a.value.set(b):a.value=b};Ha.prototype.onResourceRenamed=function(a,b,c){};e.registerComponent(Ha);
  e.CustomData=Ha;var Ta=vec3.create();Ea.icon="mini-icon-teapot.png";Ea["@texture"]={type:"texture"};Ea["@blend_mode"]={type:"enum",values:e.Blend};Ea["@atlas"]={type:"component",filter:"SpriteAtlas"};Object.defineProperty(Ea.prototype,"atlas",{set:function(a){var b=null;a&&a.constructor===String?(this._atlas=a,(b=e.GlobalScene.findComponentByUId(a))&&b.constructor!=e.Components.SpriteAtlas&&(console.warn("Atlas must be of type SpriteAtlas"),b=null)):(this._atlas=a?a.uid:null,b=a);this._atlas_component&&
  this._atlas_component!=b&&this._atlas_component.removeSprite(this);(this._atlas_component=b)&&this._atlas_component.addSprite(this)},get:function(){return this._atlas},enumerable:!0});Ea.prototype.onAddedToNode=function(a){LEvent.bind(a,"collectRenderInstances",this.onCollectInstances,this);this._atlas_component&&this._atlas_component.addSprite(this)};Ea.prototype.onRemovedFromNode=function(a){LEvent.unbind(a,"collectRenderInstances",this.onCollectInstances,this);this._atlas_component&&this._atlas_component.removeSprite(this)};
  Ea.prototype.onAddedToScene=function(a){this._atlas_component&&this._atlas_component.addSprite(this)};Ea.prototype.onRemovedFromScene=function(a){this._atlas_component&&this._atlas_component.removeSprite(this)};Ea.prototype.onCollectInstances=function(a,b){if(this.enabled&&!this._atlas&&this._root){var c=e.Components.Sprite._mesh;c||(c=e.Components.Sprite._mesh=GL.Mesh.plane());var d=this._render_instance;d||(this._render_instance=d=new e.RenderInstance(this._root,this),d.setMesh(c,gl.TRIANGLES));
  this._material||(this._material=new e.Material({shader_name:"lowglobal"}));this._material.setTexture("color",this.texture);this._material.blend_mode=this.blend_mode;d.setMaterial(this._material);this._root.transform&&d.setMatrix(this._root.transform._global_matrix);mat4.getTranslation(d.center,this._root.transform._global_matrix);Ta[0]=this.size[0]*(this.flip_x?1:-1);Ta[1]=this.size[1];Ta[2]=1;mat4.scale(d.matrix,d.matrix,Ta);d.flags=xa;d.applyNodeFlags();d.flags&=-2;this.blend_mode==e.Blend.NORMAL?
  d.disableFlag(Ya):d.enableFlag(Ya);b.push(d)}};Ea.prototype.getResources=function(a){"string"==typeof this.texture&&(a[this.texture]=GL.Texture);return a};e.registerComponent(Ea);ha.icon="mini-icon-teapot.png";ha["@texture"]={type:"texture"};ha["@areas"]={type:"texture_areas"};ha.plane_vertices=[vec3.fromValues(-0.5,0.5,0),vec3.fromValues(0.5,-0.5,0),vec3.fromValues(0.5,0.5,0),vec3.fromValues(-0.5,-0.5,0)];ha.plane_normal=vec3.fromValues(0,0,1);ha.prototype.onAddedToNode=function(a){LEvent.bind(a,
  "collectRenderInstances",this.onCollectInstances,this)};ha.prototype.onRemovedFromNode=function(a){LEvent.unbind(a,"collectRenderInstances",this.onCollectInstances,this)};ha.prototype.createMesh=function(){if(this._mesh_maxsprites!=this._max_sprites){for(var a=new Float32Array(12*this._max_sprites),b=new Float32Array(12*this._max_sprites),c=new Float32Array(8*this._max_sprites),d=new Float32Array(16*this._max_sprites),f=new Uint16Array(6*this._max_sprites),e=new Float32Array([0,0,1,1,1,0,0,1]),h=
  new Float32Array([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]),k=0,m=this._max_sprites;k<m;++k)c.set(e,8*k),d.set(h,16*k),f[6*k]=4*k,f[6*k+1]=4*k+1,f[6*k+2]=4*k+2,f[6*k+3]=4*k,f[6*k+4]=4*k+3,f[6*k+5]=4*k+1;this._mesh=new GL.Mesh;this._mesh.addBuffers({vertices:a,normals:b,coords:c,colors:d},{triangles:f},gl.STREAM_DRAW);this._mesh_maxsprites=this._max_sprites}};ha.prototype.updateMesh=function(){this._mesh||this.createMesh();for(var a=this._mesh,b=ha.plane_vertices,c=ha.plane_normal,d=a.getBuffer("vertices"),
  a=a.getBuffer("normals"),f=d.data,e=a.data,h=0,k=0,m=Math.min(this._sprites.length,this._max_sprites);k<m;++k){var l=this._sprites[k];if(l.enabled){var p=null;if(l.matrix)p=l.matrix;else if(l._root&&l._root.transform)p=l._root.transform._global_matrix;else continue;mat4.rotateVec3(Ta,p,c);for(l=0;4>l;++l){var n=12*h+3*l;vec3.transformMat4(f.subarray(n,n+3),b[l],p);e.set(Ta,n)}h+=1}}h&&(d.upload(),a.upload());this._last_index=6*h};ha.prototype.onCollectInstances=function(a,b){if(this.enabled&&this._root&&
  this._sprites.length){this.updateMesh();var c=this._mesh;if(this._last_index){var d=this._render_instance;d||(this._render_instance=d=new e.RenderInstance(this._root,this),d.setMesh(c,gl.TRIANGLES));this._material||(this._material=new e.Material({shader_name:"lowglobal"}));this._material.setTexture("COLOR",this.texture);d.setMaterial(this._material);d.flags=xa|2048;d.applyNodeFlags();d.flags&=-2;d.setRange(0,this._last_index);b.push(d)}}};ha.prototype.addSprite=function(a){-1==this._sprites.indexOf(a)&&
  this._sprites.push(a)};ha.prototype.removeSprite=function(a){a=this._sprites.indexOf(a);-1!=a&&this._sprites.splice(a,1)};ha.prototype.getResources=function(a){"string"==typeof this.texture&&(a[this.texture]=GL.Texture);return a};e.registerComponent(ha);ha.Area=function(){this._start=vec2.create();this._size=vec2.create()};ia.editor_color=[0.33,0.874,0.56,0.9];ia.onShowMainAnnotation=function(a){"undefined"!=typeof AnnotationModule&&AnnotationModule.editAnnotation(a)};ia.onShowPointAnnotation=function(a,
  b){function c(a){this.text=a}var d=a.getComponent(ia);d&&"undefined"!=typeof AnnotationModule&&AnnotationModule.showDialog(b.text,{item:b,on_close:c.bind(b),on_delete:function(a){d.removeAnnotation(a.item);e.GlobalScene.refresh()},on_focus:function(a){AnnotationModule.focusInAnnotation(a.item);d._selected=a.item}})};ia.prototype.addAnnotation=function(a){this._selected=null;this.notes.push(a)};ia.prototype.getAnnotation=function(a){return this.nodes[a]};ia.prototype.removeAnnotation=function(a){this._selected=
  null;a=this.notes.indexOf(a);-1!=a&&this.notes.splice(a,1)};ia.prototype.setStartTransform=function(){this.start_position=this.getObjectCenter()};ia.prototype.getObjectCenter=function(){var a=vec3.create(),b=this._root.getMesh();b&&b.bounding&&vec3.copy(a,BBox.getCenter(b.bounding));return this._root.transform.transformPointGlobal(a,vec3.create())};ia.prototype.serialize=function(){for(var a={text:this.text,notes:[],start_position:this.start_position},b=0;b<this.notes.length;++b){var c=this.notes[b],
  d;for(d in c)c[d].constructor==Float32Array&&Array.prototype.slice.call(c[d]);a.notes.push(c)}return a};ia.prototype.onAddedToScene=function(a){LEvent.bind(scene,"mousedown",this.onMouse.bind(this),this)};ia.prototype.onRemovedFromScene=function(a){LEvent.bind(scene,"mousedown",this.onMouse.bind(this),this)};ia.prototype.onMouse=function(a,b){if("mousedown"==b.eventType){this._screen_pos[2]=0;var c=vec3.dist(this._screen_pos,[b.canvasx,gl.canvas.height-b.canvasy,0]);if(30>c)ia.onShowMainAnnotation(this._root);
  for(var d=0;d<this.notes.length;++d){var f=this.notes[d],c=vec2.dist(f._end_screen,[b.mousex,gl.canvas.height-b.mousey]);if(30>c)return this._selected=f,ia.onShowPointAnnotation(this._root,f),!0}}};ia.prototype.renderEditor=function(a){if(this.text||this.notes.length){a=vec3.create();var b=this._root.getMesh();b&&vec3.copy(a,BBox.getCenter(b.bounding));var c=e.Renderer._current_camera,d=this._root.transform.getGlobalPosition(),f=this.getObjectCenter(),g=c.getEye(),h=c.getLocalVector([1,0,0]);a=c.getLocalVector([0,
  1,0]);var b=c.getLocalVector([0,0,1]),g=Math.tan(c.fov*DEG2RAD)*vec3.dist(d,g),k=vec3.scale(vec3.create(),a,0.2*g),h=vec3.scale(vec3.create(),h,0.2*g),m=vec3.add(vec3.create(),d,k);vec3.add(m,h,m);c.project(m,null,this._screen_pos);gl.enable(gl.BLEND);gl.enable(gl.DEPTH_TEST);e.Draw.setColor([1,1,1,1]);var h=[],k=[],l=[],p=[];this.text&&(h.push(d,m),k.push([1,1,1,0],[1,1,1,1]),window.EditorModule&&e.Draw.renderImage(m,EditorModule.icons_path+"/mini-icon-script.png",0.03*g));for(var n=this._root.transform.getGlobalMatrix(),
  d=0;d<this.notes.length;++d){var q=this.notes[d],m=mat4.multiplyVec3(vec3.create(),n,q.start),r=mat4.multiplyVec3(vec3.create(),n,q.end);q.end_world=r;l.push(r);h.push(m,r);this._selected==q?(p.push([1,1,1,1]),k.push([1,1,1,0.2],[1,1,0.8,1])):(p.push(e.Components.AnnotationComponent.editor_color),k.push([0,0,0,0.2],e.Components.AnnotationComponent.editor_color));q._end_screen=c.project(r)}if((m=this.start_position)&&1<vec3.dist(m,f))for(c=vec3.dist(m,f)/20,f=vec3.subtract(vec3.create(),f,m),vec3.normalize(f,
  f),d=0;20>d;d+=2)n=vec3.scale(vec3.create(),f,d*c),vec3.add(n,n,m),h.push(n),n=vec3.scale(vec3.create(),f,(d+1)*c),vec3.add(n,n,m),h.push(n),k.push([0,1,0,0.2],[0,1,0,1]);e.Draw.setPointSize(12);e.Draw.renderPoints(l,p);e.Draw.setColor([0,0,0,0.5]);e.Draw.setPointSize(10);e.Draw.renderPoints(l,p);e.Draw.setColor([1,1,1,1]);e.Draw.renderLines(h,k);gl.depthFunc(gl.GREATER);e.Draw.setAlpha(0.1);e.Draw.renderPoints(l,p);e.Draw.renderLines(h,k);gl.depthFunc(gl.LESS);gl.disable(gl.CULL_FACE);e.Draw.setColor(e.Components.AnnotationComponent.editor_color);
  for(d=0;d<this.notes.length;++d)q=this.notes[d],e.Draw.push(),e.Draw.fromTranslationFrontTop(q.end_world,b,a),e.Draw.translate([-1,-1,0]),e.Draw.scale([-4E-4*g,4E-4*g,4E-4*g]),f=q.text.split("\n")[0],e.Draw.renderText(f),e.Draw.pop();gl.disable(gl.BLEND)}};e.registerComponent(ia);Ua.icon="mini-icon-rotator.png";Ua.prototype.onAddedToScene=function(a){LEvent.bind(a,"update",this.onUpdate,this)};Ua.prototype.onRemovedFromScene=function(a){LEvent.unbind(a,"update",this.onUpdate,this)};Ua.prototype.onUpdate=
  function(a,b){if(this._root){var c=this._root.scene;this._default||(this._default=this._root.transform.getRotation());vec3.normalize(this.axis,this.axis);if(this.swing){var d=quat.setAxisAngle(quat.create(),this.axis,Math.sin(this.speed*c._global_time*2*Math.PI)*this.swing_amplitude*DEG2RAD);quat.multiply(this._root.transform._rotation,d,this._default);this._root.transform._dirty=!0}else this.local_space?this._root.transform.rotate(this.speed*b,this.axis):this._root.transform.rotateGlobal(this.speed*
  b,this.axis);c&&c.refresh()}};e.registerComponent(Ua);X.ORBIT=1;X.FIRSTPERSON=2;X.PLANE=3;X.icon="mini-icon-cameracontroller.png";X["@mode"]={type:"enum",values:{Orbit:X.ORBIT,FirstPerson:X.FIRSTPERSON,Plane:X.PLANE}};X.prototype.onAddedToScene=function(a){LEvent.bind(a,"mousedown",this.onMouse,this);LEvent.bind(a,"mousemove",this.onMouse,this);LEvent.bind(a,"mousewheel",this.onMouse,this);LEvent.bind(a,"keydown",this.onKey,this);LEvent.bind(a,"keyup",this.onKey,this);LEvent.bind(a,"update",this.onUpdate,
  this)};X.prototype.onRemovedFromScene=function(a){LEvent.unbindAll(a,this)};X.prototype.onUpdate=function(a){if(this._root&&this.enabled){if(!this._root.transform&&this._root.camera&&(a=this._root.camera,this.mode==X.FIRSTPERSON&&(0!=this._moving[0]||0!=this._moving[1]||0!=this._moving[2]))){var b=a.getLocalVector(this._moving);vec3.scale(b,b,this.speed*(this._move_fast?10:1));a.move(b);a.updateMatrices()}this.smooth&&this._root.scene.refresh()}};X.prototype.onMouse=function(a,b){if(this._root&&this.enabled){var c=
  this._root,d=c.camera;if(d){var f=!c.transform;b||(b=a);if("mousewheel"==b.eventType)d.orbitDistanceFactor(1+-0.05*(0<b.wheel?1:-1)*this.wheel_speed),d.updateMatrices(),c.scene.refresh();else if("mousedown"==b.eventType&&(this.mode==X.PLANE?this.testOriginPlane(b.canvasx,gl.canvas.height-b.canvasy,this._collision):this.testPerpendicularPlane(b.canvasx,gl.canvas.height-b.canvasy,d.getCenter(),this._collision),this._button=b.button),"mousemove"==b.eventType&&b.dragging){var g=!1;if(this.mode==X.FIRSTPERSON){d.rotate(-b.deltax*
  this.rot_speed,e.TOP);d.updateMatrices();var h=d.getLocalVector(e.RIGHT);f?d.rotate(-b.deltay*this.rot_speed,h):c.transform.rotate(-b.deltay*this.rot_speed,h);d.updateMatrices();g=!0}else if(this.mode==X.ORBIT)if(this.allow_panning&&(b.ctrlKey||1==b.button)){var k=vec3.create(),g=vec3.create(),h=vec3.create();d.getCenter(g);this.testPerpendicularPlane(b.canvasx,gl.canvas.height-b.canvasy,g,k);vec3.sub(h,this._collision,k);f?d.move(h):c.transform.translateGlobal(h);d.updateMatrices();g=!0}else{h=b.deltax*
  this.rot_speed;k=-b.deltay*this.rot_speed;1E-4<Math.abs(h)&&(f?d.orbit(-h,[0,1,0]):(g=d.getEye(),c.transform.globalToLocal(g,g),c.transform.orbit(-h,[0,1,0],g)),d.updateMatrices(),g=!0);var h=d.getRight(),m=d.getFront(),l=d.getUp(),m=vec3.dot(l,m);0.99<m&&0<k||-0.99>m&&0>k||(f?d.orbit(-k,h,this.orbit_center):(g=d.getEye(),c.transform.globalToLocal(g,g),c.transform.orbit(-k,h,g)),g=!0)}else this.mode==X.PLANE&&(2==this._button?(g=vec3.create(),d.getCenter(g),f?d.orbit(-b.deltax*this.rot_speed,e.TOP,
  g):c.transform.orbit(-b.deltax*this.rot_speed,e.TOP,g)):(k=vec3.create(),h=vec3.create(),this.testOriginPlane(b.canvasx,gl.canvas.height-b.canvasy,k),vec3.sub(h,this._collision,k),f?d.move(h):c.transform.translateGlobal(h),d.updateMatrices()),g=!0);g&&this._root.scene.refresh()}}}};X.prototype.testOriginPlane=function(a,b,c){a=this._root.camera.getRayInPixel(a,gl.canvas.height-b);c=c||vec3.create();return geo.testRayPlane(a.origin,a.direction,e.ZEROS,e.TOP,c)?!0:!1};X.prototype.testPerpendicularPlane=
  function(a,b,c,d){var f=this._root.camera;a=f.getRayInPixel(a,gl.canvas.height-b);b=f.getFront();c=c||f.getCenter();d=d||vec3.create();return geo.testRayPlane(a.origin,a.direction,c,b,d)?!0:!1};X.prototype.onKey=function(a,b){this._root&&this.enabled&&(87==b.keyCode?this._moving[2]="keydown"==b.type?-1:0:83==b.keyCode?this._moving[2]="keydown"==b.type?1:0:65==b.keyCode?this._moving[0]="keydown"==b.type?-1:0:68==b.keyCode?this._moving[0]="keydown"==b.type?1:0:16==b.keyCode&&(this._move_fast="keydown"==
  b.type?!0:!1))};e.registerComponent(X);Ra.icon="mini-icon-rotator.png";Ra.prototype.onAddedToNode=function(a){LEvent.bind(a,"mousemove",this.onMouse,this);LEvent.bind(a,"update",this.onUpdate,this)};Ra.prototype.onRemovedFromNode=function(a){LEvent.unbind(a,"mousemove",this.onMouse,this);LEvent.unbind(a,"update",this.onUpdate,this)};Ra.prototype.onUpdate=function(a){};Ra.prototype.onMouse=function(a,b){if(this._root&&this._root.transform&&b.dragging){var c=this._root.scene,d=c.getCamera().getLocalVector(e.Components.Transform.RIGHT);
  this._root.transform.rotateGlobal(b.deltax*this.rot_speed[0],e.Components.Transform.UP);this._root.transform.rotateGlobal(b.deltay*this.rot_speed[1],d);c.refresh()}};e.registerComponent(Ra);H.icon="mini-icon-billboard.png";H.POSX=1;H.NEGX=2;H.POSY=3;H.NEGY=4;H.POSZ=5;H.NEGZ=6;H["@node_id"]={type:"node"};H["@front"]={type:"enum",values:{"-Z":H.NEGZ,"+Z":H.POSZ,"-Y":H.NEGY,"+Y":H.POSY,"-X":H.NEGX,"+X":H.POSX}};H["@up"]={type:"enum",values:{"-Z":H.NEGZ,"+Z":H.POSZ,"-Y":H.NEGY,"+Y":H.POSY,"-X":H.NEGX,
  "+X":H.POSX}};H.prototype.onAddedToNode=function(a){LEvent.bind(a,"computeVisibility",this.updateOrientation,this)};H.prototype.onRemovedFromNode=function(a){LEvent.unbind(a,"computeVisibility",this.updateOrientation,this)};H.prototype.updateOrientation=function(a){if(this.enabled&&this._root&&this._root.transform){var b=this._root.scene;a=this._root.transform;var c=null,d=null,f=a.getGlobalPosition();switch(this.up){case H.NEGX:d=vec3.fromValues(-1,0,0);break;case H.POSX:d=vec3.fromValues(1,0,0);
  break;case H.NEGZ:d=vec3.fromValues(0,0,-1);break;case H.POSZ:d=vec3.fromValues(0,0,1);break;case H.NEGY:d=vec3.fromValues(0,-1,0);break;default:d=vec3.fromValues(0,1,0)}if(this.node_id){b=b.getNode(this.node_id);if(!b||b==this._root)return;c=b.transform.getGlobalPosition(this._target_position)}else if(this.face_camera){b=e.Renderer._main_camera||e.Renderer._current_camera;if(!b)return;c=b.getEye()}else return;this.cylindrical&&(c[1]=f[1]);a.lookAt(f,c,d,!0);switch(this.front){case H.POSY:quat.rotateX(a._rotation,
  a._rotation,-0.5*Math.PI);break;case H.NEGY:quat.rotateX(a._rotation,a._rotation,0.5*Math.PI);break;case H.POSX:quat.rotateY(a._rotation,a._rotation,0.5*Math.PI);break;case H.NEGX:quat.rotateY(a._rotation,a._rotation,-0.5*Math.PI);break;case H.POSZ:quat.rotateY(a._rotation,a._rotation,Math.PI)}}};e.registerComponent(H);fa.icon="mini-icon-fog.png";fa.LINEAR=1;fa.EXP=2;fa.EXP2=3;fa["@color"]={type:"color"};fa["@density"]={type:"number",min:0,max:1,step:1E-4,precision:4};fa["@type"]={type:"enum",values:{linear:fa.LINEAR,
  exponential:fa.EXP,"exponential 2":fa.EXP2}};fa.prototype.onAddedToScene=function(a){LEvent.bind(a,"fillSceneQuery",this.fillSceneQuery,this);LEvent.bind(a,"fillSceneUniforms",this.fillSceneUniforms,this)};fa.prototype.onRemovedFromScene=function(a){LEvent.unbind(a,"fillSceneQuery",this.fillSceneQuery,this);LEvent.unbind(a,"fillSceneUniforms",this.fillSceneUniforms,this)};fa.prototype.fillSceneQuery=function(a,b){if(this.enabled)switch(b.macros.USE_FOG="",this.type){case fa.EXP:b.macros.USE_FOG_EXP=
  "";break;case fa.EXP2:b.macros.USE_FOG_EXP2=""}};fa.prototype.fillSceneUniforms=function(a,b){this.enabled&&(b.u_fog_info=[this.start,this.end,this.density],b.u_fog_color=this.color)};e.registerComponent(fa);Va.icon="mini-icon-follow.png";Va.prototype.onAddedToScene=function(a){LEvent.bind(a,"beforeRender",this.updatePosition,this)};Va.prototype.onRemovedFromScene=function(a){LEvent.unbind(a,"beforeRender",this.updatePosition,this)};Va.prototype.updatePosition=function(a,b){if(this._root){var c=null,
  c=this._root.scene;if(this.follow_camera){c=e.Renderer._main_camera;if(!c)return;c=c.getEye()}else{c=c.getNode(this.node_uid);if(!c||!c.transform)return;c=c.transform.getGlobalPosition()}this.fixed_y&&(c[1]=this._root.transform._position[1]);this._root.transform&&(this._root.transform.position=c)}};e.registerComponent(Va);Object.defineProperty(J.prototype,"primitive",{get:function(){return this._primitive},set:function(a){a=void 0===a||null===a?-1:a|0;if(-1==a||0==a||1==a||4==a||10==a)this._primitive=
  a},enumerable:!0});Object.defineProperty(J.prototype,"geometry",{get:function(){return this._geometry},set:function(a){a=void 0===a||null===a?-1:a|0;0>a||7<a||(this._geometry=a)},enumerable:!0});J.CUBE=1;J.PLANE=2;J.CYLINDER=3;J.SPHERE=4;J.CIRCLE=5;J.HEMISPHERE=6;J.ICOSAHEDRON=7;J.icon="mini-icon-cube.png";J["@geometry"]={type:"enum",values:{Cube:J.CUBE,Plane:J.PLANE,Cylinder:J.CYLINDER,Sphere:J.SPHERE,Icosahedron:J.ICOSAHEDRON,Circle:J.CIRCLE,Hemisphere:J.HEMISPHERE}};J["@primitive"]={widget:"enum",
  values:{Default:-1,Points:0,Lines:1,Triangles:4,Wireframe:10}};J["@subdivisions"]={type:"number",step:1,min:0};J["@point_size"]={type:"number",step:0.001};J.prototype.onAddedToNode=function(a){LEvent.bind(a,"collectRenderInstances",this.onCollectInstances,this)};J.prototype.onRemovedFromNode=function(a){LEvent.unbind(a,"collectRenderInstances",this.onCollectInstances,this)};J.prototype.updateMesh=function(){var a=Math.max(0,this.subdivisions|0),b=""+this.geometry+"|"+this.size+"|"+a+"|"+this.align_z;
  switch(this.geometry){case J.CUBE:this._mesh=GL.Mesh.cube({size:this.size,normals:!0,coords:!0});break;case J.PLANE:this._mesh=GL.Mesh.plane({size:this.size,detail:a,xz:this.align_z,normals:!0,coords:!0});break;case J.CYLINDER:this._mesh=GL.Mesh.cylinder({size:this.size,subdivisions:a,normals:!0,coords:!0});break;case J.SPHERE:this._mesh=GL.Mesh.sphere({size:this.size,"long":a,lat:a,normals:!0,coords:!0});break;case J.CIRCLE:this._mesh=GL.Mesh.circle({size:this.size,slices:a,xz:this.align_z,normals:!0,
  coords:!0});break;case J.HEMISPHERE:this._mesh=GL.Mesh.sphere({size:this.size,slices:a,xz:this.align_z,normals:!0,coords:!0,hemi:!0});break;case J.ICOSAHEDRON:this._mesh=GL.Mesh.icosahedron({size:this.size,subdivisions:a})}this._key=b};J.prototype.onCollectInstances=function(a,b){if(this.enabled&&this._root){var c=Math.max(0,this.subdivisions|0),c=""+this.geometry+"|"+this.size+"|"+c+"|"+this.align_z;this._mesh&&this._key==c||this.updateMesh();c=this._render_instance;c||(this._render_instance=c=new e.RenderInstance(this._root,
  this));this._root.transform&&this._root.transform.getGlobalMatrix(c.matrix);c.setMatrix(c.matrix);mat4.getTranslation(c.center,c.matrix);c.setMesh(this._mesh,this.primitive);this._root.mesh=this._mesh;c.flags=xa|65536;c.applyNodeFlags();c.setMaterial(this.material||this._root.getMaterial());this.primitive==gl.POINTS&&(c.uniforms.u_point_size=this.point_size,c.query.macros.USE_POINTS="");b.push(c)}};e.registerComponent(J);Object.defineProperty(wa.prototype,"textures",{set:function(a){if("object"==
  typeof a)for(var b in a)if(null===a[b]||a[b].constructor===String||a[b]===GL.Texture)this._textures[b]=a[b]},get:function(){return this._textures},enumerable:!0});Object.defineProperty(wa.prototype,"render_settings",{set:function(a){"object"==typeof a&&this._render_settings.configure(a)},get:function(){return this._render_settings},enumerable:!0});wa.icon="mini-icon-bg.png";wa.DEFAULT_AMBIENT_COLOR=vec3.fromValues(0.2,0.2,0.2);wa.prototype.onAddedToScene=function(a){a.info=this};wa.prototype.onRemovedFromScene=
  function(a){};wa.prototype.getResources=function(a){for(var b in this._textures)"string"==typeof this._textures[b]&&(a[this._textures[b]]=GL.Texture);return a};wa.prototype.getPropertiesInfo=function(){return{ambient_color:"color","textures/environment":"texture","textures/irradiance":"texture",render_settings:"RenderSettings"}};wa.prototype.setProperty=function(a,b){if("textures/"==a.substr(0,9)&&(!b||b.constructor===String||b.constructor===GL.Texture))return this._textures[a.substr(9)]=b,!0};wa.prototype.getPropertyInfoFromPath=
  function(a){if("textures"==a[0]){if(1==a.length)return{node:this._root,target:this._textures,type:"object"};a=a[1];return{node:this._root,target:this._textures,name:a,value:this._textures[a]||null,type:"texture"}}};wa.prototype.setPropertyValueFromPath=function(a,b,c){c=c||0;a.length<c+1||"textures"==a[c]&&(this._textures[a[c+1]]=b)};wa.prototype.onResourceRenamed=function(a,b,c){for(var d in this._textures)this._textures[d]==a&&(this._textures[d]=b)};e.registerComponent(wa);e.GlobalInfo=wa;"undefined"!=
  typeof LGraphTexture&&(LGraphTexture.getTexturesContainer=function(){return e.ResourcesManager.textures},LGraphTexture.loadTexture=e.ResourcesManager.load.bind(e.ResourcesManager));na["@on_event"]={type:"enum",values:["start","render","update","trigger"]};na.icon="mini-icon-graph.png";na.prototype.configure=function(a){this.uid=a.uid;this.enabled=!!a.enabled;if(a.graph_data)if(e.catch_exceptions)try{var b=JSON.parse(a.graph_data);this._graph.configure(b)}catch(c){console.error("Error configuring Graph data: "+
  c)}else b=JSON.parse(a.graph_data),this._graph.configure(b);a.on_event&&(this.on_event=a.on_event);a.force_redraw&&(this.force_redraw=a.force_redraw)};na.prototype.serialize=function(){return{uid:this.uid,enabled:this.enabled,force_redraw:this.force_redraw,graph_data:JSON.stringify(this._graph.serialize()),on_event:this.on_event}};na.prototype.onAddedToNode=function(a){this._graph._scenenode=a;this._default_node&&(this._default_node.properties.node_id=a.uid)};na.prototype.onRemovedFromNode=function(a){this._graph._scenenode=
  null};na.prototype.onAddedToScene=function(a){this._graph._scene=a;LEvent.bind(a,"init",this.onSceneEvent,this);LEvent.bind(a,"start",this.onSceneEvent,this);LEvent.bind(a,"beforeRenderMainPass",this.onSceneEvent,this);LEvent.bind(a,"update",this.onSceneEvent,this)};na.prototype.onRemovedFromScene=function(a){this._graph._scene=null;LEvent.unbind(a,"init",this.onSceneEvent,this);LEvent.unbind(a,"start",this.onSceneEvent,this);LEvent.unbind(a,"beforeRenderMainPass",this.onSceneEvent,this);LEvent.unbind(a,
  "update",this.onSceneEvent,this)};na.prototype.onResourceRenamed=function(a,b,c){this._graph.sendEventToAllNodes("onResourceRenamed",[a,b,c])};na.prototype.onSceneEvent=function(a,b){"beforeRenderMainPass"==a&&(a="render");"init"==a&&this._graph.sendEventToAllNodes("onInit");"start"==a&&this._graph.sendEventToAllNodes("onStart");this.on_event==a&&this.runGraph()};na.prototype.trigger=function(a){"trigger"==this.on_event&&this.runGraph()};na.prototype.runGraph=function(){this._root._in_tree&&this.enabled&&
  (this._graph&&this._graph.runStep(1),this.force_redraw&&this._root.scene.refresh())};na.prototype.getGraph=function(){return this._graph};na.prototype.getPropertyValue=function(a){var b=this._graph.findNodesByType("scene/global");if(b.length)for(var c=0;c<b.length;++c){var d=b[c];if(d.properties.name==a)return d.properties.value}};na.prototype.setPropertyValue=function(a,b){var c=this._graph.findNodesByType("scene/global");if(c.length)for(var d=0;d<c.length;++d){var f=c[d];if(f.properties.name==a)return f.properties.value&&
  f.properties.value.set?f.properties.value.set(b):f.properties.value=b,!0}};e.registerComponent(na);V.icon="mini-icon-graph.png";V.buffer_size=[1024,512];V.prototype.configure=function(a){if(a.graph_data&&(this.uid=a.uid,this.enabled=!!a.enabled,this.use_antialiasing=!!a.use_antialiasing,this.use_node_camera=!!a.use_node_camera,a.frame&&this.frame.configure(a.frame),this._graph.configure(JSON.parse(a.graph_data)),this._graph_frame_node=this._graph.findNodesByTitle("Rendered Frame")[0],this._graph_viewport_node=
  this._graph.findNodesByType("texture/toviewport")[0],!this._graph_frame_node)){console.log("CONVERTING LEGACY DATA TO NEW FORMAT");this._graph_frame_node=LiteGraph.createNode("scene/frame","Rendered Frame");this._graph_frame_node.ignore_remove=!0;this._graph_frame_node.ignore_rename=!0;this._graph.add(this._graph_frame_node);a=["Color Buffer","Depth Buffer","Extra Buffer"];for(var b=0;b<a.length;++b){var c=this._graph.findNodesByTitle(a[b])[0];if(c){var d=c.getOutputInfo(0);if(d.links){var d=d.links.concat(),
  f;for(f in d){var e=this._graph.links[d[f]];e&&this._graph_frame_node.connect(b,e.target_id,e.target_slot)}this._graph.remove(c)}}}}};V.prototype.serialize=function(){return{uid:this.uid,enabled:this.enabled,use_antialiasing:this.use_antialiasing,frame:this.frame.serialize(),use_node_camera:this.use_node_camera,graph_data:JSON.stringify(this._graph.serialize())}};V.prototype.getResources=function(a){var b=this._graph.findNodesByType("texture/texture"),c;for(c in b)b[c].properties.name&&(a[b[c].properties.name]=
  Texture);return a};V.prototype.getPropertyValue=function(a){var b=this._graph.findNodesByType("scene/global");if(b.length)for(var c=0;c<b.length;++c){var d=b[c];if(d.properties.name==a)return d.properties.value}};V.prototype.setPropertyValue=function(a,b){var c=this._graph.findNodesByType("scene/global");if(c.length)for(var d=0;d<c.length;++d){var f=c[d];if(f.properties.name==a)return f.properties.value&&f.properties.value.set?f.properties.value.set(b):f.properties.value=b,!0}};V.prototype.getGraph=
  function(){return this._graph};V.prototype.onResourceRenamed=function(a,b,c){this._graph.sendEventToAllNodes("onResourceRenamed",[a,b,c])};V.prototype.onAddedToNode=function(a){this._graph._scenenode=a};V.prototype.onRemovedFromNode=function(a){this._graph._scenenode=null};V.prototype.onAddedToScene=function(a){this._graph._scene=a;LEvent.bind(a,"enableFrameContext",this.onBeforeRender,this);LEvent.bind(a,"showFrameContext",this.onAfterRender,this)};V.prototype.onRemovedFromScene=function(a){this._graph._scene=
  null;LEvent.unbind(a,"enableFrameContext",this.onBeforeRender,this);LEvent.unbind(a,"showFrameContext",this.onAfterRender,this);e.ResourcesManager.unregisterResource(":color_"+this.uid);e.ResourcesManager.unregisterResource(":depth_"+this.uid);e.ResourcesManager.unregisterResource(":extra_"+this.uid)};V.prototype.onBeforeRender=function(a,b){this._last_camera=e.Renderer._current_camera;if(this.enabled)if(this.use_node_camera){var c=this._root.camera;c&&c!=this._binded_camera&&(this._binded_camera&&
  LEvent.unbindAll(this._binded_camera,this),LEvent.bind(c,"enableFrameContext",this.enableCameraFBO,this),LEvent.bind(c,"showFrameContext",this.showCameraFBO,this));this._binded_camera=c}else this._binded_camera&&(LEvent.unbindAll(this._binded_camera,this),this._binded_camera=null),this.enableGlobalFBO(b);else this._binded_camera&&(LEvent.unbindAll(this._binded_camera,this),this._binded_camera=null)};V.prototype.onAfterRender=function(a,b){this.enabled&&(this.use_node_camera||this.showFBO())};V.prototype.enableCameraFBO=
  function(a,b){if(this.enabled){var c=this._viewport=this._binded_camera.getLocalViewport(null,this._viewport);this.frame.enable(b,c);b.ignore_viewports=!0}};V.prototype.showCameraFBO=function(a,b){this.enabled&&(b.ignore_viewports=!1,this.showFBO())};V.prototype.enableGlobalFBO=function(a){this.enabled&&this.frame.enable(a)};V.prototype.showFBO=function(){if(this.enabled){this.frame.disable();e.ResourcesManager.textures[":color_"+this.uid]=this.frame._color_texture;e.ResourcesManager.textures[":depth_"+
  this.uid]=this.frame._depth_texture;if(this.frame.num_extra_textures)for(var a=0;a<this.frame.num_extra_textures;++a)e.ResourcesManager.textures[":extra"+a+"_"+this.uid]=this.frame._textures[a+1];this.use_node_camera&&this._viewport?(gl.setViewport(this._viewport),this.applyGraph(),gl.setViewport(this.frame._fbo._old_viewport)):this.applyGraph()}};V.prototype.applyGraph=function(){this._graph&&(this._graph_frame_node||(this._graph_frame_node=this._graph.findNodesByTitle("Rendered Frame")[0]),this._graph_frame_node._color_texture=
  ":color_"+this.uid,this._graph_frame_node._depth_texture=":depth_"+this.uid,this._graph_frame_node._extra_texture=":extra0_"+this.uid,this._graph_frame_node._camera=this._last_camera,this._graph_viewport_node&&(this._graph_viewport_node.properties.filter=this.frame.filter_texture,this._graph_viewport_node.properties.antialiasing=this.use_antialiasing),this._graph.runStep(1))};e.registerComponent(V);(function(){function a(a){this.value=0;this.delta=0.01;this.min_value=this.steps=0;this.max_value=1;
  this.min_angle=-120;this.max_angle=120;this.axis=vec3.fromValues(0,0,1);this._dragging=!1;a&&this.configure(a)}a.icon="mini-icon-knob.png";a.prototype.onAddedToScene=function(a){LEvent.bind(a,"mousedown",this.onMouse,this);LEvent.bind(a,"mouseup",this.onMouse,this);LEvent.bind(a,"mousemove",this.onMouse,this);this.updateKnob()};a.prototype.onRemovedFromScene=function(a){LEvent.unbindAll(a,this)};a.prototype.updateKnob=function(){this._root&&(quat.setAxisAngle(this._root.transform._rotation,this.axis,
  (this.min_angle+this.value/(this.max_value-this.min_value)*(this.max_angle-this.min_angle))*DEG2RAD),this._root.transform.mustUpdate=!0)};a.prototype.onMouse=function(a,c){if("mousedown"==a){if(this._root&&this._root._instances&&this._root._instances.length){var d=this._root._instances[0],f=e.Renderer.getCameraAtPosition(c.canvasx,c.canvasy);f&&(f=f.getRayInPixel(c.canvasx,c.canvasy))&&(this._dragging=geo.testRayBBox(f.origin,f.direction,d.aabb))}}else if("mouseup"==a)this._dragging=!1;else if(c.dragging&&
  this._dragging)return this.value-=c.deltay*this.delta,this.value>this.max_value?this.value=this.max_value:this.value<this.min_value&&(this.value=this.min_value),this.updateKnob(),LEvent.trigger(this,"change",this.value),this._root&&LEvent.trigger(this._root,"knobChange",this.value),!1};e.registerComponent(a)})();Object.defineProperty($a.prototype,"pos",{get:function(){return this._pos},set:function(a){this._pos.set(a)},enumerable:!0});Object.defineProperty($a.prototype,"vel",{get:function(){return this._vel},
  set:function(a){this._vel.set(a)},enumerable:!0});O.BOX_EMISSOR=1;O.SPHERE_EMISSOR=2;O.MESH_EMISSOR=3;O.CUSTOM_EMISSOR=10;O["@emissor_type"]={type:"enum",values:{Box:O.BOX_EMISSOR,Sphere:O.SPHERE_EMISSOR,Mesh:O.MESH_EMISSOR,Custom:O.CUSTOM_EMISSOR}};O.icon="mini-icon-particles.png";Object.defineProperty(O.prototype,"particle_start_color",{get:function(){return this._particle_start_color},set:function(a){a&&this._particle_start_color.set(a)},enumerable:!0});Object.defineProperty(O.prototype,"particle_end_color",
  {get:function(){return this._particle_end_color},set:function(a){a&&this._particle_end_color.set(a)},enumerable:!0});Object.defineProperty(O.prototype,"custom_emissor_code",{get:function(){return this._custom_emissor_code},set:function(a){this._custom_emissor_code=a=M.cleanCode(a);try{this._custom_emissor_func=a&&a.length?new Function("p",a):null}catch(b){console.error("Error in ParticleEmissor custom emissor code: ",b)}},enumerable:!0});Object.defineProperty(O.prototype,"custom_update_code",{get:function(){return this._custom_update_code},
  set:function(a){this._custom_update_code=a=M.cleanCode(a);try{this._custom_update_func=a&&a.length?new Function("p","dt",a):null}catch(b){console.error("Error in ParticleEmissor custom emissor code: ",b)}},enumerable:!0});O.prototype.onAddedToScene=function(a){LEvent.bind(a,"update",this.onUpdate,this);LEvent.bind(a,"start",this.onStart,this);LEvent.bind(a,"collectRenderInstances",this.onCollectInstances,this);LEvent.bind(a,"afterCameraEnabled",this.onAfterCamera,this)};O.prototype.onRemovedFromScene=
  function(a){LEvent.unbindAll(a,this)};O.prototype.getResources=function(a){this.emissor_mesh&&(a[this.emissor_mesh]=Mesh);this.texture&&(a[this.texture]=Texture)};O.prototype.onResourceRenamed=function(a,b,c){this.emissor_mesh==a&&(this.emissor_mesh=b);this.texture==a&&(this.texture=b)};O.prototype.onAfterCamera=function(a,b){this.enabled&&this.align_always&&this.updateMesh(b)};O.prototype.createParticle=function(a){a=a||new $a;switch(this.emissor_type){case O.BOX_EMISSOR:a._pos.set([this.emissor_size[0]*
  (Math.random()-0.5),this.emissor_size[1]*(Math.random()-0.5),this.emissor_size[2]*(Math.random()-0.5)]);break;case O.SPHERE_EMISSOR:var b=2*Math.PI*Math.random(),c=Math.acos(2*Math.random()-1);a._pos.set([Math.sin(c)*Math.cos(b),Math.sin(c)*Math.sin(b),Math.cos(c)]);vec3.multiply(a.pos,a.pos,this.emissor_size);break;case O.MESH_EMISSOR:(b=this.emissor_mesh)&&b.constructor===String&&(b=e.ResourcesManager.getMesh(this.emissor_mesh)),b&&b.getBuffer("vertices")?(b=b.getBuffer("vertices").data,c=3*Math.floor(Math.random()*
  b.length/3),a._pos.set([b[c]+0.001*Math.random(),b[c+1]+0.001*Math.random(),b[c+2]+0.001*Math.random()])):a._pos.set([0,0,0])}a._vel.set([Math.random()-0.5,Math.random()-0.5,Math.random()-0.5]);a.life=this.particle_life;a.id=this._last_id;a.angle=0;a.size=1;a.rot=this.particle_rotation+0.25*this.particle_rotation*Math.random();this._last_id+=1;this.independent_color&&(a.c=vec3.clone(this.particle_start_color));vec3.scale(a._vel,a._vel,this.particle_speed);this.emissor_type==O.CUSTOM_EMISSOR&&this._custom_emissor_func&&
  this._custom_emissor_func.call(this,a);this.follow_emitter||vec3.add(a._pos,a._pos,this._emissor_pos);return a};O.prototype.onStart=function(a){if(this.enabled&&!(0>=this.warm_up_time)){a=1/30;for(var b=0;b<this.warm_up_time;b+=a)this.onUpdate(null,a,!0)}};O.prototype.onUpdate=function(a,b,c){if(this.enabled){if(!this._root.scene)throw"update without scene? impossible";this._root.transform&&this._root.transform.getGlobalPosition(this._emissor_pos);0>this.emissor_rate&&(this.emissor_rate=0);if(!this.stop_update){var d=
  vec3.clone(this.physics_gravity),f=this.physics_friction;a=[];for(var g=vec3.create(),h=0,k=this._particles.length;h<k;++h){var m=this._particles[h];vec3.copy(g,m._vel);vec3.add(g,d,g);vec3.scale(g,g,b);f&&(g[0]-=g[0]*f,g[1]-=g[1]*f,g[2]-=g[2]*f);vec3.add(m._pos,g,m._pos);m.angle+=m.rot*b;m.life-=b;this._custom_update_func&&this._custom_update_func.call(this,m,b);0<m.life&&a.push(m)}if(0!=this.emissor_rate)for(b=(b+this._remining_dt)*this.emissor_rate,this._remining_dt=b%1/this.emissor_rate,b<<=0,
  b>this.max_particles&&(b=this.max_particles),h=0;h<b;h++)m=this.createParticle(),a.length<this.max_particles&&a.push(m);this._particles=a}this.align_always||c||this.updateMesh(e.Renderer._current_camera);LEvent.trigger(this._root.scene,"change")}};O.prototype.createMesh=function(){if(this._mesh_maxparticles!=this.max_particles){this._vertices=new Float32Array(18*this.max_particles);this._coords=new Float32Array(12*this.max_particles);this._colors=new Float32Array(24*this.max_particles);this._extra2=
  new Float32Array(2*this.max_particles);for(var a=[1,1,0,1,1,0,0,1,0,0,1,0],b=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],c=0;c<this.max_particles;c++)this._coords.set(a,12*c),this._colors.set(b,24*c),this._extra2[2*c]=1,this._extra2[2*c+1]=c;this._computed_grid_size=1;this._mesh=new GL.Mesh;this._mesh.addBuffers({vertices:this._vertices,coords:this._coords,colors:this._colors,extra2:this._extra2},null,gl.STREAM_DRAW);this._mesh_maxparticles=this.max_particles}};O.prototype.updateMesh=function(a){if(a){this._mesh_maxparticles!=
  this.max_particles&&this.createMesh();var b=a.getEye(),c=this._min_particle_size,d=a.getLocalVector([0,0,1]),f=a.getLocalVector([1,0,0]),g=a.getLocalVector([0,1,0]);a=vec3.create();var h=vec3.fromValues(-1,0,-1),k=vec3.fromValues(1,0,-1),m=vec3.fromValues(-1,0,1),l=vec3.fromValues(1,0,1);this.align_with_camera&&(vec3.subtract(h,g,f),vec3.add(k,g,f),vec3.scale(m,k,-1),vec3.scale(l,h,-1));var f=vec3.create(),g=vec3.create(),p=vec3.create(),n=vec3.create(),q=this._particles;if(this.sort_in_z){for(var q=
  this._particles.concat(),r=geo.createPlane(b,d),u=1/Math.sqrt(r[0]*r[0]+r[1]*r[1]+r[2]*r[2]),b=0;b<q.length;++b)q[b]._dist=Math.abs(vec3.dot(q[b]._pos,r)+r[3])*u;q.sort(function(a,b){return a._dist<b._dist?1:a._dist>b._dist?-1:0});this._particles=q}0==this.particle_life&&(this.particle_life=1E-4);var r=new Float32Array([1,1,1,1]),u=this._particle_start_color,t=this._particle_end_color,s=!1;if(this._computed_grid_size!=this.texture_grid_size||1<this.texture_grid_size||this.point_particles)s=!0,this._computed_grid_size=
  this.texture_grid_size;for(var w=1/this.texture_grid_size,G=0,E=0,x=this.texture_grid_size<<2,y=this.animated_texture,z=this.loop_animation,A=this._root.scene.getTime()*this.animation_fps,C=new Float32Array(60*this.particle_life<<0),B=new Float32Array(60*this.particle_life<<0),I=this.particle_size,H=1/(60*this.particle_life),b=0;b<C.length;b+=1)C[b]=e.getCurveValueAt(this.particle_opacity_curve,0,1,0,b*H),B[b]=e.getCurveValueAt(this.particle_size_curve,0,1,0,b*H);for(var H=this.point_particles,K=
  this._vertices.length,F=this._vertices,J=this._colors,O=this._extra2,M=this._coords,N=quat.create(),P=G=b=0,L=q.length;P<L;++P)if(E=q[P],!(0>=E.life)){var G=1-E.life/this.particle_life,D=C[G*C.length<<0];this.independent_color&&E.c?vec3.clone(r,E.c):vec3.lerp(r,u,t,G);this.premultiplied_alpha?(vec3.scale(r,r,D),r[3]=1):r[3]=D;if(!(0.001>D||(D=E.size*B[G*B.length<<0],Math.abs(D*I)<c)))if(H){if(F.set(E._pos,3*b),J.set(r,4*b),s&&(G=(y?(z?A:G)*x<<0:E.id)%x,G*=w,E=1-(G<<0)*w-w,G%=1,M[2*b]=G,M[2*b+1]=E),
  O[2*b]=D,O[2*b+1]=b,++b,3*b>=K)break}else if(D*=I,vec3.scale(p,m,D),vec3.scale(g,k,D),vec3.scale(f,h,D),vec3.scale(n,l,D),0!=E.angle&&(quat.setAxisAngle(N,d,E.angle*DEG2RAD),vec3.transformQuat(p,p,N),vec3.transformQuat(g,g,N),vec3.transformQuat(f,f,N),vec3.transformQuat(n,n,N)),vec3.add(a,E._pos,g),F.set(a,18*b),vec3.add(a,E._pos,f),F.set(a,18*b+3),vec3.add(a,E._pos,n),F.set(a,18*b+6),vec3.add(a,E._pos,f),F.set(a,18*b+9),vec3.add(a,E._pos,p),F.set(a,18*b+12),vec3.add(a,E._pos,n),F.set(a,18*b+15),
  J.set(r,24*b),J.set(r,24*b+4),J.set(r,24*b+8),J.set(r,24*b+12),J.set(r,24*b+16),J.set(r,24*b+20),s&&(G=(y?(z?A:G)*x<<0:E.id)%x,G*=w,E=1-(G<<0)*w-w,G%=1,M.set([G+w,E+w,G,E+w,G+w,E,G,E+w,G,E,G+w,E],12*b)),++b,18*b>=K)break}this._visible_particles=b;this._mesh.vertexBuffers.vertices.data=this._vertices;this._mesh.vertexBuffers.vertices.upload(gl.STREAM_DRAW);this._mesh.vertexBuffers.colors.data=this._colors;this._mesh.vertexBuffers.colors.upload(gl.STREAM_DRAW);this._mesh.vertexBuffers.extra2.data=this._extra2;
  this._mesh.vertexBuffers.extra2.upload(gl.STREAM_DRAW);s&&(this._mesh.vertexBuffers.coords.data=this._coords,this._mesh.vertexBuffers.coords.upload(gl.STREAM_DRAW))}};O._identity=mat4.create();O.prototype.onCollectInstances=function(a,b,c){if(this._root&&this.enabled){this._material||(this._material=new s({shader_name:"lowglobal"}));this._material.opacity=this.opacity-0.01;this._material.setTexture(s.COLOR,this.texture);this._material.blend_mode=this.additive_blending?va.ADD:va.ALPHA;this._material.soft_particles=
  this.soft_particles;this._material.constant_diffuse=!0;this._material.uvs_matrix[0]=this._material.uvs_matrix[4]=1/this.texture_grid_size;if(!this._mesh)return null;a=this._render_instance;a||(this._render_instance=a=new e.RenderInstance(this._root,this));this.follow_emitter?mat4.translate(a.matrix,O._identity,this._root.transform._position):mat4.copy(a.matrix,O._identity);c=this._root.material&&this.use_node_material?this._root.getMaterial():this._material;mat4.multiplyVec3(a.center,a.matrix,vec3.create());
  a.flags=xa|2048;a.applyNodeFlags();a.setMaterial(c);this.point_particles?(a.setMesh(this._mesh,gl.POINTS),a.uniforms.u_point_size=this.particle_size,a.query.macros.USE_POINTS="",a.query.macros.USE_POINT_CLOUD="",a.query.macros.USE_TEXTURED_POINTS="",a.setRange(0,this._visible_particles)):(a.setMesh(this._mesh,gl.TRIANGLES),a.setRange(0,6*this._visible_particles),delete a.query.macros.USE_POINTS,delete a.query.macros.USE_POINT_CLOUD,delete a.query.macros.USE_TEXTURED_POINTS,delete a.uniforms.u_point_size);
  b.push(a)}};e.Particle=$a;e.registerComponent(O);Na.icon="mini-icon-text.png";Na.CSS_classname="LS3D_label";Na.prototype.onAddedToScene=function(a){LEvent.bind(a,"renderGUI",this.render,this)};Na.prototype.onRemovedFromScene=function(a){LEvent.unbind(a,"renderGUI",this.render,this);this.removeHTML()};Na.prototype.createHTML=function(){var a=document.createElement("div");a.innerHTML=this.text;var b=a.style;b.className=this.constructor.CSS_classname;b.position="absolute";b.top=0;b.left=0;b.fontSize=
  "20px";b.padding="10px";b.color="white";b.minWidth="100px";b.pointerEvents="none";b.backgroundColor="rgba(0,0,0,0.5)";b.borderRadius="2px";e.getGUIElement().appendChild(a);this._element=a};Na.prototype.removeHTML=function(){this._element&&(this._element.parentNode&&this._element.parentNode.removeChild(this._element),this._element=null)};Na.prototype.render=function(a,b){var c=this._root,d=e.Renderer._main_camera;if(d)if(c.transform.getGlobalPosition(this._world_pos),d.project(this._world_pos,null,
  this._screen_pos),this.use_html)this._element||this.createHTML(),this._element.innerHTML!=this.text&&(this._element.innerHTML=this.text),this._element.style.display=!1===c.flags.visible?"none":"block",this.text?(c=this.constructor.CSS_classname+" "+this.className,this._element.className!=c&&(this._element.className=c),this._element.style.left=this._screen_pos[0].toFixed(0)+"px",this._element.style.top=gl.canvas.height-(this._screen_pos[1]|0)-10+"px"):this._element.style.display="none";else if(this._element&&
  this.removeHTML(),gl.start2D){c=this._screen_pos[0]+5;d=gl.canvas.height-this._screen_pos[1]+10;gl.start2D();gl.font="20px Arial";var f=gl.measureText(this.text);gl.fillStyle="black";gl.globalAlpha=0.5;gl.fillRect(c-5,d-20,f.width+10,26);gl.globalAlpha=1;gl.fillStyle="white";gl.fillText(this.text,c,d);gl.finish2D()}};e.registerComponent(Na);Q.icon="mini-icon-points.png";Q["@texture"]={widget:"texture"};Q["@color"]={widget:"color"};Q["@num_points"]={widget:"info"};Q["@size"]={type:"number",step:0.001};
  Q.default_color=vec4.fromValues(1,1,1,1);Object.defineProperty(Q.prototype,"num_points",{set:function(a){},get:function(){return this._points.length},enumerable:!0});Q.prototype.addPoint=function(a,b,c,d){var f=new Float32Array(10);f.set(a,0);b?f.set(b,3):f.set(Q.default_color,3);f[7]=void 0!==c?c:1;f[8]=void 0!=d?d:0;this._points.push(f);this._dirty=!0;return this._points.length-1};Q.prototype.clear=function(){this._points.length=0};Q.prototype.reset=Q.prototype.clear;Q.prototype.setPoint=function(a,
  b,c,d,f){if(a=this._points[a])b&&a.set(b,0),c&&a.set(c,3),void 0!==d&&(a[7]=d),void 0!==f&&(a[8]=f),this._dirty=!0};Q.prototype.setPointsFromMesh=function(a){};Q.prototype.removePoint=function(a){this._points.splice(a,1);this._dirty=!0};Q.prototype.onAddedToNode=function(a){LEvent.bind(a,"collectRenderInstances",this.onCollectInstances,this)};Q.prototype.onRemovedFromNode=function(a){LEvent.unbind(a,"collectRenderInstances",this.onCollectInstances,this)};Q.prototype.getResources=function(a){this.mesh&&
  (a[this.emissor_mesh]=Mesh);this.texture&&(a[this.texture]=Texture)};Q.prototype.onResourceRenamed=function(a,b,c){this.mesh==a&&(this.mesh=b);this.texture==a&&(this.texture=b)};Q.prototype.createMesh=function(){if(this._mesh_max_points!=this.max_points){this._vertices=new Float32Array(3*this.max_points);this._colors=new Float32Array(4*this.max_points);this._extra2=new Float32Array(2*this.max_points);for(var a=0;a<this.max_points;a++)this._colors.set(Q.default_color,4*a),this._extra2[2*a]=1;this._mesh&&
  this._mesh.deleteBuffers();this._mesh=new GL.Mesh;this._mesh.addBuffers({vertices:this._vertices,colors:this._colors,extra2:this._extra2},null,gl.STREAM_DRAW);this._mesh_max_points=this.max_points}};Q.prototype.updateMesh=function(a){this._mesh_max_points!=this.max_points&&this.createMesh();var b=this._points;if(this.sort_in_z&&a){var c=a.getEye();a=a.getFront();b=this._points.concat();c=geo.createPlane(c,a);a=Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]);for(var d=0;d<b.length;++d)b[d][9]=Math.abs(vec3.dot(b[d].subarray(0,
  3),c)+c[3])/a;b.sort(function(a,b){return a[9]<b[9]?1:a[9]>b[9]?-1:0})}d=0;c=this._vertices;a=this._colors;for(var d=this._extra2,f=this.premultiplied_alpha,e=0;e<b.length&&!(3*e>=c.length);++e){var h=b[e];c.set(h.subarray(0,3),3*e);var k=h.subarray(3,7);f&&vec3.scale(k,k,k[3]);a.set(k,4*e);d.set(h.subarray(7,9),2*e)}this._mesh.vertexBuffers.vertices.data=c;this._mesh.vertexBuffers.vertices.upload();this._mesh.vertexBuffers.colors.data=a;this._mesh.vertexBuffers.colors.upload();this._mesh.vertexBuffers.extra2.data=
  d;this._mesh.vertexBuffers.extra2.upload()};Q._identity=mat4.create();Q.prototype.onCollectInstances=function(a,b,c){if(this._root&&0!=this._points.length&&this.enabled){a=e.Renderer._current_camera;this._last_premultiply!==this.premultiplied_alpha&&(this._dirty=!0);this._dirty&&this.updateMesh(a);this._material||(this._material=new e.Material({shader_name:"lowglobal"}),this._material.extra_macros={USE_POINT_CLOUD:"",USE_TEXTURED_POINTS:""});c=this._material;c.color.set(this.color);c.opacity=this.premultiplied_alpha?
  0.99:this.global_opacity-0.01;this._last_premultiply=this.premultiplied_alpha;c.setTexture(e.Material.COLOR,this.texture);c.blend_mode=this.additive_blending?e.Blend.ADD:e.Blend.ALPHA;c.constant_diffuse=!0;if(!this._mesh)return null;a=this._render_instance;a||(this._render_instance=a=new e.RenderInstance(this._root,this));this.in_world_coordinates&&this._root.transform?a.matrix.set(this._root.transform._global_matrix):mat4.copy(a.matrix,Q._identity);c=this._root.material&&this.use_node_material?this._root.getMaterial():
  this._material;mat4.multiplyVec3(a.center,a.matrix,vec3.create());a.flags=xa|2048;a.applyNodeFlags();a.uniforms.u_point_size=this.size;a.setMaterial(c);a.setMesh(this._mesh,gl.POINTS);c=this._points.length;c>this._vertices.length/3&&(c=this._vertices.length/3);a.setRange(0,c);b.push(a)}};Q.prototype.serialize=function(){var a=e.cloneObject(this);this.uid&&(a.uid=this.uid);if(this.serialize_points){for(var b=Array(this._points.length),c=0;c<this._points.length;c++)b[c]=typedArrayToArray(this._points[c]);
  a.points=b}return a};Q.prototype.configure=function(a){if(a){a.uid&&(this.uid=a.uid);if(a.points&&a.serialize_points){this._points=Array(a.points.length);for(var b=0;b<a.points.length;b++)this._points[b]=new Float32Array(a.points[b]);a.points=null}e.cloneObject(a,this)}};e.registerComponent(Q);da.icon="mini-icon-lines.png";da["@color"]={widget:"color"};Object.defineProperty(da.prototype,"num_lines",{set:function(a){},get:function(){return this._lines.length},enumerable:!0});da.prototype.clear=function(){this._lines.length=
  0};da.prototype.reset=da.prototype.clear;da.prototype.addPoint=function(a,b){var c=null,d=null;this._lines.length?(d=this._lines[this._lines.length-1],c=new Float32Array(d.subarray(3,6)),d=new Float32Array(d.subarray(10,14))):(c=a,d=b);this.addLine(c,a,d,b)};da.prototype.addLine=function(a,b,c,d){var f=new Float32Array(14);f.set(a,0);f.set(b,3);c?f.set(c,6):f.set([1,1,1,1],6);d?f.set(d,10):c?f.set(c,10):f.set([1,1,1,1],10);this._lines.push(f);this._dirty=!0;return this._lines.length-1};da.prototype.setLine=
  function(a,b,c,d,f){a=this._lines[a];b&&a.set(b,0);c&&a.set(c,3);d&&a.set(d,6);f&&a.set(f,10);this._dirty=!0};da.prototype.removeLine=function(a){this._lines.splice(a,1);this._dirty=!0};da.prototype.onAddedToNode=function(a){LEvent.bind(a,"collectRenderInstances",this.onCollectInstances,this)};da.prototype.onRemovedFromNode=function(a){LEvent.unbind(a,"collectRenderInstances",this.onCollectInstances,this)};da.prototype.onResourceRenamed=function(a,b,c){};da.prototype.createMesh=function(){this._mesh_max_lines!=
  this.max_lines&&(this._vertices=new Float32Array(6*this.max_lines),this._colors=new Float32Array(8*this.max_lines),this._mesh=new GL.Mesh,this._mesh.addBuffers({vertices:this._vertices,colors:this._colors},null,gl.STREAM_DRAW),this._mesh_max_lines=this.max_lines)};da.prototype.updateMesh=function(){this._mesh_max_lines!=this.max_lines&&this.createMesh();for(var a=0,b=this._vertices,c=this._colors,d=this._lines,f=this._lines.length,e=b.length,a=0;a<f&&!(6*a>=e);++a){var h=d[a];b.set(h.subarray(0,6),
  6*a);c.set(h.subarray(6,14),8*a)}this._mesh.vertexBuffers.vertices.data=b;this._mesh.vertexBuffers.vertices.upload();this._mesh.vertexBuffers.colors.data=c;this._mesh.vertexBuffers.colors.upload()};da._identity=mat4.create();da.prototype.onCollectInstances=function(a,b,c){if(this._root&&0!=this._lines.length&&this.enabled){this._dirty&&this.updateMesh();this._material||(this._material=new s({shader_name:"lowglobal"}));c=this._material;c.color.set(this.color);c.opacity=this.global_opacity-0.01;c.blend_mode=
  this.additive_blending?va.ADD:va.ALPHA;c.constant_diffuse=!0;if(!this._mesh)return null;a=this._render_instance;a||(this._render_instance=a=new ba(this._root,this));this.in_world_coordinates&&this._root.transform?a.matrix.set(this._root.transform._global_matrix):mat4.copy(a.matrix,da._identity);c=this._root.material&&this.use_node_material?this._root.getMaterial():this._material;mat4.multiplyVec3(a.center,a.matrix,vec3.create());a.flags=xa|2048;a.applyNodeFlags();a.setMaterial(c);a.setMesh(this._mesh,
  gl.LINES);c=2*this._lines.length;c>this._vertices.length/3&&(c=this._vertices.length/3);a.setRange(0,c);b.push(a)}};e.registerComponent(da);F.LOOP=1;F.PINGPONG=2;F.ONCE=3;F.PAUSED=4;F.MODES={loop:F.LOOP,pingpong:F.PINGPONG,once:F.ONCE,paused:F.PAUSED};F["@animation"]={widget:"animation"};F["@root_node"]={type:"node"};F["@mode"]={type:"enum",values:F.MODES};F.prototype.configure=function(a){a.play&&delete a.play;a.enabled&&(this.enabled=!0);a.range&&(this.range=a.range.concat());void 0!==a.mode&&(this.mode=
  a.mode);a.animation&&(this.animation=a.animation);a.take&&(this.take=a.take);null!=a.playback_speed&&(this.playback_speed=parseFloat(a.playback_speed));void 0!==a.root_node&&(this.root_node=a.root_node);void 0!==a.playing&&(this.playing=a.playing)};F.icon="mini-icon-clock.png";F.prototype.onAddedToScene=function(a){LEvent.bind(a,"update",this.onUpdate,this)};F.prototype.onRemovedFromScene=function(a){LEvent.unbind(a,"update",this.onUpdate,this)};F.prototype.getAnimation=function(){if(!this.animation||
  "@"==this.animation[0])return this._root.scene.animation;var a=e.ResourcesManager.getResource(this.animation);return a&&a.constructor===e.Animation?a:null};F.prototype.onUpdate=function(a,b){if(this.enabled&&this.playing){this.mode!=F.PAUSED&&(this.current_time+=b*this.playback_speed);var c=this.getAnimation();if(c){var d=c.takes[this.take];if(d){var c=this.current_time,f=0,e=d=d.duration;this.range&&(f=this.range[0],e=this.range[1],d=e-f);if(c>e)switch(this.mode){case F.ONCE:c=e;LEvent.trigger(this,
  "end_animation");this.playing=!1;break;case F.PINGPONG:c=0==(c/d|0)%2?this.current_time%d:d-this.current_time%d;break;case F.PINGPONG:c=e;break;default:c=(this.current_time-f)%d+f,LEvent.trigger(this,"animation_loop")}else c<f&&(c=f);this.applyAnimation(c,this._last_time);this._last_time=c;(c=this._root.scene)&&c.refresh()}}}};F.prototype.play=function(){this.playing=!0;this.current_time=0;this.range&&(this.current_time=this.range[0]);this._last_time=this.current_time;LEvent.trigger(this,"start_animation")};
  F.prototype.pause=function(){this.playing=!1};F.prototype.stop=function(){this.playing=!1;this.current_time=0;this.range&&(this.current_time=this.range[0]);this._last_time=this.current_time};F.prototype.playRange=function(a,b){this.playing=!0;this._last_time=this.current_time=a;this.range=[a,b]};F.prototype.applyAnimation=function(a,b){void 0===b&&(b=a);var c=this.getAnimation();if(c&&(c=c.takes[this.take])){var d=null;this.root_node&&this._root.scene&&(d="@"==this.root_node?this._root:this._root.scene.getNode(this.root_node));
  c.applyTracks(a,b,void 0,d)}};F.prototype._processSample=function(a,b,c,d){if(d=this._root.scene)if(a=d.getNode(a)){d=a.transform;switch(b){case "translate.X":d&&(d.position[0]=c);break;case "translate.Y":d&&(d.position[1]=c);break;case "translate.Z":d&&(d.position[2]=c);break;case "matrix":d&&d.fromMatrix(c)}a.transform&&a.transform.updateMatrix()}};F.prototype.getResources=function(a){this.animation&&(a[this.animation]=e.Animation)};F.prototype.onResourceRenamed=function(a,b,c){this.animation==
  a&&(this.animation=b)};F.prototype.getEvents=function(){return{start_animation:"event",end_animation:"event"}};F.prototype.getEventActions=function(){return{play:"function",pause:"function",stop:"function"}};e.registerComponent(F);Oa.icon="mini-icon-reflector.png";Oa["@texture_size"]={type:"enum",values:["viewport",64,128,256,512,1024,2048]};Oa["@layers"]={type:"layers"};Oa.prototype.onAddedToScene=function(a){LEvent.bind(a,"renderReflections",this.onRenderReflection,this);LEvent.bind(a,"afterCameraEnabled",
  this.onCameraEnabled,this)};Oa.prototype.onRemovedFromScene=function(a){LEvent.unbindAll(a,this);for(var b in this._textures)e.ResourcesManager.unregisterResource(":reflection_"+b);this._textures={}};Oa.prototype.onRenderReflection=function(a,b){if(this.enabled&&this._root){var c=this._root.scene;if(c&&(this.refresh_rate<<=0,0!=c._frame&&0==c._frame%this.refresh_rate||!this._rt)){var d=c=parseInt(this.texture_size),f=c,g=this._root.flags.visible;this.ignore_this_mesh&&(this._root.flags.seen_by_reflections=
  !1);var h=b.layers;b.layers=this.layers;var k=e.Renderer._visible_cameras;e.Renderer.clearSamplers();for(var m=0;m<k.length;m++){var l=k[m];isNaN(c)&&"viewport"==this.texture_size&&(c=512,f=l.getLocalViewport(null,l._viewport_in_pixels),d=f[2],f=f[3]);this.use_cubemap&&(d=f=c);var p=this.use_cubemap?gl.TEXTURE_CUBE_MAP:gl.TEXTURE_2D,n=this.high_precision?gl.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE,q=this._textures[l.uid];q&&q.width==d&&q.height==f&&q.type==n&&q.texture_type==p&&q.minFilter==(this.generate_mipmaps?
  gl.LINEAR_MIPMAP_LINEAR:gl.LINEAR)||(q=new GL.Texture(d,f,{type:n,texture_type:p,minFilter:this.generate_mipmaps?gl.LINEAR_MIPMAP_LINEAR:gl.LINEAR}),q.has_mipmaps=this.generate_mipmaps,this._textures[l.uid]=q);q._locked=!0;var p=this._root.transform.getGlobalPosition(),n=this._root.transform.getTop(),r=l.getEye(),u=l.getCenter(),t=l.getUp();if(this.use_mesh_info){var s=this._root.getMesh();s&&(p=this._root.transform.transformPointGlobal(BBox.getCenter(s.bounding)),n=this._root.transform.transformVectorGlobal([0,
  1,0]))}vec3.add(p,p,this.offset);this._reflected_camera=s=this._reflected_camera||new e.Camera;s.configure(l.serialize());this.use_cubemap?s.eye=p:(s.fov=l.fov,s.aspect=l.aspect,s.eye=geo.reflectPointInPlane(r,p,n),s.center=geo.reflectPointInPlane(u,p,n),s.up=geo.reflectPointInPlane(t,[0,0,0],n),vec3.add(p,p,vec3.scale(vec3.create(),n,-this.clip_offset)),p=[n[0],n[1],n[2],vec3.dot(p,n)],b.clipping_plane=p);e.Renderer.renderInstancesToRT(s,q,b);this.blur&&((p=this._textures["blur_"+l.uid])&&(Texture.compareFormats(q,
  p)||p.minFilter!=q.minFilter)&&(p=null),q.applyBlur(this.blur,this.blur,1,p));this.generate_mipmaps&&isPowerOfTwo(d)&&isPowerOfTwo(f)&&(q.setParameter(gl.TEXTURE_MIN_FILTER,gl.LINEAR_MIPMAP_LINEAR),gl.generateMipmap(q.texture_type),q.unbind());q._locked=!1;this.texture_name&&e.ResourcesManager.registerResource(this.texture_name,q);e.ResourcesManager.registerResource(":reflection_"+l.uid,q);if(!this.all_cameras)break}b.clipping_plane=null;b.layers=h;delete b.brightness_factor;delete b.colorclip_factor;
  this._root.flags.visible=g}}};Oa.prototype.onCameraEnabled=function(a,b){if(this.enabled&&this._root&&this._root.material&&this._textures[b.uid]){var c=this._root.getMaterial();c&&(c.setTexture(s.ENVIRONMENT_TEXTURE,":reflection_"+b.uid).uvs=s.COORDS_FLIPPED_SCREEN)}};e.registerComponent(Oa);x.secure_module=!1;x.block_execution=!1;x.catch_important_exceptions=!0;x.icon="mini-icon-script.png";x.templates={component:"//@unnamed\n//defined: component, node, scene, globals\nthis.onStart = function()\n{\n}\n\nthis.onUpdate = function(dt)\n{\n\t//node.scene.refresh();\n}"};
  x["@code"]={type:"script"};x.BIND_TO_COMPONENT=1;x.BIND_TO_NODE=2;x.BIND_TO_SCENE=3;x.BIND_TO_RENDERER=4;x.API_functions={};x.API_events_to_function={};x.defineAPIFunction=function(a,b,c,d){c=c||a;b=b||x.BIND_TO_SCENE;b={name:a,target:b,event:c,info:d};x.API_functions[a]=b;x.API_events_to_function[c]=b};x.defineAPIFunction("onStart",x.BIND_TO_SCENE,"start");x.defineAPIFunction("onFinish",x.BIND_TO_SCENE,"finish");x.defineAPIFunction("onPrefabReady",x.BIND_TO_NODE,"prefabReady");x.defineAPIFunction("onUpdate",
  x.BIND_TO_SCENE,"update");x.defineAPIFunction("onClicked",x.BIND_TO_NODE,"clicked");x.defineAPIFunction("onSceneRender",x.BIND_TO_SCENE,"beforeRender");x.defineAPIFunction("onCollectRenderInstances",x.BIND_TO_NODE,"collectRenderInstances");x.defineAPIFunction("onRender",x.BIND_TO_NODE,"beforeRenderInstances");x.defineAPIFunction("onAfterRender",x.BIND_TO_SCENE,"afterRenderInstances");x.defineAPIFunction("onRenderGUI",x.BIND_TO_SCENE,"renderGUI");x.defineAPIFunction("onRenderHelpers",x.BIND_TO_SCENE,
  "renderHelpers");x.defineAPIFunction("onEnableFrameContext",x.BIND_TO_SCENE,"enableFrameContext");x.defineAPIFunction("onShowFrameContext",x.BIND_TO_SCENE,"showFrameContext");x.defineAPIFunction("onMouseDown",x.BIND_TO_SCENE,"mousedown");x.defineAPIFunction("onMouseMove",x.BIND_TO_SCENE,"mousemove");x.defineAPIFunction("onMouseUp",x.BIND_TO_SCENE,"mouseup");x.defineAPIFunction("onMouseWheel",x.BIND_TO_SCENE,"mousewheel");x.defineAPIFunction("onKeyDown",x.BIND_TO_SCENE,"keydown");x.defineAPIFunction("onKeyUp",
  x.BIND_TO_SCENE,"keyup");x.defineAPIFunction("onGamepadConnected",x.BIND_TO_SCENE,"gamepadconnected");x.defineAPIFunction("onGamepadDisconnected",x.BIND_TO_SCENE,"gamepaddisconnected");x.defineAPIFunction("onButtonDown",x.BIND_TO_SCENE,"buttondown");x.defineAPIFunction("onButtonUp",x.BIND_TO_SCENE,"buttonup");x.defineAPIFunction("onDestroy",x.BIND_TO_NODE,"destroy");x.coding_help="\nFor a complete guide check: <a href='https://github.com/jagenjo/litescene.js/blob/master/guides/scripting.md' target='blank'>Scripting Guide</a>\nGlobal vars:\n + node : represent the node where this component is attached.\n + component : represent the component.\n + this : represents the script context\n\nSome of the common API functions:\n + onStart: when the Scene starts\n + onUpdate: when updating\n + onClicked : if this node is clicked\n + onRender : before rendering the node\n + onRenderGUI : to render something in the GUI using canvas2D\n + onCollectRenderInstances: when collecting instances\n + onAfterRender : after rendering the node\n + onPrefabReady: when the prefab has been loaded\n + onFinish : when the scene finished (mostly used for editor stuff)\n\nRemember, all basic vars attached to this will be exported as global.\n";
  x.active_scripts={};Object.defineProperty(x.prototype,"context",{set:function(a){console.error("Script: context cannot be assigned")},get:function(){return this._script?this._script._context:null},enumerable:!1});Object.defineProperty(x.prototype,"name",{set:function(a){console.error("Script: name cannot be assigned")},get:function(){if(this._script.code){var a=this._script.code.substr(0,32);if(0!=a.indexOf("//@"))return null;var b=a.indexOf("\n");-1==b&&(b=void 0);return a.substr(3,b-3)}},enumerable:!1});
  x.prototype.configure=function(a){a.uid&&(this.uid=a.uid);void 0!==a.enabled&&(this.enabled=a.enabled);void 0!==a.code&&(this.code=a.code);this._root&&this._root.scene&&this.processCode();a.properties&&this.setContextProperties(a.properties)};x.prototype.serialize=function(){return{uid:this.uid,enabled:this.enabled,code:this.code,properties:e.cloneObject(this.getContextProperties())}};x.prototype.getContext=function(){return this._script?this._script._context:null};x.prototype.getCode=function(){return this.code};
  x.prototype.setCode=function(a,b){this.code=a;this.processCode(b)};x.prototype.processCode=function(a){this._script.code=this.code;if(this._root&&!e.Script.block_execution){this._script&&this._script._context&&this._script._context.unbindAll();var b=this._stored_properties||this.getContextProperties(),c=this._script.compile({component:this,node:this._root,scene:this._root.scene,globals:e.Globals});a||this.hookEvents();this.setContextProperties(b);this._stored_properties=null;return c}return!0};x.prototype.getContextProperties=
  function(){var a=this.getContext();if(a)return e.cloneObject(a)};x.prototype.setContextProperties=function(a){if(a){var b=this.getContext();b?e.cloneObject(a,b,!1,!0):this._stored_properties=a}};x.prototype.setProperty=function(a,b){var c=this.getContext();if(c&&void 0!==c[a])if(c[a].set)c[a](b);else c[a]=b;else this[a]&&(this[a]=b)};x.prototype.getPropertiesInfo=function(){var a=this.getContext();if(!a)return{enabled:"boolean"};a=e.getObjectProperties(a);a.enabled="boolean";return a};x.prototype.getPropertyInfoFromPath=
  function(a){if("context"==a[0]){var b=this.getContext();if(1==a.length)return{name:"context",node:this._root,target:b,type:"object"};a=a[1];if(b&&void 0!==b[a]){var c=b[a],d=b["@"+a];d||(d=b.constructor["@"+a]);var f="";d&&(f=d.type);f||null===c||void 0===c||(c.constructor===String?f="string":c.constructor===Boolean?f="boolean":c.length?f="vec"+c.length:c.constructor===Number?f="number":c.constructor===Function&&(f="function"));"function"==f&&(c=a);return{node:this._root,target:b,name:a,value:c,type:f}}}};
  x.prototype.setPropertyValueFromPath=function(a,b,c){c=c||0;if(!(a.length<c+1)&&"context"==a[c]){var d=this.getContext();a=a[c+1];d&&void 0!==d[a]&&void 0!==d[a]&&(d[a]&&d[a].constructor==Function||(d[a]&&d[a].set?d[a].set(b):d[a]=b))}};x.prototype.hookEvents=function(){var a=this._root;if(!a)throw"hooking events of a Script without a node";var b=a.scene;b||(b=e.GlobalScene);var c=this.getContext();if(c)for(var d in e.Script.API_functions){var f=d,g=e.Script.API_functions[f],h=null;switch(g.target){case x.BIND_TO_COMPONENT:h=
  this;break;case x.BIND_TO_NODE:h=a;break;case x.BIND_TO_SCENE:h=b;break;case x.BIND_TO_RENDERER:h=e.Renderer}if(!h)throw"Script event without target?";c[f]&&c[f].constructor===Function?LEvent.isBind(h,g.event,this.onScriptEvent,this)||LEvent.bind(h,g.event,this.onScriptEvent,this):LEvent.unbind(h,g.event,this.onScriptEvent,this)}};x.prototype.onScriptEvent=function(a,b){if(this.enabled){var c=e.Script.API_events_to_function[a];if(c)return this._script.callMethod(c.name,b)}};x.prototype.onAddedToNode=
  function(a){a.script||(a.script=this)};x.prototype.onRemovedFromNode=function(a){a.script==this&&delete a.script};x.prototype.onAddedToScene=function(a){this._name&&!e.Script.active_scripts[this._name]&&(e.Script.active_scripts[this._name]=this);if(!(this._script&&this._script._context&&this._script._context._initialized))if(this.constructor.catch_important_exceptions)try{this.processCode()}catch(b){console.error(b)}else this.processCode()};x.prototype.onRemovedFromScene=function(a){this._name&&e.Script.active_scripts[this._name]&&
  delete e.Script.active_scripts[this._name];LEvent.unbindAll(a,this);if(this._context&&(LEvent.unbindAll(a,this._context,this),this._context.onRemovedFromScene))this._context.onRemovedFromScene(a)};x.prototype.getComponentTitle=function(){return this.name};x.prototype.onError=function(a){var b=this._root.scene;b&&(a.script=this,a.node=this._root,LEvent.trigger(this,"code_error",a),LEvent.trigger(b,"code_error",a),LEvent.trigger(e,"code_error",a),console.log("app finishing due to error in script"),
  b.finish())};x.prototype.onCodeChange=function(a){this.processCode()};x.prototype.getResources=function(a){var b=this.getContext();if(b&&b.onGetResources)b.onGetResources(a)};e.registerComponent(x);e.Script=x;oa.coding_help=x.coding_help;Object.defineProperty(oa.prototype,"filename",{set:function(a){a&&(a=e.ResourcesManager.cleanFullpath(a));this._filename=a;this.processCode()},get:function(){return this._filename},enumerable:!0});Object.defineProperty(oa.prototype,"context",{set:function(a){console.error("ScriptFromFile: context cannot be assigned")},
  get:function(){return this._script?this._script._context:null},enumerable:!1});Object.defineProperty(oa.prototype,"name",{set:function(a){console.error("Script: name cannot be assigned")},get:function(){if(this._script.code){var a=this._script.code.substr(0,32);if(0!=a.indexOf("//@"))return null;var b=a.indexOf("\n");-1==b&&(b=void 0);return a.substr(3,b-3)}},enumerable:!1});oa.prototype.onAddedToScene=function(a){if(!(this._script&&this._script._context&&this._script._context._initialized))if(this.constructor.catch_important_exceptions)try{this.processCode()}catch(b){console.error(b)}else this.processCode()};
  oa.prototype.processCode=function(a){var b=this;if(this.filename){var c=e.ResourcesManager.getResource(this.filename);if(c){if(c=c.data,void 0!==c&&this._script.code!=c){if(this._root&&!e.Script.block_execution){this._script.code=c;this._script&&this._script._context&&this._script._context.unbindAll();var c=this._stored_properties||this.getContextProperties(),d=this._script.compile({component:this,node:this._root,scene:this._root.scene,globals:e.Globals});a||this.hookEvents();this.setContextProperties(c);
  this._stored_properties=null;this._script._context&&!this._script._context._initialized&&(this._root&&this._script._context.onAddedToNode&&(this._script._context.onAddedToNode(this._root),this._root.scene&&this._script._context.onAddedToScene&&(this._script._context.onAddedToScene(this._root.scene),this._root.scene._state===e.RUNNING&&this._script._context.start&&this._script._context.start())),this._script._context._initialized=!0);return d}return!0}}else e.ResourcesManager.load(this.filename,null,
  function(c,d){d==b.filename&&b.processCode(a)})}};oa.prototype.configure=function(a){a.uid&&(this.uid=a.uid);void 0!==a.enabled&&(this.enabled=a.enabled);void 0!==a.filename&&(this.filename=a.filename);a.properties&&this.setContextProperties(a.properties);this._root&&this._root.scene&&this.processCode()};oa.prototype.serialize=function(){return{uid:this.uid,enabled:this.enabled,filename:this.filename,properties:e.cloneObject(this.getContextProperties())}};oa.prototype.getResources=function(a){this.filename&&
  (a[this.filename]=e.Resource);var b=this.getContext();b&&b.getResources&&b.getResources(a)};oa.prototype.getCodeResource=function(){return e.ResourcesManager.getResource(this.filename)};oa.prototype.getCode=function(){var a=e.ResourcesManager.getResource(this.filename);return a?a.data:""};oa.prototype.setCode=function(a,b){var c=e.ResourcesManager.getResource(this.filename);if(!c)return"";c.data=a;this.processCode(b)};oa.updateComponents=function(a,b){if(a)for(var c=a.filename,d=e.GlobalScene.findNodeComponents(e.ScriptFromFile),
  f=0;f<d.length;++f){var g=d[f],c=a.fullpath||a.filename;g.filename==c&&g.processCode(b)}};e.extendClass(oa,x);e.registerComponent(oa);e.ScriptFromFile=oa;Object.defineProperty(ja.prototype,"primitive",{get:function(){return this._primitive},set:function(a){a=void 0===a||null===a?-1:a|0;if(-1==a||0==a||1==a||4==a||10==a)this._primitive=a},enumerable:!0});ja.icon="mini-icon-terrain.png";ja["@subdivisions"]={type:"number",min:1,max:255,step:1,precision:0};ja["@heightmap"]={type:"texture"};ja["@action"]=
  {widget:"button",callback:function(){this.options.instance&&this.options.instance.updateMesh()}};ja["@primitive"]={type:"enum",values:{Default:null,Points:0,Lines:1,Triangles:4,Wireframe:10}};ja.prototype.onAddedToNode=function(a){LEvent.bind(a,"collectRenderInstances",this.onCollectInstances,this)};ja.prototype.onRemovedFromNode=function(a){LEvent.unbind(a,"collectRenderInstances",this.onCollectInstances,this);this._root.mesh==this._mesh&&delete this._root.mesh};ja.prototype.getResources=function(a){this.heightmap&&
  (a[this.heightmap]=Texture)};ja.prototype.onResourceRenamed=function(a,b,c){this.heightmap==a&&(this.heightmap=b)};ja.prototype.updateMesh=function(){if(this.heightmap){var a=e.ResourcesManager.textures[this.heightmap];if(a){var b=a.img;if(b){this.subdivisions>b.width&&(this.subdivisions=b.width);this.subdivisions>b.height&&(this.subdivisions=b.height);255<this.subdivisions&&!gl.extensions.OES_element_index_uint&&(this.subdivisions=255);var a=0.5*this.size,c=this.subdivisions<<0,d=this.height,f=createCanvas(c,
  c),g=f.getContext("2d");g.drawImage(b,0,0,b.width,b.height,0,0,f.width,f.height);var b=g.getImageData(0,0,f.width,f.height).data,f=[],g=[],h=[],k=[],m=[],l,p;p=l=c-1;for(var n,q=a/(c-1),r=0;r<=p;r++)for(var u=r/p,t=0;t<=l;t++){var s=t/l;n=b[r*c*4+4*t]/255;h.push(a*(2*s-1),n*d,a*(2*u-1));m.push(s,1-u);0==t||0==r||t==l-1||r==p-1?k.push(0,1,0):(n=[-(b[r*c*4+4*(t+1)]/255-b[r*c*4+4*(t-1)]/255)*d,2*q,-(b[(r+1)*c*4+4*t]/255-b[(r-1)*c*4+4*t]/255)*d],vec3.normalize(n,n),k.push(n[0],n[1],n[2]));t<l&&r<p&&(n=
  t+r*(l+1),f.push(n+1,n,n+l+1),f.push(n+1,n+l+1,n+l+2),g.push(n+1,n,n,n+l+1))}c=new GL.Mesh({vertices:h,normals:k,coords:m},{triangles:f,wireframe:g});c.setBounding([0,0.5*this.height,0],[a,0.5*this.height,a]);this._mesh=c;this._info=[this.heightmap,this.size,this.height,this.subdivisions,this.smooth]}}}};ja.PLANE=null;ja.prototype.onCollectInstances=function(a,b){!this._mesh&&this.heightmap&&this.updateMesh();this.auto_update&&this._info&&(this._info[0]==this.heightmap&&this._info[1]==this.size&&
  this._info[2]==this.height&&this._info[3]==this.subdivisions&&this._info[4]==this.smooth||this.updateMesh());var c=this._render_instance;c||(this._render_instance=c=new ba(this._root,this));if(!this._mesh)return ja.PLANE||(ja.PLANE=GL.Mesh.plane({xz:!0,normals:!0,coords:!0})),c.mesh=ja.PLANE,c;c.material=this._root.getMaterial();c.setMesh(this._mesh,this.primitive);this._root.mesh=this._mesh;this._root.transform.getGlobalMatrix(c.matrix);mat4.multiplyVec3(c.center,c.matrix,vec3.create());c.flags=
  xa;c.applyNodeFlags();b.push(c)};e.registerComponent(ja);D.GRID_MODE=1;D.RADIAL_MODE=2;D.MESH_MODE=3;D.icon="mini-icon-cloner.png";D["@mesh"]={type:"mesh"};D["@lod_mesh"]={type:"mesh"};D["@mode"]={type:"enum",values:{Grid:D.GRID_MODE,Radial:D.RADIAL_MODE,Mesh:D.MESH_MODE}};D["@count"]={type:"vec3",min:1,step:1};D.prototype.onAddedToScene=function(a){LEvent.bind(a,"collectRenderInstances",this.onCollectInstances,this);LEvent.bind(a,"afterCollectData",this.onUpdateInstances,this)};D.prototype.onRemovedFromScene=
  function(a){LEvent.unbind(a,"collectRenderInstances",this.onCollectInstances,this);LEvent.unbind(a,"afterCollectData",this.onUpdateInstances,this)};D.prototype.getMesh=function(){return"string"===typeof this.mesh?Qa.meshes[this.mesh]:this.mesh};D.prototype.getLODMesh=function(){return"string"===typeof this.lod_mesh?Qa.meshes[this.lod_mesh]:this.low_mesh};D.prototype.getResources=function(a){"string"==typeof this.mesh&&(a[this.mesh]=Mesh);"string"==typeof this.lod_mesh&&(a[this.lod_mesh]=Mesh);return a};
  D.generateTransformKey=function(a,b,c){var d=new Float32Array(9);d.set(a);d.set(b,3);d.set(c,6);return d};D.compareKeys=function(a,b){for(var c=0;c<a.length;++c)if(a[c]!=b[c])return!1;return!0};D.prototype.onCollectInstances=function(a,b){if(this.enabled){var c=this.getMesh();if(!c)return null;if(this._root){this.updateRenderInstancesArray();var d=this._RIs,f=this.material||this._root.getMaterial(),e=0,h=b.length;b.length=h+d.length;for(var k=0,m=d.length;k<m;++k){var l=d[k];0==k?(l.flags=xa|131072,
  l.applyNodeFlags(),e=l.flags):l.flags=e;l.setMesh(c);if(this.lod_mesh){var p=this.getLODMesh();p&&l.setLODMesh(p)}l.setMaterial(f);b[h+k]=l}}}};D.prototype.updateRenderInstancesArray=function(){var a=0;this.mode===D.GRID_MODE?a=(this.count[0]|0)*(this.count[1]|0)*(this.count[2]|0):this.mode===D.RADIAL_MODE?a=this.count[0]|0:this.mode===D.MESH_MODE&&(a=0);if(!a)this._RIs.length=0;else if(!this._RIs||this._RIs.length!=a){this._RIs?this._RIs.length=a:this._RIs=Array(a);for(var b=0;b<a;++b)this._RIs[b]||
  (this._RIs[b]=new e.RenderInstance(this._root,this))}};D.prototype.onUpdateInstances=function(a,b){if(this.enabled){var c=this._RIs;if(c&&c.length){var d=this._root.transform.getGlobalMatrix(mat4.create()),f=this._count[0]|0,e=this._count[1]|0,h=this._count[2]|0;if(this.mode==D.GRID_MODE){var k=vec3.scale(vec3.create(),this.size,0.5),m=vec3.create();1<f?m[0]=this.size[0]/(f-1):k[0]=0;1<e?m[1]=this.size[1]/(e-1):k[1]=0;1<h?m[2]=this.size[2]/(h-1):k[2]=0;for(var l=0,p=vec3.create(),n=vec3.create(),
  q=0;q<f;++q)for(var r=0;r<e;++r)for(var u=0;u<h;++u){var t=c[l];if(!t)return;p[0]=q*m[0]-k[0];p[1]=r*m[1]-k[1];p[2]=u*m[2]-k[2];mat4.translate(t.matrix,d,p);mat4.multiplyVec3(t.center,t.matrix,n);++l}}else if(this.mode==D.RADIAL_MODE)for(m=2*Math.PI/c.length,p=vec3.create(),n=vec3.create(),l=0,f=c.length;l<f;++l){t=c[l];if(!t)break;p[0]=Math.sin(m*l)*this.size[0];p[1]=0;p[2]=Math.cos(m*l)*this.size[0];t.matrix.set(d);mat4.translate(t.matrix,t.matrix,p);mat4.rotateY(t.matrix,t.matrix,m*l);mat4.multiplyVec3(t.center,
  t.matrix,n)}}}};e.registerComponent(D);pa["@factor"]={type:"number",step:0.001};pa["@center"]={type:"position",step:0.001};pa.icon="mini-icon-circle.png";pa.prototype.onAddedToNode=function(a){LEvent.bind(a,"computingShaderQuery",this.onShaderQuery,this);LEvent.bind(a,"computingShaderUniforms",this.onUniforms,this)};pa.prototype.onRemovedFromNode=function(a){LEvent.unbindAll(a,this)};pa._uniforms_code="uniform vec3 u_spherize_center@; uniform float u_spherize_radius@; uniform float u_spherize_factor@;";
  pa._code="\tvec3 off@ = vertex4.xyz - u_spherize_center@;    float dist@ = length(off@);\tvec3 vn@ = off@ / dist@;\tfloat factor@ = max(0.0, u_spherize_factor@ / dist@ );\tvertex4.xyz = mix(vertex4.xyz, vn@ * u_spherize_radius@, factor@);\tv_normal = (mix(v_normal, vn@, clamp(0.0,1.0,factor@)));";pa.prototype.onShaderQuery=function(a,b){this.enabled&&(b.macros.USE_VERTEX_SHADER_UNIFORMS=b.macros.USE_VERTEX_SHADER_UNIFORMS?b.macros.USE_VERTEX_SHADER_UNIFORMS+this._uniforms_code:this._uniforms_code,
  b.macros.USE_VERTEX_SHADER_CODE=b.macros.USE_VERTEX_SHADER_CODE?b.macros.USE_VERTEX_SHADER_CODE+this._code:this._code)};pa.prototype.onUniforms=function(a,b){this.enabled&&(b["u_spherize_center"+this._num_id]=this.center,b["u_spherize_radius"+this._num_id]=this.radius,b["u_spherize_factor"+this._num_id]=this.factor)};pa.prototype.renderEditor=function(a,b){if(this.enabled&&a&&this.enabled){Fa.setPointSize(6);Fa.setColor([0.33,0.874,0.56,b?0.8:0.5]);var c=vec3.clone(this.center);this._root&&this._root.transform&&
  vec3.transformMat4(c,c,this._root.transform._global_matrix);Fa.renderRoundPoints(c)}};pa.prototype.getTransformMatrix=function(a){if(!this._root||!this._root.transform)return null;var b=null;if("center"==a)b=this.center;else return!1;a=mat4.clone(this._root.transform._global_matrix);mat4.translate(a,a,b);return a};pa.prototype.renderPicking=function(a){a=vec3.clone(this.center);this._root&&this._root.transform&&vec3.transformMat4(a,a,this._root.transform._global_matrix);EditorView.addPickingPoint(a,
  4,{instance:this,info:"center"})};pa.prototype.applyTransformMatrix=function(a,b,c){if(!this._root||!this._root.transform||"center"!=c)return!1;b=this.center;mat4.multiplyVec3(b,a,b);return!0};e.registerComponent(pa);Ja.icon="mini-icon-graph.png";Ja.rift_server_url="http://tamats.com/uploads/RiftServer_0_3.zip";Ja.prototype.onAddedToNode=function(a){var b=a.scene;LEvent.bind(b,"start",this.onStart,this);LEvent.bind(b,"finish",this.onStop,this);LEvent.bind(b,"beforeRender",this.onBeforeRender,this);
  LEvent.bind(b,"afterRender",this.onAfterRender,this);LEvent.bind(a,"collectCameras",this.onCollectCameras,this)};Ja.prototype.onRemovedFromNode=function(a){var b=this._root.scene;LEvent.unbind(b,"start",this.onStart,this);LEvent.unbind(b,"finish",this.onStop,this);LEvent.unbind(b,"beforeRender",this.onBeforeRender,this);LEvent.unbind(b,"afterRender",this.onAfterRender,this);LEvent.unbind(a,"collectCameras",this.onCollectCameras,this);db.color_rendertarget=null};Ja.prototype.onCollectCameras=function(a,
  b){var c=db.main_camera;this._orientation&&c.setOrientation(this._orientation,!0);var d=c.getLocalVector([0.5*this.eye_distance,0,0]),f=vec3.scale(vec3.create(),d,-1);this._left_camera||(this._left_camera=new e.Camera,this._right_camera=new e.Camera);var g=c.serialize();this._left_camera.configure(g);this._right_camera.configure(g);this._left_camera.eye=vec3.add(vec3.create(),c.eye,f);this._right_camera.eye=vec3.add(vec3.create(),c.eye,d);this._left_camera._viewport.set([0,0,0.5,1]);this._right_camera._viewport.set([0.5,
  0,0.5,1]);this._right_camera._ignore_clear=!0;b.push(this._left_camera,this._right_camera)};Ja.prototype.onStart=function(a){a=new WebSocket("ws://localhost:1981");a.onopen=function(){console.log("VR connection stablished")};a.onmessage=this.onMessage.bind(this);a.onclose=function(){console.log("OVR connection lost")};a.onerror=function(){console.error("Oculus Server not found in your machine. To run an app using Oculus Rift you need to use a client side app, you can download it from: "+OculusController.rift_server_url)};
  this._ws=a};Ja.prototype.onMessage=function(a){var b=a.data,b=JSON.parse("["+b+"]");a=quat.create();a.set(b);b=quat.fromValues(-1,0,0,0);quat.multiply(a,b,a);this._orientation=a;this._root.scene&&this._root.scene.refresh()};Ja.prototype.onStop=function(a){this._ws&&(this._ws.close(),this._ws=null)};Ja.prototype.onBeforeRender=function(a,b){var c=1024,d=512,c=v[2],d=v[3];this._color_texture&&this._color_texture.width==c&&this._color_texture.height==d||(this._color_texture=new GL.Texture(c,d,{format:gl.RGB,
  filter:gl.LINEAR}),e.ResourcesManager.textures[":vr_color_buffer"]=this._color_texture);e.Renderer.color_rendertarget=this.enabled?this._color_texture:null};Ja.prototype.onAfterRender=function(a,b){this._color_texture&&this._color_texture.toViewport()};Pa.prototype.configure=function(a){};Pa.icon="mini-icon-clock.png";Pa.prototype.onAddedToNode=function(a){LEvent.bind(a,"update",this.onUpdate,this)};Pa.prototype.onRemoveFromNode=function(a){LEvent.unbind(a,"update",this.onUpdate,this)};Pa.prototype.onUpdate=
  function(a,b){var c=this._root.scene;c||c.refresh()};Pa.prototype.getResources=function(a){};Pa.prototype.onResourceRenamed=function(a,b,c){};ya.prototype.setupContext=function(){this._engine||(this._engine={component:this,node:this._root,scene:new THREE.Scene,camera:new THREE.PerspectiveCamera(70,gl.canvas.width/gl.canvas.height,1,1E3),renderer:new THREE.WebGLRenderer({canvas:gl.canvas,context:gl}),root:new THREE.Object3D},this._engine.scene.add(this._engine.root))};ya.default_code="//renderer, camera, scene, already created, they are globals.\n//use root as your base Object3D node if you want to use the scene manipulators.\n\nthis.start = function() {\n}\n\nthis.render = function(){\n}\n\nthis.update = function(dt){\n}\n";
  ya.library_url="http://threejs.org/build/three.min.js";Object.defineProperty(ya.prototype,"code",{set:function(a){this._code=a;this.processCode()},get:function(){return this._code},enumerable:!0});ya["@code"]={widget:"code",allow_inline:!1};ya.prototype.onAddedToScene=function(a){LEvent.bind(e.Renderer,"renderInstances",this.onEvent,this);LEvent.bind(a,"start",this.onEvent,this);LEvent.bind(a,"update",this.onEvent,this);LEvent.bind(a,"finish",this.onEvent,this);this.processCode()};ya.prototype.clearScene=
  function(){if(this._engine){for(var a=this._engine.root,b=a.children.length-1;0<=b;b--)a.remove(a.children[b]);a=this._engine.scene;for(b=a.children.length-1;0<=b;b--)a.children[b]!=this._engine.root&&a.remove(a.children[b])}};ya.prototype.onRemovedFromScene=function(a){LEvent.unbind(e.Renderer,"renderInstances",this.onEvent,this);LEvent.unbindAll(a,this);this.autoclear&&this.clearScene()};ya.prototype.onEvent=function(a,b){if(this.enabled&&this._engine){var c=this._engine;if("start"==a)this.autoclear&&
  this.clearScene(),this._script&&this._script.callMethod("start");else if("renderInstances"==a){var d=e.Renderer._current_camera;c.camera.fov=d.fov;c.camera.aspect=d._final_aspect;c.camera.near=d.near;c.camera.far=d.far;c.camera.updateProjectionMatrix();c.camera.position.fromArray(d._global_eye);c.camera.lookAt(new THREE.Vector3(d._global_center[0],d._global_center[1],d._global_center[2]));d=vec3.create();this._root.transform&&this._root.transform.getGlobalPosition(d);c.root.position.set(d[0],d[1],
  d[2]);d=quat.create();this._root.transform&&this._root.transform.getGlobalRotation(d);c.root.quaternion.set(d[0],d[1],d[2],d[3]);d=vec3.fromValues(1,1,1);this._root.transform&&this._root.transform.getGlobalScale(d);c.root.scale.set(d[0],d[1],d[2]);c.renderer.setSize(gl.viewport_data[2],gl.viewport_data[3]);c.renderer.resetGLState();this._script?this._script.callMethod("render"):c.renderer.render(c.scene,c.camera)}else"update"==a?this._script?this._script.callMethod("update",b):c.scene.update(b):"finish"==
  a&&this._script&&this._script.callMethod("finish")}};ya.prototype.loadLibrary=function(a){if(this._loading)LEvent.bind(this,"threejs_loaded",a,this);else if(this._loaded)a&&a.call(this);else{this._loading=!0;var b=this;e.Network.requestScript(ya.library_url,function(){console.log("ThreeJS library loaded");b._loading=!1;b._loaded=!0;LEvent.trigger(b,"threejs_loaded");LEvent.unbindAllEvent(b,"threejs_loaded");b._engine||b.setupContext()})}};ya.prototype.processCode=function(a){if(this._script&&this._root&&
  this._root.scene)if(this._script.code=this.code,"undefined"==typeof THREE)this.loadLibrary(function(){this.processCode()});else return this._engine||this.setupContext(),this._root&&!e.Script.block_execution?this._script.compile(this._engine,!0):!0};e.registerComponent(ya);Y.icon="mini-icon-cursor.png";Y.PICKING=1;Y.BOUNDING=2;Y.COLLIDERS=3;Y.RENDER_INSTANCES=4;Y["@mode"]={type:"enum",values:{Picking:Y.PICKING,Bounding:Y.BOUNDING,Colliders:Y.COLLIDERS}};Y["@layers"]={type:"layers"};Y.prototype.onAddedToScene=
  function(a){LEvent.bind(a,"mousedown",this._onMouse,this);LEvent.bind(a,"mousemove",this._onMouse,this);LEvent.bind(a,"mouseup",this._onMouse,this)};Y.prototype.onRemovedFromScene=function(a){LEvent.unbindAll(a,this)};Y.prototype.getNodeUnderMouse=function(a){var b=this.layers;if(this.mode==Y.PICKING)return e.Picking.getNodeAtCanvasPosition(a.canvasx,a.canvasy,null,b);var c=e.Renderer.getCameraAtPosition(a.canvasx,a.canvasy);if(!c)return null;a=c.getRayInPixel(a.canvasx,a.canvasy);if(this.mode==Y.BOUNDING){b=
  e.Physics.raycastRenderInstances(a.origin,a.direction,{layers:b});if(!b||!b.length)return null;this._last_collision=b[0];return b[0].node}if(this.mode==Y.RENDER_INSTANCES){b=e.Physics.raycastRenderInstances(a.origin,a.direction,{layers:b,triangle_collision:!0});if(!b||!b.length)return null;this._last_collision=b[0];return b[0].node}if(this.mode==Y.COLLIDERS){b=e.Physics.raycast(a.origin,a.direction,{layers:b});if(!b||!b.length)return null;this._last_collision=b[0];return b[0].node}return null};Y.prototype._onMouse=
  function(a,b){if(this.enabled&&(("mousedown"==b.eventType||"mousewheel"==b.eventType)&&(this._clicked_node=this.getNodeUnderMouse(b))&&"mousedown"==b.eventType&&0==b.button&&(console.log("Node clicked: "+this._clicked_node.name),LEvent.trigger(this._clicked_node,"clicked",b),LEvent.trigger(this._root.scene,"node_clicked",this._clicked_node)),this._clicked_node&&(b.scene_node=this._clicked_node,LEvent.trigger(this._clicked_node,b.eventType,b)),"mouseup"==b.eventType&&(this._clicked_node=null),this._clicked_node))return!0};
  e.registerComponent(Y);e.Formats={supported:{},safe_parsing:!1,merge_smoothgroups:!1,addSupportedFormat:function(a,b){a.constructor===String&&(a=a.split(","));for(var c=0;c<a.length;++c){var d=a[c].toLowerCase();this.supported[d]&&console.warn("There is already another parser associated to this extension: "+d);this.supported[d]=b}},registerParser:function(a){this.addSupportedFormat(a.extension,a)},parse:function(a,b,c){c=c||{};var d=this.getFileFormatInfo(a);d.extension=c.extension?c.extension:e.ResourcesManager.getExtension(a);
  var f=this.supported[d.extension];if(!f||!f.parse)return console.error("Parser Error: No parser found for "+d.extension+" format"),null;d=null;if(this.safe_parsing)try{d=f.parse(b,c,a)}catch(g){return console.error("Error parsing content",g),null}else d=f.parse(b,c,a);d&&(d.name=a);return d},TEXT_FORMAT:"text",JSON_FORMAT:"json",XML_FORMAT:"xml",BINARY_FORMAT:"binary",MESH_DATA:"MESH",IMAGE_DATA:"IMAGE",NONATIVE_IMAGE_DATA:"NONATIVE_IMAGE",SCENE_DATA:"SCENE",GENERIC_DATA:"GENERIC",getFileFormatInfo:function(a){a=
  a.substr(a.lastIndexOf(".")+1).toLowerCase();return this.supported[a]},guessType:function(a){if(!a)return null;a=e.RM.getExtension(a).toLowerCase();return(a=this.supported[a])?a.resource:null},convertToDataURL:function(a){var b=document.createElement("canvas");b.width=a.width;b.height=a.height;var c=b.getContext("2d"),d=c.createImageData(a.width,a.height);if(3==a.bytesPerPixel)for(var f=0;f<b.width;++f)for(var e=0;e<b.height;++e){var h=e*b.width*4+4*f,k=(b.height-e-1)*b.width*3+3*f;d.data[h+2]=a.pixels[k];
  d.data[h+1]=a.pixels[k+1];d.data[h+0]=a.pixels[k+2];d.data[h+3]=255}else for(f=0;f<b.width;++f)for(e=0;e<b.height;++e)h=e*b.width*4+4*f,k=(b.height-e-1)*b.width*4+4*f,d.data[h+0]=a.pixels[k+2],d.data[h+1]=a.pixels[k+1],d.data[h+2]=a.pixels[k+0],d.data[h+3]=a.pixels[k+3];c.putImageData(d,0,0);a.dataurl=b.toDataURL("image/png");return a.dataurl},computeMeshBounding:function(a){for(var b=[a[0],a[1],a[2]],c=[a[0],a[1],a[2]],d=0;d<a.length;d+=3){var f=[a[d],a[d+1],a[d+2]];f[0]<b[0]?b[0]=f[0]:f[0]>c[0]&&
  (c[0]=f[0]);f[1]<b[1]?b[1]=f[1]:f[1]>c[1]&&(c[1]=f[1]);f[2]<b[2]?b[2]=f[2]:f[2]>c[2]&&(c[2]=f[2])}a=[0.5*(b[0]+c[0]),0.5*(b[1]+c[1]),0.5*(b[2]+c[2])];b=[b[0]-a[0],b[1]-a[1],b[2]-a[2]];return BBox.setCenterHalfsize(BBox.create(),a,b)}};e.Formats.addSupportedFormat("png,jpg,jpeg,webp,bmp,gif",{"native":!0,dataType:"arraybuffer",resource:"Texture",resourceClass:GL.Texture,has_preview:!0,type:"image"});e.Formats.addSupportedFormat("wbin",{dataType:"arraybuffer"});e.Formats.addSupportedFormat("json,js,txt,html,css,csv",
  {dataType:"text"});e.Formats.addSupportedFormat("glsl",{dataType:"text",resource:"ShaderCode",resourceClass:e.ShaderCode});e.Formats.addSupportedFormat("zip",{dataType:"arraybuffer"});z.classes=e.Classes;e.Formats.registerParser({extension:"ase",type:"mesh",resource:"Mesh",format:"text",dataType:"text",parse:function(a,b,c){b=b||{};var d=[],f=[];c=[];var g=null,h=[],k=[],m=null,m=null,l=0,p=-1,n=null,q=[],r=this.flipAxis;null!=b.flipAxis&&(r=b.flipAxis);b=r||b.flipNormals;a=a.split("\n");for(var u=
  0;u<a.length;++u)if(m=a[u].replace(/[ \t]+/g," ").replace(/\s\s*$/,"")," "==m[0]&&(m=m.substr(1,m.length)),""!=m)if(m=m.split(" "),"*MESH"==m[0]){if(l+=1,h=[],1<l)break}else if("*NODE_NAME"==m[0])m[1].substr(1,m[1].length-2);else if("*MESH_VERTEX"==m[0])r?h.push([-1*parseFloat(m[2]),parseFloat(m[4]),parseFloat(m[3])]):h.push([parseFloat(m[2]),parseFloat(m[3]),parseFloat(m[4])]);else if("*MESH_FACE"==m[0]){var t=parseInt(m[17]);p!=t&&(p=t,null!=n&&(n.length=d.length/3-n.start,0<n.length&&q.push(n)),
  n={name:"mat_"+t,start:d.length/3,length:-1,material:""});t=h[parseInt(m[3])];d.push(t[0],t[1],t[2]);t=h[parseInt(m[5])];d.push(t[0],t[1],t[2]);t=h[parseInt(m[7])];d.push(t[0],t[1],t[2])}else"*MESH_TVERTLIST"==m[0]?k=[]:"*MESH_TVERT"==m[0]?k.push([parseFloat(m[2]),parseFloat(m[3])]):"*MESH_TFACELIST"==m[0]?(g&&g.length&&c.push(g),g=[]):"*MESH_TFACE"==m[0]?(t=k[parseInt(m[2])],g.push(t[0],t[1]),t=k[parseInt(m[3])],g.push(t[0],t[1]),t=k[parseInt(m[4])],g.push(t[0],t[1])):"*MESH_MAPPINGCHANNEL"==m[0]?
  (g&&c.push(g),g=[]):"*MESH_VERTEXNORMAL"==m[0]&&(b?f.push(-1*parseFloat(m[2]),parseFloat(m[4]),parseFloat(m[3])):f.push(parseFloat(m[2]),parseFloat(m[3]),parseFloat(m[4])));g&&c.push(g);g=d.length/3-n.start;n&&1<g&&(n.length=g,q.push(n));n={info:{}};n.vertices=new Float32Array(d);0<f.length&&(n.normals=new Float32Array(f));for(d=0;d<c.length;++d)f="",0<d&&(f=d+1),n["coords"+f]=new Float32Array(c[d]);n.bounding=e.Formats.computeMeshBounding(n.vertices);1<q.length&&(n.info.groups=q);return n}});e.Formats.registerParser({extension:"bvh",
  type:"scene",resource:"SceneTree",format:"text",dataType:"text",parse:function(a,b,c){var d=0,f=b=null,e=null,h=[];c=[];var k=-1,m=-1,l=-1,p=0,n={Xposition:"x",Yposition:"y",Zposition:"z",Xrotation:"xrotation",Yrotation:"yrotation",Zrotation:"zrotation"},q=!1;a=a.split("\n");for(var r=a.length,u=0;u<r;++u){var t=a[u].trim();if("#"!=t[0]&&""!=t)if(t=t.split(" "),f=t[0],!d)switch(f){case "HIERARCHY":d=1}else if(1==d)switch(f){case "ROOT":b=e={name:t[1]};break;case "JOINT":f=e;h.push(f);e={name:t[1],
  node_type:"JOINT"};f.children||(f.children=[]);f.children.push(e);break;case "End":q=!0;break;case "}":q?q=!1:(e=h.pop())||(e=b);break;case "CHANNELS":for(f=2;f<t.length;++f){var s=t[f];n[s]&&(s=n[s]);c.push({name:t[f],property:e.name+"/"+s,type:"number",value_size:1,data:[],packed_data:!0})}break;case "OFFSET":f=e;t=t.slice(1).map(parseFloat);f.transform={position:t};break;case "MOTION":d=2}else if(2==d)"Frames:"==t[0]?k=parseInt(t[1]):"Frame"==t[0]&&"Time:"==t[1]&&(m=parseFloat(t[2])),-1!=k&&-1!=
  m&&(l=k*m,d=3);else if(3==d){s=p*m;for(f=0;f<c.length;++f)c[f].data.push(s,parseFloat(t[f]));++p}}for(d=0;d<c.length;++d)c[d].duration=l;c={name:"#animation",object_type:"Animation",takes:{"default":{name:"default",tracks:c}}};b.animations=c.name;l={};l[c.name]=c;b={root:b,object_type:"SceneNode",resources:l};console.log(b);return b}});(function(a){function b(a,b){var c=new XMLHttpRequest;c.onload=function(){200==this.status&&b&&b(this.response)};-1==a.indexOf("://")&&(a=Collada.dataPath+a);c.open("get",
  a,!0);c.send()}var c=void 0===a.document,d=2*Math.PI/360;c&&(a.console={log:function(a){var b=Array.prototype.slice.call(arguments,0);self.postMessage({action:"log",params:b})},warn:function(a){var b=Array.prototype.slice.call(arguments,0);self.postMessage({action:"warn",params:b})},error:function(a){var b=Array.prototype.slice.call(arguments,0);self.postMessage({action:"error",params:b})}},a.alert=console.error);a.Collada={libsPath:"./",workerPath:"./",no_flip:!0,use_transferables:!0,onerror:null,
  verbose:!1,config:{forceParser:!1},init:function(a){a=a||{};for(var b in a)this[b]=a[b];this.config=a;if(c)try{importScripts(this.libsPath+"gl-matrix-min.js",this.libsPath+"tinyxml.js")}catch(d){Collada.throwException(Collada.LIBMISSING_ERROR)}mat4.create();vec3.create();vec3.create();vec3.create();quat.create();c&&console.log("Collada worker ready")},load:function(a,c){b(a,function(a){a?c(Collada.parse(a)):c(null)})},_xmlroot:null,_nodes_by_id:null,_transferables:null,_controllers_found:null,_geometries_found:null,
  safeString:function(a){return a?this.convertID?this.convertID(a):a.replace(/ /g,"_"):""},LIBMISSING_ERROR:"Libraries loading error, when using workers remember to pass the URL to the tinyxml.js in the options.libsPath",NOXMLPARSER_ERROR:"TinyXML not found, when using workers remember to pass the URL to the tinyxml.js in the options.libsPath (Workers do not allow to access the native XML DOMParser)",throwException:function(a){if(c)self.postMessage({action:"exception",msg:a});else if(Collada.onerror)Collada.onerror(a);
  throw a;},getFilename:function(a){var b=a.lastIndexOf("\\");-1!=b&&(a=a.substr(b+1));b=a.lastIndexOf("/");-1!=b&&(a=a.substr(b+1));return a},last_name:0,generateName:function(a){a=(a||"name_")+this.last_name;this.last_name++;return a},parse:function(b,c,d){d=d||"_dae_"+Date.now()+".dae";var e=null;c=null;this._transferables=[];this.verbose&&console.log(" - XML parsing...");if(a.DOMParser&&!this.config.forceParser)e=new DOMParser,c=e.parseFromString(b,"text/xml"),this.verbose&&console.log(" - XML parsed");
  else{if(!a.DOMImplementation)return Collada.throwException(Collada.NOXMLPARSER_ERROR);try{e=new DOMImplementation}catch(m){return Collada.throwException(Collada.NOXMLPARSER_ERROR)}c=e.loadXML(b);this.verbose&&console.log(" - XML parsed");b=c._nodes_by_id={};for(var e=0,l=c.all.length;e<l;++e){var p=c.all[e];b[p.id]=p;p.getAttribute("sid")&&(b[p.getAttribute("sid")]=p)}this.extra_functions||(this.extra_functions=!0,DOMDocument.prototype.querySelector=DOMElement.prototype.querySelector=function(a){a=
  a.split(" ");for(var b=this;a.length;){var c=a.shift().split("#"),d=c[0],c=c[1],d=d?b.getElementsByTagName(d):b.childNodes;if(c)for(var f=0;f<d.length;f++){if(d.item(f).getAttribute("id")==c){if(0==a.length)return d.item(f);b=d.item(f);break}}else{if(0==a.length)return d.item(0);b=d.item(0)}}return null},DOMDocument.prototype.querySelectorAll=DOMElement.prototype.querySelectorAll=function(a){function b(a,c){if(c){var f=c.shift(),f=a.getElementsByTagName(f);if(0==c.length)for(var e=0;e<f.length;e++)d.push(f.item(e));
  else for(e=0;e<f.length;e++)b(f.item(e),c.concat())}}var c=a.split(" ");if(1==c.length)return this.getElementsByTagName(a);var d=[];b(this,c);a=new DOMNodeList(this.documentElement);a._nodes=d;a.length=d.length;return a},Object.defineProperty(DOMElement.prototype,"textContent",{get:function(){return this.getChildNodes().item(0).toString()},set:function(){}}))}this._xmlroot=c;if(b=c.querySelector("COLLADA"))this._current_DAE_version=b.getAttribute("version"),console.log("DAE Version:"+this._current_DAE_version);
  e=c.getElementsByTagName("visual_scene").item(0);if(!e)throw"visual_scene XML node not found in DAE";this._nodes_by_id={};this._controllers_found={};this._geometries_found={};b={object_type:"SceneTree",light:null,materials:{},meshes:{},resources:{},root:{children:[]},external_files:{}};if(p=c.getElementsByTagName("asset")[0])b.metadata=this.readAsset(p);l=e.childNodes;for(e=0;e<l.length;e++)"node"==l.item(e).localName&&(p=this.readNodeTree(l.item(e),b,0,!1))&&b.root.children.push(p);for(e=0;e<l.length;e++)"node"==
  l.item(e).localName&&this.readNodeInfo(l.item(e),b,0,!1);this.readLibraryControllers(b);if(e=this.readAnimations(c,b))d="#animations_"+d.substr(0,d.indexOf(".")),b.resources[d]=e,b.root.animations=d;b.images=this.readImages(c);this._nodes_by_id={};this._controllers_found={};this._geometries_found={};this._xmlroot=null;return b},readAsset:function(a){for(var b={},c=0;c<a.childNodes.length;c++){var d=a.childNodes.item(c);if(1==d.nodeType)switch(d.localName){case "contributor":if(d=d.querySelector("authoring_tool"))b.authoring_tool=
  d.textContext;break;case "unit":b.unit=d.getAttribute("name");break;default:b[d.localName]=d.textContent}}return b},readNodeTree:function(a,b,c,d){var e=this.safeString(a.getAttribute("id")),l=this.safeString(a.getAttribute("sid")),p=this.safeString(a.getAttribute("name")),n=e||l||p;if(!n)return console.warn("Collada: node without name or id, skipping it"),null;var p={name:p,id:n,children:[],_depth:c},q=a.getAttribute("type");q&&(p.type=q);this._nodes_by_id[n]=p;e&&(this._nodes_by_id[e]=p);l&&(this._nodes_by_id[l]=
  p);p.model=this.readTransform(a,c,d);for(e=0;e<a.childNodes.length;e++)l=a.childNodes.item(e),1==l.nodeType&&"node"==l.localName&&(l=this.readNodeTree(l,b,c+1,d))&&p.children.push(l);return p},readNodeInfo:function(a,b,c,d,e){var l=this.safeString(a.getAttribute("id")),p=this.safeString(a.getAttribute("sid")),n=this.safeString(a.getAttribute("name"));if(n=l||p||n)e=this._nodes_by_id[n];else if(e)e=this._nodes_by_id[e.id||e.sid||e.name];else return console.warn("Collada: node without name or id, skipping it"),
  null;if(!e)return console.warn("Collada: Node not found by id: "+(l||p)),null;for(l=0;l<a.childNodes.length;l++)if(p=a.childNodes.item(l),1==p.nodeType)if("node"==p.localName)this.readNodeInfo(p,b,c+1,d,a);else{if("instance_geometry"==p.localName){var n=p.getAttribute("url"),q=n.toString().substr(1);e.mesh?(e.meshes||(e.meshes=[e.mesh]),e.meshes.push(q)):e.mesh=q;if(!b.meshes[n]){var r=this.readGeometry(n,d);r&&(r.name=q,b.meshes[q]=r)}if(n=p.querySelectorAll("instance_material"))for(q=0;q<n.length;++q)if(r=
  n.item(q)){var u=r.getAttribute("target").toString().substr(1);if(!b.materials[u]){var t=this.readMaterial(u);t&&(t.id=u,b.materials[t.id]=t)}0==q?e.material=u:(e.materials||(e.materials=[]),e.materials.push(u))}else console.warn("instance_material not found: "+l)}if("instance_controller"==p.localName&&(n=p.getAttribute("url"),r=this._xmlroot.querySelector("controller"+n))){r=this.readController(r,d,b);if(q=p.querySelector("bind_material"))for(var s=q.querySelectorAll("technique_common"),w=0;w<s.length;w++)for(var x=
  s.item(w).querySelectorAll("instance_material"),q=0;q<x.length;q++)(u=x.item(q))?(u=u.getAttribute("target").toString().substr(1),!b.materials[u]&&(t=this.readMaterial(u))&&(t.id=u,b.materials[t.id]=t),0==q?e.material=u:(e.materials||(e.materials=[]),e.materials.push(u))):console.warn("instance_material for controller not found: "+u);r&&(q=r,"morph"==r.type&&(q=r.mesh,e.morph_targets=r.morph_targets),q.name=n.toString(),e.mesh=n.toString(),b.meshes[n]=q)}"instance_light"==p.localName&&(n=p.getAttribute("url"),
  this.readLight(e,n));"instance_camera"==p.localName&&(n=p.getAttribute("url"),this.readCamera(e,n))}},material_translate_table:{},light_translate_table:{point:"omni",directional:"directional",spot:"spot"},camera_translate_table:{xfov:"fov",aspect_ratio:"aspect",znear:"near",zfar:"far"},querySelectorAndId:function(a,b,c){a=a.querySelectorAll(b);for(b=0;b<a.length;b++){var d=a.item(b).getAttribute("id");if(d&&(d=d.toString(),d==c))return a.item(b)}return null},getFirstChildElement:function(a,b){for(var c=
  a.childNodes,d=0;d<c.length;++d){var e=c.item(d);if(e.localName&&!b||b&&b==e.localName)return e}return null},readMaterial:function(a){a=this.querySelectorAndId(this._xmlroot,"library_materials material",a);if(!a)return null;a=a.querySelector("instance_effect");if(!a)return null;a=a.getAttribute("url").substr(1);a=this.querySelectorAndId(this._xmlroot,"library_effects effect",a);if(!a)return null;var b=a.querySelector("technique");if(!b)return null;var c=a.querySelectorAll("newparam");a={};for(var d=
  0;d<c.length;d++){var e=c[d].querySelector("init_from"),e=e?e.innerHTML:c[d].querySelector("source").innerHTML;a[c[d].getAttribute("sid")]={parent:e}}var c={},e=this.readImages(this._xmlroot),l=b.querySelector("phong");l||(l=b.querySelector("blinn"));l||(l=b.querySelector("lambert"));if(!l)return null;for(d=0;d<l.childNodes.length;++d){var p=l.childNodes.item(d);if(p.localName){b=p.localName.toString();this.material_translate_table[b]&&(b=this.material_translate_table[b]);var n=this.getFirstChildElement(p);
  n&&("color"==n.localName.toString()?(n=this.readContentAsFloats(n),"RGB_ZERO"==p.getAttribute("opaque")?c[b]=n.subarray(0,4):c[b]=n.subarray(0,3)):"float"==n.localName.toString()?c[b]=this.readContentAsFloats(n)[0]:"texture"==n.localName.toString()&&(c.textures||(c.textures={}),p=n.getAttribute("texture"))&&(-1===p.indexOf(".")&&(p=this.getParentParam(a,p),e[p]&&(p=e[p].path)),p={map_id:p},n=n.getAttribute("texcoord"),p.uvs=n,c.textures[b]=p))}}c.object_type="Material";return c},getParentParam:function(a,
  b){return a[b]?a[b].parent?this.getParentParam(a,a[b].parent):b:b},readLight:function(a,b){function c(a,b){for(var d=0;d<b.childNodes.length;d++){var e=b.childNodes.item(d);if(e&&1==e.nodeType)switch(e.localName){case "color":a.color=Collada.readContentAsFloats(e);break;case "falloff_angle":a.angle_end=Collada.readContentAsFloats(e)[0],a.angle=a.angle_end-10}}}var d={},e=null;if(1<b.length)e=this._xmlroot.querySelector("library_lights "+b);else var l=this._xmlroot.querySelector("library_lights"),
  e=this.getFirstChildElement(l,"light");if(!e)return null;var l=[],p=e.querySelector("technique_common");if(p)for(var n=0;n<p.childNodes.length;n++)1==p.childNodes.item(n).nodeType&&l.push(p.childNodes.item(n));e=e.querySelectorAll("technique");for(n=0;n<e.length;n++)for(var p=e.item(n),q=0;q<p.childNodes.length;q++)1==p.childNodes.item(q).nodeType&&l.push(p.childNodes.item(q));for(n=0;n<l.length;n++)switch(p=l[n],p.localName){case "point":d.type=this.light_translate_table[p.localName];c(d,p);break;
  case "directional":d.type=this.light_translate_table[p.localName];c(d,p);break;case "spot":d.type=this.light_translate_table[p.localName];c(d,p);break;case "intensity":d.intensity=this.readContentAsFloats(p)[0]}a.model?(d.position=[a.model[12],a.model[13],a.model[14]],l=[-a.model[8],-a.model[9],-a.model[10]],d.target=[d.position[0]+l[0],d.position[1]+l[1],d.position[2]+l[2]]):(console.warn("Could not read light position for light: "+a.name+". Setting defaults."),d.position=[0,0,0],d.target=[0,-1,
  0]);a.light=d},readCamera:function(a,b){var c={},d=this._xmlroot.querySelector("library_cameras "+b);if(!d)return null;var e=[],l=d.querySelector("technique_common");if(l)for(d=0;d<l.childNodes.length;d++)1==l.childNodes.item(d).nodeType&&e.push(l.childNodes.item(d));for(d=0;d<e.length;d++)for(var l=c,p=e[d],n=0;n<p.childNodes.length;n++){var q=p.childNodes.item(n);q&&1==q.nodeType&&(l[Collada.camera_translate_table[q.localName]||q.localName]=parseFloat(q.textContent))}c.yfov&&!c.fov&&(c.aspect?c.fov=
  c.yfov*c.aspect:console.warn("Could not convert camera yfov to xfov because aspect ratio not set"));a.camera=c},readTransform:function(a,b,c){for(var e=mat4.create(),m=mat4.create(),l=quat.create(),p=0;p<a.childNodes.length;p++){var n=a.childNodes.item(p);if(n&&1==n.nodeType){if("matrix"==n.localName){e=this.readContentAsFloats(n);this.transformMatrix(e,0==b);break}if("translate"==n.localName){var q=this.readContentAsFloats(n);c&&0<b&&(n=q[1],q[1]=q[2],q[2]=-n);mat4.translate(e,e,q)}else"rotate"==
  n.localName?(q=this.readContentAsFloats(n),4==q.length&&("jointOrientX"==n.getAttribute("sid")&&(q[3]+=90),c&&(n=q[1],q[1]=q[2],q[2]=-n),0!=q[3]&&(quat.setAxisAngle(l,q.subarray(0,3),q[3]*d),mat4.fromQuat(m,l),mat4.multiply(e,e,m)))):"scale"==n.localName&&(q=this.readContentAsFloats(n),c&&(n=q[1],q[1]=q[2],q[2]=-n),mat4.scale(e,e,q))}}return e},readTransform2:function(a,b,c){for(var e=mat4.create(),m=quat.create(),l=mat4.create(),p=quat.create(),n=vec3.create(),q=vec3.fromValues(1,1,1),r=0;r<a.childNodes.length;r++){var u=
  a.childNodes.item(r);if("matrix"==u.localName)return e=this.readContentAsFloats(u),this.transformMatrix(e,0==b),e;if("translate"==u.localName){var t=this.readContentAsFloats(u);n.set(t)}else"rotate"==u.localName?(t=this.readContentAsFloats(u),4==t.length&&("jointOrientX"==u.getAttribute("sid")&&(t[3]+=90),c&&(u=t[1],t[1]=t[2],t[2]=-u),0!=t[3]&&(quat.setAxisAngle(p,t.subarray(0,3),t[3]*d),quat.multiply(m,m,p)))):"scale"==u.localName&&(t=this.readContentAsFloats(u),c&&(u=t[1],t[1]=t[2],t[2]=-u),q.set(t))}c&&
  0<b&&(u=n[1],n[1]=n[2],n[2]=-u);mat4.translate(e,e,n);mat4.fromQuat(l,m);mat4.multiply(e,e,l);mat4.scale(e,e,q);return e},readGeometry:function(a,b,d){if(void 0!==this._geometries_found[a])return this._geometries_found[a];var e=this._xmlroot.getElementById(a.substr(1));if(!e)return console.warn("readGeometry: geometry not found: "+a),this._geometries_found[a]=null;if("controller"==e.localName)return d=this.readController(e,b,d),this._geometries_found[a]=d;if("geometry"!=e.localName)return console.warn("readGeometry: tag should be geometry, instead it was found: "+
  e.localName),this._geometries_found[a]=null;var m=e.querySelector("mesh");if(!m)return console.warn("readGeometry: mesh not found in geometry: "+a),this._geometries_found[a]=null;var e={},l=m.querySelectorAll("source");for(d=0;d<l.length;d++){var p=l.item(d);if(p.querySelector){var n=p.querySelector("float_array");if(n){var n=this.readContentAsFloats(n),q=p.querySelector("accessor"),q=parseInt(q.getAttribute("stride"));e[p.getAttribute("id")]={stride:q,data:n}}}}l=m.querySelector("vertices input");
  l=e[l.getAttribute("source").substr(1)];e[m.querySelector("vertices").getAttribute("id")]=l;l=null;(p=m.querySelector("polygons"))&&(l=this.readTriangles(p,e));l||(p=m.querySelectorAll("triangles"))&&p.length&&(l=this.readTriangles(p,e));l||(p=m.querySelector("polylist"))&&(l=this.readPolylist(p,e));l||(m=m.querySelector("linestrips"))&&(l=this.readLineStrip(e,m));if(!l)return console.log("no polygons or triangles in mesh: "+a),this._geometries_found[a]=null;if(b&&!this.no_flip){b=0;e=l.vertices;
  d=0;for(m=e.length;d<m;d+=3)b=e[d+1],e[d+1]=e[d+2],e[d+2]=-b;e=l.normals;d=0;for(m=e.length;d<m;d+=3)b=e[d+1],e[d+1]=e[d+2],e[d+2]=-b}if(c&&this.use_transferables)for(d in l)(b=l[d])&&b.buffer&&100<b.length&&this._transferables.push(b.buffer);l.filename=a;l.object_type="Mesh";return this._geometries_found[a]=l},readTriangles:function(a,b){for(var c=[],d=[],e=0,l={},p=[],n=[],q=0,r="",u=0;u<a.length;u++){var t=a.item(u),s="triangles"==t.localName,r=t.getAttribute("material");0==u&&(d=this.readShapeInputs(t,
  b));for(var t=t.querySelectorAll("p"),w=1,x=d.length,E=0;E<x;++E)w=Math.max(w,d[E][4]+1);for(E=0;E<t.length;E++){var y=t.item(E);if(!y||!y.textContent)break;for(var y=y.textContent.trim().split(" "),z=-1,A=-1,C=-1,B=0,I=y.length;B<I;B+=w){var H=y.slice(B,B+w).join(" "),C=A;if(l.hasOwnProperty(H))A=l[H];else{for(A=0;A<x;++A){var F=d[A],D=F[1],J=F[3],K=parseInt(y[B+F[4]]);0==A&&(p[D.length/F[2]]=K);for(var K=K*F[2],M=0;M<F[2];++M)D.push(J[K+M])}A=e;e+=1;l[H]=A}s||(0==B&&(z=A),2<B&&(n.push(z),n.push(C)));
  n.push(A)}}r={name:"group"+u,start:q,length:n.length-q,material:r||""};q=n.length;c.push(r)}c={vertices:new Float32Array(d[0][1]),info:{groups:c},_remap:new Uint32Array(p)};this.transformMeshInfo(c,d,n);return c},readPolylist:function(a,b){var c=[],d=0,e={},l=[],p=[];a.getAttribute("material");for(var c=this.readShapeInputs(a,b),n=a.querySelector("vcount"),n=this.readContentAsUInt32(n),q=a.querySelector("p"),q=this.readContentAsUInt32(q),r=1,u=c.length,t=0;t<u;++t)r=Math.max(r,c[t][4]+1);for(var s=
  t=0,w=n.length;s<w;++s)for(var x=n[s],E=-1,y=-1,z=-1,A=0;A<x;++A){var C=q.slice(t,t+r).join(" "),z=y;if(e.hasOwnProperty(C))y=e[C];else{for(y=0;y<u;++y){var B=c[y],F=B[1],I=B[3],H=parseInt(q[t+B[4]]);0==y&&(l[F.length/B[2]]=H);for(var H=H*B[2],D=0;D<B[2];++D)F.push(I[H+D])}y=d;d+=1;e[C]=y}3<x&&(0==A&&(E=y),2<A&&(p.push(E),p.push(z)));p.push(y);t+=r}d={vertices:new Float32Array(c[0][1]),info:{},_remap:new Uint32Array(l)};this.transformMeshInfo(d,c,p);return d},readShapeInputs:function(a,b){for(var c=
  [],d=a.querySelectorAll("input"),e=0;e<d.length;e++){var l=d.item(e);if(l.getAttribute){var p=l.getAttribute("semantic").toUpperCase(),n=b[l.getAttribute("source").substr(1)],q=parseInt(l.getAttribute("offset")),r=0;l.getAttribute("set")&&(r=parseInt(l.getAttribute("set")));c.push([p,[],n.stride,n.data,q,r])}}return c},transformMeshInfo:function(a,b,c){for(var d={normal:"normals",texcoord:"coords"},e=1;e<b.length;++e){var l=b[e][0].toLowerCase(),p=b[e][1];p.length&&(d[l]&&(l=d[l]),a[l]&&(l+=b[e][5]),
  a[l]=new Float32Array(p))}c&&c.length&&(a.triangles=65536<a.vertices.length?new Uint32Array(c):new Uint16Array(c));return a},readLineStrip:function(a,b){for(var c=[],d=0,e={},l=[],p=b.querySelectorAll("input"),n=0;n<p.length;n++){var q=p.item(n);if(q.getAttribute){var r=q.getAttribute("semantic").toUpperCase(),u=a[q.getAttribute("source").substr(1)],t=parseInt(q.getAttribute("offset")),s=0;q.getAttribute("set")&&(s=parseInt(q.getAttribute("set")));c.push([r,[],u.stride,u.data,t,s])}}p=b.querySelectorAll("p");
  q=c.length;for(n=0;n<p.length;n++){r=p.item(n);if(!r||!r.textContent)break;for(var r=r.textContent.trim().split(" "),w=-1,u=0,t=r.length;u<t;u+=q){s=r.slice(u,u+q).join(" ");if(e.hasOwnProperty(s))w=e[s];else{for(w=0;w<c.length;++w)for(var y=c[w],x=parseInt(r[u+w]),z=y[1],A=y[3],x=x*y[2],C=0;C<y[2];++C)z.push(A[x+C]);w=d;d+=1;e[s]=w}l.push(w)}}d={primitive:"line_strip",vertices:new Float32Array(c[0][1]),info:{}};return this.transformMeshInfo(d,c,l)},findXMLNodeById:function(a,b,c){if(this._xmlroot._nodes_by_id){var d=
  this._xmlroot._nodes_by_id[c];if(d&&d.localName==b)return d}else if(d=this._xmlroot.getElementById(c))return d;a=a.childNodes;for(d=0;d<a.length;++d){var e=a.item(d);if(1==e.nodeType&&e.localName==b&&e.getAttribute("id")==c)return e}return null},readImages:function(a){var b=a.querySelector("library_images");if(!b)return null;a={};for(var b=b.childNodes,c=0;c<b.length;++c){var d=b.item(c);if(1==d.nodeType){var e=d.querySelector("init_from");if(e&&e.textContent){var l=this.getFilename(e.textContent),
  p=d.getAttribute("id");a[p]={filename:l,map:p,name:d.getAttribute("name"),path:e.textContent}}}}return a},readAnimations:function(a,b){var c=a.querySelector("library_animations");if(!c)return null;for(var d=c.childNodes,c={object_type:"Animation",takes:{}},e={tracks:[]},l=e.tracks,p=0;p<d.length;++p){var n=d.item(p);if(1==n.nodeType&&"animation"==n.localName)if(n.getAttribute("id"))this.readAnimation(n,l);else{var q=n.querySelectorAll("animation");if(q.length)for(n=0;n<q.length;++n){var r=q.item(n);
  this.readAnimation(r,l)}else this.readAnimation(n,l)}}if(!l.length)return null;for(p=d=0;p<l.length;++p)d<l[p].duration&&(d=l[p].duration);e.name="default";e.duration=d;c.takes[e.name]=e;return c},readAnimation:function(a,b){if("animation"!=a.localName)return null;a.getAttribute("id");var c=a.querySelectorAll("channel");if(!c.length)return null;for(var d=b||[],e=0;e<c.length;++e){var l=this.readChannel(c.item(e),a);l&&d.push(l)}return d},readChannel:function(a,b){if("channel"!=a.localName||"animation"!=
  b.localName)return null;var d=a.getAttribute("source"),e=a.getAttribute("target"),m=this.findXMLNodeById(b,"sampler",d.substr(1));if(!m)return console.error("Error DAE: Sampler not found in "+d),null;for(var l={},p={},n={},q=m.querySelectorAll("input"),m=null,d=0;d<q.length;d++){var r=q.item(d),u=r.getAttribute("source"),t=r.getAttribute("semantic"),s=this.findXMLNodeById(b,"source",u.substr(1));if(s){var w=s.querySelector("param");if(w){r=w.getAttribute("type");l[t]={source:u,type:r};var y=null;
  if("float"==r||"float4x4"==r)y=s.querySelector("float_array"),y=this.readContentAsFloats(y),n[u]=y,u=w.getAttribute("name"),"TIME"==u&&(m=y),"OUTPUT"==t&&(u=t),u?p[u]=r:console.warn("Collada: <param> without name attribute in <animation>")}}}if(!m)return console.error("Error DAE: no TIME info found in <channel>: "+a.getAttribute("source")),null;d=e.split("/");e={};q=this._nodes_by_id[d[0]];r=q.id+"/"+d[1];e.name=d[1];e.property=r;r="number";u=1;p=p.OUTPUT;switch(p){case "float":u=1;break;case "float3x3":u=
  9;r="mat3";break;case "float4x4":u=16,r="mat4"}e.type=r;e.value_size=u;e.duration=m[m.length-1];l=n[l.OUTPUT.source];if(!l)return null;n=u+1;r=new Float32Array(m.length*n);for(d=0;d<m.length;++d)r[d*n]=m[d],t=l.subarray(d*u,(d+1)*u),"float4x4"==p&&this.transformMatrix(t,q?0==q._depth:0),r.set(t,d*n+1);c&&this.use_transferables&&r&&r.buffer&&100<r.length&&this._transferables.push(r.buffer);e.data=r;return e},findNode:function(a,b){if(a.id==b)return a;if(a.children)for(var c in a.children){var d=this.findNode(a.children[c],
  b);if(d)return d}return null},readLibraryControllers:function(a){var b=this._xmlroot.querySelector("library_controllers");if(!b)return null;for(var b=b.childNodes,c=0;c<b.length;++c){var d=b.item(c);if(1==d.nodeType&&"controller"==d.localName){var e=d.getAttribute("id");this._controllers_found[e]||this.readController(d,null,a)}}},readController:function(a,b,c){if("controller"==!a.localName)return console.warn("readController: not a controller: "+a.localName),null;var d=a.getAttribute("id");if(this._controllers_found[d])return this._controllers_found[d];
  var e=null,l=a.querySelector("skin");l&&(e=this.readSkinController(l,b,c));(a=a.querySelector("morph"))&&(e=this.readMorphController(a,b,c,e));return this._controllers_found[d]=e},readSkinController:function(a,b,c){var d=a.getAttribute("source");c=this.readGeometry(d,b,c);if(!c)return null;var e=this.readSources(a,b);if(!e)return null;b=null;(b=a.querySelector("bind_shape_matrix"))?(b=this.readContentAsFloats(b),this.transformMatrix(b,!0,!0)):b=mat4.create();var d=[],l=a.querySelector("joints");if(l){for(var p=
  null,n=null,q=l.querySelectorAll("input"),l=0;l<q.length;l++){var r=q[l],u=r.getAttribute("semantic").toUpperCase(),r=r.getAttribute("source"),r=e[r.substr(1)];"JOINT"==u?p=r:"INV_BIND_MATRIX"==u&&(n=r)}if(!n||!p)return console.error("Error DAE: no joints or inv_bind sources found"),null;for(l=0;l<p.length;++l)q=n.subarray(16*l,16*l+16),u=p[l],(r=this._nodes_by_id[u])?(this.transformMatrix(q,0==r._depth,!0),d.push([u,q])):console.warn("Node "+u+" not found")}if(a=a.querySelector("vertex_weights")){for(var t=
  null,q=a.querySelectorAll("input"),l=0;l<q.length;l++)"WEIGHT"==q[l].getAttribute("semantic").toUpperCase()&&(t=e[q.item(l).getAttribute("source").substr(1)]);if(!t)throw"no weights found";var l=a.querySelector("vcount"),s=this.readContentAsUInt32(l),l=a.querySelector("v"),w=this.readContentAsUInt32(l);a=c.vertices.length/3;for(var e=new Float32Array(4*a),p=new Uint8Array(4*a),y=0,n=c._remap,l=q=0,x=s.length;l<x;++l){for(var z=s[l],A=y,r=p.subarray(4*l,4*l+4),u=e.subarray(4*l,4*l+4),C=0,B=0;B<z&&
  4>B;++B)r[B]=w[A+2*B],r[B]>q&&(q=r[B]),u[B]=t[w[A+2*B+1]],C+=u[B];if(4<z&&1>C)for(r=1/C,B=0;4>B;++B)u[B]*=r;y+=2*z}t=new Float32Array(4*a);s=new Uint8Array(4*a);w=[];for(l=0;l<a;++l){r=4*n[l];u=e.subarray(r,r+4);r=p.subarray(r,r+4);for(y=0;3>y;++y){x=y;z=u[y];for(B=y+1;4>B;++B)u[B]<=z||(x=B,z=u[B]);x!=y&&(B=u[y],u[y]=u[x],u[x]=B,B=r[y],r[y]=r[x],r[x]=B)}t.set(u,4*l);s.set(r,4*l);u[0]&&(w[r[0]]=!0);u[1]&&(w[r[1]]=!0);u[2]&&(w[r[2]]=!0);u[3]&&(w[r[3]]=!0)}q>=d.length&&console.warn("Mesh uses higher bone index than bones found");
  a=[];e={};for(l=0;l<w.length;++l)w[l]&&(e[l]=a.length,a.push(d[l]));if(a.length<d.length){for(l=0;l<s.length;l++)s[l]=e[s[l]];d=a}c.weights=t;c.bone_indices=s;c.bones=d;c.bind_matrix=b}return c},readMorphController:function(a,b,c,d){d=a.getAttribute("source");d=this.readGeometry(d,b,c);if(!d)return null;var e=this.readSources(a,b),l=[];a=a.querySelector("targets");if(!a)return null;for(var p=a.querySelectorAll("input"),n=a=null,q=0;q<p.length;q++){var r=p.item(q),u=r.getAttribute("semantic").toUpperCase(),
  r=e[r.getAttribute("source").substr(1)];"MORPH_TARGET"==u?a=r:"MORPH_WEIGHT"==u&&(n=r)}if(!a||!n)return console.warn("Morph controller without targets or weights. Skipping it."),null;for(q in a)e="#"+a[q],p=this.readGeometry(e,b,c),c.meshes[e]=p,l.push({mesh:e,weight:n[q]});d.morph_targets=l;return d},readBindMaterials:function(a,b){for(var c=[],d=a.querySelectorAll("technique_common"),e=0;e<d.length;e++)for(var l=d.item(e).querySelectorAll("instance_material"),p=0;p<l.length;p++){var n=l.item(p);
  n&&c.push(n.getAttribute("symbol"))}return c},readSources:function(a,b){for(var c={},d=a.querySelectorAll("source"),e=0;e<d.length;e++){var l=d.item(e);if(l.querySelector)if(l.querySelector("float_array")){var p=this.readContentAsFloats(l);c[l.getAttribute("id")]=p}else(p=l.querySelector("Name_array"))?(p=this.readContentAsStringsArray(p))&&(c[l.getAttribute("id")]=p):(p=l.querySelector("IDREF_array"))&&(p=this.readContentAsStringsArray(p))&&(c[l.getAttribute("id")]=p)}return c},readContentAsUInt32:function(a){if(!a)return null;
  a=a.textContent;a=a.replace(/\n/gi," ");a=a.trim();if(0==a.length)return null;a=a.split(" ");for(var b=new Uint32Array(a.length),c=0;c<a.length;c++)b[c]=parseInt(a[c]);return b},readContentAsFloats:function(a){if(!a)return null;var b=a.textContent,b=b.replace(/\n/gi," "),b=b.replace(/\s\s+/gi," "),b=b.replace(/\t/gi,""),b=b.trim(),b=b.split(" ");a=(a=a.getAttribute("count"))?parseInt(a):b.length;a=new Float32Array(a);for(var c=0;c<b.length;c++)a[c]=parseFloat(b[c]);return a},readContentAsStringsArray:function(a){if(!a)return null;
  for(var b=a.textContent,b=b.replace(/\n/gi," "),b=b.replace(/\s\s/gi," "),b=b.trim(),b=b.split(" "),c=0;c<b.length;c++)b[c]=b[c].trim();if(a.getAttribute("count")&&parseInt(a.getAttribute("count"))!=b.length){var c=[],d="",e;for(e in b)d=d?d+(" "+b[e]):b[e],this._nodes_by_id[this.safeString(d)]&&(c.push(this.safeString(d)),d="");a=parseInt(a.getAttribute("count"));if(c.length==a)return c;console.error("Error: bone names have spaces, avoid using spaces in names");return null}return b},max3d_matrix_0:new Float32Array([0,
  -1,0,0,0,0,-1,0,1,0,0,-0,0,0,0,1]),transformMatrix:function(a,b,c){mat4.transpose(a,a);if(this.no_flip)return a;b?(b=new Float32Array(a.subarray(4,8)),a.set(a.subarray(8,12),4),a.set(b,8),b=a.subarray(8,12),vec4.scale(b,b,-1)):(b=mat4.create(),b.set([a[0],a[2],-a[1]],0),b.set([a[8],a[10],-a[9]],4),b.set([-a[4],-a[6],a[5]],8),b.set([a[12],a[14],-a[13]],12),a.set(b));return a}};c?(Collada.loadInWorker=function(a,b){Collada.load(b,a)},Collada.parseInWorker=function(a,b){a(Collada.parse(b))}):(Collada.launchWorker=
  function(){var a=this.worker=new Worker(Collada.workerPath+"collada.js");a.callback_ids={};a.addEventListener("error",function(a){if(Collada.onerror)Collada.onerror(err)});a.addEventListener("message",function(a){if(a.data)switch(a=a.data,a.action){case "log":console.log.apply(console,a.params);break;case "warn":console.warn.apply(console,a.params);break;case "exception":console.error.apply(console,a.params);if(Collada.onerror)Collada.onerror(a.msg);break;case "error":console.error.apply(console,
  a.params);break;case "result":var b=this.callback_ids[a.callback_id];if(!b)throw"callback not found";b(a.result);break;default:console.warn("Unknown action:",a.action)}});this.callback_ids={};this.last_callback_id=1;this.toWorker("init",[this.config])},Collada.toWorker=function(a,b,c){this.worker||this.launchWorker();var d=this.last_callback_id++;this.worker.callback_ids[d]=c;this.worker.postMessage({func:a,params:b,callback_id:d})},Collada.loadInWorker=function(a,b){this.toWorker("loadInWorker",
  [a],b)},Collada.parseInWorker=function(a,b){this.toWorker("parseInWorker",[a],b)});c&&self.addEventListener("message",function(a){if("init"==a.data.func)return Collada.init.apply(Collada,a.data.params);var b=a.data.func,c=a.data.params,d=a.data.callback_id;a=function(a){self.postMessage({action:"result",callback_id:d,result:a},Collada._transferables);Collada._transferables=null};var e=Collada[b];if(void 0===e)console.error("function not found:",b),a(null);else try{e.apply(Collada,c?[a].concat(c):
  [a])}catch(l){console.error("Error inside worker function call to "+b+" :: "+l),a(null)}},!1)})("undefined"!=typeof window?window:self);e.Formats.registerParser({extension:"dae",type:"scene",resource:"SceneNode",format:"text",dataType:"text",parse:function(a,b,c){function d(a){a.id&&(a.uid="@"+g+"::"+a.id,f[a.id]=a.uid);a.type&&(a.node_type=a.type,delete a.type);if(a.meshes)for(var b=0;b<a.meshes.length;b++)a.meshes[b]&&f[a.meshes[b]]&&(a.meshes[b]=f[a.meshes[b]]);a.mesh&&f[a.mesh]&&(a.mesh=f[a.mesh]);
  if(a.children)for(b in a.children)d(a.children[b])}if(!a||a.constructor!==String)return console.error("DAE parser requires string"),null;Collada.material_translate_table={reflectivity:"reflection_factor",specular:"specular_factor",shininess:"specular_gloss",emission:"emissive",diffuse:"color"};c=e.RM.getFilename(c);a=Collada.parse(a,b,c);console.log(a);a.root.name=c;a.metadata&&"Z_UP"==a.metadata.up_axis&&(a.root.model=mat4.rotateX(mat4.create(),mat4.create(),-90*0.0174532925));if(b.skip_renaming)return a;
  var f={},g=c.substr(0,c.indexOf("."));b={};for(var h in a.meshes)c=g+"__"+h,c=c.replace(/[^a-z0-9]/gi,"_"),f[h]=c,b[c]=a.meshes[h];a.meshes=b;for(h in a.meshes)b=a.meshes[h],this.processMesh(b,f);d(a.root);for(h in a.meshes)if(b=a.meshes[h],b.bones)for(var k in b.bones)(c=f[b.bones[k][0]])&&(b.bones[k][0]=c);for(h in a.materials)this.processMaterial(a.materials[h]);for(h in a.resources)k=a.resources[h],"Animation"==k.object_type&&this.processAnimation(k,f);return a},processMesh:function(a,b){if(a.coords&&
  a.coords.length==a.vertices.length){for(var c=a.vertices.length/3,d=a.coords,e=new Float32Array(2*c),g=0;g<c;++g)e[2*g]=d[3*g],e[2*g+1]=d[3*g+1];a.coords=e}if(a.morph_targets)for(c=0;c<a.morph_targets.length;++c)d=a.morph_targets[c],d.mesh&&b[d.mesh]&&(d.mesh=b[d.mesh])},processAnimation:function(a,b){for(var c in a.takes){for(var d=a.takes[c],e=0;e<d.tracks.length;++e){var g=d.tracks[e],h=g.property.indexOf("/");if(h){var k=g.property.substr(0,h),m=g.property.substr(h);"/transform"==m&&(m="/matrix");
  b[k]&&(k=b[k],g.property=k+m)}}m={};for(e=0;e<d.tracks.length;++e)if(g=d.tracks[e],g.packed_data=!0,"rotateX.ANGLE"==g.name||"rotateY.ANGLE"==g.name||"rotateZ.ANGLE"==g.name)k=g.property.split("/")[0],m[k]||(m[k]={tracks:[]}),m[k].tracks.push(g);for(e in m){for(var k=m[e],h={data:[],type:"quat",value_size:4,property:e+"/Transform/rotation",name:"rotation"},l=[],p=0;p<k.tracks.length;++p)for(var g=k.tracks[p],g=g.data,n=0;n<g.length;n+=2)l.push(g[n]);l.sort();g=-1;n=[];for(p=0;p<l.length;++p)l[p]!=
  g&&(n.push(l[p]),g=l[p]);l=n;h.data.length=l.length;for(p=0;p<h.data.length;++p){var q=l[p],r=quat.create();h.data[p]=[q,r];for(n=0;n<k.tracks.length;++n){var g=k.tracks[n],u;a:{u=g.data;for(var t=u.length,s=0;s<t;s+=2){if(u[s]==q){u=u[s+1];break a}if(u[s]>q){u=null;break a}}u=null}if(u)switch(u*=0.0174532925,g.name){case "rotateX.ANGLE":quat.rotateX(r,r,-u);break;case "rotateY.ANGLE":quat.rotateY(r,r,u);break;case "rotateZ.ANGLE":quat.rotateZ(r,r,u)}}}d.tracks.push(h);for(n=0;n<k.tracks.length;++n)g=
  k.tracks[n],h=d.tracks.indexOf(g),-1!=h&&d.tracks.splice(h,1)}}},processMaterial:function(a){a.object_type="StandardMaterial";a.transparency&&(a.opacity=1-parseFloat(a.transparency),a.transparent&&(a.opacity=a.transparency));if(a.textures)for(var b in a.textures){var c=a.textures[b],d=e.Material.COORDS_UV0;"TEX1"==c.uvs&&(d=e.Material.COORDS_UV1);c={texture:c.map_id,uvs:d};a.textures[b]=c}}});e.Formats.registerParser({extension:"dds",type:"image",dataType:"arraybuffer",resource:"Texture",format:"binary",
  parse:function(a,b){if(!a||a.constructor!==ArrayBuffer)throw"ParserDDS: data must be ArrayBuffer";var c=gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc"),d=new GL.Texture(0,0,b);if(!window.DDS)throw"dds.js script must be included, not found";DDS.loadDDSTextureFromMemoryEx(gl,c,a,d,!0);return d}});e.Formats.registerParser({extension:"jsmesh",type:"mesh",format:"text",dataType:"string",parse:function(a,b){var c=null;"object"==typeof a?c=a:"string"==typeof a&&(c=JSON.parse(a));c.vertices.constructor==
  Array&&(c.vertices="number"==typeof c.vertices[0]?c.vertices:linearizeArray(c.vertices),c.normals&&(c.normals="number"==typeof c.normals[0]?c.normals:linearizeArray(c.normals)),c.coords&&(c.coords="number"==typeof c.coords[0]?c.coords:linearizeArray(c.coords)),c.triangles&&(c.triangles="number"==typeof c.triangles[0]?c.triangles:linearizeArray(c.triangles)),c.vertices=new Float32Array(c.vertices),c.normals&&(c.normals=new Float32Array(c.normals)),c.coords&&(c.coords=new Float32Array(c.coords)),c.triangles&&
  (c.triangles=new Uint16Array(c.triangles)));c.bounding||(c.bounding=e.Formats.computeMeshBounding(c.vertices));return c}});e.Formats.registerParser({extension:"obj",type:"mesh",resource:"Mesh",format:"text",dataType:"text",flipAxis:!1,parse:function(a,b){b=b||{};for(var c=b.noindex?b.noindex:!1,d=[],e=[],g=[],h=[],k=[],m=[],l=[],p={},n=0,q=null,r=null,u=0,t=0,s=r=0,w=0,y=0,x=null,z=!1,A=!1,B=!1,C=!1,F=0,H=this.flipAxis||b.flipAxis,I=H||b.flipNormals,D=null,K=0,J=[],M={},N=a.split("\n"),O=N.length,
  P=0;P<O;++P)if(q=N[P].replace(/[ \t]+/g," ").replace(/\s\s*$/,""),"#"!=q[0]&&""!=q)if(x=q.split(" "),C&&"v"==x[0]&&(C=!1),"v"==x[0])H?k.push(-1*parseFloat(x[1]),parseFloat(x[3]),parseFloat(x[2])):k.push(parseFloat(x[1]),parseFloat(x[2]),parseFloat(x[3]));else if("vt"==x[0])m.push(parseFloat(x[1]),parseFloat(x[2]));else if("vn"==x[0])I?l.push(-parseFloat(x[2]),-parseFloat(x[3]),parseFloat(x[1])):l.push(parseFloat(x[1]),parseFloat(x[2]),parseFloat(x[3]));else if("f"==x[0]){if(C=!0,!(4>x.length)){for(var q=
  [],L=1;L<x.length;++L){var R=K+":"+x[L];if(!(R in p)||c){r=x[L].split("/");if(1==r.length)r=t=u=parseInt(r[0])-1;else if(2==r.length)u=parseInt(r[0])-1,t=parseInt(r[1])-1,r=-1;else if(3==r.length)u=parseInt(r[0])-1,t=parseInt(r[1])-1,r=parseInt(r[2])-1;else return console.log("Problem parsing: unknown number of values per face"),!1;3<L&&c&&(s=d.length,d.push(d[s-9*(L-3)],d[s-9*(L-3)+1],d[s-9*(L-3)+2]),d.push(d[s-3],d[s-2],d[s-1]),s=e.length,e.push(e[s-6*(L-3)],e[s-6*(L-3)+1]),e.push(e[s-2],e[s-1]),
  s=g.length,g.push(g[s-9*(L-3)],g[s-9*(L-3)+1],g[s-9*(L-3)+2]),g.push(g[s-3],g[s-2],g[s-1]));y=w=s=0;3*u+2<k.length&&(z=!0,0>u&&(u=k.length/3+u+1),s=k[3*u+0],w=k[3*u+1],y=k[3*u+2]);d.push(s,w,y);w=s=0;2*t+1<m.length&&(A=!0,0>t&&(t=m.length/2+t+1),s=m[2*t+0],w=m[2*t+1]);e.push(s,w);w=s=0;y=1;-1!=r&&(3*r+2<l.length&&(B=!0,0>r&&(r=l.length/3+r+1),s=l[3*r+0],w=l[3*r+1],y=l[3*r+2]),g.push(s,w,y));c||(p[R]=n++)}c||(u=p[R],q.push(u),F<u&&(F=u))}if(!c)for(x=2;x<q.length;x++)h.push(q[0],q[x-1],q[x])}}else if("g"==
  x[0]||"o"==x[0]){if(1<x.length){q=h.length?h.length:d.length/3;null!=D&&(D.length=q-D.start,0<D.length&&(M[Q]=D,J.push(D),K++));var Q=x[1];M[Q]&&(Q=Q+"."+K);D={name:Q,start:q,length:-1,material:""}}}else"mtllib"!=x[0]&&("usemtl"==x[0]?D&&(D.material=x[1]):"o"!=x[0]&&"s"!=x[0]&&console.warn("unknown code: "+q));D&&1<h.length-D.start&&(D.length=h.length-D.start,J.push(D));c={};z&&(c.vertices=new Float32Array(d));B&&0<g.length&&(c.normals=new Float32Array(g));A&&0<e.length&&(c.coords=new Float32Array(e));
  h&&0<h.length&&(c.triangles=new (65536<F?Uint32Array:Uint16Array)(h));c.bounding=GL.Mesh.computeBounding(c.vertices);d={};1<J.length&&(d.groups=J);c.info=d;(0==c.bounding.radius||isNaN(c.bounding.radius))&&console.log("no radius found in mesh");return c}});e.Formats.registerParser({extension:"mtl",type:"material",resource:"StandardMaterial",format:"text",dataType:"text",parse:function(a,b){function c(a){return[parseFloat(a[1]),parseFloat(a[2]),parseFloat(a[3])]}for(var d=a.split("\n"),f=d.length,
  g={},h=null,k=0;k<f;++k){var m=d[k].replace(/[ \t]+/g," ").replace(/\s\s*$/,""),m=m.trim();if("#"!=m[0]&&""!=m){var m=m.split(" "),l=m[0];switch(l){case "newmtl":h={filename:m[1],textures:{}};g[m[1]]=h;break;case "Ka":h.ambient=c(m);break;case "Kd":h.color=c(m);break;case "Ks":h.specular_factor=parseFloat(m[1]);break;case "Ke":h.emissive=c(m);break;case "Ns":h.specular_gloss=parseFloat(m[1]);break;case "Tr":h.reflection=parseFloat(m[1]);break;case "map_Kd":h.textures.color=this.clearPath(m[1]);break;
  case "map_Ka":h.textures.ambient=this.clearPath(m[1]);break;case "map_Ks":h.textures.specular=this.clearPath(m[1]);break;case "bump":case "map_bump":h.textures.bump=this.clearPath(m[1]);break;case "d":h.opacity=parseFloat(m[1]);break;case "Tr":h.opacity=parseFloat(m[1]);break;case "illum":case "Tf":case "Ni":break;default:console.log("Unknown MTL info: ",l)}}}for(var p in g)d=g[p],f=new e.StandardMaterial(d),e.RM.registerResource(d.filename,f);return null},clearPath:function(a){var b=a.lastIndexOf("\\");
  -1!=b&&(a=a.substr(b+1));a=e.RM.getFilename(a);e.RM.resources_renamed_recently[a]&&(a=e.RM.resources_renamed_recently[a]);return a.toLowerCase()}});e.Formats.registerParser({extension:"stl",type:"mesh",format:"binary",dataType:"arraybuffer",parse:function(a,b){var c=[],d=[],f=[],g=new DataView(a,80),h=g.getUint32(0,!0);console.log("number of triangles: "+h);for(var k=4,m=vec3.create(),l=vec3.create(),p=vec3.create(),n=vec3.create(),q=0;q<h;q++){for(var r=g.getFloat32(k,!0),s=g.getFloat32(k+4,!0),
  t=g.getFloat32(k+8,!0),k=k+12,w=0;3>w;w++){var x=g.getFloat32(k,!0),y=g.getFloat32(k+4,!0),z=g.getFloat32(k+8,!0);c.push(x,z,-y);k+=12}0==r&&0==s&&0==t&&(r=c.length,m.set(c.slice(r-9,r-6)),l.set(c.slice(r-6,r-3)),p.set(c.slice(r-3,r)),vec3.sub(l,l,m),vec3.sub(p,p,m),vec3.cross(n,p,l),r=n[0],s=n[1],t=n[2]);d.push(r,t,-s,r,t,-s,r,t,-s);k+=2}g={info:{}};g.vertices=new Float32Array(c);0<d.length&&(g.normals=new Float32Array(d));f&&0<f.length&&(g.triangles=new Uint16Array(f));g.bounding=e.Formats.computeMeshBounding(g.vertices);
  return g}});e.Formats.registerParser({extension:"tga",type:"image",dataType:"arraybuffer",format:"binary",parse:function(a,b){if(!a||a.constructor!==ArrayBuffer)throw"ParserTGA: data must be ArrayBuffer";a=new Uint8Array(a);for(var c=new Uint8Array([0,0,2,0,0,0,0,0,0,0,0,0]),d=a.subarray(0,12),e=0;e<d.length;e++)if(c[e]!=d[e])return null;c=a.subarray(12,18);d={};d.width=256*c[1]+c[0];d.height=256*c[3]+c[2];d.bpp=c[4];d.bytesPerPixel=d.bpp/8;d.imageSize=d.width*d.height*d.bytesPerPixel;d.pixels=a.subarray(18,
  18+d.imageSize);d.pixels=new Uint8Array(d.pixels);if(0==(c[5]&16)){for(e=0;e<d.imageSize;e+=d.bytesPerPixel){var g=d.pixels[e];d.pixels[e]=d.pixels[e+2];d.pixels[e+2]=g}c[5]|=16}d.format=32==d.bpp?"RGBA":"RGB";d.flipY=!0;return d}});e.Formats.registerParser({extension:"cgart",type:"mesh",format:"text",dataType:"string",parse:function(a,b){var c=null;"object"==typeof a?c=a:"string"==typeof a&&(c=JSON.parse(a));c.faces=c.faces[0];c.normals=c.normals[0];c.vertices=c.vertices[0];c.uvs=c.uvs[0][0];for(var d=
  [],f=[],g=[],h=null,k=[],m=0,l=0;m<c.faces.length;)if(43==c.faces[m]){var p=c.faces[m+5];l<p&&(l=p,null!=h&&(h.length=d.length/3-h.start,0<h.length&&k.push(h)),h={name:"mat_"+p,start:d.length/3,length:-1,material:""});var p=c.faces[m+1],n=c.faces[m+2],q=c.faces[m+3],r=c.faces[m+4];d.push(c.vertices[3*p],c.vertices[3*p+1],c.vertices[3*p+2]);d.push(c.vertices[3*n],c.vertices[3*n+1],c.vertices[3*n+2]);d.push(c.vertices[3*q],c.vertices[3*q+1],c.vertices[3*q+2]);d.push(c.vertices[3*p],c.vertices[3*p+1],
  c.vertices[3*p+2]);d.push(c.vertices[3*q],c.vertices[3*q+1],c.vertices[3*q+2]);d.push(c.vertices[3*r],c.vertices[3*r+1],c.vertices[3*r+2]);p=c.faces[m+6];n=c.faces[m+7];q=c.faces[m+8];r=c.faces[m+9];g.push(c.uvs[2*p],c.uvs[2*p+1]);g.push(c.uvs[2*n],c.uvs[2*n+1]);g.push(c.uvs[2*q],c.uvs[2*q+1]);g.push(c.uvs[2*p],c.uvs[2*p+1]);g.push(c.uvs[2*q],c.uvs[2*q+1]);g.push(c.uvs[2*r],c.uvs[2*r+1]);p=c.faces[m+10];n=c.faces[m+11];q=c.faces[m+12];r=c.faces[m+13];f.push(c.normals[3*p],c.normals[3*p+1],c.normals[3*
  p+2]);f.push(c.normals[3*n],c.normals[3*n+1],c.normals[3*n+2]);f.push(c.normals[3*q],c.normals[3*q+1],c.normals[3*q+2]);f.push(c.normals[3*p],c.normals[3*p+1],c.normals[3*p+2]);f.push(c.normals[3*q],c.normals[3*q+1],c.normals[3*q+2]);f.push(c.normals[3*r],c.normals[3*r+1],c.normals[3*r+2]);m+=14}else 42==c.faces[m]?(p=c.faces[m+4],l<p&&(Sa("New mat: "+p),l=p,null!=h&&(h.length=d.length/3-h.start,0<h.length&&k.push(h)),h={name:"mat_"+p,start:d.length/3,length:-1,material:""}),p=c.faces[m+1],n=c.faces[m+
  2],q=c.faces[m+3],d.push(c.vertices[3*p],c.vertices[3*p+1],c.vertices[3*p+2]),d.push(c.vertices[3*n],c.vertices[3*n+1],c.vertices[3*n+2]),d.push(c.vertices[3*q],c.vertices[3*q+1],c.vertices[3*q+2]),p=c.faces[m+5],n=c.faces[m+6],q=c.faces[m+7],g.push(c.uvs[2*p],c.uvs[2*p+1]),g.push(c.uvs[2*n],c.uvs[2*n+1]),g.push(c.uvs[2*q],c.uvs[2*q+1]),p=c.faces[m+8],n=c.faces[m+9],q=c.faces[m+10],f.push(c.normals[3*p],c.normals[3*p+1],c.normals[3*p+2]),f.push(c.normals[3*n],c.normals[3*n+1],c.normals[3*n+2]),f.push(c.normals[3*
  q],c.normals[3*q+1],c.normals[3*q+2]),m+=11):(Sa("Warning: unsupported primitive type: "+c.faces[m]),m+=1);h&&1<d.length-h.start&&(h.length=d.length-h.start,k.push(h));c={};c.vertices=new Float32Array(d);0<f.length&&(c.normals=new Float32Array(f));0<g.length&&(c.coords=new Float32Array(g));c.bounding=e.Formats.computeMeshBounding(c.vertices);c.info={};1<k.length&&(c.info.groups=k);Sa("Num vertex: "+d.length/3);Sa(c.info.groups);return c}});e.Formats.registerParser({extension:"gr2",type:"mesh",format:"text",
  dataType:"string",parse:function(a,b){a=a.replace(/\'/g,'"');Sa(a);a=JSON.parse("["+a+"]");window.foo=a;a=a[0];var c={vertices:a[0][2][0],normals:a[0][2][1],triangles:a[0][3]};c.bounding=e.Formats.computeMeshBounding(c.vertices);return c}});e.extendClass(C,sa);Object.defineProperty(C.prototype,"root",{enumerable:!0,get:function(){return this._root},set:function(a){throw"Root node cannot be replaced";}});Object.defineProperty(C.prototype,"time",{enumerable:!0,get:function(){return this._time},set:function(a){throw"Cannot set time directly";
  }});Object.defineProperty(C.prototype,"globalTime",{enumerable:!0,get:function(){return this._global_time},set:function(a){throw"Cannot set global_time directly";}});C.supported_events="start update finish clear beforeReload change afterRender configure nodeAdded nodeChangeParent nodeComponentRemoved reload renderPicking scene_loaded serialize".split(" ");C.prototype.init=function(){this.id="";this.local_repository=null;this.global_scripts=[];this.external_scripts=[];this.preloaded_resources={};this._root.removeAllComponents();
  this._root.uid=e.generateUId("NODE-");this._nodes=[this._root];this._nodes_by_name={root:this._root};this._nodes_by_uid={};this._nodes_by_uid[this._root.uid]=this._root;this.info=new e.Components.GlobalInfo;this._root.addComponent(this.info);this._root.addComponent(new e.Camera);this._root.addComponent(new e.Light({position:vec3.fromValues(100,100,100),target:vec3.fromValues(0,0,0)}));this._frame=0;this._last_collect_frame=-1;this._state=e.STOPPED;this._start_time=this._global_time=this._time=0;this._last_dt=
  1/60;this._must_redraw=!0;this.selected_node&&delete this.selected_node;this.layer_names=["main","secondary"];this.animation=null;this._local_resources={};this.extra={};this._renderer=e.Renderer};C.prototype.clear=function(){for(;this._root._children&&this._root._children.length;)this._root.removeChild(this._root._children[0],!1,!0);this._root.processActionInComponents("onRemovedFromNode",this);this._root.processActionInComponents("onRemovedFromScene",this);this.init();LEvent.trigger(this,"clear");
  LEvent.trigger(this,"change")};C.prototype.configure=function(a){this._root.removeAllComponents();a.uid&&(this.uid=a.uid);"SceneTree"!=a.object_type&&console.warn("Warning: object set to scene doesnt look like a propper one.");a.local_repository&&(this.local_repository=a.local_repository);a.extra&&(this.extra=a.extra);a.root&&this._root.configure(a.root);a.nodes&&this.root.configure({children:a.nodes});a.components&&this._root.configureComponents(a);a.camera&&(this._root.camera?this._root.camera.configure(a.camera):
  this._root.addComponent(new y(a.camera)));a.light?this._root.light?this._root.light.configure(a.light):this._root.addComponent(new A(a.light)):a.hasOwnProperty("light")&&this._root.light&&(this._root.removeComponent(this._root.light),this._root.light=null);a.global_scripts&&(this.global_scripts=a.global_scripts.concat());a.external_scripts&&(this.external_scripts=a.external_scripts.concat());a.preloaded_resources&&(this.preloaded_resources=e.cloneObject(a.preloaded_resources));a.layer_names&&(this.layer_names=
  a.layer_names.concat());a.animation&&(this.animation=new e.Animation(a.animation));a.components&&this.configureComponents(a);a.editor&&(this._editor=a.editor);LEvent.trigger(this,"configure",a);LEvent.trigger(this,"change")};C.prototype.serialize=function(){var a={};a.uid=this.uid;a.object_type=e.getObjectClassName(this);a.local_repository=this.local_repository;a.extra=this.extra||{};a.root=this.root.serialize();this.animation&&(a.animation=this.animation.serialize());a.layer_names=this.layer_names.concat();
  a.global_scripts=this.global_scripts.concat();a.external_scripts=this.external_scripts.concat();a.preloaded_resources=e.cloneObject(this.preloaded_resources);this._editor&&(a.editor=this._editor);this.serializeComponents(a);LEvent.trigger(this,"serialize",a);return a};C.prototype.load=function(a,b,c,d,f){function g(b){e.ResourcesManager.processResource(a,b,null,h)}function h(a,b){if(b&&b._data&&b._data["scene.json"]){var c=JSON.parse(b._data["scene.json"]);k(c)}else console.error("Error loading PACK, doesnt look like it has a valid scene inside")}
  function k(a){var b=e.SceneTree.getScriptsList(a);b.length?n.loadScripts(b,function(){m(a)},c):m(a)}function m(c){b&&b(n,a);n.init();n.configure(c);n.loadResources(l);LEvent.trigger(n,"load");e.ResourcesManager.isLoading()||l()}function l(){f&&f(n,a);LEvent.trigger(n,"loadCompleted")}function p(b){console.warn("Error loading scene: "+a+" -> "+b);c&&c(a)}if(a){var n=this,q=e.ResourcesManager.getNoCache(!0);q&&(a+=(-1==a.indexOf("?")?"?":"&")+q);q=e.ResourcesManager.getExtension(a);e.Network.request({url:a,
  dataType:"json"==q?"json":"binary",success:"json"==q?k:g,progress:d,error:p});LEvent.trigger(this,"beforeLoad")}};C.getScriptsList=function(a){var b=[];a.external_scripts&&a.external_scripts.length&&(b=b.concat(a.external_scripts));if(a.global_scripts&&a.global_scripts.length)for(var c in a.global_scripts){var d=a.global_scripts[c];d&&"js"==e.ResourcesManager.getExtension(d)&&(d=e.ResourcesManager.getFullURL(d),b.push(d))}return b};C.prototype.loadScripts=function(a,b,c){a=a||e.SceneTree.getScriptsList(this);
  e.Network.requestScript(a,b,c)};C.prototype.checkComponentsCodeModification=function(){for(var a=0;a<this._nodes.length;++a){for(var b=this._nodes[a],c=0;c<b._components.length;++c){var d=b._components[c],f=e.getObjectClassName(d),g=e.Components[f];if(g!=d.constructor){var h=d.serialize(),g=new g(h),h=b.getIndexOfComponent(d);b.removeComponent(d);b.addComponent(g,h);console.log("Class replaced: "+f)}}if(b._missing_components&&b._missing_components.length){d=[];for(c=0;c<b._missing_components.length;++c)h=
  b._missing_components[c],f=h[0],(g=e.Components[f])?(g=new g(h[1]),b.addComponent(g),console.log("Missing repaired: "+f)):d.push(h);b._missing_components=d.length?d:null}}};C.prototype.appendScene=function(a){a=a.root.childNodes;for(var b in a){var c=a[b],d=new e.SceneNode(c.id);this.root.addChild(d);d.configure(c.constructor==e.SceneNode?c.serialize():c)}};C.prototype.getCamera=function(){var a=this._root.camera;if(a)return a;if(this._cameras&&this._cameras.length)return this._cameras[0];this.collectData();
  return this._cameras[0]};C.prototype.getActiveCameras=function(a){a&&LEvent.trigger(this,"collectCameras",this._cameras);return this._cameras};C.prototype.getLight=function(){return this._root.light};C.prototype.getActiveLights=function(a){a&&LEvent.trigger(this,"collectLights",this._lights);return this._lights};C.prototype.onNodeAdded=function(a,b){if(b._in_tree&&b._in_tree!=this)throw"Cannot add a node from other scene, clone it";b._name&&!this._nodes_by_name[b._name]&&(this._nodes_by_name[b._name]=
  b);if(!b.uid||this._nodes_by_uid[b.uid])b._uid=e.generateUId("NODE-");this._nodes_by_uid[b.uid]=b;this._nodes.push(b);b.processActionInComponents("onAddedToScene",this);LEvent.trigger(this,"nodeAdded",b);LEvent.trigger(this,"change")};C.prototype.onNodeRemoved=function(a,b){var c=this._nodes.indexOf(b);if(-1!=c)return this._nodes.splice(c,1),b._name&&this._nodes_by_name[b._name]==b&&delete this._nodes_by_name[b._name],b.uid&&delete this._nodes_by_uid[b.uid],b.processActionInComponents("onRemovedFromScene",
  this),LEvent.trigger(this,"nodeRemoved",b),LEvent.trigger(this,"change"),!0};C.prototype.recomputeNodesArray=function(){function a(d){b[c]=d;c+=1;if(d._children&&d._children.length)for(var e=0;e<d._children.length;++e)a(d._children[e])}var b=this._nodes,c=0;a(this._root)};C.prototype.getNodes=function(a){a&&this.recomputeNodesArray();return this._nodes};C.prototype.getNode=function(a){if(""==a)return this.root;if(!a)return null;if(a.charAt(0)==e._uid_prefix)return this._nodes_by_uid[a];if(-1!=a.indexOf("|")){a=
  a.split("|");for(var b=this.root,c=0;c<a.length&&b;++c)b=b.getChildByName(a[c]);return b}return this._nodes_by_name[a]};C.prototype.getNodeByName=function(a){return this._nodes_by_name[a]};C.prototype.getNodeByUId=function(a){return this._nodes_by_uid[a]};C.prototype.getNodeByIndex=function(a){return this._nodes[a]};C.prototype.getElementById=C.prototype.getNode;C.prototype.filterNodes=function(a){for(var b=[],c=0;c<this._nodes.length;++c)a(this._nodes[c])&&b.push(this._nodes[c]);return b};C.prototype.findComponentByUId=
  function(a){for(var b=0;b<this._nodes.length;++b){var c=this._nodes[b].getComponentByUId(a);if(c)return c}return null};C.prototype.findMaterialByUId=function(a){if(e.RM.materials[a])return e.RM.materials[a];for(var b=0;b<this._nodes.length;++b){var c=this._nodes[b].getMaterial();if(c&&c.uid==a)return c}return null};C.prototype.getPropertyInfo=function(a){a=a.split("/");if("@MAT-"==a[0].substr(0,5)){var b=e.RM.materials_by_uid[a[0]];return b?b.getPropertyInfoFromPath(a.slice(1)):null}return(b=this.getNode(a[0]))?
  b.getPropertyInfoFromPath(a.slice(1)):null};C.prototype.getPropertyInfoFromPath=function(a){if("@MAT-"==a[0].substr(0,5)){var b=e.RM.materials_by_uid[a[0]];return b?b.getPropertyInfoFromPath(a.slice(1)):null}return(b=this.getNode(a[0]))?b.getPropertyInfoFromPath(a.slice(1)):null};C.prototype.setPropertyValue=function(a,b,c){a=a.split("/");this.setPropertyValueFromPath(a,b,c,0)};C.prototype.setPropertyValueFromPath=function(a,b,c,d){d=d||0;if(!(a.length<d+1))return"@MAT-"==a[d].substr(0,5)?(c=e.RM.materials_by_uid[a[d]])?
  c.setPropertyValueFromPath(a,b,d+1):null:(c=c?c.findNode(a[d]):this.getNode(a[d]))?c.setPropertyValueFromPath(a,b,d+1):null};C.prototype.getResources=function(a,b,c){a=a||{};for(var d in this.textures)this.textures[d]&&(a[this.textures[d]]=GL.Texture);if(this.preloaded_resources)for(d in this.preloaded_resources)a[d]=!0;for(d=0;d<this.global_scripts.length;++d)this.global_scripts[d]&&(a[this.global_scripts[d]]=!0);for(d=0;d<this._nodes.length;++d)this._nodes[d].getResources(a);if(c)for(d in a)(c=
  e.ResourcesManager.resources[d])&&c&&(c.from_prefab||c.from_pack)&&delete a[d];for(d in a)(c=e.ResourcesManager.resources[d])&&c.getResources&&c.getResources(a);if(!b)return a;b=[];for(d in a)b.push(d);return b};C.prototype.loadResources=function(a){function b(){LEvent.unbind(e.ResourcesManager,"end_loading_resources",b);a&&a()}var c=this.getResources(),d=0,f;for(f in c)++d;0==d?a&&a():(LEvent.bind(e.ResourcesManager,"end_loading_resources",b),e.ResourcesManager.loadResources(c))};C.prototype.addPreloadResource=
  function(a){this.preloaded_resources[a]=!0};C.prototype.removePreloadResource=function(a){delete this.preloaded_resources[a]};C.prototype.start=function(){this._state!=e.RUNNING&&(this._state=e.RUNNING,this._start_time=0.001*getTime(),LEvent.trigger(this,"init",this),this.triggerInNodes("init"),LEvent.trigger(this,"start",this),this.triggerInNodes("start"))};C.prototype.finish=function(){this._state!=e.STOPPED&&(this._state=e.STOPPED,LEvent.trigger(this,"finish",this),this.triggerInNodes("finish"),
  this.purgeResidualEvents())};C.prototype.render=function(a){this._renderer.render(this,a)};C.prototype.collectData=function(){var a=this.getNodes(),b=this._instances,c=this._lights,d=this._cameras,e=this._colliders;b.length=0;c.length=0;d.length=0;for(var g=e.length=0,h=a.length;g<h;++g){var k=a[g];if(!1!=k.flags.visible){LEvent.trigger(k,"computeVisibility");k.transform&&k.transform.updateGlobalMatrix();var m=new Ka;LEvent.trigger(k,"computingShaderQuery",m);LEvent.trigger(k,"computingShaderUniforms",
  {});k._query=m;k._instances?k._instances.length=0:k._instances=[];LEvent.trigger(k,"collectRenderInstances",k._instances);LEvent.trigger(k,"collectPhysicInstances",e);b.push.apply(b,k._instances)}}LEvent.trigger(this,"collectRenderInstances",b);LEvent.trigger(this,"collectPhysicInstances",e);LEvent.trigger(this,"collectLights",c);LEvent.trigger(this,"collectCameras",d);g=0;for(h=b.length;g<h;++g)a=b[g],a.flags&2048||a.updateAABB();g=0;for(h=e.length;g<h;++g)e[g].updateAABB();this._last_collect_frame=
  this._frame};C.prototype.updateCollectedData=function(){for(var a=this._nodes,b=this._instances,c=this._lights,d=this._cameras,e=this._colliders,g=0,h=a.length;g<h;++g)a[g].transform&&a[g].transform.updateGlobalMatrix();g=0;for(h=b.length;g<h;++g)a=b[g],a.flags&131072&&a.update(),a.flags&2048||a.updateAABB();g=0;for(h=c.length;g<h;++g);g=0;for(h=d.length;g<h;++g);g=0;for(h=e.length;g<h;++g)e[g].updateAABB()};C.prototype.update=function(a){LEvent.trigger(this,"beforeUpdate",this);this._global_time=
  0.001*getTime();this._time=this._global_time-this._start_time;this._last_dt=a;LEvent.trigger(this,"update",a);this.triggerInNodes("update",a,!0);LEvent.trigger(this,"afterUpdate",this)};C.prototype.triggerInNodes=function(a,b){LEvent.triggerArray(this._nodes,a,b)};C.prototype.generateUniqueNodeName=function(a){a=a||"node";var b=1,c=a.lastIndexOf("_");if(c){var d=a.substr(c+1);parseInt(d)&&(b=parseInt(d),a=a.substr(0,c))}for(c=a+"_"+b;null!=this.getNode(c);)c=a+"_"+b++;return c};C.prototype.refresh=
  function(){this._must_redraw=!0};C.prototype.getTime=function(){return this._time};C.prototype.purgeResidualEvents=function(){if(this.__events)for(var a in this.__events){var b=this.__events[a];if(b){for(var c=[],d=0;d<b.length;++d){var f=b[d][1];!f||!e.isClassComponent(f.constructor)||f._root&&f._root.scene===this?c.push(b[d]):console.warn("Event attached to the Scene belongs to a removed node, purged. Event:",a,"Class:",e.getObjectClassName(f))}this.__events[a]=c}}};C.prototype.getLayerNames=function(a){for(var b=
  [],c=0;32>c;++c)(void 0===a||a&1<<c)&&b.push(this.layer_names[c]||"layer"+c);return b};C.prototype.findNodeComponents=function(a){if(a){var b=null;if(b=a.constructor===String?e.Components[a]:a){a=[];for(var c=e.GlobalScene._nodes,d=0;d<c.length;++d)for(var f=c[d]._components,g=0;g<f.length;++g)f[g].constructor===b&&a.push(f[g]);return a}}};C.prototype.toPack=function(a,b){var c=e.RM.removeExtension(a||"unnamed_scene",!0)+".SCENE.wbin",d=JSON.stringify(this.serialize()),f=this.getResources(null,!0,
  !b),d=e.Pack.createPack(e.RM.getFilename(c),f,{"scene.json":d});d.fullpath=c;d.category="SceneTree";return d};C.prototype.updateStaticObjects=function(){var a=e.allow_static;e.allow_static=!1;this.collectData();e.allow_static=a};C.prototype.createAnimation=function(){if(this.animation)return this.animation;this.animation=new e.Animation;this.animation.name=e.Animation.DEFAULT_SCENE_NAME;this.animation.createTake("default",e.Animation.DEFAULT_DURATION);return this.animation};e.SceneTree=C;e.Classes.SceneTree=
  C;I.prototype.init=function(a,b){b||(this.layers=3,this._name=name||"node_"+(1E4*Math.random()).toFixed(0),this._uid=e.generateUId("NODE-"),this._classList={},this._material=null,this.extra={},this.node_type=null,this.flags={visible:!0,is_static:!1,selectable:!0,two_sided:!1,flip_normals:!1,cast_shadows:!0,receive_shadows:!0,ignore_lights:!1,depth_test:!0,depth_write:!0});a||(this._components&&this._components.length&&console.warn("SceneNode.init() should not be called if it contains components, call clear instead"),
  this._components=[],this._missing_components=null,this.addComponent(new e.Transform))};e.extendClass(I,sa);e.extendClass(I,W);Object.defineProperty(I.prototype,"name",{set:function(a){this.setName(a)},get:function(){return this._name},enumerable:!0});Object.defineProperty(I.prototype,"fullname",{set:function(a){throw"You cannot set fullname, it depends on the parent nodes";},get:function(){return this.getPathName()},enumerable:!1});Object.defineProperty(I.prototype,"uid",{set:function(a){a&&(a[0]!=
  e._uid_prefix&&(console.warn("Invalid UID, renaming it to: "+a),a=e._uid_prefix+a),a!=this._uid&&(I._last_uid_changed=this._uid,this._in_tree&&this._in_tree._nodes_by_uid[this.uid]&&delete this._in_tree._nodes_by_uid[this.uid],this._uid=a,this._in_tree&&(this._in_tree._nodes_by_uid[this.uid]=this),LEvent.trigger(this,"uid_changed",a),this._in_tree&&LEvent.trigger(this._in_tree,"node_uid_changed",this)))},get:function(){return this._uid},enumerable:!0});Object.defineProperty(I.prototype,"visible",
  {set:function(a){this.flags.visible=a},get:function(){return this.flags.visible},enumerable:!0});Object.defineProperty(I.prototype,"is_static",{set:function(a){this.flags.is_static=a},get:function(){return this.flags.is_static},enumerable:!0});Object.defineProperty(I.prototype,"material",{set:function(a){(this._material=a)&&a.constructor!==String&&(a._root&&a._root!=this?console.warn("Cannot assign a material of one SceneNode to another, you must clone it or register it"):a._root=this)},get:function(){return this._material},
  enumerable:!0});Object.defineProperty(I.prototype,"prefab",{set:function(a){if(this._prefab=a){var b=this;e.RM.getResource(a)?this.reloadFromPrefab():e.ResourcesManager.load(a,function(){b.reloadFromPrefab()})}},get:function(){return this._prefab},enumerable:!0});I.prototype.clear=function(){this.removeAllComponents();this.removeAllChildren();this.init()};I.prototype.setName=function(a){if(this._name==a)return!0;if(!e.validateName(a))return!1;var b=this._in_tree;if(!b)return this._name=a,!0;this._name&&
  delete b._nodes_by_name[this._name];(this._name=a)&&!b._nodes_by_name[a]&&(b._nodes_by_name[this._name]=this);LEvent.trigger(this,"name_changed",a);b&&LEvent.trigger(b,"node_name_changed",this);return!0};Object.defineProperty(I.prototype,"classList",{get:function(){return this._classList},set:function(a){},enumerable:!1});Object.defineProperty(I.prototype,"className",{get:function(){var a=null;if(Object.keys)a=Object.keys(this._classList);else{var a=[],b;for(b in this._classList)a.push(b)}return a.join(" ")},
  set:function(a){this._classList={};if(a){a=a.split(" ");for(var b in a)this._classList[a[b]]=!0}},enumerable:!0});I.prototype.destroy=function(){LEvent.trigger(this,"destroy");this.removeAllComponents();if(this.children)for(;this.children.length;)this.children[0].destroy();this._parentNode&&this._parentNode.removeChild(this)};I.prototype.getLocator=function(a){return a?this.uid+"/"+a:this.uid};I.prototype.getPropertyInfo=function(a){a=a.split("/");return this.getPropertyInfoFromPath(a)};I.prototype.getPropertyInfoFromPath=
  function(a){var b=this,c=a[0];if(0==a.length)return{node:this,target:null,name:"",value:this,type:"node"};if(1==a.length){if("@"==a[0][0])return b=this.getComponentByUId(a[0]),{node:this,target:b,name:b?e.getObjectClassName(b):"",type:"component",value:b};if("material"==a[0])return b=this.getMaterial(),{node:this,target:b,name:b?e.getObjectClassName(b):"",type:"material",value:b};if(b=this.getComponent(a[0]))return{node:this,target:b,name:b?e.getObjectClassName(b):"",type:"component",value:b};switch(a[0]){case "matrix":case "x":case "y":case "z":case "position":case "rotX":case "rotY":case "rotZ":b=
  this.transform;c=a[0];break;default:b=this,c=a[0]}}else if(1<a.length&&("@"==a[0][0]?(c=a[1],b=this.getComponentByUId(a[0])):(b="material"==a[0]?this.getMaterial():"flags"==a[0]?this.flags:this.getComponent(a[0]),c=a[1]),!b))return null;var d=void 0;if(b.getPropertyInfoFromPath&&b!=this&&(a=b.getPropertyInfoFromPath(a.slice(1))))return a;b.getPropertyValue&&(d=b.getPropertyValue(c));if(void 0===d&&void 0===b[c])return null;d=void 0!==d?d:b[c];a=b.constructor["@"+c];var f="";a&&(f=a.type);f||null===
  d||void 0===d||(d.constructor===String?f="string":d.constructor===Boolean?f="boolean":d.length?f="vec"+d.length:d.constructor===Number&&(f="number"));return{node:this,target:b,name:c,value:d,type:f}};I.prototype.setPropertyValue=function(a,b){var c=a.split("/");return this.setPropertyValueFromPath(c,b,0)};I.prototype.setPropertyValueFromPath=function(a,b,c){c=c||0;var d=null,e=a[c];if(a.length>c+1){if("@"==a[c][0]?(e=a[c+1],d=this.getComponentByUId(a[c])):(d="material"==a[c]?this.getMaterial():"flags"==
  a[c]?this.flags:this.getComponent(a[c]),e=a[c+1]),!d)return null}else switch(a[c]){case "matrix":d=this.transform;break;case "x":case "y":case "z":case "xrotation":case "yrotation":case "zrotation":d=this.transform;e=a[c];break;case "translate.X":d=this.transform;e="x";break;case "translate.Y":d=this.transform;e="y";break;case "translate.Z":d=this.transform;e="z";break;case "rotateX.ANGLE":d=this.transform;e="pitch";break;case "rotateY.ANGLE":d=this.transform;e="yaw";break;case "rotateZ.ANGLE":d=
  this.transform;e="roll";break;default:d=this}if(!d)return null;if(d.setPropertyValueFromPath&&d!=this&&!0===d.setPropertyValueFromPath(a,b,c+1)||d.setPropertyValue&&d!=this&&!0===d.setPropertyValue(e,b))return d;if(void 0!==d[e])return d[e]=b,d};I.prototype.getResources=function(a,b){for(var c in this._components)this._components[c].getResources&&this._components[c].getResources(a);if(this.material){this.material.constructor===String&&":"!=this.material[0]&&(a[this.material]=e.Material);var d=this.getMaterial();
  d&&d.getResources(a)}this.prefab&&(a[this.prefab]=e.Prefab);if(b)for(c in this._children)this._children[c].getResources(a,!0);return a};I.prototype.getTransform=function(){return this.transform};I.prototype.getMesh=function(){var a=this.mesh;!a&&this.meshrenderer&&(a=this.meshrenderer.mesh);return a?a.constructor===String?Qa.meshes[a]:a:null};I.prototype.getLight=function(){return this.light};I.prototype.getCamera=function(){return this.camera};I.prototype.getLODMesh=function(){var a=this.lod_mesh;
  !a&&this.meshrenderer&&(a=this.meshrenderer.lod_mesh);return a?a.constructor===String?Qa.meshes[a]:a:null};I.prototype.setMesh=function(a,b){this.meshrenderer?"string"==typeof a?this.meshrenderer.configure({mesh:a,submesh_id:b}):this.meshrenderer.mesh=a:this.addComponent(new e.MeshRenderer({mesh:a,submesh_id:b}))};I.prototype.loadAndSetMesh=function(a,b){b=b||{};if(e.ResourcesManager.meshes[a]||!a){if(this.setMesh(a),b.on_complete)b.on_complete(e.ResourcesManager.meshes[a],this)}else{var c=this;e.ResourcesManager.load(a,
  b,function(a){c.setMesh(a.filename);c.loading-=1;0==c.loading&&(LEvent.trigger(c,"resource_loaded",c),delete c.loading);if(b.on_complete)b.on_complete(a,c)})||(this.loading?this.loading+=1:(this.loading=1,LEvent.trigger(this,"resource_loading")))}};I.prototype.getMaterial=function(){return this.material?this.material.constructor===String?this._in_tree?"@"==this.material[0]?e.ResourcesManager.materials_by_uid[this.material]:e.ResourcesManager.materials[this.material]:null:this.material:null};I.prototype.reloadFromPrefab=
  function(){if(this.prefab){var a=e.ResourcesManager.resources[this.prefab];if(a){this.removeAllChildren();this.init(!0,!0);this.configure({children:a.prefab_data.children});var b=this.getResources({},!0);e.ResourcesManager.loadResources(b);LEvent.trigger(this,"prefabReady",a)}}};I.prototype.setLayer=function(a,b){var c=1<<a;this.layers&=~c;b&&(this.layers|=c)};I.prototype.isInLayer=function(a){return 0!==(this.layers&1<<a)};I.prototype.getLayers=function(){var a=[];if(!this.scene)return a;for(var b=
  0;32>b;++b)this.layers&1<<b&&a.push(this.scene.layer_names[b]||"layer"+b);return a};I.prototype.insidePrefab=function(){for(var a=this;a;){if(a.prefab)return a;a=a._parentNode}return null};I.prototype.clone=function(){var a=this._in_tree,a=a?a.generateUniqueNodeName(this._name):this._name,a=new e.SceneNode(a),b=this.serialize();e.clearUIds(b);b.uid=e.generateUId("NODE-");a.configure(b);return a};I.prototype.configure=function(a){a.name?this.setName(a.name):a.id&&this.setName(a.id);void 0!==a.layers&&
  (this.layers=a.layers);a.uid&&(this.uid=a.uid);a.className&&a.className.constructor==String&&(this.className=a.className);a.node_type&&(this.node_type=a.node_type,"JOINT"==a.node_type&&(this._is_bone=!0));a.camera&&this.addComponent(new e.Camera(a.camera));a.light&&this.addComponent(new e.Light(a.light));if(a.meshes)for(var b=0;b<a.meshes.length;++b)this.addMeshComponents(a.meshes[b],a);else a.mesh&&this.addMeshComponents(a.mesh,a);a.position&&(this.transform.position=a.position);a.model&&this.transform.fromMatrix(a.model);
  a.transform&&this.transform.configure(a.transform);if(a.material){var c=a.material.material_class;c||(c="StandardMaterial");var d=e.MaterialClasses[c];d?this.material="string"==typeof a.material?a.material:new d(a.material):console.warn("Material not found: "+c)}if(a.flags)for(b in a.flags)this.flags[b]=a.flags[b];a.animations&&(this.animations=a.animations,this.addComponent(new e.Components.PlayAnimation({animation:this.animations})));a.extra&&(this.extra=a.extra);a.editor&&(this._editor=a.editor);
  a.comments&&(this.comments=a.comments);a.components&&this.configureComponents(a);a.prefab?this.prefab=a.prefab:this.configureChildren(a);LEvent.trigger(this,"configure",a)};I.prototype.addMeshComponents=function(a,b){b=b||{};var c=e.ResourcesManager.meshes[a];if(c){var d={mesh:a};void 0!==b.submesh_id&&(d.submesh_id=b.submesh_id);void 0!==b.morph_targets&&(d.morph_targets=b.morph_targets);d=new e.Components.MeshRenderer(d);"line_strip"===c.primitive&&(d.primitive=3,delete c.primitive);this.addComponent(d);
  c&&c.bones&&(d=new e.Components.SkinDeformer,this.addComponent(d));c&&c.morph_targets&&(d=new e.Components.MorphDeformer({morph_targets:c.morph_targets}),this.addComponent(d))}else console.warn("SceneNode mesh not found: "+a)};I.prototype.serialize=function(a){var b={};this._name&&(b.name=this._name);this.uid&&(b.uid=this.uid);this.className&&(b.className=this.className);b.layers=this.layers;this.node_type&&(b.node_type=this.node_type);this.mesh&&"string"==typeof this.mesh&&(b.mesh=this.mesh);null!=
  this.submesh_id&&(b.submesh_id=this.submesh_id);this.material&&(b.material="string"==typeof this.material?this.material:this.material.serialize());this.prefab&&!a&&(b.prefab=this.prefab);this.flags&&(b.flags=e.cloneObject(this.flags));this.extra&&(b.extra=this.extra);this.comments&&(b.comments=this.comments);!this._children||this.prefab&&!a||(b.children=this.serializeChildren());this._editor&&(b.editor=this._editor);this.serializeComponents(b);LEvent.trigger(this,"serialize",b);return b};I.prototype._onChildAdded=
  function(a,b){if(b&&this.transform){var c=a.transform.getGlobalMatrix(),d=this.transform.getGlobalMatrix();mat4.invert(d,d);a.transform.fromMatrix(mat4.multiply(d,d,c));a.transform.getGlobalMatrix()}this.transform&&(a.transform._parent=this.transform)};I.prototype._onChangeParent=function(a,b){if(b&&a.transform){var c=this.transform.getGlobalMatrix(),d=a.transform.getGlobalMatrix();mat4.invert(d,d);this.transform.fromMatrix(mat4.multiply(d,d,c))}a.transform&&(this.transform._parent=a.transform)};
  I.prototype._onChildRemoved=function(a,b,c){this.transform&&(b?(b=a.transform.getGlobalMatrix(),a.transform._parent=null,a.transform.fromMatrix(b)):a.transform._parent=null);c&&a.removeAllComponents()};I.prototype.getBoundingBox=function(a,b){a=a||BBox.create();var c=this._instances;if(c)for(var d=0;d<c.length;++d)0==d?a.set(c[d].aabb):BBox.merge(a,a,c[d].aabb);return b?a:c&&0!=c.length||!this.transform?a:BBox.fromPoint(this.transform.getGlobalPosition())};e.SceneNode=I;e.Classes.SceneNode=I;qa.STOPPED=
  0;qa.PLAYING=1;qa.PAUSED=2;qa.prototype.loadScene=function(a,b,c){var d=this;this.scene.load(a,null,null,function(a){if(void 0!==d.loading){var b=0;a.total&&(b=a.loaded/a.total);d.loading.scene_bar=b;c&&c(b)}},function(){d.autoplay&&d.play();d.loading=null;b&&b()})};qa.prototype.setScene=function(a,b){function c(){g.configure(a);g.loadResources(d)}function d(){f.autoplay&&f.play();g._must_redraw=!0;console.log("Scene playing");b&&b()}var f=this,g=this.scene;a&&a.constructor===String&&(a=JSON.parse(a));
  var h=e.SceneTree.getScriptsList(a);h&&h.length?(g.clear(),g.loadScripts(h,c)):c()};qa.prototype.pause=function(){this.state=e.Player.PAUSED};qa.prototype.play=function(){this.state!=e.Player.PLAYING&&(this.debug&&console.log("Start"),this.state=e.Player.PLAYING,e.Input.reset(),e.GUI.reset(),this.scene.start())};qa.prototype.stop=function(){this.state=e.Player.STOPPED;this.scene.finish();e.GUI.reset()};qa.prototype._ondraw=function(){if(this.state==e.Player.PLAYING){if(this.onPreDraw)this.onPreDraw();
  var a=this.scene;(a._must_redraw||this.force_redraw)&&a.render(a.info?a.info.render_settings:this.render_settings);if(this.onDraw)this.onDraw();this.loading&&this.loading.visible&&this.renderLoadingBar()}};qa.prototype._onupdate=function(a){if(this.state==e.Player.PLAYING){e.Tween.update(a);e.Input.update(a);if(this.onPreUpdate)this.onPreUpdate(a);this.scene.update(a);if(this.onUpdate)this.onUpdate(a)}};qa.prototype._onmouse=function(a){if(this.state==e.Player.PLAYING&&(LEvent.trigger(this.scene,
  a.eventType||a.type,a),this.onMouse))this.onMouse(a)};qa.prototype._onkey=function(a){this.state!=e.Player.PLAYING||this.onKey&&this.onKey(a)||LEvent.trigger(this.scene,a.eventType||a.type,a)};qa.prototype._ongamepad=function(a){this.state!=e.Player.PLAYING||this.onGamepad&&this.onGamepad(a)||LEvent.trigger(this.scene,a.eventType||a.type,a)};qa.prototype.renderLoadingBar=function(){this.loading&&Z.enableWebGLCanvas&&(gl.canvas.canvas2DtoWebGL_enabled||enableWebGLCanvas(gl.canvas),gl.start2D(),gl.fillColor=
  [0,0,0,1],gl.fillRect(0,0,gl.drawingBufferWidth,8),gl.fillColor=this.loading.bar_color||[0.5,0.9,1,1],gl.fillRect(0,0,gl.drawingBufferWidth*this.loading.scene_bar,4),gl.fillColor=this.loading.bar_color||[0.9,0.5,1,1],gl.fillRect(0,4,gl.drawingBufferWidth*this.loading.resources_bar,4),gl.finish2D())};qa.prototype.enableDebug=function(){e.Script.catch_important_exceptions=!1;e.catch_exceptions=!1};e.Player=qa;e.getCurveValueAt=function(a,b,c,d,e){if(e<b||e>c)return d;b=[b,d];for(var g=0,g=0;g<a.length;g+=
  1){var h=a[g];if(e==h[0])return h[1];if(e<h[0])return g=(e-b[0])/(h[0]-b[0]),b[1]*(1-g)+h[1]*g;b=h}h=[c,d];g=(e-b[0])/(h[0]-b[0]);return b[1]*(1-g)+h[1]*g};e.resampleCurve=function(a,b,c,d,f){var g=[];g.length=f;for(var h=(c-b)/f,k=0;k<f;k++)g[k]=e.getCurveValueAt(a,b,c,d,b+h*k);return g};Object.prototype.hasOwnProperty("defineAttribute")||(Object.defineProperty(Object.prototype,"defineAttribute",{value:function(a,b,c){c&&"string"==typeof c&&(c={type:c});var d=this;"function"!=typeof this&&(this[a]=
  b,d=this.constructor);Object.defineProperty(d,"@"+a,{value:c||{},enumerable:!1})},enumerable:!1}),Object.defineProperty(Object.prototype,"getAttribute",{value:function(a){a="@"+a;return this.hasOwnProperty(a)?this[a]:this.constructor&&this.constructor.hasOwnProperty(a)?this.constructor[a]:null},enumerable:!1}));String.prototype.hasOwnProperty("hashCode")||Object.defineProperty(String.prototype,"hashCode",{value:function(){var a=0,b,c,d;if(0==this.length)return a;b=0;for(d=this.length;b<d;++b)c=this.charCodeAt(b),
  a=(a<<5)-a+c,a|=0;return a},enumerable:!1});Object.equals=function(a,b){if(a===b)return!0;if(!(a instanceof Object&&b instanceof Object)||a.constructor!==b.constructor)return!1;for(var c in a)if(a.hasOwnProperty(c)&&(!b.hasOwnProperty(c)||a[c]!==b[c]&&("object"!==typeof a[c]||!Object.equals(a[c],b[c]))))return!1;for(c in b)if(b.hasOwnProperty(c)&&!a.hasOwnProperty(c))return!1;return!0};e.GlobalScene=new C;e.newMeshNode=function(a,b){var c=new e.SceneNode(a);c.addComponent(new e.Components.MeshRenderer);
  c.setMesh(b);return c};e.newLightNode=function(a){a=new e.SceneNode(a);a.addComponent(new e.Components.Light);return a};e.newCameraNode=function(a){a=new e.SceneNode(a);a.addComponent(new e.Components.Camera);return a};Z.LS=e})("undefined"!=typeof window?window:self);
  