/** 
 * X3DOM 1.8.2
 * Build : 7298
 * Revision: e56cf6f97388aa9b4de35156fadfeba9889f6972
 * Date: Sun Jun 13 10:59:46 2021 +0200
 */
var x3dom={canvases:[],x3dNS:"http://www.web3d.org/specifications/x3d-namespace",x3dextNS:"http://philip.html5.org/x3d/ext",xsltNS:"http://www.w3.org/1999/XSL/x3dom.Transform",xhtmlNS:"http://www.w3.org/1999/xhtml"};function defineClass(e,t,i){if(e){function o(){}o.prototype=e.prototype,t.prototype=new o,t.prototype.constructor=t,t.superClass=e}if(i)for(var s in i)t.prototype[s]=i[s];return t}function array_to_object(e){for(var t={},i=0;i<e.length;i++)t[e[i]]="";return t}x3dom.about={version:"1.8.2",build:"7298",revision:"e56cf6f97388aa9b4de35156fadfeba9889f6972",date:"Sun Jun 13 10:59:46 2021 +0200"},x3dom.nodeTypes={},x3dom.nodeTypesLC={},x3dom.components={},x3dom.geoCache=[],x3dom.BUFFER_IDX={INDEX:0,POSITION:1,NORMAL:2,TEXCOORD:3,TEXCOORD_0:3,COLOR:4,COLOR_0:4,ID:5,TANGENT:6,BITANGENT:7,TEXCOORD_1:8},x3dom.BRDF_LUT="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwlW4Dj1wD/phCJ7BKLyBCQRByAgTYSHaiAFiilgjjggXmYX4IcFIBBKLJCDJiBRRIkuRNUgxUopUIFVIHfI9cgI5h1xGupE7yAAygvyGvEcxlIGyUT3UDLVDuag3GoRGogvQZHQxmo8WoJvQcrQaPYw2oefQq2gP2o8+Q8cwwOgYBzPEbDAuxsNCsTgsCZNjy7EirAyrxhqwVqwDu4n1Y8+xdwQSgUXACTYEd0IgYR5BSFhMWE7YSKggHCQ0EdoJNwkDhFHCJyKTqEu0JroR+cQYYjIxh1hILCPWEo8TLxB7iEPENyQSiUMyJ7mQAkmxpFTSEtJG0m5SI+ksqZs0SBojk8naZGuyBzmULCAryIXkneTD5DPkG+Qh8lsKnWJAcaT4U+IoUspqShnlEOU05QZlmDJBVaOaUt2ooVQRNY9aQq2htlKvUYeoEzR1mjnNgxZJS6WtopXTGmgXaPdpr+h0uhHdlR5Ol9BX0svpR+iX6AP0dwwNhhWDx4hnKBmbGAcYZxl3GK+YTKYZ04sZx1QwNzHrmOeZD5lvVVgqtip8FZHKCpVKlSaVGyovVKmqpqreqgtV81XLVI+pXlN9rkZVM1PjqQnUlqtVqp1Q61MbU2epO6iHqmeob1Q/pH5Z/YkGWcNMw09DpFGgsV/jvMYgC2MZs3gsIWsNq4Z1gTXEJrHN2Xx2KruY/R27iz2qqaE5QzNKM1ezUvOUZj8H45hx+Jx0TgnnKKeX836K3hTvKeIpG6Y0TLkxZVxrqpaXllirSKtRq0frvTau7aedpr1Fu1n7gQ5Bx0onXCdHZ4/OBZ3nU9lT3acKpxZNPTr1ri6qa6UbobtEd79up+6Ynr5egJ5Mb6feeb3n+hx9L/1U/W36p/VHDFgGswwkBtsMzhg8xTVxbzwdL8fb8VFDXcNAQ6VhlWGX4YSRudE8o9VGjUYPjGnGXOMk423GbcajJgYmISZLTepN7ppSTbmmKaY7TDtMx83MzaLN1pk1mz0x1zLnm+eb15vft2BaeFostqi2uGVJsuRaplnutrxuhVo5WaVYVVpds0atna0l1rutu6cRp7lOk06rntZnw7Dxtsm2qbcZsOXYBtuutm22fWFnYhdnt8Wuw+6TvZN9un2N/T0HDYfZDqsdWh1+c7RyFDpWOt6azpzuP33F9JbpL2dYzxDP2DPjthPLKcRpnVOb00dnF2e5c4PziIuJS4LLLpc+Lpsbxt3IveRKdPVxXeF60vWdm7Obwu2o26/uNu5p7ofcn8w0nymeWTNz0MPIQ+BR5dE/C5+VMGvfrH5PQ0+BZ7XnIy9jL5FXrdewt6V3qvdh7xc+9j5yn+M+4zw33jLeWV/MN8C3yLfLT8Nvnl+F30N/I/9k/3r/0QCngCUBZwOJgUGBWwL7+Hp8Ib+OPzrbZfay2e1BjKC5QRVBj4KtguXBrSFoyOyQrSH355jOkc5pDoVQfujW0Adh5mGLw34MJ4WHhVeGP45wiFga0TGXNXfR3ENz30T6RJZE3ptnMU85ry1KNSo+qi5qPNo3ujS6P8YuZlnM1VidWElsSxw5LiquNm5svt/87fOH4p3iC+N7F5gvyF1weaHOwvSFpxapLhIsOpZATIhOOJTwQRAqqBaMJfITdyWOCnnCHcJnIi/RNtGI2ENcKh5O8kgqTXqS7JG8NXkkxTOlLOW5hCepkLxMDUzdmzqeFpp2IG0yPTq9MYOSkZBxQqohTZO2Z+pn5mZ2y6xlhbL+xW6Lty8elQfJa7OQrAVZLQq2QqboVFoo1yoHsmdlV2a/zYnKOZarnivN7cyzytuQN5zvn//tEsIS4ZK2pYZLVy0dWOa9rGo5sjxxedsK4xUFK4ZWBqw8uIq2Km3VT6vtV5eufr0mek1rgV7ByoLBtQFr6wtVCuWFfevc1+1dT1gvWd+1YfqGnRs+FYmKrhTbF5cVf9go3HjlG4dvyr+Z3JS0qavEuWTPZtJm6ebeLZ5bDpaql+aXDm4N2dq0Dd9WtO319kXbL5fNKNu7g7ZDuaO/PLi8ZafJzs07P1SkVPRU+lQ27tLdtWHX+G7R7ht7vPY07NXbW7z3/T7JvttVAVVN1WbVZftJ+7P3P66Jqun4lvttXa1ObXHtxwPSA/0HIw6217nU1R3SPVRSj9Yr60cOxx++/p3vdy0NNg1VjZzG4iNwRHnk6fcJ3/ceDTradox7rOEH0x92HWcdL2pCmvKaRptTmvtbYlu6T8w+0dbq3nr8R9sfD5w0PFl5SvNUyWna6YLTk2fyz4ydlZ19fi753GDborZ752PO32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfVP1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i/suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADqYAAAOpgAABdvkl/FRgAAMAdJREFUeNrsXduWIruOlGjOzP8/zdceNA+QmbZ19yVJKFh79a6ChKqCkBQRkm38v/8QABBA++/zf+JD2r8k35/4lqIXd1zA/yj7i/ij7rP67jy+psRP77vszG87Lph4T3PnHYEIAAGe/x43BCAoH9L+bZ4i/jwMfotAAEjqxfx+7QL5pvyGAP6vHbxSfFb8TuPXDl6fe0O6bvYH+lm3OwDxP+b1L1ZYtN+O4ykAREJ45MKA5Efj8aB+UcTYCKTc546C3gzd6ZhLfVjfdLvjRj1Q/Ds3uPjpX/m0moujb7SZ8zrTfwBP9iu7d/b9PtFXiBXY8Ye+6eaW/IMCyRndKwUqO5KekgsDPCTBtPSfp0PjibwbakJgZCjc75aoAOBmd6yIjV8E2FN6wkD6vAfTf/X0us7YL5hK/30EabqM+Zo8Pfd1ysteGkAEdIt1swTLgcG4UDoMMMrXc+nffM86IuHMm1uQfyGRqQBIouKUEx7KesBiR5hzdWxNnAN3UDzob3b8p0RKQfeLrJC5XxAS4ueWveyO8AKXQVcqrOspUw2MsKtja+Jp7F/SG81veBqkOl+ECaS/kK0X2qANw7GKAABKesCRyJKrk9XEWfsyl85jkFpI7rOv6eHuL/g8HaS/ubNygUqGYxUB6SVdXqSx+WAYpOhQVteKxS0eCRFet4TefEjujfyaEeoyAvewC1TD1BLHUrSArSX0LO6GgUuHhtJ/GaUgx/ZFbsHu+9/RuINFoHKBIvalKB/99O+J2mD55pR9PP2DWWemOKFrQ+hKemB1VI5zHqECNIiJ6IHyymZ6x30WgN+I9dN211RPoqtlomoEaktgem4d6Phps1jQINz5nS0FEh1P3yE1ZbE8DTE+8DNgj4ZgnfycO1L+YPUImrmfGxIj7mfwzpYCiY5nX5vMLgKaNZRj7fsVU9N/pJEXB/ofmbqZImqny1w3BhQKVDqe0nyy2yazGVHjO6VYUMeL9KT/OkovzX8WFIHmld6rtEcaXu7Tj3Foi7dguk0WGhbSraF0WQh3ynoiIdAmO0f++q92JVNoYhFYFwN3ROIDYeJcWkO4I1c66V+hsClCb9SBCenffAuz4D5pyP6UGOhmL1erA3cEEr1/UJpfEZnrzlbYTCbO5u06MCf91y++qBM8ORjyYHSf0YfvuUogHgMQt0FfFKhe+KIGA/p6wPBSfSibxk4oNsw6MLq2K7kk5a+tR5lo7AzGgHEn8DXBoLSBNTIQbZMxWRxcRSDO6CcaXoGJhr61XWVUD/KfKxqTa2rCXLtzPAYsFwikHCy3ycB3SJufxhFg1IG4uanWAVDdm9GVK4Hx6bVKdwaET2tmnW/sBOnQ8/6jDwDS5KbjkJI/xalxodDq9QAdsrvF9sxF/+B+QQXH+c/C4rBYmZ7Qqc3GACTvF/oA4K1isWWxyoUgP8gZpkNqSIy5+FZUrNlh5Qtcy7md2j5YazHDrxf6AM38fYcsttwhmrBkMWIQiXVgSvofzK9n7zjyjs7AxE7t3FLAr69EMOj4TsliSxjEhswm1gGAznnJ0KCOwoWm7AQxLTwQgE71MVNRMSUGIM+IYG+EacxE4+IRWawVAU5LosMO4O/gYN2pW0OjwPUk+yX4j4SdiVAeIUJTRG1HeMCxHkBKsVoODspiZxJOn97p3sFBxHGbrcGSBCNffwYdOlfprmMy2fuNhzYKtBn2YEytgWqq2Du6qePQ5ghQig7FHdK+9e8hKAeI1jshHgPyCT4m5lP4xJQP9aP359cYyMoa/mzZ4PSAPYUanJiIe/waUueQoiuNjgr4YHe9y8ecldpTWBefWItgPStr7EWbbLM3eRYlQYIOJeuA28zqWIAyzoWm859Q7zbw6w16OOendluFORpA6AN4qtddzKUNURvEye55RWRxpA5oBk7WCApyoSuq4V65ssLZnMvmIykfon0AXfVCYfvY7qfdA6b6LylfMCQG2Pva0+tFNYRGqfyw+270vD/Cs4dwP2uEzXeTHygpENW/BG6ywO/doi+LxXk4FaAYGuDh6bZ/B8LAUEPnQ2vU9hwX30N9Kn7Hzc1uQPdlfWaD5l2XlCzevwmN9Gxdm4TFqdSBxL77kBCviYcCA+FvY0fF77aoHdvn5Xez+b5IuCMS2JkeR2UxxVwmg5n4bk+YzGR7um/hQleeHTpBuXaHQZb/FDboxoSCxwoZF1jUJbyRSdm0iro9Sjc68bW5gWk2GAa3spvMecR7uopAx/3TmU+Q3kQuKGzQ7eMX9EDhoGFggNmhTBD1fLR5ZutZNfMebOhO4y3DJ3y9awExnihbB1N+POu3LhAERm6ie1HpFwQbuoI7lPE6I32uoInZf8hf+LSbcwjPyQ3akYdGMnqqLFQuEBRpHlyyHpHFEHWHBMTH2Lnb59LqQKgUTG3oTvRG36KGu2NgJN+PpPzgNSA2wg62ow/qaIXCjZNIPVHZOYQvDidyI4pse3TkBFjIdN86wq+nOzsWAyt8GwgtjM2VBfHKdkmk6EiqjQJ3fs51h2pkOwDN9q3MiQxfznad++2zrNjpyydQ/WxB6iM2S12dbMrn8dCuB4AU6XedzYA7xPU3/01AmoQL1QGQV8MEywJ46547w8NrYL9BFgeKwAiDn+jqDKZ8QQTjpgNaIrTLUMO3Maeag+5QDtkd8wtdkgC8tT4d1eAt3mi0CIRjYApveVfKB74ksoSp2AoINQp08wdMd6iJJaBY0ypr+SclgVsKAIZ3ibuGJu4QuIOcZ6LY7Uj5zfX1KMSW7CFAVHih2OErCwOvA9AkeJECgb60JeLtGHwm62N2SNXIFkNLLVEf6/UVgyjHDBxn5XvQd6mRKZAwDKcAfVajwF3hDjodAqVL4EcLqwOQQn+NiAj6ozs6Xr4OwIwwWEdp4qOs4vsvu0AgAX1KowCCC4JrxgVd+zKodSO2WEfGcYwLnTbMPAvoYA6K4hitT0VC6spsvhf6AE8vU/Ze9F5VX6MAUguCixlSyHQJQkS/q907iwulBPGZm5DaMQAzwqAvEqbke1AXxSsuEBRADzYK0iYpKZpboUOQlLkW1Ylt7WhAlpSKHFmnLw5On1MlzlG3Hcm7L99nWxmCDQqKCyRyHrtRAMr8HOR3ebDpUFYWy4ERntcHs1WcRf+VTSEILB2eGwaD4LYPQ3Fv9SyQ5AKJnCfbKNA6yhpfgjAdgkG7k0WX+Fwwd7nLoj9+HtlbigDEls9Pd2+WPl0NgGoaVLdW7OVa4Gpfl+1IezC2+EZrrgH0OgBuqyusiUGa7SE9geF0bJ5YB2aZmCegufs9O2xQzQVqc7bRL9uWEUNg7EcIA4lNAbvGlcVQV4yovwl+KZDvUWZ7Utumu8elTVS6iUArxr0m+jaD1k13sie5AiCVxAbqtgiS4r4XcGlrhdFGMAsFKLNx7fsbk8XcITW4U7e9o3EhGATuQB1YsatPH7JpHoinFEVUK4DE77VSYHAeCM76m+6QyMEEkgPt0IRdMaIUX6E0vuHj7YvYERWX2lV3UNTSAuxOiZNiFMIOAz08IqI51UbgvlOcDgmMSK8DcjAwSkOKYce5ENC80/LOOu0UkjugTMnutPLPSQdA9Yaj0xAAj/NAeI8TS1KD3LI16JBtj4p1AAIjD5By+qXZHujeYaU3BiYO+msP4xiUp2uA7pu8JBJADwPR9VeYkmaDNu4QgKOMwaRDXL/KoQKW6w9MPwCFEn+HhE2UhcsYo9fhOdmbXfaPUYjWCyrIX/WQDmjOlFyHxx5BBWl/RZmd6znbdv2tHB+z+UFZkQxeQ75jd62lgLaSenhr9Sskdfe3asehgdEbkAb0K5sIQyUiKprdRWF1UZK1AcvZsjI2M3QLTXPkwRK1+nLK8VR3wi4SS42XS4VHQYFQxro6KRS4v3vIVAwDkQ5xWdxRB4xSAOGRB9FQSkFfveasImBxmwVk7Arjse2+QAB6GIiTQub92SHTRvi60zsgcf2OOuAkeO9igwsZfeJcXu89oX4FUi+4t8tQBRDYvxgGhV42+mIgrRGzPaVoUDFxAp4stug+ayb00XqH0MdOIQilw/x205OztvTOXz8e0KkASKWBI4pgw5apwoPd7w6ZWoJBCipg202DJ4st6RzI7uUfyD9tiihdc0+4HBPII/oEG+n6Z4D7FIhPfZRsnmNdS/kQGJ2whQQq3o5gt0lNAOjg+kp2d1kNxJu+kh6As1a6zIwB/B4ChC0Fqr38yvBRGJEA98DoRERIiN6OAXFQDOko148JVjHwohk9owcs9L9DEH8ElPsrQLM5TJwRlaMQEB6d6AkPxQN1ZbFooaZiybBHU2SGzMjJKYT3xsCJvblTKBBbEwwMwSIjErEL5UhF12SRWyVkh86FuDfdAMoBTWBakxEyY3ij/eL4M+sAXu/n3kuG0WR30LpjXARr2K0XDYM7cWSEB2v3gpSVyXDuItMNYYoPXkZXX8SDYVQh9MbALOvmUtq3+5epG2F6GDSsQywFMna1UpCcOAL2asIHiepDYh3Q4gQlgMhPQfXK7glefB9iousbzy0luPI1722bT+f6bWoUw4AFjI1py2wFVf5SvYslSIxfpfJ6HQBlvt/5GFBwDty339Abb+Q0b0/qePqr3Xe0IqPUwDZPdRmRSGPAG52wTFJtdk2iQ6D3blN1wAiVSOUJMXucN21Db4IqfRjWfQ0ghkGEEQEwYeBJiJCpKr24C1CxlAmPgjzkA6Zm7WP2dAEi8UcyevYVBA0QCQMkwY4US0F8pMI1SWUuxKqAQWNA2Y4KTLeHKPYZKGXHpU/fVATwMnAPPp1tiyJuEs/XBogJXsrWqtgVA8Y0SdVFwEqfNZLpQd/TAerqFFKxqMoP+MoYmI17PPGJ2GiAhr0MMaLgZJEYMLpJymU3KEfeAlfGpL9fbqHQJUeHyxmBL83OptfE/flw79EAPYyo7hCDO1lEEJ1IBd2qr8Op/ePRcjZDete8pjsGtI3505/9+iIwvlDhNMTHr69mgQTzR7szyIjEySKd/YOyAobne9TYtrEUK1YHLAYf7mHFkYHvg+O7dOeKJ3ZHiDALpFGd6k7tMuptIOiKWagPEtumiDhz6wB4aR7lImNH1FIev4gpnQ99fEeE3J+5lHOYHQokKTzSLlOeKIcBObC2oqgOJBd8RnjYJF4g/bhyXxsaQ9v59vyYF7QO9DkXSJSzArEJJ34xqCKuEXhzFqIkEJBalxLUH7KDZGgWbYYg/ghVmno6rnnlvti4N+ILuY7ksWEm/khgGK4RGNsBoWUBYZaxhCVBUFGsSJA9KDyXSi1i6njWC975/r8o2imS1SMi3uFIumsEZoOZ6wdgQ3LiB49d5z7bEM/xjbwYGDxKHrtWTvZfH/hx+A7ch88HkGZksYbaolJgcyTQesBaB5fd739CykNRiC+LARielsPPuRjPfamKAlUcgfFmIbPybB2RCvHAIIvh8KIBwbm0rjpgPErBEJpnCmES/vEysgL9sy5bHRuv8wFI0YjqyA1XCxhzjcizfQINOJv9U8fZ5/kY6HE8OwYlrsSkz7zstPh5USBN+1YI5jkJWQyES4EYXSiBOH5nxZFAn1ugOTEw2cHMvGa8IY0r02fHz5oCfZz3FxXbo3PSz7M4ClIBQA4DUjIfSRyX+CwA+31U9m84oSms98ZAQhMHTl8cun4lVlZfc86vio4LJLEdTenailksBRqtiiNeZv/a1Kc2Y4Nn14HUMoBpJCeQmN8Cu9QFS3+BdlE8mWEgWkCVYg4/RaRVTQeA6zltfI0M4ThQB1bN24QVKgZ+4mAMDGLXDexpr7/m6ffm067EQFD7lpgWn0KybaIpbI1WtYgXkYqyNSSrWCMGIKqYO92ejCDGwRiAVQGwFJ3nVJW75L3XH3+M8FiY1sWxpgFA3ASFI17XLRjEtJG3hl2jifbiGzkGvgPfpz16Vw8B9MLAuEB2jXRxDGx1vAZloVyANMmcgXuqVYzJGLA+mNSUxAibH2BBK9L/W2IV1D4AL+cBlKNGu5sLXEYk8h9TaYCijIWkK82EynDvA7qd6QcEMa5RtHhiAJyM/u63JUCBlDA4crl4vRckbRiQqXpR4DntHlgBZONAHYijPG74YJd27Pmwe4sAnhVO57/m86G7uq4kS4p6gwR0vlSpXuUVWmSDpRziOsGlK0GUR+bSMN7wCqiLuQ/hKWF2fuIHcVG8pl9HwsCylZo+cRDi5HF9/jGkaE/WMnLf65gmjkKtOwZMdK6+/7TIzL5m1QeglAK2SY5N63UHCVC1WW18O75nvA5497v1oZuiZD/v1Rn9veg/RwofIphcFsS+pdml4AgYCMWMJgnUGAA/MNDGdLZudJlCGJbOWYqC9IYA6MDraYzoDkg0zPUhjGwycKxLYVDazG5UhJxQPd9jRp5i19KC8ZS8Ltn3vHJyBRxOwnH3s+4UFMFj6b+KgdiVgir1QE+uYtE+JG0BMYbvjPDs/DgdxnCGJwbACbzoTL50lzaw9b+lJO45lNVS4KZ2jArlbHHA2J0YM4U6SUg8BvrAmilr41Fx2YBRbNBAGFAv7kdLgf1tng7ZHTEMeKYY2H1oIT8JhMoKWL9LLUx3iiQbVDtUmmK4B+lgo1mlIGZMWfjurQPoiVEMUOFoidAKUW8dwKmvv45uwbldZxRsUAYvCoI7kv7NUjCU++PfBu0j3Wm1gZ6Ao2v4hNcZI00IiSvXikWmEHIbFNwuWDAMhkMC5oYEpCsDmtICTbCG6kMvTCNXdpaFCwfAUlPoTkhZ/ycdBjbWx7SE8S2GK0Mw4xpYR685gFkGrxhKCSkyzII6YZ1vOb9xVPsurTPXv+3I5YPhEX+oXBIZsJKMxhmaHqiB9RxHChCYWRl9YhWa/tz3UqM7pCoA6lIhgG+0wyOIewPHtkNqz2sEFILBhbAXfNiVSkP65EQW9JYAmBIbVgUgCOds9zIWKjjGlJBmgD48aGQQGLSjxQZojOdEwJR+kQB3mh4Apxmj8ddMaoA+vEpflycHp8oCBioGdtmjGKgMGCgOCJmiYWtl3TON1IrxsnCOhp4eG10uUFwDzPua3FLA5+TM3I9JphS6XpO/ItwzBCkE0GAMTCkLU6MC3jpkColG2HgF6Pi6KAUYKx2YLwsaU0J3JC7AhXJw1wiSRqgmCQbrnoB4WKR63+4RHQFw7Aw6owKgB/fj63K8IvBERHN8mgJ8RqkDGNAPOfmriwE1BmyUhyPkVwSyj97103d7sjvxkIiVAtLojac6gkDnayblgQWvUKASFWJlmBIbg9/CR/XO4JTFBtDaoPYs0BjJqfa+FbN7ETzo1g27LMSArj4rzIWQHCKk3hmuGwZNMlhWUC1MCZLviIE76bNAEbijwVsUGxRRDRhq8GrGA9rx0EBKgnWU6ihkSQSoCM34lVPU82nU6OTAWMGF6vUABhfiX7MEf0hSsywQVwt1kGBANkRCEc3wQH0gz54dMICCMcKj1gQ7NgZoknqPubDmy2JAvEDZFiXChQxzU8SlpBYSBSTiCJGX+1kdwGDF4PhT2gVoWqXBwOivA33TqZesA7BgdIJfwxphWRkgGjhSiUBFIWDszlQ8oEFyFKvHAJOxHiAkBlLFQUHwirGL1YIY3jcmHS8FhQh2+Y/B7EUzVCkLzaNiKaBGKrh0SMn9/tecC5HOfCIWEI+BmBoO1QFPP9gPrSsLl5W5vg1KcRu0uB9NUlQd/qU8isGsH0z/ZUfMqwOoyNwITdLcGEf7Fi/iB4bImuJfe+vlL7uqZrXlb4pgrnTBGWEAN/HXA3Aq4pWsT8R2gsBMly1TBxLhYRcQE8GpL1wTaRYv6sb3BUegOx5VOsH619id+HdNrJcCkp7YxoMOd2x+AVJNTxmpnlQYigFPDXeaql8aAzDc4cosiMkIX1IkASqJv6ElxEhLUwpKoMtKQOs089Re21BIFtDtzlRq1CdI8UckgdtTy64Q6GYvOCOvvysMChcoXAQQ5QtKUoQ1ESL2RKr5ukp+eAwkdQKyIBRJP2rxoF3m6VH5gqQSUCNKm7NY7xHBslloWDP67z66uUDVMSxWJMjsv/FwpLIghgGWiZ+TH1ZVUIM+7wx42gB1XiTA1GQ+cUfIevFBbXAiFxpc1w/L+lxdGsB2gQJsp0R8Ew+k3IMSI9ISP6HUTdPTPzIZYNQBzMaDIRvM3BxsGI9A/4IxcD4p6uoDuC6QXQS4umWh0ihgoso12ktBSABQJtOLEI9gPR4DWQM07hHF9In7c8+MAbjMqHNGA2RcoNYO4kWgRnYbBnaaV3hRhCC17N+2RPXc79YEx7bPGzgYiIpxXmQ9NHV98MlhEIyEGAXS0Y+iwa8UAarv2SsGsqgoS8FOdQzO416DXh2wuZCGxT5eZFuiMDIx0SsDpi8tOC0MphQEkwKZuZ+UvOsznzLl11Hxem5RCqgMhjoqIEWHlDrQjgxpuR+8YMjLWf/O7MTEjLHqifbopbJ+PBgyNqgJ+mDKbzI9NCSnDIb9M64viEAfxfQvwl3M/Z4Y8OFolog4U5rfIsiHBLx7hHMW1vUTYjwb1KD7otgFOjL6/i2x+5ErYAnrlftZl45UQVA3bVZyvy+IPfY/x9Lp9oimbuAF15tkHmRBCQ3QRkj5I5UuGEkXvI5I0kh/A26G9ZYOeZUBdVKEujAQxYAtlDGia/UpUZfxdwTVoi7BpUweHEj8jALZGoBdcOhdVijEIqDleFKCobm/GpdQKoMtA9wOGnr8R1YCnjCYZefbsuH8zgCcOPYzy/GURTCJfQAT9AL1B8n8aaKiJkL7o7SphQbllQaoE7/cEi5/pUAwIKkQ56YnatESEAaWbPW6BJCZfZjmir6JAk3HeuSyYk2wSISK+0kKjCrrb5xn/xZLoxMq9IulgOpHoagbtL0yRrDeZRnZBSEaA0bHoIvApJjMIAWCc+c9p3P6juCpKVCA/GhZ//BzoBC+LM2/mL0eDMe/hTawwB2IAXTTv14QUM/xIWpku0NroJxaYAnTpyFobWrHqSGxdYJN8iM6oVRXDBTdT2hJDtSJvMzuFcOpU75QH2IxgLFGgRMVGqAjitlN/4E2mQXlgTXEbxmIWIf1vp9rukD68wnaakAFKZKLAFToL1VBBXTOcCS4t7JYa4FJvhBqsxKxyiAHhlEHYqNE012dJUcWTBUDE+38/grwOineSP8c+vVDIuk/agIrAkcpAAH9PNmLVaKZIHK5kGyJSpDVugSi44kdyvhEZ/PkLRZP6FtNf+VKA4h+P2rdADHfVz6KUATEUnDgHiSqwwSx4IfqMYCiHoAQERLfOEMNq9XAtINsd+hquJ+e/nENyoPPkkQwqwTG65LIguocDzWsIY77/TIQ7pRVr9QxEPSAQoRsMeCr4aQd1NHZjcP3XbjHE7HeFw/l05U+gKEEGsSz65scDzWNYXAV2E7b/4Kj+cC1csggAkseoDQogZrbYw7SYdgOmrX4azXQ32uDToQ7dlYAqSHAXSCUtEETD1D7ntq/UJcFC/di/0siP/LaAGVWFO1qIBEVNFXBiDIOxUD+pNR1hwZo21MvyuuDFSBEgbJxVpmepSBuFC0I/0JdFoAZpvIzQbkTVCmMPP2DUA2y9ija1SOT/kV/8/zsvm5JwDlwR0bmcTwAkI0AkXmlcBwRV8BlB0BHv3oPKCHFq4Fcm/SQsP91G2crm8R9kF19cv24Elhh/2vXJAPAaBIzlq8GA1VKtG0LBNBv1o465eslQqsGnLVDV8PYrQPckgo2iadg+swDjt7ojc4OADApfo1CMc0TquSlVRw687Hs/xLTjdgFtRqgdiJGpBpkGFEHKQraoxMhPuUEu3NGncefOFkDaOlfrgY17QFkU9OlL+XWAZF4iaFSuorKrI5q1dtKQGkCRFjQii1PBvGdzegng36EKZFgg07FfQVCVgRAckXLqekG6JUfWpQaUpK9JkSw6QlA5YoiWcwkogpQ7zH3qOE1O8AtpDc0H/HjTr99fxEAkdSdvTXmKecsrHEGRRsB6soAzbAQqNRfJj/1L4Hkn6fdOJXojQxB2BcCZTVmqhQMiuNu4n6FWf9ZT1QqgGKcD0K/6QaU6wQEuBeVQaT+7WZB5MkAcYfnRisXuDTaAoO+kLHFUDYexhnRuodWMJ+5BYHaAHDhXp7l2A195qWWd4IYCSKb9ywgLR5ki10KEnT3CLJ9oUk9gaEwkNpkI7g8DfHjTa7IbyJUAOr+VaQmlwx9adkASN8CG4iIjANFY0DUwWCKYIjqgQ4vqD8e8vuhT4Tj3M06z+Q/LQUihfyQMh0J/vIBOeu3W+7WA9VQr7hHluxbI8htArgpsxAGqi9k20RZ9n9KKYA1s/vv4vrjNUGqALfXmmDyaA/EhuWcHykuHthfTdpXq0n8AE4TQF4GILmiSObyK00EKztBOCyoY2MVTyfA7O7YEDWnyfCdDnfLBSL3pK0I7qWMq27hXIhgkNYWNz+SlJCwNADIygEz8cBlq7tXSjD3h2akxw7Me72fM1z8cwTr+WXhTvuKsJgCPlZjZd+OhudIewo1/ma743QThYGBUM3xbBCj7scWWMgiGjvo1Q0V9L3by8Hipth0OJ5sd6oB8GAuEFcC2OiBOhgaHBpVoZmaRk15K0ctubsAWatkvHGJ0hL1DzKS2sBGZ2CWGIAZKwRg8VLGCz59gggGa7fc9F9C7IVC2/8HggH1BTHI6BAGTqV2UzIGUinapuqy4dCoDFi8kckb4R7YFsUVwdsrESlekLJ8lvTHQ22E3mDQlkTyIQjREhWYj0HKk/a/saoYxoaCYFJHrLMO0CVSe9fmuE8NYBzAKPEfLRhIX05OQbjrl2E4GHA3NGGoFJSEB/XTwZxI0PjSAP+B2c3gcTsIAzltqZ8zRwOQ6P9gfZiFJEFdDV0x/noNcSgqlMMn7WBAUJcEIFscg8rYXBCymgzotoMGhe/S/XzeOL8w96XudCMojsjQ0j8V+YwYdGjgHZFX1pN6RB9456XyL7DJ+nVgJzZX215E7A+ELFGvN3w2+59SCugSubzvBe+EdPSepDqAzPARcK9syBN6Z0rjv+wBl5ke2AllYpDY8bCnc0btsLlG+dqpA4FRuRW5f8oGJ7Ms0aXdqxW/Q9UHIPAsoHrzWpEUdfyKpN1fdgCUQ4udOxW3FJvQbRhR7HAKdRqCb69i7kWXmgmdboAuZf/X5P21BmhcIIUxU5EFX3cbW88y28SumdU6Hdb2OpYKkH+Id4QRlcUNFakDsaOtnd1Cpe6bhtEhCkRv6IKt6GTR6RHVukAEVieVH1pBKB0wEFtFgGKmB2UCFHS4d4dBaQoVvxWC5IrGuVBwJmLgnMmZdWBwGdfUEaBzoI+iC0QgEQaQFbDQ/bWPbpd+A95fg2IqjgZCAmHjOSh8YW2SlTy8ETNtAQg7nlMWhZ3UAbieEkhqgBsd3KNsBjNP0DikWqBD4u9Fer5uVoGJoFfDpYW+XQ2wzPpiN0BfjKvOBZkQH6RAsHICYhb0161foZVxdYhg4ohhAqDsc1mHtkvpH9kf0wKVbwax/0QonB+OeyhmhzKkCMVugNT/EtdPinyGd0VmzcCNoH/F9lUjoLxOPXmJ4KMCSJOV5cnV1eFFcfTv1qqOSQB5QxRBGUn3oBFkniQQw0DMvsi+iAsAF53zBQBN9fsHQHkFe3SsAkC9v+cWDx3odxxLFgNUDmyhWRpJFhlcEkTCAClGPML7BkzZJhrm9r9oDPr0kaDvrQD8+Lr6yF4EuD2f5aJ/DyotBkA/tgyU9M8iAUtJAHIrANmHhqSuCoj2AcwD9rJFoC8SYPZiSHxfsndt0/kVgGriW1WAmvY8q8GOvwfBra4DGvqNNS0gCYBgJBzA1QsCsAPi0dwgqFLGxo5DpthN7Qk3vfv7ESJ4nTwg/Sn3x+04I4zENbgS/9nZf6X5Gh+JJKJRGKkAiqNa62BoRu7YH4f1H9dm/ZgqQN4QkHx6DYuR5le2CPSZPx/n/5zAlKwjkp59gHYagg1Ocv5Tsf8CVQ+CG7WRR1C8TmA7HzWUiZ3XYgYDb3ghSDaozumD/gzE1DCYQ/+QCYl16I/inq6O+2gfgEqoFL5n0wFoKgCHflUEOO4pAXShFAQ5IBPEuIkBnvux+K8xLuXVYSYK4woy2wKbjv4LDkFcQgST2QEopyl36r9n01vTOd5wv08ZNf9i7F8Z6KhT5GaoAXV3SLSA2HmSNkCNVoCxK1a3+zlk+AxD/5tw34rgfQ6CmiEzKvZzplr17imfAAAehQVU4j6+l2Ekr6Mu/rkSEOSP+K2yHgBA2DNUHjuLnK43y/+hEPrFlb74g75YAY7cTK0MePmVBfkpK8CtJj9UU38j5avC13Z+gjeSHBg4rEwsOwOSUYN6SJTeaLN6OCUos7Ab9EZwAJ34ybhHzzA9KBDVew9Cc6xvLX9x07soSt69b1D8SwT4sGb1y33PSVsqmZKJxfoy1JZuspUAwgvqpifGFHCHBkjEEvVEmruXm7vj5WWhj+FIwMoFwkIHw5bR6xWuSC3zAYAHwo0AaPN/CqunSf90AySgh2L8o2KGdg9DkRQPCilCtJDkQjaS/iO+p5v+xYWawfiMw/SzJh2y5ZGqrRFvVCKVk5Vj9qFI/4fwpWpLFQIF+iXibwAPdicox+9J9xsGnLzlGypKWiwpmg7W/VC7CMQ/rXOOAsCvgP6s0/JaDXD0gwvyo6X/XfiWuZ+o4j8786kQfwN8tGmekA3/xJZOIqf+qKrqtg8Agg7ua8TaB7BiBvQ59NNfGfpfMg59BABTwK9ca6b/ffaBisCBWuk+mQ80YYB1SHDIRsY/NW9USu0I7cQoApuDYEemanUgWARScO+oA7Nyf3ab148GfR0Az10hip1riapzTp8BYKR/ourf44tHRYGarF9+y8HtLHwBITz8T1cnQuJgXGrUDDN2ZFxazEK/7SjgZeB4/g/aNEChgGnDRGuAbmtkm/T/ALgpiX+nQLAxn1IB70vAqlUvbJcUeRy6secjEHE3dYzr4LD7GUHtRPSvoz34RaAXKFAlghsLqI6BGxQDP2LiL0C/5/4D98+IaWwfEj58kvYLculQAiJKX0xsbEFgU1RV/ga2/oQxq74bQHgBXL7XQaoDgB8wuslZ3KjMYwuDp/v5jIQjAB4F6IvcX+KeNvZ/8H4Oeopt/WB4vCYVRpQaYfyJ3vEtEc6d9UBHZh84w5k/9kPfgHs9AGo9i4UGaLUvVbSHdpJTCIDXt4+6DuzBUKOAwNz0E6qFv4gSwzb7fihOB4G0HqAbhZjrLqVG3+ZQ/3cz/qsNRygBIPGfZ8d3b3tRnf5fvmdRAYA2oCuIL++vOsGBMBDn21Qb1FYCiokZFcHF2GzfmuAV9uXqY/C+APosAJomAFS5/yA/JJCfw/O5bU+vs/6L9jTf7l9gbVDWYYB8U2iOe7TqPrqfTOGKGppY7Z3NRUByqymcDbU/An0pAEDuAb9Gx+jA/e78EFSknxMe2n2iB0uJpGZLKhcf2tWAUyDqQb8K+phXA/ktISa0wLr3+qResNI3gN4LADgWNJZF4EB/k/tJhv4O+j39H5HAw0Acj9aOgQFhe4lqjx3wmwMGZRdXw3SI4O5MGV/5fsHbp0C/DQBBAW8B8BK+qKO/lrzP6kCPNv2/ug0ohQEq9UE7+xFixzCR7gKBPAc6KEa75W+niTk1JeOfwX0RAEivDM0DoGH/oKN/4z9PuJcV4FkQKnqzh0ED+uAKseYQbN0eFXtkfKGMOMODxoowVHdjHpmEC5Gf3p1of+jXA+AfqwClBdSwf3yZP3uENOh/8Z993nPDghwGDfQj8QCsU8GA2zGqjjNy+Yh78/ZFJ/jHcK9SIGrYP7TaF4oi8HgAaui/HdVgJzzUMB9eCqiOByUGWn0sDbSlabq0MqZsEcR7BRpQUpNwTcrv3vF87uj/FyAeOwLgtSCY4AYy86Gd6hTo37P+qxRsib/aX5O2e6i6BylWBzRFa7qithpGvYwM+j/dLhCk0D+pOn0T6I2/ogoA4v4P1MIXZPTDrXgUigpQZv2dDpVwL6OCXo+iXgGQrFNc+XnuQDn0Z72Xjq1QDHsRp0JwhXb/Gty3AfAobdDS/4HD+jy6Yxv6oYyKnfBsoKfS7akjgeoi8LyH9uOHXRZk7MUb6wygtjLmAwGBp6GfPhvragA8mj5AwXwe2xe3Iv0/4FjtRQXRf/0LB/pf8dBk+oYFlRkd/cO6q7+5tINI5jNNGGhzmhh2Y1IsqE/+4rIIjDunf6TncAQA1R0ALCgQNfynVAIb7WkrAFTor4gQ1iexamGAlv+DeltAZeropLTgid88eKZYRhN5/AUHga6G+yMA/nsTbNDD/YSa/Ijsf0v8bQWQ8n17PzFe4p31qxEh9Gj9oMWJfwMcfwf6sgvUBABAJX8fzwGhh5L+66z/+oKFBP+iTf/SWUYGEYr0ht872bto6/Dph/7iX4K+LIKxCAAh/Re4hwL6O+F5wb3kFw9WChoOYhQE4/gZJSRQapD1W9146gJwW3uMDCB9qJlzwq99f/yjB1Ui+LD/odK+Le8vsv6L9O9hwNI8oQR3VOx8+2yvsJXZw4WGtzDp6wBMWQ18/tafXxBvmwimgwId9j9UCyMfexGAog7AK/2XfEYgOTX0CaVIiBSBshXQrETxNnaekoZX6Nd1q4FntoHpq3BvBgBL/4+S/2wN4z33U/0uEbWYfu27yENCfGMxWgQwaMgofS6dl01OddONoGvi7FOnQV8uUB0APP03FOiA1KNoY+E26gzbRkPifyIGRUaE8k5VhgZwmQ+OLaG61kbhlzmk8ZOnQbcKAEUA7HtFvdL/Rvpb86c5EpIEhlPxfqj9UPsdnaEEctZ+hgX1yYAsO4o8hH8PtesDoCgCuIvg3QDdSH+T41/9AU0MgLTvZrAOBNbmvjeHjaNw2iAQjVL5PxU/mwu07WkOVCzfZRYQfwePQToGYmKnqlMzEBH5UOw5H3v8gaL2zjoc4DeC5ptKx/2/N6IyALYYeDYHKu0rkh/aeL844CkO/XMZoFGgSKZ3y0X8czUm/s0jU0+60Q/9iygQHcsAsNy5sJl/Lpyfg+5vtKf5r6XDfEkIFh+o2xwA1eX8iE/3gjuJ4w/9WgDcSmLTCIDN+TncT2LpHyXLHyQZgJlFGbQeMvRX0DBZV3xZAOxZtu0BF6T/+RWh6XXicfhkdQ9oB7lkZEBAGaPHcK7I2mk5vn/mjxIAsG0DsW+NVUw9EBXof0L/Vq1lUQc/QaBDBOZJLPHEHH60xw+dVXZWps+f2T9NBEPNf16zbUXn60j8BfRLqnP8B4XN3/Af5b2Ux4SSo/mrP+lZczXRIQj6ExB8dwX4R49HvYE9vtB/+D8I9NzZakP/EQM3tqkJKto3u09sN9BHisZAhMxHpyf3f/EwiQJtyeYGQE/0YzHz8zh0MBToVxc6gh4D7NMj6BrH0U+m+FCViX9Mel40AJ5YxNIFeobB45jwKT0fOQb4WS/NF31rq5I7M+c2hjgFf3jJ2PvLAqAKAISaxO8bnOzmD722PxEGnkEy9Wv0O4MymMfbKSMSkWDAzwHNjzXJLtDrRIkbIEJ5XkZ1dliNftIt/wM2UrKvJiri++/QepRfGzQ/7K4JAKTHDQDghi9z81giTLXrT2arC1tLlDp2QMYzTJ5O9NEPlF9MgZ6ew+3Ys/a16HEvBXyJo05aqGFEwDgShDfbd9G/ZvE7nhB4P417HQqECHSDx22rA0X6LxO/trMVRVhwatVJqg8wDlb8jZr9UfZ1fzwbYQjwb6sA9QKx47SLjuF+7b0csYOW8Zkf7P6oBqDbqwLQv+KcvMdB/ZtdPl+mTb3bM/0+zOv/6T/SpVWA2z+gfwD/XvznmALiEz6QP98Hp6LpHcMRPxR+cwWAGzz+AT5j4Hl7yBPOO/pFh4c6ZMBbNxzs2BTkR0u+LQDoRgRwuwHdNw+UXjM/RNW+bny68yUTxI0eapFwwaznD1DQZcLvV0lWV4AX/2nO/tWnO334hB+ibvh80Tbfv9s7AwAR6A7077VrOT3UBS6q3p27QdTv9hMt51Gg5y64/14BANvYc+X5iFResjIp/2a+PRB+kfjnK8A/uN0B/lUbPRCf75+BF/zzSPzF2+UqAN5fCvg4JFjr7zaLevuO/7wAdP4mCn+xJwfAUwHv6wD2ESDgQ84LWOLPzPih+d0B8J9XB0CWvyjrV+r6WOgzEfZD21eL4DvAv4r/0C9bf+jt9wmlA+BG9FTAj3JTON30/CXD3+2rAuBOcA8MNv9uv9tXBgDcCe7F9ugS+SWXF//C5qe2P7UC/E+5Ibr1BtDv/f3dvrAC/C8dO538UPnL1n8wAMiF/q8F9SE3+r3BPRrgd/vd/m4A/CP475vOU/7dfrf3i+DXaXi/2+/2NyvAr3n4u/3pAMBfAPxuf/f2/wMAQAlQpLLpCe4AAAAASUVORK5CYII=",x3dom.caps={PLATFORM:navigator.platform,AGENT:navigator.userAgent,RENDERMODE:"HARDWARE"},x3dom.registerNodeType=function(e,t,i){void 0===x3dom.components[t]&&(x3dom.components[t]={}),i._typeName=e,i._compName=t,x3dom.components[t][e]=i,x3dom.nodeTypes[e]=i,x3dom.nodeTypesLC[e.toLowerCase()]=i},x3dom.isX3DElement=function(e){var t=e.nodeType===Node.ELEMENT_NODE&&e.localName?e.localName.toLowerCase():null;return t&&(x3dom.nodeTypes[e.localName]||x3dom.nodeTypesLC[t]||"x3d"==t||"websg"==t||"route"==t)},x3dom.extend=function(e){function t(){}return t.prototype=e.prototype||e,new t},x3dom.getStyle=function(e,t){var i="",o=document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(e,null):null;return o?i=o.getPropertyValue(t):e.currentStyle&&(t=t.replace(/\-(\w)/g,(function(e,t){return t.toUpperCase()})),i=e.currentStyle[t]),i},x3dom.isa=function(e,t){return e instanceof t},x3dom.getGlobal=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")},window.requestAnimFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(e,t){window.setTimeout(e,16)},x3dom.toggleFullScreen=function(){if(document.fullScreen||document.mozFullScreen||document.webkitIsFullScreen)document.cancelFullScreen?document.cancelFullScreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen&&document.webkitCancelFullScreen();else{var e=document.documentElement;e.requestFullScreen?e.requestFullScreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.webkitRequestFullScreen&&e.webkitRequestFullScreen()}},x3dom.debug={INFO:"INFO",WARNING:"WARNING",ERROR:"ERROR",EXCEPTION:"EXCEPTION",isActive:!1,isFirebugAvailable:!1,isSetup:!1,isAppend:!1,numLinesLogged:0,maxLinesToLog:1e4,logContainer:null,setup:function(){if(!x3dom.debug.isSetup){try{void 0!==window.console.firebug&&(x3dom.debug.isFirebugAvailable=!0)}catch(e){x3dom.debug.isFirebugAvailable=!1}x3dom.debug.setupLogContainer(),x3dom.debug.isSetup=!0}},activate:function(e){x3dom.debug.isActive=!0,x3dom.debug.logContainer.style.display=e?"block":"none"},setupLogContainer:function(){x3dom.debug.logContainer=document.createElement("div"),x3dom.debug.logContainer.setAttribute("class","x3dom-log")},appendElement:function(e){e.appendChild(x3dom.debug.logContainer)},doLog:function(e,t){if(x3dom.debug.isActive&&(x3dom.debug.numLinesLogged===x3dom.debug.maxLinesToLog&&(e="Maximum number of log lines (="+x3dom.debug.maxLinesToLog+") reached. Deactivating logging..."),!(x3dom.debug.numLinesLogged>x3dom.debug.maxLinesToLog))){var i=document.createElement("p");switch(i.style.margin=0,t){case x3dom.debug.INFO:i.style.color="#00ff00";break;case x3dom.debug.WARNING:i.style.color="#cd853f";break;case x3dom.debug.ERROR:i.style.color="#ff4500";break;case x3dom.debug.EXCEPTION:i.style.color="#ffff00";break;default:i.style.color="#00ff00"}try{i.innerHTML=t+": "+e,x3dom.debug.logContainer.insertBefore(i,x3dom.debug.logContainer.firstChild)}catch(t){void 0!==window.console.firebug&&window.console.warn(e)}if(x3dom.debug.isFirebugAvailable)switch(t){case x3dom.debug.INFO:window.console.info(e);break;case x3dom.debug.WARNING:window.console.warn(e);break;case x3dom.debug.ERROR:window.console.error(e);break;case x3dom.debug.EXCEPTION:window.console.debug(e)}x3dom.debug.numLinesLogged++}},logInfo:function(e){x3dom.debug.doLog(e,x3dom.debug.INFO)},logWarning:function(e){x3dom.debug.doLog(e,x3dom.debug.WARNING)},logError:function(e){x3dom.debug.doLog(e,x3dom.debug.ERROR)},logException:function(e){x3dom.debug.doLog(e,x3dom.debug.EXCEPTION)},assert:function(e,t){e||x3dom.debug.doLog("Assertion failed in "+x3dom.debug.assert.caller.name+": "+t,x3dom.debug.ERROR)},typeOf:function(e){var t=typeof e;return"object"!==t||e?t:"null"},exists:function(e,t,i){return i=i||"function",(e?this.typeOf(e[t]):"null")===i},dumpFields:function(e){var t="";for(var i in e)t+=i+", ";return t+="\n",x3dom.debug.logInfo(t),t}},x3dom.debug.setup(),x3dom.X3DCanvas=function(e,t){var i=this;if(this._canvasIdx=t,this.x3dElem=e,this._current_dim=[0,0],this.fps_t0=(new Date).getTime(),this.lastTimeFPSWasTaken=0,this.framesSinceLastTime=0,this._totalTime=0,this._elapsedTime=0,this.doc=null,this.vrDisplay=null,this.vrDisplayPromise=null,this.vrFrameData=null,this.supportsPassiveEvents=!1,this.devicePixelRatio=window.devicePixelRatio||1,this.lastMousePos={x:0,y:0},x3dom.caps.DOMNodeInsertedEvent_perSubtree=!(-1!=navigator.userAgent.indexOf("MSIE")||-1!=navigator.userAgent.indexOf("Trident")),e.__setAttribute=e.setAttribute,e.setAttribute=function(e,t){switch(this.__setAttribute(e,t),t=parseInt(t),e){case"width":i.canvas.setAttribute("width",t*i.devicePixelRatio),i.doc&&i.doc._viewarea&&(i.doc._viewarea._width=parseInt(i.canvas.getAttribute("width"),0),i.doc.needRender=!0);break;case"height":i.canvas.setAttribute("height",t*i.devicePixelRatio),i.doc&&i.doc._viewarea&&(i.doc._viewarea._height=parseInt(i.canvas.getAttribute("height"),0),i.doc.needRender=!0)}},this.backend=this.x3dElem.getAttribute("backend"),this.backend=this.backend?this.backend.toLowerCase():"none",this.canvas=this._createHTMLCanvas(e),x3dom.debug.appendElement(e),this.canvas.parent=this,this.gl=this._initContext(this.canvas),this.backend="webgl",null==this.gl)return this.hasRuntime=!1,void this._createInitFailedDiv(e);x3dom.caps.BACKEND=this.backend;var o=e.getAttribute("runtimeEnabled");this.hasRuntime=null!==o?"true"==o.toLowerCase():e.hasRuntime,this.showStat=e.getAttribute("showStat"),this.stateViewer=new x3dom.States(e),null!==this.showStat&&"true"==this.showStat&&this.stateViewer.display(!0),this.x3dElem.appendChild(this.stateViewer.viewer),this.showProgress=e.getAttribute("showProgress"),this.progressDiv=this._createProgressDiv(),this.progressDiv.style.display=null!==this.showProgress&&"true"==this.showProgress?"flex":"none",this.x3dElem.appendChild(this.progressDiv),this.vrDiv=this._createVRDiv(),this.x3dElem.appendChild(this.vrDiv),this.showTouchpoints=e.getAttribute("showTouchpoints"),this.showTouchpoints=!!this.showTouchpoints&&this.showTouchpoints,this.disableTouch=e.getAttribute("disableTouch"),this.disableTouch=!!this.disableTouch&&"true"==this.disableTouch.toLowerCase(),this.disableKeys=e.getAttribute("disableKeys"),this.disableKeys=!!this.disableKeys&&"true"==this.disableKeys.toLowerCase(),this.disableRightDrag=e.getAttribute("disableRightDrag"),this.disableRightDrag=!!this.disableRightDrag&&"true"==this.disableRightDrag.toLowerCase(),this.disableLeftDrag=e.getAttribute("disableLeftDrag"),this.disableLeftDrag=!!this.disableLeftDrag&&"true"==this.disableLeftDrag.toLowerCase(),this.disableMiddleDrag=e.getAttribute("disableMiddleDrag"),this.disableMiddleDrag=!!this.disableMiddleDrag&&"true"==this.disableMiddleDrag.toLowerCase(),this.detectPassiveEvents(),this.bindEventListeners()},x3dom.X3DCanvas.prototype.detectPassiveEvents=function(){if("undefined"!=typeof window&&"function"==typeof window.addEventListener){var e=!1,t=Object.defineProperty({},"passive",{get:function(){e=!0}}),i=function(){};window.addEventListener("testPassiveEventSupport",i,t),window.removeEventListener("testPassiveEventSupport",i,t),this.supportsPassiveEvents=e}},x3dom.X3DCanvas.prototype.bindEventListeners=function(){var e=this;if(this.onMouseDown=function(t){if(!this.isMulti){switch(this.focus(),this.classList.add("x3dom-canvas-mousedown"),t.button){case 0:this.mouse_button=1;break;case 1:this.mouse_button=4;break;case 2:this.mouse_button=2;break;default:this.mouse_button=0}t.shiftKey&&(this.mouse_button=1),t.ctrlKey&&(this.mouse_button=4),t.altKey&&(this.mouse_button=2);var i=this.parent.mousePosition(t);this.mouse_drag_x=i.x,this.mouse_drag_y=i.y,this.mouse_dragging=!0,this.parent.doc.onMousePress(e.gl,this.mouse_drag_x,this.mouse_drag_y,this.mouse_button),this.parent.doc.needRender=!0}},this.onMouseUp=function(t){if(!this.isMulti){var i=this.mouse_button;this.classList.remove("x3dom-canvas-mousedown"),this.mouse_button=0,this.mouse_dragging=!1,this.parent.doc.onMouseRelease(e.gl,this.mouse_drag_x,this.mouse_drag_y,this.mouse_button,i),this.parent.doc.needRender=!0}},this.onMouseOver=function(t){this.isMulti||(this.mouse_button=0,this.mouse_dragging=!1,this.parent.doc.onMouseOver(e.gl,this.mouse_drag_x,this.mouse_drag_y,this.mouse_button),this.parent.doc.needRender=!0)},this.onMouseOut=function(t){this.isMulti||(this.mouse_button=0,this.mouse_dragging=!1,this.classList.remove("x3dom-canvas-mousedown"),this.parent.doc.onMouseOut(e.gl,this.mouse_drag_x,this.mouse_drag_y,this.mouse_button),this.parent.doc.needRender=!0)},this.onDoubleClick=function(t){if(!this.isMulti){this.mouse_button=0;var i=this.parent.mousePosition(t);this.mouse_drag_x=i.x,this.mouse_drag_y=i.y,this.mouse_dragging=!1,this.parent.doc.onDoubleClick(e.gl,this.mouse_drag_x,this.mouse_drag_y),this.parent.doc.needRender=!0}},this.onMouseMove=function(t){if(!this.isMulti){var i=this.parent.mousePosition(t);i.x==e.lastMousePos.x&&i.y==e.lastMousePos.y||(e.lastMousePos=i,this.mouse_drag_x=i.x,this.mouse_drag_y=i.y,this.mouse_dragging?(t.shiftKey&&(this.mouse_button=1),t.ctrlKey&&(this.mouse_button=4),t.altKey&&(this.mouse_button=2),(1==this.mouse_button&&!this.parent.disableLeftDrag||2==this.mouse_button&&!this.parent.disableRightDrag||4==this.mouse_button&&!this.parent.disableMiddleDrag)&&this.parent.doc.onDrag(e.gl,this.mouse_drag_x,this.mouse_drag_y,this.mouse_button)):this.parent.doc.onMove(e.gl,this.mouse_drag_x,this.mouse_drag_y,this.mouse_button),this.parent.doc.needRender=!0,t.preventDefault(),t.stopPropagation())}},this.onDOMMouseScroll=function(t){if(!this.isMulti){this.focus();var i=this.parent.mousePosition(t).y;1==this.parent.doc._scene.getNavigationInfo()._vf.reverseScroll?this.mouse_drag_y-=2*t.detail:this.mouse_drag_y+=2*t.detail,this.parent.doc.onWheel(e.gl,this.mouse_drag_x,this.mouse_drag_y,i),this.parent.doc.needRender=!0,t.preventDefault(),t.stopPropagation()}},this.onKeyPress=function(e){this.parent.disableKeys||(e.preventDefault(),this.parent.doc.onKeyPress(e.charCode)),this.parent.doc.needRender=!0},this.onMouseWheel=function(t){if(!this.isMulti){this.focus();var i=this.parent.mousePosition(t).y;1==this.parent.doc._scene.getNavigationInfo()._vf.reverseScroll?this.mouse_drag_y+=.1*t.wheelDelta:this.mouse_drag_y-=.1*t.wheelDelta,this.parent.doc.onWheel(e.gl,this.mouse_drag_x,this.mouse_drag_y,i),this.parent.doc.needRender=!0,t.preventDefault(),t.stopPropagation()}},this.onKeyUp=function(e){this.parent.disableKeys||this.parent.doc.onKeyUp(e.keyCode),this.parent.doc.needRender=!0},this.onKeyDown=function(e){this.parent.disableKeys||this.parent.doc.onKeyDown(e.keyCode),this.parent.doc.needRender=!0},this.onVrDisplayPresentChange=function(e){if(this.vrDisplay&&this.vrDisplay.isPresenting){var t=this.vrDisplay.getEyeParameters("left"),i=this.vrDisplay.getEyeParameters("right");this._oldCanvasWidth=this.canvas.width,this._oldCanvasHeight=this.canvas.height,this.canvas.width=2*Math.max(t.renderWidth,i.renderWidth),this.canvas.height=Math.max(t.renderHeight,i.renderHeight),this.gl.VRMode=2,this.doc.needRender=!0}else this.vrDisplay&&!this.vrDisplay.isPresenting&&(this.canvas.width=this._oldCanvasWidth,this.canvas.height=this._oldCanvasHeight,this.vrFrameData=null,this.gl.VRMode=1,this.doc.needRender=!0)},null!==this.canvas&&null!==this.gl&&this.hasRuntime){this.canvas.mouse_dragging=!1,this.canvas.mouse_button=0,this.canvas.mouse_drag_x=0,this.canvas.mouse_drag_y=0,this.canvas.isMulti=!1,this.canvas.oncontextmenu=function(e){return e.preventDefault(),e.stopPropagation(),!1},this.canvas.addEventListener("webglcontextlost",(function(e){x3dom.debug.logError("WebGL context lost"),e.preventDefault()}),!1),this.canvas.addEventListener("webglcontextrestored",(function(e){x3dom.debug.logError("recover WebGL state and resources on context lost NYI"),e.preventDefault()}),!1),window.addEventListener("vrdisplaypresentchange",this.onVrDisplayPresentChange.bind(this),!1),this.canvas.addEventListener("mousedown",this.onMouseDown,!1),this.canvas.addEventListener("mouseup",this.onMouseUp,!1),this.canvas.addEventListener("mouseover",this.onMouseOver,!1),this.canvas.addEventListener("mouseout",this.onMouseOut,!1),this.canvas.addEventListener("dblclick",this.onDoubleClick,!1),this.canvas.addEventListener("mousemove",this.onMouseMove,!1),this.canvas.addEventListener("DOMMouseScroll",this.onDOMMouseScroll,!1),this.canvas.addEventListener("mousewheel",this.onMouseWheel,!!this.supportsPassiveEvents&&{passive:!1}),this.canvas.addEventListener("keypress",this.onKeyPress,!0),this.canvas.addEventListener("keyup",this.onKeyUp,!0),this.canvas.addEventListener("keydown",this.onKeyDown,!0);var t={numTouches:0,firstTouchTime:(new Date).getTime(),firstTouchPoint:new x3dom.fields.SFVec2f(0,0),lastPos:new x3dom.fields.SFVec2f,lastDrag:new x3dom.fields.SFVec2f,lastMiddle:new x3dom.fields.SFVec2f,lastSquareDistance:0,lastAngle:0,lastLayer:[],examineNavType:1,calcAngle:function(e){var t=e.normalize().dot(new x3dom.fields.SFVec2f(1,0));return t=Math.acos(t),e.y<0&&(t=Math.PI+(Math.PI-t)),t},disableTouch:this.disableTouch,visMarker:this.showTouchpoints,visMarkerBag:[],visualizeTouches:function(e){if(this.visMarker){for(var t=[],i=null,o=0;o<e.touches.length;o++){var s=e.touches[o].identifier||e.touches[o].streamId;s||(s=0);var r=this.visMarkerBag.indexOf(s);r>=0?((i=document.getElementById("visMarker"+s)).style.left=e.touches[o].pageX+"px",i.style.top=e.touches[o].pageY+"px"):((i=document.createElement("div")).appendChild(document.createTextNode("#"+s)),i.id="visMarker"+s,i.className="x3dom-touch-marker",document.body.appendChild(i),r=this.visMarkerBag.length,this.visMarkerBag[r]=s),t.push(s)}for(var n=this.visMarkerBag.length-1;n>=0;n--){var a=this.visMarkerBag[n];t.indexOf(a)<0&&(this.visMarkerBag.splice(n,1),i=document.getElementById("visMarker"+a),document.body.removeChild(i))}}}};this.disableTouch||(this.canvas.addEventListener("touchstart",(function(i,o){var s,r;switch(this.isMulti=!0,i.preventDefault(),t.visualizeTouches(i),this.focus(),null==o&&(o=this.parent.doc),o._scene.getNavigationInfo().getType()){case"examine":t.examineNavType=1;break;case"turntable":t.examineNavType=2;break;default:t.examineNavType=0}for(t.lastLayer=[],s=0;s<i.touches.length;s++)r=this.parent.mousePosition(i.touches[s]),t.lastLayer.push([i.touches[s].identifier,new x3dom.fields.SFVec2f(r.x,r.y)]);if(t.numTouches<1&&1==i.touches.length)t.numTouches=1,t.lastDrag=new x3dom.fields.SFVec2f(i.touches[0].screenX,i.touches[0].screenY);else if(t.numTouches<2&&i.touches.length>=2){t.numTouches=2;var n=new x3dom.fields.SFVec2f(i.touches[0].screenX,i.touches[0].screenY),a=new x3dom.fields.SFVec2f(i.touches[1].screenX,i.touches[1].screenY).subtract(n),d=a.multiply(.5).add(n),l=a.dot(a);t.lastMiddle=d,t.lastSquareDistance=l,t.lastAngle=t.calcAngle(a),t.lastPos=this.parent.mousePosition(i.touches[0])}if(o._scene.updateVolume(),1==t.examineNavType)for(s=0;s<i.touches.length;s++)r=this.parent.mousePosition(i.touches[s]),o.onPick(e.gl,r.x,r.y),o._viewarea.prepareEvents(r.x,r.y,0,"onmouseover"),o._viewarea.prepareEvents(r.x,r.y,1,"onmousedown"),o._viewarea._pickingInfo.lastClickObj=o._viewarea._pickingInfo.pickObj;else i.touches.length&&(r=this.parent.mousePosition(i.touches[0]),o.onMousePress(e.gl,r.x,r.y,1));o.needRender=!0}),!this.supportsPassiveEvents||{passive:!1}),this.canvas.addEventListener("touchmove",(function(i,o){i.preventDefault(),t.visualizeTouches(i),null==o&&(o=this.parent.doc);var s,r,n,a,d,l,h,f=null,u=null;if(1==t.examineNavType){if(1==i.touches.length){var c=new x3dom.fields.SFVec2f(i.touches[0].screenX,i.touches[0].screenY),_=c.subtract(t.lastDrag);t.lastDrag=c;var m=x3dom.fields.SFMatrix4f.rotationY(_.x/100),p=x3dom.fields.SFMatrix4f.rotationX(_.y/100);u=m.mult(p),o.onMoveView(e.gl,i,t,null,u),f=this.parent.mousePosition(i.touches[0]),o.onPick(e.gl,f.x,f.y),o._viewarea.prepareEvents(f.x,f.y,1,"onmousemove")}else if(i.touches.length>=2){s=new x3dom.fields.SFVec2f(i.touches[0].screenX,i.touches[0].screenY),n=(r=new x3dom.fields.SFVec2f(i.touches[1].screenX,i.touches[1].screenY).subtract(s)).multiply(.5).add(s),a=r.dot(r),d=n.subtract(t.lastMiddle),l=a-t.lastSquareDistance,h=new x3dom.fields.SFVec3f(d.x/screen.width,-d.y/screen.height,l/(screen.width*screen.height*.2));var x=t.calcAngle(r),g=t.lastAngle-x;t.lastAngle=x,u=x3dom.fields.SFMatrix4f.rotationZ(g),t.lastMiddle=n,t.lastSquareDistance=a,o.onMoveView(e.gl,i,t,h,u)}}else i.touches.length&&(2==t.examineNavType&&i.touches.length>=2?(s=new x3dom.fields.SFVec2f(i.touches[0].screenX,i.touches[0].screenY),l=((a=(r=new x3dom.fields.SFVec2f(i.touches[1].screenX,i.touches[1].screenY).subtract(s)).dot(r))-t.lastSquareDistance)/(.1*(screen.width+screen.height)),t.lastPos.y+=l,t.lastSquareDistance=a,o.onDrag(e.gl,t.lastPos.x,t.lastPos.y,2)):(f=this.parent.mousePosition(i.touches[0]),o.onDrag(e.gl,f.x,f.y,1)));o.needRender=!0}),!this.supportsPassiveEvents||{passive:!1}),this.canvas.addEventListener("touchend",(function(i,o){if(this.isMulti=!1,i.cancelable&&i.preventDefault(),t.visualizeTouches(i),null==o&&(o=this.parent.doc),o._viewarea._isMoving=!1,2==t.numTouches&&1==i.touches.length&&(t.lastDrag=new x3dom.fields.SFVec2f(i.touches[0].screenX,i.touches[0].screenY)),0==i.touches.length){for(var s=o._nodeBag.affectedPointingSensors,r=0;r<s.length;++r)s[r].pointerReleased();o._nodeBag.affectedPointingSensors=[]}var n=!1;if(i.touches.length<2&&(1==t.numTouches&&(n=!0),t.numTouches=i.touches.length),1==t.examineNavType){for(r=0;r<t.lastLayer.length;r++){var a=t.lastLayer[r][1];if(o.onPick(e.gl,a.x,a.y),"box"!==o._scene._vf.pickMode.toLowerCase())o._viewarea.prepareEvents(a.x,a.y,1,"onmouseup"),o._viewarea._pickingInfo.lastClickObj=o._viewarea._pickingInfo.pickObj,o._viewarea._pickingInfo.pickObj&&o._viewarea._pickingInfo.pickObj===o._viewarea._pickingInfo.lastClickObj&&o._viewarea.prepareEvents(a.x,a.y,1,"onclick");else{var d=o._viewarea.calcViewRay(a.x,a.y),l=o._scene.doIntersect(d),h=d.hitObject;l&&h&&(o._viewarea._pick.setValues(d.hitPoint),o._viewarea.checkEvents(h,a.x,a.y,1,"onclick"),x3dom.debug.logInfo("Hit '"+h._xmlNode.localName+"/ "+h._DEF+"' at pos "+o._viewarea._pick))}}if(n){var f=(new Date).getTime();t.firstTouchPoint.subtract(t.lastDrag).length()<18&&f-t.firstTouchTime<180&&o.onDoubleClick(e.gl,0,0),t.firstTouchTime=f,t.firstTouchPoint=t.lastDrag}}else t.lastLayer.length&&(a=t.lastLayer[0][1],o.onMouseRelease(e.gl,a.x,a.y,0,1));o.needRender=!0}),!0))}},x3dom.X3DCanvas.prototype._initContext=function(e){x3dom.debug.logInfo("Initializing X3DCanvas for ["+e.id+"]");var t=x3dom.gfx_webgl(e,this.x3dElem);return t?(parseFloat(x3dom.caps.VERSION.match(/\d+\.\d+/)[0])<1&&x3dom.debug.logError("WebGL version "+x3dom.caps.VERSION+" lacks important WebGL/GLSL features needed for shadows, special vertex attribute types, etc.!"),t):(x3dom.debug.logError("No 3D context found..."),this.x3dElem.removeChild(e),null)},x3dom.X3DCanvas.prototype.appendParam=function(e,t,i){var o=document.createElement("param");o.setAttribute("name",t),o.setAttribute("value",i),e.appendChild(o)},x3dom.X3DCanvas.prototype._createInitFailedDiv=function(e){var t=document.createElement("div");t.setAttribute("id","x3dom-create-init-failed"),t.style.width=e.getAttribute("width"),t.style.height=e.getAttribute("height"),t.style.backgroundColor="#C00",t.style.color="#FFF",t.style.fontSize="20px",t.style.fontWidth="bold",t.style.padding="10px 10px 10px 10px",t.style.display="inline-block",t.style.fontFamily="Helvetica",t.style.textAlign="center",t.appendChild(document.createTextNode("Your Browser does not support X3DOM")),t.appendChild(document.createElement("br")),t.appendChild(document.createTextNode("Read more about Browser support on:")),t.appendChild(document.createElement("br"));var i=document.createElement("a");i.setAttribute("href","http://www.x3dom.org/?page_id=9"),i.appendChild(document.createTextNode("X3DOM | Browser Support")),t.appendChild(i);var o=e.getAttribute("altImg")||null;o&&((new Image).src=o,t.style.backgroundImage="url("+o+")",t.style.backgroundRepeat="no-repeat",t.style.backgroundPosition="50% 50%");e.appendChild(t),x3dom.debug.logError("Your Browser does not support X3DOM!")},x3dom.X3DCanvas.prototype._createHTMLCanvas=function(e){x3dom.debug.logInfo("Creating canvas for (X)3D element...");var t=document.createElement("canvas");t.setAttribute("class","x3dom-canvas"),e.getAttribute("style")&&x3dom.debug.logInfo("Inline X3D styles detected");for(var i=["onmousedown","onmousemove","onmouseout","onmouseover","onmouseup","onclick","ondblclick","onkeydown","onkeypress","onkeyup","ontouchstart","ontouchmove","ontouchend","ontouchcancel","ontouchleave","ontouchenter","ondragstart","ondrop","ondragover"],o=0;o<i.length;o++){var s=i[o],r=e.getAttribute(s);r&&(x3dom.debug.logInfo(s+", "+r),t.setAttribute(s,r),e.removeAttribute(s))}var n=e.getAttribute("draggable");n&&(x3dom.debug.logInfo("draggable="+n),t.setAttribute("draggable",n)),e.__addEventListener||e.__removeEventListener||(e.__addEventListener=e.addEventListener,e.__removeEventListener=e.removeEventListener,e.addEventListener=function(e,o,s){var r,n=!1;for(r=0;r<i.length&&!n;r++)i[r]===e&&(n=!0);n?(x3dom.debug.logInfo("addEventListener for div.on"+e),t.addEventListener(e,o,s)):(x3dom.debug.logInfo("addEventListener for X3D.on"+e),this.__addEventListener(e,o,s))},e.removeEventListener=function(e,o,s){var r,n=!1;for(r=0;r<i.length&&!n;r++)i[r]===e&&(n=!0);n?(x3dom.debug.logInfo("removeEventListener for div.on"+e),t.removeEventListener(e,o,s)):(x3dom.debug.logInfo("removeEventListener for X3D.on"+e),this.__removeEventListener(e,o,s))}),e.hasAttribute("ondownloadsfinished")&&e.addEventListener("downloadsfinished",(function(){var t={target:e,type:"downloadsfinished"},i=e.getAttribute("ondownloadsfinished");new Function("event",i).call(e,t)}),!0),e.appendChild(t);var a,d,l=e.getAttribute("id");if(null!==l)t.id="x3dom-"+l+"-canvas";else{var h=(new Date).getTime();t.id="x3dom-"+h+"-canvas"}return e.style=e.style||{},null!==(a=e.getAttribute("width"))&&(a.indexOf("%")>=0&&x3dom.debug.logWarning("The width attribute is to be specified in pixels not in percent."),t.style.width=a,e.style.width=a,t.setAttribute("width",a)),null!==(d=e.getAttribute("height"))&&(d.indexOf("%")>=0&&x3dom.debug.logWarning("The height attribute is to be specified in pixels not in percent."),t.style.height=d,e.style.height=d,t.setAttribute("height",d)),t.setAttribute("tabindex","0"),t},x3dom.X3DCanvas.prototype._watchForResize=function(){if(!this.vrDisplay||!this.vrDisplay.isPresenting){var e=[parseInt(x3dom.getStyle(this.canvas,"width"))||0,parseInt(x3dom.getStyle(this.canvas,"height"))||0];this._current_dim[0]==e[0]&&this._current_dim[1]==e[1]||(this._current_dim=e,this.x3dElem.setAttribute("width",e[0]+"px"),this.x3dElem.setAttribute("height",e[1]+"px"))}},x3dom.X3DCanvas.prototype._createProgressDiv=function(){var e=document.createElement("div");e.setAttribute("class","x3dom-progress");var t=document.createElement("div");t.setAttribute("class","x3dom-progress-spinner"),e.appendChild(t);var i=document.createElement("div");return i.setAttribute("id","x3domProgessCount"),i.appendChild(document.createTextNode("Loading...")),e.appendChild(i),e.oncontextmenu=e.onmousedown=function(e){return e.preventDefault(),e.stopPropagation(),!1},e},x3dom.X3DCanvas.prototype._createVRDiv=function(){var e=document.createElement("div");return e.setAttribute("class","x3dom-vr"),e.onclick=function(){this.x3dElem.runtime.toggleVR()}.bind(this),e.oncontextmenu=function(e){return e.preventDefault(),e.stopPropagation(),!1},e},x3dom.X3DCanvas.prototype.mousePosition=function(e){var t=e.target.getBoundingClientRect(),i=Math.round(e.clientX-t.left)*this.devicePixelRatio,o=Math.round(e.clientY-t.top)*this.devicePixelRatio;return new x3dom.fields.SFVec2f(i,o)},x3dom.X3DCanvas.prototype.tick=function(e){this._elapsedTime=this._totalTime?e-this._totalTime:0,this._totalTime=e;var t=this.x3dElem.runtime,i=(new Date).getTime(),o=i-this.lastTimeFPSWasTaken;this.fps_t0;this.fps_t0=i,this.doc.advanceTime(i/1e3);var s,r=(new Date).getTime()-i;if(this.doc.hasAnimationStateChanged()&&(this.doc.isAnimating()?t.onAnimationStarted():t.onAnimationFinished()),this.doc.needRender&&(o>=1e3&&(t.fps=this.framesSinceLastTime/(o/1e3),t.addMeasurement("FPS",t.fps),this.framesSinceLastTime=0,this.lastTimeFPSWasTaken=i),this.framesSinceLastTime++,t.addMeasurement("ANIM",r),0==t.isReady&&(t.ready(),t.isReady=!0),t.enterFrame({total:this._totalTime,elapsed:this._elapsedTime}),this.vrDisplay&&this.vrDisplay.isPresenting?(this.vrFrameData||(this.vrFrameData=new VRFrameData),this.vrDisplay.getFrameData(this.vrFrameData)):this.doc.needRender=!1,this.doc.render(this.gl,this.vrFrameData,this.vrDisplay),this.doc._scene._vf.doPickPass||t.removeMeasurement("PICKING"),t.exitFrame({total:this._totalTime,elapsed:this._elapsedTime}),this.vrDisplay&&this.vrDisplay.isPresenting&&this.vrDisplay.submitFrame()),this.progressDiv)if(this.doc.downloadCount>0?t.addInfo("#LOADS:",this.doc.downloadCount):t.removeInfo("#LOADS:"),"false"!==this.doc.properties.getProperty("showProgress")){if(this.progressDiv){var n=Math.max(+this.doc.downloadCount,0);this.progressDiv.childNodes[1].textContent=""+n,this.doc.downloadCount>0?this.progressDiv.style.opacity="1":this.progressDiv.style.opacity="0"}}else this.progressDiv.style.opacity="0";this.doc.downloadCount<=0&&this.doc.previousDownloadCount>0&&(document.createEvent?((s=document.createEvent("Events")).initEvent("downloadsfinished",!0,!0),this.x3dElem.dispatchEvent(s)):document.createEventObject&&(s=document.createEventObject(),this.x3dElem.fireEvent("ondownloadsfinished",s)));this.doc.previousDownloadCount=this.doc.downloadCount},x3dom.X3DCanvas.prototype.load=function(e,t,i){this.doc=new x3dom.X3DDocument(this.canvas,this.gl,i);var o=this;this.doc.onload=function(){o.hasRuntime?function e(t){o.doc&&o.x3dElem.runtime&&(o._watchForResize(),o.tick(t),navigator.getVRDisplays&&null===o.vrDisplay?(o.vrDisplayPromise||(o.vrDisplayPromise=navigator.getVRDisplays()),o.vrDisplayPromise.then((function(t){t[0]?(o.vrDisplay=t[0],o.vrDisplay.requestAnimationFrame(e,o),o.vrDiv.style.display="block"):(o.vrDisplay=void 0,window.requestAnimFrame(e,o))})).catch((function(t){o.vrDisplay=void 0,window.requestAnimFrame(e,o)}))):navigator.getVRDisplays&&o.vrDisplay?o.vrDisplay.requestAnimationFrame(e,o):window.requestAnimFrame(e,o))}():o.tick()},this.x3dElem.render=function(){o.hasRuntime?o.doc.needRender=!0:o.doc.render(o.gl)},this.x3dElem.context=o.gl.ctx3d,this.doc.onerror=function(){alert("Failed to load X3D document")},this.doc.load(e,t)},x3dom.InputTypes={NAVIGATION:1,INTERACTION:2},x3dom.Viewarea=function(e,t){this._doc=e,this._scene=t,e._nodeBag.viewarea.push(this),this._pickingInfo={pickPos:new x3dom.fields.SFVec3f(0,0,0),pickNorm:new x3dom.fields.SFVec3f(0,0,1),pickObj:null,firstObj:null,lastObj:null,lastClickObj:null,shadowObjectId:-1},this._currentInputType=x3dom.InputTypes.NAVIGATION,this._rotMat=x3dom.fields.SFMatrix4f.identity(),this._transMat=x3dom.fields.SFMatrix4f.identity(),this._movement=new x3dom.fields.SFVec3f(0,0,0),this._needNavigationMatrixUpdate=!0,this._deltaT=0,this._flyMat=null,this._pitch=0,this._yaw=0,this._eyePos=new x3dom.fields.SFVec3f(0,0,0),this._width=400,this._height=300,this._dx=0,this._dy=0,this._lastX=-1,this._lastY=-1,this._pressX=-1,this._pressY=-1,this._lastButton=0,this._points=0,this._numRenderedNodes=0,this._pick=new x3dom.fields.SFVec3f(0,0,0),this._pickNorm=new x3dom.fields.SFVec3f(0,0,1),this._isAnimating=!1,this._isMoving=!1,this._lastTS=0,this._mixer=new x3dom.MatrixMixer,this._interpolator=new x3dom.FieldInterpolator,this._animationStateChanged=!1,this.vrFrameData=null,this.gamepads=null,this.vrLeftViewMatrix=new x3dom.fields.SFMatrix4f,this.vrRightViewMatrix=new x3dom.fields.SFMatrix4f,this.vrLeftProjMatrix=new x3dom.fields.SFMatrix4f,this.vrRightProjMatrix=new x3dom.fields.SFMatrix4f,this.vrControllerManager=new x3dom.VRControllerManager,this._inverseDevicePixelRatio=1/window.devicePixelRatio,this.arc=null},x3dom.Viewarea.prototype.setVRFrameData=function(e){this.vrFrameData=e,this.vrFrameData&&(this.vrLeftViewMatrix.setFromArray(this.vrFrameData.leftViewMatrix),this.vrRightViewMatrix.setFromArray(this.vrFrameData.rightViewMatrix))},x3dom.Viewarea.prototype.updateGamepads=function(e){this.vrControllerManager.update(this,e)},x3dom.Viewarea.prototype.tick=function(e){if(this._scene.getEnvironment()._vf.enableARC&&null==this.arc&&(this.arc=new x3dom.arc.AdaptiveRenderControl(this._scene)),this._mixer.isActive()){if(this._mixer._isVPtarget){var t=this._scene.getViewpoint();t.resetView();var i=t.getViewMatrix().mult(t.getCurrentTransform().inverse());this._mixer.setEndMatrix(i)}var o=this._mixer.mix(e);this._scene.getViewpoint().setView(o)}if(this._interpolator.isActive()){var s=this._interpolator.interpolate(e);this._scene.getViewpoint().setZoom(s)}var r=this.navigateTo(e),n=this._isAnimating;return this._lastTS=e,this._isAnimating=this._mixer.isMixing||this._interpolator.isInterpolating||r,this._isAnimating!=n?this._animationStateChanged=!0:this._animationStateChanged=!1,null!=this.arc&&this.arc.update(this.isMovingOrAnimating()?1:0,this._doc._x3dElem.runtime.getFPS()),this._isAnimating||n},x3dom.Viewarea.prototype.isMoving=function(){return this._isMoving},x3dom.Viewarea.prototype.isAnimating=function(){return this._isAnimating},x3dom.Viewarea.prototype.hasAnimationStateChanged=function(){return this._animationStateChanged},x3dom.Viewarea.prototype.isMovingOrAnimating=function(){return this._isMoving||this._isAnimating},x3dom.Viewarea.prototype.navigateTo=function(e){return this._scene.getNavigationInfo()._impl.navigateTo(this,e)},x3dom.Viewarea.prototype.moveFwd=function(){this._scene.getNavigationInfo()._impl.moveForward(this)},x3dom.Viewarea.prototype.moveBwd=function(){this._scene.getNavigationInfo()._impl.moveBackwards(this)},x3dom.Viewarea.prototype.strafeRight=function(){this._scene.getNavigationInfo()._impl.strafeRight(this)},x3dom.Viewarea.prototype.strafeLeft=function(){this._scene.getNavigationInfo()._impl.strafeLeft(this)},x3dom.Viewarea.prototype.animateTo=function(e,t,i){this._scene.getNavigationInfo()._impl.animateTo(this,e,t,i)},x3dom.Viewarea.prototype.orthoAnimateTo=function(e,t,i){this._scene.getNavigationInfo()._impl.orthoAnimateTo(this,e,t,i)},x3dom.Viewarea.prototype.zoom=function(e){this._scene.getNavigationInfo()._impl.zoom(this,e)},x3dom.Viewarea.prototype.getLights=function(){for(var e=[],t=0;t<this._doc._nodeBag.lights.length;t++)1==this._doc._nodeBag.lights[t]._vf.on&&e.push(this._doc._nodeBag.lights[t]);return e},x3dom.Viewarea.prototype.getLightsShadow=function(){for(var e=this._doc._nodeBag.lights,t=0;t<e.length;t++)if(e[t]._vf.shadowIntensity>0)return!0;return!1},x3dom.Viewarea.prototype.hasPhysicalEnvironmentLight=function(){for(var e=0;e<this._doc._nodeBag.lights.length;e++){var t=this._doc._nodeBag.lights[e];if(x3dom.isa(t,x3dom.nodeTypes.PhysicalEnvironmentLight)&&t._vf.on)return!0}return!1},x3dom.Viewarea.prototype.updateSpecialNavigation=function(e,t){var i=this._scene.getNavigationInfo();if("helicopter"==i.getType()&&!i._heliUpdated){var o=i.getTypeParams(),s=o[0],r=e.getViewMatrix().mult(t.inverse()).inverse();this._from=r.e3(),this._at=this._from.subtract(r.e2()),this._up=new x3dom.fields.SFVec3f(0,1,0),this._from.y=o[1],this._at.y=this._from.y;var n=r.e0(),a=x3dom.fields.Quaternion.axisAngle(n,s).toMatrix(),d=x3dom.fields.SFMatrix4f.translation(this._from);d=d.mult(a),a=x3dom.fields.SFMatrix4f.translation(this._from.negate()),d=d.mult(a),this._at=d.multMatrixPnt(this._at),this._flyMat=x3dom.fields.SFMatrix4f.lookAt(this._from,this._at,this._up),this._scene.getViewpoint().setView(this._flyMat.inverse()),i._heliUpdated=!0}},x3dom.Viewarea.prototype.getViewpointMatrix=function(){var e=this._scene.getViewpoint(),t=e.getCurrentTransform();return this.updateSpecialNavigation(e,t),e.getViewMatrix().mult(t.inverse())},x3dom.Viewarea.prototype.getViewMatrix=function(){return this.vrFrameData?this.vrLeftViewMatrix:this.getViewpointMatrix().mult(this._transMat).mult(this._rotMat)},x3dom.Viewarea.prototype.getViewMatrices=function(){if(this.vrFrameData)return[this.vrLeftViewMatrix,this.vrRightViewMatrix];var e=this.getViewpointMatrix().mult(this._transMat).mult(this._rotMat);return[e,e]},x3dom.Viewarea.prototype.getLightMatrix=function(e){var t,i=(e=e||this._doc._nodeBag.lights).length;if(i>0){var o=this._scene.getVolume();if(o.isValid()){var s=x3dom.fields.SFVec3f.MAX(),r=x3dom.fields.SFVec3f.MIN();o.getBounds(s,r);var n=[],a=this._scene.getViewpoint().getFieldOfView(),d=r.subtract(s),l=d.y/2/Math.tan(a/2)+d.z/2,h=d.x/2/Math.tan(a/2)+d.z/2;for(d=s.add(d.multiply(.5)),t=0;t<i;t++){var f=e[t];if(x3dom.isa(f,x3dom.nodeTypes.PointLight)){var u=f.getCurrentTransform().multMatrixPnt(f._vf.location);d=d.subtract(u).normalize()}else{var c=f.getCurrentTransform().multMatrixVec(f._vf.direction);c=c.normalize().negate(),d=d.add(c.multiply(1.2*(l>h?l:h)))}n.push(f.getViewMatrix(d))}return n}}return Array(i||1).fill(this.getViewMatrix())},x3dom.Viewarea.prototype.getWCtoLCMatrix=function(e){var t,i=this.getProjectionMatrix();return t=0===arguments.length?this.getLightMatrix()[0]:e,i.mult(t)},x3dom.Viewarea.prototype.getWCtoLCMatricesPointLight=function(e,t,i){var o=t._vf.zNear,s=t._vf.zFar,r=this.getLightProjectionMatrix(e,o,s,!1,i);r._00=1,r._11=1;var n,a=[];a[0]=r.mult(e);for(var d=1;d<=3;d++)n=x3dom.fields.SFMatrix4f.rotationY(d*Math.PI/2),a[d]=r.mult(n.mult(e));return n=x3dom.fields.SFMatrix4f.rotationX(Math.PI/2),a[4]=r.mult(n.mult(e)),n=x3dom.fields.SFMatrix4f.rotationX(3*Math.PI/2),a[5]=r.mult(n.mult(e)),a},x3dom.Viewarea.prototype.getWCtoLCMatricesCascaded=function(e,t,i){var o=Math.max(1,Math.min(t._vf.shadowCascades,6)),s=Math.max(0,Math.min(t._vf.shadowSplitFactor,1)),r=Math.max(0,Math.min(t._vf.shadowSplitOffset,1)),n=x3dom.isa(t,x3dom.nodeTypes.SpotLight),a=t._vf.zNear,d=t._vf.zFar,l=this.getLightProjectionMatrix(e,a,d,!0,i);n&&(l._00=1,l._11=1);var h=l.mult(e),f=[];if(1==o)return f[0]=h,f;for(var u=this.getShadowSplitDepths(o,s,r,!0,i),c=0;c<o;c++){var _=this.getLightFittingMatrix(h,u[c],u[c+1],i);f[c]=_.mult(h)}return f},x3dom.Viewarea.prototype.getLightProjectionMatrix=function(e,t,i,o,s){var r=x3dom.fields.SFMatrix4f.copy(s);if(!o||t>0||i>0){var n,a,d=e.inverse().e3(),l=x3dom.fields.SFVec3f.copy(this._scene._lastMin),h=x3dom.fields.SFVec3f.copy(this._scene._lastMax).subtract(l),f=h.length()/2,u=l.add(h.multiply(.5)),c=d.subtract(u).length();return f&&(n=c>f?.8*(c-f):1,a=1.2*(c+f)),t>0&&(n=t),i>0&&(a=i),r._22=-(a+n)/(a-n),r._23=-2*a*n/(a-n),r}return this.getLightCropMatrix(r.mult(e)).mult(r)},x3dom.Viewarea.prototype.getProjectionMatrix=function(){return this.vrFrameData?this.vrLeftProjMatrix.setFromArray(this.vrFrameData.leftProjectionMatrix):this._scene.getViewpoint().getProjectionMatrix(this._width/this._height)},x3dom.Viewarea.prototype.getProjectionMatrices=function(){if(this.vrFrameData)return[this.vrLeftProjMatrix.setFromArray(this.vrFrameData.leftProjectionMatrix),this.vrRightProjMatrix.setFromArray(this.vrFrameData.rightProjectionMatrix)];var e=this._scene.getViewpoint().getProjectionMatrix(this._width/this._height);return[e,e]},x3dom.Viewarea.prototype.getViewfrustum=function(e){var t=this._scene.getEnvironment();if(1==t._vf.frustumCulling){if(0==arguments.length){var i=this.getProjectionMatrix(),o=this.getViewMatrix();return new x3dom.fields.FrustumVolume(i.mult(o))}return new x3dom.fields.FrustumVolume(e)}return null},x3dom.Viewarea.prototype.getWCtoCCMatrix=function(){var e=this.getViewMatrix();return this.getProjectionMatrix().mult(e)},x3dom.Viewarea.prototype.getCCtoWCMatrix=function(){return this.getWCtoCCMatrix().inverse()},x3dom.Viewarea.prototype.calcViewRay=function(e,t,i){var o=i||this.getCCtoWCMatrix(),s=e/(this._width-1)*2-1,r=(this._height-1-t)/(this._height-1)*2-1,n=o.multFullMatrixPnt(new x3dom.fields.SFVec3f(s,r,-1)),a=o.multFullMatrixPnt(new x3dom.fields.SFVec3f(s,r,1)).subtract(n);return new x3dom.fields.Ray(n,a)},x3dom.Viewarea.prototype.showAll=function(e,t){void 0===e&&(e="negZ"),void 0===t&&(t=!1);var i=this._scene;i.updateVolume();var o,s=x3dom.fields.SFVec3f.copy(i._lastMin),r=x3dom.fields.SFVec3f.copy(i._lastMax),n="x",a="y",d="z",l=1,h=new x3dom.fields.SFVec3f(0,0,-1);switch(e){case"posX":l=-1;case"negX":d="x",n="y",a="z",o=new x3dom.fields.SFVec3f(l,0,0);break;case"posY":l=-1;case"negY":d="y",n="z",a="x",o=new x3dom.fields.SFVec3f(0,l,0);break;case"posZ":l=-1;case"negZ":default:o=new x3dom.fields.SFVec3f(0,0,-l)}var f=i.getViewpoint(),u=f.getFieldOfView(),c=x3dom.isa(f,x3dom.nodeTypes.OrthoViewpoint),_=r.subtract(s),m=_.multiply(.5),p=s.add(m);t&&f.setCenterOfRotation(p);var x=Math.min(this._width/this._height,1),g=_[d]/2,v=Math.tan(u/2),y=_[a]/2/v+g,T=_[n]/2/v+g;(_=s.add(_.multiply(.5)))[d]+=c?l*(y>T?y:T)*3.01:l*(y>T?y:T)*1.01,_[d]/=x;var b=x3dom.fields.Quaternion.rotateFromTo(h,o).toMatrix();b=b.mult(x3dom.fields.SFMatrix4f.translation(_.negate())),c?(this.orthoAnimateTo(y,Math.abs(f._fieldOfView[0])),this.animateTo(b,f)):this.animateTo(b,f)},x3dom.Viewarea.prototype.fit=function(e,t,i){var o=this._scene.getViewpoint(),s=this.getFitViewMatrix(e,t,o,i);x3dom.isa(o,x3dom.nodeTypes.OrthoViewpoint)?(this.orthoAnimateTo(dist/2.01,Math.abs(o._fieldOfView[0])),this.animateTo(s,o)):this.animateTo(s,o)},x3dom.Viewarea.prototype.getFitViewMatrix=function(e,t,i,o){void 0===o&&(o=!0);var s=t.subtract(e).multiply(.5),r=e.add(s),n=s.length(),a=i.getFieldOfView(),d=x3dom.fields.SFMatrix4f.copy(this.getViewMatrix()),l=new x3dom.fields.SFVec3f(d._00,d._01,d._02),h=new x3dom.fields.SFVec3f(d._10,d._11,d._12),f=new x3dom.fields.SFVec3f(d._20,d._21,d._22),u=Math.min(this._width/this._height,1),c=n/Math.tan(a/2)/u,_=r.add(f.multiply(c));return d._03=-l.dot(_),d._13=-h.dot(_),d._23=-f.dot(_),o&&i.setCenterOfRotation(r),d},x3dom.Viewarea.prototype.resetView=function(){this._scene.getNavigationInfo()._impl.resetView(this)},x3dom.Viewarea.prototype.resetNavHelpers=function(){this._rotMat=x3dom.fields.SFMatrix4f.identity(),this._transMat=x3dom.fields.SFMatrix4f.identity(),this._movement=new x3dom.fields.SFVec3f(0,0,0),this._needNavigationMatrixUpdate=!0},x3dom.Viewarea.prototype.uprightView=function(){var e=this.getViewMatrix().inverse(),t=e.e3(),i=t.subtract(e.e2()),o=new x3dom.fields.SFVec3f(0,1,0),s=e.e2().cross(o).normalize().cross(o).normalize();i=t.add(s),e=(e=x3dom.fields.SFMatrix4f.lookAt(t,i,o)).inverse(),this.animateTo(e,this._scene.getViewpoint())},x3dom.Viewarea.prototype.callEvtHandler=function(e,t,i){if(!e||!e._xmlNode)return null;try{var o=e._xmlNode[t];if("function"==typeof o)o.call(e._xmlNode,i);else{var s=e._xmlNode.getAttribute(t);new Function("event",s).call(e._xmlNode,i)}var r=e._listeners[i.type];if(r)for(var n=0;n<r.length;n++)r[n].call(e._xmlNode,i)}catch(e){x3dom.debug.logException(e)}return i.cancelBubble},x3dom.Viewarea.prototype.checkEvents=function(e,t,i,o,s){var r,n,a,d=this,l=!0,h=e&&e._xmlNode?e._xmlNode:{},f=this._doc._nodeBag.affectedPointingSensors,u={viewarea:d,target:h,type:s.substr(2,s.length-2),button:o,layerX:t*this._inverseDevicePixelRatio,layerY:i*this._inverseDevicePixelRatio,worldX:d._pick.x,worldY:d._pick.y,worldZ:d._pick.z,normalX:d._pickNorm.x,normalY:d._pickNorm.y,normalZ:d._pickNorm.z,hitPnt:d._pick.toGL(),hitObject:h,shadowObjectId:d._pickingInfo.shadowObjectId,cancelBubble:!1,stopPropagation:function(){this.cancelBubble=!0},preventDefault:function(){this.cancelBubble=!0}};try{var c=e;c&&c._xmlNode&&c._cf.geometry&&!c._xmlNode[s]&&!c._xmlNode.hasAttribute(s)&&!c._listeners[u.type]&&(c=c._cf.geometry.node),c&&!0===d.callEvtHandler(c,s,u)&&(l=!1)}catch(e){x3dom.debug.logException(e)}var _=function(e){e._parentNodes.forEach((function(e){if(e._xmlNode&&(e._xmlNode[s]||e._xmlNode.hasAttribute(s)||e._listeners[u.type])&&!0===d.callEvtHandler(e,s,u)&&(l=!1),0==o&&0==f.length&&("onmousemove"==s||"onmouseover"==s||"onmouseout"==s))for(a=e._childNodes.length,n=0;n<a;++n)r=e._childNodes[n],x3dom.isa(r,x3dom.nodeTypes.X3DPointingDeviceSensorNode)&&r._vf.enabled&&-1==f.indexOf(r)&&f.push(r);x3dom.isa(e,x3dom.nodeTypes.Anchor)&&"onclick"===s?(e.handleTouch(),l=!1):l&&_(e)}))};return l&&e&&_(e),l},x3dom.Viewarea.prototype._notifyAffectedPointingSensors=function(e){var t,i={mousedown:"pointerPressedOverSibling",mousemove:"pointerMoved",mouseover:"pointerMovedOver",mouseout:"pointerMovedOut"}[e.type],o=this._doc._nodeBag.affectedPointingSensors,s=o.length;if(s>0&&void 0!==i)for(t=0;t<s;t++)o[t][i](e)},x3dom.Viewarea.prototype.initMouseState=function(){this._deltaT=0,this._dx=0,this._dy=0,this._lastX=-1,this._lastY=-1,this._pressX=-1,this._pressY=-1,this._lastButton=0,this._isMoving=!1,this._needNavigationMatrixUpdate=!0},x3dom.Viewarea.prototype.onMousePress=function(e,t,i){(this._needNavigationMatrixUpdate=!0,this.prepareEvents(e,t,0,"onmouseover"),this.prepareEvents(e,t,i,"onmousedown"),this._pickingInfo.lastClickObj=this._pickingInfo.pickObj,this._pickingInfo.firstObj=this._pickingInfo.pickObj,this._dx=0,this._dy=0,this._lastX=e,this._lastY=t,this._pressX=e,this._pressY=t,this._lastButton=i,this._isMoving=!1,this._currentInputType==x3dom.InputTypes.NAVIGATION)&&this._scene.getNavigationInfo()._impl.onMousePress(this,e,t,i)},x3dom.Viewarea.prototype.onMouseRelease=function(e,t,i,o){var s,r,n=this._doc._nodeBag.affectedPointingSensors;for(s=0;s<n.length;++s)n[s].pointerReleased();this._doc._nodeBag.affectedPointingSensors=[];var a=this._scene.getNavigationInfo(),d=a.getType(),l=this._scene._vf.pickMode.toLowerCase();if("box"!==l){if(this.prepareEvents(e,t,o,"onmouseup"),this._pickingInfo.pickObj&&this._pickingInfo.pickObj===this._pickingInfo.lastClickObj)this.prepareEvents(e,t,o,"onclick");else if(!this._pickingInfo.pickObj&&!this._pickingInfo.lastClickObj&&!this._pickingInfo.firstObj){var h="backgroundClicked";try{if(this._scene._xmlNode&&(this._scene._xmlNode["on"+h]||this._scene._xmlNode.hasAttribute("on"+h)||this._scene._listeners[h])){var f={target:this._scene._xmlNode,type:h,button:o,layerX:e*this._inverseDevicePixelRatio,layerY:t*this._inverseDevicePixelRatio,cancelBubble:!1,stopPropagation:function(){this.cancelBubble=!0},preventDefault:function(){this.cancelBubble=!0}};this._scene.callEvtHandler("on"+h,f)}}catch(e){x3dom.debug.logException("backgroundClicked: "+e)}}}else{var u=(new Date).getTime(),c=this.calcViewRay(e,t),_=this._scene.doIntersect(c),m=c.hitObject;_&&m&&(this._pick.setValues(c.hitPoint),this.checkEvents(m,e,t,i,"onclick"),x3dom.debug.logInfo("Hit '"+m._xmlNode.localName+"/ "+m._DEF+"' at dist="+c.dist.toFixed(4)),"color"===l?x3dom.debug.logInfo("Ray hit color "+this._pick):"idbufid"===l||"texcoord"===l?x3dom.debug.logInfo("Ray hit data "+this._pick):x3dom.debug.logInfo("Ray hit at position "+this._pick.x.toFixed(4)+" "+this._pick.y.toFixed(4)+" "+this._pick.z.toFixed(4)));var p=(new Date).getTime()-u;if(x3dom.debug.logInfo("Picking time (box): "+p+"ms"),!_){var x=(r=this.getViewMatrix().e2().negate()).dot(c.pos.negate())/r.dot(c.dir);this._pick=c.pos.add(c.dir.multiply(x))}}if(this._pickingInfo.firstObj=null,this._currentInputType==x3dom.InputTypes.NAVIGATION&&(this._pickingInfo.pickObj||this._pickingInfo.shadowObjectId>=0)&&"lookat"===d&&this._pressX===e&&this._pressY===t){var g=2&this._lastButton?-1:1,v=this._pickingInfo.pickPos.subtract(this._from).length()/3,y=new x3dom.fields.SFMatrix4f;y.setValues(this.getViewMatrix());var T=(y=y.inverse()).e3(),b=(T.subtract(y.e2()),y.e1()),S=(r=this._pickingInfo.pickPos.subtract(T)).length();r=r.normalize();var F=T.addScaled(r,S),E=r.cross(b).normalize();r=E.cross(b).normalize(),g<0&&(v=2*(.5+S+v));var M=F.addScaled(r,v);y=(y=x3dom.fields.SFMatrix4f.lookAt(M,F,b)).inverse(),v=M.subtract(T).length();var C=Math.max(.5,Math.log((1+v)/a._vf.speed));this.animateTo(y,this._scene.getViewpoint(),C)}this._dx=0,this._dy=0,this._lastX=e,this._lastY=t,this._lastButton=i,this._isMoving=!1},x3dom.Viewarea.prototype.onMouseOver=function(e,t,i){this._dx=0,this._dy=0,this._lastButton=0,this._isMoving=!1,this._lastX=e,this._lastY=t,this._deltaT=0},x3dom.Viewarea.prototype.onMouseOut=function(e,t,i){var o;this._dx=0,this._dy=0,this._lastButton=0,this._isMoving=!1,this._lastX=e,this._lastY=t,this._deltaT=0;var s=this._doc._nodeBag.affectedPointingSensors;for(o=0;o<s.length;++o)s[o].pointerReleased();this._doc._nodeBag.affectedPointingSensors=[]},x3dom.Viewarea.prototype.onDoubleClick=function(e,t){this._doc._x3dElem.hasAttribute("disableDoubleClick")&&"true"===this._doc._x3dElem.getAttribute("disableDoubleClick")||this._scene.getNavigationInfo()._impl.onDoubleClick(this,e,t)},x3dom.Viewarea.prototype.handleMoveEvt=function(e,t,i){if(0==i&&(this._doc._nodeBag.affectedPointingSensors=[]),this.prepareEvents(e,t,i,"onmousemove"),this._pickingInfo.pickObj!==this._pickingInfo.lastObj){if(this._pickingInfo.lastObj){var o=this._pickingInfo.pickObj;this._pickingInfo.pickObj=this._pickingInfo.lastObj;var s=this._doc._nodeBag.affectedPointingSensors;this._doc._nodeBag.affectedPointingSensors=[],this.prepareEvents(e,t,i,"onmouseout"),this._doc._nodeBag.affectedPointingSensors=s,this._pickingInfo.pickObj=o}this._pickingInfo.pickObj&&this.prepareEvents(e,t,i,"onmouseover"),this._pickingInfo.lastObj=this._pickingInfo.pickObj}},x3dom.Viewarea.prototype.onMove=function(e,t,i){this.handleMoveEvt(e,t,i),(this._lastX<0||this._lastY<0)&&(this._lastX=e,this._lastY=t),this._dx=e-this._lastX,this._dy=t-this._lastY,this._lastX=e,this._lastY=t},x3dom.Viewarea.prototype.onMoveView=function(e,t){if(this._currentInputType==x3dom.InputTypes.NAVIGATION){var i=this._scene.getNavigationInfo(),o=this._scene.getViewpoint();if("examine"===i.getType()){if(e){var s=this._scene._lastMax.subtract(this._scene._lastMin).length();s=(s<x3dom.fields.Eps?1:s)*i._vf.speed,e=e.multiply(s),this._movement=this._movement.add(e),this._transMat=o.getViewMatrix().inverse().mult(x3dom.fields.SFMatrix4f.translation(this._movement)).mult(o.getViewMatrix())}if(t){var r=o.getCenterOfRotation(),n=this.getViewMatrix();n.setTranslate(new x3dom.fields.SFVec3f(0,0,0)),this._rotMat=this._rotMat.mult(x3dom.fields.SFMatrix4f.translation(r)).mult(n.inverse()).mult(t).mult(n).mult(x3dom.fields.SFMatrix4f.translation(r.negate()))}this._isMoving=!0}}},x3dom.Viewarea.prototype.onDrag=function(e,t,i){this.handleMoveEvt(e,t,i),this._currentInputType==x3dom.InputTypes.NAVIGATION&&this._scene.getNavigationInfo()._impl.onDrag(this,e,t,i)},x3dom.Viewarea.prototype.prepareEvents=function(e,t,i,o){var s=this._doc._nodeBag.affectedPointingSensors,r=this._scene._vf.pickMode.toLowerCase(),n=null;(0==r.indexOf("idbuf")||"color"==r||"texcoord"==r)&&(n=this._pickingInfo.pickObj)&&(this._pick.setValues(this._pickingInfo.pickPos),this._pickNorm.setValues(this._pickingInfo.pickNorm),this.checkEvents(n,e,t,i,o),"onclick"===o&&(n._xmlNode&&x3dom.debug.logInfo('Hit "'+n._xmlNode.localName+"/ "+n._DEF+'"'),"color"===r?x3dom.debug.logInfo("Ray hit color "+this._pick):"idbufid"===r||"texcoord"===r?x3dom.debug.logInfo("Ray hit data "+this._pick):x3dom.debug.logInfo("Ray hit at position "+this._pick.x.toFixed(4)+" "+this._pick.y.toFixed(4)+" "+this._pick.z.toFixed(4))));var a={viewarea:this,target:{},type:o.substr(2,o.length-2),button:i,layerX:e,layerY:t,worldX:this._pick.x,worldY:this._pick.y,worldZ:this._pick.z,normalX:this._pickNorm.x,normalY:this._pickNorm.y,normalZ:this._pickNorm.z,hitPnt:this._pick.toGL(),hitObject:n&&n._xmlNode?n._xmlNode:null,shadowObjectId:this._pickingInfo.shadowObjectId,cancelBubble:!1,stopPropagation:function(){this.cancelBubble=!0},preventDefault:function(){this.cancelBubble=!0}};this._notifyAffectedPointingSensors(a),s.length>0?this._currentInputType=x3dom.InputTypes.INTERACTION:this._currentInputType=x3dom.InputTypes.NAVIGATION},x3dom.Viewarea.prototype.getRenderMode=function(){return this._points},x3dom.Viewarea.prototype.getShadowedLights=function(){for(var e=[],t=0,i=this.getLights(),o=0;o<i.length;o++)i[o]._vf.shadowIntensity>0&&(e[t]=i[o],t++);return e},x3dom.Viewarea.prototype.getShadowSplitDepths=function(e,t,i,o,s){var r,n=[],a=this._scene.getViewpoint(),d=a.getNear(),l=a.getFar();n[0]=d,d+=i*(l-d)/10;for(var h=1;h<e;h++)r=d*Math.pow(l/d,h/e),n[h]=t*r+(1-t)*(d+h/(e*(d-l)));if(n[e]=l,!o)return n;for(var f=[],u=0;u<=e;u++)f[u]=s.multFullMatrixPnt(new x3dom.fields.SFVec3f(0,0,-n[u])).z;return f},x3dom.Viewarea.prototype.getLightCropMatrix=function(e){var t,i=x3dom.fields.SFVec3f.copy(this._scene._lastMin),o=x3dom.fields.SFVec3f.copy(this._scene._lastMax),s=[];for(s[0]=new x3dom.fields.SFVec3f(i.x,i.y,i.z),s[1]=new x3dom.fields.SFVec3f(i.x,i.y,o.z),s[2]=new x3dom.fields.SFVec3f(i.x,o.y,i.z),s[3]=new x3dom.fields.SFVec3f(i.x,o.y,o.z),s[4]=new x3dom.fields.SFVec3f(o.x,i.y,i.z),s[5]=new x3dom.fields.SFVec3f(o.x,i.y,o.z),s[6]=new x3dom.fields.SFVec3f(o.x,o.y,i.z),s[7]=new x3dom.fields.SFVec3f(o.x,o.y,o.z),t=0;t<8;t++)s[t]=e.multFullMatrixPnt(s[t]);var r=x3dom.fields.SFVec3f.copy(s[0]),n=x3dom.fields.SFVec3f.copy(s[0]);for(t=1;t<8;t++)r.z=Math.min(s[t].z,r.z),n.z=Math.max(s[t].z,n.z);var a=2/(n.z-r.z),d=-a*(n.z+r.z)/2,l=x3dom.fields.SFMatrix4f.identity();return l._22=a,l._23=d,l},x3dom.Viewarea.prototype.getLightFittingMatrix=function(e,t,i,o){var s,r=this.getViewMatrix(),n=o.mult(r).inverse(),a=[];for(a[0]=new x3dom.fields.SFVec3f(-1,-1,i),a[1]=new x3dom.fields.SFVec3f(-1,-1,t),a[2]=new x3dom.fields.SFVec3f(-1,1,i),a[3]=new x3dom.fields.SFVec3f(-1,1,t),a[4]=new x3dom.fields.SFVec3f(1,-1,i),a[5]=new x3dom.fields.SFVec3f(1,-1,t),a[6]=new x3dom.fields.SFVec3f(1,1,i),a[7]=new x3dom.fields.SFVec3f(1,1,t),s=0;s<8;s++)a[s]=n.multFullMatrixPnt(a[s]),a[s]=e.multFullMatrixPnt(a[s]);var d=x3dom.fields.SFVec3f.copy(a[0]),l=x3dom.fields.SFVec3f.copy(a[0]);for(s=1;s<8;s++)d.x=Math.min(a[s].x,d.x),d.y=Math.min(a[s].y,d.y),d.z=Math.min(a[s].z,d.z),l.x=Math.max(a[s].x,l.x),l.y=Math.max(a[s].y,l.y),l.z=Math.max(a[s].z,l.z);var h=function(e,t){var i=e.x,o=e.y,s=e.z,r=t.x,n=t.y,a=t.z;i>1||r<-1?(i=-1,r=1):(i=Math.max(i,-1),r=Math.min(r,1)),o>1||n<-1?(o=-1,n=1):(o=Math.max(o,-1),n=Math.min(n,1)),s>1||a<-1?(s=-1,a=1):(s=Math.max(s,-1),a=Math.min(a,1));var d=new x3dom.fields.SFVec3f(i,o,s),l=new x3dom.fields.SFVec3f(r,n,a);return new x3dom.fields.BoxVolume(d,l)}(d,l),f=2/(h.max.x-h.min.x),u=2/(h.max.y-h.min.y),c=-f*(h.max.x+h.min.x)/2,_=-u*(h.max.y+h.min.y)/2,m=x3dom.fields.SFMatrix4f.identity();return m._00=f,m._11=u,m._03=c,m._13=_,m},x3dom.fields={};var VecMath=x3dom.fields;function _colorParse(e){var t=0,i=0,o=0,s=1,r={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dodgerblue:"#1e90ff",feldspar:"#d19275",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslateblue:"#8470ff",lightslategray:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",violetred:"#d02090",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"},n=/^rgb\((\d{1,3}),\s{0,1}(\d{1,3}),\s{0,1}(\d{1,3})\)$/.exec(e);null!==n&&(t=n[1]/255,i=n[2]/255,o=n[3]/255);var a=/^rgba\((\d{1,3}),\s{0,1}(\d{1,3}),\s{0,1}(\d{1,3}),(0+\.?\d*|1\.?0*)\)$/.exec(e);if(null!==a&&(t=a[1]/255,i=a[2]/255,o=a[3]/255,s=+a[4]),r[e]&&(e=r[e]),e.substr&&"#"===e.substr(0,1)){var d=e.substr(1),l=d.length;8===l?(t=parseInt("0x"+d.substr(0,2),16)/255,i=parseInt("0x"+d.substr(2,2),16)/255,o=parseInt("0x"+d.substr(4,2),16)/255,s=parseInt("0x"+d.substr(6,2),16)/255):6===l?(t=parseInt("0x"+d.substr(0,2),16)/255,i=parseInt("0x"+d.substr(2,2),16)/255,o=parseInt("0x"+d.substr(4,2),16)/255):4===l?(t=parseInt("0x"+d.substr(0,1),16)/15,i=parseInt("0x"+d.substr(1,1),16)/15,o=parseInt("0x"+d.substr(2,1),16)/15,s=parseInt("0x"+d.substr(3,1),16)/15):3===l&&(t=parseInt("0x"+d.substr(0,1),16)/15,i=parseInt("0x"+d.substr(1,1),16)/15,o=parseInt("0x"+d.substr(2,1),16)/15)}return{r:t,g:i,b:o,a:s}}function startDashVideo(e,t){var i,o,s,r=function(){var e={};window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,(function(t,i,o){e[i]=o}));return e},n=e;r&&r.hasOwnProperty("url")&&(n=r.url),i=document.querySelector(t),o=new Dash.di.DashContext,(s=new MediaPlayer(o)).startup(),s.attachView(i),s.setAutoPlay(!1),s.attachSource(n)}function setNamespace(e,t,i){t instanceof Element&&void 0!==t.__setAttribute&&(t.hasAttribute("id")?t.__setAttribute("id",e.toString().replace(" ","")+"__"+t.getAttribute("id")):t.hasAttribute("DEF")&&i&&(t.__setAttribute("id",e.toString().replace(" ","")+"__"+t.getAttribute("DEF")),t.id||(t.id=t.__getAttribute("id")))),t.hasChildNodes()&&t.childNodes.forEach((function(t){setNamespace(e,t,i)}))}x3dom.fields.Eps=1e-6,x3dom.fields.SFMatrix4f=function(e,t,i,o,s,r,n,a,d,l,h,f,u,c,_,m){0===arguments.length?(this._00=1,this._01=0,this._02=0,this._03=0,this._10=0,this._11=1,this._12=0,this._13=0,this._20=0,this._21=0,this._22=1,this._23=0,this._30=0,this._31=0,this._32=0,this._33=1):(this._00=e,this._01=t,this._02=i,this._03=o,this._10=s,this._11=r,this._12=n,this._13=a,this._20=d,this._21=l,this._22=h,this._23=f,this._30=u,this._31=c,this._32=_,this._33=m)},x3dom.fields.SFMatrix4f.prototype.e0=function(){return new x3dom.fields.SFVec3f(this._00,this._10,this._20).normalize()},x3dom.fields.SFMatrix4f.prototype.e1=function(){return new x3dom.fields.SFVec3f(this._01,this._11,this._21).normalize()},x3dom.fields.SFMatrix4f.prototype.e2=function(){return new x3dom.fields.SFVec3f(this._02,this._12,this._22).normalize()},x3dom.fields.SFMatrix4f.prototype.e3=function(){return new x3dom.fields.SFVec3f(this._03,this._13,this._23)},x3dom.fields.SFMatrix4f.copy=function(e){return new x3dom.fields.SFMatrix4f(e._00,e._01,e._02,e._03,e._10,e._11,e._12,e._13,e._20,e._21,e._22,e._23,e._30,e._31,e._32,e._33)},x3dom.fields.SFMatrix4f.prototype.copy=function(){return x3dom.fields.SFMatrix4f.copy(this)},x3dom.fields.SFMatrix4f.identity=function(){return new x3dom.fields.SFMatrix4f(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)},x3dom.fields.SFMatrix4f.zeroMatrix=function(){return new x3dom.fields.SFMatrix4f(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)},x3dom.fields.SFMatrix4f.translation=function(e){return new x3dom.fields.SFMatrix4f(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1)},x3dom.fields.SFMatrix4f.rotationX=function(e){var t=Math.cos(e),i=Math.sin(e);return new x3dom.fields.SFMatrix4f(1,0,0,0,0,t,-i,0,0,i,t,0,0,0,0,1)},x3dom.fields.SFMatrix4f.rotationY=function(e){var t=Math.cos(e),i=Math.sin(e);return new x3dom.fields.SFMatrix4f(t,0,i,0,0,1,0,0,-i,0,t,0,0,0,0,1)},x3dom.fields.SFMatrix4f.rotationZ=function(e){var t=Math.cos(e),i=Math.sin(e);return new x3dom.fields.SFMatrix4f(t,-i,0,0,i,t,0,0,0,0,1,0,0,0,0,1)},x3dom.fields.SFMatrix4f.scale=function(e){return new x3dom.fields.SFMatrix4f(e.x,0,0,0,0,e.y,0,0,0,0,e.z,0,0,0,0,1)},x3dom.fields.SFMatrix4f.lookAt=function(e,t,i){var o=e.subtract(t).normalize(),s=i.normalize().cross(o).normalize();if(s.dot(s)<x3dom.fields.Eps)return x3dom.debug.logWarning("View matrix is linearly dependent."),x3dom.fields.SFMatrix4f.translation(e);var r=o.cross(s).normalize(),n=x3dom.fields.SFMatrix4f.identity();return n.setValue(s,r,o,e),n},x3dom.fields.SFMatrix4f.perspectiveFrustum=function(e,t,i,o,s,r){return new x3dom.fields.SFMatrix4f(2*s/(t-e),0,(t+e)/(t-e),0,0,2*s/(o-i),(o+i)/(o-i),0,0,0,-(r+s)/(r-s),-2*r*s/(r-s),0,0,-1,0)},x3dom.fields.SFMatrix4f.perspective=function(e,t,i,o){var s=1/Math.tan(e/2);return new x3dom.fields.SFMatrix4f(s/t,0,0,0,0,s,0,0,0,0,(i+o)/(i-o),2*i*o/(i-o),0,0,-1,0)},x3dom.fields.SFMatrix4f.ortho=function(e,t,i,o,s,r,n){var a=(t-e)/2,d=(o-i)/2,l=r-s;return void 0===n&&(n=1),n<a/d?d=a/n:a=d*n,e=-a,t=a,i=-d,o=d,a*=2,d*=2,new x3dom.fields.SFMatrix4f(2/a,0,0,-(t+e)/a,0,2/d,0,-(o+i)/d,0,0,-2/l,-(r+s)/l,0,0,0,1)},x3dom.fields.SFMatrix4f.prototype.setTranslate=function(e){this._03=e.x,this._13=e.y,this._23=e.z},x3dom.fields.SFMatrix4f.prototype.setScale=function(e){this._00=e.x,this._11=e.y,this._22=e.z},x3dom.fields.SFMatrix4f.prototype.setRotate=function(e){var t=e.x*e.x,i=e.x*e.y,o=e.x*e.z,s=e.y*e.y,r=e.y*e.z,n=e.z*e.z,a=e.w*e.x,d=e.w*e.y,l=e.w*e.z;this._00=1-2*(s+n),this._01=2*(i-l),this._02=2*(o+d),this._10=2*(i+l),this._11=1-2*(t+n),this._12=2*(r-a),this._20=2*(o-d),this._21=2*(r+a),this._22=1-2*(t+s)},x3dom.fields.SFMatrix4f.parseRotation=function(e){var t=/^([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)$/.exec(e),i=+t[1],o=+t[2],s=+t[3],r=+t[4],n=Math.sqrt(i*i+o*o+s*s);0===n?(i=1,o=s=0):(i/=n,o/=n,s/=n);var a=Math.cos(r),d=Math.sin(r),l=1-a;return new x3dom.fields.SFMatrix4f(l*i*i+a,l*i*o+d*s,l*i*s-d*o,0,l*i*o-d*s,l*o*o+a,l*o*s+d*i,0,l*i*s+d*o,l*o*s-d*i,l*s*s+a,0,0,0,0,1).transpose()},x3dom.fields.SFMatrix4f.parse=function(e){var t=!1;/matrix.*\((.+)\)/.exec(e)&&(e=RegExp.$1,t=!0);var i=e.split(/[,\s]+/).map((function(e){return+e}));return i.length>=16?t?new x3dom.fields.SFMatrix4f(i[0],i[4],i[8],i[12],i[1],i[5],i[9],i[13],i[2],i[6],i[10],i[14],i[3],i[7],i[11],i[15]):new x3dom.fields.SFMatrix4f(i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8],i[9],i[10],i[11],i[12],i[13],i[14],i[15]):6===i.length?new x3dom.fields.SFMatrix4f(i[0],i[1],0,i[4],i[2],i[3],0,i[5],0,0,1,0,0,0,0,1):(x3dom.debug.logWarning("SFMatrix4f - can't parse string: "+e),x3dom.fields.SFMatrix4f.identity())},x3dom.fields.SFMatrix4f.prototype.mult=function(e){return new x3dom.fields.SFMatrix4f(this._00*e._00+this._01*e._10+this._02*e._20+this._03*e._30,this._00*e._01+this._01*e._11+this._02*e._21+this._03*e._31,this._00*e._02+this._01*e._12+this._02*e._22+this._03*e._32,this._00*e._03+this._01*e._13+this._02*e._23+this._03*e._33,this._10*e._00+this._11*e._10+this._12*e._20+this._13*e._30,this._10*e._01+this._11*e._11+this._12*e._21+this._13*e._31,this._10*e._02+this._11*e._12+this._12*e._22+this._13*e._32,this._10*e._03+this._11*e._13+this._12*e._23+this._13*e._33,this._20*e._00+this._21*e._10+this._22*e._20+this._23*e._30,this._20*e._01+this._21*e._11+this._22*e._21+this._23*e._31,this._20*e._02+this._21*e._12+this._22*e._22+this._23*e._32,this._20*e._03+this._21*e._13+this._22*e._23+this._23*e._33,this._30*e._00+this._31*e._10+this._32*e._20+this._33*e._30,this._30*e._01+this._31*e._11+this._32*e._21+this._33*e._31,this._30*e._02+this._31*e._12+this._32*e._22+this._33*e._32,this._30*e._03+this._31*e._13+this._32*e._23+this._33*e._33)},x3dom.fields.SFMatrix4f.prototype.multMatrixPnt=function(e){return new x3dom.fields.SFVec3f(this._00*e.x+this._01*e.y+this._02*e.z+this._03,this._10*e.x+this._11*e.y+this._12*e.z+this._13,this._20*e.x+this._21*e.y+this._22*e.z+this._23)},x3dom.fields.SFMatrix4f.prototype.multMatrixVec=function(e){return new x3dom.fields.SFVec3f(this._00*e.x+this._01*e.y+this._02*e.z,this._10*e.x+this._11*e.y+this._12*e.z,this._20*e.x+this._21*e.y+this._22*e.z)},x3dom.fields.SFMatrix4f.prototype.multFullMatrixPnt=function(e){var t=this._30*e.x+this._31*e.y+this._32*e.z+this._33;return t&&(t=1/t),new x3dom.fields.SFVec3f((this._00*e.x+this._01*e.y+this._02*e.z+this._03)*t,(this._10*e.x+this._11*e.y+this._12*e.z+this._13)*t,(this._20*e.x+this._21*e.y+this._22*e.z+this._23)*t)},x3dom.fields.SFMatrix4f.prototype.multMatrixPlane=function(e){var t=new x3dom.fields.SFVec3f(e.x,e.y,e.z),i=t.multiply(-e.w);i=this.multMatrixPnt(i);var o=-(t=this.inverse().transpose().multMatrixVec(t)).dot(i);return new x3dom.fields.SFVec4f(t.x,t.y,t.z,o)},x3dom.fields.SFMatrix4f.prototype.transpose=function(){return new x3dom.fields.SFMatrix4f(this._00,this._10,this._20,this._30,this._01,this._11,this._21,this._31,this._02,this._12,this._22,this._32,this._03,this._13,this._23,this._33)},x3dom.fields.SFMatrix4f.prototype.negate=function(){return new x3dom.fields.SFMatrix4f(-this._00,-this._01,-this._02,-this._03,-this._10,-this._11,-this._12,-this._13,-this._20,-this._21,-this._22,-this._23,-this._30,-this._31,-this._32,-this._33)},x3dom.fields.SFMatrix4f.prototype.multiply=function(e){return new x3dom.fields.SFMatrix4f(e*this._00,e*this._01,e*this._02,e*this._03,e*this._10,e*this._11,e*this._12,e*this._13,e*this._20,e*this._21,e*this._22,e*this._23,e*this._30,e*this._31,e*this._32,e*this._33)},x3dom.fields.SFMatrix4f.prototype.add=function(e){return new x3dom.fields.SFMatrix4f(this._00+e._00,this._01+e._01,this._02+e._02,this._03+e._03,this._10+e._10,this._11+e._11,this._12+e._12,this._13+e._13,this._20+e._20,this._21+e._21,this._22+e._22,this._23+e._23,this._30+e._30,this._31+e._31,this._32+e._32,this._33+e._33)},x3dom.fields.SFMatrix4f.prototype.addScaled=function(e,t){return new x3dom.fields.SFMatrix4f(this._00+t*e._00,this._01+t*e._01,this._02+t*e._02,this._03+t*e._03,this._10+t*e._10,this._11+t*e._11,this._12+t*e._12,this._13+t*e._13,this._20+t*e._20,this._21+t*e._21,this._22+t*e._22,this._23+t*e._23,this._30+t*e._30,this._31+t*e._31,this._32+t*e._32,this._33+t*e._33)},x3dom.fields.SFMatrix4f.prototype.setValues=function(e){this._00=e._00,this._01=e._01,this._02=e._02,this._03=e._03,this._10=e._10,this._11=e._11,this._12=e._12,this._13=e._13,this._20=e._20,this._21=e._21,this._22=e._22,this._23=e._23,this._30=e._30,this._31=e._31,this._32=e._32,this._33=e._33},x3dom.fields.SFMatrix4f.prototype.setValue=function(e,t,i,o){this._00=e.x,this._01=t.x,this._02=i.x,this._10=e.y,this._11=t.y,this._12=i.y,this._20=e.z,this._21=t.z,this._22=i.z,this._30=0,this._31=0,this._32=0,arguments.length>3&&(this._03=o.x,this._13=o.y,this._23=o.z,this._33=1)},x3dom.fields.SFMatrix4f.prototype.setFromArray=function(e){return this._00=e[0],this._01=e[4],this._02=e[8],this._03=e[12],this._10=e[1],this._11=e[5],this._12=e[9],this._13=e[13],this._20=e[2],this._21=e[6],this._22=e[10],this._23=e[14],this._30=e[3],this._31=e[7],this._32=e[11],this._33=e[15],this},x3dom.fields.SFMatrix4f.fromArray=function(e){var t=new x3dom.fields.SFMatrix4f;return t._00=e[0],t._01=e[4],t._02=e[8],t._03=e[12],t._10=e[1],t._11=e[5],t._12=e[9],t._13=e[13],t._20=e[2],t._21=e[6],t._22=e[10],t._23=e[14],t._30=e[3],t._31=e[7],t._32=e[11],t._33=e[15],t},x3dom.fields.SFMatrix4f.prototype.fromRotationTranslationScale=function(e,t,i){t=t||new x3dom.fields.SFVec3f,e=e||new x3dom.fields.Quaternion,i=i||new x3dom.fields.SFVec3f(1,1,1);var o=e.x,s=e.y,r=e.z,n=e.w,a=o+o,d=s+s,l=r+r,h=o*a,f=o*d,u=o*l,c=s*d,_=s*l,m=r*l,p=n*a,x=n*d,g=n*l;return this._00=(1-(c+m))*i.x,this._10=(f+g)*i.x,this._20=(u-x)*i.x,this._30=0,this._01=(f-g)*i.y,this._11=(1-(h+m))*i.y,this._21=(_+p)*i.y,this._31=0,this._02=(u+x)*i.z,this._12=(_-p)*i.z,this._22=(1-(h+c))*i.z,this._32=0,this._03=t.x,this._13=t.y,this._23=t.z,this._33=1,this},x3dom.fields.SFMatrix4f.fromRotationTranslationScale=function(e,t,i){t=t||new x3dom.fields.SFVec3f,e=e||new x3dom.fields.Quaternion,i=i||new x3dom.fields.SFVec3f(1,1,1);var o=new x3dom.fields.SFMatrix4f,s=e.x,r=e.y,n=e.z,a=e.w,d=s+s,l=r+r,h=n+n,f=s*d,u=s*l,c=s*h,_=r*l,m=r*h,p=n*h,x=a*d,g=a*l,v=a*h;return o._00=(1-(_+p))*i.x,o._10=(u+v)*i.x,o._20=(c-g)*i.x,o._30=0,o._01=(u-v)*i.y,o._11=(1-(f+p))*i.y,o._21=(m+x)*i.y,o._31=0,o._02=(c+g)*i.z,o._12=(m-x)*i.z,o._22=(1-(f+_))*i.z,o._32=0,o._03=t.x,o._13=t.y,o._23=t.z,o._33=1,o},x3dom.fields.SFMatrix4f.prototype.toGL=function(){return[this._00,this._10,this._20,this._30,this._01,this._11,this._21,this._31,this._02,this._12,this._22,this._32,this._03,this._13,this._23,this._33]},x3dom.fields.SFMatrix4f.fromGL=function(e){var t=new x3dom.fields.SFMatrix4f;return t._00=e[0],t._01=e[4],t._02=e[8],t._03=e[12],t._10=e[1],t._11=e[5],t._12=e[9],t._13=e[13],t._20=e[2],t._21=e[6],t._22=e[10],t._23=e[14],t._30=e[3],t._31=e[7],t._32=e[11],t._33=e[15],t},x3dom.fields.SFMatrix4f.prototype.at=function(e,t){return this["_"+e+t]},x3dom.fields.SFMatrix4f.prototype.setAt=function(e,t,i){return this["_"+e+t]=i,this},x3dom.fields.SFMatrix4f.prototype.sqrt=function(){for(var e=x3dom.fields.SFMatrix4f.identity(),t=x3dom.fields.SFMatrix4f.copy(this),i=0;i<6;i++){var o=t.inverse(),s=0==i?x3dom.fields.SFMatrix4f.identity():e.inverse(),r=t.det(),n=e.det(),a=Math.abs(Math.pow(r*n,-.125)),d=1/a;t=(t=(t=t.multiply(a)).addScaled(s,d)).multiply(.5),e=(e=(e=e.multiply(a)).addScaled(o,d)).multiply(.5)}return t},x3dom.fields.SFMatrix4f.prototype.normInfinity=function(){var e=0,t=0;return(e=Math.abs(this._00))>t&&(t=e),(e=Math.abs(this._01))>t&&(t=e),(e=Math.abs(this._02))>t&&(t=e),(e=Math.abs(this._03))>t&&(t=e),(e=Math.abs(this._10))>t&&(t=e),(e=Math.abs(this._11))>t&&(t=e),(e=Math.abs(this._12))>t&&(t=e),(e=Math.abs(this._13))>t&&(t=e),(e=Math.abs(this._20))>t&&(t=e),(e=Math.abs(this._21))>t&&(t=e),(e=Math.abs(this._22))>t&&(t=e),(e=Math.abs(this._23))>t&&(t=e),(e=Math.abs(this._30))>t&&(t=e),(e=Math.abs(this._31))>t&&(t=e),(e=Math.abs(this._32))>t&&(t=e),(e=Math.abs(this._33))>t&&(t=e),t},x3dom.fields.SFMatrix4f.prototype.norm1_3x3=function(){var e=Math.abs(this._00)+Math.abs(this._10)+Math.abs(this._20),t=0;return(t=Math.abs(this._01)+Math.abs(this._11)+Math.abs(this._21))>e&&(e=t),(t=Math.abs(this._02)+Math.abs(this._12)+Math.abs(this._22))>e&&(e=t),e},x3dom.fields.SFMatrix4f.prototype.normInf_3x3=function(){var e=Math.abs(this._00)+Math.abs(this._01)+Math.abs(this._02),t=0;return(t=Math.abs(this._10)+Math.abs(this._11)+Math.abs(this._12))>e&&(e=t),(t=Math.abs(this._20)+Math.abs(this._21)+Math.abs(this._22))>e&&(e=t),e},x3dom.fields.SFMatrix4f.prototype.adjointT_3x3=function(){var e=x3dom.fields.SFMatrix4f.identity();return e._00=this._11*this._22-this._12*this._21,e._01=this._12*this._20-this._10*this._22,e._02=this._10*this._21-this._11*this._20,e._10=this._21*this._02-this._22*this._01,e._11=this._22*this._00-this._20*this._02,e._12=this._20*this._01-this._21*this._00,e._20=this._01*this._12-this._02*this._11,e._21=this._02*this._10-this._00*this._12,e._22=this._00*this._11-this._01*this._10,e},x3dom.fields.SFMatrix4f.prototype.equals=function(e){var t=1e-12;return Math.abs(this._00-e._00)<t&&Math.abs(this._01-e._01)<t&&Math.abs(this._02-e._02)<t&&Math.abs(this._03-e._03)<t&&Math.abs(this._10-e._10)<t&&Math.abs(this._11-e._11)<t&&Math.abs(this._12-e._12)<t&&Math.abs(this._13-e._13)<t&&Math.abs(this._20-e._20)<t&&Math.abs(this._21-e._21)<t&&Math.abs(this._22-e._22)<t&&Math.abs(this._23-e._23)<t&&Math.abs(this._30-e._30)<t&&Math.abs(this._31-e._31)<t&&Math.abs(this._32-e._32)<t&&Math.abs(this._33-e._33)<t},x3dom.fields.SFMatrix4f.prototype.getTransform=function(e,t,i,o,s){var r=null;if(arguments.length>4){r=(r=x3dom.fields.SFMatrix4f.translation(s.negate())).mult(this);var n=x3dom.fields.SFMatrix4f.translation(s);r=r.mult(n)}else r=x3dom.fields.SFMatrix4f.copy(this);var a=r.decompose(e,t,i,o);i.setValues(i.multiply(a))},x3dom.fields.SFMatrix4f.prototype.decompose=function(e,t,i,o){var s=x3dom.fields.SFMatrix4f.copy(this),r=x3dom.fields.SFMatrix4f.identity(),n=x3dom.fields.SFMatrix4f.identity(),a=x3dom.fields.SFMatrix4f.identity();e.x=s._03,e.y=s._13,e.z=s._23,s._03=0,s._13=0,s._23=0,s._30=0,s._31=0,s._32=0;var d=1;return s.polarDecompose(r,n)<0&&(r=r.negate(),d=-1),t.setValue(r),n.spectralDecompose(a,i),o.setValue(a),d},x3dom.fields.SFMatrix4f.prototype.polarDecompose=function(e,t){var i,o,s,r,n,a=this.transpose(),d=x3dom.fields.SFMatrix4f.identity(),l=a.norm1_3x3(),h=a.normInf_3x3();do{if(i=a.adjointT_3x3(),0==(n=a._00*i._00+a._01*i._01+a._02*i._02)){x3dom.debug.logWarning("polarDecompose: Mk_det == 0.0");break}o=i.norm1_3x3(),s=i.normInf_3x3();var f=Math.sqrt(Math.sqrt(o*s/(l*h))/Math.abs(n)),u=.5*f,c=.5/(f*n);d.setValues(a),a=(a=a.multiply(u)).addScaled(i,c),r=(d=d.addScaled(a,-1)).norm1_3x3(),l=a.norm1_3x3(),h=a.normInf_3x3()}while(r>1e-12*l);e.setValues(a.transpose()),t.setValues(a.mult(this));for(var _=0;_<3;++_)for(var m=_;m<3;++m)t.setAt(m,_,.5*(t.at(m,_)+t.at(_,m))),t.setAt(_,m,.5*(t.at(m,_)+t.at(_,m)));return n},x3dom.fields.SFMatrix4f.prototype.spectralDecompose=function(e,t){for(var i=[1,2,0],o=[this._00,this._11,this._22],s=[this._12,this._20,this._01],r=0;r<20;++r){if(0==Math.abs(s[0])+Math.abs(s[1])+Math.abs(s[2]))break;for(var n=2;n>=0;--n){var a=i[n],d=i[a],l=Math.abs(s[n]),h=100*l;if(l>0){var f=0,u=o[d]-o[a],c=Math.abs(u);if(c+h==c)f=s[n]/u;else{var _=.5*u/s[n];f=1/(Math.abs(_)+Math.sqrt(_*_+1)),f=_<0?-f:f}var m=1/Math.sqrt(f*f+1),p=f*m,x=p/(m+1),g=f*s[n];s[n]=0,o[a]-=g,o[d]+=g;var v=s[d];s[d]-=p*(s[a]+x*v),s[a]+=p*(v-x*s[a]);for(var y=2;y>=0;--y){var T=e.at(y,a),b=e.at(y,d);e.setAt(y,a,e.at(y,a)-p*(b+x*T)),e.setAt(y,d,e.at(y,d)+p*(T-x*b))}}}}t.x=o[0],t.y=o[1],t.z=o[2]},x3dom.fields.SFMatrix4f.prototype.log=function(){var e=x3dom.fields.SFMatrix4f.copy(this),t=x3dom.fields.SFMatrix4f.copy(this);t._00-=1,t._11-=1,t._22-=1,t._33-=1;for(var i=0;t.normInfinity()>.5;)e=e.sqrt(),t.setValues(e),t._00-=1,t._11-=1,t._22-=1,t._33-=1,i++;e._00-=1,e._11-=1,e._22-=1,e._33-=1,e=e.negate(),t.setValues(e);for(var o=x3dom.fields.SFMatrix4f.copy(e),s=1;t.normInfinity()>1e-12&&s<12;)t=t.mult(e),s++,o=o.addScaled(t,1/s);return o.multiply(-(1<<i))},x3dom.fields.SFMatrix4f.prototype.exp=function(){var e=x3dom.fields.SFMatrix4f.copy(this),t=x3dom.fields.SFMatrix4f.identity(),i=x3dom.fields.SFMatrix4f.identity(),o=x3dom.fields.SFMatrix4f.identity(),s=0,r=1,n=1+parseInt(Math.log(e.normInfinity()/.693));for(n<0&&(n=0),e=e.multiply(1/(1<<n)),s=1;s<=6;s++)r*=(6-s+1)/(s*(12-s+1)),o=e.mult(o),i=i.addScaled(o,r),t=s%2?t.addScaled(o,-r):t.addScaled(o,r);for(o=t.inverse().mult(i),s=0;s<n;s++)o=o.mult(o);return o},x3dom.fields.SFMatrix4f.prototype.det3=function(e,t,i,o,s,r,n,a,d){return e*s*d+t*r*n+i*o*a-e*r*a-t*o*d-i*s*n},x3dom.fields.SFMatrix4f.prototype.det=function(){var e=this._00,t=this._10,i=this._20,o=this._30,s=this._01,r=this._11,n=this._21,a=this._31,d=this._02,l=this._12,h=this._22,f=this._32,u=this._03,c=this._13,_=this._23,m=this._33;return e*this.det3(r,l,c,n,h,_,a,f,m)-t*this.det3(s,d,u,n,h,_,a,f,m)+i*this.det3(s,d,u,r,l,c,a,f,m)-o*this.det3(s,d,u,r,l,c,n,h,_)},x3dom.fields.SFMatrix4f.prototype.inverse=function(){var e=this._00,t=this._10,i=this._20,o=this._30,s=this._01,r=this._11,n=this._21,a=this._31,d=this._02,l=this._12,h=this._22,f=this._32,u=this._03,c=this._13,_=this._23,m=this._33,p=this.det();return 0==p?(x3dom.debug.logWarning("Invert matrix: singular matrix, no inverse!"),x3dom.fields.SFMatrix4f.identity()):(p=1/p,new x3dom.fields.SFMatrix4f(+this.det3(r,l,c,n,h,_,a,f,m)*p,-this.det3(s,d,u,n,h,_,a,f,m)*p,+this.det3(s,d,u,r,l,c,a,f,m)*p,-this.det3(s,d,u,r,l,c,n,h,_)*p,-this.det3(t,l,c,i,h,_,o,f,m)*p,+this.det3(e,d,u,i,h,_,o,f,m)*p,-this.det3(e,d,u,t,l,c,o,f,m)*p,+this.det3(e,d,u,t,l,c,i,h,_)*p,+this.det3(t,r,c,i,n,_,o,a,m)*p,-this.det3(e,s,u,i,n,_,o,a,m)*p,+this.det3(e,s,u,t,r,c,o,a,m)*p,-this.det3(e,s,u,t,r,c,i,n,_)*p,-this.det3(t,r,l,i,n,h,o,a,f)*p,+this.det3(e,s,d,i,n,h,o,a,f)*p,-this.det3(e,s,d,t,r,l,o,a,f)*p,+this.det3(e,s,d,t,r,l,i,n,h)*p))},x3dom.fields.SFMatrix4f.prototype.getEulerAngles=function(){var e,t,i,o,s,r,n,a;return Math.abs(Math.abs(this._20)-1)>1e-4?(e=-Math.asin(this._20),t=Math.PI-e,n=Math.cos(e),a=Math.cos(t),o=Math.atan2(this._21/n,this._22/n),s=Math.atan2(this._21/a,this._22/a),[o,e,Math.atan2(this._10/n,this._00/n),s,t,Math.atan2(this._10/a,this._00/a)]):(0,-1==this._20?(i=Math.PI/2,r=0+Math.atan2(this._01,this._02)):(i=-Math.PI/2,r=-0+Math.atan2(-this._01,-this._02)),[r,i,0,r,i,0])},x3dom.fields.SFMatrix4f.prototype.toString=function(){return this._00.toFixed(6)+" "+this._10.toFixed(6)+" "+this._20.toFixed(6)+" "+this._30.toFixed(6)+" "+this._01.toFixed(6)+" "+this._11.toFixed(6)+" "+this._21.toFixed(6)+" "+this._31.toFixed(6)+" "+this._02.toFixed(6)+" "+this._12.toFixed(6)+" "+this._22.toFixed(6)+" "+this._32.toFixed(6)+" "+this._03.toFixed(6)+" "+this._13.toFixed(6)+" "+this._23.toFixed(6)+" "+this._33.toFixed(6)},x3dom.fields.SFMatrix4f.prototype.setValueByStr=function(e){var t=!1;/matrix.*\((.+)\)/.exec(e)&&(e=RegExp.$1,t=!0);var i=e.split(/[,\s]+/).map((function(e){return+e}));return i.length>=16?t?(this._00=i[0],this._01=i[4],this._02=i[8],this._03=i[12],this._10=i[1],this._11=i[5],this._12=i[9],this._13=i[13],this._20=i[2],this._21=i[6],this._22=i[10],this._23=i[14],this._30=i[3],this._31=i[7],this._32=i[11],this._33=i[15]):(this._00=i[0],this._01=i[1],this._02=i[2],this._03=i[3],this._10=i[4],this._11=i[5],this._12=i[6],this._13=i[7],this._20=i[8],this._21=i[9],this._22=i[10],this._23=i[11],this._30=i[12],this._31=i[13],this._32=i[14],this._33=i[15]):6===i.length?(this._00=i[0],this._01=i[1],this._02=0,this._03=i[4],this._10=i[2],this._11=i[3],this._12=0,this._13=i[5],this._20=0,this._21=0,this._22=1,this._23=0,this._30=0,this._31=0,this._32=0,this._33=1):x3dom.debug.logWarning("SFMatrix4f - can't parse string: "+e),this},x3dom.fields.SFVec2f=function(e,t){0===arguments.length?(this.x=0,this.y=0):(this.x=e,this.y=t)},x3dom.fields.SFVec2f.copy=function(e){return new x3dom.fields.SFVec2f(e.x,e.y)},x3dom.fields.SFVec2f.parse=function(e){var t=/^\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*$/.exec(e);return null===t?new x3dom.fields.SFVec2f:new x3dom.fields.SFVec2f(+t[1],+t[2])},x3dom.fields.SFVec2f.prototype.copy=function(){return x3dom.fields.SFVec2f.copy(this)},x3dom.fields.SFVec2f.prototype.setValues=function(e){return this.x=e.x,this.y=e.y,this},x3dom.fields.SFVec2f.prototype.at=function(e){switch(e){case 0:return this.x;case 1:return this.y;default:return this.x}},x3dom.fields.SFVec2f.prototype.add=function(e){return new x3dom.fields.SFVec2f(this.x+e.x,this.y+e.y)},x3dom.fields.SFVec2f.prototype.subtract=function(e){return new x3dom.fields.SFVec2f(this.x-e.x,this.y-e.y)},x3dom.fields.SFVec2f.prototype.negate=function(){return new x3dom.fields.SFVec2f(-this.x,-this.y)},x3dom.fields.SFVec2f.prototype.dot=function(e){return this.x*e.x+this.y*e.y},x3dom.fields.SFVec2f.prototype.reflect=function(e){var t=2*this.dot(e);return new x3dom.fields.SFVec2f(this.x-t*e.x,this.y-t*e.y)},x3dom.fields.SFVec2f.prototype.normalize=function(){var e=this.length();return e&&(e=1/e),new x3dom.fields.SFVec2f(this.x*e,this.y*e)},x3dom.fields.SFVec2f.prototype.multComponents=function(e){return new x3dom.fields.SFVec2f(this.x*e.x,this.y*e.y)},x3dom.fields.SFVec2f.prototype.multiply=function(e){return new x3dom.fields.SFVec2f(this.x*e,this.y*e)},x3dom.fields.SFVec2f.prototype.divideComponents=function(e){return new x3dom.fields.SFVec2f(this.x/e.x,this.y/e.y)},x3dom.fields.SFVec2f.prototype.divide=function(e){var t=e?1/e:1;return new x3dom.fields.SFVec2f(this.x*t,this.y*t)},x3dom.fields.SFVec2f.prototype.equals=function(e,t){return Math.abs(this.x-e.x)<t&&Math.abs(this.y-e.y)<t},x3dom.fields.SFVec2f.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},x3dom.fields.SFVec2f.prototype.toGL=function(){return[this.x,this.y]},x3dom.fields.SFVec2f.prototype.toString=function(){return this.x+" "+this.y},x3dom.fields.SFVec2f.prototype.setValueByStr=function(e){var t=/^\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*$/.exec(e);return t=t||[0,0,0],this.x=+t[1],this.y=+t[2],this},x3dom.fields.SFVec3f=function(e,t,i){0===arguments.length?(this.x=0,this.y=0,this.z=0):(this.x=e,this.y=t,this.z=i)},x3dom.fields.SFVec3f.NullVector=new x3dom.fields.SFVec3f(0,0,0),x3dom.fields.SFVec3f.OneVector=new x3dom.fields.SFVec3f(1,1,1),x3dom.fields.SFVec3f.copy=function(e){return new x3dom.fields.SFVec3f(e.x,e.y,e.z)},x3dom.fields.SFVec3f.MIN=function(){return new x3dom.fields.SFVec3f(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE)},x3dom.fields.SFVec3f.MAX=function(){return new x3dom.fields.SFVec3f(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},x3dom.fields.SFVec3f.parse=function(e){try{var t=/^\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*$/.exec(e);return new x3dom.fields.SFVec3f(+t[1],+t[2],+t[3])}catch(t){var i=x3dom.fields.SFColor.colorParse(e);return new x3dom.fields.SFVec3f(i.r,i.g,i.b)}},x3dom.fields.SFVec3f.prototype.copy=function(){return x3dom.fields.SFVec3f.copy(this)},x3dom.fields.SFVec3f.prototype.fromArray=function(e){return this.x=e[0],this.y=e[1],this.z=e[2],this},x3dom.fields.SFVec3f.fromArray=function(e){return new x3dom.fields.SFVec3f(e[0],e[1],e[2])},x3dom.fields.SFVec3f.prototype.setValues=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},x3dom.fields.SFVec3f.prototype.set=function(e,t,i){return this.x=e,this.y=t,this.z=i,this},x3dom.fields.SFVec3f.prototype.at=function(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:return this.x}},x3dom.fields.SFVec3f.prototype.add=function(e){return new x3dom.fields.SFVec3f(this.x+e.x,this.y+e.y,this.z+e.z)},x3dom.fields.SFVec3f.prototype.addScaled=function(e,t){return new x3dom.fields.SFVec3f(this.x+t*e.x,this.y+t*e.y,this.z+t*e.z)},x3dom.fields.SFVec3f.prototype.subtract=function(e){return new x3dom.fields.SFVec3f(this.x-e.x,this.y-e.y,this.z-e.z)},x3dom.fields.SFVec3f.prototype.subtractVectors=function(e,t){return new x3dom.fields.SFVec3f(e.x-t.x,e.y-t.y,e.z-t.z)},x3dom.fields.SFVec3f.prototype.negate=function(){return new x3dom.fields.SFVec3f(-this.x,-this.y,-this.z)},x3dom.fields.SFVec3f.prototype.dot=function(e){return this.x*e.x+this.y*e.y+this.z*e.z},x3dom.fields.SFVec3f.prototype.cross=function(e){return new x3dom.fields.SFVec3f(this.y*e.z-this.z*e.y,this.z*e.x-this.x*e.z,this.x*e.y-this.y*e.x)},x3dom.fields.SFVec3f.prototype.reflect=function(e){var t=2*this.dot(e);return new x3dom.fields.SFVec3f(this.x-t*e.x,this.y-t*e.y,this.z-t*e.z)},x3dom.fields.SFVec3f.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},x3dom.fields.SFVec3f.prototype.normalize=function(){var e=this.length();return e&&(e=1/e),new x3dom.fields.SFVec3f(this.x*e,this.y*e,this.z*e)},x3dom.fields.SFVec3f.prototype.multComponents=function(e){return new x3dom.fields.SFVec3f(this.x*e.x,this.y*e.y,this.z*e.z)},x3dom.fields.SFVec3f.prototype.multiply=function(e){return new x3dom.fields.SFVec3f(this.x*e,this.y*e,this.z*e)},x3dom.fields.SFVec3f.prototype.divide=function(e){var t=e?1/e:1;return new x3dom.fields.SFVec3f(this.x*t,this.y*t,this.z*t)},x3dom.fields.SFVec3f.prototype.equals=function(e,t){return Math.abs(this.x-e.x)<t&&Math.abs(this.y-e.y)<t&&Math.abs(this.z-e.z)<t},x3dom.fields.SFVec3f.prototype.toGL=function(){return[this.x,this.y,this.z]},x3dom.fields.SFVec3f.prototype.toString=function(){return this.x+" "+this.y+" "+this.z},x3dom.fields.SFVec3f.prototype.setValueByStr=function(e){try{var t=/^\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*$/.exec(e);this.x=+t[1],this.y=+t[2],this.z=+t[3]}catch(t){var i=x3dom.fields.SFColor.colorParse(e);this.x=i.r,this.y=i.g,this.z=i.b}return this},x3dom.fields.SFVec4f=function(e,t,i,o){0===arguments.length?(this.x=0,this.y=0,this.z=0,this.w=0):(this.x=e,this.y=t,this.z=i,this.w=o)},x3dom.fields.SFVec4f.copy=function(e){return new x3dom.fields.SFVec4f(e.x,e.y,e.z,e.w)},x3dom.fields.SFVec4f.prototype.copy=function(){return x3dom.fields.SFVec4f(this)},x3dom.fields.SFVec4f.parse=function(e){var t=/^\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*$/.exec(e);return null===t?new x3dom.fields.SFVec4f:new x3dom.fields.SFVec4f(+t[1],+t[2],+t[3],+t[4])},x3dom.fields.SFVec4f.prototype.setValueByStr=function(e){var t=/^\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*$/.exec(e);return t=t||[0,0,0,0,0],this.x=+t[1],this.y=+t[2],this.z=+t[3],this.w=+t[4],this},x3dom.fields.SFVec4f.prototype.toGL=function(){return[this.x,this.y,this.z,this.w]},x3dom.fields.SFVec4f.prototype.toString=function(){return this.x+" "+this.y+" "+this.z+" "+this.w},x3dom.fields.Quaternion=function(e,t,i,o){0===arguments.length?(this.x=0,this.y=0,this.z=0,this.w=1):(this.x=e,this.y=t,this.z=i,this.w=o)},x3dom.fields.SFRotation=new Proxy(x3dom.fields.Quaternion,{construct:function(e,t){var i;t[0]=t[0]||0,t[1]=null==t[1]?1:t[1],t[2]=t[2]||0,t[3]=t[3]||0;var o={get:function(e,t){switch(t){case"0":return e.SFRotation.x;case"1":return e.SFRotation.y;case"2":return e.SFRotation.z;case"3":case"angle":return e.SFRotation.angle;default:return Reflect.get(e,t)}},set:function(e,t,i){var o=e.SFRotation,s={0:"x",1:"y",2:"z",x:"x",y:"y",z:"z",angle:"angle"};return t in s?(o[s[t]]=i,e.setValues(new x3dom.fields.Quaternion.axisAngle(new x3dom.fields.SFVec3f(o.x,o.y,o.z),o.angle)),!0):(x3dom.debug.logWarning(" SFRotation: property not available - "+t),!1)}};if(t[0].constructor==x3dom.fields.SFVec3f){var s=(i=t[1].constructor==x3dom.fields.SFVec3f?new x3dom.fields.Quaternion.rotateFromTo(t[0].normalize(),t[1].normalize()):new x3dom.fields.Quaternion.axisAngle(t[0],t[1])).toAxisAngle();i.SFRotation={x:s[0].x,y:s[0].y,z:s[0].z,angle:s[1]}}else(i=new x3dom.fields.Quaternion.axisAngle(new x3dom.fields.SFVec3f(t[0],t[1],t[2]),t[3])).SFRotation={x:t[0],y:t[1],z:t[2],angle:t[3]};return new Proxy(i,o)}}),x3dom.fields.Quaternion.prototype.getAxis=function(){if("SFRotation"in this){var e=this.SFRotation;return new x3dom.fields.SFVec3f(e.x,e.y,e.z)}return this.toAxisAngle()[0]},x3dom.fields.Quaternion.prototype.setAxis=function(e){var t;"SFRotation"in this?(t=this.SFRotation.angle,this.SFRotation.x=e.x,this.SFRotation.y=e.y,this.SFRotation.z=e.z):t=this.angle();var i=new x3dom.fields.Quaternion.axisAngle(e,t);this.setValues(i)},x3dom.fields.Quaternion.prototype.multiVec=function(e){var t=x3dom.fields.SFMatrix4f.identity();return t.setRotate(this),t.multMatrixVec(e)},x3dom.fields.Quaternion.prototype.setValues=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},x3dom.fields.Quaternion.copy=function(e){return new x3dom.fields.Quaternion(e.x,e.y,e.z,e.w)},x3dom.fields.Quaternion.prototype.multiply=function(e){var t=new x3dom.fields.Quaternion(this.w*e.x+this.x*e.w+this.y*e.z-this.z*e.y,this.w*e.y+this.y*e.w+this.z*e.x-this.x*e.z,this.w*e.z+this.z*e.w+this.x*e.y-this.y*e.x,this.w*e.w-this.x*e.x-this.y*e.y-this.z*e.z);if("SFRotation"in this){var i=t.toAxisAngle();return new x3dom.fields.SFRotation(i[0].x,i[0].y,i[0].z,i[1])}return t},x3dom.fields.Quaternion.prototype.fromArray=function(e){return this.x=e[0],this.y=e[1],this.z=e[2],this.w=e[3],this},x3dom.fields.Quaternion.fromArray=function(e){return new x3dom.fields.Quaternion(e[0],e[1],e[2],e[3])},x3dom.fields.Quaternion.parseAxisAngle=function(e){var t=/^\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*$/.exec(e);return null===t?new x3dom.fields.Quaternion:x3dom.fields.Quaternion.axisAngle(new x3dom.fields.SFVec3f(+t[1],+t[2],+t[3]),+t[4])},x3dom.fields.Quaternion.axisAngle=function(e,t){var i=e.length();if(i>x3dom.fields.Eps){var o=Math.sin(t/2)/i,s=Math.cos(t/2);return new x3dom.fields.Quaternion(e.x*o,e.y*o,e.z*o,s)}return new x3dom.fields.Quaternion(0,0,0,1)},x3dom.fields.Quaternion.prototype.copy=function(){return x3dom.fields.Quaternion.copy(this)},x3dom.fields.Quaternion.prototype.toMatrix=function(){var e=this.x*this.x,t=this.x*this.y,i=this.x*this.z,o=this.y*this.y,s=this.y*this.z,r=this.z*this.z,n=this.w*this.x,a=this.w*this.y,d=this.w*this.z;return new x3dom.fields.SFMatrix4f(1-2*(o+r),2*(t-d),2*(i+a),0,2*(t+d),1-2*(e+r),2*(s-n),0,2*(i-a),2*(s+n),1-2*(e+o),0,0,0,0,1)},x3dom.fields.Quaternion.prototype.toAxisAngle=function(){var e,t,i=0,o=0,s=0;return this.w>1&&this.normalize(),t=2*Math.acos(this.w),0==(e=Math.sqrt(1-this.w*this.w))?(i=this.x,o=this.y,s=this.z):(i=this.x/e,o=this.y/e,s=this.z/e),[new x3dom.fields.SFVec3f(i,o,s),t]},x3dom.fields.Quaternion.prototype.angle=function(){return 2*Math.acos(this.w)},x3dom.fields.Quaternion.prototype.setValue=function(e){var t,i=1,o=[0,0,0],s=0,r=0,n=0,a=[1,2,0];if((t=e._00+e._11+e._22)>0?(i=Math.sqrt(t+1),this.w=.5*i,i=.5/i,this.x=(e._21-e._12)*i,this.y=(e._02-e._20)*i,this.z=(e._10-e._01)*i):(s=e._11>e._00?1:0,e._22>e.at(s,s)&&(s=2),n=a[r=a[s]],i=Math.sqrt(e.at(s,s)-(e.at(r,r)+e.at(n,n))+1),o[s]=.5*i,i=.5/i,this.w=(e.at(n,r)-e.at(r,n))*i,o[r]=(e.at(r,s)+e.at(s,r))*i,o[n]=(e.at(n,s)+e.at(s,n))*i,this.x=o[0],this.y=o[1],this.z=o[2]),this.w>1||this.w<-1){var d=1+100*x3dom.fields.Eps;(this.w>d||this.w<-d)&&x3dom.debug.logInfo("MatToQuat: BUG: |quat[4]| ("+this.w+") >> 1.0 !"),this.w>1?this.w=1:this.w=-1}},x3dom.fields.Quaternion.prototype.setFromEuler=function(e,t,i){var o=Math.sin(.5*e),s=Math.cos(.5*e),r=Math.sin(.5*t),n=Math.cos(.5*t),a=Math.sin(.5*i),d=Math.cos(.5*i);return this.x=o*n*d-s*r*a,this.y=s*r*d+o*n*a,this.z=s*n*a-o*r*d,this.w=s*n*d+o*r*a,this},x3dom.fields.Quaternion.prototype.dot=function(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w},x3dom.fields.Quaternion.prototype.add=function(e){return new x3dom.fields.Quaternion(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)},x3dom.fields.Quaternion.prototype.subtract=function(e){return new x3dom.fields.Quaternion(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)},x3dom.fields.Quaternion.prototype.setValues=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},x3dom.fields.Quaternion.prototype.equals=function(e,t){return this.dot(e)>=1-t},x3dom.fields.Quaternion.prototype.multScalar=function(e){return new x3dom.fields.Quaternion(this.x*e,this.y*e,this.z*e,this.w*e)},x3dom.fields.Quaternion.prototype.normalize=function(){var e=this.dot(this),t=1;return e&&(t=1/Math.sqrt(e)),this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},x3dom.fields.Quaternion.normalize=function(e){var t=e.dot(e),i=1;return t&&(i=1/Math.sqrt(t)),e.x*=i,e.y*=i,e.z*=i,e.w*=i,e},x3dom.fields.Quaternion.prototype.negate=function(){return new x3dom.fields.Quaternion(-this.x,-this.y,-this.z,-this.w)},x3dom.fields.Quaternion.prototype.inverse=function(){var e=new x3dom.fields.Quaternion(-this.x,-this.y,-this.z,this.w);if("SFRotation"in this){var t=e.toAxisAngle();return new x3dom.fields.SFRotation(t[0].x,t[0].y,t[0].z,t[1])}return e},x3dom.fields.Quaternion.prototype.slerp=function(e,t){var i,o,s,r=this.dot(e);if(r<0?(r=-r,i=e.negate()):i=new x3dom.fields.Quaternion(e.x,e.y,e.z,e.w),1-r>1e-5){var n=Math.acos(r),a=Math.sin(n);o=Math.sin((1-t)*n)/a,s=Math.sin(t*n)/a}else o=1-t,s=t;var d=this.multScalar(o).add(i.multScalar(s));if("SFRotation"in this){var l=d.toAxisAngle();return new x3dom.fields.SFRotation(l[0].x,l[0].y,l[0].z,l[1])}return d},x3dom.fields.Quaternion.rotateFromTo=function(e,t){var i=e.normalize(),o=t.normalize(),s=i.dot(o);if(s>.99999)return new x3dom.fields.Quaternion(0,0,0,1);if(s<-.99999){var r=new x3dom.fields.SFVec3f(1,0,0),n=i.cross(r);return n.length()<1e-5&&(r.x=0,r.y=1,r.z=0,n=i.cross(r)),n=n.normalize(),x3dom.fields.Quaternion.axisAngle(n,Math.PI)}var a=e.cross(t);a=a.normalize();var d=Math.sqrt(.5*(1-s));return a=a.multiply(d),d=Math.sqrt(.5*(1+s)),new x3dom.fields.Quaternion(a.x,a.y,a.z,d)},x3dom.fields.Quaternion.prototype.toGL=function(){var e=this.toAxisAngle();return[e[0].x,e[0].y,e[0].z,e[1]]},x3dom.fields.Quaternion.prototype.toString=function(){return"SFRotation"in this?this.SFRotation.x+" "+this.SFRotation.y+" "+this.SFRotation.z+" "+this.SFRotation.angle:this.x+" "+this.y+" "+this.z+", "+this.w},x3dom.fields.Quaternion.prototype.setValueByStr=function(e){var t=/^\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*$/.exec(e);t=t||[0,1,0,0,0];var i=x3dom.fields.Quaternion.axisAngle(new x3dom.fields.SFVec3f(+t[1],+t[2],+t[3]),+t[4]);return this.x=i.x,this.y=i.y,this.z=i.z,this.w=i.w,this},x3dom.fields.SFColor=function(e,t,i){0===arguments.length?(this.r=0,this.g=0,this.b=0):(this.r=e,this.g=t,this.b=i)},x3dom.fields.SFColor.parse=function(e){try{var t=/^\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*$/.exec(e);return new x3dom.fields.SFColor(+t[1],+t[2],+t[3])}catch(t){return x3dom.fields.SFColor.colorParse(e)}},x3dom.fields.SFColor.copy=function(e){return new x3dom.fields.SFColor(e.r,e.g,e.b)},x3dom.fields.SFColor.prototype.copy=function(){return x3dom.fields.SFColor.copy(this)},x3dom.fields.SFColor.prototype.setHSV=function(e,t,i){var o,s,r,n,a,d=0,l=0,h=0;switch(r=i*(1-t),n=i*(1-t*(s=e/60-(o=Math.floor(e/60)))),a=i*(1-t*(1-s)),o){case 0:case 6:d=i,l=a,h=r;break;case 1:d=n,l=i,h=r;break;case 2:d=r,l=i,h=a;break;case 3:d=r,l=n,h=i;break;case 4:d=a,l=r,h=i;break;case 5:d=i,l=r,h=n;break;default:x3dom.debug.logWarning("Using black for invalid case in setHSV: "+o)}return this.r=d,this.g=l,this.b=h,this},x3dom.fields.SFColor.prototype.getHSV=function(){var e,t=0,i={},o=this.r;if(i.name="red",i.value=this.r,this.g<o&&(o=this.g),this.b<o&&(o=this.b),this.g>i.value&&(i.name="green",i.value=this.g),this.b>i.value&&(i.name="blue",i.value=this.b),0==(e=i.value-o))t=0;else if("red"==i.name)t=(this.g-this.b)/e%6*60;else if("green"==i.name)t=60*((this.b-this.r)/e+2);else{if("blue"!=i.name)throw"Unknown maximum component: "+i.name;t=60*((this.r-this.g)/e+4)}return t<0&&(t+=360),[t,0==i.value?0:e/i.value,i.value]},x3dom.fields.SFColor.prototype.setValues=function(e){return this.r=e.r,this.g=e.g,this.b=e.b,this},x3dom.fields.SFColor.prototype.equals=function(e,t){return Math.abs(this.r-e.r)<t&&Math.abs(this.g-e.g)<t&&Math.abs(this.b-e.b)<t},x3dom.fields.SFColor.prototype.add=function(e){return new x3dom.fields.SFColor(this.r+e.r,this.g+e.g,this.b+e.b)},x3dom.fields.SFColor.prototype.subtract=function(e){return new x3dom.fields.SFColor(this.r-e.r,this.g-e.g,this.b-e.b)},x3dom.fields.SFColor.prototype.multiply=function(e){return new x3dom.fields.SFColor(this.r*e,this.g*e,this.b*e)},x3dom.fields.SFColor.prototype.toUint=function(){return(Math.round(255*this.r)<<16|Math.round(255*this.g)<<8|Math.round(255*this.b))>>>0},x3dom.fields.SFColor.prototype.setFromUint=function(e){return this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e>>0&255)/255,this},x3dom.fields.SFColor.prototype.toGL=function(){return[this.r,this.g,this.b]},x3dom.fields.SFColor.prototype.toString=function(){return this.r+" "+this.g+" "+this.b},x3dom.fields.SFColor.prototype.setValueByStr=function(e){try{var t=/^\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*$/.exec(e);this.r=+t[1],this.g=+t[2],this.b=+t[3]}catch(t){var i=x3dom.fields.SFColor.colorParse(e);this.r=i.r,this.g=i.g,this.b=i.b}return this},x3dom.fields.SFColor.colorParse=function(e){var t=_colorParse(e);return new x3dom.fields.SFColor(t.r,t.g,t.b)},x3dom.fields.SFColorRGBA=function(e,t,i,o){0===arguments.length?(this.r=0,this.g=0,this.b=0,this.a=1):(this.r=e,this.g=t,this.b=i,this.a=o)},x3dom.fields.SFColorRGBA.parse=function(e){try{var t=/^([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)$/.exec(e);return new x3dom.fields.SFColorRGBA(+t[1],+t[2],+t[3],+t[4])}catch(t){return x3dom.fields.SFColorRGBA.colorParse(e)}},x3dom.fields.SFColorRGBA.copy=function(e){return new x3dom.fields.SFColorRGBA(e.r,e.g,e.b,e.a)},x3dom.fields.SFColorRGBA.prototype.copy=function(){return x3dom.fields.SFColorRGBA.copy(this)},x3dom.fields.SFColorRGBA.prototype.setHSV=x3dom.fields.SFColor.prototype.setHSV,x3dom.fields.SFColorRGBA.prototype.getHSV=x3dom.fields.SFColor.prototype.getHSV,x3dom.fields.SFColorRGBA.prototype.setValues=function(e){return this.r=e.r,this.g=e.g,this.b=e.b,this.a=e.a,this},x3dom.fields.SFColorRGBA.prototype.equals=function(e,t){return Math.abs(this.r-e.r)<t&&Math.abs(this.g-e.g)<t&&Math.abs(this.b-e.b)<t&&Math.abs(this.a-e.a)<t},x3dom.fields.SFColorRGBA.prototype.toGL=function(){return[this.r,this.g,this.b,this.a]},x3dom.fields.SFColorRGBA.prototype.toString=function(){return this.r+" "+this.g+" "+this.b+" "+this.a},x3dom.fields.SFColorRGBA.prototype.setValueByStr=function(e){try{var t=/^([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)\s*,?\s*([+\-]?\d*\.*\d*[eE]?[+\-]?\d*?)$/.exec(e);this.r=+t[1],this.g=+t[2],this.b=+t[3],this.a=+t[4]}catch(t){var i=x3dom.fields.SFColorRGBA.colorParse(e);this.r=i.r,this.g=i.g,this.b=i.b,this.a=i.a}return this},x3dom.fields.SFColorRGBA.prototype.toUint=function(){return(Math.round(255*this.r)<<24|Math.round(255*this.g)<<16|Math.round(255*this.b)<<8|Math.round(255*this.a))>>>0},x3dom.fields.SFColorRGBA.prototype.setFromUint=function(e){return this.r=(e>>24&255)/255,this.g=(e>>16&255)/255,this.b=(e>>8&255)/255,this.a=(e>>0&255)/255,this},x3dom.fields.SFColorRGBA.colorParse=function(e){var t=_colorParse(e);return new x3dom.fields.SFColorRGBA(t.r,t.g,t.b,t.a)},x3dom.fields.SFImage=function(e,t,i,o){if(0!==arguments.length&&o&&o.map){this.width=e,this.height=t,this.comp=i;var s=this.array;o.map((function(e){s.push(e)}),this.array)}else this.width=0,this.height=0,this.comp=0,this.array=[]},x3dom.fields.SFImage.parse=function(e){var t=new x3dom.fields.SFImage;return t.setValueByStr(e),t},x3dom.fields.SFImage.copy=function(e){var t=new x3dom.fields.SFImage;return t.width=e.width,t.height=e.height,t.comp=e.comp,t.setPixels(e.getPixels()),t},x3dom.fields.SFImage.prototype.copy=function(){return x3dom.fields.SFImage.copy(this)},x3dom.fields.SFImage.prototype.setValueByStr=function(e){var t,i,o,s,r,n=e.match(/(\w+)/g),a=n.length;if(this.array=[],!(a>2))return this.width=0,this.height=0,void(this.comp=0);this.width=+n[0],this.height=+n[1],this.comp=+n[2];var d=10;for(t=3;t<a;t++)if(n[t].substr){"x"===n[t].substr(1,1).toLowerCase()&&(d=16);var l=parseInt(n[t],d);1===this.comp?(i=255&l,this.array.push(i)):2===this.comp?(i=l>>8&255,o=255&l,this.array.push(i,o)):3===this.comp?(i=l>>16&255,o=l>>8&255,s=255&l,this.array.push(i,o,s)):4===this.comp&&(i=l>>24&255,o=l>>16&255,s=l>>8&255,r=255&l,this.array.push(i,o,s,r))}},x3dom.fields.SFImage.prototype.setPixel=function(e,t,i){var o=(t*this.width+e)*this.comp;return 1===this.comp&&o<this.array.length?this.array[o]=255*i.r:2===this.comp&&o+1<this.array.length?(this.array[o]=255*i.r,this.array[o+1]=255*i.g):3===this.comp&&o+2<this.array.length?(this.array[o]=255*i.r,this.array[o+1]=255*i.g,this.array[o+2]=255*i.b):4===this.comp&&o+3<this.array.length&&(this.array[o]=255*i.r,this.array[o+1]=255*i.g,this.array[o+2]=255*i.b,this.array[o+3]=255*i.a),this},x3dom.fields.SFImage.prototype.getPixel=function(e,t){var i=(t*this.width+e)*this.comp;if(1===this.comp&&i<this.array.length){var o=this.array[i]/255;return new x3dom.fields.SFColorRGBA(o,o,o,1)}if(2===this.comp&&i+1<this.array.length){o=this.array[i]/255;var s=this.array[i+1]/255;return new x3dom.fields.SFColorRGBA(o,o,o,s)}return 3===this.comp&&i+2<this.array.length?new x3dom.fields.SFColorRGBA(this.array[i]/255,this.array[i+1]/255,this.array[i+2]/255,1):4===this.comp&&i+3<this.array.length?new x3dom.fields.SFColorRGBA(this.array[i]/255,this.array[i+1]/255,this.array[i+2]/255,this.array[i+3]/255):void 0},x3dom.fields.SFImage.prototype.setPixels=function(e){var t,i=0;if(1===this.comp)for(t=0;t<e.length;t++)this.array[i++]=255*e[t].r;else if(2===this.comp)for(t=0;t<e.length;t++)this.array[i++]=255*e[t].r,this.array[i++]=255*e[t].g;else if(3===this.comp)for(t=0;t<e.length;t++)this.array[i++]=255*e[t].r,this.array[i++]=255*e[t].g,this.array[i++]=255*e[t].b;else if(4===this.comp)for(t=0;t<e.length;t++)this.array[i++]=255*e[t].r,this.array[i++]=255*e[t].g,this.array[i++]=255*e[t].b,this.array[i++]=255*e[t].a},x3dom.fields.SFImage.prototype.getPixels=function(){var e,t=[];if(1===this.comp)for(e=0;e<this.array.length;e+=this.comp){var i=this.array[e]/255;t.push(new x3dom.fields.SFColorRGBA(i,i,i,1))}else if(2===this.comp)for(e=0;e<this.array.length;e+=this.comp){i=this.array[e]/255;var o=this.array[e+1]/255;t.push(new x3dom.fields.SFColorRGBA(i,i,i,o))}else if(3===this.comp)for(e=0;e<this.array.length;e+=this.comp)t.push(new x3dom.fields.SFColorRGBA(this.array[e]/255,this.array[e+1]/255,this.array[e+2]/255,1));else if(4===this.comp)for(e=0;e<this.array.length;e+=this.comp)t.push(new x3dom.fields.SFColorRGBA(this.array[e]/255,this.array[e+1]/255,this.array[e+2]/255,this.array[e+3]/255));return t},x3dom.fields.SFImage.prototype.toGL=function(){var e=[];return this.array.map((function(t){e.push(t)})),e},x3dom.fields.MFColor=function(e){if(e){var t=this;e.map((function(e){t.push(e)}),this)}},x3dom.fields.MFColor.copy=function(e){var t=new x3dom.fields.MFColor;return e.map((function(e){t.push(e.copy())}),this),t},x3dom.fields.MFColor.prototype=x3dom.extend([]),x3dom.fields.MFColor.parse=function(e){for(var t=e.match(/([+\-0-9eE\.]+)/g),i=[],o=0,s=t?t.length:0;o<s;o+=3)i.push(new x3dom.fields.SFColor(+t[o+0],+t[o+1],+t[o+2]));return new x3dom.fields.MFColor(i)},x3dom.fields.MFColor.prototype.copy=function(){return x3dom.fields.MFColor.copy(this)},x3dom.fields.MFColor.prototype.setValueByStr=function(e){this.length=0;for(var t=e.match(/([+\-0-9eE\.]+)/g),i=0,o=t?t.length:0;i<o;i+=3)this.push(new x3dom.fields.SFColor(+t[i+0],+t[i+1],+t[i+2]))},x3dom.fields.MFColor.prototype.toGL=function(){var e=[];return this.map((function(t){e.push(t.r),e.push(t.g),e.push(t.b)})),e},x3dom.fields.MFColorRGBA=function(e){if(e){var t=this;e.map((function(e){t.push(e)}),this)}},x3dom.fields.MFColorRGBA.copy=function(e){var t=new x3dom.fields.MFColorRGBA;return e.map((function(e){t.push(e.copy())}),this),t},x3dom.fields.MFColorRGBA.prototype=x3dom.extend([]),x3dom.fields.MFColorRGBA.parse=function(e){for(var t=e.match(/([+\-0-9eE\.]+)/g),i=[],o=0,s=t?t.length:0;o<s;o+=4)i.push(new x3dom.fields.SFColorRGBA(+t[o+0],+t[o+1],+t[o+2],+t[o+3]));return new x3dom.fields.MFColorRGBA(i)},x3dom.fields.MFColorRGBA.prototype.copy=function(){return x3dom.fields.MFColorRGBA.copy(this)},x3dom.fields.MFColorRGBA.prototype.setValueByStr=function(e){this.length=0;for(var t=e.match(/([+\-0-9eE\.]+)/g),i=0,o=t?t.length:0;i<o;i+=4)this.push(new x3dom.fields.SFColorRGBA(+t[i+0],+t[i+1],+t[i+2],+t[i+3]))},x3dom.fields.MFColorRGBA.prototype.toGL=function(){var e=[];return this.map((function(t){e.push(t.r),e.push(t.g),e.push(t.b),e.push(t.a)})),e},x3dom.fields.MFRotation=function(e){if(e){var t=this;e.map((function(e){t.push(e)}),this)}},x3dom.fields.MFRotation.prototype=x3dom.extend([]),x3dom.fields.MFRotation.copy=function(e){var t=new x3dom.fields.MFRotation;return e.map((function(e){t.push(e.copy())}),this),t},x3dom.fields.MFRotation.prototype.copy=function(){return x3dom.fields.MFRotation.copy(this)},x3dom.fields.MFRotation.parse=function(e){for(var t=e.match(/([+\-0-9eE\.]+)/g),i=[],o=0,s=t?t.length:0;o<s;o+=4)i.push(x3dom.fields.Quaternion.axisAngle(new x3dom.fields.SFVec3f(+t[o+0],+t[o+1],+t[o+2]),+t[o+3]));return new x3dom.fields.MFRotation(i)},x3dom.fields.MFRotation.prototype.setValueByStr=function(e){this.length=0;for(var t=e.match(/([+\-0-9eE\.]+)/g),i=0,o=t?t.length:0;i<o;i+=4)this.push(x3dom.fields.Quaternion.axisAngle(new x3dom.fields.SFVec3f(+t[i+0],+t[i+1],+t[i+2]),+t[i+3]))},x3dom.fields.MFRotation.prototype.toGL=function(){var e=[];return this.map((function(t){var i=t.toAxisAngle();e.push(i[0].x),e.push(i[0].y),e.push(i[0].z),e.push(i[1])})),e},x3dom.fields.MFVec3f=function(e){if(e){var t=this;e.map((function(e){t.push(e)}),this)}},x3dom.fields.MFVec3f.prototype=x3dom.extend(Array),x3dom.fields.MFVec3f.copy=function(e){var t=new x3dom.fields.MFVec3f;return e.map((function(e){t.push(e.copy())}),this),t},x3dom.fields.MFVec3f.parse=function(e){for(var t=e.match(/([+\-0-9eE\.]+)/g),i=[],o=0,s=t?t.length:0;o<s;o+=3)i.push(new x3dom.fields.SFVec3f(+t[o+0],+t[o+1],+t[o+2]));return new x3dom.fields.MFVec3f(i)},x3dom.fields.MFVec3f.prototype.copy=function(){return x3dom.fields.MFVec3f.copy(this)},x3dom.fields.MFVec3f.prototype.setValueByStr=function(e){this.length=0;for(var t=e.match(/([+\-0-9eE\.]+)/g),i=0,o=t?t.length:0;i<o;i+=3)this.push(new x3dom.fields.SFVec3f(+t[i+0],+t[i+1],+t[i+2]));return this},x3dom.fields.MFVec3f.prototype.setValues=function(e){var t,i=Math.min(e.length,this.length);for(t=0;t<i;t++)this[t].setValues(e[t])},x3dom.fields.MFVec3f.prototype.toGL=function(){var e=[];return this.map((function(t){e.push(t.x),e.push(t.y),e.push(t.z)})),e},x3dom.fields.MFVec3f.prototype.toString=function(){var e="";return this.forEach((function(t){e=e+t.toString()+" "})),e.trim()},x3dom.fields.MFVec2f=function(e){if(e){var t=this;e.map((function(e){t.push(e)}),this)}},x3dom.fields.MFVec2f.prototype=x3dom.extend([]),x3dom.fields.MFVec2f.copy=function(e){var t=new x3dom.fields.MFVec2f;return e.map((function(e){t.push(e.copy())}),this),t},x3dom.fields.MFVec2f.parse=function(e){for(var t=e.match(/([+\-0-9eE\.]+)/g),i=[],o=0,s=t?t.length:0;o<s;o+=2)i.push(new x3dom.fields.SFVec2f(+t[o+0],+t[o+1]));return new x3dom.fields.MFVec2f(i)},x3dom.fields.MFVec2f.prototype.copy=function(){return x3dom.fields.MFVec2f.copy(this)},x3dom.fields.MFVec2f.prototype.setValueByStr=function(e){this.length=0;for(var t=e.match(/([+\-0-9eE\.]+)/g),i=0,o=t?t.length:0;i<o;i+=2)this.push(new x3dom.fields.SFVec2f(+t[i+0],+t[i+1]))},x3dom.fields.MFVec2f.prototype.toGL=function(){var e=[];return this.map((function(t){e.push(t.x),e.push(t.y)})),e},x3dom.fields.MFInt32=function(e){if(e){var t=this;e.map((function(e){t.push(e)}),this)}},x3dom.fields.MFInt32.prototype=x3dom.extend([]),x3dom.fields.MFInt32.copy=function(e){var t=new x3dom.fields.MFInt32;return e.map((function(e){t.push(e)}),this),t},x3dom.fields.MFInt32.parse=function(e){for(var t=e.match(/([+\-]?\d+\s*){1},?\s*/g),i=[],o=0,s=t?t.length:0;o<s;++o)i.push(parseInt(t[o],10));return new x3dom.fields.MFInt32(i)},x3dom.fields.MFInt32.prototype.copy=function(){return x3dom.fields.MFInt32.copy(this)},x3dom.fields.MFInt32.prototype.setValueByStr=function(e){this.length=0;for(var t=e.match(/([+\-]?\d+\s*){1},?\s*/g),i=0,o=t?t.length:0;i<o;++i)this.push(parseInt(t[i],10))},x3dom.fields.MFInt32.prototype.toGL=function(){var e=[];return this.map((function(t){e.push(t)})),e},x3dom.fields.MFFloat=function(e){if(e){var t=this;e.map((function(e){t.push(e)}),this)}},x3dom.fields.MFFloat.prototype=x3dom.extend([]),x3dom.fields.MFFloat.copy=function(e){var t=new x3dom.fields.MFFloat;return e.map((function(e){t.push(e)}),this),t},x3dom.fields.MFFloat.parse=function(e){for(var t=e.match(/([+\-0-9eE\.]+)/g),i=[],o=0,s=t?t.length:0;o<s;o++)i.push(+t[o]);return new x3dom.fields.MFFloat(i)},x3dom.fields.MFFloat.prototype.copy=function(){return x3dom.fields.MFFloat.copy(this)},x3dom.fields.MFFloat.prototype.setValueByStr=function(e){this.length=0;for(var t=e.match(/([+\-0-9eE\.]+)/g),i=0,o=t?t.length:0;i<o;i++)this.push(+t[i])},x3dom.fields.MFFloat.prototype.toGL=function(){var e=[];return this.map((function(t){e.push(t)})),e},x3dom.fields.MFBoolean=function(e){if(e){var t=this;e.map((function(e){t.push(e)}),this)}},x3dom.fields.MFBoolean.prototype=x3dom.extend([]),x3dom.fields.MFBoolean.copy=function(e){var t=new x3dom.fields.MFBoolean;return e.map((function(e){t.push(e)}),this),t},x3dom.fields.MFBoolean.parse=function(e){for(var t=e.match(/(true|false|1|0)/gi),i=[],o=0,s=t?t.length:0;o<s;o++)i.push("1"==t[o]||"true"==t[o].toLowerCase());return new x3dom.fields.MFBoolean(i)},x3dom.fields.MFBoolean.prototype.copy=function(){return x3dom.fields.MFBoolean.copy(this)},x3dom.fields.MFBoolean.prototype.setValueByStr=function(e){this.length=0;for(var t=e.match(/(true|false|1|0)/gi),i=0,o=t?t.length:0;i<o;i++)this.push("1"==t[i]||"true"==t[i].toLowerCase())},x3dom.fields.MFBoolean.prototype.toGL=function(){var e=[];return this.map((function(t){e.push(t?1:0)})),e},x3dom.fields.MFString=function(e){if(e&&e.map){var t=this;e.map((function(e){t.push(e)}),this)}},x3dom.fields.MFString.prototype=x3dom.extend([]),x3dom.fields.MFString.copy=function(e){var t=new x3dom.fields.MFString;return e.map((function(e){t.push(e)}),this),t},x3dom.fields.MFString.parse=function(e){var t=[];if((e=e.trim()).length&&'"'==e[0])for(var i,o=/"((?:[^\\"]|\\\\|\\")*)"/g;i=o.exec(e);){var s=i[1].replace(/\\([\\"])/g,"$1");void 0!==s&&t.push(s)}else t.push(e);return new x3dom.fields.MFString(t)},x3dom.fields.MFString.prototype.copy=function(){return x3dom.fields.MFString.copy(this)},x3dom.fields.MFString.prototype.setValueByStr=function(e){if(this.length=0,e.length&&'"'==e[0])for(var t,i=/"((?:[^\\"]|\\\\|\\")*)"/g;t=i.exec(e);){var o=t[1].replace(/\\([\\"])/,"$1");void 0!==o&&this.push(o)}else this.push(e);return this},x3dom.fields.MFString.prototype.toString=function(){for(var e="",t=0,i=this.length;t<i;t++)e=e+this[t]+" ";return e},x3dom.fields.SFNode=function(e){this.type=e,this.node=null},x3dom.fields.SFNode.prototype.hasLink=function(e){return e?this.node===e:this.node},x3dom.fields.SFNode.prototype.addLink=function(e){return this.node=e,!0},x3dom.fields.SFNode.prototype.rmLink=function(e){return this.node===e&&(this.node=null,!0)},x3dom.fields.MFNode=function(e){this.type=e,this.nodes=[]},x3dom.fields.MFNode.prototype.hasLink=function(e){if(!e)return this.length>0;for(var t=0,i=this.nodes.length;t<i;t++)if(this.nodes[t]===e)return!0;return!1},x3dom.fields.MFNode.prototype.addLink=function(e){return this.nodes.push(e),!0},x3dom.fields.MFNode.prototype.rmLink=function(e){for(var t=0,i=this.nodes.length;t<i;t++)if(this.nodes[t]===e)return this.nodes.splice(t,1),!0;return!1},x3dom.fields.MFNode.prototype.length=function(){return this.nodes.length},x3dom.fields.Line=function(e,t){0===arguments.length&&(this.pos=new x3dom.fields.SFVec3f(0,0,0),this.dir=new x3dom.fields.SFVec3f(0,0,1)),this.pos=x3dom.fields.SFVec3f.copy(e),this.dir=x3dom.fields.SFVec3f.copy(t)},x3dom.fields.Line.prototype.closestPoint=function(e){var t=e.subtract(this.pos).dot(this.dir);return this.pos.add(this.dir.multiply(t))},x3dom.fields.Line.prototype.shortestDistance=function(e){var t=e.subtract(this.pos),i=t.dot(this.dir);return t.subtract(this.dir.multiply(i)).length()},x3dom.fields.Ray=function(e,t){if(0===arguments.length)this.pos=new x3dom.fields.SFVec3f(0,0,0),this.dir=new x3dom.fields.SFVec3f(0,0,1);else{this.pos=new x3dom.fields.SFVec3f(e.x,e.y,e.z);var i=t.length();i&&(i=1/i),this.dir=new x3dom.fields.SFVec3f(t.x*i,t.y*i,t.z*i)}this.enter=0,this.exit=0,this.hitObject=null,this.hitPoint={},this.dist=Number.MAX_VALUE},x3dom.fields.Ray.prototype.toString=function(){return"Ray: ["+this.pos.toString()+"; "+this.dir.toString()+"]"},x3dom.fields.Ray.prototype.intersectPlane=function(e,t){var i,o=null,s=t.dot(this.dir);return s<0&&(i=(e.dot(t)-this.pos.dot(t))/s,o=this.pos.addScaled(this.dir,i)),o},x3dom.fields.Ray.prototype.intersect=function(e,t){var i,o,s,r=0,n=Number.MAX_VALUE;if(this.dir.x>x3dom.fields.Eps)i=1/this.dir.x,o=(e.x-this.pos.x)*i,(s=(t.x-this.pos.x)*i)<n&&(n=s),o>r&&(r=o);else if(this.dir.x<-x3dom.fields.Eps)i=1/this.dir.x,o=(t.x-this.pos.x)*i,(s=(e.x-this.pos.x)*i)<n&&(n=s),o>r&&(r=o);else if(this.pos.x<e.x||this.pos.x>t.x)return!1;if(this.dir.y>x3dom.fields.Eps){if(i=1/this.dir.y,o=(e.y-this.pos.y)*i,(s=(t.y-this.pos.y)*i)<n&&(n=s),o>r&&(r=o),r-n>=x3dom.fields.Eps)return!1}else if(this.dir.y<-x3dom.fields.Eps){if(i=1/this.dir.y,o=(t.y-this.pos.y)*i,(s=(e.y-this.pos.y)*i)<n&&(n=s),o>r&&(r=o),r-n>=x3dom.fields.Eps)return!1}else if(this.pos.y<e.y||this.pos.y>t.y)return!1;if(this.dir.z>x3dom.fields.Eps)i=1/this.dir.z,o=(e.z-this.pos.z)*i,(s=(t.z-this.pos.z)*i)<n&&(n=s),o>r&&(r=o);else if(this.dir.z<-x3dom.fields.Eps)i=1/this.dir.z,o=(t.z-this.pos.z)*i,(s=(e.z-this.pos.z)*i)<n&&(n=s),o>r&&(r=o);else if(this.pos.z<e.z||this.pos.z>t.z)return!1;return this.enter=r,this.exit=n,r-n<x3dom.fields.Eps},x3dom.fields.BoxVolume=function(e,t){arguments.length<2?(this.min=new x3dom.fields.SFVec3f(0,0,0),this.max=new x3dom.fields.SFVec3f(0,0,0),this.valid=!1):(this.min=x3dom.fields.SFVec3f.copy(e),this.max=x3dom.fields.SFVec3f.copy(t),this.valid=!0),this.updateInternals()},x3dom.fields.BoxVolume.prototype.getScalarValue=function(){var e=this.max.subtract(this.min);return e.x*e.y*e.z},x3dom.fields.BoxVolume.copy=function(e){var t=new x3dom.fields.BoxVolume(e.min,e.max);return t.valid=e.valid,t},x3dom.fields.BoxVolume.prototype.equals=function(e){return this.min.equals(e.min,1e-12)&&this.max.equals(e.max,1e-12)},x3dom.fields.BoxVolume.prototype.updateInternals=function(){this.radialVec=this.max.subtract(this.min).multiply(.5),this.center=this.min.add(this.radialVec),this.diameter=2*this.radialVec.length()},x3dom.fields.BoxVolume.prototype.setBounds=function(e,t){this.min.setValues(e),this.max.setValues(t),this.updateInternals(),this.valid=!0},x3dom.fields.BoxVolume.prototype.setBoundsByCenterSize=function(e,t){var i=t.multiply(.5);this.min=e.subtract(i),this.max=e.add(i),this.updateInternals(),this.valid=!0},x3dom.fields.BoxVolume.prototype.extendBounds=function(e,t){this.valid?(this.min.x>e.x&&(this.min.x=e.x),this.min.y>e.y&&(this.min.y=e.y),this.min.z>e.z&&(this.min.z=e.z),this.max.x<t.x&&(this.max.x=t.x),this.max.y<t.y&&(this.max.y=t.y),this.max.z<t.z&&(this.max.z=t.z),this.updateInternals()):this.setBounds(e,t)},x3dom.fields.BoxVolume.prototype.getBounds=function(e,t){e.setValues(this.min),t.setValues(this.max)},x3dom.fields.BoxVolume.prototype.getRadialVec=function(){return this.radialVec},x3dom.fields.BoxVolume.prototype.invalidate=function(){this.valid=!1,this.min=new x3dom.fields.SFVec3f(0,0,0),this.max=new x3dom.fields.SFVec3f(0,0,0),this.updateInternals()},x3dom.fields.BoxVolume.prototype.isValid=function(){return this.valid},x3dom.fields.BoxVolume.prototype.getCenter=function(){return this.center},x3dom.fields.BoxVolume.prototype.getDiameter=function(){return this.diameter},x3dom.fields.BoxVolume.prototype.transform=function(e){var t,i,o,s,r,n;t=s=e._03,i=r=e._13,o=n=e._23;var a=this.max.x*e._00,d=this.min.x*e._00;a>=d?(s+=a,t+=d):(s+=d,t+=a),(a=this.max.y*e._01)>=(d=this.min.y*e._01)?(s+=a,t+=d):(s+=d,t+=a),(a=this.max.z*e._02)>=(d=this.min.z*e._02)?(s+=a,t+=d):(s+=d,t+=a),(a=this.max.x*e._10)>=(d=this.min.x*e._10)?(r+=a,i+=d):(r+=d,i+=a),(a=this.max.y*e._11)>=(d=this.min.y*e._11)?(r+=a,i+=d):(r+=d,i+=a),(a=this.max.z*e._12)>=(d=this.min.z*e._12)?(r+=a,i+=d):(r+=d,i+=a),(a=this.max.x*e._20)>=(d=this.min.x*e._20)?(n+=a,o+=d):(n+=d,o+=a),(a=this.max.y*e._21)>=(d=this.min.y*e._21)?(n+=a,o+=d):(n+=d,o+=a),(a=this.max.z*e._22)>=(d=this.min.z*e._22)?(n+=a,o+=d):(n+=d,o+=a),this.min.x=t,this.min.y=i,this.min.z=o,this.max.x=s,this.max.y=r,this.max.z=n,this.updateInternals()},x3dom.fields.BoxVolume.prototype.transformFrom=function(e,t){var i,o,s,r,n,a;i=r=e._03,o=n=e._13,s=a=e._23;var d=t.max.x*e._00,l=t.min.x*e._00;d>=l?(r+=d,i+=l):(r+=l,i+=d),(d=t.max.y*e._01)>=(l=t.min.y*e._01)?(r+=d,i+=l):(r+=l,i+=d),(d=t.max.z*e._02)>=(l=t.min.z*e._02)?(r+=d,i+=l):(r+=l,i+=d),(d=t.max.x*e._10)>=(l=t.min.x*e._10)?(n+=d,o+=l):(n+=l,o+=d),(d=t.max.y*e._11)>=(l=t.min.y*e._11)?(n+=d,o+=l):(n+=l,o+=d),(d=t.max.z*e._12)>=(l=t.min.z*e._12)?(n+=d,o+=l):(n+=l,o+=d),(d=t.max.x*e._20)>=(l=t.min.x*e._20)?(a+=d,s+=l):(a+=l,s+=d),(d=t.max.y*e._21)>=(l=t.min.y*e._21)?(a+=d,s+=l):(a+=l,s+=d),(d=t.max.z*e._22)>=(l=t.min.z*e._22)?(a+=d,s+=l):(a+=l,s+=d),this.min.x=i,this.min.y=o,this.min.z=s,this.max.x=r,this.max.y=n,this.max.z=a,this.updateInternals(),this.valid=!0},x3dom.fields.FrustumVolume=function(e){if(this.planeNormals=[],this.planeDistances=[],this.directionIndex=[],0!==arguments.length){for(var t=[],i=0;i<6;i++)this.planeNormals[i]=new x3dom.fields.SFVec3f(0,0,0),this.planeDistances[i]=0,this.directionIndex[i]=0,t[i]=new x3dom.fields.SFVec4f(0,0,0,0);for(t[0].x=e._30-e._00,t[0].y=e._31-e._01,t[0].z=e._32-e._02,t[0].w=e._33-e._03,t[1].x=e._30+e._00,t[1].y=e._31+e._01,t[1].z=e._32+e._02,t[1].w=e._33+e._03,t[2].x=e._30+e._10,t[2].y=e._31+e._11,t[2].z=e._32+e._12,t[2].w=e._33+e._13,t[3].x=e._30-e._10,t[3].y=e._31-e._11,t[3].z=e._32-e._12,t[3].w=e._33-e._13,t[4].x=e._30+e._20,t[4].y=e._31+e._21,t[4].z=e._32+e._22,t[4].w=e._33+e._23,t[5].x=e._30-e._20,t[5].y=e._31-e._21,t[5].z=e._32-e._22,t[5].w=e._33-e._23,i=0;i<6;i++){var o=Math.sqrt(t[i].x*t[i].x+t[i].y*t[i].y+t[i].z*t[i].z);t[i].x/=o,t[i].y/=o,t[i].z/=o,t[i].w/=-o}var s=function(e){var t=0;return e.x>0&&(t|=1),e.y>0&&(t|=2),e.z>0&&(t|=4),t};this.planeNormals[3].setValues(t[0]),this.planeDistances[3]=t[0].w,this.directionIndex[3]=s(this.planeNormals[3]),this.planeNormals[2].setValues(t[1]),this.planeDistances[2]=t[1].w,this.directionIndex[2]=s(this.planeNormals[2]),this.planeNormals[5].setValues(t[2]),this.planeDistances[5]=t[2].w,this.directionIndex[5]=s(this.planeNormals[5]),this.planeNormals[4].setValues(t[3]),this.planeDistances[4]=t[3].w,this.directionIndex[4]=s(this.planeNormals[4]),this.planeNormals[0].setValues(t[4]),this.planeDistances[0]=t[4].w,this.directionIndex[0]=s(this.planeNormals[0]),this.planeNormals[1].setValues(t[5]),this.planeDistances[1]=t[5].w,this.directionIndex[1]=s(this.planeNormals[1])}},x3dom.fields.FrustumVolume.prototype.intersect=function(e,t){if(this.planeNormals.length<6)return x3dom.debug.logWarning("FrustumVolume not initialized!"),!1;var i=this,o=e.min,s=e.max,r=function(e){var t=new x3dom.fields.SFVec3f(0,0,0);return t.x=1&e?o.x:s.x,t.y=2&e?o.y:s.y,t.z=4&e?o.z:s.z,t},n=function(e,t){return i.planeNormals[e].dot(t)-i.planeDistances[e]>=0},a=function(e){var t=r(i.directionIndex[e]);return n(e,t)},d=function(e){var t=r(7^i.directionIndex[e]);return!n(e,t)},l=1;t<0&&(t=0);for(var h=0;h<6;h++,l<<=1)if(0==(t&l)){if(d(h))return-1;a(h)&&(t|=l)}return t},x3dom.BindableStack=function(e,t,i,o){this._doc=e,this._type=t,this._defaultType=i,this._defaultRoot=null,this._getter=o,this._bindBag=[],this._bindStack=[]},x3dom.BindableStack.prototype.top=function(){return this._bindStack.length>0?this._bindStack[this._bindStack.length-1]:null},x3dom.BindableStack.prototype.push=function(e){var t=this.top();t!==e&&(t&&t.deactivate(),this._bindStack.push(e),e.activate(t))},x3dom.BindableStack.prototype.replaceTop=function(e){var t=this.top();t!==e&&t&&(t.deactivate(),this._bindStack[this._bindStack.length-1]=e,e.activate(t))},x3dom.BindableStack.prototype.pop=function(e){var t;return e&&e!==(t=this.top())?null:((t=this._bindStack.pop())&&t.deactivate(),t)},x3dom.BindableStack.prototype.switchTo=function(e){var t=this.getActive(),i=this._bindBag.length,o=0,s=0,r=-1;if(!(i<=1)){switch(e){case"first":o=this._bindBag[0];break;case"last":o=this._bindBag[i-1];break;default:for(s=0;s<i;s++)if(this._bindBag[s]==t){r=s;break}if(r>=0)for(s=r;!o&&(s="next"==e?s<i-1?s+1:0:s>0?s-1:i-1)!=r;)this._bindBag[s]._vf.description.length>=0&&(o=this._bindBag[s])}o?this.replaceTop(o):x3dom.debug.logWarning("Cannot switch bindable; no other bindable with description found.")}},x3dom.BindableStack.prototype.getActive=function(){if(0===this._bindStack.length){if(0===this._bindBag.length)if(this._defaultRoot){x3dom.debug.logInfo("create new "+this._defaultType._typeName+" for "+this._type._typeName+"-stack");var e=new this._defaultType({doc:this._doc,nameSpace:this._defaultRoot._nameSpace,autoGen:!0});this._defaultRoot.addChild(e),e.nodeChanged()}else x3dom.debug.logError("stack without defaultRoot");else x3dom.debug.logInfo("activate first "+this._type._typeName+" for "+this._type._typeName+"-stack");this._bindStack.push(this._bindBag[0]),this._bindBag[0].activate()}return this._bindStack[this._bindStack.length-1]},x3dom.BindableBag=function(e){this._stacks=[],this.addType("X3DViewpointNode","Viewpoint","getViewpoint",e),this.addType("X3DNavigationInfoNode","NavigationInfo","getNavigationInfo",e),this.addType("X3DBackgroundNode","Background","getBackground",e),this.addType("X3DFogNode","Fog","getFog",e),this.addType("X3DEnvironmentNode","Environment","getEnvironment",e)},x3dom.BindableBag.prototype.addType=function(e,t,i,o){var s=x3dom.nodeTypes[e],r=x3dom.nodeTypes[t];if(s&&r){var n=new x3dom.BindableStack(o,s,r,i);this._stacks.push(n)}else x3dom.debug.logWarning("Invalid Bindable type/defaultType: "+e+"/"+r)},x3dom.BindableBag.prototype.setRefNode=function(e){this._stacks.forEach((function(t){t._defaultRoot=e,e[t._getter]=function(){return t.getActive()}}))},x3dom.BindableBag.prototype.addBindable=function(e){for(var t=0,i=this._stacks.length;t<i;t++){var o=this._stacks[t];if(x3dom.isa(e,o._type)){x3dom.debug.logInfo("register "+e.typeName()+"Bindable "+e._DEF+"/"+e._vf.description),o._bindBag.push(e);var s=o.top();if(s&&s._autoGen){o.replaceTop(e);for(var r=0,n=o._bindBag.length;r<n;r++)if(o._bindBag[r]===s){o._bindBag.splice(r,1);break}o._defaultRoot.removeChild(s)}return o}}return x3dom.debug.logError(e.typeName()+" is not a valid bindable"),null},x3dom.NodeNameSpace=function(e,t){this.name=e,this.doc=t,this.baseURL="",this.defMap={},this.parent=null,this.childSpaces=[],this.protos=[],this.lateRoutes=[]},x3dom.NodeNameSpace.prototype.addNode=function(e,t){this.defMap[t]=e,e._nameSpace=this},x3dom.NodeNameSpace.prototype.removeNode=function(e){var t=e?this.defMap[e]:null;t&&(delete this.defMap[e],t._nameSpace=null)},x3dom.NodeNameSpace.prototype.getNamedNode=function(e){return this.defMap[e]},x3dom.NodeNameSpace.prototype.getNamedElement=function(e){var t=this.defMap[e];return t?t._xmlNode:null},x3dom.NodeNameSpace.prototype.addSpace=function(e){this.childSpaces.push(e),e.parent=this},x3dom.NodeNameSpace.prototype.removeSpace=function(e){e.parent=null;for(var t=0;t<this.childSpaces.length;t++)this.childSpaces[t]==e&&this.childSpaces.splice(t,1)},x3dom.NodeNameSpace.prototype.setBaseURL=function(e){var t=e.lastIndexOf("/");this.baseURL=t>=0?e.substr(0,t+1):"",x3dom.debug.logInfo("setBaseURL: "+this.baseURL)},x3dom.NodeNameSpace.prototype.getURL=function(e){return void 0!==e&&e.length?"/"===e[0]||e.indexOf(":")>=0?e:this.baseURL+e:""},x3dom.hasElementAttribute=function(e){var t=this.__hasAttribute(e);return!t&&e&&(t=this.__hasAttribute(e.toLowerCase())),t},x3dom.getElementAttribute=function(e){var t=this.__getAttribute(e);return!t&&""!=t&&e&&(t=this.__getAttribute(e.toLowerCase())),t||!this._x3domNode?t:this._x3domNode._vf[e]},x3dom.setElementAttribute=function(e,t){this.__setAttribute(e,t);var i=this._x3domNode;i&&(i.updateField(e,t),i._nameSpace.doc.needRender=!0)},x3dom.getFieldValue=function(e){var t=this._x3domNode;if(t&&void 0!==t._vf[e]){var i=t._vf[e];return i instanceof Object&&"copy"in i?t._vf[e].copy():t._vf[e]}return null},x3dom.setFieldValue=function(e,t){var i=this._x3domNode;i&&void 0!==i._vf[e]&&(t instanceof Object&&"copy"in t?i._vf[e]=t.copy():i._vf[e]=t,i.fieldChanged(e),i._nameSpace.doc.needRender=!0)},x3dom.requestFieldRef=function(e){var t=this._x3domNode;return t&&t._vf[e]?t._vf[e]:null},x3dom.releaseFieldRef=function(e){var t=this._x3domNode;t&&t._vf[e]&&(t.fieldChanged(e),t._nameSpace.doc.needRender=!0)},x3dom.NodeNameSpace.prototype.setupTree=function(e,t){var i=null;if(t=t||null,x3dom.isX3DElement(e)){if(e._x3domNode)return x3dom.debug.logWarning("Tree is already initialized"),null;if(void 0===e.tagName||e.__addEventListener||e.__removeEventListener||(e.__addEventListener=e.addEventListener,e.addEventListener=function(e,t,i){this._x3domNode._listeners[e]||(this._x3domNode._listeners[e]=[]),this._x3domNode._listeners[e].push(t),this.__addEventListener(e,t,i)},e.__removeEventListener=e.removeEventListener,e.removeEventListener=function(e,t,i){var o=this._x3domNode._listeners[e];if(o)for(var s=0;s<o.length;s++)o[s]==t&&(o.splice(s,1),s--);this.__removeEventListener(e,t,i)}),e.hasAttribute("USE")||e.hasAttribute("use")){if(e.hasAttribute("USE")||e.setAttribute("USE",e.getAttribute("use")),!(i=this.defMap[e.getAttribute("USE")])){var o=e.getAttribute("USE").split("__");if(o.length>=2){for(var s=this;s;)s.name==o[0]&&(i=s.defMap[o[1]]),s=i?null:s.parent;i||(i=null,x3dom.debug.logWarning("Could not USE: "+e.getAttribute("USE")))}}return i&&(e._x3domNode=i),i}if("route"===e.localName.toLowerCase()){var r=e,n=r.getAttribute("fromNode")||r.getAttribute("fromnode"),a=r.getAttribute("toNode")||r.getAttribute("tonode"),d=this.defMap[n],l=this.defMap[a],h=r.getAttribute("fromField")||r.getAttribute("fromfield"),f=r.getAttribute("toField")||r.getAttribute("tofield");return d&&l?(d.setupRoute(h,l,f),r._nodeNameSpace=this):(x3dom.debug.logWarning("not yet available route - can't find all DEFs for "+h+" -> "+f),this.lateRoutes.push({route:r,fnDEF:n,tnDEF:a,fnAtt:h,tnAtt:f})),null}e.requestFieldRef=x3dom.requestFieldRef,e.releaseFieldRef=x3dom.releaseFieldRef,e.getFieldValue=x3dom.getFieldValue,e.setFieldValue=x3dom.setFieldValue;var u=x3dom.nodeTypesLC[e.localName.toLowerCase()];if(void 0!==u){!1===x3dom.userAgentFeature.supportsDOMAttrModified&&e instanceof Element&&(e.setAttribute&&!e.__setAttribute&&(e.__setAttribute=e.setAttribute,e.setAttribute=x3dom.setElementAttribute),e.getAttribute&&!e.__getAttribute&&(e.__getAttribute=e.getAttribute,e.getAttribute=x3dom.getElementAttribute),e.hasAttribute&&!e.__hasAttribute&&(e.__hasAttribute=e.hasAttribute,e.hasAttribute=x3dom.hasElementAttribute));var c={doc:this.doc,runtime:this.doc._x3dElem.runtime,xmlNode:e,nameSpace:this};return i=new u(c),e.hasAttribute("DEF")?(i._DEF=e.getAttribute("DEF"),this.defMap[i._DEF]=i):e.hasAttribute("id")&&(i._DEF=e.getAttribute("id"),i._DEF in this.defMap||(this.defMap[i._DEF]=i)),void 0===e.highlight&&(e.highlight=function(e,t){var i=x3dom.fields.SFColor.parse(t);this._x3domNode.highlight(e,i),this._x3domNode._nameSpace.doc.needRender=!0}),i._xmlNode=e,e._x3domNode=i,e.querySelectorAll(":scope > *").forEach((function(t){var i=t.localName.toLowerCase();"protodeclare"==i?this.protoDeclare(t):"externprotodeclare"==i?this.externProtoDeclare(t):"protoinstance"==i&&this.protoInstance(t,e)}),this),e.childNodes.forEach((function(e){var t=this.setupTree(e,i);t&&i.addChild(t,e.getAttribute("containerField"))}),this),i.nodeChanged(),i}x3dom.debug.logWarning("Unrecognised X3D element &lt;"+e.localName+"&gt;.")}else if(e.localName){var _=e.localName.toLowerCase(),m=this.protos.find((function(e){return _==e.name.toLowerCase()&&e.isExternProto}));t&&"x3dommetagroup"==_?e.childNodes.forEach(function(e){var i=this.setupTree(e,t);i&&t.addChild(i,e.getAttribute("containerField"))}.bind(this)):"protodeclare"==_||"externprotodeclare"==_||"protoinstance"==_?i=null:"is"==e.localName.toLowerCase()?0==e.querySelectorAll("connect").length&&x3dom.debug.logWarning("IS statement without connect link: "+e.parentElement.localName):m?this.loadExternProtoAsync(m,e,e,e.parentElement):(x3dom.debug.logWarning("Unrecognised X3D element &lt;"+e.localName+"&gt;."),i=null)}return i},x3dom.NodeNameSpace.prototype.protoInstance=function(e,t){if(e.localName&&!e._x3dom){var i=e.getAttribute("name");if(e.hasAttribute("USE")){var o=e.getAttribute("USE"),s=this.defMap[o];i=s?s.constructor._typeName:t.getRootNode().querySelector("[DEF="+o+"]").getAttribute("name")}var r=this.protos.find((function(e){return e.name==i}));if(null!=r){var n=document.createElement(i);if(e.hasAttribute("DEF")?n.setAttribute("DEF",e.getAttribute("DEF")):e.hasAttribute("USE")&&n.setAttribute("USE",e.getAttribute("USE")),e.hasAttribute("containerField")&&n.setAttribute("containerField",e.getAttribute("containerField")),e.querySelectorAll(":scope > fieldValue , :scope > fieldvalue").forEach((function(e){var t=e.getAttribute("name"),i=e.querySelectorAll(":scope > *");if(i.length>0)i.forEach((function(e){e.setAttribute("containerField",t),n.appendChild(e)}));else{var o=e.getAttribute("value");o&&n.setAttribute(t,o)}})),r.isExternProto&&r.needsLoading)this.loadExternProtoAsync(r,n,e,t);else{this.doc.mutationObserver.disconnect(),e.insertAdjacentElement("afterend",n);var a=this.doc._x3dElem;this.doc._scene&&(a=this.doc._scene._xmlNode),this.doc.mutationObserver.observe(a,{attributes:!0,attributeOldValue:!0,childList:!0,subtree:!0}),e._x3dom=n}}else x3dom.debug.logWarning("ProtoInstance without a ProtoDeclaration "+i)}},x3dom.NodeNameSpace.prototype.loadExternProtoAsync=function(e,t,i,o){e.instanceQueue.push({protoInstanceDom:t,domNode:i,parentDom:o}),i._x3dom=t;var s=this,r=this.getURL(e.url[0]);fetch(r).then((function(e){return e.text()})).then((function(t){var i=new DOMParser,o=i.parseFromString(t,"application/xml"),n=o.querySelector("X3D");null==n&&(n=(o=i.parseFromString(responseText,"text/html")).querySelector("X3D"));var a=r.includes("#")?r.split("#").slice(-1)[0]:"",d=""==a?"ProtoDeclare":"ProtoDeclare[name='"+a+"']",l=n.querySelector(d);l.setAttribute("name",e.name);var h,f=s.protos.findIndex((function(t){return t==e}));for(s.protos.splice(f,1),s.protoDeclare(l);h=e.instanceQueue.shift();)s.doc.mutationObserver.disconnect(),h.domNode!==h.protoInstanceDom&&h.domNode.insertAdjacentElement("afterend",h.protoInstanceDom),s.doc.mutationObserver.observe(s.doc._scene._xmlNode,{attributes:!0,attributeOldValue:!0,childList:!0,subtree:!0}),s.doc.onNodeAdded(h.protoInstanceDom,h.parentDom),s.lateRoutes.forEach((function(e){var t=s.defMap[e.fnDEF],i=s.defMap[e.tnDEF];t&&i&&(x3dom.debug.logInfo("fixed ROUTE: from="+t._DEF+", to="+i._DEF),t.setupRoute(e.fnAtt,i,e.tnAtt),e.route._nodeNameSpace=s)}));e.needsLoading=!1})).catch((function(t){return x3dom.debug.logError("ExternProto fetch failed: "+t),e.needsLoading=!1,null}))},x3dom.NodeNameSpace.prototype.externProtoDeclare=function(e){var t=e.getAttribute("name"),i=x3dom.fields.MFString.parse(e.getAttribute("url")),o=new x3dom.ProtoDeclaration(this,t,null,null,!0,i);this.protos.push(o)},x3dom.NodeNameSpace.prototype.protoDeclare=function(e){var t=e.getAttribute("name"),i=e.querySelector("ProtoInterface"),o=[];i&&i.querySelectorAll("field").forEach((function(e){o.push({name:e.getAttribute("name"),accessType:e.getAttribute("accessType"),dataType:e.getAttribute("type"),value:e.getAttribute("value"),cfValue:e.querySelectorAll(":scope > *")})}));var s=e.querySelector("ProtoBody");if(s){s._ISRoutes={},s.querySelectorAll("IS").forEach((function(e){for(var t=e.parentElement;"protobody"!==t.localName.toLowerCase();)t=t.parentElement;t===s&&e.querySelectorAll("connect").forEach((function(t){var i=e.parentElement;if(0==i.hasAttribute("DEF")){var o="_proto_"+i.tagName+"_"+x3dom.protoISDEFuid++;i.setAttribute("DEF",o),"protoinstance"==i.localName.toLowerCase()&&i._x3domNode&&(i._x3domNode._DEF=o,i._x3domNode.typeNode._nameSpace.defMap[o]=i._x3domNode)}var r=t.getAttribute("protoField"),n=i.getAttribute("DEF"),a=t.getAttribute("nodeField");s._ISRoutes[r]||(s._ISRoutes[r]=[]),s._ISRoutes[r].push({nodeDEF:n,nodeField:a})}))}));var r=new x3dom.ProtoDeclaration(this,t,s,o);r.registerNode(),this.protos.push(r)}else x3dom.debug.logWarning("ProtoDeclare without a ProtoBody definition: "+e.name);return"ProtoDeclare"},x3dom.protoISDEFuid=0,x3dom.gfx_webgl=function(){"use strict";function e(e,t,i,o){this.ctx3d=e,this.canvas=t,this.name=i,this.x3dElem=o,this.IG_PositionBuffer=null,this.cache=new x3dom.Cache,this.stateManager=new x3dom.StateManager(e),this.VRMode=1,this.vrFrameData=null,this.BUFFER_IDX={INDEX:0,POSITION:1,NORMAL:2,TEXCOORD:3,TEXCOORD_0:3,COLOR:4,TANGENT:6,BITANGENT:7,TEXCOORD_1:8,ID:9}}return e.prototype.getName=function(){return this.name},e.prototype.setupShape=function(e,t,i){var o,s,r,n,a,d,l,h,f,u,c,_,m=0,p=t.shape,x=p._cf.geometry.node;if(void 0!==p._webgl){var g=!1;if(!0===p._dirty.colors&&void 0===p._webgl.shader.color&&x._mesh._colors[0].length&&(g=!0),g&&p._cleanupGLObjects&&p._cleanupGLObjects(!0,!1),!0===p._dirty.texture){if(p._webgl.texture.length!=p.getTextures().length){for(r=0;r<p._webgl.texture.length;++r)p._webgl.texture.pop();for(s=p.getTextures(),r=0;r<s.length;++r)p._webgl.texture.push(new x3dom.Texture(e,p._nameSpace.doc,this.cache,s[r]));p._dirty.shader=!0,void 0===p._webgl.shader.texcoord&&(p._dirty.texcoords=!0)}else for(s=p.getTextures(),r=0;r<s.length;++r)s[r]===p._webgl.texture[r].node?p._webgl.texture[r].update():(p._webgl.texture[r].texture=null,p._webgl.texture[r].node=s[r],p._webgl.texture[r].update());p._dirty.texture=!1}if(p._webgl.shader=this.cache.getShaderByProperties(e,p,p.getShaderProperties(i)),!g&&0==p._webgl.binaryGeometry&&0==p._webgl.bufferGeometry)for(m=0;m<p._webgl.positions.length;m++)if(o=6*m,1!=p._dirty.positions&&1!=p._dirty.indexes||(void 0!==p._webgl.shader.position&&(p._webgl.indexes[m]=x._mesh._indices[m],e.deleteBuffer(p._webgl.buffers[o+x3dom.BUFFER_IDX.INDEX]),f=e.createBuffer(),p._webgl.buffers[o+x3dom.BUFFER_IDX.INDEX]=f,x3dom.caps.INDEX_UINT&&x._mesh._positions[0].length/3>65535?(u=new Uint32Array(p._webgl.indexes[m]),p._webgl.indexType=e.UNSIGNED_INT):(u=new Uint16Array(p._webgl.indexes[m]),p._webgl.indexType=e.UNSIGNED_SHORT),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,f),e.bufferData(e.ELEMENT_ARRAY_BUFFER,u,e.STATIC_DRAW),u=null,p._webgl.positions[m]=x._mesh._positions[m],e.deleteBuffer(p._webgl.buffers[o+x3dom.BUFFER_IDX.POSITION]),a=e.createBuffer(),p._webgl.buffers[o+x3dom.BUFFER_IDX.POSITION]=a,e.bindBuffer(e.ARRAY_BUFFER,a),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,p._webgl.buffers[o+x3dom.BUFFER_IDX.INDEX]),n=new Float32Array(p._webgl.positions[m]),e.bufferData(e.ARRAY_BUFFER,n,e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,a),e.vertexAttribPointer(p._webgl.shader.position,x._mesh._numPosComponents,p._webgl.coordType,!1,p._coordStrideOffset[0],p._coordStrideOffset[1]),n=null),p._dirty.positions=!1,p._dirty.indexes=!1),1==p._dirty.colors&&(void 0!==p._webgl.shader.color&&(p._webgl.colors[m]=x._mesh._colors[m],e.deleteBuffer(p._webgl.buffers[o+x3dom.BUFFER_IDX.COLOR]),_=e.createBuffer(),p._webgl.buffers[o+x3dom.BUFFER_IDX.COLOR]=_,M=new Float32Array(p._webgl.colors[m]),e.bindBuffer(e.ARRAY_BUFFER,_),e.bufferData(e.ARRAY_BUFFER,M,e.STATIC_DRAW),e.vertexAttribPointer(p._webgl.shader.color,x._mesh._numColComponents,p._webgl.colorType,!1,p._colorStrideOffset[0],p._colorStrideOffset[1]),M=null),p._dirty.colors=!1),1==p._dirty.normals&&(void 0!==p._webgl.shader.normal&&(p._webgl.normals[m]=x._mesh._normals[m],e.deleteBuffer(p._webgl.buffers[o+x3dom.BUFFER_IDX.NORMAL]),c=e.createBuffer(),p._webgl.buffers[o+x3dom.BUFFER_IDX.NORMAL]=c,S=new Float32Array(p._webgl.normals[m]),e.bindBuffer(e.ARRAY_BUFFER,c),e.bufferData(e.ARRAY_BUFFER,S,e.STATIC_DRAW),e.vertexAttribPointer(p._webgl.shader.normal,x._mesh._numNormComponents,p._webgl.normalType,!1,p._normalStrideOffset[0],p._normalStrideOffset[1]),S=null),p._dirty.normals=!1),1==p._dirty.texcoords&&(void 0!==p._webgl.shader.texcoord&&(p._webgl.texcoords[m]=x._mesh._texCoords[m],e.deleteBuffer(p._webgl.buffers[o+x3dom.BUFFER_IDX.TEXCOORD]),d=e.createBuffer(),p._webgl.buffers[o+x3dom.BUFFER_IDX.TEXCOORD]=d,E=new Float32Array(p._webgl.texcoords[m]),e.bindBuffer(e.ARRAY_BUFFER,d),e.bufferData(e.ARRAY_BUFFER,E,e.STATIC_DRAW),e.vertexAttribPointer(p._webgl.shader.texCoord,x._mesh._numTexComponents,p._webgl.texCoordType,!1,p._texCoordStrideOffset[0],p._texCoordStrideOffset[1]),E=null),p._dirty.texcoords=!1),1==p._dirty.specialAttribs&&void 0!==p._webgl.shader.particleSize){var v=x._vf.size.toGL();v.length&&(e.deleteBuffer(p._webgl.buffers[o+x3dom.BUFFER_IDX.ID]),p._webgl.buffers[o+x3dom.BUFFER_IDX.ID]=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,p._webgl.buffers[o+x3dom.BUFFER_IDX.ID]),e.bufferData(e.ARRAY_BUFFER,new Float32Array(v),e.STATIC_DRAW)),p._dirty.specialAttribs=!1}if(!g)return}else if(!(x3dom.isa(x,x3dom.nodeTypes.Text)||x3dom.isa(x,x3dom.nodeTypes.BinaryGeometry)||x3dom.isa(x,x3dom.nodeTypes.PopGeometry)||x3dom.isa(x,x3dom.nodeTypes.BufferGeometry))&&(!x||x._mesh._positions[0].length<1))return void x3dom.debug.logError("NO VALID MESH OR NO VERTEX POSITIONS SET!");for(p.unsetDirty(),p._cleanupGLObjects||(p._cleanupGLObjects=function(t,i){if(this._webgl&&(arguments.length>0&&t||0==this._parentNodes.length)){for(var o=this._webgl.shader,s=0;s<this._webgl.positions.length;s++){var r=6*s;void 0!==o.position&&(e.deleteBuffer(this._webgl.buffers[r+x3dom.BUFFER_IDX.INDEX]),e.deleteBuffer(this._webgl.buffers[r+x3dom.BUFFER_IDX.POSITION])),void 0!==o.normal&&e.deleteBuffer(this._webgl.buffers[r+x3dom.BUFFER_IDX.NORMAL]),void 0!==o.texcoord&&e.deleteBuffer(this._webgl.buffers[r+x3dom.BUFFER_IDX.TEXCOORD]),void 0!==o.color&&e.deleteBuffer(this._webgl.buffers[r+x3dom.BUFFER_IDX.COLOR]),void 0!==o.id&&e.deleteBuffer(this._webgl.buffers[r+x3dom.BUFFER_IDX.ID]),void 0!==o.tangent&&e.deleteBuffer(this._webgl.buffers[r+x3dom.BUFFER_IDX.TANGENT]),void 0!==o.binormal&&e.deleteBuffer(this._webgl.buffers[r+x3dom.BUFFER_IDX.BITANGENT])}for(var n=0;n<this._webgl.dynamicFields.length;n++){var a=this._webgl.dynamicFields[n];void 0!==o[a.name]&&e.deleteBuffer(a.buf)}void 0===i&&(i=!0),i&&(delete this._webgl,x3dom.BinaryContainerLoader.outOfMemory=!1)}}),p._webgl={positions:x._mesh._positions,normals:x._mesh._normals,texcoords:x._mesh._texCoords,colors:x._mesh._colors,tangents:x._mesh._tangents,binormals:x._mesh._binormals,indexes:x._mesh._indices,indexType:e.UNSIGNED_SHORT,coordType:e.FLOAT,normalType:e.FLOAT,texCoordType:e.FLOAT,texCoord2Type:e.FLOAT,colorType:e.FLOAT,tangentType:e.FLOAT,binormalType:e.FLOAT,coordNormalized:!1,normalNormalized:!1,texCoordNormalized:!1,texCoord2Normalized:!1,colorNormalized:!1,tangentNormalized:!1,binormalNormalized:!1,texture:[],dirtyLighting:x3dom.Utils.checkDirtyLighting(i),binaryGeometry:0,popGeometry:0,bufferGeometry:0},s=p.getTextures(),r=0;r<s.length;++r)p._webgl.texture.push(new x3dom.Texture(e,p._nameSpace.doc,this.cache,s[r]));p._webgl.shader=this.cache.getShaderByProperties(e,p,p.getShaderProperties(i));var y=p._webgl.shader,T=0;if(p._webgl.buffers=[],p._webgl.dynamicFields=[],x3dom.isa(x,x3dom.nodeTypes.X3DBinaryContainerGeometryNode)){p._webgl.primType=[];for(var b=0;b<x._vf.primType.length;++b)p._webgl.primType.push(x3dom.Utils.primTypeDic(e,x._vf.primType[b]))}else p._webgl.primType=x3dom.Utils.primTypeDic(e,x._mesh._primType);if(x3dom.isa(x,x3dom.nodeTypes.BinaryGeometry))x3dom.BinaryContainerLoader.setupBinGeo(p,y,e,i,this);else if(x3dom.isa(x,x3dom.nodeTypes.BufferGeometry))x3dom.BinaryContainerLoader.setupBufferGeo(p,y,e,i,this);else if(x3dom.isa(x,x3dom.nodeTypes.PopGeometry))x3dom.BinaryContainerLoader.setupPopGeo(p,y,e,i,this);else{for(m=0;m<p._webgl.positions.length;m++){if(o=6*m,p._webgl.positions[m]&&(f=e.createBuffer(),p._webgl.buffers[o+x3dom.BUFFER_IDX.INDEX]=f,x3dom.caps.INDEX_UINT&&p._webgl.positions[0].length/3>65535?(u=new Uint32Array(p._webgl.indexes[m]),p._webgl.indexType=e.UNSIGNED_INT):(u=new Uint16Array(p._webgl.indexes[m]),p._webgl.indexType=e.UNSIGNED_SHORT),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,f),e.bufferData(e.ELEMENT_ARRAY_BUFFER,u,e.STATIC_DRAW),u=null,a=e.createBuffer(),p._webgl.buffers[o+x3dom.BUFFER_IDX.POSITION]=a,e.bindBuffer(e.ARRAY_BUFFER,a),n=new Float32Array(p._webgl.positions[m]),e.bufferData(e.ARRAY_BUFFER,n,e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,a),e.vertexAttribPointer(y.position,x._mesh._numPosComponents,p._webgl.coordType,!1,p._coordStrideOffset[0],p._coordStrideOffset[1]),e.enableVertexAttribArray(y.position),n=null),p._webgl.normals[m]){c=e.createBuffer(),p._webgl.buffers[o+x3dom.BUFFER_IDX.NORMAL]=c;var S=new Float32Array(p._webgl.normals[m]);e.bindBuffer(e.ARRAY_BUFFER,c),e.bufferData(e.ARRAY_BUFFER,S,e.STATIC_DRAW),e.vertexAttribPointer(y.normal,x._mesh._numNormComponents,p._webgl.normalType,!1,p._normalStrideOffset[0],p._normalStrideOffset[1]),e.enableVertexAttribArray(y.normal),S=null}if(p._webgl.texcoords[m]){var F=e.createBuffer();p._webgl.buffers[o+x3dom.BUFFER_IDX.TEXCOORD]=F;var E=new Float32Array(p._webgl.texcoords[m]);e.bindBuffer(e.ARRAY_BUFFER,F),e.bufferData(e.ARRAY_BUFFER,E,e.STATIC_DRAW),e.vertexAttribPointer(y.texcoord,x._mesh._numTexComponents,p._webgl.texCoordType,!1,p._texCoordStrideOffset[0],p._texCoordStrideOffset[1]),e.enableVertexAttribArray(y.texcoord),E=null}if(p._webgl.colors[m]){_=e.createBuffer(),p._webgl.buffers[o+x3dom.BUFFER_IDX.COLOR]=_;var M=new Float32Array(p._webgl.colors[m]);e.bindBuffer(e.ARRAY_BUFFER,_),e.bufferData(e.ARRAY_BUFFER,M,e.STATIC_DRAW),e.vertexAttribPointer(y.color,x._mesh._numColComponents,p._webgl.colorType,!1,p._colorStrideOffset[0],p._colorStrideOffset[1]),e.enableVertexAttribArray(y.color),M=null}if(void 0!==y.particleSize){var C=x._vf.size.toGL();if(C.length){var w=e.createBuffer();p._webgl.buffers[o+x3dom.BUFFER_IDX.ID]=w,e.bindBuffer(e.ARRAY_BUFFER,w),e.bufferData(e.ARRAY_BUFFER,new Float32Array(C),e.STATIC_DRAW)}}if(p._webgl.tangents[m]){l=e.createBuffer(),p._webgl.buffers[o+x3dom.BUFFER_IDX.TANGENT]=l;var A=new Float32Array(p._webgl.tangents[m]);e.bindBuffer(e.ARRAY_BUFFER,l),e.bufferData(e.ARRAY_BUFFER,A,e.STATIC_DRAW),e.vertexAttribPointer(y.tangent,x._mesh._numTangentComponents,p._webgl.tangentType,!1,p._tangentStrideOffset[0],p._tangentStrideOffset[1]),e.enableVertexAttribArray(y.tangent),A=null}if(p._webgl.binormals[m]){h=e.createBuffer(),p._webgl.buffers[o+x3dom.BUFFER_IDX.BITANGENT]=h;var R=new Float32Array(p._webgl.binormals[m]);e.bindBuffer(e.ARRAY_BUFFER,h),e.bufferData(e.ARRAY_BUFFER,R,e.STATIC_DRAW),e.vertexAttribPointer(y.binormal,x._mesh._numBinormalComponents,p._webgl.binormalType,!1,p._binormalStrideOffset[0],p._binormalStrideOffset[1]),e.enableVertexAttribArray(y.tangent),R=null}}for(var D in x._mesh._dynamicFields)if(x._mesh._dynamicFields.hasOwnProperty(D)){var N=x._mesh._dynamicFields[D];if(p._webgl.dynamicFields[T]={buf:{},name:D,numComponents:N.numComponents},void 0!==y[D]){var I=e.createBuffer();p._webgl.dynamicFields[T++].buf=I;var P=new Float32Array(N.value);e.bindBuffer(e.ARRAY_BUFFER,I),e.bufferData(e.ARRAY_BUFFER,P,e.STATIC_DRAW),e.vertexAttribPointer(y[D],N.numComponents,e.FLOAT,!1,0,0),P=null}}}},e.prototype.setupScene=function(e,t){var i=null,o=null,s=this;if(void 0!==t._webgl){if(!t._dirty)return;void 0!==t._webgl.texture&&t._webgl.texture&&e.deleteTexture(t._webgl.texture),t._cleanupGLObjects&&t._cleanupGLObjects(),t._webgl={}}t._dirty=!1;var r=t.getTexUrl(),n=0;if(r.length>0&&r[0].length>0)r.length>=6&&r[1].length>0&&r[2].length>0&&r[3].length>0&&r[4].length>0&&r[5].length>0||-1!=r[0].indexOf(".dds")?(i=new x3dom.nodeTypes.Sphere,t._webgl={positions:i._mesh._positions[0],indexes:i._mesh._indices[0],buffers:[{},{}]},t._webgl.primType=e.TRIANGLES,-1!=r[0].indexOf(".dds")?(t._webgl.shader=this.cache.getShader(e,x3dom.shader.BACKGROUND_CUBETEXTURE_DDS),t._webgl.texture=x3dom.Utils.createTextureCube(e,t._nameSpace.doc,[r[0]],!1,t._vf.crossOrigin,!0,!1,!1)):(t._webgl.shader=this.cache.getShader(e,x3dom.shader.BACKGROUND_CUBETEXTURE_DDS),t._webgl.texture=x3dom.Utils.createTextureCube(e,t._nameSpace.doc,r,!1,t._vf.crossOrigin,!0,!1))):(t._webgl={positions:[-1,-1,0,-1,1,0,1,-1,0,1,1,0],indexes:[0,1,2,3],buffers:[{},{}]},r=t._nameSpace.getURL(r[0]),t._webgl.texture=x3dom.Utils.createTexture2D(e,t._nameSpace.doc,r,!0,t._vf.crossOrigin,!1,!1),t._webgl.primType=e.TRIANGLE_STRIP,t._webgl.shader=s.cache.getShader(e,x3dom.shader.BACKGROUND_TEXTURE));else if(t.getSkyColor().length>1||t.getGroundColor().length){i=new x3dom.nodeTypes.Sphere,o=e.createTexture(),t._webgl={positions:i._mesh._positions[0],texcoords:i._mesh._texCoords[0],indexes:i._mesh._indices[0],buffers:[{},{},{}],texture:o,primType:e.TRIANGLES};var a=x3dom.Utils.nextHighestPowerOfTwo(t.getSkyColor().length+t.getGroundColor().length+2);a=a<512?512:a;var d=t._vf.groundAngle.length,l=[],h=[],f=[],u=[0];for(n=0;n<t._vf.skyColor.length;n++)f[n]=t._vf.skyColor[n];for(n=0;n<t._vf.skyAngle.length;n++)u[n+1]=t._vf.skyAngle[n];if(d>0||1==t._vf.groundColor.length){for(u[u.length-1]<Math.PI/2&&(u[u.length]=Math.PI/2-x3dom.fields.Eps,f[f.length]=f[f.length-1]),n=d-1;n>=0;n--)n==d-1&&Math.PI-t._vf.groundAngle[n]<=Math.PI/2&&(u[u.length]=Math.PI/2,f[f.length]=t._vf.groundColor[t._vf.groundColor.length-1]),u[u.length]=Math.PI-t._vf.groundAngle[n],f[f.length]=t._vf.groundColor[n+1];0==d&&1==t._vf.groundColor.length&&(u[u.length]=Math.PI/2,f[f.length]=t._vf.groundColor[0]),u[u.length]=Math.PI,f[f.length]=t._vf.groundColor[0]}else u[u.length-1]<Math.PI&&(u[u.length]=Math.PI,f[f.length]=f[f.length-1]);for(n=0;n<u.length;n++)u[n]/=Math.PI;if(u.length!=f.length){x3dom.debug.logError("Number of background colors and corresponding angles do not match.\nYou have to define one angle less than the count of RGB colors because the angle 0° is added automatically.");var c=u.length<f.length?u.length:f.length;u.length=c,f.length=c}var _=new x3dom.nodeTypes.ColorInterpolator;for(_._vf.key=new x3dom.fields.MFFloat(u),_._vf.keyValue=new x3dom.fields.MFColor(f),_._vf.RGB=!0,_.fieldChanged("keyValue"),n=0;n<a;n++)_._vf.set_fraction=n/(a-1),_.fieldChanged("set_fraction"),l[n]=_._vf.value_changed;l.reverse();var m=Math.floor(255*(1-t.getTransparency()));for(n=0;n<l.length;n++)h.push(Math.floor(255*l[n].r),Math.floor(255*l[n].g),Math.floor(255*l[n].b),m);var p=new Uint8Array(h),x=e.RGBA;a=p.length/4,e.bindTexture(e.TEXTURE_2D,o),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,x,1,a,0,x,e.UNSIGNED_BYTE,p),e.bindTexture(e.TEXTURE_2D,null),t._webgl.shader=s.cache.getShader(e,x3dom.shader.BACKGROUND_SKYTEXTURE)}else t._webgl={};if(t._webgl.shader){var g=t._webgl.shader,v=e.createBuffer();t._webgl.buffers[x3dom.BUFFER_IDX.POSITION]=v,e.bindBuffer(e.ARRAY_BUFFER,v);var y=new Float32Array(t._webgl.positions);e.bufferData(e.ARRAY_BUFFER,y,e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,v),e.vertexAttribPointer(g.position,3,e.FLOAT,!1,0,0),e.enableVertexAttribArray(g.position);var T=e.createBuffer();t._webgl.buffers[x3dom.BUFFER_IDX.INDEX]=T;var b=new Uint16Array(t._webgl.indexes);if(e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,T),e.bufferData(e.ELEMENT_ARRAY_BUFFER,b,e.STATIC_DRAW),y=null,b=null,void 0!==g.texcoord){var S=e.createBuffer();t._webgl.buffers[x3dom.BUFFER_IDX.TEXCOORD]=S;var F=new Float32Array(t._webgl.texcoords);e.bindBuffer(e.ARRAY_BUFFER,S),e.bufferData(e.ARRAY_BUFFER,F,e.STATIC_DRAW),e.vertexAttribPointer(g.texcoord,2,e.FLOAT,!1,0,0),e.enableVertexAttribArray(g.texcoord),F=null}t._cleanupGLObjects=function(){var t=this._webgl.shader;void 0!==t.position&&(e.deleteBuffer(this._webgl.buffers[x3dom.BUFFER_IDX.INDEX]),e.deleteBuffer(this._webgl.buffers[x3dom.BUFFER_IDX.POSITION])),void 0!==t.texcoord&&e.deleteBuffer(this._webgl.buffers[x3dom.BUFFER_IDX.TEXCOORD])}}t._webgl.render=function(e,i,o,r){var n=t._webgl.shader,a=1-t.getTransparency(),d=null,l=o._22,h=o._23,f=i.e3();if(null!=n&&void 0!==n.texcoord&&null!==n.texcoord&&void 0!==t._webgl.texture&&null!==t._webgl.texture)e.clearColor(0,0,0,a),e.clearDepth(1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT|e.STENCIL_BUFFER_BIT),s.stateManager.frontFace(e.CCW),s.stateManager.disable(e.CULL_FACE),s.stateManager.disable(e.DEPTH_TEST),s.stateManager.disable(e.BLEND),s.stateManager.useProgram(n),n.tex||(n.tex=0),o._22=100001/99999,o._23=2e5/99999,i._03=0,i._13=0,i._23=0,d=o.mult(i),n.modelViewProjectionMatrix=d.toGL(),i._03=f.x,i._13=f.y,i._23=f.z,o._22=l,o._23=h,e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,t._webgl.texture),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t._webgl.buffers[x3dom.BUFFER_IDX.INDEX]),e.bindBuffer(e.ARRAY_BUFFER,t._webgl.buffers[x3dom.BUFFER_IDX.POSITION]),e.vertexAttribPointer(n.position,3,e.FLOAT,!1,0,0),e.enableVertexAttribArray(n.position),e.bindBuffer(e.ARRAY_BUFFER,t._webgl.buffers[x3dom.BUFFER_IDX.TEXCOORD]),e.vertexAttribPointer(n.texcoord,2,e.FLOAT,!1,0,0),e.enableVertexAttribArray(n.texcoord),s.setVertexAttribEyeIdx(e,n),s.drawElements(e,t._webgl.primType,t._webgl.indexes.length,e.UNSIGNED_SHORT,0),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,null),e.disableVertexAttribArray(n.position),e.disableVertexAttribArray(n.texcoord),s.disableVertexAttribEyeIdx(e,n),e.clear(e.DEPTH_BUFFER_BIT);else if(!n||!t._webgl.texture||void 0!==t._webgl.texture.textureCubeReady&&!0!==t._webgl.texture.textureCubeReady){var u=t.getSkyColor().toGL();e.clearColor(u[0],u[1],u[2],a),e.clearDepth(1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT|e.STENCIL_BUFFER_BIT)}else{if(e.clearColor(0,0,0,a),e.clearDepth(1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT|e.STENCIL_BUFFER_BIT),s.stateManager.frontFace(e.CCW),s.stateManager.disable(e.CULL_FACE),s.stateManager.disable(e.DEPTH_TEST),s.stateManager.disable(e.BLEND),s.stateManager.useProgram(n),n.tex||(n.tex=0),t._webgl.texture.textureCubeReady)o._22=100001/99999,o._23=2e5/99999,i._03=0,i._13=0,i._23=0,d=o.mult(i),n.modelViewProjectionMatrix=d.toGL(),i._03=f.x,i._13=f.y,i._23=f.z,o._22=l,o._23=h,e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_CUBE_MAP,t._webgl.texture),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);else{if(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,t._webgl.texture),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),t._vf.scaling&&t._webgl.texture.ready){var c=1,_=new x3dom.fields.SFVec2f(s.canvas.width,s.canvas.height),m=new x3dom.fields.SFVec2f(t._webgl.texture.width,t._webgl.texture.height);_.x>_.y?(c=_.x/m.x,m.x=_.x,m.y=m.y*c):(c=_.y/m.y,m.y=_.y,m.x=m.x*c);var p=_.divideComponents(m),x=m.subtract(_).multiply(.5).divideComponents(m)}else p=new x3dom.fields.SFVec2f(1,1),x=new x3dom.fields.SFVec2f(0,0);n.scale=p.toGL(),n.translation=x.toGL()}if(n.isVR=-1,n.screenWidth=s.canvas.width,s.setTonemappingOperator(r,n),2==s.VRMode){var g=r.getViewMatrices()[1],v=g.e3();g._03=0,g._13=0,g._23=0;var y=r.getProjectionMatrices()[1].mult(g);n.modelViewProjectionMatrix2=y.toGL(),g._03=v.x,g._13=v.y,g._23=v.z,n.isVR=1}s.setVertexAttribEyeIdx(e,n),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t._webgl.buffers[x3dom.BUFFER_IDX.INDEX]),e.bindBuffer(e.ARRAY_BUFFER,t._webgl.buffers[x3dom.BUFFER_IDX.POSITION]),e.vertexAttribPointer(n.position,3,e.FLOAT,!1,0,0),e.enableVertexAttribArray(n.position),s.drawElements(e,t._webgl.primType,t._webgl.indexes.length,e.UNSIGNED_SHORT,0),e.disableVertexAttribArray(n.position),s.disableVertexAttribEyeIdx(e,n),e.activeTexture(e.TEXTURE0),t._webgl.texture.textureCubeReady?e.bindTexture(e.TEXTURE_CUBE_MAP,null):e.bindTexture(e.TEXTURE_2D,null),e.clear(e.DEPTH_BUFFER_BIT)}}},e.prototype.setupFgnds=function(e,t){if(void 0===t._fgnd){var i=this;t._fgnd={},t._fgnd._webgl={positions:[-1,-1,0,-1,1,0,1,-1,0,1,1,0],indexes:[0,1,2,3],buffers:[{},{}]},t._fgnd._webgl.primType=e.TRIANGLE_STRIP,t._fgnd._webgl.shader=this.cache.getShader(e,x3dom.shader.FRONTGROUND_TEXTURE);var o=t._fgnd._webgl.shader,s=e.createBuffer();t._fgnd._webgl.buffers[x3dom.BUFFER_IDX.POSITION]=s,e.bindBuffer(e.ARRAY_BUFFER,s);var r=new Float32Array(t._fgnd._webgl.positions);e.bufferData(e.ARRAY_BUFFER,r,e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,s),e.vertexAttribPointer(o.position,3,e.FLOAT,!1,0,0);var n=e.createBuffer();t._fgnd._webgl.buffers[x3dom.BUFFER_IDX.INDEX]=n;var a=new Uint16Array(t._fgnd._webgl.indexes);e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,n),e.bufferData(e.ELEMENT_ARRAY_BUFFER,a,e.STATIC_DRAW),r=null,a=null,t._fgnd._webgl.render=function(e,s){t._fgnd._webgl.texture=s,i.stateManager.frontFace(e.CCW),i.stateManager.disable(e.CULL_FACE),i.stateManager.disable(e.DEPTH_TEST),i.stateManager.useProgram(o),o.tex||(o.tex=0),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,t._fgnd._webgl.texture),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t._fgnd._webgl.buffers[x3dom.BUFFER_IDX.INDEX]),e.bindBuffer(e.ARRAY_BUFFER,t._fgnd._webgl.buffers[x3dom.BUFFER_IDX.POSITION]),e.vertexAttribPointer(o.position,3,e.FLOAT,!1,0,0),e.enableVertexAttribArray(o.position),i.drawElements(e,t._fgnd._webgl.primType,t._fgnd._webgl.indexes.length,e.UNSIGNED_SHORT,0,1),e.disableVertexAttribArray(o.position),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,null)}}},e.prototype.renderShadowPass=function(e,t,i,o,s,r,n){var a=t._scene,d=!1;this.stateManager.bindFramebuffer(e.FRAMEBUFFER,s.fbo),this.stateManager.viewport(0,0,s.width,s.height),e.clearColor(1,1,1,0),e.clearDepth(1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT),this.stateManager.depthFunc(e.LEQUAL),this.stateManager.enable(e.DEPTH_TEST),this.stateManager.enable(e.CULL_FACE),this.stateManager.disable(e.BLEND);x3dom.fields.SFVec3f.NullVector.toGL(),x3dom.fields.SFVec3f.OneVector.toGL();var l,h=a.getEnvironment()._vf.shadowExcludeTransparentObjects,f=a.drawableCollection.length;for(l=0;l<f;l++){var u=a.drawableCollection.get(l),c=u.transform,_=u.shape,m=_._webgl;if(m&&(!h||"transparent"!=u.sortType)){var p=_._cf.geometry.node,x=_._cf.appearance.node,g=(p._mesh,_.getShaderProperties(t)),v=this.cache.getShaderByProperties(e,_,g,null,!0);if(!v)return;if(this.stateManager.useProgram(v),v.cameraView=n,v.offset=r,v.modelViewProjectionMatrix=i.mult(c).toGL(),m.coordType!=e.FLOAT&&(!m.popGeometry&&x3dom.Utils.isUnsignedType(p._vf.coordType)?v.bgCenter=p.getMin().toGL():v.bgCenter=p._vf.position.toGL(),v.bgSize=p._vf.size.toGL(),v.bgPrecisionMax=p.getPrecisionMax("coordType")),_._clipPlanes){v.modelViewMatrix=o.mult(c).toGL(),v.viewMatrixInverse=o.inverse().toGL();for(var y=0;y<_._clipPlanes.length;y++){var T=_._clipPlanes[y].plane,b=_._clipPlanes[y].trafo;v["clipPlane"+y+"_Plane"]=b.multMatrixPlane(T._vf.plane).toGL(),v["clipPlane"+y+"_CappingStrength"]=T._vf.cappingStrength,v["clipPlane"+y+"_CappingColor"]=T._vf.cappingColor.toGL()}}_.isSolid()?(this.stateManager.enable(e.CULL_FACE),_.isCCW()?this.stateManager.frontFace(e.CCW):this.stateManager.frontFace(e.CW)):this.stateManager.disable(e.CULL_FACE);var S,F=x?x._cf.depthMode.node:null;if(F?F._vf.enableDepthTest?(this.stateManager.enable(e.DEPTH_TEST),this.stateManager.depthMask(!F._vf.readOnly),this.stateManager.depthFunc(x3dom.Utils.depthFunc(e,F._vf.depthFunc)),this.stateManager.depthRange(F._vf.zNearRange,F._vf.zFarRange)):this.stateManager.disable(e.DEPTH_TEST):(this.stateManager.enable(e.DEPTH_TEST),this.stateManager.depthMask(!0),this.stateManager.depthFunc(e.LEQUAL)),m.popGeometry){var E=o.mult(c);this.updatePopState(u,p,v,m,a,E,t,this.x3dElem.runtime.fps)}S=m.positions.length;for(var M=0;M<S;M++){var C,w,A,R=6*M;if(void 0!==v.position&&m.buffers[R+x3dom.BUFFER_IDX.POSITION]&&m.indexes[M]){if(d=!1,m.buffers[R+x3dom.BUFFER_IDX.INDEX]&&(e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,m.buffers[R+x3dom.BUFFER_IDX.INDEX]),d=!0),this.setVertexAttribPointerPosition(e,_,R,M),void 0!==v.id&&m.buffers[R+x3dom.BUFFER_IDX.ID]&&(e.bindBuffer(e.ARRAY_BUFFER,m.buffers[R+x3dom.BUFFER_IDX.ID]),0!=m.binaryGeometry&&1==p._vf.idsPerVertex&&(e.vertexAttribPointer(v.id,1,e.FLOAT,!1,4,0),e.enableVertexAttribArray(v.id))),d&&(m.binaryGeometry>0||m.popGeometry>0))for(C=0,A=0,w=p._vf.vertexCount.length;C<w;C++)this.drawElements(e,m.primType[C],p._vf.vertexCount[C],m.indexType,x3dom.Utils.getByteAwareOffset(A,m.indexType,e)),A+=p._vf.vertexCount[C];else if(m.binaryGeometry<0||m.popGeometry<0)for(C=0,A=0,w=p._vf.vertexCount.length;C<w;C++)this.drawArrays(e,m.primType[C],A,p._vf.vertexCount[C]),A+=p._vf.vertexCount[C];else if(p.hasIndexOffset()){var D=_.tessellationProperties();for(C=0,w=D.length;C<w;C++)this.drawElements(e,m.primType,D[C].count,m.indexType,D[C].offset*x3dom.Utils.getOffsetMultiplier(m.indexType,e))}else 0==m.indexes[M].length?this.drawArrays(e,m.primType,0,m.positions[M].length/3):this.drawElements(e,m.primType,m.indexes[M].length,m.indexType,0);e.disableVertexAttribArray(v.position),void 0!==v.texcoord&&m.buffers[R+x3dom.BUFFER_IDX.TEXCOORD]&&e.disableVertexAttribArray(v.texcoord),void 0!==v.color&&m.buffers[R+x3dom.BUFFER_IDX.COLOR]&&e.disableVertexAttribArray(v.color),void 0!==v.id&&m.buffers[R+x3dom.BUFFER_IDX.ID]&&e.disableVertexAttribArray(v.id)}}}}x3dom.Utils.needLineWidth&&this.stateManager.lineWidth(1),F&&(this.stateManager.enable(e.DEPTH_TEST),this.stateManager.depthMask(!0),this.stateManager.depthFunc(e.LEQUAL),this.stateManager.depthRange(0,1)),e.flush(),this.stateManager.bindFramebuffer(e.FRAMEBUFFER,null)},e.prototype.renderPickingPass=function(e,t,i,o,s,r,n,a,d,l,h){var f=t._webgl.pickScale,u=t._webgl.fboPick.height,c=a*f,_=u-1-d*f,m=!1;this.stateManager.bindFramebuffer(e.FRAMEBUFFER,t._webgl.fboPick.fbo),this.stateManager.viewport(0,0,t._webgl.fboPick.width,u),e.clearColor(0,0,0,0),e.clearDepth(1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT);var p=t.drawableCollection.viewarea,x=t.getEnvironment(),g=t.drawableCollection.length;x._vf.smallFeatureCulling&&x._lowPriorityThreshold<1&&p.isMovingOrAnimating()&&!(g=Math.floor(g*x._lowPriorityThreshold))&&t.drawableCollection.length&&(g=1);x3dom.fields.SFVec3f.NullVector.toGL(),x3dom.fields.SFVec3f.OneVector.toGL();this.stateManager.depthFunc(e.LEQUAL),this.stateManager.enable(e.DEPTH_TEST),this.stateManager.enable(e.CULL_FACE),this.stateManager.disable(e.BLEND),x3dom.Utils.needLineWidth&&this.stateManager.lineWidth(2);for(var v=0;v<g;v++){var y=t.drawableCollection.get(v),T=y.transform,b=y.shape,S=b._webgl;if(S&&!(b._objectID<1)&&b._vf.isPickable){var F=b._cf.geometry.node,E=b._cf.appearance.node,M=(F._mesh,b.getShaderProperties(p)),C=this.cache.getShaderByProperties(e,b,M,n);if(!C)return;if(S.shader=C,this.stateManager.useProgram(C),C.screenWidth=this.canvas.width*t._webgl.pickScale,C.modelMatrix=T.toGL(),C.modelViewProjectionMatrix=o.mult(T).toGL(),C.isVR=-1,2==this.VRMode){var w=p.getViewMatrices()[1],A=p.getProjectionMatrices()[1].mult(w);C.modelViewProjectionMatrix2=A.mult(T).toGL(),C.isVR=1}if(C.lowBit=(255&b._objectID)/255,C.highBit=(b._objectID>>>8)/255,C.from=s.toGL(),C.sceneSize=r,0!=S.binaryGeometry&&1==F._vf.idsPerVertex&&(C.shadowIDs=b._vf.idOffset+x3dom.nodeTypes.Shape.objectID+2),S.coordType!=e.FLOAT&&(!S.popGeometry&&x3dom.Utils.isUnsignedType(F._vf.coordType)?C.bgCenter=F.getMin().toGL():C.bgCenter=F._vf.position.toGL(),C.bgSize=F._vf.size.toGL(),C.bgPrecisionMax=F.getPrecisionMax("coordType")),1==n&&S.colorType!=e.FLOAT&&(C.bgPrecisionColMax=F.getPrecisionMax("colorType")),2==n&&S.texCoordType!=e.FLOAT&&(C.bgPrecisionTexMax=F.getPrecisionMax("texCoordType")),b._clipPlanes){C.modelViewMatrix=i.mult(T).toGL(),C.viewMatrixInverse=i.inverse().toGL(),2==this.VRMode&&(C.modelViewMatrix2=w.mult(T).toGL(),C.viewMatrixInverse2=w.inverse().toGL());for(var R=0;R<b._clipPlanes.length;R++){var D=b._clipPlanes[R].plane,N=b._clipPlanes[R].trafo;C["clipPlane"+R+"_Plane"]=N.multMatrixPlane(D._vf.plane).toGL(),C["clipPlane"+R+"_CappingStrength"]=D._vf.cappingStrength,C["clipPlane"+R+"_CappingColor"]=D._vf.cappingColor.toGL()}}b.isSolid()?(this.stateManager.enable(e.CULL_FACE),b.isCCW()?this.stateManager.frontFace(e.CCW):this.stateManager.frontFace(e.CW)):this.stateManager.disable(e.CULL_FACE);var I=E?E._cf.depthMode.node:null;if(I?I._vf.enableDepthTest?(this.stateManager.enable(e.DEPTH_TEST),this.stateManager.depthMask(!I._vf.readOnly),this.stateManager.depthFunc(x3dom.Utils.depthFunc(e,I._vf.depthFunc)),this.stateManager.depthRange(I._vf.zNearRange,I._vf.zFarRange)):this.stateManager.disable(e.DEPTH_TEST):(this.stateManager.enable(e.DEPTH_TEST),this.stateManager.depthMask(!0),this.stateManager.depthFunc(e.LEQUAL)),S.popGeometry){var P=i.mult(T);this.updatePopState(y,F,C,S,t,P,p,this.x3dElem.runtime.fps)}for(var V=S.positions.length,L=0;L<V;L++){var O,B,U,X=6*L;if(void 0!==C.position&&S.buffers[X+x3dom.BUFFER_IDX.POSITION]&&S.indexes[L]){if(m=!1,S.buffers[X+x3dom.BUFFER_IDX.INDEX]&&(e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,S.buffers[X+x3dom.BUFFER_IDX.INDEX]),m=!0),this.setVertexAttribEyeIdx(e,C),this.setVertexAttribPointerPosition(e,b,X,L),1==n&&this.setVertexAttribPointerColor(e,b,X,L),2==n&&void 0!==C.texcoord&&S.buffers[X+x3dom.BUFFER_IDX.TEXCOORD]&&this.setVertexAttribPointerTexCoord(e,b,X,L),void 0!==C.id&&S.buffers[X+x3dom.BUFFER_IDX.ID]&&(e.bindBuffer(e.ARRAY_BUFFER,S.buffers[X+x3dom.BUFFER_IDX.ID]),0!=S.binaryGeometry&&1==F._vf.idsPerVertex&&(e.vertexAttribPointer(C.id,1,e.FLOAT,!1,4,0),e.enableVertexAttribArray(C.id))),m&&(S.binaryGeometry>0||S.popGeometry>0))for(O=0,U=0,B=F._vf.vertexCount.length;O<B;O++)this.drawElements(e,S.primType[O],F._vf.vertexCount[O],S.indexType,x3dom.Utils.getByteAwareOffset(U,S.indexType,e)),U+=F._vf.vertexCount[O];else if(S.binaryGeometry<0||S.popGeometry<0)for(O=0,U=0,B=F._vf.vertexCount.length;O<B;O++)this.drawArrays(e,S.primType[O],U,F._vf.vertexCount[O]),U+=F._vf.vertexCount[O];else if(m&&S.bufferGeometry>0)this.drawElements(e,S.primType[0],F._vf.vertexCount[0],S.indexType,b._indexOffset);else if(S.bufferGeometry<0)this.drawArrays(e,S.primType[0],0,F._vf.vertexCount[0]);else if(F.hasIndexOffset()){var k=b.tessellationProperties();for(O=0,B=k.length;O<B;O++)this.drawElements(e,S.primType,k[O].count,S.indexType,k[O].offset*x3dom.Utils.getOffsetMultiplier(S.indexType,e))}else 0==S.indexes[L].length?this.drawArrays(e,S.primType,0,S.positions[L].length/3):this.drawElements(e,S.primType,S.indexes[L].length,S.indexType,0);e.disableVertexAttribArray(C.position),void 0!==C.texcoord&&S.buffers[X+x3dom.BUFFER_IDX.TEXCOORD]&&e.disableVertexAttribArray(C.texcoord),void 0!==C.color&&S.buffers[X+x3dom.BUFFER_IDX.COLOR]&&e.disableVertexAttribArray(C.color),void 0!==C.id&&S.buffers[X+x3dom.BUFFER_IDX.ID]&&e.disableVertexAttribArray(C.id),this.disableVertexAttribEyeIdx(e,C)}}}}x3dom.Utils.needLineWidth&&this.stateManager.lineWidth(1),I&&(this.stateManager.enable(e.DEPTH_TEST),this.stateManager.depthMask(!0),this.stateManager.depthFunc(e.LEQUAL),this.stateManager.depthRange(0,1)),e.flush();try{var G=new Uint8Array(4*l*h);e.readPixels(c,_,l,h,e.RGBA,e.UNSIGNED_BYTE,G),t._webgl.fboPick.pixelData=G}catch(e){t._webgl.fboPick.pixelData=[],x3dom.debug.logException(e+" (cannot pick)")}this.stateManager.bindFramebuffer(e.FRAMEBUFFER,null)},e.prototype.renderShape=function(e,t,i,o,s,r,n,a,d){var l=!1,h=e.shape,f=e.transform;if(h&&h._webgl&&f){var u=h._webgl,c=u.shader;if(c){var _=this.stateManager.useProgram(c),m=h._cf.appearance.node,p=h._cf.geometry.node,x=p._mesh,g=t._scene,v=null;u.coordType!=d.FLOAT?(!u.popGeometry&&x3dom.Utils.isUnsignedType(p._vf.coordType)?c.bgCenter=p.getMin().toGL():c.bgCenter=p._vf.position.toGL(),c.bgSize=p._vf.size.toGL(),c.bgPrecisionMax=p.getPrecisionMax("coordType")):(c.bgCenter=[0,0,0],c.bgSize=[1,1,1],c.bgPrecisionMax=1),u.colorType!=d.FLOAT?c.bgPrecisionColMax=p.getPrecisionMax("colorType"):c.bgPrecisionColMax=1,u.texCoordType!=d.FLOAT?c.bgPrecisionTexMax=p.getPrecisionMax("texCoordType"):c.bgPrecisionTexMax=1,u.normalType!=d.FLOAT?c.bgPrecisionNorMax=p.getPrecisionMax("normalType"):c.bgPrecisionNorMax=1,u.tangentType!=d.FLOAT?c.bgPrecisionTangentMax=p.getPrecisionMax("tangentType"):c.bgPrecisionTangentMax=1,u.binormalType!=d.FLOAT?c.bgPrecisionBinormalMax=p.getPrecisionMax("binormalType"):c.bgPrecisionBinormalMax=1;var y=g.getFog();y&&_&&(c.fogColor=y._vf.color.toGL(),c.fogRange=y._vf.visibilityRange,c.fogType="LINEAR"==y._vf.fogType?0:1);var T,b=m?m._cf.material.node:null,S=m?m._shader:null,F=!1,E=S&&x3dom.isa(S,x3dom.nodeTypes.ComposedShader);if(u.csshader?(c.diffuseColor=S._vf.diffuseFactor.toGL(),c.specularColor=S._vf.specularFactor.toGL(),c.emissiveColor=S._vf.emissiveFactor.toGL(),c.shininess=S._vf.shininessFactor,c.ambientIntensity=(S._vf.ambientFactor.x+S._vf.ambientFactor.y+S._vf.ambientFactor.z)/3,c.transparency=1-S._vf.alphaFactor,c.environmentFactor=S._vf.environmentFactor.x,c.normalBias=S._vf.normalBias.toGL(),S.getDisplacementMap()?(v=x3dom.Utils.findTextureByName(u.texture,"displacementMap"),c.displacementWidth=v.texture.width,c.displacementHeight=v.texture.height,c.displacementFactor=S._vf.displacementFactor,c.displacementAxis="x"==S._vf.displacementAxis?0:"y"==S._vf.displacementAxis?1:2):S.getDiffuseDisplacementMap()&&(v=x3dom.Utils.findTextureByName(u.texture,"diffuseDisplacementMap"),c.displacementWidth=v.texture.width,c.displacementHeight=v.texture.height,c.displacementFactor=S._vf.displacementFactor,c.displacementAxis="x"==S._vf.displacementAxis?0:"y"==S._vf.displacementAxis?1:2)):b&&x3dom.isa(b,x3dom.nodeTypes.PhysicalMaterial)?("roughnessMetallic"==b._vf.model?(c.diffuseColor=[b._vf.baseColorFactor.r,b._vf.baseColorFactor.g,b._vf.baseColorFactor.b],c.specularColor=[x3dom.Utils.lerp(.04,b._vf.baseColorFactor.r,b._vf.metallicFactor),x3dom.Utils.lerp(.04,b._vf.baseColorFactor.g,b._vf.metallicFactor),x3dom.Utils.lerp(.04,b._vf.baseColorFactor.b,b._vf.metallicFactor)],c.shininess=1-b._vf.roughnessFactor,c.metallicFactor=b._vf.metallicFactor,c.transparency=1-b._vf.baseColorFactor.a):(c.diffuseColor=[b._vf.diffuseFactor.r,b._vf.diffuseFactor.g,b._vf.diffuseFactor.b],c.specularColor=[b._vf.specularFactor.r,b._vf.specularFactor.g,b._vf.specularFactor.b],c.shininess=b._vf.glossinessFactor,c.transparency=1-b._vf.diffuseFactor.a),c.emissiveColor=b._vf.emissiveFactor.toGL(),c.normalBias=b._vf.normalBias.toGL(),c.ambientIntensity=1,c.alphaCutoff=b._vf.alphaCutoff):b?(c.diffuseColor=b._vf.diffuseColor.toGL(),c.specularColor=b._vf.specularColor.toGL(),c.emissiveColor=b._vf.emissiveColor.toGL(),c.shininess=b._vf.shininess,c.ambientIntensity=b._vf.ambientIntensity,c.transparency=b._vf.transparency,c.environmentFactor=0,c.alphaCutoff=m._vf.alphaClipThreshold.toFixed(2),x3dom.isa(b,x3dom.nodeTypes.TwoSidedMaterial)&&(F=!0,c.backDiffuseColor=b._vf.backDiffuseColor.toGL(),c.backSpecularColor=b._vf.backSpecularColor.toGL(),c.backEmissiveColor=b._vf.backEmissiveColor.toGL(),c.backShininess=b._vf.backShininess,c.backAmbientIntensity=b._vf.backAmbientIntensity,c.backTransparency=b._vf.backTransparency)):(c.diffuseColor=[1,1,1],c.specularColor=[0,0,0],c.emissiveColor=[0,0,0],c.shininess=0,c.ambientIntensity=1,c.transparency=0,c.alphaCutoff=.1),S)if(E){for(var M in S._vf)if(S._vf.hasOwnProperty(M)&&"language"!==M){var C=S._vf[M];null!=C&&(C.toGL?c[M]=C.toGL():c[M]=C)}}else x3dom.isa(S,x3dom.nodeTypes.CommonSurfaceShader)&&(u.csshader=S);for(var w=0;w<o&&_;w++){var A=s.mult(i[w].getCurrentTransform());x3dom.isa(i[w],x3dom.nodeTypes.DirectionalLight)?(c["light"+w+"_Type"]=0,c["light"+w+"_On"]=i[w]._vf.on?1:0,c["light"+w+"_Color"]=i[w]._vf.color.toGL(),c["light"+w+"_Intensity"]=i[w]._vf.intensity,c["light"+w+"_AmbientIntensity"]=i[w]._vf.ambientIntensity,c["light"+w+"_Direction"]=A.multMatrixVec(i[w]._vf.direction).toGL(),c["light"+w+"_Attenuation"]=[1,1,1],c["light"+w+"_Location"]=[1,1,1],c["light"+w+"_Radius"]=0,c["light"+w+"_BeamWidth"]=0,c["light"+w+"_CutOffAngle"]=0,c["light"+w+"_ShadowIntensity"]=i[w]._vf.shadowIntensity):x3dom.isa(i[w],x3dom.nodeTypes.PointLight)?(c["light"+w+"_Type"]=1,c["light"+w+"_On"]=i[w]._vf.on?1:0,c["light"+w+"_Color"]=i[w]._vf.color.toGL(),c["light"+w+"_Intensity"]=i[w]._vf.intensity,c["light"+w+"_AmbientIntensity"]=i[w]._vf.ambientIntensity,c["light"+w+"_Direction"]=[1,1,1],c["light"+w+"_Attenuation"]=i[w]._vf.attenuation.toGL(),c["light"+w+"_Location"]=A.multMatrixPnt(i[w]._vf.location).toGL(),c["light"+w+"_Radius"]=i[w]._vf.radius,c["light"+w+"_BeamWidth"]=0,c["light"+w+"_CutOffAngle"]=0,c["light"+w+"_ShadowIntensity"]=i[w]._vf.shadowIntensity):x3dom.isa(i[w],x3dom.nodeTypes.SpotLight)?(c["light"+w+"_Type"]=2,c["light"+w+"_On"]=i[w]._vf.on?1:0,c["light"+w+"_Color"]=i[w]._vf.color.toGL(),c["light"+w+"_Intensity"]=i[w]._vf.intensity,c["light"+w+"_AmbientIntensity"]=i[w]._vf.ambientIntensity,c["light"+w+"_Direction"]=A.multMatrixVec(i[w]._vf.direction).toGL(),c["light"+w+"_Attenuation"]=i[w]._vf.attenuation.toGL(),c["light"+w+"_Location"]=A.multMatrixPnt(i[w]._vf.location).toGL(),c["light"+w+"_Radius"]=i[w]._vf.radius,c["light"+w+"_BeamWidth"]=i[w]._vf.beamWidth,c["light"+w+"_CutOffAngle"]=i[w]._vf.cutOffAngle,c["light"+w+"_ShadowIntensity"]=i[w]._vf.shadowIntensity):x3dom.isa(i[w],x3dom.nodeTypes.PhysicalEnvironmentLight)&&(T=i[w],o--)}if(g.getNavigationInfo()._vf.headlight&&_&&(c["light"+(o=o||0)+"_Type"]=0,c["light"+o+"_On"]=1,c["light"+o+"_Color"]=[1,1,1],c["light"+o+"_Intensity"]=1,c["light"+o+"_AmbientIntensity"]=0,c["light"+o+"_Direction"]=[0,0,-1],c["light"+o+"_Attenuation"]=[1,1,1],c["light"+o+"_Location"]=[1,1,1],c["light"+o+"_Radius"]=0,c["light"+o+"_BeamWidth"]=0,c["light"+o+"_CutOffAngle"]=0,c["light"+o+"_ShadowIntensity"]=0),h._clipPlanes)for(var R=0;R<h._clipPlanes.length;R++){var D=h._clipPlanes[R].plane,N=h._clipPlanes[R].trafo;c["clipPlane"+R+"_Plane"]=N.multMatrixPlane(D._vf.plane).toGL(),c["clipPlane"+R+"_CappingStrength"]=D._vf.cappingStrength,c["clipPlane"+R+"_CappingColor"]=D._vf.cappingColor.toGL()}var I=m?m._cf.depthMode.node:null;I?I._vf.enableDepthTest?(this.stateManager.enable(d.DEPTH_TEST),this.stateManager.depthMask(!I._vf.readOnly),this.stateManager.depthFunc(x3dom.Utils.depthFunc(d,I._vf.depthFunc)),this.stateManager.depthRange(I._vf.zNearRange,I._vf.zFarRange)):this.stateManager.disable(d.DEPTH_TEST):(this.stateManager.enable(d.DEPTH_TEST),this.stateManager.depthMask(!0),this.stateManager.depthFunc(d.LEQUAL));var P=m?m._cf.blendMode.node:null;if(P){var V=x3dom.Utils.blendFunc(d,P._vf.srcFactor),L=x3dom.Utils.blendFunc(d,P._vf.destFactor);V&&L?(this.stateManager.enable(d.BLEND),this.stateManager.blendFuncSeparate(V,L,d.ONE,d.ONE),this.stateManager.blendColor(P._vf.color.r,P._vf.color.g,P._vf.color.b,1-P._vf.colorTransparency),this.stateManager.blendEquation(x3dom.Utils.blendEquation(d,P._vf.equation))):this.stateManager.disable(d.BLEND)}else b&&x3dom.isa(b,x3dom.nodeTypes.PhysicalMaterial)?"BLEND"==b._vf.alphaMode?(this.stateManager.enable(d.BLEND),this.stateManager.blendFuncSeparate(d.SRC_ALPHA,d.ONE_MINUS_SRC_ALPHA,d.ONE,d.ONE)):this.stateManager.disable(d.BLEND):(this.stateManager.enable(d.BLEND),this.stateManager.blendFuncSeparate(d.SRC_ALPHA,d.ONE_MINUS_SRC_ALPHA,d.ONE,d.ONE));var O=m?m._cf.colorMaskMode.node:null;O?this.stateManager.colorMask(O._vf.maskR,O._vf.maskG,O._vf.maskB,O._vf.maskA):this.stateManager.colorMask(!0,!0,!0,!0);var B=m?m._cf.lineProperties.node:null;B?this.stateManager.lineWidth(B._vf.linewidthScaleFactor):x3dom.Utils.needLineWidth&&this.stateManager.lineWidth(1),h.isSolid()&&!F?(this.stateManager.enable(d.CULL_FACE),h.isCCW()?this.stateManager.frontFace(d.CCW):this.stateManager.frontFace(d.CW)):this.stateManager.disable(d.CULL_FACE);var U=s.mult(f),X=U.inverse();if(c.screenWidth=this.canvas.width,c.isOrthoView=1==a._33?1:0,c.modelMatrix=f.toGL(),c.modelViewMatrix=U.toGL(),c.viewMatrix=s.toGL(),c.normalMatrix=X.transpose().toGL(),c.modelViewMatrixInverse=X.toGL(),c.modelViewProjectionMatrix=r.mult(f).toGL(),c.modelViewProjectionInverseMatrix=r.mult(f).inverse().toGL(),c.viewMatrixInverse=s.inverse().toGL(),c.cameraPosWS=s.inverse().e3().toGL(),this.setTonemappingOperator(t,c),E&&(c.model=f.toGL(),c.projectionMatrix=a.toGL(),c.worldMatrix=f.toGL(),c.worldInverseTranspose=f.inverse().transpose().toGL()),2==this.VRMode){var k=t.getViewMatrices()[1],G=t.getProjectionMatrices()[1].mult(k),z=k.mult(f),H=z.inverse();c.viewMatrix2=k.toGL(),c.modelViewMatrix2=z.toGL(),c.normalMatrix2=H.transpose().toGL(),c.modelViewMatrixInverse2=H.toGL(),c.modelViewProjectionMatrix2=G.mult(f).toGL(),c.isVR=1}else c.isVR=0;u.popGeometry&&this.updatePopState(e,p,c,u,g,U,t,this.x3dElem.runtime.fps);for(var j=0,W=u.texture.length;j<W;j++)v=u.texture[j],d.activeTexture(d.TEXTURE0+j),d.bindTexture(v.type,v.texture),d.texParameteri(v.type,d.TEXTURE_WRAP_S,v.wrapS),d.texParameteri(v.type,d.TEXTURE_WRAP_T,v.wrapT),d.texParameteri(v.type,d.TEXTURE_MAG_FILTER,v.magFilter),d.texParameteri(v.type,d.TEXTURE_MIN_FILTER,v.minFilter),x3dom.caps.ANISOTROPIC&&d.texParameterf(v.type,x3dom.caps.ANISOTROPIC.TEXTURE_MAX_ANISOTROPY_EXT,v.anisotropicDegree),S&&E||c[v.samplerName]||(c[v.samplerName]=j);if(x3dom.isa(b,x3dom.nodeTypes.PhysicalMaterial)&&null!=T&&""!=T._vf.diffuse&&""!=T._vf.specular){var Y=T._nameSpace.getURL(T._vf.diffuse),q=T._nameSpace.getURL(T._vf.specular),Q=x3dom.BRDF_LUT,K=this.cache.getTexture2D(d,h._nameSpace.doc,Q,!1,"anonymous",!1,!1,!0),Z=this.cache.getTextureCube(d,h._nameSpace.doc,[Y],!1,"anonymous",!1,!1,!0),J=this.cache.getTextureCube(d,h._nameSpace.doc,[q],!1,"anonymous",!1,!1,!0);d.activeTexture(d.TEXTURE0+W),d.bindTexture(d.TEXTURE_2D,K),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MIN_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MAG_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_S,d.CLAMP_TO_EDGE),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_T,d.CLAMP_TO_EDGE),c.brdfMap=W++,Z.ready&&(d.activeTexture(d.TEXTURE0+W),d.bindTexture(d.TEXTURE_CUBE_MAP,Z),d.texParameteri(d.TEXTURE_CUBE_MAP,d.TEXTURE_MIN_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_CUBE_MAP,d.TEXTURE_MAG_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_CUBE_MAP,d.TEXTURE_WRAP_S,d.CLAMP_TO_EDGE),d.texParameteri(d.TEXTURE_CUBE_MAP,d.TEXTURE_WRAP_T,d.CLAMP_TO_EDGE),c.diffuseEnvironmentMap=W++),J.ready&&(d.activeTexture(d.TEXTURE0+W),d.bindTexture(d.TEXTURE_CUBE_MAP,J),d.texParameteri(d.TEXTURE_CUBE_MAP,d.TEXTURE_MIN_FILTER,d.LINEAR_MIPMAP_LINEAR),d.texParameteri(d.TEXTURE_CUBE_MAP,d.TEXTURE_MAG_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_CUBE_MAP,d.TEXTURE_WRAP_S,d.CLAMP_TO_EDGE),d.texParameteri(d.TEXTURE_CUBE_MAP,d.TEXTURE_WRAP_T,d.CLAMP_TO_EDGE),c.specularEnvironmentMap=W++)}if(m&&m._cf.textureTransform.node){var $=m.texTransformMatrix();c.texTrafoMatrix=$.toGL()}var ee,te,ie,oe,se,re=null,ne=u.dynamicFields.length;for(ee=0;ee<ne;ee++)void 0!==c[(re=u.dynamicFields[ee]).name]&&(d.bindBuffer(d.ARRAY_BUFFER,re.buf),d.vertexAttribPointer(c[re.name],re.numComponents,d.FLOAT,!1,0,0),d.enableVertexAttribArray(c[re.name]));var ae=!1;x3dom.isa(p,x3dom.nodeTypes.ParticleSet)&&(ae=!0);var de=m?m._cf.pointProperties.node:null;if(de=de&&x3dom.isa(p,x3dom.nodeTypes.PointSet)){var le=m._cf.pointProperties.node._vf;c.pointSizeAttenuation=le.attenuation.toGL(),c.pointSizeFactor=le.pointSizeScaleFactor,c.minPointSize=le.pointSizeMinValue,c.maxPointSize=le.pointSizeMaxValue}se=u.positions.length;for(var he=0;he<se;he++){var fe=6*he;if(l=!1,void 0!==c.position&&u.buffers[fe+x3dom.BUFFER_IDX.POSITION]&&u.indexes[he]){if(u.buffers[fe+x3dom.BUFFER_IDX.INDEX]){if(ae&&"any"!=p.drawOrder()){for(var ue,ce=[],_e=p._cf.coord.node.getPoints(),me=_e.length==u.indexes[he].length?u.indexes[he].length:0,pe=0;pe<me;pe++){var xe=U.multMatrixPnt(_e[pe]);ce.push([pe,xe.z])}for("backtofront"==p.drawOrder()?ce.sort((function(e,t){return e[1]-t[1]})):ce.sort((function(e,t){return t[1]-e[1]})),pe=0;pe<me;pe++)h._webgl.indexes[he][pe]=ce[pe][0];x3dom.caps.INDEX_UINT&&me>65535?(ue=new Uint32Array(h._webgl.indexes[he]),h._webgl.indexType=d.UNSIGNED_INT):(ue=new Uint16Array(h._webgl.indexes[he]),h._webgl.indexType=d.UNSIGNED_SHORT),d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,u.buffers[fe+x3dom.BUFFER_IDX.INDEX]),d.bufferData(d.ELEMENT_ARRAY_BUFFER,ue,d.DYNAMIC_DRAW),ue=null}d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,u.buffers[fe+x3dom.BUFFER_IDX.INDEX]),l=!0}this.setVertexAttribEyeIdx(d,c),this.setVertexAttribPointerPosition(d,h,fe,he),this.setVertexAttribPointerNormal(d,h,fe,he),this.setVertexAttribPointerTexCoord(d,h,fe,he),this.setVertexAttribPointerTexCoord2(d,h,fe,he),this.setVertexAttribPointerColor(d,h,fe,he),this.setVertexAttribPointerTangent(d,h,fe,he),this.setVertexAttribPointerBinormal(d,h,fe,he),void 0===c.id&&void 0===c.particleSize||!h._webgl.buffers[fe+x3dom.BUFFER_IDX.ID]||(d.bindBuffer(d.ARRAY_BUFFER,h._webgl.buffers[fe+x3dom.BUFFER_IDX.ID]),0!=u.binaryGeometry&&1==p._vf.idsPerVertex?(d.vertexAttribPointer(c.id,1,d.FLOAT,!1,4,0),d.enableVertexAttribArray(c.id)):ae&&(d.vertexAttribPointer(c.particleSize,3,d.FLOAT,!1,0,0),d.enableVertexAttribArray(c.particleSize))),0!=u.popGeometry&&u.buffers[fe+x3dom.BUFFER_IDX.ID]&&(d.bindBuffer(d.ARRAY_BUFFER,u.buffers[fe+x3dom.BUFFER_IDX.ID]),d.vertexAttribPointer(c.PG_vertexID,1,d.FLOAT,!1,4,0),d.enableVertexAttribArray(c.PG_vertexID));var ge,ve=t.getRenderMode(),ye=!!b&&(b._vf.transparency>0&&!h.isSolid()),Te=function(e,t){e.frontFace(h.isCCW()?d.CCW:d.CW),e.enable(d.CULL_FACE),e.cullFace(d.FRONT),t(),e.cullFace(d.BACK),t(),e.disable(d.CULL_FACE)};if(ve>0){var be=1==ve?d.POINTS:d.LINES;if(l&&(u.binaryGeometry>0||u.popGeometry>0))for(te=0,oe=0,ie=p._vf.vertexCount.length;te<ie;te++)this.drawElements(d,be,p._vf.vertexCount[te],u.indexType,x3dom.Utils.getByteAwareOffset(oe,u.indexType,d)),oe+=p._vf.vertexCount[te];else if(u.binaryGeometry<0||u.popGeometry<0)for(te=0,oe=0,ie=p._vf.vertexCount.length;te<ie;te++)this.drawArrays(d,be,oe,p._vf.vertexCount[te]),oe+=p._vf.vertexCount[te];else if(l&&u.bufferGeometry>0)this.drawElements(d,u.primType[0],p._vf.vertexCount[0],u.indexType,h._indexOffset);else if(u.bufferGeometry<0)this.drawArrays(d,u.primType[0],0,p._vf.vertexCount[0]);else if(p.hasIndexOffset())for(te=0,ie=(ge=h.tessellationProperties()).length;te<ie;te++)this.drawElements(d,be,ge[te].count,u.indexType,ge[te].offset*x3dom.Utils.getOffsetMultiplier(u.indexType,d));else 0==u.indexes[he].length?this.drawArrays(d,be,0,u.positions[he].length/3):this.drawElements(d,be,u.indexes[he].length,u.indexType,0)}else if(l&&(u.binaryGeometry>0||u.popGeometry>0))for(te=0,oe=0,ie=p._vf.vertexCount.length;te<ie;te++)this.drawElements(d,u.primType[te],p._vf.vertexCount[te],u.indexType,x3dom.Utils.getByteAwareOffset(oe,u.indexType,d)),oe+=p._vf.vertexCount[te];else if(u.binaryGeometry<0||u.popGeometry<0)for(te=0,oe=0,ie=p._vf.vertexCount.length;te<ie;te++)this.drawArrays(d,u.primType[te],oe,p._vf.vertexCount[te]),oe+=p._vf.vertexCount[te];else if(l&&u.bufferGeometry>0)this.drawElements(d,u.primType[0],p._vf.vertexCount[0],u.indexType,h._indexOffset);else if(u.bufferGeometry<0)this.drawArrays(d,u.primType[0],0,p._vf.vertexCount[0]);else if(p.hasIndexOffset())for(te=0,ie=(ge=h.tessellationProperties()).length;te<ie;te++)this.drawElements(d,u.primType,ge[te].count,u.indexType,ge[te].offset*x3dom.Utils.getOffsetMultiplier(u.indexType,d));else 0==u.indexes[he].length?ye?Te(this.stateManager,this.drawArrays.bind(this,d,u.primType,0,u.positions[he].length/3)):this.drawArrays(d,u.primType,0,u.positions[he].length/3):ye?Te(this.stateManager,this.drawElements.bind(this,d,u.primType,u.indexes[he].length,u.indexType,0)):this.drawElements(d,u.primType,u.indexes[he].length,u.indexType,0);d.disableVertexAttribArray(c.position),void 0!==c.normal&&d.disableVertexAttribArray(c.normal),this.disableVertexAttribEyeIdx(d,c),void 0!==c.texcoord&&d.disableVertexAttribArray(c.texcoord),void 0!==c.texcoord2&&d.disableVertexAttribArray(c.texcoord2),void 0!==c.color&&d.disableVertexAttribArray(c.color),void 0!==c.tangent&&d.disableVertexAttribArray(c.tangent),void 0!==c.binormal&&d.disableVertexAttribArray(c.binormal),u.buffers[fe+x3dom.BUFFER_IDX.ID]&&(void 0!==c.id?d.disableVertexAttribArray(c.id):void 0!==c.particleSize&&d.disableVertexAttribArray(c.particleSize)),0!=u.popGeometry&&void 0!==c.PG_vertexID&&d.disableVertexAttribArray(c.PG_vertexID)}}for(ee=0;ee<ne;ee++)void 0!==c[(re=u.dynamicFields[ee]).name]&&d.disableVertexAttribArray(c[re.name]);this.numCoords+=x._numCoords,this.numFaces+=x._numFaces,u.binaryGeometry||u.popGeometry||u.bufferGeometry?this.numDrawCalls+=p._vf.vertexCount.length:p.hasIndexOffset()?this.numDrawCalls+=h.tessellationProperties().length:this.numDrawCalls+=se,I&&(this.stateManager.enable(d.DEPTH_TEST),this.stateManager.depthMask(!0),this.stateManager.depthFunc(d.LEQUAL),this.stateManager.depthRange(0,1)),P&&(this.stateManager.enable(d.BLEND),this.stateManager.blendFuncSeparate(d.SRC_ALPHA,d.ONE_MINUS_SRC_ALPHA,d.ONE,d.ONE),this.stateManager.blendColor(1,1,1,1),this.stateManager.blendEquation(d.FUNC_ADD)),O&&this.stateManager.colorMask(!0,!0,!0,!0),B&&this.stateManager.lineWidth(1);var Se=u.texture;for(W=Se?Se.length:0,j=0;j<W;j++)Se[j]&&m&&m._cf.texture.node&&(v=m._cf.texture.node.getTexture(j),d.activeTexture(d.TEXTURE0+j),x3dom.isa(v,x3dom.nodeTypes.X3DEnvironmentTextureNode)?d.bindTexture(d.TEXTURE_CUBE_MAP,null):d.bindTexture(d.TEXTURE_2D,null))}else x3dom.debug.logError("[Context|RenderShape] No Shader is set!")}else x3dom.debug.logError("[Context|RenderShape] No valid Shape!")},e.prototype.updatePopState=function(e,t,i,o,s,r,n,a){var d=x3dom.nodeTypes.PopGeometry.ErrorToleranceFactor*t._vf.precisionFactor;(a<=1||n.isMovingOrAnimating())&&(d*=x3dom.nodeTypes.PopGeometry.PrecisionFactorOnMove);var l=16;if(d>0){var h=s.getViewpoint(),f=h.getImgPlaneHeightAtDistOne(),u=h.getNear(),c=r.multMatrixPnt(t._vf.position),_=.5*r.multMatrixVec(t._vf.size).length(),m=2*(.5*r.multMatrixVec(t._vf.maxBBSize).length())/(d*(Math.max(-c.z-_,u)*(f/n._height)));l=(l=Math.ceil(Math.log(m)/.693147180559945))<1?1:l>16?16:l}var p=t._vf.minPrecisionLevel,x=t._vf.maxPrecisionLevel;l=-1!=p&&l<p?p:l,l=-1!=x&&l>x?x:l;var g=o.levelsAvailable<l?o.levelsAvailable:l;l=g,d<=1&&(l=l==t.getNumLevels()?16:l);var v=t._vf.indexedRendering,y=t._mesh;y._numCoords=0,y._numFaces=0;for(var T=0;T<g;++T){var b=o.numVerticesAtLevel[T];y._numCoords+=b,y._numFaces+=(v?t.getNumIndicesByLevel(T):b)/3}x3dom.nodeTypes.PopGeometry.numRenderedVerts+=y._numCoords,x3dom.nodeTypes.PopGeometry.numRenderedTris+=y._numFaces,y.currentLOD=l,t.adaptVertexCount(v?3*y._numFaces:y._numCoords),i.PG_maxBBSize=t._vf.maxBBSize.toGL(),i.PG_bbMin=t._bbMinBySize,i.PG_numAnchorVertices=t._vf.numAnchorVertices,i.PG_bbMaxModF=t._vf.bbMaxModF.toGL(),i.PG_bboxShiftVec=t._vf.bbShiftVec.toGL(),i.PG_precisionLevel=l,i.PG_powPrecision=x3dom.nodeTypes.PopGeometry.powLUT[l-1]},e.prototype.pickValue=function(e,t,i,o,s,r){x3dom.Utils.startMeasure("picking");var n=e._scene,a=this.ctx3d;if(!(a&&n&&n._webgl&&n.drawableCollection))return!1;var d,l,h=n._vf.pickMode.toLowerCase(),f=0;switch(h){case"box":return!1;case"idbuf":f=0;break;case"idbuf24":f=3;break;case"idbufid":f=4;break;case"color":f=1;break;case"texcoord":f=2}arguments.length>4?(d=s,l=r):(d=e._last_mat_view,l=e._last_mat_scene);var u=x3dom.fields.SFVec3f.copy(n._lastMin),c=x3dom.fields.SFVec3f.copy(n._lastMax),_=d.inverse().e3(),m=x3dom.fields.SFVec3f.copy(_),p=x3dom.fields.SFVec3f.copy(_);m.x>u.x&&(m.x=u.x),m.y>u.y&&(m.y=u.y),m.z>u.z&&(m.z=u.z),p.x<c.x&&(p.x=c.x),p.y<c.y&&(p.y=c.y),p.z<c.z&&(p.z=c.z),n._lastMin.setValues(m),n._lastMax.setValues(p);var x=n._lastMax.subtract(n._lastMin).length();n.getViewpoint().getFar()&&(x=Math.min(x,n.getViewpoint().getFar()));var g=e.getCCtoWCMatrix();n._lastMin.setValues(u),n._lastMax.setValues(c);var v=x3dom.nodeTypes.Shape.objectID+2;this.renderPickingPass(a,n,d,l,_,x,f,t,i,2,2);var y=n._webgl.fboPick.pixelData;if(y&&y.length){var T,b,S,F,E,M,C=new x3dom.fields.SFVec3f(0,0,0),w=new x3dom.fields.SFVec3f(0,0,1),A=0,R=y[A+3],D=1/n._webgl.pickScale,N=1/256;0==f?(R+=256*y[A+2],b=y[A]/255*N+y[A+1]/255,S=e.calcViewRay(t,i,g),C=_.add(S.dir.multiply(b*x)),b=y[A=4]/255*N+y[A+1]/255,F=e.calcViewRay(t+D,i,g),E=(E=_.add(F.dir.multiply(b*x))).subtract(C).normalize(),b=y[A=8]/255*N+y[A+1]/255,F=e.calcViewRay(t,i-D,g),M=(M=_.add(F.dir.multiply(b*x))).subtract(C).normalize(),w=E.cross(M).normalize()):3==f?(R+=256*y[A+2]+65536*y[A+1],b=y[A]/255,S=e.calcViewRay(t,i,g),C=_.add(S.dir.multiply(b*x)),b=y[A=4]/255,F=e.calcViewRay(t+D,i,g),E=(E=_.add(F.dir.multiply(b*x))).subtract(C).normalize(),b=y[A=8]/255,F=e.calcViewRay(t,i-D,g),M=(M=_.add(F.dir.multiply(b*x))).subtract(C).normalize(),w=E.cross(M).normalize()):4==f?(R+=256*y[A+2],T=y[A+1],T+=256*y[A],0==R&&T>0&&T<v&&(R=T)):(C.x=y[A],C.y=y[A+1],C.z=y[A+2]);var I,P,V="shadowObjectIdChanged",L=Math.max(o>>>8,255&o);if(R>=v){var O;R-=v;var B=t*e._inverseDevicePixelRatio,U=i*e._inverseDevicePixelRatio;if(4!=f?(e._pickingInfo.pickPos=C,e._pick.setValues(C),e._pickingInfo.pickNorm=w,e._pickNorm.setValues(w),e._pickingInfo.pickObj=null,e._pickingInfo.lastClickObj=null,O=n._xmlNode):(e._pickingInfo.pickObj=x3dom.nodeTypes.Shape.idMap.nodeID[T],O=e._pickingInfo.pickObj._xmlNode),I=e._pickingInfo.shadowObjectId!=R,e._pickingInfo.lastShadowObjectId=e._pickingInfo.shadowObjectId,e._pickingInfo.shadowObjectId=R,(I||L)&&n._xmlNode&&(n._xmlNode["on"+V]||n._xmlNode.hasAttribute("on"+V)||n._listeners[V])&&(P={target:n._xmlNode,type:V,button:L,mouseup:o>>>8>0,layerX:B,layerY:U,shadowObjectId:R,worldX:C.x,worldY:C.y,worldZ:C.z,normalX:w.x,normalY:w.y,normalZ:w.z,hitPnt:C.toGL(),hitObject:O,cancelBubble:!1,stopPropagation:function(){this.cancelBubble=!0},preventDefault:function(){this.cancelBubble=!0}},n.callEvtHandler("on"+V,P)),n._shadowIdMap&&n._shadowIdMap.mapping&&R<n._shadowIdMap.mapping.length){var X,k,G,z=n._shadowIdMap.mapping[R].usage;for(S||(S=e.calcViewRay(t,i,g)),k=0;k<z.length;k++)if((G=n._nameSpace.defMap[z[k]])&&G.doIntersect(S)){e._pickingInfo.pickObj=G;break}for(X=0;X<n._nameSpace.childSpaces.length;X++)for(k=0;k<z.length;k++)if((G=n._nameSpace.childSpaces[X].defMap[z[k]])&&G.doIntersect(S)){e._pickingInfo.pickObj=G;break}}}else I=-1!=e._pickingInfo.shadowObjectId,e._pickingInfo.shadowObjectId=-1,I&&n._xmlNode&&(n._xmlNode["on"+V]||n._xmlNode.hasAttribute("on"+V)||n._listeners[V])&&(P={target:n._xmlNode,type:V,button:L,mouseup:o>>>8>0,layerX:B,layerY:U,shadowObjectId:e._pickingInfo.shadowObjectId,cancelBubble:!1,stopPropagation:function(){this.cancelBubble=!0},preventDefault:function(){this.cancelBubble=!0}},n.callEvtHandler("on"+V,P)),R>0?(e._pickingInfo.pickPos=C,e._pickingInfo.pickNorm=w,e._pickingInfo.pickObj=x3dom.nodeTypes.Shape.idMap.nodeID[R]):(e._pickingInfo.pickObj=null,e._pickingInfo.lastClickObj=null)}var H=x3dom.Utils.stopMeasure("picking");return this.x3dElem.runtime.addMeasurement("PICKING",H),!0},e.prototype.pickRect=function(e,t,i,o,s){var r=this.ctx3d,n=e?e._scene:null;if(!(r&&n&&n._webgl&&n.drawableCollection))return!1;var a,d=e._last_mat_view.inverse().e3(),l=n._lastMax.subtract(n._lastMin).length(),h=t<=o?t:o,f=i>=s?i:s,u=(1+Math.abs(o-t))*n._webgl.pickScale,c=(1+Math.abs(s-i))*n._webgl.pickScale;this.renderPickingPass(r,n,e._last_mat_view,e._last_mat_scene,d,l,0,h,f,u<1?1:u,c<1?1:c);var _=[];for(a=0;n._webgl.fboPick.pixelData&&a<n._webgl.fboPick.pixelData.length;a+=4){var m=n._webgl.fboPick.pixelData[a+3]+256*n._webgl.fboPick.pixelData[a+2];m>0&&_.push(m)}_.sort(),_=function(e){for(var t=[],i=e.length,o=0;o<i;o++){for(var s=o+1;s<i;s++)e[o]===e[s]&&(s=++o);t.push(e[o])}return t}(_);var p,x=[],g=x3dom.nodeTypes.Shape.objectID+2;for(a=0;a<_.length;a++)(m=_[a])>=g?m-=g:(p=(p=x3dom.nodeTypes.Shape.idMap.nodeID[m])&&p._xmlNode?p._xmlNode:null)&&x.push(p);return x},e.prototype.renderScene=function(e,t){var i=this.ctx3d,o=e._scene;if(null!==i&&null!==o){var s,r,n,a,d,l,h,f,u,c,_,m=e._doc._nodeBag.renderTextures,p=m.length,x=null,g=i.UNSIGNED_BYTE,v=i.UNSIGNED_BYTE;x3dom.caps.FP_TEXTURES&&(g=i.FLOAT,v=i.FLOAT,x3dom.caps.FPL_TEXTURES||!0);var y=[-1,-1,1,-1,-1,1,-1,1,1,-1,1,1];if(o.updateVolume(),o._webgl){var T=Math.round(this.canvas.width*o._webgl.pickScale),b=Math.round(this.canvas.height*o._webgl.pickScale);for(o._webgl._currFboWidth===T&&o._webgl._currFboHeight===b||(o._webgl._currFboWidth=T,o._webgl._currFboHeight=b,o._webgl.fboPick=x3dom.Utils.initFBO(i,T,b,o._webgl.fboPick.type,!1,!0),o._webgl.fboPick.pixelData=null,x3dom.debug.logInfo("Refreshed picking FBO to size ("+T+", "+b+")")),r=0;r<p;r++)(s=m[r])._webgl&&s._webgl.fbo&&s._webgl.fbo.width==s._vf.dimensions[0]&&s._webgl.fbo.height==s._vf.dimensions[1]||(s.invalidateGLObject(),s._cleanupGLObjects?s._cleanupGLObjects():s._cleanupGLObjects=function(e){e||i.deleteTexture(this._webgl.fbo.tex),this._webgl.fbo.dtex&&i.deleteTexture(this._webgl.fbo.dtex),this._webgl.fbo.rbo&&i.deleteRenderbuffer(this._webgl.fbo.rbo),i.bindFramebuffer(i.FRAMEBUFFER,null),i.deleteFramebuffer(this._webgl.fbo.fbo),this._webgl.fbo.rbo=null,this._webgl.fbo.fbo=null},x=s._cf.textureProperties.node,c=s.requirePingPong()?i.UNSIGNED_BYTE:g,s._webgl={},s._webgl.fbo=x3dom.Utils.initFBO(i,s._vf.dimensions[0],s._vf.dimensions[1],c,x&&x._vf.generateMipMaps,s._vf.depthMap||!s.requirePingPong()),s.requirePingPong()&&(_=s._vf.dimensions[0]+"x"+s._vf.dimensions[1],void 0===o._webgl.refinement[_]&&(o._webgl.refinement[_]=x3dom.Utils.initFBO(i,s._vf.dimensions[0],s._vf.dimensions[1],c,!1,!1)),s._webgl.texture=null),x3dom.debug.logInfo("Init/resize RenderedTexture_"+r+" to size "+s._vf.dimensions[0]+" x "+s._vf.dimensions[1]));for(h=(n=e.getShadowedLights()).length,d=0;d<h;d++)if(f=n[d]._vf.shadowMapSize,a=x3dom.isa(n[d],x3dom.nodeTypes.PointLight)?6:Math.max(1,Math.min(n[d]._vf.shadowCascades,6)),void 0===o._webgl.fboShadow[d]||o._webgl.fboShadow[d].length!=a||o._webgl.fboShadow[d][0].height!=f)for(o._webgl.fboShadow[d]=[],l=0;l<a;l++)o._webgl.fboShadow[d][l]=x3dom.Utils.initFBO(i,f,f,v,!1,!0);for(d=0;d<h;d++){for(f=o._webgl.fboShadow[d][0].height,u=!1,l=0;l<o._webgl.fboBlur.length;l++)f==o._webgl.fboBlur[l].height&&(u=!0);u||(o._webgl.fboBlur[o._webgl.fboBlur.length]=x3dom.Utils.initFBO(i,f,f,v,!1,!0))}((x3dom.SSAO.isEnabled(o)||o._webgl.fboShadow.length>0)&&void 0===o._webgl.fboScene||o._webgl.fboScene&&(this.canvas.width!=o._webgl.fboScene.width||this.canvas.height!=o._webgl.fboScene.height))&&(o._webgl.fboScene=x3dom.Utils.initFBO(i,this.canvas.width,this.canvas.height,v,!1,!0))}else{for(o._webgl={},this.setupFgnds(i,o),o._webgl.pickScale=.5,o._webgl._currFboWidth=Math.round(this.canvas.width*o._webgl.pickScale),o._webgl._currFboHeight=Math.round(this.canvas.height*o._webgl.pickScale),o._webgl.fboPick=x3dom.Utils.initFBO(i,o._webgl._currFboWidth,o._webgl._currFboHeight,i.UNSIGNED_BYTE,!1,!0),o._webgl.fboPick.pixelData=null,o._webgl.normalShader=this.cache.getShader(i,x3dom.shader.NORMAL),o._webgl.fboShadow=[],h=(n=e.getShadowedLights()).length,d=0;d<h;d++)for(f=n[d]._vf.shadowMapSize,a=x3dom.isa(n[d],x3dom.nodeTypes.PointLight)?6:Math.max(1,Math.min(n[d]._vf.shadowCascades,6)),o._webgl.fboShadow[d]=[],l=0;l<a;l++)o._webgl.fboShadow[d][l]=x3dom.Utils.initFBO(i,f,f,v,!1,!0);for((o._webgl.fboShadow.length>0||x3dom.SSAO.isEnabled(o))&&(o._webgl.fboScene=x3dom.Utils.initFBO(i,this.canvas.width,this.canvas.height,v,!1,!0)),o._webgl.fboBlur=[],d=0;d<h;d++){for(f=o._webgl.fboShadow[d][0].height,u=!1,l=0;l<o._webgl.fboBlur.length;l++)f==o._webgl.fboBlur[l].height&&(u=!0);u||(o._webgl.fboBlur[o._webgl.fboBlur.length]=x3dom.Utils.initFBO(i,f,f,v,!1,!0))}for(o._webgl.ppBuffer=i.createBuffer(),i.bindBuffer(i.ARRAY_BUFFER,o._webgl.ppBuffer),i.bufferData(i.ARRAY_BUFFER,new Float32Array(y),i.STATIC_DRAW),o._webgl.refinement={stamps:new Array(2),positionBuffer:i.createBuffer()},i.bindBuffer(i.ARRAY_BUFFER,o._webgl.refinement.positionBuffer),i.bufferData(i.ARRAY_BUFFER,new Float32Array(y),i.STATIC_DRAW),r=0;r<p;r++)x=(s=m[r])._cf.textureProperties.node,c=s.requirePingPong()?i.UNSIGNED_BYTE:g,s._webgl={},s._webgl.fbo=x3dom.Utils.initFBO(i,s._vf.dimensions[0],s._vf.dimensions[1],c,x&&x._vf.generateMipMaps,s._vf.depthMap||!s.requirePingPong()),s._cleanupGLObjects=function(e){e||i.deleteTexture(this._webgl.fbo.tex),this._webgl.fbo.dtex&&i.deleteTexture(this._webgl.fbo.dtex),this._webgl.fbo.rbo&&i.deleteFramebuffer(this._webgl.fbo.rbo),i.bindFramebuffer(i.FRAMEBUFFER,null),i.deleteFramebuffer(this._webgl.fbo.fbo),this._webgl.fbo.rbo=null,this._webgl.fbo.fbo=null},s.requirePingPong()&&(_=s._vf.dimensions[0]+"x"+s._vf.dimensions[1],void 0===o._webgl.refinement[_]&&(o._webgl.refinement[_]=x3dom.Utils.initFBO(i,s._vf.dimensions[0],s._vf.dimensions[1],c,!1,!1)),s._webgl.texture=null);e._last_mat_view=x3dom.fields.SFMatrix4f.identity(),e._last_mat_proj=x3dom.fields.SFMatrix4f.identity(),e._last_mat_scene=x3dom.fields.SFMatrix4f.identity(),this._calledViewpointChangedHandler=!1}var S=o.getEnvironment();S.checkSanity();var F=o.getBackground();this.setupScene(i,F),this.numFaces=0,this.numCoords=0,this.numDrawCalls=0;var E=e.getProjectionMatrix(),M=e.getViewMatrix();if(!this._calledViewpointChangedHandler||!e._last_mat_view.equals(M)){var C=o.getViewpoint(),w="viewpointChanged";try{if(C.hasEventListener(w)||o.hasEventListener(w)){var A=C.getCurrentTransform(),R=(A=A.inverse().mult(M)).inverse(),D=new x3dom.fields.Quaternion(0,0,1,0);D.setValue(R);var N=R.e3(),I={target:C._xmlNode,type:w,matrix:A,position:N,orientation:D.toAxisAngle(),cancelBubble:!1,stopPropagation:function(){this.cancelBubble=!0},preventDefault:function(){this.cancelBubble=!0}};C.hasEventListener(w)&&C.callEvtHandler("on"+w,I),o.hasEventListener(w)&&o.callEvtHandler("on"+w,I),C.callEvtHandler("on"+w,I),this._calledViewpointChangedHandler=!0}}catch(e){x3dom.debug.logException(e)}}e._last_mat_view=M,e._last_mat_proj=E;var P=E.mult(M);if(e._last_mat_scene=P,o.drawableCollection=null,!o.drawableCollection){var V={viewArea:e,sortTrans:S._vf.sortTrans,viewMatrix:M,projMatrix:E,sceneMatrix:P,frustumCulling:!0,smallFeatureThreshold:S._smallFeatureThreshold,context:this,gl:i};o.drawableCollection=new x3dom.DrawableCollection(V),x3dom.Utils.startMeasure("traverse"),o.collectDrawableObjects(x3dom.fields.SFMatrix4f.identity(),o.drawableCollection,!0,!1,0,[]);var L=x3dom.Utils.stopMeasure("traverse");this.x3dElem.runtime.addMeasurement("TRAVERSE",L)}x3dom.Utils.startMeasure("sorting"),o.drawableCollection.sort();var O=x3dom.Utils.stopMeasure("sorting");this.x3dElem.runtime.addMeasurement("SORT",O);var B,U=e.getLights(),X=U.length,k=[],G=[],z=0;x3dom.Utils.startMeasure("shadow");for(var H=e.getLightMatrix(U),j=0;j<X;j++)if(U[j]._vf.shadowIntensity>0){var W=H[j],Y=o._webgl.fboShadow[z],q=Math.max(0,Math.min(1,U[j]._vf.shadowOffset));if(x3dom.isa(U[j],x3dom.nodeTypes.PointLight))for(B=e.getWCtoLCMatricesPointLight(W,U[j],E),d=0;d<6;d++)this.renderShadowPass(i,e,B[d],M,Y[d],q,!1);else{var Q=Math.max(1,Math.min(U[j]._vf.shadowCascades,6));for(B=e.getWCtoLCMatricesCascaded(W,U[j],E),d=0;d<Q;d++)this.renderShadowPass(i,e,B[d],M,Y[d],q,!1)}z++,k[k.length]=B,G[G.length]=W}if(z>0||x3dom.SSAO.isEnabled(o)){this.renderShadowPass(i,e,P,M,o._webgl.fboScene,0,!0);var K=x3dom.Utils.stopMeasure("shadow");this.x3dElem.runtime.addMeasurement("SHADOW",K)}else this.x3dElem.runtime.removeMeasurement("SHADOW");for(B=e.getWCtoLCMatrix(e.getLightMatrix()[0]),r=0;r<p;r++)this.renderRTPass(i,e,m[r]);for(x3dom.Utils.startMeasure("render"),this.stateManager.viewport(0,0,this.canvas.width,this.canvas.height),F._webgl.render(i,M,E,e),x3dom.nodeTypes.PopGeometry.numRenderedVerts=0,x3dom.nodeTypes.PopGeometry.numRenderedTris=0,h=o.drawableCollection.length,S._vf.smallFeatureCulling&&S._lowPriorityThreshold<1&&e.isMovingOrAnimating()&&!(h=Math.floor(h*S._lowPriorityThreshold))&&o.drawableCollection.length&&(h=1),this.stateManager.unsetProgram(),d=0;d<h;d++){var Z=o.drawableCollection.get(d);this.renderShape(Z,e,U,X,M,P,B,E,i)}if(z>0&&this.renderShadows(i,e,n,k,G,M,E,P),this.stateManager.disable(i.BLEND),this.stateManager.disable(i.DEPTH_TEST),e._numRenderedNodes=h,x3dom.SSAO.isEnabled(o)&&x3dom.SSAO.renderSSAO(this.stateManager,i,o,this.canvas),void 0!==e._visDbgBuf&&e._visDbgBuf){var J=o._vf.pickMode.toLowerCase();0!=J.indexOf("idbuf")&&"color"!=J&&"texcoord"!=J||(this.stateManager.viewport(0,3*this.canvas.height/4,this.canvas.width/4,this.canvas.height/4),o._fgnd._webgl.render(i,o._webgl.fboPick.tex)),(z>0||x3dom.SSAO.isEnabled(o))&&(this.stateManager.viewport(this.canvas.width/4,3*this.canvas.height/4,this.canvas.width/4,this.canvas.height/4),o._fgnd._webgl.render(i,o._webgl.fboScene.tex));var $=3,ee=2;for(d=0;d<z;d++){Y=o._webgl.fboShadow[d];for(l=0;l<Y.length;l++)this.stateManager.viewport(ee*this.canvas.width/4,$*this.canvas.height/4,this.canvas.width/4,this.canvas.height/4),o._fgnd._webgl.render(i,Y[l].tex),ee<2?ee++:(ee=0,$--)}for(r=0;r<p;r++)(s=m[r])._webgl.fbo.fbo&&(this.stateManager.viewport(r*this.canvas.width/8,5*this.canvas.height/8,this.canvas.width/8,this.canvas.height/8),o._fgnd._webgl.render(i,s._webgl.fbo.tex))}i.finish();var te=x3dom.Utils.stopMeasure("render");this.x3dElem.runtime.addMeasurement("RENDER",te),this.x3dElem.runtime.addMeasurement("DRAW",h?te/h:0),this.x3dElem.runtime.addInfo("#NODES:",o.drawableCollection.numberOfNodes),this.x3dElem.runtime.addInfo("#SHAPES:",e._numRenderedNodes),this.x3dElem.runtime.addInfo("#DRAWS:",this.numDrawCalls),this.x3dElem.runtime.addInfo("#POINTS:",this.numCoords),this.x3dElem.runtime.addInfo("#TRIS:",this.numFaces)}},e.prototype.renderPingPongPass=function(e,t,i){var o=t._scene,s=i._vf.dimensions[0]+"x"+i._vf.dimensions[1],r=o._webgl.refinement[s];if(0!=i._currLoadLevel||o._webgl.refinement.stamps[0]&&o._webgl.refinement.stamps[1]||(o._webgl.refinement.stamps[0]=this.cache.getTexture2D(e,i._nameSpace.doc,i._nameSpace.getURL(i._vf.stamp0),!1,"anonymous",!1,!1),o._webgl.refinement.stamps[1]=this.cache.getTexture2D(e,i._nameSpace.doc,i._nameSpace.getURL(i._vf.stamp1),!1,"anonymous",!1,!1)),i._currLoadLevel<i._loadLevel){i._currLoadLevel++,i._webgl.texture&&e.deleteTexture(i._webgl.texture);var n=i._vf.url[0]+"/"+i._currLoadLevel+"."+i._vf.format;i._webgl.texture=x3dom.Utils.createTexture2D(e,i._nameSpace.doc,i._nameSpace.getURL(n),!1,"anonymous",!1,!1),i._vf.iterations%2==0?i._currLoadLevel%2!=0?i._repeat.x*=2:i._repeat.y*=2:i._currLoadLevel%2==0?i._repeat.x*=2:i._repeat.y*=2}if(i._webgl.texture.ready&&o._webgl.refinement.stamps[0].ready&&o._webgl.refinement.stamps[1].ready){this.stateManager.bindFramebuffer(e.FRAMEBUFFER,r.fbo),this.stateManager.viewport(0,0,r.width,r.height),this.stateManager.disable(e.BLEND),this.stateManager.disable(e.CULL_FACE),this.stateManager.disable(e.DEPTH_TEST),e.clearColor(0,0,0,1),e.clearDepth(1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT);var a=this.cache.getShader(e,x3dom.shader.TEXTURE_REFINEMENT);this.stateManager.useProgram(a),e.bindBuffer(e.ARRAY_BUFFER,o._webgl.refinement.positionBuffer),e.vertexAttribPointer(a.position,2,e.FLOAT,!1,0,0),e.enableVertexAttribArray(a.position),a.stamp=0,e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,o._webgl.refinement.stamps[(i._currLoadLevel+1)%2]),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.REPEAT),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.REPEAT),i._currLoadLevel>1&&(a.lastTex=1,e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,i._webgl.fbo.tex),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)),a.curTex=2,e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,i._webgl.texture),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),a.mode=i._currLoadLevel-1,a.repeat=i._repeat.toGL(),e.drawArrays(e.TRIANGLES,0,6),this.stateManager.bindFramebuffer(e.FRAMEBUFFER,i._webgl.fbo.fbo),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT),a.mode=0,a.curTex=2,e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,r.tex),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.drawArrays(e.TRIANGLES,0,6),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,null),e.disableVertexAttribArray(a.position),this.stateManager.bindFramebuffer(e.FRAMEBUFFER,null),this.stateManager.viewport(0,0,this.canvas.width,this.canvas.height),i._vf.autoRefinement&&i.nextLevel(),i._currLoadLevel==i._vf.maxLevel&&i._currLoadLevel++,i._webgl.fbo.mipMap&&(e.bindTexture(e.TEXTURE_2D,i._webgl.fbo.tex),e.generateMipmap(e.TEXTURE_2D),e.bindTexture(e.TEXTURE_2D,null)),i.requirePingPong()||(e.deleteTexture(i._webgl.texture),delete i._webgl.texture,i._cleanupGLObjects(!0)),i._renderedImage++}},e.prototype.renderRTPass=function(e,t,i){if(x3dom.isa(i,x3dom.nodeTypes.RefinementTexture))i.requirePingPong()&&this.renderPingPongPass(e,t,i);else{switch(i._vf.update.toUpperCase()){case"NONE":return;case"NEXT_FRAME_ONLY":if(!i._needRenderUpdate)return;i._needRenderUpdate=!1}var o,s,r=t._scene,n=null,a=i.getViewMatrix(),d=i.getProjectionMatrix(),l=d.mult(a),h=t.getLightMatrix()[0],f=t.getWCtoLCMatrix(h),u=i._cf.excludeNodes.nodes,c=u.length,_=new Array(c);for(o=0;o<c;o++){var m=u[o].renderFlag&&u[o].renderFlag();_[o]=void 0===m?-1:!0===m?1:0,i._cf.excludeNodes.nodes[o]._vf.visible=!1}this.stateManager.bindFramebuffer(e.FRAMEBUFFER,i._webgl.fbo.fbo),this.stateManager.viewport(0,0,i._webgl.fbo.width,i._webgl.fbo.height),null===i._cf.background.node?(e.clearColor(0,0,0,1),e.clearDepth(1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT|e.STENCIL_BUFFER_BIT)):i._cf.background.node===r.getBackground()?(n=r.getBackground())._webgl.render(e,a,d,t):(n=i._cf.background.node,this.setupScene(e,n),n._webgl.render(e,a,d,t)),this.stateManager.depthFunc(e.LEQUAL),this.stateManager.enable(e.DEPTH_TEST),this.stateManager.enable(e.CULL_FACE),this.stateManager.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE),this.stateManager.enable(e.BLEND);var p,x=t.getLights(),g=x.length,v=i._cf.scene.node;if(v&&v!==r){var y={viewArea:t,sortTrans:r.getEnvironment()._vf.sortTrans,viewMatrix:a,projMatrix:d,sceneMatrix:l,frustumCulling:!1,smallFeatureThreshold:1,context:this,gl:e};if(v.numberOfNodes=0,v.drawableCollection=new x3dom.DrawableCollection(y),v.collectDrawableObjects(x3dom.fields.SFMatrix4f.identity(),v.drawableCollection,!0,!1,0,[]),v.drawableCollection.sort(),s=v.drawableCollection.length,i._vf.showNormals)this.renderNormals(e,v,r._webgl.normalShader,a,l);else for(this.stateManager.unsetProgram(),o=0;o<s;o++)(p=v.drawableCollection.get(o)).shape.renderFlag()&&this.renderShape(p,t,x,g,a,l,f,d,e)}else if(s=r.drawableCollection.length,i._vf.showNormals)this.renderNormals(e,r,r._webgl.normalShader,a,l);else for(this.stateManager.unsetProgram(),o=0;o<s;o++)p=r.drawableCollection.get(o),this.renderShape(p,t,x,g,a,l,f,d,e);for(this.stateManager.disable(e.BLEND),this.stateManager.disable(e.DEPTH_TEST),e.flush(),this.stateManager.bindFramebuffer(e.FRAMEBUFFER,null),i._webgl.fbo.mipMap&&(e.bindTexture(e.TEXTURE_2D,i._webgl.fbo.tex),e.generateMipmap(e.TEXTURE_2D),e.bindTexture(e.TEXTURE_2D,null)),o=0;o<c;o++)0!==_[o]&&(i._cf.excludeNodes.nodes[o]._vf.visible=!0)}},e.prototype.renderNormals=function(e,t,i,o,s){if(i&&t){this.stateManager.depthFunc(e.LEQUAL),this.stateManager.enable(e.DEPTH_TEST),this.stateManager.enable(e.CULL_FACE),this.stateManager.disable(e.BLEND),this.stateManager.useProgram(i);for(var r=x3dom.fields.SFVec3f.NullVector.toGL(),n=x3dom.fields.SFVec3f.OneVector.toGL(),a=0,d=t.drawableCollection.length;a<d;a++){var l=t.drawableCollection.get(a),h=l.transform,f=l.shape,u=f._webgl;if(u&&f&&f.renderFlag()){var c=f._cf.geometry.node,_=c._mesh,m=o.mult(h).inverse();i.normalMatrix=m.transpose().toGL(),i.modelViewProjectionMatrix=s.mult(h).toGL(),u.coordType!=e.FLOAT?(0!=u.popGeometry||4==_._numPosComponents&&x3dom.Utils.isUnsignedType(c._vf.coordType)?i.bgCenter=c.getMin().toGL():i.bgCenter=c._vf.position.toGL(),i.bgSize=c._vf.size.toGL(),i.bgPrecisionMax=c.getPrecisionMax("coordType")):(i.bgCenter=r,i.bgSize=n,i.bgPrecisionMax=1),u.normalType!=e.FLOAT?i.bgPrecisionNorMax=c.getPrecisionMax("normalType"):i.bgPrecisionNorMax=1,f.isSolid()?(this.stateManager.enable(e.CULL_FACE),f.isCCW()?this.stateManager.frontFace(e.CCW):this.stateManager.frontFace(e.CW)):this.stateManager.disable(e.CULL_FACE);for(var p=0,x=u.positions.length;p<x;p++){var g,v,y,T=6*p;if(void 0!==i.position&&u.buffers[T+x3dom.BUFFER_IDX.POSITION]&&u.indexes[p]){if(u.buffers[T+x3dom.BUFFER_IDX.INDEX]&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,u.buffers[T+x3dom.BUFFER_IDX.INDEX]),this.setVertexAttribPointerPosition(e,f,T,p),this.setVertexAttribPointerNormal(e,f,T,p),u.binaryGeometry>0||u.popGeometry>0)for(g=0,y=0,v=c._vf.vertexCount.length;g<v;g++)this.drawElements(e,u.primType[g],c._vf.vertexCount[g],u.indexType,x3dom.Utils.getByteAwareOffset(y,u.indexType,e)),y+=c._vf.vertexCount[g];else if(u.binaryGeometry<0||u.popGeometry<0)for(g=0,y=0,v=c._vf.vertexCount.length;g<v;g++)this.drawArrays(e,u.primType[g],y,c._vf.vertexCount[g]),y+=c._vf.vertexCount[g];else if(indicesReady&&u.bufferGeometry>0)this.drawElements(e,u.primType[0],c._vf.vertexCount[0],u.indexType,f._indexOffset);else if(u.bufferGeometry<0)this.drawArrays(e,u.primType[0],0,c._vf.vertexCount[0]);else if(c.hasIndexOffset()){var b=f.tessellationProperties();for(g=0,v=b.length;g<v;g++)this.drawElements(e,u.primType,b[g].count,u.indexType,b[g].offset*x3dom.Utils.getOffsetMultiplier(u.indexType,e))}else 0==u.indexes[p].length?this.drawArrays(e,u.primType,0,u.positions[p].length/3):this.drawElements(e,u.primType,u.indexes[p].length,u.indexType,0);e.disableVertexAttribArray(i.position),void 0!==i.normal&&e.disableVertexAttribArray(i.normal)}}}}}},e.prototype.shutdown=function(e){var t=this.ctx3d,i=e._scene;if(null!=t&&i){var o=i.getBackground();o._webgl&&void 0!==o._webgl.position&&(t.deleteBuffer(o._webgl.buffers[x3dom.BUFFER_IDX.INDEX]),t.deleteBuffer(o._webgl.buffers[x3dom.BUFFER_IDX.POSITION]));var s=i._fgnd;void 0!==s._webgl.position&&(t.deleteBuffer(s._webgl.buffers[x3dom.BUFFER_IDX.INDEX]),t.deleteBuffer(s._webgl.buffers[x3dom.BUFFER_IDX.POSITION]));for(var r=i.drawableCollection?i.drawableCollection.length:0,n=0;n<r;n++){var a=i.drawableCollection.get(n).shape;a._cleanupGLObjects&&a._cleanupGLObjects(!0)}this.cache.Release(t)}},e.prototype.renderShadows=function(e,t,i,o,s,r,n,a){var d=t._scene,l=x3dom.caps.MAX_TEXTURE_IMAGE_UNITS;if(!(l<7)){var h,f,u,c,_,m=1,p=[0];for(u=0;u<i.length;u++){var x=i[u]._vf.shadowFilterSize;for(f=(h=d._webgl.fboShadow[u]).length,c=0;c<f;c++)this.blurTex(e,d,h[c],x);(m+=6)>l&&(p[p.length]=u,m=7)}p[p.length]=i.length;var g=p.length-1,v=n.inverse(),y=a.inverse();this.stateManager.enable(e.BLEND),this.stateManager.blendFunc(e.DST_COLOR,e.ZERO);for(var T=0;T<g;T++){var b=p[T],S=p[T+1],F=[];for(_=b;_<S;_++)F[F.length]=i[_];var E,M,C=this.cache.getShadowRenderingShader(e,F);this.stateManager.useProgram(C),e.bindBuffer(e.ARRAY_BUFFER,d._webgl.ppBuffer),e.vertexAttribPointer(C.position,2,e.FLOAT,!1,0,0),e.enableVertexAttribArray(C.position),C.sceneMap=0,e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,d._webgl.fboScene.tex),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),C.inverseProj=v.toGL(),C.inverseViewProj=y.toGL();for(var w=0,A=0,R=F.length;A<R;A++){for(M=s[A+b],E=o[A+b],h=d._webgl.fboShadow[A+b],f=E.length,u=0;u<f;u++)e.activeTexture(e.TEXTURE1+w),e.bindTexture(e.TEXTURE_2D,h[u].tex),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),C["light"+A+"_"+u+"_ShadowMap"]=w+1,C["light"+A+"_"+u+"_Matrix"]=E[u].toGL(),w++;if(C["light"+A+"_ViewMatrix"]=M.toGL(),!x3dom.isa(F[A],x3dom.nodeTypes.PointLight))for(c=0;c<f;c++){var D=Math.max(1,Math.min(F[A]._vf.shadowCascades,6)),N=Math.max(0,Math.min(F[A]._vf.shadowSplitFactor,1)),I=Math.max(0,Math.min(F[A]._vf.shadowSplitOffset,1)),P=t.getShadowSplitDepths(D,N,I,!1,n);C["light"+A+"_"+c+"_Split"]=P[c+1]}var V=r.mult(F[A].getCurrentTransform());x3dom.isa(F[A],x3dom.nodeTypes.DirectionalLight)?(C["light"+A+"_Type"]=0,C["light"+A+"_On"]=F[A]._vf.on?1:0,C["light"+A+"_Direction"]=V.multMatrixVec(F[A]._vf.direction).toGL(),C["light"+A+"_Attenuation"]=[1,1,1],C["light"+A+"_Location"]=[1,1,1],C["light"+A+"_Radius"]=0,C["light"+A+"_BeamWidth"]=0,C["light"+A+"_CutOffAngle"]=0,C["light"+A+"_ShadowIntensity"]=F[A]._vf.shadowIntensity,C["light"+A+"_ShadowCascades"]=F[A]._vf.shadowCascades,C["light"+A+"_ShadowOffset"]=Math.max(0,Math.min(1,F[A]._vf.shadowOffset))):x3dom.isa(F[A],x3dom.nodeTypes.PointLight)?(C["light"+A+"_Type"]=1,C["light"+A+"_On"]=F[A]._vf.on?1:0,C["light"+A+"_Direction"]=[1,1,1],C["light"+A+"_Attenuation"]=F[A]._vf.attenuation.toGL(),C["light"+A+"_Location"]=V.multMatrixPnt(F[A]._vf.location).toGL(),C["light"+A+"_Radius"]=F[A]._vf.radius,C["light"+A+"_BeamWidth"]=0,C["light"+A+"_CutOffAngle"]=0,C["light"+A+"_ShadowIntensity"]=F[A]._vf.shadowIntensity,C["light"+A+"_ShadowOffset"]=Math.max(0,Math.min(1,F[A]._vf.shadowOffset))):x3dom.isa(F[A],x3dom.nodeTypes.SpotLight)&&(C["light"+A+"_Type"]=2,C["light"+A+"_On"]=F[A]._vf.on?1:0,C["light"+A+"_Direction"]=V.multMatrixVec(F[A]._vf.direction).toGL(),C["light"+A+"_Attenuation"]=F[A]._vf.attenuation.toGL(),C["light"+A+"_Location"]=V.multMatrixPnt(F[A]._vf.location).toGL(),C["light"+A+"_Radius"]=F[A]._vf.radius,C["light"+A+"_BeamWidth"]=F[A]._vf.beamWidth,C["light"+A+"_CutOffAngle"]=F[A]._vf.cutOffAngle,C["light"+A+"_ShadowIntensity"]=F[A]._vf.shadowIntensity,C["light"+A+"_ShadowCascades"]=F[A]._vf.shadowCascades,C["light"+A+"_ShadowOffset"]=Math.max(0,Math.min(1,F[A]._vf.shadowOffset)))}e.drawArrays(e.TRIANGLES,0,6);var L=w+1;for(_=0;_<L;_++)e.activeTexture(e.TEXTURE0+_),e.bindTexture(e.TEXTURE_2D,null);e.disableVertexAttribArray(C.position)}this.stateManager.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA)}},e.prototype.blurTex=function(e,t,i,o){if(!(o<=0)){o=o<5?3:o<7?5:7;for(var s=i.width,r=i.height,n=null,a=0,d=t._webgl.fboBlur.length;a<d;a++)if(r==t._webgl.fboBlur[a].height){n=t._webgl.fboBlur[a];break}this.stateManager.bindFramebuffer(e.FRAMEBUFFER,n.fbo),this.stateManager.viewport(0,0,s,r),this.stateManager.enable(e.BLEND),this.stateManager.blendFunc(e.ONE,e.ZERO),this.stateManager.disable(e.CULL_FACE),this.stateManager.disable(e.DEPTH_TEST),e.clearColor(1,1,1,0),e.clearDepth(1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT);var l=this.cache.getShader(e,x3dom.shader.BLUR);this.stateManager.useProgram(l),e.bindBuffer(e.ARRAY_BUFFER,t._webgl.ppBuffer),e.vertexAttribPointer(l.position,2,e.FLOAT,!1,0,0),e.enableVertexAttribArray(l.position),l.pixelSizeHor=1/s,l.pixelSizeVert=1/r,l.filterSize=o,l.horizontal=!0,l.texture=0,e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,i.tex),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.drawArrays(e.TRIANGLES,0,6),this.stateManager.bindFramebuffer(e.FRAMEBUFFER,i.fbo),e.clearColor(1,1,1,0),e.clearDepth(1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT),l.horizontal=!1,e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,n.tex),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.drawArrays(e.TRIANGLES,0,6),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,null),e.disableVertexAttribArray(l.position),e.flush(),this.stateManager.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),this.stateManager.bindFramebuffer(e.FRAMEBUFFER,null),this.stateManager.viewport(0,0,this.canvas.width,this.canvas.height)}},e.prototype.drawElements=function(e,t,i,o,s,r){if(r=null==r?1:r,r*=this.VRMode,2==x3dom.caps.WEBGL_VERSION)e.drawElementsInstanced(t,i,o,s,r);else if(x3dom.caps.INSTANCED_ARRAYS){this.ctx3d.getExtension("ANGLE_instanced_arrays").drawElementsInstancedANGLE(t,i,o,s,r)}else e.drawElements(t,i,o,s)},e.prototype.drawArrays=function(e,t,i,o,s){if(s=null==s?1:s,s*=this.VRMode,2==x3dom.caps.WEBGL_VERSION)e.drawArraysInstanced(t,i,o,s);else if(x3dom.caps.INSTANCED_ARRAYS){this.ctx3d.getExtension("ANGLE_instanced_arrays").drawArraysInstancedANGLE(t,i,o,s)}else e.drawArrays(t,i,o)},e.prototype.setVertexAttribEyeIdx=function(e,t){if(2==x3dom.caps.WEBGL_VERSION&&null!=t.eyeIdx)this.eyeIdxBuffer?(e.bindBuffer(e.ARRAY_BUFFER,this.eyeIdxBuffer),e.vertexAttribPointer(t.eyeIdx,1,e.FLOAT,!1,0,0),e.enableVertexAttribArray(t.eyeIdx),e.vertexAttribDivisor(t.eyeIdx,1)):(this.eyeIdxBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.eyeIdxBuffer),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,1]),e.STATIC_DRAW),e.vertexAttribPointer(t.eyeIdx,1,e.FLOAT,!1,0,0),e.enableVertexAttribArray(t.eyeIdx),e.vertexAttribDivisor(t.eyeIdx,1));else if(x3dom.caps.INSTANCED_ARRAYS&&null!=t.eyeIdx){var i=this.ctx3d.getExtension("ANGLE_instanced_arrays");this.eyeIdxBuffer?(e.bindBuffer(e.ARRAY_BUFFER,this.eyeIdxBuffer),e.vertexAttribPointer(t.eyeIdx,1,e.FLOAT,!1,0,0),e.enableVertexAttribArray(t.eyeIdx),i.vertexAttribDivisorANGLE(t.eyeIdx,1)):(this.eyeIdxBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.eyeIdxBuffer),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,1]),e.STATIC_DRAW),e.vertexAttribPointer(t.eyeIdx,1,e.FLOAT,!1,0,0),e.enableVertexAttribArray(t.eyeIdx),i.vertexAttribDivisorANGLE(t.eyeIdx,1))}},e.prototype.disableVertexAttribEyeIdx=function(e,t){if(2==x3dom.caps.WEBGL_VERSION&&null!=t.eyeIdx)e.disableVertexAttribArray(t.eyeIdx),e.vertexAttribDivisor(t.eyeIdx,0);else if(x3dom.caps.INSTANCED_ARRAYS&&null!=t.eyeIdx){var i=this.ctx3d.getExtension("ANGLE_instanced_arrays");e.disableVertexAttribArray(t.eyeIdx),i.vertexAttribDivisorANGLE(t.eyeIdx,0)}},e.prototype.setVertexAttribPointerPosition=function(e,t,i,o){var s=t._webgl.shader;if(void 0!==s.position&&t._webgl.buffers[i+x3dom.BUFFER_IDX.POSITION]){var r=t._cf.geometry.node;e.bindBuffer(e.ARRAY_BUFFER,t._webgl.buffers[i+x3dom.BUFFER_IDX.POSITION]),e.vertexAttribPointer(s.position,r._mesh._numPosComponents,t._webgl.coordType,t._webgl.coordNormalized,t._coordStrideOffset[0],t._coordStrideOffset[1]),e.enableVertexAttribArray(s.position)}},e.prototype.setVertexAttribPointerNormal=function(e,t,i,o){var s=t._webgl.shader;if(void 0!==s.normal&&t._webgl.buffers[i+x3dom.BUFFER_IDX.NORMAL]){var r=t._cf.geometry.node;e.bindBuffer(e.ARRAY_BUFFER,t._webgl.buffers[i+x3dom.BUFFER_IDX.NORMAL]),e.vertexAttribPointer(s.normal,r._mesh._numNormComponents,t._webgl.normalType,t._webgl.normalNormalized,t._normalStrideOffset[0],t._normalStrideOffset[1]),e.enableVertexAttribArray(s.normal)}},e.prototype.setVertexAttribPointerTexCoord=function(e,t,i,o){var s=t._webgl.shader;if(void 0!==s.texcoord&&t._webgl.buffers[i+x3dom.BUFFER_IDX.TEXCOORD]){var r=t._cf.geometry.node;e.bindBuffer(e.ARRAY_BUFFER,t._webgl.buffers[i+x3dom.BUFFER_IDX.TEXCOORD]),e.vertexAttribPointer(s.texcoord,r._mesh._numTexComponents,t._webgl.texCoordType,t._webgl.texCoordNormalized,t._texCoordStrideOffset[0],t._texCoordStrideOffset[1]),e.enableVertexAttribArray(s.texcoord)}},e.prototype.setVertexAttribPointerTexCoord2=function(e,t,i,o){var s=t._webgl.shader;if(void 0!==s.texcoord2&&t._webgl.buffers[i+x3dom.BUFFER_IDX.TEXCOORD_1]){var r=t._cf.geometry.node;e.bindBuffer(e.ARRAY_BUFFER,t._webgl.buffers[i+x3dom.BUFFER_IDX.TEXCOORD_1]),e.vertexAttribPointer(s.texcoord2,r._mesh._numTex2Components,t._webgl.texCoord2Type,t._webgl.texCoord2Normalized,t._texCoord2StrideOffset[0],t._texCoord2StrideOffset[1]),e.enableVertexAttribArray(s.texcoord2)}},e.prototype.setVertexAttribPointerColor=function(e,t,i,o){var s=t._webgl.shader;if(void 0!==s.color&&t._webgl.buffers[i+x3dom.BUFFER_IDX.COLOR]){var r=t._cf.geometry.node;e.bindBuffer(e.ARRAY_BUFFER,t._webgl.buffers[i+x3dom.BUFFER_IDX.COLOR]),e.vertexAttribPointer(s.color,r._mesh._numColComponents,t._webgl.colorType,t._webgl.colorNormalized,t._colorStrideOffset[0],t._colorStrideOffset[1]),e.enableVertexAttribArray(s.color)}},e.prototype.setVertexAttribPointerTangent=function(e,t,i,o){var s=t._webgl.shader;if(void 0!==s.tangent&&t._webgl.buffers[i+x3dom.BUFFER_IDX.TANGENT]){var r=t._cf.geometry.node;e.bindBuffer(e.ARRAY_BUFFER,t._webgl.buffers[i+x3dom.BUFFER_IDX.TANGENT]),e.vertexAttribPointer(s.tangent,r._mesh._numTangentComponents,t._webgl.tangentType,t._webgl.tangentNormalized,t._tangentStrideOffset[0],t._tangentStrideOffset[1]),e.enableVertexAttribArray(s.tangent)}},e.prototype.setVertexAttribPointerBinormal=function(e,t,i,o){var s=t._webgl.shader;if(void 0!==s.binormal&&t._webgl.buffers[i+x3dom.BUFFER_IDX.BITANGENT]){var r=t._cf.geometry.node;e.bindBuffer(e.ARRAY_BUFFER,t._webgl.buffers[i+x3dom.BUFFER_IDX.BITANGENT]),e.vertexAttribPointer(s.binormal,r._mesh._numBinormalComponents,t._webgl.binormalType,t._webgl.binormalNormalized,t._binormalStrideOffset[0],t._binormalStrideOffset[1]),e.enableVertexAttribArray(s.binormal)}},e.prototype.setTonemappingOperator=function(e,t){switch(e._scene.getEnvironment()._vf.tonemapping){case"none":t.tonemappingOperator=0;break;case"reinhard":t.tonemappingOperator=1;break;case"uncharted":t.tonemappingOperator=2;break;case"filmic":t.tonemappingOperator=3;break;default:t.tonemappingOperator=0}},function(t,i){var o=["webgl2","webgl","experimental-webgl","moz-webgl","webkit-3d"],s=/mac|ip(hone|od|ad)/i.test(navigator.platform),r=/safari/i.test(navigator.userAgent),n=/trident\//i.test(navigator.userAgent);s&&o.splice(0,1);for(var a=null,d=i.getElementsByTagName("Environment"),l={alpha:!0,depth:!0,stencil:!0,antialias:!!!(d&&d[0]&&d[0].hasAttribute("SSAO")&&"true"===d[0].getAttribute("SSAO").toLowerCase()),premultipliedAlpha:!1,preserveDrawingBuffer:!0,failIfMajorPerformanceCaveat:!0},h=0;h<o.length;h++)try{if(x3dom.caps.RENDERMODE="HARDWARE ("+o[h]+")",(a=t.getContext(o[h],l))||(x3dom.caps.RENDERMODE="SOFTWARE",l.failIfMajorPerformanceCaveat=!1,a=t.getContext(o[h],l),l.failIfMajorPerformanceCaveat=!0),a){var f=new e(a,t,"webgl",i);try{x3dom.caps.VENDOR=a.getParameter(a.VENDOR),x3dom.caps.VERSION=a.getParameter(a.VERSION),x3dom.caps.WEBGL_VERSION=-1===x3dom.caps.VERSION.indexOf("WebGL 2.0")?1:2,x3dom.caps.RENDERER=a.getParameter(a.RENDERER),x3dom.caps.SHADING_LANGUAGE_VERSION=a.getParameter(a.SHADING_LANGUAGE_VERSION),x3dom.caps.RED_BITS=a.getParameter(a.RED_BITS),x3dom.caps.GREEN_BITS=a.getParameter(a.GREEN_BITS),x3dom.caps.BLUE_BITS=a.getParameter(a.BLUE_BITS),x3dom.caps.ALPHA_BITS=a.getParameter(a.ALPHA_BITS),x3dom.caps.DEPTH_BITS=a.getParameter(a.DEPTH_BITS),x3dom.caps.MAX_VERTEX_ATTRIBS=a.getParameter(a.MAX_VERTEX_ATTRIBS),x3dom.caps.MAX_VERTEX_TEXTURE_IMAGE_UNITS=a.getParameter(a.MAX_VERTEX_TEXTURE_IMAGE_UNITS),x3dom.caps.MAX_VARYING_VECTORS=a.getParameter(a.MAX_VARYING_VECTORS),x3dom.caps.MAX_VERTEX_UNIFORM_VECTORS=a.getParameter(a.MAX_VERTEX_UNIFORM_VECTORS),x3dom.caps.MAX_COMBINED_TEXTURE_IMAGE_UNITS=a.getParameter(a.MAX_COMBINED_TEXTURE_IMAGE_UNITS),x3dom.caps.MAX_TEXTURE_SIZE=a.getParameter(a.MAX_TEXTURE_SIZE),x3dom.caps.MAX_TEXTURE_IMAGE_UNITS=a.getParameter(a.MAX_TEXTURE_IMAGE_UNITS),x3dom.caps.MAX_CUBE_MAP_TEXTURE_SIZE=a.getParameter(a.MAX_CUBE_MAP_TEXTURE_SIZE),x3dom.caps.COMPRESSED_TEXTURE_FORMATS=a.getParameter(a.COMPRESSED_TEXTURE_FORMATS),x3dom.caps.MAX_RENDERBUFFER_SIZE=a.getParameter(a.MAX_RENDERBUFFER_SIZE),x3dom.caps.MAX_VIEWPORT_DIMS=a.getParameter(a.MAX_VIEWPORT_DIMS),x3dom.caps.ALIASED_LINE_WIDTH_RANGE=a.getParameter(a.ALIASED_LINE_WIDTH_RANGE),x3dom.caps.ALIASED_POINT_SIZE_RANGE=a.getParameter(a.ALIASED_POINT_SIZE_RANGE),x3dom.caps.SAMPLES=a.getParameter(a.SAMPLES),x3dom.caps.COMPRESSED_TEXTURE=a.getExtension("WEBGL_compressed_texture_s3tc"),x3dom.caps.INDEX_UINT=a.getExtension("OES_element_index_uint"),x3dom.caps.FP_TEXTURES=a.getExtension("OES_texture_float"),x3dom.caps.FPL_TEXTURES=a.getExtension("OES_texture_float_linear"),x3dom.caps.HFP_TEXTURES=a.getExtension("OES_texture_half_float"),x3dom.caps.COLOR_BUFFER_FLOAT=a.getExtension("WEBGL_color_buffer_float"),x3dom.caps.HFPL_TEXTURES=a.getExtension("OES_texture_half_float_linear"),x3dom.caps.STD_DERIVATIVES=a.getExtension("OES_standard_derivatives"),x3dom.caps.DRAW_BUFFERS=a.getExtension("WEBGL_draw_buffers"),x3dom.caps.DEPTH_TEXTURE=a.getExtension("WEBGL_depth_texture"),x3dom.caps.DEBUGRENDERINFO=a.getExtension("WEBGL_debug_renderer_info"),x3dom.caps.ANISOTROPIC=a.getExtension("EXT_texture_filter_anisotropic"),x3dom.caps.TEXTURE_LOD=a.getExtension("EXT_shader_texture_lod"),x3dom.caps.INSTANCED_ARRAYS=a.getExtension("ANGLE_instanced_arrays"),x3dom.caps.ANISOTROPIC&&(x3dom.caps.MAX_ANISOTROPY=a.getParameter(x3dom.caps.ANISOTROPIC.MAX_TEXTURE_MAX_ANISOTROPY_EXT)),x3dom.caps.EXTENSIONS=a.getSupportedExtensions(),x3dom.Utils.isWebGL2Enabled()&&(x3dom.caps.DEPTH_TEXTURE=null,x3dom.caps.INDEX_UINT=!0),x3dom.caps.DEBUGRENDERINFO?(x3dom.caps.UNMASKED_RENDERER_WEBGL=a.getParameter(x3dom.caps.DEBUGRENDERINFO.UNMASKED_RENDERER_WEBGL),x3dom.caps.UNMASKED_VENDOR_WEBGL=a.getParameter(x3dom.caps.DEBUGRENDERINFO.UNMASKED_VENDOR_WEBGL)):(x3dom.caps.UNMASKED_RENDERER_WEBGL="",x3dom.caps.UNMASKED_VENDOR_WEBGL="");var u=x3dom.caps.EXTENSIONS.toString().replace(/,/g,", ");x3dom.debug.logInfo(o[h]+" context found\nVendor: "+x3dom.caps.VENDOR+" "+x3dom.caps.UNMASKED_VENDOR_WEBGL+", Renderer: "+x3dom.caps.RENDERER+" "+x3dom.caps.UNMASKED_RENDERER_WEBGL+", Version: "+x3dom.caps.VERSION+", ShadingLangV.: "+x3dom.caps.SHADING_LANGUAGE_VERSION+", MSAA samples: "+x3dom.caps.SAMPLES+"\nExtensions: "+u),x3dom.caps.INDEX_UINT&&(x3dom.Utils.maxIndexableCoords=4294967295),s&&(x3dom.caps.HFP_TEXTURES=!1,x3dom.caps.FP_TEXTURES=!1),r&&(x3dom.caps.TEXTURE_LOD=!1),n&&(x3dom.caps.INSTANCED_ARRAYS=!1)}catch(e){x3dom.debug.logWarning("Your browser probably supports an older WebGL version."),f=null}return f}}catch(e){x3dom.debug.logWarning(e)}return null}}(),x3dom.SSAO={},x3dom.SSAO.isEnabled=function(e){return e.getEnvironment()._vf.SSAO},x3dom.SSAO.reinitializeShadersIfNecessary=function(e){void 0===x3dom.SSAO.shaderProgram&&(x3dom.SSAO.shaderProgram=x3dom.Utils.wrapProgram(e,new x3dom.shader.SSAOShader(e),"ssao")),void 0===x3dom.SSAO.blurShaderProgram&&(x3dom.SSAO.blurShaderProgram=x3dom.Utils.wrapProgram(e,new x3dom.shader.SSAOBlurShader(e),"ssao-blur"))},x3dom.SSAO.reinitializeRandomTextureIfNecessary=function(e,t){var i=t.getEnvironment()._vf.SSAOrandomTextureSize!=x3dom.SSAO.currentRandomTextureSize;if(void 0===x3dom.SSAO.randomTexture&&(x3dom.SSAO.randomTexture=e.createTexture()),void 0===x3dom.SSAO.randomTexture||i){e.bindTexture(e.TEXTURE_2D,x3dom.SSAO.randomTexture);for(var o=x3dom.SSAO.currentRandomTextureSize=t.getEnvironment()._vf.SSAOrandomTextureSize,s=new ArrayBuffer(o*o*4),r=new Uint8Array(s),n=0;n<o*o;++n){var a=2*Math.random()-1,d=2*Math.random()-1,l=Math.sqrt(a*a+d*d+0);a/=l,d/=l,r[4*n]=.5*(a+1)*255,r[4*n+1]=.5*(d+1)*255,r[4*n+2]=127.5,r[4*n+3]=255}e.texImage2D(e.TEXTURE_2D,0,e.RGBA,o,o,0,e.RGBA,e.UNSIGNED_BYTE,r),e.bindTexture(e.TEXTURE_2D,null)}},x3dom.SSAO.reinitializeFBOIfNecessary=function(e,t){var i=x3dom.SSAO.currentFBOWidth!=t.width||x3dom.SSAO.currentFBOHeight!=t.height;if(void 0===x3dom.SSAO.fbo||i){x3dom.SSAO.currentFBOWidth=t.width,x3dom.SSAO.currentFBOHeight=t.height;var o=e.getParameter(e.FRAMEBUFFER_BINDING);void 0===x3dom.SSAO.fbo&&(x3dom.SSAO.fbo=e.createFramebuffer()),e.bindFramebuffer(e.FRAMEBUFFER,x3dom.SSAO.fbo),void 0===x3dom.SSAO.fbotex&&(x3dom.SSAO.fbotex=e.createTexture()),e.bindTexture(e.TEXTURE_2D,x3dom.SSAO.fbotex),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,x3dom.SSAO.currentFBOWidth,x3dom.SSAO.currentFBOHeight,0,e.RGBA,e.UNSIGNED_BYTE,null),e.bindTexture(e.TEXTURE_2D,null),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,x3dom.SSAO.fbotex,0),e.bindFramebuffer(e.FRAMEBUFFER,o)}},x3dom.SSAO.render=function(e,t,i,o,s,r){var n=t.getParameter(t.FRAMEBUFFER_BINDING);null!=r&&t.bindFramebuffer(t.FRAMEBUFFER,r),e.frontFace(t.CCW),e.disable(t.CULL_FACE),e.disable(t.DEPTH_TEST);var a=x3dom.SSAO.shaderProgram;e.useProgram(a),a.depthTexture=0,a.randomTexture=1,a.radius=i.getEnvironment()._vf.SSAOradius,a.randomTextureTilingFactor=[s.width/x3dom.SSAO.currentRandomTextureSize,s.height/x3dom.SSAO.currentRandomTextureSize];var d=i.getViewpoint(),l=d.getNear(),h=d.getFar();a.nearPlane=l,a.farPlane=h,a.depthReconstructionConstantA=(h+l)/(l-h),a.depthReconstructionConstantB=2*h*l/(l-h),a.depthBufferEpsilon=1e-4*(h-l),a.samples=[.03800223814729654,.10441029119843426,-.04479934806797181,-.03800223814729654,-.10441029119843426,.04479934806797181,-.17023209847088397,.1428416910414532,.6154407640895228,.17023209847088397,-.1428416910414532,-.6154407640895228,-.288675134594813,-.16666666666666646,-.3774214123135722,.288675134594813,.16666666666666646,.3774214123135722,.07717696785196887,-.43769233467209245,-.5201284112706428,-.07717696785196887,.43769233467209245,.5201284112706428,.5471154183401156,-.09647120981496134,-.15886420745887797,-.5471154183401156,.09647120981496134,.15886420745887797,.3333333333333342,.5773502691896253,-.8012446019636266,-.3333333333333342,-.5773502691896253,.8012446019636266,-.49994591864508653,.5958123446480936,-.15385106176844343,.49994591864508653,-.5958123446480936,.15385106176844343,-.8352823295874743,-.3040179051783715,.7825440557226517,.8352823295874743,.3040179051783715,-.7825440557226517],a.tex||(a.tex=0),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,o),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,x3dom.SSAO.randomTexture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.REPEAT),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.REPEAT),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,i._fgnd._webgl.buffers[x3dom.BUFFER_IDX.INDEX]),t.bindBuffer(t.ARRAY_BUFFER,i._fgnd._webgl.buffers[x3dom.BUFFER_IDX.POSITION]),t.vertexAttribPointer(a.position,3,t.FLOAT,!1,0,0),t.enableVertexAttribArray(a.position),t.drawElements(i._fgnd._webgl.primType,i._fgnd._webgl.indexes.length,t.UNSIGNED_SHORT,0),t.disableVertexAttribArray(a.position),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,null),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,null),null!=r&&t.bindFramebuffer(t.FRAMEBUFFER,n)},x3dom.SSAO.blur=function(e,t,i,o,s,r,n){var a=t.getParameter(t.FRAMEBUFFER_BINDING);null!=n&&t.bindFramebuffer(t.FRAMEBUFFER,n),e.frontFace(t.CCW),e.disable(t.CULL_FACE),e.disable(t.DEPTH_TEST);var d=x3dom.SSAO.blurShaderProgram;e.useProgram(d),d.SSAOTexture=0,d.depthTexture=1,d.depthThreshold=i.getEnvironment()._vf.SSAOblurDepthTreshold;var l=i.getViewpoint(),h=l.getNear(),f=l.getFar();d.nearPlane=h,d.farPlane=f,d.depthReconstructionConstantA=(f+h)/(h-f),d.depthReconstructionConstantB=2*f*h/(h-f),d.pixelSize=[1/r.width,1/r.height],d.amount=i.getEnvironment()._vf.SSAOamount,t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,o),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,s),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,i._fgnd._webgl.buffers[x3dom.BUFFER_IDX.INDEX]),t.bindBuffer(t.ARRAY_BUFFER,i._fgnd._webgl.buffers[x3dom.BUFFER_IDX.POSITION]),t.vertexAttribPointer(d.position,3,t.FLOAT,!1,0,0),t.enableVertexAttribArray(d.position),t.drawElements(i._fgnd._webgl.primType,i._fgnd._webgl.indexes.length,t.UNSIGNED_SHORT,0),t.disableVertexAttribArray(d.position),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,null),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,null),null!=n&&t.bindFramebuffer(t.FRAMEBUFFER,a)},x3dom.SSAO.renderSSAO=function(e,t,i,o){this.reinitializeShadersIfNecessary(t),this.reinitializeRandomTextureIfNecessary(t,i),this.reinitializeFBOIfNecessary(t,o),e.viewport(0,0,o.width,o.height),this.render(e,t,i,i._webgl.fboScene.tex,o,x3dom.SSAO.fbo),t.enable(t.BLEND),t.blendFunc(t.DST_COLOR,t.ONE_MINUS_SRC_ALPHA),this.blur(e,t,i,x3dom.SSAO.fbotex,i._webgl.fboScene.tex,o,null),t.disable(t.BLEND)},x3dom.runtime={},x3dom.Runtime=function(e,t){this.doc=e,this.canvas=t,this.config={},this.isReady=!1,this.fps=0,this.VRMode=!1,this.states={measurements:[],infos:[]}},x3dom.Runtime.prototype.addMeasurement=function(e,t){this.states.measurements[e]=t},x3dom.Runtime.prototype.removeMeasurement=function(e){this.states.measurements[e]&&delete this.states.measurements[e]},x3dom.Runtime.prototype.addInfo=function(e,t){this.states.infos[e]=t},x3dom.Runtime.prototype.removeInfo=function(e){delete this.states.infos[e]},x3dom.Runtime.prototype.initialize=function(e,t){this.doc=e,this.canvas=t,this.config={},this.isReady=!1,this.fps=0},x3dom.Runtime.prototype.noBackendFound=function(){x3dom.debug.logInfo("No backend found. Unable to render.")},x3dom.Runtime.prototype.ready=function(){x3dom.debug.logInfo("System ready.")},x3dom.Runtime.prototype.enterFrame=function(){},x3dom.Runtime.prototype.exitFrame=function(){},x3dom.Runtime.prototype.triggerRedraw=function(){this.canvas.doc.needRender=!0},x3dom.Runtime.prototype.getActiveBindable=function(e){var t,i,o,s,r;if(t=this.canvas.doc._bindableBag._stacks,s=[],!(r=x3dom.nodeTypesLC[e.toLowerCase()]))return x3dom.debug.logError('No node of type "'+e+'" found.'),null;for(i=0;i<t.length;i++)void 0!==(o=t[i].getActive())._xmlNode&&x3dom.isa(o,r)&&s.push(o);return s[0]?s[0]._xmlNode:null},x3dom.Runtime.prototype.nextView=function(){var e=this.canvas.doc._scene.getViewpoint()._stack;e?e.switchTo("next"):x3dom.debug.logError("No valid ViewBindable stack.")},x3dom.Runtime.prototype.prevView=function(){var e=this.canvas.doc._scene.getViewpoint()._stack;e?e.switchTo("prev"):x3dom.debug.logError("No valid ViewBindable stack.")},x3dom.Runtime.prototype.viewpoint=function(){return this.canvas.doc._scene.getViewpoint()},x3dom.Runtime.prototype.viewMatrix=function(){return this.canvas.doc._viewarea.getViewMatrix()},x3dom.Runtime.prototype.projectionMatrix=function(){return this.canvas.doc._viewarea.getProjectionMatrix()},x3dom.Runtime.prototype.getWorldToCameraCoordinatesMatrix=function(){return this.canvas.doc._viewarea.getWCtoCCMatrix()},x3dom.Runtime.prototype.getCameraToWorldCoordinatesMatrix=function(){return this.canvas.doc._viewarea.getCCtoWCMatrix()},x3dom.Runtime.prototype.getViewingRay=function(e,t){return this.canvas.doc._viewarea.calcViewRay(e,t)},x3dom.Runtime.prototype.shootRay=function(e,t){var i=this.canvas.doc,o=i._viewarea._pickingInfo;return i.onPick(this.canvas.gl,e,t),{pickPosition:o.pickObj?o.pickPos:null,pickNormal:o.pickObj?o.pickNorm:null,pickObject:o.pickObj?o.pickObj._xmlNode:null}},x3dom.Runtime.prototype.getWidth=function(){return this.canvas.doc._viewarea._width},x3dom.Runtime.prototype.getHeight=function(){return this.canvas.doc._viewarea._height},x3dom.Runtime.prototype.mousePosition=function(e){var t=this.canvas.mousePosition(e);return[t.x,t.y]},x3dom.Runtime.prototype.calcCanvasPos=function(e,t,i){var o=window.devicePixelRatio||1,s=new x3dom.fields.SFVec3f(e,t,i),r=this.canvas.doc._viewarea.getWCtoCCMatrix().multFullMatrixPnt(s),n=this.canvas.doc._viewarea._width/o,a=this.canvas.doc._viewarea._height/o;return[Math.round((r.x+1)*(n-1)/2),Math.round((a-1)*(1-r.y)/2)]},x3dom.Runtime.prototype.calcPagePos=x3dom.Runtime.prototype.calcCanvasPos,x3dom.Runtime.prototype.getBBoxPoints=function(){var e=this.canvas.doc._scene;return e.updateVolume(),[{x:e._lastMin.x,y:e._lastMin.y,z:e._lastMin.z},{x:e._lastMax.x,y:e._lastMin.y,z:e._lastMin.z},{x:e._lastMin.x,y:e._lastMax.y,z:e._lastMin.z},{x:e._lastMax.x,y:e._lastMax.y,z:e._lastMin.z},{x:e._lastMin.x,y:e._lastMin.y,z:e._lastMax.z},{x:e._lastMax.x,y:e._lastMin.y,z:e._lastMax.z},{x:e._lastMin.x,y:e._lastMax.y,z:e._lastMax.z},{x:e._lastMax.x,y:e._lastMax.y,z:e._lastMax.z}]},x3dom.Runtime.prototype.getSceneBRect=function(){for(var e={x:Number.MAX_VALUE,y:Number.MAX_VALUE},t={x:Number.MIN_VALUE,y:Number.MIN_VALUE},i=this.getBBoxPoints(),o=0;o<i.length;o++){var s=this.calcCanvasPos(i[o].x,i[o].y,i[o].z);e.x=s[0]<e.x?s[0]:e.x,e.y=s[1]<e.y?s[1]:e.y,t.x=s[0]>t.x?s[0]:t.x,t.y=s[1]>t.y?s[1]:t.y}return{x:e.x,y:e.y,width:t.x-e.x,height:t.y-e.y}},x3dom.Runtime.prototype.calcClientPos=function(e,t,i){var o=this.canvas.canvas.offsetParent;if(!o)return x3dom.debug.logError("Can't calc client pos without offsetParent."),[0,0];var s=o.getBoundingClientRect(),r=this.calcCanvasPos(e,t,i),n=document.defaultView.getComputedStyle(o,null),a=parseFloat(n.getPropertyValue("padding-left")),d=parseFloat(n.getPropertyValue("border-left-width")),l=parseFloat(n.getPropertyValue("padding-top")),h=parseFloat(n.getPropertyValue("border-top-width"));return[s.left+a+d+r[0],s.top+l+h+r[1]]},x3dom.Runtime.prototype.getScreenshot=function(){var e="",t=this.canvas.backend,i=this.canvas.canvas;if(i)if("flash"==t)e=i.getScreenshot();else{var o=document.createElement("canvas");o.width=i.width,o.height=i.height;var s=o.getContext("2d");s.drawImage(i,0,0,i.width,i.height),s.scale(1,-1),s.translate(0,-i.height),e=o.toDataURL()}return e},x3dom.Runtime.prototype.getCanvas=function(){return this.canvas.canvas},x3dom.Runtime.prototype.lightMatrix=function(){this.canvas.doc._viewarea.getLightMatrix()},x3dom.Runtime.prototype.resetView=function(){this.canvas.doc._viewarea.resetView()},x3dom.Runtime.prototype.lightView=function(){return this.canvas.doc._nodeBag.lights.length>0?(this.canvas.doc._viewarea.animateTo(this.canvas.doc._viewarea.getLightMatrix()[0],this.canvas.doc._scene.getViewpoint()),!0):(x3dom.debug.logInfo("No lights to navigate to."),!1)},x3dom.Runtime.prototype.uprightView=function(){this.canvas.doc._viewarea.uprightView()},x3dom.Runtime.prototype.fitAll=function(e){void 0===e&&(e=!0);var t=this.canvas.doc._scene;t.updateVolume(),this.canvas.doc._viewarea.fit(t._lastMin,t._lastMax,e)},x3dom.Runtime.prototype.fitObject=function(e,t){if(e&&e._x3domNode){void 0===t&&(t=!0);var i=x3dom.fields.SFVec3f.MAX(),o=x3dom.fields.SFVec3f.MIN();e._x3domNode.getVolume().getBounds(i,o);var s=e._x3domNode.getCurrentTransform();if(i=s.multMatrixPnt(i),o=s.multMatrixPnt(o),x3dom.isa(e._x3domNode,x3dom.nodeTypes.X3DTransformNode)){var r=e._x3domNode._trafo.inverse();i=r.multMatrixPnt(i),o=r.multMatrixPnt(o)}this.canvas.doc._viewarea.fit(i,o,t)}},x3dom.Runtime.prototype.showAll=function(e,t){this.canvas.doc._viewarea.showAll(e,t)},x3dom.Runtime.prototype.showObject=function(e,t){if(e&&e._x3domNode){void 0===t&&(t="negZ");var i=x3dom.fields.SFVec3f.MAX(),o=x3dom.fields.SFVec3f.MIN();e._x3domNode.getVolume().getBounds(i,o);var s=e._x3domNode.getCurrentTransform();i=s.multMatrixPnt(i),o=s.multMatrixPnt(o);var r,n=this.canvas.doc._viewarea,a=n._width<n._height?n._width:n._height;switch(t){case"posX":r=new x3dom.fields.SFVec3f(1,0,0);break;case"negX":r=new x3dom.fields.SFVec3f(-1,0,0);break;case"posY":r=new x3dom.fields.SFVec3f(0,1,0);break;case"negY":r=new x3dom.fields.SFVec3f(0,-1,0);break;case"posZ":r=new x3dom.fields.SFVec3f(0,0,1);break;case"negZ":r=new x3dom.fields.SFVec3f(0,0,-1)}var d=this.canvas.doc._scene.getViewpoint(),l=d.getFieldOfView()/2,h=Math.tan(l);Math.abs(h)>x3dom.fields.Eps&&(a/=h);var f=n._width-1,u=n._height-1,c=.25,_=new x3dom.fields.SFVec2f(c*f,c*u);c=.75;var m=new x3dom.fields.SFVec2f(c*f,c*u),p=o.subtract(i).multiply(.5),x=p.length(),g=i.add(p),v=m.subtract(_).multiply(.5),y=1.5*v.length();v=v.add(_);var T=1;y>x3dom.fields.Eps&&(T=x/y*Math.sqrt(v.x*v.x+v.y*v.y+a*a)),r=(r=s.multMatrixVec(r).normalize()).multiply(T);var b=g.add(r),S=x3dom.fields.Quaternion.rotateFromTo(new x3dom.fields.SFVec3f(0,0,1),r).toMatrix(),F=x3dom.fields.SFMatrix4f.translation(b.negate()),E=x3dom.fields.SFMatrix4f.translation(b),M=(E=E.mult(S).mult(F).mult(E)).inverse();n.animateTo(M,d)}},x3dom.Runtime.prototype.animateViewpointTo=function(e,t){var i=this.canvas.doc._viewarea,o=this.canvas.doc._scene.getViewpoint();null!=e._x3domNode&&(e=e._x3domNode),i.animateTo(e,o,t)},x3dom.Runtime.prototype.getCenter=function(e){return e&&e._x3domNode&&(this.isA(e,"X3DShapeNode")||this.isA(e,"X3DGeometryNode"))?e._x3domNode.getCenter():null},x3dom.Runtime.prototype.getCurrentTransform=function(e){return e&&e._x3domNode?e._x3domNode.getCurrentTransform():null},x3dom.Runtime.prototype.getBBox=function(e){if(e&&e._x3domNode&&this.isA(e,"X3DBoundedObject")){var t=e._x3domNode.getVolume();return{min:x3dom.fields.SFVec3f.copy(t.min),max:x3dom.fields.SFVec3f.copy(t.max)}}return null},x3dom.Runtime.prototype.getSceneBBox=function(){var e=this.canvas.doc._scene;return e.updateVolume(),{min:x3dom.fields.SFVec3f.copy(e._lastMin),max:x3dom.fields.SFVec3f.copy(e._lastMax)}},x3dom.Runtime.prototype.debug=function(e){var t=this.canvas.doc;return void 0===t._viewarea._visDbgBuf&&(t._viewarea._visDbgBuf="true"===t._x3dElem.getAttribute("showLog")),arguments.length>0?!0===e?(t._viewarea._visDbgBuf=!0,x3dom.debug.logContainer.style.display="block"):(t._viewarea._visDbgBuf=!1,x3dom.debug.logContainer.style.display="none"):(t._viewarea._visDbgBuf=!t._viewarea._visDbgBuf,x3dom.debug.logContainer.style.display=1==t._viewarea._visDbgBuf?"block":"none"),t.needRender=!0,t._viewarea._visDbgBuf},x3dom.Runtime.prototype.navigationType=function(){return this.canvas.doc._scene.getNavigationInfo().getType()},x3dom.Runtime.prototype.noNav=function(){this.canvas.doc._scene.getNavigationInfo().setType("none")},x3dom.Runtime.prototype.examine=function(){this.canvas.doc._scene.getNavigationInfo().setType("examine")},x3dom.Runtime.prototype.turnTable=function(){this.canvas.doc._scene.getNavigationInfo().setType("turntable")},x3dom.Runtime.prototype.fly=function(){this.canvas.doc._scene.getNavigationInfo().setType("fly")},x3dom.Runtime.prototype.freeFly=function(){this.canvas.doc._scene.getNavigationInfo().setType("freefly")},x3dom.Runtime.prototype.lookAt=function(){this.canvas.doc._scene.getNavigationInfo().setType("lookat")},x3dom.Runtime.prototype.lookAround=function(){this.canvas.doc._scene.getNavigationInfo().setType("lookaround")},x3dom.Runtime.prototype.walk=function(){this.canvas.doc._scene.getNavigationInfo().setType("walk")},x3dom.Runtime.prototype.game=function(){this.canvas.doc._scene.getNavigationInfo().setType("game")},x3dom.Runtime.prototype.helicopter=function(){this.canvas.doc._scene.getNavigationInfo().setType("helicopter")},x3dom.Runtime.prototype.resetExamin=function(){var e=this.canvas.doc._viewarea;e._rotMat=x3dom.fields.SFMatrix4f.identity(),e._transMat=x3dom.fields.SFMatrix4f.identity(),e._movement=new x3dom.fields.SFVec3f(0,0,0),e._needNavigationMatrixUpdate=!0,this.canvas.doc.needRender=!0},x3dom.Runtime.prototype.disableKeys=function(){this.canvas.disableKeys=!0},x3dom.Runtime.prototype.enableKeys=function(){this.canvas.disableKeys=!1},x3dom.Runtime.prototype.disableLeftDrag=function(){this.canvas.disableLeftDrag=!0},x3dom.Runtime.prototype.enableLeftDrag=function(){this.canvas.disableLeftDrag=!1},x3dom.Runtime.prototype.disableRightDrag=function(){this.canvas.disableRightDrag=!0},x3dom.Runtime.prototype.enableRightDrag=function(){this.canvas.disableRightDrag=!1},x3dom.Runtime.prototype.disableMiddleDrag=function(){this.canvas.disableMiddleDrag=!0},x3dom.Runtime.prototype.enableMiddleDrag=function(){this.canvas.disableMiddleDrag=!1},x3dom.Runtime.prototype.togglePoints=function(e){var t=this.canvas.doc,i=!0===e?3:2;return t._viewarea._points=++t._viewarea._points%i,t.needRender=!0,t._viewarea._points},x3dom.Runtime.prototype.pickRect=function(e,t,i,o){return this.canvas.doc.onPickRect(this.canvas.gl,e,t,i,o)},x3dom.Runtime.prototype.pickMode=function(e){return e&&!0===e.internal?this.canvas.doc._scene._vf.pickMode:this.canvas.doc._scene._vf.pickMode.toLowerCase()},x3dom.Runtime.prototype.changePickMode=function(e){switch(e=e.toLowerCase()){case"idbuf":e="idBuf";break;case"idbuf24":e="idBuf24";break;case"idbufid":e="idBufId";break;case"texcoord":e="texCoord";break;case"color":e="color";break;case"box":e="box";break;default:x3dom.debug.logWarning("Switch pickMode to "+e+" unknown intersect type"),e=void 0}return void 0!==e&&(this.canvas.doc._scene._vf.pickMode=e,x3dom.debug.logInfo("Switched pickMode to '"+e+"'."),!0)},x3dom.Runtime.prototype.speed=function(e){var t=this.canvas.doc._scene.getNavigationInfo();return e&&(t._vf.speed=e,x3dom.debug.logInfo("Changed navigation speed to "+t._vf.speed)),t._vf.speed},x3dom.Runtime.prototype.zoom=function(e){this.canvas.doc._viewarea.zoom(e),this.canvas.doc.needRender=!0},x3dom.Runtime.prototype.statistics=function(e){var t=this.canvas.stateViewer;return!!t&&(this.canvas.doc.needRender=!0,!0===e?(t.display(e),!0):!1===e?(t.display(e),!1):(t.display(!t.active),t.active))},x3dom.Runtime.prototype.processIndicator=function(e){var t=this.canvas.progressDiv;return!!t&&(!0===e?(t.style.display="flex",!0):!1===e?(t.style.display="none",!1):"none"!=t.style.display)},x3dom.Runtime.prototype.properties=function(){return this.canvas.doc.properties},x3dom.Runtime.prototype.backendName=function(){return this.canvas.backend},x3dom.Runtime.prototype.getFPS=function(){return this.fps},x3dom.Runtime.prototype.isA=function(e,t){var i=!1;return t&&e&&e._x3domNode&&(""===t&&(t="X3DNode"),i=x3dom.isa(e._x3domNode,x3dom.nodeTypesLC[t.toLowerCase()])),i},x3dom.Runtime.prototype.getPixelScale=function(){var e=this.viewpoint();if(!x3dom.isa(e,x3dom.nodeTypes.OrthoViewpoint))return x3dom.debug.logError("getPixelScale is only implemented for orthographic Viewpoints"),null;var t=e.getZoom(),i=t[0],o=t[1],s=t[2],r=t[3]-o,n=(s-i)/this.getWidth(),a=r/this.getHeight();return new x3dom.fields.SFVec3f(n,a,0)},x3dom.Runtime.prototype.onAnimationStarted=function(){},x3dom.Runtime.prototype.onAnimationFinished=function(){},x3dom.Runtime.prototype.enterVR=function(){this.canvas.vrDisplay&&!this.canvas.vrDisplay.isPresenting&&this.canvas.vrDisplay.requestPresent([{source:this.canvas.canvas}]).then(function(){this.canvas.doc.needRender=!0}.bind(this))},x3dom.Runtime.prototype.exitVR=function(){this.canvas.vrDisplay&&this.canvas.vrDisplay.isPresenting&&this.canvas.vrDisplay.exitPresent()},x3dom.Runtime.prototype.toggleVR=function(){this.canvas.vrDisplay&&!this.canvas.vrDisplay.isPresenting?this.enterVR():this.canvas.vrDisplay&&this.canvas.vrDisplay.isPresenting&&this.exitVR()},x3dom.Runtime.prototype.toggleProjection=function(e,t){var i,o=document.getElementById("x3d").runtime.canvas.doc._scene.getNavigationInfo(),s=o._vf.transitionTime,r=document.getElementById(e)._x3domNode,n=document.getElementById(t)._x3domNode;if(o._vf.transitionTime=0,n._bindAnimation=!1,r._bindAnimation=!1,r._vf.isActive)n._viewMatrix=r._viewMatrix,document.getElementById(t).setAttribute("set_bind","true"),i=r._viewMatrix.e3().length()/2.2,n.setZoom(i);else if(n._vf.isActive){r._viewMatrix=n._viewMatrix,document.getElementById(e).setAttribute("set_bind","true"),i=-2.2*n._fieldOfView[2];var a=n._viewMatrix.e2().normalize().multiply(i);r._viewMatrix.setTranslate(a)}return o._vf.transitionTime=s,n._bindAnimation=!0,r._bindAnimation=!0,r._vf.isActive?0:1},x3dom.Runtime.prototype.replaceWorld=function(e){for(var t,i,o=this.doc.cloneNode(!1);t=e.firstChild;)"HEAD"==(i=1===t.nodeType?t.localName.toUpperCase():null)||"SCENE"==i?o.appendChild(t):t.remove();this.doc.parentNode.replaceChild(o,this.doc),this.doc=o,x3dom.reload()},x3dom.Runtime.prototype.createX3DFromJS=function(e,t){return t&&(e=x3dom.protoExpander.prototypeExpander(t,e)),(new x3dom.JSONParser).parseJavaScript(e)},x3dom.Runtime.prototype.createX3DFromString=function(e,t){try{var i=JSON.parse(e);return this.createX3DFromJS(i,t)}catch(t){var o=new DOMParser,s=o.parseFromString(e,"application/xml"),r=s.querySelector("X3D");return null==r&&(r=(s=o.parseFromString(e,"text/html")).querySelector("X3D")),r}},x3dom.Runtime.prototype.createX3DFromURLPromise=function(e,t){this.canvas.doc.incrementDownloads();var i=this;return fetch(e).then((function(e){return e.text()})).then((function(e){return i.canvas.doc.decrementDownloads(),i.createX3DFromString(e,t)})).catch((function(e){return i.canvas.doc.decrementDownloads(),x3dom.debug.logError("fetch failed: "+e),null}))},x3dom.Runtime.prototype.loadURL=function(e,t){var i=this;this.createX3DFromURLPromise(e,t).then((function(t){null!=t?i.replaceWorld(t):x3dom.debug.logError("loadURL: could not fetch or parse "+e)}))},x3dom.userAgentFeature={supportsDOMAttrModified:!1},function(){"use strict";var e=function(){var e,t,i,o=document.getElementsByTagName("X3D"),s=[];for(e=0;e<o.length;e++)void 0===o[e].hasRuntime&&s.push(o[e]);var r,n,a,d,l,h,f,u=new x3dom.Properties,c=array_to_object(["showLog","showStat","showProgress","PrimitiveQuality","components","loadpath","disableDoubleClick","backend","altImg","runtimeEnabled","disableKeys","showTouchpoints","disableTouch","maxActiveDownloads","useGeoCache"]),_=!1;for(e=0;e<s.length;e++){for(u.setProperty("showLog",s[e].getAttribute("showLog")||"false"),u.setProperty("showStat",s[e].getAttribute("showStat")||"false"),u.setProperty("showProgress",s[e].getAttribute("showProgress")||"true"),u.setProperty("PrimitiveQuality",s[e].getAttribute("PrimitiveQuality")||"High"),u.setProperty("useGeoCache",s[e].getAttribute("useGeoCache")||"true"),i=s[e].getElementsByTagName("PARAM"),t=0;t<i.length;t++)i[t].getAttribute("name")in c&&u.setProperty(i[t].getAttribute("name"),i[t].getAttribute("value"));"true"===u.getProperty("showLog")&&(_=!0)}for(1==_?x3dom.debug.activate(!0):x3dom.debug.activate(!1),s=s.map((function(e){return e.hasRuntime=!0,e})),void 0!==x3dom.about&&x3dom.debug.logInfo("X3DOM "+x3dom.about.version+", Build: "+x3dom.about.build+", Revison: <a href='https://github.com/x3dom/x3dom/tree/"+x3dom.about.revision+"'>"+x3dom.about.revision+"</a>, Date: "+x3dom.about.date),x3dom.debug.logInfo("Found "+s.length+" X3D and nodes..."),e=0;e<s.length;e++)r=s[e],n=new x3dom.X3DCanvas(r,x3dom.canvases.length),x3dom.canvases.push(n),null!==n.gl?(h=(new Date).getTime(),s[e].runtime=new x3dom.Runtime(s[e],n),s[e].runtime.initialize(s[e],n),x3dom.runtime.ready&&(s[e].runtime.ready=x3dom.runtime.ready),""==n.backend&&x3dom.runtime.noBackendFound(),n.load(s[e],e,u),"true"===u.getProperty("showStat")?s[e].runtime.statistics(!0):s[e].runtime.statistics(!1),"true"===u.getProperty("showProgress")?("bar"===u.getProperty("showProgress")&&n.progressDiv.setAttribute("class","x3dom-progress bar"),s[e].runtime.processIndicator(!0)):s[e].runtime.processIndicator(!1),f=(new Date).getTime()-h,x3dom.debug.logInfo("Time for setup and init of GL element no. "+e+": "+f+" ms.")):((a=document.createElement("div")).setAttribute("class","x3dom-nox3d"),a.setAttribute("id","x3dom-nox3d"),(d=document.createElement("p")).appendChild(document.createTextNode("WebGL is not yet supported in your browser. ")),(l=document.createElement("a")).setAttribute("href","http://www.x3dom.org/?page_id=9"),l.appendChild(document.createTextNode("Follow link for a list of supported browsers... ")),a.appendChild(d),a.appendChild(l),n.x3dElem.appendChild(a),n.stateViewer&&r.removeChild(n.stateViewer.viewer));var m;m=null,document.createEvent?((m=document.createEvent("Events")).initEvent("load",!0,!0),document.dispatchEvent(m)):document.createEventObject&&(m=document.createEventObject(),document.body.fireEvent("onload",m))},t=function(){if(x3dom.canvases&&x3dom.canvases.length>0&&x3dom.canvases[0].doc){for(var e=0;e<x3dom.canvases.length;e++)x3dom.canvases[e].doc.shutdown(x3dom.canvases[e].gl);x3dom.canvases=[]}};x3dom.reload=function(){e()},window.addEventListener?(window.addEventListener("load",e,!1),window.addEventListener("unload",t,!1),window.addEventListener("reload",t,!1)):window.attachEvent&&(window.attachEvent("onload",e),window.attachEvent("onunload",t),window.attachEvent("onreload",t)),"complete"===document.readyState&&window.setTimeout((function(){e()}),20)}(),x3dom.Cache=function(){this.textures=[],this.shaders=[]},x3dom.Cache.prototype.getTexture2D=function(e,t,i,o,s,r,n,a,d){var l=i;return void 0===this.textures[l]&&(this.textures[l]=x3dom.Utils.createTexture2D(e,t,i,o,s,r,n,a,d)),this.textures[l]},x3dom.Cache.prototype.getTexture2DByDEF=function(e,t,i){var o=t.name+"_"+i;return void 0===this.textures[o]&&(this.textures[o]=e.createTexture()),this.textures[o]},x3dom.Cache.prototype.getTextureCube=function(e,t,i,o,s,r,n,a){for(var d="",l=0;l<i.length;++l)d+=i[l]+"|";return void 0===this.textures[d]&&(this.textures[d]=x3dom.Utils.createTextureCube(e,t,i,o,s,r,n,a)),this.textures[d]},x3dom.Cache.prototype.getShader=function(e,t){var i=null;if(void 0===this.shaders[t]){switch(t){case x3dom.shader.PICKING:i=new x3dom.shader.PickingShader(e);break;case x3dom.shader.PICKING_24:i=new x3dom.shader.Picking24Shader(e);break;case x3dom.shader.PICKING_ID:i=new x3dom.shader.PickingIdShader(e);break;case x3dom.shader.PICKING_COLOR:i=new x3dom.shader.PickingColorShader(e);break;case x3dom.shader.PICKING_TEXCOORD:i=new x3dom.shader.PickingTexcoordShader(e);break;case x3dom.shader.FRONTGROUND_TEXTURE:i=new x3dom.shader.FrontgroundTextureShader(e);break;case x3dom.shader.BACKGROUND_TEXTURE:i=new x3dom.shader.BackgroundTextureShader(e);break;case x3dom.shader.BACKGROUND_SKYTEXTURE:i=new x3dom.shader.BackgroundSkyTextureShader(e);break;case x3dom.shader.BACKGROUND_CUBETEXTURE:i=new x3dom.shader.BackgroundCubeTextureShader(e);break;case x3dom.shader.BACKGROUND_CUBETEXTURE_DDS:i=new x3dom.shader.BackgroundCubeTextureDDSShader(e);break;case x3dom.shader.SHADOW:i=new x3dom.shader.ShadowShader(e);break;case x3dom.shader.BLUR:i=new x3dom.shader.BlurShader(e);break;case x3dom.shader.DEPTH:break;case x3dom.shader.NORMAL:i=new x3dom.shader.NormalShader(e);break;case x3dom.shader.TEXTURE_REFINEMENT:i=new x3dom.shader.TextureRefinementShader(e)}i?this.shaders[t]=x3dom.Utils.wrapProgram(e,i,t):x3dom.debug.logError("Couldn't create shader: "+t)}return this.shaders[t]},x3dom.Cache.prototype.getDynamicShader=function(e,t,i){var o=x3dom.Utils.generateProperties(t,i),s=o.id;if(void 0===this.shaders[s]){var r=null;r=-1!=o.CSHADER?new x3dom.shader.ComposedShader(e,i):new x3dom.shader.DynamicShader(e,o),this.shaders[s]=x3dom.Utils.wrapProgram(e,r,s)}return this.shaders[s]},x3dom.Cache.prototype.getShaderByProperties=function(e,t,i,o,s){var r=i.id;if(null!=o&&(r+=o),null!=s&&(r+="S"),void 0===this.shaders[r]){var n=null;if(null!=o)n=new x3dom.shader.DynamicShaderPicking(e,i,o);else if(null!=s)n=new x3dom.shader.DynamicShadowShader(e,i);else if(-1!=i.CSHADER)n=new x3dom.shader.ComposedShader(e,t);else if(null!=i.KHR_MATERIAL_COMMONS&&0!=i.KHR_MATERIAL_COMMONS)n=new x3dom.shader.KHRMaterialCommonsShader(e,i);else{if(null!=i.EMPTY_SHADER&&0!=i.EMPTY_SHADER)return{shaderID:r};n=new x3dom.shader.DynamicShader(e,i)}this.shaders[r]=x3dom.Utils.wrapProgram(e,n,r)}return this.shaders[r]},x3dom.Cache.prototype.getShadowRenderingShader=function(e,t){for(var i="shadow",o=0;o<t.length;o++)x3dom.isa(t[o],x3dom.nodeTypes.SpotLight)?i+="S":x3dom.isa(t[o],x3dom.nodeTypes.PointLight)?i+="P":i+="D";if(void 0===this.shaders[i]){var s=new x3dom.shader.ShadowRenderingShader(e,t);this.shaders[i]=x3dom.Utils.wrapProgram(e,s,i)}return this.shaders[i]},x3dom.Cache.prototype.Release=function(e){for(var t in this.textures)e.deleteTexture(this.textures[t]);for(var i in this.textures=[],this.shaders){for(var o=this.shaders[i],s=e.getAttachedShaders(o.program),r=0;r<s.length;++r)e.detachShader(o.program,s[r]),e.deleteShader(s[r]);e.deleteProgram(o.program)}this.shaders=[]},x3dom.Texture=function(e,t,i,o){this.gl=e,this.doc=t,this.cache=i,this.node=o,this.samplerName="diffuseMap",this.type=e.TEXTURE_2D,this.format=e.RGBA,this.magFilter=e.LINEAR,this.minFilter=e.LINEAR,this.wrapS=e.REPEAT,this.wrapT=e.REPEAT,this.genMipMaps=!1,this.texture=null,this.ready=!1,this.anisotropicDegree=1,this.dashtexture=!1;var s=this.node;if(this.node._x3domTexture=this,x3dom.isa(s,x3dom.nodeTypes.MovieTexture)&&-1!==s._vf.url[0].indexOf("mpd",s._vf.url[0].length-"mpd".length)){this.dashtexture=!0;var r=document.getElementById("AdditionalDashVideoScript");r||((r=document.createElement("script")).setAttribute("type","text/javascript"),r.setAttribute("src",x3dom.Texture.dashVideoScriptFile),r.setAttribute("id","AdditionalDashVideoScript"),r.onload=function(){for(var e;e=x3dom.Texture.loadDashVideos.pop();)x3dom.Texture.textNum++,e.update();r.ready=!0},document.getElementsByTagName("head")[0].appendChild(r)),!0===r.ready?(x3dom.Texture.textNum++,this.update()):x3dom.Texture.loadDashVideos.push(this)}this.dashtexture||this.update()},x3dom.Texture.dashVideoScriptFile="dash.all.js",x3dom.Texture.loadDashVideos=[],x3dom.Texture.textNum=0,x3dom.Texture.clampFontSize=!1,x3dom.Texture.minFontQuality=.5,x3dom.Texture.maxFontQuality=10,x3dom.Texture.prototype.update=function(){x3dom.isa(this.node,x3dom.nodeTypes.Text)?this.updateText():this.updateTexture(),this.node.validateGLObject()},x3dom.Texture.prototype.setPixel=function(e,t,i,o){var s=this.gl,r=new Uint8Array(i);s.bindTexture(this.type,this.texture),s.pixelStorei(s.UNPACK_ALIGNMENT,1),s.texSubImage2D(this.type,0,e,t,1,1,this.format,s.UNSIGNED_BYTE,r),s.bindTexture(this.type,null),o&&(this.doc.needRender=!0)},x3dom.Texture.prototype.updateTexture=function(){var e=this.gl,t=this.doc,i=this.node;if(this.samplerName=i._type,x3dom.isa(i,x3dom.nodeTypes.X3DEnvironmentTextureNode)?this.type=e.TEXTURE_CUBE_MAP:this.type=e.TEXTURE_2D,x3dom.isa(i,x3dom.nodeTypes.PixelTexture))switch(i._vf.image.comp){case 1:this.format=e.LUMINANCE;break;case 2:this.format=e.LUMINANCE_ALPHA;break;case 3:this.format=e.RGB;break;case 4:this.format=e.RGBA}else this.format=e.RGBA;if(null!==i._cf.textureProperties.node){var o=i._cf.textureProperties.node;this.wrapS=x3dom.Utils.boundaryModesDic(e,o._vf.boundaryModeS),this.wrapT=x3dom.Utils.boundaryModesDic(e,o._vf.boundaryModeT),this.minFilter=x3dom.Utils.minFilterDic(e,o._vf.minificationFilter),this.magFilter=x3dom.Utils.magFilterDic(e,o._vf.magnificationFilter),this.anisotropicDegree=Math.min(Math.max(o._vf.anisotropicDegree,1),x3dom.caps.MAX_ANISOTROPY),!0===o._vf.generateMipMaps?(this.genMipMaps=!0,this.minFilter==e.NEAREST?this.minFilter=e.NEAREST_MIPMAP_NEAREST:this.minFilter==e.LINEAR&&(this.minFilter=e.LINEAR_MIPMAP_LINEAR),this.texture&&(this.texture.ready||this.texture.textureCubeReady)&&(e.bindTexture(this.type,this.texture),e.generateMipmap(this.type),e.bindTexture(this.type,null))):(this.genMipMaps=!1,this.minFilter==e.LINEAR_MIPMAP_LINEAR||this.minFilter==e.LINEAR_MIPMAP_NEAREST?this.minFilter=e.LINEAR:this.minFilter!=e.NEAREST_MIPMAP_LINEAR&&this.minFilter!=e.NEAREST_MIPMAP_NEAREST||(this.minFilter=e.NEAREST))}else 0==i._vf.repeatS?this.wrapS=e.CLAMP_TO_EDGE:this.wrapS=e.REPEAT,0==i._vf.repeatT?this.wrapT=e.CLAMP_TO_EDGE:this.wrapT=e.REPEAT,"displacementMap"==this.samplerName&&(this.wrapS=e.CLAMP_TO_EDGE,this.wrapT=e.CLAMP_TO_EDGE,this.minFilter=e.NEAREST,this.magFilter=e.NEAREST);var s=i._video&&!0===i._needPerFrameUpdate;if(i._isCanvas&&i._canvas)null==this.texture&&(this.texture=e.createTexture()),this.texture.width=i._canvas.width,this.texture.height=i._canvas.height,this.texture.ready=!0,e.bindTexture(this.type,this.texture),e.texImage2D(this.type,0,this.format,this.format,e.UNSIGNED_BYTE,i._canvas),this.genMipMaps&&e.generateMipmap(this.type),e.bindTexture(this.type,null);else if(x3dom.isa(i,x3dom.nodeTypes.RenderedTexture))i._webgl&&i._webgl.fbo?i._webgl.fbo.dtex&&i._vf.depthMap?this.texture=i._webgl.fbo.dtex:this.texture=i._webgl.fbo.tex:(this.texture=null,x3dom.debug.logError("Try updating RenderedTexture without FBO initialized!")),this.texture&&(this.texture.ready=!0);else if(x3dom.isa(i,x3dom.nodeTypes.PixelTexture)){0==i._vf.origChannelCount&&i.setOrigChannelCount(i._vf.image.comp),null==this.texture&&(this.node._DEF?this.texture=this.cache.getTexture2DByDEF(e,this.node._nameSpace,this.node._DEF):this.texture=e.createTexture()),this.texture.width=i._vf.image.width,this.texture.height=i._vf.image.height,this.texture.ready=!0;var r=i._vf.image.array,n=i._vf.image.width*i._vf.image.height*i._vf.image.comp,a=new Uint8Array(n);a.set(r),e.bindTexture(this.type,this.texture),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(this.type,0,this.format,i._vf.image.width,i._vf.image.height,0,this.format,e.UNSIGNED_BYTE,a),this.genMipMaps&&e.generateMipmap(this.type),e.bindTexture(this.type,null)}else if(x3dom.isa(i,x3dom.nodeTypes.MovieTexture)||s){var d=this,l=document.getElementsByTagName("body")[0];if(null==this.texture&&(this.texture=e.createTexture()),this.dashtexture){var h=document.createElement("div");h.setAttribute("class","dash-video-player"+x3dom.Texture.textNum),i._video=document.createElement("video"),i._video.setAttribute("preload","auto"),i._video.setAttribute("muted","muted");var f=document.createElement("script");f.setAttribute("type","text/javascript"),f.innerHTML='startDashVideo("'+i._vf.url[0]+'",".dash-video-player'+x3dom.Texture.textNum+' video")',h.appendChild(f),h.appendChild(i._video),l.appendChild(h),i._video.style.visibility="hidden",i._video.style.display="none"}else{s||(i._video=document.createElement("video"),i._video.setAttribute("preload","auto"),i._video.setAttribute("muted","muted"),l.appendChild(i._video),i._video.style.visibility="hidden",i._video.style.display="none");for(var u=0;u<i._vf.url.length;u++){var c=i._nameSpace.getURL(i._vf.url[u]);x3dom.debug.logInfo("Adding video file: "+c);var _=document.createElement("source");_.setAttribute("src",c),i._video.appendChild(_)}}var m=function(){e.bindTexture(d.type,d.texture),e.texImage2D(d.type,0,d.format,d.format,e.UNSIGNED_BYTE,i._video),d.genMipMaps&&e.generateMipmap(d.type),e.bindTexture(d.type,null),d.texture.ready=!0,t.needRender=!0};i._video.addEventListener("canplaythrough",(function(){i._video.play(),i._intervalID=setInterval(m,16)}),!0),i._video.addEventListener("ended",(function(){clearInterval(i._intervalID),!0===i._vf.loop&&(i._video.play(),i._intervalID=setInterval(m,16))}),!0)}else x3dom.isa(i,x3dom.nodeTypes.X3DEnvironmentTextureNode)?this.texture=this.cache.getTextureCube(e,t,i.getTexUrl(),!1,i._vf.crossOrigin,i._vf.scale,this.genMipMaps,i._vf.flipY):this.texture=this.cache.getTexture2D(e,t,i._nameSpace.getURL(i._vf.url[0]),!1,i._vf.crossOrigin,i._vf.scale,this.genMipMaps,i._vf.flipY,i)},x3dom.Texture.prototype.updateText=function(){var e=this.gl;this.wrapS=e.CLAMP_TO_EDGE,this.wrapT=e.CLAMP_TO_EDGE,this.type=e.TEXTURE_2D,this.format=e.RGBA,this.magFilter=e.LINEAR,this.minFilter=e.LINEAR_MIPMAP_LINEAR,this.genMipMaps=!0,x3dom.caps.MAX_ANISOTROPY&&(this.anisotropicDegree=x3dom.caps.MAX_ANISOTROPY);var t=this.node._cf.fontStyle.node,i="serif",o="normal",s="left",r=1,n=1,a=2,d="FIRST";if(null!==t){var l=t._vf.family.toString();switch(i=(l=(l=l.trim().replace(/\'/g,"").replace(/\,/," ")).split(" ")).map((function(e){return"SANS"==e?"Verdana, sans-serif":"SERIF"==e?"Georgia, serif":"TYPEWRITER"==e?"monospace":""+e})).join(","),(o=t._vf.style.toString().replace(/\'/g,"")).toUpperCase()){case"PLAIN":o="normal";break;case"BOLD":o="bold";break;case"ITALIC":o="italic";break;case"BOLDITALIC":o="italic bold";break;default:o="normal"}var h=t._vf.leftToRight?"ltr":"rtl",f=t._vf.topToBottom,u="ltr"==h?"left":"right",c="ltr"==h?"right":"left";switch((s=t._vf.justify[0].toString().replace(/\'/g,"")).toUpperCase()){case"BEGIN":s=u;break;case"END":s=c;break;case"FIRST":s=u;break;case"MIDDLE":s="center";break;default:s=u}if(void 0===t._vf.justify[1])d="FIRST";else switch((d=t._vf.justify[1].toString().replace(/\'/g,"")).toUpperCase()){case"BEGIN":d="BEGIN";break;case"FIRST":d="FIRST";break;case"MIDDLE":d="MIDDLE";break;case"END":d="END";break;default:d="FIRST"}r=t._vf.size,n=t._vf.spacing,t._vf.horizontal,t._vf.language,a=t._vf.quality,a=Math.max(x3dom.Texture.minFontQuality,a),a=Math.min(x3dom.Texture.maxFontQuality,a),r<.1&&(r=.1),x3dom.Texture.clampFontSize&&r>2.3&&(r=2.3)}var _,m,p=this.node._vf.string,x=this.node._vf.maxExtent,g=[],v=s,y=document.createElement("canvas");y.dir=h;var T=32*r;document.body.appendChild(y);var b=y.getContext("2d");b.font=o+" "+T+"px "+i;var S,F,E,M=0;for(E=0;E<p.length;E++)(S=b.measureText(p[E]).width)>M&&(M=S),F=0|this.node._vf.length[E],x>0&&(F>x||0==F)&&(F=x),g[E]=F<=0?S:32*F;var C=.25*T,w=M+C,A=T+T*n*(p.length-1)+C;_=0,m=0;var R=0,D=0,N="alphabetic";switch(s){case"center":R=-w/2,_=w/2;break;case"left":R=0,_=0;break;case"right":R=-w,_=w}switch(d){case"MIDDLE":D=A/2-C/2,N="middle",m=T/2;break;case"BEGIN":D=f?0:A-C,N=f?"top":"bottom",m=f?0:T;break;case"FIRST":D=f?T:A-C,N=f?"alphabetic":"bottom",m=T;break;case"END":D=f?A-C:0,N=f?"bottom":"top",m=f?T:0}var I=w*(1/32),P=A*(1/32),V=x3dom.caps.MAX_TEXTURE_SIZE>>2;R*=1/32,D*=1/32,y.width=Math.min(x3dom.Utils.nextHighestPowerOfTwo(w*a),V),y.height=Math.min(x3dom.Utils.nextHighestPowerOfTwo(A*a),V),y.dir=h,b.scale(y.width/w,y.height/A),b.fillStyle="rgba(0,0,0,0)",b.fillRect(0,0,b.canvas.width,b.canvas.height),b.fillStyle="white",b.textBaseline=N,b.font=o+" "+T+"px "+i,b.textAlign=v;var L={font_style:o,font_family:i,font_spacing:n,paragraph:p,topToBottom:f,leftToRight:h,textX:_,textY:m,textHeight:T,lengths:g};this.renderScaledText(b,1,L),null===this.texture&&(this.texture=e.createTexture()),e.bindTexture(this.type,this.texture),this.uploadTextMipmap(y,L),e.bindTexture(this.type,null),document.body.removeChild(y),this.node._mesh._positions[0]=[0+R,-P+D,0,I+R,-P+D,0,I+R,0+D,0,0+R,0+D,0],this.node.invalidateVolume(),this.node._parentNodes.forEach((function(e){e.setAllDirty()}))},x3dom.Texture.prototype.renderScaledText=function(e,t,i){e.font=i.font_style+" "+i.textHeight/t+"px "+i.font_family;for(var o=i.textY,s=0;s<i.paragraph.length;s++){var r=i.topToBottom?s:i.paragraph.length-1-s,n=i.paragraph[r];"rtl"==i.leftToRight&&(n="‮"+n),e.fillText(n,i.textX/t,o/t,i.lengths[r]/t),o+=i.textHeight*i.font_spacing}},x3dom.Texture.prototype.uploadTextMipmap=function(e,t){for(var i=this.gl,o=e.width,s=e.height,r=0,n=1,a=o,d=s,l=e.getContext("2d");i.texImage2D(this.type,r++,this.format,this.format,i.UNSIGNED_BYTE,l.getImageData(0,0,a,d)),1!=a||1!=d;)a=Math.max(1,a>>1),d=Math.max(1,d>>1),l.clearRect(0,0,o,s),n*=2,this.renderScaledText(l,n,t)},x3dom.X3DDocument=function(e,t,i){this.canvas=e,this.ctx=t,this.properties=i,this.needRender=!0,this._x3dElem=null,this._scene=null,this._viewarea=null,this.downloadCount=0,this.previousDownloadCount=0,this.mutationObserver=new MutationObserver(this.onMutation.bind(this)),this.X3DMutationObserver=new MutationObserver(this.onX3DMutation.bind(this)),this._nodeBag={timer:[],lights:[],clipPlanes:[],followers:[],trans:[],renderTextures:[],viewarea:[],affectedPointingSensors:[]},this.onload=function(){},this.onerror=function(){}},x3dom.X3DDocument.prototype.load=function(e,t){var i={},o=[e],s=this;!function r(){if(0===o.length)return s._setup(i[e],i,t),void s.onload();var n=o.shift();!x3dom.isX3DElement(n)||"x3d"!==n.localName.toLowerCase()&&"websg"!==n.localName.toLowerCase()||(i[n]=n,s._x3dElem=n,r())}()},x3dom.findScene=function(e){for(var t=[],i=0;i<e.childNodes.length;i++){var o=e.childNodes[i];o&&o.localName&&"scene"===o.localName.toLowerCase()&&t.push(o)}return t.length>1?(x3dom.debug.logError("X3D element has more than one Scene child (has "+e.childNodes.length+")."),null):t[0]},x3dom.X3DDocument.prototype._setup=function(e){var t=x3dom.findScene(e);this.X3DMutationObserver.observe(document,{attributes:!1,attributeOldValue:!1,childList:!0,subtree:!0}),this.mutationObserver.observe(e,{attributes:!1,attributeOldValue:!1,childList:!0,subtree:!1}),this.mutationObserver.observe(t,{attributes:!0,attributeOldValue:!0,childList:!0,subtree:!0}),this._bindableBag=new x3dom.BindableBag(this);var i=new x3dom.NodeNameSpace("scene",this).setupTree(t);this._scene=i,this._bindableBag.setRefNode(i),this._viewarea=new x3dom.Viewarea(this,i),this._viewarea._width=this.canvas.width,this._viewarea._height=this.canvas.height},x3dom.X3DDocument.prototype.advanceTime=function(e){var t=0;if(this._nodeBag.timer.length)for(t=0;t<this._nodeBag.timer.length;t++)this.needRender|=this._nodeBag.timer[t].tick(e);if(this._nodeBag.followers.length)for(t=0;t<this._nodeBag.followers.length;t++)this.needRender|=this._nodeBag.followers[t].tick(e);if(this._nodeBag.trans.length)for(t=0;t<this._nodeBag.trans.length;t++)this.needRender|=this._nodeBag.trans[t].tick(e);if(this._nodeBag.viewarea.length)for(t=0;t<this._nodeBag.viewarea.length;t++)this.needRender|=this._nodeBag.viewarea[t].tick(e)},x3dom.X3DDocument.prototype.render=function(e,t,i){e&&this._viewarea&&(this._viewarea.setVRFrameData(t),this._viewarea.updateGamepads(i),e.renderScene(this._viewarea))},x3dom.X3DDocument.prototype.onPick=function(e,t,i){e&&this._viewarea&&e.pickValue(this._viewarea,t,i,1)},x3dom.X3DDocument.prototype.onPickRect=function(e,t,i,o,s){return e&&this._viewarea?e.pickRect(this._viewarea,t,i,o,s):[]},x3dom.X3DDocument.prototype.onMove=function(e,t,i,o){e&&this._viewarea&&(this._viewarea._scene._vf.doPickPass&&e.pickValue(this._viewarea,t,i,o),this._viewarea.onMove(t,i,o))},x3dom.X3DDocument.prototype.onMoveView=function(e,t,i,o,s){e&&this._viewarea&&this._scene.getNavigationInfo()._impl.onTouchDrag(this._viewarea,t,i,o,s)},x3dom.X3DDocument.prototype.onDrag=function(e,t,i,o){e&&this._viewarea&&(this._viewarea._scene._vf.doPickPass&&!this._viewarea._isMoving&&e.pickValue(this._viewarea,t,i,o),this._viewarea.onDrag(t,i,o))},x3dom.X3DDocument.prototype.onWheel=function(e,t,i,o){e&&this._viewarea&&(this._viewarea._scene._vf.doPickPass&&e.pickValue(this._viewarea,t,o,0),this._viewarea.onDrag(t,i,2))},x3dom.X3DDocument.prototype.onMousePress=function(e,t,i,o){e&&this._viewarea&&(this._viewarea._scene.updateVolume(),e.pickValue(this._viewarea,t,i,o),this._viewarea.onMousePress(t,i,o))},x3dom.X3DDocument.prototype.onMouseRelease=function(e,t,i,o,s){if(e&&this._viewarea){var r=s<<8|o;e.pickValue(this._viewarea,t,i,r),this._viewarea.onMouseRelease(t,i,o,s)}},x3dom.X3DDocument.prototype.onMouseOver=function(e,t,i,o){e&&this._viewarea&&(e.pickValue(this._viewarea,t,i,o),this._viewarea.onMouseOver(t,i,o))},x3dom.X3DDocument.prototype.onMouseOut=function(e,t,i,o){e&&this._viewarea&&(e.pickValue(this._viewarea,t,i,o),this._viewarea.onMouseOut(t,i,o))},x3dom.X3DDocument.prototype.onDoubleClick=function(e,t,i){e&&this._viewarea&&this._viewarea.onDoubleClick(t,i)},x3dom.X3DDocument.prototype.onKeyDown=function(e){switch(e){case 37:this._viewarea.strafeLeft();break;case 38:this._viewarea.moveFwd();break;case 39:this._viewarea.strafeRight();break;case 40:this._viewarea.moveBwd()}},x3dom.X3DDocument.prototype.onKeyUp=function(e){var t=null;switch(e){case 13:x3dom.toggleFullScreen();break;case 33:(t=this._scene.getViewpoint()._stack)?t.switchTo("prev"):x3dom.debug.logError("No valid ViewBindable stack.");break;case 34:(t=this._scene.getViewpoint()._stack)?t.switchTo("next"):x3dom.debug.logError("No valid ViewBindable stack.");break;case 35:(t=this._scene.getViewpoint()._stack)?t.switchTo("last"):x3dom.debug.logError("No valid ViewBindable stack.");break;case 36:(t=this._scene.getViewpoint()._stack)?t.switchTo("first"):x3dom.debug.logError("No valid ViewBindable stack.")}},x3dom.X3DDocument.prototype.onKeyPress=function(e){var t=this._scene.getNavigationInfo(),i=this._scene.getEnvironment();switch(e){case 32:var o=this.canvas.parent.stateViewer;o&&o.display(),x3dom.debug.logInfo("a: show all | i: fit view | d: show helper buffers | s: small feature culling | t: light view | m: toggle render mode | c: frustum culling | p: intersect type | \ne: examine mode | f: fly mode | y: freefly mode | w: walk mode | h: helicopter mode | l: lookAt mode | o: lookaround | g: game mode | n: turntable | u: upright position | \nv: print viewpoint info | r: reset view | home: first view | end: last view | pageUp: next view | pageDown: prev. view | +: increase speed | -: decrease speed ");break;case 43:t._vf.speed=2*t._vf.speed,x3dom.debug.logInfo("Changed navigation speed to "+t._vf.speed);break;case 45:t._vf.speed=.5*t._vf.speed,x3dom.debug.logInfo("Changed navigation speed to "+t._vf.speed);break;case 51:x3dom.nodeTypes.PopGeometry.ErrorToleranceFactor+=.5,x3dom.debug.logInfo("Changed POP error tolerance to "+x3dom.nodeTypes.PopGeometry.ErrorToleranceFactor);break;case 52:x3dom.nodeTypes.PopGeometry.ErrorToleranceFactor-=.5,x3dom.debug.logInfo("Changed POP error tolerance to "+x3dom.nodeTypes.PopGeometry.ErrorToleranceFactor);break;case 54:t._vf.typeParams[1]+=1,t._heliUpdated=!1,x3dom.debug.logInfo("Changed helicopter height to "+t._vf.typeParams[1]);break;case 55:t._vf.typeParams[1]-=1,t._heliUpdated=!1,x3dom.debug.logInfo("Changed helicopter height to "+t._vf.typeParams[1]);break;case 56:t._vf.typeParams[0]-=.02,t._heliUpdated=!1,x3dom.debug.logInfo("Changed helicopter angle to "+t._vf.typeParams[0]);break;case 57:t._vf.typeParams[0]+=.02,t._heliUpdated=!1,x3dom.debug.logInfo("Changed helicopter angle to "+t._vf.typeParams[0]);break;case 97:this._viewarea.showAll();break;case 99:i._vf.frustumCulling=!i._vf.frustumCulling,x3dom.debug.logInfo("Viewfrustum culling "+(i._vf.frustumCulling?"on":"off"));break;case 100:void 0===this._viewarea._visDbgBuf&&(this._viewarea._visDbgBuf="true"===this._x3dElem.getAttribute("showLog")),this._viewarea._visDbgBuf=!this._viewarea._visDbgBuf,x3dom.debug.logContainer.style.display=1==this._viewarea._visDbgBuf?"block":"none";break;case 101:t.setType("examine",this._viewarea);break;case 102:t.setType("fly",this._viewarea);break;case 103:t.setType("game",this._viewarea);break;case 104:t.setType("helicopter",this._viewarea);break;case 105:this._viewarea.fit(this._scene._lastMin,this._scene._lastMax);break;case 108:t.setType("lookat",this._viewarea);break;case 109:this._viewarea._points=++this._viewarea._points%2;break;case 110:t.setType("turntable",this._viewarea);break;case 111:t.setType("lookaround",this._viewarea);break;case 112:switch(this._scene._vf.pickMode.toLowerCase()){case"idbuf":this._scene._vf.pickMode="color";break;case"color":this._scene._vf.pickMode="texCoord";break;case"texcoord":this._scene._vf.pickMode="box";break;default:this._scene._vf.pickMode="idBuf"}x3dom.debug.logInfo("Switch pickMode to '"+this._scene._vf.pickMode+"'.");break;case 114:this._viewarea.resetView();break;case 115:i._vf.smallFeatureCulling=!i._vf.smallFeatureCulling,x3dom.debug.logInfo("Small feature culling "+(i._vf.smallFeatureCulling?"on":"off"));break;case 116:this._nodeBag.lights.length>0&&this._viewarea.animateTo(this._viewarea.getLightMatrix()[0],this._scene.getViewpoint());break;case 117:this._viewarea.uprightView();break;case 118:var s=this;!function(){var e=s._viewarea._scene.getViewpoint(),t=s._viewarea.getViewMatrix().inverse(),i=new x3dom.fields.Quaternion(0,0,1,0);i.setValue(t);var o=i.toAxisAngle(),r=t.e3(),n=e.getCenterOfRotation();x3dom.debug.logInfo('\n&lt;Viewpoint position="'+r.x.toFixed(5)+" "+r.y.toFixed(5)+" "+r.z.toFixed(5)+'" orientation="'+o[0].x.toFixed(5)+" "+o[0].y.toFixed(5)+" "+o[0].z.toFixed(5)+" "+o[1].toFixed(5)+'" \n\tzNear="'+e.getNear().toFixed(5)+'" zFar="'+e.getFar().toFixed(5)+'" centerOfRotation="'+n.x.toFixed(5)+" "+n.y.toFixed(5)+" "+n.z.toFixed(5)+'" fieldOfView="'+e.getFieldOfView().toFixed(5)+'" description="'+e._vf.description+'"&gt;&lt;/Viewpoint&gt;')}();break;case 119:t.setType("walk",this._viewarea);break;case 121:t.setType("freefly",this._viewarea)}},x3dom.X3DDocument.prototype.shutdown=function(e){e&&e.shutdown(this._viewarea)},x3dom.X3DDocument.prototype.hasAnimationStateChanged=function(){return!!this._viewarea&&this._viewarea.hasAnimationStateChanged()},x3dom.X3DDocument.prototype.isAnimating=function(){return!!this._viewarea&&this._viewarea.isAnimating()},x3dom.X3DDocument.prototype.incrementDownloads=function(){this.downloadCount++},x3dom.X3DDocument.prototype.decrementDownloads=function(){this.downloadCount--},x3dom.X3DDocument.prototype.cleanNodeBag=function(e,t){for(var i=0,o=e.length;i<o;i++)if(e[i]===t){e.splice(i,1);break}},x3dom.X3DDocument.prototype.removeX3DOMBackendGraph=function(e){for(var t=e.childNodes,i=0,o=t.length;i<o;i++)this.removeX3DOMBackendGraph(t[i]);if(e._x3domNode){var s=e._x3domNode,r=s._nameSpace;if(x3dom.isa(s,x3dom.nodeTypes.X3DShapeNode))s._cleanupGLObjects&&s._cleanupGLObjects(!0),x3dom.nodeTypes.Shape.idMap.nodeID[s._objectID]&&delete x3dom.nodeTypes.Shape.idMap.nodeID[s._objectID];else if(x3dom.isa(s,x3dom.nodeTypes.TimeSensor))this.cleanNodeBag(this._nodeBag.timer,s);else if(x3dom.isa(s,x3dom.nodeTypes.X3DLightNode))this.cleanNodeBag(this._nodeBag.lights,s);else if(x3dom.isa(s,x3dom.nodeTypes.X3DFollowerNode))this.cleanNodeBag(this._nodeBag.followers,s);else if(x3dom.isa(s,x3dom.nodeTypes.X3DTransformNode))this.cleanNodeBag(this._nodeBag.trans,s);else if(x3dom.isa(s,x3dom.nodeTypes.RenderedTexture))this.cleanNodeBag(this._nodeBag.renderTextures,s),s._cleanupGLObjects&&s._cleanupGLObjects();else if(x3dom.isa(s,x3dom.nodeTypes.X3DPointingDeviceSensorNode))this.cleanNodeBag(this._nodeBag.affectedPointingSensors,s);else if(x3dom.isa(s,x3dom.nodeTypes.Texture))s.shutdown();else if(x3dom.isa(s,x3dom.nodeTypes.AudioClip))s.shutdown();else if(x3dom.isa(s,x3dom.nodeTypes.X3DBindableNode)){var n=s._stack;n&&(s.bind(!1),this.cleanNodeBag(n._bindBag,s)),s._cleanupGLObjects&&s._cleanupGLObjects()}else x3dom.isa(s,x3dom.nodeTypes.Scene)&&s._webgl&&(s._webgl=null);!r||e.getAttribute("use")||e.getAttribute("USE")||r.removeNode(s._DEF),s._xmlNode=null,delete e._x3domNode}},x3dom.X3DDocument.prototype.getParentNode=function(e){return e&&"x3dommetagroup"==e.localName.toLowerCase()&&(e=this.getParentNode(e.parentNode)),e},x3dom.X3DDocument.prototype.onAttributeChanged=function(e,t,i){"_x3domNode"in e&&(e._x3domNode.updateField(t,i),this.needRender=!0)},x3dom.X3DDocument.prototype.onNodeRemoved=function(e,t){var i=e;if(i){i.querySelectorAll&&i.querySelectorAll("*").forEach((function(e){e.highlight=null,e.addEventListener=null,e.removeEventListener=null}));var o=this.getParentNode(t);if(o&&"_x3domNode"in o&&"_x3domNode"in i){var s=o._x3domNode,r=i._x3domNode,n=r.findX3DDoc()._viewarea._pickingInfo;n.firstObj=null,n.lastObj=null,n.lastClickObj=null,n.pickObj=null,s&&r&&(s.removeChild(r),s.nodeChanged(),this.removeX3DOMBackendGraph(i),this._viewarea&&this._viewarea._scene&&(this._viewarea._scene.nodeChanged(),this._viewarea._scene.updateVolume(),this.needRender=!0))}else if(i.localName&&"ROUTE"==i.localName.toUpperCase()&&i._nodeNameSpace){var a=i._nodeNameSpace.defMap[i.getAttribute("fromNode")],d=i._nodeNameSpace.defMap[i.getAttribute("toNode")];a&&d&&a.removeRoute(i.getAttribute("fromField"),d,i.getAttribute("toField"))}}},x3dom.X3DDocument.prototype.onX3DNodeRemoved=function(e,t){var i=[];"querySelector"in e&&e.querySelector("X3D")&&(i=e.querySelectorAll("X3D")),e.localName&&"X3D"==e.localName.toUpperCase()&&(i=[e]),i.forEach((function(e){var t=e.runtime;if(t&&t.canvas&&t.canvas.doc&&t.canvas.doc._scene){var i=t.canvas.doc._scene._xmlNode;this.removeX3DOMBackendGraph(i);for(var o=0;o<x3dom.canvases.length;o++)if(x3dom.canvases[o]===t.canvas){x3dom.canvases[o].doc.shutdown(x3dom.canvases[o].gl),x3dom.canvases.splice(o,1);break}t.canvas.doc._scene=null,t.canvas.doc._viewarea=null,t.canvas.doc=null,t.canvas=null,t=null,e.context=null,e.runtime=null}}),this)},x3dom.X3DDocument.prototype.onNodeAdded=function(e,t){var i=e,o=this.getParentNode(t);if((!o.tagName||"inline"!=o.tagName.toLowerCase())&&"_x3domNode"in o){var s=o._x3domNode;if(s&&s._nameSpace&&i instanceof Element){if("_x3domNode"in i){if(i._x3domNode._parentNodes.includes(s))return;s.removeChild(i._x3domNode),this.removeX3DOMBackendGraph(i)}x3dom.caps.DOMNodeInsertedEvent_perSubtree&&this.removeX3DOMBackendGraph(i);var r=s._nameSpace.setupTree(i);s.addChild(r,i.getAttribute("containerField")),s.nodeChanged();var n=o.parentNode;n&&n._x3domNode&&n._x3domNode.nodeChanged(),this._viewarea&&this._viewarea._scene&&(this._viewarea._scene.nodeChanged(),this._viewarea._scene.updateVolume(),this.needRender=!0)}else x3dom.debug.logWarning("No _nameSpace in onNodeAdded")}},x3dom.X3DDocument.prototype.onX3DNodeAdded=function(e,t){var i=e;i.localName&&i.localName.toUpperCase()},x3dom.X3DDocument.prototype.onMutation=function(e){for(var t=0,i=e.length;t<i;t++)if("attributes"===e[t].type&&e[t].oldValue)this.onAttributeChanged(e[t].target,e[t].attributeName,e[t].target[e[t].attributeName]);else if("childList"===e[t].type){if(e[t].removedNodes.length)for(var o=0,s=e[t].removedNodes.length;o<s;o++)this.onNodeRemoved(e[t].removedNodes[o],e[t].target);if(e[t].addedNodes.length)for(o=0,s=e[t].addedNodes.length;o<s;o++)this.onNodeAdded(e[t].addedNodes[o],e[t].target)}},x3dom.X3DDocument.prototype.onX3DMutation=function(e){for(var t=0,i=e.length;t<i;t++)if("childList"===e[t].type&&e[t].removedNodes.length)for(var o=0,s=e[t].removedNodes.length;o<s;o++)this.onX3DNodeRemoved(e[t].removedNodes[o],e[t].target)},x3dom.MatrixMixer=function(e,t){this.beginTime=e||0,this.endTime=t||1,this.isMixing=!1,this._beginMat=x3dom.fields.SFMatrix4f.identity(),this._beginInvMat=x3dom.fields.SFMatrix4f.identity(),this._beginLogMat=x3dom.fields.SFMatrix4f.identity(),this._endMat=x3dom.fields.SFMatrix4f.identity(),this._endLogMat=x3dom.fields.SFMatrix4f.identity(),this._beginRot=new x3dom.fields.Quaternion,this._endRot=new x3dom.fields.Quaternion,this._beginPos=new x3dom.fields.SFVec3f,this._endPos=new x3dom.fields.SFVec3f,this._result=x3dom.fields.SFMatrix4f.identity(),this._useQuaternion=!1,this._isVPtarget=!1},x3dom.MatrixMixer.prototype._calcFraction=function(e){var t=(e-this.beginTime)/(this.endTime-this.beginTime);return(Math.sin(t*Math.PI-Math.PI/2)+1)/2},x3dom.MatrixMixer.prototype._isValid=function(){var e=this._beginMat.inverse().mult(this._endMat).getEulerAngles();return Math.abs(e[0])!=Math.PI&&Math.abs(e[1])!=Math.PI&&Math.abs(e[2])!=Math.PI},x3dom.MatrixMixer.prototype._prepareQuaternionAnimation=function(){this._beginRot.setValue(this._beginMat),this._endRot.setValue(this._endMat),this._beginPos=this._beginMat.e3(),this._endPos=this._endMat.e3(),this._useQuaternion=!0},x3dom.MatrixMixer.prototype.reset=function(){this.beginTime=0,this.endTime=0,this._useQuaternion=!1,this.isMixing=!1},x3dom.MatrixMixer.prototype.isActive=function(){return this.beginTime>0},x3dom.MatrixMixer.prototype.setBeginMatrix=function(e){this._beginMat.setValues(e),this._beginInvMat=e.inverse(),this._beginLogMat=x3dom.fields.SFMatrix4f.zeroMatrix()},x3dom.MatrixMixer.prototype.getBeginMatrix=function(e){return this._beginMat},x3dom.MatrixMixer.prototype.setEndMatrix=function(e){this._endMat.setValues(e),this._isValid()||this._prepareQuaternionAnimation(),this._endLogMat=this._endMat.mult(this._beginInvMat).log(),this._logDiffMat=this._endLogMat.addScaled(this._beginLogMat,-1)},x3dom.MatrixMixer.prototype.getEndMatrix=function(e){return this._endMat},x3dom.MatrixMixer.prototype._mixQuaternion=function(e){var t=this._beginRot.slerp(this._endRot,e),i=this._beginPos.addScaled(this._endPos.subtract(this._beginPos),e);return this._result.setRotate(t),this._result.setTranslate(i),this._result.copy()},x3dom.MatrixMixer.prototype._mixMatrix=function(e){return this._logDiffMat.multiply(e).add(this._beginLogMat).exp().mult(this._beginMat)},x3dom.MatrixMixer.prototype.mix=function(e){if(e<=this.beginTime)return this._beginMat;if(e>=this.endTime)return this.reset(),this._endMat;this.isMixing=!0;var t=this._calcFraction(e);return this._useQuaternion?this._mixQuaternion(t):this._mixMatrix(t)},x3dom.Mesh=function(e){this._parent=e,this._vol=new x3dom.fields.BoxVolume,this._invalidate=!0,this._numFaces=0,this._numCoords=0,this._primType="TRIANGLES",this._positions=[],this._normals=[],this._texCoords=[],this._texCoords2=[],this._colors=[],this._indices=[],this._tangents=[],this._binormals=[],this._positions[0]=[],this._normals[0]=[],this._texCoords[0]=[],this._texCoords2[0]=[],this._colors[0]=[],this._indices[0]=[],this._tangents[0]=[],this._binormals[0]=[]},x3dom.Mesh.prototype._dynamicFields={},x3dom.Mesh.prototype._numPosComponents=3,x3dom.Mesh.prototype._numTexComponents=2,x3dom.Mesh.prototype._numTex2Components=2,x3dom.Mesh.prototype._numColComponents=3,x3dom.Mesh.prototype._numNormComponents=3,x3dom.Mesh.prototype._numTangentComponents=3,x3dom.Mesh.prototype._numBinormalComponents=3,x3dom.Mesh.prototype._lit=!0,x3dom.Mesh.prototype._vol=null,x3dom.Mesh.prototype._invalidate=!0,x3dom.Mesh.prototype._numFaces=0,x3dom.Mesh.prototype._numCoords=0,x3dom.Mesh.prototype.getVolume=function(){if(1==this._invalidate&&!this._vol.isValid()){var e=this._positions[0],t=e.length;if(t>=3){var i=new x3dom.fields.SFVec3f(e[0],e[1],e[2]);this._vol.setBounds(i,i);for(var o=3;o<t;o+=3)this._vol.min.x>e[o]&&(this._vol.min.x=e[o]),this._vol.min.y>e[o+1]&&(this._vol.min.y=e[o+1]),this._vol.min.z>e[o+2]&&(this._vol.min.z=e[o+2]),this._vol.max.x<e[o]&&(this._vol.max.x=e[o]),this._vol.max.y<e[o+1]&&(this._vol.max.y=e[o+1]),this._vol.max.z<e[o+2]&&(this._vol.max.z=e[o+2]);this._invalidate=!1}}return this._vol},x3dom.Mesh.prototype.invalidate=function(){this._invalidate=!0,this._vol.invalidate()},x3dom.Mesh.prototype.isValid=function(){return this._vol.isValid()},x3dom.Mesh.prototype.getCenter=function(){return this.getVolume().getCenter()},x3dom.Mesh.prototype.getDiameter=function(){return this.getVolume().getDiameter()},x3dom.Mesh.prototype.doIntersect=function(e){var t=this.getVolume(),i=e.intersect(t.min,t.max);return i&&e.enter<e.dist&&(e.dist=e.enter,e.hitObject=this._parent,e.hitPoint=e.pos.add(e.dir.multiply(e.enter))),i},x3dom.Mesh.prototype.calcNormals=function(e,t){void 0===t&&(t=!0);var i,o,s,r,n=this._multiIndIndices&&this._multiIndIndices.length,a=n?this._multiIndIndices:this._indices[0],d=this._positions[0],l=[],h=[],f=d.length,u=null,c=void 0!==this._posSize&&this._posSize>f?this._posSize/3:f/3;for(c=3*(c-Math.floor(c)>0?Math.floor(c+1):c),i=0;i<c;++i)h[i]=[];for(c=a.length,i=0;i<c;i+=3){var _,m,p,x;n?(_=3*i,m=3*(i+1),p=3*(i+2),x=new x3dom.fields.SFVec3f(d[m],d[m+1],d[m+2]),s=new x3dom.fields.SFVec3f(d[_],d[_+1],d[_+2]).subtract(x),r=x.subtract(new x3dom.fields.SFVec3f(d[p],d[p+1],d[p+2]))):(_=3*a[i],m=3*a[i+1],p=3*a[i+2],x=new x3dom.fields.SFVec3f(d[m],d[m+1],d[m+2]),s=new x3dom.fields.SFVec3f(d[_],d[_+1],d[_+2]).subtract(x),r=x.subtract(new x3dom.fields.SFVec3f(d[p],d[p+1],d[p+2])),_=3*i,m=3*(i+1),p=3*(i+2)),u=s.cross(r).normalize(),t||(u=u.negate()),e<=x3dom.fields.Eps?(l[_]=l[m]=l[p]=u.x,l[_+1]=l[m+1]=l[p+1]=u.y,l[_+2]=l[m+2]=l[p+2]=u.z):(h[a[i]].push(u),h[a[i+1]].push(u),h[a[i+2]].push(u))}if(e>x3dom.fields.Eps)for(i=0;i<f;i+=3){var g,v=i/3;for(c=(g=n?h[a[v]]:h[v]).length,u=new x3dom.fields.SFVec3f(0,0,0),o=0;o<c;++o)u=u.add(g[o]);u=u.normalize(),l[i]=u.x,l[i+1]=u.y,l[i+2]=u.z}this._normals[0]=l},x3dom.Mesh.prototype.splitMesh=function(e,t){var i,o;i=void 0===e?3:e,void 0===t&&(t=!1);var s=x3dom.Utils.maxIndexableCoords;if(s=Math.floor(s/i)*i,!(this._positions[0].length/3<=s)||t){o=!!t&&(this._multiIndIndices&&this._multiIndIndices.length);var r=this._positions[0],n=this._normals[0],a=this._texCoords[0],d=this._colors[0],l=o?this._multiIndIndices:this._indices[0],h=this._tangents[0],f=this._binormals[0],u=0;do{this._positions[u]=[],this._normals[u]=[],this._texCoords[u]=[],this._colors[u]=[],this._indices[u]=[],this._tangents[u]=[],this._binormals[u]=[];var c=l.length-(u+1)*s>=0;if(this._indices[u]=c?l.slice(u*s,(u+1)*s):l.slice(u*s),o)for(m=0,p=this._indices[u].length;m<p;m++)this._indices[u][m]=m;else if(u)for(var _=u*s,m=0,p=this._indices[u].length;m<p;m++)this._indices[u][m]-=_;this._positions[u]=c?r.slice(u*s*3,3*(u+1)*s):r.slice(u*s*3),n.length&&(this._normals[u]=c?n.slice(u*s*3,3*(u+1)*s):n.slice(u*s*3)),a.length&&(this._texCoords[u]=c?a.slice(u*s*this._numTexComponents,this._numTexComponents*(u+1)*s):a.slice(u*s*this._numTexComponents)),d.length&&(this._colors[u]=c?d.slice(u*s*this._numColComponents,this._numColComponents*(u+1)*s):d.slice(u*s*this._numColComponents)),h.length&&(this._tangents[u]=c?h.slice(u*s*3,3*(u+1)*s):h.slice(u*s*3)),f.length&&(this._binormals[u]=c?f.slice(u*s*3,3*(u+1)*s):f.slice(u*s*3))}while(r.length>++u*s*3)}},x3dom.Mesh.prototype.calcTexCoords=function(e){if(this._texCoords[0]=[],"sphere-local"===e.toLowerCase())for(var t=0,i=0,o=this._normals[0].length;t<o;t+=3)this._texCoords[0][i++]=.5+this._normals[0][t]/2,this._texCoords[0][i++]=.5+this._normals[0][t+1]/2;if("coord"===e.toLowerCase())for(var s=0,r=0,n=this._positions[0].length;s<n;s+=3)this._texCoords[0][r++]=this._positions[0][s],this._texCoords[0][r++]=this._positions[0][s+1];else{var a=new x3dom.fields.SFVec3f(0,0,0),d=new x3dom.fields.SFVec3f(0,0,0);this.getVolume().getBounds(a,d);var l=d.subtract(a),h=0,f=1;l.x>=l.y?l.x>=l.z?(h=0,f=l.y>=l.z?1:2):(h=2,f=0):l.y>=l.z?(h=1,f=l.x>=l.z?0:2):(h=2,f=1);var u=1,c=0,_=0;switch(h){case 0:u=l.x,c=a.x;break;case 1:u=l.y,c=a.y;break;case 2:u=l.z,c=a.z}switch(f){case 0:l.x,_=a.x;break;case 1:l.y,_=a.y;break;case 2:l.z,_=a.z}for(s=0,r=0,n=this._positions[0].length;s<n;s+=3)this._texCoords[0][r++]=(this._positions[0][s+h]-c)/u,this._texCoords[0][r++]=(this._positions[0][s+f]-_)/u}},x3dom.docs={},x3dom.docs.specURLMap={CADGeometry:"CADGeometry.html",Core:"core.html",DIS:"dis.html",CubeMapTexturing:"env_texture.html",EnvironmentalEffects:"enveffects.html",EnvironmentalSensor:"envsensor.html",Followers:"followers.html",Geospatial:"geodata.html",Geometry2D:"geometry2D.html",Geometry3D:"geometry3D.html",Grouping:"group.html","H-Anim":"hanim.html",Interpolation:"interp.html",KeyDeviceSensor:"keyboard.html",Layering:"layering.html",Layout:"layout.html",Lighting:"lighting.html",Navigation:"navigation.html",Networking:"networking.html",NURBS:"nurbs.html",ParticleSystems:"particle_systems.html",Picking:"picking.html",PointingDeviceSensor:"pointingsensor.html",Rendering:"rendering.html",RigidBodyPhysics:"rigid_physics.html",Scripting:"scripting.html",Shaders:"shaders.html",Shape:"shape.html",Sound:"sound.html",Text:"text.html",Texturing3D:"texture3D.html",Texturing:"texturing.html",Time:"time.html",EventUtilities:"utils.html",VolumeRendering:"volume.html"},x3dom.docs.specBaseURL="https://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/components/",x3dom.docs.getNodeTreeInfo=function(){var e,t="",i=function(e,t){for(var i=0;i<e.length;i++)if(e[i]===t)return!0;return!1},o=function(e,i){for(var s=0;s<i;s++)t+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";for(var s in t+="<a href='"+x3dom.docs.specBaseURL+x3dom.docs.specURLMap[x3dom.nodeTypes[e]._compName]+"#"+e+"' style='color:black; text-decoration:none; font-weight:bold;'>"+e+"</a> &nbsp; <a href='"+x3dom.docs.specBaseURL+x3dom.docs.specURLMap[x3dom.nodeTypes[e]._compName]+"' style='color:black; text-decoration:none; font-style:italic;'>"+x3dom.nodeTypes[e]._compName+"</a><br/>",x3dom.nodeTypes[e].childTypes[e])o(x3dom.nodeTypes[e].childTypes[e][s],i+1)};for(e in x3dom.nodeTypes){var s;for(void 0===(s=x3dom.nodeTypes[e]).childTypes&&(s.childTypes={});s.superClass;)void 0===s.superClass.childTypes[s.superClass._typeName]&&(s.superClass.childTypes[s.superClass._typeName]=[]),i(s.superClass.childTypes[s.superClass._typeName],s._typeName)||s.superClass.childTypes[s.superClass._typeName].push(s._typeName),s=s.superClass}return o("X3DNode",0),"<div class='x3dom-doc-nodes-tree'>"+t+"</div>"},x3dom.docs.getComponentInfo=function(){var e,t,i,o=[],s="";for(t in x3dom.components)o.push(t);for(i in o.sort(),o){for(var r in t=o[i],e=x3dom.components[t],s+="<h2><a href='"+x3dom.docs.specBaseURL+x3dom.docs.specURLMap[t]+"' style='color:black; text-decoration:none; font-style:italic;'>"+t+"</a></h2>",s+="<ul style='list-style-type:circle;'>",e)s+="<li><a href='"+x3dom.docs.specBaseURL+x3dom.docs.specURLMap[t]+"#"+r+"' style='color:black; text-decoration:none; font-weight:bold;'>"+r+"</a></li>";s+="</ul>"}return s},x3dom.arc={},x3dom.arc.instance=null,x3dom.arc.Limits=function(e,t,i){this._min=e,this._max=t,this.getValue=function(e){return e=this._min+(this._max-this._min)*e,this._max>=e?this._min<=e?e:this._min:this._max}},x3dom.arc.ARF=function(e,t,i,o,s,r,n,a){this._name=e,this._stateValue=[.5,.5],this._limits=new x3dom.arc.Limits(t,i),this._factorGetterFunc=s,this._factorSetterFunc=r,this._setterFunc=a,this._getterFunc=n,this._dirFac=o,this.getFactor=function(){return this._factorGetterFunc()},this.update=function(e,t){var i=this._stateValue[e]+t*this._dirFac;this._stateValue[e]=0<=i?1>=i?i:1:0,this._setterFunc(this._limits.getValue(this._stateValue[e]))},this.reset=function(){this._stateValue[0]=.5,this._stateValue[1]=.5}},x3dom.arc.AdaptiveRenderControl=defineClass(null,(function(e){x3dom.arc.instance=this,this._scene=e,this._targetFrameRate=[],this._targetFrameRate[0]=this._scene._vf.minFrameRate,this._targetFrameRate[1]=this._scene._vf.maxFrameRate,this._currentState=0;var t=this._scene.getEnvironment();this._arfs=[],this._arfs.push(new x3dom.arc.ARF("smallFeatureCulling",0,10,-1,(function(){return t._vf.smallFeatureFactor}),(function(e){t._vf.smallFeatureFactor=e}),(function(){return t._vf.smallFeatureThreshold}),(function(e){t._vf.smallFeatureThreshold=e}))),this._arfs.push(new x3dom.arc.ARF("lowPriorityCulling",0,100,1,(function(){return t._vf.lowPriorityFactor}),(function(e){t._vf.lowPriorityFactor=e}),(function(){return 100*t._vf.lowPriorityThreshold}),(function(e){t._vf.lowPriorityThreshold=e/100}))),this._arfs.push(new x3dom.arc.ARF("tessellationDetailCulling",1,12,-1,(function(){return t._vf.tessellationErrorFactor}),(function(e){t._vf.tessellationErrorFactor=e}),(function(){return t.tessellationErrorThreshold}),(function(e){t.tessellationErrorThreshold=e}))),this._stepWidth=.1}),{update:function(e,t){this._currentState=e;var i=t-this._targetFrameRate[e];this._stepWidth=Math.abs(i)>10?.1:.01;var o,s=0,r=[],n=this._arfs.length;for(o=0;o<n;++o)r[o]=this._arfs[o].getFactor(),r[o]>0&&(s+=r[o]);var a=i<0?-1:1;for(o=0;o<n;++o)r[o]>0&&(r[o]/=s,this._arfs[o].update(e,this._stepWidth*r[o]*a))},reset:function(){for(var e=0,t=this._arfs.length;e<t;++e)this._arfs[e].reset()}}),x3dom.RequestManager={},x3dom.RequestManager.requests=[],x3dom.RequestManager.maxParallelRequests=50,x3dom.RequestManager.failedRequests=0,x3dom.RequestManager.loadedRequests=0,x3dom.RequestManager.totalRequests=0,x3dom.RequestManager.activeRequests=[],x3dom.RequestManager.requestHeaders=[],x3dom.RequestManager.withCredentials=!1,x3dom.RequestManager.onSendRequest=function(e){},x3dom.RequestManager.onAbortAllRequests=function(e){},x3dom.RequestManager.addRequestHeader=function(e,t){this.requestHeaders.push({header:e,value:t})},x3dom.RequestManager._sendRequest=function(){if(this.onSendRequest(this._getCounters()),!(this.activeRequests.length>this.maxParallelRequests)){var e=this.requests.pop();e&&(this.activeRequests.push(e),e.send(null),this._sendRequest())}},x3dom.RequestManager._getCounters=function(){return{loaded:this.loadedRequests,active:this.activeRequests.length,failed:this.failedRequests,total:this.totalRequests}},x3dom.RequestManager.addRequest=function(e){if(e instanceof XMLHttpRequest){this.totalRequests++,e.withCredentials=this.withCredentials;for(var t=0;t<this.requestHeaders.length;t++){var i=this.requestHeaders[t].header,o=this.requestHeaders[t].value;e.setRequestHeader(i,o)}e.addEventListener("load",this._onLoadHandler.bind(this)),e.addEventListener("error",this._onErrorHandler.bind(this)),this.requests.push(e),this._sendRequest()}},x3dom.RequestManager.abortAllRequests=function(){for(var e=0;e<this.activeRequests.length;e++)this.activeRequests[e].abort();this.requests=[],this.activeRequests=[],this.failedRequests=0,this.loadedRequests=0,this.totalRequests=0,this.onAbortAllRequests(this._getCounters())},x3dom.RequestManager._removeActiveRequest=function(e){var t=this.activeRequests.indexOf(e);return this.activeRequests.splice(t,1)},x3dom.RequestManager._onLoadHandler=function(e){this._removeActiveRequest(e.target),this.loadedRequests++,this._sendRequest()},x3dom.RequestManager._onErrorHandler=function(e){this._removeActiveRequest(e.target),this.failedRequests++,this._sendRequest()},x3dom.Properties=function(){this.properties={}},x3dom.Properties.prototype.setProperty=function(e,t){x3dom.debug.logInfo("Properties: Setting property '"+e+"' to value '"+t+"'"),this.properties[e]=t},x3dom.Properties.prototype.getProperty=function(e,t){return this.properties[e]?this.properties[e]:t},x3dom.Properties.prototype.merge=function(e){for(var t in e.properties)this.properties[t]=e.properties[t]},x3dom.Properties.prototype.toString=function(){var e="";for(var t in this.properties)e+="Name: "+t+" Value: "+this.properties[t]+"\n";return e},x3dom.DoublyLinkedList=function(){this.length=0,this.first=null,this.last=null},x3dom.DoublyLinkedList.ListNode=function(e,t,i,o,s){this.point=e,this.point_index=t,this.normals=i,this.colors=o,this.texCoords=s,this.next=null,this.prev=null},x3dom.DoublyLinkedList.prototype.appendNode=function(e){null===this.first?(e.prev=e,e.next=e,this.first=e,this.last=e):(e.prev=this.last,e.next=this.first,this.first.prev=e,this.last.next=e,this.last=e),this.length++},x3dom.DoublyLinkedList.prototype.insertAfterNode=function(e,t){t.prev=e,t.next=e.next,e.next.prev=t,e.next=t,t.prev==this.last&&(this.last=t),this.length++},x3dom.DoublyLinkedList.prototype.deleteNode=function(e){this.length>1?(e.prev.next=e.next,e.next.prev=e.prev,e==this.first&&(this.first=e.next),e==this.last&&(this.last=e.prev)):(this.first=null,this.last=null),e.prev=null,e.next=null,this.length--},x3dom.DoublyLinkedList.prototype.getNode=function(e){var t=null;if(e>this.length)return t;for(var i=0;i<this.length;i++)if(t=0==i?this.first:t.next,i==e)return t;return null},x3dom.DoublyLinkedList.prototype.invert=function(){for(var e=null,t=this.first,i=0;i<this.length;i++)e=t.prev,t.prev=t.next,t.next=e,t=t.prev;e=this.first,this.first=this.last,this.last=e},x3dom.EarClipping={getIndexes:function(e){var t,i,o,s,r,n=e.first.next,a=this.identifyPlane(n.prev.point,n.point,n.next.point);for(i=[],o=[],t=0;t<e.length;t++){switch(n=e.getNode(t),a){case"XY":s=n.point.x,r=n.point.y;break;case"XZ":s=n.point.z,r=n.point.x;break;default:s=n.point.y,r=n.point.z}i.push(r),i.push(s),o.push(n.point_index)}var d=x3dom.EarCut.triangulate(i,null,2);return d=d.map((function(e){return o[e]}))},getMultiIndexes:function(e){var t,i,o,s=e.first.next,r=this.identifyPlane(s.prev.point,s.point,s.next.point),n={indices:[],point:[],normals:[],colors:[],texCoords:[]},a={indices:[],point:[],normals:[],colors:[],texCoords:[]},d=[];for(t=0;t<e.length;t++){switch(s=e.getNode(t),r){case"XY":i=s.point.x,o=s.point.y;break;case"XZ":i=s.point.z,o=s.point.x;break;default:i=s.point.y,o=s.point.z}d.push(o),d.push(i),a.indices.push(s.point_index),a.point.push(s.point),s.normals&&a.normals.push(s.normals),s.colors&&a.colors.push(s.colors),s.texCoords&&a.texCoords.push(s.texCoords)}var l=x3dom.EarCut.triangulate(d,null,2);return n.indices=l.map((function(e){return a.indices[e]})),n.point=l.map((function(e){return a.point[e]})),s.normals&&(n.normals=l.map((function(e){return a.normals[e]}))),s.colors&&(n.colors=l.map((function(e){return a.colors[e]}))),s.texCoords&&(n.texCoords=l.map((function(e){return a.texCoords[e]}))),n},identifyPlane:function(e,t,i){var o,s,r,n,a,d,l,h,f;o=t.x-e.x,s=t.y-e.y,r=t.z-e.z,n=i.x-e.x,a=i.y-e.y,d=i.z-e.z,l=Math.abs(s*d-r*a),h=Math.abs(r*n-o*d),f=Math.abs(o*a-s*n);var u=Math.max(l,h,f);return u==l?"YZ":u==h?"XZ":u==f?"XY":"XZ"}},x3dom.EarCut={triangulate:function(e,t,i){return function(e,t,i){i=i||2;var n,a,d,l,u,_,m,p=t&&t.length,x=p?t[0]*i:e.length,g=function(e,t,i,o){var s,r,n=0;for(s=t,r=i-o;s<i;s+=o)n+=(e[r]-e[s])*(e[s+1]+e[r+1]),r=s;return n>0}(e,0,x,i),v=o(e,0,x,i,!0,g),y=[];if(!v)return y;p&&(v=function(e,t,i,r){var n,a,d,l,u,_=[];for(n=0,a=t.length;n<a;n++)d=t[n]*r,l=n<a-1?t[n+1]*r:e.length,(u=o(e,d,l,r,!1))===u.next&&(u.steiner=!0),_.push(c(u));for(_.sort(h),n=0;n<_.length;n++)f(_[n],i),i=s(i,i.next);return i}(e,t,v,i));if(e.length>80*i){n=d=e[0],a=l=e[1];for(var T=i;T<x;T+=i)u=e[T],_=e[T+1],u<n&&(n=u),_<a&&(a=_),u>d&&(d=u),_>l&&(l=_);m=Math.max(d-n,l-a)}r(v,y,i,n,a,m),!1===g&&y.reverse();return y}(e,t,i);function o(e,t,i,o,s,r){var n,a;if(s===r)for(n=t;n<i;n+=o)a=T(n,e[n],e[n+1],a);else for(n=i-o;n>=t;n-=o)a=T(n,e[n],e[n+1],a);return a}function s(e,t){if(!e)return e;t||(t=e);var i,o=e;do{if(i=!1,o.steiner||!x(o,o.next)&&0!==p(o.prev,o,o.next))o=o.next;else{if(b(o),(o=t=o.prev)===o.next)return null;i=!0}}while(i||o!==t);return t}function r(e,t,i,o,h,f,c){if(e){!c&&f&&function(e,t,i,o){var s=e;do{null===s.z&&(s.z=u(s.x,s.y,t,i,o)),s.prevZ=s.prev,s.nextZ=s.next,s=s.next}while(s!==e);s.prevZ.nextZ=null,s.prevZ=null,function(e){var t,i,o,s,r,n,a,d,l=1;do{for(i=e,e=null,r=null,n=0;i;){for(n++,o=i,a=0,t=0;t<l&&(a++,o=o.nextZ);t++);for(d=l;a>0||d>0&&o;)0===a?(s=o,o=o.nextZ,d--):0!==d&&o?i.z<=o.z?(s=i,i=i.nextZ,a--):(s=o,o=o.nextZ,d--):(s=i,i=i.nextZ,a--),r?r.nextZ=s:e=s,s.prevZ=r,r=s;i=o}r.nextZ=null,l*=2}while(n>1)}(s)}(e,o,h,f);for(var _,m,p=e;e.prev!==e.next;)if(_=e.prev,m=e.next,f?a(e,o,h,f):n(e))t.push(_.i/i),t.push(e.i/i),t.push(m.i/i),b(e),e=m.next,p=m.next;else if((e=m)===p){c?1===c?r(e=d(e,t,i),t,i,o,h,f,2):2===c&&l(e,t,i,o,h,f):r(s(e),t,i,o,h,f,1);break}}}function n(e){var t=e.prev,i=e,o=e.next;if(p(t,i,o)>=0)return!1;for(var s=e.next.next;s!==e.prev;){if(_(t.x,t.y,i.x,i.y,o.x,o.y,s.x,s.y)&&p(s.prev,s,s.next)>=0)return!1;s=s.next}return!0}function a(e,t,i,o){var s=e.prev,r=e,n=e.next;if(p(s,r,n)>=0)return!1;for(var a=s.x<r.x?s.x<n.x?s.x:n.x:r.x<n.x?r.x:n.x,d=s.y<r.y?s.y<n.y?s.y:n.y:r.y<n.y?r.y:n.y,l=s.x>r.x?s.x>n.x?s.x:n.x:r.x>n.x?r.x:n.x,h=s.y>r.y?s.y>n.y?s.y:n.y:r.y>n.y?r.y:n.y,f=u(a,d,t,i,o),c=u(l,h,t,i,o),m=e.nextZ;m&&m.z<=c;){if(m!==e.prev&&m!==e.next&&_(s.x,s.y,r.x,r.y,n.x,n.y,m.x,m.y)&&p(m.prev,m,m.next)>=0)return!1;m=m.nextZ}for(m=e.prevZ;m&&m.z>=f;){if(m!==e.prev&&m!==e.next&&_(s.x,s.y,r.x,r.y,n.x,n.y,m.x,m.y)&&p(m.prev,m,m.next)>=0)return!1;m=m.prevZ}return!0}function d(e,t,i){var o=e;do{var s=o.prev,r=o.next.next;g(s,o,o.next,r)&&v(s,r)&&v(r,s)&&(t.push(s.i/i),t.push(o.i/i),t.push(r.i/i),b(o),b(o.next),o=e=r),o=o.next}while(o!==e);return o}function l(e,t,i,o,n,a){var d=e;do{for(var l=d.next.next;l!==d.prev;){if(d.i!==l.i&&m(d,l)){var h=y(d,l);return d=s(d,d.next),h=s(h,h.next),r(d,t,i,o,n,a),void r(h,t,i,o,n,a)}l=l.next}d=d.next}while(d!==e)}function h(e,t){return e.x-t.x}function f(e,t){if(t=function(e,t){var i,o=t,s=e.x,r=e.y,n=-1/0;do{if(r<=o.y&&r>=o.next.y){var a=o.x+(r-o.y)*(o.next.x-o.x)/(o.next.y-o.y);a<=s&&a>n&&(n=a,i=o.x<o.next.x?o:o.next)}o=o.next}while(o!==t);if(!i)return null;var d,l=i,h=1/0;o=i.next;for(;o!==l;)s>=o.x&&o.x>=i.x&&_(r<i.y?s:n,r,i.x,i.y,r<i.y?n:s,r,o.x,o.y)&&((d=Math.abs(r-o.y)/(s-o.x))<h||d===h&&o.x>i.x)&&v(o,e)&&(i=o,h=d),o=o.next;return i}(e,t)){var i=y(t,e);s(i,i.next)}}function u(e,t,i,o,s){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-i)/s)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-o)/s)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function c(e){var t=e,i=e;do{t.x<i.x&&(i=t),t=t.next}while(t!==e);return i}function _(e,t,i,o,s,r,n,a){return(s-n)*(t-a)-(e-n)*(r-a)>=0&&(e-n)*(o-a)-(i-n)*(t-a)>=0&&(i-n)*(r-a)-(s-n)*(o-a)>=0}function m(e,t){return x(e,t)||e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){var i=e;do{if(i.i!==e.i&&i.next.i!==e.i&&i.i!==t.i&&i.next.i!==t.i&&g(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}(e,t)&&v(e,t)&&v(t,e)&&function(e,t){var i=e,o=!1,s=(e.x+t.x)/2,r=(e.y+t.y)/2;do{i.y>r!=i.next.y>r&&s<(i.next.x-i.x)*(r-i.y)/(i.next.y-i.y)+i.x&&(o=!o),i=i.next}while(i!==e);return o}(e,t)}function p(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function x(e,t){return e.x===t.x&&e.y===t.y}function g(e,t,i,o){return p(e,t,i)>0!=p(e,t,o)>0&&p(i,o,e)>0!=p(i,o,t)>0}function v(e,t){return p(e.prev,e,e.next)<0?p(e,t,e.next)>=0&&p(e,e.prev,t)>=0:p(e,t,e.prev)<0||p(e,e.next,t)<0}function y(e,t){var i=new S(e.i,e.x,e.y),o=new S(t.i,t.x,t.y),s=e.next,r=t.prev;return e.next=t,t.prev=e,i.next=s,s.prev=i,o.next=i,i.prev=o,r.next=o,o.prev=r,o}function T(e,t,i,o){var s=new S(e,t,i);return o?(s.next=o.next,s.prev=o,o.next.prev=s,o.next=s):(s.prev=s,s.next=s),s}function b(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function S(e,t,i){this.i=e,this.x=t,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}}},x3dom.FieldInterpolator=function(e,t,i,o){this.beginTime=e||0,this.endTime=t||1,this.beginValue=i||0,this.endValue=o||0,this.isInterpolating=!1},x3dom.FieldInterpolator.prototype.isActive=function(){return this.beginTime>0},x3dom.FieldInterpolator.prototype.calcFraction=function(e){var t=(e-this.beginTime)/(this.endTime-this.beginTime);return(Math.sin(t*Math.PI-Math.PI/2)+1)/2},x3dom.FieldInterpolator.prototype.reset=function(){this.isInterpolating=!1,this.beginTime=0,this.endTime=1,this.beginValue=0,this.endValue=0},x3dom.FieldInterpolator.prototype.interpolate=function(e){if(e<this.beginTime)return this.beginValue;if(e>=this.endTime){var t=this.endValue;return this.reset(),t}return this.isInterpolating=!0,this.beginValue+(this.endValue-this.beginValue)*this.calcFraction(e)},x3dom.Utils={},x3dom.Utils.maxIndexableCoords=65535,x3dom.Utils.needLineWidth=!1,x3dom.Utils.measurements=[],window.performance=window.performance||{},performance.now=performance.now||performance.mozNow||performance.msNow||performance.oNow||performance.webkitNow||function(){return(new Date).getTime()},x3dom.Utils.startMeasure=function(e){var t=e.toUpperCase();x3dom.Utils.measurements[t]||(x3dom.Utils.measurements[t]=performance.now())},x3dom.Utils.stopMeasure=function(e){var t=e.toUpperCase();if(x3dom.Utils.measurements[t]){var i=x3dom.Utils.measurements[t];return delete x3dom.Utils.measurements[t],performance.now()-i}return 0},x3dom.Utils.isNumber=function(e){return!isNaN(parseFloat(e))&&isFinite(e)},x3dom.Utils.createTexture2D=function(e,t,i,o,s,r,n,a,d){a=a||!1;var l=e.createTexture(),h=new Uint8Array([0,0,0,255,0,0,0,255,0,0,0,255,0,0,0,255]);if(e.bindTexture(e.TEXTURE_2D,l),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,2,2,0,e.RGBA,e.UNSIGNED_BYTE,h),n&&e.generateMipmap(e.TEXTURE_2D),e.bindTexture(e.TEXTURE_2D,null),l.ready=!1,null==i||""==i)return l;var f=new Image;switch(s.toLowerCase()){case"anonymous":f.crossOrigin="anonymous";break;case"use-credentials":f.crossOrigin="use-credentials";break;case"none":break;default:x3dom.Utils.forbiddenBySOP(i)&&(f.crossOrigin="anonymous")}if(d&&0===d.getOrigChannelCount()){var u=new XMLHttpRequest;u.open("GET",i),u.onloadstart=function(){u.responseType="arraybuffer"},u.onload=function(){var e=u.getResponseHeader("Content-Type"),t=new Uint8Array(u.response),i=x3dom.Utils.detectChannelCount(t,e);i&&d.setOrigChannelCount(i),f.src=x3dom.Utils.arrayBufferToObjectURL(t,e)},x3dom.RequestManager.addRequest(u)}else f.src=i;return t.incrementDownloads(),f.onload=function(){l.originalWidth=f.width,l.originalHeight=f.height,r&&(f=x3dom.Utils.scaleImage(f)),1!=o&&1!=a||e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!0),e.bindTexture(e.TEXTURE_2D,l),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,f),n&&e.generateMipmap(e.TEXTURE_2D),e.bindTexture(e.TEXTURE_2D,null),1!=o&&1!=a||e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),l.width=f.width,l.height=f.height,l.ready=!0,t.decrementDownloads(),t.needRender=!0},f.onerror=function(o){x3dom.Utils.tryDDSLoading(l,e,t,i,n,a,d).then((function(){t.decrementDownloads(),t.needRender=!0}),(function(){x3dom.debug.logError("[Utils|createTexture2D] Can't load Image: "+i),t.decrementDownloads()}))},l},x3dom.Utils.tryDDSLoading=function(e,t,i,o,s,r,n){return x3dom.DDSLoader.load(o).then((function(i){if(i&&(!i.isCompressed||x3dom.caps.COMPRESSED_TEXTURE)){for(var o in t.bindTexture(i.type,e),!1,x3dom.Utils.isPowerOfTwo(i.width)||x3dom.Utils.isPowerOfTwo(i.height)?i.generateMipmaps&&t.texParameteri(i.type,t.TEXTURE_MIN_FILTER,t.LINEAR_MIPMAP_LINEAR):(t.texParameteri(i.type,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(i.type,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(i.type,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(i.type,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),i.generateMipmaps=!1),i.data)for(var s=i.width,r=i.height,a=i.data[o],d=0;d<a.length;d++)0!=d&&(s=Math.max(.5*s,1),r=Math.max(.5*r,1)),i.format.internal<33776||i.format.internal>33779?t.texImage2D(+o,d,i.format.internal,s,r,0,i.format.format,i.format.type,a[d]):(t.compressedTexImage2D(+o,d,i.format.internal,s,r,0,a[d]),i.generateMipmaps=!1);i.generateMipmaps&&t.generateMipmap(i.type),t.bindTexture(i.type,null),e.width=i.width,e.height=i.height,e.ready=!0,e.textureCubeReady=!0,n&&i.channelCount&&n.setOrigChannelCount(i.channelCount)}}))},x3dom.Utils.createTextureCube=function(e,t,i,o,s,r,n,a){var d,l=new Uint8Array([0,0,0,255,0,0,0,255,0,0,0,255,0,0,0,255]),h=e.createTexture();d=o?[e.TEXTURE_CUBE_MAP_POSITIVE_Z,e.TEXTURE_CUBE_MAP_NEGATIVE_Z,e.TEXTURE_CUBE_MAP_POSITIVE_Y,e.TEXTURE_CUBE_MAP_NEGATIVE_Y,e.TEXTURE_CUBE_MAP_POSITIVE_X,e.TEXTURE_CUBE_MAP_NEGATIVE_X]:[e.TEXTURE_CUBE_MAP_NEGATIVE_Z,e.TEXTURE_CUBE_MAP_POSITIVE_Z,e.TEXTURE_CUBE_MAP_NEGATIVE_Y,e.TEXTURE_CUBE_MAP_POSITIVE_Y,e.TEXTURE_CUBE_MAP_NEGATIVE_X,e.TEXTURE_CUBE_MAP_POSITIVE_X],h.ready=!1,h.pendingTextureLoads=-1,h.textureCubeReady=!1;for(var f=0,u=0,c=0;c<d.length;c++)e.bindTexture(e.TEXTURE_CUBE_MAP,h),e.texImage2D(d[c],0,e.RGBA,2,2,0,e.RGBA,e.UNSIGNED_BYTE,l),e.bindTexture(e.TEXTURE_CUBE_MAP,null);if(1==i.length)t.incrementDownloads(),x3dom.Utils.tryDDSLoading(h,e,t,i[0],n,a).then((function(){t.decrementDownloads(),t.needRender=!0}),(function(){x3dom.debug.logError("[Utils|createTexture2D] Can't load Image: "+i),t.decrementDownloads()}));else if(6==i.length)for(c=0;c<d.length;c++){var _=d[c],m=new Image;switch(s.toLowerCase()){case"anonymous":m.crossOrigin="anonymous";break;case"use-credentials":m.crossOrigin="use-credentials";break;case"none":break;default:x3dom.Utils.forbiddenBySOP(i[c])&&(m.crossOrigin="anonymous")}h.pendingTextureLoads++,t.incrementDownloads(),m.onload=function(i,o,s,a){return function(){0==f&&0==u?(f=s.width,u=s.height):!r||f==s.width&&u==s.height||(x3dom.debug.logWarning("[Utils|createTextureCube] Rescaling CubeMap images, which are of different size!"),s=x3dom.Utils.rescaleImage(s,f,u)),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,a),e.bindTexture(e.TEXTURE_CUBE_MAP,i),e.texImage2D(o,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,s),e.bindTexture(e.TEXTURE_CUBE_MAP,null),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),i.pendingTextureLoads--,t.decrementDownloads(),i.pendingTextureLoads<0&&(i.width=f,i.height=u,i.textureCubeReady=!0,n&&(e.bindTexture(e.TEXTURE_CUBE_MAP,i),e.generateMipmap(e.TEXTURE_CUBE_MAP),e.bindTexture(e.TEXTURE_CUBE_MAP,null)),x3dom.debug.logInfo("[Utils|createTextureCube] Loading CubeMap finished..."),t.needRender=!0)}}(h,_,m,o),m.onerror=function(){t.decrementDownloads(),x3dom.debug.logError("[Utils|createTextureCube] Can't load CubeMap!")},m.src=i[c]}return h},x3dom.Utils.detectChannelCount=function(e,t){switch(t){case"image/jpeg":return x3dom.Utils.detectChannelCountJPG(e);case"image/png":return x3dom.Utils.detectChannelCountPNG(e);case"image/gif":return x3dom.Utils.detectChannelCountGIF(e)}},x3dom.Utils.detectChannelCountJPG=function(e){if(255==e[0]&&216==e[1])for(var t=2,i=new DataView(e.buffer,e.byteOffset,e.byteLength);t+4<e.byteLength;)if(255==e[t]){var o=e[t+1];if(255!=e[t+=2]){var s=i.getUint16(t);if(t+s>e.byteLength)return;if(s>=7&&(192==o||194==o))return e[t+7];t+=s}}else t+=1},x3dom.Utils.detectChannelCountPNG=function(e){if(!(e.byteLength<29)&&137==e[0]&&80==e[1]&&78==e[2]&&71==e[3]&&13==e[4]&&10==e[5]&&26==e[6]&&10==e[7]&&73==e[12]&&72==e[13]&&68==e[14]&&82==e[15])return 0==e[25]?1:2==e[25]?3:4==e[25]?2:6==e[25]?4:void 0},x3dom.Utils.detectChannelCountGIF=function(e){if(71==e[0]&&73==e[1]&&70==e[2]&&56==e[3]&&(55==e[4]||57==e[4])&&97==e[5]&&1&e[10]){for(var t=224&e[10],i=13;i<t;i+=3)if(e[i]!=e[i+1]||e[i]!=e[i+2]||e[i+1]!=e[i+2])return 3;return 1}},x3dom.Utils.initFBO=function(e,t,i,o,s,r,n){var a=e.createTexture();a.width=t,a.height=i,e.bindTexture(e.TEXTURE_2D,a),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,i,0,e.RGBA,o,null),s&&e.generateMipmap(e.TEXTURE_2D),e.bindTexture(e.TEXTURE_2D,null);var d,l=null;if(x3dom.caps.DRAW_BUFFERS&&void 0!==n)for(l=[a],d=1;d<n;d++)l[d]=e.createTexture(),l[d].width=t,l[d].height=i,e.bindTexture(e.TEXTURE_2D,l[d]),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,i,0,e.RGBA,o,null),s&&e.generateMipmap(e.TEXTURE_2D),e.bindTexture(e.TEXTURE_2D,null);var h=e.createFramebuffer(),f=null,u=null;if(r&&(null!==x3dom.caps.DEPTH_TEXTURE?(f=e.createTexture(),e.bindTexture(e.TEXTURE_2D,f),e.texImage2D(e.TEXTURE_2D,0,e.DEPTH_COMPONENT,t,i,0,e.DEPTH_COMPONENT,e.UNSIGNED_SHORT,null),s&&e.generateMipmap(e.TEXTURE_2D),e.bindTexture(e.TEXTURE_2D,null),f.width=t,f.height=i):(u=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,u),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_COMPONENT16,t,i),e.bindRenderbuffer(e.RENDERBUFFER,null))),e.bindFramebuffer(e.FRAMEBUFFER,h),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,a,0),x3dom.caps.DRAW_BUFFERS&&void 0!==n)for(d=1;d<n;d++)e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+d,e.TEXTURE_2D,l[d],0);r&&null!==x3dom.caps.DEPTH_TEXTURE?e.framebufferTexture2D(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.TEXTURE_2D,f,0):e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,u);var c=e.checkFramebufferStatus(e.FRAMEBUFFER);return c!=e.FRAMEBUFFER_COMPLETE&&x3dom.debug.logWarning("[Utils|InitFBO] FBO-Status: "+c),e.bindFramebuffer(e.FRAMEBUFFER,null),{fbo:h,dtex:f,rbo:u,tex:a,texTargets:l,width:t,height:i,type:o,mipMap:s}},x3dom.Utils.getFileName=function(e){return e.lastIndexOf("/")>-1?e.substr(e.lastIndexOf("/")+1):e.lastIndexOf("\\")>-1?e.substr(e.lastIndexOf("\\")+1):e},x3dom.Utils.isWebGL2Enabled=function(){var e=document.createElement("canvas");return!!(e.getContext("webgl2")||e.getContext("experimental-webgl2"))},x3dom.Utils.findTextureByName=function(e,t){for(var i=0;i<e.length;++i)if(t==e[i].samplerName)return e[i];return!1},x3dom.Utils.rescaleImage=function(e,t,i){var o=document.createElement("canvas");return o.width=t,o.height=i,o.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,o.width,o.height),o},x3dom.Utils.scaleImage=function(e){if(!x3dom.Utils.isPowerOfTwo(e.width)||!x3dom.Utils.isPowerOfTwo(e.height)){var t=document.createElement("canvas");t.width=x3dom.Utils.nextHighestPowerOfTwo(e.width),t.height=x3dom.Utils.nextHighestPowerOfTwo(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e},x3dom.Utils.isPowerOfTwo=function(e){return 0==(e&e-1)},x3dom.Utils.nextHighestPowerOfTwo=function(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1},x3dom.Utils.nextBestPowerOfTwo=function(e){var t=Math.log(e)/.693147180559945;return Math.pow(2,Math.round(t))},x3dom.Utils.getDataTypeSize=function(e){switch(e){case"Int8":case"Uint8":return 1;case"Int16":case"Uint16":return 2;case"Int32":case"Uint32":case"Float32":return 4;case"Float64":default:return 8}},x3dom.Utils.getOffsetMultiplier=function(e,t){switch(e){case t.UNSIGNED_SHORT:return 1;case t.UNSIGNED_INT:return 2;case t.UNSIGNED_BYTE:return.5;default:return 1}},x3dom.Utils.getByteAwareOffset=function(e,t,i){switch(t){case i.UNSIGNED_SHORT:return 2*e;case i.UNSIGNED_INT:return 4*e;case i.UNSIGNED_BYTE:return e;default:return 2*e}},x3dom.Utils.getVertexAttribType=function(e,t){var i=t.NONE;switch(e){case"Int8":i=t.BYTE;break;case"Uint8":i=t.UNSIGNED_BYTE;break;case"Int16":i=t.SHORT;break;case"Uint16":i=t.UNSIGNED_SHORT;break;case"Int32":i=t.INT;break;case"Uint32":i=t.UNSIGNED_INT;break;case"Float32":i=t.FLOAT;break;case"Float64":default:x3dom.debug.logError("Can't find this.gl data type for "+e+", getting FLOAT..."),i=t.FLOAT}return i},x3dom.Utils.getArrayBufferView=function(e,t){var i=null;switch(e){case"Int8":i=new Int8Array(t);break;case"Uint8":i=new Uint8Array(t);break;case"Int16":i=new Int16Array(t);break;case"Uint16":i=new Uint16Array(t);break;case"Int32":i=new Int32Array(t);break;case"Uint32":i=new Uint32Array(t);break;case"Float32":i=new Float32Array(t);break;case"Float64":i=new Float64Array(t);break;default:x3dom.debug.logError("Can't create typed array view of type "+e+", trying Float32..."),i=new Float32Array(t)}return i},x3dom.Utils.isUnsignedType=function(e){return"Uint8"==e||"Uint16"==e||"Uint16"==e||"Uint32"==e},x3dom.Utils.checkDirtyLighting=function(e){return e.getLights().length+e._scene.getNavigationInfo()._vf.headlight},x3dom.Utils.checkDirtyPhysicalEnvironmentLight=function(e,t){return!!t.PHYSICALENVLIGHT!=e.hasPhysicalEnvironmentLight()},x3dom.Utils.checkDirtyEnvironment=function(e,t){var i=e._scene.getEnvironment();return t.GAMMACORRECTION!=i._vf.gammaCorrectionDefault},x3dom.Utils.minFilterDic=function(e,t){switch(t.toUpperCase()){case"NEAREST":return e.NEAREST;case"LINEAR":return e.LINEAR;case"NEAREST_MIPMAP_NEAREST":return e.NEAREST_MIPMAP_NEAREST;case"NEAREST_MIPMAP_LINEAR":return e.NEAREST_MIPMAP_LINEAR;case"LINEAR_MIPMAP_NEAREST":return e.LINEAR_MIPMAP_NEAREST;case"LINEAR_MIPMAP_LINEAR":return e.LINEAR_MIPMAP_LINEAR;case"AVG_PIXEL":return e.LINEAR;case"AVG_PIXEL_AVG_MIPMAP":return e.LINEAR_MIPMAP_LINEAR;case"AVG_PIXEL_NEAREST_MIPMAP":return e.LINEAR_MIPMAP_NEAREST;case"DEFAULT":return e.LINEAR_MIPMAP_LINEAR;case"FASTEST":case"NEAREST_PIXEL":return e.NEAREST;case"NEAREST_PIXEL_AVG_MIPMAP":return e.NEAREST_MIPMAP_LINEAR;case"NEAREST_PIXEL_NEAREST_MIPMAP":return e.NEAREST_MIPMAP_NEAREST;case"NICEST":return e.LINEAR_MIPMAP_LINEAR;default:return e.LINEAR}},x3dom.Utils.minFilterDicX3D=function(e){switch(e){case 9728:return"NEAREST";case 9729:return"LINEAR";case 9984:return"NEAREST_MIPMAP_NEAREST";case 9985:return"LINEAR_MIPMAP_NEAREST";case 9986:return"NEAREST_MIPMAP_LINEAR";case 9987:default:return"LINEAR_MIPMAP_LINEAR"}},x3dom.Utils.magFilterDic=function(e,t){switch(t.toUpperCase()){case"NEAREST":return e.NEAREST;case"LINEAR":case"AVG_PIXEL":case"DEFAULT":return e.LINEAR;case"FASTEST":case"NEAREST_PIXEL":return e.NEAREST;case"NICEST":default:return e.LINEAR}},x3dom.Utils.magFilterDicX3D=function(e){switch(e){case 9728:return"NEAREST";case 9729:default:return"LINEAR"}},x3dom.Utils.boundaryModesDicX3D=function(e){switch(e){case 10497:return"REPEAT";case 33071:return"CLAMP_TO_EDGE";case 33648:return"MIRRORED_REPEAT";default:return"REPEAT"}},x3dom.Utils.boundaryModesDic=function(e,t){switch(t.toUpperCase()){case"CLAMP":case"CLAMP_TO_EDGE":case"CLAMP_TO_BOUNDARY":return e.CLAMP_TO_EDGE;case"MIRRORED_REPEAT":return e.MIRRORED_REPEAT;case"REPEAT":default:return e.REPEAT}},x3dom.Utils.primTypeDic=function(e,t){switch(t.toUpperCase()){case"POINTS":return e.POINTS;case"LINES":return e.LINES;case"LINELOOP":return e.LINE_LOOP;case"LINESTRIP":return e.LINE_STRIP;case"TRIANGLES":return e.TRIANGLES;case"TRIANGLESTRIP":return e.TRIANGLE_STRIP;case"TRIANGLEFAN":return e.TRIANGLE_FAN;default:return e.TRIANGLES}},x3dom.Utils.depthFunc=function(e,t){switch(t.toUpperCase()){case"NEVER":return e.NEVER;case"ALWAYS":return e.ALWAYS;case"LESS":return e.LESS;case"EQUAL":return e.EQUAL;case"LEQUAL":return e.LEQUAL;case"GREATER":return e.GREATER;case"GEQUAL":return e.GEQUAL;case"NOTEQUAL":return e.NOTEQUAL;default:return e.LEQUAL}},x3dom.Utils.blendFunc=function(e,t){switch(t.toLowerCase()){case"zero":return e.ZERO;case"one":return e.ONE;case"dst_color":return e.DST_COLOR;case"dst_alpha":return e.DST_ALPHA;case"src_color":return e.SRC_COLOR;case"src_alpha":return e.SRC_ALPHA;case"one_minus_dst_color":return e.ONE_MINUS_DST_COLOR;case"one_minus_dst_alpha":return e.ONE_MINUS_DST_ALPHA;case"one_minus_src_color":return e.ONE_MINUS_SRC_COLOR;case"one_minus_src_alpha":return e.ONE_MINUS_SRC_ALPHA;case"src_alpha_saturate":return e.SRC_ALPHA_SATURATE;case"constant_color":return e.CONSTANT_COLOR;case"constant_alpha":return e.CONSTANT_ALPHA;case"one_minus_constant_color":return e.ONE_MINUS_CONSTANT_COLOR;case"one_minus_constant_alpha":return e.ONE_MINUS_CONSTANT_ALPHA;default:return 0}},x3dom.Utils.blendEquation=function(e,t){switch(t.toLowerCase()){case"func_add":return e.FUNC_ADD;case"func_subtract":return e.FUNC_SUBTRACT;case"func_reverse_subtract":return e.FUNC_REVERSE_SUBTRACT;case"min":case"max":case"logic_op":default:return 0}},x3dom.Utils.generateProperties=function(e,t){var i={},o=t._cf.geometry.node,s=t._cf.appearance.node,r=s?s._cf.texture.node:null,n=s?s._cf.material.node:null,a=e._scene.getEnvironment();return s&&s._shader&&x3dom.isa(s._shader,x3dom.nodeTypes.ComposedShader)?i.CSHADER=s._shader._id:o&&(i.CSHADER=-1,i.APPMAT=s&&(n||i.CSSHADER)?1:0,i.SOLID=t.isSolid()?1:0,i.TEXT=x3dom.isa(o,x3dom.nodeTypes.Text)?1:0,i.POPGEOMETRY=x3dom.isa(o,x3dom.nodeTypes.PopGeometry)?1:0,i.BUFFERGEOMETRY=x3dom.isa(o,x3dom.nodeTypes.BufferGeometry)?1:0,i.BINARYGEOMETRY=x3dom.isa(o,x3dom.nodeTypes.BinaryGeometry)?1:0,i.POINTLINE2D=o.needLighting()?0:1,i.VERTEXID=i.BINARYGEOMETRY&&o._vf.idsPerVertex?1:0,i.IS_PARTICLE=x3dom.isa(o,x3dom.nodeTypes.ParticleSet)?1:0,i.POINTPROPERTIES=s&&s._cf.pointProperties.node?1:0,i.TANGENTDATA=o._mesh._tangents[0].length>0&&o._mesh._binormals[0].length>0?1:0,i.PBR_MATERIAL=i.APPMAT&&x3dom.isa(n,x3dom.nodeTypes.PhysicalMaterial)?1:0,i.TWOSIDEDMAT=i.APPMAT&&x3dom.isa(n,x3dom.nodeTypes.TwoSidedMaterial)?1:0,i.SEPARATEBACKMAT=i.TWOSIDEDMAT&&n._vf.separateBackColor?1:0,i.SHADOW=e.getLightsShadow()?1:0,i.FOG=e._scene.getFog()._vf.visibilityRange>0?1:0,i.CSSHADER=s&&s._shader&&x3dom.isa(s._shader,x3dom.nodeTypes.CommonSurfaceShader)?1:0,i.LIGHTS=!i.POINTLINE2D&&s&&t.isLit()&&(n||i.CSSHADER)?e.getLights().length+e._scene.getNavigationInfo()._vf.headlight:0,i.TEXTURED=r||i.TEXT||i.CSSHADER&&s._shader.needTexcoords()||i.PBR_MATERIAL&&n.hasTextures()?1:0,i.CUBEMAP=r&&x3dom.isa(r,x3dom.nodeTypes.X3DEnvironmentTextureNode)||i.CSSHADER&&s._shader.getEnvironmentMap()?1:0,i.PIXELTEX=r&&x3dom.isa(r,x3dom.nodeTypes.PixelTexture)?1:0,i.TEXTRAFO=s&&s._cf.textureTransform.node?1:0,i.DIFFUSEMAP=r&&!x3dom.isa(r,x3dom.nodeTypes.X3DEnvironmentTextureNode)||i.CSSHADER&&s._shader.getDiffuseMap()||i.PBR_MATERIAL&&n._cf.baseColorTexture.node?1:0,i.NORMALMAP=i.CSSHADER&&s._shader.getNormalMap()||i.PBR_MATERIAL&&n._cf.normalTexture.node?1:0,i.SPECMAP=i.CSSHADER&&s._shader.getSpecularMap()?1:0,i.SHINMAP=i.CSSHADER&&s._shader.getShininessMap()?1:0,i.EMISSIVEMAP=i.PBR_MATERIAL&&n._cf.emissiveTexture.node?1:0,i.OCCLUSIONMAP=i.PBR_MATERIAL&&n._cf.occlusionTexture.node?1:0,i.DISPLACEMENTMAP=i.CSSHADER&&s._shader.getDisplacementMap()?1:0,i.DIFFPLACEMENTMAP=i.CSSHADER&&s._shader.getDiffuseDisplacementMap()?1:0,i.ALPHAMODE=i.PBR_MATERIAL?n._vf.alphaMode:"BLEND",i.ISROUGHNESSMETALLIC=i.PBR_MATERIAL&&"roughnessMetallic"==n._vf.model?1:0,i.ROUGHNESSMETALLICMAP=i.PBR_MATERIAL&&n._cf.roughnessMetallicTexture.node?1:0,i.SPECULARGLOSSINESSMAP=i.PBR_MATERIAL&&n._cf.specularGlossinessTexture.node?1:0,i.OCCLUSIONROUGHNESSMETALLICMAP=i.PBR_MATERIAL&&n._cf.occlusionRoughnessMetallicTexture.node?1:0,i.PHYSICALENVLIGHT=e.hasPhysicalEnvironmentLight()?1:0,i.NORMALSPACE=i.NORMALMAP&&i.CSSHADER?s._shader._vf.normalSpace.toUpperCase():i.NORMALMAP&&i.PBR_MATERIAL?n._vf.normalSpace.toUpperCase():"TANGENT",i.BLENDING=i.TEXT||i.CUBEMAP||i.CSSHADER||i.PBR_MATERIAL||r&&r._blending?1:0,i.REQUIREBBOX=void 0!==o._vf.coordType&&"Float32"!=o._vf.coordType?1:0,i.REQUIREBBOXNOR=void 0!==o._vf.normalType&&"Float32"!=o._vf.normalType?1:0,i.REQUIREBBOXCOL=void 0!==o._vf.colorType&&"Float32"!=o._vf.colorType?1:0,i.REQUIREBBOXTEX=void 0!==o._vf.texCoordType&&"Float32"!=o._vf.texCoordType?1:0,i.COLCOMPONENTS=o._mesh._numColComponents,i.NORCOMPONENTS=o._mesh._numNormComponents,i.POSCOMPONENTS=o._mesh._numPosComponents,i.SPHEREMAPPING=void 0!==o._cf.texCoord&&null!==o._cf.texCoord.node&&o._cf.texCoord.node._vf.mode&&"sphere"==o._cf.texCoord.node._vf.mode.toLowerCase()?1:0,i.VERTEXCOLOR=o._mesh._colors[0].length>0||i.POPGEOMETRY&&o.hasColor()||i.BUFFERGEOMETRY&&o.hasColor()||void 0!==o._vf.color&&o._vf.color.length>0?1:0,i.CLIPPLANES=t._clipPlanes.length,i.ALPHATHRESHOLD=s?s._vf.alphaClipThreshold.toFixed(2):.1,i.MULTITEXCOORD=i.BUFFERGEOMETRY&&o.hasMultiTexCoord()?1:0,i.DIFFUSEMAPCHANNEL=i.PBR_MATERIAL&&i.DIFFUSEMAP&&1===n._cf.baseColorTexture.node._vf.channel?1:0,i.NORMALMAPCHANNEL=i.PBR_MATERIAL&&i.NORMALMAP&&1===n._cf.normalTexture.node._vf.channel?1:0,i.EMISSIVEMAPCHANNEL=i.PBR_MATERIAL&&i.EMISSIVEMAP&&1===n._cf.emissiveTexture.node._vf.channel?1:0,i.OCCLUSIONMAPCHANNEL=i.PBR_MATERIAL&&i.OCCLUSIONMAP&&1===n._cf.occlusionTexture.node._vf.channel?1:0,i.ROUGHNESSMETALLICMAPCHANNEL=i.PBR_MATERIAL&&i.ROUGHNESSMETALLICMAP&&1===n._cf.roughnessMetallicTexture.node._vf.channel?1:0,i.OCCLUSIONROUGHNESSMETALLICMAPCHANNEL=i.PBR_MATERIAL&&i.OCCLUSIONROUGHNESSMETALLICMAP&&1===n._cf.occlusionRoughnessMetallicTexture.node._vf.channel?1:0,i.SPECULARGLOSSINESSMAPCHANNEL=i.PBR_MATERIAL&&i.SPECULARGLOSSINESSMAP&&1===n._cf.specularGlossinessTexture.node._vf.channel?1:0,i.ALPHAMASK=i.PBR_MATERIAL&&"MASK"==n._vf.alphaMode?1:0,i.UNLIT=i.PBR_MATERIAL&&n._vf.unlit?1:0,i.GAMMACORRECTION=a._vf.gammaCorrectionDefault,i.KHR_MATERIAL_COMMONS=0),i.toIdentifier=function(){delete this.id;var e="";for(var t in this)this[t]!=this.toIdentifier&&this[t]!=this.toString&&(e+=this[t]);return this.id=e,e},i.toString=function(){var e="";for(var t in this)this[t]!=this.toIdentifier&&this[t]!=this.toString&&(e+=t+": "+this[t]+", ");return e},i.toIdentifier(),i},x3dom.Utils.lerp=function(e,t,i){return e+(t-e)*(i=(i=i<0?0:i)>1?1:i)},x3dom.Utils.wrapProgram=function(e,t,i){var o,s,r={shaderID:i,program:t,bind:function(){e.useProgram(t)}},n=null,a=null,d=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(o=0;o<d;++o){try{a=e.getActiveUniform(t,o)}catch(e){if(!a)continue}switch((s=e.getError())&&x3dom.debug.logError("GL-Error (on searching uniforms): name="+a.name+" type="+a.type+" size="+a.size+" Err="+s),n=e.getUniformLocation(t,a.name),a.type){case e.SAMPLER_2D:case e.SAMPLER_CUBE:case e.BOOL:r.__defineSetter__(a.name,function(t){return function(i){e.uniform1i(t,i)}}(n));break;case e.FLOAT:-1!=a.name.indexOf("[0]")?r.__defineSetter__(a.name.substring(0,a.name.length-3),function(t){return function(i){e.uniform1fv(t,new Float32Array(i))}}(n)):r.__defineSetter__(a.name,function(t){return function(i){e.uniform1f(t,i)}}(n));break;case e.FLOAT_VEC2:r.__defineSetter__(a.name,function(t){return function(i){e.uniform2f(t,i[0],i[1])}}(n));break;case e.FLOAT_VEC3:-1!=a.name.indexOf("[0]")?r.__defineSetter__(a.name.substring(0,a.name.length-3),function(t){return function(i){e.uniform3fv(t,new Float32Array(i))}}(n)):r.__defineSetter__(a.name,function(t){return function(i){e.uniform3f(t,i[0],i[1],i[2])}}(n));break;case e.FLOAT_VEC4:r.__defineSetter__(a.name,function(t){return function(i){e.uniform4f(t,i[0],i[1],i[2],i[3])}}(n));break;case e.FLOAT_MAT2:r.__defineSetter__(a.name,function(t){return function(i){e.uniformMatrix2fv(t,!1,new Float32Array(i))}}(n));break;case e.FLOAT_MAT3:r.__defineSetter__(a.name,function(t){return function(i){e.uniformMatrix3fv(t,!1,new Float32Array(i))}}(n));break;case e.FLOAT_MAT4:r.__defineSetter__(a.name,function(t){return function(i){e.uniformMatrix4fv(t,!1,new Float32Array(i))}}(n));break;case e.INT:r.__defineSetter__(a.name,function(t){return function(i){e.uniform1i(t,i)}}(n));break;default:x3dom.debug.logWarning("GLSL program variable "+a.name+" has unknown type "+a.type)}}var l=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(o=0;o<l;++o){try{a=e.getActiveAttrib(t,o)}catch(e){if(!a)continue}(s=e.getError())&&x3dom.debug.logError("GL-Error (on searching attributes): name="+a.name+" type="+a.type+" size="+a.size+" Err="+s),n=e.getAttribLocation(t,a.name),r[a.name]=n}return r},x3dom.Utils.arrayBufferToJSON=function(e,t,i){var o,s,r,n,a,d;for(t=null!=t?t:0,o="",r=i=null!=i?i:e.length,s=t;s<r;)switch((n=e[s++])>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:o+=String.fromCharCode(n);break;case 12:case 13:a=e[s++],o+=String.fromCharCode((31&n)<<6|63&a);break;case 14:a=e[s++],d=e[s++],o+=String.fromCharCode((15&n)<<12|(63&a)<<6|(63&d)<<0)}return JSON.parse(o)},x3dom.Utils.arrayBufferToObjectURL=function(e,t){return URL.createObjectURL(new Blob([new Uint8Array(e)],{type:t}))},x3dom.Utils.dataURIToObjectURL=function(e){if(-1==e.indexOf("data:"))return e;for(var t=e.split(","),i=t[0].split(":")[1].split(";")[0],o=t[1],s=window.atob(o),r=s.length,n=new Uint8Array(r),a=0;a<r;a++)n[a]=s.charCodeAt(a);return URL.createObjectURL(new Blob([n],{type:i}))},x3dom.Utils.arrayBufferToDataURL=function(e,t){for(var i="",o=new Uint8Array(e),s=0;s<o.byteLength;s++)i+=String.fromCharCode(o[s]);return"data:"+t+";base64,"+window.btoa(i)},x3dom.Utils.forbiddenBySOP=function(e){var t,i,o,s,r,n=(e=e.toLowerCase()).split("//"),a=""===document.location.port?"80":document.location.port;return 2===n.length&&(t=n[0],r=(o=(1===(i=n[1].split("/")[0].split("?")[0].split("#")[0].split("@")).length?i[0]:i[1]).split(":"))[0],s=o[1]),s=s||a,r=r||document.location.host,t=t||document.location.protocol,!(s===a&&r===document.location.host&&t===document.location.protocol)},x3dom.States=function(e){var t=this;this.active=!1,this.viewer=document.createElement("div"),this.viewer.id="x3dom-state-viewer";var i=document.createElement("div");i.className="x3dom-states-head",i.appendChild(document.createTextNode("x3dom"));var o=document.createElement("span");o.className="x3dom-states-head2",o.appendChild(document.createTextNode("stats")),i.appendChild(o),this.renderMode=document.createElement("div"),this.renderMode.className="x3dom-states-rendermode-hardware",this.measureList=document.createElement("ul"),this.measureList.className="x3dom-states-list",this.infoList=document.createElement("ul"),this.infoList.className="x3dom-states-list",this.requestList=document.createElement("ul"),this.requestList.className="x3dom-states-list",this.viewer.appendChild(this.renderMode),this.viewer.appendChild(this.measureList),this.viewer.appendChild(this.infoList),this.viewer.appendChild(this.requestList),this.disableContextMenu=function(e){return e.preventDefault(),e.stopPropagation(),e.returnValue=!1,!1},this.thousandSeperator=function(e){return e.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")},this.toFixed=function(e){return e.toFixed(2)},this.addItem=function(e,t,i){var o=document.createElement("li");o.className="x3dom-states-item";var s=document.createElement("div");s.className="x3dom-states-item-title",s.appendChild(document.createTextNode(t));var r=document.createElement("div");r.className="x3dom-states-item-value",r.appendChild(document.createTextNode(i)),o.appendChild(s),o.appendChild(r),e.appendChild(o)},this.update=function(){if(e.runtime||void 0===this.updateMethodID){var t=e.runtime.states.infos,i=e.runtime.states.measurements,o=x3dom.caps.RENDERMODE;for(var s in"HARDWARE"==o?(this.renderMode.innerHTML="Hardware-Rendering",this.renderMode.className="x3dom-states-rendermode-hardware"):"SOFTWARE"==o&&(this.renderMode.innerHTML="Software-Rendering",this.renderMode.className="x3dom-states-rendermode-software"),this.measureList.innerHTML="",i)i.hasOwnProperty(s)&&this.addItem(this.measureList,s,this.toFixed(i[s]));for(var r in this.infoList.innerHTML="",t)t.hasOwnProperty(r)&&this.addItem(this.infoList,r,this.thousandSeperator(t[r]));this.requestList.innerHTML="",this.addItem(this.requestList,"#ACTIVE",x3dom.RequestManager.activeRequests.length),this.addItem(this.requestList,"#TOTAL",x3dom.RequestManager.totalRequests),this.addItem(this.requestList,"#LOADED",x3dom.RequestManager.loadedRequests),this.addItem(this.requestList,"#FAILED",x3dom.RequestManager.failedRequests)}else clearInterval(this.updateMethodID)},this.updateMethodID=window.setInterval((function(){t.update()}),1e3),this.viewer.addEventListener("contextmenu",t.disableContextMenu)},x3dom.States.prototype.display=function(e){this.active=void 0!==e?e:!this.active,this.viewer.style.display=this.active?"block":"none"},x3dom.StateManager=function(e){this.gl=e,this.states=[],this.initStates()},x3dom.StateManager.prototype.initStates=function(){this.states.shaderID=null,this.states.colorMask={red:null,green:null,blue:null,alpha:null},this.states.depthMask=null,this.states.stencilMask=null,this.states.cullFace=null,this.states.frontFace=null,this.states.lineWidth=null,this.states.blendColor={red:null,green:null,blue:null,alpha:null},this.states.blendEquation=null,this.states.blendEquationSeparate={modeRGB:null,modeAlpha:null},this.states.blendFunc={sfactor:null,dfactor:null},this.states.blendFuncSeparate={srcRGB:null,dstRGB:null,srcAlpha:null,dstAlpha:null},this.states.depthFunc=null,this.states.viewport={x:null,y:null,width:null,height:null},this.states.depthRange={zNear:null,zFar:null}},x3dom.StateManager.prototype.useProgram=function(e){return this.states.shaderID!=e.shaderID&&(this.gl.useProgram(e.program),this.states.shaderID=e.shaderID,!0)},x3dom.StateManager.prototype.unsetProgram=function(){this.states.shaderID=null},x3dom.StateManager.prototype.enable=function(e){!0!==this.states[e]&&(this.gl.enable(e),this.states[e]=!0)},x3dom.StateManager.prototype.disable=function(e){!1!==this.states[e]&&(this.gl.disable(e),this.states[e]=!1)},x3dom.StateManager.prototype.colorMask=function(e,t,i,o){this.states.colorMask.red==e&&this.states.colorMask.green==t&&this.states.colorMask.blue==i&&this.states.colorMask.alpha==o||(this.gl.colorMask(e,t,i,o),this.states.colorMask.red=e,this.states.colorMask.green=t,this.states.colorMask.blue=i,this.states.colorMask.alpha=o)},x3dom.StateManager.prototype.depthMask=function(e){this.states.depthMask!=e&&(this.gl.depthMask(e),this.states.depthMask=e)},x3dom.StateManager.prototype.stencilMask=function(e){this.states.stencilMask!=e&&(this.gl.stencilMask(e),this.states.stencilMask=e)},x3dom.StateManager.prototype.cullFace=function(e){this.states.cullFace!=e&&(this.gl.cullFace(e),this.states.cullFace=e)},x3dom.StateManager.prototype.frontFace=function(e){this.states.frontFace!=e&&(this.gl.frontFace(e),this.states.frontFace=e)},x3dom.StateManager.prototype.lineWidth=function(e){e=e<=1?1:e,this.states.lineWidth!=e&&(this.gl.lineWidth(e),this.states.lineWidth=e)},x3dom.StateManager.prototype.blendColor=function(e,t,i,o){this.states.blendColor.red==e&&this.states.blendColor.green==t&&this.states.blendColor.blue==i&&this.states.blendColor.alpha==o||(this.gl.blendColor(e,t,i,o),this.states.blendColor.red=e,this.states.blendColor.green=t,this.states.blendColor.blue=i,this.states.blendColor.alpha=o)},x3dom.StateManager.prototype.blendEquation=function(e){e&&this.states.blendEquation!=e&&(this.gl.blendEquation(e),this.states.blendEquation=e)},x3dom.StateManager.prototype.blendEquationSeparate=function(e,t){this.states.blendEquationSeparate.modeRGB==e&&this.states.blendEquationSeparate.modeAlpha==t||(this.gl.blendEquationSeparate(e,t),this.states.blendEquationSeparate.modeRGB=e,this.states.blendEquationSeparate.modeAlpha=t)},x3dom.StateManager.prototype.blendFunc=function(e,t){this.states.blendFunc.sfactor==e&&this.states.blendFunc.dfactor==t||(this.gl.blendFunc(e,t),this.states.blendFunc.sfactor=e,this.states.blendFunc.dfactor=t)},x3dom.StateManager.prototype.blendFuncSeparate=function(e,t,i,o){this.states.blendFuncSeparate.srcRGB==e&&this.states.blendFuncSeparate.dstRGB==t&&this.states.blendFuncSeparate.srcAlpha==i&&this.states.blendFuncSeparate.dstAlpha==o||(this.gl.blendFuncSeparate(e,t,i,o),this.states.blendFuncSeparate.srcRGB=e,this.states.blendFuncSeparate.dstRGB=t,this.states.blendFuncSeparate.srcAlpha=i,this.states.blendFuncSeparate.dstAlpha=o)},x3dom.StateManager.prototype.depthFunc=function(e){this.states.depthFunc!=e&&(this.gl.depthFunc(e),this.states.depthFunc=e)},x3dom.StateManager.prototype.depthRange=function(e,t){e<0||t<0||e>t||(e=e>1?1:e,t=t>1?1:t,this.states.depthRange.zNear==e&&this.states.depthRange.zFar==t||(this.gl.depthRange(e,t),this.states.depthRange.zNear=e,this.states.depthRange.zFar=t))},x3dom.StateManager.prototype.viewport=function(e,t,i,o){this.states.viewport.x==e&&this.states.viewport.y==t&&this.states.viewport.width==i&&this.states.viewport.height==o||(this.gl.viewport(e,t,i,o),this.states.viewport.x=e,this.states.viewport.y=t,this.states.viewport.width=i,this.states.viewport.height=o)},x3dom.StateManager.prototype.bindFramebuffer=function(e,t){this.gl.bindFramebuffer(e,t),this.initStates()},x3dom.BinaryContainerLoader={outOfMemory:!1,checkError:function(e){var t=e.getError();t&&(t==e.OUT_OF_MEMORY?(this.outOfMemory=!0,x3dom.debug.logError("GL-Error "+t+" on loading binary container (out of memory)."),console.error("WebGL: OUT_OF_MEMORY")):x3dom.debug.logError("GL-Error "+t+" on loading binary container."))}},x3dom.BinaryContainerLoader.setupBinGeo=function(e,t,i,o,s){if(!this.outOfMemory){var r=(new Date).getTime(),n=this,a=e._cf.geometry.node;e._webgl.binaryGeometry=-1,e._webgl.internalDownloadCount=(a._vf.index.length>0?1:0)+(a._hasStrideOffset&&a._vf.coord.length>0?1:0)+(!a._hasStrideOffset&&a._vf.coord.length>0?1:0)+(!a._hasStrideOffset&&a._vf.normal.length>0?1:0)+(!a._hasStrideOffset&&a._vf.texCoord.length>0?1:0)+(!a._hasStrideOffset&&a._vf.color.length>0?1:0);var d=0==a._vf.normalPerVertex||a._vf.index.length>0&&("Int32"==a._vf.indexType||"Uint32"==a._vf.indexType&&!x3dom.caps.INDEX_UINT);if(e._webgl.makeSeparateTris={index:null,coord:null,normal:null,texCoord:null,color:null,pushBuffer:function(t,i){this[t]=i,0==--e._webgl.internalDownloadCount&&(this.coord&&this.createMesh(),e._nameSpace.doc.needRender=!0),0==--e._nameSpace.doc.downloadCount&&(e._nameSpace.doc.needRender=!0)},createMesh:function(){var r=a;if(r._hasStrideOffset)x3dom.debug.logError(r._vf.indexType+" index type and per-face normals not supported for interleaved arrays.");else{for(var d=0;d<e._webgl.primType.length;d++)if(e._webgl.primType[d]==i.TRIANGLE_STRIP)return void x3dom.debug.logError("makeSeparateTris: triangle strips not yet supported for per-face normals.");var l,h,f=r._vf.coordType;e._webgl.coordType=x3dom.Utils.getVertexAttribType(f,i),e._webgl.coordType!=i.FLOAT?(4==r._mesh._numPosComponents&&x3dom.Utils.isUnsignedType(r._vf.coordType)?x3dom.fields.SFVec3f.copy(r.getMin()):x3dom.fields.SFVec3f.copy(r._vf.position),l=x3dom.fields.SFVec3f.copy(r._vf.size),h=r.getPrecisionMax("coordType")):(new x3dom.fields.SFVec3f(0,0,0),l=new x3dom.fields.SFVec3f(1,1,1),h=1);var u=e._coordStrideOffset[0]/x3dom.Utils.getDataTypeSize(r._vf.coordType);u=0==u?3:u,x3dom.debug.logWarning("makeSeparateTris.createMesh called with coord length "+u),this.color&&u!=e._colorStrideOffset[0]/x3dom.Utils.getDataTypeSize(r._vf.colorType)&&(this.color=null,x3dom.debug.logWarning("Color format not supported."));var c=this.texCoord?e._texCoordStrideOffset[0]/x3dom.Utils.getDataTypeSize(r._vf.texCoordType):0;r._vf.normalType="Float32",e._webgl.normalType=i.FLOAT,r._mesh._numNormComponents=3,e._normalStrideOffset=[0,0];var _,m,p,x=[],g=[],v=[],y=[],T=this.index?this.index.length-2:this.coord.length/3-2;for(_=0;_<T;_+=3){m=u*(this.index?this.index[_]:_);var b=new x3dom.fields.SFVec3f(l.x*this.coord[m]/h,l.y*this.coord[m+1]/h,l.z*this.coord[m+2]/h);x.push(this.coord[m]),x.push(this.coord[m+1]),x.push(this.coord[m+2]),u>3&&x.push(this.coord[m+3]),this.color&&(y.push(this.color[m]),y.push(this.color[m+1]),y.push(this.color[m+2]),u>3&&y.push(this.color[m+3])),this.texCoord&&(p=c*(this.index?this.index[_]:_),v.push(this.texCoord[p]),v.push(this.texCoord[p+1]),c>3&&(v.push(this.texCoord[p+2]),v.push(this.texCoord[p+3]))),m=u*(this.index?this.index[_+1]:_+1);var S=new x3dom.fields.SFVec3f(l.x*this.coord[m]/h,l.y*this.coord[m+1]/h,l.z*this.coord[m+2]/h);x.push(this.coord[m]),x.push(this.coord[m+1]),x.push(this.coord[m+2]),u>3&&x.push(this.coord[m+3]),this.color&&(y.push(this.color[m]),y.push(this.color[m+1]),y.push(this.color[m+2]),u>3&&y.push(this.color[m+3])),this.texCoord&&(p=c*(this.index?this.index[_+1]:_+1),v.push(this.texCoord[p]),v.push(this.texCoord[p+1]),c>3&&(v.push(this.texCoord[p+2]),v.push(this.texCoord[p+3]))),m=u*(this.index?this.index[_+2]:_+2);var F=new x3dom.fields.SFVec3f(l.x*this.coord[m]/h,l.y*this.coord[m+1]/h,l.z*this.coord[m+2]/h);x.push(this.coord[m]),x.push(this.coord[m+1]),x.push(this.coord[m+2]),u>3&&x.push(this.coord[m+3]),this.color&&(y.push(this.color[m]),y.push(this.color[m+1]),y.push(this.color[m+2]),u>3&&y.push(this.color[m+3])),this.texCoord&&(p=c*(this.index?this.index[_+2]:_+2),v.push(this.texCoord[p]),v.push(this.texCoord[p+1]),c>3&&(v.push(this.texCoord[p+2]),v.push(this.texCoord[p+3])));var E=b.subtract(S),M=S.subtract(F),C=E.cross(M).normalize();for(m=0;m<3;m++)g.push(C.x),g.push(C.y),g.push(C.z)}var w=i.createBuffer();e._webgl.buffers[x3dom.BUFFER_IDX.POSITION]=w,i.bindBuffer(i.ARRAY_BUFFER,w),i.bufferData(i.ARRAY_BUFFER,x3dom.Utils.getArrayBufferView(r._vf.coordType,x),i.STATIC_DRAW),i.vertexAttribPointer(t.position,r._mesh._numPosComponents,e._webgl.coordType,!1,e._coordStrideOffset[0],e._coordStrideOffset[1]),i.enableVertexAttribArray(t.position),w=i.createBuffer(),e._webgl.buffers[x3dom.BUFFER_IDX.NORMAL]=w,i.bindBuffer(i.ARRAY_BUFFER,w),i.bufferData(i.ARRAY_BUFFER,new Float32Array(g),i.STATIC_DRAW),i.vertexAttribPointer(t.normal,r._mesh._numNormComponents,e._webgl.normalType,!1,e._normalStrideOffset[0],e._normalStrideOffset[1]),i.enableVertexAttribArray(t.normal),this.texCoord&&(w=i.createBuffer(),e._webgl.buffers[x3dom.BUFFER_IDX.TEXCOORD]=w,i.bindBuffer(i.ARRAY_BUFFER,w),i.bufferData(i.ARRAY_BUFFER,x3dom.Utils.getArrayBufferView(r._vf.texCoordType,v),i.STATIC_DRAW),i.vertexAttribPointer(t.texcoord,r._mesh._numTexComponents,e._webgl.texCoordType,!1,e._texCoordStrideOffset[0],e._texCoordStrideOffset[1]),i.enableVertexAttribArray(t.texcoord)),this.color&&(w=i.createBuffer(),e._webgl.buffers[x3dom.BUFFER_IDX.COLOR]=w,i.bindBuffer(i.ARRAY_BUFFER,w),i.bufferData(i.ARRAY_BUFFER,x3dom.Utils.getArrayBufferView(r._vf.colorType,y),i.STATIC_DRAW),i.vertexAttribPointer(t.color,r._mesh._numColComponents,e._webgl.colorType,!1,e._colorStrideOffset[0],e._colorStrideOffset[1]),i.enableVertexAttribArray(t.color)),r._vf.vertexCount=[],r._vf.vertexCount[0]=x.length/u,r._mesh._numCoords=r._vf.vertexCount[0],r._mesh._numFaces=r._vf.vertexCount[0]/3,e._webgl.primType=[],e._webgl.primType[0]=i.TRIANGLES,x=null,g=null,v=null,y=null,this.index=null,this.coord=null,this.normal=null,this.texCoord=null,this.color=null,n.checkError(i),delete e._webgl.shader,e._webgl.shader=s.cache.getDynamicShader(i,o,e)}}},a._vf.index.length>0){e._webgl.binaryGeometry=1;var l=new XMLHttpRequest;l.open("GET",e._nameSpace.getURL(a._vf.index),!0),l.responseType="arraybuffer",e._nameSpace.doc.incrementDownloads(),x3dom.RequestManager.addRequest(l),l.onload=function(){if(e._nameSpace.doc.decrementDownloads(),e._webgl.internalDownloadCount-=1,200==l.status){if(e._webgl)if(a._vf.compressed)x3dom.debug.logError("x3dom 1.8.2+ do not support compressed BinaryGeometries anymore");else{var t=l.response,o=a,s=o._vf.indexType,h=x3dom.Utils.getArrayBufferView(s,t);if(d)e._webgl.makeSeparateTris.pushBuffer("index",h);else{var f=i.createBuffer();x3dom.caps.INDEX_UINT&&"Uint32"==s?e._webgl.indexType=i.UNSIGNED_INT:e._webgl.indexType=i.UNSIGNED_SHORT,i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,f),i.bufferData(i.ELEMENT_ARRAY_BUFFER,h,i.STATIC_DRAW),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,null),0==o._vf.vertexCount[0]&&(o._vf.vertexCount[0]=h.length),o._mesh._numFaces=0;for(var u=0;u<o._vf.vertexCount.length;u++)e._webgl.primType[u]==i.TRIANGLE_STRIP?o._mesh._numFaces+=o._vf.vertexCount[u]-2:o._mesh._numFaces+=o._vf.vertexCount[u]/3;h=null,0==e._webgl.internalDownloadCount&&(e._nameSpace.doc.needRender=!0),n.checkError(i);var c=(new Date).getTime()-r;x3dom.debug.logInfo("XHR0/ index load time: "+c+" ms"),e._webgl.buffers[x3dom.BUFFER_IDX.INDEX]=f}}}else x3dom.debug.logError("XHR1/ index load failed with status: "+l.status)}}if(a._hasStrideOffset&&a._vf.coord.length>0){var h=new XMLHttpRequest;h.open("GET",e._nameSpace.getURL(a._vf.coord),!0),h.responseType="arraybuffer",e._nameSpace.doc.incrementDownloads(),x3dom.RequestManager.addRequest(h),h.onload=function(){if(e._nameSpace.doc.decrementDownloads(),e._webgl.internalDownloadCount-=1,200==h.status){if(e._webgl)if(a._vf.compressed)x3dom.debug.logError("x3dom 1.8.2+ do not support compressed BinaryGeometries anymore");else{var o=h.response,s=a,d=s._vf.coordType;e._webgl.coordType=x3dom.Utils.getVertexAttribType(d,i),e._webgl.normalType=e._webgl.coordType,e._webgl.texCoordType=e._webgl.coordType,e._webgl.colorType=e._webgl.coordType;var l=x3dom.Utils.getArrayBufferView(d,o),f=e._coordStrideOffset[0]/x3dom.Utils.getDataTypeSize(d);if(f&&(s._mesh._numCoords=l.length/f),0==s._vf.index.length)for(var u=0;u<s._vf.vertexCount.length;u++)e._webgl.primType[u]==i.TRIANGLE_STRIP?s._mesh._numFaces+=s._vf.vertexCount[u]-2:s._mesh._numFaces+=s._vf.vertexCount[u]/3;var c=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,c),i.bufferData(i.ARRAY_BUFFER,l,i.STATIC_DRAW),i.vertexAttribPointer(t.position,s._mesh._numPosComponents,e._webgl.coordType,!1,e._coordStrideOffset[0],e._coordStrideOffset[1]),i.enableVertexAttribArray(t.position),s._vf.normal.length>0&&(e._webgl.buffers[x3dom.BUFFER_IDX.NORMAL]=c,i.bindBuffer(i.ARRAY_BUFFER,c),i.bufferData(i.ARRAY_BUFFER,l,i.STATIC_DRAW),i.vertexAttribPointer(t.normal,s._mesh._numNormComponents,e._webgl.normalType,!1,e._normalStrideOffset[0],e._normalStrideOffset[1]),i.enableVertexAttribArray(t.normal)),s._vf.texCoord.length>0&&(e._webgl.buffers[x3dom.BUFFER_IDX.TEXCOORD]=c,i.bindBuffer(i.ARRAY_BUFFER,c),i.bufferData(i.ARRAY_BUFFER,l,i.STATIC_DRAW),i.vertexAttribPointer(t.texcoord,s._mesh._numTexComponents,e._webgl.texCoordType,!1,e._texCoordStrideOffset[0],e._texCoordStrideOffset[1]),i.enableVertexAttribArray(t.texcoord)),s._vf.color.length>0&&(e._webgl.buffers[x3dom.BUFFER_IDX.COLOR]=c,i.bindBuffer(i.ARRAY_BUFFER,c),i.bufferData(i.ARRAY_BUFFER,l,i.STATIC_DRAW),i.vertexAttribPointer(t.color,s._mesh._numColComponents,e._webgl.colorType,!1,e._colorStrideOffset[0],e._colorStrideOffset[1]),i.enableVertexAttribArray(t.color)),l=null,0==e._webgl.internalDownloadCount&&(e._nameSpace.doc.needRender=!0),n.checkError(i);var _=(new Date).getTime()-r;x3dom.debug.logInfo("XHR/ interleaved array load time: "+_+" ms"),e._webgl.buffers[x3dom.BUFFER_IDX.POSITION]=c}}else x3dom.debug.logError("XHR1/ interleaved array load failed with status: "+h.status)}}if(!a._hasStrideOffset&&a._vf.coord.length>0){var f=new XMLHttpRequest;f.open("GET",e._nameSpace.getURL(a._vf.coord),!0),f.responseType="arraybuffer",e._nameSpace.doc.incrementDownloads(),x3dom.RequestManager.addRequest(f),f.onload=function(){if(e._nameSpace.doc.decrementDownloads(),e._webgl.internalDownloadCount-=1,200==f.status){if(e._webgl)if(a._vf.compressed)x3dom.debug.logError("x3dom 1.8.2+ do not support compressed BinaryGeometries anymore");else{var o=f.response,s=a,l=0,h=s._vf.coordType;e._webgl.coordType=x3dom.Utils.getVertexAttribType(h,i);var u=x3dom.Utils.getArrayBufferView(h,o);if(d)e._webgl.makeSeparateTris.pushBuffer("coord",u);else{i.bindAttribLocation(t.program,0,"position");var c=i.createBuffer();if(i.bindBuffer(i.ARRAY_BUFFER,c),i.bufferData(i.ARRAY_BUFFER,u,i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,null),s._mesh._numCoords=u.length/s._mesh._numPosComponents,0==s._vf.index.length)for(l=0;l<s._vf.vertexCount.length;l++)e._webgl.primType[l]==i.TRIANGLE_STRIP?s._mesh._numFaces+=s._vf.vertexCount[l]-2:s._mesh._numFaces+=s._vf.vertexCount[l]/3;if("Float32"==h&&(e._vf.bboxSize.x<0||e._vf.bboxSize.y<0||e._vf.bboxSize.z<0)){var _=new x3dom.fields.SFVec3f(u[0],u[1],u[2]),m=new x3dom.fields.SFVec3f(u[0],u[1],u[2]);for(l=3;l<u.length;l+=3)_.x>u[l+0]&&(_.x=u[l+0]),_.y>u[l+1]&&(_.y=u[l+1]),_.z>u[l+2]&&(_.z=u[l+2]),m.x<u[l+0]&&(m.x=u[l+0]),m.y<u[l+1]&&(m.y=u[l+1]),m.z<u[l+2]&&(m.z=u[l+2]);e._vf.bboxCenter.setValues(_.add(m).multiply(.5)),e._vf.bboxSize.setValues(m.subtract(_))}u=null,0==e._webgl.internalDownloadCount&&(e._nameSpace.doc.needRender=!0),n.checkError(i);var p=(new Date).getTime()-r;x3dom.debug.logInfo("XHR1/ coord load time: "+p+" ms"),e._webgl.buffers[x3dom.BUFFER_IDX.POSITION]=c}}}else x3dom.debug.logError("XHR1/ coord load failed with status: "+f.status)}}if(!a._hasStrideOffset&&a._vf.normal.length>0){var u=new XMLHttpRequest;u.open("GET",e._nameSpace.getURL(a._vf.normal),!0),u.responseType="arraybuffer",e._nameSpace.doc.incrementDownloads(),x3dom.RequestManager.addRequest(u),u.onload=function(){if(e._nameSpace.doc.decrementDownloads(),e._webgl.internalDownloadCount-=1,200==u.status){if(e._webgl)if(a._vf.compressed)x3dom.debug.logError("x3dom 1.8.2+ do not support compressed BinaryGeometries anymore");else{var t=u.response,o=a._vf.normalType;e._webgl.normalType=x3dom.Utils.getVertexAttribType(o,i);var s=x3dom.Utils.getArrayBufferView(o,t);if(d)e._webgl.makeSeparateTris.pushBuffer("normal",s);else{var l=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,l),i.bufferData(i.ARRAY_BUFFER,s,i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,null),s=null,0==e._webgl.internalDownloadCount&&(e._nameSpace.doc.needRender=!0),n.checkError(i);var h=(new Date).getTime()-r;x3dom.debug.logInfo("XHR2/ normal load time: "+h+" ms"),e._webgl.buffers[x3dom.BUFFER_IDX.NORMAL]=l}}}else x3dom.debug.logError("XHR2/ normal load failed with status: "+u.status)}}if(!a._hasStrideOffset&&a._vf.texCoord.length>0){var c=new XMLHttpRequest;c.open("GET",e._nameSpace.getURL(a._vf.texCoord),!0),c.responseType="arraybuffer",e._nameSpace.doc.incrementDownloads(),x3dom.RequestManager.addRequest(c),c.onload=function(){var t,o;if(e._nameSpace.doc.decrementDownloads(),e._webgl.internalDownloadCount-=1,200==c.status){if(e._webgl)if(a._vf.compressed)x3dom.debug.logError("x3dom 1.8.2+ do not support compressed BinaryGeometries anymore");else{var s=c.response,l=a._vf.texCoordType;e._webgl.texCoordType=x3dom.Utils.getVertexAttribType(l,i);var h=x3dom.Utils.getArrayBufferView(l,s);if(d)e._webgl.makeSeparateTris.pushBuffer("texCoord",h);else{if(a._vf.idsPerVertex){var f=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,f);var u=x3dom.Utils.getArrayBufferView("Float32",h.length/2);for(t=0,o=0;t<h.length;t+=2,o++)u[o]=65536*h[t+1]+h[t];i.bufferData(i.ARRAY_BUFFER,u,i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,null),e._webgl.buffers[x3dom.BUFFER_IDX.ID]=f}else{var _=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,_),i.bufferData(i.ARRAY_BUFFER,h,i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,null),e._webgl.buffers[x3dom.BUFFER_IDX.TEXCOORD]=_}h=null,0==e._webgl.internalDownloadCount&&(e._nameSpace.doc.needRender=!0),n.checkError(i);var m=(new Date).getTime()-r;x3dom.debug.logInfo("XHR3/ texCoord load time: "+m+" ms")}}}else x3dom.debug.logError("XHR3/ texcoord load failed with status: "+c.status)}}if(!a._hasStrideOffset&&a._vf.color.length>0){var _=new XMLHttpRequest;_.open("GET",e._nameSpace.getURL(a._vf.color),!0),_.responseType="arraybuffer",e._nameSpace.doc.incrementDownloads(),x3dom.RequestManager.addRequest(_),_.onload=function(){if(e._nameSpace.doc.decrementDownloads(),e._webgl.internalDownloadCount-=1,200==_.status){if(e._webgl)if(a._vf.compressed)x3dom.debug.logError("x3dom 1.8.2+ do not support compressed BinaryGeometries anymore");else{var t=_.response,o=a._vf.colorType;e._webgl.colorType=x3dom.Utils.getVertexAttribType(o,i);var s=x3dom.Utils.getArrayBufferView(o,t);if(d)e._webgl.makeSeparateTris.pushBuffer("color",s);else{var l=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,l),i.bufferData(i.ARRAY_BUFFER,s,i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,null),s=null,0==e._webgl.internalDownloadCount&&(e._nameSpace.doc.needRender=!0),n.checkError(i);var h=(new Date).getTime()-r;x3dom.debug.logInfo("XHR4/ color load time: "+h+" ms"),e._webgl.buffers[x3dom.BUFFER_IDX.COLOR]=l}}}else x3dom.debug.logError("XHR4/ color load failed with status: "+_.status)}}if(!a._hasStrideOffset&&a._vf.tangent.length>0){var m=new XMLHttpRequest;m.open("GET",e._nameSpace.getURL(a._vf.normal),!0),m.responseType="arraybuffer",e._nameSpace.doc.incrementDownloads(),x3dom.RequestManager.addRequest(m),m.onload=function(){if(e._nameSpace.doc.decrementDownloads(),e._webgl.internalDownloadCount-=1,200==m.status){if(e._webgl)if(a._vf.compressed)x3dom.debug.logError("x3dom 1.8.2+ do not support compressed BinaryGeometries anymore");else{var t=m.response,o=a._vf.tangentType;e._webgl.tangentType=x3dom.Utils.getVertexAttribType(o,i);var s=x3dom.Utils.getArrayBufferView(o,t);if(d)e._webgl.makeSeparateTris.pushBuffer("tangent",s);else{var l=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,l),i.bufferData(i.ARRAY_BUFFER,s,i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,null),s=null,0==e._webgl.internalDownloadCount&&(e._nameSpace.doc.needRender=!0),n.checkError(i);var h=(new Date).getTime()-r;x3dom.debug.logInfo("XHR5/ normal load time: "+h+" ms"),e._webgl.buffers[x3dom.BUFFER_IDX.TANGENT]=l}}}else x3dom.debug.logError("XHR2/ normal load failed with status: "+m.status)}}if(!a._hasStrideOffset&&a._vf.binormal.length>0){var p=new XMLHttpRequest;p.open("GET",e._nameSpace.getURL(a._vf.normal),!0),p.responseType="arraybuffer",e._nameSpace.doc.incrementDownloads(),x3dom.RequestManager.addRequest(p),p.onload=function(){if(e._nameSpace.doc.decrementDownloads(),e._webgl.internalDownloadCount-=1,200==p.status){if(e._webgl)if(a._vf.compressed)x3dom.debug.logError("x3dom 1.8.2+ do not support compressed BinaryGeometries anymore");else{var t=p.response,o=a._vf.binormalType;e._webgl.binormalType=x3dom.Utils.getVertexAttribType(o,i);var s=x3dom.Utils.getArrayBufferView(o,t);if(d)e._webgl.makeSeparateTris.pushBuffer("binormal",s);else{var l=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,l),i.bufferData(i.ARRAY_BUFFER,s,i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,null),s=null,0==e._webgl.internalDownloadCount&&(e._nameSpace.doc.needRender=!0),n.checkError(i);var h=(new Date).getTime()-r;x3dom.debug.logInfo("XHR6/ normal load time: "+h+" ms"),e._webgl.buffers[x3dom.BUFFER_IDX.BITANGENT]=l}}}else x3dom.debug.logError("XHR6/ normal load failed with status: "+p.status)}}}},x3dom.BinaryContainerLoader.setupPopGeo=function(e,t,i,o,s){if(!this.outOfMemory){var r=e._cf.geometry.node;if(r.hasIndex()){e._webgl.popGeometry=1,e._webgl.buffers[x3dom.BUFFER_IDX.INDEX]=i.createBuffer(),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,e._webgl.buffers[x3dom.BUFFER_IDX.INDEX]),i.bufferData(i.ELEMENT_ARRAY_BUFFER,2*r.getTotalNumberOfIndices(),i.STATIC_DRAW),e._webgl.buffers[x3dom.BUFFER_IDX.ID]=i.createBuffer();var n=new Float32Array(r._vf.vertexBufferSize);!function(){for(var e=0;e<n.length;++e)n[e]=e}(),i.bindBuffer(i.ARRAY_BUFFER,e._webgl.buffers[x3dom.BUFFER_IDX.ID]),i.bufferData(i.ARRAY_BUFFER,n,i.STATIC_DRAW)}else e._webgl.popGeometry=-1;e._webgl.buffers[x3dom.BUFFER_IDX.POSITION]=i.createBuffer(),i.bindBuffer(i.ARRAY_BUFFER,e._webgl.buffers[x3dom.BUFFER_IDX.POSITION]),i.bufferData(i.ARRAY_BUFFER,r._vf.attributeStride*r._vf.vertexBufferSize,i.STATIC_DRAW);var a=r._vf.coordType;e._webgl.coordType=x3dom.Utils.getVertexAttribType(a,i),e._coordStrideOffset[0]=r.getAttributeStride(),e._coordStrideOffset[1]=r.getPositionOffset(),i.vertexAttribPointer(t.position,e._cf.geometry.node._mesh._numPosComponents,e._webgl.coordType,!1,e._coordStrideOffset[0],e._coordStrideOffset[1]),i.enableVertexAttribArray(t.position),r.hasNormal()&&(a=r._vf.normalType,e._webgl.normalType=x3dom.Utils.getVertexAttribType(a,i),e._normalStrideOffset[0]=r.getAttributeStride(),e._normalStrideOffset[1]=r.getNormalOffset(),e._webgl.buffers[x3dom.BUFFER_IDX.NORMAL]=e._webgl.buffers[x3dom.BUFFER_IDX.POSITION],i.vertexAttribPointer(t.normal,e._cf.geometry.node._mesh._numNormComponents,e._webgl.normalType,!1,e._normalStrideOffset[0],e._normalStrideOffset[1]),i.enableVertexAttribArray(t.normal)),r.hasTexCoord()&&(a=r._vf.texCoordType,e._webgl.texCoordType=x3dom.Utils.getVertexAttribType(a,i),e._webgl.buffers[x3dom.BUFFER_IDX.TEXCOORD]=e._webgl.buffers[x3dom.BUFFER_IDX.POSITION],e._texCoordStrideOffset[0]=r.getAttributeStride(),e._texCoordStrideOffset[1]=r.getTexCoordOffset(),i.vertexAttribPointer(t.texcoord,e._cf.geometry.node._mesh._numTexComponents,e._webgl.texCoordType,!1,e._texCoordStrideOffset[0],e._texCoordStrideOffset[1]),i.enableVertexAttribArray(t.texcoord)),r.hasColor()&&(a=r._vf.colorType,e._webgl.colorType=x3dom.Utils.getVertexAttribType(a,i),e._webgl.buffers[x3dom.BUFFER_IDX.COLOR]=e._webgl.buffers[x3dom.BUFFER_IDX.POSITION],e._colorStrideOffset[0]=r.getAttributeStride(),e._colorStrideOffset[1]=r.getColorOffset(),i.vertexAttribPointer(t.color,e._cf.geometry.node._mesh._numColComponents,e._webgl.colorType,!1,e._colorStrideOffset[0],e._colorStrideOffset[1]),i.enableVertexAttribArray(t.color)),e._webgl.currentNumIndices=0,e._webgl.currentNumVertices=0,e._webgl.numVerticesAtLevel=[],e._webgl.levelsAvailable=0,this.checkError(i),e._webgl.levelLoaded=[],function(){for(var t=0;t<r.getNumLevels();++t)e._webgl.levelLoaded.push(!1)}();var d=function(t,o){if(e._webgl.levelLoaded[o]=!0,e._webgl.numVerticesAtLevel[o]=0,t){var s=0,n=!1;if(r.hasIndex()&&(s=2*r.getNumIndicesByLevel(o))>0){n=!0;var a=new Uint8Array(t,0,s);i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,e._webgl.buffers[x3dom.BUFFER_IDX.INDEX]),function(){for(var e=0,t=0;t<o;++t)e+=r.getNumIndicesByLevel(t);i.bufferSubData(i.ELEMENT_ARRAY_BUFFER,2*e,a)}()}var d=t.byteLength-s;if(d>0){n=!0;var l=new Uint8Array(t,s,d);i.bindBuffer(i.ARRAY_BUFFER,e._webgl.buffers[x3dom.BUFFER_IDX.POSITION]),r.hasIndex()?i.bufferSubData(i.ARRAY_BUFFER,r.getVertexDataBufferOffset(o)*r.getAttributeStride(),l):i.bufferSubData(i.ARRAY_BUFFER,e._webgl.currentNumVertices*r.getAttributeStride(),l),e._webgl.numVerticesAtLevel[o]=d/r.getAttributeStride(),e._webgl.currentNumVertices+=e._webgl.numVerticesAtLevel[o]}!function(){for(var t=0,i=e._webgl.levelsAvailable;i<r.getNumLevels()&&!1!==e._webgl.levelLoaded[i];++i)t+=r.getNumIndicesByLevel(i),++e._webgl.levelsAvailable;e._webgl.currentNumIndices=t}(),r._mesh._numCoords=e._webgl.currentNumVertices,r._mesh._numFaces=(r.hasIndex()?e._webgl.currentNumIndices:e._webgl.currentNumVertices)/3,r.adaptVertexCount(r.hasIndex()?3*r._mesh._numFaces:r._mesh._numCoords),n&&(e._nameSpace.doc.needRender=!0)}},l=r.getDataURLs();e._webgl.downloadStartTimer=(new Date).getTime();for(var h=0;h<l.length;++h){e._nameSpace.doc.incrementDownloads();var f=new XMLHttpRequest;f.responseType="arraybuffer",f.open("GET",l[h]),f.onload=function(t,i){e._nameSpace.doc.decrementDownloads(),d(t.response,i)}.bind(this,f,h),x3dom.RequestManager.addRequest(f)}}},x3dom.BinaryContainerLoader.bufferGeoCache={},x3dom.BinaryContainerLoader.setupBufferGeo=function(e,t,i,o,s){var r,n=e._cf.geometry.node,a=null,d=null,l=!0;e._webgl.bufferGeometry=n._indexed?1:-1,n._mesh._numCoords=n._vf.vertexCount[0],n._mesh._numFaces=n._vf.vertexCount[0]/3;var h=function(t){if(0!=l){var o=function(e){var t;if(d){var i=n._cf.views.nodes[d._vf.view],o=d._vf.byteOffset+i._vf.byteOffset,s=d._vf.count*d._vf.components;t=x3dom.BinaryContainerLoader.getArrayBufferFromType(d._vf.componentType,e,o,s)}return t}(t),s=function(e){var t;if(a){var i=n._cf.views.nodes[a._vf.view],o=a._vf.byteOffset+i._vf.byteOffset,s=a._vf.count*a._vf.components;t=x3dom.BinaryContainerLoader.getArrayBufferFromType(a._vf.componentType,e,o,s)}return t}(t),r=new Float32Array(3*d._vf.count),h=new x3dom.fields.SFVec3f,f=new x3dom.fields.SFVec3f,u=new x3dom.fields.SFVec3f,c=new x3dom.fields.SFVec3f,_=new x3dom.fields.SFVec3f;if(s)for(var m,p,x,g=0;g<s.length;g+=3)m=3*s[g],p=3*s[g+1],x=3*s[g+2],h.set(o[m],o[m+1],o[m+2]),f.set(o[p],o[p+1],o[p+2]),u.set(o[x],o[x+1],o[x+2]),c=c.subtractVectors(h,f),_=(_=(_=_.subtractVectors(u,f)).cross(c)).normalize(),r[m]=r[p]=r[x]=_.x,r[m+1]=r[p+1]=r[x+1]=_.y,r[m+2]=r[p+2]=r[x+2]=_.z;else if(o)for(g=0;g<o.length;g+=9)h.set(o[g],o[g+1],o[g+2]),f.set(o[g+3],o[g+4],o[g+5]),u.set(o[g+6],o[g+7],o[g+8]),c=c.subtractVectors(h,f),_=(_=(_=_.subtractVectors(u,f)).cross(c)).normalize(),r[g]=r[g+3]=r[g+6]=_.x,r[g+1]=r[g+4]=r[g+7]=_.y,r[g+2]=r[g+5]=r[g+8]=_.z;var v=i.createBuffer();i.bindBuffer(34962,v),i.bufferData(34962,r,i.STATIC_DRAW),i.bindBuffer(34962,null),e._webgl.buffers[x3dom.BUFFER_IDX.NORMAL]=v,e._normalStrideOffset=[12,0],e._webgl.normalType=5126,n._mesh._numNormComponents=3}};""!=n._vf.buffer&&(r=e._nameSpace.getURL(n._vf.buffer),null==x3dom.BinaryContainerLoader.bufferGeoCache[r]&&(e._nameSpace.doc.incrementDownloads(),x3dom.BinaryContainerLoader.bufferGeoCache[r]={},x3dom.BinaryContainerLoader.bufferGeoCache[r].buffers=[],x3dom.BinaryContainerLoader.bufferGeoCache[r].shapes=[],x3dom.BinaryContainerLoader.bufferGeoCache[r].decrementDownload=!0,x3dom.BinaryContainerLoader.bufferGeoCache[r].promise=new Promise((function(e,t){var i=new XMLHttpRequest;i.open("GET",r),i.responseType="arraybuffer",i.onload=function(o){200!=i.status?t():e(i.response)},i.onerror=function(e){t()},x3dom.RequestManager.addRequest(i)}))),x3dom.BinaryContainerLoader.bufferGeoCache[r].promise.then((function(t){null!=e._webgl?(!function(e){for(var t=n._cf.views.nodes,o=0;o<t.length;o++){var s=t[o],a=s._vf.id,d=s._vf.byteOffset,l=s._vf.byteLength;if(null==x3dom.BinaryContainerLoader.bufferGeoCache[r].buffers[a]||!i.isBuffer(x3dom.BinaryContainerLoader.bufferGeoCache[r].buffers[a])){var h=new Uint8Array(e,d,l),f=i.createBuffer();i.bindBuffer(s._vf.target,f),i.bufferData(s._vf.target,h,i.STATIC_DRAW),i.bindBuffer(s._vf.target,null),x3dom.BinaryContainerLoader.bufferGeoCache[r].buffers[a]=f}}}(t),function(){for(var t=n._cf.accessors.nodes,i=0;i<t.length;i++){var o=t[i],s=o._vf.byteOffset,h=o._vf.byteStride,f=o._vf.bufferType,u=o._vf.components,c=o._vf.componentType,_=o._vf.normalized,m=o._vf.view;switch(f){case"INDEX":a=o,e._webgl.indexType=c,e._indexOffset=s;break;case"POSITION":d=o,e._coordStrideOffset=[h,s],e._webgl.coordType=c,e._webgl.coordNormalized=_,n._mesh._numPosComponents=u;break;case"NORMAL":l=!1,e._normalStrideOffset=[h,s],e._webgl.normalType=c,e._webgl.normalNormalized=_,n._mesh._numNormComponents=u;break;case"TEXCOORD_0":case"TEXCOORD":e._texCoordStrideOffset=[h,s],e._webgl.texCoordType=c,e._webgl.texCoordNormalized=_,n._mesh._numTexComponents=u;break;case"TEXCOORD_1":e._texCoord2StrideOffset=[h,s],e._webgl.texCoord2Type=c,e._webgl.texCoord2Normalized=_,n._mesh._numTex2Components=u;break;case"COLOR":case"COLOR_0":e._colorStrideOffset=[h,s],e._webgl.colorType=c,e._webgl.colorNormalized=_,n._mesh._numColComponents=u;break;case"TANGENT":e._tangentStrideOffset=[h,s],e._webgl.tangentType=c,e._webgl.tangentNormalized=_,n._mesh._numTangentComponents=u;break;case"BITANGENT":e._binormalStrideOffset=[h,s],e._webgl.binormalType=c,e._webgl.binormalNormalized=_,n._mesh._numBinormalComponents=u}var p=x3dom.BUFFER_IDX[o._vf.bufferType],x=n._cf.views.nodes[m]._vf.id;e._webgl.buffers[p]=x3dom.BinaryContainerLoader.bufferGeoCache[r].buffers[x]}}(),h(t),function(t){t.shapes.push(e),e._webgl._bufferGeoCache=t;var i=e._cleanupGLObjects;e._cleanupGLObjects=function(e,t){var o=this._webgl._bufferGeoCache,s=o.shapes.indexOf(this);s>-1&&o.shapes.splice(s,1),o.shapes.length>0||i.call(this,e,t)}}(x3dom.BinaryContainerLoader.bufferGeoCache[r]),x3dom.BinaryContainerLoader.bufferGeoCache[r].decrementDownload&&(x3dom.BinaryContainerLoader.bufferGeoCache[r].decrementDownload=!1,e._nameSpace.doc.decrementDownloads(),e._nameSpace.doc.needRender=!0)):x3dom.BinaryContainerLoader.bufferGeoCache[r]=void 0})).catch((function(){x3dom.BinaryContainerLoader.bufferGeoCache[r].decrementDownload&&(x3dom.BinaryContainerLoader.bufferGeoCache[r].decrementDownload=!1,e._nameSpace.doc.decrementDownloads())})))},x3dom.BinaryContainerLoader.setupBufferInterpolator=function(e){var t=function(e,t,i){for(var o=e._cf.views.nodes[t._vf.view],s=t._vf.byteOffset+o._vf.byteOffset,r=t._vf.count*t._vf.components,n=t._vf.componentType,a=x3dom.BinaryContainerLoader.getArrayBufferFromType(n,i,s,r),d=0,l=a.length;d<l;d++)a[d]=a[d]/e._vf.duration;return new x3dom.fields.MFFloat(a)},i=function(e,t,i){var o=e._cf.views.nodes[t._vf.view],s=t._vf.byteOffset+o._vf.byteOffset,r=t._vf.count*t._vf.components,n=t._vf.componentType,a=x3dom.BinaryContainerLoader.getArrayBufferFromType(n,i,s,r);return e.keyValueFromAccessor(a,n)},o=e._nameSpace.getURL(e._vf.buffer);null==x3dom.BinaryContainerLoader.bufferGeoCache[o]&&(e._nameSpace.doc.incrementDownloads(),x3dom.BinaryContainerLoader.bufferGeoCache[o]={},x3dom.BinaryContainerLoader.bufferGeoCache[o].buffers=[],x3dom.BinaryContainerLoader.bufferGeoCache[o].decrementDownload=!0,x3dom.BinaryContainerLoader.bufferGeoCache[o].promise=new Promise((function(e,t){var i=new XMLHttpRequest;i.open("GET",o),i.responseType="arraybuffer",i.onload=function(o){200!=i.status?t():e(i.response)},i.onerror=function(e){t()},x3dom.RequestManager.addRequest(i)}))),x3dom.BinaryContainerLoader.bufferGeoCache[o].promise.then((function(s){null!=e?(!function(o){for(var s,r,n=e._cf.accessors.nodes,a=0;a<n.length;a++){var d=n[a];switch(d._vf.bufferType){case"SAMPLER_INPUT":s=t(e,d,o);break;case"SAMPLER_OUTPUT":r=i(e,d,o)}}if("STEP"===e._vf.interpolation){for(var l=s.copy(),h=r.copy(),f=(a=1,s.length);a<f;a++)l.splice(2*a,0,s[a]);for(a=0,f=r.length;a<f;a++)h.splice(2*a+1,0,r[a]);s=l,r=h}e._vf.key=s,e._vf.keyValue=r}(s),x3dom.BinaryContainerLoader.bufferGeoCache[o].decrementDownload&&(x3dom.BinaryContainerLoader.bufferGeoCache[o].decrementDownload=!1,e._nameSpace.doc.decrementDownloads(),e._nameSpace.doc.needRender=!0)):x3dom.BinaryContainerLoader.bufferGeoCache[o]=void 0})).catch((function(){x3dom.BinaryContainerLoader.bufferGeoCache[o].decrementDownload&&(x3dom.BinaryContainerLoader.bufferGeoCache[o].decrementDownload=!1,e._nameSpace.doc.decrementDownloads())}))},x3dom.BinaryContainerLoader.getArrayBufferFromType=function(e,t,i,o){switch(e){case 5120:return new Int8Array(t,i,o);case 5121:return new Uint8Array(t,i,o);case 5122:return new Int16Array(t,i,o);case 5123:return new Uint16Array(t,i,o);case 5125:return new Uint32Array(t,i,o);case 5126:return new Float32Array(t,i,o)}},x3dom.DrawableCollection=function(e){this.collection=[],this.viewMatrix=e.viewMatrix,this.projMatrix=e.projMatrix,this.sceneMatrix=e.sceneMatrix,this.viewarea=e.viewArea;var t=this.viewarea._scene,i=t.getEnvironment(),o=t.getViewpoint();this.near=o.getNear(),this.pixelHeightAtDistOne=o.getImgPlaneHeightAtDistOne()/this.viewarea._height,this.context=e.context,this.gl=e.gl,this.viewFrustum=this.viewarea.getViewfrustum(this.sceneMatrix),this.worldVol=new x3dom.fields.BoxVolume,this.frustumCulling=e.frustumCulling&&null!=this.viewFrustum,this.smallFeatureThreshold=e.smallFeatureThreshold,this.sortOpaque=this.smallFeatureThreshold>0&&i._lowPriorityThreshold<1,this.sortTrans=e.sortTrans,this.prioLevels=10,this.maxTreshold=100,this.sortBySortKey=!1,this.sortByPriority=!1,this.numberOfNodes=0,this.length=0},x3dom.DrawableCollection.prototype.cull=function(e,t,i,o){var s=t.boundedNode;if(!s||!s.renderFlag())return-1;var r,n=s.getVolume();if(this.frustumCulling&&t.needCulling){if(i&&!t.worldVolume.isValid()?(t.worldVolume.transformFrom(e,n),r=t.worldVolume):o<63&&(this.worldVol.transformFrom(e,n),r=this.worldVol),o<63&&(o=this.viewFrustum.intersect(r,o)),-1==o)return-1}else o=63;if(t.coverage=-1,this.smallFeatureThreshold>0||s.forceUpdateCoverage()){var a=this.viewMatrix.mult(e);t.center=a.multMatrixPnt(n.getCenter());var d=a.multMatrixVec(n.getRadialVec()).length(),l=Math.max(-t.center.z-d,this.near)*this.pixelHeightAtDistOne;if(t.coverage=2*d/l,this.smallFeatureThreshold>0&&t.coverage<this.smallFeatureThreshold&&t.needCulling)return-1}return this.numberOfNodes++,o},x3dom.DrawableCollection.prototype.addShape=function(e,t,i){var o={};o.shape=e,o.transform=t,o.localTransform=i.localMatrix,o.localVolume=i.volume,o.worldVolume=x3dom.fields.BoxVolume.copy(i.worldVolume),o.priority=Math.max(0,i.coverage),o.shaderID=e.getShaderProperties(this.viewarea).id;var s=e._cf.appearance.node;if(o.sortType=s?s._vf.sortType.toLowerCase():"opaque",o.sortKey=s?s._vf.sortKey:0,"transparent"==o.sortType)if(this.smallFeatureThreshold>0)o.zPos=i.center.z;else{var r=t.multMatrixPnt(e.getCenter());r=this.viewMatrix.multMatrixPnt(r),o.zPos=r.z}this.sortBySortKey||0==o.sortKey||(this.sortBySortKey=!0),void 0===this.collection[o.sortType]&&(this.collection[o.sortType]=[]),this.collection[o.sortType].push(o),this.length++,this.context&&this.gl&&this.context.setupShape(this.gl,o,this.viewarea)},x3dom.DrawableCollection.prototype.addDrawable=function(e){e.shaderID=e.shape.getShaderProperties(this.viewarea).id;var t=e.shape._cf.appearance.node;if(e.sortType=t?t._vf.sortType.toLowerCase():"opaque",e.sortKey=t?t._vf.sortKey:0,"transparent"==e.sortType){var i=e.transform.multMatrixPnt(e.shape.getCenter());i=this.viewMatrix.multMatrixPnt(i),e.zPos=i.z}this.sortBySortKey||0==e.sortKey||(this.sortBySortKey=!0),void 0===this.collection[e.sortType]&&(this.collection[e.sortType]=[]),this.collection[e.sortType].push(e),this.length++,this.context&&this.gl&&this.context.setupShape(this.gl,e,this.viewarea)},x3dom.DrawableCollection.prototype.calculatePriority=function(e){var t=Math.max(0,e.coverage),i=this.prioLevels-1;return t=Math.min(Math.round(t/(this.maxTreshold/i)),i)},x3dom.DrawableCollection.prototype.concat=function(){var e=void 0!==this.collection.opaque?this.collection.opaque:[],t=void 0!==this.collection.transparent?this.collection.transparent:[];this.collection=e.concat(t)},x3dom.DrawableCollection.prototype.get=function(e){return this.collection[e]},x3dom.DrawableCollection.prototype.sort=function(){var e=[],t=[],i=this;void 0!==this.collection.opaque&&(this.sortOpaque&&this.collection.opaque.sort((function(e,t){return e.sortKey!=t.sortKey&&i.sortBySortKey?e.sortKey-t.sortKey:t.priority-e.priority})),e=this.collection.opaque),void 0!==this.collection.transparent&&(this.sortTrans&&this.collection.transparent.sort((function(e,t){return e.sortKey!=t.sortKey&&i.sortBySortKey?e.sortKey-t.sortKey:e.priority!=t.priority&&i.sortByPriority?t.priority-e.priority:e.zPos-t.zPos})),t=this.collection.transparent),this.collection=e.concat(t)},x3dom.DrawableCollection.prototype.forEach=function(e,t){var i,o,s,r;for(t=void 0!==t?Math.min(t,this.prioLevels):this.prioLevels,i=0;i<this.collection.opaque.length;++i)if(void 0!==this.collection.opaque[i])for(o=this.collection.opaque[i].length;o>0;--o)if(void 0!==this.collection.opaque[i][o])for(s in this.collection.opaque[i][o])for(r=0;r<this.collection.opaque[i][o][s].length;++r)e(this.collection.opaque[i][o][s][r]);for(i=0;i<this.collection.transparent.length;++i)if(void 0!==this.collection.transparent[i])for(o=this.collection.transparent[i].length;o>0;--o)if(void 0!==this.collection.transparent[i][o])for(var n in this.collection.transparent[i][o])for(this.collection.transparent[i][o][n].sort((function(e,t){return e.zPos-t.zPos})),r=0;r<this.collection.transparent[i][o][n].length;++r)e(this.collection.transparent[i][o][n][r])},x3dom.Moveable=function(e,t,i,o,s){this._x3domRoot=e,this._runtime=e.runtime,this._callback=i,this._gridSize=o||0,this._moveable=t,this._drag=!1,this._w=0,this._h=0,this._uPlane=null,this._vPlane=null,this._pPlane=null,this._isect=null,this._translationOffset=null,this._rotationOffset=null,this._scaleOffset=null,this._lastX=0,this._lastY=0,this._buttonState=0,this._mode=s&&s.length?s.toLowerCase():"translation",this._firstRay=null,this._matrixTrafo=null,this._navType="examine",this.attachHandlers()},x3dom.Moveable.prototype.setGridSize=function(e){this._gridSize=e},x3dom.Moveable.prototype.setMode=function(e){this._mode=e.toLowerCase()},x3dom.Moveable.prototype.attachHandlers=function(){this._moveable._iMove=this,this._x3domRoot._iMove||(this._x3domRoot._iMove=[]),this._x3domRoot._iMove.push(this),this._moveable.addEventListener("mousedown",this.start,!1),this._moveable.addEventListener("mouseover",this.over,!1),this._moveable.addEventListener("mouseout",this.out,!1),1==this._x3domRoot._iMove.length&&(this._x3domRoot.addEventListener("mouseup",this.stop,!1),this._x3domRoot.addEventListener("mouseout",this.stop,!1),this._x3domRoot.addEventListener("mousemove",this.move,!0),this._runtime.canvas.disableTouch||(this._x3domRoot.addEventListener("MozTouchDown",this.touchStartHandlerMoz,!1),this._x3domRoot.addEventListener("MozTouchMove",this.touchMoveHandlerMoz,!0),this._x3domRoot.addEventListener("MozTouchUp",this.touchEndHandlerMoz,!1),this._x3domRoot.addEventListener("touchstart",this.touchStartHandler,!1),this._x3domRoot.addEventListener("touchmove",this.touchMoveHandler,!0),this._x3domRoot.addEventListener("touchend",this.touchEndHandler,!1)))},x3dom.Moveable.prototype.detachHandlers=function(){var e=this._x3domRoot._iMove;if(e)for(var t=0,i=e.length;t<i;t++)if(e[t]==this){e.splice(t,1);break}this._moveable.removeEventListener("mousedown",this.start,!1),this._moveable.removeEventListener("mouseover",this.over,!1),this._moveable.removeEventListener("mouseout",this.out,!1),0==e.length&&(this._x3domRoot.removeEventListener("mouseup",this.stop,!1),this._x3domRoot.removeEventListener("mouseout",this.stop,!1),this._x3domRoot.removeEventListener("mousemove",this.move,!0),this._runtime.canvas.disableTouch||(this._x3domRoot.removeEventListener("MozTouchDown",this.touchStartHandlerMoz,!1),this._x3domRoot.removeEventListener("MozTouchMove",this.touchMoveHandlerMoz,!0),this._x3domRoot.removeEventListener("MozTouchUp",this.touchEndHandlerMoz,!1),this._x3domRoot.removeEventListener("touchstart",this.touchStartHandler,!1),this._x3domRoot.removeEventListener("touchmove",this.touchMoveHandler,!0),this._x3domRoot.removeEventListener("touchend",this.touchEndHandler,!1))),this._moveable._iMove&&delete this._moveable._iMove},x3dom.Moveable.prototype.calcViewPlane=function(e){this._w=this._runtime.getWidth(),this._h=this._runtime.getHeight();var t=this._runtime.getViewingRay(0,this._h-1),i=t.pos.add(t.dir),o=(t=this._runtime.getViewingRay(this._w-1,this._h-1)).pos.add(t.dir),s=(t=this._runtime.getViewingRay(0,0)).pos.add(t.dir);this._uPlane=o.subtract(i).normalize(),this._vPlane=s.subtract(i).normalize(),0===arguments.length?this._pPlane=i:this._pPlane=x3dom.fields.SFVec3f.copy(e)},x3dom.Moveable.prototype.det=function(e){return e[0][0]*e[1][1]*e[2][2]+e[0][1]*e[1][2]*e[2][0]+e[0][2]*e[2][1]*e[1][0]-e[2][0]*e[1][1]*e[0][2]-e[0][0]*e[2][1]*e[1][2]-e[1][0]*e[0][1]*e[2][2]},x3dom.Moveable.prototype.translateXY=function(e){for(var t=null,i=[],o=[],s=0;s<3;s++)i[s]=[],o[s]=[],i[s][0]=this._uPlane.at(s),o[s][0]=i[s][0],i[s][1]=this._vPlane.at(s),o[s][1]=i[s][1],i[s][2]=e.pos.subtract(this._pPlane).at(s),o[s][2]=-e.dir.at(s);var r=this.det(o);if(0!==r){var n=this.det(i)/r;t=e.pos.addScaled(e.dir,n)}return t&&(this._isect&&(t=t.subtract(this._isect)),t=t.add(this._translationOffset)),t},x3dom.Moveable.prototype.translateZ=function(e,t){var i=this._runtime.getSceneBBox(),o=(t<this._lastY?1:-1)*i.max.subtract(i.min).length()/100;return this._translationOffset=this._translationOffset.addScaled(e.dir,o),this._translationOffset},x3dom.Moveable.prototype.rotate=function(e,t){var i=2*Math.PI,o=(t-this._lastY)*i/this._w,s=(e-this._lastX)*i/this._h,r=x3dom.fields.Quaternion.axisAngle(this._uPlane,o),n=r.toMatrix();this._rotationOffset=n.mult(this._rotationOffset),n=(r=x3dom.fields.Quaternion.axisAngle(this._vPlane,s)).toMatrix(),this._rotationOffset=n.mult(this._rotationOffset);var a=this._rotationOffset.mult(x3dom.fields.SFMatrix4f.scale(this._scaleOffset)),d=new x3dom.fields.Quaternion(0,0,1,0);return d.setValue(a),d},x3dom.Moveable.prototype.over=function(e){this._iMove._runtime.getCanvas().style.cursor="crosshair"},x3dom.Moveable.prototype.out=function(e){var t=this._iMove;t._drag||(t._runtime.getCanvas().style.cursor="pointer")},x3dom.Moveable.prototype.start=function(e){var t=this._iMove;switch(t._mode){case"translation":t._buttonState=4==e.button?1:3&e.button;break;case"rotation":t._buttonState=4;break;case"all":default:t._buttonState=e.button}if(!t._drag&&t._buttonState){t._lastX=e.layerX,t._lastY=e.layerY,t._drag=!0,t._navType=t._runtime.navigationType(),t._runtime.noNav(),t._isect=new x3dom.fields.SFVec3f(e.worldX,e.worldY,e.worldZ),t.calcViewPlane(t._isect),t._firstRay=t._runtime.getViewingRay(e.layerX,e.layerY);var i=t._moveable.getAttribute("translation");if(t._matrixTrafo=null,i){t._translationOffset=x3dom.fields.SFVec3f.parse(i);var o=t._moveable.getAttribute("rotation");o=o?x3dom.fields.Quaternion.parseAxisAngle(o):new x3dom.fields.Quaternion(0,0,1,0),t._rotationOffset=o.toMatrix();var s=t._moveable.getAttribute("scale");t._scaleOffset=s?x3dom.fields.SFVec3f.parse(s):new x3dom.fields.SFVec3f(1,1,1)}else if(i=t._moveable.getAttribute("matrix")){t._matrixTrafo=x3dom.fields.SFMatrix4f.parse(i).transpose();var r=new x3dom.fields.SFVec3f(0,0,0),n=new x3dom.fields.SFVec3f(1,1,1),a=new x3dom.fields.Quaternion(0,0,1,0),d=new x3dom.fields.Quaternion(0,0,1,0);t._matrixTrafo.getTransform(r,a,n,d),t._translationOffset=r,t._rotationOffset=a.toMatrix(),t._scaleOffset=n}else t._translationOffset=new x3dom.fields.SFVec3f(0,0,0),t._rotationOffset=new x3dom.fields.SFMatrix4f,t._scaleOffset=new x3dom.fields.SFVec3f(1,1,1);t._runtime.getCanvas().style.cursor="crosshair"}},x3dom.Moveable.prototype.move=function(e){for(var t=0,i=this._iMove.length;t<i;t++){var o=this._iMove[t];if(o._drag){var s=o._runtime.mousePosition(e),r=o._runtime.getViewingRay(s[0],s[1]),n=null;if(n=2==o._buttonState?o.translateZ(o._firstRay,s[1]):1==o._buttonState?o.translateXY(r):o.rotate(s[0],s[1])){if(o._gridSize>0&&4!=o._buttonState){var a=o._gridSize*Math.round(n.x/o._gridSize),d=o._gridSize*Math.round(n.y/o._gridSize),l=o._gridSize*Math.round(n.z/o._gridSize);n=new x3dom.fields.SFVec3f(a,d,l)}o._matrixTrafo?(4==o._buttonState?o._matrixTrafo.setRotate(n):o._matrixTrafo.setTranslate(n),o._moveable.setAttribute("matrix",o._matrixTrafo.toGL().toString())):4==o._buttonState?o._moveable.setAttribute("rotation",n.toAxisAngle().toString()):o._moveable.setAttribute("translation",n.toString()),o._callback&&o._callback(o._moveable,n)}o._lastX=s[0],o._lastY=s[1]}}},x3dom.Moveable.prototype.stop=function(e){for(var t=0,i=this._iMove.length;t<i;t++){var o=this._iMove[t];if(o._drag)o._lastX=e.layerX,o._lastY=e.layerY,o._isect=null,o._drag=!1,o._runtime.canvas.doc._scene.getNavigationInfo().setType(o._navType),o._runtime.getCanvas().style.cursor="pointer"}},x3dom.Moveable.prototype.touchStartHandler=function(e){e.preventDefault()},x3dom.Moveable.prototype.touchStartHandlerMoz=function(e){e.preventDefault()},x3dom.Moveable.prototype.touchMoveHandler=function(e){e.preventDefault()},x3dom.Moveable.prototype.touchMoveHandlerMoz=function(e){e.preventDefault()},x3dom.Moveable.prototype.touchEndHandler=function(e){if(this._iMove.length){var t=this._iMove[0];t.stop.apply(t._x3domRoot,[e])}e.preventDefault()},x3dom.Moveable.prototype.touchEndHandlerMoz=function(e){if(this._iMove.length){var t=this._iMove[0];t.stop.apply(t._x3domRoot,[e])}e.preventDefault()},function(){"use strict";function e(e){return"function"==typeof e}function t(){var e=setTimeout;return function(){return e(i,1)}}function i(){for(var e=0;e<x;e+=2)(0,M[e])(M[e+1]),M[e]=void 0,M[e+1]=void 0;x=0}function o(e,t){var i=this,o=new this.constructor(r);void 0===o[w]&&m(o);var s=i._state;if(s){var n=arguments[s-1];y((function(){return _(s,o,n,i._result)}))}else u(i,o,e,t);return o}function s(e){if(e&&"object"==typeof e&&e.constructor===this)return e;var t=new this(r);return d(t,e),t}function r(){}function n(e){try{return e.then}catch(e){return N.error=e,N}}function a(t,i,r){i.constructor===t.constructor&&r===o&&i.constructor.resolve===s?function(e,t){t._state===R?h(e,t._result):t._state===D?f(e,t._result):u(t,void 0,(function(t){return d(e,t)}),(function(t){return f(e,t)}))}(t,i):r===N?(f(t,N.error),N.error=null):void 0===r?h(t,i):e(r)?function(e,t,i){y((function(e){var o=!1,s=function(e,t,i,o){try{e.call(t,i,o)}catch(e){return e}}(i,t,(function(i){o||(o=!0,t!==i?d(e,i):h(e,i))}),(function(t){o||(o=!0,f(e,t))}),e._label);!o&&s&&(o=!0,f(e,s))}),e)}(t,i,r):h(t,i)}function d(e,t){e===t?f(e,new TypeError("You cannot resolve a promise with itself")):function(e){var t=typeof e;return null!==e&&("object"===t||"function"===t)}(t)?a(e,t,n(t)):h(e,t)}function l(e){e._onerror&&e._onerror(e._result),c(e)}function h(e,t){e._state===A&&(e._result=t,e._state=R,0!==e._subscribers.length&&y(c,e))}function f(e,t){e._state===A&&(e._state=D,e._result=t,y(l,e))}function u(e,t,i,o){var s=e._subscribers,r=s.length;e._onerror=null,s[r]=t,s[r+R]=i,s[r+D]=o,0===r&&e._state&&y(c,e)}function c(e){var t=e._subscribers,i=e._state;if(0!==t.length){for(var o=void 0,s=void 0,r=e._result,n=0;n<t.length;n+=3)o=t[n],s=t[n+i],o?_(i,o,s,r):s(r);e._subscribers.length=0}}function _(t,i,o,s){var r=e(o),n=void 0,a=void 0,l=void 0,u=void 0;if(r){if((n=function(e,t){try{return e(t)}catch(e){return N.error=e,N}}(o,s))===N?(u=!0,a=n.error,n.error=null):l=!0,i===n)return void f(i,new TypeError("A promises callback cannot return that same promise."))}else n=s,l=!0;i._state!==A||(r&&l?d(i,n):u?f(i,a):t===R?h(i,n):t===D&&f(i,n))}function m(e){e[w]=I++,e._state=void 0,e._result=void 0,e._subscribers=[]}var p=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},x=0,g=void 0,v=void 0,y=function(e,t){M[x]=e,M[x+1]=t,2===(x+=2)&&(v?v(i):C())},T="undefined"!=typeof window?window:void 0,b=T||{},S=b.MutationObserver||b.WebKitMutationObserver,F="undefined"==typeof self&&"undefined"!=typeof process&&"[object process]"==={}.toString.call(process),E="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,M=new Array(1e3),C=void 0;C=F?function(){return process.nextTick(i)}:S?function(){var e=0,t=new S(i),o=document.createTextNode("");return t.observe(o,{characterData:!0}),function(){o.data=e=++e%2}}():E?function(){var e=new MessageChannel;return e.port1.onmessage=i,function(){return e.port2.postMessage(0)}}():void 0===T&&"function"==typeof require?function(){try{var e=Function("return this")().require("vertx");return void 0!==(g=e.runOnLoop||e.runOnContext)?function(){g(i)}:t()}catch(e){return t()}}():t();var w=Math.random().toString(36).substring(2),A=void 0,R=1,D=2,N={error:null},I=0,P=function(){function e(e,t){this._instanceConstructor=e,this.promise=new e(r),this.promise[w]||m(this.promise),p(t)?(this.length=t.length,this._remaining=t.length,this._result=new Array(this.length),0===this.length?h(this.promise,this._result):(this.length=this.length||0,this._enumerate(t),0===this._remaining&&h(this.promise,this._result))):f(this.promise,new Error("Array Methods must be provided an Array"))}return e.prototype._enumerate=function(e){for(var t=0;this._state===A&&t<e.length;t++)this._eachEntry(e[t],t)},e.prototype._eachEntry=function(e,t){var i=this._instanceConstructor,d=i.resolve;if(d===s){var l=n(e);if(l===o&&e._state!==A)this._settledAt(e._state,t,e._result);else if("function"!=typeof l)this._remaining--,this._result[t]=e;else if(i===V){var h=new i(r);a(h,e,l),this._willSettleAt(h,t)}else this._willSettleAt(new i((function(t){return t(e)})),t)}else this._willSettleAt(d(e),t)},e.prototype._settledAt=function(e,t,i){var o=this.promise;o._state===A&&(this._remaining--,e===D?f(o,i):this._result[t]=i),0===this._remaining&&h(o,this._result)},e.prototype._willSettleAt=function(e,t){var i=this;u(e,void 0,(function(e){return i._settledAt(R,t,e)}),(function(e){return i._settledAt(D,t,e)}))},e}(),V=function(){function e(t){this[w]=I++,this._result=this._state=void 0,this._subscribers=[],r!==t&&("function"!=typeof t&&function(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}(),this instanceof e?function(e,t){try{t((function(t){d(e,t)}),(function(t){f(e,t)}))}catch(t){f(e,t)}}(this,t):function(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}())}return e.prototype.catch=function(e){return this.then(null,e)},e.prototype.finally=function(e){var t=this.constructor;return this.then((function(i){return t.resolve(e()).then((function(){return i}))}),(function(i){return t.resolve(e()).then((function(){throw i}))}))},e}();V.prototype.then=o,V.all=function(e){return new P(this,e).promise},V.race=function(e){var t=this;return new t(p(e)?function(i,o){for(var s=e.length,r=0;r<s;r++)t.resolve(e[r]).then(i,o)}:function(e,t){return t(new TypeError("You must pass an array to race."))})},V.resolve=s,V.reject=function(e){var t=new this(r);return f(t,e),t},V._setScheduler=function(e){v=e},V._setAsap=function(e){y=e},V._asap=y,V.polyfill=function(){var e=void 0;if("undefined"!=typeof global)e=global;else if("undefined"!=typeof self)e=self;else try{e=Function("return this")()}catch(e){throw new Error("polyfill failed because global object is unavailable in this environment")}var t=e.Promise;if(t){var i=null;try{i=Object.prototype.toString.call(t.resolve())}catch(e){}if("[object Promise]"===i&&!t.cast)return}e.Promise=V},V.Promise=V,V.polyfill()}(),x3dom.glTF2Loader=function(e){this._nameSpace=e,this._definitions={}},x3dom.glTF2Loader.prototype.load=function(e,t){this._gltf=this._getGLTF(e,t);var i=this._generateX3DScene(),o=this._gltf.scene||0,s=this._gltf.scenes[o];this._generateX3DWorldInfo(s,i);for(var r=0;r<s.nodes.length;r++){var n=this._gltf.nodes[s.nodes[r]];this._traverseNodes(n,i,s.nodes[r])}if(this._gltf.animations)for(r=0;r<this._gltf.animations.length;r++){var a=this._gltf.animations[r],d="glTF_ANIMATION_"+r;this._generateX3DAnimationNodes(i,a,d)}return i},x3dom.glTF2Loader.prototype._generateX3DWorldInfo=function(e,t){if(this._gltf.asset){var i,o,s=this._gltf.asset,r=["copyright","generator","version","minversion"],n=document.createElement("worldinfo"),a=new x3dom.fields.MFString;for(o=0;o<r.length;o++)s[i=r[o]]&&a.push('"'+r[o]+":"+s[i]+'"');n.setAttribute("info",a.toString()),s.extras&&s.extras.title&&n.setAttribute("title",s.extras.title);var d=document.createElement("MetadataSet");d.setAttribute("name","global"),d.setAttribute("containerfield","metadata"),this._generateX3DMetadata(s,d,"asset_extras","value"),this._generateX3DMetadata(e,d,"scene_extras","value"),d.hasChildNodes()&&n.appendChild(d),t.appendChild(n)}},x3dom.glTF2Loader.prototype._generateX3DMetadata=function(e,t,i,o){if(e.extras){o=o||"metadata";var s=r(i=i||"extras",e.extras,o);t.appendChild(s)}else;function r(e,t,i){var o=typeof t;return"string"==o||null===t||"undefined"==o?n("MetadataString",e,JSON.stringify(t),i):"number"==o?n("MetadataFloat",e,t,i):"boolean"==o?n("MetadataBoolean",e,t,i):"object"==o?function(e,t,i){var o=document.createElement("MetadataSet");o.setAttribute("name",e),o.setAttribute("containerfield",i);var s,n,a=Object.keys(t);for(n=0;n<a.length;n++)s=a[n],o.appendChild(r(s,t[s],"value"));return o}(e,t,i):n("MetadataString",e,t,i)}function n(e,t,i,o){var s=document.createElement(e);return s.setAttribute("name",t),s.setAttribute("value",i),s.setAttribute("containerfield",o),s}},x3dom.glTF2Loader.prototype._traverseNodes=function(e,t,i){var o=this._generateX3DNode(e,i);if(t.appendChild(o),e.children)for(var s=0;s<e.children.length;s++){var r=this._gltf.nodes[e.children[s]];this._traverseNodes(r,o,e.children[s])}},x3dom.glTF2Loader.prototype._generateX3DNode=function(e,t){var i;if(e.name=e.name?e.name:t,i=null!=e.matrix?this._generateX3DMatrixTransform(e):(null!=e.translation||null!=e.rotation||e.scale,this._generateX3DTransform(e)),this._generateX3DMetadata(e,i),null!=e.mesh)for(var o=this._gltf.meshes[e.mesh],s=0;s<o.primitives.length;s++)i.appendChild(this._generateX3DShape(o.primitives[s]));if(null!=e.model){var r=this._gltf.models[e.model];null!=r.uri&&i.appendChild(this._generateX3DInline(r))}return null!=e.camera&&i.appendChild(this._generateX3DViewpoint(e)),i},x3dom.glTF2Loader.prototype._generateX3DScene=function(){return document.createElement("scene")},x3dom.glTF2Loader.prototype._generateX3DTransform=function(e){var t=document.createElement("transform");return null!=e.translation&&t.setAttribute("translation",e.translation.join(" ")),null!=e.rotation&&t.setAttribute("rotation",this._toAxisAngle(e.rotation).join(" ")),null!=e.scale&&t.setAttribute("scale",e.scale.join(" ")),null!=e.name&&t.setAttribute("DEF","glTF_NODE_"+e.name),t},x3dom.glTF2Loader.prototype._generateX3DMatrixTransform=function(e){var t=document.createElement("matrixtransform");return null!=e.matrix&&t.setAttribute("matrix",e.matrix.join(" ")),null!=e.name&&t.setAttribute("DEF","glTF_NODE_"+e.name),t},x3dom.glTF2Loader.prototype._generateX3DGroup=function(e){return document.createElement("group")},x3dom.glTF2Loader.prototype._generateX3DInline=function(e){var t=document.createElement("inline");return t.setAttribute("url",e.uri),null!=e.mimeType&&t.setAttribute("contentType",e.mimeType),t},x3dom.glTF2Loader.prototype._generateX3DViewpoint=function(e){var t=this._gltf.cameras[e.camera],i="glTF_CAMERA_"+e.camera;switch(t.type){case"orthographic":return this._generateX3DOrthoViewpoint(i,t.orthographic);case"perspective":default:return this._generateX3DPerspectiveViewpoint(i,t.perspective)}},x3dom.glTF2Loader.prototype._generateX3DPerspectiveViewpoint=function(e,t){var i=document.createElement("viewpoint");this._generateX3DMetadata(t,i);var o=t.yfov||.785398,s=t.znear||-1,r=t.zfar||-1;return r/s>1e5&&(r=s=-1),i.setAttribute("DEF",e),i.setAttribute("fieldOfView",o),i.setAttribute("zNear",s),i.setAttribute("zFar",r),i.setAttribute("position","0 0 0"),i},x3dom.glTF2Loader.prototype._generateX3DOrthoViewpoint=function(e,t){var i=document.createElement("orthoviewpoint");this._generateX3DMetadata(t,i);var o=t.xmag||1,s=t.ymag||1,r=t.znear||-1,n=t.zfar||-1,a=[-o,-s,o,s];return i.setAttribute("DEF",e),i.setAttribute("fieldOfView",a),i.setAttribute("zNear",r),i.setAttribute("zFar",n),i.setAttribute("position","0 0 0"),i},x3dom.glTF2Loader.prototype._generateX3DShape=function(e){var t=document.createElement("shape");this._generateX3DMetadata(e,t);var i=null!=e.material?this._gltf.materials[e.material]:{name:"DEFAULT"};return null==i.name&&(i.name=e.material),t.appendChild(this._generateX3DAppearance(i)),t.appendChild(this._generateX3DBufferGeometry(e)),t},x3dom.glTF2Loader.prototype._generateX3DAppearance=function(e){var t=document.createElement("appearance");return this._generateX3DMetadata(e,t),"BLEND"===e.alphaMode?t.setAttribute("sortType","transparent"):t.setAttribute("sortType","opaque"),t.appendChild(this._generateX3DPhysicalMaterial(e)),this._textureTransform&&(t.appendChild(this._textureTransform),this._textureTransform=void 0),t},x3dom.glTF2Loader.prototype._generateX3DPhysicalMaterial=function(e){var t=document.createElement("physicalmaterial");if(this._USEorDEF(t,"glTF_MATERIAL_"+e.name))return t;var i,o,s=[1,1,1,1],r=e.emissiveFactor||[0,0,0],n=1,a=1,d=e.alphaMode||"OPAQUE",l=e.alphaCutoff||.5,h=!0,f=void 0,u=void 0,c=0;if(e.pbrMetallicRoughness?(u=e.pbrMetallicRoughness,f="roughnessMetallic"):e.extensions&&e.extensions.KHR_materials_pbrSpecularGlossiness&&(u=e.extensions.KHR_materials_pbrSpecularGlossiness,f="specularGlossiness"),"roughnessMetallic"==f){s=u.baseColorFactor||[1,1,1,1],n=null!=u.metallicFactor?u.metallicFactor:1,a=null!=u.roughnessFactor?u.roughnessFactor:1;u.baseColorTexture&&(c=u.baseColorTexture.texCoord?1:0,i=this._gltf.textures[u.baseColorTexture.index],o=u.baseColorTexture.extensions&&u.baseColorTexture.extensions.KHR_texture_transform?u.baseColorTexture.extensions.KHR_texture_transform:void 0,t.appendChild(this._generateX3DImageTexture(i,"baseColorTexture",c,o))),u.metallicRoughnessTexture&&(c=u.metallicRoughnessTexture.texCoord?1:0,i=this._gltf.textures[u.metallicRoughnessTexture.index],o=u.metallicRoughnessTexture.extensions&&u.metallicRoughnessTexture.extensions.KHR_texture_transform?u.metallicRoughnessTexture.extensions.KHR_texture_transform:void 0,e.occlusionTexture&&e.occlusionTexture.index==u.metallicRoughnessTexture.index?(h=!1,t.appendChild(this._generateX3DImageTexture(i,"occlusionRoughnessMetallicTexture",c,o))):t.appendChild(this._generateX3DImageTexture(i,"roughnessMetallicTexture",c,o))),t.setAttribute("baseColorFactor",s.join(" ")),t.setAttribute("metallicFactor",n),t.setAttribute("roughnessFactor",a)}else if("specularGlossiness"==f){var _=u.diffuseFactor||[1,1,1,1],m=u.specularFactor||[1,1,1],p=null!=u.glossinessFactor?u.glossinessFactor:1;u.diffuseTexture&&(c=u.diffuseTexture.texCoord?1:0,i=this._gltf.textures[u.diffuseTexture.index],o=u.diffuseTexture.extensions&&u.diffuseTexture.extensions.KHR_texture_transform?u.diffuseTexture.extensions.KHR_texture_transform:void 0,t.appendChild(this._generateX3DImageTexture(i,"baseColorTexture",c,o))),u.specularGlossinessTexture&&(c=u.specularGlossinessTexture.texCoord?1:0,i=this._gltf.textures[u.specularGlossinessTexture.index],o=u.specularGlossinessTexture.extensions&&u.specularGlossinessTexture.extensions.KHR_texture_transform?u.specularGlossinessTexture.extensions.KHR_texture_transform:void 0,t.appendChild(this._generateX3DImageTexture(i,"specularGlossinessTexture",c,o))),t.setAttribute("diffuseFactor",_.join(" ")),t.setAttribute("specularFactor",m.join(" ")),t.setAttribute("glossinessFactor",p)}return e.normalTexture&&(c=e.normalTexture.texCoord?1:0,i=this._gltf.textures[e.normalTexture.index],o=e.normalTexture.extensions&&e.normalTexture.extensions.KHR_texture_transform?e.normalTexture.extensions.KHR_texture_transform:void 0,t.appendChild(this._generateX3DImageTexture(i,"normalTexture",c,o))),e.emissiveTexture&&(c=e.emissiveTexture.texCoord?1:0,i=this._gltf.textures[e.emissiveTexture.index],o=e.emissiveTexture.extensions&&e.emissiveTexture.extensions.KHR_texture_transform?e.emissiveTexture.extensions.KHR_texture_transform:void 0,t.appendChild(this._generateX3DImageTexture(i,"emissiveTexture",c,o))),e.occlusionTexture&&h&&(c=e.occlusionTexture.texCoord?1:0,i=this._gltf.textures[e.occlusionTexture.index],o=e.occlusionTexture.extensions&&e.occlusionTexture.extensions.KHR_texture_transform?e.occlusionTexture.extensions.KHR_texture_transform:void 0,t.appendChild(this._generateX3DImageTexture(i,"occlusionTexture",c,o))),e.extensions&&e.extensions.KHR_materials_unlit&&t.setAttribute("unlit",!0),t.setAttribute("emissiveFactor",r.join(" ")),t.setAttribute("alphaMode",d),t.setAttribute("alphaCutoff",l),t.setAttribute("model",f),t},x3dom.glTF2Loader.prototype._generateX3DImageTexture=function(e,t,i,o){var s=this._gltf.images[e.source],r=document.createElement("imagetexture");if(this._generateX3DMetadata(e,r),r.setAttribute("origChannelCount","2"),r.setAttribute("flipY","true"),t&&r.setAttribute("containerField",t),null!=s.uri&&r.setAttribute("url",x3dom.Utils.dataURIToObjectURL(s.uri)),null!=e.sampler){var n=this._gltf.samplers[e.sampler];r.appendChild(this._createX3DTextureProperties(n))}return i&&r.setAttribute("channel","1"),o&&(this._textureTransform=this._createX3DTextureTransform(r,o)),r},x3dom.glTF2Loader.prototype._createX3DTextureProperties=function(e){var t=document.createElement("textureproperties");return t.setAttribute("boundaryModeS",x3dom.Utils.boundaryModesDicX3D(e.wrapS)),t.setAttribute("boundaryModeT",x3dom.Utils.boundaryModesDicX3D(e.wrapT)),t.setAttribute("magnificationFilter",x3dom.Utils.magFilterDicX3D(e.magFilter)),t.setAttribute("minificationFilter",x3dom.Utils.minFilterDicX3D(e.minFilter)),(null==e.minFilter||e.minFilter>=9984&&e.minFilter<=9987)&&t.setAttribute("generateMipMaps","true"),t},x3dom.glTF2Loader.prototype._createX3DTextureTransform=function(e,t){var i=document.createElement("matrixtexturetransform"),o=t.offset||[0,0],s=t.rotation||0,r=t.scale||[1,1],n=new x3dom.fields.SFVec3f(-0,-0,0),a=new x3dom.fields.SFVec3f(0,0,0),d=new x3dom.fields.SFVec3f(o[0],o[1],0),l=new x3dom.fields.SFVec3f(r[0],r[1],0),h=x3dom.fields.SFMatrix4f.translation(a.add(d)).mult(x3dom.fields.SFMatrix4f.rotationZ(-1*s)).mult(x3dom.fields.SFMatrix4f.scale(l)).mult(x3dom.fields.SFMatrix4f.translation(n));return i.setAttribute("matrix",h.toString()),t.texCoord&&e.setAttribute("channel",texCoord),i},x3dom.glTF2Loader.prototype._generateX3DBufferGeometry=function(e){var t=[],i=document.createElement("buffergeometry"),o=this._getCenterAndSize(e);(i.setAttribute("buffer",this._bufferURI(e)),i.setAttribute("position",o.center.join(" ")),i.setAttribute("size",o.size.join(" ")),i.setAttribute("vertexCount",this._getVertexCount(e)),i.setAttribute("primType",this._primitiveType(e.mode)),null!=e.material)&&(this._gltf.materials[e.material].doubleSided&&i.setAttribute("solid","false"));if(null!=e.indices){var s=this._gltf.accessors[e.indices];(a=this._gltf.bufferViews[s.bufferView]).id=s.bufferView,a.target=34963;var r=t.indexOf(a);null!=a.target&&-1==r&&(r=t.push(a)-1),i.appendChild(this._generateX3DBufferAccessor("INDEX",s,r))}for(var n in e.attributes){var a;s=this._gltf.accessors[e.attributes[n]];(a=this._gltf.bufferViews[s.bufferView]).target=34962,a.id=s.bufferView;r=t.indexOf(a);null!=a.target&&-1==r&&(r=t.push(a)-1),i.appendChild(this._generateX3DBufferAccessor(n,s,r))}for(var d=0;d<t.length;d++)i.appendChild(this._generateX3DBufferView(t[d]));return i},x3dom.glTF2Loader.prototype._generateX3DBufferView=function(e){var t=document.createElement("bufferview");return t.setAttribute("target",e.target),t.setAttribute("byteOffset",e.byteOffset||0),t.setAttribute("byteLength",e.byteLength),t.setAttribute("id",e.id),t},x3dom.glTF2Loader.prototype._generateX3DBufferAccessor=function(e,t,i){var o=this._componentsOf(t.type),s=this._gltf.bufferViews[t.bufferView],r=t.byteOffset,n=document.createElement("bufferaccessor");return n.setAttribute("bufferType",e.replace("_0","")),n.setAttribute("view",i),n.setAttribute("byteOffset",r||0),n.setAttribute("byteStride",s.byteStride||0),n.setAttribute("normalized",t.normalized||!1),n.setAttribute("components",o),n.setAttribute("componentType",t.componentType),n.setAttribute("count",t.count),n},x3dom.glTF2Loader.prototype._generateX3DAnimationNodes=function(e,t,i){var o=this._animationDuration(t),s=i+"_TIMESENSOR";e.appendChild(this._generateX3DTimeSensor(s,o));for(var r=0;r<t.channels.length;r++){var n=t.channels[r],a=n.target.path,d=n.target.node,l=t.samplers[n.sampler],h="glTF_NODE_"+this._gltf.nodes[d].name,f=i+"_INTERPOLATOR_"+r;e.appendChild(this._generateX3DInterpolator(f,a,l,o)),e.appendChild(this._createX3DRoute("fraction_changed",s,"set_fraction",f)),e.appendChild(this._createX3DRoute("value_changed",f,"set_"+a,h))}},x3dom.glTF2Loader.prototype._generateX3DTimeSensor=function(e,t){var i=document.createElement("TimeSensor");return i.setAttribute("loop","true"),i.setAttribute("cycleInterval",t),i.setAttribute("DEF",e),i},x3dom.glTF2Loader.prototype._generateX3DInterpolator=function(e,t,i,o){var s,r=i.interpolation||"LINEAR",n=this._gltf.accessors[i.input],a=this._gltf.accessors[i.output],d=this._gltf.bufferViews[n.bufferView],l=this._gltf.bufferViews[a.bufferView];switch(t){case"scale":case"translation":s=document.createElement("PositionInterpolator");break;case"rotation":s=document.createElement("OrientationInterpolator");break;case"weights":s=document.createElement("ScalarInterpolator")}return s.setAttribute("DEF",e),s.setAttribute("buffer",this._bufferURI(i)),s.setAttribute("interpolation",r),s.setAttribute("duration",o),s.appendChild(this._generateX3DBufferAccessor("SAMPLER_INPUT",n,0)),s.appendChild(this._generateX3DBufferAccessor("SAMPLER_OUTPUT",a,1)),s.appendChild(this._generateX3DBufferView(d)),s.appendChild(this._generateX3DBufferView(l)),s},x3dom.glTF2Loader.prototype._createX3DRoute=function(e,t,i,o){var s=document.createElement("ROUTE");return s.setAttribute("fromField",e),s.setAttribute("fromNode",t),s.setAttribute("toField",i),s.setAttribute("toNode",o),s},x3dom.glTF2Loader.prototype._getCenterAndSize=function(e){var t=[1,1,1],i=[0,0,0];if(null!=e.attributes.POSITION){var o=this._gltf.accessors[e.attributes.POSITION];t[0]=o.max[0]-o.min[0],t[1]=o.max[1]-o.min[1],t[2]=o.max[2]-o.min[2],i[0]=o.min[0]+.5*t[0],i[1]=o.min[1]+.5*t[1],i[2]=o.min[2]+.5*t[2]}return{center:i,size:t}},x3dom.glTF2Loader.prototype._getVertexCount=function(e){var t=0;return null!=e.indices?t=this._gltf.accessors[e.indices].count:null!=e.attributes.POSITION&&(t=this._gltf.accessors[e.attributes.POSITION].count),t},x3dom.glTF2Loader.prototype._sizeInBytes=function(e){switch(e){case 5120:case 5121:return 1;case 5122:case 5123:return 2;case 5125:case 5126:return 4}},x3dom.glTF2Loader.prototype._componentsOf=function(e){switch(e){case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16}},x3dom.glTF2Loader.prototype._bufferURI=function(e){var t,i="";if(null!=e.attributes&&null!=e.attributes.POSITION?t=e.attributes.POSITION:e.input&&(t=e.input),null!=t){var o=this._gltf.accessors[t],s=this._gltf.bufferViews[o.bufferView],r=this._gltf.buffers[s.buffer];i=x3dom.Utils.dataURIToObjectURL(r.uri)}return i},x3dom.glTF2Loader.prototype._USEorDEF=function(e,t){return null!=this._definitions[t]?(e.setAttribute("USE",t),!0):(e.setAttribute("DEF",t),this._definitions[t]=t,!1)},x3dom.glTF2Loader.prototype._primitiveType=function(e){switch(e){case 0:return"POINTS";case 1:return"LINES";case 2:return"LINE_LOOP";case 3:return"LINE_STRIP";case 4:return"TRIANGLES";case 5:return"TRIANGLE_STRIP";case 6:return"TRIANGLE_FAN";default:return"TRIANGLES"}},x3dom.glTF2Loader.prototype._isDefaultSampler=function(e){return 10497==e.wrapS&&10497==e.wrapT&&9729==e.magFilter&&9729==e.minFilter},x3dom.glTF2Loader.prototype._toAxisAngle=function(e){var t=[],i=(e=new x3dom.fields.Quaternion(e[0],e[1],e[2],e[3])).toAxisAngle();return t[0]=i[0].x,t[1]=i[0].y,t[2]=i[0].z,t[3]=i[1],t},x3dom.glTF2Loader.prototype._getGLTF=function(e,t){if(!t)return"string"==typeof e?JSON.parse(e):e;var i=0,o=new Uint32Array(e,i,3);if(1179937895==o[0]||2==o[1]){i+=12;var s=new Uint32Array(e,i,2);if(1313821514==s[1]){i+=8;var r=new Uint8Array(e,i,s[0]);i+=s[0];var n=new Uint32Array(e,i,2);if(5130562==n[1]){i+=8;var a=new Uint8Array(e,i,n[0]),d=x3dom.Utils.arrayBufferToJSON(r);return d.buffers[0].uri=x3dom.Utils.arrayBufferToObjectURL(a,"application/octet-stream"),this._convertBinaryImages(d,e,i),d}}}},x3dom.glTF2Loader.prototype._convertBinaryImages=function(e,t,i){if(null!=e.images)for(var o=0;o<e.images.length;o++){var s=e.images[o];if(null!=s.bufferView){var r=e.bufferViews[s.bufferView];r.byteOffset=r.byteOffset||0;var n=new Uint8Array(t,i+r.byteOffset,r.byteLength);s.uri=x3dom.Utils.arrayBufferToObjectURL(n,s.mimeType)}}},x3dom.glTF2Loader.prototype._animationDuration=function(e){for(var t=-1,i=0;i<e.channels.length;i++){var o=e.channels[i],s=e.samplers[o.sampler],r=this._gltf.accessors[s.input];t=Math.max(r.max[0],t)}return t},x3dom.DDSLoader={},x3dom.DDSLoader.load=function(e){return new Promise((function(t,i){var o=new XMLHttpRequest;o.open("GET",e,!0),o.responseType="arraybuffer",o.onload=function(){var e=x3dom.DDSLoader._read(o.response);e?t(e):i(e)},o.onerror=function(){i()},x3dom.RequestManager.addRequest(o)}))},x3dom.DDSLoader._read=function(e){if(!(void 0===e||e.byteLength<128)){var t={isCompressed:!1,isVolume:!1,isCubeMap:!1,targets:[],data:[]},i=new Uint32Array(e,0,32);if(t.header=x3dom.DDSLoader._readHeader(i),i=new Uint32Array(e,128,5),t.header10=x3dom.DDSLoader._readHeader10(t,i),542327876==t.header.dwMagic&&124==t.header.dwSize&&x3dom.DDSLoader._readFormat(t))return x3dom.DDSLoader._readMipmapCount(t),x3dom.DDSLoader._readType(t),this._readData(t,e),t}},x3dom.DDSLoader._readHeader=function(e){return{dwMagic:e[0],dwSize:e[1],dwFlags:x3dom.DDSLoader._readDDSFlags(e[2]),dwHeight:e[3],dwWidth:e[4],dwPitchOrLinearSize:e[5],dwDepth:e[6],dwMipMapCount:e[7],dwReserved1:"UNUSED",ddspf:{dwSize:e[19],dwFlags:x3dom.DDSLoader._readPFFlags(e[20]),dwFourCC:x3dom.DDSLoader.int32ToFourCC(e[21]),dwRGBBitCount:e[22],dwRBitMask:e[23],dwGBitMask:e[24],dwBBitMask:e[25],dwABitMask:e[26]},dwCaps:x3dom.DDSLoader._readCapsFlags(e[27]),dwCaps2:x3dom.DDSLoader._readCaps2Flags(e[28]),dwCaps3:"UNUSED",dwCaps4:"UNUSED",dwReserved2:"UNUSED"}},x3dom.DDSLoader._readHeader10=function(e,t){return"DX10"!=e.header.ddspf.dwFourCC?null:{dxgiFormat:t[0],resourceDimension:x3dom.DDSLoader._readResourceDimension(t[1]),miscFlags:x3dom.DDSLoader._readMiscFlags(t[2]),arraySize:t[3],miscFlags2:x3dom.DDSLoader._readMiscFlags2(t[4])}},x3dom.DDSLoader._readMipmapCount=function(e){e.numberOfMipmaps=e.header.dwFlags.DDSD_MIPMAPCOUNT?e.header.dwMipMapCount:1},x3dom.DDSLoader._readType=function(e){e.header.dwFlags.DDSD_DEPTH&&e.header.dwCaps2.DDSCAPS2_VOLUME?(e.type=32879,e.numberOfImages=e.header.dwCaps.DDSD_DEPTH):e.header.dwCaps2.DDSCAPS2_CUBEMAP?(e.type=34067,e.header.dwCaps2.DDSCAPS2_CUBEMAP_POSITIVEX&&e.targets.push(34069),e.header.dwCaps2.DDSCAPS2_CUBEMAP_NEGATIVEX&&e.targets.push(34070),e.header.dwCaps2.DDSCAPS2_CUBEMAP_POSITIVEY&&e.targets.push(34071),e.header.dwCaps2.DDSCAPS2_CUBEMAP_NEGATIVEY&&e.targets.push(34072),e.header.dwCaps2.DDSCAPS2_CUBEMAP_POSITIVEZ&&e.targets.push(34073),e.header.dwCaps2.DDSCAPS2_CUBEMAP_NEGATIVEZ&&e.targets.push(34074),e.numberOfImages=e.targets.length):(e.type=3553,e.targets.push(3553),e.numberOfImages=e.targets.length)},x3dom.DDSLoader._readDDSFlags=function(e){return{DDSD_CAPS:!!(1&e),DDSD_HEIGHT:!!(2&e),DDSD_WIDTH:!!(4&e),DDSD_PITCH:!!(8&e),DDSD_PIXELFORMAT:!!(4096&e),DDSD_MIPMAPCOUNT:!!(131072&e),DDSD_LINEARSIZE:!!(524288&e),DDSD_DEPTH:!!(8388608&e)}},x3dom.DDSLoader._readPFFlags=function(e){return{DDPF_ALPHAPIXELS:!!(1&e),DDPF_ALPHA:!!(2&e),DDPF_FOURCC:!!(4&e),DDPF_RGB:!!(64&e),DDPF_YUV:!!(512&e),DDPF_LUMINANCE:!!(131072&e)}},x3dom.DDSLoader._readCapsFlags=function(e){return{DDSCAPS_COMPLEX:!!(8&e),DDSCAPS_MIPMAP:!!(4194304&e),DDSCAPS_TEXTURE:!!(4096&e)}},x3dom.DDSLoader._readCaps2Flags=function(e){return{DDSCAPS2_CUBEMAP:!!(512&e),DDSCAPS2_CUBEMAP_POSITIVEX:!!(1024&e),DDSCAPS2_CUBEMAP_NEGATIVEX:!!(2048&e),DDSCAPS2_CUBEMAP_POSITIVEY:!!(4096&e),DDSCAPS2_CUBEMAP_NEGATIVEY:!!(8192&e),DDSCAPS2_CUBEMAP_POSITIVEZ:!!(16384&e),DDSCAPS2_CUBEMAP_NEGATIVEZ:!!(32768&e),DDSCAPS2_VOLUME:!!(131072&e)}},x3dom.DDSLoader._readResourceDimension=function(e){switch(e){case 0:return"D3D10_RESOURCE_DIMENSION_UNKNOWN";case 1:return"D3D10_RESOURCE_DIMENSION_BUFFER";case 2:return"D3D10_RESOURCE_DIMENSION_TEXTURE1D";case 3:return"D3D10_RESOURCE_DIMENSION_TEXTURE2D";case 4:return"D3D10_RESOURCE_DIMENSION_TEXTURE3D"}},x3dom.DDSLoader._readMiscFlags=function(e){return{D3D11_RESOURCE_MISC_GENERATE_MIPS:!!(1&e),D3D11_RESOURCE_MISC_SHARED:!!(2&e),D3D11_RESOURCE_MISC_TEXTURECUBE:!!(4&e),D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS:!!(16&e),D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS:!!(32&e),D3D11_RESOURCE_MISC_BUFFER_STRUCTURED:!!(64&e),D3D11_RESOURCE_MISC_RESOURCE_CLAMP:!!(128&e),D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX:!!(256&e),D3D11_RESOURCE_MISC_GDI_COMPATIBLE:!!(512&e),D3D11_RESOURCE_MISC_SHARED_NTHANDLE:!!(2048&e),D3D11_RESOURCE_MISC_RESTRICTED_CONTENT:!!(4096&e),D3D11_RESOURCE_MISC_RESTRICT_SHARED_RESOURCE:!!(8192&e),D3D11_RESOURCE_MISC_RESTRICT_SHARED_RESOURCE_DRIVER:!!(16384&e),D3D11_RESOURCE_MISC_GUARDED:!!(32768&e),D3D11_RESOURCE_MISC_TILE_POOL:!!(131072&e),D3D11_RESOURCE_MISC_TILED:!!(262144&e),D3D11_RESOURCE_MISC_HW_PROTECTED:!!(524288&e)}},x3dom.DDSLoader._readMiscFlags2=function(e){var t={};switch(e){case 0:case 1:case 2:case 3:case 4:t.alphaMode="DDS_ALPHA_MODE_UNKNOWN"}return t},x3dom.DDSLoader._readData=function(e,t,i,o){var s,r,n,a=e.header10?148:128;e.width=e.header.dwWidth,e.height=e.header.dwHeight,e.generateMipmaps=e.numberOfMipmaps<=1&&!e.isCompressed;for(var d=0;d<e.numberOfImages;d++){r=e.header.dwWidth,n=e.header.dwHeight,e.data[e.targets[d]]=[];for(var l=0;l<e.numberOfMipmaps;l++)0!=l&&(r=Math.max(.5*r,1),n=Math.max(.5*n,1)),e.isCompressed?(s=this._readCompressedData(t,r,n,a,e.blockSize),e.data[e.targets[d]][l]=s):(s=this._readUncompressedData(t,r,n,a,e.format),e.data[e.targets[d]][l]=s),a+=s.length*s.BYTES_PER_ELEMENT*e.format.bytesPerElementFactor}return e.format.overwriteType&&(e.format.type=e.format.overwriteType),e.format.overwriteInternalType&&(e.format.internal=e.format.overwriteInternalType),e},x3dom.DDSLoader._readCompressedData=function(e,t,i,o,s){var r=Math.max(1,parseInt((t+3)/4))*Math.max(1,parseInt((i+3)/4))*s;return new Uint8Array(e.slice(o,o+r))},x3dom.DDSLoader._readUncompressedData=function(e,t,i,o,s,r){if(s.bytesPerElementFactor=1,6406==s.internal)return new Uint8Array(e.slice(o,o+t*i));if(6409==s.internal)return new Uint8Array(e.slice(o,o+t*i));if(6410==s.internal)return new Uint8Array(e.slice(o,o+t*i*2));if(6407==s.internal)return x3dom.DDSLoader.R8G8B8_To_B8G8R8(new Uint8Array(e.slice(o,o+t*i*3)));if(36194==s.internal)return new Uint16Array(e.slice(o,o+t*i*2));if(6408==s.internal&&36193!=s.type&&5126!=s.type)return x3dom.DDSLoader.A8R8G8B8_To_A8B8G8R8(new Uint8Array(e.slice(o,o+t*i*4)));if(32854==s.internal)return x3dom.DDSLoader.A4R4G4B4_To_A4B4G4R4(new Uint16Array(e.slice(o,o+t*i*2)));if(32855==s.internal)return x3dom.DDSLoader.A1R5G5B5_To_A1B5G5R5(new Uint16Array(e.slice(o,o+t*i*2)));if(34842==s.internal||36193==s.type)return x3dom.caps.HFP_TEXTURES||2==x3dom.caps.WEBGL_VERSION?new Uint16Array(e.slice(o,o+t*i*4*2)):x3dom.caps.FP_TEXTURES?(s.overwriteType=5126,s.overwriteInternalType=2==x3dom.caps.WEBGL_VERSION?34836:6408,s.bytesPerElementFactor=.5,x3dom.DDSLoader.UI16_To_F32(new Uint16Array(e.slice(o,o+t*i*4*2)))):(s.overwriteType=5121,s.overwriteInternalType=6408,s.bytesPerElementFactor=2,x3dom.DDSLoader.UI16_To_UI8(new Uint16Array(e.slice(o,o+t*i*4*2))));if(34836==s.internal||5126==s.type){if(x3dom.caps.FP_TEXTURES||2==x3dom.caps.WEBGL_VERSION)return new Float32Array(e.slice(o,o+t*i*4*4))}else if(35898==s.internal)return new Uint8Array(e.slice(o,o+t*i*3))},x3dom.DDSLoader._readFormat=function(e){var t=e.header.ddspf;if(t.dwFlags.DDPF_FOURCC)if("DXT1"==t.dwFourCC)e.channelCount=3,e.blockSize=8,e.isCompressed=!0,e.format={internal:33776,format:6407,type:5121};else if("DXT3"==t.dwFourCC)e.channelCount=3,e.blockSize=16,e.isCompressed=!0,e.format={internal:33778,format:6408,type:5121};else if("DXT5"==t.dwFourCC)e.channelCount=4,e.blockSize=16,e.isCompressed=!0,e.format={internal:33779,format:6408,type:5121};else if("t"==t.dwFourCC)e.channelCount=4,2==x3dom.caps.WEBGL_VERSION?e.format={internal:34836,format:6408,type:5126}:e.format={internal:6408,format:6408,type:5126};else{if("q"!=t.dwFourCC&&"$"!=t.dwFourCC)return!1;e.channelCount=4,2==x3dom.caps.WEBGL_VERSION?e.format={internal:34842,format:6408,type:5131}:e.format={internal:6408,format:6408,type:36193}}else if(t.dwFlags.DDPF_RGB&&!t.dwFlags.DDPF_ALPHAPIXELS)if(e.channelCount=3,24==t.dwRGBBitCount&&16711680==t.dwRBitMask&&65280==t.dwGBitMask&&255==t.dwBBitMask)e.format={internal:6407,format:6407,type:5121};else{if(16!=t.dwRGBBitCount||63488!=t.dwRBitMask||2016!=t.dwGBitMask||31!=t.dwBBitMask)return!1;e.format={internal:36194,format:6407,type:33635}}else if(t.dwFlags.DDPF_RGB&&t.dwFlags.DDPF_ALPHAPIXELS)if(e.channelCount=4,32==t.dwRGBBitCount&&16711680==t.dwRBitMask&&65280==t.dwGBitMask&&255==t.dwBBitMask&&4278190080==t.dwABitMask)e.format={internal:6408,format:6408,type:5121};else if(16==t.dwRGBBitCount&&3840==t.dwRBitMask&&240==t.dwGBitMask&&15==t.dwBBitMask&&61440==t.dwABitMask)e.format={internal:32854,format:6408,type:32819};else{if(16!=t.dwRGBBitCount||31744!=t.dwRBitMask||992!=t.dwGBitMask||31!=t.dwBBitMask||32768!=t.dwABitMask)return!1;e.format={internal:32855,format:6408,type:32820}}else if(t.dwFlags.DDPF_LUMINANCE&&!t.dwFlags.DDPF_ALPHAPIXELS){if(8!=t.dwRGBBitCount||255!=t.dwRBitMask)return!1;e.format={internal:6409,format:6409,type:5121},e.channelCount=1}else if(t.dwFlags.DDPF_LUMINANCE&&t.dwFlags.DDPF_ALPHAPIXELS){if(16!=t.dwRGBBitCount||255!=t.dwRBitMask||65280!=t.dwABitMask)return!1;e.format={internal:6410,format:6410,type:5121},e.channelCount=2}else{if(!t.dwFlags.DDPF_ALPHA)return!1;if(8!=t.dwRGBBitCount||255!=t.dwABitMask)return!1;e.format={internal:6406,format:6406,type:5121},e.channelCount=1}return!0},x3dom.DDSLoader.int32ToFourCC=function(e){return String.fromCharCode(255&e,e>>8&255,e>>16&255,e>>24&255).replace(/[\x00]/g,"")},x3dom.DDSLoader.R8G8B8_To_B8G8R8=function(e){for(var t=new Uint8Array(e.length),i=0;i<e.length;i+=3)t[i]=e[i+1],t[i+1]=e[i+0],t[i+2]=e[i+2];return t},x3dom.DDSLoader.A8R8G8B8_To_A8B8G8R8=function(e){for(var t=new Uint8Array(e.length),i=0;i<e.length;i+=4)t[i]=e[i+2],t[i+1]=e[i+1],t[i+2]=e[i+0],t[i+3]=e[i+3];return t},x3dom.DDSLoader.UI16_To_UI8=function(e){for(var t=new Uint8Array(e.length),i=0;i<e.length;i+=4)t[i]=255*x3dom.DDSLoader.UI16_To_UI8_2(e[i]),t[i+1]=255*x3dom.DDSLoader.UI16_To_UI8_2(e[i+1]),t[i+2]=255*x3dom.DDSLoader.UI16_To_UI8_2(e[i+2]),t[i+3]=255*x3dom.DDSLoader.UI16_To_UI8_2(e[i+3]);return t},x3dom.DDSLoader.UI16_To_F32=function(e){for(var t=new Float32Array(e.length),i=0;i<e.length;i+=4)t[i]=x3dom.DDSLoader.UI16_To_F16(e[i]),t[i+1]=x3dom.DDSLoader.UI16_To_F16(e[i+1]),t[i+2]=x3dom.DDSLoader.UI16_To_F16(e[i+2]),t[i+3]=x3dom.DDSLoader.UI16_To_F16(e[i+3]);return t},x3dom.DDSLoader.UI16_To_F16=function(e){var t=e>>15&1,i=e>>10&1023,o=e&Math.pow(2,10)-1;return 0!==i?Math.pow(-1,t)*(1+o/Math.pow(2,10))*Math.pow(2,i-15):0===o?0:Math.pow(-1,t)*o/Math.pow(2,10)*Math.pow(2,-14)},x3dom.DDSLoader.UI16_To_UI8_2=function(e){var t=x3dom.DDSLoader.UI16_To_F16(e);return t/(t+1)},x3dom.DDSLoader.A4R4G4B4_To_A4B4G4R4=function(e){for(var t,i,o,s,r=new Uint16Array(e.length),n=0;n<e.length;n++)t=e[n]>>12&15,i=e[n]>>8&15,o=e[n]>>4&15,s=15&e[n],r[n]=i<<12&o<<8&s<<4&t;return r},x3dom.DDSLoader.A1R5G5B5_To_A1B5G5R5=function(e){for(var t,i,o,s,r=new Uint16Array(e.length),n=0;n<e.length;n++)t=e[n]>>15&1,i=e[n]>>10&31,o=e[n]>>5&95,s=95&e[n],r[n]=i<<11&o<<6&s<<1&t;return r},x3dom.VRControllerManager=function(){this.leftInline=void 0,this.leftTransform=void 0,this.rightInline=void 0,this.rightTransform=void 0,this.leftGamepadIdx=void 0,this.rightGamepadIdx=void 0,this.vrDisplay=void 0,this.wasPresenting=!1,this.controllers={"HTC Vive MV":{left:"https://x3dom.org/download/assets/vr/vive.glb",right:"https://x3dom.org/download/assets/vr/vive.glb",scaleFactor:new x3dom.fields.SFVec3f(40,40,40),offset:new x3dom.fields.SFVec3f,axesScale:[1,1]},"Oculus Oculus Rift CV1":{left:"https://x3dom.org/download/assets/vr/oculus-touch-left.glb",right:"https://x3dom.org/download/assets/vr/oculus-touch-right.glb",scaleFactor:new x3dom.fields.SFVec3f(39.5,39.5,39.5),offset:new x3dom.fields.SFVec3f,axesScale:[1,1]},"Oculus Go":{left:"https://x3dom.org/download/assets/vr/oculus-go.glb",right:"https://x3dom.org/download/assets/vr/oculus-go.glb",scaleFactor:new x3dom.fields.SFVec3f(1,1,1),offset:new x3dom.fields.SFVec3f(.2,-.3,-.3),axesScale:[1,-1]},"Emulated HTC Vive DVT":{left:"https://x3dom.org/download/assets/vr/vive.glb",right:"https://x3dom.org/download/assets/vr/vive.glb",scaleFactor:new x3dom.fields.SFVec3f(40,40,40),offset:new x3dom.fields.SFVec3f,axesScale:[1,1]},"WindowsMR DELL VISOR VR118":{left:"https://x3dom.org/download/assets/vr/microsoft-left.glb",right:"https://x3dom.org/download/assets/vr/microsoft-right.glb",scaleFactor:new x3dom.fields.SFVec3f(40,40,40),offset:new x3dom.fields.SFVec3f,axesScale:[1,1]}},this._addInlines(),this._addGamePadListeners()},x3dom.VRControllerManager.prototype._addGamePadListeners=function(){window.addEventListener("gamepadconnected",this._onGamePadConnected.bind(this)),window.addEventListener("gamepaddisconnected",this._onGamePadDisconnected.bind(this))},x3dom.VRControllerManager.prototype._onGamePadConnected=function(e){var t=e.gamepad;navigator.getVRDisplays().then(function(e){var i=e[0];if(i&&t.displayId==i.displayId){var o=this.controllers[i.displayName];if(!o)return;"left"==t.hand?(this.leftGamepadIdx=t.index,this.leftInline.setAttribute("url",o.left)):"right"==t.hand&&(this.rightGamepadIdx=t.index,this.rightInline.setAttribute("url",o.right,o.scaleFactor))}}.bind(this))},x3dom.VRControllerManager.prototype._onGamePadDisconnected=function(e){console.log(e)},x3dom.VRControllerManager.prototype._addInlines=function(){var e=document.querySelector("scene")||document.querySelector("Scene");e&&(this.leftTransform=document.createElement("matrixtransform"),this.leftInline=document.createElement("inline"),this.rightTransform=document.createElement("matrixtransform"),this.rightInline=document.createElement("inline"),this.leftInline.setAttribute("render","false"),this.rightInline.setAttribute("render","false"),this.leftTransform.appendChild(this.leftInline),this.rightTransform.appendChild(this.rightInline),e.appendChild(this.leftTransform),e.appendChild(this.rightTransform))},x3dom.VRControllerManager.prototype.fit=function(e,t){var i=e._scene._lastMin,o=e._scene._lastMax.subtract(i).multiply(.5).length(),s=e.vrLeftViewMatrix.e2(),r=Math.min(e._width/e._height,1),n=o/Math.tan(.5*Math.PI/2)/r;e._movement=s.multiply(-n)},x3dom.VRControllerManager.prototype.update=function(e,t){if(!t||t&&!t.isPresenting)this.wasPresenting&&(this.leftInline.setAttribute("render","false"),this.rightInline.setAttribute("render","false"),this.wasPresenting=!1);else{this.wasPresenting||(this.leftInline.setAttribute("render","true"),this.rightInline.setAttribute("render","true"),this.fit(e,t)),this.wasPresenting=!0;var i=navigator.getGamepads(),o={};if(null!=this.leftGamepadIdx&&i[this.leftGamepadIdx]){var s=i[this.leftGamepadIdx];o.left=s}if(null!=this.rightGamepadIdx&&i[this.rightGamepadIdx]){s=i[this.rightGamepadIdx];o.right=s}this.onUpdate(e,t,o)}},x3dom.VRControllerManager.prototype.onUpdate=function(e,t,i){var o=new x3dom.fields.SFMatrix4f,s=new x3dom.fields.SFMatrix4f,r=[0,0],n=this.controllers[t.displayName].axesScale;i.left&&(r[0]+=i.left.axes[0]*n[0],r[1]+=i.left.axes[1]*n[1],i.left.buttons[1].pressed&&this.fit(e)),i.right&&(r[0]+=i.right.axes[0]*n[0],r[1]+=i.right.axes[1]*n[1],i.right.buttons[1].pressed&&this.fit(e));var a=5*r[0],d=5*r[1],l=e.vrLeftViewMatrix.e2(),h=e.vrLeftViewMatrix.e0(),f=e._scene._lastMax.subtract(e._scene._lastMin).length();f=f<x3dom.fields.Eps?1:f,l=new x3dom.fields.SFVec3f(-l.x,-l.y,l.z).multiply(f*(d/e._height)),h=new x3dom.fields.SFVec3f(-h.x,-h.y,h.z).multiply(f*(a/e._width)),e._movement=e._movement.add(h).add(l),o=x3dom.fields.SFMatrix4f.translation(e._movement),e.vrLeftViewMatrix=e.vrLeftViewMatrix.mult(o).mult(s),e.vrRightViewMatrix=e.vrRightViewMatrix.mult(o).mult(s),this._updateControllerModels(e,t,i)},x3dom.VRControllerManager.prototype._updateControllerModels=function(e,t,i){if(!t||t&&!t.isPresenting)return this.leftInline.setAttribute("render","false"),void this.rightInline.setAttribute("render","false");if(this.leftInline.setAttribute("render","true"),this.rightInline.setAttribute("render","true"),i.left){var o=(a=i.left.pose).orientation?x3dom.fields.Quaternion.fromArray(a.orientation):new x3dom.fields.Quaternion,s=a.position?x3dom.fields.SFVec3f.fromArray(a.position):this.controllers[t.displayName].offset,r=this.controllers[t.displayName].scaleFactor;s=s.subtract(e._movement);var n=x3dom.fields.SFMatrix4f.fromRotationTranslationScale(o,s,r);this.leftTransform.setAttribute("matrix",n.toString())}if(i.right){var a;o=(a=i.right.pose).orientation?x3dom.fields.Quaternion.fromArray(a.orientation):new x3dom.fields.Quaternion,s=a.position?x3dom.fields.SFVec3f.fromArray(a.position):this.controllers[t.displayName].offset,r=this.controllers[t.displayName].scaleFactor;s=s.subtract(e._movement);n=x3dom.fields.SFMatrix4f.fromRotationTranslationScale(o,s,r);this.rightTransform.setAttribute("matrix",n.toString())}},x3dom.JSONParser=function(e){this.x3djsonNS="http://www.web3d.org/specifications/x3d-namespace"},x3dom.JSONParser.prototype.constructor=x3dom.JSONParser,x3dom.JSONParser.prototype.parseJavaScript=function(e){var t=this.CreateElement("X3D");return this.ConvertToX3DOM(e,"",t),t},x3dom.JSONParser.prototype.elementSetAttribute=function(e,t,i){"SON schema"===t||"ncoding"===t||"function"==typeof e.setAttribute&&e.setAttribute(t,i)},x3dom.JSONParser.prototype.ConvertChildren=function(e,t,i){var o;for(o in t)"object"==typeof t[o]&&(isNaN(parseInt(o))?this.ConvertObject(o,t,i,e.substr(1)):this.ConvertToX3DOM(t[o],o,i,e.substr(1)))},x3dom.JSONParser.prototype.CreateElement=function(e,t){var i=null;return void 0===this.x3djsonNS?i=document.createElement(e):null==(i=document.createElementNS(this.x3djsonNS,e))&&(console.error("Trouble creating element for",e),i=document.createElement(e)),void 0!==t&&this.elementSetAttribute(i,"containerField",t),i},x3dom.JSONParser.prototype.CDATACreateFunction=function(e,t,i){var o=i.trim().replace(/\\"/g,'\\"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&");do{o=(i=o).replace(/'([^'\r\n]*)\n([^']*)'/g,"'$1\\n$2'")}while(o!=i);var s="<script> <![CDATA[ "+o+" ]]> <\/script>",r=(new DOMParser).parseFromString(s,"application/xml").children[0].childNodes[1];t.appendChild(r)},x3dom.JSONParser.prototype.ConvertObject=function(e,t,i,o){var s;if(null!==t&&"object"==typeof t[e])if(e.startsWith("@"))this.ConvertToX3DOM(t[e],e,i);else if(e.startsWith("-"))this.ConvertChildren(e,t[e],i);else if("#comment"===e)for(var r in t[e])s=document.createComment(this.CommentStringToXML(t[e][r])),i.appendChild(s);else if("#sourceText"===e)this.CDATACreateFunction(document,i,t[e].join("\r\n")+"\r\n");else if("connect"===e||"fieldValue"===e||"field"===e||"meta"===e||"component"===e)for(var n in t[e])"object"==typeof t[e][n]&&(s=this.CreateElement(e,o),this.ConvertToX3DOM(t[e][n],n,s),i.appendChild(s),i.appendChild(document.createTextNode("\n")));else s=this.CreateElement(e,o),this.ConvertToX3DOM(t[e],e,s),i.appendChild(s),i.appendChild(document.createTextNode("\n"))},x3dom.JSONParser.prototype.CommentStringToXML=function(e){return e=e.replace(/\\\\/g,"\\")},x3dom.JSONParser.prototype.SFStringToXML=function(e){return e=(e=e.replace(/\\/g,"\\\\")).replace(/"/g,'\\"')},x3dom.JSONParser.prototype.JSONStringToXML=function(e){return e=(e=e.replace(/\\/g,"\\\\")).replace(/\n/g,"\\n")},x3dom.JSONParser.prototype.ConvertToX3DOM=function(e,t,i,o){var s,r=[],n=!1,a=!1;for(s in e)if(n=!isNaN(parseInt(s)))"number"==typeof e[s]?r.push(e[s]):"string"==typeof e[s]?(r.push(e[s]),a=!0):"boolean"==typeof e[s]?r.push(e[s]):"object"==typeof e[s]?this.ConvertToX3DOM(e[s],s,i):void 0===e[s]||console.error("Unknown type found in array "+typeof e[s]);else if("object"==typeof e[s])if("X3D"===s)this.ConvertToX3DOM(e[s],s,i);else if("-skin"===s||"-skeleton"===s||"-value"===s){var d=e[s][0];for(var l in d)d[l]["@containerField"]=s.substr(1),console.log(d[l]),this.ConvertObject(s,e,i,d[l]["@containerField"])}else 0===s.indexOf("HAnim")&&"HAnimHumanoid"!==s&&void 0!==e[s]["@USE"]?(e[s]["@containerField"]=s.substr(5).toLowerCase()+"s",this.ConvertObject(s,e,i,e[s]["@containerField"])):this.ConvertObject(s,e,i);else if("number"==typeof e[s])this.elementSetAttribute(i,s.substr(1),e[s]);else if("string"==typeof e[s])if("#comment"!==s)this.elementSetAttribute(i,s.substr(1),this.JSONStringToXML(e[s]));else{var h=document.createComment(this.CommentStringToXML(e[s]));i.appendChild(h)}else"boolean"==typeof e[s]?this.elementSetAttribute(i,s.substr(1),e[s]):void 0===e[s]||(console.error("Unknown type found in object "+typeof e[s]),console.error(e));if(n&&t.startsWith("@"))if(a){for(var f in r)r[f]=this.SFStringToXML(r[f]);this.elementSetAttribute(i,t.substr(1),'"'+r.join('" "')+'"')}else this.elementSetAttribute(i,t.substr(1),r.join(" "));return i},x3dom.PROTOS=function(){this.protos={},this.names={},this.protoField={},this.scriptField={},this.interfaceField={},this.envField={},this.scopecount=0,this.privatescope=[],this.defs={},this.founddef=null,this.SFNodes={"-appearance":1,"-body":1,"-child":1,"-collidable":1,"-collider":1,"-color":1,"-composableRenderStyle":1,"-coord":1,"-emitter":1,"-fillProperties":1,"-fogCoord":1,"-fontStyle":1,"-geometry":1,"-geoOrigin":1,"-layout":1,"-lineProperties":1,"-massDensityModel":1,"-material":1,"-metadata":1,"-normal":1,"-nurbsCurve":1,"-nurbsCurve2D":1,"-pickingGeometry":1,"-renderStyle":1,"-shape":1,"-source":1,"-texCoord":1,"-texCoordNurbs":1,"-texCoordRamp":1,"-texture":1,"-texture2D":1,"-texture2DMulti":1,"-texture3D":1,"-textureProperties":1,"-textureTransform":1,"-transferFunction":1,"-viewport":1}},x3dom.PROTOS.prototype={flattenerArray:function(e,t){var i=[],o=0;for(var s in e){var r=this.flattener(e[s],i,e.length);if(Array.isArray(r)){for(var n in r)i[parseInt(s)+o+parseInt(n)]=r[n];o+=r.length-1}else i[parseInt(s)+o]=r}return i},flattenerObject:function(e,t,i){var o={};for(var s in e){var r=this.flattener(e[s],t,i);if(Array.isArray(r))if(this.SFNodes[s]){if(o[s]=r[0],r.length>1){t[i]={Switch:{"@whichChoice":-1,"-children":[{Group:{"-children":[]}}]}};for(var n=1;n<r.length;n++)t[i].Switch["-children"][0].Group["-children"][n-1]=r[n]}}else o[s]=r;else this.SFNodes[s]&&"object"==typeof r&&r["#comment"]?o["-children"]?(o[s]={},o["-children"].push(r)):(o[s]={},o["-children"]=[r]):o[s]=r}return o},flattener:function(e,t,i){if("object"==typeof e){if(Array.isArray(e))var o=this.flattenerArray(e,t);else o=this.flattenerObject(e,t,i);return o}return e},pushScope:function(e){this.privatescope.push(e)},popScope:function(){this.privatescope.pop()},saveDef:function(e){return this.defs[e]=this.getScope(),this.getScope(e)},getDef:function(e){return this.defs[e]},getField:function(e,t){return e+"_"+t},getScope:function(e){var t,i=(t=e?this.defs[e]?this.defs[e]+"_"+e:e:this.privatescope.join("_")).lastIndexOf("DECL");return i>0&&(t=t.substring(i)),t},scopeLength:function(){return this.privatescope.length},upScope:function(e){return this.privatescope.slice(0,this.privatescope.length-e).join("_")},setValueFromInterface:function(e,t,i){var o=this.getInterface(e),s="@";if(void 0!==o&&void 0!==o[0]&&(s=o[0].substr(0,1)),"@"===s&&"children"===i&&(s="-"),"-"===s&&"value"===i&&(s="@"),i=s+i,void 0!==o&&void 0!==o[1]&&void 0!==o[0]&&void 0!==o[1][o[0]]){var r=o[1][o[0]];return Array.isArray(r)&&"SFNode"===o[1]["@type"]&&"-children"!==i&&(console.error("SFNode is array, reducing",r),r=r[0]),Array.isArray(r)||"-children"!==i||(i="@value"),t[i]=r,[o[1]["@type"],o[2]]}},getObjectField:function(e,t){var i="value";for(var o in 1===t.indexOf("FNode")&&(i="children"),e)"@value"!==o&&"-children"!==o||(i=o.substr(1));return i},findFieldByName:function(e,t){for(var i in e){var o=e[i];if(o["@name"]===t)return o}throw"Can't find "+t},getScriptFieldFieldTypeFieldByNameAttribute:function(e,t){var i=this.findFieldByName(e,t),o=i["@name"],s=i["@type"];return[i,o,s,t=this.getObjectField(i,s)]},getScriptFieldFieldTypeField:function(e,t){var i=e[t],o=i["@name"],s=i["@type"];return[i,o,s,this.getObjectField(i,s)]},setScriptFields:function(e,t){var i=this.getScope();for(var o in e){var s=this.getScriptFieldFieldTypeField(e,o),r=s[0],n=s[1],a=s[2],d=s[3],l=this.setValueFromInterface(n,r,d);this.setScriptField(i,n,r,d,a,t),void 0!==l&&this.setScriptField(l[1],n,r,d,a,t)}},setScriptField:function(e,t,i,o,s,r){void 0===this.scriptField[this.getField(e,t)]&&(this.scriptField[this.getField(e,t)]=[]),this.scriptField[this.getField(e,t)][this.scriptField[this.getField(e,t)].length]=[i,o,s,r]},setEnv:function(e,t,i,o,s,r){var n=this.getInterface(t);void 0!==n&&(e=n[2]),void 0===this.envField[this.getField(e,t)]&&(this.envField[this.getField(e,t)]=[]),this.envField[this.getField(e,t)][this.envField[this.getField(e,t)].length]=[i,o,s,r]},getEnv:function(e,t){return this.envField[this.getField(e,t)]},setConnectField:function(e,t,i,o,s,r){void 0===this.protoField[this.getField(e,t)]&&(this.protoField[this.getField(e,t)]=[]),this.protoField[this.getField(e,t)][this.protoField[this.getField(e,t)].length]=[i,o,s,r]},setConnectFields:function(e,t,i){var o=e["@DEF"],s=this.saveDef(o),r=e[t].connect,n=this.getScope();for(var a in r){var d=r[a];if(d){var l=this.getScope(d["@protoField"]),h=d["@nodeField"],f=this.setValueFromInterface(l,i,h),u=void 0;void 0!==f?(u=f[0],this.setEnv(n,l,i,h,u,s),this.setConnectField(n,l,i,h,u,s),this.setConnectField(f[1],l,i,h,u,s)):(this.setEnv(n,l,i,h,u,s),this.setConnectField(n,l,i,h,u,s))}}},setScriptConnectFields:function(e,t,i,o){var s=t[i].connect,r=this.getScope(),n=t["@DEF"];o.field=this.realPrototypeExpander(e,t.field,!0);o["@DEF"];for(var a in s){var d=s[a];if(d){var l=this.getScope(d["@protoField"]),h=d["@nodeField"],f=this.getScriptFieldFieldTypeFieldByNameAttribute(o.field,h);d=f[0];f[1];var u=f[2];h=f[3];var c=this.setValueFromInterface(l,d,h);void 0!==c?(u=c[0],this.setScriptField(r,l,d,h,u,n),this.setScriptField(c[1],l,d,h,u,n)):this.setScriptField(r,l,d,h,u,n)}}},getInterface:function(e){for(var t=0;t<this.scopeLength();t++){var i=this.upScope(t);if(!i)break;var o=this.interfaceField[this.getField(i,e)];if(o)return o}},setInterface:function(e,t){var i=this.getScope();this.interfaceField[this.getField(i,e["@name"])]=[t,e,i]},clearScope:function(e,t){var i=this.getScope();delete this.scriptField[this.getField(i,e)],delete this.protoField[this.getField(i,e)],this.zap(e,t)},extractConnectedDef:function(e,t){var i;for(var o in this.scriptField[this.getField(e,t)])if(void 0===i){var s=this.scriptField[this.getField(e,t)][o];if(void 0!==s&&void 0!==s[3]){var r=this.getField(e,s[3]);-1==r.indexOf("DECL",1)&&(i=[r,s[0]["@name"]])}}if(void 0===i)for(var n in this.protoField[this.getField(e,t)]){var a=this.protoField[this.getField(e,t)][n];void 0!==a&&(i=[a[3],a[1]])}if(void 0===i)for(var d in this.protoField[this.getField(e,"__DEF_FIELD__")]){var l=this.protoField[this.getField(e,"__DEF_FIELD__")][d];void 0!==l&&(i=[l[3],t])}return void 0===i&&(i=[e,t]),i},setObjectValues:function(e,t,i,o){var s=!1;for(var r in this.protoField[this.getField(e,t)]){var n=this.protoField[this.getField(e,t)][r];void 0!==n&&(this.setObjectValue(e,t,n,i,o),s=!0)}for(var a in this.scriptField[this.getField(e,t)]){var d=this.scriptField[this.getField(e,t)][a];void 0!==d&&(this.setObjectValue(e,t,d,i,o),s=!0)}if(!s)for(var l=0;l<this.scopeLength();l++){var h=this.upScope(l);if(!h)break;var f=this.getEnv(h,t);for(var u in f){var c=f[u];void 0!==c&&c[3].indexOf(h)===c[3].lastIndexOf(h)&&this.setObjectValue(h,c[1],c,i,o)}}},setObjectValue:function(e,t,i,o,s){Array.isArray(s)&&void 0!==i[2]&&("SFNode"===i[2]?s=s[0]:i[2]);var r=i[1].substr(0,1);"@"===(r="-"!==r&&"@"!==r?o.substr(0,1):"")&&"children"===i[1]&&(r="-"),"-"===r&&"value"===i[1]&&(r="@"),Array.isArray(s)||"children"!==i[1]||(s=[s]),i[0][r+i[1]]=s},zap:function(e,t){var i;if("object"==typeof t)for(i in t)if("is"===i.toLowerCase()){var o=t[i].connect;for(var s in o){var r=o[s];r&&r["@protoField"]===e&&delete o[s]}}else this.zap(e,t[i]);return t},zapIs:function(e){var t;if("object"==typeof e)for(t in e)"is"===t.toLowerCase()?delete e[t]:this.zapIs(e[t]);return e},prototypeExpander:function(e,t){return t},readCode:function(e,t,i,o,s,r){void 0!==e&&(r[s]["#sourceText"]=e.split(/\r?\n/),delete r[s]["@url"])},handleScript:function(e,t,i,o){o[i]=this.realPrototypeExpander(e,t[i],!0),this.setScriptFields(o[i].field,o[i]["@DEF"]);var s=o[i]["@url"];this.loadURLs(e,s,this.readCode,null,(function(){}),i,o)},handleProtoDeclare:function(e,t,i){var o=t[i]["@name"],s=t[i]["@DEF"];return this.protos[o]=t[i],this.saveDef(s),void 0!==t[i]["@appinfo"]&&(this.protos[o]["@appinfo"]=t[i]["@appinfo"]),void 0!==t[i]["@documentation"]&&(this.protos[o]["@documentation"]=t[i]["@documentation"]),this.pushScope("DECL"+o),this.names[s]=o,this.realPrototypeExpander(e,t[i],!1),this.popScope(),t},handleProtoInterface:function(e,t,i){var o=t[i].field;for(var s in o){var r=o[s];void 0!==r["@value"]?this.setInterface(r,"@value"):void 0!==r["-children"]?this.setInterface(r,"-children"):this.setInterface(r)}return t},handleProtoInstance:function(e,t,i){var o=t[i]["@name"],s=t[i]["@DEF"],r=t[i]["@USE"];this.names[s]=o,void 0===o&&void 0!==r&&(o=this.names[r]),this.pushScope("DECL"+o);var n,a={};if(void 0===s&&void 0===r&&(s="INSTANCE"),this.getDef(s)&&void 0===r&&(this.scopecount+=1e3,s+=""+this.scopecount),void 0!==s){this.saveDef(s);this.pushScope(s)}if(void 0===this.protos[o]||void 0===this.protos[o].ProtoBody)console.error("ProtoBody undefined for",o);else{var d=this.protos[o].ProtoBody["-children"];for(var l in d){var h=d[l];for(var f in h)if(void 0===n&&(n=h[f]["@DEF"],void 0!==r)){this.saveDef(r);this.pushScope(r)}}a=JSON.parse(JSON.stringify(d))}for(var u=a;Array.isArray(u)&&null!==u[0]&&void 0!==u[0];)u=u[0];if(void 0!==r&&"object"==typeof u){(c={})[f]={},c[f]["@USE"]=this.getScope(),void 0!==n&&this.popScope()}else{var c=this.realPrototypeExpander(e,a,!1),_=t[i].fieldValue;for(var m in _){var p=_[m],x=p["@name"],g="@value",v=p[g];for(var y in p)"@name"!==y&&(v=p[g=y],this.pushScope("FIELD"+x),"object"==typeof u&&void 0!==u[f]&&(u[f]["@DEF"]=this.getScope()),v=this.realPrototypeExpander(e,v,!1),this.popScope(),this.getInterface(x),this.setObjectValues(this.getScope(),x,g,v))}}return void 0!==r&&this.popScope(),void 0!==s&&this.popScope(),this.popScope(),c},realPrototypeExpander:function(e,t,i){if("object"==typeof t){var o=null;for(var s in o=Array.isArray(t)?[]:{},t){var r=s.toLowerCase();if("script"===r)this.handleScript(e,t,s,o);else if("protodeclare"===r)this.handleProtoDeclare(e,t,s);else if("protointerface"===r)this.handleProtoInterface(e,t,s);else if("protobody"===r)this.realPrototypeExpander(e,t[s],i);else if("protoinstance"===r)o=this.handleProtoInstance(e,t,s);else if("connect"===r)this.realPrototypeExpander(e,t[s],i);else if("fieldvalue"===r)this.realPrototypeExpander(e,t[s],i);else if("field"===r)o[s]=this.realPrototypeExpander(e,t[s],i);else if("@value"===r)o[s]=this.realPrototypeExpander(e,t[s],i);else if("-children"===r)o[s]=this.realPrototypeExpander(e,t[s],i);else if("is"===r)i?this.setScriptConnectFields(e,t,s,o):this.setConnectFields(t,s,o),this.realPrototypeExpander(e,t[s],i);else if("route"===r){o[s]={};var n=this.extractConnectedDef(this.getScope(t[s]["@fromNode"]),t[s]["@fromField"]);o[s]["@fromNode"]=n[0],o[s]["@fromField"]=n[1];var a=this.extractConnectedDef(this.getScope(t[s]["@toNode"]),t[s]["@toField"]);o[s]["@toNode"]=a[0],o[s]["@toField"]=a[1]}else"@name"===r?o[s]=t[s]:"@def"===r?(o[s]=this.saveDef(t[s]),this.setConnectField(this.getScope(),"__DEF_FIELD__",o,t[s],"SFString",o[s])):o[s]="@use"===r?this.getScope(t[s]):this.realPrototypeExpander(e,t[s],i)}return o}return t},searchForProtoDeclare:function(e,t){var i,o;if("object"==typeof e)for(i in e)"ProtoDeclare"===i&&(e[i]["@name"]===t&&(o=e),void 0===o&&null===this.founddef&&(this.founddef=e)),void 0===o&&(o=this.searchForProtoDeclare(e[i],t));return o},searchAndReplaceProto:function(e,t,i,o,s,r){var n=this.searchForProtoDeclare(t,i);if(void 0===n&&(n=o),null===n||void 0===n.ProtoDeclare)console.error("ProtoDeclare is still null or undefined",e,i,JSON.stringify(t));else{var a=s["@name"],d=s["@appinfo"],l=s["@description"];n.ProtoDeclare["@name"]=a,n.ProtoDeclare["@appinfo"]=d,n.ProtoDeclare["@description"]=l}r(n)},loadedProto:function(e,t,i,o,s,r){if(void 0!==e)try{this.founddef=null;var n={};try{n=JSON.parse(e),s.searchAndReplaceProto(o,n,t,s.founddef,i,r)}catch(n){if("function"==typeof DOM2JSONSerializer)try{var a=(new DOM2JSONSerializer).serializeToString(null,e.firstElementChild,o,mapToMethod,fieldTypes);s.searchAndReplaceProto(o,JSON.parse(a),t,s.founddef,i,r)}catch(e){"function"==typeof alert&&alert(e),console.error("Convert failed",e)}else console.error("Did not convert XML to JSON.  Oops!")}}catch(e){console.error("Failed to parse JSON in ",o,e)}else console.error("data is undefined for file",o)},doLoad:function(e,t,i,o,s,r){var n=r["@name"],a=t.indexOf("#"),d=n;a>=0&&(d=t.substring(a+1));try{i.loadedProto(e,d,r,t,i,(function(e){o(s,e,i)}))}catch(e){console.error("Error searching for proto",e)}},processURLs:function(e,t){var i;for(i in e){if(0===e[i].indexOf("http://")||0===e[i].indexOf("https://"));else if(0===e[i].indexOf("urn:web3d:media:textures/panoramas/")){var o=e[i].lastIndexOf("/");o>0&&(e[i]="examples/Basic/UniversalMediaPanoramas/"+e[i].substring(o+1))}else{var s=e[i].indexOf("#"),r=t.lastIndexOf("/"),n=t;for(r>=0&&(n=t.substring(0,r));e[i].startsWith("../");){e[i]=e[i].substr(3);r=n.lastIndexOf("/");n=r>=0?n.substring(0,r):""}e[i]=0==s?t+e[i]:n+"/"+e[i]}var a=e[i].lastIndexOf("#"),d="";a>=0&&(d=e[i].substring(a),e[i]=e[i].substring(0,a));var l=e[i].lastIndexOf(".wrl");l===e[i].length-4&&(e[i]=e[i].substring(0,l)+".json"+d);var h=e[i].lastIndexOf(".wrz");h===e[i].length-4&&(e[i]=e[i].substring(0,h)+".json"+d)}return e},loadURLs:function(e,t,i,o,s,r,n){if(void 0!==t)for(var a in t=this.processURLs(t,e))try{!function(t){var a=t.indexOf("://"),d="file",l="localhost",h="/"+e;if(a>0){d=t.substring(0,a);var f=t.indexOf("/",a+3);l=t.substring(a+3,f),h=t.substring(f)}if("http"===d){if("undefined"!=typeof http)http.get({host:l,path:h},(function(e){var a="";e.on("data",(function(e){a+=e})),e.on("end",(function(){i(a,t,o,s,r,n)}))}));else if((c=new XMLHttpRequest).open("GET",t,!1),c.send(null),200===c.status){var u=c.responseText;i(u,t,o,s,r,n)}}else if("https"===d){if("undefined"!=typeof https)https.get({host:l,path:h},(function(e){var a="";e.on("data",(function(e){a+=e})),e.on("end",(function(){i(a,t,o,s,r,n)}))}));else if((c=new XMLHttpRequest).open("GET",t,!1),c.send(null),200===c.status){u=c.responseText;i(u,t,o,s,r,n)}}else if("undefined"==typeof fs||d.startsWith("http")){var c;if((c=new XMLHttpRequest).open("GET",t,!1),c.send(null),200===c.status){u=c.responseText;i(u,t,o,s,r,n)}else console.error("Didn't load",t,".  No file system or http request.")}else{var _=t.indexOf("#");_>0&&(t=t.substring(0,_));try{var u=fs.readFileSync(t);i(u.toString(),t,o,s,r,n)}catch(e){var m=t;m.endsWith(".json")&&(m=m.substring(0,m.lastIndexOf("."))+".x3d","function"==typeof runAndSend&&runAndSend(["---silent",m],(function(e){u=JSON.stringify(e),i(u,m,o,s,r,n)})))}}}(t[a])}catch(e){console.error(e)}},load:function(e,t,i,o,s){var r=i[e],n=r["@url"];this.loadURLs(t,n,o.doLoad,o,s,e,r)},externalPrototypeExpander:function(e,t){if("object"==typeof t){var i=null;for(var o in i=Array.isArray(t)?[]:{},t)"ExternProtoDeclare"===o?this.load(o,e,t,this,(function(t,o,s){null!=o&&void 0!==o&&(i.ProtoDeclare=s.externalPrototypeExpander(e,o).ProtoDeclare)})):i[o]=this.externalPrototypeExpander(e,t[o]);for(var s=Object.keys(t).length;s>Object.keys(i).length+1;);return setTimeout((function(){}),50),i}return t}},x3dom.protoExpander=new x3dom.PROTOS,x3dom.ProtoDeclaration=function(e,t,i,o,s,r){this._nameSpace=e,this.name=t,this._protoBody=i||null,this.fields=o||[],this.isExternProto=s||!1,this.url=r||[],this.needsLoading=!0,this.instanceQueue=[]},x3dom.ProtoDeclaration.prototype.registerNode=function(){var e=this;x3dom.registerNodeType(e.name,"Core",defineClass(x3dom.nodeTypes.X3DNode,(function(t){x3dom.nodeTypes[e.name].superClass.call(this,t),this._cf_hash={},e.fields.forEach((function(i){if(i.dataType.endsWith("ode")){t&&t.xmlNode&&0==t.xmlNode.querySelectorAll("[containerField='"+i.name+"']").length&&i.cfValue.forEach((function(e){t.xmlNode.appendChild(e.cloneNode(!0))}));var o=x3dom.nodeTypes.X3DNode,s=e._protoBody._ISRoutes;if(i.name in s){var r=s[i.name][0],n=r.nodeField,a=e._protoBody.querySelector("[DEF="+r.nodeDEF+"]"),d=a.localName.toLowerCase();if(d in x3dom.nodeTypesLC){var l={doc:t.doc,runtime:t.runtime,xmlNode:a.cloneNode(!0),nameSpace:t.nameSpace},h=new x3dom.nodeTypesLC[d](l);n in h._cf&&(o=h._cf[n].type)}}else x3dom.debug.logWarning(e.name+" Proto: field without IS connection - "+i.name);this["addField_"+i.dataType](i.name,o),this._cf_hash[i.name]="trigger"}else t&&t.xmlNode&&!t.xmlNode.hasAttribute(i.name)&&i.value&&t.xmlNode.setAttribute(i.name,i.value),this["addField_"+i.dataType](t,i.name,i.value)}),this);var i="protoNS";t.xmlNode.hasAttribute("DEF")&&(i=t.xmlNode.getAttribute("DEF")+"NS"),this.innerNameSpace=new x3dom.NodeNameSpace(i,t.doc),this.innerNameSpace.setBaseURL(t.nameSpace.baseURL+e.name),e._nameSpace.addSpace(this.innerNameSpace),e._nameSpace.protos.forEach((function(e){this.innerNameSpace.protos.push(e)}),this),this.nodes=[],this.protoBodyClone=e._protoBody.cloneNode(!0),this.declaration=e,this.isProtoInstance=!0,this._changing=!1,this._externTries=0,this._maxTries=5}),{nodeChanged:function(e){if(!this._changing){this._changing=!0;var t=this.protoBodyClone;t.querySelectorAll(":scope > *").forEach((function(e){var i=e.localName.toLowerCase();"protodeclare"==i?this.innerNameSpace.protoDeclare(e):"externprotodeclare"==i?this.innerNameSpace.externProtoDeclare(e):"protoinstance"==i&&this.innerNameSpace.protoInstance(e,t)}),this);var i,o=this.protoBodyClone.childNodes;for(i=0;i<o.length;i++){var s=this.innerNameSpace.setupTree.call(this.innerNameSpace,o[i],this);null!=s&&this.nodes.push(s)}this.typeNode=this.nodes[0],this.helperNodes=this.nodes.slice(1);var r,n=this._xmlNode.attributes;for(i=0;i<n.length;i++)(r=n[i]).name.startsWith("on")&&this.typeNode._xmlNode.setAttribute(r.name,r.value);for(var a in this._vf)this.fieldChanged(a);for(a in this._cf){"nodes"in this._cf[a]&&this._cf_hash[a]===this._get_cf_hash(a)&&a!=e||this.fieldChanged(a)}for(a in this._vf){a in this.declaration._protoBody._ISRoutes&&this._setupFieldWatchers(a)}for(a in this._changing=!1,this._cf)"nodes"in this._cf[a]&&(this._cf_hash[a]=this._get_cf_hash(a))}},fieldChanged:function(e){try{var t=this.declaration._protoBody._ISRoutes;if(!(e in t))return;t[e].forEach((function(t){var i=this.innerNameSpace.defMap[t.nodeDEF];if(null!=i){this._externTries=0;var o=this._normalizeName(t.nodeField,i);if(e in this._vf)i._vf[o]=this._vf[e],i.fieldChanged(o);else if(e in this._cf){i._cf[o]=this._cf[e];var s=[];if("MFNode"==i._cfFieldTypes[o]?s=this._cf[e].nodes:"SFNode"==i._cfFieldTypes[o]&&this._cf[e].node?s=[this._cf[e].node]:x3dom.debug.logWarning("Unexpected field type: "+i._cfFieldTypes[o]),i._childNodes.forEach((function(e){i.removeChild(e,o,"force")})),s.forEach((function(e){i.addChild(e,o)})),"MFNode"==i._cfFieldTypes[o])for(var r=0;r<s.length;r++)for(var n=s[r],a=s.length-1;a>r;a--)n==s[a]&&s.splice(a,1);i.nodeChanged(o)}}else{if("protoinstance"==this.protoBodyClone.querySelector("[DEF="+t.nodeDEF+"]").tagName.toLowerCase()&&this._externTries++<this._maxTries){x3dom.debug.logWarning(" ExternProto instance attempt: "+this._externTries);setTimeout(this.fieldChanged.bind(this),1e3,e)}}}),this)}catch(e){x3dom.debug.logWarning("Proto warning: "+e)}},_normalizeName:function(e,t){return e in t._vf?e:e.replace(/^set_/,"").replace(/_changed$/,"")},_setupFieldWatchers:function(e){this.declaration._protoBody._ISRoutes[e].forEach((function(t){var i=this.innerNameSpace.defMap[t.nodeDEF];if(null!=i){var o=this._normalizeName(t.nodeField,i);i._fieldWatchers[o]||(i._fieldWatchers[o]=[]),i._fieldWatchers[o].push(this.postMessage.bind(this,e))}else{if("protoinstance"==this.protoBodyClone.querySelector("[DEF="+t.nodeDEF+"]").tagName.toLowerCase()&&this._externTries++<this._maxTries){x3dom.debug.logWarning(" retrying ExternProto: "+this._externTries);setTimeout(this._setupFieldWatchers.bind(this),1e3,e)}}}),this)},_get_cf_hash:function(e){return this._cf[e].nodes.length}}))},x3dom.shader={},x3dom.shader.PICKING="picking",x3dom.shader.PICKING_24="picking24",x3dom.shader.PICKING_ID="pickingId",x3dom.shader.PICKING_COLOR="pickingColor",x3dom.shader.PICKING_TEXCOORD="pickingTexCoord",x3dom.shader.FRONTGROUND_TEXTURE="frontgroundTexture",x3dom.shader.BACKGROUND_TEXTURE="backgroundTexture",x3dom.shader.BACKGROUND_SKYTEXTURE="backgroundSkyTexture",x3dom.shader.BACKGROUND_CUBETEXTURE="backgroundCubeTexture",x3dom.shader.BACKGROUND_CUBETEXTURE_DDS="backgroundCubeTextureDDS",x3dom.shader.BLUR="blur",x3dom.shader.DEPTH="depth",x3dom.shader.NORMAL="normal",x3dom.shader.TEXTURE_REFINEMENT="textureRefinement",x3dom.shader.SSAO="ssao",x3dom.shader.material=function(){return"uniform vec3  diffuseColor;\nuniform vec3  specularColor;\nuniform vec3  emissiveColor;\nuniform float shininess;\nuniform float transparency;\nuniform float ambientIntensity;\n"},x3dom.shader.physicalMaterial=function(){return"uniform vec3  baseColorFacor;\nuniform vec3  emissiveFactor;\nuniform float metallicFactor;\nuniform float roughnessFactor;\n"},x3dom.shader.twoSidedMaterial=function(){return"uniform vec3  backDiffuseColor;\nuniform vec3  backSpecularColor;\nuniform vec3  backEmissiveColor;\nuniform float backShininess;\nuniform float backTransparency;\nuniform float backAmbientIntensity;\n"},x3dom.shader.fog=function(){return"uniform vec3  fogColor;\nuniform float fogType;\nuniform float fogRange;\nvarying vec3 fragEyePosition;\nfloat calcFog(in vec3 eye) {\n   float f0 = 0.0;\n   if(fogType == 0.0) {\n       if(length(eye) < fogRange){\n           f0 = (fogRange-length(eye)) / fogRange;\n       }\n   }else{\n       if(length(eye) < fogRange){\n           f0 = exp(-length(eye) / (fogRange-length(eye) ) );\n       }\n   }\n   f0 = clamp(f0, 0.0, 1.0);\n   return f0;\n}\n"},x3dom.shader.clipPlanes=function(e){var t,i="";for(t=0;t<e;t++)i+="uniform vec4 clipPlane"+t+"_Plane;\n",i+="uniform float clipPlane"+t+"_CappingStrength;\n",i+="uniform vec3 clipPlane"+t+"_CappingColor;\n";for(i+="vec3 calculateClipPlanes() {\n",t=0;t<e;t++)i+="vec4 clipPlane"+t+";\n",i+="if(fragEyeIdx == 1.0){\n",i+="    clipPlane"+t+" = clipPlane"+t+"_Plane * viewMatrixInverse2;\n",i+="}else{\n",i+="    clipPlane"+t+" = clipPlane"+t+"_Plane * viewMatrixInverse;\n",i+="}\n",i+="float dist"+t+" = dot(fragPosition, clipPlane"+t+");\n";for(i+="    if( ",t=0;t<e;t++)0!=t&&(i+=" || "),i+="dist"+t+" < 0.0";for(i+=" ) ",i+="{ discard; }\n",t=0;t<e;t++)i+="    if( abs(dist"+t+") < clipPlane"+t+"_CappingStrength ) ",i+="{ return clipPlane"+t+"_CappingColor; }\n";return i+="    return vec3(-1.0, -1.0, -1.0);\n",i+="}\n"},x3dom.shader.gammaCorrectionDecl=function(e){var t="";return"none"===e.GAMMACORRECTION||("fastlinear"===e.GAMMACORRECTION?(t+="vec4 gammaEncode(vec4 color){\n  vec4 tmp = sqrt(color);\n  return vec4(tmp.rgb, color.a);\n}\n",t+="vec4 gammaDecode(vec4 color){\n  vec4 tmp = color * color;\n  return vec4(tmp.rgb, color.a);\n}\n",t+="vec3 gammaEncode(vec3 color){\n  return sqrt(color);\n}\n",t+="vec3 gammaDecode(vec3 color){\n  return (color * color);\n}\n"):(t+="const vec4 gammaEncode4Vector = vec4(0.4545454545454545, 0.4545454545454545, 0.4545454545454545, 1.0);\n",t+="const vec4 gammaDecode4Vector = vec4(2.2, 2.2, 2.2, 1.0);\n",t+="vec4 gammaEncode(vec4 color){\n    return pow(abs(color), gammaEncode4Vector);\n}\n",t+="vec4 gammaDecode(vec4 color){\n    return pow(abs(color), gammaDecode4Vector);\n}\n",t+="const vec3 gammaEncode3Vector = vec3(0.4545454545454545, 0.4545454545454545, 0.4545454545454545);\n",t+="const vec3 gammaDecode3Vector = vec3(2.2, 2.2, 2.2);\n",t+="vec3 gammaEncode(vec3 color){\n    return pow(abs(color), gammaEncode3Vector);\n}\n",t+="vec3 gammaDecode(vec3 color){\n    return pow(abs(color), gammaDecode3Vector);\n}\n")),t},x3dom.shader.encodeGamma=function(e,t){return"none"===e.GAMMACORRECTION?t:"gammaEncode ("+t+")"},x3dom.shader.decodeGamma=function(e,t){return"none"===e.GAMMACORRECTION?t:"gammaDecode ("+t+")"},x3dom.shader.rgbaPacking=function(){return"vec4 packDepth(float depth){\n    depth = (depth + 1.0)*0.5;\n    vec4 outVal = vec4(1.0, 255.0, 65025.0, 160581375.0) * depth;\n    outVal = fract(outVal);\n      outVal -= outVal.yzww * vec4(1.0/255.0, 1.0/255.0, 1.0/255.0, 0.0);\n      return outVal;\n}\n","float unpackDepth(vec4 color){\n    float depth = dot(color, vec4(1.0, 1.0/255.0, 1.0/65025.0, 1.0/160581375.0));\n    return (2.0*depth - 1.0);\n}\n","vec4 packDepth(float depth){\n    depth = (depth + 1.0)*0.5;\n    vec4 outVal = vec4(1.0, 255.0, 65025.0, 160581375.0) * depth;\n    outVal = fract(outVal);\n      outVal -= outVal.yzww * vec4(1.0/255.0, 1.0/255.0, 1.0/255.0, 0.0);\n      return outVal;\n}\nfloat unpackDepth(vec4 color){\n    float depth = dot(color, vec4(1.0, 1.0/255.0, 1.0/65025.0, 1.0/160581375.0));\n    return (2.0*depth - 1.0);\n}\n"},x3dom.shader.calcMipLevel=function(){return"vec2 dirToCubeUV( vec3 dir ) {\n    vec2 uv = vec2(0.0);\n    vec3 absDir = abs(dir);\n    if( absDir.x >= absDir.y && absDir.x >= absDir.z) {\n        if(dir.x < 0.0) {\n           uv.x = 1.0 - (((dir.z/absDir.x) + 1.0) * 0.5);\n           uv.y = 1.0 - (((-dir.y/absDir.x) + 1.0) * 0.5);\n       } else {\n           uv.x = 1.0 - (((-dir.z/absDir.x) + 1.0) * 0.5);\n           uv.y = 1.0 - (((-dir.y/absDir.x) + 1.0) * 0.5);\n       }\n   } else if( absDir.y >= absDir.x && absDir.y >= absDir.z) {\n       if(dir.y < 0.0) {\n              uv.x = ((dir.x/absDir.y) + 1.0) * 0.5;\n           uv.y = ((-dir.z/absDir.y) + 1.0) * 0.5;\n       } else {\n           uv.x = ((dir.x/absDir.y) + 1.0) * 0.5;\n           uv.y = ((dir.z/absDir.y) + 1.0) * 0.5;\nif(uv.y == 0.0) { uv.x = 1.0; uv.y = 0.0; }\n       }\n   } else if( absDir.z >= absDir.x && absDir.z >= absDir.y) {\n       if(dir.z < 0.0) {\n           uv.x = (((-dir.x/absDir.z) + 1.0) * 0.5);\n           uv.y = 1.0 - (((-dir.y/absDir.z) + 1.0) * 0.5);\n       } else {\n           uv.x = ((dir.x/absDir.z) + 1.0) * 0.5;\n           uv.y = 1.0 - (((-dir.y/absDir.z) + 1.0) * 0.5);\n       }\n   }\n   float a = pow(64.0,2.0) / pow(64.0,3.0);\n    uv.x = a * pow(uv.x, 3.0) + uv.x;\n    uv.y = a * pow(uv.y, 3.0) + uv.y;\n   return uv;\n}\n","float calcMipLevel( vec2 uv ) {\n    vec2  dx_vtc        = dFdx(uv) * 64.0;\n    vec2  dy_vtc        = dFdy(uv) * 64.0;\n    float delta_max_sqr = max(dot(dx_vtc, dx_vtc), dot(dy_vtc, dy_vtc));\n    return 0.5 * log2(delta_max_sqr);\n}\n","vec3 fixSeams(vec3 vec, float mipmapIndex) {\n    float scale = 1.0 - exp2(mipmapIndex) / 64.0;\n    float M = max(max(abs(vec.x), abs(vec.y)), abs(vec.z));\n    if (abs(vec.x) != M) vec.x *= scale;\n    if (abs(vec.y) != M) vec.y *= scale;\n    if (abs(vec.z) != M) vec.z *= scale;\n    return vec;\n}","vec2 dirToCubeUV( vec3 dir ) {\n    vec2 uv = vec2(0.0);\n    vec3 absDir = abs(dir);\n    if( absDir.x >= absDir.y && absDir.x >= absDir.z) {\n        if(dir.x < 0.0) {\n           uv.x = 1.0 - (((dir.z/absDir.x) + 1.0) * 0.5);\n           uv.y = 1.0 - (((-dir.y/absDir.x) + 1.0) * 0.5);\n       } else {\n           uv.x = 1.0 - (((-dir.z/absDir.x) + 1.0) * 0.5);\n           uv.y = 1.0 - (((-dir.y/absDir.x) + 1.0) * 0.5);\n       }\n   } else if( absDir.y >= absDir.x && absDir.y >= absDir.z) {\n       if(dir.y < 0.0) {\n              uv.x = ((dir.x/absDir.y) + 1.0) * 0.5;\n           uv.y = ((-dir.z/absDir.y) + 1.0) * 0.5;\n       } else {\n           uv.x = ((dir.x/absDir.y) + 1.0) * 0.5;\n           uv.y = ((dir.z/absDir.y) + 1.0) * 0.5;\nif(uv.y == 0.0) { uv.x = 1.0; uv.y = 0.0; }\n       }\n   } else if( absDir.z >= absDir.x && absDir.z >= absDir.y) {\n       if(dir.z < 0.0) {\n           uv.x = (((-dir.x/absDir.z) + 1.0) * 0.5);\n           uv.y = 1.0 - (((-dir.y/absDir.z) + 1.0) * 0.5);\n       } else {\n           uv.x = ((dir.x/absDir.z) + 1.0) * 0.5;\n           uv.y = 1.0 - (((-dir.y/absDir.z) + 1.0) * 0.5);\n       }\n   }\n   float a = pow(64.0,2.0) / pow(64.0,3.0);\n    uv.x = a * pow(uv.x, 3.0) + uv.x;\n    uv.y = a * pow(uv.y, 3.0) + uv.y;\n   return uv;\n}\nfloat calcMipLevel( vec2 uv ) {\n    vec2  dx_vtc        = dFdx(uv) * 64.0;\n    vec2  dy_vtc        = dFdy(uv) * 64.0;\n    float delta_max_sqr = max(dot(dx_vtc, dx_vtc), dot(dy_vtc, dy_vtc));\n    return 0.5 * log2(delta_max_sqr);\n}\nvec3 fixSeams(vec3 vec, float mipmapIndex) {\n    float scale = 1.0 - exp2(mipmapIndex) / 64.0;\n    float M = max(max(abs(vec.x), abs(vec.y)), abs(vec.z));\n    if (abs(vec.x) != M) vec.x *= scale;\n    if (abs(vec.y) != M) vec.y *= scale;\n    if (abs(vec.z) != M) vec.z *= scale;\n    return vec;\n}"},x3dom.shader.shadowRendering=function(){var e="";return e+="float getLightInfluence(float lType, float lShadowIntensity, float lOn, vec3 lLocation, vec3 lDirection, float lCutOffAngle, float lBeamWidth, vec3 lAttenuation, float lRadius, vec3 eyeCoords) {\n    if (lOn == 0.0 || lShadowIntensity == 0.0){ return 0.0;\n    } else if (lType == 0.0) {\n        return 1.0;\n    } else {\n       float attenuation = 0.0;\n       vec3 lightVec = (lLocation - (eyeCoords));\n       float distance = length(lightVec);\n        lightVec = normalize(lightVec);\n        eyeCoords = normalize(-eyeCoords);\n       if(lRadius == 0.0 || distance <= lRadius) {\n           attenuation = 1.0 / max(lAttenuation.x + lAttenuation.y * distance + lAttenuation.z * (distance * distance), 1.0);\n        }\n         if (lType == 1.0) return attenuation;\n       float spotAngle = acos(max(0.0, dot(-lightVec, normalize(lDirection))));\n       if(spotAngle >= lCutOffAngle) return 0.0;\n       else if(spotAngle <= lBeamWidth) return attenuation;\n       else return attenuation * (spotAngle - lCutOffAngle) / (lBeamWidth - lCutOffAngle);\n    }\n}\n",e+="void getShadowValues(inout vec4 shadowMapValues, inout float viewSampleDepth, in mat4 lightMatrix, in vec4 worldCoords, in sampler2D shadowMap){\n    vec4 lightSpaceCoords = lightMatrix*worldCoords;\n    vec3 lightSpaceCoordsCart = lightSpaceCoords.xyz / lightSpaceCoords.w;\n    vec2 textureCoords = (lightSpaceCoordsCart.xy + 1.0)*0.5;\n    viewSampleDepth = lightSpaceCoordsCart.z;\n    shadowMapValues = texture2D(shadowMap, textureCoords);\n",x3dom.caps.FP_TEXTURES||(e+="    shadowMapValues = vec4(1.0,1.0,unpackDepth(shadowMapValues),1.0);\n"),e+="}\n",e+="void getShadowValuesPointLight(inout vec4 shadowMapValues, inout float viewSampleDepth, in vec3 lLocation, in vec4 worldCoords, in mat4 lightViewMatrix,in mat4 lMatrix_0, in mat4 lMatrix_1, in mat4 lMatrix_2, in mat4 lMatrix_3, in mat4 lMatrix_4, in mat4 lMatrix_5,in sampler2D shadowMap_0, in sampler2D shadowMap_1, in sampler2D shadowMap_2, in sampler2D shadowMap_3,in sampler2D shadowMap_4, in sampler2D shadowMap_5){\n    vec4 transformed = lightViewMatrix * worldCoords;\n    vec3 lightVec = normalize(transformed.xyz/transformed.w);\n    vec3 lightVecAbs = abs(lightVec);\n    float maximum = max(max(lightVecAbs.x, lightVecAbs.y),lightVecAbs.z);\n    if (lightVecAbs.x == maximum) {\n        if (lightVec.x < 0.0) getShadowValues(shadowMapValues, viewSampleDepth, lMatrix_3,worldCoords,shadowMap_3);\n        else getShadowValues(shadowMapValues, viewSampleDepth, lMatrix_1,worldCoords,shadowMap_1);\n    }\n    else if (lightVecAbs.y == maximum) {\n        if (lightVec.y < 0.0) getShadowValues(shadowMapValues, viewSampleDepth, lMatrix_4,worldCoords,shadowMap_4);\n        else getShadowValues(shadowMapValues, viewSampleDepth, lMatrix_5,worldCoords,shadowMap_5);\n    }\n    else if (lightVec.z < 0.0) getShadowValues(shadowMapValues, viewSampleDepth, lMatrix_0,worldCoords,shadowMap_0);\n    else getShadowValues(shadowMapValues, viewSampleDepth, lMatrix_2,worldCoords,shadowMap_2);\n}\n",e+="void getShadowValuesCascaded(inout vec4 shadowMapValues, inout float viewSampleDepth, in vec4 worldCoords, in float eyeDepth, in mat4 lMatrix_0, in mat4 lMatrix_1, in mat4 lMatrix_2,in mat4 lMatrix_3, in mat4 lMatrix_4, in mat4 lMatrix_5, in sampler2D shadowMap_0, in sampler2D shadowMap_1, in sampler2D shadowMap_2,in sampler2D shadowMap_3, in sampler2D shadowMap_4, in sampler2D shadowMap_5, in float split_0, in float split_1, in float split_2, in float split_3, in float split_4){\n    if (eyeDepth < split_0) getShadowValues(shadowMapValues, viewSampleDepth, lMatrix_0, worldCoords, shadowMap_0);\n    else if (eyeDepth < split_1) getShadowValues(shadowMapValues, viewSampleDepth, lMatrix_1, worldCoords, shadowMap_1);\n    else if (eyeDepth < split_2) getShadowValues(shadowMapValues, viewSampleDepth, lMatrix_2, worldCoords, shadowMap_2);\n    else if (eyeDepth < split_3) getShadowValues(shadowMapValues, viewSampleDepth, lMatrix_3, worldCoords, shadowMap_3);\n    else if (eyeDepth < split_4) getShadowValues(shadowMapValues, viewSampleDepth, lMatrix_4, worldCoords, shadowMap_4);\n    else getShadowValues(shadowMapValues, viewSampleDepth, lMatrix_5, worldCoords, shadowMap_5);\n}\n",e+="float ESM(float shadowMapDepth, float viewSampleDepth, float offset){\n",x3dom.caps.FP_TEXTURES?e+="    return shadowMapDepth * exp(-80.0*(1.0-offset)*viewSampleDepth);\n":e+="    return exp(-80.0*(1.0-offset)*(viewSampleDepth - shadowMapDepth));\n",e+="}\n",e+="float VSM(vec2 moments, float viewSampleDepth, float offset){\n    viewSampleDepth = (viewSampleDepth + 1.0) * 0.5;\n    if (viewSampleDepth <= moments.x) return 1.0;\n    float variance = moments.y - moments.x * moments.x;\n    variance = max(variance, 0.00002 + offset*0.01);\n    float d = viewSampleDepth - moments.x;\n    return variance/(variance + d*d);\n}\n"};x3dom.shader.light=function(e){for(var t="",i=0;i<e;i++)t+="uniform float light"+i+"_On;\nuniform float light"+i+"_Type;\nuniform vec3  light"+i+"_Location;\nuniform vec3  light"+i+"_Direction;\nuniform vec3  light"+i+"_Color;\nuniform vec3  light"+i+"_Attenuation;\nuniform float light"+i+"_Radius;\nuniform float light"+i+"_Intensity;\nuniform float light"+i+"_AmbientIntensity;\nuniform float light"+i+"_BeamWidth;\nuniform float light"+i+"_CutOffAngle;\nuniform float light"+i+"_ShadowIntensity;\n";return t+="void lighting(in float lType, in vec3 lLocation, in vec3 lDirection, in vec3 lColor, in vec3 lAttenuation, in float lRadius, in float lIntensity, in float lAmbientIntensity, in float lBeamWidth, in float lCutOffAngle, in vec3 positionVS, in vec3 N, in vec3 V, float shin, float ambIntensity, vec3 reflectivity, inout vec3 ambient, inout vec3 diffuse, inout vec3 specular)\n{\n   vec3 L;\n   float spot = 1.0, attentuation = 0.0;\n   if(lType == 0.0) {\n       L = -normalize(lDirection);\n        V = normalize(V);\n        attentuation = 1.0;\n   } else{\n       L = (lLocation - (-V));\n       float d = length(L);\n        L = normalize(L);\n        V = normalize(V);\n       if(lRadius == 0.0 || d <= lRadius) {\n           attentuation = 1.0 / max(lAttenuation.x + lAttenuation.y * d + lAttenuation.z * (d * d), 1.0);\n        }\n       if(lType == 2.0) {\n           float spotAngle = acos(max(0.0, dot(-L, normalize(lDirection))));\n           if(spotAngle >= lCutOffAngle) spot = 0.0;\n           else if(spotAngle <= lBeamWidth) spot = 1.0;\n           else spot = (spotAngle - lCutOffAngle ) / (lBeamWidth - lCutOffAngle);\n       }\n   }\n   vec3  H = normalize( L + V );\n   float NdotL = clamp(dot(L, N), 0.0, 1.0);\n   float NdotH = clamp(dot(H, N), 0.0, 1.0);\n   float ambientFactor  = lAmbientIntensity * ambIntensity;\n   float diffuseFactor  = lIntensity * NdotL;\n   float specularFactor = lIntensity * pow(NdotH, shin*128.0);\n   ambient  += lColor * ambientFactor * attentuation * spot;\n   diffuse  += lColor * diffuseFactor * attentuation * spot;\n   specular += lColor * specularFactor * attentuation * spot;\n}\n"},x3dom.shader.lightPBR=function(e){for(var t="",i=0;i<e;i++)t+="uniform float light"+i+"_On;\nuniform float light"+i+"_Type;\nuniform vec3  light"+i+"_Location;\nuniform vec3  light"+i+"_Direction;\nuniform vec3  light"+i+"_Color;\nuniform vec3  light"+i+"_Attenuation;\nuniform float light"+i+"_Radius;\nuniform float light"+i+"_Intensity;\nuniform float light"+i+"_AmbientIntensity;\nuniform float light"+i+"_BeamWidth;\nuniform float light"+i+"_CutOffAngle;\nuniform float light"+i+"_ShadowIntensity;\n";return t+="void lighting(in float lType, in vec3 lLocation, in vec3 lDirection, in vec3 lColor, in vec3 lAttenuation, in float lRadius, in float lIntensity, in float lAmbientIntensity, in float lBeamWidth, in float lCutOffAngle, in vec3 positionVS, in vec3 N, in vec3 V, float shin, float ambIntensity, vec3 reflectivity, inout vec3 ambient, inout vec3 diffuse, inout vec3 specular)\n{\n   vec3 L;\n   float spot = 1.0, attentuation = 0.0;\n   if(lType == 0.0) {\n       L = -normalize(lDirection);\n        V = normalize(V);\n        attentuation = 1.0;\n   } else{\n       L = (lLocation - (-V));\n       float d = length(L);\n        L = normalize(L);\n        V = normalize(V);\n       if(lRadius == 0.0 || d <= lRadius) {\n           attentuation = 1.0 / max(lAttenuation.x + lAttenuation.y * d + lAttenuation.z * (d * d), 1.0);\n        }\n       if(lType == 2.0) {\n           float spotAngle = acos(max(0.0, dot(-L, normalize(lDirection))));\n           if(spotAngle >= lCutOffAngle) spot = 0.0;\n           else if(spotAngle <= lBeamWidth) spot = 1.0;\n           else spot = (spotAngle - lCutOffAngle ) / (lBeamWidth - lCutOffAngle);\n       }\n   }\n   vec3  fresnel = vec3(1.0, 1.0, 1.0);\n   vec3  H = normalize( L + V );\n   float NoL = clamp( dot( N, L ), 0.0, 1.0 );\n   float NoH = clamp( dot( N, H ), 0.0, 1.0 );\n   float NoV = clamp( dot( N, V ), 0.0, 1.0 );\n   float VoH = clamp( dot( V, H ), 0.0, 1.0 );\n   float ambientFactor  = lAmbientIntensity * ambIntensity;\n   float diffuseFactor  = lIntensity * NoL;\n   float spec  = lIntensity * NoL;\n   float roughness = 1.0 - shin;\n   float a = max( roughness * roughness, 5e-4 );\n   float a2 = a * a;\n   float denom = NoH * NoH * ( a2 - 1.0 ) + 1.0;\n   float D = a2 / ( denom * denom );\n   float k = a / 2.0;\n   float G_V = ( NoV * ( 1.0 - k ) + k );\n   float G_L = ( NoL * ( 1.0 - k ) + k );\n   float G = 0.25 / ( G_V * G_L );\n   vec3 F = reflectivity + (fresnel - fresnel*reflectivity) * exp2( (-5.55473 * VoH - 6.98316) * VoH );\n   vec3 specularFactor = (D * G) * (F * spec);\n   ambient  += lColor * ambientFactor * attentuation * spot;\n   diffuse  += lColor * diffuseFactor * attentuation * spot;\n   specular += lColor * specularFactor * attentuation * spot;\n}\n"},x3dom.shader.TBNCalculation=function(){return"mat3 cotangent_frame(vec3 N, vec3 p, vec2 uv)\n{\n    // get edge vectors of the pixel triangle\n    vec3 dp1 = dFdx( p );\n    vec3 dp2 = dFdy( p );\n    vec2 duv1 = dFdx( uv );\n    vec2 duv2 = dFdy( uv );\n\n    // solve the linear system\n    vec3 dp2perp = cross( dp2, N );\n    vec3 dp1perp = cross( N, dp1 );\n    vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n    vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n\n    // construct a scale-invariant frame\n    float invmax = inversesqrt( max( dot(T,T), dot(B,B) ) );\n    return mat3( T * invmax, B * invmax, N );\n}\n\n","vec3 perturb_normal( vec3 N, vec3 V, vec2 texcoord, vec3 bias )\n{\n    // assume N, the interpolated vertex normal and\n    // V, the view vector (vertex to eye)\n    vec3 map = texture2D(normalMap, texcoord ).xyz;\n    map = 2.0 * map - 1.0;\n    map = map * bias;\n    mat3 TBN = cotangent_frame(N, -V, texcoord);\n    return normalize(TBN * map);\n}\n\n","mat3 cotangent_frame(vec3 N, vec3 p, vec2 uv)\n{\n    // get edge vectors of the pixel triangle\n    vec3 dp1 = dFdx( p );\n    vec3 dp2 = dFdy( p );\n    vec2 duv1 = dFdx( uv );\n    vec2 duv2 = dFdy( uv );\n\n    // solve the linear system\n    vec3 dp2perp = cross( dp2, N );\n    vec3 dp1perp = cross( N, dp1 );\n    vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n    vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n\n    // construct a scale-invariant frame\n    float invmax = inversesqrt( max( dot(T,T), dot(B,B) ) );\n    return mat3( T * invmax, B * invmax, N );\n}\n\nvec3 perturb_normal( vec3 N, vec3 V, vec2 texcoord, vec3 bias )\n{\n    // assume N, the interpolated vertex normal and\n    // V, the view vector (vertex to eye)\n    vec3 map = texture2D(normalMap, texcoord ).xyz;\n    map = 2.0 * map - 1.0;\n    map = map * bias;\n    mat3 TBN = cotangent_frame(N, -V, texcoord);\n    return normalize(TBN * map);\n}\n\n"},x3dom.shader.toneMapping=function(){return"uniform float tonemappingOperator;\n","vec3 tonemapReinhard(vec3 color) { \n    return color / (color + vec3(1.0));\n}\n\n","vec3 uncharted2Tonemap(vec3 color) { \n    float A = 0.15;\n    float B = 0.50;\n    float C = 0.10;\n    float D = 0.20;\n    float E = 0.02;\n    float F = 0.30;\n    return ((color*(A*color+C*B)+D*E)/(color*(A*color+B)+D*F))-E/F;\n}\n\n","vec3 tonemapUncharted2(vec3 color) { \n    float W = 11.2;\n   float exposureBias = 2.0;\n    vec3 curr = uncharted2Tonemap(exposureBias * color);\n    vec3 whiteScale = 1.0 / uncharted2Tonemap(vec3(W));\n    return curr * whiteScale;\n}\n\n","vec3 tonemapeFilmic(vec3 color) { \n    const float a = 2.51;\n    const float b = 0.03;\n    const float c = 2.43;\n    const float d = 0.59;\n    const float e = 0.14;\n    return clamp((color * (a * color + b)) / (color * (c * color + d ) + e), 0.0, 1.0);\n}\n\n","vec3 tonemap(vec3 color) { \n    if(tonemappingOperator == 0.0) {\n       return color;\n    }\n    if(tonemappingOperator == 1.0) {\n       return tonemapReinhard(color);\n    }\n    if(tonemappingOperator == 2.0) {\n       return tonemapUncharted2(color);\n    }\n    if(tonemappingOperator == 3.0) {\n       return tonemapeFilmic(color);\n    }\n}\n\n","uniform float tonemappingOperator;\nvec3 tonemapReinhard(vec3 color) { \n    return color / (color + vec3(1.0));\n}\n\nvec3 uncharted2Tonemap(vec3 color) { \n    float A = 0.15;\n    float B = 0.50;\n    float C = 0.10;\n    float D = 0.20;\n    float E = 0.02;\n    float F = 0.30;\n    return ((color*(A*color+C*B)+D*E)/(color*(A*color+B)+D*F))-E/F;\n}\n\nvec3 tonemapUncharted2(vec3 color) { \n    float W = 11.2;\n   float exposureBias = 2.0;\n    vec3 curr = uncharted2Tonemap(exposureBias * color);\n    vec3 whiteScale = 1.0 / uncharted2Tonemap(vec3(W));\n    return curr * whiteScale;\n}\n\nvec3 tonemapeFilmic(vec3 color) { \n    const float a = 2.51;\n    const float b = 0.03;\n    const float c = 2.43;\n    const float d = 0.59;\n    const float e = 0.14;\n    return clamp((color * (a * color + b)) / (color * (c * color + d ) + e), 0.0, 1.0);\n}\n\nvec3 tonemap(vec3 color) { \n    if(tonemappingOperator == 0.0) {\n       return color;\n    }\n    if(tonemappingOperator == 1.0) {\n       return tonemapReinhard(color);\n    }\n    if(tonemappingOperator == 2.0) {\n       return tonemapUncharted2(color);\n    }\n    if(tonemappingOperator == 3.0) {\n       return tonemapeFilmic(color);\n    }\n}\n\n"},x3dom.shader.DynamicShader=function(e,t){this.program=e.createProgram();var i=this.generateVertexShader(e,t,x3dom.caps.WEBGL_VERSION),o=this.generateFragmentShader(e,t,x3dom.caps.WEBGL_VERSION);return e.attachShader(this.program,i),e.attachShader(this.program,o),e.bindAttribLocation(this.program,0,"position"),e.linkProgram(this.program),this.program},x3dom.shader.DynamicShader.prototype.generateVertexShader=function(e,t,i){var o="";o+="uniform mat4 modelMatrix;\n",o+="uniform mat4 modelViewMatrix;\n",o+="uniform mat4 modelViewProjectionMatrix;\n",o+="uniform mat4 modelViewMatrix2;\n",o+="uniform mat4 modelViewProjectionMatrix2;\n",o+="uniform float isVR;\n",o+="attribute float eyeIdx;\n",o+="varying float vrOffset;\n",o+="varying float fragEyeIdx;\n",3==t.POSCOMPONENTS?o+="attribute vec3 position;\n":4==t.POSCOMPONENTS&&(o+="attribute vec4 position;\n"),t.POPGEOMETRY&&(o+="uniform float PG_precisionLevel;\n",o+="uniform float PG_powPrecision;\n",o+="uniform vec3 PG_maxBBSize;\n",o+="uniform vec3 PG_bbMin;\n",o+="uniform vec3 PG_bbMaxModF;\n",o+="uniform vec3 PG_bboxShiftVec;\n",o+="uniform float PG_numAnchorVertices;\n",o+="attribute float PG_vertexID;\n"),(t.LIGHTS||t.PBR_MATERIAL)&&(t.NORMALMAP&&"OBJECT"==t.NORMALSPACE||(o+="varying vec3 fragNormal;\n",o+="uniform mat4 normalMatrix;\n",o+="uniform mat4 normalMatrix2;\n",2==t.NORCOMPONENTS?4!=t.POSCOMPONENTS&&(o+="attribute vec2 normal;\n"):3==t.NORCOMPONENTS&&(o+="attribute vec3 normal;\n"))),t.VERTEXCOLOR&&(3==t.COLCOMPONENTS?(o+="attribute vec3 color;\n",o+="varying vec3 fragColor;\n"):4==t.COLCOMPONENTS&&(o+="attribute vec4 color;\n",o+="varying vec4 fragColor;\n")),t.TEXTURED&&(o+="varying vec2 fragTexcoord;\n",t.MULTITEXCOORD&&(o+="varying vec2 fragTexcoord2;\n"),t.SPHEREMAPPING||t.IS_PARTICLE||(o+="attribute vec2 texcoord;\n",t.MULTITEXCOORD&&(o+="attribute vec2 texcoord2;\n")),t.TEXTRAFO&&(o+="uniform mat4 texTrafoMatrix;\n"),t.NORMALMAP&&"TANGENT"==t.NORMALSPACE&&(t.TANGENTDATA||x3dom.caps.STD_DERIVATIVES||x3dom.debug.logWarning("Your System doesn't support the 'OES_STANDARD_DERIVATIVES' Extension. You must set tangents and binormals manually via the FloatVertexAttribute-Node to use normal maps"),o+="attribute vec3 tangent;\n",o+="attribute vec3 binormal;\n",o+="varying vec3 fragTangent;\n",o+="varying vec3 fragBinormal;\n"),t.DISPLACEMENTMAP&&(o+="uniform sampler2D displacementMap;\n",o+="uniform float displacementFactor;\n",o+="uniform float displacementWidth;\n",o+="uniform float displacementHeight;\n",o+="uniform float displacementAxis;\n"),t.DIFFPLACEMENTMAP&&(o+="uniform sampler2D diffuseDisplacementMap;\n",o+="uniform float displacementFactor;\n",o+="uniform float displacementWidth;\n",o+="uniform float displacementHeight;\n",o+="uniform float displacementAxis;\n")),(t.CUBEMAP||t.PBR_MATERIAL)&&(o+="varying vec3 fragViewDir;\n",o+="uniform mat4 viewMatrix;\n",o+="uniform mat4 viewMatrix2;\n"),t.VERTEXID&&(o+="attribute float id;\n",o+="varying float fragID;\n"),t.IS_PARTICLE&&(o+="attribute vec3 particleSize;\n"),t.POINTPROPERTIES&&(o+="uniform vec3 pointSizeAttenuation;\n",o+="uniform float pointSizeFactor;\n",o+="uniform float minPointSize;\n",o+="uniform float maxPointSize;\n"),(t.LIGHTS||t.FOG||t.CLIPPLANES||t.POINTPROPERTIES)&&(o+="uniform vec3 eyePosition;\n",o+="varying vec4 fragPosition;\n",o+="varying vec4 fragPositionWS;\n",t.FOG&&(o+="varying vec3 fragEyePosition;\n")),t.REQUIREBBOX&&(o+="uniform vec3 bgCenter;\n",o+="uniform vec3 bgSize;\n",o+="uniform float bgPrecisionMax;\n"),t.REQUIREBBOXNOR&&(o+="uniform float bgPrecisionNorMax;\n"),t.REQUIREBBOXCOL&&(o+="uniform float bgPrecisionColMax;\n"),t.REQUIREBBOXTEX&&(o+="uniform float bgPrecisionTexMax;\n"),o+="void main(void) {\n",o+="mat4 mat_mvp = modelViewProjectionMatrix;\n",o+="mat4 mat_mv  = modelViewMatrix;\n",o+="fragEyeIdx = eyeIdx;\n",(t.CUBEMAP||t.PBR_MATERIAL)&&(o+="mat4 mat_v   = viewMatrix;\n"),(t.LIGHTS||t.PBR_MATERIAL)&&(t.NORMALMAP&&"OBJECT"==t.NORMALSPACE||(o+="mat4 mat_n   = normalMatrix;\n")),o+="if(eyeIdx == 1.0){\n",o+="    mat_mvp = modelViewProjectionMatrix2;\n",(t.CUBEMAP||t.PBR_MATERIAL)&&(o+="    mat_v   = viewMatrix2;\n"),(t.LIGHTS||t.PBR_MATERIAL)&&(t.NORMALMAP&&"OBJECT"==t.NORMALSPACE||(o+="mat4 mat_n   = normalMatrix2;\n")),o+="}\n",o+="vec3 vertPosition = position.xyz;\n",t.POPGEOMETRY?(o+="vec3 offsetVec = step(vertPosition / bgPrecisionMax, PG_bbMaxModF) * PG_bboxShiftVec;\n",o+="if ((PG_precisionLevel <= 2.0) || PG_vertexID >= PG_numAnchorVertices) {\n",o+="   vertPosition = floor(vertPosition / PG_powPrecision) * PG_powPrecision;\n",o+="   vertPosition /= (65536.0 - PG_powPrecision);\n",o+="}\n",o+="else {\n",o+="   vertPosition /= bgPrecisionMax;\n",o+="}\n",o+="vertPosition = (vertPosition + offsetVec + PG_bbMin) * PG_maxBBSize;\n"):t.REQUIREBBOX&&(o+="vertPosition = bgCenter + bgSize * vertPosition / bgPrecisionMax;\n"),t.LIGHTS&&(2==t.NORCOMPONENTS?(4==t.POSCOMPONENTS?(o+="vec3 vertNormal = vec3(position.w / 256.0); \n",o+="vertNormal.x = floor(vertNormal.x) / 255.0; \n",o+="vertNormal.y = fract(vertNormal.y) * 1.00392156862745; \n"):t.REQUIREBBOXNOR&&(o+="vec3 vertNormal = vec3(normal.xy, 0.0) / bgPrecisionNorMax;\n"),o+="vec2 thetaPhi = 3.14159265358979 * vec2(vertNormal.x, vertNormal.y*2.0-1.0); \n",o+="vec4 sinCosThetaPhi = sin( vec4(thetaPhi, thetaPhi + 1.5707963267949) ); \n",o+="vertNormal.x = sinCosThetaPhi.x * sinCosThetaPhi.w; \n",o+="vertNormal.y = sinCosThetaPhi.x * sinCosThetaPhi.y; \n",o+="vertNormal.z = sinCosThetaPhi.z; \n"):t.NORMALMAP&&"OBJECT"==t.NORMALSPACE||(o+="vec3 vertNormal = normal;\n",t.REQUIREBBOXNOR&&(o+="vertNormal = vertNormal / bgPrecisionNorMax;\n"),t.POPGEOMETRY&&(o+="vertNormal = 2.0*vertNormal - 1.0;\n"))),t.VERTEXCOLOR&&(o+="fragColor = color;\n",t.REQUIREBBOXCOL&&(o+="fragColor = fragColor / bgPrecisionColMax;\n")),t.TEXTURED&&!t.SPHEREMAPPING&&(t.IS_PARTICLE||t.POINTPROPERTIES?o+="vec2 vertTexCoord = vec2(0.0);\n":(o+="vec2 vertTexCoord = texcoord;\n",t.MULTITEXCOORD&&(o+="vec2 vertTexCoord2 = texcoord2;\n"),t.REQUIREBBOXTEX&&(o+="vertTexCoord = vertTexCoord / bgPrecisionTexMax;\n"))),t.LIGHTS&&(!t.DISPLACEMENTMAP&&!t.DIFFPLACEMENTMAP||t.NORMALMAP?t.NORMALMAP&&"OBJECT"==t.NORMALSPACE||(o+="fragNormal = (mat_n * vec4(vertNormal, 0.0)).xyz;\n"):(o+="float dx = 1.0 / displacementWidth;\n",o+="float dy = 1.0 / displacementHeight;\n",t.DISPLACEMENTMAP?(o+="float s1 = texture2D(displacementMap, vec2(vertTexCoord.x - dx, 1.0 - vertTexCoord.y)).r;\n",o+="float s2 = texture2D(displacementMap, vec2(vertTexCoord.x, 1.0 - vertTexCoord.y - dy)).r;\n",o+="float s3 = texture2D(displacementMap, vec2(vertTexCoord.x + dx, 1.0 - vertTexCoord.y)).r;\n",o+="float s4 = texture2D(displacementMap, vec2(vertTexCoord.x, 1.0 - vertTexCoord.y + dy)).r;\n"):t.DIFFPLACEMENTMAP&&(o+="float s1 = texture2D(diffuseDisplacementMap, vec2(vertTexCoord.x - dx, 1.0 - vertTexCoord.y)).a;\n",o+="float s2 = texture2D(diffuseDisplacementMap, vec2(vertTexCoord.x, 1.0 - vertTexCoord.y - dy)).a;\n",o+="float s3 = texture2D(diffuseDisplacementMap, vec2(vertTexCoord.x + dx, 1.0 - vertTexCoord.y)).a;\n",o+="float s4 = texture2D(diffuseDisplacementMap, vec2(vertTexCoord.x, 1.0 - vertTexCoord.y + dy)).a;\n"),o+="float coef = displacementFactor;\n",o+="vec3 calcNormal;\n",o+="if (displacementAxis == 0.0) {\n",o+="calcNormal = vec3((s1 - s3) * coef, -5.0, (s2 - s4) * coef);\n",o+="} else if(displacementAxis == 1.0) {\n",o+="calcNormal = vec3((s1 - s3) * coef, -5.0, (s2 - s4) * coef);\n",o+="} else {\n",o+="calcNormal = vec3((s1 - s3) * coef, -(s2 - s4) * coef, 5.0);\n",o+="}\n",o+="calcNormal = normalize(calcNormal);\n",o+="fragNormal = (mat_n * vec4(calcNormal, 0.0)).xyz;\n")),(t.CUBEMAP||t.PBR_MATERIAL)&&(o+="fragViewDir = (mat_v[3].xyz);\n"),t.TEXTURED&&(t.SPHEREMAPPING?(o+=" fragTexcoord = 0.5 + fragNormal.xy / 2.0;\n",t.TEXTRAFO&&(o+=" fragTexcoord = (texTrafoMatrix * vec4(fragTexcoord, 1.0, 1.0)).xy;\n")):t.TEXTRAFO?o+=" fragTexcoord = (texTrafoMatrix * vec4(vertTexCoord, 1.0, 1.0)).xy;\n":(o+=" fragTexcoord = vertTexCoord;\n",t.MULTITEXCOORD&&(o+=" fragTexcoord2 = vertTexCoord2;\n"),t.POPGEOMETRY&&!0===x3dom.debug.usePrecisionLevelAsTexCoord&&(o+="fragTexcoord = vec2(0.03125 + 0.9375 * (PG_precisionLevel / 16.0), 1.0);")),t.NORMALMAP&&"TANGENT"==t.NORMALSPACE&&t.TANGENTDATA&&(o+="fragTangent  = (mat_n * vec4(tangent, 0.0)).xyz;\n",o+="fragBinormal = (mat_n * vec4(binormal, 0.0)).xyz;\n")),(t.LIGHTS||t.FOG||t.CLIPPLANES||t.POINTPROPERTIES)&&(o+="fragPosition = (mat_mv * vec4(vertPosition, 1.0));\n",o+="fragPositionWS = (modelMatrix * vec4(vertPosition, 1.0));\n",t.FOG&&(o+="fragEyePosition = eyePosition - fragPosition.xyz;\n")),t.DISPLACEMENTMAP?o+="vertPosition += normalize(vertNormal) * texture2D(displacementMap, vec2(fragTexcoord.x, 1.0-fragTexcoord.y)).r * displacementFactor;\n":t.DIFFPLACEMENTMAP&&(o+="vertPosition += normalize(vertNormal) * texture2D(diffuseDisplacementMap, vec2(fragTexcoord.x, 1.0-fragTexcoord.y)).a * displacementFactor;\n"),o+="gl_Position = mat_mvp * vec4(vertPosition, 1.0);\n",o+="if(isVR == 1.0){\n",o+="    vrOffset = eyeIdx * 0.5;\n",o+="    gl_Position.x *= 0.5;\n",o+="    gl_Position.x += vrOffset * gl_Position.w;\n",o+="}\n",t.IS_PARTICLE?(o+="float spriteDist = (gl_Position.w > 0.000001) ? gl_Position.w : 0.000001;\n",o+="float pointSize = floor(length(particleSize) * 256.0 / spriteDist + 0.5);\n",o+="gl_PointSize = clamp(pointSize, 2.0, 256.0);\n"):t.POINTPROPERTIES?(o+="float r = length( fragPosition.xyz );\n",o+="vec3 a = pointSizeAttenuation;\n",o+="float attFactor = ( a.x + a.y * r + a.z * r * r );\n",o+="float pointSize =  pointSizeFactor * 1.0 / attFactor;\n",o+="gl_PointSize = clamp(pointSize, minPointSize, maxPointSize);\n"):o+="gl_PointSize = 2.0;\n",o+="}\n",2==i&&(o=x3dom.shader.convertVertexShader(o));var s=e.createShader(e.VERTEX_SHADER);return e.shaderSource(s,o),e.compileShader(s),e.getShaderParameter(s,e.COMPILE_STATUS)||(x3dom.debug.logInfo("VERTEX:\n"+o),x3dom.debug.logError("VertexShader "+e.getShaderInfoLog(s))),s},x3dom.shader.DynamicShader.prototype.generateFragmentShader=function(e,t,i){var o="#ifdef GL_FRAGMENT_PRECISION_HIGH\n";if(o+=" precision highp float;\n",o+="#else\n",o+=" precision mediump float;\n",o+="#endif\n\n",t.PBR_MATERIAL&&x3dom.caps.TEXTURE_LOD&&(o+="#extension GL_EXT_shader_texture_lod : enable\n"),(t.PBR_MATERIAL||t.NORMALMAP)&&x3dom.caps.STD_DERIVATIVES&&(o+="#extension GL_OES_standard_derivatives:enable\n"),o+="//@insertFragColor\n",o+="uniform float isVR;\n",o+="varying float vrOffset;\n",o+="varying float fragEyeIdx;\n",o+="uniform float screenWidth;\n",o+="uniform vec3 cameraPosWS;\n",o+="uniform float alphaCutoff;\n",o+=x3dom.shader.material(),o+=x3dom.shader.toneMapping(),t.PBR_MATERIAL&&!x3dom.caps.TEXTURE_LOD&&1==x3dom.caps.WEBGL_VERSION&&(o+=x3dom.shader.calcMipLevel()),t.TWOSIDEDMAT&&(o+=x3dom.shader.twoSidedMaterial()),t.PBR_MATERIAL&&(t.ISROUGHNESSMETALLIC&&(o+="uniform float metallicFactor;\n"),o+="uniform sampler2D brdfMap;\n",o+="uniform samplerCube diffuseEnvironmentMap;\n",o+="uniform samplerCube specularEnvironmentMap;\n"),t.VERTEXCOLOR&&(3==t.COLCOMPONENTS?o+="varying vec3 fragColor;  \n":4==t.COLCOMPONENTS&&(o+="varying vec4 fragColor;  \n")),(t.CUBEMAP||t.CLIPPLANES||t.PBR_MATERIAL)&&(o+="uniform mat4 viewMatrixInverse;\n",o+="uniform mat4 viewMatrixInverse2;\n",o+="uniform mat4 modelViewMatrixInverse;\n",o+="uniform mat4 modelViewMatrixInverse2;\n"),t.VERTEXID&&(o+="varying float fragID;\n"),t.TEXTURED&&(o+="varying vec2 fragTexcoord;\n",t.MULTITEXCOORD&&(o+="varying vec2 fragTexcoord2;\n"),(t.TEXTURED||t.DIFFUSEMAP)&&(o+="uniform sampler2D diffuseMap;\n"),(t.CUBEMAP||t.PBR_MATERIAL)&&(o+="uniform samplerCube environmentMap;\n",o+="varying vec3 fragViewDir;\n",t.CSSHADER&&(o+="uniform float environmentFactor;\n")),t.EMISSIVEMAP&&(o+="uniform sampler2D emissiveMap;\n"),t.OCCLUSIONMAP&&(o+="uniform sampler2D occlusionMap;\n"),t.ROUGHNESSMETALLICMAP&&(o+="uniform sampler2D roughnessMetallicMap;\n"),t.SPECULARGLOSSINESSMAP&&(o+="uniform sampler2D specularGlossinessMap;\n"),t.OCCLUSIONROUGHNESSMETALLICMAP&&(o+="uniform sampler2D occlusionRoughnessMetallicMap;\n"),t.SPECMAP&&(o+="uniform sampler2D specularMap;\n"),t.SHINMAP&&(o+="uniform sampler2D shininessMap;\n"),t.DISPLACEMENTMAP&&(o+="uniform sampler2D displacementMap;\n",o+="uniform float displacementWidth;\n",o+="uniform float displacementHeight;\n"),t.DIFFPLACEMENTMAP&&(o+="uniform sampler2D diffuseDisplacementMap;\n",o+="uniform float displacementWidth;\n",o+="uniform float displacementHeight;\n"),t.NORMALMAP&&(o+="uniform sampler2D normalMap;\n",o+="uniform vec3 normalBias;\n","TANGENT"==t.NORMALSPACE?x3dom.caps.STD_DERIVATIVES||2==x3dom.caps.WEBGL_VERSION?o+=x3dom.shader.TBNCalculation():(o+="varying vec3 fragTangent;\n",o+="varying vec3 fragBinormal;\n"):"OBJECT"==t.NORMALSPACE&&(o+="uniform mat4 normalMatrix;\n",o+="uniform mat4 normalMatrix2;\n"))),t.FOG&&(o+=x3dom.shader.fog()),(t.LIGHTS||t.CLIPPLANES)&&(o+="varying vec4 fragPosition;\n",o+="varying vec4 fragPositionWS;\n",o+="uniform float isOrthoView;\n"),t.LIGHTS){t.NORMALMAP&&"OBJECT"==t.NORMALSPACE||(o+="varying vec3 fragNormal;\n");var s=t.LIGHTS;t.PHYSICALENVLIGHT&&s--,t.PBR_MATERIAL&&s?o+=x3dom.shader.lightPBR(t.LIGHTS):s&&(o+=x3dom.shader.light(t.LIGHTS))}if(t.CLIPPLANES&&(o+=x3dom.shader.clipPlanes(t.CLIPPLANES)),o+=x3dom.shader.gammaCorrectionDecl(t),o+="void main(void) {\n",(t.CUBEMAP||t.CLIPPLANES||t.PBR_MATERIAL)&&(o+="mat4 mat_mvi = modelViewMatrixInverse;\n",o+="mat4 mat_vi  = viewMatrixInverse;\n"),"OBJECT"==t.NORMALSPACE&&(o+="mat4 mat_n = normalMatrix;\n"),o+="if(fragEyeIdx == 1.0){\n",(t.CUBEMAP||t.CLIPPLANES)&&(o+="    mat_mvi   = modelViewMatrixInverse2;\n",o+="    mat_vi    = viewMatrixInverse2;\n"),"OBJECT"==t.NORMALSPACE&&(o+="    mat_n   = normalMatrix2;\n"),o+="}\n",o+="if ( isVR == 1.0) {\n",o+="    if ( ( step( 0.5, gl_FragCoord.x / screenWidth ) - 0.5 ) * vrOffset < 0.0 ) discard;\n",o+="}\n",t.CLIPPLANES&&(o+="vec3 cappingColor = calculateClipPlanes();\n"),o+="vec4 color;\n",o+="vec4 texColor;\n",o+="color.rgb = diffuseColor;\n",o+="color.a = 1.0 - transparency;\n",o+="vec3 _emissiveColor     = emissiveColor;\n",o+="float _shininess        = shininess;\n",o+="vec3 _specularColor     = specularColor;\n",o+="float _ambientIntensity = ambientIntensity;\n",o+="float _transparency     = transparency;\n",o+="float _occlusion        = 1.0;\n","OPAQUE"==t.ALPHAMODE&&(o+="color.a = 1.0;\n"),t.PBR_MATERIAL&&t.ISROUGHNESSMETALLIC&&(o+="float _metallic         = metallicFactor;\n"),t.SEPARATEBACKMAT&&(o+="  if(!gl_FrontFacing) {\n",o+="    color.rgb = backDiffuseColor;\n",o+="    color.a = 1.0 - backTransparency;\n",o+="    _transparency = 1.0 - backTransparency;\n",o+="    _shininess = backShininess;\n",o+="    _emissiveColor = backEmissiveColor;\n",o+="    _specularColor = backSpecularColor;\n",o+="    _ambientIntensity = backAmbientIntensity;\n",o+="  }\n"),t.VERTEXCOLOR&&(3!==t.COLCOMPONENTS&&"OPAQUE"!=t.ALPHAMODE||!t.PBR_MATERIAL?3!==t.COLCOMPONENTS||t.PBR_MATERIAL?4===t.COLCOMPONENTS&&t.PBR_MATERIAL?o+="color *= fragColor;\n":4!==t.COLCOMPONENTS||t.PBR_MATERIAL||(o+="color = fragColor;\n"):o+="color.rgb = fragColor.rgb;\n":o+="color.rgb *= fragColor.rgb;\n"),t.IS_PARTICLE||t.POINTPROPERTIES?(o+="vec2 texcoord = clamp(gl_PointCoord, 0.01, 0.99);\n",t.MULTITEXCOORD&&(o+="vec2 texcoord2 = texcoord;\n")):t.TEXTURED&&(o+="vec2 texcoord = fragTexcoord;\n",t.MULTITEXCOORD&&(o+="vec2 texcoord2 = fragTexcoord2;\n")),t.UNLIT)t.DIFFUSEMAP&&(t.DIFFUSEMAPCHANNEL?o+="texColor = "+x3dom.shader.decodeGamma(t,"texture2D(diffuseMap, vec2(texcoord2.x, 1.0 - texcoord2.y))")+";\n":o+="texColor = "+x3dom.shader.decodeGamma(t,"texture2D(diffuseMap, vec2(texcoord.x, 1.0 - texcoord.y))")+";\n","OPAQUE"==t.ALPHAMODE&&(o+="texColor.a = 1.0;\n"),o+="color *= texColor;\n");else if(t.LIGHTS){if(o+="vec3 ambient   = vec3(0.0, 0.0, 0.0);\n",o+="vec3 diffuse   = vec3(0.0, 0.0, 0.0);\n",o+="vec3 specular  = vec3(0.0, 0.0, 0.0);\n",o+="vec3 eye;\n",o+="vec3 positionVS = fragPosition.rgb;\n",o+="if ( isOrthoView > 0.0 ) {\n",o+="    eye = vec3(0.0, 0.0, 1.0);\n",o+="} else {\n",o+="    eye = -fragPosition.xyz;\n",o+="}\n",t.NORMALMAP&&(o+="vec3 _normalBias = normalBias;\n"),t.NORMALMAP&&"OBJECT"==t.NORMALSPACE?o+="vec3 normal = vec3(0.0, 0.0, 0.0);\n":o+="vec3 normal = normalize(fragNormal);\n",t.SOLID&&!t.TWOSIDEDMAT||(o+="if (dot(normalize(fragNormal), eye) < 0.0) {\n",o+="  normal *= -1.0;\n",t.NORMALMAP&&(o+="  _normalBias = _normalBias * _normalBias;\n"),o+="}\n"),t.TEXTURED&&(t.NORMALMAP&&("TANGENT"==t.NORMALSPACE?(o+="vec3 n = normal;\n",t.TANGENTDATA||!x3dom.caps.STD_DERIVATIVES&&2!=x3dom.caps.WEBGL_VERSION?(o+="vec3 t = normalize( fragTangent );\n",o+="vec3 b = normalize( fragBinormal );\n",o+="mat3 tangentToWorld = mat3(t, b, n);\n",o+="normal = texture2D( normalMap, vec2(texcoord.x, 1.0-texcoord.y) ).rgb;\n",o+="normal = 2.0 * normal - 1.0;\n",o+="normal = normalize( normal * tangentToWorld );\n"):o+="normal = perturb_normal( n, fragPosition.xyz, vec2(texcoord.x, 1.0 - texcoord.y), _normalBias);\n"):"OBJECT"==t.NORMALSPACE&&(o+="normal = texture2D( normalMap, vec2(texcoord.x, 1.0-texcoord.y) ).rgb;\n",o+="normal = 2.0 * normal - 1.0;\n",o+="normal = (mat_n * vec4(normal, 0.0)).xyz;\n",o+="normal = normalize(normal);\n")),t.CUBEMAP?(o+="vec3 viewDir = normalize(fragViewDir);\n",o+="vec3 reflected = reflect(-eye, normal);\n",o+="reflected = (mat_mvi * vec4(reflected, 0.0)).xyz;\n",o+="texColor = "+x3dom.shader.decodeGamma(t,"textureCube(environmentMap, reflected)")+";\n"):t.DIFFPLACEMENTMAP?o+="texColor = texture2D(diffuseDisplacementMap, vec2(texcoord.x, 1.0-texcoord.y));\n":(t.DIFFUSEMAP||t.TEXT)&&(t.PIXELTEX?t.DIFFUSEMAPCHANNEL?o+="texColor = "+x3dom.shader.decodeGamma(t,"texture2D(diffuseMap, texcoord2)")+";\n":o+="texColor = "+x3dom.shader.decodeGamma(t,"texture2D(diffuseMap, texcoord)")+";\n":t.DIFFUSEMAPCHANNEL?o+="texColor = "+x3dom.shader.decodeGamma(t,"texture2D(diffuseMap, vec2(texcoord2.x, 1.0 - texcoord2.y))")+";\n":o+="texColor = "+x3dom.shader.decodeGamma(t,"texture2D(diffuseMap, vec2(texcoord.x, 1.0 - texcoord.y))")+";\n"),"OPAQUE"==t.ALPHAMODE&&(o+="texColor.a = 1.0;\n"),t.BLENDING&&(t.DIFFUSEMAP||t.TEXT||t.DIFFPLACEMENTMAP||t.CUBEMAP)?t.CUBEMAP&&t.CSSHADER?o+="color.rgb *= mix(vec3(1.0,1.0,1.0), texColor.rgb, environmentFactor);\n":o+="color *= texColor;\n":!t.BLENDING&&(t.DIFFUSEMAP||t.TEXT||t.DIFFPLACEMENTMAP||t.CUBEMAP)&&(o+="color = texColor;\n"),t.SHINMAP&&(o+="_shininess *= texture2D( shininessMap, vec2(texcoord.x, 1.0-texcoord.y) ).r;\n"),t.SPECMAP&&(o+="_specularColor = texture2D(specularMap, vec2(texcoord.x, 1.0-texcoord.y)).rgb;\n"),t.EMISSIVEMAP&&(t.EMISSIVEMAPCHANNEL?o+="_emissiveColor = _emissiveColor * texture2D(emissiveMap, vec2(texcoord2.x, 1.0-texcoord2.y)).rgb;\n":o+="_emissiveColor = _emissiveColor * texture2D(emissiveMap, vec2(texcoord.x, 1.0-texcoord.y)).rgb;\n"),t.ROUGHNESSMETALLICMAP&&(t.ROUGHNESSMETALLICMAPCHANNEL?o+="vec3 roughnessMetallic = texture2D(roughnessMetallicMap, vec2(texcoord2.x, 1.0-texcoord2.y)).rgb;\n":o+="vec3 roughnessMetallic = texture2D(roughnessMetallicMap, vec2(texcoord.x, 1.0-texcoord.y)).rgb;\n",o+="_shininess = 1.0 - (roughnessMetallic.g * (1.0 - _shininess));\n",o+="_metallic  = roughnessMetallic.b * metallicFactor;\n"),t.SPECULARGLOSSINESSMAP&&(t.SPECULARGLOSSINESSMAPCHANNEL?o+="vec4 specularGlossiness = "+x3dom.shader.decodeGamma(t,"texture2D(specularGlossinessMap, vec2(texcoord2.x, 1.0 - texcoord2.y))")+";\n":o+="vec4 specularGlossiness = "+x3dom.shader.decodeGamma(t,"texture2D(specularGlossinessMap, vec2(texcoord.x, 1.0 - texcoord.y))")+";\n",o+="_shininess = specularGlossiness.a * _shininess;\n"),t.OCCLUSIONROUGHNESSMETALLICMAP&&(t.OCCLUSIONROUGHNESSMETALLICMAPCHANNEL?o+="vec3 occlusionRoughnessMetallic = texture2D(occlusionRoughnessMetallicMap, vec2(texcoord2.x, 1.0-texcoord2.y)).rgb;\n":o+="vec3 occlusionRoughnessMetallic = texture2D(occlusionRoughnessMetallicMap, vec2(texcoord.x, 1.0-texcoord.y)).rgb;\n",o+="_occlusion = occlusionRoughnessMetallic.r;\n",o+="_shininess = 1.0 - occlusionRoughnessMetallic.g;\n",o+="_metallic  = occlusionRoughnessMetallic.b;\n"),t.OCCLUSIONMAP&&(t.OCCLUSIONMAPCHANNEL?o+="_occlusion = texture2D(occlusionMap, vec2(texcoord2.x, 1.0-texcoord2.y)).r;\n":o+="_occlusion = texture2D(occlusionMap, vec2(texcoord.x, 1.0-texcoord.y)).r;\n")),t.PBR_MATERIAL&&t.ISROUGHNESSMETALLIC?(o+="_specularColor = mix(vec3(0.04, 0.04, 0.04), color.rgb, _metallic);\n",o+="color.rgb *= (1.0 - _metallic);\n"):t.PBR_MATERIAL&&t.SPECULARGLOSSINESSMAP&&(o+="_specularColor = specularGlossiness.rgb * _specularColor;\n"),s){for(var r=0;r<s;r++){o+=" lighting(light"+r+"_Type, light"+r+"_Location, light"+r+"_Direction, "+("light"+r+"_Color")+", light"+r+"_Attenuation, light"+r+"_Radius, light"+r+"_Intensity, light"+r+"_AmbientIntensity, light"+r+"_BeamWidth, light"+r+"_CutOffAngle, positionVS, normal, eye, _shininess, _ambientIntensity, _specularColor, ambient, diffuse, specular);\n"}o+="ambient = max(ambient, 0.0);\n",o+="diffuse = max(diffuse, 0.0);\n",o+="specular = max(specular, 0.0);\n"}t.PBR_MATERIAL&&t.PHYSICALENVLIGHT&&(o+="float camDistance = length(cameraPosWS.xyz - fragPositionWS.xyz);\n",o+="vec3 N = (mat_vi * vec4(normal, 0.0)).rgb;\n",o+="vec3 V = normalize ( cameraPosWS.xyz - fragPositionWS.xyz );\n",o+="vec3 R = normalize( reflect ( -V, N ) );\n",o+="float roughness  =  1.0 - _shininess;\n",o+="float NoV = clamp(dot( N, V ), 0.0, 1.0);\n",o+="float lod = roughness * 6.0;",o+="diffuse = textureCube( diffuseEnvironmentMap, N ).rgb;\n",x3dom.caps.TEXTURE_LOD||2==x3dom.caps.WEBGL_VERSION?o+="specular = textureCubeLodEXT( specularEnvironmentMap, R, lod ).rgb;\n":(o+="float level = calcMipLevel(dirToCubeUV(R));\n",o+="float bias  = lod - level;\n",o+="specular    = textureCube( specularEnvironmentMap, R, bias ).rgb;\n"),o+="vec3 brdf      = texture2D( brdfMap, vec2( NoV, roughness ) ).rgb;\n",o+="_specularColor = ( _specularColor * brdf.x + brdf.y );\n"),o+="color.rgb = _emissiveColor + ((ambient + diffuse) * color.rgb + specular * _specularColor) * _occlusion;\n",(t.IS_PARTICLE||t.POINTPROPERTIES)&&(t.TEXTURED?o+="if (color.a < 0.01 ) discard;\n":(o+="float pAlpha = 1.0 - clamp(length((gl_PointCoord - 0.5) * 2.0), 0.0, 1.0);\n",o+="if ( pAlpha < 0.01 ) discard;\n"))}else!t.APPMAT||t.VERTEXCOLOR||t.TEXTURED||t.PBR_MATERIAL||(o+="color = vec4(0.0, 0.0, 0.0, 1.0 - _transparency);\n"),t.TEXTURED&&(t.DIFFUSEMAP||t.DIFFPLACEMENTMAP||t.TEXT)?(t.PIXELTEX?t.IS_PARTICLE||t.POINTPROPERTIES?o+="vec2 texCoord = clamp(gl_PointCoord, 0.01, 0.99);\n":o+="vec2 texCoord = fragTexcoord;\n":t.IS_PARTICLE||t.POINTPROPERTIES?(o+="vec2 texCoord = clamp(gl_PointCoord, 0.01, 0.99);\n",o+="texCoord.y = 1.0 - texCoord.y;\n"):o+="vec2 texCoord = vec2(fragTexcoord.x, 1.0-fragTexcoord.y);\n",o+="texColor = "+x3dom.shader.decodeGamma(t,"texture2D(diffuseMap, texCoord)")+";\n",o+="color.a = texColor.a;\n",t.BLENDING||t.IS_PARTICLE||t.POINTPROPERTIES?(o+="if (color.a < 0.01 ) discard;\n",o+="color.rgb += _emissiveColor.rgb;\n",o+="color.rgb *= texColor.rgb;\n"):o+="color = texColor;\n"):t.VERTEXCOLOR||t.PBR_MATERIAL||t.POINTLINE2D?t.VERTEXCOLOR||t.PBR_MATERIAL||!t.POINTLINE2D?t.IS_PARTICLE?(o+="float pAlpha = 1.0 - clamp(length((gl_PointCoord - 0.5) * 2.0), 0.0, 1.0);\n",o+="color.rgb *= vec3(pAlpha);\n",o+="color.a = pAlpha;\n"):t.POINTPROPERTIES&&!t.TEXTURED&&(o+="float pAlpha = 1.0 - clamp(length((gl_PointCoord - 0.5) * 2.0), 0.0, 1.0);\n",o+="if ( pAlpha < 0.01 ) discard;\n"):(o+="color.rgb = _emissiveColor;\n",t.IS_PARTICLE?(o+="float pAlpha = 1.0 - clamp(length((gl_PointCoord - 0.5) * 2.0), 0.0, 1.0);\n",o+="color.rgb *= vec3(pAlpha);\n",o+="color.a = pAlpha;\n"):t.POINTPROPERTIES&&!t.TEXTURED&&(o+="float pAlpha = 1.0 - clamp(length((gl_PointCoord - 0.5) * 2.0), 0.0, 1.0);\n",o+="if ( pAlpha < 0.01 ) discard;\n")):o+="color.rgb += _emissiveColor;\n";t.CLIPPLANES&&(o+="if (cappingColor.r != -1.0) {\n",o+="    color.rgb = cappingColor;\n",o+="}\n"),t.TEXT?o+="if (color.a < (1.0 - _transparency) * 0.5) discard;\n":t.ALPHAMASK&&(o+="if (color.a <= alphaCutoff) discard;\n",o+="color.a = 1.0;\n"),o+="if(tonemappingOperator == 1.0) {\n",o+="       color.rgb = tonemapReinhard(color.rgb);\n",o+="    }\n",o+="    if(tonemappingOperator == 2.0) {\n",o+="       color.rgb = tonemapUncharted2(color.rgb);\n",o+="    }\n",o+="    if(tonemappingOperator == 3.0) {\n",o+="       color.rgb = tonemapeFilmic(color.rgb);\n",o+="    }\n",o+="color = "+x3dom.shader.encodeGamma(t,"color")+";\n",t.FOG&&(o+="float f0 = calcFog(fragEyePosition);\n",o+="color.rgb = fogColor * (1.0-f0) + f0 * (color.rgb);\n"),o+="gl_FragColor = color;\n",o+="}\n",2==i&&(o=x3dom.shader.convertFragmentShader(o));var n=e.createShader(e.FRAGMENT_SHADER);return e.shaderSource(n,o),e.compileShader(n),e.getShaderParameter(n,e.COMPILE_STATUS)||(x3dom.debug.logInfo("FRAGMENT:\n"+o),x3dom.debug.logError("FragmentShader "+e.getShaderInfoLog(n))),n},x3dom.shader.DynamicShaderPicking=function(e,t,i){this.program=e.createProgram();var o=this.generateVertexShader(e,t,i),s=this.generateFragmentShader(e,t,i);return e.attachShader(this.program,o),e.attachShader(this.program,s),e.bindAttribLocation(this.program,0,"position"),e.linkProgram(this.program),this.program},x3dom.shader.DynamicShaderPicking.prototype.generateVertexShader=function(e,t,i){var o="";o+="uniform mat4 modelMatrix;\n",o+="uniform mat4 modelViewProjectionMatrix;\n",o+="uniform mat4 modelMatrix2;\n",o+="uniform mat4 modelViewProjectionMatrix2;\n",o+="uniform float isVR;\n",o+="attribute float eyeIdx;\n",o+="varying float vrOffset;\n",o+="varying float fragEyeIdx;\n",o+="attribute vec3 position;\n",o+="uniform vec3 from;\n",o+="varying vec3 worldCoord;\n",1==i?(o+="attribute vec3 color;\n",o+="varying vec3 fragColor;\n"):2==i&&(o+="attribute vec2 texcoord;\n",o+="varying vec3 fragColor;\n"),t.REQUIREBBOX&&(o+="uniform vec3 bgCenter;\n",o+="uniform vec3 bgSize;\n",o+="uniform float bgPrecisionMax;\n"),t.REQUIREBBOXCOL&&(o+="uniform float bgPrecisionColMax;\n"),t.REQUIREBBOXTEX&&(o+="uniform float bgPrecisionTexMax;\n"),t.VERTEXID&&(o+="uniform float shadowIDs;\n",o+=3==i?"varying vec3 idCoord;\n":"varying vec2 idCoord;\n",o+="varying float fragID;\n",o+="attribute float id;\n"),t.POPGEOMETRY&&(o+="uniform float PG_precisionLevel;\n",o+="uniform float PG_powPrecision;\n",o+="uniform vec3 PG_maxBBSize;\n",o+="uniform vec3 PG_bbMin;\n",o+="uniform vec3 PG_bbMaxModF;\n",o+="uniform vec3 PG_bboxShiftVec;\n",o+="uniform float PG_numAnchorVertices;\n",o+="attribute float PG_vertexID;\n"),t.CLIPPLANES&&(o+="uniform mat4 modelViewMatrix;\n",o+="uniform mat4 modelViewMatrix2;\n",o+="varying vec4 fragPosition;\n"),o+="void main(void) {\n",o+="fragEyeIdx = eyeIdx;\n",o+="gl_PointSize = 2.0;\n",o+="vec3 pos = position;\n",t.VERTEXID&&(0==i?(o+="idCoord = vec2((id + shadowIDs) / 256.0);\n",o+="idCoord.x = floor(idCoord.x) / 255.0;\n",o+="idCoord.y = fract(idCoord.y) * 1.00392156862745;\n",o+="fragID = id;\n"):3==i?(o+="float ID = id + shadowIDs;\n",o+="float h = floor(ID / 256.0);\n",o+="idCoord.x = ID - (h * 256.0);\n",o+="idCoord.z = floor(h / 256.0);\n",o+="idCoord.y = h - (idCoord.z * 256.0);\n",o+="idCoord = idCoord.zyx / 255.0;\n",o+="fragID = id;\n"):4==i&&(o+="idCoord = vec2((id + shadowIDs) / 256.0);\n",o+="idCoord.x = floor(idCoord.x) / 255.0;\n",o+="idCoord.y = fract(idCoord.y) * 1.00392156862745;\n",o+="fragID = id;\n")),t.POPGEOMETRY?(o+="vec3 offsetVec = step(pos / bgPrecisionMax, PG_bbMaxModF) * PG_bboxShiftVec;\n",o+="if (PG_precisionLevel <= 2.0) {\n",o+="pos = floor(pos / PG_powPrecision) * PG_powPrecision;\n",o+="pos /= (65536.0 - PG_powPrecision);\n",o+="}\n",o+="else {\n",o+="pos /= bgPrecisionMax;\n",o+="}\n",o+="pos = (pos + offsetVec + PG_bbMin) * PG_maxBBSize;\n"):(t.REQUIREBBOX&&(o+="pos = bgCenter + bgSize * pos / bgPrecisionMax;\n"),1!=i||t.REQUIREBBOXCOL?1==i&&t.REQUIREBBOXCOL?o+="fragColor = color / bgPrecisionColMax;\n":2!=i||t.REQUIREBBOXTEX?2==i&&t.REQUIREBBOXTEX&&(o+="vec2 texCoord = texcoord / bgPrecisionTexMax;\n",o+="fragColor = vec3(abs(texCoord.x), abs(texCoord.y), 0.0);\n"):o+="fragColor = vec3(abs(texcoord.x), abs(texcoord.y), 0.0);\n":o+="fragColor = color;\n"),t.CLIPPLANES&&(o+="if(eyeIdx == 1.0){\n",o+="    fragPosition = (modelViewMatrix2 * vec4(pos, 1.0));\n",o+="}else{\n",o+="    fragPosition = (modelViewMatrix * vec4(pos, 1.0));\n",o+="}\n"),o+="worldCoord = (modelMatrix * vec4(pos, 1.0)).xyz - from;\n",o+="if(eyeIdx == 1.0){\n",o+="    gl_Position = modelViewProjectionMatrix2 * vec4(pos, 1.0);\n",o+="}else{\n",o+="    gl_Position = modelViewProjectionMatrix * vec4(pos, 1.0);\n",o+="}\n",o+="if(isVR == 1.0){\n",o+="    vrOffset = eyeIdx * 0.5;\n",o+="    gl_Position.x *= 0.5;\n",o+="    gl_Position.x += vrOffset * gl_Position.w;\n",o+="}\n",o+="}\n";var s=e.createShader(e.VERTEX_SHADER);return e.shaderSource(s,o),e.compileShader(s),e.getShaderParameter(s,e.COMPILE_STATUS)||(x3dom.debug.logInfo("VERTEX:\n"+o),x3dom.debug.logError("VertexShader "+e.getShaderInfoLog(s))),s},x3dom.shader.DynamicShaderPicking.prototype.generateFragmentShader=function(e,t,i){var o="#ifdef GL_FRAGMENT_PRECISION_HIGH\n";o+=" precision highp float;\n",o+="#else\n",o+=" precision mediump float;\n",o+="#endif\n\n",o+="uniform float highBit;\n",o+="uniform float lowBit;\n",o+="uniform float sceneSize;\n",o+="varying vec3 worldCoord;\n",o+="uniform float isVR;\n",o+="varying float vrOffset;\n",o+="varying float fragEyeIdx;\n",o+="uniform float screenWidth;\n",1!=i&&2!=i||(o+="varying vec3 fragColor;\n"),t.VERTEXID&&(o+=3==i?"varying vec3 idCoord;\n":"varying vec2 idCoord;\n",o+="varying float fragID;\n"),t.CLIPPLANES&&(o+="uniform mat4 viewMatrixInverse;\n",o+="uniform mat4 viewMatrixInverse2;\n",o+="varying vec4 fragPosition;\n"),t.CLIPPLANES&&(o+=x3dom.shader.clipPlanes(t.CLIPPLANES)),o+="void main(void) {\n",o+="if ( isVR == 1.0) {\n",o+="    if ( ( step( 0.5, gl_FragCoord.x / screenWidth ) - 0.5 ) * vrOffset < 0.0 ) discard;\n",o+="}\n",t.CLIPPLANES&&(o+="calculateClipPlanes();\n"),o+=1==i||2==i?"vec4 color = vec4(fragColor, lowBit);\n":4==i?"vec4 color = vec4(highBit, lowBit, 0.0, 0.0);\n":"vec4 color = vec4(0.0, 0.0, highBit, lowBit);\n",t.VERTEXID&&(0==i||4==i?o+="color.ba = idCoord;\n":3==i&&(o+="color.gba = idCoord;\n")),1!=i&&2!=i&&(o+="float d = length(worldCoord) / sceneSize;\n"),0==i?(o+="vec2 comp = fract(d * vec2(256.0, 1.0));\n",o+="color.rg = comp - (comp.rr * vec2(0.0, 1.0/256.0));\n"):3==i&&(o+="color.r = d;\n"),o+="gl_FragColor = color;\n",o+="}\n";var s=e.createShader(e.FRAGMENT_SHADER);return e.shaderSource(s,o),e.compileShader(s),e.getShaderParameter(s,e.COMPILE_STATUS)||(x3dom.debug.logInfo("FRAGMENT:\n"+o),x3dom.debug.logError("FragmentShader "+e.getShaderInfoLog(s))),s},x3dom.shader.DynamicShadowShader=function(e,t){this.program=e.createProgram();var i=this.generateVertexShader(e,t),o=this.generateFragmentShader(e,t);return e.attachShader(this.program,i),e.attachShader(this.program,o),e.bindAttribLocation(this.program,0,"position"),e.linkProgram(this.program),this.program},x3dom.shader.DynamicShadowShader.prototype.generateVertexShader=function(e,t){var i="";i+="attribute vec3 position;\n",i+="uniform mat4 modelViewProjectionMatrix;\n",i+="varying vec4 projCoords;\n",t.VERTEXID&&(i+="varying float fragID;\n",i+="attribute float id;\n"),t.REQUIREBBOX&&(i+="uniform vec3 bgCenter;\n",i+="uniform vec3 bgSize;\n",i+="uniform float bgPrecisionMax;\n"),t.POPGEOMETRY&&(i+="uniform float PG_precisionLevel;\n",i+="uniform float PG_powPrecision;\n",i+="uniform vec3 PG_maxBBSize;\n",i+="uniform vec3 PG_bbMin;\n",i+="uniform vec3 PG_bbMaxModF;\n",i+="uniform vec3 PG_bboxShiftVec;\n",i+="uniform float PG_numAnchorVertices;\n",i+="attribute float PG_vertexID;\n"),t.CLIPPLANES&&(i+="uniform mat4 modelViewMatrix;\n",i+="varying vec4 fragPosition;\n"),i+="void main(void) {\n",i+="    vec3 pos = position;\n",t.POPGEOMETRY?(i+="    vec3 offsetVec = step(pos / bgPrecisionMax, PG_bbMaxModF) * PG_bboxShiftVec;\n",i+="    if (PG_precisionLevel <= 2.0) {\n",i+="        pos = floor(pos / PG_powPrecision) * PG_powPrecision;\n",i+="        pos /= (65536.0 - PG_powPrecision);\n",i+="    }\n",i+="    else {\n",i+="        pos /= bgPrecisionMax;\n",i+="    }\n",i+="    pos = (pos + offsetVec + PG_bbMin) * PG_maxBBSize;\n"):t.REQUIREBBOX&&(i+="    pos = bgCenter + bgSize * pos / bgPrecisionMax;\n"),t.VERTEXID&&(i+="    fragID = id;\n"),t.CLIPPLANES&&(i+="    fragPosition = (modelViewMatrix * vec4(pos, 1.0));\n"),i+="    projCoords = modelViewProjectionMatrix * vec4(pos, 1.0);\n",i+="    gl_Position = projCoords;\n",i+="}\n";var o=e.createShader(e.VERTEX_SHADER);return e.shaderSource(o,i),e.compileShader(o),e.getShaderParameter(o,e.COMPILE_STATUS)||x3dom.debug.logError("[ShadowShader] VertexShader "+e.getShaderInfoLog(o)),o},x3dom.shader.DynamicShadowShader.prototype.generateFragmentShader=function(e,t){var i="";i+="#ifdef GL_FRAGMENT_PRECISION_HIGH\n",i+="    precision highp float;\n",i+="#else\n",i+="    precision mediump float;\n",i+="#endif\n\n",i+="varying vec4 projCoords;\n",i+="uniform float offset;\n",i+="uniform bool cameraView;\n",t.VERTEXID&&(i+="varying float fragID;\n"),t.CLIPPLANES&&(i+="uniform mat4 viewMatrixInverse;\n",i+="varying vec4 fragPosition;\n",i+=x3dom.shader.clipPlanes(t.CLIPPLANES)),x3dom.caps.FP_TEXTURES||(i+=x3dom.shader.rgbaPacking()),i+="void main(void) {\n",t.CLIPPLANES&&(i+="calculateClipPlanes();\n"),i+="    vec3 proj = (projCoords.xyz / projCoords.w);\n",x3dom.caps.FP_TEXTURES?(i+="       if (!cameraView){\n",i+="           proj.z = (proj.z + 1.0)*0.5;\n",i+="           proj.y = proj.z * proj.z;\n",i+="       }\n",i+="    gl_FragColor = vec4(proj, 1.0);\n"):i+="    gl_FragColor = packDepth(proj.z);\n",i+="}\n";var o=e.createShader(e.FRAGMENT_SHADER);return e.shaderSource(o,i),e.compileShader(o),e.getShaderParameter(o,e.COMPILE_STATUS)||x3dom.debug.logError("[ShadowShader] FragmentShader "+e.getShaderInfoLog(o)),o},x3dom.shader.ComposedShader=function(e,t){this.program=e.createProgram();var i=this.generateVertexShader(e,t),o=this.generateFragmentShader(e,t);return e.attachShader(this.program,i),e.attachShader(this.program,o),e.bindAttribLocation(this.program,0,"position"),e.linkProgram(this.program),this.program},x3dom.shader.ComposedShader.prototype.generateVertexShader=function(e,t){var i=t._cf.appearance.node._shader._vertex._vf.url[0];i=this.injectVRPartsVS(i);var o=e.createShader(e.VERTEX_SHADER);return e.shaderSource(o,i),e.compileShader(o),e.getShaderParameter(o,e.COMPILE_STATUS)||x3dom.debug.logError("[ComposedShader] VertexShader "+e.getShaderInfoLog(o)),o},x3dom.shader.ComposedShader.prototype.generateFragmentShader=function(e,t){var i=t._cf.appearance.node._shader._fragment._vf.url[0];i=this.injectVRPartsFS(i);var o=e.createShader(e.FRAGMENT_SHADER);return e.shaderSource(o,i),e.compileShader(o),e.getShaderParameter(o,e.COMPILE_STATUS)||x3dom.debug.logError("[ComposedShader] FragmentShader "+e.getShaderInfoLog(o)),o},x3dom.shader.ComposedShader.prototype.injectVRPartsVS=function(e){var t=this.extractShaderSections(e);return t.before+"attribute float eyeIdx;\nuniform   float isVR;\nuniform   mat4  modelViewProjectionMatrix2;\nuniform   mat4  modelViewProjectionInverseMatrix;\nvarying   float vrOffset;\nvarying   float fragEyeIdx;\n"+t.mainStart+t.main+"fragEyeIdx = eyeIdx;\nif(isVR == 1.0)\n{\n    vec4 webVRPos = modelViewProjectionInverseMatrix * gl_Position;\n    webVRPos.xyz = webVRPos.xyz / webVRPos.w;\n    if(fragEyeIdx == 1.0) {\n        gl_Position = modelViewProjectionMatrix2 * webVRPos;\n    } else {\n        gl_Position = modelViewProjectionMatrix  * webVRPos;\n    }\n    vrOffset = fragEyeIdx * 0.5;\n    gl_Position.x *= 0.5;\n    gl_Position.x += vrOffset * gl_Position.w;\n}"+t.mainEnd},x3dom.shader.ComposedShader.prototype.injectVRPartsFS=function(e){var t=this.extractShaderSections(e);return t.before+"uniform   float isVR;\nuniform   float screenWidth;\nvarying   float vrOffset;\nvarying   float fragEyeIdx;\n"+t.mainStart+"if ( isVR == 1.0) {\n    if ( ( step( 0.5, gl_FragCoord.x / screenWidth ) - 0.5 ) * vrOffset < 0.0 ) discard;\n}\n"+t.main+t.mainEnd},x3dom.shader.ComposedShader.prototype.extractShaderSections=function(e){var t=/void\s*main\s*\(\s*(?:void)?\s*\)\s*{[\s\S]*}/.exec(e),i=t[0].indexOf("{")+t.index+1,o=t[0].lastIndexOf("}")+t.index;return{before:e.substring(0,t.index),mainStart:e.substring(t.index,i),main:e.substring(i,o),mainEnd:e.substring(o,e.length)}},x3dom.shader.NormalShader=function(e){this.program=e.createProgram();var t=this.generateVertexShader(e),i=this.generateFragmentShader(e);return e.attachShader(this.program,t),e.attachShader(this.program,i),e.bindAttribLocation(this.program,0,"position"),e.linkProgram(this.program),this.program},x3dom.shader.NormalShader.prototype.generateVertexShader=function(e){var t=e.createShader(e.VERTEX_SHADER);return e.shaderSource(t,"attribute vec3 position;\nattribute vec3 normal;\nuniform vec3 bgCenter;\nuniform vec3 bgSize;\nuniform float bgPrecisionMax;\nuniform float bgPrecisionNorMax;\nuniform mat4 normalMatrix;\nuniform mat4 modelViewProjectionMatrix;\nvarying vec3 fragNormal;\nvoid main(void) {\n    vec3 pos = bgCenter + bgSize * position / bgPrecisionMax;\n    fragNormal = (normalMatrix * vec4(normal / bgPrecisionNorMax, 0.0)).xyz;\n    gl_Position = modelViewProjectionMatrix * vec4(pos, 1.0);\n}\n"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[NormalShader] VertexShader "+e.getShaderInfoLog(t)),t},x3dom.shader.NormalShader.prototype.generateFragmentShader=function(e){var t=e.createShader(e.FRAGMENT_SHADER);return e.shaderSource(t,"#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\n precision mediump float;\n#endif\n\nvarying vec3 fragNormal;\nvoid main(void) {\n    gl_FragColor = vec4(normalize(fragNormal) / 2.0 + 0.5, 1.0);\n}\n"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[NormalShader] FragmentShader "+e.getShaderInfoLog(t)),t},x3dom.shader.FrontgroundTextureShader=function(e){this.program=e.createProgram();var t=this.generateVertexShader(e),i=this.generateFragmentShader(e);return e.attachShader(this.program,t),e.attachShader(this.program,i),e.bindAttribLocation(this.program,0,"position"),e.linkProgram(this.program),this.program},x3dom.shader.FrontgroundTextureShader.prototype.generateVertexShader=function(e){var t=e.createShader(e.VERTEX_SHADER);return e.shaderSource(t,"attribute vec3 position;\nvarying vec2 fragTexCoord;\n\nvoid main(void) {\n    vec2 texCoord = (position.xy + 1.0) * 0.5;\n    fragTexCoord = texCoord;\n    gl_Position = vec4(position.xy, 0.0, 1.0);\n}\n"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[FrontgroundTextureShader] VertexShader "+e.getShaderInfoLog(t)),t},x3dom.shader.FrontgroundTextureShader.prototype.generateFragmentShader=function(e){var t=e.createShader(e.FRAGMENT_SHADER);return e.shaderSource(t,"#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform sampler2D tex;\nvarying vec2 fragTexCoord;\n\nvoid main(void) {\n    vec4 col = texture2D(tex, fragTexCoord);\n    gl_FragColor = vec4(col.rgb, 1.0);\n}\n"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[FrontgroundTextureShader] FragmentShader "+e.getShaderInfoLog(t)),t},x3dom.shader.BackgroundTextureShader=function(e){this.program=e.createProgram();var t=this.generateVertexShader(e),i=this.generateFragmentShader(e);return e.attachShader(this.program,t),e.attachShader(this.program,i),e.bindAttribLocation(this.program,0,"position"),e.linkProgram(this.program),this.program},x3dom.shader.BackgroundTextureShader.prototype.generateVertexShader=function(e){var t=e.createShader(e.VERTEX_SHADER);return e.shaderSource(t,"attribute vec3 position;\nvarying vec2 fragTexCoord;\nuniform vec2 scale;\nuniform vec2 translation;\nuniform float isVR;\nattribute float eyeIdx;\nvarying float vrOffset;\nvarying float fragEyeIdx;\n\nvoid main(void) {\n   vec2 texCoord = (position.xy + 1.0) * 0.5;\n   fragTexCoord = texCoord * scale + translation;\n    fragEyeIdx = eyeIdx;\n   gl_Position = vec4(position.xy, 0.0, 1.0);\n    if(isVR == 1.0){\n        vrOffset = eyeIdx * 0.5;\n        gl_Position.x *= 0.5;\n        gl_Position.x += vrOffset * gl_Position.w;\n    }\n}\n"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[BackgroundTextureShader] VertexShader "+e.getShaderInfoLog(t)),t},x3dom.shader.BackgroundTextureShader.prototype.generateFragmentShader=function(e){var t=e.createShader(e.FRAGMENT_SHADER);return e.shaderSource(t,"#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform float isVR;\nvarying float vrOffset;\nvarying float fragEyeIdx;\nuniform float screenWidth;\nuniform sampler2D tex;\nvarying vec2 fragTexCoord;\n\nvoid main(void) {\n       if ( isVR == 1.0 ) {\n        if ( ( step( 0.5, gl_FragCoord.x / screenWidth ) - 0.5 ) * vrOffset < 0.0 ) discard;\n       }\n    gl_FragColor = texture2D(tex, fragTexCoord);\n}"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[BackgroundTextureShader] FragmentShader "+e.getShaderInfoLog(t)),t},x3dom.shader.BackgroundSkyTextureShader=function(e){this.program=e.createProgram();var t=this.generateVertexShader(e),i=this.generateFragmentShader(e);return e.attachShader(this.program,t),e.attachShader(this.program,i),e.bindAttribLocation(this.program,0,"position"),e.linkProgram(this.program),this.program},x3dom.shader.BackgroundSkyTextureShader.prototype.generateVertexShader=function(e){var t=e.createShader(e.VERTEX_SHADER);return e.shaderSource(t,"attribute vec3 position;\nattribute vec2 texcoord;\nuniform mat4 modelViewProjectionMatrix;\nuniform mat4 modelViewProjectionMatrix2;\nvarying vec2 fragTexCoord;\nuniform float isVR;\nattribute float eyeIdx;\nvarying float vrOffset;\nvarying float fragEyeIdx;\n\nvoid main(void) {\n    fragTexCoord = texcoord;\n     fragEyeIdx = eyeIdx;\n     if(eyeIdx == 1.0){\n       gl_Position = modelViewProjectionMatrix2 * vec4(position, 1.0);\n     } else {\n       gl_Position = modelViewProjectionMatrix * vec4(position, 1.0);\n     }\n     if(isVR == 1.0){\n        vrOffset = eyeIdx * 0.5;\n        gl_Position.x *= 0.5;\n        gl_Position.x += vrOffset * gl_Position.w;\n     }\n}\n"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[BackgroundSkyTextureShader] VertexShader "+e.getShaderInfoLog(t)),t},x3dom.shader.BackgroundSkyTextureShader.prototype.generateFragmentShader=function(e){var t=e.createShader(e.FRAGMENT_SHADER);return e.shaderSource(t,"#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform float isVR;\nvarying float vrOffset;\nvarying float fragEyeIdx;\nuniform float screenWidth;\nuniform sampler2D tex;\nvarying vec2 fragTexCoord;\n\nvoid main(void) {\n    if ( isVR == 1.0 ) {\n        if ( ( step( 0.5, gl_FragCoord.x / screenWidth ) - 0.5 ) * vrOffset < 0.0 ) discard;\n    }\n    gl_FragColor = texture2D(tex, fragTexCoord);\n}\n"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[BackgroundSkyTextureShader] FragmentShader "+e.getShaderInfoLog(t)),t},x3dom.shader.BackgroundCubeTextureShader=function(e){this.program=e.createProgram();var t=this.generateVertexShader(e),i=this.generateFragmentShader(e);return e.attachShader(this.program,t),e.attachShader(this.program,i),e.bindAttribLocation(this.program,0,"position"),e.linkProgram(this.program),this.program},x3dom.shader.BackgroundCubeTextureShader.prototype.generateVertexShader=function(e){var t=e.createShader(e.VERTEX_SHADER);return e.shaderSource(t,"attribute vec3 position;\nuniform mat4 modelViewProjectionMatrix;\nvarying vec3 fragNormal;\n\nvoid main(void) {\n    fragNormal = normalize(position);\n    gl_Position = modelViewProjectionMatrix * vec4(position, 1.0);\n}\n"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[BackgroundCubeTextureShader] VertexShader "+e.getShaderInfoLog(t)),t},x3dom.shader.BackgroundCubeTextureShader.prototype.generateFragmentShader=function(e){var t=e.createShader(e.FRAGMENT_SHADER);return e.shaderSource(t,"#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform samplerCube tex;\nvarying vec3 fragNormal;\n\nfloat magn(float val) {\n    return ((val >= 0.0) ? val : -1.0 * val);\n}\nvoid main(void) {\n    gl_FragColor = textureCube(tex, fragNormal);\n}\n"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[BackgroundCubeTextureShader] FragmentShader "+e.getShaderInfoLog(t)),t},x3dom.shader.BackgroundCubeTextureDDSShader=function(e){this.program=e.createProgram();var t=this.generateVertexShader(e),i=this.generateFragmentShader(e);if(e.attachShader(this.program,t),e.attachShader(this.program,i),e.bindAttribLocation(this.program,0,"position"),e.linkProgram(this.program),!e.getProgramParameter(this.program,e.LINK_STATUS))throw"Error linking shaders:"+e.getProgramInfoLog(this.program);return this.program},x3dom.shader.BackgroundCubeTextureDDSShader.prototype.generateVertexShader=function(e){var t=e.createShader(e.VERTEX_SHADER);return e.shaderSource(t,"attribute vec3 position;\nuniform mat4 modelViewProjectionMatrix;\nuniform mat4 modelViewProjectionMatrix2;\nvarying vec3 fragNormal;\nuniform float isVR;\nattribute float eyeIdx;\nvarying float vrOffset;\nvarying float fragEyeIdx;\n\nvoid main(void) {\n    fragEyeIdx = eyeIdx;\n   fragNormal = normalize(position);\n    if(eyeIdx == 1.0){\n       gl_Position = modelViewProjectionMatrix2 * vec4(position, 1.0);\n    } else {\n       gl_Position = modelViewProjectionMatrix * vec4(position, 1.0);\n    }\n    if(isVR == 1.0){\n        vrOffset = eyeIdx * 0.5;\n        gl_Position.x *= 0.5;\n        gl_Position.x += vrOffset * gl_Position.w;\n    }\n}\n"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[BackgroundCubeTextureDDSShader] VertexShader "+e.getShaderInfoLog(t)),t},x3dom.shader.BackgroundCubeTextureDDSShader.prototype.generateFragmentShader=function(e){var t="#ifdef GL_FRAGMENT_PRECISION_HIGH\n";t+="precision highp float;\n",t+="#else\n",t+=" precision mediump float;\n",t+="#endif\n\n",t+=x3dom.shader.toneMapping();var i={GAMMACORRECTION:e.canvas.parent.doc._viewarea._scene.getEnvironment()._vf.gammaCorrectionDefault};t+=x3dom.shader.gammaCorrectionDecl(i),t+="uniform float isVR;\nvarying float vrOffset;\nvarying float fragEyeIdx;\nuniform float screenWidth;\nuniform samplerCube tex;\nvarying vec3 fragNormal;\n\nvoid main(void) {\n    if ( isVR == 1.0 ) {\n       if ( ( step( 0.5, gl_FragCoord.x / screenWidth ) - 0.5 ) * vrOffset < 0.0 ) discard;\n    }\n   vec4 color = textureCube(tex, fragNormal);\n    if(tonemappingOperator == 1.0) {\n       color.rgb = tonemapReinhard(color.rgb);\n    }\n    if(tonemappingOperator == 2.0) {\n       color.rgb = tonemapUncharted2(color.rgb);\n    }\n    if(tonemappingOperator == 3.0) {\n       color.rgb = tonemapeFilmic(color.rgb);\n    }\n   color = "+x3dom.shader.encodeGamma(i,"color")+";\n   gl_FragColor = color;\n}\n";var o=e.createShader(e.FRAGMENT_SHADER);return e.shaderSource(o,t),e.compileShader(o),e.getShaderParameter(o,e.COMPILE_STATUS)||x3dom.debug.logError("[BackgroundCubeTextureDDSShader] FragmentShader "+e.getShaderInfoLog(o)),o},x3dom.shader.ShadowRenderingShader=function(e,t){this.program=e.createProgram();var i=this.generateVertexShader(e),o=this.generateFragmentShader(e,t);return e.attachShader(this.program,i),e.attachShader(this.program,o),e.bindAttribLocation(this.program,0,"position"),e.linkProgram(this.program),this.program},x3dom.shader.ShadowRenderingShader.prototype.generateVertexShader=function(e){var t=e.createShader(e.VERTEX_SHADER);return e.shaderSource(t,"attribute vec2 position;\nvarying vec2 vPosition;\nvoid main(void) {\n vPosition = position;\n gl_Position = vec4(position, -1.0, 1.0);\n}\n"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[ShadowRendering] VertexShader "+e.getShaderInfoLog(t)),t},x3dom.shader.ShadowRenderingShader.prototype.generateFragmentShader=function(e,t){var i="#ifdef GL_FRAGMENT_PRECISION_HIGH\n";i+="precision highp float;\n",i+="#else\n",i+=" precision mediump float;\n",i+="#endif\n\n",i+="uniform mat4 inverseViewProj;\n",i+="uniform mat4 inverseProj;\n",i+="varying vec2 vPosition;\n",i+="uniform sampler2D sceneMap;\n";for(var o=0;o<5;o++)i+="uniform float cascade"+o+"_Depth;\n";for(var s=0;s<t.length;s++){i+="uniform float light"+s+"_On;\nuniform float light"+s+"_Type;\nuniform vec3  light"+s+"_Location;\nuniform vec3  light"+s+"_Direction;\nuniform vec3  light"+s+"_Attenuation;\nuniform float light"+s+"_Radius;\nuniform float light"+s+"_BeamWidth;\nuniform float light"+s+"_CutOffAngle;\nuniform float light"+s+"_ShadowIntensity;\nuniform float light"+s+"_ShadowOffset;\nuniform mat4 light"+s+"_ViewMatrix;\n";for(var r=0;r<6;r++)i+="uniform mat4 light"+s+"_"+r+"_Matrix;\n",i+="uniform sampler2D light"+s+"_"+r+"_ShadowMap;\n";for(r=0;r<5;r++)i+="uniform float light"+s+"_"+r+"_Split;\n"}x3dom.caps.FP_TEXTURES||(i+=x3dom.shader.rgbaPacking()),i+=x3dom.shader.shadowRendering(),i+=x3dom.shader.gammaCorrectionDecl({}),i+="void main(void) {\n    float shadowValue = 1.0;\n    vec2 texCoordsSceneMap = (vPosition + 1.0)*0.5;\n    vec4 projCoords = texture2D(sceneMap, texCoordsSceneMap);\n    if (projCoords != vec4(1.0,1.0,1.0,0.0)){\n",x3dom.caps.FP_TEXTURES||(i+="    projCoords.z = unpackDepth(projCoords);\n    projCoords.w = 1.0;\n"),i+="    projCoords = projCoords / projCoords.w;\n    projCoords.xy = vPosition;\n    vec4 eyeCoords = inverseProj*projCoords;\n    vec4 worldCoords = inverseViewProj*projCoords;\n    float lightInfluence = 0.0;\n";for(s=0;s<t.length;s++)i+="    lightInfluence = getLightInfluence(light"+s+"_Type, light"+s+"_ShadowIntensity, light"+s+"_On, light"+s+"_Location, light"+s+"_Direction, light"+s+"_CutOffAngle, light"+s+"_BeamWidth, light"+s+"_Attenuation, light"+s+"_Radius, eyeCoords.xyz/eyeCoords.w);\n    if (lightInfluence != 0.0){\n        vec4 shadowMapValues;\n        float viewSampleDepth;\n",x3dom.isa(t[s],x3dom.nodeTypes.PointLight)?i+="        getShadowValuesPointLight(shadowMapValues, viewSampleDepth, light"+s+"_Location, worldCoords, light"+s+"_ViewMatrix, light"+s+"_0_Matrix,light"+s+"_1_Matrix,light"+s+"_2_Matrix,light"+s+"_3_Matrix,light"+s+"_4_Matrix,light"+s+"_5_Matrix,light"+s+"_0_ShadowMap,light"+s+"_1_ShadowMap,light"+s+"_2_ShadowMap,light"+s+"_3_ShadowMap,light"+s+"_4_ShadowMap,light"+s+"_5_ShadowMap);\n":i+="        getShadowValuesCascaded(shadowMapValues, viewSampleDepth, worldCoords, -eyeCoords.z/eyeCoords.w,light"+s+"_0_Matrix,light"+s+"_1_Matrix,light"+s+"_2_Matrix,light"+s+"_3_Matrix,light"+s+"_4_Matrix,light"+s+"_5_Matrix,light"+s+"_0_ShadowMap,light"+s+"_1_ShadowMap,light"+s+"_2_ShadowMap,light"+s+"_3_ShadowMap,light"+s+"_4_ShadowMap,light"+s+"_5_ShadowMap, light"+s+"_0_Split, light"+s+"_1_Split, light"+s+"_2_Split, light"+s+"_3_Split, \nlight"+s+"_4_Split);\n",x3dom.caps.FP_TEXTURES?i+="     shadowValue *= clamp(VSM(shadowMapValues.zy, viewSampleDepth, light"+s+"_ShadowOffset),                 1.0 - light"+s+"_ShadowIntensity*lightInfluence, 1.0);\n":i+="    shadowValue *= clamp(ESM(shadowMapValues.z, viewSampleDepth, light"+s+"_ShadowOffset),                 1.0 - light"+s+"_ShadowIntensity*lightInfluence, 1.0);\n",i+="    }\n";i+="}\n    gl_FragColor = "+x3dom.shader.encodeGamma({},"vec4(shadowValue, shadowValue, shadowValue, 1.0)")+";\n}\n";var n=e.createShader(e.FRAGMENT_SHADER);return e.shaderSource(n,i),e.compileShader(n),e.getShaderParameter(n,e.COMPILE_STATUS)||x3dom.debug.logError("[ShadowRendering] FragmentShader "+e.getShaderInfoLog(n)),n},x3dom.shader.TextureRefinementShader=function(e){this.program=e.createProgram();var t=this.generateVertexShader(e),i=this.generateFragmentShader(e);return e.attachShader(this.program,t),e.attachShader(this.program,i),e.bindAttribLocation(this.program,0,"position"),e.linkProgram(this.program),this.program},x3dom.shader.TextureRefinementShader.prototype.generateVertexShader=function(e){var t=e.createShader(e.VERTEX_SHADER);return e.shaderSource(t,"attribute vec2 position;\nvarying vec2 fragTexCoord;\n\nvoid main(void) {\n    fragTexCoord = (position.xy + 1.0) / 2.0;\n    gl_Position = vec4(position, -1.0, 1.0);\n}\n"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[TextureRefinementShader] VertexShader "+e.getShaderInfoLog(t)),t},x3dom.shader.TextureRefinementShader.prototype.generateFragmentShader=function(e){var t=e.createShader(e.FRAGMENT_SHADER);return e.shaderSource(t,"#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform sampler2D stamp;\nuniform sampler2D lastTex;\nuniform sampler2D curTex;\nuniform int mode;\nuniform vec2 repeat;\nvarying vec2 fragTexCoord;\n\nvoid init(void);\nvoid refine(void);\n\nvoid main(void) {\n    if (mode == 0) { init(); }\n    else { refine(); }\n}\n\nvoid init(void) {\n    gl_FragColor = texture2D(curTex, fragTexCoord);\n}\n\nvoid refine(void) {\n    vec3 red = texture2D(stamp, repeat * fragTexCoord).rgb;\n    vec3 v1  = texture2D(lastTex, fragTexCoord).rgb;\n    vec3 v2  = texture2D(curTex, fragTexCoord).rgb;\n    if (red.r <= 0.5) {\n        gl_FragColor = vec4(v1, 1.0);\n    }\n    else {\n        gl_FragColor = vec4(v2, 1.0);\n    }\n}\n"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[TextureRefinementShader] FragmentShader "+e.getShaderInfoLog(t)),t},x3dom.shader.BlurShader=function(e){this.program=e.createProgram();var t=this.generateVertexShader(e),i=this.generateFragmentShader(e);return e.attachShader(this.program,t),e.attachShader(this.program,i),e.bindAttribLocation(this.program,0,"position"),e.linkProgram(this.program),this.program},x3dom.shader.BlurShader.prototype.generateVertexShader=function(e){var t=e.createShader(e.VERTEX_SHADER);return e.shaderSource(t,"attribute vec2 position;\nvarying vec2 vPosition;\nvoid main(void) {\n vPosition = position;\n gl_Position = vec4(position, -1.0, 1.0);\n}\n"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[BlurShader] VertexShader "+e.getShaderInfoLog(t)),t},x3dom.shader.BlurShader.prototype.generateFragmentShader=function(e){var t="#ifdef GL_FRAGMENT_PRECISION_HIGH\n";t+="precision highp float;\n",t+="#else\n",t+=" precision mediump float;\n",t+="#endif\n\n",t+="varying vec2 vPosition;\nuniform sampler2D texture;\nuniform bool horizontal;\nuniform float pixelSizeHor;\nuniform float pixelSizeVert;\nuniform int filterSize;\n",x3dom.caps.FP_TEXTURES?t+="void main(void) {\n    vec2 texCoords = (vPosition + 1.0)*0.5;\n    vec2 offset;\n    if (horizontal) offset = vec2(pixelSizeHor, 0.0);\n    else offset = vec2(0.0, pixelSizeVert);\n    vec4 color = texture2D(texture, texCoords);\n    if (filterSize == 3){\n        color = color * 0.3844;\n        color += 0.3078*texture2D(texture, texCoords-offset);\n        color += 0.3078*texture2D(texture, texCoords+offset);\n    } else if (filterSize == 5){\n        color = color * 0.2921;\n        color += 0.2339*texture2D(texture, texCoords-offset);\n        color += 0.2339*texture2D(texture, texCoords+offset);\n        color += 0.1201*texture2D(texture, texCoords-2.0*offset);\n        color += 0.1201*texture2D(texture, texCoords+2.0*offset);\n    } else if (filterSize == 7){\n        color = color * 0.2161;\n        color += 0.1907*texture2D(texture, texCoords-offset);\n        color += 0.1907*texture2D(texture, texCoords+offset);\n        color += 0.1311*texture2D(texture, texCoords-2.0*offset);\n        color += 0.1311*texture2D(texture, texCoords+2.0*offset);\n        color += 0.0702*texture2D(texture, texCoords-3.0*offset);\n        color += 0.0702*texture2D(texture, texCoords+3.0*offset);\n    }\n    gl_FragColor = color;\n}\n":t+=x3dom.shader.rgbaPacking()+"void main(void) {\n    vec2 texCoords = (vPosition + 1.0)*0.5;\n    vec2 offset;\n    if (horizontal) offset = vec2(pixelSizeHor, 0.0);\n    else offset = vec2(0.0, pixelSizeVert);\n    float depth = unpackDepth(texture2D(texture, texCoords));\n    if (filterSize == 3){\n        depth = depth * 0.3844;\n        depth += 0.3078*unpackDepth(texture2D(texture, texCoords-offset));\n        depth += 0.3078*unpackDepth(texture2D(texture, texCoords+offset));\n    } else if (filterSize == 5){\n        depth = depth * 0.2921;\n        depth += 0.2339*unpackDepth(texture2D(texture, texCoords-offset));\n        depth += 0.2339*unpackDepth(texture2D(texture, texCoords+offset));\n        depth += 0.1201*unpackDepth(texture2D(texture, texCoords-2.0*offset));\n        depth += 0.1201*unpackDepth(texture2D(texture, texCoords+2.0*offset));\n    } else if (filterSize == 7){\n        depth = depth * 0.2161;\n        depth += 0.1907*unpackDepth(texture2D(texture, texCoords-offset));\n        depth += 0.1907*unpackDepth(texture2D(texture, texCoords+offset));\n        depth += 0.1311*unpackDepth(texture2D(texture, texCoords-2.0*offset));\n        depth += 0.1311*unpackDepth(texture2D(texture, texCoords+2.0*offset));\n        depth += 0.0702*unpackDepth(texture2D(texture, texCoords-3.0*offset));\n        depth += 0.0702*unpackDepth(texture2D(texture, texCoords+3.0*offset));\n    }\n    gl_FragColor = packDepth(depth);\n}\n";var i=e.createShader(e.FRAGMENT_SHADER);return e.shaderSource(i,t),e.compileShader(i),e.getShaderParameter(i,e.COMPILE_STATUS)||x3dom.debug.logError("[BlurShader] FragmentShader "+e.getShaderInfoLog(i)),i},x3dom.shader.SSAOShader=function(e){this.program=e.createProgram();var t=this.generateVertexShader(e),i=this.generateFragmentShader(e);return e.attachShader(this.program,t),e.attachShader(this.program,i),e.bindAttribLocation(this.program,0,"position"),e.linkProgram(this.program),this.program},x3dom.shader.SSAOShader.prototype.generateVertexShader=function(e){var t=e.createShader(e.VERTEX_SHADER);return e.shaderSource(t,"attribute vec3 position;\nvarying vec2 depthTexCoord;\nvarying vec2 randomTexCoord;\nuniform vec2 randomTextureTilingFactor;\n\nvoid main(void) {\n    vec2 texCoord = (position.xy + 1.0) * 0.5;\n    depthTexCoord = texCoord;\n     randomTexCoord = randomTextureTilingFactor*texCoord;\n    gl_Position = vec4(position.xy, 0.0, 1.0);\n}\n"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[SSAOShader] VertexShader "+e.getShaderInfoLog(t)),t},x3dom.shader.SSAOShader.depthReconsructionFunctionCode=function(){var e="uniform float depthReconstructionConstantA;\nuniform float depthReconstructionConstantB;\n";return x3dom.caps.FP_TEXTURES||(e+=x3dom.shader.rgbaPacking()),e+="float getDepth(vec2 depthTexCoord) {\n    vec4 col = texture2D(depthTexture, depthTexCoord);\n    float d;\n",x3dom.caps.FP_TEXTURES?e+="    d = col.b;\n":e+="    d = unpackDepth(col);\n",e+="    return depthReconstructionConstantB/(depthReconstructionConstantA+d);\n",e+="}\n"},x3dom.shader.SSAOShader.prototype.generateFragmentShader=function(e){var t="#ifdef GL_FRAGMENT_PRECISION_HIGH\n";t+="precision highp float;\n",t+="#else\n",t+=" precision mediump float;\n",t+="#endif\n\n",t+="uniform sampler2D depthTexture;\nuniform sampler2D randomTexture;\nuniform float nearPlane;\nuniform float farPlane;\nuniform float radius;\nuniform float depthBufferEpsilon;\nuniform vec3 samples[16];\nvarying vec2 depthTexCoord;\nvarying vec2 randomTexCoord;\n",t+=x3dom.shader.SSAOShader.depthReconsructionFunctionCode(),t+="void main(void) {\n    float referenceDepth = getDepth(depthTexCoord);\n    if(referenceDepth == 1.0)\n    {\n        gl_FragColor = vec4(1.0,1.0,1.0, 1.0);\n        return;\n    }\n    int numOcclusions = 0;\n    for(int i = 0; i<16; ++i){\n        float scale  = 1.0/referenceDepth;\n        vec3 samplepos = reflect(samples[i],texture2D(randomTexture,randomTexCoord).xyz*2.0-vec3(1.0,1.0,1.0));\n        float sampleDepth = getDepth(depthTexCoord+samplepos.xy*scale*radius);\n        //if(abs(sampleDepth-referenceDepth)<=radius*(1.0/nearPlane))\n        if( sampleDepth < referenceDepth-depthBufferEpsilon) {\n            ++numOcclusions;\n        }\n    }\n    float r = 1.0-float(numOcclusions)/16.0;\n    r*=2.0;\n    gl_FragColor = vec4(r,r,r, 1.0);\n}\n";var i=e.createShader(e.FRAGMENT_SHADER);return e.shaderSource(i,t),e.compileShader(i),e.getShaderParameter(i,e.COMPILE_STATUS)||x3dom.debug.logError("[SSAOhader] FragmentShader "+e.getShaderInfoLog(i)),i},x3dom.shader.SSAOBlurShader=function(e){this.program=e.createProgram();var t=this.generateVertexShader(e),i=this.generateFragmentShader(e);return e.attachShader(this.program,t),e.attachShader(this.program,i),e.bindAttribLocation(this.program,0,"position"),e.linkProgram(this.program),this.program},x3dom.shader.SSAOBlurShader.prototype.generateVertexShader=function(e){var t=e.createShader(e.VERTEX_SHADER);return e.shaderSource(t,"attribute vec3 position;\nvarying vec2 fragTexCoord;\n\nvoid main(void) {\n    vec2 texCoord = (position.xy + 1.0) * 0.5;\n    fragTexCoord = texCoord;\n    gl_Position = vec4(position.xy, 0.0, 1.0);\n}\n"),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS)||x3dom.debug.logError("[SSAOShader] VertexShader "+e.getShaderInfoLog(t)),t},x3dom.shader.SSAOBlurShader.prototype.generateFragmentShader=function(e){var t="#ifdef GL_FRAGMENT_PRECISION_HIGH\n";t+="precision highp float;\n",t+="#else\n",t+=" precision mediump float;\n",t+="#endif\n\n",t+="uniform sampler2D SSAOTexture;\nuniform sampler2D depthTexture;\nuniform float nearPlane;\nuniform float farPlane;\nuniform float amount;\nuniform vec2 pixelSize;\nuniform float depthThreshold;\nvarying vec2 fragTexCoord;\n",t+=x3dom.shader.SSAOShader.depthReconsructionFunctionCode(),t+="void main(void) {\n    float sum = 0.0;\n    float numSamples = 0.0;\n    float referenceDepth = getDepth(fragTexCoord);\n    for(int i = -2; i<2;i++){\n        for(int j = -2; j<2;j++){\n            vec2 sampleTexCoord = fragTexCoord+vec2(pixelSize.x*float(i),pixelSize.y*float(j));\n            if(abs(referenceDepth - getDepth(sampleTexCoord))<depthThreshold){\n                sum+= texture2D(SSAOTexture,sampleTexCoord).r;\n                numSamples++;\n    }}}\n    float intensity = mix(1.0,sum/numSamples,amount);\n    gl_FragColor = vec4(intensity,intensity,intensity,1.0);\n}\n";var i=e.createShader(e.FRAGMENT_SHADER);return e.shaderSource(i,t),e.compileShader(i),e.getShaderParameter(i,e.COMPILE_STATUS)||x3dom.debug.logError("[SSAOhader] FragmentShader "+e.getShaderInfoLog(i)),i},x3dom.shader.FRAG_COLOR="x3dom_fragColor",x3dom.shader.convertVertexShader=function(e){return"#version 300 es\n"+(e=(e=(e=e.replace(/attribute/g,"in")).replace(/varying/g,"out")).replace(/texture2D/g,"texture"))},x3dom.shader.convertFragmentShader=function(e){return"#version 300 es\n"+(e=(e=(e=(e=(e=e.replace(/varying/g,"in")).replace(/textureCubeLodEXT/g,"textureLod")).replace(/texture2D|textureCube/g,"texture")).replace(/\/\/@insertFragColor/g,"out vec4 "+x3dom.shader.FRAG_COLOR+";\n")).replace(/gl_FragColor/g,x3dom.shader.FRAG_COLOR))},x3dom.registerNodeType("X3DNode","Core",defineClass(null,(function(e){this._xmlNode=null,this._runtime=e&&e.runtime?e.runtime:null,this._DEF=null,this._nameSpace=e&&e.nameSpace?e.nameSpace:null,this._vf={},this._vfFieldTypes={},this._cf={},this._cfFieldTypes={},this._fieldWatchers={},this._routes={},this._listeners={},this._parentNodes=[],this._childNodes=[],this.addField_SFNode("metadata",x3dom.nodeTypes.X3DMetadataObject)}),{type:function(){return this.constructor},typeName:function(){return this.constructor._typeName},addChild:function(e,t){if("isProtoInstance"in e){if(this.addChild(e.typeNode,t),e.helperNodes.length>0){var i=new x3dom.nodeTypes.Switch;i._nameSpace=this._nameSpace,e.helperNodes.forEach((function(e){i.addChild(e,"children")})),this.addChild2(i)}}else this.addChild2(e,t)},addChild2:function(e,t){if(e){var i=null;if(t)i=this._cf[t];else for(var o in this._cf)if(this._cf.hasOwnProperty(o)){var s=this._cf[o];if(x3dom.isa(e,s.type)){i=s;break}}if(i&&i.addLink(e))return e._parentNodes.push(this),this._childNodes.push(e),"isProtoInstance"in this||e.parentAdded(this),!0;if("isProtoInstance"in this)if("isProtoInstance"in e)this.nodes.concat(e.nodes);else{this.nodes.push(e),that=this,function e(t){Object.keys(t).forEach((function(i){t[i].node&&t[i].node._DEF&&(that.innerNameSpace.defMap[t[i].node._DEF]=t[i].node),t[i].node&&t[i].node._cf&&e(t[i].node._cf)}))}({child:{node:e}})}}return!1},removeChild:function(e,t,i){if(t=t||"any",e)for(var o in this._cf){if(this._cf.hasOwnProperty(o)&&("any"==t||o==t))if(this._cf[o].rmLink(e)||i){for(var s=e._parentNodes.length-1;s>=0;s--)e._parentNodes[s]===this&&(e._parentNodes.splice(s,1),e.parentRemoved(this));for(var r=this._childNodes.length-1;r>=0;r--)if(this._childNodes[r]===e)return e.onRemove(),this._childNodes.splice(r,1),!0}}return!1},onRemove:function(){},parentAdded:function(e){},parentRemoved:function(e){for(var t=0,i=this._childNodes.length;t<i;t++)this._childNodes[t]&&this._childNodes[t].parentRemoved(this)},getCurrentTransform:function(){return this._parentNodes.length>=1?this.transformMatrix(this._parentNodes[0].getCurrentTransform()):x3dom.fields.SFMatrix4f.identity()},transformMatrix:function(e){return e},getVolume:function(){return null},invalidateVolume:function(){},invalidateCache:function(){},volumeValid:function(){return!1},collectDrawableObjects:function(e,t,i,o,s,r){},highlight:function(e,t){this._vf.hasOwnProperty("diffuseColor")&&(e?(void 0===this._actDiffuseColor&&(this._actDiffuseColor=new x3dom.fields.SFColor,this._highlightOn=!1),this._highlightOn||(this._actDiffuseColor.setValues(this._vf.diffuseColor),this._highlightOn=!0),this._vf.diffuseColor.setValues(t)):void 0!==this._actDiffuseColor&&(this._vf.diffuseColor.setValues(this._actDiffuseColor),this._highlightOn=!1,delete this._actDiffuseColor));for(var i=0,o=this._childNodes.length;i<o;i++)this._childNodes[i]&&this._childNodes[i].highlight(e,t)},getRuntime:function(){return this._runtime},findX3DDoc:function(){return this._nameSpace.doc},doIntersect:function(e){for(var t=!1,i=0;i<this._childNodes.length;i++)this._childNodes[i]&&(t=this._childNodes[i].doIntersect(e)||t);return t},postMessage:function(e,t){this._vf[e]=t;var i=this._fieldWatchers[e],o=this;i&&i.forEach((function(e){e.call(o,t)}));var s={target:o._xmlNode,type:"outputchange",fieldName:e,value:t};this.callEvtHandler("onoutputchange",s)},updateField:function(e,t){var i=this._vf[e];if(void 0===i){for(var o in this._vf)if(o.toLowerCase()==e){e=o,i=this._vf[e];break}if(void 0===i&&0==e.indexOf("set_")){var s=e.substr("set_".length,e.length-1);void 0!==this._vf[s]&&(e=s,i=this._vf[e])}void 0===i&&(i=null,this._vf[e]=i)}if(null!==i){try{this._vf[e].setValueByStr(t)}catch(o){try{switch((typeof this._vf[e]).toString()){case"number":this._vf[e]="number"==typeof t?t:+t;break;case"boolean":this._vf[e]="boolean"==typeof t?t:"true"==t.toLowerCase();break;case"string":this._vf[e]=t}}catch(e){x3dom.debug.logError("updateField: setValueByStr() NYI for "+typeof i)}}this.fieldChanged(e)}},setupRoute:function(e,t,i){var o,s="set_",r="_changed";this._vf[e]||(0===e.indexOf(s)?(o=e.substr(s.length,e.length-1),void 0!==this._vf[o]&&(e=o)):e.indexOf(r)>0&&(o=e.substr(0,e.length-r.length),void 0!==this._vf[o]&&(e=o))),t._vf[i]||(0===i.indexOf(s)?(o=i.substr(s.length,i.length-1),void 0!==t._vf[o]&&(i=o)):i.indexOf(r)>0&&(o=i.substr(0,i.length-r.length),void 0!==t._vf[o]&&(i=o)));var n=this._DEF+"&"+e+"&"+t._DEF+"&"+i;this._routes[n]||(this._fieldWatchers[e]||(this._fieldWatchers[e]=[]),this._fieldWatchers[e].push((function(e){t.postMessage(i,e)})),t._fieldWatchers[i]||(t._fieldWatchers[i]=[]),t._fieldWatchers[i].push((function(e){t._vf[i]=e,t.fieldChanged(i)})),this._routes[n]={from:this._fieldWatchers[e].length-1,to:t._fieldWatchers[i].length-1})},removeRoute:function(e,t,i){var o,s="set_",r="_changed";this._vf[e]||(0===e.indexOf(s)?(o=e.substr(s.length,e.length-1),void 0!==this._vf[o]&&(e=o)):e.indexOf(r)>0&&(o=e.substr(0,e.length-r.length),void 0!==this._vf[o]&&(e=o))),t._vf[i]||(0===i.indexOf(s)?(o=i.substr(s.length,i.length-1),void 0!==t._vf[o]&&(i=o)):i.indexOf(r)>0&&(o=i.substr(0,i.length-r.length),void 0!==t._vf[o]&&(i=o)));var n=this._DEF+"&"+e+"&"+t._DEF+"&"+i;this._routes[n]&&(this._fieldWatchers[e].splice(this._routes[n].from,1),t._fieldWatchers[i].splice(this._routes[n].to,1),delete this._routes[n])},fieldChanged:function(e){},nodeChanged:function(){},callEvtHandler:function(e,t){if(!this._xmlNode)return t.cancelBubble;if(!this._xmlNode.getAttribute(e)&&!this._xmlNode[e]&&!this._listeners[t.type])return t.cancelBubble;try{var i=this._xmlNode[e];if(t.target=this._xmlNode,"function"==typeof i)i.call(this._xmlNode,t);else{var o=this._xmlNode.getAttribute(e);new Function("event",o).call(this._xmlNode,t)}var s=this._listeners[t.type];if(s)for(var r=0;r<s.length;r++)s[r].call(this._xmlNode,t)}catch(e){x3dom.debug.logException(e)}return t.cancelBubble},hasEventListener:function(e){return this._xmlNode&&(this._xmlNode["on"+e]||this._xmlNode.hasAttribute("on"+e)||this._listeners[e])},initSetter:function(e,t){if(e&&t){var i=t.toLowerCase();if(e.__defineSetter__&&e.__defineGetter__?(e.__defineSetter__(t,(function(i){e.setAttribute(t,i)})),e.__defineGetter__(t,(function(){return e.getAttribute(t)})),i!=t&&(e.__defineSetter__(i,(function(i){e.setAttribute(t,i)})),e.__defineGetter__(i,(function(){return e.getAttribute(t)})))):Object.defineProperty(e,t,{set:function(i){e.setAttribute(t,i)},get:function(){return e.getAttribute(t)},configurable:!0,enumerable:!0}),this._vf[t]&&!e.attributes[t]&&!e.attributes[t.toLowerCase()]){var o="";try{o=this._vf[t].toGL?this._vf[t].toGL().toString():this._vf[t].toString()}catch(e){o=this._vf[t].toString()}o||(o=""),e.setAttribute(t,o)}}},addField_SFInt32:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?parseInt(e.xmlNode.getAttribute(t),10):i,e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="SFInt32"},addField_SFFloat:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?+e.xmlNode.getAttribute(t):i,e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="SFFloat"},addField_SFDouble:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?+e.xmlNode.getAttribute(t):i,e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="SFDouble"},addField_SFTime:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?+e.xmlNode.getAttribute(t):i,e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="SFTime"},addField_SFBool:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?"true"===e.xmlNode.getAttribute(t).toLowerCase():i,e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="SFBool"},addField_SFString:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?e.xmlNode.getAttribute(t):i,e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="SFString"},addField_SFColor:function(e,t,i,o,s){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.SFColor.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.SFColor(i,o,s),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="SFColor"},addField_SFColorRGBA:function(e,t,i,o,s,r){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.SFColorRGBA.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.SFColorRGBA(i,o,s,r),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="SFColorRGBA"},addField_SFVec2f:function(e,t,i,o){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.SFVec2f.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.SFVec2f(i,o),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="SFVec2f"},addField_SFVec3f:function(e,t,i,o,s){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.SFVec3f.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.SFVec3f(i,o,s),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="SFVec3f"},addField_SFVec4f:function(e,t,i,o,s,r){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.SFVec4f.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.SFVec4f(i,o,s,r),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="SFVec4f"},addField_SFVec3d:function(e,t,i,o,s){this.addField_SFVec3f(e,t,i,o,s),this._vfFieldTypes[t]="SFVec3d"},addField_SFRotation:function(e,t,i,o,s,r){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.Quaternion.parseAxisAngle(e.xmlNode.getAttribute(t)):x3dom.fields.Quaternion.axisAngle(new x3dom.fields.SFVec3f(i,o,s),r),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="SFRotation"},addField_SFMatrix4f:function(e,t,i,o,s,r,n,a,d,l,h,f,u,c,_,m,p,x){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.SFMatrix4f.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.SFMatrix4f(i,o,s,r,n,a,d,l,h,f,u,c,_,m,p,x),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="SFMatrix4f"},addField_SFImage:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.SFImage.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.SFImage(i),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="SFImage"},addField_MFString:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.MFString.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.MFString(i),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="MFString"},addField_MFBoolean:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.MFBoolean.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.MFBoolean(i),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="MFBoolean"},addField_MFInt32:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.MFInt32.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.MFInt32(i),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="MFInt32"},addField_MFFloat:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.MFFloat.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.MFFloat(i),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="MFFloat"},addField_MFDouble:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.MFFloat.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.MFFloat(i),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="MFDouble"},addField_MFColor:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.MFColor.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.MFColor(i),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="MFColor"},addField_MFColorRGBA:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.MFColorRGBA.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.MFColorRGBA(i),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="MFColorRGBA"},addField_MFVec2f:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.MFVec2f.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.MFVec2f(i),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="MFVec2f"},addField_MFVec3f:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.MFVec3f.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.MFVec3f(i),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="MFVec3f"},addField_MFVec3d:function(e,t,i){this.addField_MFVec3f(e,t,i),this._vfFieldTypes[t]="MFVec3d"},addField_MFRotation:function(e,t,i){this._vf[t]=e&&e.xmlNode&&e.xmlNode.hasAttribute(t)?x3dom.fields.MFRotation.parse(e.xmlNode.getAttribute(t)):new x3dom.fields.MFRotation(i),e&&e.xmlNode&&this.initSetter(e.xmlNode,t),this._vfFieldTypes[t]="MFRotation"},addField_SFNode:function(e,t){this._cf[e]=new x3dom.fields.SFNode(t),this._cfFieldTypes[e]="SFNode"},addField_MFNode:function(e,t){this._cf[e]=new x3dom.fields.MFNode(t),this._cfFieldTypes[e]="MFNode"}})),x3dom.registerNodeType("X3DMetadataObject","Core",defineClass(x3dom.nodeTypes.X3DNode,(function(e){x3dom.nodeTypes.X3DMetadataObject.superClass.call(this,e),this.addField_SFString(e,"name",""),this.addField_SFString(e,"reference","")}))),x3dom.registerNodeType("MetadataBoolean","Core",defineClass(x3dom.nodeTypes.X3DMetadataObject,(function(e){x3dom.nodeTypes.MetadataBoolean.superClass.call(this,e),this.addField_MFBoolean(e,"value",[])}))),x3dom.registerNodeType("MetadataDouble","Core",defineClass(x3dom.nodeTypes.X3DMetadataObject,(function(e){x3dom.nodeTypes.MetadataDouble.superClass.call(this,e),this.addField_MFDouble(e,"value",[])}))),x3dom.registerNodeType("MetadataFloat","Core",defineClass(x3dom.nodeTypes.X3DMetadataObject,(function(e){x3dom.nodeTypes.MetadataFloat.superClass.call(this,e),this.addField_MFFloat(e,"value",[])}))),x3dom.registerNodeType("MetadataInteger","Core",defineClass(x3dom.nodeTypes.X3DMetadataObject,(function(e){x3dom.nodeTypes.MetadataInteger.superClass.call(this,e),this.addField_MFInt32(e,"value",[])}))),x3dom.registerNodeType("MetadataSet","Core",defineClass(x3dom.nodeTypes.X3DMetadataObject,(function(e){x3dom.nodeTypes.MetadataSet.superClass.call(this,e),this.addField_MFNode("value",x3dom.nodeTypes.X3DMetadataObject)}))),x3dom.registerNodeType("MetadataString","Core",defineClass(x3dom.nodeTypes.X3DMetadataObject,(function(e){x3dom.nodeTypes.MetadataString.superClass.call(this,e),this.addField_MFString(e,"value",[])}))),x3dom.registerNodeType("Field","Core",defineClass(x3dom.nodeTypes.X3DNode,(function(e){x3dom.nodeTypes.Field.superClass.call(this,e),this.addField_SFString(e,"name",""),this.addField_SFString(e,"type",""),this.addField_SFString(e,"value","")}),{fieldChanged:function(e){var t=this;"value"===e&&this._parentNodes.forEach((function(e){e.fieldChanged(t._vf.name)}))}})),x3dom.registerNodeType("X3DChildNode","Core",defineClass(x3dom.nodeTypes.X3DNode,(function(e){x3dom.nodeTypes.X3DChildNode.superClass.call(this,e)}))),x3dom.registerNodeType("X3DBindableNode","Core",defineClass(x3dom.nodeTypes.X3DChildNode,(function(e){x3dom.nodeTypes.X3DBindableNode.superClass.call(this,e),this.addField_SFBool(e,"bind",!1),this.addField_SFString(e,"description",""),this.addField_SFBool(e,"isActive",!1),this._autoGen=!(!e||!e.autoGen),this._autoGen&&(this._vf.description="default"+this.constructor.superClass._typeName),this._stack=null,this._bindAnimation=!0}),{bind:function(e){this._stack?e?this._stack.push(this):this._stack.pop(this):x3dom.debug.logError("No BindStack in "+this.typeName()+"Bindable")},activate:function(e){this.postMessage("isActive",!0),x3dom.debug.logInfo("activate "+this.typeName()+"Bindable "+this._DEF+"/"+this._vf.description)},deactivate:function(e){this.postMessage("isActive",!1),x3dom.debug.logInfo("deactivate "+this.typeName()+"Bindable "+this._DEF+"/"+this._vf.description)},fieldChanged:function(e){e.indexOf("bind")>=0&&this.bind(this._vf.bind)},nodeChanged:function(){this._stack=this._nameSpace.doc._bindableBag.addBindable(this)}})),x3dom.registerNodeType("X3DInfoNode","Core",defineClass(x3dom.nodeTypes.X3DChildNode,(function(e){x3dom.nodeTypes.X3DInfoNode.superClass.call(this,e)}))),x3dom.registerNodeType("WorldInfo","Core",defineClass(x3dom.nodeTypes.X3DInfoNode,(function(e){x3dom.nodeTypes.WorldInfo.superClass.call(this,e),this.addField_MFString(e,"info",[]),this.addField_SFString(e,"title",""),x3dom.debug.logInfo(this._vf.info),x3dom.debug.logInfo(this._vf.title)}))),x3dom.registerNodeType("X3DSensorNode","Core",defineClass(x3dom.nodeTypes.X3DChildNode,(function(e){x3dom.nodeTypes.X3DSensorNode.superClass.call(this,e),this.addField_SFBool(e,"enabled",!0)}))),x3dom.registerNodeType("Param","Core",defineClass(x3dom.nodeTypes.X3DNode,(function(e){x3dom.nodeTypes.Param.superClass.call(this,e),x3dom.debug.logWarning('DEPRECATED: Param element needs to be child of X3D element [<a href="http://x3dom.org/docs/latest/configuration.html">DOCS</a>]')}))),x3dom.registerNodeType("X3DBoundedObject","Grouping",defineClass(x3dom.nodeTypes.X3DChildNode,(function(e){x3dom.nodeTypes.X3DBoundedObject.superClass.call(this,e),this.addField_SFBool(e,"render",!0),this.addField_SFBool(e,"visible",!0),this.addField_SFVec3f(e,"bboxCenter",0,0,0),this.addField_SFVec3f(e,"bboxSize",-1,-1,-1),this._graph={boundedNode:this,localMatrix:x3dom.fields.SFMatrix4f.identity(),globalMatrix:null,volume:new x3dom.fields.BoxVolume,lastVolume:new x3dom.fields.BoxVolume,worldVolume:new x3dom.fields.BoxVolume,center:new x3dom.fields.SFVec3f(0,0,0),coverage:-1,needCulling:!0},this._render=!0}),{fieldChanged:function(e){this._vf.hasOwnProperty(e)&&this.invalidateVolume()},nodeChanged:function(){this.invalidateVolume()},parentAdded:function(e){this.invalidateVolume()},getVolume:function(){var e=this._graph.volume;if(!this.volumeValid()&&this.renderFlag&&this.renderFlag())for(var t=0,i=this._childNodes.length;t<i;t++){var o=this._childNodes[t];if(o&&(!o.renderFlag||!0===o.renderFlag())){var s=o.getVolume();s&&s.isValid()&&e.extendBounds(s.min,s.max)}}if(!e.equals(this._graph.lastVolume)){this._graph.lastVolume=x3dom.fields.BoxVolume.copy(e);var r={target:this._xmlNode,type:"volumechanged",volume:x3dom.fields.BoxVolume.copy(e)};this.callEvtHandler("onvolumechanged",r)}return e},invalidateVolume:function(){var e=this._graph;e.volume.invalidate(),e.worldVolume.invalidate(),e.globalMatrix=null;for(var t=0,i=this._parentNodes.length;t<i;t++){var o=this._parentNodes[t];o&&o.invalidateVolume()}},invalidateCache:function(){var e=this._graph;e.worldVolume.invalidate(),e.globalMatrix=null},cacheInvalid:function(){return null==this._graph.globalMatrix||!this._graph.worldVolume.isValid()},volumeValid:function(){return this._graph.volume.isValid()},graphState:function(){return this._graph},forceUpdateCoverage:function(){return!1},renderFlag:function(){return this._render!==this._vf.render?(this._vf.visible=this._vf.render,this._render=this._vf.visible):this._render!==this._vf.visible&&(this._vf.render=this._vf.visible,this._render=this._vf.visible),this._render}})),x3dom.registerNodeType("X3DGroupingNode","Grouping",defineClass(x3dom.nodeTypes.X3DBoundedObject,(function(e){x3dom.nodeTypes.X3DGroupingNode.superClass.call(this,e),this.addField_MFNode("children",x3dom.nodeTypes.X3DChildNode)}),{collectDrawableObjects:function(e,t,i,o,s,r){if(i&&this._parentNodes.length>1&&(i=!1),i&&(o=o||this.cacheInvalid())&&this.invalidateCache(),!((s=t.cull(e,this.graphState(),i,s))<0)){var n,a;i?(this._graph.globalMatrix||(this._graph.globalMatrix=this.transformMatrix(e)),a=this._graph.globalMatrix):a=this.transformMatrix(e);var d=this._childNodes.length;if(x3dom.nodeTypes.ClipPlane.count>0){for(var l=[],h=0;h<d;h++)(n=this._childNodes[h])&&x3dom.isa(n,x3dom.nodeTypes.ClipPlane)&&n._vf.on&&n._vf.enabled&&l.push({plane:n,trafo:a});r=l.concat(r)}for(var f=0;f<d;f++)(n=this._childNodes[f])&&n.collectDrawableObjects(a,t,i,o,s,r)}}})),x3dom.registerNodeType("Switch","Grouping",defineClass(x3dom.nodeTypes.X3DGroupingNode,(function(e){x3dom.nodeTypes.Switch.superClass.call(this,e),this.addField_SFInt32(e,"whichChoice",-1)}),{fieldChanged:function(e){"whichChoice"==e&&this.invalidateVolume()},getVolume:function(){var e=this._graph.volume;if(!this.volumeValid()&&this.renderFlag&&this.renderFlag()&&this._vf.whichChoice>=0&&this._vf.whichChoice<this._childNodes.length){var t=this._childNodes[this._vf.whichChoice],i=t&&t.renderFlag&&!0===t.renderFlag()?t.getVolume():null;i&&i.isValid()&&e.extendBounds(i.min,i.max)}return e},collectDrawableObjects:function(e,t,i,o,s,r){var n,a;(i&&this._parentNodes.length>1&&(i=!1),i&&(o=o||this.cacheInvalid())&&this.invalidateCache(),this._vf.whichChoice<0||this._vf.whichChoice>=this._childNodes.length||(s=t.cull(e,this.graphState(),i,s))<0)||(i?(this._graph.globalMatrix||(this._graph.globalMatrix=this.transformMatrix(e)),a=this._graph.globalMatrix):a=this.transformMatrix(e),(n=this._childNodes[this._vf.whichChoice])&&n.collectDrawableObjects(a,t,i,o,s,r))},doIntersect:function(e){if(this._vf.whichChoice<0||this._vf.whichChoice>=this._childNodes.length)return!1;var t=this._childNodes[this._vf.whichChoice];return!!t&&t.doIntersect(e)}})),x3dom.registerNodeType("X3DTransformNode","Grouping",defineClass(x3dom.nodeTypes.X3DGroupingNode,(function(e){x3dom.nodeTypes.X3DTransformNode.superClass.call(this,e),e?e.doc._nodeBag.trans.push(this):x3dom.debug.logWarning("X3DTransformNode: No runtime context found!"),this._trafo=null,this._needCssStyleUpdates=!0}),{tick:function(e){var t=this._xmlNode;if(t&&(t.ontransform||t.hasAttribute("ontransform")||this._listeners.transform)){var i=this.getCurrentTransform(),o={target:t,type:"transform",worldX:i._03,worldY:i._13,worldZ:i._23,cancelBubble:!1,stopPropagation:function(){this.cancelBubble=!0}};this.callEvtHandler("ontransform",o)}if(this._needCssStyleUpdates&&t){var s=x3dom.getStyle(t,"-webkit-transform")||x3dom.getStyle(t,"-moz-transform")||x3dom.getStyle(t,"-ms-transform")||x3dom.getStyle(t,"transform");if(s&&"none"!=s)return this._trafo.setValueByStr(s),this.invalidateVolume(),!0;this._needCssStyleUpdates=!1}return!1},transformMatrix:function(e){return e.mult(this._trafo)},getVolume:function(){var e=this._graph.volume;if(!this.volumeValid()&&this.renderFlag&&this.renderFlag()){this._graph.localMatrix=this._trafo;for(var t=0,i=this._childNodes.length;t<i;t++){var o=this._childNodes[t];if(o&&(!o.renderFlag||!0===o.renderFlag())){var s=o.getVolume();s&&s.isValid()&&e.extendBounds(s.min,s.max)}}e.isValid()&&e.transform(this._trafo)}return e},doIntersect:function(e){var t=!1,i=this._trafo.inverse(),o=new x3dom.fields.SFVec3f(e.pos.x,e.pos.y,e.pos.z),s=new x3dom.fields.SFVec3f(e.dir.x,e.dir.y,e.dir.z);e.pos=i.multMatrixPnt(e.pos),e.dir=i.multMatrixVec(e.dir),e.hitObject&&(e.dist*=e.dir.length());for(var r=0;r<this._childNodes.length;r++)this._childNodes[r]&&(t=this._childNodes[r].doIntersect(e)||t);return e.pos.setValues(o),e.dir.setValues(s),t&&(e.hitPoint=this._trafo.multMatrixPnt(e.hitPoint),e.dist*=e.dir.length()),t},parentRemoved:function(e){var t,i,o=this.findX3DDoc();for(t=0,i=o._nodeBag.trans.length;t<i;t++)o._nodeBag.trans[t]===this&&o._nodeBag.trans.splice(t,1);for(t=0,i=this._childNodes.length;t<i;t++)this._childNodes[t]&&this._childNodes[t].parentRemoved(this)}})),x3dom.registerNodeType("Transform","Grouping",defineClass(x3dom.nodeTypes.X3DTransformNode,(function(e){x3dom.nodeTypes.Transform.superClass.call(this,e),this.addField_SFVec3f(e,"center",0,0,0),this.addField_SFVec3f(e,"translation",0,0,0),this.addField_SFRotation(e,"rotation",0,0,1,0),this.addField_SFVec3f(e,"scale",1,1,1),this.addField_SFRotation(e,"scaleOrientation",0,0,1,0),this._trafo=x3dom.fields.SFMatrix4f.translation(this._vf.translation.add(this._vf.center)).mult(this._vf.rotation.toMatrix()).mult(this._vf.scaleOrientation.toMatrix()).mult(x3dom.fields.SFMatrix4f.scale(this._vf.scale)).mult(this._vf.scaleOrientation.toMatrix().inverse()).mult(x3dom.fields.SFMatrix4f.translation(this._vf.center.negate()))}),{fieldChanged:function(e){"center"==e||"translation"==e||"rotation"==e||"scale"==e||"scaleOrientation"==e?(this._trafo=x3dom.fields.SFMatrix4f.translation(this._vf.translation.add(this._vf.center)).mult(this._vf.rotation.toMatrix()).mult(this._vf.scaleOrientation.toMatrix()).mult(x3dom.fields.SFMatrix4f.scale(this._vf.scale)).mult(this._vf.scaleOrientation.toMatrix().inverse()).mult(x3dom.fields.SFMatrix4f.translation(this._vf.center.negate())),this.invalidateVolume()):"render"==e&&this.invalidateVolume()}})),x3dom.registerNodeType("MatrixTransform","Grouping",defineClass(x3dom.nodeTypes.X3DTransformNode,(function(e){x3dom.nodeTypes.MatrixTransform.superClass.call(this,e),this.addField_SFMatrix4f(e,"matrix",1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this._trafo=this._vf.matrix.transpose()}),{fieldChanged:function(e){"matrix"==e?(this._trafo=this._vf.matrix.transpose(),this.invalidateVolume()):"render"==e&&this.invalidateVolume()}})),x3dom.registerNodeType("Group","Grouping",defineClass(x3dom.nodeTypes.X3DGroupingNode,(function(e){x3dom.nodeTypes.Group.superClass.call(this,e)}))),x3dom.registerNodeType("Block","Grouping",defineClass(x3dom.nodeTypes.X3DGroupingNode,(function(e){x3dom.nodeTypes.Block.superClass.call(this,e),this.addField_MFString(e,"nameSpaceName",[])}))),x3dom.registerNodeType("StaticGroup","Grouping",defineClass(x3dom.nodeTypes.X3DGroupingNode,(function(e){x3dom.nodeTypes.StaticGroup.superClass.call(this,e),x3dom.debug.logWarning("StaticGroup erroneously also bakes parent transforms, if happens use Group node!"),this.addField_SFBool(e,"debug",!1),this.addField_SFBool(e,"showDebugBoxVolumes",!1),this.addField_SFString(e,"bvhType","jsBIH"),this.addField_SFInt32(e,"maxObjectsPerNode",1),this.addField_SFInt32(e,"maxDepth",-1),this.addField_SFFloat(e,"minRelativeBBoxSize",.01),this.needBvhRebuild=!0,this.drawableCollection=null,this.bvh=null}),{getMaxDepth:function(){return-1==this._vf.maxDepth?"jsBIH"==this._vf.bvhType?50:4:this._vf.maxDepth},collectDrawableObjects:function(e,t,i,o,s,r){if(i&&this._parentNodes.length>1&&(i=!1),i&&(o=o||this.cacheInvalid())&&this.invalidateCache(),!((s=t.cull(e,this.graphState(),i,s))<0)){var n,a;if(i?(this._graph.globalMatrix||(this._graph.globalMatrix=this.transformMatrix(e)),a=this._graph.globalMatrix):a=this.transformMatrix(e),this.needBvhRebuild){var d={viewArea:t.viewarea,sortTrans:t.sortTrans,viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,sceneMatrix:t.sceneMatrix,frustumCulling:!1,smallFeatureThreshold:0,context:t.context};this.drawableCollection=new x3dom.DrawableCollection(d);var l,h=this._childNodes.length;for(l=0;l<h;l++)(n=this._childNodes[l])&&n.collectDrawableObjects(a,this.drawableCollection,i,o,s,r);this.drawableCollection.concat();var f=this._nameSpace.doc._scene,u=new x3dom.bvh.Settings(this._vf.debug,this._vf.showDebugBoxVolumes,this._vf.bvhType,this._vf.maxObjectsPerNode,this.getMaxDepth(),this._vf.minRelativeBBoxSize);for(this.bvh="jsBIH"==this._vf.bvhType?new x3dom.bvh.BIH(f,u):new x3dom.bvh.Culler(this.drawableCollection,f,u),(this._vf.debug||this._vf.showDebugBoxVolumes)&&(this.bvh=new x3dom.bvh.DebugDecorator(this.bvh,f,u)),h=this.drawableCollection.length,l=0;l<h;l++)this.bvh.addDrawable(this.drawableCollection.get(l));this.bvh.compile(),this._vf.debug&&this.bvh.showCompileStats(),this.needBvhRebuild=!1}x3dom.Utils.startMeasure("bvhTraverse"),this.bvh.collectDrawables(t);var c=x3dom.Utils.stopMeasure("bvhTraverse");this._nameSpace.doc.ctx.x3dElem.runtime.addMeasurement("BVH",c),this.bvh.showTraverseStats(this._nameSpace.doc.ctx.x3dElem.runtime)}}})),x3dom.registerNodeType("RemoteSelectionGroup","Grouping",defineClass(x3dom.nodeTypes.X3DGroupingNode,(function(e){x3dom.nodeTypes.RemoteSelectionGroup.superClass.call(this,e),this.addField_MFString(e,"url",["ws://localhost:35668/cstreams/0"]),this.addField_MFString(e,"label",[]),this.addField_SFInt32(e,"maxRenderedIds",-1),this.addField_SFBool(e,"reconnect",!0),this.addField_SFFloat(e,"scaleRenderedIdsOnMove",1),this.addField_SFBool(e,"enableCulling",!0),this.addField_MFString(e,"invisibleNodes",[]),this._idList=[],this._websocket=null,this._nameObjMap={},this._createTime=[],this._visibleList=[],e?this.initializeSocket():x3dom.debug.logWarning("RemoteSelectionGroup: No runtime context found!")}),{initializeSocket:function(){var e=this;if("WebSocket"in window){var t="ws://localhost:35668/cstreams/0";this._vf.url.length&&this._vf.url[0].length&&(t=this._vf.url[0]),this._websocket=new WebSocket(t),this._websocket._lastMsg=null,this._websocket._lastData="",this._websocket.onopen=function(t){x3dom.debug.logInfo("WS Connected");var i=e._nameSpace.doc._viewarea.getViewMatrix();this._lastMsg=i.toGL().toString(),i=e._nameSpace.doc._viewarea.getProjectionMatrix(),this._lastMsg+=","+i.toGL().toString(),this.send(this._lastMsg),x3dom.debug.logInfo("WS Sent: "+this._lastMsg),this._lastMsg="",this._lastData=""},this._websocket.onclose=function(t){x3dom.debug.logInfo("WS Disconnected"),e._vf.reconnect&&window.setTimeout((function(){e.initializeSocket()}),2e3)},this._websocket.onmessage=function(t){if(e._vf.maxRenderedIds<0)e._idList=x3dom.fields.MFString.parse(t.data);else if(e._vf.maxRenderedIds>0){e._idList=[];for(var i=x3dom.fields.MFString.parse(t.data),o=Math.min(i.length,Math.abs(e._vf.maxRenderedIds)),s=0;s<o;++s)e._idList[s]=i[s]}0!=e._vf.maxRenderedIds&&this._lastData!=t.data&&(this._lastData=t.data,e._nameSpace.doc.needRender=!0,e.invalidateVolume())},this._websocket.onerror=function(e){x3dom.debug.logError(e.data)},this._websocket.updateCamera=function(){var t=e._nameSpace.doc._viewarea.getViewMatrix(),i=t.toGL().toString();i+=","+(t=e._nameSpace.doc._viewarea.getProjectionMatrix()).toGL().toString(),null!=this._lastMsg&&this._lastMsg!=i&&(this._lastMsg=i,this.send(i))}}else x3dom.debug.logError("Browser has no WebSocket support!")},nodeChanged:function(){var e=this._vf.label.length;this._nameObjMap={},this._createTime=new Array(e),this._visibleList=new Array(e);for(var t=0;t<e;++t){var i=this._childNodes[t];i&&x3dom.isa(i,x3dom.nodeTypes.X3DShapeNode)?(this._nameObjMap[this._vf.label[t]]={shape:i,pos:t},this._visibleList[t]=!0):(this._visibleList[t]=!1,x3dom.debug.logError("Invalid children: "+this._vf.label[t])),this._createTime[t]=0}this.invalidateVolume(),x3dom.debug.logInfo("RemoteSelectionGroup has "+e+" entries.")},fieldChanged:function(e){if("url"==e)this._websocket&&(this._websocket.close(),this._websocket=null),this.initializeSocket();else if("invisibleNodes"==e){for(var t=0,i=this._vf.label.length;t<i;++t){var o=this._childNodes[t];if(o&&x3dom.isa(o,x3dom.nodeTypes.X3DShapeNode)){this._visibleList[t]=!0;for(var s=0,r=this._vf.invisibleNodes.length;s<r;++s){var n=this._vf.invisibleNodes[s],a=n.lastIndexOf("*"),d=!1;if(a>0&&(n=n.substring(0,a),d=!0),!(n.length<=1)&&(d&&0==this._vf.label[t].indexOf(n)||this._vf.label[t]==n)){this._visibleList[t]=!1;break}}}else this._visibleList[t]=!1}this.invalidateVolume()}else"render"==e&&this.invalidateVolume()},getNumRenderedObjects:function(e,t){var i=e;if(this._vf.maxRenderedIds>0){var o=Math.max(this._vf.maxRenderedIds,16),s=1;t&&(s=Math.min(this._vf.scaleRenderedIdsOnMove,1)),o=Math.max(Math.round(s*o),0),i=Math.min(i,o)}return i},collectDrawableObjects:function(e,t,i,o,s,r){if(i&&this._parentNodes.length>1&&(i=!1),i&&(o=o||this.cacheInvalid())&&this.invalidateCache(),!((s=t.cull(e,this.graphState(),i,s))<=0)){var n,a,d=this._nameSpace.doc._viewarea.isMovingOrAnimating(),l=(new Date).getTime(),h=this._childNodes.length;if(this._vf.enableCulling){if(this._websocket&&this._websocket.updateCamera(),this._vf.label.length){for(a=this.getNumRenderedObjects(this._idList.length,d),n=0;n<a;n++){var f=this._nameObjMap[this._idList[n]];f&&f.shape?(f.shape.collectDrawableObjects(e,t,i,o,s,r),this._createTime[f.pos]=l):x3dom.debug.logError("Invalid label: "+this._idList[n])}for(n=0;n<this._childNodes.length;n++)this._childNodes[n]&&!d&&this._createTime[n]>0&&l-this._createTime[n]>1e4&&this._childNodes[n]._cleanupGLObjects&&(this._childNodes[n]._cleanupGLObjects(!0),this._createTime[n]=0)}}else{a=this.getNumRenderedObjects(h,d);var u=0;for(n=0;n<h;n++){var c=this._childNodes[n];if(c){var _=!0;this._visibleList[n]&&u<a&&c.collectDrawableObjects(e,t,i,o,s,r)&&(this._createTime[n]=l,u++,_=!1),_&&!d&&this._createTime[n]>0&&l-this._createTime[n]>1e4&&c._cleanupGLObjects&&(c._cleanupGLObjects(!0),this._createTime[n]=0)}}}}}})),x3dom.registerNodeType("Scene","Grouping",defineClass(x3dom.nodeTypes.X3DGroupingNode,(function(e){x3dom.nodeTypes.Scene.superClass.call(this,e),this.addField_SFString(e,"pickMode","idBuf"),this.addField_SFBool(e,"doPickPass",!0),this.addField_SFString(e,"shadowObjectIdMapping",""),this._lastMin=new x3dom.fields.SFVec3f(0,0,0),this._lastMax=new x3dom.fields.SFVec3f(1,1,1),this._shadowIdMap=null,this.loadMapping()}),{fieldChanged:function(e){"shadowObjectIdMapping"==e&&this.loadMapping()},updateVolume:function(){var e=this.getVolume();e.isValid()&&(this._lastMin=x3dom.fields.SFVec3f.copy(e.min),this._lastMax=x3dom.fields.SFVec3f.copy(e.max))},loadMapping:function(){if(this._shadowIdMap=null,0!=this._vf.shadowObjectIdMapping.length){var that=this,xhr=new XMLHttpRequest;xhr.open("GET",this._nameSpace.getURL(this._vf.shadowObjectIdMapping),!0),x3dom.RequestManager.addRequest(xhr),xhr.onload=function(){that._shadowIdMap=eval("("+xhr.response+")"),that._shadowIdMap&&that._shadowIdMap.mapping?x3dom.debug.assert(that._shadowIdMap.maxID<=that._shadowIdMap.mapping.length,"Too few ID map entries in "+that._vf.shadowObjectIdMapping+", length of mapping array is only "+that._shadowIdMap.mapping.length+" instead of "+that._shadowIdMap.ids.length+"!"):x3dom.debug.logWarning("Invalid ID map: "+that._vf.shadowObjectIdMapping)}}}})),x3dom.registerNodeType("X3DGeometryNode","Rendering",defineClass(x3dom.nodeTypes.X3DNode,(function(e){x3dom.nodeTypes.X3DGeometryNode.superClass.call(this,e),this.addField_SFBool(e,"solid",!0),this.addField_SFBool(e,"ccw",!0),this.addField_SFBool(e,"useGeoCache",!!this._nameSpace&&"true"==this._nameSpace.doc.properties.getProperty("useGeoCache","true").toLowerCase()),this.addField_SFBool(e,"lit",!0),this._mesh=new x3dom.Mesh(this)}),{getVolume:function(){return this._mesh.getVolume()},invalidateVolume:function(){this._mesh.invalidate()},getCenter:function(){return this._mesh.getCenter()},getDiameter:function(){return this._mesh.getDiameter()},doIntersect:function(e){return this._mesh.doIntersect(e)},forceUpdateCoverage:function(){return!1},hasIndexOffset:function(){return!1},getColorTexture:function(){return null},getColorTextureURL:function(){return null},parentAdded:function(e){x3dom.isa(e,x3dom.nodeTypes.X3DShapeNode)&&(e._cleanupGLObjects&&e._cleanupGLObjects(!0),e.setAllDirty(),e.invalidateVolume())},needLighting:function(){var e=this._mesh._primType.indexOf("TRIANGLE")>=0;return this._vf.lit&&e}})),x3dom.registerNodeType("Mesh","Rendering",defineClass(x3dom.nodeTypes.X3DGeometryNode,(function(e){x3dom.nodeTypes.Mesh.superClass.call(this,e),this.addField_SFString(e,"primType","triangle"),this.addField_MFInt32(e,"index",[]),this.addField_MFNode("vertexAttributes",x3dom.nodeTypes.X3DVertexAttributeNode)}),{nodeChanged:function(){var e,t=(new Date).getTime(),i=this._cf.vertexAttributes.nodes.length;for(e=0;e<i;e++){var o=this._cf.vertexAttributes.nodes[e]._vf.name;switch(o.toLowerCase()){case"position":this._mesh._positions[0]=this._cf.vertexAttributes.nodes[e]._vf.value.toGL();break;case"normal":this._mesh._normals[0]=this._cf.vertexAttributes.nodes[e]._vf.value.toGL();break;case"texcoord":this._mesh._texCoords[0]=this._cf.vertexAttributes.nodes[e]._vf.value.toGL();break;case"color":this._mesh._colors[0]=this._cf.vertexAttributes.nodes[e]._vf.value.toGL();break;default:this._mesh._dynamicFields[o]={},this._mesh._dynamicFields[o].numComponents=this._cf.vertexAttributes.nodes[e]._vf.numComponents,this._mesh._dynamicFields[o].value=this._cf.vertexAttributes.nodes[e]._vf.value.toGL()}}this._mesh._indices[0]=this._vf.index.toGL(),this.invalidateVolume(),this._mesh._numFaces=this._mesh._indices[0].length/3,this._mesh._numCoords=this._mesh._positions[0].length/3;var s=(new Date).getTime()-t;x3dom.debug.logWarning("Mesh load time: "+s+" ms")}})),x3dom.registerNodeType("PointSet","Rendering",defineClass(x3dom.nodeTypes.X3DGeometryNode,(function(e){x3dom.nodeTypes.PointSet.superClass.call(this,e),this.addField_SFNode("coord",x3dom.nodeTypes.X3DCoordinateNode),this.addField_SFNode("color",x3dom.nodeTypes.X3DColorNode),this.addField_SFNode("normal",x3dom.nodeTypes.Normal),this._mesh._primType="POINTS"}),{nodeChanged:function(){var e=(new Date).getTime(),t=this._cf.coord.node;x3dom.debug.assert(t,"PointSet without coord node!");var i=t.getPoints(),o=3,s=this._cf.color.node,r=new x3dom.fields.MFColor;s&&(r=s._vf.color,x3dom.debug.assert(i.length==r.length,"Size of color and coord array differs!"),x3dom.isa(s,x3dom.nodeTypes.ColorRGBA)&&(o=4));var n=this._cf.normal.node,a=new x3dom.fields.MFVec3f;n&&(a=n._vf.vector),this._mesh._numColComponents=o,this._mesh._lit=!1,this._mesh._indices[0]=[],this._mesh._positions[0]=i.toGL(),this._mesh._colors[0]=r.toGL(),this._mesh._normals[0]=a.toGL(),this._mesh._texCoords[0]=[],this.invalidateVolume(),this._mesh._numCoords=this._mesh._positions[0].length/3;(new Date).getTime()},fieldChanged:function(e){var t=null;"coord"==e?(t=this._cf.coord.node.getPoints(),this._mesh._positions[0]=t.toGL(),this.invalidateVolume(),this._parentNodes.forEach((function(e){e._dirty.positions=!0,e.invalidateVolume()}))):"color"==e&&(t=this._cf.color.node._vf.color,this._mesh._colors[0]=t.toGL(),this._parentNodes.forEach((function(e){e._dirty.colors=!0})))},needLighting:function(){return this._vf.lit&&this._cf.normal.node}})),x3dom.registerNodeType("X3DComposedGeometryNode","Rendering",defineClass(x3dom.nodeTypes.X3DGeometryNode,(function(e){x3dom.nodeTypes.X3DComposedGeometryNode.superClass.call(this,e),this.addField_SFBool(e,"colorPerVertex",!0),this.addField_SFBool(e,"normalPerVertex",!0),this.addField_SFString(e,"normalUpdateMode","fast"),this.addField_MFNode("attrib",x3dom.nodeTypes.X3DVertexAttributeNode),this.addField_SFNode("coord",x3dom.nodeTypes.X3DCoordinateNode),this.addField_SFNode("normal",x3dom.nodeTypes.Normal),this.addField_SFNode("color",x3dom.nodeTypes.X3DColorNode),this.addField_SFNode("texCoord",x3dom.nodeTypes.X3DTextureCoordinateNode)}),{handleAttribs:function(){var e,t=this._cf.attrib.nodes.length;for(e=0;e<t;e++){var i=this._cf.attrib.nodes[e]._vf.name;switch(i.toLowerCase()){case"position":this._mesh._positions[0]=this._cf.attrib.nodes[e]._vf.value.toGL();break;case"normal":this._mesh._normals[0]=this._cf.attrib.nodes[e]._vf.value.toGL();break;case"texcoord":this._mesh._texCoords[0]=this._cf.attrib.nodes[e]._vf.value.toGL();break;case"color":this._mesh._colors[0]=this._cf.attrib.nodes[e]._vf.value.toGL();break;default:this._mesh._dynamicFields[i]={},this._mesh._dynamicFields[i].numComponents=this._cf.attrib.nodes[e]._vf.numComponents,this._mesh._dynamicFields[i].value=this._cf.attrib.nodes[e]._vf.value.toGL()}}}})),x3dom.registerNodeType("LineSet","Rendering",defineClass(x3dom.nodeTypes.X3DGeometryNode,(function(e){x3dom.nodeTypes.LineSet.superClass.call(this,e),this.addField_MFInt32(e,"vertexCount",[]),this.addField_MFNode("attrib",x3dom.nodeTypes.X3DVertexAttributeNode),this.addField_SFNode("coord",x3dom.nodeTypes.X3DCoordinateNode),this.addField_SFNode("color",x3dom.nodeTypes.X3DColorNode),this._mesh._primType="LINES",x3dom.Utils.needLineWidth=!0}),{nodeChanged:function(){var e=this._cf.coord.node;x3dom.debug.assert(e);var t=e.getPoints();this._mesh._positions[0]=t.toGL();var i=this._cf.color.node;if(i){var o=i._vf.color;this._mesh._colors[0]=o.toGL(),this._mesh._numColComponents=3,x3dom.isa(i,x3dom.nodeTypes.ColorRGBA)&&(this._mesh._numColComponents=4)}var s=0;this._mesh._indices[0]=[];for(var r=0,n=this._vf.vertexCount.length;r<n;r++){var a=this._vf.vertexCount[r];if(a<2){x3dom.debug.logError("LineSet.vertexCount must not be smaller than 2!");break}for(var d=a-2;d>=0;d--)this._mesh._indices[0].push(s++,s),0==d&&s++}},fieldChanged:function(e){if("coord"==e){var t=this._cf.coord.node.getPoints();this._mesh._positions[0]=t.toGL(),this.invalidateVolume(),this._parentNodes.forEach((function(e){e._dirty.positions=!0,e.invalidateVolume()}))}else if("color"==e){var i=this._cf.color.node._vf.color;this._mesh._colors[0]=i.toGL(),this._parentNodes.forEach((function(e){e._dirty.colors=!0}))}}})),x3dom.registerNodeType("IndexedLineSet","Rendering",defineClass(x3dom.nodeTypes.X3DGeometryNode,(function(e){x3dom.nodeTypes.IndexedLineSet.superClass.call(this,e),this.addField_SFBool(e,"colorPerVertex",!0),this.addField_MFNode("attrib",x3dom.nodeTypes.X3DVertexAttributeNode),this.addField_SFNode("coord",x3dom.nodeTypes.X3DCoordinateNode),this.addField_SFNode("color",x3dom.nodeTypes.X3DColorNode),this.addField_MFInt32(e,"coordIndex",[]),this.addField_MFInt32(e,"colorIndex",[]),this._mesh._primType="LINES",x3dom.Utils.needLineWidth=!0}),{_buildGeometry:function(){var e=(new Date).getTime(),t=this._vf.coordIndex;-1!=t.slice(-1)[0]&&t.push(-1);var i=t.filter((function(e){return-1==e})).length,o=this._vf.colorPerVertex,s=this._vf.colorIndex;if(0==s.length&&!o)for(;s.length<i;)s.push(s.length);var r,n,a=!1,d=!1;o&&s.length>=t.length&&(d=!0),!o&&s.length>=i&&(d=!0);var l=this._cf.coord.node;x3dom.debug.assert(l),r=l.getPoints();var h,f,u,c,_,m,p,x,g=3,v=this._cf.color.node;if(v&&(a=!0,n=v._vf.color,x3dom.isa(v,x3dom.nodeTypes.ColorRGBA)&&(g=4)),this._mesh._indices[0]=[],this._mesh._positions[0]=[],this._mesh._colors[0]=[],a&&d||r.length>x3dom.Utils.maxIndexableCoords){for(f=0,u=0,c=0,h=0;h<t.length;++h)if(!(t[h]>r.length-1))if(-1!==t[h])switch(d&&x3dom.debug.assert(-1!=s[h]),f){case 0:_=+t[h],p=d&&o?+s[h]:d&&!o?+s[c]:_,f=1;break;case 1:T(this._mesh),f=2;break;case 2:_=m,p=x,T(this._mesh)}else f=0,c+=o?0:1;r.length>x3dom.Utils.maxIndexableCoords&&this._mesh.splitMesh(2)}else{var y=t.length;for(f=0,h=0;h<y;++h)if(-1!=t[h])switch(f){case 0:_=+t[h],f=1;break;case 1:m=+t[h],f=2,this._mesh._indices[0].push(_,m);break;case 2:_=m,m=+t[h],this._mesh._indices[0].push(_,m)}else f=0;this._mesh._positions[0]=r.toGL(),a&&(this._mesh._colors[0]=n.toGL(),this._mesh._numColComponents=g)}for(this.invalidateVolume(),this._mesh._numCoords=0,h=0;h<this._mesh._indices.length;h++)this._mesh._numCoords+=this._mesh._positions[h].length/3;(new Date).getTime();function T(e){m=+t[h],x=d&&o?+s[h]:d&&!o?+s[c]:m,e._indices[0].push(u++,u++),e._positions[0].push(r[_].x),e._positions[0].push(r[_].y),e._positions[0].push(r[_].z),e._positions[0].push(r[m].x),e._positions[0].push(r[m].y),e._positions[0].push(r[m].z),a&&(o||(p=x),e._colors[0].push(n[p].r),e._colors[0].push(n[p].g),e._colors[0].push(n[p].b),e._colors[0].push(n[x].r),e._colors[0].push(n[x].g),e._colors[0].push(n[x].b)),c+=o?1:0}},nodeChanged:function(){this._buildGeometry()},fieldChanged:function(e){"coord"==e?(this._buildGeometry(),this._parentNodes.forEach((function(e){e._dirty.positions=!0,e.invalidateVolume()}))):"color"==e?(this._buildGeometry(),this._parentNodes.forEach((function(e){e._dirty.colors=!0}))):"coordIndex"==e?(this._buildGeometry(),this._parentNodes.forEach((function(e){e._dirty.indexes=!0,e.invalidateVolume()}))):"colorIndex"==e&&(this._buildGeometry(),this._parentNodes.forEach((function(e){e._dirty.colors=!0,e.invalidateVolume()})))}})),x3dom.registerNodeType("IndexedTriangleSet","Rendering",defineClass(x3dom.nodeTypes.X3DComposedGeometryNode,(function(e){x3dom.nodeTypes.IndexedTriangleSet.superClass.call(this,e),this.addField_MFInt32(e,"index",[])}),{nodeChanged:function(){var e=(new Date).getTime();this.handleAttribs();var t,i,o,s,r=this._vf.colorPerVertex,n=this._vf.normalPerVertex,a=this._vf.ccw,d=this._vf.index,l=!1,h=!1,f=!1,u=this._cf.coord.node;x3dom.debug.assert(u),t=u._vf.point;var c=this._cf.normal.node;c?(l=!0,i=c._vf.vector):l=!1;var _="",m=2,p=this._cf.texCoord.node;x3dom.isa(p,x3dom.nodeTypes.MultiTextureCoordinate)&&p._cf.texCoord.nodes.length&&(p=p._cf.texCoord.nodes[0]),p?p._vf.point?(h=!0,o=p._vf.point,x3dom.isa(p,x3dom.nodeTypes.TextureCoordinate3D)&&(m=3)):p._vf.mode&&(_=p._vf.mode):h=!1;var x,g,v,y,T,b,S,F,E,M,C,w,A,R,D,N,I,P=3,V=this._cf.color.node;for(V?(f=!0,s=V._vf.color,x3dom.isa(V,x3dom.nodeTypes.ColorRGBA)&&(P=4)):f=!1,this._mesh._indices[0]=[],this._mesh._positions[0]=[],this._mesh._normals[0]=[],this._mesh._texCoords[0]=[],this._mesh._colors[0]=[];t.length%3>0;)t.push(t.length-1);if(T=t.length,!n||!r||T>x3dom.Utils.maxIndexableCoords){for(g=0,v=0,y=0,this._mesh._multiIndIndices=[],this._mesh._posSize=t.length,x=0;x<d.length;++x)switch(x>0&&x%3==0&&(g=0,y++),g){case 0:b=+d[x],n?E=b:n||(E=y),w=b,r?D=b:r||(D=y),g=1;break;case 1:S=+d[x],n?M=S:n||(M=y),A=S,r?N=S:r||(N=y),g=2;break;case 2:F=+d[x],n?C=F:n||(C=y),R=F,r?I=F:r||(I=y),g=3,this._mesh._indices[0].push(v++,v++,v++),this._mesh._positions[0].push(t[b].x),this._mesh._positions[0].push(t[b].y),this._mesh._positions[0].push(t[b].z),this._mesh._positions[0].push(t[S].x),this._mesh._positions[0].push(t[S].y),this._mesh._positions[0].push(t[S].z),this._mesh._positions[0].push(t[F].x),this._mesh._positions[0].push(t[F].y),this._mesh._positions[0].push(t[F].z),l?(this._mesh._normals[0].push(i[E].x),this._mesh._normals[0].push(i[E].y),this._mesh._normals[0].push(i[E].z),this._mesh._normals[0].push(i[M].x),this._mesh._normals[0].push(i[M].y),this._mesh._normals[0].push(i[M].z),this._mesh._normals[0].push(i[C].x),this._mesh._normals[0].push(i[C].y),this._mesh._normals[0].push(i[C].z)):this._mesh._multiIndIndices.push(b,S,F),f&&(this._mesh._colors[0].push(s[D].r),this._mesh._colors[0].push(s[D].g),this._mesh._colors[0].push(s[D].b),4===P&&this._mesh._colors[0].push(s[D].a),this._mesh._colors[0].push(s[N].r),this._mesh._colors[0].push(s[N].g),this._mesh._colors[0].push(s[N].b),4===P&&this._mesh._colors[0].push(s[N].a),this._mesh._colors[0].push(s[I].r),this._mesh._colors[0].push(s[I].g),this._mesh._colors[0].push(s[I].b),4===P&&this._mesh._colors[0].push(s[I].a)),h&&(this._mesh._texCoords[0].push(o[w].x),this._mesh._texCoords[0].push(o[w].y),3===m&&this._mesh._texCoords[0].push(o[w].z),this._mesh._texCoords[0].push(o[A].x),this._mesh._texCoords[0].push(o[A].y),3===m&&this._mesh._texCoords[0].push(o[A].z),this._mesh._texCoords[0].push(o[R].x),this._mesh._texCoords[0].push(o[R].y),3===m&&this._mesh._texCoords[0].push(o[R].z))}l||this._mesh.calcNormals(n?Math.PI:0),h||this._mesh.calcTexCoords(_),this._mesh.splitMesh()}else{for(y=0,x=0;x<d.length;x++)x>0&&x%3==0&&y++,this._mesh._indices[0].push(d[x]),!n&&l&&(this._mesh._normals[0].push(i[y].x),this._mesh._normals[0].push(i[y].y),this._mesh._normals[0].push(i[y].z)),!r&&f&&(this._mesh._colors[0].push(s[y].r),this._mesh._colors[0].push(s[y].g),this._mesh._colors[0].push(s[y].b),4===P&&this._mesh._colors[0].push(s[y].a));this._mesh._positions[0]=t.toGL(),l?this._mesh._normals[0]=i.toGL():this._mesh.calcNormals(n?Math.PI:0,a),h?(this._mesh._texCoords[0]=o.toGL(),this._mesh._numTexComponents=m):this._mesh.calcTexCoords(_),f&&r&&(this._mesh._colors[0]=s.toGL(),this._mesh._numColComponents=P)}for(this.invalidateVolume(),this._mesh._numFaces=0,this._mesh._numCoords=0,x=0;x<this._mesh._indices.length;x++)this._mesh._numFaces+=this._mesh._indices[x].length/3,this._mesh._numCoords+=this._mesh._positions[x].length/3;(new Date).getTime()},fieldChanged:function(e){var t=this._cf.coord.node._vf.point;if(t.length>x3dom.Utils.maxIndexableCoords)x3dom.debug.logWarning("IndexedTriangleSet: fieldChanged with too many coordinates not yet implemented!");else if("coord"==e)this._mesh._positions[0]=t.toGL(),this.invalidateVolume(),this._parentNodes.forEach((function(e){e._dirty.positions=!0,e.invalidateVolume()}));else if("color"==e){if(t=this._cf.color.node._vf.color,this._vf.colorPerVertex)this._mesh._colors[0]=t.toGL();else if(!this._vf.colorPerVertex){var i=0,o=3;x3dom.isa(this._cf.color.node,x3dom.nodeTypes.ColorRGBA)&&(o=4),this._mesh._colors[0]=[];for(var s=this._vf.index,r=0;r<s.length;++r)r>0&&r%3==0&&i++,this._mesh._colors[0].push(t[i].r),this._mesh._colors[0].push(t[i].g),this._mesh._colors[0].push(t[i].b),4===o&&this._mesh._colors[0].push(t[i].a)}this._parentNodes.forEach((function(e){e._dirty.colors=!0}))}else if("normal"==e){if(t=this._cf.normal.node._vf.vector,this._vf.normalPerVertex)this._mesh._normals[0]=t.toGL();else if(!this._vf.normalPerVertex){s=this._vf.index;this._mesh._normals[0]=[];for(i=0,r=0;r<s.length;++r)r>0&&r%3==0&&i++,this._mesh._normals[0].push(t[i].x),this._mesh._normals[0].push(t[i].y),this._mesh._normals[0].push(t[i].z)}this._parentNodes.forEach((function(e){e._dirty.normals=!0}))}else if("texCoord"==e){var n=this._cf.texCoord.node;x3dom.isa(n,x3dom.nodeTypes.MultiTextureCoordinate)&&n._cf.texCoord.nodes.length&&(n=n._cf.texCoord.nodes[0]),t=n._vf.point,this._mesh._texCoords[0]=t.toGL(),this._parentNodes.forEach((function(e){e._dirty.texcoords=!0}))}}})),x3dom.registerNodeType("IndexedTriangleStripSet","Rendering",defineClass(x3dom.nodeTypes.X3DComposedGeometryNode,(function(e){x3dom.nodeTypes.IndexedTriangleStripSet.superClass.call(this,e),this.addField_MFInt32(e,"index",[]),this._hasIndexOffset=!1,this._indexOffset=null}),{hasIndexOffset:function(){return this._hasIndexOffset},nodeChanged:function(){this.handleAttribs();var e,t,i,o,s=!1,r=!1,n=!1,a=this._vf.colorPerVertex,d=this._vf.normalPerVertex,l=this._vf.index;l.length&&-1!=l[l.length-1]&&l.push(-1);var h=this._cf.coord.node;x3dom.debug.assert(h),e=h._vf.point;var f=this._cf.normal.node;f?(s=!0,t=f._vf.vector):s=!1;var u="",c=2,_=this._cf.texCoord.node;x3dom.isa(_,x3dom.nodeTypes.MultiTextureCoordinate)&&_._cf.texCoord.nodes.length&&(_=_._cf.texCoord.nodes[0]),_?_._vf.point?(r=!0,i=_._vf.point,x3dom.isa(_,x3dom.nodeTypes.TextureCoordinate3D)&&(c=3)):_._vf.mode&&(u=_._vf.mode):r=!1,this._mesh._numTexComponents=c;var m=3,p=this._cf.color.node;p?(n=!0,o=p._vf.color,x3dom.isa(p,x3dom.nodeTypes.ColorRGBA)&&(m=4)):n=!1,this._mesh._numColComponents=m,this._mesh._indices[0]=[],this._mesh._positions[0]=[],this._mesh._normals[0]=[],this._mesh._texCoords[0]=[],this._mesh._colors[0]=[],this.invalidateVolume(),this._mesh._numFaces=0,this._mesh._numCoords=0;var x=0,g=0;if(s&&e.length<=x3dom.Utils.maxIndexableCoords){this._hasIndexOffset=!0,this._indexOffset=[],this._mesh._primType="TRIANGLESTRIP";var v=[0];for(P=0;P<l.length;P++)-1==l[P]?(x++,v.push(this._mesh._indices[0].length)):(this._mesh._indices[0].push(+l[P]),d||(this._mesh._normals[0].push(t[x].x),this._mesh._normals[0].push(t[x].y),this._mesh._normals[0].push(t[x].z)),a||(this._mesh._colors[0].push(o[x].r),this._mesh._colors[0].push(o[x].g),this._mesh._colors[0].push(o[x].b),4===m&&this._mesh._colors[0].push(o[x].a)));for(this._mesh._positions[0]=e.toGL(),d&&(this._mesh._normals[0]=t.toGL()),r?(this._mesh._texCoords[0]=i.toGL(),this._mesh._numTexComponents=c):x3dom.debug.logWarning("IndexedTriangleStripSet: no texCoords given and won't calculate!"),n&&(a&&(this._mesh._colors[0]=o.toGL()),this._mesh._numColComponents=m),P=1;P<v.length;P++){var y=v[P]-v[P-1];this._indexOffset.push({count:y,offset:2*v[P-1]}),this._mesh._numFaces+=y-2}this._mesh._numCoords=this._mesh._positions[0].length/3}else{var T,b,S,F,E,M,C,w,A,R,D,N;this._hasIndexOffset=!1;for(var I=!1,P=1;P<l.length-2;++P)-1!=l[P+1]?(I?(T=l[P],b=l[P-1],S=l[P+1]):(T=l[P-1],b=l[P],S=l[P+1]),I=!I,d?(F=T,E=b,M=S):F=E=M=x,C=T,w=b,A=S,a?(R=T,D=b,N=S):R=D=N=x,this._mesh._indices[0].push(g++,g++,g++),this._mesh._positions[0].push(e[T].x),this._mesh._positions[0].push(e[T].y),this._mesh._positions[0].push(e[T].z),this._mesh._positions[0].push(e[b].x),this._mesh._positions[0].push(e[b].y),this._mesh._positions[0].push(e[b].z),this._mesh._positions[0].push(e[S].x),this._mesh._positions[0].push(e[S].y),this._mesh._positions[0].push(e[S].z),s&&(this._mesh._normals[0].push(t[F].x),this._mesh._normals[0].push(t[F].y),this._mesh._normals[0].push(t[F].z),this._mesh._normals[0].push(t[E].x),this._mesh._normals[0].push(t[E].y),this._mesh._normals[0].push(t[E].z),this._mesh._normals[0].push(t[M].x),this._mesh._normals[0].push(t[M].y),this._mesh._normals[0].push(t[M].z)),n&&(this._mesh._colors[0].push(o[R].r),this._mesh._colors[0].push(o[R].g),this._mesh._colors[0].push(o[R].b),4===m&&this._mesh._colors[0].push(o[R].a),this._mesh._colors[0].push(o[D].r),this._mesh._colors[0].push(o[D].g),this._mesh._colors[0].push(o[D].b),4===m&&this._mesh._colors[0].push(o[D].a),this._mesh._colors[0].push(o[N].r),this._mesh._colors[0].push(o[N].g),this._mesh._colors[0].push(o[N].b),4===m&&this._mesh._colors[0].push(o[N].a)),r&&(this._mesh._texCoords[0].push(i[C].x),this._mesh._texCoords[0].push(i[C].y),3===c&&this._mesh._texCoords[0].push(i[C].z),this._mesh._texCoords[0].push(i[w].x),this._mesh._texCoords[0].push(i[w].y),3===c&&this._mesh._texCoords[0].push(i[w].z),this._mesh._texCoords[0].push(i[A].x),this._mesh._texCoords[0].push(i[A].y),3===c&&this._mesh._texCoords[0].push(i[A].z))):(P+=2,x++);for(s||this._mesh.calcNormals(Math.PI),r||this._mesh.calcTexCoords(u),this._mesh.splitMesh(),this.invalidateVolume(),P=0;P<this._mesh._indices.length;P++)this._mesh._numFaces+=this._mesh._indices[P].length/3,this._mesh._numCoords+=this._mesh._positions[P].length/3}},fieldChanged:function(e){if("coord"==e||"normal"==e||"texCoord"==e||"color"==e){var t=this._cf.coord.node._vf.point;if(null===this._cf.normal.node||t.length>x3dom.Utils.maxIndexableCoords){if("coord"==e){this._mesh._positions[0]=[],this._mesh._indices[0]=[],this._mesh._normals[0]=[],this._mesh._texCoords[0]=[];var i,o,s,r,n=!1,a=!1,d=!1,l=this._vf.colorPerVertex,h=this._vf.normalPerVertex,f=this._vf.index,u=this._cf.coord.node;x3dom.debug.assert(u),i=u._vf.point;var c=this._cf.normal.node;c?(n=!0,o=c._vf.vector):n=!1;var _="",m=2,p=this._cf.texCoord.node;x3dom.isa(p,x3dom.nodeTypes.MultiTextureCoordinate)&&p._cf.texCoord.nodes.length&&(p=p._cf.texCoord.nodes[0]),p?p._vf.point?(a=!0,s=p._vf.point,x3dom.isa(p,x3dom.nodeTypes.TextureCoordinate3D)&&(m=3)):p._vf.mode&&(_=p._vf.mode):a=!1,this._mesh._numTexComponents=m;var x=3,g=this._cf.color.node;g?(d=!0,r=g._vf.color,x3dom.isa(g,x3dom.nodeTypes.ColorRGBA)&&(x=4)):d=!1,this._mesh._numColComponents=x,this._mesh._indices[0]=[],this._mesh._positions[0]=[],this._mesh._normals[0]=[],this._mesh._texCoords[0]=[],this._mesh._colors[0]=[];var v,y,T,b,S,F,E,M,C,w=0,A=0,R=!1;if(n||a||d){for(var D=1;D<f.length-2;++D)-1!=f[D+1]?(R?(v=f[D],y=f[D-1],T=f[D+1]):(v=f[D-1],y=f[D],T=f[D+1]),R=!R,h?(V=v,b=y,S=T):V=b=S=w,O=v,F=y,E=T,l?(I=v,M=y,C=T):I=M=C=w,this._mesh._indices[0].push(A++,A++,A++),this._mesh._positions[0].push(i[v].x),this._mesh._positions[0].push(i[v].y),this._mesh._positions[0].push(i[v].z),this._mesh._positions[0].push(i[y].x),this._mesh._positions[0].push(i[y].y),this._mesh._positions[0].push(i[y].z),this._mesh._positions[0].push(i[T].x),this._mesh._positions[0].push(i[T].y),this._mesh._positions[0].push(i[T].z),n&&(this._mesh._normals[0].push(o[V].x),this._mesh._normals[0].push(o[V].y),this._mesh._normals[0].push(o[V].z),this._mesh._normals[0].push(o[b].x),this._mesh._normals[0].push(o[b].y),this._mesh._normals[0].push(o[b].z),this._mesh._normals[0].push(o[S].x),this._mesh._normals[0].push(o[S].y),this._mesh._normals[0].push(o[S].z)),d&&(this._mesh._colors[0].push(r[I].r),this._mesh._colors[0].push(r[I].g),this._mesh._colors[0].push(r[I].b),4===x&&this._mesh._colors[0].push(r[I].a),this._mesh._colors[0].push(r[M].r),this._mesh._colors[0].push(r[M].g),this._mesh._colors[0].push(r[M].b),4===x&&this._mesh._colors[0].push(r[M].a),this._mesh._colors[0].push(r[C].r),this._mesh._colors[0].push(r[C].g),this._mesh._colors[0].push(r[C].b),4===x&&this._mesh._colors[0].push(r[C].a)),a&&(this._mesh._texCoords[0].push(s[O].x),this._mesh._texCoords[0].push(s[O].y),3===m&&this._mesh._texCoords[0].push(s[O].z),this._mesh._texCoords[0].push(s[F].x),this._mesh._texCoords[0].push(s[F].y),3===m&&this._mesh._texCoords[0].push(s[F].z),this._mesh._texCoords[0].push(s[E].x),this._mesh._texCoords[0].push(s[E].y),3===m&&this._mesh._texCoords[0].push(s[E].z))):(D+=2,w++);n||this._mesh.calcNormals(Math.PI),a||this._mesh.calcTexCoords(_),this._mesh.splitMesh()}else{for(R=!1,D=1;D<f.length;++D)-1!=f[D+1]?(R?(this._mesh._indices[0].push(f[D]),this._mesh._indices[0].push(f[D-1]),this._mesh._indices[0].push(f[D+1])):(this._mesh._indices[0].push(f[D-1]),this._mesh._indices[0].push(f[D]),this._mesh._indices[0].push(f[D+1])),R=!R):D+=2;this._mesh._positions[0]=i.toGL(),this._mesh.calcNormals(Math.PI),this._mesh.calcTexCoords(_)}for(this.invalidateVolume(),this._mesh._numFaces=0,this._mesh._numCoords=0,D=0;D<this._mesh._indices.length;D++)this._mesh._numFaces+=this._mesh._indices[D].length/3,this._mesh._numCoords+=this._mesh._positions[D].length/3;this._parentNodes.forEach((function(e){e.setAllDirty(),e.invalidateVolume()}))}else if("color"==e){var N=this._cf.color.node._vf.color,I=(w=0,M=C=0);x=3;x3dom.isa(this._cf.color.node,x3dom.nodeTypes.ColorRGBA)&&(x=4),this._mesh._colors[0]=[];f=this._vf.index,R=!1;for(D=1;D<f.length-2;++D)-1!=f[D+1]?(this._vf.colorPerVertex?(R?(I=f[D],M=f[D-1],C=f[D+1]):(I=f[D-1],M=f[D],C=f[D+1]),R=!R):this._vf.colorPerVertex||(I=M=C=w),this._mesh._colors[0].push(N[I].r),this._mesh._colors[0].push(N[I].g),this._mesh._colors[0].push(N[I].b),4===x&&this._mesh._colors[0].push(N[I].a),this._mesh._colors[0].push(N[M].r),this._mesh._colors[0].push(N[M].g),this._mesh._colors[0].push(N[M].b),4===x&&this._mesh._colors[0].push(N[M].a),this._mesh._colors[0].push(N[C].r),this._mesh._colors[0].push(N[C].g),this._mesh._colors[0].push(N[C].b),4===x&&this._mesh._colors[0].push(N[C].a)):(D+=2,w++);this._parentNodes.forEach((function(e){e._dirty.colors=!0}))}else if("normal"==e){var P=this._cf.normal.node._vf.vector,V=(w=0,b=S=0);this._mesh._normals[0]=[];f=this._vf.index,R=!1;for(D=1;D<f.length-2;++D)-1!=f[D+1]?(this._vf.normalPerVertex?(R?(V=f[D],b=f[D-1],S=f[D+1]):(V=f[D-1],b=f[D],S=f[D+1]),R=!R):this._vf.normalPerVertex||(V=b=S=w),this._mesh._normals[0].push(P[V].x),this._mesh._normals[0].push(P[V].y),this._mesh._normals[0].push(P[V].z),this._mesh._normals[0].push(P[b].x),this._mesh._normals[0].push(P[b].y),this._mesh._normals[0].push(P[b].z),this._mesh._normals[0].push(P[S].x),this._mesh._normals[0].push(P[S].y),this._mesh._normals[0].push(P[S].z)):(D+=2,w++);this._parentNodes.forEach((function(e){e._dirty.normals=!0}))}else if("texCoord"==e){p=this._cf.texCoord.node;x3dom.isa(p,x3dom.nodeTypes.MultiTextureCoordinate)&&p._cf.texCoord.nodes.length&&(p=p._cf.texCoord.nodes[0]);var L=p._vf.point,O=F=E=0;m=2;x3dom.isa(p,x3dom.nodeTypes.TextureCoordinate3D)&&(m=3),this._mesh._texCoords[0]=[];f=this._vf.index,R=!1;for(D=1;D<f.length-2;++D)-1!=f[D+1]?(R?(O=f[D],F=f[D-1],E=f[D+1]):(O=f[D-1],F=f[D],E=f[D+1]),R=!R,this._mesh._texCoords[0].push(L[O].x),this._mesh._texCoords[0].push(L[O].y),3===m&&this._mesh._texCoords[0].push(L[O].z),this._mesh._texCoords[0].push(L[F].x),this._mesh._texCoords[0].push(L[F].y),3===m&&this._mesh._texCoords[0].push(L[F].z),this._mesh._texCoords[0].push(L[E].x),this._mesh._texCoords[0].push(L[E].y),3===m&&this._mesh._texCoords[0].push(L[E].z)):D+=2;this._parentNodes.forEach((function(e){e._dirty.texcoords=!0}))}}else if("coord"==e)this._mesh._positions[0]=t.toGL(),this.invalidateVolume(),this._parentNodes.forEach((function(e){e._dirty.positions=!0,e.invalidateVolume()}));else if("color"==e){if(t=this._cf.color.node._vf.color,this._vf.colorPerVertex)this._mesh._colors[0]=t.toGL();else if(!this._vf.colorPerVertex){w=0,x=3;x3dom.isa(this._cf.color.node,x3dom.nodeTypes.ColorRGBA)&&(x=4),this._mesh._colors[0]=[];f=this._vf.index;for(D=0;D<f.length;++D)-1!=f[D]?(this._mesh._colors[0].push(t[w].r),this._mesh._colors[0].push(t[w].g),this._mesh._colors[0].push(t[w].b),4===x&&this._mesh._colors[0].push(t[w].a)):w++}this._parentNodes.forEach((function(e){e._dirty.colors=!0}))}else if("normal"==e){if(t=this._cf.normal.node._vf.vector,this._vf.normalPerVertex)this._mesh._normals[0]=t.toGL();else if(!this._vf.normalPerVertex){f=this._vf.index;this._mesh._normals[0]=[];w=0;for(D=0;D<f.length;++D)-1!=f[D]?(this._mesh._normals[0].push(t[w].x),this._mesh._normals[0].push(t[w].y),this._mesh._normals[0].push(t[w].z)):w++}this._parentNodes.forEach((function(e){e._dirty.normals=!0}))}else if("texCoord"==e){p=this._cf.texCoord.node;x3dom.isa(p,x3dom.nodeTypes.MultiTextureCoordinate)&&p._cf.texCoord.nodes.length&&(p=p._cf.texCoord.nodes[0]),t=p._vf.point,this._mesh._texCoords[0]=t.toGL(),this._parentNodes.forEach((function(e){e._dirty.texcoords=!0}))}}else x3dom.debug.logWarning("IndexedTriangleStripSet: fieldChanged for "+e+" not yet implemented!")}})),x3dom.registerNodeType("TriangleSet","Rendering",defineClass(x3dom.nodeTypes.X3DComposedGeometryNode,(function(e){x3dom.nodeTypes.TriangleSet.superClass.call(this,e)}),{_buildGeometry:function(){var e,t,i,o,s=this._vf.colorPerVertex,r=this._vf.normalPerVertex,n=this._vf.ccw,a=!1,d=!1,l=!1,h=this._cf.coord.node;if(x3dom.debug.assert(h),!h||h._vf.point.length<3)this._vf.visible=!1;else{e=h._vf.point;var f=this._cf.normal.node;f?(a=!0,t=f._vf.vector):a=!1;var u="",c=2,_=this._cf.texCoord.node;x3dom.isa(_,x3dom.nodeTypes.MultiTextureCoordinate)&&_._cf.texCoord.nodes.length&&(_=_._cf.texCoord.nodes[0]),_?_._vf.point?(d=!0,i=_._vf.point,x3dom.isa(_,x3dom.nodeTypes.TextureCoordinate3D)&&(c=3)):_._vf.mode&&(u=_._vf.mode):d=!1;var m=3,p=this._cf.color.node;for(p?(l=!0,o=p._vf.color,x3dom.isa(p,x3dom.nodeTypes.ColorRGBA)&&(m=4)):l=!1;e.length%3>0;)e.pop();this._mesh._indices[0]=new Array(e.length),this._mesh._positions[0]=[],this._mesh._normals[0]=[],this._mesh._texCoords[0]=[],this._mesh._colors[0]=[];var x,g=e.length/3,v=0;for(x=0;x<g;x++)this._mesh._indices[0][v]=v++,this._mesh._indices[0][v]=v++,this._mesh._indices[0][v]=v++,!r&&a&&(this._mesh._normals[0].push(t[x].x),this._mesh._normals[0].push(t[x].y),this._mesh._normals[0].push(t[x].z)),!s&&l&&(this._mesh._colors[0].push(o[x].r),this._mesh._colors[0].push(o[x].g),this._mesh._colors[0].push(o[x].b),4===m&&this._mesh._colors[0].push(o[x].a));this._mesh._positions[0]=e.toGL(),a?this._mesh._normals[0]=t.toGL():this._mesh.calcNormals(r?Math.PI:0,n),d?(this._mesh._texCoords[0]=i.toGL(),this._mesh._numTexComponents=c):this._mesh.calcTexCoords(u),l&&s&&(this._mesh._colors[0]=o.toGL(),this._mesh._numColComponents=m),this._mesh._numFaces=g,this._mesh._numCoords=e.length,this.invalidateVolume()}},nodeChanged:function(){this._buildGeometry()},fieldChanged:function(e){"coord"==e?(this._buildGeometry(),this._parentNodes.forEach((function(e){e._dirty.positions=!0,e.invalidateVolume()}))):"color"==e?(this._buildGeometry(),this._parentNodes.forEach((function(e){e._dirty.colors=!0}))):"normal"==e?(this._buildGeometry(),this._parentNodes.forEach((function(e){e._dirty.normals=!0}))):"texCoord"==e&&(this._buildGeometry(),this._parentNodes.forEach((function(e){e._dirty.texcoords=!0})))}})),x3dom.registerNodeType("X3DGeometricPropertyNode","Rendering",defineClass(x3dom.nodeTypes.X3DNode,(function(e){x3dom.nodeTypes.X3DGeometricPropertyNode.superClass.call(this,e)}))),x3dom.registerNodeType("X3DCoordinateNode","Rendering",defineClass(x3dom.nodeTypes.X3DGeometricPropertyNode,(function(e){x3dom.nodeTypes.X3DCoordinateNode.superClass.call(this,e)}),{fieldChanged:function(e){"coord"!==e&&"point"!==e||this._parentNodes.forEach((function(e){e.fieldChanged("coord")}))},parentAdded:function(e){e._mesh&&e._cf.coord&&e._cf.coord.node!==this&&e.fieldChanged("coord")}})),x3dom.registerNodeType("Coordinate","Rendering",defineClass(x3dom.nodeTypes.X3DCoordinateNode,(function(e){x3dom.nodeTypes.Coordinate.superClass.call(this,e),this.addField_MFVec3f(e,"point",[])}),{getPoints:function(){return this._vf.point}})),x3dom.registerNodeType("CoordinateDouble","Nurbs",defineClass(x3dom.nodeTypes.X3DCoordinateNode,(function(e){x3dom.nodeTypes.CoordinateDouble.superClass.call(this,e),this.addField_MFVec3d(e,"point",[])}),{getPoints:function(){return this._vf.point}})),x3dom.registerNodeType("Normal","Rendering",defineClass(x3dom.nodeTypes.X3DGeometricPropertyNode,(function(e){x3dom.nodeTypes.Normal.superClass.call(this,e),this.addField_MFVec3f(e,"vector",[])}),{fieldChanged:function(e){"normal"!==e&&"vector"!==e||this._parentNodes.forEach((function(e){e.fieldChanged("normal")}))},parentAdded:function(e){e._mesh&&e._cf.normal.node!==this&&e.fieldChanged("normal")}})),x3dom.registerNodeType("X3DColorNode","Rendering",defineClass(x3dom.nodeTypes.X3DGeometricPropertyNode,(function(e){x3dom.nodeTypes.X3DColorNode.superClass.call(this,e)}),{fieldChanged:function(e){"color"===e&&this._parentNodes.forEach((function(e){e.fieldChanged("color")}))},parentAdded:function(e){e._mesh&&e._cf.color.node!==this&&e.fieldChanged("color")}})),x3dom.registerNodeType("Color","Rendering",defineClass(x3dom.nodeTypes.X3DColorNode,(function(e){x3dom.nodeTypes.Color.superClass.call(this,e),this.addField_MFColor(e,"color",[])}))),x3dom.registerNodeType("ColorRGBA","Rendering",defineClass(x3dom.nodeTypes.X3DColorNode,(function(e){x3dom.nodeTypes.ColorRGBA.superClass.call(this,e),this.addField_MFColorRGBA(e,"color",[])}))),x3dom.registerNodeType("ParticleSet","Rendering",defineClass(x3dom.nodeTypes.PointSet,(function(e){x3dom.nodeTypes.ParticleSet.superClass.call(this,e),this.addField_SFString(e,"mode","ViewDirQuads"),this.addField_SFString(e,"drawOrder","Any"),this.addField_SFNode("normal",x3dom.nodeTypes.Normal),this.addField_MFVec3f(e,"size",[]),this.addField_MFInt32(e,"index",[]),this.addField_MFFloat(e,"textureZ",[]),this._mesh._primType="POINTS"}),{drawOrder:function(){return this._vf.drawOrder.toLowerCase()},nodeChanged:function(){var e=this._cf.coord.node;x3dom.debug.assert(e,"ParticleSet without coord node!");var t=e.getPoints(),i=3,o=this._cf.color.node,s=new x3dom.fields.MFColor;o&&(s=o._vf.color,x3dom.debug.assert(t.length==s.length,"Size of color and coord array differs!"),x3dom.isa(o,x3dom.nodeTypes.ColorRGBA)&&(i=4));var r=this._cf.normal.node,n=new x3dom.fields.MFVec3f;r&&(n=r._vf.vector);var a=[];if("any"!=this.drawOrder()&&0==(a=this._vf.index.toGL()).length){var d,l=t.length;for(a=new Array(l),d=0;d<l;d++)a[d]=d}this._mesh._numColComponents=i,this._mesh._lit=!1,this._mesh._indices[0]=a,this._mesh._positions[0]=t.toGL(),this._mesh._colors[0]=s.toGL(),this._mesh._normals[0]=n.toGL(),this._mesh._texCoords[0]=[],this.invalidateVolume(),this._mesh._numCoords=this._mesh._positions[0].length/3},fieldChanged:function(e){var t=null;if("index"==e)this._mesh._indices[0]=this._vf.index.toGL(),this._parentNodes.forEach((function(e){e._dirty.indexes=!0}));else if("size"==e)this._parentNodes.forEach((function(e){e._dirty.specialAttribs=!0}));else if("coord"==e){t=this._cf.coord.node.getPoints(),this._mesh._positions[0]=t.toGL();var i=[];if("any"!=this.drawOrder()&&0==(i=this._vf.index.toGL()).length){var o,s=t.length;for(i=new Array(s),o=0;o<s;o++)i[o]=o}this._mesh._indices[0]=i,this.invalidateVolume(),this._parentNodes.forEach((function(e){e._dirty.positions=!0,e._dirty.indexes=!0,e.invalidateVolume()}))}else"color"==e&&(t=this._cf.color.node._vf.color,this._mesh._colors[0]=t.toGL(),this._parentNodes.forEach((function(e){e._dirty.colors=!0})))}})),x3dom.registerNodeType("ClipPlane","Rendering",defineClass(x3dom.nodeTypes.X3DChildNode,(function(e){x3dom.nodeTypes.ClipPlane.superClass.call(this,e),this.addField_SFBool(e,"enabled",!0),this.addField_SFVec4f(e,"plane",0,1,0,0),this.addField_SFFloat(e,"cappingStrength",0),this.addField_SFColor(e,"cappingColor",1,1,1),this.addField_SFBool(e,"on",!0)}),{fieldChanged:function(e){},nodeChanged:function(){x3dom.nodeTypes.ClipPlane.count++},onRemove:function(){x3dom.nodeTypes.ClipPlane.count--},parentAdded:function(e){},parentRemoved:function(e){}})),x3dom.nodeTypes.ClipPlane.count=0,x3dom.registerNodeType("X3DAppearanceNode","Shape",defineClass(x3dom.nodeTypes.X3DNode,(function(e){x3dom.nodeTypes.X3DAppearanceNode.superClass.call(this,e)}))),x3dom.registerNodeType("Appearance","Shape",defineClass(x3dom.nodeTypes.X3DAppearanceNode,(function(e){x3dom.nodeTypes.Appearance.superClass.call(this,e),this.addField_SFNode("material",x3dom.nodeTypes.X3DMaterialNode),this.addField_SFNode("texture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("textureTransform",x3dom.nodeTypes.X3DTextureTransformNode),this.addField_SFNode("lineProperties",x3dom.nodeTypes.LineProperties),this.addField_SFNode("pointProperties",x3dom.nodeTypes.PointProperties),this.addField_SFNode("colorMaskMode",x3dom.nodeTypes.ColorMaskMode),this.addField_SFNode("blendMode",x3dom.nodeTypes.BlendMode),this.addField_SFNode("depthMode",x3dom.nodeTypes.DepthMode),this.addField_MFNode("shaders",x3dom.nodeTypes.X3DShaderNode),this.addField_SFString(e,"sortType","auto"),this.addField_SFInt32(e,"sortKey",0),this.addField_SFFloat(e,"alphaClipThreshold",.1),this._shader=null}),{fieldChanged:function(e){"alphaClipThreshold"==e&&this._parentNodes.forEach((function(e){e.setAppDirty()}))},nodeChanged:function(){this._cf.material.node,this._cf.shaders.nodes.length?this._shader=this._cf.shaders.nodes[0]:this._shader&&(this._shader=null),this._parentNodes.forEach((function(e){e.setAppDirty()})),this.checkSortType()},checkSortType:function(){if("auto"==this._vf.sortType)if(this._cf.material.node&&(this._cf.material.node._vf.transparency>0||this._cf.material.node._vf.backTransparency&&this._cf.material.node._vf.backTransparency>0))this._vf.sortType="transparent";else if(this._cf.texture.node&&this._cf.texture.node._vf.url.length)this._cf.texture.node._vf.url[0].toLowerCase().indexOf(".png")>=0?this._vf.sortType="transparent":this._vf.sortType="opaque";else if(x3dom.isa(this._cf.material.node,x3dom.nodeTypes.PhysicalMaterial)){var e=this._cf.material.node;"OPAQUE"==e._vf.alphaMode?this._vf.sortType="opaque":"BLEND"!=e._vf.alphaMode&&"MASK"!=e._vf.alphaMode||(this._vf.sortType="transparent");var t=e._cf.baseColorTexture.node;"opaque"==this._vf.sortType&&t&&t._vf.url.length&&t._vf.url[0].toLowerCase().indexOf(".png")>=0&&(this._vf.sortType="transparent")}else this._vf.sortType="opaque"},texTransformMatrix:function(){return null===this._cf.textureTransform.node?x3dom.fields.SFMatrix4f.identity():this._cf.textureTransform.node.texTransformMatrix()},parentAdded:function(e){this!=x3dom.nodeTypes.Appearance._defaultNode&&e.setAppDirty()}})),x3dom.nodeTypes.Appearance.defaultNode=function(){return x3dom.nodeTypes.Appearance._defaultNode||(x3dom.nodeTypes.Appearance._defaultNode=new x3dom.nodeTypes.Appearance,x3dom.nodeTypes.Appearance._defaultNode.nodeChanged()),x3dom.nodeTypes.Appearance._defaultNode},x3dom.registerNodeType("X3DAppearanceChildNode","Shape",defineClass(x3dom.nodeTypes.X3DNode,(function(e){x3dom.nodeTypes.X3DAppearanceChildNode.superClass.call(this,e)}))),x3dom.registerNodeType("BlendMode","Shape",defineClass(x3dom.nodeTypes.X3DAppearanceChildNode,(function(e){x3dom.nodeTypes.BlendMode.superClass.call(this,e),this.addField_SFString(e,"srcFactor","src_alpha"),this.addField_SFString(e,"destFactor","one_minus_src_alpha"),this.addField_SFColor(e,"color",1,1,1),this.addField_SFFloat(e,"colorTransparency",0),this.addField_SFString(e,"alphaFunc","none"),this.addField_SFFloat(e,"alphaFuncValue",0),this.addField_SFString(e,"equation","none")}))),x3dom.registerNodeType("DepthMode","Shape",defineClass(x3dom.nodeTypes.X3DAppearanceChildNode,(function(e){x3dom.nodeTypes.DepthMode.superClass.call(this,e),this.addField_SFBool(e,"enableDepthTest",!0),this.addField_SFString(e,"depthFunc","none"),this.addField_SFBool(e,"readOnly",!1),this.addField_SFFloat(e,"zNearRange",-1),this.addField_SFFloat(e,"zFarRange",-1)}))),x3dom.registerNodeType("ColorMaskMode","Shape",defineClass(x3dom.nodeTypes.X3DAppearanceChildNode,(function(e){x3dom.nodeTypes.ColorMaskMode.superClass.call(this,e),this.addField_SFBool(e,"maskR",!0),this.addField_SFBool(e,"maskG",!0),this.addField_SFBool(e,"maskB",!0),this.addField_SFBool(e,"maskA",!0)}))),x3dom.registerNodeType("LineProperties","Shape",defineClass(x3dom.nodeTypes.X3DAppearanceChildNode,(function(e){x3dom.nodeTypes.LineProperties.superClass.call(this,e),this.addField_SFBool(e,"applied",!0),this.addField_SFInt32(e,"linetype",1),this.addField_SFFloat(e,"linewidthScaleFactor",0)}))),x3dom.registerNodeType("PointProperties","Shape",defineClass(x3dom.nodeTypes.X3DAppearanceChildNode,(function(e){x3dom.nodeTypes.PointProperties.superClass.call(this,e),this.addField_SFFloat(e,"pointSizeScaleFactor",1),this.addField_SFFloat(e,"pointSizeMinValue",1),this.addField_SFFloat(e,"pointSizeMaxValue",1),this.addField_SFVec3f(e,"attenuation",1,0,0)}),{nodeChanged:function(){this._vf.pointSizeMinValue>this._vf.pointSizeMaxValue&&(x3dom.debug.logWarning("pointSizeMinValue is larger than pointSizeMaxValue, will set to MaxValue"),this._vf.pointSizeMinValue=this._vf.pointSizeMaxValue)},fieldChanged:function(e){this._nodeChanged()}})),x3dom.registerNodeType("X3DMaterialNode","Shape",defineClass(x3dom.nodeTypes.X3DAppearanceChildNode,(function(e){x3dom.nodeTypes.X3DMaterialNode.superClass.call(this,e)}),{_fieldChanged:function(e,t){t.indexOf(e)>-1&&this._parentNodes.forEach((function(e){e._parentNodes.forEach((function(e){x3dom.isa(e,x3dom.nodeTypes.X3DShapeNode)&&(e._dirty.material=!0)})),x3dom.isa(e,x3dom.nodeTypes.X3DAppearanceNode)&&e.checkSortType()}))}})),x3dom.registerNodeType("Material","Shape",defineClass(x3dom.nodeTypes.X3DMaterialNode,(function(e){x3dom.nodeTypes.Material.superClass.call(this,e),this.addField_SFFloat(e,"ambientIntensity",.2),this.addField_SFColor(e,"diffuseColor",.8,.8,.8),this.addField_SFColor(e,"emissiveColor",0,0,0),this.addField_SFFloat(e,"shininess",.2),this.addField_SFColor(e,"specularColor",0,0,0),this.addField_SFFloat(e,"transparency",0)}),{fieldChanged:function(e){this._fieldChanged(e,["ambientIntensity","diffuseColor","emissiveColor","shininess","specularColor","transparency"])}})),x3dom.nodeTypes.Material.defaultNode=function(){return x3dom.nodeTypes.Material._defaultNode||(x3dom.nodeTypes.Material._defaultNode=new x3dom.nodeTypes.Material,x3dom.nodeTypes.Material._defaultNode.nodeChanged()),x3dom.nodeTypes.Material._defaultNode},x3dom.registerNodeType("TwoSidedMaterial","Shape",defineClass(x3dom.nodeTypes.Material,(function(e){x3dom.nodeTypes.TwoSidedMaterial.superClass.call(this,e),this.addField_SFFloat(e,"backAmbientIntensity",.2),this.addField_SFColor(e,"backDiffuseColor",.8,.8,.8),this.addField_SFColor(e,"backEmissiveColor",0,0,0),this.addField_SFFloat(e,"backShininess",.2),this.addField_SFColor(e,"backSpecularColor",0,0,0),this.addField_SFFloat(e,"backTransparency",0),this.addField_SFBool(e,"separateBackColor",!1)}),{fieldChanged:function(e){this._fieldChanged(e,["ambientIntensity","diffuseColor","emissiveColor","shininess","specularColor","transparency","backAmbientIntensity","backDiffuseColor","backEmissiveColor","backShininess","backSpecularColor","backTransparency","separateBackColor"])}})),x3dom.registerNodeType("PhysicalMaterial","Shape",defineClass(x3dom.nodeTypes.X3DMaterialNode,(function(e){x3dom.nodeTypes.X3DMaterialNode.superClass.call(this,e),this.addField_SFString(e,"model","roughnessMetallic"),this.addField_SFColorRGBA(e,"baseColorFactor",1,1,1,1),this.addField_SFFloat(e,"metallicFactor",0),this.addField_SFFloat(e,"roughnessFactor",.2),this.addField_SFColorRGBA(e,"diffuseFactor",1,1,1,1),this.addField_SFColor(e,"specularFactor",1,1,1),this.addField_SFFloat(e,"glossinessFactor",1),this.addField_SFColor(e,"emissiveFactor",0,0,0),this.addField_SFString(e,"normalSpace","TANGENT"),this.addField_SFString(e,"alphaMode","OPAQUE"),this.addField_SFFloat(e,"alphaCutoff",.5),this.addField_SFVec3f(e,"normalBias",-1,-1,1),this.addField_SFFloat(e,"normalScale",1),this.addField_SFBool(e,"unlit",!1),this.addField_SFNode("baseColorTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("emissiveTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("roughnessMetallicTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("specularGlossinessTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("occlusionRoughnessMetallicTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("normalTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("occlusionTexture",x3dom.nodeTypes.X3DTextureNode)}),{fieldChanged:function(e){this._fieldChanged(e,["baseColorFactor","metallicFactor","roughnessFactor","emissiveFactor"]),"alphaMode"==e&&this._parentNodes.forEach((function(e){e._parentNodes.forEach((function(e){x3dom.isa(e,x3dom.nodeTypes.X3DShapeNode)&&(e._dirty.shader=!0)})),x3dom.isa(e,x3dom.nodeTypes.X3DAppearanceNode)&&e.checkSortType()}))},hasTextures:function(){return this._cf.baseColorTexture.node||this._cf.normalTexture.node||this._cf.occlusionTexture.node||this._cf.emissiveTexture.node||this._cf.roughnessMetallicTexture.node},getTextures:function(){var e=[];return this._cf.baseColorTexture.node&&(this._cf.baseColorTexture.node._type="diffuseMap",e.push(this._cf.baseColorTexture.node)),this._cf.normalTexture.node&&(this._cf.normalTexture.node._type="normalMap",e.push(this._cf.normalTexture.node)),this._cf.occlusionTexture.node&&(this._cf.occlusionTexture.node._type="occlusionMap",e.push(this._cf.occlusionTexture.node)),this._cf.emissiveTexture.node&&(this._cf.emissiveTexture.node._type="emissiveMap",e.push(this._cf.emissiveTexture.node)),this._cf.roughnessMetallicTexture.node&&(this._cf.roughnessMetallicTexture.node._type="roughnessMetallicMap",e.push(this._cf.roughnessMetallicTexture.node)),this._cf.specularGlossinessTexture.node&&(this._cf.specularGlossinessTexture.node._type="specularGlossinessMap",e.push(this._cf.specularGlossinessTexture.node)),this._cf.occlusionRoughnessMetallicTexture.node&&(this._cf.occlusionRoughnessMetallicTexture.node._type="occlusionRoughnessMetallicMap",e.push(this._cf.occlusionRoughnessMetallicTexture.node)),e}})),x3dom.registerNodeType("X3DShapeNode","Shape",defineClass(x3dom.nodeTypes.X3DBoundedObject,(function(e){x3dom.nodeTypes.X3DShapeNode.superClass.call(this,e),this.addField_SFBool(e,"isPickable",!0),this.addField_SFInt32(e,"idOffset",0),this.addField_SFNode("appearance",x3dom.nodeTypes.X3DAppearanceNode),this.addField_SFNode("geometry",x3dom.nodeTypes.X3DGeometryNode),this._objectID=0,this._shaderProperties=null,this._clipPlanes=[],this._cleanupGLObjects=null,this._dirty={positions:!0,normals:!0,texcoords:!0,colors:!0,tangents:!0,binormals:!0,specialAttribs:!0,indexes:!0,texture:!0,material:!0,text:!0,shader:!0,ids:!0},this._indexOffset=0,this._coordStrideOffset=[0,0],this._normalStrideOffset=[0,0],this._texCoordStrideOffset=[0,0],this._texCoord2StrideOffset=[0,0],this._colorStrideOffset=[0,0],this._idStrideOffset=[0,0],this._tangentStrideOffset=[0,0],this._binormalStrideOffset=[0,0],this._tessellationProperties=[]}),{collectDrawableObjects:function(e,t,i,o,s,r){var n=this.graphState();return i&&this._parentNodes.length>1&&(i=!1),i&&(o=o||this.cacheInvalid())&&this.invalidateCache(),!(!this._cf.geometry.node||t.cull(e,n,i,s)<=0)&&(i&&!this._graph.globalMatrix&&(this._graph.globalMatrix=e),this._clipPlanes.length!=r.length&&(this._dirty.shader=!0),this._clipPlanes=r,t.addShape(this,e,n),!0)},getVolume:function(){var e=this._graph.volume;if(!this.volumeValid()&&this.renderFlag&&this.renderFlag()){var t=this._cf.geometry.node,i=t?t.getVolume():null;i&&i.isValid()&&e.extendBounds(i.min,i.max)}return e},getCenter:function(){var e=this._cf.geometry.node;return e?e.getCenter():new x3dom.fields.SFVec3f(0,0,0)},getDiameter:function(){var e=this._cf.geometry.node;return e?e.getDiameter():0},doIntersect:function(e){return this._cf.geometry.node.doIntersect(e)},forceUpdateCoverage:function(){var e=this._cf.geometry.node;return!!e&&e.forceUpdateCoverage()},tessellationProperties:function(){var e=this._cf.geometry.node;return e&&e._indexOffset?e._indexOffset:this._tessellationProperties},isLit:function(){return this._cf.geometry.node._vf.lit},isSolid:function(){var e=this._cf.appearance.node&&this._cf.appearance.node._cf.material.node&&x3dom.isa(this._cf.appearance.node._cf.material.node,x3dom.nodeTypes.TwoSidedMaterial);return this._cf.geometry.node._vf.solid&&!e},isCCW:function(){return this._cf.geometry.node._vf.ccw},parentRemoved:function(e){for(var t=0,i=this._childNodes.length;t<i;t++){var o=this._childNodes[t];o&&o.parentRemoved(this)}e&&e.invalidateVolume(),this._parentNodes.length>0&&this.invalidateVolume(),this._cleanupGLObjects&&this._cleanupGLObjects()},unsetDirty:function(){this._dirty.positions=!1,this._dirty.normals=!1,this._dirty.texcoords=!1,this._dirty.colors=!1,this._dirty.tangents=!1,this._dirty.binormals=!1,this._dirty.specialAttribs=!1,this._dirty.indexes=!1,this._dirty.texture=!1,this._dirty.material=!1,this._dirty.text=!1,this._dirty.shader=!1},unsetGeoDirty:function(){this._dirty.positions=!1,this._dirty.normals=!1,this._dirty.texcoords=!1,this._dirty.colors=!1,this._dirty.tangents=!1,this._dirty.binormals=!1,this._dirty.specialAttribs=!1,this._dirty.indexes=!1},setAllDirty:function(){this._dirty.positions=!0,this._dirty.normals=!0,this._dirty.texcoords=!0,this._dirty.colors=!0,this._dirty.tangents=!0,this._dirty.binormals=!0,this._dirty.specialAttribs=!0,this._dirty.indexes=!0,this._dirty.texture=!0,this._dirty.material=!0,this._dirty.text=!0,this._dirty.shader=!0,this.invalidateVolume()},setAppDirty:function(){this._dirty.texture=!0,this._dirty.material=!0,this._dirty.shader=!0},setGeoDirty:function(){this._dirty.positions=!0,this._dirty.normals=!0,this._dirty.texcoords=!0,this._dirty.colors=!0,this._dirty.tangents=!0,this._dirty.binormals=!0,this._dirty.specialAttribs=!0,this._dirty.indexes=!0,this.invalidateVolume()},getShaderProperties:function(e){return(null==this._shaderProperties||1==this._dirty.shader||x3dom.Utils.checkDirtyEnvironment(e,this._shaderProperties)||x3dom.Utils.checkDirtyPhysicalEnvironmentLight(e,this._shaderProperties)||void 0!==this._webgl&&this._webgl.dirtyLighting!=x3dom.Utils.checkDirtyLighting(e))&&(this._shaderProperties=x3dom.Utils.generateProperties(e,this),this._dirty.shader=!1,void 0!==this._webgl&&(this._webgl.dirtyLighting=x3dom.Utils.checkDirtyLighting(e))),this._shaderProperties},getTextures:function(){var e=[],t=this._cf.appearance.node;if(t){var i=t._cf.texture.node;i&&(x3dom.isa(i,x3dom.nodeTypes.MultiTexture)?e=e.concat(i.getTextures()):e.push(i));var o=t._cf.shaders.nodes[0];o&&x3dom.isa(o,x3dom.nodeTypes.CommonSurfaceShader)&&(e=e.concat(o.getTextures()));var s=t._cf.material.node;s&&x3dom.isa(s,x3dom.nodeTypes.PhysicalMaterial)&&(e=e.concat(s.getTextures()))}var r=this._cf.geometry.node;return r&&x3dom.isa(r,x3dom.nodeTypes.Text)&&(e=e.concat(r)),e}})),x3dom.registerNodeType("Shape","Shape",defineClass(x3dom.nodeTypes.X3DShapeNode,(function(e){x3dom.nodeTypes.Shape.superClass.call(this,e)}),{nodeChanged:function(){this._cf.appearance.node,this._cf.geometry.node?this._objectID||(this._objectID=++x3dom.nodeTypes.Shape.objectID,x3dom.nodeTypes.Shape.idMap.nodeID[this._objectID]=this):this._DEF&&x3dom.debug.logError("No geometry given in Shape/"+this._DEF),this.setAllDirty()}})),x3dom.nodeTypes.Shape.shaderPartID=0,x3dom.nodeTypes.Shape.objectID=0,x3dom.nodeTypes.Shape.idMap={nodeID:{},remove:function(e){for(var t in this.nodeID)if(this.nodeID.hasOwnProperty(t)){var i=this.nodeID[t];i._objectID&&e._objectID&&i._objectID===e._objectID&&(delete this.nodeID[t],x3dom.debug.logInfo("Unreg "+i._objectID))}}},x3dom.registerNodeType("X3DLightNode","Lighting",defineClass(x3dom.nodeTypes.X3DChildNode,(function(e){x3dom.nodeTypes.X3DLightNode.superClass.call(this,e),e?e.doc._nodeBag.lights.push(this):x3dom.debug.logWarning("X3DLightNode: No runtime context found!"),this._lightID=0,this._dirty=!0,this.addField_SFFloat(e,"ambientIntensity",0),this.addField_SFColor(e,"color",1,1,1),this.addField_SFFloat(e,"intensity",1),this.addField_SFBool(e,"global",!1),this.addField_SFBool(e,"on",!0),this.addField_SFFloat(e,"shadowIntensity",0),this.addField_SFInt32(e,"shadowMapSize",1024),this.addField_SFInt32(e,"shadowFilterSize",0),this.addField_SFFloat(e,"shadowOffset",0),this.addField_SFFloat(e,"zNear",-1),this.addField_SFFloat(e,"zFar",-1)}),{getViewMatrix:function(e){return x3dom.fields.SFMatrix4f.identity},nodeChanged:function(){this._lightID||(this._lightID=++x3dom.nodeTypes.X3DLightNode.lightID)},fieldChanged:function(e){this._vf.hasOwnProperty(e)&&(this._dirty=!0,this.postMessage(e+"_changed",this._vf[e]))},parentRemoved:function(e){if(1===this._parentNodes.length&&this._parentNodes[0]==e)for(var t=this.findX3DDoc(),i=0,o=t._nodeBag.lights.length;i<o;i++)t._nodeBag.lights[i]===this&&t._nodeBag.lights.splice(i,1)},onRemove:function(){}})),x3dom.nodeTypes.X3DLightNode.lightID=0,x3dom.registerNodeType("DirectionalLight","Lighting",defineClass(x3dom.nodeTypes.X3DLightNode,(function(e){x3dom.nodeTypes.DirectionalLight.superClass.call(this,e),this.addField_SFVec3f(e,"direction",0,0,-1),this.addField_SFInt32(e,"shadowCascades",1),this.addField_SFFloat(e,"shadowSplitFactor",1),this.addField_SFFloat(e,"shadowSplitOffset",.1)}),{getViewMatrix:function(e){var t=this.getCurrentTransform().multMatrixVec(this._vf.direction).normalize();return x3dom.fields.Quaternion.rotateFromTo(new x3dom.fields.SFVec3f(0,0,-1),t).toMatrix().transpose().mult(x3dom.fields.SFMatrix4f.translation(e.negate()))}})),x3dom.registerNodeType("PointLight","Lighting",defineClass(x3dom.nodeTypes.X3DLightNode,(function(e){x3dom.nodeTypes.PointLight.superClass.call(this,e),this.addField_SFVec3f(e,"attenuation",1,0,0),this.addField_SFVec3f(e,"location",0,0,0),this.addField_SFFloat(e,"radius",100),this._vf.global=!0}),{getViewMatrix:function(e){var t=this.getCurrentTransform().multMatrixPnt(this._vf.location);return x3dom.fields.Quaternion.rotateFromTo(new x3dom.fields.SFVec3f(0,0,-1),e).toMatrix().transpose().mult(x3dom.fields.SFMatrix4f.translation(t.negate()))}})),x3dom.registerNodeType("SpotLight","Lighting",defineClass(x3dom.nodeTypes.X3DLightNode,(function(e){x3dom.nodeTypes.SpotLight.superClass.call(this,e),this.addField_SFVec3f(e,"direction",0,0,-1),this.addField_SFVec3f(e,"attenuation",1,0,0),this.addField_SFVec3f(e,"location",0,0,0),this.addField_SFFloat(e,"radius",100),this.addField_SFFloat(e,"beamWidth",Math.PI/2),this.addField_SFFloat(e,"cutOffAngle",Math.PI/2),this.addField_SFInt32(e,"shadowCascades",1),this.addField_SFFloat(e,"shadowSplitFactor",1),this.addField_SFFloat(e,"shadowSplitOffset",.1),this._vf.global=!0}),{getViewMatrix:function(e){var t=this.getCurrentTransform().multMatrixPnt(this._vf.location),i=this.getCurrentTransform().multMatrixVec(this._vf.direction).normalize();return x3dom.fields.Quaternion.rotateFromTo(new x3dom.fields.SFVec3f(0,0,-1),i).toMatrix().transpose().mult(x3dom.fields.SFMatrix4f.translation(t.negate()))}})),x3dom.registerNodeType("PhysicalEnvironmentLight","Lighting",defineClass(x3dom.nodeTypes.X3DLightNode,(function(e){x3dom.nodeTypes.PhysicalEnvironmentLight.superClass.call(this,e),this.addField_SFVec3f(e,"direction",0,0,-1),this.addField_SFString(e,"diffuse","https://x3dom.org/download/assets/pbr/papermillDiffuse.dds"),this.addField_SFString(e,"specular","https://x3dom.org/download/assets/pbr/papermillSpecular.dds"),this.addField_SFInt32(e,"shadowCascades",1),this.addField_SFFloat(e,"shadowSplitFactor",1),this.addField_SFFloat(e,"shadowSplitOffset",.1)}),{fieldChanged:function(e){},getViewMatrix:function(e){var t=this.getCurrentTransform().multMatrixVec(this._vf.direction).normalize();return x3dom.fields.Quaternion.rotateFromTo(new x3dom.fields.SFVec3f(0,0,-1),t).toMatrix().transpose().mult(x3dom.fields.SFMatrix4f.translation(e.negate()))}})),x3dom.registerNodeType("X3DFollowerNode","Followers",defineClass(x3dom.nodeTypes.X3DChildNode,(function(e){x3dom.nodeTypes.X3DFollowerNode.superClass.call(this,e),e?e.doc._nodeBag.followers.push(this):x3dom.debug.logWarning("X3DFollowerNode: No runtime context found!"),this.addField_SFBool(e,"isActive",!1),this._eps=x3dom.fields.Eps}),{parentRemoved:function(e){if(0===this._parentNodes.length)for(var t=this.findX3DDoc(),i=0,o=t._nodeBag.followers.length;i<o;i++)t._nodeBag.followers[i]===this&&t._nodeBag.followers.splice(i,1)},tick:function(e){return!1},stepResponse:function(e){return e<=0?0:e>=this._vf.duration?1:this.stepResponseCore(e/this._vf.duration)},stepResponseCore:function(e){return.5-.5*Math.cos(e*Math.PI)}})),x3dom.registerNodeType("X3DChaserNode","Followers",defineClass(x3dom.nodeTypes.X3DFollowerNode,(function(e){x3dom.nodeTypes.X3DChaserNode.superClass.call(this,e),this.addField_SFTime(e,"duration",1),this._initDone=!1,this._stepTime=0,this._currTime=0,this._bufferEndTime=0,this._numSupports=60}))),x3dom.registerNodeType("X3DDamperNode","Followers",defineClass(x3dom.nodeTypes.X3DFollowerNode,(function(e){x3dom.nodeTypes.X3DDamperNode.superClass.call(this,e),this.addField_SFTime(e,"tau",.3),this.addField_SFFloat(e,"tolerance",-1),this.addField_SFInt32(e,"order",3),this._eps=this._vf.tolerance<0?this._eps:this._vf.tolerance,this._lastTick=0}))),x3dom.registerNodeType("ColorChaser","Followers",defineClass(x3dom.nodeTypes.X3DChaserNode,(function(e){x3dom.nodeTypes.ColorChaser.superClass.call(this,e),this.addField_SFColor(e,"initialDestination",.8,.8,.8),this.addField_SFColor(e,"initialValue",.8,.8,.8),this.addField_SFColor(e,"value",0,0,0),this.addField_SFColor(e,"destination",0,0,0),this._buffer=new x3dom.fields.MFColor,this._previousValue=new x3dom.fields.SFColor(0,0,0),this._value=new x3dom.fields.SFColor(0,0,0),this.initialize()}),{fieldChanged:function(e){if(e.indexOf("destination")>=0)this.initialize(),this.updateBuffer(this._currTime),this._vf.isActive||this.postMessage("isActive",!0);else if(e.indexOf("value")>=0){this.initialize(),this._previousValue.setValues(this._vf.value);for(var t=1;t<this._buffer.length;t++)this._buffer[t].setValues(this._vf.value);this.postMessage("value",this._vf.value),this._vf.isActive||this.postMessage("isActive",!0)}},initialize:function(){if(!this._initDone){this._initDone=!0,this._vf.destination=this._vf.initialDestination,this._buffer.length=this._numSupports,this._buffer[0]=this._vf.initialDestination;for(var e=1;e<this._buffer.length;e++)this._buffer[e]=this._vf.initialValue;this._previousValue=this._vf.initialValue,this._stepTime=this._vf.duration/this._numSupports;var t=!this._buffer[0].equals(this._buffer[1],this._eps);this._vf.isActive!==t&&this.postMessage("isActive",t)}},tick:function(e){if(this.initialize(),this._currTime=e,!this._bufferEndTime)return this._bufferEndTime=e,this._value=this._vf.initialValue,this.postMessage("value",this._value),!0;var t=this.updateBuffer(e),i=this._previousValue,o=this._buffer[this._buffer.length-1].subtract(this._previousValue),s=o.multiply(this.stepResponse((this._buffer.length-1+t)*this._stepTime));i=i.add(s);for(var r=this._buffer.length-2;r>=0;r--)s=(o=this._buffer[r].subtract(this._buffer[r+1])).multiply(this.stepResponse((r+t)*this._stepTime)),i=i.add(s);return i.equals(this._value,this._eps)?this.postMessage("isActive",!1):(this._value.setValues(i),this.postMessage("value",this._value)),this._vf.isActive},updateBuffer:function(e){var t,i,o,s=(e-this._bufferEndTime)/this._stepTime;if(s>=1){if(s-=i=Math.floor(s),i<this._buffer.length){for(this._previousValue=this._buffer[this._buffer.length-i],t=this._buffer.length-1;t>=i;t--)this._buffer[t]=this._buffer[t-i];for(t=0;t<i;t++)o=t/i,this._buffer[t]=this._buffer[i].multiply(o).add(this._vf.destination.multiply(1-o))}else for(this._previousValue=i==this._buffer.length?this._buffer[0]:this._vf.destination,t=0;t<this._buffer.length;t++)this._buffer[t]=this._vf.destination;this._bufferEndTime+=i*this._stepTime}return s}})),x3dom.registerNodeType("ColorDamper","Followers",defineClass(x3dom.nodeTypes.X3DDamperNode,(function(e){x3dom.nodeTypes.ColorDamper.superClass.call(this,e),this.addField_SFColor(e,"initialDestination",.8,.8,.8),this.addField_SFColor(e,"initialValue",.8,.8,.8),this.addField_SFColor(e,"value",0,0,0),this.addField_SFColor(e,"destination",0,0,0),this._value0=new x3dom.fields.SFColor(0,0,0),this._value1=new x3dom.fields.SFColor(0,0,0),this._value2=new x3dom.fields.SFColor(0,0,0),this._value3=new x3dom.fields.SFColor(0,0,0),this._value4=new x3dom.fields.SFColor(0,0,0),this._value5=new x3dom.fields.SFColor(0,0,0),this.initialize()}),{fieldChanged:function(e){"tolerance"===e?this._eps=this._vf.tolerance<0?.001:this._vf.tolerance:e.indexOf("destination")>=0?this._value0.equals(this._vf.destination,this._eps)||(this._value0=this._vf.destination,this._vf.isActive||this.postMessage("isActive",!0)):e.indexOf("value")>=0&&(this._value1.setValues(this._vf.value),this._value2.setValues(this._vf.value),this._value3.setValues(this._vf.value),this._value4.setValues(this._vf.value),this._value5.setValues(this._vf.value),this._lastTick=0,this.postMessage("value",this._value5),this._vf.isActive||(this._lastTick=0,this.postMessage("isActive",!0)))},initialize:function(){this._value0.setValues(this._vf.initialDestination),this._value1.setValues(this._vf.initialValue),this._value2.setValues(this._vf.initialValue),this._value3.setValues(this._vf.initialValue),this._value4.setValues(this._vf.initialValue),this._value5.setValues(this._vf.initialValue),this._lastTick=0;var e=!this._value0.equals(this._value1,this._eps);this._vf.isActive!==e&&this.postMessage("isActive",e)},distance:function(e,t){var i=e.subtract(t);return Math.sqrt(i.r*i.r+i.g*i.g+i.b*i.b)},tick:function(e){if(!this._lastTick)return this._lastTick=e,!1;var t=e-this._lastTick,i=Math.exp(-t/this._vf.tau);this._value1=this._vf.order>0&&this._vf.tau?this._value0.add(this._value1.subtract(this._value0).multiply(i)):new x3dom.fields.SFColor(this._value0.r,this._value0.g,this._value0.b),this._value2=this._vf.order>1&&this._vf.tau?this._value1.add(this._value2.subtract(this._value1).multiply(i)):new x3dom.fields.SFColor(this._value1.r,this._value1.g,this._value1.b),this._value3=this._vf.order>2&&this._vf.tau?this._value2.add(this._value3.subtract(this._value2).multiply(i)):new x3dom.fields.SFColor(this._value2.r,this._value2.g,this._value2.b),this._value4=this._vf.order>3&&this._vf.tau?this._value3.add(this._value4.subtract(this._value3).multiply(i)):new x3dom.fields.SFColor(this._value3.r,this._value3.g,this._value3.b),this._value5=this._vf.order>4&&this._vf.tau?this._value4.add(this._value5.subtract(this._value4).multiply(i)):new x3dom.fields.SFColor(this._value4.r,this._value4.g,this._value4.b);var o=this.distance(this._value1,this._value0);if(this._vf.order>1){var s=this.distance(this._value2,this._value1);s>o&&(o=s)}if(this._vf.order>2){var r=this.distance(this._value3,this._value2);r>o&&(o=r)}if(this._vf.order>3){var n=this.distance(this._value4,this._value3);n>o&&(o=n)}if(this._vf.order>4){var a=this.distance(this._value5,this._value4);a>o&&(o=a)}return o<=this._eps?(this._value1.setValues(this._value0),this._value2.setValues(this._value0),this._value3.setValues(this._value0),this._value4.setValues(this._value0),this._value5.setValues(this._value0),this.postMessage("value",this._value0),this.postMessage("isActive",!1),this._lastTick=0,!1):(this.postMessage("value",this._value5),this._lastTick=e,!0)}})),x3dom.registerNodeType("OrientationChaser","Followers",defineClass(x3dom.nodeTypes.X3DChaserNode,(function(e){x3dom.nodeTypes.OrientationChaser.superClass.call(this,e),this.addField_SFRotation(e,"initialDestination",0,1,0,0),this.addField_SFRotation(e,"initialValue",0,1,0,0),this.addField_SFRotation(e,"value",0,1,0,0),this.addField_SFRotation(e,"destination",0,1,0,0),this._numSupports=30,this._buffer=new x3dom.fields.MFRotation,this._previousValue=new x3dom.fields.Quaternion(0,1,0,0),this._value=new x3dom.fields.Quaternion(0,1,0,0),this.initialize()}),{fieldChanged:function(e){if(e.indexOf("destination")>=0)this.initialize(),this.updateBuffer(this._currTime),this._vf.isActive||this.postMessage("isActive",!0);else if(e.indexOf("value")>=0){this.initialize(),this._previousValue.setValues(this._vf.value);for(var t=1;t<this._buffer.length;t++)this._buffer[t].setValues(this._vf.value);this.postMessage("value",this._vf.value),this._vf.isActive||this.postMessage("isActive",!0)}},initialize:function(){if(!this._initDone){this._initDone=!0,this._vf.destination=x3dom.fields.Quaternion.copy(this._vf.initialDestination),this._buffer.length=this._numSupports,this._buffer[0]=x3dom.fields.Quaternion.copy(this._vf.initialDestination);for(var e=1;e<this._buffer.length;e++)this._buffer[e]=x3dom.fields.Quaternion.copy(this._vf.initialValue);this._previousValue=x3dom.fields.Quaternion.copy(this._vf.initialValue),this._stepTime=this._vf.duration/this._numSupports;var t=!this._buffer[0].equals(this._buffer[1],this._eps);this._vf.isActive!==t&&this.postMessage("isActive",t)}},tick:function(e){if(this.initialize(),this._currTime=e,!this._bufferEndTime)return this._bufferEndTime=e,this._value=x3dom.fields.Quaternion.copy(this._vf.initialValue),this.postMessage("value",this._value),!0;var t=this.updateBuffer(e),i=x3dom.fields.Quaternion.copy(this._previousValue),o=this._previousValue.inverse().multiply(this._buffer[this._buffer.length-1]);i=i.slerp(i.multiply(o),this.stepResponse((this._buffer.length-1+t)*this._stepTime));for(var s=this._buffer.length-2;s>=0;s--)o=this._buffer[s+1].inverse().multiply(this._buffer[s]),i=i.slerp(i.multiply(o),this.stepResponse((s+t)*this._stepTime));return i.equals(this._value,this._eps)?this.postMessage("isActive",!1):(i=i.normalize(i),this._value.setValues(i),this.postMessage("value",this._value)),this._vf.isActive},updateBuffer:function(e){var t,i,o,s=(e-this._bufferEndTime)/this._stepTime;if(s>=1){if(s-=i=Math.floor(s),i<this._buffer.length){for(this._previousValue=x3dom.fields.Quaternion.copy(this._buffer[this._buffer.length-i]),t=this._buffer.length-1;t>=i;t--)this._buffer[t]=x3dom.fields.Quaternion.copy(this._buffer[t-i]);for(t=0;t<i;t++)o=t/i,this._buffer[t]=this._vf.destination.slerp(this._buffer[i],o)}else for(this._previousValue=x3dom.fields.Quaternion.copy(i==this._buffer.length?this._buffer[0]:this._vf.destination),t=0;t<this._buffer.length;t++)this._buffer[t]=x3dom.fields.Quaternion.copy(this._vf.destination);this._bufferEndTime+=i*this._stepTime}return s}})),x3dom.registerNodeType("OrientationDamper","Followers",defineClass(x3dom.nodeTypes.X3DDamperNode,(function(e){x3dom.nodeTypes.OrientationDamper.superClass.call(this,e),this.addField_SFRotation(e,"initialDestination",0,1,0,0),this.addField_SFRotation(e,"initialValue",0,1,0,0),this.addField_SFRotation(e,"value",0,1,0,0),this.addField_SFRotation(e,"destination",0,1,0,0),this._value0=new x3dom.fields.Quaternion(0,1,0,0),this._value1=new x3dom.fields.Quaternion(0,1,0,0),this._value2=new x3dom.fields.Quaternion(0,1,0,0),this._value3=new x3dom.fields.Quaternion(0,1,0,0),this._value4=new x3dom.fields.Quaternion(0,1,0,0),this._value5=new x3dom.fields.Quaternion(0,1,0,0),this.initialize()}),{fieldChanged:function(e){"tolerance"===e?this._eps=this._vf.tolerance<0?.001:this._vf.tolerance:e.indexOf("destination")>=0?this._value0.equals(this._vf.destination,this._eps)||(this._value0=this._vf.destination,this._vf.isActive||this.postMessage("isActive",!0)):e.indexOf("value")>=0&&(this._value1.setValues(this._vf.value),this._value2.setValues(this._vf.value),this._value3.setValues(this._vf.value),this._value4.setValues(this._vf.value),this._value5.setValues(this._vf.value),this._lastTick=0,this.postMessage("value",this._value5),this._vf.isActive||(this._lastTick=0,this.postMessage("isActive",!0)))},initialize:function(){this._value0.setValues(this._vf.initialDestination),this._value1.setValues(this._vf.initialValue),this._value2.setValues(this._vf.initialValue),this._value3.setValues(this._vf.initialValue),this._value4.setValues(this._vf.initialValue),this._value5.setValues(this._vf.initialValue),this._lastTick=0;var e=!this._value0.equals(this._value1,this._eps);this._vf.isActive!==e&&this.postMessage("isActive",e)},tick:function(e){if(!this._lastTick)return this._lastTick=e,!1;var t=e-this._lastTick,i=Math.exp(-t/this._vf.tau);this._value1=this._vf.order>0&&this._vf.tau?this._value0.slerp(this._value1,i):new x3dom.fields.Quaternion(this._value0.x,this._value0.y,this._value0.z,this._value0.w),this._value2=this._vf.order>1&&this._vf.tau?this._value1.slerp(this._value2,i):new x3dom.fields.Quaternion(this._value1.x,this._value1.y,this._value1.z,this._value1.w),this._value3=this._vf.order>2&&this._vf.tau?this._value2.slerp(this._value3,i):new x3dom.fields.Quaternion(this._value2.x,this._value2.y,this._value2.z,this._value2.w),this._value4=this._vf.order>3&&this._vf.tau?this._value3.slerp(this._value4,i):new x3dom.fields.Quaternion(this._value3.x,this._value3.y,this._value3.z,this._value3.w),this._value5=this._vf.order>4&&this._vf.tau?this._value4.slerp(this._value5,i):new x3dom.fields.Quaternion(this._value4.x,this._value4.y,this._value4.z,this._value4.w);var o=Math.abs(this._value1.inverse().multiply(this._value0).angle());if(this._vf.order>1){var s=Math.abs(this._value2.inverse().multiply(this._value1).angle());s>o&&(o=s)}if(this._vf.order>2){var r=Math.abs(this._value3.inverse().multiply(this._value2).angle());r>o&&(o=r)}if(this._vf.order>3){var n=Math.abs(this._value4.inverse().multiply(this._value3).angle());n>o&&(o=n)}if(this._vf.order>4){var a=Math.abs(this._value5.inverse().multiply(this._value4).angle());a>o&&(o=a)}return o<=this._eps?(this._value1.setValues(this._value0),this._value2.setValues(this._value0),this._value3.setValues(this._value0),this._value4.setValues(this._value0),this._value5.setValues(this._value0),this.postMessage("value",this._value0),this.postMessage("isActive",!1),this._lastTick=0,!1):(this.postMessage("value",this._value5),this._lastTick=e,!0)}})),x3dom.registerNodeType("PositionChaser","Followers",defineClass(x3dom.nodeTypes.X3DChaserNode,(function(e){x3dom.nodeTypes.PositionChaser.superClass.call(this,e),this.addField_SFVec3f(e,"initialDestination",0,0,0),this.addField_SFVec3f(e,"initialValue",0,0,0),this.addField_SFVec3f(e,"value",0,0,0),this.addField_SFVec3f(e,"destination",0,0,0),this._buffer=new x3dom.fields.MFVec3f,this._previousValue=new x3dom.fields.SFVec3f(0,0,0),this._value=new x3dom.fields.SFVec3f(0,0,0),this.initialize()}),{fieldChanged:function(e){if(e.indexOf("destination")>=0)this.initialize(),this.updateBuffer(this._currTime),this._vf.isActive||this.postMessage("isActive",!0);else if(e.indexOf("value")>=0){this.initialize(),this._previousValue.setValues(this._vf.value);for(var t=1;t<this._buffer.length;t++)this._buffer[t].setValues(this._vf.value);this.postMessage("value",this._vf.value),this._vf.isActive||this.postMessage("isActive",!0)}},initialize:function(){if(!this._initDone){this._initDone=!0,this._vf.destination=x3dom.fields.SFVec3f.copy(this._vf.initialDestination),this._buffer.length=this._numSupports,this._buffer[0]=x3dom.fields.SFVec3f.copy(this._vf.initialDestination);for(var e=1;e<this._buffer.length;e++)this._buffer[e]=x3dom.fields.SFVec3f.copy(this._vf.initialValue);this._previousValue=x3dom.fields.SFVec3f.copy(this._vf.initialValue),this._stepTime=this._vf.duration/this._numSupports;var t=!this._buffer[0].equals(this._buffer[1],this._eps);this._vf.isActive!==t&&this.postMessage("isActive",t)}},tick:function(e){if(this.initialize(),this._currTime=e,!this._bufferEndTime)return this._bufferEndTime=e,this._value=x3dom.fields.SFVec3f.copy(this._vf.initialValue),this.postMessage("value",this._value),!0;var t=this.updateBuffer(e),i=x3dom.fields.SFVec3f.copy(this._previousValue),o=this._buffer[this._buffer.length-1].subtract(this._previousValue),s=o.multiply(this.stepResponse((this._buffer.length-1+t)*this._stepTime));i=i.add(s);for(var r=this._buffer.length-2;r>=0;r--)s=(o=this._buffer[r].subtract(this._buffer[r+1])).multiply(this.stepResponse((r+t)*this._stepTime)),i=i.add(s);return i.equals(this._value,this._eps)?this.postMessage("isActive",!1):(this._value.setValues(i),this.postMessage("value",this._value)),this._vf.isActive},updateBuffer:function(e){var t,i,o,s=(e-this._bufferEndTime)/this._stepTime;if(s>=1){if(s-=i=Math.floor(s),i<this._buffer.length){for(this._previousValue=x3dom.fields.SFVec3f.copy(this._buffer[this._buffer.length-i]),t=this._buffer.length-1;t>=i;t--)this._buffer[t]=x3dom.fields.SFVec3f.copy(this._buffer[t-i]);for(t=0;t<i;t++)o=t/i,this._buffer[t]=this._buffer[i].multiply(o).add(this._vf.destination.multiply(1-o))}else for(this._previousValue=x3dom.fields.SFVec3f.copy(i==this._buffer.length?this._buffer[0]:this._vf.destination),t=0;t<this._buffer.length;t++)this._buffer[t]=x3dom.fields.SFVec3f.copy(this._vf.destination);this._bufferEndTime+=i*this._stepTime}return s}})),x3dom.registerNodeType("PositionChaser2D","Followers",defineClass(x3dom.nodeTypes.X3DChaserNode,(function(e){x3dom.nodeTypes.PositionChaser2D.superClass.call(this,e),this.addField_SFVec2f(e,"initialDestination",0,0),this.addField_SFVec2f(e,"initialValue",0,0),this.addField_SFVec2f(e,"value",0,0),this.addField_SFVec2f(e,"destination",0,0),this._buffer=new x3dom.fields.MFVec2f,this._previousValue=new x3dom.fields.SFVec2f(0,0),this._value=new x3dom.fields.SFVec2f(0,0),this.initialize()}),{fieldChanged:function(e){if(e.indexOf("destination")>=0)this.initialize(),this.updateBuffer(this._currTime),this._vf.isActive||this.postMessage("isActive",!0);else if(e.indexOf("value")>=0){this.initialize(),this._previousValue.setValues(this._vf.value);for(var t=1;t<this._buffer.length;t++)this._buffer[t].setValues(this._vf.value);this.postMessage("value",this._vf.value),this._vf.isActive||this.postMessage("isActive",!0)}},initialize:function(){if(!this._initDone){this._initDone=!0,this._vf.destination=x3dom.fields.SFVec2f.copy(this._vf.initialDestination),this._buffer.length=this._numSupports,this._buffer[0]=x3dom.fields.SFVec2f.copy(this._vf.initialDestination);for(var e=1;e<this._buffer.length;e++)this._buffer[e]=x3dom.fields.SFVec2f.copy(this._vf.initialValue);this._previousValue=x3dom.fields.SFVec2f.copy(this._vf.initialValue),this._stepTime=this._vf.duration/this._numSupports;var t=!this._buffer[0].equals(this._buffer[1],this._eps);this._vf.isActive!==t&&this.postMessage("isActive",t)}},tick:function(e){if(this.initialize(),this._currTime=e,!this._bufferEndTime)return this._bufferEndTime=e,this._value=x3dom.fields.SFVec2f.copy(this._vf.initialValue),this.postMessage("value",this._value),!0;var t=this.updateBuffer(e),i=x3dom.fields.SFVec2f.copy(this._previousValue),o=this._buffer[this._buffer.length-1].subtract(this._previousValue),s=o.multiply(this.stepResponse((this._buffer.length-1+t)*this._stepTime));i=i.add(s);for(var r=this._buffer.length-2;r>=0;r--)s=(o=this._buffer[r].subtract(this._buffer[r+1])).multiply(this.stepResponse((r+t)*this._stepTime)),i=i.add(s);return i.equals(this._value,this._eps)?this.postMessage("isActive",!1):(this._value.setValues(i),this.postMessage("value",this._value)),this._vf.isActive},updateBuffer:function(e){var t,i,o,s=(e-this._bufferEndTime)/this._stepTime;if(s>=1){if(s-=i=Math.floor(s),i<this._buffer.length){for(this._previousValue=x3dom.fields.SFVec2f.copy(this._buffer[this._buffer.length-i]),t=this._buffer.length-1;t>=i;t--)this._buffer[t]=x3dom.fields.SFVec2f.copy(this._buffer[t-i]);for(t=0;t<i;t++)o=t/i,this._buffer[t]=this._buffer[i].multiply(o).add(this._vf.destination.multiply(1-o))}else for(this._previousValue=x3dom.fields.SFVec2f.copy(i==this._buffer.length?this._buffer[0]:this._vf.destination),t=0;t<this._buffer.length;t++)this._buffer[t]=x3dom.fields.SFVec2f.copy(this._vf.destination);this._bufferEndTime+=i*this._stepTime}return s}})),x3dom.registerNodeType("PositionDamper","Followers",defineClass(x3dom.nodeTypes.X3DDamperNode,(function(e){x3dom.nodeTypes.PositionDamper.superClass.call(this,e),this.addField_SFVec3f(e,"initialDestination",0,0,0),this.addField_SFVec3f(e,"initialValue",0,0,0),this.addField_SFVec3f(e,"value",0,0,0),this.addField_SFVec3f(e,"destination",0,0,0),this._value0=new x3dom.fields.SFVec3f(0,0,0),this._value1=new x3dom.fields.SFVec3f(0,0,0),this._value2=new x3dom.fields.SFVec3f(0,0,0),this._value3=new x3dom.fields.SFVec3f(0,0,0),this._value4=new x3dom.fields.SFVec3f(0,0,0),this._value5=new x3dom.fields.SFVec3f(0,0,0),this.initialize()}),{fieldChanged:function(e){"tolerance"===e?this._eps=this._vf.tolerance<0?.001:this._vf.tolerance:e.indexOf("destination")>=0?this._value0.equals(this._vf.destination,this._eps)||(this._value0=this._vf.destination,this._vf.isActive||this.postMessage("isActive",!0)):e.indexOf("value")>=0&&(this._value1.setValues(this._vf.value),this._value2.setValues(this._vf.value),this._value3.setValues(this._vf.value),this._value4.setValues(this._vf.value),this._value5.setValues(this._vf.value),this._lastTick=0,this.postMessage("value",this._value5),this._vf.isActive||(this._lastTick=0,this.postMessage("isActive",!0)))},initialize:function(){this._value0.setValues(this._vf.initialDestination),this._value1.setValues(this._vf.initialValue),this._value2.setValues(this._vf.initialValue),this._value3.setValues(this._vf.initialValue),this._value4.setValues(this._vf.initialValue),this._value5.setValues(this._vf.initialValue),this._lastTick=0;var e=!this._value0.equals(this._value1,this._eps);this._vf.isActive!==e&&this.postMessage("isActive",e)},tick:function(e){if(!this._lastTick)return this._lastTick=e,!1;var t=e-this._lastTick,i=Math.exp(-t/this._vf.tau);this._value1=this._vf.order>0&&this._vf.tau?this._value0.add(this._value1.subtract(this._value0).multiply(i)):new x3dom.fields.SFVec3f(this._value0.x,this._value0.y,this._value0.z),this._value2=this._vf.order>1&&this._vf.tau?this._value1.add(this._value2.subtract(this._value1).multiply(i)):new x3dom.fields.SFVec3f(this._value1.x,this._value1.y,this._value1.z),this._value3=this._vf.order>2&&this._vf.tau?this._value2.add(this._value3.subtract(this._value2).multiply(i)):new x3dom.fields.SFVec3f(this._value2.x,this._value2.y,this._value2.z),this._value4=this._vf.order>3&&this._vf.tau?this._value3.add(this._value4.subtract(this._value3).multiply(i)):new x3dom.fields.SFVec3f(this._value3.x,this._value3.y,this._value3.z),this._value5=this._vf.order>4&&this._vf.tau?this._value4.add(this._value5.subtract(this._value4).multiply(i)):new x3dom.fields.SFVec3f(this._value4.x,this._value4.y,this._value4.z);var o=this._value1.subtract(this._value0).length();if(this._vf.order>1){var s=this._value2.subtract(this._value1).length();s>o&&(o=s)}if(this._vf.order>2){var r=this._value3.subtract(this._value2).length();r>o&&(o=r)}if(this._vf.order>3){var n=this._value4.subtract(this._value3).length();n>o&&(o=n)}if(this._vf.order>4){var a=this._value5.subtract(this._value4).length();a>o&&(o=a)}return o<=this._eps?(this._value1.setValues(this._value0),this._value2.setValues(this._value0),this._value3.setValues(this._value0),this._value4.setValues(this._value0),this._value5.setValues(this._value0),this.postMessage("value",this._value0),this.postMessage("isActive",!1),this._lastTick=0,!1):(this.postMessage("value",this._value5),this._lastTick=e,!0)}})),x3dom.registerNodeType("PositionDamper2D","Followers",defineClass(x3dom.nodeTypes.X3DDamperNode,(function(e){x3dom.nodeTypes.PositionDamper2D.superClass.call(this,e),this.addField_SFVec2f(e,"initialDestination",0,0),this.addField_SFVec2f(e,"initialValue",0,0),this.addField_SFVec2f(e,"value",0,0),this.addField_SFVec2f(e,"destination",0,0),this._value0=new x3dom.fields.SFVec2f(0,0),this._value1=new x3dom.fields.SFVec2f(0,0),this._value2=new x3dom.fields.SFVec2f(0,0),this._value3=new x3dom.fields.SFVec2f(0,0),this._value4=new x3dom.fields.SFVec2f(0,0),this._value5=new x3dom.fields.SFVec2f(0,0),this.initialize()}),{fieldChanged:function(e){"tolerance"===e?this._eps=this._vf.tolerance<0?.001:this._vf.tolerance:e.indexOf("destination")>=0?this._value0.equals(this._vf.destination,this._eps)||(this._value0=this._vf.destination,this._vf.isActive||this.postMessage("isActive",!0)):e.indexOf("value")>=0&&(this._value1.setValues(this._vf.value),this._value2.setValues(this._vf.value),this._value3.setValues(this._vf.value),this._value4.setValues(this._vf.value),this._value5.setValues(this._vf.value),this._lastTick=0,this.postMessage("value",this._value5),this._vf.isActive||(this._lastTick=0,this.postMessage("isActive",!0)))},initialize:function(){this._value0.setValues(this._vf.initialDestination),this._value1.setValues(this._vf.initialValue),this._value2.setValues(this._vf.initialValue),this._value3.setValues(this._vf.initialValue),this._value4.setValues(this._vf.initialValue),this._value5.setValues(this._vf.initialValue),this._lastTick=0;var e=!this._value0.equals(this._value1,this._eps);this._vf.isActive!==e&&this.postMessage("isActive",e)},tick:function(e){if(!this._lastTick)return this._lastTick=e,!1;var t=e-this._lastTick,i=Math.exp(-t/this._vf.tau);this._value1=this._vf.order>0&&this._vf.tau?this._value0.add(this._value1.subtract(this._value0).multiply(i)):new x3dom.fields.SFVec2f(this._value0.x,this._value0.y,this._value0.z),this._value2=this._vf.order>1&&this._vf.tau?this._value1.add(this._value2.subtract(this._value1).multiply(i)):new x3dom.fields.SFVec2f(this._value1.x,this._value1.y,this._value1.z),this._value3=this._vf.order>2&&this._vf.tau?this._value2.add(this._value3.subtract(this._value2).multiply(i)):new x3dom.fields.SFVec2f(this._value2.x,this._value2.y,this._value2.z),this._value4=this._vf.order>3&&this._vf.tau?this._value3.add(this._value4.subtract(this._value3).multiply(i)):new x3dom.fields.SFVec2f(this._value3.x,this._value3.y,this._value3.z),this._value5=this._vf.order>4&&this._vf.tau?this._value4.add(this._value5.subtract(this._value4).multiply(i)):new x3dom.fields.SFVec2f(this._value4.x,this._value4.y,this._value4.z);var o=this._value1.subtract(this._value0).length();if(this._vf.order>1){var s=this._value2.subtract(this._value1).length();s>o&&(o=s)}if(this._vf.order>2){var r=this._value3.subtract(this._value2).length();r>o&&(o=r)}if(this._vf.order>3){var n=this._value4.subtract(this._value3).length();n>o&&(o=n)}if(this._vf.order>4){var a=this._value5.subtract(this._value4).length();a>o&&(o=a)}return o<=this._eps?(this._value1.setValues(this._value0),this._value2.setValues(this._value0),this._value3.setValues(this._value0),this._value4.setValues(this._value0),this._value5.setValues(this._value0),this.postMessage("value",this._value0),this.postMessage("isActive",!1),this._lastTick=0,!1):(this.postMessage("value",this._value5),this._lastTick=e,!0)}})),x3dom.registerNodeType("ScalarChaser","Followers",defineClass(x3dom.nodeTypes.X3DChaserNode,(function(e){x3dom.nodeTypes.ScalarChaser.superClass.call(this,e),this.addField_SFFloat(e,"initialDestination",0),this.addField_SFFloat(e,"initialValue",0),this.addField_SFFloat(e,"value",0),this.addField_SFFloat(e,"destination",0),this._buffer=[],this._previousValue=0,this._value=0,this.initialize()}),{fieldChanged:function(e){if(e.indexOf("destination")>=0)this.initialize(),this.updateBuffer(this._currTime),this._vf.isActive||this.postMessage("isActive",!0);else if(e.indexOf("value")>=0){this.initialize(),this._previousValue=this._vf.value;for(var t=1;t<this._buffer.length;t++)this._buffer[t]=this._vf.value;this.postMessage("value",this._vf.value),this._vf.isActive||this.postMessage("isActive",!0)}},initialize:function(){if(!this._initDone){this._initDone=!0,this._vf.destination=this._vf.initialDestination,this._buffer.length=this._numSupports,this._buffer[0]=this._vf.initialDestination;for(var e=1;e<this._buffer.length;e++)this._buffer[e]=this._vf.initialValue;this._previousValue=this._vf.initialValue,this._stepTime=this._vf.duration/this._numSupports;var t=Math.abs(this._buffer[0]-this._buffer[1])>this._eps;this._vf.isActive!==t&&this.postMessage("isActive",t)}},tick:function(e){if(this.initialize(),this._currTime=e,!this._bufferEndTime)return this._bufferEndTime=e,this._value=this._vf.initialValue,this.postMessage("value",this._value),!0;var t=this.updateBuffer(e),i=this._previousValue,o=this._buffer[this._buffer.length-1]-this._previousValue,s=o*this.stepResponse((this._buffer.length-1+t)*this._stepTime);i+=s;for(var r=this._buffer.length-2;r>=0;r--)i+=s=(o=this._buffer[r]-this._buffer[r+1])*this.stepResponse((r+t)*this._stepTime);return Math.abs(i-this._value)>this._eps?(this._value=i,this.postMessage("value",this._value)):this.postMessage("isActive",!1),this._vf.isActive},updateBuffer:function(e){var t,i,o,s=(e-this._bufferEndTime)/this._stepTime;if(s>=1){if(s-=i=Math.floor(s),i<this._buffer.length){for(this._previousValue=this._buffer[this._buffer.length-i],t=this._buffer.length-1;t>=i;t--)this._buffer[t]=this._buffer[t-i];for(t=0;t<i;t++)o=t/i,this._buffer[t]=this._buffer[i]*o+this._vf.destination*(1-o)}else for(this._previousValue=i==this._buffer.length?this._buffer[0]:this._vf.destination,t=0;t<this._buffer.length;t++)this._buffer[t]=this._vf.destination;this._bufferEndTime+=i*this._stepTime}return s}})),x3dom.registerNodeType("ScalarDamper","Followers",defineClass(x3dom.nodeTypes.X3DDamperNode,(function(e){x3dom.nodeTypes.ScalarDamper.superClass.call(this,e),this.addField_SFFloat(e,"initialDestination",0),this.addField_SFFloat(e,"initialValue",0),this.addField_SFFloat(e,"value",0),this.addField_SFFloat(e,"destination",0),this._value0=0,this._value1=0,this._value2=0,this._value3=0,this._value4=0,this._value5=0,this.initialize()}),{fieldChanged:function(e){"tolerance"===e?this._eps=this._vf.tolerance<0?.001:this._vf.tolerance:e.indexOf("destination")>=0?Math.abs(this._value0-this._vf.destination)>this._eps&&(this._value0=this._vf.destination,this._vf.isActive||this.postMessage("isActive",!0)):e.indexOf("value")>=0&&(this._value1=this._vf.value,this._value2=this._vf.value,this._value3=this._vf.value,this._value4=this._vf.value,this._value5=this._vf.value,this._lastTick=0,this.postMessage("value",this._value5),this._vf.isActive||(this._lastTick=0,this.postMessage("isActive",!0)))},initialize:function(){this._value0=this._vf.initialDestination,this._value1=this._vf.initialValue,this._value2=this._vf.initialValue,this._value3=this._vf.initialValue,this._value4=this._vf.initialValue,this._value5=this._vf.initialValue,this._lastTick=0;var e=Math.abs(this._value0-this._value1)>this._eps;this._vf.isActive!==e&&this.postMessage("isActive",e)},tick:function(e){if(!this._lastTick)return this._lastTick=e,!1;var t=e-this._lastTick,i=Math.exp(-t/this._vf.tau);this._value1=this._vf.order>0&&this._vf.tau?this._value0+i*(this._value1-this._value0):this._value0,this._value2=this._vf.order>1&&this._vf.tau?this._value1+i*(this._value2-this._value1):this._value1,this._value3=this._vf.order>2&&this._vf.tau?this._value2+i*(this._value3-this._value2):this._value2,this._value4=this._vf.order>3&&this._vf.tau?this._value3+i*(this._value4-this._value3):this._value3,this._value5=this._vf.order>4&&this._vf.tau?this._value4+i*(this._value5-this._value4):this._value4;var o=Math.abs(this._value1-this._value0);if(this._vf.order>1){var s=Math.abs(this._value2-this._value1);s>o&&(o=s)}if(this._vf.order>2){var r=Math.abs(this._value3-this._value2);r>o&&(o=r)}if(this._vf.order>3){var n=Math.abs(this._value4-this._value3);n>o&&(o=n)}if(this._vf.order>4){var a=Math.abs(this._value5-this._value4);a>o&&(o=a)}return o<=this._eps?(this._value1=this._value0,this._value2=this._value0,this._value3=this._value0,this._value4=this._value0,this._value5=this._value0,this.postMessage("value",this._value0),this.postMessage("isActive",!1),this._lastTick=0,!1):(this.postMessage("value",this._value5),this._lastTick=e,!0)}})),x3dom.registerNodeType("CoordinateDamper","Followers",defineClass(x3dom.nodeTypes.X3DDamperNode,(function(e){x3dom.nodeTypes.CoordinateDamper.superClass.call(this,e),this.addField_MFVec3f(e,"initialDestination",[]),this.addField_MFVec3f(e,"initialValue",[]),this.addField_MFVec3f(e,"value",[]),this.addField_MFVec3f(e,"destination",[]),x3dom.debug.logWarning("CoordinateDamper NYI")}))),x3dom.registerNodeType("TexCoordDamper2D","Followers",defineClass(x3dom.nodeTypes.X3DDamperNode,(function(e){x3dom.nodeTypes.TexCoordDamper2D.superClass.call(this,e),this.addField_MFVec2f(e,"initialDestination",[]),this.addField_MFVec2f(e,"initialValue",[]),this.addField_MFVec2f(e,"value",[]),this.addField_MFVec2f(e,"destination",[]),x3dom.debug.logWarning("TexCoordDamper2D NYI")}))),x3dom.registerNodeType("X3DInterpolatorNode","Interpolation",defineClass(x3dom.nodeTypes.X3DChildNode,(function(e){x3dom.nodeTypes.X3DInterpolatorNode.superClass.call(this,e),this.addField_MFFloat(e,"key",[]),this.addField_SFFloat(e,"set_fraction",0),this.addField_SFString(e,"buffer",""),this.addField_SFString(e,"interpolation","LINEAR"),this.addField_SFFloat(e,"duration",0),this.addField_MFNode("views",x3dom.nodeTypes.BufferView),this.addField_MFNode("accessors",x3dom.nodeTypes.BufferAccessor),this._lastValue=void 0,this.normalizeFromType={5120:function(e){return Math.max(e/127,-1)},5121:function(e){return e/255},5122:function(e){return Math.max(e/32767,-1)},5123:function(e){return e/65535},5125:function(e){return e/4294967295},5126:function(e){return e}}}),{nodeChanged:function(){this._vf.buffer&&x3dom.BinaryContainerLoader.setupBufferInterpolator(this)},linearInterp:function(e,t){var i=this._vf.key,o=this._vf.keyValue;if(0!=i.length){if(e<=i[0])return t(o[0],o[0],0);if(e>=i[i.length-1])return t(o[i.length-1],o[i.length-1],1);for(var s=0,r=i.length-1;s<r;++s)if(i[s]<e&&e<=i[s+1])return t(o[s],o[s+1],(e-i[s])/(i[s+1]-i[s]));return o[0]}},cubicSplineInterp:function(e,t){if(0!=this._vf.key.length){var i,o,s,r,n,a,d;if(e<=this._vf.key[0])return this._vf.keyValue[1];if(e>=this._vf.key[this._vf.key.length-1])return this._vf.keyValue[this._vf.keyValue.length-2];for(i=0,s=this._vf.key.length-1;i<s;++i)if(this._vf.key[i]<e&&e<=this._vf.key[i+1])return o=3*i,r=this._vf.key[i+1]-this._vf.key[i],a=(e-this._vf.key[i])/r,d=r*this._vf.duration,n=this.cubicSplineBasis(a,d),t(this._vf.keyValue[o+2],this._vf.keyValue[o+1],this._vf.keyValue[o+3],this._vf.keyValue[o+4],n.h00,n.h10,n.h01,n.h11);return this._vf.keyValue[0]}},cubicSplineBasis:function(e,t){var i=e*e,o=i*e,s=-2*o+3*i,r=o-i;return{h00:1-s,h10:t*(r-i+e),h01:s,h11:t*r}},keyValueFromArray:function(e){return e}})),x3dom.XHRCache={},x3dom.registerNodeType("OrientationInterpolator","Interpolation",defineClass(x3dom.nodeTypes.X3DInterpolatorNode,(function(e){x3dom.nodeTypes.OrientationInterpolator.superClass.call(this,e),this.addField_MFRotation(e,"keyValue",[])}),{fieldChanged:function(e){var t;"set_fraction"===e&&(null!=(t="CUBICSPLINE"===this._vf.interpolation?this.cubicSplineInterp(this._vf.set_fraction,(function(e,t,i,o,s,r,n,a){function d(d){return s*t[d]+r*e[d]+n*o[d]+a*i[d]}var l=new x3dom.fields.Quaternion(0,0,0,0);l.x=d("x"),l.y=d("y"),l.z=d("z"),l.w=d("w");var h=Math.sqrt(1/l.dot(l));return l.x*=h,l.y*=h,l.z*=h,l.w*=h,l})):this.linearInterp(this._vf.set_fraction,(function(e,t,i){return e.slerp(t,i)})))&&t!=this._lastValue&&(this._lastValue=t,this.postMessage("value_changed",t)))},keyValueFromAccessor:function(e,t){var i=new x3dom.fields.MFRotation,o=this.normalizeFromType[t];return e.forEach((function(t,s){s%4==3&&i.push(new x3dom.fields.Quaternion(o(e[s-3]),o(e[s-2]),o(e[s-1]),o(t)))})),i}})),x3dom.registerNodeType("PositionInterpolator","Interpolation",defineClass(x3dom.nodeTypes.X3DInterpolatorNode,(function(e){x3dom.nodeTypes.PositionInterpolator.superClass.call(this,e),this.addField_MFVec3f(e,"keyValue",[])}),{fieldChanged:function(e){var t;"set_fraction"===e&&(null!=(t="CUBICSPLINE"===this._vf.interpolation?this.cubicSplineInterp(this._vf.set_fraction,(function(e,t,i,o,s,r,n,a){function d(d){return s*t[d]+r*e[d]+n*o[d]+a*i[d]}var l=new x3dom.fields.SFVec3f;return l.x=d("x"),l.y=d("y"),l.z=d("z"),l})):this.linearInterp(this._vf.set_fraction,(function(e,t,i){var o=e.multiply(1-i);return o.x+=i*t.x,o.y+=i*t.y,o.z+=i*t.z,o})))&&t!=this._lastValue&&(this._lastValue=t,this.postMessage("value_changed",t)))},keyValueFromAccessor:function(e){var t=new x3dom.fields.MFVec3f;return e.forEach((function(i,o){o%3==2&&t.push(new x3dom.fields.SFVec3f(e[o-2],e[o-1],i))})),t}})),x3dom.registerNodeType("PositionInterpolator2D","Interpolation",defineClass(x3dom.nodeTypes.X3DInterpolatorNode,(function(e){x3dom.nodeTypes.PositionInterpolator2D.superClass.call(this,e),this.addField_MFVec2f(e,"keyValue",[])}),{fieldChanged:function(e){if("set_fraction"===e){var t=this.linearInterp(this._vf.set_fraction,(function(e,t,i){return e.multiply(1-i).add(t.multiply(i))}));this.postMessage("value_changed",t)}}})),x3dom.registerNodeType("NormalInterpolator","Interpolation",defineClass(x3dom.nodeTypes.X3DInterpolatorNode,(function(e){x3dom.nodeTypes.NormalInterpolator.superClass.call(this,e),this.addField_MFVec3f(e,"keyValue",[])}),{fieldChanged:function(e){if("set_fraction"===e){var t=this.linearInterp(this._vf.set_fraction,(function(e,t,i){return e.multiply(1-i).add(t.multiply(i)).normalize()}));null!=t&&t!=this._lastValue&&(this._lastValue=t,this.postMessage("value_changed",t))}}})),x3dom.registerNodeType("ColorInterpolator","Interpolation",defineClass(x3dom.nodeTypes.X3DInterpolatorNode,(function(e){x3dom.nodeTypes.ColorInterpolator.superClass.call(this,e),this.addField_MFColor(e,"keyValue",[]),this.addField_SFBool(e,"RGB",!1),this._lastValue=new x3dom.fields.SFColor,this.fieldChanged("keyValue")}),{fieldChanged:function(e){var t,i;"set_fraction"===e&&(this._vf.RGB?t=this.linearInterp(this._vf.set_fraction,(function(e,t,o){return i=e.multiply(1-o).add(t.multiply(o))})):(this._vf.keyValue=this._keyValueHSV,t=this.linearInterp(this._vf.set_fraction,(function(e,t,o){var s=e.copy(),r=t.copy();return r.r=r.r>s.r?r.r:r.r+360,r.r-s.r<180?i=s.multiply(1-o).add(r.multiply(o)):(s.r=s.r+360,i=s.multiply(1-o).add(r.multiply(o))),i.setHSV(i.r%360,i.g,i.b)})),this._vf.keyValue=this._keyValue),null==t||t.equals(this._lastValue,x3dom.fields.Eps)||(this._lastValue=t,this.postMessage("value_changed",t)));"keyValue"===e&&(this._keyValueHSV=this._vf.keyValue.map((function(e){var t=e.getHSV();return new x3dom.fields.SFColor(t[0],t[1],t[2])})),this._keyValue=this._vf.keyValue.copy())}})),x3dom.registerNodeType("ScalarInterpolator","Interpolation",defineClass(x3dom.nodeTypes.X3DInterpolatorNode,(function(e){x3dom.nodeTypes.ScalarInterpolator.superClass.call(this,e),this.addField_MFFloat(e,"keyValue",[])}),{fieldChanged:function(e){if("set_fraction"===e){var t;if("CUBICSPLINE"===this._vf.interpolation){t=this.cubicSplineInterp(this._vf.set_fraction,(function(e,t,i,o,s,r,n,a){return s*t+r*e+n*o+a*i}))}else t=this.linearInterp(this._vf.set_fraction,(function(e,t,i){return(1-i)*e+i*t}));null!=t&&t!=this._lastValue&&(this._lastValue=t,this.postMessage("value_changed",t))}},keyValueFromAccessor:function(e,t){var i=this.normalizeFromType[t];return e.map((function(e){return i(e)}))}})),x3dom.registerNodeType("CoordinateInterpolator","Interpolation",defineClass(x3dom.nodeTypes.X3DInterpolatorNode,(function(e){if(x3dom.nodeTypes.CoordinateInterpolator.superClass.call(this,e),this.addField_MFVec3f(e,"keyValue",[]),e&&e.xmlNode.hasAttribute("keyValue")){this._vf.keyValue=[];for(var t=x3dom.fields.MFVec3f.parse(e.xmlNode.getAttribute("keyValue")),i=this._vf.key.length>0?this._vf.key.length:1,o=t.length/i,s=0;s<i;s++){for(var r=new x3dom.fields.MFVec3f,n=0;n<o;n++)r.push(t[s*o+n]);this._vf.keyValue.push(r)}}}),{fieldChanged:function(e){if("set_fraction"===e){var t=this.linearInterp(this._vf.set_fraction,(function(e,t,i){for(var o=new x3dom.fields.MFVec3f,s=0;s<e.length;s++)o.push(e[s].multiply(1-i).add(t[s].multiply(i)));return o}));null!=t&&t!=this._lastValue&&(this._lastValue=t,this.postMessage("value_changed",t))}}})),x3dom.registerNodeType("SplinePositionInterpolator","Interpolation",defineClass(x3dom.nodeTypes.X3DInterpolatorNode,(function(e){x3dom.nodeTypes.SplinePositionInterpolator.superClass.call(this,e),this.addField_MFVec3f(e,"keyValue",[]),this.addField_MFVec3f(e,"keyVelocity",[]),this.addField_SFBool(e,"closed",!1),this.addField_SFBool(e,"normalizeVelocity",!1),this.dtot=0,this.T0=[],this.T1=[],this.checkSanity=function(){this._vf.key.length==this._vf.keyValue.length&&(this._vf.key.length==this._vf.keyVelocity.length||2==this._vf.keyVelocity.length&&this._vf.key.length>=2||0==this._vf.keyVelocity.length)||x3dom.debug.logWarning("SplinePositionInterpolator Node: 'key' , 'keyValue' and/or 'keyVelocity' fields have inappropriate sizes")},this.calcDtot=function(){this.dtot=0;for(var e=0;e<this._vf.key.length-1;e++)this.dtot+=Math.abs(this._vf.key[e]-this._vf.key[e+1])},this.calcAdjustedKeyVelocity=function(){var e,t,i,o,s=this._vf.key.length;if(this._vf.keyVelocity.length==s)for(e=0;e<s;e++)t=this._vf.keyVelocity[e],this._vf.normalizeVelocity&&(t=t.multiply(this.dtot/t.length())),i=0==e||e==s-1?1:2*(this._vf.key[e]-this._vf.key[e-1])/(this._vf.key[e+1]-this._vf.key[e-1]),o=0==e||e==s-1?1:2*(this._vf.key[e+1]-this._vf.key[e])/(this._vf.key[e+1]-this._vf.key[e-1]),this.T0[e]=t.multiply(i),this.T1[e]=t.multiply(o);else if(2==this._vf.keyVelocity.length&&s>2)for(e=0;e<s;e++)t=0==e?this._vf.keyVelocity[0]:e==s-1?this._vf.keyVelocity[1]:this._vf.keyValue[e+1].subtract(this._vf.keyValue[e-1]).multiply(.5),this._vf.normalizeVelocity&&(t=t.multiply(this.dtot/t.length())),i=0==e||e==s-1?1:2*(this._vf.key[e]-this._vf.key[e-1])/(this._vf.key[e+1]-this._vf.key[e-1]),o=0==e||e==s-1?1:2*(this._vf.key[e+1]-this._vf.key[e])/(this._vf.key[e+1]-this._vf.key[e-1]),this.T0[e]=t.multiply(i),this.T1[e]=t.multiply(o);else{var r=this._vf.closed&&this._vf.keyValue[0].equals(this._vf.keyValue[s-1],1e-5);for(e=0;e<s;e++)0!=e&&e!=s-1||r?(0!=e&&e!=s-1||!r?(t=this._vf.keyValue[e+1].subtract(this._vf.keyValue[e-1]).multiply(.5),i=2*(this._vf.key[e]-this._vf.key[e-1])/(this._vf.key[e+1]-this._vf.key[e-1]),o=2*(this._vf.key[e+1]-this._vf.key[e])/(this._vf.key[e+1]-this._vf.key[e-1])):(t=this._vf.keyValue[1].subtract(this._vf.keyValue[s-2]).multiply(.5),0==e?(i=2*(this._vf.key[0]-this._vf.key[s-2])/(this._vf.key[1]-this._vf.key[s-2]),o=2*(this._vf.key[1]-this._vf.key[0])/(this._vf.key[1]-this._vf.key[s-2])):(i=2*(this._vf.key[s-1]-this._vf.key[s-2])/(this._vf.key[1]-this._vf.key[s-2]),o=2*(this._vf.key[1]-this._vf.key[s-1])/(this._vf.key[1]-this._vf.key[s-2])),i=2*(this._vf.key[s-1]-this._vf.key[s-2])/(this._vf.key[s-2]-this._vf.key[1]),o=2*(this._vf.key[1]-this._vf.key[0])/(this._vf.key[s-2]-this._vf.key[1])),this.T0[e]=t.multiply(i),this.T1[e]=t.multiply(o)):(this.T0[e]=new x3dom.fields.SFVec3f(0,0,0),this.T1[e]=new x3dom.fields.SFVec3f(0,0,0))}},this.checkSanity(),this.calcDtot(),this.calcAdjustedKeyVelocity()}),{fieldChanged:function(e){switch(e){case"key":case"keyValue":case"keyVelocity":this.checkSanity(),this.calcDtot(),this.calcAdjustedKeyVelocity();break;case"closed":case"normalizeVelocity":this.calcAdjustedKeyVelocity();break;case"set_fraction":var t;this._vf.key.length>0&&(this._vf.set_fraction<=this._vf.key[0]?t=x3dom.fields.SFVec3f.copy(this._vf.keyValue[0]):this._vf.set_fraction>=this._vf.key[this._vf.key.length-1]&&(t=x3dom.fields.SFVec3f.copy(this._vf.keyValue[this._vf.key.length-1])));for(var i=0;i<this._vf.key.length-1;i++)if(this._vf.key[i]<this._vf.set_fraction&&this._vf.set_fraction<=this._vf.key[i+1]){var o=(this._vf.set_fraction-this._vf.key[i])/(this._vf.key[i+1]-this._vf.key[i]),s=new x3dom.fields.SFVec4f(2*o*o*o-3*o*o+1,-2*o*o*o+3*o*o,o*o*o-2*o*o+o,o*o*o-o*o);t=new x3dom.fields.SFVec3f(s.x*this._vf.keyValue[i].x+s.y*this._vf.keyValue[i+1].x+s.z*this.T0[i].x+s.w*this.T1[i+1].x,s.x*this._vf.keyValue[i].y+s.y*this._vf.keyValue[i+1].y+s.z*this.T0[i].y+s.w*this.T1[i+1].y,s.x*this._vf.keyValue[i].z+s.y*this._vf.keyValue[i+1].z+s.z*this.T0[i].z+s.w*this.T1[i+1].z);break}null!=t&&t!=this._lastValue&&(this._lastValue=t,this.postMessage("value_changed",t))}}})),x3dom.registerNodeType("TimeSensor","Time",defineClass(x3dom.nodeTypes.X3DSensorNode,(function(e){x3dom.nodeTypes.TimeSensor.superClass.call(this,e),e?e.doc._nodeBag.timer.push(this):x3dom.debug.logWarning("TimeSensor: No runtime context found!"),this.addField_SFTime(e,"cycleInterval",1),this.addField_SFBool(e,"loop",!1),this.addField_SFTime(e,"startTime",0),this.addField_SFTime(e,"stopTime",0),this.addField_SFTime(e,"pauseTime",0),this.addField_SFTime(e,"resumeTime",0),this.addField_SFTime(e,"cycleTime",0),this.addField_SFTime(e,"elapsedTime",0),this.addField_SFFloat(e,"fraction_changed",0),this.addField_SFBool(e,"isActive",!1),this.addField_SFBool(e,"isPaused",!1),this.addField_SFTime(e,"time",0),this.addField_SFBool(e,"first",!0),this.addField_SFFloat(e,"firstCycle",0),this._prevCycle=-1,this._lastTime=0,this._cycleStopTime=0,this._activatedTime=0,this._vf.startTime>0&&this._updateCycleStopTime(),this._backupStartTime=this._vf.startTime,this._backupStopTime=this._vf.stopTime,this._backupCycleInterval=this._vf.cycleInterval}),{tick:function(e){if(!this._vf.enabled)return this._lastTime=e,!1;var t=this._vf.cycleInterval>0&&e>=this._vf.startTime&&(e<this._vf.stopTime||this._vf.stopTime<=this._vf.startTime)&&(1==this._vf.loop||0==this._vf.loop&&e<this._cycleStopTime);if(t&&!this._vf.isActive&&(this.postMessage("isActive",!0),this._activatedTime=e),t||this._vf.isActive){this.postMessage("elapsedTime",e-this._activatedTime);var i=e>=this._vf.pauseTime&&this._vf.pauseTime>this._vf.resumeTime;if(i&&!this._vf.isPaused?(this.postMessage("isPaused",!0),this.postMessage("pauseTime",e)):!i&&this._vf.isPaused&&(this.postMessage("isPaused",!1),this.postMessage("resumeTime",e)),!i){var o=this._getCycleAt(e),s=Math.floor(o),r=this._vf.startTime+s*this._vf.cycleInterval,n=0;this._vf.stopTime>this._vf.startTime&&this._lastTime<this._vf.stopTime&&e>=this._vf.stopTime?n=this._vf.stopTime:this._lastTime<r&&e>=r&&(n=r),n>0&&(e=n,o=this._getCycleAt(e),s=Math.floor(o));var a=o-s;a<x3dom.fields.Eps&&(a=this._lastTime<this._vf.startTime?0:1,this.postMessage("cycleTime",e)),this._fraction=a,this.postMessage("fraction_changed",a),this.postMessage("time",e)}}return!t&&this._vf.isActive&&this.postMessage("isActive",!1),this._lastTime=e,!0},fieldChanged:function(e){if("enabled"==e)!this._vf.enabled&&this._vf.isActive&&this.postMessage("isActive",!1);else if("startTime"==e){if(this._vf.isActive)return void(this._vf.startTime=this._backupStartTime);this._backupStartTime=this._vf.startTime,this._updateCycleStopTime()}else if("stopTime"==e){if(this._vf.isActive&&this._vf.stopTime<=this._vf.startTime)return void(this._vf.stopTime=this._backupStopTime);this._backupStopTime=this._vf.stopTime}else if("cycleInterval"==e){if(this._vf.isActive)return void(this._vf.cycleInterval=this._backupCycleInterval);this._backupCycleInterval=this._vf.cycleInterval}else if("loop"==e)this._updateCycleStopTime();else if("resumeTime"==e){if(this._vf.resumeTime<this._vf.pauseTime||this._vf.resumeTime<this._vf.startTime||!this._vf.enabled)return;this._vf.startTime=this._vf.resumeTime-this._fraction*this._vf.cycleInterval,this._backupStartTime=this._vf.startTime,this._updateCycleStopTime()}},parentRemoved:function(e){if(0===this._parentNodes.length)for(var t=this.findX3DDoc(),i=0,o=t._nodeBag.timer.length;i<o;i++)t._nodeBag.timer[i]===this&&t._nodeBag.timer.splice(i,1)},_getCycleAt:function(e){return Math.max(0,e-this._vf.startTime)/this._vf.cycleInterval},_updateCycleStopTime:function(){if(0==this._vf.loop){var e=(new Date).getTime()/1e3,t=Math.floor(this._getCycleAt(e))+1;this._cycleStopTime=this._vf.startTime+t*this._vf.cycleInterval}else this._cycleStopTime=0}})),x3dom.registerNodeType("X3DTimeDependentNode","Time",defineClass(x3dom.nodeTypes.X3DChildNode,(function(e){x3dom.nodeTypes.X3DTimeDependentNode.superClass.call(this,e),this.addField_SFBool(e,"loop",!1),this.addField_SFString(e,"description","")}))),x3dom.registerNodeType("Anchor","Networking",defineClass(x3dom.nodeTypes.X3DGroupingNode,(function(e){x3dom.nodeTypes.Anchor.superClass.call(this,e),this.addField_MFString(e,"url",[]),this.addField_MFString(e,"parameter",[]),this.addField_SFString(e,"description","")}),{doIntersect:function(e){for(var t=!1,i=0;i<this._childNodes.length;i++)this._childNodes[i]&&(t=this._childNodes[i].doIntersect(e)||t);return t},handleTouch:function(){var e=this._vf.url.length?this._vf.url[0]:"",t=e.search("#"),i="";t>=0&&(i=e.slice(t+1));var o=this._vf.parameter.length?this._vf.parameter[0]:"",s=o.search("target="),r="";(s>=0&&(r=o.slice(s+7)),x3dom.debug.logInfo("Anchor url="+e+", target="+r+", #viewpoint="+i),i.length>0&&e=="#"+i)?i in this._nameSpace.defMap?this._nameSpace.defMap[i]._xmlNode.setAttribute("bind","true"):x3dom.debug.logWarning("Anchor #viewpoint="+i+" not in DEF list."):0!=r.length||"_self"!=r?window.open(this._nameSpace.getURL(e),r):window.location=this._nameSpace.getURL(e)}})),x3dom.registerNodeType("Inline","Networking",defineClass(x3dom.nodeTypes.X3DGroupingNode,(function(e){x3dom.nodeTypes.Inline.superClass.call(this,e),this.addField_MFString(e,"url",[]),this.addField_SFBool(e,"load",!0),this.addField_SFString(e,"description",""),this.addField_MFString(e,"nameSpaceName",[]),this.addField_SFString(e,"contentType",""),this.addField_SFBool(e,"mapDEFToID",!1),this.initDone=!1,this.count=0,this.numRetries=x3dom.nodeTypes.Inline.MaximumRetries,this.ContentType={X3D:"model/x3d+xml",GLTF:"model/gltf+json",GLB:"model/gltf-binary",X3DJ:"model/x3d+json"}}),{fieldChanged:function(e){if("url"==e||"load"==e){for(var t=0;t<this._childNodes.length;t++)this.removeChild(this._childNodes[t]);if(0!=this._vf.nameSpaceName.length){var i=this._xmlNode;if(i&&i.hasChildNodes())for(;i.childNodes.length>=1;)i.removeChild(i.firstChild)}this.loadInline()}else"render"==e&&this.invalidateVolume()},nodeChanged:function(){this.initDone||(this.initDone=!0,this.loadInline())},parentRemoved:function(){var e=x3dom.getGlobal();this._childNodes.length>0&&this._childNodes[0]&&this._childNodes[0]._nameSpace&&this._nameSpace.removeSpace(this._childNodes[0]._nameSpace);for(var t=0,i=this._childNodes.length;t<i;t++)this._childNodes[t]&&(this._childNodes[t].parentRemoved(this),e._remover=this.removeChild(this._childNodes[t]));delete e._remover},fireEvents:function(e){if(this._xmlNode&&(this._xmlNode["on"+e]||this._xmlNode.hasAttribute("on"+e)||this._listeners[e])){var t={target:this._xmlNode,type:e,error:"error"==e?"XMLHttpRequest Error":"",cancelBubble:!1,stopPropagation:function(){this.cancelBubble=!0}};try{var i=this._xmlNode["on"+e];if("function"==typeof i)i.call(this._xmlNode,t);else{var o=this._xmlNode.getAttribute("on"+e);new Function("event",o).call(this._xmlNode,t)}var s=this._listeners[e];if(s)for(var r=0;r<s.length;r++)s[r].call(this._xmlNode,t)}catch(e){x3dom.debug.logException(e)}}},isValidContentType:function(e){for(var t in this.ContentType)if(e===this.ContentType[t])return!0;return!1},getContentType:function(){if(""!=this._vf.contentType&&this.isValidContentType(this._vf.contentType))return this._vf.contentType;if(this._vf.url.length&&this._vf.url[0].length){var e=this._vf.url[0].lastIndexOf(".");if(-1!=e)switch(this._vf.url[0].substr(e).toLowerCase()){case".x3d":return this.ContentType.X3D;case".gltf":return this.ContentType.GLTF;case".glb":return this.ContentType.GLB;case".json":return this.ContentType.X3DJ}}},loadX3D:function(e,t){if(this._vf.load){var i=this,o=null;if(e){if(o=t.setupTree(e),0!=i._vf.nameSpaceName.length)for(;e.children.length;){var s=e.children[0];setNamespace(i._vf.nameSpaceName,s,i._vf.mapDEFToID),i._xmlNode.appendChild(s)}}else x3dom.debug.logError("No Scene in resource");var r=x3dom.getGlobal();for(i._childNodes.length>0&&i._childNodes[0]&&i._childNodes[0]._nameSpace&&i._nameSpace.removeSpace(i._childNodes[0]._nameSpace);0!==i._childNodes.length;)r._remover=i.removeChild(i._childNodes[0]);if(delete r._remover,o){i.addChild(o),i.invalidateVolume();var n=i._nameSpace.doc._scene;n&&(n.invalidateVolume(),window.setTimeout((function(){i.invalidateVolume(),n.updateVolume(),i._nameSpace.doc.needRender=!0,i._nameSpace.doc.decrementDownloads(),i._nameSpace.doc.needRender=!0,x3dom.debug.logInfo("Inline: added "+i._vf.url[0]+" to scene.")}),1e3)),i.fireEvents("load")}o=null,t=null,e=null}else x3dom.debug.logInfo("Inline: load field prevented loading of "+this._vf.url[0])},loadInline:function(){var e=this,t=this.getContentType(),i=!1,o=new window.XMLHttpRequest;if(o.onreadystatechange=function(){if(4==o.readyState)if(o.status===x3dom.nodeTypes.Inline.AwaitTranscoding)if(e.count<e.numRetries){e.count++;var s=+o.getResponseHeader("Refresh")||5;x3dom.debug.logInfo("XHR status: "+o.status+" - Await Transcoding ("+e.count+"/"+e.numRetries+"): Next request in "+s+" seconds"),window.setTimeout((function(){e._nameSpace.doc.decrementDownloads(),e.loadInline()}),1e3*s)}else x3dom.debug.logError("XHR status: "+o.status+" - Await Transcoding ("+e.count+"/"+e.numRetries+"): No Retries left"),e._nameSpace.doc.decrementDownloads(),e.count=0;else if(200==o.status||0==o.status){var r;x3dom.debug.logInfo("Inline: downloading "+e._vf.url[0]+" done."),null==t&&(t=o.getResponseHeader("Content-Type")),e.count=0;var n=e.addNameSpace();if(t==e.ContentType.GLTF||t==e.ContentType.GLB)if(o.response)r=new x3dom.glTF2Loader(n).load(o.response,i),e.loadX3D(r,n);else x3dom.debug.logError("Invalide XHR Response"),e.fireEvents("error"),e._nameSpace.doc.decrementDownloads(),e.count=0;else if(t==e.ContentType.X3DJ)if(o.response){var a=x3dom.protoExpander.prototypeExpander(o.responseURL,o.response);null!=(d=(new x3dom.JSONParser).parseJavaScript(a))?(r=d.getElementsByTagName("Scene")[0]||d.getElementsByTagName("scene")[0],e.loadX3D(r,n)):(e.fireEvents("error"),e._nameSpace.doc.decrementDownloads(),e.count=0)}else x3dom.debug.logError("Invalide XHR Response"),e.fireEvents("error"),e._nameSpace.doc.decrementDownloads(),e.count=0;else if(t==e.ContentType.X3D){var d;null!=(d="Microsoft Internet Explorer"==navigator.appName?(new DOMParser).parseFromString(o.responseText,"text/xml"):o.responseXML)?(r=d.getElementsByTagName("Scene")[0]||d.getElementsByTagName("scene")[0],e.loadX3D(r,n)):(e.fireEvents("error"),e._nameSpace.doc.decrementDownloads(),e.count=0)}}else x3dom.debug.logError("XHR status: "+o.status+" - XMLHttpRequest requires web server running!"),e.fireEvents("error"),e._nameSpace.doc.decrementDownloads(),e.count=0},this._vf.url.length&&this._vf.url[0].length){var s=this._nameSpace.getURL(this._vf.url[0]);o.open("GET",s,!0),o.setRequestHeader("Accept","model/x3d+xml; q=1.0, model/gltf+json; q=0.5, model/gltf-binary; q=0.5"),o.overrideMimeType&&(t==this.ContentType.X3D&&o.overrideMimeType("text/xml"),t==this.ContentType.X3DJ?(o.overrideMimeType("application/json"),o.responseType="json"):t==this.ContentType.GLTF?(i=!1,o.responseType="json"):t==this.ContentType.GLB&&(i=!0,o.responseType="arraybuffer"));try{this._nameSpace.doc.incrementDownloads(),x3dom.RequestManager.addRequest(o)}catch(e){this.fireEvents("error"),x3dom.debug.logError(this._vf.url[0]+": "+e),this._nameSpace.doc.decrementDownloads()}}},addNameSpace:function(){var e=0!=this._vf.nameSpaceName.length?this._vf.nameSpaceName.toString().replace(" ",""):"",t=new x3dom.NodeNameSpace(e,this._nameSpace.doc),i=this._vf.url.length?this._vf.url[0]:"";return"/"===i[0]||i.indexOf(":")>=0?t.setBaseURL(i):t.setBaseURL(this._nameSpace.baseURL+i),this._nameSpace.addSpace(t),t}})),x3dom.nodeTypes.Inline.AwaitTranscoding=202,x3dom.nodeTypes.Inline.MaximumRetries=15,x3dom.registerNodeType("X3DBackgroundNode","EnvironmentalEffects",defineClass(x3dom.nodeTypes.X3DBindableNode,(function(e){x3dom.nodeTypes.X3DBackgroundNode.superClass.call(this,e);var t=e&&e.autoGen?1:0;this.addField_SFString(e,"crossOrigin",""),this.addField_MFColor(e,"groundColor",[]),this.addField_MFFloat(e,"groundAngle",[]),this.addField_MFColor(e,"skyColor",[new x3dom.fields.SFColor(0,0,0)]),this.addField_MFFloat(e,"skyAngle",[]),this.addField_SFFloat(e,"transparency",t),this._dirty=!0}),{getSkyColor:function(){return new x3dom.fields.SFColor(0,0,0)},getTransparency:function(){return 0},getTexUrl:function(){return[]}})),x3dom.registerNodeType("X3DFogNode","EnvironmentalEffects",defineClass(x3dom.nodeTypes.X3DBindableNode,(function(e){x3dom.nodeTypes.X3DFogNode.superClass.call(this,e),this.addField_SFColor(e,"color",1,1,1),this.addField_SFString(e,"fogType","LINEAR"),this.addField_SFFloat(e,"visibilityRange",0)}),{})),x3dom.registerNodeType("Fog","EnvironmentalEffects",defineClass(x3dom.nodeTypes.X3DFogNode,(function(e){x3dom.nodeTypes.Fog.superClass.call(this,e)}),{})),x3dom.registerNodeType("Background","EnvironmentalEffects",defineClass(x3dom.nodeTypes.X3DBackgroundNode,(function(e){x3dom.nodeTypes.Background.superClass.call(this,e),this.addField_MFString(e,"backUrl",[]),this.addField_MFString(e,"bottomUrl",[]),this.addField_MFString(e,"frontUrl",[]),this.addField_MFString(e,"leftUrl",[]),this.addField_MFString(e,"rightUrl",[]),this.addField_MFString(e,"topUrl",[]),this.addField_SFBool(e,"scaling",!1)}),{fieldChanged:function(e){e.indexOf("Url")>0||"transparency"==e||e.search("sky")>=0||e.search("ground")>=0?this._dirty=!0:e.indexOf("bind")>=0&&this.bind(this._vf.bind)},getSkyColor:function(){return this._vf.skyColor},getGroundColor:function(){return this._vf.groundColor},getTransparency:function(){return this._vf.transparency},getTexUrl:function(){return[this._nameSpace.getURL(this._vf.backUrl[0]),this._nameSpace.getURL(this._vf.frontUrl[0]),this._nameSpace.getURL(this._vf.bottomUrl[0]),this._nameSpace.getURL(this._vf.topUrl[0]),this._nameSpace.getURL(this._vf.leftUrl[0]),this._nameSpace.getURL(this._vf.rightUrl[0])]}})),x3dom.registerNodeType("X3DEnvironmentNode","EnvironmentalEffects",defineClass(x3dom.nodeTypes.X3DBindableNode,(function(e){x3dom.nodeTypes.X3DEnvironmentNode.superClass.call(this,e)}))),x3dom.registerNodeType("Environment","EnvironmentalEffects",defineClass(x3dom.nodeTypes.X3DEnvironmentNode,(function(e){x3dom.nodeTypes.Environment.superClass.call(this,e),this.addField_SFBool(e,"sortTrans",!0),this.addField_SFBool(e,"shadowExcludeTransparentObjects",!1),this.addField_SFString(e,"gammaCorrectionDefault","linear"),this.addField_SFString(e,"tonemapping","none"),this.addField_SFBool(e,"frustumCulling",!0),this.addField_SFBool(e,"smallFeatureCulling",!1),this.addField_SFFloat(e,"smallFeatureThreshold",1),this.addField_SFBool(e,"occlusionCulling",!1),this.addField_SFFloat(e,"occlusionVisibilityThreshold",0),this.addField_SFBool(e,"lowPriorityCulling",!1),this.addField_SFFloat(e,"lowPriorityThreshold",1),this.addField_SFBool(e,"tessellationDetailCulling",!1),this.addField_SFFloat(e,"tessellationErrorThreshold",0),this.addField_SFBool(e,"enableARC",!1),this.addField_SFFloat(e,"minFrameRate",1),this.addField_SFFloat(e,"maxFrameRate",62.5),this.addField_SFFloat(e,"userDataFactor",-1),this.addField_SFFloat(e,"smallFeatureFactor",-1),this.addField_SFFloat(e,"occlusionVisibilityFactor",-1),this.addField_SFFloat(e,"lowPriorityFactor",-1),this.addField_SFFloat(e,"tessellationErrorFactor",-1),this.addField_SFBool(e,"SSAO",!1),this.addField_SFFloat(e,"SSAOradius",.7),this.addField_SFFloat(e,"SSAOamount",.3),this.addField_SFInt32(e,"SSAOrandomTextureSize",4),this.addField_SFInt32(e,"SSAOblurDepthTreshold",1),this._validGammaCorrectionTypes=["none","fastlinear","linear"],this.checkSanity()}),{checkSanity:function(){var e=function(e,t,i,o){return e&&t==o?i:e||t==o?t:o};this._smallFeatureThreshold=e(this._vf.smallFeatureCulling,this._vf.smallFeatureThreshold,10,0),this._lowPriorityThreshold=e(this._vf.lowPriorityCulling,this._vf.lowPriorityThreshold,.5,1),this._occlusionVisibilityThreshold=e(this._vf.occlusionCulling,this._vf.occlusionVisibilityThreshold,1,0),this._tessellationErrorThreshold=e(this._vf.tessellationDetailCulling,this._vf.tessellationErrorThreshold,1,0);this._vf.gammaCorrectionDefault=function(e,t){return e=e.toLowerCase(),t._validGammaCorrectionTypes.indexOf(e)>-1?e:(x3dom.debug.logWarning(e+" gammaCorrectionDefault may only be linear (default), fastLinear, or none"),t._validGammaCorrectionTypes[0])}(this._vf.gammaCorrectionDefault,this)}})),x3dom.registerNodeType("X3DViewpointNode","Navigation",defineClass(x3dom.nodeTypes.X3DBindableNode,(function(e){if(x3dom.nodeTypes.X3DViewpointNode.superClass.call(this,e),this.addField_SFFloat(e,"nearClippingPlane",-1),this.addField_SFFloat(e,"farClippingPlane",-1),this.addField_SFBool(e,"viewAll",!1),this.addField_SFNode("navigationInfo",x3dom.nodeTypes.NavigationInfo),e&&e.xmlNode){var t=e.xmlNode;t.resetView||t.getFieldOfView||t.getNear||t.getFar||(t.resetView=function(){var e=this._x3domNode;e.resetView(),e._nameSpace.doc.needRender=!0},t.getFieldOfView=function(){return this._x3domNode.getFieldOfView()},t.getNear=function(){return this._x3domNode.getNear()},t.getFar=function(){return this._x3domNode.getFar()})}}),{activate:function(e){var t=this._nameSpace.doc._viewarea;e=e||this;var i=this;if(this._bindAnimation){if(this._vf.viewAll){var o=this._runtime.getSceneBBox();i=t.getFitViewMatrix(o.min,o.max,e,!0)}t.animateTo(i,e._autoGen?null:e)}t._needNavigationMatrixUpdate=!0,this._cf.navigationInfo.node&&this._cf.navigationInfo.node.bind(!0),x3dom.nodeTypes.X3DBindableNode.prototype.activate.call(this,e)},deactivate:function(e){x3dom.nodeTypes.X3DBindableNode.prototype.deactivate.call(this,e)},getTransformation:function(){return this.getCurrentTransform()},getCenterOfRotation:function(){return new x3dom.fields.SFVec3f(0,0,0)},setCenterOfRotation:function(e){this._vf.centerOfRotation.setValues(e)},getFieldOfView:function(){return Math.PI/2},setView:function(e){var t=this.getCurrentTransform();this._viewMatrix=e.mult(t)},setViewAbsolute:function(e){this._viewMatrix=e},setProjectionMatrix:function(e){},resetView:function(){},getNear:function(){return.1},getFar:function(){return 1e4},getImgPlaneHeightAtDistOne:function(){return 2},getViewMatrix:function(){return null},getProjectionMatrix:function(e){return null},setZoom:function(e){}})),x3dom.registerNodeType("Viewpoint","Navigation",defineClass(x3dom.nodeTypes.X3DViewpointNode,(function(e){x3dom.nodeTypes.Viewpoint.superClass.call(this,e),this.addField_SFFloat(e,"fieldOfView",.785398),this.addField_SFVec3f(e,"position",0,0,10),this.addField_SFRotation(e,"orientation",0,0,1,0),this.addField_SFVec3f(e,"centerOfRotation",0,0,0),this.addField_SFFloat(e,"zNear",-1),this.addField_SFFloat(e,"zFar",-1),this._viewMatrix=x3dom.fields.SFMatrix4f.translation(this._vf.position).mult(this._vf.orientation.toMatrix()).inverse(),this._projMatrix=null,this._lastAspect=1,this._vf.nearClippingPlane>-1&&(this._vf.zNear=this._vf.nearClippingPlane),this._vf.farClippingPlane>-1&&(this._vf.zFar=this._vf.farClippingPlane),this._zRatio=1e4,this._zNear=this._vf.zNear,this._zFar=this._vf.zFar,this._imgPlaneHeightAtDistOne=2*Math.tan(this._vf.fieldOfView/2)}),{fieldChanged:function(e){"nearClippingPlane"==e?(this._vf.zNear=this._vf.nearClippingPlane,e="zNear"):"farClippingPlane"==e&&(this._vf.zFar=this._vf.farClippingPlane,e="zFar"),"position"==e||"orientation"==e?this.resetView():"fieldOfView"==e||"zNear"==e||"zFar"==e?(this._projMatrix=null,this._zNear=this._vf.zNear,this._zFar=this._vf.zFar,this._imgPlaneHeightAtDistOne=2*Math.tan(this._vf.fieldOfView/2)):e.indexOf("bind")>=0?(this.bind(this._vf.bind),this._cf.navigationInfo.node&&this._cf.navigationInfo.node.bind(this._vf.bind)):"viewAll"==e&&this._vf.viewAll&&this._nameSpace.doc._x3dElem.runtime.fitAll()},setProjectionMatrix:function(e){this._projMatrix=e},getCenterOfRotation:function(){return this._vf.centerOfRotation},getViewMatrix:function(){return this._viewMatrix},getFieldOfView:function(){return this._vf.fieldOfView},resetView:function(){this._viewMatrix=x3dom.fields.SFMatrix4f.translation(this._vf.position).mult(this._vf.orientation.toMatrix()).inverse(),this._vf.isActive&&this._nameSpace&&this._nameSpace.doc._viewarea&&this._nameSpace.doc._viewarea.resetNavHelpers()},getNear:function(){return this._zNear},getFar:function(){return this._zFar},getImgPlaneHeightAtDistOne:function(){return this._imgPlaneHeightAtDistOne},getProjectionMatrix:function(e){var t=this._vf.fieldOfView,i=this._vf.zFar,o=this._vf.zNear;if(o<=0||i<=0){var s=.8,r=1.2,n=this._nameSpace.doc._viewarea,a=n._scene,d=x3dom.fields.SFVec3f.copy(a._lastMin),l=x3dom.fields.SFVec3f.copy(a._lastMax).subtract(d),h=l.length()/2,f=n.getViewMatrix().inverse(),u=f.e3(),c=new x3dom.fields.SFVec3f(0,0,0),_=new x3dom.fields.SFVec3f(1,1,1),m=new x3dom.fields.Quaternion(0,0,1,0),p=new x3dom.fields.Quaternion(0,0,1,0);f.getTransform(c,m,_,p);var x=_.x,g=_.x;g<_.y&&(g=_.y),x>_.y&&(x=_.y),g<_.z&&(g=_.z),x>_.z&&(x=_.z),g>1?s/=g:x>x3dom.fields.Eps&&x<1&&(r/=x);var v=d.add(l.multiply(.5)),y=u.subtract(v).length();h?(o=y>h?(y-h)*s:0,i=(y+h)*r):(o=.1,i=1e5);var T=i/this._zRatio;o=Math.max(o,Math.max(x3dom.fields.Eps,T)),i>this._vf.zNear&&this._vf.zNear>0&&(o=this._vf.zNear),this._vf.zFar>o&&(i=this._vf.zFar),i<=o&&(i=o+1)}if(null==this._projMatrix)this._projMatrix=x3dom.fields.SFMatrix4f.perspective(t,e,o,i);else if(this._zNear!=o||this._zFar!=i){var b=o-i;this._projMatrix._22=(o+i)/b,this._projMatrix._23=2*o*i/b}else this._lastAspect!=e&&(this._projMatrix._00=1/Math.tan(t/2)/e,this._lastAspect=e);return this._zNear=o,this._zFar=i,this._projMatrix}})),x3dom.registerNodeType("OrthoViewpoint","Navigation",defineClass(x3dom.nodeTypes.X3DViewpointNode,(function(e){x3dom.nodeTypes.OrthoViewpoint.superClass.call(this,e),this.addField_MFFloat(e,"fieldOfView",[-1,-1,1,1]),this.addField_SFVec3f(e,"position",0,0,10),this.addField_SFRotation(e,"orientation",0,0,0,1),this.addField_SFVec3f(e,"centerOfRotation",0,0,0),this.addField_SFFloat(e,"zNear",-1),this.addField_SFFloat(e,"zFar",-1),this._viewMatrix=null,this._projMatrix=null,this._lastAspect=1,this._vf.nearClippingPlane>-1&&(this._vf.zNear=this._vf.nearClippingPlane),this._vf.farClippingPlane>-1&&(this._vf.zFar=this._vf.farClippingPlane),this._zRatio=1e4,this._zNear=this._vf.zNear,this._zFar=this._vf.zFar,this._fieldOfView=this._vf.fieldOfView.slice(0),this.resetView()}),{fieldChanged:function(e){"nearClippingPlane"==e?(this._vf.zNear=this._vf.nearClippingPlane,e="zNear"):"farClippingPlane"==e&&(this._vf.zFar=this._vf.farClippingPlane,e="zFar"),"position"==e||"orientation"==e?this.resetView():"fieldOfView"==e?(this._fieldOfView=this._vf.fieldOfView,this._projMatrix=null):"zNear"==e||"zFar"==e?(this._projMatrix=null,this.resetView()):e.indexOf("bind")>=0?(this.bind(this._vf.bind),this._cf.navigationInfo.node&&this._cf.navigationInfo.node.bind(this._vf.bind)):"viewAll"==e&&this._vf.viewAll&&this._nameSpace.doc._x3dElem.runtime.fitAll()},getCenterOfRotation:function(){return this.getCurrentTransform().multMatrixPnt(this._vf.centerOfRotation)},getViewMatrix:function(){return this._viewMatrix},resetView:function(){x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f((this._vf.fieldOfView[0]+this._vf.fieldOfView[2])/2,(this._vf.fieldOfView[1]+this._vf.fieldOfView[3])/2,0));this._viewMatrix=x3dom.fields.SFMatrix4f.translation(this._vf.position).mult(this._vf.orientation.toMatrix()),this._viewMatrix=this._viewMatrix.inverse(),this._projMatrix=null,this._vf.isActive&&this._nameSpace&&this._nameSpace.doc._viewarea&&this._nameSpace.doc._viewarea.resetNavHelpers()},getNear:function(){return this._vf.zNear},getFar:function(){return this._vf.zFar},getFieldOfView:function(){return.785},setZoom:function(e){this._fieldOfView[0]=-e,this._fieldOfView[1]=-e,this._fieldOfView[2]=e,this._fieldOfView[3]=e,this._projMatrix=null},getZoom:function(e){return this._fieldOfView},getProjectionMatrix:function(e){var t=this.getFieldOfView(),i=this._vf.zFar,o=this._vf.zNear;if(o<=0||i<=0){var s=this._nameSpace.doc._viewarea._scene,r=x3dom.fields.SFVec3f.copy(s._lastMin),n=x3dom.fields.SFVec3f.copy(s._lastMax).subtract(r),a=Math.tan(t/2),d=n.y/2/a+n.z+this._fieldOfView[2],l=n.x/2/a+n.z+this._fieldOfView[2],h=d>l?d:l;i=4*h,o=1e-4,this._viewMatrix._23=-2*h}if(null==this._projMatrix||this._lastAspect!=e||this._zNear!=o||this._zFar!=i){var f=this._zNear=o,u=this._zFar=i,c=this._fieldOfView[0],_=this._fieldOfView[1],m=this._fieldOfView[2],p=this._fieldOfView[3];this._projMatrix=x3dom.fields.SFMatrix4f.ortho(c,m,_,p,f,u,e)}return this._lastAspect=e,this._projMatrix}})),x3dom.registerNodeType("Viewfrustum","Navigation",defineClass(x3dom.nodeTypes.X3DViewpointNode,(function(e){x3dom.nodeTypes.Viewfrustum.superClass.call(this,e),this.addField_SFMatrix4f(e,"modelview",1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this.addField_SFMatrix4f(e,"projection",1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this._viewMatrix=this._vf.modelview.transpose().inverse(),this._projMatrix=this._vf.projection.transpose(),this._centerOfRotation=new x3dom.fields.SFVec3f(0,0,0)}),{fieldChanged:function(e){"modelview"==e?this.resetView():"projection"==e?this._projMatrix=this._vf.projection.transpose():e.indexOf("bind")>=0&&this.bind(this._vf.bind)},getCenterOfRotation:function(){return this.getCurrentTransform().multMatrixPnt(this._centerOfRotation)},setCenterOfRotation:function(e){this._centerOfRotation.setValues(e)},getViewMatrix:function(){return this._viewMatrix},getFieldOfView:function(){return 2*Math.atan(1/this._projMatrix._11)},getImgPlaneHeightAtDistOne:function(){return 2/this._projMatrix._11},resetView:function(){this._viewMatrix=this._vf.modelview.transpose().inverse(),this._centerOfRotation=new x3dom.fields.SFVec3f(0,0,0)},getProjectionMatrix:function(e){return this._projMatrix}})),x3dom.registerNodeType("X3DNavigationInfoNode","Navigation",defineClass(x3dom.nodeTypes.X3DBindableNode,(function(e){x3dom.nodeTypes.X3DNavigationInfoNode.superClass.call(this,e)}))),x3dom.registerNodeType("NavigationInfo","Navigation",defineClass(x3dom.nodeTypes.X3DNavigationInfoNode,(function(e){x3dom.nodeTypes.NavigationInfo.superClass.call(this,e),this.addField_SFBool(e,"headlight",!0),this.addField_SFBool(e,"reverseScroll",!1),this.addField_MFString(e,"type",["EXAMINE","ANY"]),this.addField_MFFloat(e,"typeParams",[-.4,60,.05,2.8]),this.addField_SFString(e,"explorationMode","all"),this.addField_MFFloat(e,"avatarSize",[.25,1.6,.75]),this.addField_SFFloat(e,"walkDamping",2),this.addField_SFFloat(e,"visibilityLimit",0),this.addField_SFFloat(e,"speed",1),this.addField_SFTime(e,"transitionTime",1),this.addField_MFString(e,"transitionType",["LINEAR"]),this._validTypes=["none","examine","turntable","fly","freefly","lookat","lookaround","walk","game","helicopter","any"],this._typeMapping={default:x3dom.DefaultNavigation,turntable:x3dom.TurntableNavigation,walk:x3dom.WalkNavigation},this._heliUpdated=!1;var t=this.setType(this.getType());x3dom.debug.logInfo("NavType: "+t)}),{fieldChanged:function(e){"typeParams"==e?this._heliUpdated=!1:"type"==e?this.setType(this.getType()):e.indexOf("bind")>=0&&this.bind(this._vf.bind)},setType:function(e,t){var i=this.checkType(e.toLowerCase());if(this.checkType(this.getType())!==i||null==this._impl){switch(null==this._typeMapping[i]?this._impl=new this._typeMapping.default(this):this._impl=new this._typeMapping[i](this),i){case"game":t?t.initMouseState():this._nameSpace.doc._viewarea.initMouseState();break;case"helicopter":this._heliUpdated=!1;break;case"turntable":t?t.initMouseState():this._nameSpace.doc._viewarea&&this._nameSpace.doc._viewarea.initMouseState()}this._nameSpace.doc._viewarea&&this._impl.init(this._nameSpace.doc._viewarea,!1)}this._vf.type[0]=i,x3dom.debug.logInfo("Switch to "+i+" mode.")},getType:function(){var e=this._vf.type[0].toLowerCase();return e.length<=1?e="none":"any"==e&&(e="examine"),e},getTypeParams:function(){var e=this._vf.typeParams.length,t=[e>=1?this._vf.typeParams[0]:-.4,e>=2?this._vf.typeParams[1]:60,e>=3?this._vf.typeParams[2]:x3dom.fields.Eps,e>=4?this._vf.typeParams[3]:Math.PI-x3dom.fields.Eps];return e>=5&&(t=t.concat(this._vf.typeParams.slice(4))),t},setTypeParams:function(e){for(var t=0;t<e.length;t++)this._vf.typeParams[t]=e[t]},checkType:function(e){return this._validTypes.indexOf(e)>-1?e:(x3dom.debug.logWarning(e+" is no valid navigation type, use one of "+this._validTypes.toString()),"examine")},getExplorationMode:function(){switch(this._vf.explorationMode.toLowerCase()){case"all":return 7;case"rotate":return 1;case"zoom":return 2;case"pan":return 4;case"-rotate":return 6;case"-zoom":return 5;case"-pan":return 3;case"none":return 0;default:return 7}}})),x3dom.registerNodeType("Billboard","Navigation",defineClass(x3dom.nodeTypes.X3DGroupingNode,(function(e){x3dom.nodeTypes.Billboard.superClass.call(this,e),this.addField_SFVec3f(e,"axisOfRotation",0,1,0),this._eye=new x3dom.fields.SFVec3f(0,0,0),this._eyeViewUp=new x3dom.fields.SFVec3f(0,0,0),this._eyeLook=new x3dom.fields.SFVec3f(0,0,0)}),{collectDrawableObjects:function(e,t,i,o,s,r){if(i&&this._parentNodes.length>1&&(i=!1),i&&(o=o||this.cacheInvalid())&&this.invalidateCache(),!((s=t.cull(e,this.graphState(),i,s))<0)){i=!1;var n=this.getVolume(),a=x3dom.fields.SFVec3f.MAX(),d=x3dom.fields.SFVec3f.MIN();n.getBounds(a,d);var l=t.viewMatrix,h=new x3dom.fields.SFVec3f(0,0,0);h=l.inverse().multMatrixPnt(h);var f=l.mult(e);this._eye=e.inverse().multMatrixPnt(h),this._eyeViewUp=new x3dom.fields.SFVec3f(f._10,f._11,f._12),this._eyeLook=new x3dom.fields.SFVec3f(f._20,f._21,f._22);var u=x3dom.fields.SFMatrix4f.identity(),c=d.add(a).multiply(.5),_=this._eye.subtract(c);if(this._vf.axisOfRotation.equals(new x3dom.fields.SFVec3f(0,0,0),x3dom.fields.Eps)){var m=(u=x3dom.fields.Quaternion.rotateFromTo(_,new x3dom.fields.SFVec3f(0,0,1)).toMatrix().transpose()).multMatrixPnt(new x3dom.fields.SFVec3f(0,1,0)).normalize(),p=u.multMatrixPnt(new x3dom.fields.SFVec3f(0,0,1)).normalize();if(!this._eyeViewUp.equals(new x3dom.fields.SFVec3f(0,0,0),x3dom.fields.Eps)){var x=x3dom.fields.Quaternion.rotateFromTo(this._eyeLook,p),g=x.toMatrix().transpose().multMatrixVec(m),v=x3dom.fields.Quaternion.rotateFromTo(this._eyeViewUp,g);u=x.toMatrix().transpose().mult(u),u=v.toMatrix().transpose().mult(u)}}else{var y=this._vf.axisOfRotation.cross(_).normalize();this._eye.z<0&&(y=y.multiply(-1));var T=Math.asin(y.dot(new x3dom.fields.SFVec3f(0,0,1)));this._eye.z<0&&(T+=Math.PI),u=x3dom.fields.SFMatrix4f.parseRotation(this._vf.axisOfRotation.x+", "+this._vf.axisOfRotation.y+", "+this._vf.axisOfRotation.z+", "+-1*T)}for(var b=this.transformMatrix(e.mult(u)),S=0,F=this._childNodes.length;S<F;S++){var E=this._childNodes[S];E&&E.collectDrawableObjects(b,t,i,o,s,r)}}}})),x3dom.registerNodeType("Collision","Navigation",defineClass(x3dom.nodeTypes.X3DGroupingNode,(function(e){x3dom.nodeTypes.Collision.superClass.call(this,e),this.addField_SFBool(e,"enabled",!0),this.addField_SFNode("proxy",x3dom.nodeTypes.X3DGroupingNode),this.addField_SFTime(e,"collideTime",0),this.addField_SFBool(e,"isActive",!0)}),{collectDrawableObjects:function(e,t,i,o,s,r){if(i&&this._parentNodes.length>1&&(i=!1),i&&(o=o||this.cacheInvalid())&&this.invalidateCache(),!((s=t.cull(e,this.graphState(),i,s))<0)){var n,a;i?(this._graph.globalMatrix||(this._graph.globalMatrix=this.transformMatrix(e)),a=this._graph.globalMatrix):a=this.transformMatrix(e);for(var d=0,l=this._childNodes.length;d<l;d++)(n=this._childNodes[d])&&n!==this._cf.proxy.node&&n.collectDrawableObjects(a,t,i,o,s,r)}}})),x3dom.registerNodeType("X3DLODNode","Navigation",defineClass(x3dom.nodeTypes.X3DGroupingNode,(function(e){x3dom.nodeTypes.X3DLODNode.superClass.call(this,e),this.addField_SFBool(e,"forceTransitions",!1),this.addField_SFVec3f(e,"center",0,0,0),this._eye=new x3dom.fields.SFVec3f(0,0,0)}),{collectDrawableObjects:function(e,t,i,o,s,r){i&&this._parentNodes.length>1&&(i=!1),i&&(o=o||this.cacheInvalid())&&this.invalidateCache(),(s=t.cull(e,this.graphState(),i,s))<0||(i=!1,this.visitChildren(e,t,i,o,s,r))},visitChildren:function(e,t,i,o,s,r){}})),x3dom.registerNodeType("LOD","Navigation",defineClass(x3dom.nodeTypes.X3DLODNode,(function(e){x3dom.nodeTypes.LOD.superClass.call(this,e),this.addField_MFFloat(e,"range",[]),this.addField_SFInt32(e,"level_changed",0),this._lastRangePos=-1}),{visitChildren:function(e,t,i,o,s,r){var n=0,a=this._childNodes.length,d=t.viewMatrix,l=new x3dom.fields.SFVec3f(0,0,0);l=d.inverse().multMatrixPnt(l),this._eye=e.inverse().multMatrixPnt(l);for(var h=this._vf.center.subtract(this._eye).length();n<this._vf.range.length&&h>this._vf.range[n];)n++;n&&n>=a&&(n=a-1),n!==this._lastRangePos&&this.postMessage("level_changed",n),this._lastRangePos=n;var f=this._childNodes[n];if(a&&f){var u=this.transformMatrix(e);f.collectDrawableObjects(u,t,i,o,s,r)}},getVolume:function(){var e,t,i=this._graph.volume;if(!this.volumeValid()&&this.renderFlag&&this.renderFlag())if(this._lastRangePos>=0)(t=(e=this._childNodes[this._lastRangePos])&&e.renderFlag&&!0===e.renderFlag()?e.getVolume():null)&&t.isValid()&&i.extendBounds(t.min,t.max);else for(var o=0,s=this._childNodes.length;o<s;o++)!(e=this._childNodes[o])||e.renderFlag&&!0!==e.renderFlag()||(t=e.getVolume())&&t.isValid()&&i.extendBounds(t.min,t.max);return i},nodeChanged:function(){this.invalidateVolume()},fieldChanged:function(e){"render"!=e&&"center"!=e&&"range"!=e||this.invalidateVolume()}})),x3dom.registerNodeType("DynamicLOD","Navigation",defineClass(x3dom.nodeTypes.X3DLODNode,(function(e){x3dom.nodeTypes.DynamicLOD.superClass.call(this,e),this.addField_SFFloat(e,"subScale",.5),this.addField_SFVec2f(e,"size",2,2),this.addField_SFVec2f(e,"subdivision",1,1),this.addField_SFNode("root",x3dom.nodeTypes.X3DShapeNode),this.addField_SFString(e,"urlHead","http://r"),this.addField_SFString(e,"urlCenter",".ortho.tiles.virtualearth.net/tiles/h"),this.addField_SFString(e,"urlTail",".png?g=-1"),this.rootGeometry=new x3dom.nodeTypes.Plane(e),this.level=0,this.quadrant=4,this.cell=""}),{nodeChanged:function(){var e=this._cf.root.node;null!=e&&null==e._cf.geometry.node&&(this.rootGeometry._vf.size.setValues(this._vf.size),this.rootGeometry._vf.subdivision.setValues(this._vf.subdivision),this.rootGeometry._vf.center.setValues(this._vf.center),this.rootGeometry.fieldChanged("subdivision"),this._cf.root.node.addChild(this.rootGeometry),this.rootGeometry.nodeChanged(),this._cf.root.node.nodeChanged(),this._nameSpace.doc.needRender=!0)},visitChildren:function(e,t,i,o,s,r){var n=this._cf.root.node;if(null!=n){var a=t.viewMatrix,d=new x3dom.fields.SFVec3f(0,0,0);d=a.inverse().multMatrixPnt(d),this._eye=e.inverse().multMatrixPnt(d);var l,h=this._vf.center.subtract(this._eye).length();if(h>x3dom.fields.Eps&&h*this._vf.subScale<=this._vf.size.length())if(this._childNodes.length<=1){var f=new Array(new x3dom.fields.SFVec3f(-.25*this._vf.size.x,.25*this._vf.size.y,0),new x3dom.fields.SFVec3f(.25*this._vf.size.x,.25*this._vf.size.y,0),new x3dom.fields.SFVec3f(-.25*this._vf.size.x,-.25*this._vf.size.y,0),new x3dom.fields.SFVec3f(.25*this._vf.size.x,-.25*this._vf.size.y,0));for(l=0;l<4;l++){var u=new x3dom.nodeTypes.DynamicLOD;u._nameSpace=this._nameSpace,u._eye.setValues(this._eye),u.level=this.level+1,u.quadrant=l,u.cell=this.cell+l,u._vf.urlHead=this._vf.urlHead,u._vf.urlCenter=this._vf.urlCenter,u._vf.urlTail=this._vf.urlTail,u._vf.center=this._vf.center.add(f[l]),u._vf.size=this._vf.size.multiply(.5),u._vf.subdivision.setValues(this._vf.subdivision);var c=new x3dom.nodeTypes.Appearance,_=new x3dom.nodeTypes.ImageTexture;_._nameSpace=this._nameSpace,_._vf.url[0]=this._vf.urlHead+u.quadrant+this._vf.urlCenter+u.cell+this._vf.urlTail,c.addChild(_),_.nodeChanged();var m=new x3dom.nodeTypes.Shape;m._nameSpace=this._nameSpace,m.addChild(c),c.nodeChanged(),u.addChild(m,"root"),m.nodeChanged(),this.addChild(u),u.nodeChanged()}}else for(l=1;l<this._childNodes.length;l++)this._childNodes[l].collectDrawableObjects(e,t,i,o,s,r);else n.collectDrawableObjects(e,t,i,o,s,r)}},getVolume:function(){var e=this._graph.volume;return e.isValid()||(e.min.setValues(this._vf.center),e.min.x-=.5*this._vf.size.x,e.min.y-=.5*this._vf.size.y,e.min.z-=x3dom.fields.Eps,e.max.setValues(this._vf.center),e.max.x+=.5*this._vf.size.x,e.max.y+=.5*this._vf.size.y,e.max.z+=x3dom.fields.Eps),e}})),x3dom.DefaultNavigation=function(e){this.navi=e},x3dom.DefaultNavigation.prototype.onMousePress=function(e,t,i,o){},x3dom.DefaultNavigation.prototype.onMouseReleased=function(e,t,i,o,s){},x3dom.DefaultNavigation.prototype.init=function(e,t){},x3dom.DefaultNavigation.prototype.zoom=function(e,t){var i=this.navi,o=e._scene.getViewpoint(),s=e._scene._lastMax.subtract(e._scene._lastMin).length();s=((s=Math.min(s,o.getFar()))<x3dom.fields.Eps?1:s)*i._vf.speed;var r=new x3dom.fields.SFVec3f(0,0,s*t/e._height);if(x3dom.isa(o,x3dom.nodeTypes.OrthoViewpoint)&&o.setZoom(Math.abs(o._fieldOfView[0])-r.z),i._vf.typeParams.length>=6){var n=-i._vf.typeParams[5],a=i._vf.typeParams[4];e._movement.z=Math.min(Math.max(e._movement.z,n),a)}e._movement=e._movement.add(r);var d=e.getViewpointMatrix().mult(e._transMat);e._transMat=d.inverse().mult(x3dom.fields.SFMatrix4f.translation(e._movement)).mult(d)},x3dom.DefaultNavigation.prototype.moveForward=function(e){var t=this.navi;if("game"===t.getType()){var i=.25;t._vf.avatarSize.length>2&&(i=t._vf.avatarSize[0]);var o=5*e._deltaT*t._vf.speed,s=e._yaw/180*Math.PI,r=e._pitch/180*Math.PI,n=e._flyMat.inverse();e._scene._nameSpace.doc.ctx.pickValue(e,e._width/2,e._height/2,e._lastButton),e._pickingInfo.pickObj&&(e._pickingInfo.pickPos.subtract(n.e3()).length()<=2*i||(e._eyePos.x-=Math.sin(s)*o,e._eyePos.z+=Math.cos(s)*o,e._eyePos.y+=Math.sin(r)*o))}},x3dom.DefaultNavigation.prototype.moveBackwards=function(e){var t=this.navi;if("game"===t.getType()){var i=5*e._deltaT*t._vf.speed,o=e._yaw/180*Math.PI,s=e._pitch/180*Math.PI;e._eyePos.x+=Math.sin(o)*i,e._eyePos.z-=Math.cos(o)*i,e._eyePos.y-=Math.sin(s)*i}},x3dom.DefaultNavigation.prototype.strafeLeft=function(e){var t=this.navi;if("game"===t.getType()){var i=5*e._deltaT*t._vf.speed,o=e._yaw/180*Math.PI;e._eyePos.x+=Math.cos(o)*i,e._eyePos.z+=Math.sin(o)*i}},x3dom.DefaultNavigation.prototype.strafeRight=function(e){var t=this.navi;if("game"===t.getType()){var i=5*e._deltaT*t._vf.speed,o=e._yaw/180*Math.PI;e._eyePos.x-=Math.cos(o)*i,e._eyePos.z-=Math.sin(o)*i}},x3dom.DefaultNavigation.prototype.navigateTo=function(e,t){var i=this.navi,o=i.getType(),s=null,r=e._currentInputType==x3dom.InputTypes.NAVIGATION&&("game"===o||e._lastButton>0&&(o.indexOf("fly")>=0||"walk"===o||"helicopter"===o||"looka"===o.substr(0,5)));e._deltaT=t-e._lastTS;var n=function(e,t){return e>0?e<=t?0:e-t:e<=0?e>=-t?0:e+t:void 0},a=function(e,t){return(t<0?-1:1)*Math.pow(e*Math.abs(t),1.65)};if(r){null!==e._pickingInfo.pickObj&&(s={pickPos:e._pickingInfo.pickPos,pickNorm:e._pickingInfo.pickNorm,pickObj:e._pickingInfo.pickObj,firstObj:e._pickingInfo.firstObj,lastObj:e._pickingInfo.lastObj,lastClickObj:e._pickingInfo.lastClickObj,shadowObjectId:e._pickingInfo.shadowObjectId});var d=.25,l=1.6;i._vf.avatarSize.length>2&&(d=i._vf.avatarSize[0],l=i._vf.avatarSize[1],i._vf.avatarSize[2]);var h=e.getViewMatrix(),f=0,u=Math.min(e._width,e._height),c=n((e._pressX-e._lastX)/u,.01),_=n((e._pressY-e._lastY)/u,.01),m=a(1,c),p=a(1,_),x=2&e._lastButton?-1:1;x*=e._deltaT*i._vf.speed;e._deltaT,i._vf.speed;var g=e._deltaT*i._vf.speed*p,v=Math.PI*e._deltaT*m,y=Math.PI*e._deltaT*p;if(!0===e._needNavigationMatrixUpdate){e._needNavigationMatrixUpdate=!1,e._rotMat=x3dom.fields.SFMatrix4f.identity(),e._transMat=x3dom.fields.SFMatrix4f.identity(),e._movement=new x3dom.fields.SFVec3f(0,0,0);var T=0,b=Math.asin(h._02),S=Math.cos(b);Math.abs(S)>1e-4&&(T=Math.atan2(-h._12/S,h._22/S)),e._flyMat=h.inverse(),e._from=e._flyMat.e3(),e._at=e._from.subtract(e._flyMat.e2()),"helicopter"===o&&(e._at.y=e._from.y),e._up=e._flyMat.e1(),e._pitch=180*T/Math.PI,e._yaw=180*b/Math.PI,e._eyePos=e._from.negate()}var F,E,M,C,w,A=null,R=null,D=null;if("game"===o){e._pitch+=e._dy,e._yaw+=e._dx,e._pitch>=89&&(e._pitch=89),e._pitch<=-89&&(e._pitch=-89),e._yaw>=360&&(e._yaw-=360),e._yaw<0&&(e._yaw=360+e._yaw),e._dx=0,e._dy=0;var N=x3dom.fields.SFMatrix4f.rotationX(e._pitch/180*Math.PI),I=x3dom.fields.SFMatrix4f.rotationY(e._yaw/180*Math.PI),P=x3dom.fields.SFMatrix4f.translation(e._eyePos);e._flyMat=N.mult(I).mult(P);var V=e._flyMat.inverse(),L=V.e3();return R=new x3dom.fields.SFVec3f(0,-1,0),A=L.add(R),R=V.e0().cross(R).normalize(),D=(D=x3dom.fields.SFMatrix4f.lookAt(L,A,R)).inverse(),e._scene._nameSpace.doc.ctx.pickValue(e,e._width/2,e._height/2,e._lastButton,D,e.getProjectionMatrix().mult(D)),e._pickingInfo.pickObj&&(f=e._pickingInfo.pickPos.subtract(L).length(),L.y+=l-f,V.setTranslate(L),e._eyePos=V.e3().negate(),e._flyMat=V.inverse(),e._pickingInfo.pickObj=null),e._scene.getViewpoint().setView(e._flyMat),r}if("helicopter"===o){var O=i.getTypeParams();if(2&e._lastButton){var B=200*g;O[1]+=B,i.setTypeParams(O)}x=1&e._lastButton?300*g:0,y=O[0],e._from.y=O[1],e._at.y=e._from.y,F=x3dom.fields.Quaternion.axisAngle(e._up,v).toMatrix(),E=(E=x3dom.fields.SFMatrix4f.translation(e._from)).mult(F),F=x3dom.fields.SFMatrix4f.translation(e._from.negate()),E=E.mult(F),e._at=E.multMatrixPnt(e._at),w=(C=(M=e._at.subtract(e._from).normalize()).cross(e._up).normalize()).cross(M).normalize(),M=M.multiply(x),e._from=e._from.add(M),e._at=e._at.add(M),F=x3dom.fields.Quaternion.axisAngle(C,y).toMatrix(),E=(E=x3dom.fields.SFMatrix4f.translation(e._from)).mult(F),F=x3dom.fields.SFMatrix4f.translation(e._from.negate());var U=(E=E.mult(F)).multMatrixPnt(e._at);return e._flyMat=x3dom.fields.SFMatrix4f.lookAt(e._from,U,w),e._scene.getViewpoint().setView(e._flyMat.inverse()),r}if(F=x3dom.fields.Quaternion.axisAngle(e._up,v).toMatrix(),E=(E=x3dom.fields.SFMatrix4f.translation(e._from)).mult(F),F=x3dom.fields.SFMatrix4f.translation(e._from.negate()),E=E.mult(F),e._at=E.multMatrixPnt(e._at),w=(C=(M=e._at.subtract(e._from).normalize()).cross(e._up).normalize()).cross(M).normalize(),F=x3dom.fields.Quaternion.axisAngle(C,y).toMatrix(),E=(E=x3dom.fields.SFMatrix4f.translation(e._from)).mult(F),F=x3dom.fields.SFMatrix4f.translation(e._from.negate()),E=E.mult(F),e._at=E.multMatrixPnt(e._at),"looka"!==o.substr(0,5)){var X=e.getProjectionMatrix();"freefly"!==o&&(x<0?((D=new x3dom.fields.SFMatrix4f).setValue(e._last_mat_view.e0(),e._last_mat_view.e1(),e._last_mat_view.e2().negate(),e._last_mat_view.e3()),e._scene._nameSpace.doc.ctx.pickValue(e,e._width/2,e._height/2,e._lastButton,D,X.mult(D))):e._scene._nameSpace.doc.ctx.pickValue(e,e._width/2,e._height/2,e._lastButton),e._pickingInfo.pickObj&&(f=e._pickingInfo.pickPos.subtract(e._from).length())<=d+x&&(x=0)),M=e._at.subtract(e._from).normalize().multiply(x),e._at=e._at.add(M),e._from=e._from.add(M),"walk"===o&&(w.x=0,w.y=1,w.z=0,A=e._from.addScaled(w,-1),R=C.cross(w.negate()).normalize(),D=(D=x3dom.fields.SFMatrix4f.lookAt(e._from,A,R)).inverse(),e._scene._nameSpace.doc.ctx.pickValue(e,e._width/2,e._height/2,e._lastButton,D,X.mult(D)),e._pickingInfo.pickObj&&(f=(l-(f=e._pickingInfo.pickPos.subtract(e._from).length()))/i._vf.walkDamping,e._at=e._at.add(w.multiply(f)),e._from=e._from.add(w.multiply(f)))),e._pickingInfo.pickObj=null}e._flyMat=x3dom.fields.SFMatrix4f.lookAt(e._from,e._at,w),e._scene.getViewpoint().setView(e._flyMat.inverse()),null!==s&&(e._pickingInfo=s)}return r},x3dom.DefaultNavigation.prototype.animateTo=function(e,t,i,o){var s,r=this.navi;e._mixer._isVPtarget=x3dom.isa(t,x3dom.nodeTypes.X3DViewpointNode),e._mixer._isVPtarget&&(t=t.getViewMatrix().mult(t.getCurrentTransform().inverse())),"teleport"!==r._vf.transitionType[0].toLowerCase()&&0!=o&&"game"!==r.getType()&&i&&x3dom.isa(i,x3dom.nodeTypes.X3DViewpointNode)?(s=i.getViewMatrix().mult(i.getCurrentTransform().inverse()).mult(e._transMat).mult(e._rotMat),e._mixer.isActive()&&(i.setView(e._mixer.getEndMatrix()),e._mixer.reset()),e._mixer.beginTime=e._lastTS,arguments.length>=4&&null!=arguments[3]?e._mixer.endTime=e._lastTS+o:e._mixer.endTime=e._lastTS+r._vf.transitionTime,e._mixer.setBeginMatrix(s),e._mixer.setEndMatrix(t),e._scene.getViewpoint().setView(s)):e._scene.getViewpoint().setView(t),e._rotMat=x3dom.fields.SFMatrix4f.identity(),e._transMat=x3dom.fields.SFMatrix4f.identity(),e._movement=new x3dom.fields.SFVec3f(0,0,0),e._needNavigationMatrixUpdate=!0},x3dom.DefaultNavigation.prototype.orthoAnimateTo=function(e,t,i,o){var s=this.navi;o=o||s._vf.transitionTime,e._interpolator.beginValue=i,e._interpolator.endValue=t,e._interpolator.beginTime=e._lastTS,e._interpolator.endTime=e._lastTS+o},x3dom.DefaultNavigation.prototype.resetView=function(e){var t=this.navi;if("teleport"!==t._vf.transitionType[0].toLowerCase()&&"game"!==t.getType()){var i=e._scene.getViewpoint();e._mixer.beginTime=e._lastTS,e._mixer.endTime=e._lastTS+t._vf.transitionTime,e._mixer.setBeginMatrix(e.getViewMatrix()),x3dom.isa(i,x3dom.nodeTypes.OrthoViewpoint)&&this.orthoAnimateTo(e,Math.abs(i._vf.fieldOfView[0]),Math.abs(i._fieldOfView[0]));var o=e._scene.getViewpoint();o.resetView(),o=o.getViewMatrix().mult(o.getCurrentTransform().inverse()),e._mixer.setEndMatrix(o)}else e._scene.getViewpoint().resetView();e.resetNavHelpers(),t._heliUpdated=!1},x3dom.DefaultNavigation.prototype.onDrag=function(e,t,i,o){var s=this.navi,r=s.getType(),n=s.getExplorationMode();if("none"!==r&&0!=n){var a=e._scene.getViewpoint(),d=t-e._lastX,l=i-e._lastY;if(e._dx=d,e._dy=l,e._lastX=t,e._lastY=i,"examine"===r){var h,f,u,c,_=null;if(1&(o&=n)){u=2*l*Math.PI/e._width,c=2*d*Math.PI/e._height,_=e.getViewMatrix();var m=x3dom.fields.SFMatrix4f.rotationX(u),p=x3dom.fields.SFMatrix4f.rotationY(c),x=a.getCenterOfRotation();_.setTranslate(new x3dom.fields.SFVec3f(0,0,0)),e._rotMat=e._rotMat.mult(x3dom.fields.SFMatrix4f.translation(x)).mult(_.inverse()).mult(m).mult(p).mult(_).mult(x3dom.fields.SFMatrix4f.translation(x.negate()))}if(4&o&&(h=e._scene._lastMax.subtract(e._scene._lastMin).length(),h=((h=Math.min(h,a.getFar()))<x3dom.fields.Eps?1:h)*s._vf.speed,f=new x3dom.fields.SFVec3f(h*d/e._width,h*-l/e._height,0),e._movement=e._movement.add(f),_=e.getViewpointMatrix().mult(e._transMat),e._transMat=_.inverse().mult(x3dom.fields.SFMatrix4f.translation(e._movement)).mult(_)),2&o){if(h=e._scene._lastMax.subtract(e._scene._lastMin).length(),h=((h=Math.min(h,a.getFar()))<x3dom.fields.Eps?1:h)*s._vf.speed,f=new x3dom.fields.SFVec3f(0,0,h*(d+l)/e._height),x3dom.isa(a,x3dom.nodeTypes.OrthoViewpoint)&&a.setZoom(Math.abs(a._fieldOfView[0])-f.z),s._vf.typeParams.length>=6){var g=-s._vf.typeParams[5],v=s._vf.typeParams[4];e._movement.z=Math.min(Math.max(e._movement.z,g),v)}e._movement=e._movement.add(f),_=e.getViewpointMatrix().mult(e._transMat),e._transMat=_.inverse().mult(x3dom.fields.SFMatrix4f.translation(e._movement)).mult(_)}e._isMoving=!0}}},x3dom.DefaultNavigation.prototype.onTouchStart=function(e,t,i){},x3dom.DefaultNavigation.prototype.onTouchDrag=function(e,t,i,o,s){if(e._currentInputType==x3dom.InputTypes.NAVIGATION){var r=this.navi,n=e._scene.getViewpoint(),a=r.getExplorationMode();if("examine"===r.getType()&&0!==a){if(o&&4&a){var d=e._scene._lastMax.subtract(e._scene._lastMin).length();d=((d=Math.min(d,n.getFar()))<x3dom.fields.Eps?1:d)*r._vf.speed,o=o.multiply(d),x3dom.isa(n,x3dom.nodeTypes.OrthoViewpoint)&&(n.setZoom(Math.abs(n._fieldOfView[0])-o.z),o.z=0),e._movement=e._movement.add(o),e._transMat=n.getViewMatrix().inverse().mult(x3dom.fields.SFMatrix4f.translation(e._movement)).mult(n.getViewMatrix())}if(s&&1&a){var l=n.getCenterOfRotation(),h=e.getViewMatrix();h.setTranslate(new x3dom.fields.SFVec3f(0,0,0)),e._rotMat=e._rotMat.mult(x3dom.fields.SFMatrix4f.translation(l)).mult(h.inverse()).mult(s).mult(h).mult(x3dom.fields.SFMatrix4f.translation(l.negate()))}e._isMoving=!0}}},x3dom.DefaultNavigation.prototype.onTouchEnd=function(e,t){},x3dom.DefaultNavigation.prototype.onDoubleClick=function(e,t,i){if((!e._doc._x3dElem.hasAttribute("disableDoubleClick")||"true"!==e._doc._x3dElem.getAttribute("disableDoubleClick"))&&"none"!=e._scene.getNavigationInfo().getType()){var o=e._scene._vf.pickMode.toLowerCase();if("color"!=o&&"texcoord"!=o){var s=e._scene.getViewpoint();s.setCenterOfRotation(e._pick),x3dom.debug.logInfo("New center of Rotation:  "+e._pick);var r=e.getViewMatrix().inverse(),n=r.e3(),a=e._pick,d=r.e1(),l=r.e0().cross(d).normalize(),h=l.dot(e._pick.subtract(n));n=a.addScaled(l,-h),r=x3dom.fields.SFMatrix4f.lookAt(n,a,d),x3dom.debug.logInfo("New camera position:  "+n),e.animateTo(r.inverse(),s)}}},x3dom.TurntableNavigation=function(e){x3dom.DefaultNavigation.call(this,e),this.panAxisX=null,this.panAxisY=null,this.panEnabled=!0},x3dom.TurntableNavigation.prototype=Object.create(x3dom.DefaultNavigation.prototype),x3dom.TurntableNavigation.prototype.constructor=x3dom.TurntableNavigation,x3dom.TurntableNavigation.prototype.onDrag=function(e,t,i,o){var s=this.navi;e._flyMat||this.initTurnTable(e,!1);var r=s.getType(),n=s.getExplorationMode();if("none"!==r&&0!=n){var a,d,l=t-e._lastX,h=i-e._lastY,f=null;if(1&(o&=n))a=2*h*Math.PI/e._height,d=2*l*Math.PI/e._width,this.rotate(e,a,d);else if(2&o){var u=(f=((f=e._scene._lastMax.subtract(e._scene._lastMin).length())<x3dom.fields.Eps?1:f)*s._vf.speed)*(l+h)/e._height;this.zoom(e,u)}else if(4&o&&1==this.panEnabled){var c=-(f=((f=e._scene._lastMax.subtract(e._scene._lastMin).length())<x3dom.fields.Eps?1:f)*s._vf.speed*.75)*l/e._width,_=f*h/e._height;this.pan(e,c,_)}e._isMoving=!0,e._dx=l,e._dy=h,e._lastX=t,e._lastY=i}},x3dom.TurntableNavigation.prototype.pan=function(e,t,i){var o=e._scene.getViewpoint();if(null!=this.target){var s=this.target._x3domNode.getVolume();e._up=e._flyMat.e1(),e._from=e._flyMat.e3();var r=n=(n=e._at).addScaled(this.panAxisY,i);n.y>s.max.y||n.y<s.min.y?r=e._at:e._from=e._from.addScaled(this.panAxisY,i),(n=r.addScaled(this.panAxisX,t)).x>s.max.x||n.x<s.min.x?n=r:e._from=e._from.addScaled(this.panAxisX,t),e._at=n,e._flyMat=x3dom.fields.SFMatrix4f.lookAt(e._from,n,e._up),o.setViewAbsolute(e._flyMat.inverse())}else if(null!=this.panAxisX&&null!=this.panAxisY){e._up=e._flyMat.e1(),e._from=e._flyMat.e3();r=n=(n=e._at).addScaled(this.panAxisY,i);e._from=e._from.addScaled(this.panAxisY,i),n=r.addScaled(this.panAxisX,t),e._from=e._from.addScaled(this.panAxisX,t),e._at=n,e._flyMat=x3dom.fields.SFMatrix4f.lookAt(e._from,n,e._up),o.setViewAbsolute(e._flyMat.inverse())}else{e._up=e._flyMat.e1(),e._from=e._flyMat.e3();var n,a=e._up.cross(e._from).normalize(),d=e._from.cross(a).normalize();r=n=(n=e._at).addScaled(d,i);e._from=e._from.addScaled(d,i),n=r.addScaled(a,t),e._from=e._from.addScaled(a,t),e._at=n,e._flyMat=x3dom.fields.SFMatrix4f.lookAt(e._from,n,e._up),o.setViewAbsolute(e._flyMat.inverse())}},x3dom.TurntableNavigation.prototype.rotate=function(e,t,i){var o=e._scene.getViewpoint();e._flyMat=this.calcOrbit(e,t,i),o.setView(e._flyMat.inverse())},x3dom.TurntableNavigation.prototype.zoom=function(e,t){var i=this.navi,o=e._scene.getViewpoint();e._up=e._flyMat.e1(),e._from=e._flyMat.e3();var s=e._at,r=s.subtract(e._from),n=r.length();r=r.normalize();var a=t;i._vf.typeParams[6]&&(a=Math.min(t,n-i._vf.typeParams[6])),i._vf.typeParams[7]&&(a=Math.max(a,n-i._vf.typeParams[7])),e._from=e._from.addScaled(r,a),e._flyMat=x3dom.fields.SFMatrix4f.lookAt(e._from,s,e._up),o.setViewAbsolute(e._flyMat.inverse())},x3dom.TurntableNavigation.prototype.calcOrbit=function(e,t,i,o){var s=this.navi;e._up=e._flyMat.e1(),e._from=e._flyMat.e3();var r,n,a=e._from.subtract(e._at);1==o?(r=i,n=t):(r=Math.atan2(a.x,a.z),n=Math.atan2(Math.sqrt(a.x*a.x+a.z*a.z),a.y),r-=i,n-=t),n=Math.max(s._vf.typeParams[2],Math.min(s._vf.typeParams[3],n)),s._vf.typeParams[4]<=s._vf.typeParams[5]?r=Math.max(s._vf.typeParams[4],Math.min(s._vf.typeParams[5],r)):i>0&&r<s._vf.typeParams[4]&&r>s._vf.typeParams[5]?r=s._vf.typeParams[4]:i<0&&r>s._vf.typeParams[5]&&r<s._vf.typeParams[4]&&(r=s._vf.typeParams[5]);var d=a.length(),l=d*Math.sin(n);a.x=l*Math.sin(r),a.y=d*Math.cos(n),a.z=l*Math.cos(r),a=e._at.add(a),n-=Math.PI/2;var h=Math.sin(n),f=Math.cos(n),u=new x3dom.fields.SFVec3f(h*Math.sin(r),f,h*Math.cos(r));return u.y<0&&(u=u.negate()),x3dom.fields.SFMatrix4f.lookAt(a,e._at,u)},x3dom.TurntableNavigation.prototype.initTurnTable=function(e,t){var i=this.navi;t=null==t||t;var o=e.getViewMatrix();e._rotMat=x3dom.fields.SFMatrix4f.identity(),e._transMat=x3dom.fields.SFMatrix4f.identity();var s=e._scene.getViewpoint(),r=x3dom.fields.SFVec3f.copy(s.getCenterOfRotation());e._flyMat=o.inverse(),e._from=s._vf.position,e._at=r,e._up=new x3dom.fields.SFVec3f(0,1,0),e._flyMat=x3dom.fields.SFMatrix4f.lookAt(e._from,e._at,e._up);var n=o.inverse().e3().subtract(e._at),a=Math.atan2(n.x,n.z),d=Math.atan2(Math.sqrt(n.x*n.x+n.z*n.z),n.y);e._flyMat=this.calcOrbit(e,d,a,!0);var l=0;t&&(l=.2/i._vf.speed,this.animateTo(e,e._flyMat.inverse(),o,l)),e.resetNavHelpers()},x3dom.TurntableNavigation.prototype.onMousePress=function(e,t,i,o){e._flyMat||this.initTurnTable(e,!1)},x3dom.TurntableNavigation.prototype.init=function(e,t){this.initTurnTable(e,!0)},x3dom.TurntableNavigation.prototype.resetView=function(e){e._mixer.beginTime=e._lastTS,e._mixer.endTime=e._lastTS+this.navi._vf.transitionTime,e._mixer.setBeginMatrix(e.getViewMatrix());var t=e._scene.getViewpoint();t.resetView(),t=x3dom.fields.SFMatrix4f.lookAt(t._vf.position,t.getCenterOfRotation(),new x3dom.fields.SFVec3f(0,1,0)),e._mixer.setEndMatrix(t.inverse()),this.updateFlyMat(e)},x3dom.TurntableNavigation.prototype.updateFlyMat=function(e,t,i){e._flyMat||this.initTurnTable(e,!1);var o=e.getViewMatrix(),s=t;null!=s&&x3dom.isa(s,x3dom.nodeTypes.X3DViewpointNode)||(s=e._scene.getViewpoint());var r=x3dom.fields.SFVec3f.copy(s.getCenterOfRotation());e._flyMat=o.inverse(),e._from=i?i.inverse().e3():s._vf.position,e._at=r,e._up=new x3dom.fields.SFVec3f(0,1,0),e._flyMat=x3dom.fields.SFMatrix4f.lookAt(e._from,e._at,e._up);var n=o.inverse().e3().subtract(e._at),a=Math.atan2(n.x,n.z),d=Math.atan2(Math.sqrt(n.x*n.x+n.z*n.z),n.y);e._flyMat=this.calcOrbit(e,d,a,!0)},x3dom.TurntableNavigation.prototype.animateTo=function(e,t,i,o){var s,r=this.navi;s=x3dom.isa(t,x3dom.nodeTypes.X3DViewpointNode)?x3dom.fields.SFMatrix4f.lookAt(t._vf.position,t.getCenterOfRotation(),new x3dom.fields.SFVec3f(0,1,0)):t,"teleport"!==r._vf.transitionType[0].toLowerCase()&&0!=o&&"game"!==r.getType()?i&&x3dom.isa(i,x3dom.nodeTypes.X3DViewpointNode)?(i=i.getViewMatrix().mult(i.getCurrentTransform().inverse()).mult(e._transMat).mult(e._rotMat),e._mixer.beginTime=e._lastTS,arguments.length>=4&&null!=arguments[3]?e._mixer.endTime=e._lastTS+o:e._mixer.endTime=e._lastTS+r._vf.transitionTime,e._mixer.setBeginMatrix(i),e._mixer.setEndMatrix(s),e._scene.getViewpoint().setViewAbsolute(i)):i?(e._mixer.beginTime=e._lastTS,arguments.length>=4&&null!=arguments[3]?e._mixer.endTime=e._lastTS+o:e._mixer.endTime=e._lastTS+r._vf.transitionTime,e._mixer.setBeginMatrix(i),e._mixer.setEndMatrix(s),e._scene.getViewpoint().setViewAbsolute(i)):e._scene.getViewpoint().setViewAbsolute(s):e._scene.getViewpoint().setViewAbsolute(t),e._rotMat=x3dom.fields.SFMatrix4f.identity(),e._transMat=x3dom.fields.SFMatrix4f.identity(),e._movement=new x3dom.fields.SFVec3f(0,0,0),e._needNavigationMatrixUpdate=!0,this.updateFlyMat(e,t,s)},x3dom.TurntableNavigation.prototype.onTouchStart=function(e,t,i){e._numTouches=t.touches.length,e._lastX=t.touches[0].screenX,e._lastY=t.touches[0].screenY},x3dom.TurntableNavigation.prototype.onTouchDrag=function(e,t,i,o,s){if(e._currentInputType==x3dom.InputTypes.NAVIGATION)if(1==t.touches.length){var r=t.touches[0].screenX-e._lastX,n=2*(t.touches[0].screenY-e._lastY)*Math.PI/e._height,a=2*r*Math.PI/e._width;this.rotate(e,n,a),e._lastX=t.touches[0].screenX,e._lastY=t.touches[0].screenY}else t.touches.length>=2&&(1==this.panEnabled&&this.pan(e,4*-o.x,4*-o.y),this.zoom(e,4*o.z))},x3dom.TurntableNavigation.prototype.onTouchEnd=function(e,t,i){2==e._numTouches&&1==t.touches.length&&(e._lastX=t.touches[0].screenX,e._lastY=t.touches[0].screenY),e._numTouches=t.touches.length},x3dom.TurntableNavigation.prototype.setPanTarget=function(e){this.target=e},x3dom.TurntableNavigation.prototype.setPanAxis=function(e,t){this.panAxisX=e,this.panAxisY=t},x3dom.TurntableNavigation.prototype.setPanEnabled=function(e){this.panEnabled=e},x3dom.TurntableNavigation.prototype.onDoubleClick=function(e,t,i){if((!e._doc._x3dElem.hasAttribute("disableDoubleClick")||"true"!==e._doc._x3dElem.getAttribute("disableDoubleClick"))&&"none"!=e._scene.getNavigationInfo().getType()){var o=e._scene._vf.pickMode.toLowerCase();if("color"!=o&&"texcoord"!=o){e._scene.getViewpoint().setCenterOfRotation(e._pick),x3dom.debug.logInfo("New center of Rotation:  "+e._pick);var s=e.getViewMatrix().inverse();e._from=s.e3(),e._up=s.e1(),e._at=e._pick,e._flyMat=x3dom.fields.SFMatrix4f.lookAt(e._from,e._at,e._up);var r=e._from.subtract(e._at),n=Math.atan2(r.x,r.z),a=Math.atan2(Math.sqrt(r.x*r.x+r.z*r.z),r.y);e._flyMat=this.calcOrbit(e,a,n,!0),x3dom.debug.logInfo("New camera position:  "+e._from),this.animateTo(e,e._flyMat.inverse(),e.getViewMatrix())}}},x3dom.WalkNavigation=function(e){x3dom.DefaultNavigation.call(this,e)},x3dom.WalkNavigation.prototype=Object.create(x3dom.DefaultNavigation.prototype),x3dom.WalkNavigation.prototype.constructor=x3dom.WalkNavigation,x3dom.WalkNavigation.prototype.onDrag=function(e,t,i,o){var s=this.navi,r=s.getType();if(0!==s.getExplorationMode()){e._scene.getViewpoint();var n=t-e._lastX,a=i-e._lastY;e._dx=n,e._dy=a,e._lastX=t,e._lastY=i,"walk"!==r&&console.log("#### CHECK: in WalkNavigation but nav. type is not walk !")}},x3dom.registerNodeType("X3DFontStyleNode","Text",defineClass(x3dom.nodeTypes.X3DNode,(function(e){x3dom.nodeTypes.X3DFontStyleNode.superClass.call(this,e)}))),x3dom.registerNodeType("FontStyle","Text",defineClass(x3dom.nodeTypes.X3DFontStyleNode,(function(e){x3dom.nodeTypes.FontStyle.superClass.call(this,e),this.addField_MFString(e,"family",["SERIF"]),this.addField_SFBool(e,"horizontal",!0),this.addField_MFString(e,"justify",["BEGIN","FIRST"]),this.addField_SFString(e,"language",""),this.addField_SFBool(e,"leftToRight",!0),this.addField_SFFloat(e,"size",1),this.addField_SFFloat(e,"spacing",1),this.addField_SFString(e,"style","PLAIN"),this.addField_SFBool(e,"topToBottom",!0),this.addField_SFFloat(e,"quality",2)}),{fieldChanged:function(e){"family"!=e&&"horizontal"!=e&&"justify"!=e&&"language"!=e&&"leftToRight"!=e&&"size"!=e&&"spacing"!=e&&"style"!=e&&"topToBottom"!=e||this._parentNodes.forEach((function(e){e._parentNodes.forEach((function(e){e.setAllDirty()}))}))}})),x3dom.nodeTypes.FontStyle.defaultNode=function(){return x3dom.nodeTypes.FontStyle._defaultNode||(x3dom.nodeTypes.FontStyle._defaultNode=new x3dom.nodeTypes.FontStyle,x3dom.nodeTypes.FontStyle._defaultNode.nodeChanged()),x3dom.nodeTypes.FontStyle._defaultNode},x3dom.registerNodeType("Text","Text",defineClass(x3dom.nodeTypes.X3DGeometryNode,(function(e){x3dom.nodeTypes.Text.superClass.call(this,e),this.addField_MFString(e,"string",[]),this.addField_MFFloat(e,"length",[]),this.addField_SFFloat(e,"maxExtent",0),this.addField_SFNode("fontStyle",x3dom.nodeTypes.X3DFontStyleNode),this._mesh._positions[0]=[0,0,0,1,0,0,1,1,0,0,1,0],this._mesh._normals[0]=[0,0,1,0,0,1,0,0,1,0,0,1],this._mesh._texCoords[0]=[0,0,1,0,1,1,0,1],this._mesh._colors[0]=[],this._mesh._indices[0]=[0,1,2,2,3,0],this._mesh._invalidate=!0,this._mesh._numFaces=2,this._mesh._numCoords=4}),{nodeChanged:function(){this._cf.fontStyle.node||this.addChild(x3dom.nodeTypes.FontStyle.defaultNode()),this.invalidateVolume()},fieldChanged:function(e){"string"!=e&&"length"!=e&&"maxExtent"!=e||(this.invalidateVolume(),this._parentNodes.forEach((function(e){e.setAllDirty()})))},validateGLObject:function(){this._parentNodes.forEach((function(e){e._dirty.texture=!1})),this._nameSpace.doc.needRender=!0}})),x3dom.registerNodeType("X3DSoundNode","Sound",defineClass(x3dom.nodeTypes.X3DChildNode,(function(e){x3dom.nodeTypes.X3DSoundNode.superClass.call(this,e)}))),x3dom.registerNodeType("Sound","Sound",defineClass(x3dom.nodeTypes.X3DSoundNode,(function(e){x3dom.nodeTypes.Sound.superClass.call(this,e),this.addField_SFNode("source",x3dom.nodeTypes.X3DSoundSourceNode)}),{nodeChanged:function(){if(!this._cf.source.node&&this._xmlNode){x3dom.debug.logInfo("No AudioClip child node given, searching for &lt;audio&gt; elements...");try{this._xmlNode.childNodes.forEach((function(e){if(1===e.nodeType&&(x3dom.debug.logInfo("### Found &lt;"+e.nodeName+"&gt; tag."),"audio"===e.localName.toLowerCase())){var t=e.getAttribute("loop");t=!!t&&"loop"===t.toLowerCase();var i=e.cloneNode(!1);e.parentNode.removeChild(e),e=null,"Microsoft Internet Explorer"!=navigator.appName&&document.body.appendChild(i);i.addEventListener("canplaythrough",(function(){i.play()}),!0),i.addEventListener("ended",(function(){t&&i.play()}),!0)}}))}catch(e){x3dom.debug.logException(e)}}}})),x3dom.registerNodeType("X3DSoundSourceNode","Sound",defineClass(x3dom.nodeTypes.X3DTimeDependentNode,(function(e){x3dom.nodeTypes.X3DSoundSourceNode.superClass.call(this,e)}))),x3dom.registerNodeType("AudioClip","Sound",defineClass(x3dom.nodeTypes.X3DSoundSourceNode,(function(e){x3dom.nodeTypes.AudioClip.superClass.call(this,e),this.addField_MFString(e,"url",[]),this.addField_SFBool(e,"enabled",!1),this.addField_SFBool(e,"loop",!1),this._audio=document.createElement("audio"),"Microsoft Internet Explorer"!=navigator.appName&&document.body.appendChild(this._audio),this._sources=[]}),{nodeChanged:function(){this._createSources=function(){this._sources=[];for(var e=0;e<this._vf.url.length;e++){var t=this._nameSpace.getURL(this._vf.url[e]);x3dom.debug.logInfo("Adding sound file: "+t);var i=document.createElement("source");i.setAttribute("src",t),this._sources.push(i),this._audio.appendChild(i)}};var e=this,t=0;this._startAudio=function(){e._audio.loop=e._vf.loop?"loop":"",!0===e._vf.enabled&&e._audio.play().then((function(e){clearTimeout(t)})).catch((function(i){x3dom.debug.logError(i),t=setTimeout(e._startAudio,100)}))},this._stopAudio=function(){e._audio.pause()},this._audioEnded=function(){!0===e._vf.enabled&&!0===e._vf.loop&&e._startAudio()};this._audio.addEventListener("canplaythrough",this._startAudio,!0),this._audio.addEventListener("ended",this._audioEnded,!0),this._audio.addEventListener("error",(function(e){x3dom.debug.logWarning("MediaEvent error:"+e)}),!0),this._audio.addEventListener("pause",this._audioEnded,!0),this._createSources()},fieldChanged:function(e){if("enabled"===e)!0===this._vf.enabled?this._startAudio():this._stopAudio();else if("loop"===e);else if("url"===e){for(this._stopAudio();this._audio.hasChildNodes();)this._audio.removeChild(this._audio.firstChild);for(var t=0;t<this._vf.url.length;t++){var i=this._nameSpace.getURL(this._vf.url[t]);x3dom.debug.logInfo("Adding sound file: "+i);var o=document.createElement("source");o.setAttribute("src",i),this._audio.appendChild(o)}}},shutdown:function(){if(this._audio){for(this._audio.pause();this._audio.hasChildNodes();)this._audio.removeChild(this._audio.firstChild);document.body.removeChild(this._audio),this._audio=null}}})),x3dom.registerNodeType("X3DTextureTransformNode","Texturing",defineClass(x3dom.nodeTypes.X3DAppearanceChildNode,(function(e){x3dom.nodeTypes.X3DTextureTransformNode.superClass.call(this,e)}),{texTransformMatrix:function(){return this._trafo}})),x3dom.registerNodeType("TextureTransform","Texturing",defineClass(x3dom.nodeTypes.X3DTextureTransformNode,(function(e){x3dom.nodeTypes.TextureTransform.superClass.call(this,e),this.addField_SFVec2f(e,"center",0,0),this.addField_SFFloat(e,"rotation",0),this.addField_SFVec2f(e,"scale",1,1),this.addField_SFVec2f(e,"translation",0,0),this._calcTrafo()}),{fieldChanged:function(e){"center"!=e&&"rotation"!=e&&"scale"!=e&&"translation"!=e||this._calcTrafo()},_calcTrafo:function(){var e=new x3dom.fields.SFVec3f(-this._vf.center.x,-this._vf.center.y,0),t=new x3dom.fields.SFVec3f(this._vf.center.x,this._vf.center.y,0),i=new x3dom.fields.SFVec3f(this._vf.translation.x,this._vf.translation.y,0),o=new x3dom.fields.SFVec3f(this._vf.scale.x,this._vf.scale.y,0);this._trafo=x3dom.fields.SFMatrix4f.translation(e).mult(x3dom.fields.SFMatrix4f.scale(o)).mult(x3dom.fields.SFMatrix4f.rotationZ(this._vf.rotation)).mult(x3dom.fields.SFMatrix4f.translation(t.add(i)))}})),x3dom.registerNodeType("MatrixTextureTransform","Texturing",defineClass(x3dom.nodeTypes.X3DTextureTransformNode,(function(e){x3dom.nodeTypes.MatrixTextureTransform.superClass.call(this,e),this.addField_SFMatrix4f(e,"matrix",1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this._trafo=this._vf.matrix.transpose()}),{fieldChanged:function(e){"matrix"==e&&(this._trafo=this._vf.matrix.transpose())}})),x3dom.registerNodeType("TextureProperties","Texturing",defineClass(x3dom.nodeTypes.X3DNode,(function(e){x3dom.nodeTypes.TextureProperties.superClass.call(this,e),this.addField_SFFloat(e,"anisotropicDegree",1),this.addField_SFColorRGBA(e,"borderColor",0,0,0,0),this.addField_SFInt32(e,"borderWidth",0),this.addField_SFString(e,"boundaryModeS","REPEAT"),this.addField_SFString(e,"boundaryModeT","REPEAT"),this.addField_SFString(e,"boundaryModeR","REPEAT"),this.addField_SFString(e,"magnificationFilter","FASTEST"),this.addField_SFString(e,"minificationFilter","FASTEST"),this.addField_SFString(e,"textureCompression","FASTEST"),this.addField_SFFloat(e,"texturePriority",0),this.addField_SFBool(e,"generateMipMaps",!1)}),{fieldChanged:function(e){this._vf.hasOwnProperty(e)&&(this._parentNodes.forEach((function(e){e._parentNodes.forEach((function(e){e._parentNodes.forEach((function(e){e._dirty.texture=!0}))}))})),this._nameSpace.doc.needRender=!0)}})),x3dom.registerNodeType("X3DTextureNode","Texturing",defineClass(x3dom.nodeTypes.X3DAppearanceChildNode,(function(e){x3dom.nodeTypes.X3DTextureNode.superClass.call(this,e),this.addField_SFInt32(e,"origChannelCount",0),this.addField_MFString(e,"url",[]),this.addField_SFBool(e,"repeatS",!0),this.addField_SFBool(e,"repeatT",!0),this.addField_SFBool(e,"scale",!0),this.addField_SFString(e,"crossOrigin",""),this.addField_SFNode("textureProperties",x3dom.nodeTypes.TextureProperties),this.addField_SFBool(e,"flipY",!1),this.addField_SFInt32(e,"channel",0),this._needPerFrameUpdate=!1,this._isCanvas=!1,this._type="diffuseMap",this._blending=1==this._vf.origChannelCount||2==this._vf.origChannelCount}),{invalidateGLObject:function(){this._parentNodes.forEach((function(e){e._parentNodes.forEach((function(e){x3dom.isa(e,x3dom.nodeTypes.X3DShapeNode)?e._dirty.texture=!0:e._parentNodes.forEach((function(e){x3dom.isa(e,x3dom.nodeTypes.X3DShapeNode)?e._dirty.texture=!0:e._parentNodes.forEach((function(e){x3dom.isa(e,x3dom.nodeTypes.X3DShapeNode)&&(e._dirty.texture=!0)}))}))}))})),this._nameSpace.doc.needRender=!0},validateGLObject:function(){this._parentNodes.forEach((function(e){e._parentNodes.forEach((function(e){x3dom.isa(e,x3dom.nodeTypes.X3DShapeNode)?e._dirty.texture=!1:e._parentNodes.forEach((function(e){x3dom.isa(e,x3dom.nodeTypes.X3DShapeNode)?e._dirty.texture=!1:e._parentNodes.forEach((function(e){x3dom.isa(e,x3dom.nodeTypes.X3DShapeNode)&&(e._dirty.texture=!1)}))}))}))})),this._nameSpace.doc.needRender=!0},parentAdded:function(e){e._parentNodes.forEach((function(e){x3dom.isa(e,x3dom.nodeTypes.Shape)?e._dirty.texture=!0:e._parentNodes.forEach((function(e){e._dirty.texture=!0}))}))},parentRemoved:function(e){e._parentNodes.forEach((function(e){x3dom.isa(e,x3dom.nodeTypes.X3DShapeNode)?e._dirty.texture=!0:e._parentNodes.forEach((function(e){e._dirty.texture=!0}))}))},fieldChanged:function(e){if("url"==e||"origChannelCount"==e||"repeatS"==e||"repeatT"==e||"scale"==e||"crossOrigin"==e||"image"==e){var t=this;t._blending=1==t._vf.origChannelCount||2==t._vf.origChannelCount,this._parentNodes.forEach((function(e){if(x3dom.isa(e,x3dom.nodeTypes.X3DAppearanceNode))e.nodeChanged();else if(x3dom.isa(e,x3dom.nodeTypes.MultiTexture))e._parentNodes.forEach((function(e){e.nodeChanged()}));else if(x3dom.isa(e,x3dom.nodeTypes.ComposedCubeMapTexture))e._parentNodes.forEach((function(e){e.nodeChanged()}));else if(x3dom.isa(e,x3dom.nodeTypes.PhysicalMaterial))e._parentNodes.forEach((function(e){e.nodeChanged()}));else if(void 0!==x3dom.nodeTypes.X3DVolumeDataNode)if(x3dom.isa(e,x3dom.nodeTypes.X3DVolumeRenderStyleNode)){if(t._xmlNode&&t._xmlNode.hasAttribute("containerField"))if(e._volumeDataParent)e._volumeDataParent._dirty.texture=!0;else{for(var i=e._parentNodes[0];!x3dom.isa(i,x3dom.nodeTypes.X3DVolumeDataNode)&&x3dom.isa(i,x3dom.nodeTypes.X3DNode);)i=i._parentNodes[0];x3dom.isa(i,x3dom.nodeTypes.X3DNode)&&(i._dirty.texture=!0)}}else x3dom.isa(e,x3dom.nodeTypes.X3DVolumeDataNode)&&t._xmlNode&&t._xmlNode.hasAttribute("containerField")&&(e._dirty.texture=!0)}))}},getTexture:function(e){return 0===e?this:null},size:function(){return 1},setOrigChannelCount:function(e){this._vf.origChannelCount=e,this.fieldChanged("origChannelCount")},getOrigChannelCount:function(){return this._vf.origChannelCount}})),x3dom.registerNodeType("MultiTexture","Texturing",defineClass(x3dom.nodeTypes.X3DTextureNode,(function(e){x3dom.nodeTypes.MultiTexture.superClass.call(this,e),this.addField_MFNode("texture",x3dom.nodeTypes.X3DTextureNode)}),{getTexture:function(e){return e>=0&&e<this._cf.texture.nodes.length?this._cf.texture.nodes[e]:null},getTextures:function(){return this._cf.texture.nodes},size:function(){return this._cf.texture.nodes.length}})),x3dom.registerNodeType("Texture","Texturing",defineClass(x3dom.nodeTypes.X3DTextureNode,(function(e){x3dom.nodeTypes.Texture.superClass.call(this,e),this.addField_SFBool(e,"hideChildren",!0),this._video=null,this._intervalID=0,this._canvas=null}),{nodeChanged:function(){if(!(this._vf.url.length&&this._vf.url[0].length||!this._xmlNode)){x3dom.debug.logInfo("No Texture URL given, searching for &lt;img&gt; elements...");var e=this;try{this._xmlNode.childNodes.forEach((function(t){if(1===t.nodeType){var i=t.getAttribute("src");if(i){if(e._vf.url.push(i),x3dom.debug.logInfo(e._vf.url[e._vf.url.length-1]),"video"===t.localName.toLowerCase())e._needPerFrameUpdate=!0,e._video=document.createElement("video"),e._video.setAttribute("preload","auto"),e._video.setAttribute("muted","muted"),document.getElementsByTagName("body")[0].appendChild(e._video),e._video.style.display="none",e._video.style.visibility="hidden"}else"canvas"===t.localName.toLowerCase()&&(e._needPerFrameUpdate=!0,e._isCanvas=!0,e._canvas=t);t.style&&e._vf.hideChildren&&(t.style.display="none",t.style.visibility="hidden"),x3dom.debug.logInfo("### Found &lt;"+t.nodeName+"&gt; tag.")}}))}catch(e){x3dom.debug.logException(e)}}},shutdown:function(){if(this._video){for(this._video.pause();this._video.hasChildNodes();)this._video.removeChild(this._video.firstChild);document.body.removeChild(this._video),this._video=null}}})),x3dom.registerNodeType("RenderedTexture","Texturing",defineClass(x3dom.nodeTypes.X3DTextureNode,(function(e){x3dom.nodeTypes.RenderedTexture.superClass.call(this,e),e?e.doc._nodeBag.renderTextures.push(this):x3dom.debug.logWarning("RenderedTexture: No runtime context found!"),this.addField_SFNode("viewpoint",x3dom.nodeTypes.X3DViewpointNode),this.addField_SFNode("background",x3dom.nodeTypes.X3DBackgroundNode),this.addField_SFNode("fog",x3dom.nodeTypes.X3DFogNode),this.addField_SFNode("scene",x3dom.nodeTypes.X3DNode),this.addField_MFNode("excludeNodes",x3dom.nodeTypes.X3DNode),this.addField_MFInt32(e,"dimensions",[128,128,4]),this.addField_SFString(e,"update","NONE"),this.addField_SFBool(e,"showNormals",!1),this.addField_SFString(e,"stereoMode","NONE"),this.addField_SFFloat(e,"interpupillaryDistance",.064),this.addField_SFFloat(e,"eyeToScreenDistance",.041),this.addField_SFFloat(e,"vScreenSize",.07074),this.addField_SFVec3f(e,"lensCenter",.15197,0,0),this.addField_SFBool(e,"depthMap",!1),this.addField_SFBool(e,"oculusRiftVersion",1),x3dom.debug.assert(this._vf.dimensions.length>=3,"RenderedTexture.dimensions requires at least 3 entries."),this._clearParents=!0,this._needRenderUpdate=!0,this.checkDepthTextureSupport=function(){this._vf.depthMap&&null===x3dom.caps.DEPTH_TEXTURE&&x3dom.debug.logWarning("RenderedTexture Node: depth texture extension not supported")},this.checkDepthTextureSupport()}),{nodeChanged:function(){this._clearParents=!0,this._needRenderUpdate=!0},fieldChanged:function(e){switch(e){case"excludeNodes":this._clearParents=!0;break;case"update":"NEXT_FRAME_ONLY"!=this._vf.update.toUpperCase()&&"ALWAYS"!=this._vf.update.toUpperCase()||(this._needRenderUpdate=!0);break;case"depthMap":this.checkDepthTextureSupport(),this._x3domTexture.updateTexture(),this._needRenderUpdate=!0}},getViewMatrix:function(){if(this._clearParents&&this._cf.excludeNodes.nodes.length){var e=this;this._cf.excludeNodes.nodes.forEach((function(t){for(var i=0,o=t._parentNodes.length;i<o;i++)t._parentNodes[i]===e&&(t._parentNodes.splice(i,1),t.parentRemoved(e))})),this._clearParents=!1}var t=this._cf.scene.node,i=this._nameSpace.doc._scene,o=i.getViewpoint(),s=this._cf.viewpoint.node,r=null;if(null===s||s===o)r=this._nameSpace.doc._viewarea.getViewMatrix();else if(t&&t!==i)r=s.getViewMatrix();else{var n=s.getCurrentTransform();r=s.getViewMatrix().mult(n.inverse())}var a=this._vf.stereoMode.toUpperCase();if("NONE"!=a){var d=this._vf.interpupillaryDistance/2;"RIGHT_EYE"==a&&(d=-d),r=new x3dom.fields.SFMatrix4f(1,0,0,d,0,1,0,0,0,0,1,0,0,0,0,1).mult(r)}return r},getProjectionMatrix:function(){var e,t=this._nameSpace.doc,i=t._scene.getViewpoint(),o=this._cf.viewpoint.node,s=null,r=this._vf.dimensions[0],n=this._vf.dimensions[1],a=this._vf.stereoMode.toUpperCase(),d="NONE"!=a;if(null===o||o===i?(s=x3dom.fields.SFMatrix4f.copy(t._viewarea.getProjectionMatrix()),d?(e=2*Math.atan(this._vf.vScreenSize/(2*this._vf.eyeToScreenDistance)),e=1/Math.tan(e/2)):e=1/Math.tan(i._vf.fieldOfView/2),s._00=e/(r/n),s._11=e):s=o.getProjectionMatrix(r/n),d){var l=this._vf.lensCenter.copy();"RIGHT_EYE"==a&&(l.x=-l.x),s=new x3dom.fields.SFMatrix4f(1,0,0,l.x,0,1,0,l.y,0,0,1,l.z,0,0,0,1).mult(s)}return s},getWCtoCCMatrix:function(){var e=this.getViewMatrix();return this.getProjectionMatrix().mult(e)},parentRemoved:function(e){if(0===this._parentNodes.length)for(var t=this.findX3DDoc(),i=0,o=t._nodeBag.renderTextures.length;i<o;i++)t._nodeBag.renderTextures[i]===this&&t._nodeBag.renderTextures.splice(i,1);this._cf.scene.node&&this._cf.scene.node.parentRemoved(this)},requirePingPong:function(){return!1}})),x3dom.registerNodeType("RefinementTexture","Texturing",defineClass(x3dom.nodeTypes.RenderedTexture,(function(e){if(x3dom.nodeTypes.RefinementTexture.superClass.call(this,e),this.addField_SFString(e,"stamp0","gpuii/stamps/0.gif"),this.addField_SFString(e,"stamp1","gpuii/stamps/1.gif"),this.addField_SFBool(e,"autoRefinement",!0),this.addField_SFString(e,"format","jpg"),this.addField_SFInt32(e,"iterations",7),this.addField_SFInt32(e,"maxLevel",this._vf.iterations),this._vf.iterations%2==0){var t=this._vf.stamp0;this._vf.stamp0=this._vf.stamp1,this._vf.stamp1=t}this._vf.iterations=this._vf.iterations>11?11:this._vf.iterations,this._vf.iterations=this._vf.iterations<3?3:this._vf.iterations,this._vf.maxLevel=this._vf.maxLevel>11?11:this._vf.maxLevel,this._vf.maxLevel=this._vf.maxLevel<3?3:this._vf.maxLevel,this._vf.maxLevel=this._vf.maxLevel>this._vf.iterations?this._vf.iterations:this._vf.maxLevel;var i=[{x:4,y:8},{x:8,y:8},{x:8,y:16},{x:16,y:16},{x:16,y:32},{x:32,y:32},{x:32,y:64},{x:64,y:64},{x:64,y:128}];this._repeat=new x3dom.fields.SFVec2f(this._vf.dimensions[0]/i[this._vf.iterations-3].x,this._vf.dimensions[1]/i[this._vf.iterations-3].y),this._renderedImage=0,this._currLoadLevel=0,this._loadLevel=1}),{nextLevel:function(){this._loadLevel<this._vf.maxLevel&&(this._loadLevel++,this._nameSpace.doc.needRender=!0)},requirePingPong:function(){return this._currLoadLevel<=this._vf.maxLevel&&this._renderedImage<this._loadLevel}})),x3dom.registerNodeType("PixelTexture","Texturing",defineClass(x3dom.nodeTypes.X3DTextureNode,(function(e){x3dom.nodeTypes.PixelTexture.superClass.call(this,e),this.addField_SFImage(e,"image",0,0,0)}),{getWidth:function(){return this._vf.image.width},getHeight:function(){return this._vf.image.height},getComponents:function(){return this._vf.image.comp},setPixel:function(e,t,i,o){o=null==o||o,this._x3domTexture?(this._x3domTexture.setPixel(e,t,[255*i.r,255*i.g,255*i.b,255*i.a],o),this._vf.image.setPixel(e,t,i)):(this._vf.image.setPixel(e,t,i),o&&this.invalidateGLObject())},getPixel:function(e,t){return this._vf.image.getPixel(e,t)},setPixels:function(e,t){t=null==t||t,this._vf.image.setPixels(e),t&&this.invalidateGLObject()},getPixels:function(){return this._vf.image.getPixels()}})),x3dom.registerNodeType("ImageTexture","Texturing",defineClass(x3dom.nodeTypes.Texture,(function(e){x3dom.nodeTypes.ImageTexture.superClass.call(this,e)}))),x3dom.registerNodeType("MovieTexture","Texturing",defineClass(x3dom.nodeTypes.Texture,(function(e){x3dom.nodeTypes.MovieTexture.superClass.call(this,e),this.addField_SFBool(e,"loop",!1),this.addField_SFFloat(e,"speed",1),this.addField_SFTime(e,"pauseTime",0),this.addField_SFFloat(e,"pitch",1),this.addField_SFTime(e,"resumeTime",0),this.addField_SFTime(e,"startTime",0),this.addField_SFTime(e,"stopTime",0)}))),x3dom.registerNodeType("X3DTextureCoordinateNode","Texturing",defineClass(x3dom.nodeTypes.X3DGeometricPropertyNode,(function(e){x3dom.nodeTypes.X3DTextureCoordinateNode.superClass.call(this,e)}),{fieldChanged:function(e){"texCoord"!==e&&"point"!==e&&"parameter"!==e&&"mode"!==e||this._parentNodes.forEach((function(e){e.fieldChanged("texCoord")}))},parentAdded:function(e){e._mesh&&e._cf.texCoord.node!==this&&e.fieldChanged("texCoord")}})),x3dom.registerNodeType("TextureCoordinate","Texturing",defineClass(x3dom.nodeTypes.X3DTextureCoordinateNode,(function(e){x3dom.nodeTypes.TextureCoordinate.superClass.call(this,e),this.addField_MFVec2f(e,"point",[])}))),x3dom.registerNodeType("TextureCoordinateGenerator","Texturing",defineClass(x3dom.nodeTypes.X3DTextureCoordinateNode,(function(e){x3dom.nodeTypes.TextureCoordinateGenerator.superClass.call(this,e),this.addField_SFString(e,"mode","SPHERE"),this.addField_MFFloat(e,"parameter",[])}))),x3dom.registerNodeType("MultiTextureCoordinate","Texturing",defineClass(x3dom.nodeTypes.X3DTextureCoordinateNode,(function(e){x3dom.nodeTypes.MultiTextureCoordinate.superClass.call(this,e),this.addField_MFNode("texCoord",x3dom.nodeTypes.X3DTextureCoordinateNode)}))),x3dom.registerNodeType("ImageTextureAtlas","Texturing",defineClass(x3dom.nodeTypes.Texture,(function(e){x3dom.nodeTypes.ImageTextureAtlas.superClass.call(this,e),this.addField_SFInt32(e,"numberOfSlices",0),this.addField_SFInt32(e,"slicesOverX",0),this.addField_SFInt32(e,"slicesOverY",0)}))),x3dom.registerNodeType("X3DEnvironmentTextureNode","CubeMapTexturing",defineClass(x3dom.nodeTypes.X3DTextureNode,(function(e){x3dom.nodeTypes.X3DEnvironmentTextureNode.superClass.call(this,e)}),{getTexUrl:function(){return[]},getTexSize:function(){return-1}})),x3dom.registerNodeType("ComposedCubeMapTexture","CubeMapTexturing",defineClass(x3dom.nodeTypes.X3DEnvironmentTextureNode,(function(e){x3dom.nodeTypes.ComposedCubeMapTexture.superClass.call(this,e),this.addField_SFNode("back",x3dom.nodeTypes.Texture),this.addField_SFNode("front",x3dom.nodeTypes.Texture),this.addField_SFNode("bottom",x3dom.nodeTypes.Texture),this.addField_SFNode("top",x3dom.nodeTypes.Texture),this.addField_SFNode("left",x3dom.nodeTypes.Texture),this.addField_SFNode("right",x3dom.nodeTypes.Texture),this._type="environmentMap"}),{getTexUrl:function(){return[this._nameSpace.getURL(this._cf.back.node._vf.url[0]),this._nameSpace.getURL(this._cf.front.node._vf.url[0]),this._nameSpace.getURL(this._cf.bottom.node._vf.url[0]),this._nameSpace.getURL(this._cf.top.node._vf.url[0]),this._nameSpace.getURL(this._cf.left.node._vf.url[0]),this._nameSpace.getURL(this._cf.right.node._vf.url[0])]}})),x3dom.registerNodeType("GeneratedCubeMapTexture","CubeMapTexturing",defineClass(x3dom.nodeTypes.X3DEnvironmentTextureNode,(function(e){x3dom.nodeTypes.GeneratedCubeMapTexture.superClass.call(this,e),this.addField_SFInt32(e,"size",128),this.addField_SFString(e,"update","NONE"),this._type="cubeMap",x3dom.debug.logWarning("GeneratedCubeMapTexture NYI")}),{getTexSize:function(){return this._vf.size}})),x3dom.registerNodeType("Uniform","Shaders",defineClass(x3dom.nodeTypes.Field,(function(e){x3dom.nodeTypes.Uniform.superClass.call(this,e)}))),x3dom.registerNodeType("SurfaceShaderTexture","Shaders",defineClass(x3dom.nodeTypes.X3DTextureNode,(function(e){x3dom.nodeTypes.SurfaceShaderTexture.superClass.call(this,e),this.addField_SFInt32(e,"textureCoordinatesId",0),this.addField_SFString(e,"channelMask","DEFAULT"),this.addField_SFBool(e,"isSRGB",!1),this.addField_SFNode("texture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("textureTransform",x3dom.nodeTypes.X3DTextureTransformNode)}))),x3dom.registerNodeType("X3DShaderNode","Shaders",defineClass(x3dom.nodeTypes.X3DAppearanceChildNode,(function(e){x3dom.nodeTypes.X3DShaderNode.superClass.call(this,e),this.addField_SFString(e,"language","")}))),x3dom.registerNodeType("CommonSurfaceShader","Shaders",defineClass(x3dom.nodeTypes.X3DShaderNode,(function(e){x3dom.nodeTypes.CommonSurfaceShader.superClass.call(this,e),this.addField_SFInt32(e,"tangentTextureCoordinatesId",-1),this.addField_SFInt32(e,"binormalTextureCoordinatesId",-1),this.addField_SFVec3f(e,"emissiveFactor",0,0,0),this.addField_SFInt32(e,"emissiveTextureId",-1),this.addField_SFInt32(e,"emissiveTextureCoordinatesId",0),this.addField_SFString(e,"emissiveTextureChannelMask","rgb"),this.addField_SFVec3f(e,"ambientFactor",.2,.2,.2),this.addField_SFInt32(e,"ambientTextureId",-1),this.addField_SFInt32(e,"ambientTextureCoordinatesId",0),this.addField_SFString(e,"ambientTextureChannelMask","rgb"),this.addField_SFVec3f(e,"diffuseFactor",.8,.8,.8),this.addField_SFInt32(e,"diffuseTextureId",-1),this.addField_SFInt32(e,"diffuseTextureCoordinatesId",0),this.addField_SFString(e,"diffuseTextureChannelMask","rgb"),this.addField_SFVec3f(e,"specularFactor",0,0,0),this.addField_SFInt32(e,"specularTextureId",-1),this.addField_SFInt32(e,"specularTextureCoordinatesId",0),this.addField_SFString(e,"specularTextureChannelMask","rgb"),this.addField_SFFloat(e,"shininessFactor",.2),this.addField_SFInt32(e,"shininessTextureId",-1),this.addField_SFInt32(e,"shininessTextureCoordinatesId",0),this.addField_SFString(e,"shininessTextureChannelMask","a"),this.addField_SFString(e,"normalFormat","UNORM"),this.addField_SFString(e,"normalSpace","TANGENT"),this.addField_SFInt32(e,"normalTextureId",-1),this.addField_SFInt32(e,"normalTextureCoordinatesId",0),this.addField_SFString(e,"normalTextureChannelMask","rgb"),this.addField_SFVec3f(e,"reflectionFactor",0,0,0),this.addField_SFInt32(e,"reflectionTextureId",-1),this.addField_SFInt32(e,"reflectionTextureCoordinatesId",0),this.addField_SFString(e,"reflectionTextureChannelMask","rgb"),this.addField_SFVec3f(e,"transmissionFactor",0,0,0),this.addField_SFInt32(e,"transmissionTextureId",-1),this.addField_SFInt32(e,"transmissionTextureCoordinatesId",0),this.addField_SFString(e,"transmissionTextureChannelMask","rgb"),this.addField_SFVec3f(e,"environmentFactor",1,1,1),this.addField_SFInt32(e,"environmentTextureId",-1),this.addField_SFInt32(e,"environmentTextureCoordinatesId",0),this.addField_SFString(e,"environmentTextureChannelMask","rgb"),this.addField_SFFloat(e,"relativeIndexOfRefraction",1),this.addField_SFFloat(e,"fresnelBlend",0),this.addField_SFString(e,"displacementAxis","y"),this.addField_SFFloat(e,"displacementFactor",255),this.addField_SFInt32(e,"displacementTextureId",-1),this.addField_SFInt32(e,"displacementTextureCoordinatesId",0),this.addField_SFNode("emissiveTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("ambientTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("diffuseTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("specularTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("shininessTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("normalTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("reflectionTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("transmissionTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("environmentTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("displacementTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFNode("diffuseDisplacementTexture",x3dom.nodeTypes.X3DTextureNode),this.addField_SFVec3f(e,"normalScale",2,2,2),this.addField_SFVec3f(e,"normalBias",-1,-1,1),this.addField_SFFloat(e,"alphaFactor",1),this.addField_SFBool(e,"invertAlphaTexture",!1),this.addField_SFInt32(e,"alphaTextureId",-1),this.addField_SFInt32(e,"alphaTextureCoordinatesId",0),this.addField_SFString(e,"alphaTextureChannelMask","a"),this.addField_SFNode("alphaTexture",x3dom.nodeTypes.X3DTextureNode),this._dirty={}}),{getDiffuseMap:function(){return this._cf.diffuseTexture.node?x3dom.isa(this._cf.diffuseTexture.node,x3dom.nodeTypes.SurfaceShaderTexture)?(this._cf.diffuseTexture.node._cf.texture.node._type="diffuseMap",this._cf.diffuseTexture.node._cf.texture.node):(this._cf.diffuseTexture.node._type="diffuseMap",this._cf.diffuseTexture.node):null},getEnvironmentMap:function(){return this._cf.environmentTexture.node?x3dom.isa(this._cf.environmentTexture.node,x3dom.nodeTypes.SurfaceShaderTexture)?(this._cf.environmentTexture.node._cf.texture.node._type="environmentMap",this._cf.environmentTexture.node._cf.texture.node):(this._cf.environmentTexture.node._type="environmentMap",this._cf.environmentTexture.node):null},getNormalMap:function(){return this._cf.normalTexture.node?x3dom.isa(this._cf.normalTexture.node,x3dom.nodeTypes.SurfaceShaderTexture)?(this._cf.normalTexture.node._cf.texture.node._type="normalMap",this._cf.normalTexture.node._cf.texture.node):(this._cf.normalTexture.node._type="normalMap",this._cf.normalTexture.node):null},getAmbientMap:function(){return this._cf.ambientTexture.node?x3dom.isa(this._cf.ambientTexture.node,x3dom.nodeTypes.SurfaceShaderTexture)?(this._cf.ambientTexture.node._cf.texture.node._type="ambientMap",this._cf.ambientTexture.node._cf.texture.node):(this._cf.ambientTexture.node._type="ambientMap",this._cf.ambientTexture.node):null},getSpecularMap:function(){return this._cf.specularTexture.node?x3dom.isa(this._cf.specularTexture.node,x3dom.nodeTypes.SurfaceShaderTexture)?(this._cf.specularTexture.node._cf.texture.node._type="specularMap",this._cf.specularTexture.node._cf.texture.node):(this._cf.specularTexture.node._type="specularMap",this._cf.specularTexture.node):null},getShininessMap:function(){return this._cf.shininessTexture.node?x3dom.isa(this._cf.shininessTexture.node,x3dom.nodeTypes.SurfaceShaderTexture)?(this._cf.shininessTexture.node._cf.texture.node._type="shininessMap",this._cf.shininessTexture.node._cf.texture.node):(this._cf.shininessTexture.node._type="shininessMap",this._cf.shininessTexture.node):null},getAlphaMap:function(){return this._cf.alphaTexture.node?x3dom.isa(this._cf.alphaTexture.node,x3dom.nodeTypes.SurfaceShaderTexture)?(this._cf.alphaTexture.node._cf.texture.node._type="alphaMap",this._cf.alphaTexture.node._cf.texture.node):(this._cf.alphaTexture.node._type="alphaMap",this._cf.alphaTexture.node):null},getDisplacementMap:function(){return this._cf.displacementTexture.node?x3dom.isa(this._cf.displacementTexture.node,x3dom.nodeTypes.SurfaceShaderTexture)?(this._cf.displacementTexture.node._cf.texture.node._type="displacementMap",this._cf.displacementTexture.node._cf.texture.node):(this._cf.displacementTexture.node._type="displacementMap",this._cf.displacementTexture.node):null},getDiffuseDisplacementMap:function(){return this._cf.diffuseDisplacementTexture.node?x3dom.isa(this._cf.diffuseDisplacementTexture.node,x3dom.nodeTypes.SurfaceShaderTexture)?(this._cf.diffuseDisplacementTexture.node._cf.texture.node._type="diffuseDisplacementMap",this._cf.diffuseDisplacementTexture.node._cf.texture.node):(this._cf.diffuseDisplacementTexture.node._type="diffuseDisplacementMap",this._cf.diffuseDisplacementTexture.node):null},getTextures:function(){var e=[],t=this.getDiffuseMap();t&&e.push(t);var i=this.getNormalMap();i&&e.push(i);var o=this.getSpecularMap();o&&e.push(o);var s=this.getShininessMap();s&&e.push(s);var r=this.getEnvironmentMap();r&&e.push(r);var n=this.getDisplacementMap();n&&e.push(n);var a=this.getDiffuseDisplacementMap();return a&&e.push(a),e},needTexcoords:function(){return!!(this.getDiffuseMap()||this.getNormalMap()||this.getSpecularMap()||this.getShininessMap()||this.getDisplacementMap()||this.getDiffuseDisplacementMap()||this.getEnvironmentMap())}})),x3dom.registerNodeType("ComposedShader","Shaders",defineClass(x3dom.nodeTypes.X3DShaderNode,(function(e){x3dom.nodeTypes.ComposedShader.superClass.call(this,e),this.addField_MFNode("fields",x3dom.nodeTypes.Field),this.addField_MFNode("parts",x3dom.nodeTypes.ShaderPart),this._vertex=null,this._fragment=null,this._id=null,x3dom.nodeTypes.ComposedShader.ShaderInfoMsgShown||(x3dom.debug.logInfo("Current ComposedShader node implementation limitations:\nVertex attributes (if given in the standard X3D fields 'coord', 'color', 'normal', 'texCoord'), matrices and texture are provided as follows...\n(see also <a href='http://x3dom.org/x3dom/doc/help/composedShader.html'>http://x3dom.org/x3dom/doc/help/composedShader.html</a>)\n    attribute vec3 position;\n    attribute vec3 normal;\n    attribute vec2 texcoord;\n    attribute vec3 color;\n    uniform mat4 modelViewProjectionMatrix;\n    uniform mat4 modelViewMatrix;\n    uniform mat4 normalMatrix;\n    uniform mat4 viewMatrix;\n    uniform sampler2D tex;\n"),x3dom.nodeTypes.ComposedShader.ShaderInfoMsgShown=!0)}),{nodeChanged:function(){var e,t=this._cf.parts.nodes.length;for(e=0;e<t;e++)"vertex"==this._cf.parts.nodes[e]._vf.type.toLowerCase()?(this._vertex=this._cf.parts.nodes[e],this._id=this._cf.parts.nodes[e]._id):"fragment"==this._cf.parts.nodes[e]._vf.type.toLowerCase()&&(this._fragment=this._cf.parts.nodes[e],this._id+=" - "+this._cf.parts.nodes[e]._id);var i={};for(t=this._cf.fields.nodes.length,e=0;e<t;e++){var o=this._cf.fields.nodes[e]._vf.name;i.xmlNode=this._cf.fields.nodes[e]._xmlNode;var s=!1;void 0!==i.xmlNode&&null!==i.xmlNode||(i.xmlNode=document.createElement("field"),s=!0),i.xmlNode.setAttribute(o,this._cf.fields.nodes[e]._vf.value);var r="this.addField_"+this._cf.fields.nodes[e]._vf.type+"(ctx, name);";new Function("ctx","name",r).call(this,i,o),s&&(i.xmlNode=null)}this._parentNodes.forEach((function(e){e._parentNodes.forEach((function(e){e._cleanupGLObjects&&e._cleanupGLObjects(),e.setAllDirty()}))}))},fieldChanged:function(e){var t,i=this._cf.fields.nodes.length;for(t=0;t<i;t++){var o=this._cf.fields.nodes[t]._vf.name;if(o===e){var s=this._cf.fields.nodes[t]._vf.value;try{this._vf[o].setValueByStr(s)}catch(e){try{switch((typeof this._vf[o]).toString()){case"number":this._vf[o]=+s;break;case"boolean":this._vf[o]="true"===s.toLowerCase();break;case"string":this._vf[o]=s}}catch(e){x3dom.debug.logError("setValueByStr() NYI for "+typeof this._vf[o])}}break}}if("url"===e){for(t=0;t<i;t++)"vertex"==this._cf.parts.nodes[t]._vf.type.toLowerCase()?(this._vertex=this._cf.parts.nodes[t],this._id=this._cf.parts.nodes[t]._id):"fragment"==this._cf.parts.nodes[t]._vf.type.toLowerCase()&&(this._fragment=this._cf.parts.nodes[t],this._id+=" - "+this._cf.parts.nodes[t]._id);this._parentNodes.forEach((function(e){e._parentNodes.forEach((function(e){e._cleanupGLObjects&&e._cleanupGLObjects(),e.setAllDirty()}))}))}},parentAdded:function(e){e.nodeChanged()}})),x3dom.nodeTypes.ComposedShader.ShaderInfoMsgShown=!1,x3dom.registerNodeType("ShaderPart","Shaders",defineClass(x3dom.nodeTypes.X3DNode,(function(e){x3dom.nodeTypes.ShaderPart.superClass.call(this,e),this.addField_MFString(e,"url",[]),this.addField_SFString(e,"type","VERTEX"),this._id=e&&e.xmlNode&&""!=e.xmlNode.id?e.xmlNode.id:++x3dom.nodeTypes.Shape.shaderPartID,x3dom.debug.assert("vertex"==this._vf.type.toLowerCase()||"fragment"==this._vf.type.toLowerCase(),"Unknown shader part type!")}),{nodeChanged:function(){var e={};if(e.xmlNode=this._xmlNode,void 0!==e.xmlNode&&null!==e.xmlNode){var t=this;if(t._vf.url.length&&-1==t._vf.url[0].indexOf("\n")){var i=new XMLHttpRequest,o=t._nameSpace.getURL(t._vf.url[0]),s=t._id;t._id="default",t._vf.url=new x3dom.fields.MFString([this._getDefaultShader()]),i.open("GET",o,!1),i.onload=function(){t._vf.url=new x3dom.fields.MFString([]),t._vf.url.push(i.response),t._id=s,t.fieldChanged("url")},i.onerror=function(){x3dom.debug.logError("Could not load file '"+t._vf.url[0]+"'.")},x3dom.RequestManager.addRequest(i)}else{t._vf.url.length&&(t._vf.url=new x3dom.fields.MFString([]));try{t._vf.url.push(e.xmlNode.childNodes[1].nodeValue),e.xmlNode.removeChild(e.xmlNode.childNodes[1])}catch(i){e.xmlNode.childNodes.forEach((function(e){3===e.nodeType?t._vf.url.push(e.nodeValue):4===e.nodeType&&t._vf.url.push(e.data),e.parentNode.removeChild(e)}))}}}this._parentNodes.forEach((function(e){e.nodeChanged()}))},fieldChanged:function(e){"url"===e&&this._parentNodes.forEach((function(e){e.fieldChanged("url")}))},parentAdded:function(e){e.nodeChanged()},_getDefaultShader:function(){return"vertex"==this._vf.type.toLowerCase()?"attribute vec3 position;\nuniform mat4 modelViewProjectionMatrix;\nvoid main(void) {\n    gl_Position = modelViewProjectionMatrix * vec4(position, 1.0);\n}\n":"fragment"==this._vf.type.toLowerCase()?"precision highp float;\nvoid main(void) {\n    gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n}\n":void 0}})),x3dom.registerNodeType("X3DVertexAttributeNode","Shaders",defineClass(x3dom.nodeTypes.X3DGeometricPropertyNode,(function(e){x3dom.nodeTypes.X3DVertexAttributeNode.superClass.call(this,e),this.addField_SFString(e,"name","")}))),x3dom.registerNodeType("FloatVertexAttribute","Shaders",defineClass(x3dom.nodeTypes.X3DVertexAttributeNode,(function(e){x3dom.nodeTypes.FloatVertexAttribute.superClass.call(this,e),this.addField_SFInt32(e,"numComponents",4),this.addField_MFFloat(e,"value",[])}))),x3dom.registerNodeType("X3DSpatialGeometryNode","Geometry3D",defineClass(x3dom.nodeTypes.X3DGeometryNode,(function(e){x3dom.nodeTypes.X3DSpatialGeometryNode.superClass.call(this,e)}))),x3dom.registerNodeType("Plane","Geometry3D",defineClass(x3dom.nodeTypes.X3DSpatialGeometryNode,(function(e){x3dom.nodeTypes.Plane.superClass.call(this,e),this.addField_SFVec2f(e,"size",2,2),this.addField_SFVec2f(e,"subdivision",1,1),this.addField_SFVec3f(e,"center",0,0,0),this.addField_MFString(e,"primType",["TRIANGLES"]),this._vf.primType.length&&(this._mesh._primType=this._vf.primType[0]);var t=this._vf.size.x,i=this._vf.size.y,o=this._vf.subdivision.x,s=this._vf.subdivision.y,r=this._vf.ccw,n=["Plane",t,i,o,s,this._vf.center.x,this._vf.center.y,this._vf.center.z,r].join("-");if(e&&this._vf.useGeoCache&&void 0!==x3dom.geoCache[n])this._mesh=x3dom.geoCache[n];else{var a=0,d=0,l=t/o,h=i/s,f=r?1:-1;for(t/=2,i/=2,d=0;d<=s;d++)for(a=0;a<=o;a++)this._mesh._positions[0].push(this._vf.center.x+a*l-t),this._mesh._positions[0].push(this._vf.center.y+d*h-i),this._mesh._positions[0].push(this._vf.center.z),this._mesh._normals[0].push(0),this._mesh._normals[0].push(0),this._mesh._normals[0].push(1*f),this._mesh._texCoords[0].push(a/o),this._mesh._texCoords[0].push(d/s);for(d=1;d<=s;d++)for(a=0;a<o;a++)this._mesh._indices[0].push((d-1)*(o+1)+a),this._mesh._indices[0].push((d-1)*(o+1)+a+1),this._mesh._indices[0].push(d*(o+1)+a),this._mesh._indices[0].push(d*(o+1)+a),this._mesh._indices[0].push((d-1)*(o+1)+a+1),this._mesh._indices[0].push(d*(o+1)+a+1);this._mesh._invalidate=!0,this._mesh._numFaces=this._mesh._indices[0].length/3,this._mesh._numCoords=this._mesh._positions[0].length/3,x3dom.geoCache[n]=this._mesh}}),{fieldChanged:function(e){if("size"==e||"center"==e){this._mesh._positions[0]=[];var t=this._vf.size.x,i=this._vf.size.y,o=0,s=0,r=t/(a=this._vf.subdivision.x),n=i/(d=this._vf.subdivision.y);for(t/=2,i/=2,s=0;s<=d;s++)for(o=0;o<=a;o++)this._mesh._positions[0].push(this._vf.center.x+o*r-t),this._mesh._positions[0].push(this._vf.center.y+s*n-i),this._mesh._positions[0].push(this._vf.center.z);this.invalidateVolume(),this._mesh._numCoords=this._mesh._positions[0].length/3,this._parentNodes.forEach((function(e){e._dirty.positions=!0,e.invalidateVolume()}))}else if("subdivision"==e){this._mesh._positions[0]=[],this._mesh._indices[0]=[],this._mesh._normals[0]=[],this._mesh._texCoords[0]=[];var a,d;t=this._vf.size.x,i=this._vf.size.y,o=0,s=0,r=t/(a=this._vf.subdivision.x),n=i/(d=this._vf.subdivision.y);for(t/=2,i/=2,s=0;s<=d;s++)for(o=0;o<=a;o++)this._mesh._positions[0].push(this._vf.center.x+o*r-t),this._mesh._positions[0].push(this._vf.center.y+s*n-i),this._mesh._positions[0].push(this._vf.center.z),this._mesh._normals[0].push(0),this._mesh._normals[0].push(0),this._mesh._normals[0].push(1*nSign),this._mesh._texCoords[0].push(o/a),this._mesh._texCoords[0].push(s/d);for(s=1;s<=d;s++)for(o=0;o<a;o++)this._mesh._indices[0].push((s-1)*(a+1)+o),this._mesh._indices[0].push((s-1)*(a+1)+o+1),this._mesh._indices[0].push(s*(a+1)+o),this._mesh._indices[0].push(s*(a+1)+o),this._mesh._indices[0].push((s-1)*(a+1)+o+1),this._mesh._indices[0].push(s*(a+1)+o+1);this.invalidateVolume(),this._mesh._numFaces=this._mesh._indices[0].length/3,this._mesh._numCoords=this._mesh._positions[0].length/3,this._parentNodes.forEach((function(e){e.setAllDirty(),e.invalidateVolume()}))}}})),x3dom.registerNodeType("Box","Geometry3D",defineClass(x3dom.nodeTypes.X3DSpatialGeometryNode,(function(e){x3dom.nodeTypes.Box.superClass.call(this,e),this.addField_SFVec3f(e,"size",2,2,2),this.addField_SFBool(e,"hasHelperColors",!1);var t=this._vf.size.x,i=this._vf.size.y,o=this._vf.size.z,s=this._vf.ccw,r=["Box",t,i,o,s].join("-");this._vf.useGeoCache&&void 0!==x3dom.geoCache[r]?this._mesh=x3dom.geoCache[r]:(t/=2,i/=2,o/=2,this._mesh._positions[0]=[-t,-i,-o,-t,i,-o,t,i,-o,t,-i,-o,-t,-i,o,-t,i,o,t,i,o,t,-i,o,-t,-i,-o,-t,-i,o,-t,i,o,-t,i,-o,t,-i,-o,t,-i,o,t,i,o,t,i,-o,-t,i,-o,-t,i,o,t,i,o,t,i,-o,-t,-i,-o,-t,-i,o,t,-i,o,t,-i,-o],this._mesh._normals[0]=s?[0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,1,0,0,1,0,0,1,0,0,1,-1,0,0,-1,0,0,-1,0,0,-1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0]:[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,1,0,0,1,0,0,1,0,0,1,0],this._mesh._texCoords[0]=[1,0,1,1,0,1,0,0,0,0,0,1,1,1,1,0,0,0,1,0,1,1,0,1,1,0,0,0,0,1,1,1,0,1,0,0,1,0,1,1,0,0,0,1,1,1,1,0],this._vf.hasHelperColors&&(this._mesh._colors[0]=[0,0,0,0,1,0,1,1,0,1,0,0,0,0,1,0,1,1,1,1,1,1,0,1,0,0,0,0,0,1,0,1,1,0,1,0,1,0,0,1,0,1,1,1,1,1,1,0,0,1,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,0,1,1,0,0]),this._mesh._indices[0]=[0,1,2,2,3,0,4,7,5,5,7,6,8,9,10,10,11,8,12,14,13,14,12,15,16,17,18,18,19,16,20,22,21,22,20,23],this._mesh._invalidate=!0,this._mesh._numFaces=12,this._mesh._numCoords=24,x3dom.geoCache[r]=this._mesh)}),{fieldChanged:function(e){if("size"===e){var t=this._vf.size.x/2,i=this._vf.size.y/2,o=this._vf.size.z/2;this._mesh._positions[0]=[-t,-i,-o,-t,i,-o,t,i,-o,t,-i,-o,-t,-i,o,-t,i,o,t,i,o,t,-i,o,-t,-i,-o,-t,-i,o,-t,i,o,-t,i,-o,t,-i,-o,t,-i,o,t,i,o,t,i,-o,-t,i,-o,-t,i,o,t,i,o,t,i,-o,-t,-i,-o,-t,-i,o,t,-i,o,t,-i,-o],this.invalidateVolume(),this._parentNodes.forEach((function(e){e._dirty.positions=!0,e.invalidateVolume()}))}else"hasHelperColors"===e&&(this._vf.hasHelperColors?this._mesh._colors[0]=[0,0,0,0,1,0,1,1,0,1,0,0,0,0,1,0,1,1,1,1,1,1,0,1,0,0,0,0,0,1,0,1,1,0,1,0,1,0,0,1,0,1,1,1,1,1,1,0,0,1,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,0,1,1,0,0]:this._mesh._colors[0]=[],this._parentNodes.forEach((function(e){e._dirty.colors=!0})))}})),x3dom.registerNodeType("Sphere","Geometry3D",defineClass(x3dom.nodeTypes.X3DSpatialGeometryNode,(function(e){x3dom.nodeTypes.Sphere.superClass.call(this,e),this.addField_SFFloat(e,"radius",e?1:1e3),this.addField_SFVec2f(e,"subdivision",24,24),this._qfactors={low:.3,medium:.5,high:1},void 0===e&&this.nodeChanged()}),{nodeChanged:function(){var e=1;this._nameSpace&&(e=this._nameSpace.doc.properties.getProperty("PrimitiveQuality","Medium")),e=x3dom.Utils.isNumber(e)?parseFloat(e):this._qfactors[e.toLowerCase()]||.5,this._quality=e;var t=["Sphere",this._vf.radius,this._vf.subdivision.x,this._vf.subdivision.y,e,this._vf.ccw].join("-");this._vf.useGeoCache&&void 0!==x3dom.geoCache[t]?this._mesh=x3dom.geoCache[t]:(this._regenerateMesh(),this._mesh._invalidate=!0,this._mesh._numFaces=this._mesh._indices[0].length/3,this._mesh._numCoords=this._mesh._positions[0].length/3,x3dom.geoCache[t]=this._mesh)},_regenerateMesh:function(){this._mesh._positions[0]=[],this._mesh._indices[0]=[],this._mesh._normals[0]=[],this._mesh._texCoords[0]=[];var e,t,i,o,s,r,n,a,d,l,h=this._vf.radius,f=this._vf.ccw?1:-1,u=this._vf.subdivision.x,c=this._vf.subdivision.y,_=Math.floor(u*this._quality),m=Math.floor(c*this._quality);for(e=0;e<=_;e++)for(i=e*Math.PI/_,o=Math.sin(i),s=Math.cos(i),t=0;t<=m;t++)r=this._calcXYZ(t,m,o,s),n=this._uFromlong(t,m),a=e/_,this._mesh._positions[0].push(h*r.x,h*r.y,h*r.z),this._mesh._normals[0].push(f*r.x,f*r.y,f*r.z),this._mesh._texCoords[0].push(n,a);for(e=0;e<_;e++)for(t=0;t<m;t++)l=(d=e*(m+1)+t)+m+1,this._mesh._indices[0].push(d,l,d+1),this._mesh._indices[0].push(l,l+1,d+1)},_calcXYZ:function(e,t,i,o){var s=.5*Math.PI+2*e*Math.PI/t;return{x:-Math.cos(s)*i,y:-o,z:-Math.sin(s)*i}},_uFromlong:function(e,t){return 1-e/t},fieldChanged:function(e){if("radius"===e){this._mesh._positions[0]=[];var t,i,o,s,r,n,a=this._vf.radius,d=this._vf.subdivision.x,l=this._vf.subdivision.y,h=this._quality,f=Math.floor(d*h),u=Math.floor(l*h);for(t=0;t<=f;t++)for(o=t*Math.PI/f,s=Math.sin(o),r=Math.cos(o),i=0;i<=u;i++)n=this._calcXYZ(i,u,s,r),this._mesh._positions[0].push(a*n.x,a*n.y,a*n.z);this.invalidateVolume(),this._mesh._numCoords=this._mesh._positions[0].length/3,this._parentNodes.forEach((function(e){e._dirty.positions=!0,e.invalidateVolume()}))}else if("subdivision"===e){this._regenerateMesh(),this.invalidateVolume(),this._mesh._numFaces=this._mesh._indices[0].length/3,this._mesh._numCoords=this._mesh._positions[0].length/3;var c="Sphere_"+(a=this._vf.radius)+"-"+(d=this._vf.subdivision.x)+"-"+(l=this._vf.subdivision.y);x3dom.geoCache[c]=this._mesh,this._parentNodes.forEach((function(e){e.setAllDirty(),e.invalidateVolume()}))}}})),x3dom.registerNodeType("Torus","Geometry3D",defineClass(x3dom.nodeTypes.X3DSpatialGeometryNode,(function(e){x3dom.nodeTypes.Torus.superClass.call(this,e);var t=2*Math.PI;this.addField_SFFloat(e,"innerRadius",.5),this.addField_SFFloat(e,"outerRadius",1),this.addField_SFFloat(e,"angle",t),this.addField_SFBool(e,"caps",!0),this.addField_SFVec2f(e,"subdivision",24,24),this.addField_SFBool(e,"insideOutsideRadius",!1),this._vf.angle<0?this._vf.angle=0:this._vf.angle>t&&(this._vf.angle=t),this._origCCW=this._vf.ccw;var i=this._vf.innerRadius,o=this._vf.outerRadius;if(1==this._vf.insideOutsideRadius){if(i>o){var s=i;i=o,o=s}var r=(o-i)/2;o=i+r,i=r,this._vf.ccw=!this._origCCW}var n=this._vf.subdivision.x,a=this._vf.subdivision.y,d=this._vf.ccw?1:-1;n=Math.max(3,Math.round(this._vf.angle/t*n));var l=["Torus_",i,o,this._vf.angle,this._vf.subdivision,this._vf.caps,d].join("_");if(this._vf.useGeoCache&&void 0!==x3dom.geoCache[l])this._mesh=x3dom.geoCache[l];else{var h,f,u,c,_,m,p,x,g,v=this._vf.angle/n,y=t/a;for(h=0,u=0;h<=n;h++,u+=v)for(_=Math.cos(u),m=Math.sin(u),f=0,c=0;f<=a;f++,c+=y)p=Math.cos(c),x=Math.sin(c),g=o+i*p,this._vf.insideOutsideRadius?(this._mesh._positions[0].push(_*g,i*x,-m*g),this._mesh._normals[0].push(d*_*p,d*x,d*-m*p)):(this._mesh._positions[0].push(_*g,-m*g,i*x),this._mesh._normals[0].push(d*_*p,d*-m*p,d*x)),this._mesh._texCoords[0].push(-h/n,f/a);for(h=0;h<a;h++)for(f=0;f<n;f++)this._mesh._indices[0].push(f*(a+1)+h),this._mesh._indices[0].push(f*(a+1)+h+1),this._mesh._indices[0].push((f+1)*(a+1)+h),this._mesh._indices[0].push(f*(a+1)+h+1),this._mesh._indices[0].push((f+1)*(a+1)+h+1),this._mesh._indices[0].push((f+1)*(a+1)+h);if(this._vf.angle<t&&1==this._vf.caps){var T=this._mesh._positions[0].length/3;for(this._vf.insideOutsideRadius?(this._mesh._positions[0].push(o,0,0),this._mesh._normals[0].push(0,0,1*d)):(this._mesh._positions[0].push(o,0,0),this._mesh._normals[0].push(0,1*d,0)),this._mesh._texCoords[0].push(.5,.5),f=0,c=0;f<=a;f++,c+=y)p=Math.cos(c),x=Math.sin(c),g=o+i*p,this._vf.insideOutsideRadius?(this._mesh._positions[0].push(g,x*i,0),this._mesh._normals[0].push(0,0,1*d)):(this._mesh._positions[0].push(g,0,x*i),this._mesh._normals[0].push(0,1*d,0)),this._mesh._texCoords[0].push(.5*(1+p),.5*(1-x)),f>0&&(this._mesh._indices[0].push(T),this._mesh._indices[0].push(T+f),this._mesh._indices[0].push(T+f-1)),f==a&&(this._mesh._indices[0].push(T),this._mesh._indices[0].push(T+1),this._mesh._indices[0].push(T+f));_=Math.cos(this._vf.angle),m=Math.sin(this._vf.angle),T=this._mesh._positions[0].length/3;var b=-m,S=-_;for(this._vf.insideOutsideRadius?(this._mesh._positions[0].push(_*o,0,-m*o),this._mesh._normals[0].push(d*b,0,d*S)):(this._mesh._positions[0].push(_*o,-m*o,0),this._mesh._normals[0].push(d*b,d*S,0)),this._mesh._texCoords[0].push(.5,.5),f=0,c=0;f<=a;f++,c+=y)p=Math.cos(c),x=Math.sin(c),g=o+i*p,this._vf.insideOutsideRadius?(this._mesh._positions[0].push(_*g,x*i,-m*g),this._mesh._normals[0].push(d*b,0,d*S)):(this._mesh._positions[0].push(_*g,-m*g,x*i),this._mesh._normals[0].push(d*b,d*S,0)),this._mesh._texCoords[0].push(1-.5*(1+p),.5*(1-x)),f>0&&(this._mesh._indices[0].push(T),this._mesh._indices[0].push(T+f-1),this._mesh._indices[0].push(T+f)),f==a&&(this._mesh._indices[0].push(T),this._mesh._indices[0].push(T+f),this._mesh._indices[0].push(T+1))}this._mesh._invalidate=!0,this._mesh._numFaces=this._mesh._indices[0].length/3,this._mesh._numCoords=this._mesh._positions[0].length/3,x3dom.geoCache[l]=this._mesh}}),{fieldChanged:function(e){if("innerRadius"==e||"outerRadius"==e||"subdivision"==e||"angle"==e||"insideOutsideRadius"==e||"caps"==e){var t=2*Math.PI;this._vf.angle<0?this._vf.angle=0:this._vf.angle>t&&(this._vf.angle=t);var i=this._vf.innerRadius,o=this._vf.outerRadius;if(1==this._vf.insideOutsideRadius){if(i>o){var s=i;i=o,o=s}var r=(o-i)/2;o=i+r,i=r,this._vf.ccw=!this._origCCW}else this._vf.ccw=this._origCCW;var n=this._vf.subdivision.x,a=this._vf.subdivision.y,d=this._vf.ccw?1:-1;n=Math.max(3,Math.round(this._vf.angle/t*n));var l,h,f,u,c,_,m,p,x,g=this._vf.angle/n,v=t/a;for(this._mesh._positions[0]=[],this._mesh._normals[0]=[],this._mesh._texCoords[0]=[],this._mesh._indices[0]=[],l=0,f=0;l<=n;l++,f+=g)for(c=Math.cos(f),_=Math.sin(f),h=0,u=0;h<=a;h++,u+=v)m=Math.cos(u),p=Math.sin(u),x=o+i*m,this._vf.insideOutsideRadius?(this._mesh._positions[0].push(c*x,i*p,-_*x),this._mesh._normals[0].push(d*c*m,d*p,d*-_*m)):(this._mesh._positions[0].push(c*x,-_*x,i*p),this._mesh._normals[0].push(d*c*m,d*-_*m,d*p)),this._mesh._texCoords[0].push(-l/n,h/a);for(l=0;l<a;l++)for(h=0;h<n;h++)this._mesh._indices[0].push(h*(a+1)+l),this._mesh._indices[0].push(h*(a+1)+l+1),this._mesh._indices[0].push((h+1)*(a+1)+l),this._mesh._indices[0].push(h*(a+1)+l+1),this._mesh._indices[0].push((h+1)*(a+1)+l+1),this._mesh._indices[0].push((h+1)*(a+1)+l);if(this._vf.angle<t&&1==this._vf.caps){var y=this._mesh._positions[0].length/3;for(this._vf.insideOutsideRadius?(this._mesh._positions[0].push(o,0,0),this._mesh._normals[0].push(0,0,1*d)):(this._mesh._positions[0].push(o,0,0),this._mesh._normals[0].push(0,1*d,0)),this._mesh._texCoords[0].push(.5,.5),h=0,u=0;h<=a;h++,u+=v)m=Math.cos(u),p=Math.sin(u),x=o+i*m,this._vf.insideOutsideRadius?(this._mesh._positions[0].push(x,p*i,0),this._mesh._normals[0].push(0,0,1*d)):(this._mesh._positions[0].push(x,0,p*i),this._mesh._normals[0].push(0,1*d,0)),this._mesh._texCoords[0].push(.5*(1+m),.5*(1-p)),h>0&&(this._mesh._indices[0].push(y),this._mesh._indices[0].push(y+h),this._mesh._indices[0].push(y+h-1)),h==a&&(this._mesh._indices[0].push(y),this._mesh._indices[0].push(y+1),this._mesh._indices[0].push(y+h));c=Math.cos(this._vf.angle),_=Math.sin(this._vf.angle),y=this._mesh._positions[0].length/3;var T=-_,b=-c;for(this._vf.insideOutsideRadius?(this._mesh._positions[0].push(c*o,0,-_*o),this._mesh._normals[0].push(d*T,0,d*b)):(this._mesh._positions[0].push(c*o,-_*o,0),this._mesh._normals[0].push(d*T,d*b,0)),this._mesh._texCoords[0].push(.5,.5),h=0,u=0;h<=a;h++,u+=v)m=Math.cos(u),p=Math.sin(u),x=o+i*m,this._vf.insideOutsideRadius?(this._mesh._positions[0].push(c*x,p*i,-_*x),this._mesh._normals[0].push(d*T,0,d*b)):(this._mesh._positions[0].push(c*x,-_*x,p*i),this._mesh._normals[0].push(d*T,d*b,0)),this._mesh._texCoords[0].push(1-.5*(1+m),.5*(1-p)),h>0&&(this._mesh._indices[0].push(y),this._mesh._indices[0].push(y+h-1),this._mesh._indices[0].push(y+h)),h==a&&(this._mesh._indices[0].push(y),this._mesh._indices[0].push(y+h),this._mesh._indices[0].push(y+1))}this.invalidateVolume(),this._mesh._numFaces=this._mesh._indices[0].length/3,this._mesh._numCoords=this._mesh._positions[0].length/3,this._parentNodes.forEach((function(e){e.setAllDirty(),e.invalidateVolume()}))}}})),x3dom.registerNodeType("Cone","Geometry3D",defineClass(x3dom.nodeTypes.X3DSpatialGeometryNode,(function(e){x3dom.nodeTypes.Cone.superClass.call(this,e),this.addField_SFFloat(e,"bottomRadius",1),this.addField_SFFloat(e,"topRadius",0),this.addField_SFFloat(e,"height",2),this.addField_SFBool(e,"bottom",!0),this.addField_SFBool(e,"side",!0),this.addField_SFBool(e,"top",!0),this.addField_SFFloat(e,"subdivision",32);var t=["Cone",this._vf.bottomRadius,this._vf.height,this._vf.top,this._vf.bottom,this._vf.side,this._vf.topRadius,this._vf.subdivision,this._vf.ccw].join("_");this._vf.useGeoCache&&void 0!==x3dom.geoCache[t]?this._mesh=x3dom.geoCache[t]:(this._calcMesh(),this._mesh._invalidate=!0,x3dom.geoCache[t]=this._mesh)}),{_calcMesh:function(){var e,t,i,o,s,r=this._vf.bottomRadius,n=this._vf.height,a=this._vf.topRadius,d=this._vf.subdivision,l=this._vf.ccw?1:-1,h=2*Math.PI/d,f=(r-a)/n,u=1/Math.sqrt(1+f*f),c=0,_=0;if(this._vf.side&&n>0){var m=0,p=0;for(c=0,_=0;c<=d;c++)e=c*h,t=Math.sin(e),i=-Math.cos(e),a>x3dom.fields.Eps&&(m=t*a,p=i*a),this._mesh._positions[0].push(m,n/2,p),this._mesh._normals[0].push(l*t/u,l*f/u,l*i/u),this._mesh._texCoords[0].push(1-c/d,1),this._mesh._positions[0].push(t*r,-n/2,i*r),this._mesh._normals[0].push(l*t/u,l*f/u,l*i/u),this._mesh._texCoords[0].push(1-c/d,0),c>0&&(this._mesh._indices[0].push(_),this._mesh._indices[0].push(_+2),this._mesh._indices[0].push(_+1),this._mesh._indices[0].push(_+1),this._mesh._indices[0].push(_+2),this._mesh._indices[0].push(_+3),_+=2)}if(this._vf.bottom&&r>0){for(s=this._mesh._positions[0].length/3,c=d-1;c>=0;c--)e=c*h,t=r*Math.sin(e),i=-r*Math.cos(e),this._mesh._positions[0].push(t,-n/2,i),this._mesh._normals[0].push(0,-1*l,0),this._mesh._texCoords[0].push(t/r/2+.5,i/r/2+.5);for(o=s+1,c=2;c<d;c++)this._mesh._indices[0].push(o),this._mesh._indices[0].push(s),o=s+c,this._mesh._indices[0].push(o)}if(this._vf.top&&a>x3dom.fields.Eps){for(s=this._mesh._positions[0].length/3,c=d-1;c>=0;c--)e=c*h,t=a*Math.sin(e),i=-a*Math.cos(e),this._mesh._positions[0].push(t,n/2,i),this._mesh._normals[0].push(0,1*l,0),this._mesh._texCoords[0].push(t/a/2+.5,1-i/a/2+.5);for(o=s+1,c=2;c<d;c++)this._mesh._indices[0].push(s),this._mesh._indices[0].push(o),o=s+c,this._mesh._indices[0].push(o)}this._mesh._numFaces=this._mesh._indices[0].length/3,this._mesh._numCoords=this._mesh._positions[0].length/3},fieldChanged:function(e){"bottomRadius"!=e&&"topRadius"!=e&&"height"!=e&&"subdivision"!=e&&"bottom"!=e&&"top"!=e&&"side"!=e||(this._mesh._positions[0]=[],this._mesh._indices[0]=[],this._mesh._normals[0]=[],this._mesh._texCoords[0]=[],this._calcMesh(),this.invalidateVolume(),this._parentNodes.forEach((function(e){e.setAllDirty(),e.invalidateVolume()})))}})),x3dom.registerNodeType("Cylinder","Geometry3D",defineClass(x3dom.nodeTypes.X3DSpatialGeometryNode,(function(e){x3dom.nodeTypes.Cylinder.superClass.call(this,e),this.addField_SFFloat(e,"radius",1),this.addField_SFFloat(e,"height",2),this.addField_SFBool(e,"bottom",!0),this.addField_SFBool(e,"top",!0),this.addField_SFFloat(e,"subdivision",32),this.addField_SFBool(e,"side",!0);var t=this._vf.subdivision,i=this._vf.ccw,o=["Cylinder",this._vf.radius,this._vf.height,this._vf.bottom,this._vf.top,this._vf.side,t,i].join("_");this._vf.useGeoCache&&void 0!==x3dom.geoCache[o]?this._mesh=x3dom.geoCache[o]:(this._calcMesh(),this._mesh._invalidate=!0,x3dom.geoCache[o]=this._mesh)}),{_calcMesh:function(){var e,t,i,o,s=this._vf.radius,r=this._vf.height/2,n=this._vf.subdivision,a=this._vf.ccw?1:-1,d=2*Math.PI/n,l=0;if(this._vf.side)for(o=0,l=0;o<=n;o++)e=o*d,t=Math.sin(e),i=-Math.cos(e),this._mesh._positions[0].push(t*s,-r,i*s),this._mesh._normals[0].push(a*t,0,a*i),this._mesh._texCoords[0].push(1-o/n,0),this._mesh._positions[0].push(t*s,r,i*s),this._mesh._normals[0].push(a*t,0,a*i),this._mesh._texCoords[0].push(1-o/n,1),o>0&&(this._mesh._indices[0].push(l+0,l+1,l+2),this._mesh._indices[0].push(l+2,l+1,l+3),l+=2);if(s>0){var h,f=this._mesh._positions[0].length/3;if(this._vf.top){for(o=n-1;o>=0;o--)e=o*d,t=s*Math.sin(e),i=-s*Math.cos(e),this._mesh._positions[0].push(t,r,i),this._mesh._normals[0].push(0,1*a,0),this._mesh._texCoords[0].push(t/s/2+.5,-i/s/2+.5);for(h=f+1,o=2;o<n;o++)this._mesh._indices[0].push(f),this._mesh._indices[0].push(h),h=f+o,this._mesh._indices[0].push(h);f=this._mesh._positions[0].length/3}if(this._vf.bottom){for(o=n-1;o>=0;o--)e=o*d,t=s*Math.sin(e),i=-s*Math.cos(e),this._mesh._positions[0].push(t,-r,i),this._mesh._normals[0].push(0,-1*a,0),this._mesh._texCoords[0].push(t/s/2+.5,i/s/2+.5);for(h=f+1,o=2;o<n;o++)this._mesh._indices[0].push(h),this._mesh._indices[0].push(f),h=f+o,this._mesh._indices[0].push(h)}}this._mesh._numFaces=this._mesh._indices[0].length/3,this._mesh._numCoords=this._mesh._positions[0].length/3},fieldChanged:function(e){if("radius"===e||"height"===e){this._mesh._positions[0]=[];var t,i,o,s,r=this._vf.radius,n=this._vf.height/2,a=this._vf.subdivision,d=2*Math.PI/a;if(this._vf.side)for(s=0;s<=a;s++)t=s*d,i=Math.sin(t),o=-Math.cos(t),this._mesh._positions[0].push(i*r,-n,o*r),this._mesh._positions[0].push(i*r,n,o*r);if(r>0){this._mesh._positions[0].length;if(this._vf.top)for(s=a-1;s>=0;s--)t=s*d,i=r*Math.sin(t),o=-r*Math.cos(t),this._mesh._positions[0].push(i,n,o)}if(this._vf.bottom)for(s=a-1;s>=0;s--)t=s*d,i=r*Math.sin(t),o=-r*Math.cos(t),this._mesh._positions[0].push(i,-n,o);this.invalidateVolume(),this._mesh._numCoords=this._mesh._positions[0].length/3,this._parentNodes.forEach((function(e){e._dirty.positions=!0,e.invalidateVolume()}))}else"subdivision"!==e&&"bottom"!==e&&"top"!==e&&"side"!==e||(this._mesh._positions[0]=[],this._mesh._indices[0]=[],this._mesh._normals[0]=[],this._mesh._texCoords[0]=[],this._calcMesh(),this.invalidateVolume(),this._parentNodes.forEach((function(e){e.setAllDirty(),e.invalidateVolume()})))}})),x3dom.registerNodeType("X3DBinaryContainerGeometryNode","Geometry3D",defineClass(x3dom.nodeTypes.X3DSpatialGeometryNode,(function(e){x3dom.nodeTypes.X3DBinaryContainerGeometryNode.superClass.call(this,e),this.addField_SFVec3f(e,"position",0,0,0),this.addField_SFVec3f(e,"size",1,1,1),this.addField_MFInt32(e,"vertexCount",[0]),this.addField_MFString(e,"primType",["TRIANGLES"]),this._mesh._invalidate=!1,this._mesh._numCoords=0,this._mesh._numFaces=0,this._diameter=this._vf.size.length()}),{getMin:function(){var e=this._mesh._vol;return e.isValid()||e.setBoundsByCenterSize(this._vf.position,this._vf.size),e.min},getMax:function(){var e=this._mesh._vol;return e.isValid()||e.setBoundsByCenterSize(this._vf.position,this._vf.size),e.max},getVolume:function(){var e=this._mesh._vol;return e.isValid()||e.setBoundsByCenterSize(this._vf.position,this._vf.size),e},invalidateVolume:function(){},getCenter:function(){return this._vf.position},getDiameter:function(){return this._diameter},needLighting:function(){var e=this._vf.primType.length&&this._vf.primType[0].indexOf("TRIANGLE")>=0;return this._vf.lit&&e}})),x3dom.registerNodeType("BinaryGeometry","Geometry3D",defineClass(x3dom.nodeTypes.X3DBinaryContainerGeometryNode,(function(e){x3dom.nodeTypes.BinaryGeometry.superClass.call(this,e),this.addField_SFString(e,"index",""),this.addField_SFString(e,"coord",""),this.addField_SFString(e,"normal",""),this.addField_SFString(e,"texCoord",""),this.addField_SFString(e,"color",""),this.addField_SFString(e,"tangent",""),this.addField_SFString(e,"binormal",""),this.addField_SFString(e,"indexType","Uint16"),this.addField_SFString(e,"coordType","Float32"),this.addField_SFString(e,"normalType","Float32"),this.addField_SFString(e,"texCoordType","Float32"),this.addField_SFString(e,"colorType","Float32"),this.addField_SFString(e,"tangentType","Float32"),this.addField_SFString(e,"binormalType","Float32"),this.addField_SFBool(e,"normalAsSphericalCoordinates",!1),this.addField_SFBool(e,"rgbaColors",!1),this.addField_SFInt32(e,"numTexCoordComponents",2),this.addField_SFBool(e,"normalPerVertex",!0),this.addField_SFBool(e,"idsPerVertex",!1),this.addField_SFBool(e,"compressed",!1),this._hasStrideOffset=!1,this._mesh._numPosComponents=this._vf.normalAsSphericalCoordinates?4:3,this._mesh._numTexComponents=this._vf.numTexCoordComponents,this._mesh._numColComponents=this._vf.rgbaColors?4:3,this._mesh._numNormComponents=this._vf.normalAsSphericalCoordinates?2:3,this._vertexCountSum=0;for(var t=0;t<this._vf.vertexCount.length;++t)this._vertexCountSum+=this._vf.vertexCount[t]}),{parentAdded:function(e){var t,i,o,s;t=this._vf.coord.lastIndexOf("#"),i=this._vf.coord.lastIndexOf("+"),t>=0&&i>=0?(o=+this._vf.coord.substring(++t,i),s=+this._vf.coord.substring(i),e._coordStrideOffset=[s,o],this._hasStrideOffset=!0,o/8-Math.floor(o/8)==0&&(this._mesh._numPosComponents=4)):i>=0&&(s=+this._vf.coord.substring(i),e._coordStrideOffset=[s,0],s/8-Math.floor(s/8)==0&&(this._mesh._numPosComponents=4)),t=this._vf.normal.lastIndexOf("#"),i=this._vf.normal.lastIndexOf("+"),t>=0&&i>=0?(o=+this._vf.normal.substring(++t,i),s=+this._vf.normal.substring(i),e._normalStrideOffset=[s,o]):i>=0&&(s=+this._vf.normal.substring(i),e._normalStrideOffset=[s,0]),t=this._vf.texCoord.lastIndexOf("#"),i=this._vf.texCoord.lastIndexOf("+"),t>=0&&i>=0?(o=+this._vf.texCoord.substring(++t,i),s=+this._vf.texCoord.substring(i),e._texCoordStrideOffset=[s,o]):i>=0&&(s=+this._vf.texCoord.substring(i),e._texCoordStrideOffset=[s,0]),t=this._vf.color.lastIndexOf("#"),i=this._vf.color.lastIndexOf("+"),t>=0&&i>=0?(o=+this._vf.color.substring(++t,i),s=+this._vf.color.substring(i),e._colorStrideOffset=[s,o]):i>=0&&(s=+this._vf.color.substring(i),e._colorStrideOffset=[s,0]),"Uint16"==this._vf.indexType||x3dom.caps.INDEX_UINT||x3dom.debug.logWarning("Index type "+this._vf.indexType+" problematic")},doIntersect:function(e){var t=this.getMin(),i=this.getMax();return!!(e.intersect(t,i)&&e.enter<e.dist)&&(e.dist=e.enter,e.hitObject=this,e.hitPoint=e.pos.add(e.dir.multiply(e.enter)),!0)},getPrecisionMax:function(e){switch(this._vf[e]){case"Int8":return 127;case"Uint8":return 255;case"Int16":return 32767;case"Uint16":return 65535;case"Int32":return 2147483647;case"Uint32":return 4294967295;case"Float32":case"Float64":default:return 1}}})),x3dom.registerNodeType("PopGeometryLevel","Geometry3D",defineClass(x3dom.nodeTypes.X3DGeometricPropertyNode,(function(e){x3dom.nodeTypes.PopGeometryLevel.superClass.call(this,e),this.addField_SFString(e,"src",""),this.addField_SFInt32(e,"numIndices",0),this.addField_SFInt32(e,"vertexDataBufferOffset",0)}),{getSrc:function(){return this._vf.src},getNumIndices:function(){return this._vf.numIndices},getVertexDataBufferOffset:function(){return this._vf.vertexDataBufferOffset}})),x3dom.registerNodeType("PopGeometry","Geometry3D",defineClass(x3dom.nodeTypes.X3DBinaryContainerGeometryNode,(function(e){x3dom.nodeTypes.PopGeometry.superClass.call(this,e),this.addField_SFVec3f(e,"tightSize",1,1,1),this.addField_SFVec3f(e,"maxBBSize",1,1,1),this.addField_SFVec3f(e,"bbMinModF",0,0,0),this.addField_SFVec3f(e,"bbMaxModF",1,1,1),this.addField_SFVec3f(e,"bbMin",0,0,0),this.addField_SFVec3f(e,"bbShiftVec",0,0,0),this._vf.bbMinModF.x>this._vf.bbMaxModF.x&&(this._vf.bbShiftVec.x=1),this._vf.bbMinModF.y>this._vf.bbMaxModF.y&&(this._vf.bbShiftVec.y=1),this._vf.bbMinModF.z>this._vf.bbMaxModF.z&&(this._vf.bbShiftVec.z=1),this.addField_MFNode("levels",x3dom.nodeTypes.PopGeometryLevel),this.addField_SFInt32(e,"attributeStride",0),this.addField_SFInt32(e,"positionOffset",0),this.addField_SFInt32(e,"normalOffset",0),this.addField_SFInt32(e,"texcoordOffset",0),this.addField_SFInt32(e,"colorOffset",0),this.addField_SFInt32(e,"numAnchorVertices",0),this.addField_SFInt32(e,"positionPrecision",2),this.addField_SFInt32(e,"normalPrecision",1),this.addField_SFInt32(e,"texcoordPrecision",2),this.addField_SFInt32(e,"colorPrecision",1),this.addField_SFInt32(e,"minPrecisionLevel",-1),this.addField_SFInt32(e,"maxPrecisionLevel",-1),this.addField_SFFloat(e,"precisionFactor",1),this.addField_SFString(e,"coordType","Uint16"),this.addField_SFString(e,"normalType","Uint8"),this.addField_SFString(e,"texCoordType","Uint16"),this.addField_SFString(e,"colorType","Uint8"),this.addField_SFInt32(e,"vertexBufferSize",0),this.addField_SFBool(e,"indexedRendering",!0),this.addField_SFBool(e,"sphericalNormals",!1),this.addField_MFInt32(e,"originalVertexCount",[0]);for(var t=0;t<this._vf.vertexCount.length;++t)this._vf.originalVertexCount[t]=this._vf.vertexCount[t];this._vf.maxBBSize=x3dom.fields.SFVec3f.copy(this._vf.size),this._vf.size=this._vf.tightSize,this._diameter=this._vf.size.length(),this._bbMinBySize=[Math.floor(this._vf.bbMin.x/this._vf.maxBBSize.x),Math.floor(this._vf.bbMin.y/this._vf.maxBBSize.y),Math.floor(this._vf.bbMin.z/this._vf.maxBBSize.z)],this._volRadius=this._vf.size.length()/2,this._volLargestRadius=this._vf.maxBBSize.length()/2,this._mesh._numPosComponents=this._vf.sphericalNormals?4:3,this._mesh._numNormComponents=this._vf.sphericalNormals?2:3,this._mesh._numTexComponents=2,this._mesh._numColComponents=3,x3dom.nodeTypes.PopGeometry.numTotalVerts+=this.getVertexCount(),x3dom.nodeTypes.PopGeometry.numTotalTris+=(this.hasIndex()?this.getTotalNumberOfIndices():this.getVertexCount())/3}),{forceUpdateCoverage:function(){return!0},getBBoxShiftVec:function(){return this._vf.bbShiftVec},getBBoxSize:function(){return this._vf.size},hasIndex:function(){return this._vf.indexedRendering},getTotalNumberOfIndices:function(){if(this._vf.indexedRendering){for(var e=0,t=0;t<this._vf.originalVertexCount.length;++t)e+=this._vf.originalVertexCount[t];return e}return 0},getVertexCount:function(){for(var e=0,t=0;t<this._vf.originalVertexCount.length;++t)e+=this._vf.originalVertexCount[t];return e},adaptVertexCount:function(e){for(var t=0,i=0;i<this._vf.originalVertexCount.length;++i){if(!(this._vf.originalVertexCount[i]+t<=e)){this._vf.vertexCount[i]=e-t;break}this._vf.vertexCount[i]=this._vf.originalVertexCount[i],t+=this._vf.originalVertexCount[i]}},hasNormal:function(){return 0!=this._vf.normalOffset&&!this._vf.sphericalNormals},hasTexCoord:function(){return 0!=this._vf.texcoordOffset},hasColor:function(){return 0!=this._vf.colorOffset},getPositionPrecision:function(){return this._vf.positionPrecision},getNormalPrecision:function(){return this._vf.normalPrecision},getTexCoordPrecision:function(){return this._vf.texcoordPrecision},getColorPrecision:function(){return this._vf.colorPrecision},getAttributeStride:function(){return this._vf.attributeStride},getPositionOffset:function(){return this._vf.positionOffset},getNormalOffset:function(){return this._vf.normalOffset},getTexCoordOffset:function(){return this._vf.texcoordOffset},getColorOffset:function(){return this._vf.colorOffset},getBufferTypeStringFromByteCount:function(e){switch(e){case 1:return"Uint8";case 2:return"Uint16";default:return 0}},getDataURLs:function(){for(var e=[],t=0;t<this._cf.levels.nodes.length;++t)e.push(this._cf.levels.nodes[t].getSrc());return e},getNumIndicesByLevel:function(e){return this._cf.levels.nodes[e].getNumIndices()},getNumLevels:function(e){return this._cf.levels.nodes.length},getVertexDataBufferOffset:function(e){return this._cf.levels.nodes[e].getVertexDataBufferOffset()},getPrecisionMax:function(e){switch(this._vf[e]){case"Uint8":return 255;case"Uint16":return 65535;default:return 1}}})),x3dom.nodeTypes.PopGeometry.ErrorToleranceFactor=1,x3dom.nodeTypes.PopGeometry.PrecisionFactorOnMove=1,x3dom.nodeTypes.PopGeometry.numRenderedVerts=0,x3dom.nodeTypes.PopGeometry.numRenderedTris=0,x3dom.nodeTypes.PopGeometry.numTotalVerts=0,x3dom.nodeTypes.PopGeometry.numTotalTris=0,x3dom.nodeTypes.PopGeometry.powLUT=[32768,16384,8192,4096,2048,1024,512,256,128,64,32,16,8,4,2,1],x3dom.registerNodeType("IndexedFaceSet","Geometry3D",defineClass(x3dom.nodeTypes.X3DComposedGeometryNode,(function(e){x3dom.nodeTypes.IndexedFaceSet.superClass.call(this,e),this.addField_SFFloat(e,"creaseAngle",0),this.addField_SFBool(e,"convex",!0),this.addField_MFInt32(e,"coordIndex",[]),this.addField_MFInt32(e,"normalIndex",[]),this.addField_MFInt32(e,"colorIndex",[]),this.addField_MFInt32(e,"texCoordIndex",[])}),{nodeChanged:function(){(new Date).getTime();this.handleAttribs();var e=this._vf.coordIndex;e.length&&-1!=e[e.length-1]&&e.push(-1);var t,i,o,s,r=this._vf.normalIndex,n=this._vf.texCoordIndex,a=this._vf.colorIndex,d=!1,l=!1,h=!1,f=!1,u=!1,c=!1,_=this._vf.colorPerVertex,m=this._vf.normalPerVertex;r.length>0&&(l=!0),n.length>0&&(f=!0),a.length>0&&(c=!0);var p=this._cf.coord.node;x3dom.debug.assert(p),t=p.getPoints();var x=this._cf.normal.node;x?(d=!0,i=x._vf.vector):d=!1;var g="",v=2,y=this._cf.texCoord.node;if(x3dom.isa(y,x3dom.nodeTypes.MultiTextureCoordinate)&&y._cf.texCoord.nodes.length&&(y=y._cf.texCoord.nodes[0]),y)if(y._vf.point){if(h=!0,o=y._vf.point,!f){var T=o.length;for(b=T;b<t.length;b++)o.push(o[b%T])}x3dom.isa(y,x3dom.nodeTypes.TextureCoordinate3D)&&(v=3)}else y._vf.mode&&(g=y._vf.mode);else h=!1;this._mesh._numTexComponents=v;var b,S,F,E,M,C,w,A,R,D,N,I,P,V,L,O,B,U=3,X=this._cf.color.node;if(X?(u=!0,s=X._vf.color,x3dom.isa(X,x3dom.nodeTypes.ColorRGBA)&&(U=4)):u=!1,this._mesh._numColComponents=U,this._mesh._indices[0]=[],this._mesh._positions[0]=[],this._mesh._normals[0]=[],this._mesh._texCoords[0]=[],this._mesh._colors[0]=[],this._vf.creaseAngle<=x3dom.fields.Eps||t.length>x3dom.Utils.maxIndexableCoords||d&&l||h&&f||u&&c){if(this._vf.creaseAngle<=x3dom.fields.Eps&&x3dom.debug.logWarning("Fallback to inefficient multi-index mode since creaseAngle=0."),this._vf.convex)for(F=0,E=0,M=0,this._mesh._multiIndIndices=[],this._mesh._posSize=t.length,b=0;b<e.length;++b)if(-1!=e[b])switch(l&&x3dom.debug.assert(-1!=r[b]),f&&x3dom.debug.assert(-1!=n[b]),c&&x3dom.debug.assert(-1!=a[b]),F){case 0:C=+e[b],R=l&&m?+r[b]:l&&!m?+r[M]:m?C:M,I=f?+n[b]:C,L=c&&_?+a[b]:c&&!_?+a[M]:_?C:M,F=1;break;case 1:w=+e[b],D=l&&m?+r[b]:l&&!m?+r[M]:m?w:M,P=f?+n[b]:w,O=c&&_?+a[b]:c&&!_?+a[M]:_?w:M,F=2;break;case 2:A=+e[b],N=l&&m?+r[b]:l&&!m?+r[M]:m?A:M,V=f?+n[b]:A,B=c&&_?+a[b]:c&&!_?+a[M]:_?A:M,F=3,this._mesh._positions[0].push(t[C].x),this._mesh._positions[0].push(t[C].y),this._mesh._positions[0].push(t[C].z),this._mesh._positions[0].push(t[w].x),this._mesh._positions[0].push(t[w].y),this._mesh._positions[0].push(t[w].z),this._mesh._positions[0].push(t[A].x),this._mesh._positions[0].push(t[A].y),this._mesh._positions[0].push(t[A].z),d&&(this._mesh._normals[0].push(i[R].x),this._mesh._normals[0].push(i[R].y),this._mesh._normals[0].push(i[R].z),this._mesh._normals[0].push(i[D].x),this._mesh._normals[0].push(i[D].y),this._mesh._normals[0].push(i[D].z),this._mesh._normals[0].push(i[N].x),this._mesh._normals[0].push(i[N].y),this._mesh._normals[0].push(i[N].z)),this._mesh._multiIndIndices.push(C,w,A),u&&(this._mesh._colors[0].push(s[L].r),this._mesh._colors[0].push(s[L].g),this._mesh._colors[0].push(s[L].b),4===U&&this._mesh._colors[0].push(s[L].a),this._mesh._colors[0].push(s[O].r),this._mesh._colors[0].push(s[O].g),this._mesh._colors[0].push(s[O].b),4===U&&this._mesh._colors[0].push(s[O].a),this._mesh._colors[0].push(s[B].r),this._mesh._colors[0].push(s[B].g),this._mesh._colors[0].push(s[B].b),4===U&&this._mesh._colors[0].push(s[B].a)),h&&(this._mesh._texCoords[0].push(o[I].x),this._mesh._texCoords[0].push(o[I].y),3===v&&this._mesh._texCoords[0].push(o[I].z),this._mesh._texCoords[0].push(o[P].x),this._mesh._texCoords[0].push(o[P].y),3===v&&this._mesh._texCoords[0].push(o[P].z),this._mesh._texCoords[0].push(o[V].x),this._mesh._texCoords[0].push(o[V].y),3===v&&this._mesh._texCoords[0].push(o[V].z));break;case 3:w=A,P=V,m&&(D=N),_&&(O=B),A=+e[b],l&&m?N=+r[b]:l&&!m||(N=m?A:M),V=f?+n[b]:A,c&&_?B=+a[b]:c&&!_||(B=_?A:M),this._mesh._positions[0].push(t[C].x),this._mesh._positions[0].push(t[C].y),this._mesh._positions[0].push(t[C].z),this._mesh._positions[0].push(t[w].x),this._mesh._positions[0].push(t[w].y),this._mesh._positions[0].push(t[w].z),this._mesh._positions[0].push(t[A].x),this._mesh._positions[0].push(t[A].y),this._mesh._positions[0].push(t[A].z),d&&(this._mesh._normals[0].push(i[R].x),this._mesh._normals[0].push(i[R].y),this._mesh._normals[0].push(i[R].z),this._mesh._normals[0].push(i[D].x),this._mesh._normals[0].push(i[D].y),this._mesh._normals[0].push(i[D].z),this._mesh._normals[0].push(i[N].x),this._mesh._normals[0].push(i[N].y),this._mesh._normals[0].push(i[N].z)),this._mesh._multiIndIndices.push(C,w,A),u&&(this._mesh._colors[0].push(s[L].r),this._mesh._colors[0].push(s[L].g),this._mesh._colors[0].push(s[L].b),4===U&&this._mesh._colors[0].push(s[L].a),this._mesh._colors[0].push(s[O].r),this._mesh._colors[0].push(s[O].g),this._mesh._colors[0].push(s[O].b),4===U&&this._mesh._colors[0].push(s[O].a),this._mesh._colors[0].push(s[B].r),this._mesh._colors[0].push(s[B].g),this._mesh._colors[0].push(s[B].b),4===U&&this._mesh._colors[0].push(s[B].a)),h&&(this._mesh._texCoords[0].push(o[I].x),this._mesh._texCoords[0].push(o[I].y),3===v&&this._mesh._texCoords[0].push(o[I].z),this._mesh._texCoords[0].push(o[P].x),this._mesh._texCoords[0].push(o[P].y),3===v&&this._mesh._texCoords[0].push(o[P].z),this._mesh._texCoords[0].push(o[V].x),this._mesh._texCoords[0].push(o[V].y),3===v&&this._mesh._texCoords[0].push(o[V].z))}else F=0,M++;else{var k=new x3dom.DoublyLinkedList,G={};for(E=0,M=0,b=0;b<e.length;++b)if(-1!=e[b])d&&(G.normals=l&&m?i[r[b]]:l&&!m?i[r[M]]:i[e[b]]),u&&(G.colors=c&&_?s[a[b]]:c&&!_?s[a[M]]:_?s[e[b]]:s[M]),h&&(G.texCoords=f?o[n[b]]:o[e[b]]),k.appendNode(new x3dom.DoublyLinkedList.ListNode(t[e[b]],e[b],G.normals,G.colors,G.texCoords));else{var z=x3dom.EarClipping.getMultiIndexes(k);for(S=0;S<z.indices.length;S++)this._mesh._indices[0].push(E),E++,this._mesh._positions[0].push(z.point[S].x,z.point[S].y,z.point[S].z),d&&this._mesh._normals[0].push(z.normals[S].x,z.normals[S].y,z.normals[S].z),u&&(this._mesh._colors[0].push(z.colors[S].r,z.colors[S].g,z.colors[S].b),4===U&&this._mesh._colors[0].push(z.colors[S].a)),h&&(this._mesh._texCoords[0].push(z.texCoords[S].x,z.texCoords[S].y),3===v&&this._mesh._texCoords[0].push(z.texCoords[S].z));k=new x3dom.DoublyLinkedList,M++}this._mesh.splitMesh()}d||this._mesh.calcNormals(this._vf.creaseAngle,this._vf.ccw),h||this._mesh.calcTexCoords(g)}else{if(F=0,this._vf.convex)for(b=0;b<e.length;++b)if(-1!=e[b])switch(F){case 0:R=+e[b],F=1;break;case 1:D=+e[b],F=2;break;case 2:N=+e[b],F=3,this._mesh._indices[0].push(R,D,N);break;case 3:D=N,N=+e[b],this._mesh._indices[0].push(R,D,N)}else F=0;else for(k=new x3dom.DoublyLinkedList,b=0;b<e.length;++b)if(-1!=e[b])k.appendNode(new x3dom.DoublyLinkedList.ListNode(t[e[b]],e[b]));else{var H=x3dom.EarClipping.getIndexes(k);for(S=0;S<H.length;S++)this._mesh._indices[0].push(H[S]);k=new x3dom.DoublyLinkedList}this._mesh._positions[0]=t.toGL(),d?this._mesh._normals[0]=i.toGL():this._mesh.calcNormals(this._vf.creaseAngle,this._vf.ccw),h?(this._mesh._texCoords[0]=o.toGL(),this._mesh._numTexComponents=v):this._mesh.calcTexCoords(g),u&&(this._mesh._colors[0]=s.toGL(),this._mesh._numColComponents=U)}for(this.invalidateVolume(),this._mesh._numFaces=0,this._mesh._numCoords=0,b=0;b<this._mesh._positions.length;b++){var j=this._mesh._indices[b].length,W=this._mesh._positions[b].length/3;this._mesh._numCoords+=W,this._mesh._numFaces+=j>0?j/3:W/3}},fieldChanged:function(e){if("coord"==e||"normal"==e||"texCoord"==e||"color"==e||"coordIndex"==e){var t=this._cf.coord.node._vf.point,i=t.length,o=this._cf.texCoord.node;if(x3dom.isa(o,x3dom.nodeTypes.MultiTextureCoordinate)&&o._cf.texCoord.nodes.length&&(o=o._cf.texCoord.nodes[0]),(this._vf.creaseAngle<=x3dom.fields.Eps||i>x3dom.Utils.maxIndexableCoords||this._vf.normalIndex.length>0&&this._cf.normal.node||this._vf.texCoordIndex.length>0&&o||this._vf.colorIndex.length>0&&this._cf.color.node)&&this._mesh._multiIndIndices){var s=!this._cf.normal.node&&"none"!=this._vf.normalUpdateMode.toLowerCase();if(i=this._mesh._multiIndIndices.length,this._mesh._positions[0]=[],this._mesh._indices[0]=[],"coord"==e&&i){for(s&&(this._mesh._normals[0]=[]),V=0;V<i;V+=3){var r=this._mesh._multiIndIndices[V],n=this._mesh._multiIndIndices[V+1],a=this._mesh._multiIndIndices[V+2],d=t[r],l=t[n],h=t[a];if(this._mesh._positions[0].push(d.x,d.y,d.z),this._mesh._positions[0].push(l.x,l.y,l.z),this._mesh._positions[0].push(h.x,h.y,h.z),s){var f=d.subtract(l),u=l.subtract(h),c=f.cross(u).normalize();this._vf.ccw||(c=c.negate()),this._mesh._normals[0].push(c.x,c.y,c.z),this._mesh._normals[0].push(c.x,c.y,c.z),this._mesh._normals[0].push(c.x,c.y,c.z)}}return this.invalidateVolume(),void this._parentNodes.forEach((function(e){e._dirty.positions=!0,s&&(e._dirty.normals=!0)}))}this._mesh._normals[0]=[],this._mesh._texCoords[0]=[],this._mesh._colors[0]=[];var _,m,p,x,g=this._vf.coordIndex,v=this._vf.normalIndex,y=this._vf.texCoordIndex,T=this._vf.colorIndex,b=!1,S=!1,F=!1,E=!1,M=!1,C=!1,w=this._vf.colorPerVertex,A=this._vf.normalPerVertex;v.length>0&&(S=!0),y.length>0&&(E=!0),T.length>0&&(C=!0);var R=this._cf.coord.node;x3dom.debug.assert(R),_=R.getPoints();var D=this._cf.normal.node;D?(b=!0,m=D._vf.vector):b=!1;var N="",I=2;if(o=this._cf.texCoord.node,x3dom.isa(o,x3dom.nodeTypes.MultiTextureCoordinate)&&o._cf.texCoord.nodes.length&&(o=o._cf.texCoord.nodes[0]),o)if(o._vf.point){if(F=!0,p=o._vf.point,!E){var P=p.length;for(V=P;V<_.length;V++)p.push(p[V%P])}x3dom.isa(o,x3dom.nodeTypes.TextureCoordinate3D)&&(I=3)}else o._vf.mode&&(N=o._vf.mode);else F=!1;this._mesh._numTexComponents=I;var V,L,O,B,U,X,k,G,z,H,j,W,Y,q,Q,K,Z,J=3,$=this._cf.color.node;if($?(M=!0,x=$._vf.color,x3dom.isa($,x3dom.nodeTypes.ColorRGBA)&&(J=4)):M=!1,this._mesh._numColComponents=J,this._vf.convex)for(O=0,B=0,U=0,this._mesh._multiIndIndices=[],this._mesh._posSize=_.length,V=0;V<g.length;++V)if(-1!=g[V])switch(S&&x3dom.debug.assert(-1!=v[V]),E&&x3dom.debug.assert(-1!=y[V]),C&&x3dom.debug.assert(-1!=T[V]),O){case 0:X=+g[V],z=S&&A?+v[V]:S&&!A?+v[U]:A?X:U,W=E?+y[V]:X,Q=C&&w?+T[V]:C&&!w?+T[U]:w?X:U,O=1;break;case 1:k=+g[V],H=S&&A?+v[V]:S&&!A?+v[U]:A?k:U,Y=E?+y[V]:k,K=C&&w?+T[V]:C&&!w?+T[U]:w?k:U,O=2;break;case 2:G=+g[V],j=S&&A?+v[V]:S&&!A?+v[U]:A?G:U,q=E?+y[V]:G,Z=C&&w?+T[V]:C&&!w?+T[U]:w?G:U,O=3,this._mesh._positions[0].push(_[X].x),this._mesh._positions[0].push(_[X].y),this._mesh._positions[0].push(_[X].z),this._mesh._positions[0].push(_[k].x),this._mesh._positions[0].push(_[k].y),this._mesh._positions[0].push(_[k].z),this._mesh._positions[0].push(_[G].x),this._mesh._positions[0].push(_[G].y),this._mesh._positions[0].push(_[G].z),b&&(this._mesh._normals[0].push(m[z].x),this._mesh._normals[0].push(m[z].y),this._mesh._normals[0].push(m[z].z),this._mesh._normals[0].push(m[H].x),this._mesh._normals[0].push(m[H].y),this._mesh._normals[0].push(m[H].z),this._mesh._normals[0].push(m[j].x),this._mesh._normals[0].push(m[j].y),this._mesh._normals[0].push(m[j].z)),this._mesh._multiIndIndices.push(X,k,G),M&&(this._mesh._colors[0].push(x[Q].r),this._mesh._colors[0].push(x[Q].g),this._mesh._colors[0].push(x[Q].b),4===J&&this._mesh._colors[0].push(x[Q].a),this._mesh._colors[0].push(x[K].r),this._mesh._colors[0].push(x[K].g),this._mesh._colors[0].push(x[K].b),4===J&&this._mesh._colors[0].push(x[K].a),this._mesh._colors[0].push(x[Z].r),this._mesh._colors[0].push(x[Z].g),this._mesh._colors[0].push(x[Z].b),4===J&&this._mesh._colors[0].push(x[Z].a)),F&&(this._mesh._texCoords[0].push(p[W].x),this._mesh._texCoords[0].push(p[W].y),3===I&&this._mesh._texCoords[0].push(p[W].z),this._mesh._texCoords[0].push(p[Y].x),this._mesh._texCoords[0].push(p[Y].y),3===I&&this._mesh._texCoords[0].push(p[Y].z),this._mesh._texCoords[0].push(p[q].x),this._mesh._texCoords[0].push(p[q].y),3===I&&this._mesh._texCoords[0].push(p[q].z));break;case 3:k=G,Y=q,A&&(H=j),w&&(K=Z),G=+g[V],S&&A?j=+v[V]:S&&!A||(j=A?G:U),q=E?+y[V]:G,C&&w?Z=+T[V]:C&&!w||(Z=w?G:U),this._mesh._positions[0].push(_[X].x),this._mesh._positions[0].push(_[X].y),this._mesh._positions[0].push(_[X].z),this._mesh._positions[0].push(_[k].x),this._mesh._positions[0].push(_[k].y),this._mesh._positions[0].push(_[k].z),this._mesh._positions[0].push(_[G].x),this._mesh._positions[0].push(_[G].y),this._mesh._positions[0].push(_[G].z),b&&(this._mesh._normals[0].push(m[z].x),this._mesh._normals[0].push(m[z].y),this._mesh._normals[0].push(m[z].z),this._mesh._normals[0].push(m[H].x),this._mesh._normals[0].push(m[H].y),this._mesh._normals[0].push(m[H].z),this._mesh._normals[0].push(m[j].x),this._mesh._normals[0].push(m[j].y),this._mesh._normals[0].push(m[j].z)),this._mesh._multiIndIndices.push(X,k,G),M&&(this._mesh._colors[0].push(x[Q].r),this._mesh._colors[0].push(x[Q].g),this._mesh._colors[0].push(x[Q].b),4===J&&this._mesh._colors[0].push(x[Q].a),this._mesh._colors[0].push(x[K].r),this._mesh._colors[0].push(x[K].g),this._mesh._colors[0].push(x[K].b),4===J&&this._mesh._colors[0].push(x[K].a),this._mesh._colors[0].push(x[Z].r),this._mesh._colors[0].push(x[Z].g),this._mesh._colors[0].push(x[Z].b),4===J&&this._mesh._colors[0].push(x[Z].a)),F&&(this._mesh._texCoords[0].push(p[W].x),this._mesh._texCoords[0].push(p[W].y),3===I&&this._mesh._texCoords[0].push(p[W].z),this._mesh._texCoords[0].push(p[Y].x),this._mesh._texCoords[0].push(p[Y].y),3===I&&this._mesh._texCoords[0].push(p[Y].z),this._mesh._texCoords[0].push(p[q].x),this._mesh._texCoords[0].push(p[q].y),3===I&&this._mesh._texCoords[0].push(p[q].z))}else O=0,U++;else{var ee=new x3dom.DoublyLinkedList,te={};for(B=0,U=0,V=0;V<g.length;++V)if(-1!=g[V])b&&(te.normals=S&&A?m[v[V]]:S&&!A?m[v[U]]:m[g[V]]),M&&(te.colors=C&&w?x[T[V]]:C&&!w?x[T[U]]:x[g[V]]),F&&(te.texCoords=E?p[y[V]]:p[g[V]]),ee.appendNode(new x3dom.DoublyLinkedList.ListNode(_[g[V]],g[V],te.normals,te.colors,te.texCoords));else{var ie=x3dom.EarClipping.getMultiIndexes(ee);for(L=0;L<ie.indices.length;L++)this._mesh._indices[0].push(B),B++,this._mesh._positions[0].push(ie.point[L].x,ie.point[L].y,ie.point[L].z),b&&this._mesh._normals[0].push(ie.normals[L].x,ie.normals[L].y,ie.normals[L].z),M&&(this._mesh._colors[0].push(ie.colors[L].r,ie.colors[L].g,ie.colors[L].b),4===J&&this._mesh._colors[0].push(ie.colors[L].a)),F&&(this._mesh._texCoords[0].push(ie.texCoords[L].x,ie.texCoords[L].y),3===I&&this._mesh._texCoords[0].push(ie.texCoords[L].z));ee=new x3dom.DoublyLinkedList,U++}this._mesh.splitMesh()}for(b||this._mesh.calcNormals(this._vf.creaseAngle,this._vf.ccw),F||this._mesh.calcTexCoords(N),this.invalidateVolume(),this._mesh._numFaces=0,this._mesh._numCoords=0,V=0;V<this._mesh._positions.length;V++){var oe=this._mesh._indices[V].length,se=this._mesh._positions[V].length/3;this._mesh._numCoords+=se,this._mesh._numFaces+=oe>0?oe/3:se/3}this._parentNodes.forEach((function(e){e.setGeoDirty()}))}else if("coord"==e){s=!this._cf.normal.node&&"none"!=this._vf.normalUpdateMode.toLowerCase();this._mesh._positions[0]=t.toGL(),s&&this._mesh.calcNormals(this._vf.creaseAngle,this._vf.ccw),this.invalidateVolume(),this._parentNodes.forEach((function(e){e._dirty.positions=!0,s&&(e._dirty.normals=!0),e.invalidateVolume()}))}else if("color"==e)t=this._cf.color.node._vf.color,this._mesh._colors[0]=t.toGL(),this._parentNodes.forEach((function(e){e._dirty.colors=!0}));else if("normal"==e)t=this._cf.normal.node._vf.vector,this._mesh._normals[0]=t.toGL(),this._parentNodes.forEach((function(e){e._dirty.normals=!0}));else if("texCoord"==e)o=this._cf.texCoord.node,x3dom.isa(o,x3dom.nodeTypes.MultiTextureCoordinate)&&o._cf.texCoord.nodes.length&&(o=o._cf.texCoord.nodes[0]),t=o._vf.point,this._mesh._texCoords[0]=t.toGL(),this._parentNodes.forEach((function(e){e._dirty.texcoords=!0}));else if("coordIndex"==e){for(s=!this._cf.normal.node&&"none"!=this._vf.normalUpdateMode.toLowerCase(),O=0,i=(g=this._vf.coordIndex).length,this._mesh._indices[0]=[],V=0;V<i;++V)if(-1==g[V])O=0;else switch(O){case 0:X=+g[V],O=1;break;case 1:k=+g[V],O=2;break;case 2:G=+g[V],O=3,this._mesh._indices[0].push(X,k,G);break;case 3:k=G,G=+g[V],this._mesh._indices[0].push(X,k,G)}s&&this._mesh.calcNormals(this._vf.creaseAngle,this._vf.ccw),this._parentNodes.forEach((function(e){e._dirty.indexes=!0,s&&(e._dirty.normals=!0)}))}}else x3dom.debug.logWarning("IndexedFaceSet: fieldChanged for "+e+" not yet implemented!")}})),x3dom.registerNodeType("BufferGeometry","Geometry3D",defineClass(x3dom.nodeTypes.X3DBinaryContainerGeometryNode,(function(e){x3dom.nodeTypes.BufferGeometry.superClass.call(this,e),this.addField_SFString(e,"buffer",""),this.addField_MFNode("views",x3dom.nodeTypes.BufferView),this.addField_MFNode("accessors",x3dom.nodeTypes.BufferAccessor),this._hasColor=!1,this._hasMultiTexCoord=!1,this._indexed=!1}),{parentAdded:function(e){},nodeChanged:function(){},doIntersect:function(e){var t=this.getMin(),i=this.getMax();return!!(e.intersect(t,i)&&e.enter<e.dist)&&(e.dist=e.enter,e.hitObject=this,e.hitPoint=e.pos.add(e.dir.multiply(e.enter)),!0)},hasColor:function(){return this._hasColor},hasMultiTexCoord:function(){return this._hasMultiTexCoord},getPrecisionMax:function(e){switch(this._vf[e]){case"Int8":return 127;case"Uint8":return 255;case"Int16":return 32767;case"Uint16":return 65535;case"Int32":return 2147483647;case"Uint32":return 4294967295;case"Float32":case"Float64":default:return 1}}})),x3dom.registerNodeType("BufferView","Geometry3D",defineClass(x3dom.nodeTypes.X3DNode,(function(e){x3dom.nodeTypes.BufferView.superClass.call(this,e),this.addField_SFInt32(e,"target",34962),this.addField_SFInt32(e,"byteOffset",0),this.addField_SFInt32(e,"byteStride",0),this.addField_SFInt32(e,"byteLength",0),this.addField_SFInt32(e,"id",0)}),{parentAdded:function(e){}})),x3dom.registerNodeType("BufferAccessor","Geometry3D",defineClass(x3dom.nodeTypes.X3DNode,(function(e){x3dom.nodeTypes.BufferAccessor.superClass.call(this,e),this.addField_SFString(e,"bufferType",""),this.addField_SFInt32(e,"view",0),this.addField_SFInt32(e,"byteOffset",0),this.addField_SFInt32(e,"byteStride",0),this.addField_SFInt32(e,"components",0),this.addField_SFInt32(e,"componentType",5126),this.addField_SFInt32(e,"count",0),this.addField_SFBool(e,"normalized",!1)}),{parentAdded:function(e){switch(this._vf.bufferType){case"COLOR_0":case"COLOR":e._hasColor=!0;break;case"INDEX":e._indexed=!0;break;case"TEXCOORD_1":e._hasMultiTexCoord=!0}}})),x3dom.registerNodeType("X3DTexture3DNode","Texturing3D",defineClass(x3dom.nodeTypes.X3DTextureNode,(function(e){x3dom.nodeTypes.X3DTexture3DNode.superClass.call(this,e)}))),x3dom.registerNodeType("ComposedTexture3D","Texturing3D",defineClass(x3dom.nodeTypes.X3DTexture3DNode,(function(e){x3dom.nodeTypes.ComposedTexture3D.superClass.call(this,e),this.addField_MFNode("texture",x3dom.nodeTypes.X3DTexture3DNode)}))),x3dom.registerNodeType("ImageTexture3D","Texturing3D",defineClass(x3dom.nodeTypes.X3DTexture3DNode,(function(e){x3dom.nodeTypes.ImageTexture3D.superClass.call(this,e)}))),x3dom.registerNodeType("PixelTexture3D","Texturing3D",defineClass(x3dom.nodeTypes.X3DTexture3DNode,(function(e){x3dom.nodeTypes.PixelTexture3D.superClass.call(this,e)}))),x3dom.registerNodeType("TextureCoordinate3D","Texturing3D",defineClass(x3dom.nodeTypes.X3DTextureCoordinateNode,(function(e){x3dom.nodeTypes.TextureCoordinate3D.superClass.call(this,e),this.addField_MFVec3f(e,"point",[])}))),x3dom.registerNodeType("TextureTransform3D","Texturing3D",defineClass(x3dom.nodeTypes.X3DTextureTransformNode,(function(e){x3dom.nodeTypes.TextureTransform3D.superClass.call(this,e),this.addField_SFVec3f(e,"center",0,0,0),this.addField_SFRotation(e,"rotation",0,0,1,0),this.addField_SFVec3f(e,"scale",1,1,1),this.addField_SFVec3f(e,"translation",0,0,0),this.addField_SFRotation(e,"scaleOrientation",0,0,1,0)}))),x3dom.registerNodeType("TextureTransformMatrix3D","Texturing3D",defineClass(x3dom.nodeTypes.X3DTextureTransformNode,(function(e){x3dom.nodeTypes.TextureTransformMatrix3D.superClass.call(this,e),this.addField_SFMatrix4f(e,"matrix",1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)}))),x3dom.registerNodeType("X3DPointingDeviceSensorNode","PointingDeviceSensor",defineClass(x3dom.nodeTypes.X3DSensorNode,(function(e){x3dom.nodeTypes.X3DPointingDeviceSensorNode.superClass.call(this,e),this._isOver=!1}),{pointerPressedOverSibling:function(e){this._vf.enabled&&(this._vf.isActive=!0,this.postMessage("isActive",!0),this._isOver=!0)},pointerMoved:function(e){},pointerMovedOver:function(e){this._vf.enabled&&this.postMessage("isOver",!0)},pointerMovedOut:function(e){this._vf.enabled&&(this.postMessage("isOver",!1),this._isOver=!1)},pointerReleased:function(){this._vf.enabled&&(this._vf.isActive=!1,this.postMessage("isActive",!1),this._isOver&&this.postMessage("touchTime",Date.now()/1e3))}})),x3dom.registerNodeType("X3DDragSensorNode","PointingDeviceSensor",defineClass(x3dom.nodeTypes.X3DPointingDeviceSensorNode,(function(e){x3dom.nodeTypes.X3DDragSensorNode.superClass.call(this,e),this.addField_SFBool(e,"autoOffset",!0),this._lastX=-1,this._lastY=-1}),{pointerPressedOverSibling:function(e){x3dom.nodeTypes.X3DPointingDeviceSensorNode.prototype.pointerPressedOverSibling.call(this,e),this._lastX=e.layerX,this._lastY=e.layerY,this._startDragging(e.viewarea,e.layerX,e.layerX,e.worldX,e.worldY,e.worldZ)},pointerMoved:function(e){x3dom.nodeTypes.X3DPointingDeviceSensorNode.prototype.pointerMoved.call(this,e),this._vf.isActive&&this._vf.enabled&&this._process2DDrag(e.layerX,e.layerY,e.layerX-this._lastX,e.layerY-this._lastY)},pointerReleased:function(){x3dom.nodeTypes.X3DPointingDeviceSensorNode.prototype.pointerReleased.call(this),this._stopDragging()},_startDragging:function(e,t,i,o,s,r){},_process2DDrag:function(e,t,i,o){},_stopDragging:function(){}})),x3dom.registerNodeType("X3DTouchSensorNode","PointingDeviceSensor",defineClass(x3dom.nodeTypes.X3DPointingDeviceSensorNode,(function(e){x3dom.nodeTypes.X3DTouchSensorNode.superClass.call(this,e)}),{})),x3dom.registerNodeType("TouchSensor","PointingDeviceSensor",defineClass(x3dom.nodeTypes.X3DTouchSensorNode,(function(e){x3dom.nodeTypes.TouchSensor.superClass.call(this,e),this._hitPoint=new x3dom.fields.SFVec3f,this._hitNormal=new x3dom.fields.SFVec3f,this._hitRotation=new x3dom.fields.Quaternion,this._up=new x3dom.fields.SFVec3f(0,1,0)}),{pointerMoved:function(e){this._vf.enabled&&(this.postMessage("hitPoint_changed",this._hitPoint.fromArray(e.hitPnt)),this._hitNormal.set(e.normalX,e.normalY,e.normalZ),this.postMessage("hitNormal_changed",this._hitNormal),this.postMessage("hitRotation_changed",x3dom.fields.Quaternion.rotateFromTo(this._up,this._hitNormal)))}})),x3dom.registerNodeType("PlaneSensor","PointingDeviceSensor",defineClass(x3dom.nodeTypes.X3DDragSensorNode,(function(e){x3dom.nodeTypes.PlaneSensor.superClass.call(this,e),this.addField_SFRotation(e,"axisRotation",0,0,1,0),this.addField_SFVec2f(e,"minPosition",0,0),this.addField_SFVec2f(e,"maxPosition",-1,-1),this.addField_SFVec3f(e,"offset",0,0,0),this.addField_SFString(e,"planeOrientation","XY"),this._rotationMatrix=this._vf.axisRotation.toMatrix(),this._worldToLocalMatrix=null,this._initialPlaneIntersection=null,this._planeNormal=null,this._viewArea=null,this._currentTranslation=new x3dom.fields.SFVec3f(0,0,0),this._lineModeAxis=null,this._vf.minPosition.x==this._vf.maxPosition.x&&(this._lineModeAxis=new x3dom.fields.SFVec3f(0,1,0)),this._vf.minPosition.y==this._vf.maxPosition.y&&(this._lineModeAxis=new x3dom.fields.SFVec3f(1,0,0))}),{getCurrentTransform:function(){var e=x3dom.nodeTypes.X3DDragSensorNode.prototype.getCurrentTransform.call(this);return this._rotationMatrix.mult(e)},_startDragging:function(e,t,i,o,s,r){var n;if(x3dom.nodeTypes.X3DDragSensorNode.prototype._startDragging.call(this,e,t,i,o,s,r),this._viewArea=e,this._viewMat=this._viewArea.getViewMatrix(),this._viewMatInv=this._viewMat.inverse(),this._currentTranslation=new x3dom.fields.SFVec3f(0,0,0).add(this._vf.offset),this._localToWorldMatrix=this.getCurrentTransform(),this._worldToLocalMatrix=this._localToWorldMatrix.inverse(),this._initialPlaneIntersection=this._worldToLocalMatrix.multMatrixPnt(new x3dom.fields.SFVec3f(o,s,r)),this._planeNormal=new x3dom.fields.SFVec3f(0,0,1),"screen"==this._vf.planeOrientation)n=e.calcViewRay(e._width/2,e._height/2),this._planeNormal=this._worldToLocalMatrix.multMatrixVec(n.dir.normalize());else if(this._lineModeAxis){n=e.calcViewRay(t,i);var a=this._worldToLocalMatrix.multMatrixVec(n.dir.normalize()),d=this._lineModeAxis;this._planeNormal=d.cross(d.cross(a))}},_process2DDrag:function(e,t,i,o){x3dom.nodeTypes.X3DDragSensorNode.prototype._process2DDrag.call(this,e,t,i,o);var s,r,n=null;if(this._initialPlaneIntersection){var a=this._viewArea.calcViewRay(e,t);if(a.pos=this._worldToLocalMatrix.multMatrixPnt(a.pos),a.dir=this._worldToLocalMatrix.multMatrixVec(a.dir.normalize()),Math.abs(this._planeNormal.dot(a.dir))<.1)return;if((n=a.intersectPlane(this._initialPlaneIntersection,this._planeNormal))||(n=a.intersectPlane(this._initialPlaneIntersection,this._planeNormal.negate())),n){if(this._currentTranslation=n.subtract(this._initialPlaneIntersection),this._currentTranslation=this._currentTranslation.add(this._vf.offset),s=this._vf.minPosition,r=this._vf.maxPosition,"screen"==this._vf.planeOrientation){if(s.x<=r.x||s.y<=r.y){var d=this._localToWorldMatrix.multMatrixVec(this._currentTranslation);l(d=this._viewMat.multMatrixVec(d),s,r),d=this._viewMatInv.multMatrixVec(d),this._currentTranslation=this._worldToLocalMatrix.multMatrixVec(d)}}else l(this._currentTranslation,s,r),this._currentTranslation.z=0;this.postMessage("translation_changed",x3dom.fields.SFVec3f.copy(this._currentTranslation)),this.postMessage("trackPoint_changed",n)}}function l(e,t,i){t.x<=i.x&&(e.x=Math.min(e.x,i.x),e.x=Math.max(e.x,t.x)),t.y<=i.y&&(e.y=Math.min(e.y,i.y),e.y=Math.max(e.y,t.y))}},_stopDragging:function(){x3dom.nodeTypes.X3DDragSensorNode.prototype._stopDragging.call(this),this._vf.autoOffset&&(this._vf.offset=x3dom.fields.SFVec3f.copy(this._currentTranslation),this.postMessage("offset_changed",this._vf.offset))}})),x3dom.registerNodeType("SphereSensor","PointingDeviceSensor",defineClass(x3dom.nodeTypes.X3DDragSensorNode,(function(e){x3dom.nodeTypes.SphereSensor.superClass.call(this,e),this.addField_SFRotation(e,"offset",0,1,0,0),this._currentRotation=null,this._rotationMatrix=this._vf.offset.toMatrix()}),{getCurrentTransform:function(){return x3dom.nodeTypes.X3DDragSensorNode.prototype.getCurrentTransform.call(this).mult(this._rotationMatrix)},_startDragging:function(e,t,i,o,s,r){x3dom.nodeTypes.X3DDragSensorNode.prototype._startDragging.call(this,e,t,i,o,s,r),this._currentRotation=new x3dom.fields.Quaternion,this._viewArea=e,this._localOrigin=new x3dom.fields.SFVec3f(0,0,0),this._inverseToWorldMatrix=this.getCurrentTransform().inverse();var n=this._inverseToWorldMatrix.multMatrixPnt(new x3dom.fields.SFVec3f(o,s,r));this._initialSphereIntersectionVector=n.subtract(this._localOrigin),this._sphereRadius=this._initialSphereIntersectionVector.length(),this._initialSphereIntersectionVector=this._initialSphereIntersectionVector.normalize()},_process2DDrag:function(e,t,i,o){x3dom.nodeTypes.X3DDragSensorNode.prototype._process2DDrag.call(this,e,t,i,o);var s=this._viewArea.calcViewRay(e,t);s.pos=this._inverseToWorldMatrix.multMatrixPnt(s.pos),s.dir=this._inverseToWorldMatrix.multMatrixVec(s.dir);var r,n,a=s.dir.dot(s.dir),d=2*s.dir.dot(s.pos.subtract(this._localOrigin)),l=d*d-4*a*(s.pos.dot(s.pos)-2*this._localOrigin.dot(s.pos)+this._localOrigin.dot(this._localOrigin)-this._sphereRadius*this._sphereRadius);if(l>=0&&(r=(-d+Math.sqrt(l))/(2*a),n=(-d-Math.sqrt(l))/(2*a),(r=Math.min(r,n))>=1)){var h=s.pos.add(s.dir.multiply(r)).subtract(this._localOrigin).normalize();this._currentRotation=x3dom.fields.Quaternion.rotateFromTo(this._initialSphereIntersectionVector,h),this._currentRotation=this._currentRotation.multiply(this._vf.offset),this.postMessage("rotation_changed",this._currentRotation)}},_stopDragging:function(){x3dom.nodeTypes.X3DDragSensorNode.prototype._stopDragging.call(this),this._vf.autoOffset&&(this._vf.offset=this._currentRotation,this.postMessage("offset_changed",this._vf.offset)),this._currentRotation=new x3dom.fields.Quaternion}})),x3dom.registerNodeType("CylinderSensor","PointingDeviceSensor",defineClass(x3dom.nodeTypes.X3DDragSensorNode,(function(e){x3dom.nodeTypes.CylinderSensor.superClass.call(this,e),this.addField_SFFloat(e,"offset",0),this.addField_SFRotation(e,"axisRotation",0,1,0,0),this.addField_SFFloat(e,"diskAngle",.262),this.addField_SFFloat(e,"minAngle",0),this.addField_SFFloat(e,"maxAngle",-1),this._rotationMatrix=this._vf.axisRotation.toMatrix(),this._inverseToWorldMatrix=null,this._initialCylinderIntersectionVector=null,this._viewArea=null,this._cylinderRadius=0,this._yAxisLine=null,this._cylinderMode=!0,this._currentRotationAngle=0}),{getCurrentTransform:function(){return x3dom.nodeTypes.X3DDragSensorNode.prototype.getCurrentTransform.call(this).mult(this._rotationMatrix)},_startDragging:function(e,t,i,o,s,r){x3dom.nodeTypes.X3DDragSensorNode.prototype._startDragging.call(this,e,t,i,o,s,r),this._currentRotation=new x3dom.fields.Quaternion,this._viewArea=e,this._yAxisLine=new x3dom.fields.Line(new x3dom.fields.SFVec3f(0,0,0),new x3dom.fields.SFVec3f(0,1,0)),this._inverseToWorldMatrix=this.getCurrentTransform().inverse();var n=this._inverseToWorldMatrix.multMatrixPnt(new x3dom.fields.SFVec3f(o,s,r)),a=this._yAxisLine.closestPoint(n);this._initialCylinderIntersectionVector=n.subtract(a),this._cylinderRadius=this._initialCylinderIntersectionVector.length(),this._initialCylinderIntersectionVector=this._initialCylinderIntersectionVector.normalize()},_process2DDrag:function(e,t,i,o){if(x3dom.nodeTypes.X3DDragSensorNode.prototype._process2DDrag.call(this,e,t,i,o),this._cylinderMode){var s=this._viewArea.calcViewRay(e,t);s.pos=this._inverseToWorldMatrix.multMatrixPnt(s.pos),s.dir=this._inverseToWorldMatrix.multMatrixVec(s.dir);var r,n,a=s.dir.subtract(this._yAxisLine.dir.multiply(s.dir.dot(this._yAxisLine.dir))),d=s.pos.subtract(this._yAxisLine.pos).add(this._yAxisLine.dir.multiply(this._yAxisLine.dir.dot(this._yAxisLine.pos.subtract(s.pos)))),l=2*a.dot(d)/a.dot(a),h=l*l*.25-(d.dot(d)-this._cylinderRadius*this._cylinderRadius)/a.dot(a);if(h>=0&&(r=.5*-l+(h=Math.sqrt(h)),n=.5*-l-h,(r=Math.min(r,n))>0)){var f=s.pos.add(s.dir.multiply(r)),u=this._yAxisLine.closestPoint(f),c=f.subtract(u).normalize();this._currentRotation=x3dom.fields.Quaternion.rotateFromTo(this._initialCylinderIntersectionVector,c);var _=x3dom.fields.Quaternion.axisAngle(this._yAxisLine.dir,this._vf.offset);this._currentRotation=this._currentRotation.multiply(_),this.postMessage("rotation_changed",this._currentRotation)}}},_stopDragging:function(){x3dom.nodeTypes.X3DDragSensorNode.prototype._stopDragging.call(this),this._vf.autoOffset&&(this._vf.offset=this._currentRotation.angle(),this.postMessage("offset_changed",this._vf.offset))}})),x3dom.registerNodeType("X3DSequencerNode","EventUtilities",defineClass(x3dom.nodeTypes.X3DChildNode,(function(e){x3dom.nodeTypes.X3DSequencerNode.superClass.call(this,e),this.addField_SFBool(e,"next",!1),this.addField_SFBool(e,"previous",!1),this.addField_MFFloat(e,"key",[]),this.addField_SFFloat(e,"set_fraction",0),this._keyIndex=-1,this._key_changed=!1,this._keyValue_changed=!1}),{findInterval:function(e){var t=this._vf.key.length-1;if(e<this._vf.key[0])return 0;if(e>=this._vf.key[t])return t;for(var i=0;i<t;++i)if(this._vf.key[i]<=e&&e<this._vf.key[i+1])return i;return 0},fieldChanged:function(e){if("set_fraction"!==e)return"next"===e&&this._vf.next?(this._keyIndex=(this._keyIndex+1)%this._vf.key.length,void this.postMessage("value_changed",this._vf.keyValue[this._keyIndex])):"previous"===e&&this._vf.previous?(this._keyIndex=(this._keyIndex-1+this._vf.key.length)%this._vf.key.length,void this.postMessage("value_changed",this._vf.keyValue[this._keyIndex])):"key"===e?this._key_changed?void(this._key_changed=!1):(this._key_changed=!0,void this.postMessage("key",this._vf.key)):"keyValue"===e?this._keyValue_changed?void(this._keyValue_changed=!1):(this._keyValue_changed=!0,void this.postMessage("keyValue",this._vf.keyValue)):void 0;var t=this.findInterval(this._vf.set_fraction);t!==this._keyIndex&&(this._keyIndex=t,this.postMessage("value_changed",this._vf.keyValue[t]))}})),x3dom.registerNodeType("X3DTriggerNode","EventUtilities",defineClass(x3dom.nodeTypes.X3DChildNode,(function(e){x3dom.nodeTypes.X3DTriggerNode.superClass.call(this,e)}))),x3dom.registerNodeType("BooleanFilter","EventUtilities",defineClass(x3dom.nodeTypes.X3DChildNode,(function(e){x3dom.nodeTypes.BooleanFilter.superClass.call(this,e),this.addField_SFBool(e,"set_boolean"),this.addField_SFBool(e,"inputFalse"),this.addField_SFBool(e,"inputTrue"),this.addField_SFBool(e,"inputNegate")}),{fieldChanged:function(e){if("set_boolean"===e){var t=this._vf.set_boolean;return this._vf.inputNegate=!t,this.postMessage("inputNegate",!t),t?(this._vf.inputTrue=!0,void this.postMessage("inputTrue",!0)):(this._vf.inputFalse=!1,void this.postMessage("inputFalse",!1))}}})),x3dom.registerNodeType("BooleanSequencer","EventUtilities",defineClass(x3dom.nodeTypes.X3DSequencerNode,(function(e){x3dom.nodeTypes.BooleanSequencer.superClass.call(this,e),this.addField_MFBoolean(e,"keyValue",[])}),{})),x3dom.registerNodeType("BooleanToggle","EventUtilities",defineClass(x3dom.nodeTypes.X3DChildNode,(function(e){x3dom.nodeTypes.BooleanToggle.superClass.call(this,e),this.addField_SFBool(e,"set_boolean"),this.addField_SFBool(e,"toggle",!1)}),{fieldChanged:function(e){if("set_boolean"!==e)"toggle"===e&&this.postMessage("toggle",this._vf.toggle);else if(this._vf.set_boolean){var t=!this._vf.toggle;this._vf.toggle=t,this.postMessage("toggle",t)}}})),x3dom.registerNodeType("BooleanTrigger","EventUtilities",defineClass(x3dom.nodeTypes.X3DTriggerNode,(function(e){x3dom.nodeTypes.BooleanTrigger.superClass.call(this,e),this.addField_SFTime(e,"set_triggerTime")}),{fieldChanged:function(e){"set_triggerTime"===e&&this.postMessage("triggerTrue",!0)}})),x3dom.registerNodeType("IntegerSequencer","EventUtilities",defineClass(x3dom.nodeTypes.X3DSequencerNode,(function(e){x3dom.nodeTypes.IntegerSequencer.superClass.call(this,e),this.addField_MFInt32(e,"keyValue",[])}),{})),x3dom.registerNodeType("IntegerTrigger","EventUtilities",defineClass(x3dom.nodeTypes.X3DTriggerNode,(function(e){x3dom.nodeTypes.IntegerTrigger.superClass.call(this,e),this.addField_SFBool(e,"set_boolean"),this.addField_SFInt32(e,"integerKey",-1)}),{fieldChanged:function(e){"set_boolean"===e&&this.postMessage("triggerValue",this._vf.integerKey)}})),x3dom.registerNodeType("TimeTrigger","EventUtilities",defineClass(x3dom.nodeTypes.X3DTriggerNode,(function(e){x3dom.nodeTypes.TimeTrigger.superClass.call(this,e),this.addField_SFBool(e,"set_boolean")}),{fieldChanged:function(e){"set_boolean"===e&&this.postMessage("triggerTime",Date.now()/1e3)}}));