Advertisement
Zuzuk

adseButtons

Sep 25th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var makeSkinEditorButtons = function (material, scene) {
  2.     var properties = [1, 1, 1]; // man, eye, nose
  3.     var maxProperties = [3, 3, 3];
  4.     var propertyNames = ["Man", "Eyes", "Nose"];
  5.     var usedTextures = [];
  6.  
  7.     var makeSkinEditorButton = function (propertyIndex, right) {
  8.         let buttonId = "change" + propertyNames[propertyIndex] + (right ? "Right" : "Left");
  9.         let button = document.getElementById(buttonId); //changeEyesRight
  10.         //let button = document.getElementById("changeEyesRight");
  11.  
  12.         if (button) {
  13.             button.addEventListener("click", function () {
  14.                 let prop = properties[propertyIndex];
  15.                 let max = maxProperties[propertyIndex];
  16.                 properties[propertyIndex] = right ? prop + 1 <= max ? prop + 1 : 1 : prop - 1 < 1 ? max : prop - 1; //yeah, I like this kind of porn
  17.                 updateTexture();
  18.             });
  19.         }
  20.         else
  21.             console.log(buttonId + " is not found");
  22.     };
  23.     var makeSkinEditorButtonPair = function (propertyIndex) {
  24.         makeSkinEditorButton(propertyIndex, false);
  25.         makeSkinEditorButton(propertyIndex, true);
  26.     };
  27.    
  28.  
  29.     var updateTexture = function () {
  30.         var texture = null;
  31.         var newUrl = "/Content/images/skins/" +
  32.             propertyNames[0] + properties[0] +
  33.             propertyNames[1] + properties[1] +
  34.             propertyNames[2] + properties[2] + ".png";
  35.         for (var i = 0; i < usedTextures.length; i++) {
  36.             if (usedTextures[i].url === newUrl) {
  37.                 texture = usedTextures[i];
  38.                 break;
  39.             }
  40.         }
  41.         if (texture) {
  42.             material.albedoTexture = texture;
  43.         }
  44.         else {
  45.             material.albedoTexture = new BABYLON.Texture(newUrl, scene, false, true, BABYLON.Texture.NEAREST_SAMPLINGMODE);
  46.         }
  47.     };
  48.  
  49.     makeSkinEditorButtonPair(0);
  50.     makeSkinEditorButtonPair(1);
  51.     makeSkinEditorButtonPair(2);
  52.     updateTexture();
  53. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement