mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 06:44:06 +02:00
checking for bounds and modified paint script to start a new line entity if user paints outside of line entity's bounding box
This commit is contained in:
parent
8183e7393d
commit
830a8b6909
2 changed files with 49 additions and 33 deletions
|
@ -13,14 +13,15 @@
|
|||
//
|
||||
Script.include('lineRider.js')
|
||||
var MAX_POINTS_PER_LINE = 30;
|
||||
var LINE_LIFETIME = 60 * 5 //5 minute lifetime
|
||||
var DRAWING_DISTANCE = 5;
|
||||
var LINE_DIMENSIONS = 5;
|
||||
|
||||
var colorPalette = [{
|
||||
red: 236,
|
||||
green: 208,
|
||||
blue: 120
|
||||
}, {
|
||||
red: 217,
|
||||
red: 214,
|
||||
green: 91,
|
||||
blue: 67
|
||||
}, {
|
||||
|
@ -69,7 +70,7 @@ function hydraCheck() {
|
|||
//************ Mouse Paint **************************
|
||||
|
||||
function MousePaint() {
|
||||
var DRAWING_DISTANCE = 2;
|
||||
|
||||
var lines = [];
|
||||
var deletedLines = [];
|
||||
var isDrawing = false;
|
||||
|
@ -92,7 +93,7 @@ function MousePaint() {
|
|||
var points = [];
|
||||
|
||||
|
||||
var BRUSH_SIZE = 0.02;
|
||||
var BRUSH_SIZE = .05;
|
||||
|
||||
var brush = Entities.addEntity({
|
||||
type: 'Sphere',
|
||||
|
@ -111,45 +112,46 @@ function MousePaint() {
|
|||
|
||||
|
||||
function newLine(point) {
|
||||
if (!point) {
|
||||
return;
|
||||
}
|
||||
line = Entities.addEntity({
|
||||
position: MyAvatar.position,
|
||||
position: point,
|
||||
type: "Line",
|
||||
color: currentColor,
|
||||
dimensions: {
|
||||
x: 10,
|
||||
y: 10,
|
||||
z: 10
|
||||
x: LINE_DIMENSIONS,
|
||||
y: LINE_DIMENSIONS,
|
||||
z: LINE_DIMENSIONS
|
||||
},
|
||||
lineWidth: LINE_WIDTH,
|
||||
lifetime: LINE_LIFETIME
|
||||
lineWidth: LINE_WIDTH
|
||||
});
|
||||
points = [];
|
||||
if (point) {
|
||||
|
||||
points.push(point);
|
||||
path.push(point);
|
||||
}
|
||||
points.push(point);
|
||||
path.push(point);
|
||||
lines.push(line);
|
||||
}
|
||||
|
||||
|
||||
function mouseMoveEvent(event) {
|
||||
|
||||
var point = computePoint(event)
|
||||
Entities.editEntity(brush, {
|
||||
position: point
|
||||
});
|
||||
|
||||
if (!isDrawing) {
|
||||
return;
|
||||
}
|
||||
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var addVector = Vec3.multiply(Vec3.normalize(pickRay.direction), DRAWING_DISTANCE);
|
||||
var point = Vec3.sum(Camera.getPosition(), addVector);
|
||||
points.push(point);
|
||||
path.push(point);
|
||||
Entities.editEntity(line, {
|
||||
linePoints: points
|
||||
});
|
||||
Entities.editEntity(brush, {
|
||||
position: point
|
||||
});
|
||||
var success = Entities.setAllPoints(line, points);
|
||||
if (!success) {
|
||||
//We're out of bounds of entity bounding box, so start a new line
|
||||
newLine(point)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (points.length === MAX_POINTS_PER_LINE) {
|
||||
|
@ -158,6 +160,8 @@ function MousePaint() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function undoStroke() {
|
||||
var deletedLine = lines.pop();
|
||||
var deletedLineProps = Entities.getEntityProperties(deletedLine);
|
||||
|
@ -172,13 +176,14 @@ function MousePaint() {
|
|||
}
|
||||
|
||||
function mousePressEvent(event) {
|
||||
if(!event.isLeftButton) {
|
||||
if (!event.isLeftButton) {
|
||||
isDrawing = false;
|
||||
return;
|
||||
}
|
||||
lineRider.mousePressEvent(event);
|
||||
path = [];
|
||||
newLine();
|
||||
var point = computePoint(event);
|
||||
newLine(point);
|
||||
isDrawing = true;
|
||||
|
||||
|
||||
|
@ -198,14 +203,14 @@ function MousePaint() {
|
|||
if (event.text === "z") {
|
||||
undoStroke();
|
||||
}
|
||||
if(event.text === "x") {
|
||||
if (event.text === "x") {
|
||||
redoStroke();
|
||||
}
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
lines.forEach(function(line) {
|
||||
Entities.deleteEntity(line);
|
||||
// Entities.deleteEntity(line);
|
||||
});
|
||||
Entities.deleteEntity(brush);
|
||||
lineRider.cleanup();
|
||||
|
@ -255,6 +260,7 @@ function HydraPaint() {
|
|||
var maxLineWidth = 10;
|
||||
var currentLineWidth = minLineWidth;
|
||||
var MIN_PAINT_TRIGGER_THRESHOLD = .01;
|
||||
var LINE_LIFETIME = 20;
|
||||
var COLOR_CHANGE_TIME_FACTOR = 0.1;
|
||||
|
||||
var RIGHT_BUTTON_1 = 7
|
||||
|
@ -331,7 +337,7 @@ function HydraPaint() {
|
|||
z: 10
|
||||
},
|
||||
lineWidth: 5,
|
||||
lifetime: LINE_LIFETIME
|
||||
// lifetime: LINE_LIFETIME
|
||||
});
|
||||
this.points = [];
|
||||
if (point) {
|
||||
|
@ -482,6 +488,12 @@ function HydraPaint() {
|
|||
|
||||
}
|
||||
|
||||
function computePoint(event) {
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var addVector = Vec3.multiply(Vec3.normalize(pickRay.direction), DRAWING_DISTANCE);
|
||||
return Vec3.sum(Camera.getPosition(), addVector);
|
||||
}
|
||||
|
||||
function randFloat(low, high) {
|
||||
return low + Math.random() * (high - low);
|
||||
}
|
||||
|
|
|
@ -86,17 +86,21 @@ bool LineEntityItem::setProperties(const EntityItemProperties& properties) {
|
|||
}
|
||||
|
||||
bool LineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
|
||||
int invalidPoints = 0;
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
glm::vec3 point = points.at(i);
|
||||
// Make sure all of our points are valid numbers.
|
||||
// Must be greater than 0 because vector component is set to 0 if it is invalid data. Also should never be greater than TREE_SCALE
|
||||
if ( (point.x <= 0 || point.x >= TREE_SCALE) || (point.y <= 0 || point.y >= TREE_SCALE) || (point.z <= 0 || point.z >= TREE_SCALE) ) {
|
||||
qDebug() << "Point is outside domain bounds";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (invalidPoints > 0) {
|
||||
qDebug() << "Line with" << invalidPoints << "INVALID POINTS";
|
||||
glm::vec3 pos = getPosition();
|
||||
glm::vec3 halfBox = getDimensions() * 0.5f;
|
||||
if ( (point.x < pos.x - halfBox.x || point.x > pos.x + halfBox.x) || (point.y < pos.y - halfBox.y || point.y > pos.y + halfBox.y) || (point.z < pos.z - halfBox.z || point.z > pos.z + halfBox.z) ) {
|
||||
qDebug() << "Point is outside entity's bounding box";
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
_points = points;
|
||||
_pointsChanged = true;
|
||||
|
|
Loading…
Reference in a new issue