mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 15:09:34 +02:00
Erase closest line
This commit is contained in:
parent
9c1bb37a34
commit
25761adf6c
1 changed files with 38 additions and 1 deletions
|
@ -26,7 +26,7 @@
|
||||||
// Paints in 3D.
|
// Paints in 3D.
|
||||||
var brushName = name,
|
var brushName = name,
|
||||||
STROKE_COLOR = { red: 250, green: 0, blue: 0 },
|
STROKE_COLOR = { red: 250, green: 0, blue: 0 },
|
||||||
ERASE_SEARCH_DISTANCE = 0.1, // m
|
ERASE_SEARCH_RADIUS = 0.1, // m
|
||||||
isDrawingLine = false,
|
isDrawingLine = false,
|
||||||
entityID,
|
entityID,
|
||||||
basePosition,
|
basePosition,
|
||||||
|
@ -118,6 +118,43 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function eraseClosestLine(position) {
|
function eraseClosestLine(position) {
|
||||||
|
// Erase closest line that is within search radius of finger tip.
|
||||||
|
var entities,
|
||||||
|
entitiesLength,
|
||||||
|
properties,
|
||||||
|
entityID,
|
||||||
|
entityDistance,
|
||||||
|
i,
|
||||||
|
pointsLength,
|
||||||
|
j,
|
||||||
|
distance,
|
||||||
|
found = false,
|
||||||
|
foundID,
|
||||||
|
foundDistance = ERASE_SEARCH_RADIUS;
|
||||||
|
|
||||||
|
// Find entities with bounding box within search radius.
|
||||||
|
entities = Entities.findEntities(position, ERASE_SEARCH_RADIUS);
|
||||||
|
|
||||||
|
// Fine polyline entity with closest point within search radius.
|
||||||
|
for (i = 0, entitiesLength = entities.length; i < entitiesLength; i += 1) {
|
||||||
|
properties = Entities.getEntityProperties(entities[i], ["type", "position", "linePoints"]);
|
||||||
|
if (properties.type === "PolyLine") {
|
||||||
|
basePosition = properties.position;
|
||||||
|
for (j = 0, pointsLength = properties.linePoints.length; j < pointsLength; j += 1) {
|
||||||
|
distance = Vec3.distance(position, Vec3.sum(basePosition, properties.linePoints[j]));
|
||||||
|
if (distance <= foundDistance) {
|
||||||
|
found = true;
|
||||||
|
foundID = entities[i];
|
||||||
|
foundDistance = distance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete found entity.
|
||||||
|
if (found) {
|
||||||
|
Entities.deleteEntity(foundID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
|
|
Loading…
Reference in a new issue