/* JSModeler 0.38 - http://www.github.com/kovacsv/JSModeler */ 'use strict';JSM.ResizeImageToPowerOfTwoSides=function(a){if(JSM.IsPowerOfTwo(a.width)&&!JSM.IsPowerOfTwo(a.height))return a;var b=JSM.NextPowerOfTwo(a.width),d=JSM.NextPowerOfTwo(a.height),c=document.createElement("canvas");c.width=b;c.height=d;c=c.getContext("2d");c.drawImage(a,0,0,b,d);return c.getImageData(0,0,b,d)}; JSM.ConvertBodyToThreeMeshes=function(a,b,d){var c={textureLoadedCallback:null,hasConvexPolygons:!1,doubleSided:!0};void 0!==d&&null!==d&&(c.textureLoadedCallback=JSM.ValueOrDefault(d.textureLoadedCallback,c.textureLoadedCallback),c.hasConvexPolygons=JSM.ValueOrDefault(d.hasConvexPolygons,c.hasConvexPolygons),c.doubleSided=JSM.ValueOrDefault(d.doubleSided,c.doubleSided));var f=[],e=null;JSM.ExplodeBodyToTriangles(a,b,{hasConvexPolygons:c.hasConvexPolygons,onGeometryStart:function(){e=new THREE.Geometry}, onGeometryEnd:function(a){var b=null!==a.texture,d=1!==a.opacity,v=a.ambient,G=a.diffuse,k=a.specular,l=a.shininess;0===l&&(k=0,l=1);v=new THREE.MeshPhongMaterial({ambient:v,color:G,specular:k,shininess:l});c.doubleSided&&(v.side=THREE.DoubleSide);d&&(v.opacity=a.opacity,v.transparent=!0);if(b){var m=THREE.ImageUtils.loadTexture(a.texture,new THREE.UVMapping,function(){m.image=JSM.ResizeImageToPowerOfTwoSides(m.image);null!==c.textureLoadedCallback&&c.textureLoadedCallback()});m.wrapS=THREE.RepeatWrapping; m.wrapT=THREE.RepeatWrapping;v.map=m}e.computeFaceNormals();a=new THREE.Mesh(e,v);f.push(a)},onTriangle:function(a,b,c,d,f,k,l,m,z){var n=e.vertices.length;e.vertices.push(new THREE.Vector3(a.x,a.y,a.z));e.vertices.push(new THREE.Vector3(b.x,b.y,b.z));e.vertices.push(new THREE.Vector3(c.x,c.y,c.z));a=new THREE.Face3(n+0,n+1,n+2);e.faces.push(a);null!==d&&(null!==f&&null!==k)&&(a=[],a.push(new THREE.Vector3(d.x,d.y,d.z)),a.push(new THREE.Vector3(f.x,f.y,f.z)),a.push(new THREE.Vector3(k.x,k.y,k.z)), e.faces[e.faces.length-1].vertexNormals=a);null!==l&&(null!==m&&null!==z)&&(d=[],d.push(new THREE.Vector2(l.x,-l.y)),d.push(new THREE.Vector2(m.x,-m.y)),d.push(new THREE.Vector2(z.x,-z.y)),e.faceVertexUvs[0].push(d))}});return f};JSM.ConvertModelToThreeMeshes=function(a,b,d){var c=[],f=[],e,h;for(e=0;e