3
0
Fork 0
mirror of https://github.com/JulianGro/overte.git synced 2025-04-30 20:03:48 +02:00

multi-editing support for properties

This commit is contained in:
Thijs Wenker 2019-04-08 15:52:37 +02:00
parent 71770e3f4e
commit 8e97c4f3f2
4 changed files with 631 additions and 349 deletions

View file

@ -2361,41 +2361,64 @@ var PropertiesTool = function (opts) {
}
var i, properties, dY, diff, newPosition;
if (data.type === "update") {
if (selectionManager.selections.length > 1) {
for (i = 0; i < selectionManager.selections.length; i++) {
Entities.editEntity(selectionManager.selections[i], data.properties);
if (data.properties || data.propertiesMap) {
var propertiesMap = data.propertiesMap;
if (propertiesMap === undefined) {
var updateEntityIDs = data.ids !== undefined ? data.ids : selectionManager.selections;
propertiesMap = [];
propertiesMap.push({
entityIDs: updateEntityIDs,
properties: data.properties
});
}
} else if (data.properties) {
if (data.properties.dynamic === false) {
// this object is leaving dynamic, so we zero its velocities
data.properties.localVelocity = Vec3.ZERO;
data.properties.localAngularVelocity = Vec3.ZERO;
}
if (data.properties.rotation !== undefined) {
data.properties.rotation = Quat.fromVec3Degrees(data.properties.rotation);
}
if (data.properties.localRotation !== undefined) {
data.properties.localRotation = Quat.fromVec3Degrees(data.properties.localRotation);
}
if (data.properties.emitOrientation !== undefined) {
data.properties.emitOrientation = Quat.fromVec3Degrees(data.properties.emitOrientation);
}
if (data.properties.keyLight !== undefined && data.properties.keyLight.direction !== undefined) {
var currentKeyLightDirection = Vec3.toPolar(Entities.getEntityProperties(selectionManager.selections[0], ['keyLight.direction']).keyLight.direction);
if (data.properties.keyLight.direction.x === undefined) {
data.properties.keyLight.direction.x = currentKeyLightDirection.x;
var sendListUpdate = false;
propertiesMap.forEach(function(propertiesObject) {
var properties = propertiesObject.properties;
var updateEntityIDs = propertiesObject.entityIDs;
if (properties.dynamic === false) {
// this object is leaving dynamic, so we zero its velocities
properties.localVelocity = Vec3.ZERO;
properties.localAngularVelocity = Vec3.ZERO;
}
if (data.properties.keyLight.direction.y === undefined) {
data.properties.keyLight.direction.y = currentKeyLightDirection.y;
if (properties.rotation !== undefined) {
properties.rotation = Quat.fromVec3Degrees(properties.rotation);
}
data.properties.keyLight.direction = Vec3.fromPolar(data.properties.keyLight.direction.x, data.properties.keyLight.direction.y);
}
Entities.editEntity(selectionManager.selections[0], data.properties);
if (data.properties.name !== undefined || data.properties.modelURL !== undefined || data.properties.materialURL !== undefined ||
data.properties.visible !== undefined || data.properties.locked !== undefined) {
if (properties.localRotation !== undefined) {
properties.localRotation = Quat.fromVec3Degrees(properties.localRotation);
}
if (properties.emitOrientation !== undefined) {
properties.emitOrientation = Quat.fromVec3Degrees(properties.emitOrientation);
}
if (properties.keyLight !== undefined && properties.keyLight.direction !== undefined) {
var currentKeyLightDirection = Vec3.toPolar(Entities.getEntityProperties(selectionManager.selections[0], ['keyLight.direction']).keyLight.direction);
if (properties.keyLight.direction.x === undefined) {
properties.keyLight.direction.x = currentKeyLightDirection.x;
}
if (properties.keyLight.direction.y === undefined) {
properties.keyLight.direction.y = currentKeyLightDirection.y;
}
properties.keyLight.direction = Vec3.fromPolar(properties.keyLight.direction.x, properties.keyLight.direction.y);
}
updateEntityIDs.forEach(function (entityID) {
Entities.editEntity(entityID, properties);
});
if (properties.name !== undefined || properties.modelURL !== undefined || properties.materialURL !== undefined ||
properties.visible !== undefined || properties.locked !== undefined) {
sendListUpdate = true;
}
});
if (sendListUpdate) {
entityListTool.sendUpdate();
}
}
if (data.onlyUpdateEntities) {
blockPropertyUpdates = true;
} else {
@ -2405,9 +2428,9 @@ var PropertiesTool = function (opts) {
selectionManager._update(false, this);
blockPropertyUpdates = false;
} else if (data.type === 'saveUserData' || data.type === 'saveMaterialData') {
//the event bridge and json parsing handle our avatar id string differently.
var actualID = data.id.split('"')[1];
Entities.editEntity(actualID, data.properties);
data.ids.forEach(function(entityID) {
Entities.editEntity(entityID, data.properties);
});
} else if (data.type === "showMarketplace") {
showMarketplace();
} else if (data.type === "action") {

File diff suppressed because one or more lines are too long

View file

@ -13,6 +13,7 @@ function DraggableNumber(min, max, step, decimals, dragStart, dragEnd) {
this.min = min;
this.max = max;
this.step = step !== undefined ? step : 1;
this.multiDiffModeEnabled = false;
this.decimals = decimals;
this.dragStartFunction = dragStart;
this.dragEndFunction = dragEnd;
@ -20,6 +21,7 @@ function DraggableNumber(min, max, step, decimals, dragStart, dragEnd) {
this.initialMouseEvent = null;
this.lastMouseEvent = null;
this.valueChangeFunction = null;
this.multiDiffDragFunction = null;
this.initialize();
}
@ -71,21 +73,26 @@ DraggableNumber.prototype = {
}
if (this.dragging && this.lastMouseEvent) {
let initialValue = this.elInput.value;
let dx = event.clientX - this.lastMouseEvent.clientX;
let changeValue = dx !== 0;
if (changeValue) {
while (dx !== 0) {
if (dx > 0) {
this.elInput.stepUp();
--dx;
} else {
this.elInput.stepDown();
++dx;
let changeDelta = event.clientX - this.lastMouseEvent.clientX;
if (changeDelta !== 0) {
if (this.multiDiffModeEnabled) {
if (this.multiDiffDragFunction) {
this.multiDiffDragFunction(changeDelta * this.step);
}
} else {
while (changeDelta !== 0) {
if (changeDelta > 0) {
this.elInput.stepUp();
--changeDelta;
} else {
this.elInput.stepDown();
++changeDelta;
}
}
this.inputChange();
if (this.valueChangeFunction) {
this.valueChangeFunction();
}
}
this.inputChange();
if (this.valueChangeFunction) {
this.valueChangeFunction();
}
}
this.lastMouseEvent = event;
@ -124,20 +131,39 @@ DraggableNumber.prototype = {
}
},
setValue: function(newValue) {
if (newValue !== "" && this.decimals !== undefined) {
this.elInput.value = parseFloat(newValue).toFixed(this.decimals);
} else {
this.elInput.value = newValue;
setValue: function(newValue, isMultiDiff) {
if (isMultiDiff !== undefined) {
this.setMultiDiff(isMultiDiff);
}
if (!isMultiDiff) {
if (newValue !== "" && this.decimals !== undefined) {
this.elInput.value = parseFloat(newValue).toFixed(this.decimals);
} else {
this.elInput.value = newValue;
}
this.elText.firstChild.data = this.elInput.value;
}
},
setMultiDiff: function(isMultiDiff) {
this.multiDiffModeEnabled = isMultiDiff;
if (isMultiDiff) {
this.elDiv.classList.add('multi-diff');
} else {
this.elDiv.classList.remove('multi-diff');
}
this.elText.firstChild.data = this.elInput.value;
},
setValueChangeFunction: function(valueChangeFunction) {
this.valueChangeFunction = valueChangeFunction.bind(this.elInput);
this.elInput.addEventListener("change", this.valueChangeFunction);
},
setMultiDiffDragFunction: function(multiDiffDragFunction) {
this.multiDiffDragFunction = multiDiffDragFunction;
},
inputChange: function() {
let value = this.elInput.value;
if (this.max !== undefined) {
@ -203,7 +229,10 @@ DraggableNumber.prototype = {
this.elRightArrow.className = 'right-arrow';
this.elRightArrow.innerHTML = 'D';
this.elRightArrow.addEventListener("click", this.onStepUp);
this.elMultiDiff = document.createElement('span');
this.elMultiDiff.className = 'multi-diff';
this.elInput = document.createElement('input');
this.elInput.className = "input";
this.elInput.setAttribute("type", "number");
@ -220,6 +249,7 @@ DraggableNumber.prototype = {
this.elDiv.appendChild(this.elLeftArrow);
this.elDiv.appendChild(this.elText);
this.elDiv.appendChild(this.elInput);
this.elDiv.appendChild(this.elMultiDiff);
this.elDiv.appendChild(this.elRightArrow);
}
};

File diff suppressed because it is too large Load diff