mirror of
https://github.com/lubosz/overte.git
synced 2025-04-07 15:22:09 +02:00
implement support for zone properties in filters
This commit is contained in:
parent
5a843b1342
commit
17288386ae
2 changed files with 49 additions and 0 deletions
|
@ -73,12 +73,37 @@ bool EntityEditFilters::filter(glm::vec3& position, EntityItemProperties& proper
|
|||
auto currentProperties = existingEntity ? existingEntity->getProperties() : EntityItemProperties();
|
||||
QScriptValue currentValues = currentProperties.copyToScriptValue(filterData.engine, false, true, true);
|
||||
|
||||
// get the zone properties
|
||||
auto zoneEntity = _tree->findEntityByEntityItemID(id);
|
||||
auto zoneProperties = zoneEntity ? zoneEntity->getProperties() : EntityItemProperties();
|
||||
QScriptValue zoneValues = zoneProperties.copyToScriptValue(filterData.engine, false, true, true);
|
||||
|
||||
if (zoneEntity) {
|
||||
bool success = true;
|
||||
AABox aaBox = zoneEntity->getAABox(success);
|
||||
|
||||
if (success) {
|
||||
QScriptValue boundingBox = filterData.engine->newObject();
|
||||
QScriptValue bottomRightNear = vec3toScriptValue(filterData.engine, aaBox.getCorner());
|
||||
QScriptValue topFarLeft = vec3toScriptValue(filterData.engine, aaBox.calcTopFarLeft());
|
||||
QScriptValue center = vec3toScriptValue(filterData.engine, aaBox.calcCenter());
|
||||
QScriptValue boundingBoxDimensions = vec3toScriptValue(filterData.engine, aaBox.getDimensions());
|
||||
boundingBox.setProperty("brn", bottomRightNear);
|
||||
boundingBox.setProperty("tfl", topFarLeft);
|
||||
boundingBox.setProperty("center", center);
|
||||
boundingBox.setProperty("dimensions", boundingBoxDimensions);
|
||||
zoneValues.setProperty("boundingBox", boundingBox);
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValueList args;
|
||||
args << inputValues;
|
||||
args << filterType;
|
||||
args << currentValues;
|
||||
args << zoneValues;
|
||||
|
||||
QScriptValue result = filterData.filterFn.call(_nullObjectForFilter, args);
|
||||
|
||||
if (filterData.uncaughtExceptions()) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
function filter(properties, type, originalProperties, zoneProperties) {
|
||||
|
||||
var nearZero = 0.0001 * Math.random() + 0.001;
|
||||
|
||||
/* Clamp position changes to bounding box of zone.*/
|
||||
function clamp(val, min, max) {
|
||||
/* Random near-zero value used as "zero" to prevent two sequential updates from being
|
||||
exactly the same (which would cause them to be ignored) */
|
||||
if (val > max) {
|
||||
val = max - nearZero;
|
||||
} else if (val < min) {
|
||||
val = min + nearZero;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
if (properties.position) {
|
||||
properties.position.x = clamp(properties.position.x, zoneProperties.boundingBox.brn.x, zoneProperties.boundingBox.tfl.x);
|
||||
properties.position.y = clamp(properties.position.y, zoneProperties.boundingBox.brn.y, zoneProperties.boundingBox.tfl.y);
|
||||
properties.position.z = clamp(properties.position.z, zoneProperties.boundingBox.brn.z, zoneProperties.boundingBox.tfl.z);
|
||||
}
|
||||
|
||||
return properties;
|
||||
}
|
Loading…
Reference in a new issue