function Label(n,t,i,r){this.id=n;this.parentId=t;this.name=i;this.path=r}function LabelsTree(n){function r(n){var e=[],t,i,f,o,s,r;for(i in n)t=n[i],e.push(new Label(t.id,t.parentId,t.name));for(f={},i=0;i<e.length;i++)f[e[i].id]=e[i];o=[];for(s in f)t=f[s],r=f[t.parentId],r?(r.children=r.children||[],r.children.push(t),t.parentName=r.name):o.push(t);return u(o)}function u(n){var i,t;for(i in n)t=n[i],t&&t.children&&t.children.length>0&&(t.children=u(t.children));return _.sortBy(n,function(n){return n&&n.children&&n.children.length>0?0:1})}function i(n){var t='<ul class="tree">';return n.length==0&&(t+='<li class="parent">'+translate("No labels found")+"<\/li>"),$.each(n,function(n,r){t+=r.children&&r.children.length>0?'<li class="parent">':"<li>";t+=f(r.name,r.id);r.children&&r.children.length>0&&(t+=i(r.children));t+="<\/li>"}),t+="<\/ul>"}function f(n,t){var i='<input type="checkbox" id="cb_'+t+'" name="cb_'+t+'" class="Label" data-id="'+t+'">';return i+('<label for="cb_'+t+'">'+n+"<\/label>")}var t=this;t.init=function(n){t.dataSource=n};t.init(n);t.showLabelTree=function(n,u,f){var e,o,s;e=u?_.filter(t.dataSource,function(n){return n.name.search(new RegExp(u,"i"))!==-1}):t.dataSource;o=r(e);s=i(o);n.html(s);initFormElements(n);n.parents(".allLabels").show();f&&f instanceof Function&&e&&f({count:e.length})};t.updateLabelTree=function(n,u,f){var e,o,s;e=u?_.filter(t.dataSource,function(n){return n.name.search(new RegExp(u,"i"))!==-1}):t.dataSource;o=r(e);s=i(o);n.html(s);initFormElements(n);u.length>0?n.parents(".allLabels").show():n.parents(".allLabels").hide();f&&f instanceof Function&&f({count:e.length})}}function LabelsWidget(n,t){var i=this;i.initLabelTree=function(){i.labelsTree&&(i.labelsTree.showLabelTree(i.$tree,"",i.onRenderLabelTree),i.$tree.find("input.Label").each(function(){var n=$(this)[0].id.replace("cb_",""),t=i.$list.find('input[value="'+n+'"]');t[0]?$(this).parent().addClass("notAllowed"):$(this).parent().removeClass("notAllowed")}))};i.refreshSearchPanel=function(){i.labelsTree&&i.labelsTree.updateLabelTree(i.$tree,"",null)};i.init=function(n,t){i.labelsTree=n;i.options=t||{};i.$list=i.options.$list;i.$tree=i.options.$tree;i.$search=i.options.$search;i.$removeAll=i.options.$removeAll;i.$form=i.options.$form;i.labelTreeSelected=!1;i.$list&&!i.$list.find("ul li").length&&i.$removeAll.hide();i.options.useSearchList?i.refreshSearchPanel():i.initLabelTree()};i.init(n,t);i.removeAllLabels=function(){var n=translate("Are you sure you want to delete all labels?");dialogBox(n,function(){i.submitLabels(window.LABELS_OPERATIONS.removeAll);ChangesManager.addChange("o-properties")})};i.removeLabel=function(n){var t=i.$list.find("LI > SPAN > INPUT[type=checkbox][value="+n+"]").parent().text(),r=translate('Are you sure you want to delete label "{0}"?',t);dialogBox(r,function(){i.$form.find("INPUT#LabelId").val(n);i.submitLabels(window.LABELS_OPERATIONS.remove);ChangesManager.addChange("o-properties")})};i.addLabel=function(n){i.$form.find("INPUT#LabelId").val(n);i.submitLabels(window.LABELS_OPERATIONS.add);ChangesManager.addChange("o-properties")};i.submitLabels=function(n){i.$form.find("INPUT#Operation").val(n);i.$form.submit()};i.onRenderLabelTree=function(){i.$tree.find("LI > SPAN > INPUT[type=checkbox]").click(function(){var n=$(this).data("id"),t=$(this).parent().text();i.labelExists(n)?errorLog(translate('Label "{0}" is already assigned to this object',t)):i.addLabel(n);i.highlightLabel(n,!1)})};i.labelExists=function(n){return i.$list.find("LI > SPAN > INPUT[type=checkbox][value="+n+"]").length>0};i.highlightLabel=function(n,t){i.$tree.find("LI > SPAN > INPUT[type=checkbox][data-id="+n+"]").attr("checked",t?"checked":null)};i.selectedLabels=function(){var n=[];return i.$list.find("LI > SPAN > INPUT[type=checkbox]:checked").each(function(){n.push(this.value)}),n};i.bindEvents=function(){i.$form.keydown(function(n){if(n.keyCode==13)return n.preventDefault(),!1});i.$tree.hover(function(){i.labelTreeSelected=!0},function(){i.labelTreeSelected=!1});i.$search.off("focus").on("focus",function(){i.labelsTree.showLabelTree(i.$tree,"",i.onRenderLabelTree)});i.$search.off("focusout").on("focusout",function(){i.labelTreeSelected||i.labelsTree.updateLabelTree(i.$tree,"",null)});i.$search.off("keyup").on("keyup",function(){var n=$.trim($(this).val());i.labelsTree.updateLabelTree(i.$tree,n,i.onRenderLabelTree)});i.$removeAll.off("click").click(function(){i.removeAllLabels()});i.$list.find(".LabelRemove A").off("click").click(function(){var n=$(this).data("id");i.removeLabel(n)})}}function translate(n){var t=n;return(translate.cache[n]?t=translate.cache[n]:($.ajax({type:"GET",url:url.shared.api.localization+"?path="+encodeURI(n),async:!1,success:function(n){n&&(t=n)},error:function(){t=n}}),translate.cache[n]=t),arguments.length>1)?String.prototype.format.apply(t,Array.prototype.slice.call(arguments,1)):t}function translateWithDefault(n,t){var i=n;return(translate.cache[n]?i=translate.cache[n]:($.ajax({type:"GET",url:url.shared.api.localization+"?path="+encodeURI(n)+"&defaultValue="+encodeURI(t),async:!1,success:function(n){n&&(i=n)},error:function(){i=n}}),translate.cache[n]=i),arguments.length>1)?String.prototype.format.apply(i,Array.prototype.slice.call(arguments,1)):i}function getDefaultBabylonSceneColor(){return new BABYLON.Color3(1,1,1)}function createMaterial(n){var t,i;return n.hdrFileUrl?(t=new BABYLON.PBRMaterial("pbr",n.scene),t.albedoTexture=new BABYLON.Texture(n.diffuseTextureUrl,n.scene),t.metallic=n.materialOptions.metallic,t.alpha=n.materialOptions.alpha,t.albedoTexture.uScale=n.materialOptions.repeatX,t.albedoTexture.vScale=n.materialOptions.repeatY,t.albedoTexture.hasAlpha=!0,t.reflectionTexture=new BABYLON.HDRCubeTexture(n.hdrFileUrl,n.scene,128,!1,!0,!1,!0),t.directIntensity=n.materialOptions.directIntensity,i=n.materialOptions.directIntensity,t.directColor=new BABYLON.Color3(i,i,i),n.bumpTextureUrl&&(t.bumpTexture=new BABYLON.Texture(n.bumpTextureUrl,n.scene),t.bumpTexture.uScale=n.materialOptions.repeatX,t.bumpTexture.vScale=n.materialOptions.repeatY,t.bumpTexture.level=1),n.specularTextureUrl?(t.reflectivityTexture=new BABYLON.Texture(n.specularTextureUrl,n.scene),t.reflectivityTexture.uScale=n.materialOptions.repeatX,t.reflectivityTexture.vScale=n.materialOptions.repeatY):(i=n.materialOptions.specularIntensity,t.reflectivityColor=new BABYLON.Color3(i,i,i)),n.metallicRoughnessTextureUrl?(t.metallicRoughnessTexture=new BABYLON.Texture(n.metallicRoughnessTextureUrl,n.scene),t.metallicRoughnessTexture.uScale=n.materialOptions.repeatX,t.metallicRoughnessTexture.vScale=n.materialOptions.repeatY):t.roughness=n.materialOptions.roughness,n.emissiveTextureUrl)?(t=new BABYLON.StandardMaterial("standard",n.scene),t.emissiveTexture=new BABYLON.Texture(n.emissiveTextureUrl,n.scene),t.emissiveTexture.uScale=n.materialOptions.repeatX,t.emissiveTexture.vScale=n.materialOptions.repeatY,n.opacityTextureUrl&&(t.opacityTexture=new BABYLON.Texture(n.opacityTextureUrl),t.opacityTexture.uAng=degreesToRadians(180)),n.aoMapUrl&&(t.ambientTexture=new BABYLON.Texture(n.aoMapUrl),t.ambientTexture.uAng=degreesToRadians(180),console.log("a")),t.backFaceCulling=!1,t.needDepthPrePass=!0,t):(i=n.materialOptions.emissiveIntensity,t.emissiveColor=new BABYLON.Color3(i,i,i),n.opacityTextureUrl&&(t.opacityTexture=new BABYLON.Texture(n.opacityTextureUrl),t.opacityTexture.uAng=degreesToRadians(180)),n.aoMapUrl&&(t.ambientTexture=new BABYLON.Texture(n.aoMapUrl),t.ambientTexture.uAng=degreesToRadians(180),console.log("b")),t.backFaceCulling=!1,t.needDepthPrePass=!0,t):(t=new BABYLON.PBRMetallicRoughnessMaterial("pbr",n.scene),t.baseTexture=new BABYLON.Texture(n.diffuseTextureUrl,n.scene),t.metallic=n.materialOptions.metallic,t.alpha=n.materialOptions.alpha,t.baseTexture.uScale=n.materialOptions.repeatX,t.baseTexture.vScale=n.materialOptions.repeatY,t.baseTexture.hasAlpha=!0,n.environmentUrls&&n.environmentUrls.length>0&&(t.environmentTexture=BABYLON.CubeTexture.CreateFromImages(n.environmentUrls,n.scene)),t.directIntensity=n.materialOptions.directIntensity,i=n.materialOptions.directIntensity,t.directColor=new BABYLON.Color3(i,i,i),n.bumpTextureUrl&&(t.normalTexture=new BABYLON.Texture(n.bumpTextureUrl,n.scene),t.normalTexture.uScale=n.materialOptions.repeatX,t.normalTexture.vScale=n.materialOptions.repeatY,t.normalTexture.level=1),n.specularTextureUrl?(t.specularTexture=new BABYLON.Texture(n.specularTextureUrl,n.scene),t.specularTexture.uScale=n.materialOptions.repeatX,t.specularTexture.vScale=n.materialOptions.repeatY):(i=n.materialOptions.specularIntensity,t.specularColor=new BABYLON.Color3(i,i,i)),n.metallicRoughnessTextureUrl?(t.metallicRoughnessTexture=new BABYLON.Texture(n.metallicRoughnessTextureUrl,n.scene),t.metallicRoughnessTexture.uScale=n.materialOptions.repeatX,t.metallicRoughnessTexture.vScale=n.materialOptions.repeatY):t.roughness=n.materialOptions.roughness,n.emissiveTextureUrl)?(t=new BABYLON.StandardMaterial("standard",n.scene),t.emissiveTexture=new BABYLON.Texture(n.emissiveTextureUrl,n.scene),t.emissiveTexture.uScale=n.materialOptions.repeatX,t.emissiveTexture.vScale=n.materialOptions.repeatY,n.aoMapUrl&&(t.ambientTexture=new BABYLON.Texture(n.aoMapUrl),t.ambientTexture.uAng=degreesToRadians(180),console.log("c")),t.backFaceCulling=!1,t.needDepthPrePass=!0,t):(i=n.materialOptions.emissiveIntensity,t.emissiveColor=new BABYLON.Color3(i,i,i),n.aoMapUrl&&(t.occlusionTexture=new BABYLON.Texture(n.aoMapUrl),t.occlusionTexture.uAng=degreesToRadians(180),console.log("d")),t.backFaceCulling=!1,t.needDepthPrePass=!0,t)}function CreateMaterial(n){return createMaterial({scene:n.scene,diffuseTextureUrl:n.diffuseTextureUrl,bumpTextureUrl:n.bumpTextureUrl,specularTextureUrl:n.specularTextureUrl,metallicRoughnessTextureUrl:n.metallicRoughnessTextureUrl,emissiveTextureUrl:n.emissiveTextureUrl,materialOptions:{metallic:n.materialOptions.Metallic,alpha:n.materialOptions.Alpha,roughness:n.materialOptions.Roughness,directIntensity:n.materialOptions.DirectIntensity,emissiveIntensity:n.materialOptions.EmissiveIntensity,specularIntensity:n.materialOptions.SpecularIntensity,repeatX:n.materialOptions.RepeatX,repeatY:n.materialOptions.RepeatY},environmentUrls:n.environmentUrls})}function degreesToRadians(n){return n*(Math.PI/180)}function OverwriteEntityWidget(){var n=this,i,t;n.init=function(t){n.options=t||{};n.$chooseEntityFile=n.options.$chooseEntityFile;n.$chosenEntityFile=n.options.$chosenEntityFile;n.$stepUpload=n.options.$stepUpload;n.$content=n.options.$content;n.popopLayoutId=n.options.popopLayoutId;n.uploadingUrl=n.options.uploadingUrl;n.entityId=n.options.entityId;n.$entityUsedInProject=n.options.$entityUsedInProject;n.entityType=$("#EntityType").val();n.askForResetEntity=n.options.askForResetEntity;n.$stepUpload.uploadProgress({url:n.uploadingUrl+"?entityId="+n.entityId,autoUpload:!0,multiple:!1});n.$stepUpload.uploadProgress("onAllFilesUploadDone",function(t){for(var i=t.length-1;i>=0;i--)if(t[i].success){Backbone.trigger("masterFilter",MASTER_FILTERS["new"]);Backbone.trigger("showpopup",t[i].id,function(){n.close()});break}});n.$stepUpload.uploadProgress("onSingleFileUploadDone",function(t){t?t.success?successLog(translate("Upload process has been successfully finished")):t.errorMessage?(n.showError(translate(t.errorMessage)),errorLog(translate(t.errorMessage))):(n.showError(translate("Unexpected result!")),errorLog(translate("Unexpected result!"))):(n.showError(translate("Can`t get action result.")),errorLog(translate("Can`t get action result.")))});n.$stepUpload.uploadProgress("onFilesSelected",function(t){n.$chosenEntityFile.val(t.join(", "));$(this).hide();n.increasePopupHeight()});n.$chooseEntityFile.on("click",function(t){t.preventDefault();var i=translate("Warning: <br/> Overwriting this "+n.entityType+" will remove existing files that were uploaded. <br/> After you select a new file the upload will automatically start.");n.$entityUsedInProject.val()=="true"&&(i+=translate("<br/><\/br>Warning:<br/> This "+n.entityType+" is used in one or more projects.<br/> Overwriting this "+n.entityType+" can have unwanted effects in these projects."));dialogBox(i,function(){n.askForResetEntity?setTimeout(function(){i=translate("Do you want to reset the "+n.entityType+"? Click cancel to keep the current settings.");dialogBox(i,function(){n.$stepUpload.uploadProgress("setResetEntity",!0);n.openUpload()},function(){n.$stepUpload.uploadProgress("setResetEntity",!1);n.openUpload()})},1e3):n.openUpload()})});$.popup.on(SHOWROOM_EVENTS.hideAdd,function(){n.reset()})};n.openUpload=function(){n.$stepUpload.uploadProgress("openSelectFileDialog");n.$stepUpload.uploadProgress("clearUploadFiles")};n.reset=function(){n.$chosenEntityFile.val("");n.hideError()};n.bindActions_popup=function(){$('.jqBind_ClosePopup,[data-jqaction="closePopup"]').click(function(t){t.preventDefault();n.close()})};n.showError=function(t){n.$stepUpload.find(".validation-error-message").text(t).show()};n.hideError=function(){n.$stepUpload.find(".validation-error-message").text("").hide()};n.close=function(){$.popup.close({event:SHOWROOM_EVENTS.hideAdd})};n.increasePopupHeight=function(){$.popup.growToWindowHeight();var r=$(window).height()-40-t;n.$content.animate({height:r+t},"fast");n.$stepUpload.find("#fileUploadProgressContainer").css("height",r+i-50+"px").css("overflow","auto");n.$stepUpload.delay(1500).uploadProgress("uploadFiles",n.uploadingUrl)}}String.prototype.format||(String.prototype.format=function(){var n=arguments;return this.replace(/{(\d+)}/g,function(t,i){return typeof n[i]!="undefined"?n[i]:t})});translate.cache={};!function(n){"use strict";var r=function(){return document.createElement("canvas").getContext("2d")},u=function(n,t){var i=new Image,u=n.src||n;"data:"!==u.substring(0,5)&&(i.crossOrigin="Anonymous");i.onload=function(){var n=r("2d"),u;n.drawImage(i,0,0);u=n.getImageData(0,0,i.width,i.height);t&&t(u.data)};i.src=u},t=function(n){return["rgb(",n,")"].join("")},f=function(n){return n.map(function(n){return t(n.name)})},e=5,o=10,i={};i.colors=function(n,i){i=i||{};var r=i.exclude||[],s=i.paletteSize||o;u(n,function(u){for(var l,y,p=n.width*n.height||u.length,a={},o="",v=[],h={dominant:{name:"",count:0},palette:Array.apply(null,new Array(s)).map(Boolean).map(function(){return{name:"0,0,0",count:0}})},c=0;p>c;)(v[0]=u[c],v[1]=u[c+1],v[2]=u[c+2],o=v.join(","),a[o]=o in a?a[o]+1:1,-1===r.indexOf(t(o)))&&(l=a[o],l>h.dominant.count?(h.dominant.name=o,h.dominant.count=l):h.palette.some(function(n){if(l>n.count)return(n.name=o,n.count=l,!0)})),c+=4*e;i.success&&(y=f(h.palette),i.success({dominant:t(h.dominant.name),secondary:y[0],palette:y}))})};n.RGBaster=n.RGBaster||i}(window)