Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var makeSkinEditorButtons = function (material, scene) {
- var properties = [1, 1, 1]; // man, eye, nose
- var maxProperties = [3, 3, 3];
- var propertyNames = ["Man", "Eyes", "Nose"];
- var usedTextures = [];
- var makeSkinEditorButton = function (propertyIndex, right) {
- let buttonId = "change" + propertyNames[propertyIndex] + (right ? "Right" : "Left");
- let button = document.getElementById(buttonId); //changeEyesRight
- //let button = document.getElementById("changeEyesRight");
- if (button) {
- button.addEventListener("click", function () {
- let prop = properties[propertyIndex];
- let max = maxProperties[propertyIndex];
- properties[propertyIndex] = right ? prop + 1 <= max ? prop + 1 : 1 : prop - 1 < 1 ? max : prop - 1; //yeah, I like this kind of porn
- updateTexture();
- });
- }
- else
- console.log(buttonId + " is not found");
- };
- var makeSkinEditorButtonPair = function (propertyIndex) {
- makeSkinEditorButton(propertyIndex, false);
- makeSkinEditorButton(propertyIndex, true);
- };
- var updateTexture = function () {
- var texture = null;
- var newUrl = "/Content/images/skins/" +
- propertyNames[0] + properties[0] +
- propertyNames[1] + properties[1] +
- propertyNames[2] + properties[2] + ".png";
- for (var i = 0; i < usedTextures.length; i++) {
- if (usedTextures[i].url === newUrl) {
- texture = usedTextures[i];
- break;
- }
- }
- if (texture) {
- material.albedoTexture = texture;
- }
- else {
- material.albedoTexture = new BABYLON.Texture(newUrl, scene, false, true, BABYLON.Texture.NEAREST_SAMPLINGMODE);
- }
- };
- makeSkinEditorButtonPair(0);
- makeSkinEditorButtonPair(1);
- makeSkinEditorButtonPair(2);
- updateTexture();
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement