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,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() {

View file

@ -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;