Merge remote-tracking branch 'upstream/master'

This commit is contained in:
James B. Pollack 2015-09-29 21:34:39 -07:00
commit cbeeb62c32
19 changed files with 334 additions and 118 deletions

View file

@ -39,11 +39,13 @@ var ZERO_VEC = {
};
var totalTime = 0;
var lastUpdate = 0;
var UPDATE_INTERVAL = 1 / 30; // 30fps
var MINIMUM_LIGHT_INTENSITY = 0.75;
var MAXIMUM_LIGHT_INTENSITY = 2.75;
var LIGHT_INTENSITY_RANDOMNESS = 0.3;
var EPHEMERAL_LIFETIME = 10; // ephemeral entities will live for 10 seconds after script stops running
var EPHEMERAL_LIFETIME = 60; // ephemeral entities will live for 60 seconds after script stops running
var LightMaker = {
light: null,
@ -74,10 +76,17 @@ function update(deltaTime) {
LightMaker.spawnLight();
} else {
totalTime += deltaTime;
var intensity = (MINIMUM_LIGHT_INTENSITY + (MAXIMUM_LIGHT_INTENSITY + (Math.sin(totalTime) * MAXIMUM_LIGHT_INTENSITY)));
intensity += randFloat(-LIGHT_INTENSITY_RANDOMNESS, LIGHT_INTENSITY_RANDOMNESS);
var properties = Entities.getEntityProperties(LightMaker.light, "age");
Entities.editEntity(LightMaker.light, { intensity: intensity, lifetime: properties.age + EPHEMERAL_LIFETIME });
// We don't want to edit the entity EVERY update cycle, because that's just a lot
// of wasted bandwidth and extra effort on the server for very little visual gain
if (totalTime - lastUpdate > UPDATE_INTERVAL) {
var intensity = (MINIMUM_LIGHT_INTENSITY + (MAXIMUM_LIGHT_INTENSITY + (Math.sin(totalTime) * MAXIMUM_LIGHT_INTENSITY)));
intensity += randFloat(-LIGHT_INTENSITY_RANDOMNESS, LIGHT_INTENSITY_RANDOMNESS);
var properties = Entities.getEntityProperties(LightMaker.light, "age");
var newLifetime = properties.age + EPHEMERAL_LIFETIME;
Entities.editEntity(LightMaker.light, { type: "Light", intensity: intensity, lifetime: newLifetime });
lastUpdate = totalTime;
}
}
}

View file

