From b8b9035f9d4530f50bd46d3033c88d05bf83895b Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 8 Apr 2019 13:29:43 -0700 Subject: [PATCH 1/2] fix avatar/shape material targets, refresh material target when parent changes --- scripts/system/edit.js | 29 +++++++++++++--------- scripts/system/html/js/entityProperties.js | 25 +++++++++++++++++-- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 11fc88dcbd..4f90c17e94 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -2523,18 +2523,23 @@ var PropertiesTool = function (opts) { propertyRanges: propertyRanges, }); } else if (data.type === "materialTargetRequest") { - var properties = Entities.getEntityProperties(data.entityID, ["type", "parentID"]); - var parentModel = properties.parentID !== Uuid.NULL && - Entities.getEntityProperties(properties.parentID, ["type"]).type === "Model"; - var parentModelData; - if (properties.type === "Material" && parentModel) { - parentModelData = Graphics.getModel(properties.parentID); - } - emitScriptEvent({ - type: 'materialTargetReply', - materialTargetData: parentModelData, - }); - } + var parentModelData; + var properties = Entities.getEntityProperties(data.entityID, ["type", "parentID"]); + if (properties.type === "Material" && properties.parentID !== Uuid.NULL) { + var parentType = Entities.getEntityProperties(properties.parentID, ["type"]).type; + if (parentType === "Model" || Entities.getNestableType(properties.parentID) === "avatar") { + parentModelData = Graphics.getModel(properties.parentID); + } else if (parentType === "Shape" || parentType === "Box" || parentType === "Sphere") { + parentModelData = {}; + parentModelData.numMeshes = 1; + parentModelData.materialNames = []; + } + } + emitScriptEvent({ + type: 'materialTargetReply', + materialTargetData: parentModelData, + }); + } }; HMD.displayModeChanged.connect(function() { diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index ca04f36dc9..1fe29cc579 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -55,6 +55,7 @@ const GROUPS = [ label: "Parent", type: "string", propertyID: "parentID", + onChange: parentIDChanged, }, { label: "Parent Joint Index", @@ -2007,6 +2008,9 @@ function createStringProperty(property, elProperty) { elInput.addEventListener('change', createEmitTextPropertyUpdateFunction(property)); + if (propertyData.onChange !== undefined) { + elInput.addEventListener('change', propertyData.onChange); + } elProperty.appendChild(elInput); @@ -2622,6 +2626,17 @@ function createProperty(propertyData, propertyElementID, propertyName, propertyI } +/** + * PROPERTY-SPECIFIC CALLBACKS + */ + +function parentIDChanged() { + if (selectedEntityProperties.type === "Material") { + requestMaterialTarget(); + } +} + + /** * BUTTON CALLBACKS */ @@ -3156,6 +3171,10 @@ function setTextareaScrolling(element) { * MATERIAL TARGET FUNCTIONS */ +function requestMaterialTarget() { + EventBridge.emitWebEvent(JSON.stringify({ type: 'materialTargetRequest', entityID: selectedEntityProperties.id })); +} + function setMaterialTargetData(materialTargetData) { let elDivOptions = getPropertyInputElement("parentMaterialName"); resetDynamicMultiselectProperty(elDivOptions); @@ -3256,7 +3275,9 @@ function sendMaterialTargetProperty() { if (materialTargetList !== "") { materialTargetList = materialTargetList.substring(0, materialTargetList.length - 1); - materialTargetList = "[" + materialTargetList + "]"; + if (materialTargetList.length > 1) { + materialTargetList = "[" + materialTargetList + "]"; + } } updateProperty("parentMaterialName", materialTargetList, false); @@ -3780,7 +3801,7 @@ function loaded() { } if (hasSelectedEntityChanged && selectedEntityProperties.type === "Material") { - EventBridge.emitWebEvent(JSON.stringify({ type: 'materialTargetRequest', entityID: selectedEntityProperties.id })); + requestMaterialTarget(); } let activeElement = document.activeElement; From 1537d4351d16a7bccf322553cc328448ef76e994 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 8 Apr 2019 14:07:25 -0700 Subject: [PATCH 2/2] CR changes from PR 15325 --- scripts/system/edit.js | 1 + scripts/system/html/js/entityProperties.js | 28 +++++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 4f90c17e94..0346e1c7a1 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -2537,6 +2537,7 @@ var PropertiesTool = function (opts) { } emitScriptEvent({ type: 'materialTargetReply', + entityID: data.entityID, materialTargetData: parentModelData, }); } diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index 1fe29cc579..bc8212ca1c 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -2480,7 +2480,7 @@ function resetDynamicMultiselectProperty(elDivOptions) { let elDivOption = elInputs[0].parentNode; elDivOption.parentNode.removeChild(elDivOption); } - elDivOptions.firstChild.style.display = "block"; // show "No Options" text + elDivOptions.firstChild.style.display = null; // show "No Options" text elDivOptions.parentNode.lastChild.style.display = "none"; // hide Select/Clear all buttons } @@ -3184,7 +3184,7 @@ function setMaterialTargetData(materialTargetData) { } elDivOptions.firstChild.style.display = "none"; // hide "No Options" text - elDivOptions.parentNode.lastChild.style.display = "block"; // show Select/Clear all buttons + elDivOptions.parentNode.lastChild.style.display = null; // show Select/Clear all buttons let numMeshes = materialTargetData.numMeshes; for (let i = 0; i < numMeshes; ++i) { @@ -3260,37 +3260,35 @@ function sendMaterialTargetProperty() { let elDivOptions = getPropertyInputElement("parentMaterialName"); let elInputs = elDivOptions.getElementsByClassName("materialTargetInput"); - let materialTargetList = ""; + let materialTargetList = []; for (let i = 0; i < elInputs.length; ++i) { let elInput = elInputs[i]; if (elInput.checked) { let targetID = elInput.getAttribute("targetID"); if (elInput.getAttribute("isMaterialName") === "true") { - materialTargetList += "mat::" + targetID + ","; + materialTargetList.push("mat::" + targetID); } else { - materialTargetList += targetID + ","; + materialTargetList.push(targetID); } } } - if (materialTargetList !== "") { - materialTargetList = materialTargetList.substring(0, materialTargetList.length - 1); - if (materialTargetList.length > 1) { - materialTargetList = "[" + materialTargetList + "]"; - } + let propertyValue = materialTargetList.join(","); + if (propertyValue.length > 1) { + propertyValue = "[" + propertyValue + "]"; } - updateProperty("parentMaterialName", materialTargetList, false); + updateProperty("parentMaterialName", propertyValue, false); } function materialTargetPropertyUpdate(propertyValue) { let elDivOptions = getPropertyInputElement("parentMaterialName"); let elInputs = elDivOptions.getElementsByClassName("materialTargetInput"); - if (propertyValue.charAt(0) === '[') { + if (propertyValue.startsWith('[')) { propertyValue = propertyValue.substring(1, propertyValue.length); } - if (propertyValue.charAt(propertyValue.length - 1) === ']') { + if (propertyValue.endsWith(']')) { propertyValue = propertyValue.substring(0, propertyValue.length - 1); } @@ -3854,7 +3852,9 @@ function loaded() { } } } else if (data.type === 'materialTargetReply') { - setMaterialTargetData(data.materialTargetData); + if (data.entityID === selectedEntityProperties.id) { + setMaterialTargetData(data.materialTargetData); + } } });