fix avatar/shape material targets, refresh material target when parent changes

This commit is contained in:
unknown 2019-04-08 13:29:43 -07:00
parent 78256fb5bb
commit b8b9035f9d
2 changed files with 40 additions and 14 deletions

View file

@ -2523,12 +2523,17 @@ var PropertiesTool = function (opts) {
propertyRanges: propertyRanges, propertyRanges: propertyRanges,
}); });
} else if (data.type === "materialTargetRequest") { } 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; var parentModelData;
if (properties.type === "Material" && parentModel) { 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); parentModelData = Graphics.getModel(properties.parentID);
} else if (parentType === "Shape" || parentType === "Box" || parentType === "Sphere") {
parentModelData = {};
parentModelData.numMeshes = 1;
parentModelData.materialNames = [];
}
} }
emitScriptEvent({ emitScriptEvent({
type: 'materialTargetReply', type: 'materialTargetReply',

View file

@ -55,6 +55,7 @@ const GROUPS = [
label: "Parent", label: "Parent",
type: "string", type: "string",
propertyID: "parentID", propertyID: "parentID",
onChange: parentIDChanged,
}, },
{ {
label: "Parent Joint Index", label: "Parent Joint Index",
@ -2007,6 +2008,9 @@ function createStringProperty(property, elProperty) {
elInput.addEventListener('change', createEmitTextPropertyUpdateFunction(property)); elInput.addEventListener('change', createEmitTextPropertyUpdateFunction(property));
if (propertyData.onChange !== undefined) {
elInput.addEventListener('change', propertyData.onChange);
}
elProperty.appendChild(elInput); 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 * BUTTON CALLBACKS
*/ */
@ -3156,6 +3171,10 @@ function setTextareaScrolling(element) {
* MATERIAL TARGET FUNCTIONS * MATERIAL TARGET FUNCTIONS
*/ */
function requestMaterialTarget() {
EventBridge.emitWebEvent(JSON.stringify({ type: 'materialTargetRequest', entityID: selectedEntityProperties.id }));
}
function setMaterialTargetData(materialTargetData) { function setMaterialTargetData(materialTargetData) {
let elDivOptions = getPropertyInputElement("parentMaterialName"); let elDivOptions = getPropertyInputElement("parentMaterialName");
resetDynamicMultiselectProperty(elDivOptions); resetDynamicMultiselectProperty(elDivOptions);
@ -3256,8 +3275,10 @@ function sendMaterialTargetProperty() {
if (materialTargetList !== "") { if (materialTargetList !== "") {
materialTargetList = materialTargetList.substring(0, materialTargetList.length - 1); materialTargetList = materialTargetList.substring(0, materialTargetList.length - 1);
if (materialTargetList.length > 1) {
materialTargetList = "[" + materialTargetList + "]"; materialTargetList = "[" + materialTargetList + "]";
} }
}
updateProperty("parentMaterialName", materialTargetList, false); updateProperty("parentMaterialName", materialTargetList, false);
} }
@ -3780,7 +3801,7 @@ function loaded() {
} }
if (hasSelectedEntityChanged && selectedEntityProperties.type === "Material") { if (hasSelectedEntityChanged && selectedEntityProperties.type === "Material") {
EventBridge.emitWebEvent(JSON.stringify({ type: 'materialTargetRequest', entityID: selectedEntityProperties.id })); requestMaterialTarget();
} }
let activeElement = document.activeElement; let activeElement = document.activeElement;