mirror of
https://github.com/overte-org/overte.git
synced 2025-08-05 14:39:45 +02:00
flowy
This commit is contained in:
parent
191f7f2c22
commit
8aeb559848
2 changed files with 36 additions and 233 deletions
|
@ -11,6 +11,10 @@
|
|||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var eraseTrail = true;
|
||||
var ugLSD = 25;
|
||||
// var eraseTrail = false;
|
||||
var LEFT = 0;
|
||||
var RIGHT = 1;
|
||||
var LASER_WIDTH = 3;
|
||||
|
@ -23,13 +27,11 @@ var LASER_COLOR = {
|
|||
var MAX_POINTS_PER_LINE = 50;
|
||||
|
||||
var LIFETIME = 6000;
|
||||
var DRAWING_DEPTH = 0.3;
|
||||
var DRAWING_DEPTH = 0.2;
|
||||
var LINE_DIMENSIONS = 20;
|
||||
|
||||
|
||||
var MIN_POINT_DISTANCE = 0.03;
|
||||
|
||||
|
||||
var MIN_POINT_DISTANCE = 0.02;
|
||||
|
||||
|
||||
var colorPalette = [{
|
||||
|
@ -54,8 +56,7 @@ var colorPalette = [{
|
|||
blue: 122
|
||||
}];
|
||||
|
||||
var MIN_STROKE_WIDTH = 0.002;
|
||||
var MAX_STROKE_WIDTH = 0.05;
|
||||
var STROKE_WIDTH = 0.05;
|
||||
|
||||
function controller(side, triggerAction) {
|
||||
this.triggerHeld = false;
|
||||
|
@ -65,6 +66,16 @@ function controller(side, triggerAction) {
|
|||
this.cycleColorButton = side == LEFT ? Controller.Standard.LeftPrimaryThumb : Controller.Standard.RightPrimaryThumb;
|
||||
this.currentColorIndex = 0;
|
||||
this.currentColor = colorPalette[this.currentColorIndex];
|
||||
var textures = "http://localhost:8080/trails.png?v2" + Math.random();
|
||||
|
||||
// this.light = Entities.addEntity({
|
||||
// type: 'Light',
|
||||
// position: MyAvatar.position,
|
||||
// dimensions: {x: 20, y: 20, z: 20},
|
||||
// color: {red: 60, green: 10, blue: 100},
|
||||
// intensity: 10
|
||||
// });
|
||||
|
||||
this.trail = Entities.addEntity({
|
||||
type: "PolyLine",
|
||||
color: this.currentColor,
|
||||
|
@ -73,7 +84,7 @@ function controller(side, triggerAction) {
|
|||
y: LINE_DIMENSIONS,
|
||||
z: LINE_DIMENSIONS
|
||||
},
|
||||
textures: "http://localhost:8080/trails.png?v1" + Math.random(),
|
||||
textures: textures,
|
||||
lifetime: LIFETIME
|
||||
});
|
||||
this.points = [];
|
||||
|
@ -81,6 +92,18 @@ function controller(side, triggerAction) {
|
|||
this.strokeWidths = [];
|
||||
var self = this;
|
||||
|
||||
this.trailEraseInterval = Script.setInterval(function() {
|
||||
if (self.points.length > 0 && eraseTrail) {
|
||||
self.points.shift();
|
||||
self.normals.shift();
|
||||
self.strokeWidths.shift();
|
||||
Entities.editEntity(self.trail, {
|
||||
linePoints: self.points,
|
||||
strokeWidths: self.strokeWidths,
|
||||
normals: self.normals
|
||||
});
|
||||
}
|
||||
}, ugLSD);
|
||||
|
||||
this.cycleColor = function() {
|
||||
this.currentColor = colorPalette[++this.currentColorIndex];
|
||||
|
@ -101,6 +124,9 @@ function controller(side, triggerAction) {
|
|||
this.updateControllerState();
|
||||
var newTrailPosOffset = Vec3.multiply(Vec3.normalize(Vec3.subtract(this.tipPosition, this.palmPosition)), DRAWING_DEPTH);
|
||||
var newTrailPos = Vec3.sum(this.palmPosition, newTrailPosOffset);
|
||||
// Entities.editEntity(this.light, {
|
||||
// position: newTrailPos
|
||||
// });
|
||||
|
||||
|
||||
if (!this.drawing) {
|
||||
|
@ -125,8 +151,7 @@ function controller(side, triggerAction) {
|
|||
var normal = computeNormal(newTrailPos, Camera.getPosition());
|
||||
|
||||
this.normals.push(normal);
|
||||
var strokeWidth = MAX_STROKE_WIDTH;
|
||||
this.strokeWidths.push(strokeWidth);
|
||||
this.strokeWidths.push(STROKE_WIDTH);
|
||||
Entities.editEntity(this.trail, {
|
||||
linePoints: this.points,
|
||||
normals: this.normals,
|
||||
|
@ -158,6 +183,8 @@ function controller(side, triggerAction) {
|
|||
|
||||
this.cleanup = function() {
|
||||
Entities.deleteEntity(this.trail);
|
||||
// Entities.deleteEntity(this.light);
|
||||
Script.clearInterval(this.trailEraseInterval);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,224 +0,0 @@
|
|||
//
|
||||
// hydraPaint.js
|
||||
// examples
|
||||
//
|
||||
// Created by Eric Levin on 5/14/15.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// This script allows you to paint with the hydra!
|
||||
//
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
var LEFT = 0;
|
||||
var RIGHT = 1;
|
||||
var LASER_WIDTH = 3;
|
||||
var LASER_COLOR = {
|
||||
red: 50,
|
||||
green: 150,
|
||||
blue: 200
|
||||
};
|
||||
var TRIGGER_THRESHOLD = .1;
|
||||
|
||||
var MAX_POINTS_PER_LINE = 40;
|
||||
|
||||
var LIFETIME = 6000;
|
||||
var DRAWING_DEPTH = 1;
|
||||
var LINE_DIMENSIONS = 20;
|
||||
|
||||
|
||||
var MIN_POINT_DISTANCE = 0.01;
|
||||
|
||||
var MIN_BRUSH_RADIUS = 0.08;
|
||||
var MAX_BRUSH_RADIUS = 0.1;
|
||||
|
||||
var RIGHT_BUTTON_1 = 7
|
||||
var RIGHT_BUTTON_2 = 8
|
||||
var RIGHT_BUTTON_3 = 9;
|
||||
var RIGHT_BUTTON_4 = 10
|
||||
var LEFT_BUTTON_1 = 1;
|
||||
var LEFT_BUTTON_2 = 2;
|
||||
var LEFT_BUTTON_3 = 3;
|
||||
var LEFT_BUTTON_4 = 4;
|
||||
|
||||
var colorPalette = [{
|
||||
red: 250,
|
||||
green: 0,
|
||||
blue: 0
|
||||
}, {
|
||||
red: 214,
|
||||
green: 91,
|
||||
blue: 67
|
||||
}, {
|
||||
red: 192,
|
||||
green: 41,
|
||||
blue: 66
|
||||
}, {
|
||||
red: 84,
|
||||
green: 36,
|
||||
blue: 55
|
||||
}, {
|
||||
red: 83,
|
||||
green: 119,
|
||||
blue: 122
|
||||
}];
|
||||
|
||||
var MIN_STROKE_WIDTH = 0.002;
|
||||
var MAX_STROKE_WIDTH = 0.05;
|
||||
|
||||
function controller(side, triggerAction) {
|
||||
this.triggerHeld = false;
|
||||
this.triggerThreshold = 0.9;
|
||||
this.side = side;
|
||||
this.triggerAction = triggerAction;
|
||||
this.cycleColorButton = side == LEFT ? Controller.Standard.LeftPrimaryThumb : Controller.Standard.RightPrimaryThumb;
|
||||
|
||||
this.points = [];
|
||||
this.normals = [];
|
||||
this.strokeWidths = [];
|
||||
|
||||
this.currentColorIndex = 0;
|
||||
this.currentColor = colorPalette[this.currentColorIndex];
|
||||
|
||||
var self = this;
|
||||
|
||||
|
||||
this.brush = Entities.addEntity({
|
||||
type: 'Sphere',
|
||||
position: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
color: this.currentColor,
|
||||
dimensions: {
|
||||
x: MIN_BRUSH_RADIUS,
|
||||
y: MIN_BRUSH_RADIUS,
|
||||
z: MIN_BRUSH_RADIUS
|
||||
}
|
||||
});
|
||||
|
||||
this.cycleColor = function() {
|
||||
this.currentColor = colorPalette[++this.currentColorIndex];
|
||||
if (this.currentColorIndex === colorPalette.length - 1) {
|
||||
this.currentColorIndex = -1;
|
||||
}
|
||||
}
|
||||
this.newLine = function(position) {
|
||||
this.linePosition = position;
|
||||
this.line = Entities.addEntity({
|
||||
position: position,
|
||||
type: "PolyLine",
|
||||
color: this.currentColor,
|
||||
dimensions: {
|
||||
x: LINE_DIMENSIONS,
|
||||
y: LINE_DIMENSIONS,
|
||||
z: LINE_DIMENSIONS
|
||||
},
|
||||
textures: "http://localhost:8080/trails.png",
|
||||
lifetime: LIFETIME
|
||||
});
|
||||
this.points = [];
|
||||
this.normals = []
|
||||
this.strokeWidths = [];
|
||||
}
|
||||
|
||||
this.update = function(deltaTime) {
|
||||
this.updateControllerState();
|
||||
var newBrushPosOffset = Vec3.multiply(Vec3.normalize(Vec3.subtract(this.tipPosition, this.palmPosition)), DRAWING_DEPTH);
|
||||
var newBrushPos = Vec3.sum(this.palmPosition, newBrushPosOffset);
|
||||
var brushRadius = map(this.triggerValue, TRIGGER_THRESHOLD, 1, MIN_BRUSH_RADIUS, MAX_BRUSH_RADIUS)
|
||||
Entities.editEntity(this.brush, {
|
||||
position: newBrushPos,
|
||||
color: this.currentColor,
|
||||
dimensions: {
|
||||
x: brushRadius,
|
||||
y: brushRadius,
|
||||
z: brushRadius
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (this.triggerValue > TRIGGER_THRESHOLD && !this.drawing) {
|
||||
this.newLine(newBrushPos);
|
||||
this.drawing = true;
|
||||
} else if (this.drawing && this.triggerValue < TRIGGER_THRESHOLD) {
|
||||
this.drawing = false;
|
||||
}
|
||||
|
||||
if (this.drawing && this.points.length < MAX_POINTS_PER_LINE) {
|
||||
var localPoint = Vec3.subtract(newBrushPos, this.linePosition);
|
||||
if (Vec3.distance(localPoint, this.points[this.points.length - 1]) < MIN_POINT_DISTANCE) {
|
||||
//Need a minimum distance to avoid binormal NANs
|
||||
return;
|
||||
}
|
||||
|
||||
this.points.push(localPoint);
|
||||
var normal = computeNormal(newBrushPos, Camera.getPosition());
|
||||
|
||||
this.normals.push(normal);
|
||||
var strokeWidth = map(this.triggerValue, TRIGGER_THRESHOLD, 1, MIN_STROKE_WIDTH, MAX_STROKE_WIDTH);
|
||||
this.strokeWidths.push(strokeWidth);
|
||||
Entities.editEntity(this.line, {
|
||||
linePoints: this.points,
|
||||
normals: this.normals,
|
||||
strokeWidths: this.strokeWidths,
|
||||
color: this.currentColor
|
||||
});
|
||||
}
|
||||
|
||||
// Once we get to max points
|
||||
}
|
||||
|
||||
|
||||
this.updateControllerState = function() {
|
||||
this.cycleColorButtonPressed = Controller.getValue(this.cycleColorButton);
|
||||
this.palmPosition = this.side == RIGHT ? MyAvatar.rightHandPose.translation : MyAvatar.leftHandPose.translation;
|
||||
this.tipPosition = this.side == RIGHT ? MyAvatar.rightHandTipPose.translation : MyAvatar.leftHandTipPose.translation;
|
||||
this.triggerValue = Controller.getActionValue(this.triggerAction);
|
||||
|
||||
|
||||
if (this.prevCycleColorButtonPressed === true && this.cycleColorButtonPressed === false) {
|
||||
this.cycleColor();
|
||||
Entities.editEntity(this.brush, {
|
||||
// color: this.currentColor
|
||||
});
|
||||
}
|
||||
|
||||
this.prevCycleColorButtonPressed = this.cycleColorButtonPressed;
|
||||
|
||||
}
|
||||
|
||||
this.cleanup = function() {
|
||||
Entities.deleteEntity(self.brush);
|
||||
}
|
||||
}
|
||||
|
||||
function computeNormal(p1, p2) {
|
||||
return Vec3.normalize(Vec3.subtract(p2, p1));
|
||||
}
|
||||
|
||||
function update(deltaTime) {
|
||||
leftController.update(deltaTime);
|
||||
rightController.update(deltaTime);
|
||||
}
|
||||
|
||||
function scriptEnding() {
|
||||
leftController.cleanup();
|
||||
rightController.cleanup();
|
||||
}
|
||||
|
||||
function vectorIsZero(v) {
|
||||
return v.x === 0 && v.y === 0 && v.z === 0;
|
||||
}
|
||||
|
||||
|
||||
var rightController = new controller(RIGHT, Controller.findAction("RIGHT_HAND_CLICK"));
|
||||
var leftController = new controller(LEFT, Controller.findAction("LEFT_HAND_CLICK"));
|
||||
Script.update.connect(update);
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
|
||||
function map(value, min1, max1, min2, max2) {
|
||||
return min2 + (max2 - min2) * ((value - min1) / (max1 - min1));
|
||||
}
|
Loading…
Reference in a new issue