Merge branch 'master' into feature/hand-controller-web-entity-integration

This commit is contained in:
Anthony J. Thibault 2016-08-17 13:55:12 -07:00
commit 7b248b440a
13 changed files with 190 additions and 61 deletions

View file

@ -91,6 +91,11 @@ void RenderableShapeEntityItem::render(RenderArgs* args) {
_procedural.reset(new Procedural(getUserData()));
_procedural->_vertexSource = simple_vert;
_procedural->_fragmentSource = simple_frag;
_procedural->_opaqueState->setCullMode(gpu::State::CULL_NONE);
_procedural->_opaqueState->setDepthTest(true, true, gpu::LESS_EQUAL);
_procedural->_opaqueState->setBlendFunction(false,
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);
}
gpu::Batch& batch = *args->_batch;

View file

@ -325,6 +325,8 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const {
CHECK_PROPERTY_CHANGE(PROP_QUERY_AA_CUBE, queryAACube);
CHECK_PROPERTY_CHANGE(PROP_LOCAL_POSITION, localPosition);
CHECK_PROPERTY_CHANGE(PROP_LOCAL_ROTATION, localRotation);
CHECK_PROPERTY_CHANGE(PROP_LOCAL_VELOCITY, localVelocity);
CHECK_PROPERTY_CHANGE(PROP_LOCAL_ANGULAR_VELOCITY, localAngularVelocity);
CHECK_PROPERTY_CHANGE(PROP_FLYING_ALLOWED, flyingAllowed);
CHECK_PROPERTY_CHANGE(PROP_GHOSTING_ALLOWED, ghostingAllowed);
@ -570,6 +572,8 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_LOCAL_POSITION, localPosition);
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_LOCAL_ROTATION, localRotation);
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_LOCAL_VELOCITY, localVelocity);
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_LOCAL_ANGULAR_VELOCITY, localAngularVelocity);
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_CLIENT_ONLY, clientOnly);
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_OWNING_AVATAR_ID, owningAvatarID);
@ -707,6 +711,8 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool
COPY_PROPERTY_FROM_QSCRIPTVALUE(localPosition, glmVec3, setLocalPosition);
COPY_PROPERTY_FROM_QSCRIPTVALUE(localRotation, glmQuat, setLocalRotation);
COPY_PROPERTY_FROM_QSCRIPTVALUE(localVelocity, glmVec3, setLocalVelocity);
COPY_PROPERTY_FROM_QSCRIPTVALUE(localAngularVelocity, glmVec3, setLocalAngularVelocity);
COPY_PROPERTY_FROM_QSCRIPTVALUE(jointRotationsSet, qVectorBool, setJointRotationsSet);
COPY_PROPERTY_FROM_QSCRIPTVALUE(jointRotations, qVectorQuat, setJointRotations);
@ -864,6 +870,8 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue
ADD_PROPERTY_TO_MAP(PROP_LOCAL_POSITION, LocalPosition, localPosition, glm::vec3);
ADD_PROPERTY_TO_MAP(PROP_LOCAL_ROTATION, LocalRotation, localRotation, glm::quat);
ADD_PROPERTY_TO_MAP(PROP_LOCAL_VELOCITY, LocalVelocity, localVelocity, glm::vec3);
ADD_PROPERTY_TO_MAP(PROP_LOCAL_ANGULAR_VELOCITY, LocalAngularVelocity, localAngularVelocity, glm::vec3);
ADD_PROPERTY_TO_MAP(PROP_JOINT_ROTATIONS_SET, JointRotationsSet, jointRotationsSet, QVector<bool>);
ADD_PROPERTY_TO_MAP(PROP_JOINT_ROTATIONS, JointRotations, jointRotations, QVector<glm::quat>);
@ -1982,7 +1990,9 @@ QList<QString> EntityItemProperties::listChangedProperties() {
}
bool EntityItemProperties::parentDependentPropertyChanged() const {
return localPositionChanged() || positionChanged() || localRotationChanged() || rotationChanged();
return localPositionChanged() || positionChanged() ||
localRotationChanged() || rotationChanged() ||
localVelocityChanged() || localAngularVelocityChanged();
}
bool EntityItemProperties::parentRelatedPropertyChanged() const {

View file

@ -201,6 +201,8 @@ public:
// these are used when bouncing location data into and out of scripts
DEFINE_PROPERTY_REF(PROP_LOCAL_POSITION, LocalPosition, localPosition, glmVec3, ENTITY_ITEM_ZERO_VEC3);
DEFINE_PROPERTY_REF(PROP_LOCAL_ROTATION, LocalRotation, localRotation, glmQuat, ENTITY_ITEM_DEFAULT_ROTATION);
DEFINE_PROPERTY_REF(PROP_LOCAL_VELOCITY, LocalVelocity, localVelocity, glmVec3, ENTITY_ITEM_ZERO_VEC3);
DEFINE_PROPERTY_REF(PROP_LOCAL_ANGULAR_VELOCITY, LocalAngularVelocity, localAngularVelocity, glmVec3, ENTITY_ITEM_ZERO_VEC3);
DEFINE_PROPERTY_REF(PROP_JOINT_ROTATIONS_SET, JointRotationsSet, jointRotationsSet, QVector<bool>, QVector<bool>());
DEFINE_PROPERTY_REF(PROP_JOINT_ROTATIONS, JointRotations, jointRotations, QVector<glm::quat>, QVector<glm::quat>());

View file

@ -177,6 +177,9 @@ enum EntityPropertyList {
PROP_SHAPE,
PROP_LOCAL_VELOCITY, // only used to convert values to and from scripts
PROP_LOCAL_ANGULAR_VELOCITY, // only used to convert values to and from scripts
////////////////////////////////////////////////////////////////////////////////////////////////////
// ATTENTION: add new properties to end of list just ABOVE this line
PROP_AFTER_LAST_ITEM,

View file

@ -78,6 +78,8 @@ EntityItemProperties convertLocationToScriptSemantics(const EntityItemProperties
EntityItemProperties scriptSideProperties = entitySideProperties;
scriptSideProperties.setLocalPosition(entitySideProperties.getPosition());
scriptSideProperties.setLocalRotation(entitySideProperties.getRotation());
scriptSideProperties.setLocalVelocity(entitySideProperties.getLocalVelocity());
scriptSideProperties.setLocalAngularVelocity(entitySideProperties.getLocalAngularVelocity());
bool success;
glm::vec3 worldPosition = SpatiallyNestable::localToWorld(entitySideProperties.getPosition(),
@ -88,10 +90,19 @@ EntityItemProperties convertLocationToScriptSemantics(const EntityItemProperties
entitySideProperties.getParentID(),
entitySideProperties.getParentJointIndex(),
success);
// TODO -- handle velocity and angularVelocity
glm::vec3 worldVelocity = SpatiallyNestable::localToWorldVelocity(entitySideProperties.getVelocity(),
entitySideProperties.getParentID(),
entitySideProperties.getParentJointIndex(),
success);
glm::vec3 worldAngularVelocity = SpatiallyNestable::localToWorldAngularVelocity(entitySideProperties.getAngularVelocity(),
entitySideProperties.getParentID(),
entitySideProperties.getParentJointIndex(),
success);
scriptSideProperties.setPosition(worldPosition);
scriptSideProperties.setRotation(worldRotation);
scriptSideProperties.setVelocity(worldVelocity);
scriptSideProperties.setAngularVelocity(worldAngularVelocity);
return scriptSideProperties;
}
@ -125,6 +136,27 @@ EntityItemProperties convertLocationFromScriptSemantics(const EntityItemProperti
entitySideProperties.setRotation(localRotation);
}
if (scriptSideProperties.localVelocityChanged()) {
entitySideProperties.setVelocity(scriptSideProperties.getLocalVelocity());
} else if (scriptSideProperties.velocityChanged()) {
glm::vec3 localVelocity = SpatiallyNestable::worldToLocalVelocity(entitySideProperties.getVelocity(),
entitySideProperties.getParentID(),
entitySideProperties.getParentJointIndex(),
success);
entitySideProperties.setVelocity(localVelocity);
}
if (scriptSideProperties.localAngularVelocityChanged()) {
entitySideProperties.setAngularVelocity(scriptSideProperties.getLocalAngularVelocity());
} else if (scriptSideProperties.angularVelocityChanged()) {
glm::vec3 localAngularVelocity =
SpatiallyNestable::worldToLocalAngularVelocity(entitySideProperties.getAngularVelocity(),
entitySideProperties.getParentID(),
entitySideProperties.getParentJointIndex(),
success);
entitySideProperties.setAngularVelocity(localAngularVelocity);
}
return entitySideProperties;
}

View file

@ -9,7 +9,11 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "FBXReader.h"
#include <iostream>
#include <memory>
#include <QBuffer>
#include <QDataStream>
#include <QIODevice>
@ -20,9 +24,8 @@
#include <QFileInfo>
#include <QJsonDocument>
#include <QJsonObject>
#include "FBXReader.h"
#include <memory>
#include "ModelFormatLogging.h"
bool FBXMaterial::needTangentSpace() const {
return !normalTexture.isNull();
@ -258,11 +261,11 @@ void FBXReader::consolidateFBXMaterials(const QVariantHash& mapping) {
}
}
}
qDebug() << " fbx material Name:" << material.name;
qCDebug(modelformat) << " fbx material Name:" << material.name;
if (materialMap.contains(material.name)) {
QJsonObject materialOptions = materialMap.value(material.name).toObject();
qDebug() << "Mapping fbx material:" << material.name << " with HifiMaterial: " << materialOptions;
qCDebug(modelformat) << "Mapping fbx material:" << material.name << " with HifiMaterial: " << materialOptions;
if (materialOptions.contains("scattering")) {
float scattering = (float) materialOptions.value("scattering").toDouble();

View file

@ -224,6 +224,38 @@ glm::quat SpatiallyNestable::worldToLocal(const glm::quat& orientation,
return result.getRotation();
}
glm::vec3 SpatiallyNestable::worldToLocalVelocity(const glm::vec3& velocity, const QUuid& parentID,
int parentJointIndex, bool& success) {
SpatiallyNestablePointer parent = SpatiallyNestable::findByID(parentID, success);
if (!success || !parent) {
return velocity;
}
Transform parentTransform = parent->getTransform(success);
if (!success) {
return velocity;
}
glm::vec3 parentVelocity = parent->getVelocity(success);
if (!success) {
return velocity;
}
return glm::inverse(parentTransform.getRotation()) * (velocity - parentVelocity);
}
glm::vec3 SpatiallyNestable::worldToLocalAngularVelocity(const glm::vec3& angularVelocity, const QUuid& parentID,
int parentJointIndex, bool& success) {
SpatiallyNestablePointer parent = SpatiallyNestable::findByID(parentID, success);
if (!success || !parent) {
return angularVelocity;
}
Transform parentTransform = parent->getTransform(success);
if (!success) {
return angularVelocity;
}
return glm::inverse(parentTransform.getRotation()) * angularVelocity;
}
glm::vec3 SpatiallyNestable::localToWorld(const glm::vec3& position,
const QUuid& parentID, int parentJointIndex,
bool& success) {
@ -298,6 +330,38 @@ glm::quat SpatiallyNestable::localToWorld(const glm::quat& orientation,
return result.getRotation();
}
glm::vec3 SpatiallyNestable::localToWorldVelocity(const glm::vec3& velocity, const QUuid& parentID,
int parentJointIndex, bool& success) {
SpatiallyNestablePointer parent = SpatiallyNestable::findByID(parentID, success);
if (!success || !parent) {
return velocity;
}
Transform parentTransform = parent->getTransform(success);
if (!success) {
return velocity;
}
glm::vec3 parentVelocity = parent->getVelocity(success);
if (!success) {
return velocity;
}
return parentVelocity + parentTransform.getRotation() * velocity;
}
glm::vec3 SpatiallyNestable::localToWorldAngularVelocity(const glm::vec3& angularVelocity, const QUuid& parentID,
int parentJointIndex, bool& success) {
SpatiallyNestablePointer parent = SpatiallyNestable::findByID(parentID, success);
if (!success || !parent) {
return angularVelocity;
}
Transform parentTransform = parent->getTransform(success);
if (!success) {
return angularVelocity;
}
return parentTransform.getRotation() * angularVelocity;
}
glm::vec3 SpatiallyNestable::getPosition(bool& success) const {
return getTransform(success).getTranslation();
}
@ -1004,3 +1068,15 @@ void SpatiallyNestable::setLocalTransformAndVelocities(
locationChanged(false);
}
}
SpatiallyNestablePointer SpatiallyNestable::findByID(QUuid id, bool& success) {
QSharedPointer<SpatialParentFinder> parentFinder = DependencyManager::get<SpatialParentFinder>();
if (!parentFinder) {
return nullptr;
}
SpatiallyNestableWeakPointer parentWP = parentFinder->find(id, success);
if (!success) {
return nullptr;
}
return parentWP.lock();
}

View file

@ -48,9 +48,17 @@ public:
static glm::vec3 worldToLocal(const glm::vec3& position, const QUuid& parentID, int parentJointIndex, bool& success);
static glm::quat worldToLocal(const glm::quat& orientation, const QUuid& parentID, int parentJointIndex, bool& success);
static glm::vec3 worldToLocalVelocity(const glm::vec3& velocity, const QUuid& parentID,
int parentJointIndex, bool& success);
static glm::vec3 worldToLocalAngularVelocity(const glm::vec3& angularVelocity, const QUuid& parentID,
int parentJointIndex, bool& success);
static glm::vec3 localToWorld(const glm::vec3& position, const QUuid& parentID, int parentJointIndex, bool& success);
static glm::quat localToWorld(const glm::quat& orientation, const QUuid& parentID, int parentJointIndex, bool& success);
static glm::vec3 localToWorldVelocity(const glm::vec3& velocity,
const QUuid& parentID, int parentJointIndex, bool& success);
static glm::vec3 localToWorldAngularVelocity(const glm::vec3& angularVelocity,
const QUuid& parentID, int parentJointIndex, bool& success);
// world frame
virtual const Transform getTransform(bool& success, int depth = 0) const;
@ -151,6 +159,8 @@ public:
virtual SpatialParentTree* getParentTree() const { return nullptr; }
bool hasAncestorOfType(NestableType nestableType);
SpatiallyNestablePointer getParentPointer(bool& success) const;
static SpatiallyNestablePointer findByID(QUuid id, bool& success);
void getLocalTransformAndVelocities(Transform& localTransform,
glm::vec3& localVelocity,
@ -166,7 +176,6 @@ protected:
QUuid _id;
QUuid _parentID; // what is this thing's transform relative to?
quint16 _parentJointIndex { 0 }; // which joint of the parent is this relative to?
SpatiallyNestablePointer getParentPointer(bool& success) const;
mutable SpatiallyNestableWeakPointer _parent;

View file

@ -2418,28 +2418,13 @@ function MyController(hand) {
var props = Entities.getEntityProperties(entityID, ["parentID", "velocity", "dynamic", "shapeType"]);
var parentID = props.parentID;
var doSetVelocity = false;
if (parentID != NULL_UUID && deactiveProps.parentID == NULL_UUID && propsArePhysical(props)) {
// TODO: EntityScriptingInterface::convertLocationToScriptSemantics should be setting up
// props.velocity to be a world-frame velocity and localVelocity to be vs parent. Until that
// is done, we use a measured velocity here so that things held via a bumper-grab / parenting-grab
// can be thrown.
doSetVelocity = true;
}
if (!noVelocity &&
!doSetVelocity &&
parentID == MyAvatar.sessionUUID &&
Vec3.length(data["gravity"]) > 0.0 &&
data["dynamic"] &&
data["parentID"] == NULL_UUID &&
!data["collisionless"]) {
deactiveProps["velocity"] = {
x: 0.0,
y: 0.1,
z: 0.0
};
doSetVelocity = false;
deactiveProps["velocity"] = this.currentVelocity;
}
if (noVelocity) {
deactiveProps["velocity"] = {
@ -2452,21 +2437,9 @@ function MyController(hand) {
y: 0.0,
z: 0.0
};
doSetVelocity = false;
}
Entities.editEntity(entityID, deactiveProps);
if (doSetVelocity) {
// this is a continuation of the TODO above -- we shouldn't need to set this here.
// do this after the parent has been reset. setting this at the same time as
// the parent causes it to go off in the wrong direction. This is a bug that should
// be fixed.
Entities.editEntity(entityID, {
velocity: this.currentVelocity
// angularVelocity: this.currentAngularVelocity
});
}
data = null;
} else if (this.shouldResetParentOnRelease) {
// we parent-grabbed this from another parent grab. try to put it back where we found it.

View file

@ -1128,37 +1128,40 @@ function handeMenuEvent(menuItem) {
}
tooltip.show(false);
}
// This function tries to find a reasonable position to place a new entity based on the camera
// position. If a reasonable position within the world bounds can't be found, `null` will
// be returned. The returned position will also take into account grid snapping settings.
function getPositionToCreateEntity() {
var distance = cameraManager.enabled ? cameraManager.zoomDistance : DEFAULT_ENTITY_DRAG_DROP_DISTANCE;
var direction = Quat.getFront(Camera.orientation);
var offset = Vec3.multiply(distance, direction);
var placementPosition = Vec3.sum(Camera.position, offset);
var cameraPosition = Camera.position;
var HALF_TREE_SCALE = 16384;
var direction = Quat.getFront(MyAvatar.orientation);
var distance = 1;
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(direction, distance));
var cameraOutOfBounds = Math.abs(cameraPosition.x) > HALF_TREE_SCALE || Math.abs(cameraPosition.y) > HALF_TREE_SCALE ||
Math.abs(cameraPosition.z) > HALF_TREE_SCALE;
var placementOutOfBounds = Math.abs(placementPosition.x) > HALF_TREE_SCALE ||
Math.abs(placementPosition.y) > HALF_TREE_SCALE ||
Math.abs(placementPosition.z) > HALF_TREE_SCALE;
if (cameraOutOfBounds && placementOutOfBounds) {
return null;
if (Camera.mode === "entity" || Camera.mode === "independent") {
position = Vec3.sum(Camera.position, Vec3.multiply(Quat.getFront(Camera.orientation), distance))
}
placementPosition.x = Math.min(HALF_TREE_SCALE, Math.max(-HALF_TREE_SCALE, placementPosition.x));
placementPosition.y = Math.min(HALF_TREE_SCALE, Math.max(-HALF_TREE_SCALE, placementPosition.y));
placementPosition.z = Math.min(HALF_TREE_SCALE, Math.max(-HALF_TREE_SCALE, placementPosition.z));
return placementPosition;
position.y += 0.5;
if (position.x > HALF_TREE_SCALE || position.y > HALF_TREE_SCALE || position.z > HALF_TREE_SCALE) {
return null
}
return position;
}
function getPositionToImportEntity() {
var dimensions = Clipboard.getContentsDimensions();
var HALF_TREE_SCALE = 16384;
var direction = Quat.getFront(MyAvatar.orientation);
var longest = 1;
longest = Math.sqrt(Math.pow(dimensions.x, 2) + Math.pow(dimensions.z, 2));
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(direction, longest));
if (Camera.mode === "entity" || Camera.mode === "independent") {
position = Vec3.sum(Camera.position, Vec3.multiply(Quat.getFront(Camera.orientation), longest))
}
if (position.x > HALF_TREE_SCALE || position.y > HALF_TREE_SCALE || position.z > HALF_TREE_SCALE) {
return null
}
return position;
}
function importSVO(importURL) {
print("Import URL requested: " + importURL);
if (!Entities.canAdjustLocks()) {
@ -1183,7 +1186,7 @@ function importSVO(importURL) {
z: 0
};
if (Clipboard.getClipboardContentsLargestDimension() < VERY_LARGE) {
position = getPositionToCreateEntity();
position = getPositionToImportEntity();
}
if (position !== null && position !== undefined) {
var pastedEntityIDs = Clipboard.pasteEntities(position);

View file

@ -8,6 +8,7 @@
<body onload="ready()">
<div class="search">
<input id="search-input" placeholder="filter" />
<button id="view-logs">Open Log Directory</button>
</div>
<ul class="tabs top">

View file

@ -43,6 +43,7 @@ ready = function() {
var domainServer = remote.getGlobal('domainServer');
var acMonitor = remote.getGlobal('acMonitor');
var openLogDirectory = remote.getGlobal('openLogDirectory');
var pendingLines = {
'ds': new Array(),
@ -218,6 +219,12 @@ ready = function() {
appendLogMessages('ac');
}
// Binding a remote function directly does not work, so bind to a function
// that calls the remote function.
$('#view-logs').on('click', function() {
openLogDirectory();
});
// handle filtering of table rows on input change
$('#search-input').on('input', function() {
filter = $(this).val().toLowerCase();

View file

@ -285,6 +285,10 @@ function openFileBrowser(path) {
}
}
function openLogDirectory() {
openFileBrowser(logPath);
}
// NOTE: this looks like it does nothing, but it's very important.
// Without it the default behaviour is to quit the app once all windows closed
// which is absolutely not what we want for a taskbar application.
@ -309,6 +313,7 @@ global.homeServer = null;
global.domainServer = null;
global.acMonitor = null;
global.userConfig = userConfig;
global.openLogDirectory = openLogDirectory;
var LogWindow = function(ac, ds) {
this.ac = ac;