From 5fc7965042a8b7aa4a3f2e61e134431eb3362bc4 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 28 Sep 2015 13:04:58 -0700 Subject: [PATCH 01/33] Throw held objects with velocity from fingertip --- examples/controllers/handControllerGrab.js | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index a13f1de86d..975c1d2e0b 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -41,10 +41,10 @@ var LINE_LENGTH = 500; // var GRAB_RADIUS = 0.3; // if the ray misses but an object is this close, it will still be selected -var NEAR_GRABBING_ACTION_TIMEFRAME = 0.05; // how quickly objects move to their new position +var NEAR_GRABBING_ACTION_TIMEFRAME = 0.01; // how quickly objects move to their new position var NEAR_GRABBING_VELOCITY_SMOOTH_RATIO = 1.0; // adjust time-averaging of held object's velocity. 1.0 to disable. var NEAR_PICK_MAX_DISTANCE = 0.6; // max length of pick-ray for close grabbing to be selected -var RELEASE_VELOCITY_MULTIPLIER = 1.5; // affects throwing things +var RELEASE_VELOCITY_MULTIPLIER = 1.0; // affects throwing things ///////////////////////////////////////////////////////////////// // @@ -86,7 +86,7 @@ function MyController(hand, triggerAction) { 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.tip = 2 * hand + 1; this.actionID = null; // action this script created... this.grabbedEntity = null; // on this entity. @@ -343,7 +343,8 @@ function MyController(hand, triggerAction) { } - this.currentHandControllerPosition = Controller.getSpatialControlPosition(this.palm); + this.currentHandControllerTipPosition = Controller.getSpatialControlPosition(this.tip); + this.currentObjectTime = Date.now(); }; @@ -353,15 +354,21 @@ function MyController(hand, triggerAction) { 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"); }; From 5c7cf76035271ab53cf590d353204a1cb6f4848f Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 28 Sep 2015 16:13:35 -0700 Subject: [PATCH 02/33] Distance grab works with walking and turning --- examples/controllers/handControllerGrab.js | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 975c1d2e0b..011a9d434b 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -256,6 +256,9 @@ function MyController(hand, triggerAction) { Entities.callEntityMethod(this.grabbedEntity, "startDistantGrab"); } + this.currentAvatarPosition = MyAvatar.position; + this.currentAvatarOrientation = MyAvatar.orientation; + }; this.continueDistanceHolding = function() { @@ -274,11 +277,44 @@ 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 From 7b1c04512a34258c7c8ffccb80c9f4a416424160 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 28 Sep 2015 16:20:27 -0700 Subject: [PATCH 03/33] Adding support for accessing IPD in scripts --- examples/example/hmd/colorCube.fs | 10 ++++ examples/example/hmd/colorCube.js | 52 +++++++++++++++++++ .../src/scripting/HMDScriptingInterface.cpp | 6 ++- .../src/scripting/HMDScriptingInterface.h | 2 + .../src/display-plugins/DisplayPlugin.h | 4 ++ .../oculus/OculusBaseDisplayPlugin.cpp | 8 +++ .../oculus/OculusBaseDisplayPlugin.h | 1 + libraries/render-utils/src/simple.slf | 1 + libraries/render-utils/src/simple.slv | 2 + 9 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 examples/example/hmd/colorCube.fs create mode 100644 examples/example/hmd/colorCube.js diff --git a/examples/example/hmd/colorCube.fs b/examples/example/hmd/colorCube.fs new file mode 100644 index 0000000000..2687b70807 --- /dev/null +++ b/examples/example/hmd/colorCube.fs @@ -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; +} \ No newline at end of file diff --git a/examples/example/hmd/colorCube.js b/examples/example/hmd/colorCube.js new file mode 100644 index 0000000000..b36fa6362b --- /dev/null +++ b/examples/example/hmd/colorCube.js @@ -0,0 +1,52 @@ +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(); + + +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); diff --git a/interface/src/scripting/HMDScriptingInterface.cpp b/interface/src/scripting/HMDScriptingInterface.cpp index f65d638ccc..68ac511eaf 100644 --- a/interface/src/scripting/HMDScriptingInterface.cpp +++ b/interface/src/scripting/HMDScriptingInterface.cpp @@ -10,7 +10,7 @@ // #include "HMDScriptingInterface.h" - +#include "display-plugins/DisplayPlugin.h" #include HMDScriptingInterface& HMDScriptingInterface::getInstance() { @@ -53,3 +53,7 @@ QScriptValue HMDScriptingInterface::getHUDLookAtPosition3D(QScriptContext* conte } return QScriptValue::NullValue; } + +float HMDScriptingInterface::getIPD() const { + return Application::getInstance()->getActiveDisplayPlugin()->getIPD(); +} diff --git a/interface/src/scripting/HMDScriptingInterface.h b/interface/src/scripting/HMDScriptingInterface.h index 4bcced1fa2..82b444abaa 100644 --- a/interface/src/scripting/HMDScriptingInterface.h +++ b/interface/src/scripting/HMDScriptingInterface.h @@ -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; diff --git a/libraries/display-plugins/src/display-plugins/DisplayPlugin.h b/libraries/display-plugins/src/display-plugins/DisplayPlugin.h index 86cfabe724..2aaf4ddbc5 100644 --- a/libraries/display-plugins/src/display-plugins/DisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/DisplayPlugin.h @@ -121,6 +121,10 @@ 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; } diff --git a/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.cpp index fa9d09e392..f2a7b06510 100644 --- a/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.cpp @@ -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; +} \ No newline at end of file diff --git a/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.h index 12023db1ae..d879085b8f 100644 --- a/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.h @@ -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; diff --git a/libraries/render-utils/src/simple.slf b/libraries/render-utils/src/simple.slf index 5901a72838..576acf9340 100644 --- a/libraries/render-utils/src/simple.slf +++ b/libraries/render-utils/src/simple.slf @@ -17,6 +17,7 @@ // the interpolated normal in vec3 _normal; +in vec3 _modelNormal; in vec3 _color; in vec2 _texCoord0; in vec4 _position; diff --git a/libraries/render-utils/src/simple.slv b/libraries/render-utils/src/simple.slv index e7fed4a6b4..823654ec27 100644 --- a/libraries/render-utils/src/simple.slv +++ b/libraries/render-utils/src/simple.slv @@ -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(); From 56a0456f705e634b6889f5b2967406aef784a8bf Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 28 Sep 2015 16:49:55 -0700 Subject: [PATCH 04/33] Adjust force multiplier and timestep --- examples/controllers/handControllerGrab.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 011a9d434b..024b40a885 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -41,10 +41,10 @@ var LINE_LENGTH = 500; // var GRAB_RADIUS = 0.3; // if the ray misses but an object is this close, it will still be selected -var NEAR_GRABBING_ACTION_TIMEFRAME = 0.01; // how quickly objects move to their new position +var NEAR_GRABBING_ACTION_TIMEFRAME = 0.05; // how quickly objects move to their new position var NEAR_GRABBING_VELOCITY_SMOOTH_RATIO = 1.0; // adjust time-averaging of held object's velocity. 1.0 to disable. var NEAR_PICK_MAX_DISTANCE = 0.6; // max length of pick-ray for close grabbing to be selected -var RELEASE_VELOCITY_MULTIPLIER = 1.0; // affects throwing things +var RELEASE_VELOCITY_MULTIPLIER = 1.5; // affects throwing things ///////////////////////////////////////////////////////////////// // From 35e4ec17ea2ccbe8a135b6cf9c15c01b33e20798 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 10:35:38 -0700 Subject: [PATCH 05/33] add which hand for near grab of non physical objects --- examples/controllers/handControllerGrab.js | 31 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 41f36c19d5..1b891f56b5 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -29,9 +29,21 @@ var TRIGGER_ON_VALUE = 0.2; var DISTANCE_HOLDING_RADIUS_FACTOR = 5; // multiplied by distance between hand and object var DISTANCE_HOLDING_ACTION_TIMEFRAME = 0.1; // how quickly objects move to their new position var DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR = 2.0; // object rotates this much more than hand did -var NO_INTERSECT_COLOR = { red: 10, green: 10, blue: 255}; // line color when pick misses -var INTERSECT_COLOR = { red: 250, green: 10, blue: 10}; // line color when pick hits -var LINE_ENTITY_DIMENSIONS = { x: 1000, y: 1000, z: 1000}; +var NO_INTERSECT_COLOR = { + red: 10, + green: 10, + blue: 255 +}; // line color when pick misses +var INTERSECT_COLOR = { + red: 250, + green: 10, + blue: 10 +}; // line color when pick hits +var LINE_ENTITY_DIMENSIONS = { + x: 1000, + y: 1000, + z: 1000 +}; var LINE_LENGTH = 500; @@ -54,7 +66,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; @@ -391,6 +407,11 @@ function MyController(hand, triggerAction) { 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; }; @@ -546,4 +567,4 @@ function cleanup() { } Script.scriptEnding.connect(cleanup); -Script.update.connect(update); +Script.update.connect(update); \ No newline at end of file From 745a59af1c8fd6644e282e122943ee12d0593e2f Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Tue, 29 Sep 2015 12:48:57 -0700 Subject: [PATCH 06/33] Default animation is anim graph. Remove state change logging from animation graph state machine. --- interface/src/Menu.cpp | 4 ++-- interface/src/avatar/MyAvatar.cpp | 3 ++- libraries/animation/src/AnimStateMachine.cpp | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 5793510fb5..96f640b96e 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -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))); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 16964735da..514a6f9aaa 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -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); diff --git a/libraries/animation/src/AnimStateMachine.cpp b/libraries/animation/src/AnimStateMachine.cpp index 758067343d..5304cefe46 100644 --- a/libraries/animation/src/AnimStateMachine.cpp +++ b/libraries/animation/src/AnimStateMachine.cpp @@ -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; } From 06194b6088cdf779fdb644dbb7ba803222827fc4 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 12:51:01 -0700 Subject: [PATCH 07/33] fixed formatting --- examples/controllers/handControllerGrab.js | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 1b891f56b5..52b1e94e4b 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -29,21 +29,9 @@ var TRIGGER_ON_VALUE = 0.2; var DISTANCE_HOLDING_RADIUS_FACTOR = 5; // multiplied by distance between hand and object var DISTANCE_HOLDING_ACTION_TIMEFRAME = 0.1; // how quickly objects move to their new position var DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR = 2.0; // object rotates this much more than hand did -var NO_INTERSECT_COLOR = { - red: 10, - green: 10, - blue: 255 -}; // line color when pick misses -var INTERSECT_COLOR = { - red: 250, - green: 10, - blue: 10 -}; // line color when pick hits -var LINE_ENTITY_DIMENSIONS = { - x: 1000, - y: 1000, - z: 1000 -}; +var NO_INTERSECT_COLOR = { red: 10, green: 10, blue: 255 }; // line color when pick misses +var INTERSECT_COLOR = { red: 250, green: 10, blue: 10}; // line color when pick hits +var LINE_ENTITY_DIMENSIONS = { x: 1000, y: 1000, z: 1000}; var LINE_LENGTH = 500; From 96e3c722ed2f0df97012ba840fe3dd30bb026343 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Tue, 29 Sep 2015 13:04:59 -0700 Subject: [PATCH 08/33] Quiet once/second logging/updating of other people's default avatars. --- libraries/avatars/src/AvatarData.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 104b592c1a..3bd147d398 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -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(); From fdb94555401b2435260567cddda994fe692ca37b Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 29 Sep 2015 13:12:55 -0700 Subject: [PATCH 09/33] debug --- examples/acScripts/flickeringLight.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/acScripts/flickeringLight.js b/examples/acScripts/flickeringLight.js index edf8332eb5..ea7f7f9c68 100644 --- a/examples/acScripts/flickeringLight.js +++ b/examples/acScripts/flickeringLight.js @@ -77,6 +77,7 @@ function update(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"); + print("age:" + properties.age); Entities.editEntity(LightMaker.light, { intensity: intensity, lifetime: properties.age + EPHEMERAL_LIFETIME }); } } From 49da3c503431f32adecfa0148d876279eecb9ccd Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 29 Sep 2015 13:24:03 -0700 Subject: [PATCH 10/33] disable avatar collisions while holding something --- examples/controllers/handControllerGrab.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 41f36c19d5..0b9e609c77 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -244,6 +244,10 @@ function MyController(hand, triggerAction) { }; this.distanceHolding = function() { + + this.previousAvCollision = Menu.isOptionChecked("Enable avatar collisions"); + Menu.setIsOptionChecked("Enable avatar collisions", false); + var handControllerPosition = Controller.getSpatialControlPosition(this.palm); var handRotation = Quat.multiply(MyAvatar.orientation, Controller.getSpatialControlRawRotation(this.palm)); var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, ["position", "rotation"]); @@ -323,6 +327,10 @@ function MyController(hand, triggerAction) { }; this.nearGrabbing = function() { + + this.previousAvCollision = Menu.isOptionChecked("Enable avatar collisions"); + Menu.setIsOptionChecked("Enable avatar collisions", false); + if (!this.triggerSmoothedSqueezed()) { this.state = STATE_RELEASE; return; @@ -491,6 +499,9 @@ function MyController(hand, triggerAction) { }; this.release = function() { + + Menu.setIsOptionChecked("Enable avatar collisions", this.previousAvCollision); + this.lineOff(); if (this.grabbedEntity !== null && this.actionID !== null) { From 4abb2517289c561101120a744def2b05d1e02c26 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 29 Sep 2015 13:28:45 -0700 Subject: [PATCH 11/33] more debug --- examples/acScripts/flickeringLight.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/acScripts/flickeringLight.js b/examples/acScripts/flickeringLight.js index ea7f7f9c68..93264e192c 100644 --- a/examples/acScripts/flickeringLight.js +++ b/examples/acScripts/flickeringLight.js @@ -76,9 +76,13 @@ function update(deltaTime) { 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"); + var properties = Entities.getEntityProperties(LightMaker.light, ["age", "lifetime"]); + print("props:" +JSON.stringify(properties)); print("age:" + properties.age); - Entities.editEntity(LightMaker.light, { intensity: intensity, lifetime: properties.age + EPHEMERAL_LIFETIME }); + print("lifetime:" + properties.lifetime); + var newLifetime = properties.age + EPHEMERAL_LIFETIME; + print("newLifetime:" + newLifetime); + Entities.editEntity(LightMaker.light, { intensity : intensity, lifetime: newLifetime }); } } From 9c199b23a2b9b4240dba1b5bce535783fb9f64dc Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 29 Sep 2015 13:32:28 -0700 Subject: [PATCH 12/33] more debug --- examples/acScripts/flickeringLight.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/acScripts/flickeringLight.js b/examples/acScripts/flickeringLight.js index 93264e192c..571684b385 100644 --- a/examples/acScripts/flickeringLight.js +++ b/examples/acScripts/flickeringLight.js @@ -77,12 +77,12 @@ function update(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", "lifetime"]); - print("props:" +JSON.stringify(properties)); - print("age:" + properties.age); - print("lifetime:" + properties.lifetime); + //print("props:" +JSON.stringify(properties)); + //print("age:" + properties.age); + //print("lifetime:" + properties.lifetime); var newLifetime = properties.age + EPHEMERAL_LIFETIME; - print("newLifetime:" + newLifetime); - Entities.editEntity(LightMaker.light, { intensity : intensity, lifetime: newLifetime }); + //print("newLifetime:" + newLifetime); + Entities.editEntity(LightMaker.light, { type: "Light", intensity : intensity, lifetime: newLifetime }); } } From 6a01c10453bfa1dfe73c0be014d15c209ced83c3 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 29 Sep 2015 13:35:16 -0700 Subject: [PATCH 13/33] more debug --- examples/acScripts/flickeringLight.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/acScripts/flickeringLight.js b/examples/acScripts/flickeringLight.js index 571684b385..03ea4681ef 100644 --- a/examples/acScripts/flickeringLight.js +++ b/examples/acScripts/flickeringLight.js @@ -78,10 +78,10 @@ function update(deltaTime) { intensity += randFloat(-LIGHT_INTENSITY_RANDOMNESS, LIGHT_INTENSITY_RANDOMNESS); var properties = Entities.getEntityProperties(LightMaker.light, ["age", "lifetime"]); //print("props:" +JSON.stringify(properties)); - //print("age:" + properties.age); - //print("lifetime:" + properties.lifetime); + print("age:" + properties.age); + print("lifetime:" + properties.lifetime); var newLifetime = properties.age + EPHEMERAL_LIFETIME; - //print("newLifetime:" + newLifetime); + print("newLifetime:" + newLifetime); Entities.editEntity(LightMaker.light, { type: "Light", intensity : intensity, lifetime: newLifetime }); } } From f7b34f63c10d732bc8f06e87c5bfb97f23904ea1 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 29 Sep 2015 13:40:54 -0700 Subject: [PATCH 14/33] try calling updateMotionBehaviorFromMenu --- examples/controllers/handControllerGrab.js | 4 ++++ interface/src/avatar/MyAvatar.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 0b9e609c77..4339c92f28 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -247,6 +247,8 @@ function MyController(hand, triggerAction) { this.previousAvCollision = Menu.isOptionChecked("Enable avatar collisions"); Menu.setIsOptionChecked("Enable avatar collisions", false); + MyAvatar.updateMotionBehaviorFromMenu(); + var handControllerPosition = Controller.getSpatialControlPosition(this.palm); var handRotation = Quat.multiply(MyAvatar.orientation, Controller.getSpatialControlRawRotation(this.palm)); @@ -330,6 +332,7 @@ function MyController(hand, triggerAction) { this.previousAvCollision = Menu.isOptionChecked("Enable avatar collisions"); Menu.setIsOptionChecked("Enable avatar collisions", false); + MyAvatar.updateMotionBehaviorFromMenu(); if (!this.triggerSmoothedSqueezed()) { this.state = STATE_RELEASE; @@ -501,6 +504,7 @@ function MyController(hand, triggerAction) { this.release = function() { Menu.setIsOptionChecked("Enable avatar collisions", this.previousAvCollision); + MyAvatar.updateMotionBehaviorFromMenu(); this.lineOff(); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index bbc0667015..6efec3be13 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -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(); From e9dd165b1dc89d91b0d2f585604f60559f2d4756 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 29 Sep 2015 14:00:22 -0700 Subject: [PATCH 15/33] try calling updateMotionBehaviorFromMenu --- examples/controllers/handControllerGrab.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 4339c92f28..d6603a7887 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -92,7 +92,7 @@ function MyController(hand, triggerAction) { 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_SEARCHING; this.pointer = null; // entity-id of line object this.triggerValue = 0; // rolling average of trigger value var _this = this; @@ -247,6 +247,7 @@ function MyController(hand, triggerAction) { this.previousAvCollision = Menu.isOptionChecked("Enable avatar collisions"); Menu.setIsOptionChecked("Enable avatar collisions", false); + print("avatar collisions -->" + this.previousAvCollision); MyAvatar.updateMotionBehaviorFromMenu(); @@ -332,6 +333,7 @@ function MyController(hand, triggerAction) { this.previousAvCollision = Menu.isOptionChecked("Enable avatar collisions"); Menu.setIsOptionChecked("Enable avatar collisions", false); + print("avatar collisions -->" + this.previousAvCollision); MyAvatar.updateMotionBehaviorFromMenu(); if (!this.triggerSmoothedSqueezed()) { @@ -504,6 +506,7 @@ function MyController(hand, triggerAction) { this.release = function() { Menu.setIsOptionChecked("Enable avatar collisions", this.previousAvCollision); + print("avatar collisions -->" + this.previousAvCollision); MyAvatar.updateMotionBehaviorFromMenu(); this.lineOff(); From 644687f3303bdff30dd9ead7e246836cc4513569 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 14:04:03 -0700 Subject: [PATCH 16/33] releaseGrab event now triggered for non physical entities --- examples/controllers/handControllerGrab.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 52b1e94e4b..ea22d77bbc 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -29,7 +29,7 @@ var TRIGGER_ON_VALUE = 0.2; var DISTANCE_HOLDING_RADIUS_FACTOR = 5; // multiplied by distance between hand and object var DISTANCE_HOLDING_ACTION_TIMEFRAME = 0.1; // how quickly objects move to their new position var DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR = 2.0; // object rotates this much more than hand did -var NO_INTERSECT_COLOR = { red: 10, green: 10, blue: 255 }; // line color when pick misses +var NO_INTERSECT_COLOR = { red: 10, green: 10, blue: 255}; // line color when pick misses var INTERSECT_COLOR = { red: 250, green: 10, blue: 10}; // line color when pick hits var LINE_ENTITY_DIMENSIONS = { x: 1000, y: 1000, z: 1000}; var LINE_LENGTH = 500; @@ -502,8 +502,10 @@ 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"); } From 9b13aac37db162a126b7ae1bcf51fa79d50959d6 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 29 Sep 2015 14:23:56 -0700 Subject: [PATCH 17/33] PR comments --- examples/example/hmd/colorCube.js | 16 +++------------- .../src/display-plugins/DisplayPlugin.h | 4 +--- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/examples/example/hmd/colorCube.js b/examples/example/hmd/colorCube.js index b36fa6362b..a138f38190 100644 --- a/examples/example/hmd/colorCube.js +++ b/examples/example/hmd/colorCube.js @@ -37,16 +37,6 @@ ColorCube.prototype.create = function() { }); } -var ColorCube = new ColorCube(); -ColorCube.clear(); -ColorCube.create(); - - -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); +var colorCube = new ColorCube(); +colorCube.clear(); +colorCube.create(); diff --git a/libraries/display-plugins/src/display-plugins/DisplayPlugin.h b/libraries/display-plugins/src/display-plugins/DisplayPlugin.h index 2aaf4ddbc5..8b9d249bd4 100644 --- a/libraries/display-plugins/src/display-plugins/DisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/DisplayPlugin.h @@ -121,9 +121,7 @@ public: static const glm::mat4 pose; return pose; } - virtual float getIPD() const { - return 0.0f; - } + virtual float getIPD() const { return 0.0f; } virtual void abandonCalibration() {} virtual void resetSensors() {} From 006650f23bba7672bbeb81063948a76280c23291 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 29 Sep 2015 14:34:23 -0700 Subject: [PATCH 18/33] Fix for PR comments --- examples/controllers/handControllerGrab.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 024b40a885..4b1d6e9648 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -84,9 +84,11 @@ 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; + 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. @@ -287,10 +289,12 @@ function MyController(hand, triggerAction) { // 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 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)); @@ -482,17 +486,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"); }; From b1a133e55c188325b714e7a846c03a0c56e47226 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 29 Sep 2015 14:38:47 -0700 Subject: [PATCH 19/33] working on disabling avatar collisions during grab --- examples/controllers/handControllerGrab.js | 87 +++++++++++++++------- 1 file changed, 62 insertions(+), 25 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index d6603a7887..0c042a1f22 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -9,7 +9,6 @@ // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -/*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */ Script.include("../libraries/utils.js"); @@ -63,18 +62,22 @@ 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"; + function MyController(hand, triggerAction) { this.hand = hand; if (this.hand === RIGHT_HAND) { @@ -92,13 +95,28 @@ function MyController(hand, triggerAction) { 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 = STATE_SEARCHING; + this.state = STATE_OFF; this.pointer = null; // entity-id of line object this.triggerValue = 0; // rolling average of trigger value + + // HACK -- until we have collision groups, don't allow held object to collide with avatar + this.initialavatarCollisionsMenu = Menu.isOptionChecked(AVATAR_COLLISIONS_MENU_ITEM); + var _this = this; this.update = function() { + + // XXX + if (this.state != this.previousState) { + print("state --> " + this.state); + } + this.previousState = this.state; + // XXX + switch (this.state) { + case STATE_OFF: + this.off(); + break; case STATE_SEARCHING: this.search(); this.touchTest(); @@ -171,6 +189,16 @@ function MyController(hand, triggerAction) { return triggerValue > TRIGGER_ON_VALUE; }; + this.off = function() { + // HACK -- until we have collision groups, don't allow held object to collide with avatar + this.revertAvatarCollisions(); + + if (this.triggerSmoothedSqueezed()) { + this.state = STATE_SEARCHING; + return; + } + } + this.search = function() { if (!this.triggerSmoothedSqueezed()) { this.state = STATE_RELEASE; @@ -243,13 +271,26 @@ function MyController(hand, triggerAction) { }; + this.disableAvatarCollisions = function() { + if (Menu.isOptionChecked(AVATAR_COLLISIONS_MENU_ITEM) != false) { + Menu.setIsOptionChecked(AVATAR_COLLISIONS_MENU_ITEM, false); + print("avatar collisions --> off"); + MyAvatar.updateMotionBehaviorFromMenu(); + } + } + + this.revertAvatarCollisions = function() { + if (Menu.isOptionChecked(AVATAR_COLLISIONS_MENU_ITEM) != this.initialavatarCollisionsMenu) { + Menu.setIsOptionChecked(AVATAR_COLLISIONS_MENU_ITEM, this.initialavatarCollisionsMenu); + print("avatar collisions --> revert"); + MyAvatar.updateMotionBehaviorFromMenu(); + } + } + this.distanceHolding = function() { - this.previousAvCollision = Menu.isOptionChecked("Enable avatar collisions"); - Menu.setIsOptionChecked("Enable avatar collisions", false); - print("avatar collisions -->" + this.previousAvCollision); - MyAvatar.updateMotionBehaviorFromMenu(); - + // 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)); @@ -331,10 +372,8 @@ function MyController(hand, triggerAction) { this.nearGrabbing = function() { - this.previousAvCollision = Menu.isOptionChecked("Enable avatar collisions"); - Menu.setIsOptionChecked("Enable avatar collisions", false); - print("avatar collisions -->" + this.previousAvCollision); - MyAvatar.updateMotionBehaviorFromMenu(); + // HACK -- until we have collision groups, don't allow held object to collide with avatar + this.disableAvatarCollisions(); if (!this.triggerSmoothedSqueezed()) { this.state = STATE_RELEASE; @@ -504,11 +543,6 @@ function MyController(hand, triggerAction) { }; this.release = function() { - - Menu.setIsOptionChecked("Enable avatar collisions", this.previousAvCollision); - print("avatar collisions -->" + this.previousAvCollision); - MyAvatar.updateMotionBehaviorFromMenu(); - this.lineOff(); if (this.grabbedEntity !== null && this.actionID !== null) { @@ -526,7 +560,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() { @@ -565,3 +599,6 @@ function cleanup() { Script.scriptEnding.connect(cleanup); Script.update.connect(update); + +// this comment keeps jslint quiet. +/*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */ From 1bd07b58c3371df3f1e1e548bdd145f22330fa5d Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 29 Sep 2015 14:40:37 -0700 Subject: [PATCH 20/33] Fixing the lighting view matrix for stereo again --- libraries/render-utils/src/DeferredLightingEffect.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index a9d83aa9d6..dbcbe3c05e 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -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(); From f83eae4d4259e56d657863eb2a73ca51ade4858c Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 29 Sep 2015 14:45:24 -0700 Subject: [PATCH 21/33] more debugging --- examples/acScripts/flickeringLight.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/acScripts/flickeringLight.js b/examples/acScripts/flickeringLight.js index 03ea4681ef..367b604567 100644 --- a/examples/acScripts/flickeringLight.js +++ b/examples/acScripts/flickeringLight.js @@ -43,7 +43,7 @@ var totalTime = 0; 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, @@ -78,11 +78,13 @@ function update(deltaTime) { intensity += randFloat(-LIGHT_INTENSITY_RANDOMNESS, LIGHT_INTENSITY_RANDOMNESS); var properties = Entities.getEntityProperties(LightMaker.light, ["age", "lifetime"]); //print("props:" +JSON.stringify(properties)); - print("age:" + properties.age); - print("lifetime:" + properties.lifetime); + //print("deltaTime:" + deltaTime); + //print("age:" + properties.age); + //print("lifetime:" + properties.lifetime); var newLifetime = properties.age + EPHEMERAL_LIFETIME; - print("newLifetime:" + newLifetime); - Entities.editEntity(LightMaker.light, { type: "Light", intensity : intensity, lifetime: newLifetime }); + //print("newLifetime:" + newLifetime); + Entities.editEntity(LightMaker.light, { type: "Light", intensity: intensity, lifetime: newLifetime }); + //print("packetsToSendCount:" + Entities.packetsToSendCount()); } } From 2ba686ed890999c6271f4c8fcab2a0dd86e68bbd Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 29 Sep 2015 15:11:52 -0700 Subject: [PATCH 22/33] cleanups --- examples/controllers/handControllerGrab.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index bc8fd504ef..24aa88cc65 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -115,13 +115,6 @@ function MyController(hand, triggerAction) { this.update = function() { - // XXX - if (this.state != this.previousState) { - print("state --> " + this.state); - } - this.previousState = this.state; - // XXX - this.updateSmoothedTrigger(); switch (this.state) { @@ -158,7 +151,6 @@ function MyController(hand, triggerAction) { this.disableAvatarCollisions = function() { if (this.currentAvatarCollisionsMenu != false) { - print("avatar collisions --> off"); this.currentAvatarCollisionsMenu = false; Menu.setIsOptionChecked(AVATAR_COLLISIONS_MENU_ITEM, false); MyAvatar.updateMotionBehaviorFromMenu(); @@ -167,7 +159,6 @@ function MyController(hand, triggerAction) { this.revertAvatarCollisions = function() { if (this.currentAvatarCollisionsMenu != this.initialAvatarCollisionsMenu) { - print("avatar collisions --> revert"); this.currentAvatarCollisionsMenu = this.initialAvatarCollisionsMenu; Menu.setIsOptionChecked(AVATAR_COLLISIONS_MENU_ITEM, this.initialAvatarCollisionsMenu); MyAvatar.updateMotionBehaviorFromMenu(); From 8f2f14c9e5f86c19ae5c829e6395028164bb27d5 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 29 Sep 2015 15:30:24 -0700 Subject: [PATCH 23/33] keep track of state of avatar-collisions menu-item with global variables rather than per object ones --- examples/controllers/handControllerGrab.js | 38 ++++++++++++++-------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 24aa88cc65..0b9238e7c9 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -84,6 +84,13 @@ 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) { @@ -107,10 +114,6 @@ function MyController(hand, triggerAction) { this.pointer = null; // entity-id of line object this.triggerValue = 0; // rolling average of trigger value - // HACK -- until we have collision groups, don't allow held object to collide with avatar - this.initialAvatarCollisionsMenu = Menu.isOptionChecked(AVATAR_COLLISIONS_MENU_ITEM); - this.currentAvatarCollisionsMenu = this.initialAvatarCollisionsMenu; - var _this = this; this.update = function() { @@ -120,10 +123,10 @@ function MyController(hand, triggerAction) { 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(); @@ -149,19 +152,25 @@ function MyController(hand, triggerAction) { } }; + // HACK -- until we have collision groups, don't allow held object to collide with avatar this.disableAvatarCollisions = function() { - if (this.currentAvatarCollisionsMenu != false) { - this.currentAvatarCollisionsMenu = false; + 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() { - if (this.currentAvatarCollisionsMenu != this.initialAvatarCollisionsMenu) { - this.currentAvatarCollisionsMenu = this.initialAvatarCollisionsMenu; - Menu.setIsOptionChecked(AVATAR_COLLISIONS_MENU_ITEM, this.initialAvatarCollisionsMenu); - MyAvatar.updateMotionBehaviorFromMenu(); + noCollisionsCount -= 1; + if (noCollisionsCount < 1) { + if (currentAvatarCollisionsMenu != initialAvatarCollisionsMenu) { + currentAvatarCollisionsMenu = initialAvatarCollisionsMenu; + Menu.setIsOptionChecked(AVATAR_COLLISIONS_MENU_ITEM, initialAvatarCollisionsMenu); + MyAvatar.updateMotionBehaviorFromMenu(); + } } } @@ -217,9 +226,6 @@ function MyController(hand, triggerAction) { }; this.off = function() { - // HACK -- until we have collision groups, don't allow held object to collide with avatar - this.revertAvatarCollisions(); - if (this.triggerSmoothedSqueezed()) { this.state = STATE_SEARCHING; return; @@ -601,6 +607,10 @@ function MyController(hand, triggerAction) { }; this.release = function() { + + // HACK -- until we have collision groups, don't allow held object to collide with avatar + this.revertAvatarCollisions(); + this.lineOff(); if (this.grabbedEntity !== null) { From e7834365f5cd17cc97f1b44e208341d4c5d99412 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 15:33:39 -0700 Subject: [PATCH 24/33] Made polyline painting experience smoother- no more flickering --- .../src/RenderablePolyLineEntityItem.cpp | 212 +++++------ libraries/entities/src/PolyLineEntityItem.cpp | 330 +++++++++--------- 2 files changed, 271 insertions(+), 271 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index c6b7b58538..f7057ff906 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -25,12 +25,12 @@ EntityItemPointer RenderablePolyLineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { - return EntityItemPointer(new RenderablePolyLineEntityItem(entityID, properties)); + return EntityItemPointer(new RenderablePolyLineEntityItem(entityID, properties)); } RenderablePolyLineEntityItem::RenderablePolyLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : PolyLineEntityItem(entityItemID, properties) { - _numVertices = 0; + _numVertices = 0; } @@ -40,119 +40,119 @@ gpu::TexturePointer RenderablePolyLineEntityItem::_texture; GLint RenderablePolyLineEntityItem::PAINTSTROKE_GPU_SLOT; 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(); - QString path = PathUtils::resourcesPath() + "images/paintStroke.png"; - _texture = textureCache->getImageTexture(path); - _format.reset(new gpu::Stream::Format()); - _format->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); - _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)); + static const int NORMAL_OFFSET = 12; + static const int COLOR_OFFSET = 24; + static const int TEXTURE_OFFSET = 28; + + auto textureCache = DependencyManager::get(); + QString path = PathUtils::resourcesPath() + "images/paintStroke.png"; + _texture = textureCache->getImageTexture(path); + _format.reset(new gpu::Stream::Format()); + _format->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); + _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)); } void RenderablePolyLineEntityItem::updateGeometry() { - _numVertices = 0; - _verticesBuffer.reset(new gpu::Buffer()); - int vertexIndex = 0; - vec2 uv; - 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 numHeadStrips = 10; - int startHeadIndex = _normals.size() - numHeadStrips; - for (int i = 0; i < _normals.size(); i++) { - uCoord = 0.26f; - vCoord = 0.0f; - //tail - if(i < numTailStrips) { - uCoord = float(i)/numTailStrips * tailLength + tailStart; - } - - //head - if( i > startHeadIndex) { - uCoord = float( (i+ 1) - startHeadIndex)/numHeadStrips * headLength + headStart; - } + _numVertices = 0; + _verticesBuffer.reset(new gpu::Buffer()); + int vertexIndex = 0; + vec2 uv; + float tailStart = 0.0f; + float tailEnd = 0.25f; + float tailLength = tailEnd - tailStart; - 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); - _verticesBuffer->append(sizeof(glm::vec2), (gpu::Byte*)&uv); - vertexIndex++; + float headStart = 0.76f; + float headEnd = 1.0f; + float headLength = headEnd - headStart; + float uCoord, vCoord; + + int numTailStrips = 5; + int numHeadStrips = 10; + 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; + } + + //head + 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); + _verticesBuffer->append(sizeof(glm::vec2), (gpu::Byte*)&uv); + vertexIndex++; + + uv.y = 1.0f; + _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); + _verticesBuffer->append(sizeof(glm::vec2), (const gpu::Byte*)&uv); + vertexIndex++; + + _numVertices += 2; + } + _pointsChanged = false; - uv.y = 1.0f; - _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); - _verticesBuffer->append(sizeof(glm::vec2), (const gpu::Byte*)&uv); - vertexIndex++; - - _numVertices +=2; - } - _pointsChanged = false; - } void RenderablePolyLineEntityItem::render(RenderArgs* args) { - QWriteLocker lock(&_quadReadWriteLock); - if (_points.size() < 2 || _vertices.size() != _normals.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()); - transform.setRotation(getRotation()); - batch.setModelTransform(transform); + QWriteLocker lock(&_quadReadWriteLock); + if (_points.size() < 2) { + return; + } - batch.setPipeline(_pipeline); - batch.setResourceTexture(PAINTSTROKE_GPU_SLOT, _texture); + if (!_pipeline) { + createPipeline(); + } - batch.setInputFormat(_format); - batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride); - - batch.draw(gpu::TRIANGLE_STRIP, _numVertices, 0); - - RenderableDebugableEntityItem::render(this, args); + 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()); + transform.setRotation(getRotation()); + batch.setModelTransform(transform); + + batch.setPipeline(_pipeline); + batch.setResourceTexture(PAINTSTROKE_GPU_SLOT, _texture); + + batch.setInputFormat(_format); + batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride); + + batch.draw(gpu::TRIANGLE_STRIP, _numVertices, 0); + + RenderableDebugableEntityItem::render(this, args); }; diff --git a/libraries/entities/src/PolyLineEntityItem.cpp b/libraries/entities/src/PolyLineEntityItem.cpp index 29a44547ff..09ddc4ec76 100644 --- a/libraries/entities/src/PolyLineEntityItem.cpp +++ b/libraries/entities/src/PolyLineEntityItem.cpp @@ -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) }; - return result; + 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(0.0f)), @@ -40,200 +40,200 @@ _vertices(QVector(0.0f)), _normals(QVector(0.0f)), _strokeWidths(QVector(0.0f)) { - _type = EntityTypes::PolyLine; - _created = properties.getCreated(); - setProperties(properties); + _type = EntityTypes::PolyLine; + _created = properties.getCreated(); + setProperties(properties); } 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; + 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; } 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(); - } - setLastEdited(properties._lastEdited); - } - return somethingChanged; + 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(); + } + setLastEdited(properties._lastEdited); + } + return somethingChanged; } bool PolyLineEntityItem::appendPoint(const glm::vec3& point) { - if (_points.size() > MAX_POINTS_PER_LINE - 1) { - qDebug() << "MAX POINTS REACHED!"; - 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) ) { - qDebug() << "Point is outside entity's bounding box"; - return false; - } - _points << point; - _pointsChanged = true; - return true; + if (_points.size() > MAX_POINTS_PER_LINE - 1) { + qDebug() << "MAX POINTS REACHED!"; + 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)) { + qDebug() << "Point is outside entity's bounding box"; + return false; + } + _points << point; + _pointsChanged = true; + return true; } -bool PolyLineEntityItem::setStrokeWidths(const QVector& strokeWidths ) { - _strokeWidths = strokeWidths; - return true; +bool PolyLineEntityItem::setStrokeWidths(const QVector& strokeWidths) { + _strokeWidths = strokeWidths; + return true; } bool PolyLineEntityItem::setNormals(const QVector& normals) { - _normals = normals; - if (_points.size () < 2 || _normals.size() < 2) { - return false; - } - - int minVectorSize = _normals.size(); - if (_points.size() < minVectorSize) { - minVectorSize = _points.size(); - } - if (_strokeWidths.size() < minVectorSize) { - minVectorSize = _strokeWidths.size(); - } + _normals = normals; + if (_points.size() < 2 || _normals.size() < 2) { + return false; + } - _vertices.clear(); - glm::vec3 v1, v2, tangent, binormal, point; - - for (int i = 0; i < minVectorSize-1; i++) { - float width = _strokeWidths.at(i); - point = _points.at(i); - - 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; - v2 = point - binormal; - _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); - v1 = point + binormal; - v2 = point - binormal; - _vertices << v1 << v2; - - return true; + int minVectorSize = _normals.size(); + if (_points.size() < minVectorSize) { + minVectorSize = _points.size(); + } + if (_strokeWidths.size() < minVectorSize) { + minVectorSize = _strokeWidths.size(); + } + + _vertices.clear(); + glm::vec3 v1, v2, tangent, binormal, point; + + for (int i = 0; i < minVectorSize - 1; i++) { + float width = _strokeWidths.at(i); + point = _points.at(i); + + 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; + v2 = point - binormal; + _vertices << v1 << v2; + } + //for last point we can just assume binormals are same since it represents last two vertices of quad + point = _points.at(minVectorSize - 1); + v1 = point + binormal; + v2 = point - binormal; + _vertices << v1 << v2; + + return true; } bool PolyLineEntityItem::setLinePoints(const QVector& points) { - if (points.size() > MAX_POINTS_PER_LINE) { - return false; - } - if (points.size() != _points.size()) { - _pointsChanged = true; - } - //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++ ) { - if (points.at(i) != _points.at(i)){ - _pointsChanged = true; - break; - } - } - } - if (!_pointsChanged) { - return false; - } + if (points.size() > MAX_POINTS_PER_LINE) { + return false; + } + if (points.size() != _points.size()) { + _pointsChanged = true; + } + //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++) { + if (points.at(i) != _points.at(i)){ + _pointsChanged = true; + break; + } + } + } + if (!_pointsChanged) { + return false; + } - 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) || - (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; - } - } - _points = points; - return true; + 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) || + (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; + } + } + _points = points; + return true; } int PolyLineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, - 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, setLinePoints); - READ_ENTITY_PROPERTY(PROP_NORMALS, QVector, setNormals); - READ_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, QVector, setStrokeWidths); - - return bytesRead; + 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, setLinePoints); + READ_ENTITY_PROPERTY(PROP_NORMALS, QVector, setNormals); + READ_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, QVector, setStrokeWidths); + + return bytesRead; } // TODO: eventually only include properties changed since the params.lastViewFrustumSent time EntityPropertyFlags PolyLineEntityItem::getEntityProperties(EncodeBitstreamParams& params) const { - EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); - requestedProperties += PROP_COLOR; - requestedProperties += PROP_LINE_WIDTH; - requestedProperties += PROP_LINE_POINTS; - requestedProperties += PROP_NORMALS; - requestedProperties += PROP_STROKE_WIDTHS; - return requestedProperties; + EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); + requestedProperties += PROP_COLOR; + requestedProperties += PROP_LINE_WIDTH; + requestedProperties += PROP_LINE_POINTS; + requestedProperties += PROP_NORMALS; + requestedProperties += PROP_STROKE_WIDTHS; + return requestedProperties; } void PolyLineEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, - 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()); - APPEND_ENTITY_PROPERTY(PROP_NORMALS, getNormals()); - APPEND_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, getStrokeWidths()); + 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()); + APPEND_ENTITY_PROPERTY(PROP_NORMALS, getNormals()); + APPEND_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, getStrokeWidths()); } void PolyLineEntityItem::debugDump() const { - quint64 now = usecTimestampNow(); - qCDebug(entities) << " QUAD EntityItem id:" << getEntityItemID() << "---------------------------------------------"; - qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; - qCDebug(entities) << " position:" << debugTreeVector(getPosition()); - qCDebug(entities) << " dimensions:" << debugTreeVector(getDimensions()); - qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); + quint64 now = usecTimestampNow(); + qCDebug(entities) << " QUAD EntityItem id:" << getEntityItemID() << "---------------------------------------------"; + qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; + qCDebug(entities) << " position:" << debugTreeVector(getPosition()); + qCDebug(entities) << " dimensions:" << debugTreeVector(getDimensions()); + qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); } From 90afeb4ce1ad9692af4b38e3d23648832478d587 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 29 Sep 2015 15:45:29 -0700 Subject: [PATCH 25/33] more debugging --- examples/acScripts/flickeringLight.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/examples/acScripts/flickeringLight.js b/examples/acScripts/flickeringLight.js index 367b604567..cf3dd70934 100644 --- a/examples/acScripts/flickeringLight.js +++ b/examples/acScripts/flickeringLight.js @@ -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 = 60; // ephemeral entities will live for 60 seconds after script stops running +var EPHEMERAL_LIFETIME = 10; // ephemeral entities will live for 60 seconds after script stops running var LightMaker = { light: null, @@ -74,17 +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", "lifetime"]); - //print("props:" +JSON.stringify(properties)); - //print("deltaTime:" + deltaTime); - //print("age:" + properties.age); - //print("lifetime:" + properties.lifetime); - var newLifetime = properties.age + EPHEMERAL_LIFETIME; - //print("newLifetime:" + newLifetime); - Entities.editEntity(LightMaker.light, { type: "Light", intensity: intensity, lifetime: newLifetime }); - //print("packetsToSendCount:" + Entities.packetsToSendCount()); + + // 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; + } } } From 67823b79d5de72120e2c1b33478dd29ffdb370d8 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 29 Sep 2015 15:48:46 -0700 Subject: [PATCH 26/33] change additional lifetime to 60 seconds to avoid processing hiccups --- examples/acScripts/flickeringLight.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/acScripts/flickeringLight.js b/examples/acScripts/flickeringLight.js index cf3dd70934..ed60d56c86 100644 --- a/examples/acScripts/flickeringLight.js +++ b/examples/acScripts/flickeringLight.js @@ -45,7 +45,7 @@ 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 60 seconds after script stops running +var EPHEMERAL_LIFETIME = 60; // ephemeral entities will live for 60 seconds after script stops running var LightMaker = { light: null, From 472ff89f48ce9ba69cabd630011295b984ba2012 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 29 Sep 2015 15:52:38 -0700 Subject: [PATCH 27/33] rearrange when avatar collisions are adjusted --- examples/controllers/handControllerGrab.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 0b9238e7c9..388c042285 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -348,6 +348,9 @@ function MyController(hand, triggerAction) { this.continueDistanceHolding = function() { 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; } @@ -431,6 +434,9 @@ function MyController(hand, triggerAction) { 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; } @@ -477,6 +483,9 @@ function MyController(hand, triggerAction) { this.continueNearGrabbing = function() { 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; } @@ -608,9 +617,6 @@ function MyController(hand, triggerAction) { this.release = function() { - // HACK -- until we have collision groups, don't allow held object to collide with avatar - this.revertAvatarCollisions(); - this.lineOff(); if (this.grabbedEntity !== null) { From 36be35a8363a02669c626d865cf57c370582fcff Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Tue, 29 Sep 2015 16:30:42 -0700 Subject: [PATCH 28/33] Update RenderablePolyLineEntityItem.cpp --- .../entities-renderer/src/RenderablePolyLineEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index f7057ff906..7d95d472ee 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -25,7 +25,7 @@ EntityItemPointer RenderablePolyLineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { - return EntityItemPointer(new RenderablePolyLineEntityItem(entityID, properties)); + return EntityItemPointer(new RenderablePolyLineEntityItem(entityID, properties)); } RenderablePolyLineEntityItem::RenderablePolyLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : From 614312f04f5c6e68fc555b36e031916a7dfbf158 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Tue, 29 Sep 2015 16:32:07 -0700 Subject: [PATCH 29/33] Update PolyLineEntityItem.cpp --- libraries/entities/src/PolyLineEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities/src/PolyLineEntityItem.cpp b/libraries/entities/src/PolyLineEntityItem.cpp index 09ddc4ec76..f5e6a98423 100644 --- a/libraries/entities/src/PolyLineEntityItem.cpp +++ b/libraries/entities/src/PolyLineEntityItem.cpp @@ -139,7 +139,7 @@ bool PolyLineEntityItem::setNormals(const QVector& 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(minVectorSize - 1); + point = _points.at(minVectorSize - 1); v1 = point + binormal; v2 = point - binormal; _vertices << v1 << v2; From c901a749c2c300b84cb745b36c2dddb70e000d51 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Tue, 29 Sep 2015 16:33:18 -0700 Subject: [PATCH 30/33] Update RenderablePolyLineEntityItem.cpp --- .../entities-renderer/src/RenderablePolyLineEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index 7d95d472ee..d87138637d 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -124,7 +124,7 @@ void RenderablePolyLineEntityItem::updateGeometry() { void RenderablePolyLineEntityItem::render(RenderArgs* args) { QWriteLocker lock(&_quadReadWriteLock); - if (_points.size() < 2) { + if (_points.size() < 2) { return; } From d1b016b483be465df722ab76062a018cd341718d Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 16:38:21 -0700 Subject: [PATCH 31/33] untabbified lines --- .../src/RenderablePolyLineEntityItem.cpp | 178 +++++------ libraries/entities/src/PolyLineEntityItem.cpp | 294 +++++++++--------- 2 files changed, 236 insertions(+), 236 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index 7d95d472ee..27981d2530 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -30,7 +30,7 @@ EntityItemPointer RenderablePolyLineEntityItem::factory(const EntityItemID& enti RenderablePolyLineEntityItem::RenderablePolyLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : PolyLineEntityItem(entityItemID, properties) { - _numVertices = 0; + _numVertices = 0; } @@ -40,119 +40,119 @@ gpu::TexturePointer RenderablePolyLineEntityItem::_texture; GLint RenderablePolyLineEntityItem::PAINTSTROKE_GPU_SLOT; void RenderablePolyLineEntityItem::createPipeline() { - static const int NORMAL_OFFSET = 12; - static const int COLOR_OFFSET = 24; - static const int TEXTURE_OFFSET = 28; + static const int NORMAL_OFFSET = 12; + static const int COLOR_OFFSET = 24; + static const int TEXTURE_OFFSET = 28; - auto textureCache = DependencyManager::get(); - QString path = PathUtils::resourcesPath() + "images/paintStroke.png"; - _texture = textureCache->getImageTexture(path); - _format.reset(new gpu::Stream::Format()); - _format->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); - _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 textureCache = DependencyManager::get(); + QString path = PathUtils::resourcesPath() + "images/paintStroke.png"; + _texture = textureCache->getImageTexture(path); + _format.reset(new gpu::Stream::Format()); + _format->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); + _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)); + 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::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::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)); } void RenderablePolyLineEntityItem::updateGeometry() { - _numVertices = 0; - _verticesBuffer.reset(new gpu::Buffer()); - int vertexIndex = 0; - vec2 uv; - float tailStart = 0.0f; - float tailEnd = 0.25f; - float tailLength = tailEnd - tailStart; + _numVertices = 0; + _verticesBuffer.reset(new gpu::Buffer()); + int vertexIndex = 0; + vec2 uv; + 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; + float headStart = 0.76f; + float headEnd = 1.0f; + float headLength = headEnd - headStart; + float uCoord, vCoord; - int numTailStrips = 5; - int numHeadStrips = 10; - 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; - } + int numTailStrips = 5; + int numHeadStrips = 10; + 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; + } - //head - if (i > startHeadIndex) { - uCoord = float((i + 1) - startHeadIndex) / numHeadStrips * headLength + headStart; - } + //head + if (i > startHeadIndex) { + uCoord = float((i + 1) - startHeadIndex) / numHeadStrips * headLength + headStart; + } - uv = vec2(uCoord, vCoord); + 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); - _verticesBuffer->append(sizeof(glm::vec2), (gpu::Byte*)&uv); - vertexIndex++; + _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); + _verticesBuffer->append(sizeof(glm::vec2), (gpu::Byte*)&uv); + vertexIndex++; - uv.y = 1.0f; - _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); - _verticesBuffer->append(sizeof(glm::vec2), (const gpu::Byte*)&uv); - vertexIndex++; + uv.y = 1.0f; + _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); + _verticesBuffer->append(sizeof(glm::vec2), (const gpu::Byte*)&uv); + vertexIndex++; - _numVertices += 2; - } - _pointsChanged = false; + _numVertices += 2; + } + _pointsChanged = false; } void RenderablePolyLineEntityItem::render(RenderArgs* args) { - QWriteLocker lock(&_quadReadWriteLock); - if (_points.size() < 2) { - return; - } + QWriteLocker lock(&_quadReadWriteLock); + if (_points.size() < 2) { + return; + } - if (!_pipeline) { - createPipeline(); - } + if (!_pipeline) { + createPipeline(); + } - PerformanceTimer perfTimer("RenderablePolyLineEntityItem::render"); - Q_ASSERT(getType() == EntityTypes::PolyLine); + PerformanceTimer perfTimer("RenderablePolyLineEntityItem::render"); + Q_ASSERT(getType() == EntityTypes::PolyLine); - Q_ASSERT(args->_batch); - if (_pointsChanged) { - updateGeometry(); - } + Q_ASSERT(args->_batch); + if (_pointsChanged) { + updateGeometry(); + } - gpu::Batch& batch = *args->_batch; - Transform transform = Transform(); - transform.setTranslation(getPosition()); - transform.setRotation(getRotation()); - batch.setModelTransform(transform); + gpu::Batch& batch = *args->_batch; + Transform transform = Transform(); + transform.setTranslation(getPosition()); + transform.setRotation(getRotation()); + batch.setModelTransform(transform); - batch.setPipeline(_pipeline); - batch.setResourceTexture(PAINTSTROKE_GPU_SLOT, _texture); + batch.setPipeline(_pipeline); + batch.setResourceTexture(PAINTSTROKE_GPU_SLOT, _texture); - batch.setInputFormat(_format); - batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride); + batch.setInputFormat(_format); + batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride); - batch.draw(gpu::TRIANGLE_STRIP, _numVertices, 0); + batch.draw(gpu::TRIANGLE_STRIP, _numVertices, 0); - RenderableDebugableEntityItem::render(this, args); + RenderableDebugableEntityItem::render(this, args); }; diff --git a/libraries/entities/src/PolyLineEntityItem.cpp b/libraries/entities/src/PolyLineEntityItem.cpp index f5e6a98423..c29ed43041 100644 --- a/libraries/entities/src/PolyLineEntityItem.cpp +++ b/libraries/entities/src/PolyLineEntityItem.cpp @@ -27,8 +27,8 @@ const int PolyLineEntityItem::MAX_POINTS_PER_LINE = 70; EntityItemPointer PolyLineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { - EntityItemPointer result{ new PolyLineEntityItem(entityID, properties) }; - return result; + EntityItemPointer result{ new PolyLineEntityItem(entityID, properties) }; + return result; } PolyLineEntityItem::PolyLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : @@ -40,200 +40,200 @@ _vertices(QVector(0.0f)), _normals(QVector(0.0f)), _strokeWidths(QVector(0.0f)) { - _type = EntityTypes::PolyLine; - _created = properties.getCreated(); - setProperties(properties); + _type = EntityTypes::PolyLine; + _created = properties.getCreated(); + setProperties(properties); } EntityItemProperties PolyLineEntityItem::getProperties(EntityPropertyFlags desiredProperties) const { - QWriteLocker lock(&_quadReadWriteLock); - EntityItemProperties properties = EntityItem::getProperties(desiredProperties); // get the properties from our base class + QWriteLocker lock(&_quadReadWriteLock); + EntityItemProperties properties = EntityItem::getProperties(desiredProperties); // get the properties from our base class - properties._color = getXColor(); - properties._colorChanged = false; + 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); + 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; + properties._glowLevel = getGlowLevel(); + properties._glowLevelChanged = false; + return properties; } bool PolyLineEntityItem::setProperties(const EntityItemProperties& properties) { - QWriteLocker lock(&_quadReadWriteLock); - bool somethingChanged = false; - somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class + 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); + 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(); - } - setLastEdited(properties._lastEdited); - } - return somethingChanged; + 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(); + } + setLastEdited(properties._lastEdited); + } + return somethingChanged; } bool PolyLineEntityItem::appendPoint(const glm::vec3& point) { - if (_points.size() > MAX_POINTS_PER_LINE - 1) { - qDebug() << "MAX POINTS REACHED!"; - 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)) { - qDebug() << "Point is outside entity's bounding box"; - return false; - } - _points << point; - _pointsChanged = true; - return true; + if (_points.size() > MAX_POINTS_PER_LINE - 1) { + qDebug() << "MAX POINTS REACHED!"; + 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)) { + qDebug() << "Point is outside entity's bounding box"; + return false; + } + _points << point; + _pointsChanged = true; + return true; } bool PolyLineEntityItem::setStrokeWidths(const QVector& strokeWidths) { - _strokeWidths = strokeWidths; - return true; + _strokeWidths = strokeWidths; + return true; } bool PolyLineEntityItem::setNormals(const QVector& normals) { - _normals = normals; - if (_points.size() < 2 || _normals.size() < 2) { - return false; - } + _normals = normals; + if (_points.size() < 2 || _normals.size() < 2) { + return false; + } - int minVectorSize = _normals.size(); - if (_points.size() < minVectorSize) { - minVectorSize = _points.size(); - } - if (_strokeWidths.size() < minVectorSize) { - minVectorSize = _strokeWidths.size(); - } + int minVectorSize = _normals.size(); + if (_points.size() < minVectorSize) { + minVectorSize = _points.size(); + } + if (_strokeWidths.size() < minVectorSize) { + minVectorSize = _strokeWidths.size(); + } - _vertices.clear(); - glm::vec3 v1, v2, tangent, binormal, point; + _vertices.clear(); + glm::vec3 v1, v2, tangent, binormal, point; - for (int i = 0; i < minVectorSize - 1; i++) { - float width = _strokeWidths.at(i); - point = _points.at(i); + for (int i = 0; i < minVectorSize - 1; i++) { + float width = _strokeWidths.at(i); + point = _points.at(i); - tangent = _points.at(i + 1) - point; - glm::vec3 normal = normals.at(i); - binormal = glm::normalize(glm::cross(tangent, normal)) * width; + 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; - v2 = point - binormal; - _vertices << v1 << v2; - } - //for last point we can just assume binormals are same since it represents last two vertices of quad + //This checks to make sure binormal is not a NAN + assert(binormal.x == binormal.x); + v1 = point + binormal; + v2 = point - binormal; + _vertices << v1 << v2; + } + //for last point we can just assume binormals are same since it represents last two vertices of quad point = _points.at(minVectorSize - 1); - v1 = point + binormal; - v2 = point - binormal; - _vertices << v1 << v2; + v1 = point + binormal; + v2 = point - binormal; + _vertices << v1 << v2; - return true; + return true; } bool PolyLineEntityItem::setLinePoints(const QVector& points) { - if (points.size() > MAX_POINTS_PER_LINE) { - return false; - } - if (points.size() != _points.size()) { - _pointsChanged = true; - } - //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++) { - if (points.at(i) != _points.at(i)){ - _pointsChanged = true; - break; - } - } - } - if (!_pointsChanged) { - return false; - } + if (points.size() > MAX_POINTS_PER_LINE) { + return false; + } + if (points.size() != _points.size()) { + _pointsChanged = true; + } + //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++) { + if (points.at(i) != _points.at(i)){ + _pointsChanged = true; + break; + } + } + } + if (!_pointsChanged) { + return false; + } - 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) || - (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; - } - } - _points = points; - return true; + 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) || + (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; + } + } + _points = points; + return true; } int PolyLineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, - ReadBitstreamToTreeParams& args, - EntityPropertyFlags& propertyFlags, bool overwriteLocalData) { - QWriteLocker lock(&_quadReadWriteLock); - int bytesRead = 0; - const unsigned char* dataAt = data; + 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, setLinePoints); - READ_ENTITY_PROPERTY(PROP_NORMALS, QVector, setNormals); - READ_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, QVector, setStrokeWidths); + READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor); + READ_ENTITY_PROPERTY(PROP_LINE_WIDTH, float, setLineWidth); + READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector, setLinePoints); + READ_ENTITY_PROPERTY(PROP_NORMALS, QVector, setNormals); + READ_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, QVector, setStrokeWidths); - return bytesRead; + return bytesRead; } // TODO: eventually only include properties changed since the params.lastViewFrustumSent time EntityPropertyFlags PolyLineEntityItem::getEntityProperties(EncodeBitstreamParams& params) const { - EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); - requestedProperties += PROP_COLOR; - requestedProperties += PROP_LINE_WIDTH; - requestedProperties += PROP_LINE_POINTS; - requestedProperties += PROP_NORMALS; - requestedProperties += PROP_STROKE_WIDTHS; - return requestedProperties; + EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); + requestedProperties += PROP_COLOR; + requestedProperties += PROP_LINE_WIDTH; + requestedProperties += PROP_LINE_POINTS; + requestedProperties += PROP_NORMALS; + requestedProperties += PROP_STROKE_WIDTHS; + return requestedProperties; } 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; + 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()); - APPEND_ENTITY_PROPERTY(PROP_NORMALS, getNormals()); - APPEND_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, getStrokeWidths()); + APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); + APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, getLineWidth()); + APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, getLinePoints()); + APPEND_ENTITY_PROPERTY(PROP_NORMALS, getNormals()); + APPEND_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, getStrokeWidths()); } void PolyLineEntityItem::debugDump() const { - quint64 now = usecTimestampNow(); - qCDebug(entities) << " QUAD EntityItem id:" << getEntityItemID() << "---------------------------------------------"; - qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; - qCDebug(entities) << " position:" << debugTreeVector(getPosition()); - qCDebug(entities) << " dimensions:" << debugTreeVector(getDimensions()); - qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); + quint64 now = usecTimestampNow(); + qCDebug(entities) << " QUAD EntityItem id:" << getEntityItemID() << "---------------------------------------------"; + qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; + qCDebug(entities) << " position:" << debugTreeVector(getPosition()); + qCDebug(entities) << " dimensions:" << debugTreeVector(getDimensions()); + qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); } From 5ce3b13a4c006406656ecb65f99668f0d8debcc9 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 17:31:02 -0700 Subject: [PATCH 32/33] Fixed spacing issues --- libraries/entities/src/PolyLineEntityItem.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/entities/src/PolyLineEntityItem.cpp b/libraries/entities/src/PolyLineEntityItem.cpp index c29ed43041..a01c2ce17b 100644 --- a/libraries/entities/src/PolyLineEntityItem.cpp +++ b/libraries/entities/src/PolyLineEntityItem.cpp @@ -183,9 +183,9 @@ bool PolyLineEntityItem::setLinePoints(const QVector& 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; @@ -211,12 +211,12 @@ 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; From 1760720b2be77e53278ff8fa325d400f86f204b5 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 17:42:20 -0700 Subject: [PATCH 33/33] added check for normals and vertices --- .../entities-renderer/src/RenderablePolyLineEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index 27981d2530..572b24e99f 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -124,7 +124,7 @@ void RenderablePolyLineEntityItem::updateGeometry() { void RenderablePolyLineEntityItem::render(RenderArgs* args) { QWriteLocker lock(&_quadReadWriteLock); - if (_points.size() < 2) { + if (_points.size() < 2 || _normals.size () < 2 || _vertices.size() < 2) { return; }