This repository was archived by the owner on Sep 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathapplication.min.js
More file actions
2 lines (2 loc) · 35.1 KB
/
application.min.js
File metadata and controls
2 lines (2 loc) · 35.1 KB
1
2
var __extends,BABYLON,RW;(function(n){(function(n){"use strict";var t=function(){function t(n){this.name=n}return t.prototype.start=function(){var t=this;$(document).ready(function(){window.zip.workerScriptsPath="/vendor/zip/";t.app=angular.module(name,["ui.bootstrap","colorpicker.module","ui.slider"]).controller("CanvasController",n.CanvasController).controller("ObjectSubMeshesController",n.ObjectSubMeshesController).controller("MaterialController",n.MaterialController).controller("MaterialExportModalController",n.MaterialExportModlController).controller("TextureController",n.TextureController).service("materialService",n.MaterialService).service("canvasService",n.CanvasService).directive("textureImage",n.textureImage).directive("disableEnableButton",n.disableEnableButton);angular.bootstrap(document,[t.app.name])})},t}();n.AngularStarter=t;new t("materialEditor").start()})(n.TextureEditor||(n.TextureEditor={}));var t=n.TextureEditor})(RW||(RW={}));__extends=this.__extends||function(n,t){function r(){this.constructor=n}for(var i in t)t.hasOwnProperty(i)&&(n[i]=t[i]);r.prototype=t.prototype;n.prototype=new r},function(n){var t=function(t){function i(i,r,u){t.call(this,r);this.urls=i;this._noMipmap=u;this.coordinatesMode=n.Texture.CUBIC_MODE;this.name="ExtendedCubeTexture";this.hasAlpha=!1;this._texture||(r.useDelayedTextureLoading?this.delayLoadState=n.Engine.DELAYLOADSTATE_NOTLOADED:this._texture=this.createCubeTexture(i,this._noMipmap,r,i));this.isCube=!0;this._textureMatrix=n.Matrix.Identity()}return __extends(i,t),i.prototype.clone=function(){var i=this,t;return this.urls.forEach(function(n){i.urls.push(n)}),t=new n.ExtendedCubeTexture([],this.getScene(),this._noMipmap),t.level=this.level,t.wrapU=this.wrapU,t.wrapV=this.wrapV,t.coordinatesIndex=this.coordinatesIndex,t.coordinatesMode=this.coordinatesMode,t},i.prototype.delayLoad=function(){this.delayLoadState==n.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=n.Engine.DELAYLOADSTATE_LOADED,this._texture||(this._texture=this.createCubeTexture(this.urls,this._noMipmap,this.getScene(),this.urls)))},i.prototype.getReflectionTextureMatrix=function(){return this._textureMatrix},i.prototype.createCubeTexture=function(t,i,r,u){var s,c,l;if(t.length!=6)throw new Error("Not enough images to create a cube. Aborting.");var o=r.getEngine(),f=o._gl,e=f.createTexture();e.isCube=!0;e.url=t[0];e.references=1;o._loadedTexturesCache.push(e);var h=[],a=function(){console.log("error loadig image")},v=function(n){h.push(n);h.length==6&&y(h)},y=function(t){var u=n.Tools.GetExponantOfTwo(t[0].width,o.getCaps().maxCubemapTextureSize),s=u,h=o._workingCanvas,l=o._workingContext,c,r;for(h.width=u,h.height=s,c=[f.TEXTURE_CUBE_MAP_POSITIVE_X,f.TEXTURE_CUBE_MAP_POSITIVE_Y,f.TEXTURE_CUBE_MAP_POSITIVE_Z,f.TEXTURE_CUBE_MAP_NEGATIVE_X,f.TEXTURE_CUBE_MAP_NEGATIVE_Y,f.TEXTURE_CUBE_MAP_NEGATIVE_Z],f.bindTexture(f.TEXTURE_CUBE_MAP,e),f.pixelStorei(f.UNPACK_FLIP_Y_WEBGL,0),r=0;r<c.length;r++)l.drawImage(t[r],0,0,t[r].width,t[r].height,0,0,u,s),f.texImage2D(c[r],0,f.RGBA,f.RGBA,f.UNSIGNED_BYTE,h);i||f.generateMipmap(f.TEXTURE_CUBE_MAP);f.texParameteri(f.TEXTURE_CUBE_MAP,f.TEXTURE_MAG_FILTER,f.LINEAR);f.texParameteri(f.TEXTURE_CUBE_MAP,f.TEXTURE_MIN_FILTER,i?f.LINEAR:f.LINEAR_MIPMAP_LINEAR);f.texParameteri(f.TEXTURE_CUBE_MAP,f.TEXTURE_WRAP_S,f.CLAMP_TO_EDGE);f.texParameteri(f.TEXTURE_CUBE_MAP,f.TEXTURE_WRAP_T,f.CLAMP_TO_EDGE);f.bindTexture(f.TEXTURE_CUBE_MAP,null);o._activeTexturesCache=[];e._width=u;e._height=s;e.isReady=!0};for(s=0;s<6;s++)c=t[s],l=!1,c.substr(0,5)==="data:"&&(l=!0),l?n.Tools.LoadImage(u[s],v,a,r.database):n.Tools.LoadImage(c,v,a,r.database);return e},i}(n.BaseTexture);n.ExtendedCubeTexture=t}(BABYLON||(BABYLON={})),function(n){(function(n){var t=function(){function t(t,i,r,u){var f=this;this.$scope=t;this.$timeout=i;this.$modal=r;this.canvasService=u;this.resetLightParameters=function(t){f.$scope.light=t;f.$scope.lightSpecularColor=new n.HexToBabylon("specular",t,"");f.$scope.lightDiffuseColor=new n.HexToBabylon("diffuse",t,"")};this.objectSelected=function(){while(!f.canvasService.selectObjectInPosition(f.selectedObjectPosition.value))f.selectedObjectPosition=f.objectTypes[f.selectedObjectPosition.value+1];f.singleOutMesh&&f.singleOutChanged()};this.singleOutMesh=!1;this.lightTypes=[{name:"Hemispheric",type:0},{name:"Point (in camera position)",type:2}];this.selectedLightType=this.lightTypes[0];t.$on("sceneReset",function(){i(function(){var t=u.getObjects(),n;for(f.objectTypes=[],n=0;n<t.length;n++)f.objectTypes.push({name:t[n].name,value:n});n=0;f.selectedObjectPosition=f.objectTypes[n];f.objectSelected();f.canvasService.sceneLoadingUI(!1)})});t.$on("objectChanged",function(n,r,u){typeof u=="undefined"&&(u=!1);u&&i(function(){t.$apply(function(){f.selectedObjectPosition=f.objectTypes.filter(function(n){return n.name===r.name})[0]})})});t.$on("lightChanged",function(n,t){f.resetLightParameters(t)});t.lightConfigure=!0;this.canvasService.resetScene();this.canvasService.initLight()}return t.prototype.lightTypeChanged=function(){this.canvasService.initLight(this.selectedLightType.type)},t.prototype.fileAdded=function(){function n(n,t){return n.indexOf(t,n.length-t.length)!==-1}var f=this,e=document.getElementById("scene-input");this.canvasService.sceneLoadingUI(!0);var r=function(){var n=window.webkitURL||window.mozURL||window.URL;return{getEntries:function(n,t){window.zip.createReader(new window.zip.BlobReader(n),function(n){n.getEntries(t)},onerror)},getEntryFile:function(t,i,r,u){function o(){t.getData(f,function(u){var f=i=="Blob"?n.createObjectURL(u):e.toURL();r(t,f)},u)}var f,e;i=="Blob"&&(f=new window.zip.BlobWriter,o())}}}(),t,i=[],u=0;r.getEntries(e.files[0],function(e){e.forEach(function(t){(n(t.filename,".jpg")||n(t.filename,".png"))&&u++});e.forEach(function(e){r.getEntryFile(e,"Blob",function(r,o){n(r.filename,".babylon")?t=o:(n(r.filename,".jpg")||n(e.filename,".png"))&&i.push({originalName:r.filename,newUrl:o});i.length===u&&t&&f.canvasService.loadScene(t,i)},function(){})})})},t.prototype.resetScene=function(){this.canvasService.resetScene()},t.prototype.objectSubMeshes=function(){var n=this,t=this.$modal.open({templateUrl:"objectSubMeshes.html",controller:"ObjectSubMeshesController",size:"lg",resolve:{object:function(){return n.canvasService.getObjectInPosition(n.selectedObjectPosition.value)}}});t.result.then(function(){n.objectSelected()},function(){})},t.prototype.singleOutChanged=function(){this.canvasService.singleOut(this.singleOutMesh,this.selectedObjectPosition.value)},t.$inject=["$scope","$timeout","$modal","canvasService"],t}();n.CanvasController=t})(n.TextureEditor||(n.TextureEditor={}));var t=n.TextureEditor}(RW||(RW={})),function(n){(function(n){var t,i;(function(n){n[n.SPHERE=0]="SPHERE";n[n.BOX=1]="BOX";n[n.PLANE=2]="PLANE";n[n.CYLINDER=3]="CYLINDER";n[n.KNOT=4]="KNOT";n[n.TORUS=5]="TORUS"})(n.ObjectType||(n.ObjectType={}));t=n.ObjectType,function(n){n[n.HEMISPHERIC=0]="HEMISPHERIC";n[n.SPOT=1]="SPOT";n[n.POINT=2]="POINT"}(n.LightType||(n.LightType={}));i=n.LightType})(n.TextureEditor||(n.TextureEditor={}));var t=n.TextureEditor}(RW||(RW={})),function(n){(function(n){var t=function(){function t(n){var t=this;this.$rootScope=n;this._canvasElement=document.getElementById("renderCanvas");this._engine=new BABYLON.Engine(this._canvasElement);this._scene=new BABYLON.Scene(this._engine);this._camera=new BABYLON.ArcRotateCamera("ArcRotateCamera",10,.8,30,new BABYLON.Vector3(0,0,0),this._scene);this._camera.wheelPrecision=20;this._camera.attachControl(this._canvasElement,!1);this._engine.runRenderLoop(function(){t._scene.render()});window.addEventListener("resize",function(){t._engine.resize()});this._scene.registerBeforeRender(function(){})}return t.prototype.getLight=function(){return this._light},t.prototype.updateTexture=function(n,t){this._textureObject.material[n]=t},t.prototype.loadScene=function(n,t){for(var i=this;this._scene.meshes.pop(););BABYLON.Tools.LoadFile(n,function(n){t.forEach(function(t){var i=new RegExp(t.originalName,"g");n=n.replace(i,t.newUrl)});BABYLON.SceneLoader.ImportMesh("","","data:"+n,i._scene,function(n){n.forEach(function(n){n.material||(n.material=new BABYLON.StandardMaterial(n.name+"Mat",i._scene));n.actionManager=new BABYLON.ActionManager(i._scene);n.actionManager.registerAction(new BABYLON.SetValueAction(BABYLON.ActionManager.OnPointerOutTrigger,n,"renderOutline",!1));n.actionManager.registerAction(new BABYLON.SetValueAction(BABYLON.ActionManager.OnPointerOverTrigger,n,"renderOutline",!0));n.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnRightPickTrigger,function(){i.selectObject(n,!0)}))});i.$rootScope.$broadcast("sceneReset")})})},t.prototype.resetScene=function(){for(var n=this._scene.meshes.length-1;n>-1;n--)this._scene.meshes[n].dispose();this.createDefaultScene();this.$rootScope.$broadcast("sceneReset")},t.prototype.createDefaultScene=function(){var t=this,n=this._scene,i=BABYLON.Mesh.CreateBox("Box",6,n),r=BABYLON.Mesh.CreateSphere("Sphere",10,10,n),u=BABYLON.Mesh.CreatePlane("Plane",10,n),f=BABYLON.Mesh.CreateCylinder("Cylinder",3,3,3,6,1,n),e=BABYLON.Mesh.CreateTorus("Torus",5,1,10,n),o=BABYLON.Mesh.CreateTorusKnot("Knot",2,.5,128,64,2,3,n);i.position=new BABYLON.Vector3(-10,0,0);r.position=new BABYLON.Vector3(0,10,0);u.position.z=10;f.position.z=-10;e.position.x=10;o.position.y=-10;n.meshes.forEach(function(n){n.material=new BABYLON.StandardMaterial(n.name+"Mat",t._scene);n.actionManager=new BABYLON.ActionManager(t._scene);n.actionManager.registerAction(new BABYLON.SetValueAction(BABYLON.ActionManager.OnPointerOutTrigger,n,"renderOutline",!1));n.actionManager.registerAction(new BABYLON.SetValueAction(BABYLON.ActionManager.OnPointerOverTrigger,n,"renderOutline",!0));n.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnRightPickTrigger,function(){t.selectObject(n,!0)}))})},t.prototype.initLight=function(n){typeof n=="undefined"&&(n=0);this._scene.lights.forEach(function(n){n.dispose()});switch(n){case 0:this._light=new BABYLON.HemisphericLight("light",new BABYLON.Vector3(0,1,0),this._scene);this._light.groundColor=new BABYLON.Color3(0,0,0);break;case 2:this._light=new BABYLON.PointLight("light",this._camera.position,this._scene);break;case 1:this._light=new BABYLON.SpotLight("light",this._camera.position,new BABYLON.Vector3(0,-1,0),.8,2,this._scene)}this._light.diffuse=new BABYLON.Color3(.6,.6,.6);this._light.specular=new BABYLON.Color3(1,1,1);this.$rootScope.$broadcast("lightChanged",this._light)},t.prototype.selectObjectInPosition=function(n){return this.selectObject(this._scene.meshes[n])},t.prototype.getObjectInPosition=function(n){return this._scene.meshes[n]},t.prototype.selectObject=function(n,t){var u,r,i;if(typeof t=="undefined"&&(t=!1),n.subMeshes==null)return!1;if(this._textureObject=n,n.subMeshes.length>1&&n.material instanceof BABYLON.StandardMaterial){for(u=n.material,r=new BABYLON.MultiMaterial(n.name+"MultiMat",this._scene),r.subMaterials.push(u),i=1;i<n.subMeshes.length;i++)r.subMaterials.push(new BABYLON.StandardMaterial(n.name+"MatInMulti"+i,this._scene));this._textureObject.material=r}else if(n.subMeshes.length==1&&n.material instanceof BABYLON.MultiMaterial)n.material=new BABYLON.StandardMaterial(n.name+"Mat",this._scene);else if(n.material instanceof BABYLON.MultiMaterial&&n.material.subMaterials.length<n.subMeshes.length)for(i=n.material.subMaterials.length;i<n.subMeshes.length;i++)n.material.subMaterials.push(new BABYLON.StandardMaterial(n.name+"MatInMulti"+i,this._scene));return this.$rootScope.$broadcast("objectChanged",this._textureObject,t),this.directCameraTo(this._textureObject),!0},t.prototype.directCameraTo=function(n){this._camera.target=n.position},t.prototype.getObjects=function(){return this._scene.meshes},t.prototype.sceneLoadingUI=function(n){typeof n=="undefined"&&(n=!0);n?this._scene.getEngine().displayLoadingUI():this._scene.getEngine().hideLoadingUI()},t.prototype.appendMaterial=function(t,i,r,u){BABYLON.SceneLoader.Append(n.MaterialController.ServerUrl+"/materials/",t+".babylon",this._scene,i,r,u)},t.prototype.getMaterial=function(n){return this._scene.getMaterialByID(n)},t.prototype.singleOut=function(n,t){var i,r;if(n)for(i=0;i<this._scene.meshes.length;i++)r=this._scene.meshes[i],r.lastVisibleState=r.isVisible,r.isVisible=i==t?!0:!1;else for(i=0;i<this._scene.meshes.length;i++)r=this._scene.meshes[i],r.isVisible=!!r.lastVisibleState},t.$inject=["$rootScope"],t}();n.CanvasService=t})(n.TextureEditor||(n.TextureEditor={}));var t=n.TextureEditor}(RW||(RW={})),function(n){(function(n){var t=function(){function n(n,t,i,r){var u=this;this.$scope=n;this.$timeout=t;this.$modalInstance=i;this.object=r;n.object=r;n.totalNumberOfIndices=r.getTotalIndices();n.division=2;n.close=function(){n.updateObject(!0);i.close()};n.updateObject=function(t){typeof t=="undefined"&&(t=!1);var i=0,u=0;r.subMeshes.forEach(function(f){var e=f.indexCount%3;f.indexCount-=f.indexCount%3;i+f.indexCount>n.totalNumberOfIndices&&(f.indexCount=n.totalNumberOfIndices-i);f.indexStart=i;f.indexStart+f.indexCount>n.totalNumberOfIndices&&(f.indexCount=n.totalNumberOfIndices-f.indexStart);f.materialIndex=u;i+=f.indexCount;u++;t&&u==r.subMeshes.length&&i<n.totalNumberOfIndices&&(f.indexCount+=n.totalNumberOfIndices-i)});n.indicesLeft=n.totalNumberOfIndices-i};n.addSubMesh=function(){var t=u.$scope.indicesLeft<0?0:u.$scope.indicesLeft;new BABYLON.SubMesh(r.subMeshes.length,0,r.getTotalVertices(),u.$scope.totalNumberOfIndices-u.$scope.indicesLeft,t,r);n.updateObject(!1)};n.removeSubMesh=function(t){r.subMeshes.splice(t,1);n.updateObject(!1)};n.divideObject=function(){n.division*3>n.totalNumberOfIndices&&(n.division=~~(n.totalNumberOfIndices/3));r.subdivide(n.division);n.updateObject(!1)};n.updateObject(!1)}return n.$inject=["$scope","$timeout","$modalInstance","object"],n}();n.ObjectSubMeshesController=t})(n.TextureEditor||(n.TextureEditor={}));var t=n.TextureEditor}(RW||(RW={})),function(n){(function(n){n.disableEnableButton=[function(){return{require:"ngModel",priority:1,link:function(n,t,i,r){function f(){r.$modelValue===!0||r.$modelValue===1?(t.html(u+"Enabled"),t.addClass("btn-success"),t.removeClass("btn-danger")):(t.html(u+"Disabled"),t.addClass("btn-danger"),t.removeClass("btn-success"));e()}var e=r.$render,u=i.extraText?" "+i.extraText+" ":"";t.bind("mouseenter",function(){r.$modelValue===!0||r.$modelValue===1?(t.html("Disable"+u),t.addClass("btn-danger"),t.removeClass("btn-success")):(t.html("Enable"+u),t.addClass("btn-success"),t.removeClass("btn-danger"))});t.bind("mouseleave",f);r.$render=f;f()}}}]})(n.TextureEditor||(n.TextureEditor={}));var t=n.TextureEditor}(RW||(RW={})),function(n){(function(n){var t=function(){function n(n,t,i,r,u,f){var e=this;this.$scope=n;this.$modal=t;this.$http=i;this.$timeout=r;this.canvasService=u;this.materialService=f;this.alerts=[];this.afterObjectChanged=function(n,t){if(t.subMeshes!=null){e._object=t;e.isMultiMaterial=t.subMeshes.length>1;var i=!1;e.isMultiMaterial?(e.numberOfMaterials=t.material.subMaterials.length,e.multiMaterialPosition=0,i=!0):(e.numberOfMaterials=0,e.multiMaterialPosition=-1);e.initMaterial(i,function(){e.$timeout(function(){e.$scope.$apply()})},e.multiMaterialPosition)}};this.getMaterialIndices=function(){return new Array(e.numberOfMaterials)};this.isMultiMaterial=!1;this.multiMaterialPosition=0;this.numberOfMaterials=0;this.progress={enabled:!1,value:0,text:""};n.updateTexture=function(t){n.$apply(function(){n.materialDefinition.materialSections[t].texture.canvasUpdated()})};n.$on("objectChanged",this.afterObjectChanged)}return n.prototype.initMaterial=function(n,t,i){this.$scope.materialDefinition=this.isMultiMaterial?this.materialService.initMaterialSections(this._object,n,t,i):this.materialService.initMaterialSections(this._object,n,t)},n.prototype.setPlaneForMirror=function(){var t,r,u;console.log("setPlane");var n=[],f=this._object.computeWorldMatrix(),e=this._object.getVerticesData(BABYLON.VertexBuffer.PositionKind),i=0;for(this.isMultiMaterial&&(i=this._object.subMeshes[this.multiMaterialPosition].indexStart),t=0;t<3;t++)r=this._object.getIndices()[i+t],n.push(BABYLON.Vector3.TransformCoordinates(BABYLON.Vector3.FromArray(e,r*3),f));u=BABYLON.Plane.FromPoints(n[0],n[1],n[2]);this.$scope.materialDefinition.materialSections.reflection.texture.setMirrorPlane(u)},n.prototype.exportMaterial=function(){var n=this,t=this.$modal.open({templateUrl:"materialExport.html",controller:"MaterialExportModalController",size:"lg",resolve:{materialDefinitions:function(){return n.materialService.getMaterialDefinisionsArray(n._object.id)}}})},n.prototype.updateProgress=function(n,t,i){this.progress.enabled=n;this.progress.text=t;this.progress.value=i},n.prototype.saveMaterial=function(){var t=this;this.updateProgress(!0,"Saving...",20);this.$http.get(n.ServerUrl+"/getNextId").success(function(i){var r=i.id,u=t.materialService.exportAsBabylonScene(r,t.$scope.materialDefinition);t.updateProgress(!0,"Received ID...",40);t.$http.post(n.ServerUrl+"/materials",u).success(function(i){var u,f;if(!i.success){t.alerts.push({type:"danger",msg:"Error uploading to server."});t.updateProgress(!1);return}u=[];t.$scope.materialDefinition.sectionNames.forEach(function(n){if(t.$scope.materialDefinition.materialSections[n].hasTexture&&t.$scope.materialDefinition.materialSections[n].texture.enabled()){var i=t.$scope.materialDefinition.materialSections[n].texture;i.babylonTextureType==1&&u.push(n)}});u.length==0?(t.updateProgress(!1),t.alerts.push({type:"success",msg:"Material stored. "}),t.$timeout(function(){t.alerts.pop()},5e3),t.materialId=r):(f=0,t.updateProgress(!0,"Uploading textures...",50),u.forEach(function(i){if(t.$scope.materialDefinition.materialSections[i].hasTexture&&t.$scope.materialDefinition.materialSections[i].texture.enabled()){var e=t.$scope.materialDefinition.materialSections[i].texture;e.babylonTextureType==1&&e.getCanvasImageUrls(function(i){var o={};o[r+"_"+e.name+e.getExtension()]=i[0];t.$http.post(n.ServerUrl+"/textures",o).success(function(n){n.success||(t.alerts.push({type:"danger",msg:"error uploading the texture "+e.name}),t.updateProgress(!1));f++;t.updateProgress(!0,"Uploading textures...",50+f*10);f==u.length&&(t.updateProgress(!1),t.alerts.push({type:"success",msg:"Material stored."}),t.$timeout(function(){t.alerts.pop()},5e3),t.materialId=r)})})}}))})})},n.prototype.loadMaterial=function(){var t=this;if(!this.materialId){this.alerts.push({type:"warning",msg:"Please enter an ID"});return}this.updateProgress(!0,"Loading material...",30);this.$http.get(n.ServerUrl+"/materials/"+this.materialId+".babylon").error(function(){t.alerts.push({type:"danger",msg:"Material could not be loaded. Check the ID."});t.updateProgress(!1)}).success(function(){t.canvasService.appendMaterial(t.materialId,function(){var n=t.canvasService.getMaterial(t.materialId),i=function(){t.alerts.length<1&&t.alerts.push({type:"success",msg:"Material loaded."});t.$timeout(function(){t.alerts.pop()},5e3);t.updateProgress(!1);t.$scope.$apply()};t.$timeout(function(){t.isMultiMaterial?(t._object.material.subMaterials[t.multiMaterialPosition]=n,t.initMaterial(!0,i,t.multiMaterialPosition)):(t._object.material=n,t.initMaterial(!0,i))})},function(){t.updateProgress(!0,"Loading material...",60)},function(n){console.log(n);t.alerts.push({type:"danger",msg:"Material could not be loaded. Check the ID."});t.updateProgress(!1)})})},n.prototype.closeAlert=function(n){this.alerts.splice(n,1)},n.$inject=["$scope","$modal","$http","$timeout","canvasService","materialService"],n.ServerUrl="",n}();n.MaterialController=t})(n.TextureEditor||(n.TextureEditor={}));var t=n.TextureEditor}(RW||(RW={})),function(n){(function(n){var t=function(){function n(n,t,i){var r=this;this.$scope=n;this.$modalInstance=t;this.materialDefinitions=i;n.materialName="my awsome material";n.materialVariableName="myAwsomeMaterial";n.sceneVariableName="myWonderfulScene";n.close=function(){t.close()};n.updateExport=function(){var u=[],e,n,t,i,f;if(u.push("//Material generated using raananw's babylon material editor, https://github.com/raananw/BabylonJS-Material-Editor "),u.push(""),e=r.materialDefinitions.length>1?"MultiMaterial":"StandardMaterial",u.push("var "+r.$scope.materialVariableName+" = new BABYLON."+e+"('"+r.$scope.materialName+"', "+r.$scope.sceneVariableName+")"),n=[],n.push(u.join(";\n")),r.materialDefinitions.length==1)r.materialDefinitions[0].material instanceof BABYLON.StandardMaterial&&(f=r.materialDefinitions[0].material,["alpha","backFaceCulling","specularPower","useSpecularOverAlpha","useAlphaFromDiffuseTexture"].forEach(function(t){n.push(r.$scope.materialVariableName+"."+t+" = "+f[t])})),r.materialDefinitions[0].getMaterialSectionsArray().forEach(function(t){n.push(r.materialDefinitions[0].materialSections[t].exportToJavascript(r.$scope.sceneVariableName,r.$scope.materialName,r.$scope.materialVariableName))});else for(t=0;t<r.materialDefinitions.length;++t)i=r.$scope.materialVariableName+"_"+t,n.push("var "+i+" = new BABYLON.StandardMaterial('"+r.$scope.materialName+" "+t+"', "+r.$scope.sceneVariableName+")"),r.materialDefinitions[t].material instanceof BABYLON.StandardMaterial&&(f=r.materialDefinitions[0].material,["alpha","backFaceCulling","specularPower","useSpecularOverAlpha","useAlphaFromDiffuseTexture"].forEach(function(t){n.push(i+"."+t+" = "+f[t])})),r.materialDefinitions[0].getMaterialSectionsArray().forEach(function(u){n.push(r.materialDefinitions[t].materialSections[u].exportToJavascript(r.$scope.sceneVariableName,r.$scope.materialName+" "+t,i))}),n.push(r.$scope.materialVariableName+".subMaterials["+t+"] = "+i);r.$scope.materialExport=n.join(";\n").replace(/\n;\n/g,"\n\n").replace(/\n;\n/g,"\n\n").replace(/\n\n\n/g,"\n\n")};n.updateExport()}return n.$inject=["$scope","$modalInstance","materialDefinitions"],n}();n.MaterialExportModlController=t})(n.TextureEditor||(n.TextureEditor={}));var t=n.TextureEditor}(RW||(RW={})),function(n){(function(n){var t=function(){function t(n,t){this.sectionNames=["diffuse","emissive","ambient","opacity","specular","reflection","bump"];this.initFromMaterial(n,t)}return t.prototype.initFromMaterial=function(t,i){this.material=t;this.materialSections={};this.materialSections.diffuse=new n.MaterialDefinitionSection("diffuse",!0,!0,!0,t,i);this.materialSections.emissive=new n.MaterialDefinitionSection("emissive",!0,!0,!0,t,i);this.materialSections.ambient=new n.MaterialDefinitionSection("ambient",!0,!0,!1,t,i);this.materialSections.opacity=new n.MaterialDefinitionSection("opacity",!1,!0,!0,t,i);this.materialSections.specular=new n.MaterialDefinitionSection("specular",!0,!0,!1,t,i);this.materialSections.reflection=new n.MaterialDefinitionSection("reflection",!1,!0,!0,t,i);this.materialSections.bump=new n.MaterialDefinitionSection("bump",!1,!0,!1,t,i)},t.prototype.getMaterialSectionsArray=function(){return this.sectionNames},t.prototype.getMaterialSections=function(){return this.materialSections},t.prototype.exportAsBabylonScene=function(n){var r=this,t={id:n,name:n},i;return this.material instanceof BABYLON.StandardMaterial&&(i=this.material,t.alpha=i.alpha,t.backFaceCulling=i.backFaceCulling,t.specularPower=i.specularPower,t.useSpecularOverAlpha=i.useSpecularOverAlpha,t.useAlphaFromDiffuseTexture=i.useAlphaFromDiffuseTexture),this.getMaterialSectionsArray().forEach(function(n){r.materialSections[n].exportAsBabylonScene(t)}),{ambientColor:[0,0,0],autoClear:!0,clearColor:[.2,.2,.3],gravity:[0,0,-.9],materials:[t],lights:[],meshes:[],cameras:[]}},t}(),i;n.MaterialDefinition=t;i=function(){function n(n,t){this.$rootScope=n;this.canvasService=t;this.materialDefinisions={}}return n.prototype.initMaterialSections=function(n,t,i,r){return this.materialDefinisions[n.id]||(this.materialDefinisions[n.id]=[]),angular.isDefined(r)?((!this.materialDefinisions[n.id][r]||t)&&(this.materialDefinisions[n.id][r]=this.createNewMaterialDefinition(n,i,r)),this.materialDefinisions[n.id][r]):((!this.materialDefinisions[n.id][0]||t)&&(this.materialDefinisions[n.id][0]=this.createNewMaterialDefinition(n,i)),this.materialDefinisions[n.id][0])},n.prototype.getMaterialDefinisionsArray=function(n){return this.materialDefinisions[n]},n.prototype.createNewMaterialDefinition=function(n,i,r){var u;return u=angular.isDefined(r)?n.material.subMaterials[r]:n.material,new t(u,i)},n.prototype.exportAsBabylonScene=function(n,t){return t.exportAsBabylonScene(n)},n.$inject=["$rootScope","canvasService"],n}();n.MaterialService=i})(n.TextureEditor||(n.TextureEditor={}));var t=n.TextureEditor}(RW||(RW={})),function(n){(function(n){var t=function(){function t(t,i){this.name=t;this.propertyInMaterial=t+"FresnelParameters";i[this.propertyInMaterial]?this.fresnelVariable=i[this.propertyInMaterial]:(this.fresnelVariable=new BABYLON.FresnelParameters,this.fresnelVariable.isEnabled=!1,i[this.propertyInMaterial]=this.fresnelVariable);this.leftColor=new n.HexToBabylon("left",i[this.propertyInMaterial]);this.rightColor=new n.HexToBabylon("right",i[this.propertyInMaterial])}return t.prototype.exportAsJavascript=function(n){var t=[],r=n+"_"+this.name+"Fresnel",i;return t.push("var "+r+" = new BABYLON.FresnelParameters()"),t.push(r+".isEnabled = true"),t.push(r+".bias = "+this.fresnelVariable.bias),t.push(r+".power = "+this.fresnelVariable.power),i=this.fresnelVariable.leftColor.asArray(),t.push(r+".leftColor = new BABYLON.Color3("+i[0]+", "+i[1]+", "+i[2]+")"),i=this.fresnelVariable.rightColor.asArray(),t.push(r+".rightColor = new BABYLON.Color3("+i[0]+", "+i[1]+", "+i[2]+")"),t.push(n+"."+this.propertyInMaterial+" = "+r),t.join(";\n")},t.prototype.exportAsBabylonScene=function(){return{bias:this.fresnelVariable.bias,power:this.fresnelVariable.power,isEnabled:this.fresnelVariable.isEnabled,leftColor:this.fresnelVariable.leftColor.asArray(),rightColor:this.fresnelVariable.rightColor.asArray()}},t}();n.FresnelDefinition=t})(n.TextureEditor||(n.TextureEditor={}));var t=n.TextureEditor}(RW||(RW={})),function(n){(function(n){var t=function(){function n(n,t,i){typeof i=="undefined"&&(i="Color");this.propertyName=n;this._variable=t;this.propertyName+=i;this._setBabylonColor(t[this.propertyName])}return n.prototype.hex=function(n){if(n)this._hex=n,this.babylonColor=this.convertStringToBabylonArray(this._hex),this.babylonColor&&(this._variable[this.propertyName]=this.babylonColor);else return this._hex},n.prototype._setBabylonColor=function(n){this.babylonColor=n;var t="#";["r","g","b"].forEach(function(i){var r=~~(n[i]*255);t=t+(r<16?"0"+r.toString(16):""+r.toString(16))});this._hex=t},n.prototype.convertStringToBabylonArray=function(n){var t;return n=n.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,function(n,t,i,r){return t+t+i+i+r+r}),t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n),t?BABYLON.Color3.FromArray([parseInt(t[1],16)/255,parseInt(t[2],16)/255,parseInt(t[3],16)/255]):null},n}();n.HexToBabylon=t})(n.TextureEditor||(n.TextureEditor={}));var t=n.TextureEditor}(RW||(RW={})),function(n){(function(n){var t=function(){function t(t,i,r,u,f,e){this.name=t;this.hasColor=i;this.hasTexture=r;this.hasFresnel=u;this.material=f;i&&(this.color=new n.HexToBabylon(t,f));r&&(this.texture=new n.TextureDefinition(t,f,e));u&&(this.fresnel=new n.FresnelDefinition(t,f))}return t.prototype.exportToJavascript=function(n,t,i){var r=[],u;return this.hasColor&&(u=this.color.babylonColor.asArray(),r.push(i+"."+this.color.propertyName+" = new BABYLON.Color3("+u[0].toFixed(2)+", "+u[1].toFixed(2)+", "+u[2].toFixed(2)+")")),this.hasFresnel&&this.fresnel.fresnelVariable.isEnabled&&(r.push("//Fresnel Parameters "),r.push(this.fresnel.exportAsJavascript(i))),this.hasTexture&&this.texture.enabled()&&(r.push("//Texture Parameters "),r.push(this.texture.exportAsJavascript(n,i))),r.length>0&&(r.unshift(""),r.unshift("// "+this.name+" definitions"),r.unshift("")),r.join(";\n")},t.prototype.exportAsBabylonScene=function(n){var t=n.id;this.hasColor&&(n[this.name]=this.color.babylonColor.asArray());this.hasTexture&&(n[this.texture.propertyInMaterial]=this.texture.enabled()?this.texture.exportAsBabylonScene(t):null);this.hasFresnel&&this.fresnel.fresnelVariable.isEnabled&&(n[this.fresnel.propertyInMaterial]=this.fresnel.exportAsBabylonScene())},t}();n.MaterialDefinitionSection=t})(n.TextureEditor||(n.TextureEditor={}));var t=n.TextureEditor}(RW||(RW={})),function(n){(function(n){n.textureImage=["$parse",function(){return{restrict:"E",templateUrl:function(){return"template/image-drag-drop.html"},scope:{tex:"=",updateTexture:"&onUpdateTexture"},transclude:!0,link:function(n,t){function r(t,r){if(!t.type.match(/image.*/)){console.log("The dropped file is not an image: ",t.type);return}var u=new FileReader;u.onload=function(t){i.updateCanvasFromUrl(r,t.target.result,function(){n.updateTexture&&n.updateTexture({$name:i.name})})};u.readAsDataURL(t)}var i=n.tex;t.on("dragover",".texture-canvas-drop",function(n){n.preventDefault()});t.on("dragleave",".texture-canvas-drop",function(n){n.preventDefault()});t.on("drop",".texture-canvas-drop",function(n){n.preventDefault();r(n.originalEvent.dataTransfer.files[0],$(this).find("canvas")[0])})}}}]})(n.TextureEditor||(n.TextureEditor={}));var t=n.TextureEditor}(RW||(RW={})),function(n){(function(n){var t=function(){function n(n,t,i){this.$scope=n;this.canvasService=t;this.materialService=i}return n.$inject=["$scope","canvasService","materialService"],n}();n.TextureController=t})(n.TextureEditor||(n.TextureEditor={}));var t=n.TextureEditor}(RW||(RW={})),function(n){(function(n){var t=function(){function n(n,t,i){var f=this,r,u;this.name=n;this._material=t;this.getCanvasNumber=function(){return new Array(f.numberOfImages)};this.propertyInMaterial=this.name.toLowerCase()+"Texture";this.canvasId=this.name+"Canvas";this.numberOfImages=1;this._mirrorPlane=new BABYLON.Plane(0,0,0,0);this._material[this.propertyInMaterial]?(this.babylonTextureType=this._material[this.propertyInMaterial]instanceof BABYLON.MirrorTexture?4:this._material[this.propertyInMaterial]instanceof BABYLON.VideoTexture?4:this._material[this.propertyInMaterial]instanceof BABYLON.CubeTexture?3:1,this.initFromMaterial(i)):(this.babylonTextureType=1,this.enabled(!1),this.init=!1,r=document.getElementById(this.canvasId+"-0"),r&&(u=r.getContext("2d"),u.clearRect(0,0,r.width,r.height)),i&&i())}return n.prototype.initTexture=function(){var i,r,t,n;if(this.textureVariable&&this.textureVariable.dispose(),this.numberOfImages==1)n=document.getElementById(this.canvasId+"-0"),i=n.toDataURL(),this.textureVariable=new BABYLON.Texture(i,this._material.getScene(),!1,undefined,undefined,undefined,undefined,i,!1),this.name!="reflection"?this.coordinatesMode(0):this.coordinatesMode(2),this.babylonTextureType=1,this.init=!0;else{for(r=[],t=0;t<6;t++)n=document.getElementById(this.canvasId+"-"+t),r.push(n.toDataURL());this.textureVariable=new BABYLON.ExtendedCubeTexture(r,this._material.getScene(),!1);this.babylonTextureType=3;this.init=!0}},n.prototype.initFromMaterial=function(n){var t=this;this.textureVariable=this._material[this.propertyInMaterial];this.updateCanvas(function(){t.canvasUpdated();t.enabled(!0);n&&n()})},n.prototype.coordinatesMode=function(n){if(angular.isDefined(n)){var t=n!=3&&this.numberOfImages==6;this.textureVariable.coordinatesMode=n;this.numberOfImages=n===3?6:1;t}else return this.textureVariable?this.textureVariable.coordinatesMode:0},n.prototype.setMirrorPlane=function(n){this._mirrorPlane.normal=n.normal;this._mirrorPlane.d=n.d},n.prototype.mirrorEnabled=function(n){if(angular.isDefined(n))if(n){if(this.name!="reflection")throw new Error("wrong texture for mirror! Should be reflection!");this.babylonTextureType=4;this.textureVariable=new BABYLON.MirrorTexture("mirrorTex",512,this._material.getScene());this.textureVariable.renderList=this._material.getScene().meshes;this.textureVariable.mirrorPlane=this._mirrorPlane;this.init=!0;this.enabled(!0)}else this.babylonTextureType=1,this._material[this.propertyInMaterial]=null,this.init=!1,this.initTexture();else return this._isEnabled&&this.babylonTextureType==4},n.prototype.enabled=function(n){if(angular.isDefined(n))n?(this.init||this.initTexture(),this.textureVariable&&(this._material[this.propertyInMaterial]=this.textureVariable),this._isEnabled=!0,this.updateCanvas()):(this._material[this.propertyInMaterial]=null,this._isEnabled=!1);else return this._isEnabled},n.prototype.canvasUpdated=function(){this.initTexture();this._isEnabled&&(this._material[this.propertyInMaterial]=this.textureVariable)},n.prototype.getCanvasImageUrls=function(n){var t=this,i=[];this.textureVariable instanceof BABYLON.MirrorTexture||this.textureVariable instanceof BABYLON.CubeTexture||this.updateCanvas(function(){for(var u,r=0;r<t.numberOfImages;r++)u=document.getElementById(t.canvasId+"-"+r),t.getExtension()==".png"?i.push(u.toDataURL("image/png",.8)):i.push(u.toDataURL("image/jpeg",.8));i.length==t.numberOfImages&&n(i)})},n.prototype.updateCanvas=function(n){var r,u,t,i;if(this.textureVariable instanceof BABYLON.Texture)r=this.textureVariable,i=document.getElementById(this.canvasId+"-0"),this.updateCanvasFromUrl(i,r.url,n);else if(this.textureVariable instanceof BABYLON.ExtendedCubeTexture)for(u=this.textureVariable,t=0;t<this.numberOfImages;t++)i=document.getElementById(this.canvasId+"-"+t),this.updateCanvasFromUrl(i,u.urls[t],n)},n.prototype.updateCanvasFromUrl=function(n,t,i){if(t){var r=new Image;r.onload=function(){var e=n.getContext("2d");e.clearRect(0,0,n.width,n.height);var t=BABYLON.Tools.GetExponantOfTwo(r.width,1024),u=BABYLON.Tools.GetExponantOfTwo(r.height,1024),f=Math.max(t,u);t>u?(r.width*=u/r.height,r.height=u):(r.height*=t/r.width,r.width=t);n.width=f;n.height=f;e.drawImage(r,0,0,f,f);i&&i()};r.src=t}},n.prototype.exportAsJavascript=function(n,t){var e=this,i=[],r=t+"_"+this.name+"Texture",f,u;return this.babylonTextureType==4?(i.push("var "+r+" = new BABYLON.MirrorTexture('MirrorTexture', 512,"+n+" )"),f=this.textureVariable.mirrorPlane,u=f.asArray(),i.push(r+".mirrorPlane = new BABYLON.Plane("+u[0]+","+u[1]+","+u[2]+","+u[3]+")"),i.push("// Change the render list to fit your needs. The scene's meshes is being used per default"),i.push(r+".renderList = "+n+".meshes")):this.babylonTextureType==3?(i.push("//TODO change the root URL for your cube reflection texture!"),i.push("var "+r+" = new BABYLON.CubeTexture(rootUrl, "+n+" )")):(i.push("//TODO change the filename to fit your needs!"),i.push("var "+r+" = new BABYLON.Texture('textures/"+t+"_"+this.name+this.getExtension()+"', "+n+")")),["uScale","vScale","coordinatesMode","uOffset","vOffset","uAng","vAng","level","coordinatesIndex","hasAlpha","getAlphaFromRGB"].forEach(function(n){i.push(r+"."+n+" = "+e.textureVariable[n])}),i.push(""),i.push(t+"."+this.propertyInMaterial+" = "+r),i.join(";\n")},n.prototype.exportAsBabylonScene=function(n){var i=this,t={name:"textures/"+n+"_"+this.name+this.getExtension()};return["uScale","vScale","coordinatesMode","uOffset","vOffset","uAng","vAng","level","coordinatesIndex","hasAlpha","getAlphaFromRGB"].forEach(function(n){t[n]=i.textureVariable[n]}),t},n.prototype.getExtension=function(){return this.textureVariable.hasAlpha?".png":".jpg"},n}();n.TextureDefinition=t})(n.TextureEditor||(n.TextureEditor={}));var t=n.TextureEditor}(RW||(RW={})),function(n){(function(n){var t,i;(function(n){n[n.DYNAMIC=0]="DYNAMIC";n[n.NORMAL=1]="NORMAL";n[n.VIDEO=2]="VIDEO";n[n.CUBE=3]="CUBE";n[n.MIRROR=4]="MIRROR"})(n.BabylonTextureType||(n.BabylonTextureType={}));t=n.BabylonTextureType,function(n){n[n.EXPLICIT=0]="EXPLICIT";n[n.SPHERICAL=1]="SPHERICAL";n[n.PLANAR=2]="PLANAR";n[n.CUBIC=3]="CUBIC";n[n.PROJECTION=4]="PROJECTION"}(n.CoordinatesMode||(n.CoordinatesMode={}));i=n.CoordinatesMode})(n.TextureEditor||(n.TextureEditor={}));var t=n.TextureEditor}(RW||(RW={}));
//# sourceMappingURL=application.min.js.map