Merge pull request #15352 from dback2/materialTargetMasterFollowup

Case 22082, 22101: PR 15325 follow up and PR 15351 RC82 > Master
This commit is contained in:
Shannon Romano 2019-04-11 17:53:05 -07:00 committed by GitHub
commit 13fb3148a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 25 deletions

View file

@ -2523,18 +2523,24 @@ 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',
entityID: data.entityID,
materialTargetData: parentModelData,
});
}
};
HMD.displayModeChanged.connect(function() {

View file

@ -55,6 +55,7 @@ const GROUPS = [
label: "Parent",
type: "string",
propertyID: "parentID",
onChange: parentIDChanged,
},
{
label: "Parent Joint Index",
@ -2009,6 +2010,9 @@ function createStringProperty(property, elProperty) {
elInput.addEventListener('change', createEmitTextPropertyUpdateFunction(property));
if (propertyData.onChange !== undefined) {
elInput.addEventListener('change', propertyData.onChange);
}
elProperty.appendChild(elInput);
@ -2478,7 +2482,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
}
@ -2624,6 +2628,17 @@ function createProperty(propertyData, propertyElementID, propertyName, propertyI
}
/**
* PROPERTY-SPECIFIC CALLBACKS
*/
function parentIDChanged() {
if (selectedEntityProperties.type === "Material") {
requestMaterialTarget();
}
}
/**
* BUTTON CALLBACKS
*/
@ -3158,6 +3173,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);
@ -3167,7 +3186,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) {
@ -3243,35 +3262,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);
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);
}
@ -3782,7 +3801,7 @@ function loaded() {
}
if (hasSelectedEntityChanged && selectedEntityProperties.type === "Material") {
EventBridge.emitWebEvent(JSON.stringify({ type: 'materialTargetRequest', entityID: selectedEntityProperties.id }));
requestMaterialTarget();
}
let activeElement = document.activeElement;
@ -3835,7 +3854,9 @@ function loaded() {
}
}
} else if (data.type === 'materialTargetReply') {
setMaterialTargetData(data.materialTargetData);
if (data.entityID === selectedEntityProperties.id) {
setMaterialTargetData(data.materialTargetData);
}
}
});