@ -19,7 +19,8 @@ Script.include("../libraries/utils.js");
//
var TRIGGER_SMOOTH_RATIO = 0.1; // 0.0 disables smoothing of trigger value
var TRIGGER_ON_VALUE = 0.2;
var TRIGGER_ON_VALUE = 0.4;
var TRIGGER_OFF_VALUE = 0.15;
/////////////////////////////////////////////////////////////////
//
@ -54,7 +55,11 @@ var RELEASE_VELOCITY_MULTIPLIER = 1.5; // affects throwing things
var RIGHT_HAND = 1;
var LEFT_HAND = 0;
var ZERO_VEC = { x: 0, y: 0, z: 0};
var ZERO_VEC = {
x: 0,
y: 0,
z: 0
};
var NULL_ACTION_ID = "{00000000-0000-0000-000000000000}";
var MSEC_PER_SEC = 1000.0;
@ -63,18 +68,29 @@ var startTime = Date.now();
var LIFETIME = 10;
// states for the state machine
var STATE_SEARCHING = 0;
var STATE_DISTANCE_HOLDING = 1;
var STATE_CONTINUE_DISTANCE_HOLDING = 2;
var STATE_NEAR_GRABBING = 3;
var STATE_CONTINUE_NEAR_GRABBING = 4;
var STATE_NEAR_GRABBING_NON_COLLIDING = 5;
var STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING = 6;
var STATE_RELEASE = 7;
var STATE_OFF = 0;
var STATE_SEARCHING = 1;
var STATE_DISTANCE_HOLDING = 2;
var STATE_CONTINUE_DISTANCE_HOLDING = 3;
var STATE_NEAR_GRABBING = 4;
var STATE_CONTINUE_NEAR_GRABBING = 5;
var STATE_NEAR_GRABBING_NON_COLLIDING = 6;
var STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING = 7;
var STATE_RELEASE = 8;
var GRAB_USER_DATA_KEY = "grabKey";
var GRABBABLE_DATA_KEY = "grabbableKey";
// HACK -- until we have collision groups, don't allow held object to collide with avatar
var AVATAR_COLLISIONS_MENU_ITEM = "Enable avatar collisions";
// HACK -- until we have collision groups, don't allow held object to collide with avatar
var initialAvatarCollisionsMenu = Menu.isOptionChecked(AVATAR_COLLISIONS_MENU_ITEM);
var currentAvatarCollisionsMenu = initialAvatarCollisionsMenu;
var noCollisionsCount = 0; // how many hands want collisions disabled?
function MyController(hand, triggerAction) {
this.hand = hand;
if (this.hand === RIGHT_HAND) {
@ -85,23 +101,32 @@ function MyController(hand, triggerAction) {
this.getHandRotation = MyAvatar.getLeftPalmRotation;
}
var SPATIAL_CONTROLLERS_PER_PALM = 2;
var TIP_CONTROLLER_OFFSET = 1;
this.triggerAction = triggerAction;
this.palm = 2 * hand;
// this.tip = 2 * hand + 1; // unused, but I'm leaving this here for fear it will be needed
this.palm = SPATIAL_CONTROLLERS_PER_PALM * hand;
this.tip = SPATIAL_CONTROLLERS_PER_PALM * hand + TIP_CONTROLLER_OFFSET;
this.actionID = null; // action this script created...
this.grabbedEntity = null; // on this entity.
this.grabbedVelocity = ZERO_VEC; // rolling average of held object's velocity
this.state = 0;
this.state = STATE_OFF;
this.pointer = null; // entity-id of line object
this.triggerValue = 0; // rolling average of trigger value
var _this = this;
this.update = function() {
this.updateSmoothedTrigger();
switch (this.state) {
case STATE_OFF:
this.off();
this.touchTest();
break;
case STATE_SEARCHING:
this.search();
this.touchTest();
break;
case STATE_DISTANCE_HOLDING:
this.distanceHolding();
@ -127,6 +152,28 @@ function MyController(hand, triggerAction) {
}
};
// HACK -- until we have collision groups, don't allow held object to collide with avatar
this.disableAvatarCollisions = function() {
noCollisionsCount += 1;
if (currentAvatarCollisionsMenu != false) {
currentAvatarCollisionsMenu = false;
Menu.setIsOptionChecked(AVATAR_COLLISIONS_MENU_ITEM, false);
MyAvatar.updateMotionBehaviorFromMenu();
}
}
// HACK -- until we have collision groups, don't allow held object to collide with avatar
this.revertAvatarCollisions = function() {
noCollisionsCount -= 1;
if (noCollisionsCount < 1) {
if (currentAvatarCollisionsMenu != initialAvatarCollisionsMenu) {
currentAvatarCollisionsMenu = initialAvatarCollisionsMenu;
Menu.setIsOptionChecked(AVATAR_COLLISIONS_MENU_ITEM, initialAvatarCollisionsMenu);
MyAvatar.updateMotionBehaviorFromMenu();
}
}
}
this.lineOn = function(closePoint, farPoint, color) {
// draw a line
if (this.pointer === null) {
@ -158,21 +205,35 @@ function MyController(hand, triggerAction) {
this.pointer = null;
};
this.triggerSmoothedSqueezed = function() {
this.updateSmoothedTrigger = function() {
var triggerValue = Controller.getActionValue(this.triggerAction);
// smooth out trigger value
this.triggerValue = (this.triggerValue * TRIGGER_SMOOTH_RATIO) +
(triggerValue * (1.0 - TRIGGER_SMOOTH_RATIO));
}
this.triggerSmoothedSqueezed = function() {
return this.triggerValue > TRIGGER_ON_VALUE;
};
this.triggerSmoothedReleased = function() {
return this.triggerValue < TRIGGER_OFF_VALUE;
};
this.triggerSqueezed = function() {
var triggerValue = Controller.getActionValue(this.triggerAction);
return triggerValue > TRIGGER_ON_VALUE;
};
this.off = function() {
if (this.triggerSmoothedSqueezed()) {
this.state = STATE_SEARCHING;
return;
}
}
this.search = function() {
if (!this.triggerSmoothedSqueezed()) {
if (this.triggerSmoothedReleased()) {
this.state = STATE_RELEASE;
return;
}
@ -244,6 +305,10 @@ function MyController(hand, triggerAction) {
};
this.distanceHolding = function() {
// HACK -- until we have collision groups, don't allow held object to collide with avatar
this.disableAvatarCollisions();
var handControllerPosition = Controller.getSpatialControlPosition(this.palm);
var handRotation = Quat.multiply(MyAvatar.orientation, Controller.getSpatialControlRawRotation(this.palm));
var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, ["position", "rotation"]);
@ -276,10 +341,16 @@ function MyController(hand, triggerAction) {
Entities.callEntityMethod(this.grabbedEntity, "startDistantGrab");
}
this.currentAvatarPosition = MyAvatar.position;
this.currentAvatarOrientation = MyAvatar.orientation;
};
this.continueDistanceHolding = function() {
if (!this.triggerSmoothedSqueezed()) {
if (this.triggerSmoothedReleased()) {
// HACK -- until we have collision groups, don't allow held object to collide with avatar
this.revertAvatarCollisions();
this.state = STATE_RELEASE;
return;
}
@ -294,11 +365,46 @@ function MyController(hand, triggerAction) {
// the action was set up on a previous call. update the targets.
var radius = Math.max(Vec3.distance(this.currentObjectPosition, handControllerPosition) * DISTANCE_HOLDING_RADIUS_FACTOR, DISTANCE_HOLDING_RADIUS_FACTOR);
// how far did avatar move this timestep?
var currentPosition = MyAvatar.position;
var avatarDeltaPosition = Vec3.subtract(currentPosition, this.currentAvatarPosition);
this.currentAvatarPosition = currentPosition;
// How far did the avatar turn this timestep?
// Note: The following code is too long because we need a Quat.quatBetween() function
// that returns the minimum quaternion between two quaternions.
var currentOrientation = MyAvatar.orientation;
if (Quat.dot(currentOrientation, this.currentAvatarOrientation) < 0.0) {
var negativeCurrentOrientation = {
x: -currentOrientation.x,
y: -currentOrientation.y,
z: -currentOrientation.z,
w: -currentOrientation.w
};
var avatarDeltaOrientation = Quat.multiply(negativeCurrentOrientation, Quat.inverse(this.currentAvatarOrientation));
} else {
var avatarDeltaOrientation = Quat.multiply(currentOrientation, Quat.inverse(this.currentAvatarOrientation));
}
var handToAvatar = Vec3.subtract(handControllerPosition, this.currentAvatarPosition);
var objectToAvatar = Vec3.subtract(this.currentObjectPosition, this.currentAvatarPosition);
var handMovementFromTurning = Vec3.subtract(Quat.multiply(avatarDeltaOrientation, handToAvatar), handToAvatar);
var objectMovementFromTurning = Vec3.subtract(Quat.multiply(avatarDeltaOrientation, objectToAvatar), objectToAvatar);
this.currentAvatarOrientation = currentOrientation;
// how far did hand move this timestep?
var handMoved = Vec3.subtract(handControllerPosition, this.handPreviousPosition);
this.handPreviousPosition = handControllerPosition;
// magnify the hand movement but not the change from avatar movement & rotation
handMoved = Vec3.subtract(handMoved, avatarDeltaPosition);
handMoved = Vec3.subtract(handMoved, handMovementFromTurning);
var superHandMoved = Vec3.multiply(handMoved, radius);
// Move the object by the magnified amount and then by amount from avatar movement & rotation
var newObjectPosition = Vec3.sum(this.currentObjectPosition, superHandMoved);
newObjectPosition = Vec3.sum(newObjectPosition, avatarDeltaPosition);
newObjectPosition = Vec3.sum(newObjectPosition, objectMovementFromTurning);
var deltaPosition = Vec3.subtract(newObjectPosition, this.currentObjectPosition); // meters
var now = Date.now();
var deltaTime = (now - this.currentObjectTime) / MSEC_PER_SEC; // convert to seconds
@ -323,7 +429,14 @@ function MyController(hand, triggerAction) {
};
this.nearGrabbing = function() {
if (!this.triggerSmoothedSqueezed()) {
// HACK -- until we have collision groups, don't allow held object to collide with avatar
this.disableAvatarCollisions();
if (this.triggerSmoothedReleased()) {
// HACK -- until we have collision groups, don't allow held object to collide with avatar
this.revertAvatarCollisions();
this.state = STATE_RELEASE;
return;
}
@ -363,40 +476,55 @@ function MyController(hand, triggerAction) {
}
this.currentHandControllerPosition = Controller.getSpatialControlPosition(this.palm);
this.currentHandControllerTipPosition = Controller.getSpatialControlPosition(this.tip);
this.currentObjectTime = Date.now();
};
this.continueNearGrabbing = function() {
if (!this.triggerSmoothedSqueezed()) {
if (this.triggerSmoothedReleased()) {
// HACK -- until we have collision groups, don't allow held object to collide with avatar
this.revertAvatarCollisions();
this.state = STATE_RELEASE;
return;
}
// keep track of the measured velocity of the held object
var handControllerPosition = Controller.getSpatialControlPosition(this.palm);
// Keep track of the fingertip velocity to impart when we release the object
// Note that the idea of using a constant 'tip' velocity regardless of the
// object's actual held offset is an idea intended to make it easier to throw things:
// Because we might catch something or transfer it between hands without a good idea
// of it's actual offset, let's try imparting a velocity which is at a fixed radius
// from the palm.
var handControllerPosition = Controller.getSpatialControlPosition(this.tip);
var now = Date.now();
var deltaPosition = Vec3.subtract(handControllerPosition, this.currentHandControllerPosition); // meters
var deltaPosition = Vec3.subtract(handControllerPosition, this.currentHandControllerTipPosition); // meters
var deltaTime = (now - this.currentObjectTime) / MSEC_PER_SEC; // convert to seconds
this.computeReleaseVelocity(deltaPosition, deltaTime, true);
this.currentHandControllerPosition = handControllerPosition;
this.currentHandControllerTipPosition = handControllerPosition;
this.currentObjectTime = now;
Entities.callEntityMethod(this.grabbedEntity, "continueNearGrab");
};
this.nearGrabbingNonColliding = function() {
if (!this.triggerSmoothedSqueezed()) {
if (this.triggerSmoothedReleased()) {
this.state = STATE_RELEASE;
return;
}
if (this.hand === RIGHT_HAND) {
Entities.callEntityMethod(this.grabbedEntity, "setRightHand");
} else {
Entities.callEntityMethod(this.grabbedEntity, "setLeftHand");
}
Entities.callEntityMethod(this.grabbedEntity, "startNearGrabNonColliding");
this.state = STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING;
};
this.continueNearGrabbingNonColliding = function() {
if (!this.triggerSmoothedSqueezed()) {
if (this.triggerSmoothedReleased()) {
this.state = STATE_RELEASE;
return;
}
@ -459,17 +587,14 @@ function MyController(hand, triggerAction) {
};
this.startTouch = function(entityID) {
// print('START TOUCH' + entityID);
Entities.callEntityMethod(entityID, "startTouch");
};
this.continueTouch = function(entityID) {
// print('CONTINUE TOUCH' + entityID);
Entities.callEntityMethod(entityID, "continueTouch");
};
this.stopTouch = function(entityID) {
// print('STOP TOUCH' + entityID);
Entities.callEntityMethod(entityID, "stopTouch");
};
@ -491,10 +616,13 @@ function MyController(hand, triggerAction) {
};
this.release = function() {
this.lineOff();
if (this.grabbedEntity !== null && this.actionID !== null) {
Entities.deleteAction(this.grabbedEntity, this.actionID);
if (this.grabbedEntity !== null) {
if(this.actionID !== null) {
Entities.deleteAction(this.grabbedEntity, this.actionID);
}
Entities.callEntityMethod(this.grabbedEntity, "releaseGrab");
}
@ -508,7 +636,7 @@ function MyController(hand, triggerAction) {
this.grabbedVelocity = ZERO_VEC;
this.grabbedEntity = null;
this.actionID = null;
this.state = STATE_SEARCHING;
this.state = STATE_OFF;
};
this.cleanup = function() {

View file

@ -0,0 +1,10 @@
float getProceduralColors(inout vec3 diffuse, inout vec3 specular, inout float shininess) {
specular = _modelNormal.rgb;
if (any(lessThan(specular, vec3(0.0)))) {
specular = vec3(1.0) + specular;
}
diffuse = vec3(1.0, 1.0, 1.0);
return 1.0;
}

View file

@ -0,0 +1,42 @@
function avatarRelativePosition(position) {
return Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, position));
}
ColorCube = function() {};
ColorCube.prototype.NAME = "ColorCube";
ColorCube.prototype.POSITION = { x: 0, y: 0.5, z: -0.5 };
ColorCube.prototype.USER_DATA = { ProceduralEntity: {
version: 2, shaderUrl: Script.resolvePath("colorCube.fs"),
} };
// Clear any previous entities within 50 meters
ColorCube.prototype.clear = function() {
var ids = Entities.findEntities(MyAvatar.position, 50);
var that = this;
ids.forEach(function(id) {
var properties = Entities.getEntityProperties(id);
if (properties.name == that.NAME) {
Entities.deleteEntity(id);
}
}, this);
}
ColorCube.prototype.create = function() {
var that = this;
var size = HMD.ipd;
var id = Entities.addEntity({
type: "Box",
position: avatarRelativePosition(that.POSITION),
name: that.NAME,
color: that.COLOR,
ignoreCollisions: true,
collisionsWillMove: false,
dimensions: { x: size, y: size, z: size },
lifetime: 3600,
userData: JSON.stringify(that.USER_DATA)
});
}
var colorCube = new ColorCube();
colorCube.clear();
colorCube.create();

View file

@ -446,9 +446,9 @@ Menu::Menu() {
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::FixGaze, 0, false);
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::EnableAvatarUpdateThreading, 0, false,
qApp, SLOT(setAvatarUpdateThreading(bool)));
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::EnableRigAnimations, 0, true,
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::EnableRigAnimations, 0, false,
avatar, SLOT(setEnableRigAnimations(bool)));
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::EnableAnimGraph, 0, false,
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::EnableAnimGraph, 0, true,
avatar, SLOT(setEnableAnimGraph(bool)));
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::AnimDebugDrawBindPose, 0, false,
avatar, SLOT(setEnableDebugDrawBindPose(bool)));

View file

@ -153,7 +153,8 @@ void MyAvatar::reset() {
// This should be simpler when we have only graph animations always on.
bool isRig = _rig->getEnableRig();
bool isGraph = _rig->getEnableAnimGraph();
// seting rig animation to true, below, will clear the graph animation menu item, so grab it now.
bool isGraph = _rig->getEnableAnimGraph() || Menu::getInstance()->isOptionChecked(MenuOption::EnableAnimGraph);
qApp->setRawAvatarUpdateThreading(false);
_rig->disableHands = true;
setEnableRigAnimations(true);
@ -1764,6 +1765,12 @@ void MyAvatar::goToLocation(const glm::vec3& newPosition,
}
void MyAvatar::updateMotionBehaviorFromMenu() {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "updateMotionBehaviorFromMenu");
return;
}
Menu* menu = Menu::getInstance();
if (menu->isOptionChecked(MenuOption::KeyboardMotorControl)) {
_motionBehaviors |= AVATAR_MOTION_KEYBOARD_MOTOR_ENABLED;

View file

@ -193,7 +193,7 @@ public slots:
glm::vec3 getThrust() { return _thrust; };
void setThrust(glm::vec3 newThrust) { _thrust = newThrust; }
void updateMotionBehaviorFromMenu();
Q_INVOKABLE void updateMotionBehaviorFromMenu();
glm::vec3 getLeftPalmPosition();
glm::vec3 getLeftPalmVelocity();

View file

@ -10,7 +10,7 @@
//
#include "HMDScriptingInterface.h"
#include "display-plugins/DisplayPlugin.h"
#include <avatar/AvatarManager.h>
HMDScriptingInterface& HMDScriptingInterface::getInstance() {
@ -53,3 +53,7 @@ QScriptValue HMDScriptingInterface::getHUDLookAtPosition3D(QScriptContext* conte
}
return QScriptValue::NullValue;
}
float HMDScriptingInterface::getIPD() const {
return Application::getInstance()->getActiveDisplayPlugin()->getIPD();
}

View file

@ -20,6 +20,7 @@ class HMDScriptingInterface : public QObject {
Q_OBJECT
Q_PROPERTY(bool magnifier READ getMagnifier)
Q_PROPERTY(bool active READ isHMDMode)
Q_PROPERTY(float ipd READ getIPD)
public:
static HMDScriptingInterface& getInstance();
@ -33,6 +34,7 @@ private:
HMDScriptingInterface() {};
bool getMagnifier() const { return Application::getInstance()->getApplicationCompositor().hasMagnifier(); };
bool isHMDMode() const { return Application::getInstance()->isHMDMode(); }
float getIPD() const;
bool getHUDLookAtPosition3D(glm::vec3& result) const;

View file

@ -93,9 +93,9 @@ void AnimStateMachine::switchState(const AnimVariantMap& animVars, State::Pointe
const float dt = 0.0f;
Triggers triggers;
_nextPoses = nextStateNode->evaluate(animVars, dt, triggers);
#if WANT_DEBUGa
qCDebug(animation) << "AnimStateMachine::switchState:" << _currentState->getID() << "->" << desiredState->getID() << "duration =" << duration << "targetFrame =" << desiredState->_interpTarget;
#endif
_currentState = desiredState;
}

View file

@ -989,8 +989,11 @@ void AvatarData::setFaceModelURL(const QUrl& faceModelURL) {
}
void AvatarData::setSkeletonModelURL(const QUrl& skeletonModelURL) {
_skeletonModelURL = skeletonModelURL.isEmpty() ? AvatarData::defaultFullAvatarModelUrl() : skeletonModelURL;
const QUrl& expanded = skeletonModelURL.isEmpty() ? AvatarData::defaultFullAvatarModelUrl() : skeletonModelURL;
if (expanded == _skeletonModelURL) {
return;
}
_skeletonModelURL = expanded;
qCDebug(avatars) << "Changing skeleton model for avatar to" << _skeletonModelURL.toString();
updateJointMappings();

View file

@ -121,6 +121,8 @@ public:
static const glm::mat4 pose; return pose;
}
virtual float getIPD() const { return 0.0f; }
virtual void abandonCalibration() {}
virtual void resetSensors() {}
virtual float devicePixelRatio() { return 1.0; }

View file

@ -149,3 +149,11 @@ void OculusBaseDisplayPlugin::deactivate() {
void OculusBaseDisplayPlugin::display(GLuint finalTexture, const glm::uvec2& sceneSize) {
++_frameIndex;
}
float OculusBaseDisplayPlugin::getIPD() const {
float result = 0.0f;
#if (OVR_MAJOR_VERSION >= 6)
result = ovr_GetFloat(_hmd, OVR_KEY_IPD, OVR_DEFAULT_IPD);
#endif
return result;
}

View file

@ -31,6 +31,7 @@ public:
virtual void resetSensors() override final;
virtual glm::mat4 getEyePose(Eye eye) const override final;
virtual glm::mat4 getHeadPose() const override final;
virtual float getIPD() const override final;
protected:
virtual void preRender() override final;

View file

@ -43,7 +43,7 @@ void RenderablePolyLineEntityItem::createPipeline() {
static const int NORMAL_OFFSET = 12;
static const int COLOR_OFFSET = 24;
static const int TEXTURE_OFFSET = 28;
auto textureCache = DependencyManager::get<TextureCache>();
QString path = PathUtils::resourcesPath() + "images/paintStroke.png";
_texture = textureCache->getImageTexture(path);
@ -52,22 +52,22 @@ void RenderablePolyLineEntityItem::createPipeline() {
_format->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), NORMAL_OFFSET);
_format->setAttribute(gpu::Stream::COLOR, 0, gpu::Element::COLOR_RGBA_32, COLOR_OFFSET);
_format->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), TEXTURE_OFFSET);
auto VS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(paintStroke_vert)));
auto PS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(paintStroke_frag)));
gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(VS, PS));
gpu::Shader::BindingSet slotBindings;
PAINTSTROKE_GPU_SLOT = 0;
slotBindings.insert(gpu::Shader::Binding(std::string("paintStrokeTextureBinding"), PAINTSTROKE_GPU_SLOT));
gpu::Shader::makeProgram(*program, slotBindings);
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
state->setDepthTest(true, true, gpu::LESS_EQUAL);
state->setBlendFunction(true,
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
_pipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
_pipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
}
void RenderablePolyLineEntityItem::updateGeometry() {
@ -78,30 +78,30 @@ void RenderablePolyLineEntityItem::updateGeometry() {
float tailStart = 0.0f;
float tailEnd = 0.25f;
float tailLength = tailEnd - tailStart;
float headStart = 0.76f;
float headEnd = 1.0f;
float headLength = headEnd - headStart;
float uCoord, vCoord;
int numTailStrips = 5;
int numTailStrips = 5;
int numHeadStrips = 10;
int startHeadIndex = _normals.size() - numHeadStrips;
for (int i = 0; i < _normals.size(); i++) {
int startHeadIndex = _vertices.size() / 2 - numHeadStrips;
for (int i = 0; i < _vertices.size() / 2; i++) {
uCoord = 0.26f;
vCoord = 0.0f;
//tail
if(i < numTailStrips) {
uCoord = float(i)/numTailStrips * tailLength + tailStart;
if (i < numTailStrips) {
uCoord = float(i) / numTailStrips * tailLength + tailStart;
}
//head
if( i > startHeadIndex) {
uCoord = float( (i+ 1) - startHeadIndex)/numHeadStrips * headLength + headStart;
if (i > startHeadIndex) {
uCoord = float((i + 1) - startHeadIndex) / numHeadStrips * headLength + headStart;
}
uv = vec2(uCoord, vCoord);
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex));
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i));
_verticesBuffer->append(sizeof(int), (gpu::Byte*)&_color);
@ -114,32 +114,32 @@ void RenderablePolyLineEntityItem::updateGeometry() {
_verticesBuffer->append(sizeof(int), (gpu::Byte*)_color);
_verticesBuffer->append(sizeof(glm::vec2), (const gpu::Byte*)&uv);
vertexIndex++;
_numVertices +=2;
_numVertices += 2;
}
_pointsChanged = false;
}
void RenderablePolyLineEntityItem::render(RenderArgs* args) {
QWriteLocker lock(&_quadReadWriteLock);
if (_points.size() < 2 || _vertices.size() != _normals.size() * 2) {
if (_points.size() < 2 || _normals.size () < 2 || _vertices.size() < 2) {
return;
}
if (!_pipeline) {
createPipeline();
}
PerformanceTimer perfTimer("RenderablePolyLineEntityItem::render");
Q_ASSERT(getType() == EntityTypes::PolyLine);
Q_ASSERT(args->_batch);
if (_pointsChanged) {
updateGeometry();
}
gpu::Batch& batch = *args->_batch;
Transform transform = Transform();
transform.setTranslation(getPosition());
@ -151,8 +151,8 @@ void RenderablePolyLineEntityItem::render(RenderArgs* args) {
batch.setInputFormat(_format);
batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride);
batch.draw(gpu::TRIANGLE_STRIP, _numVertices, 0);
RenderableDebugableEntityItem::render(this, args);
};

View file

@ -27,12 +27,12 @@ const int PolyLineEntityItem::MAX_POINTS_PER_LINE = 70;
EntityItemPointer PolyLineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
EntityItemPointer result { new PolyLineEntityItem(entityID, properties) };
EntityItemPointer result{ new PolyLineEntityItem(entityID, properties) };
return result;
}
PolyLineEntityItem::PolyLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
EntityItem(entityItemID) ,
EntityItem(entityItemID),
_lineWidth(DEFAULT_LINE_WIDTH),
_pointsChanged(true),
_points(QVector<glm::vec3>(0.0f)),
@ -48,16 +48,16 @@ _strokeWidths(QVector<float>(0.0f))
EntityItemProperties PolyLineEntityItem::getProperties(EntityPropertyFlags desiredProperties) const {
QWriteLocker lock(&_quadReadWriteLock);
EntityItemProperties properties = EntityItem::getProperties(desiredProperties); // get the properties from our base class
properties._color = getXColor();
properties._colorChanged = false;
COPY_ENTITY_PROPERTY_TO_PROPERTIES(lineWidth, getLineWidth);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(linePoints, getLinePoints);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(normals, getNormals);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(strokeWidths, getStrokeWidths);
properties._glowLevel = getGlowLevel();
properties._glowLevelChanged = false;
return properties;
@ -67,20 +67,20 @@ bool PolyLineEntityItem::setProperties(const EntityItemProperties& properties) {
QWriteLocker lock(&_quadReadWriteLock);
bool somethingChanged = false;
somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class
SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(lineWidth, setLineWidth);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(linePoints, setLinePoints);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(normals, setNormals);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(strokeWidths, setStrokeWidths);
if (somethingChanged) {
bool wantDebug = false;
if (wantDebug) {
uint64_t now = usecTimestampNow();
int elapsed = now - getLastEdited();
qCDebug(entities) << "PolyLineEntityItem::setProperties() AFTER update... edited AGO=" << elapsed <<
"now=" << now << " getLastEdited()=" << getLastEdited();
"now=" << now << " getLastEdited()=" << getLastEdited();
}
setLastEdited(properties._lastEdited);
}
@ -93,7 +93,7 @@ bool PolyLineEntityItem::appendPoint(const glm::vec3& point) {
return false;
}
glm::vec3 halfBox = getDimensions() * 0.5f;
if ( (point.x < - halfBox.x || point.x > halfBox.x) || (point.y < -halfBox.y || point.y > halfBox.y) || (point.z < - halfBox.z || point.z > halfBox.z) ) {
if ((point.x < -halfBox.x || point.x > halfBox.x) || (point.y < -halfBox.y || point.y > halfBox.y) || (point.z < -halfBox.z || point.z > halfBox.z)) {
qDebug() << "Point is outside entity's bounding box";
return false;
}
@ -102,17 +102,17 @@ bool PolyLineEntityItem::appendPoint(const glm::vec3& point) {
return true;
}
bool PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths ) {
bool PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths) {
_strokeWidths = strokeWidths;
return true;
}
bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
_normals = normals;
if (_points.size () < 2 || _normals.size() < 2) {
if (_points.size() < 2 || _normals.size() < 2) {
return false;
}
int minVectorSize = _normals.size();
if (_points.size() < minVectorSize) {
minVectorSize = _points.size();
@ -123,15 +123,15 @@ bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
_vertices.clear();
glm::vec3 v1, v2, tangent, binormal, point;
for (int i = 0; i < minVectorSize-1; i++) {
for (int i = 0; i < minVectorSize - 1; i++) {
float width = _strokeWidths.at(i);
point = _points.at(i);
tangent = _points.at(i+1) - point;
tangent = _points.at(i + 1) - point;
glm::vec3 normal = normals.at(i);
binormal = glm::normalize(glm::cross(tangent, normal)) * width;
//This checks to make sure binormal is not a NAN
assert(binormal.x == binormal.x);
v1 = point + binormal;
@ -139,11 +139,11 @@ bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
_vertices << v1 << v2;
}
//for last point we can just assume binormals are same since it represents last two vertices of quad
point = _points.at(_points.size() - 1);
point = _points.at(minVectorSize - 1);
v1 = point + binormal;
v2 = point - binormal;
_vertices << v1 << v2;
return true;
}
@ -157,7 +157,7 @@ bool PolyLineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
//Check to see if points actually changed. If they haven't, return before doing anything else
else if (points.size() == _points.size()) {
//same number of points, so now compare every point
for (int i = 0; i < points.size(); i++ ) {
for (int i = 0; i < points.size(); i++) {
if (points.at(i) != _points.at(i)){
_pointsChanged = true;
break;
@ -171,9 +171,9 @@ bool PolyLineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
for (int i = 0; i < points.size(); i++) {
glm::vec3 point = points.at(i);
glm::vec3 halfBox = getDimensions() * 0.5f;
if ((point.x < - halfBox.x || point.x > halfBox.x) ||
if ((point.x < -halfBox.x || point.x > halfBox.x) ||
(point.y < -halfBox.y || point.y > halfBox.y) ||
(point.z < - halfBox.z || point.z > halfBox.z)) {
(point.z < -halfBox.z || point.z > halfBox.z)) {
qDebug() << "Point is outside entity's bounding box";
return false;
}
@ -183,18 +183,18 @@ bool PolyLineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
}
int PolyLineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
ReadBitstreamToTreeParams& args,
EntityPropertyFlags& propertyFlags, bool overwriteLocalData) {
QWriteLocker lock(&_quadReadWriteLock);
ReadBitstreamToTreeParams& args,
EntityPropertyFlags& propertyFlags, bool overwriteLocalData) {
QWriteLocker lock(&_quadReadWriteLock);
int bytesRead = 0;
const unsigned char* dataAt = data;
READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor);
READ_ENTITY_PROPERTY(PROP_LINE_WIDTH, float, setLineWidth);
READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector<glm::vec3>, setLinePoints);
READ_ENTITY_PROPERTY(PROP_NORMALS, QVector<glm::vec3>, setNormals);
READ_ENTITY_PROPERTY(PROP_NORMALS, QVector<glm::vec3>, setNormals);
READ_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, QVector<float>, setStrokeWidths);
return bytesRead;
}
@ -211,16 +211,16 @@ EntityPropertyFlags PolyLineEntityItem::getEntityProperties(EncodeBitstreamParam
}
void PolyLineEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData,
EntityPropertyFlags& requestedProperties,
EntityPropertyFlags& propertyFlags,
EntityPropertyFlags& propertiesDidntFit,
int& propertyCount,
OctreeElement::AppendState& appendState) const {
EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData,
EntityPropertyFlags& requestedProperties,
EntityPropertyFlags& propertyFlags,
EntityPropertyFlags& propertiesDidntFit,
int& propertyCount,
OctreeElement::AppendState& appendState) const {
QWriteLocker lock(&_quadReadWriteLock);
bool successPropertyFits = true;
APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor());
APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, getLineWidth());
APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, getLinePoints());

View file

@ -442,7 +442,7 @@ void DeferredLightingEffect::render(RenderArgs* args) {
deferredTransforms[i].projection = projMats[i];
auto sideViewMat = eyeViews[i] * monoViewMat;
auto sideViewMat = monoViewMat * glm::inverse(eyeViews[i]);
viewTransforms[i].evalFromRawMatrix(sideViewMat);
deferredTransforms[i].viewInverse = sideViewMat;
@ -574,10 +574,8 @@ void DeferredLightingEffect::render(RenderArgs* args) {
for (auto lightID : _pointLights) {
auto& light = _allocatedLights[lightID];
// IN DEBUG: light->setShowContour(true);
if (_pointLightLocations->lightBufferUnit >= 0) {
batch.setUniformBuffer(_pointLightLocations->lightBufferUnit, light->getSchemaBuffer());
}
// IN DEBUG: light->setShowContour(true);
batch.setUniformBuffer(_pointLightLocations->lightBufferUnit, light->getSchemaBuffer());
float expandedRadius = light->getMaximumRadius() * (1.0f + SCALE_EXPANSION);
// TODO: We shouldn;t have to do that test and use a different volume geometry for when inside the vlight volume,
@ -612,8 +610,7 @@ void DeferredLightingEffect::render(RenderArgs* args) {
for (auto lightID : _spotLights) {
auto light = _allocatedLights[lightID];
// IN DEBUG: light->setShowContour(true);
// IN DEBUG: light->setShowContour(true);
batch.setUniformBuffer(_spotLightLocations->lightBufferUnit, light->getSchemaBuffer());
auto eyeLightPos = eyePoint - light->getPosition();

View file

@ -17,6 +17,7 @@
// the interpolated normal
in vec3 _normal;
in vec3 _modelNormal;
in vec3 _color;
in vec2 _texCoord0;
in vec4 _position;

View file

@ -22,6 +22,7 @@ uniform bool Instanced = false;
// the interpolated normal
out vec3 _normal;
out vec3 _modelNormal;
out vec3 _color;
out vec2 _texCoord0;
out vec4 _position;
@ -30,6 +31,7 @@ void main(void) {
_color = inColor.rgb;
_texCoord0 = inTexCoord0.st;
_position = inPosition;
_modelNormal = inNormal.xyz;
// standard transform
TransformCamera cam = getTransformCamera();