This commit is contained in:
barnold1953 2014-05-22 12:46:39 -07:00
commit f069b70563
9 changed files with 85 additions and 44 deletions

View file

@ -40,6 +40,16 @@ var modelURLs = [
var toolBar;
function isLocked(properties) {
// special case to lock the ground plane model in hq.
if (location.hostname == "hq.highfidelity.io" &&
properties.modelURL == "https://s3-us-west-1.amazonaws.com/highfidelity-public/ozan/Terrain_Reduce_forAlpha.fbx") {
return true;
}
return false;
}
function controller(wichSide) {
this.side = wichSide;
this.palm = 2 * wichSide;
@ -117,7 +127,7 @@ function controller(wichSide) {
this.grab = function (modelID, properties) {
if (this.isLocked(properties)) {
if (isLocked(properties)) {
print("Model locked " + modelID.id);
} else {
print("Grabbing " + modelID.id);
@ -150,15 +160,6 @@ function controller(wichSide) {
}
}
this.isLocked = function (properties) {
// special case to lock the ground plane model in hq.
if (location.hostname == "hq.highfidelity.io" &&
properties.modelURL == "https://s3-us-west-1.amazonaws.com/highfidelity-public/ozan/Terrain_Reduce_forAlpha.fbx") {
return true;
}
return false;
}
this.checkModel = function (properties) {
// special case to lock the ground plane model in hq.
if (this.isLocked(properties)) {
@ -293,6 +294,7 @@ function controller(wichSide) {
if (this.pressing) {
Vec3.print("Looking at: ", this.palmPosition);
var foundModels = Models.findModels(this.palmPosition, LASER_LENGTH_FACTOR);
for (var i = 0; i < foundModels.length; i++) {
if (!foundModels[i].isKnownID) {
@ -305,7 +307,9 @@ function controller(wichSide) {
}
var properties = Models.getModelProperties(foundModels[i]);
if (this.isLocked(properties)) {
print("foundModels["+i+"].modelURL=" + properties.modelURL);
if (isLocked(properties)) {
print("Model locked " + properties.id);
} else {
print("Checking properties: " + properties.id + " " + properties.isKnownID);
@ -486,7 +490,7 @@ function mousePressEvent(event) {
}
var properties = Models.getModelProperties(foundModels[i]);
if (this.isLocked(properties)) {
if (isLocked(properties)) {
print("Model locked " + properties.id);
} else {
print("Checking properties: " + properties.id + " " + properties.isKnownID);
@ -632,10 +636,23 @@ function mouseMoveEvent(event) {
Models.editModel(selectedModelID, selectedModelProperties);
}
function setupModelMenus() {
// add our menuitems
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Models", isSeparator: true, beforeItem: "Physics" });
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Delete Model", shortcutKeyEvent: { text: "backspace" }, afterItem: "Models" });
}
function cleanupModelMenus() {
// delete our menuitems
Menu.removeSeparator("Edit", "Models");
Menu.removeMenuItem("Edit", "Delete Model");
}
function scriptEnding() {
leftController.cleanup();
rightController.cleanup();
toolBar.cleanup();
cleanupModelMenus();
}
Script.scriptEnding.connect(scriptEnding);
@ -644,5 +661,22 @@ Script.update.connect(checkController);
Controller.mousePressEvent.connect(mousePressEvent);
Controller.mouseMoveEvent.connect(mouseMoveEvent);
setupModelMenus();
Menu.menuItemEvent.connect(function(menuItem){
print("menuItemEvent() in JS... menuItem=" + menuItem);
if (menuItem == "Delete Model") {
if (leftController.grabbing) {
print(" Delete Model.... controller.modelID="+ leftController.modelID);
Models.deleteModel(leftController.modelID);
leftController.grabbing = false;
} else if (rightController.grabbing) {
print(" Delete Model.... controller.modelID="+ rightController.modelID);
Models.deleteModel(rightController.modelID);
rightController.grabbing = false;
} else {
print(" Delete Model.... not holding...");
}
}
});

View file

@ -8,6 +8,10 @@
// This is an example script that demonstrates use of the Controller and MyAvatar classes to implement
// avatar flying through the hydra/controller joysticks
//
// The joysticks (on hydra) will drive the avatar much like a playstation controller.
//
// Pressing the '4' or the 'FWD' button and moving/banking the hand will allow you to move and fly.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
@ -15,8 +19,8 @@
var damping = 0.9;
var position = { x: MyAvatar.position.x, y: MyAvatar.position.y, z: MyAvatar.position.z };
var joysticksCaptured = false;
var THRUST_CONTROLLER = 0;
var VIEW_CONTROLLER = 1;
var THRUST_CONTROLLER = 1;
var VIEW_CONTROLLER = 0;
var INITIAL_THRUST_MULTPLIER = 1.0;
var THRUST_INCREASE_RATE = 1.05;
var MAX_THRUST_MULTIPLIER = 75.0;
@ -46,9 +50,12 @@ var JOYSTICK_PITCH_MAG = PITCH_MAG * 0.5;
var LEFT_PALM = 0;
var LEFT_BUTTON_4 = 4;
var LEFT_BUTTON_4 = 5;
var LEFT_BUTTON_FWD = 5;
var RIGHT_PALM = 2;
var RIGHT_BUTTON_4 = 10;
var RIGHT_BUTTON_FWD = 11;
function printVector(text, v, decimals) {
@ -57,6 +64,15 @@ function printVector(text, v, decimals) {
var debug = false;
function getJoystickPosition(palm) {
// returns CONTROLLER_ID position in avatar local frame
var invRotation = Quat.inverse(MyAvatar.orientation);
var palmWorld = Controller.getSpatialControlPosition(palm);
var palmRelative = Vec3.subtract(palmWorld, MyAvatar.position);
var palmLocal = Vec3.multiplyQbyV(invRotation, palmRelative);
return palmLocal;
}
// Used by handleGrabBehavior() for managing the grab position changes
function getAndResetGrabDelta() {
var HAND_GRAB_SCALE_DISTANCE = 2.0;
@ -75,19 +91,19 @@ function getGrabRotation() {
// When move button is pressed, process results
function handleGrabBehavior(deltaTime) {
// check for and handle grab behaviors
grabbingWithRightHand = Controller.isButtonPressed(RIGHT_BUTTON_4);
grabbingWithLeftHand = Controller.isButtonPressed(LEFT_BUTTON_4);
grabbingWithRightHand = Controller.isButtonPressed(RIGHT_BUTTON_FWD) || Controller.isButtonPressed(RIGHT_BUTTON_4);
grabbingWithLeftHand = Controller.isButtonPressed(LEFT_BUTTON_FWD) || Controller.isButtonPressed(LEFT_BUTTON_4);
stoppedGrabbingWithLeftHand = false;
stoppedGrabbingWithRightHand = false;
if (grabbingWithRightHand && !wasGrabbingWithRightHand) {
// Just starting grab, capture starting rotation
grabStartRotation = Controller.getSpatialControlRawRotation(RIGHT_PALM);
grabStartPosition = Controller.getSpatialControlPosition(RIGHT_PALM);
grabStartPosition = getJoystickPosition(RIGHT_PALM);
if (debug) printVector("start position", grabStartPosition, 3);
}
if (grabbingWithRightHand) {
grabDelta = Vec3.subtract(Controller.getSpatialControlPosition(RIGHT_PALM), grabStartPosition);
grabDelta = Vec3.subtract(getJoystickPosition(RIGHT_PALM), grabStartPosition);
grabCurrentRotation = Controller.getSpatialControlRawRotation(RIGHT_PALM);
}
if (!grabbingWithRightHand && wasGrabbingWithRightHand) {
@ -99,12 +115,12 @@ function handleGrabBehavior(deltaTime) {
if (grabbingWithLeftHand && !wasGrabbingWithLeftHand) {
// Just starting grab, capture starting rotation
grabStartRotation = Controller.getSpatialControlRawRotation(LEFT_PALM);
grabStartPosition = Controller.getSpatialControlPosition(LEFT_PALM);
grabStartPosition = getJoystickPosition(LEFT_PALM);
if (debug) printVector("start position", grabStartPosition, 3);
}
if (grabbingWithLeftHand) {
grabDelta = Vec3.subtract(Controller.getSpatialControlPosition(LEFT_PALM), grabStartPosition);
grabDelta = Vec3.subtract(getJoystickPosition(LEFT_PALM), grabStartPosition);
grabCurrentRotation = Controller.getSpatialControlRawRotation(LEFT_PALM);
}
if (!grabbingWithLeftHand && wasGrabbingWithLeftHand) {
@ -122,23 +138,20 @@ function handleGrabBehavior(deltaTime) {
var front = Quat.getFront(headOrientation);
var right = Quat.getRight(headOrientation);
var up = Quat.getUp(headOrientation);
grabDelta = Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.multiply(grabDelta, -1));
if (debug) {
printVector("grabDelta: ", grabDelta, 3);
}
var THRUST_GRAB_SCALING = 0.0;
var THRUST_GRAB_SCALING = 300000.0;
var thrustFront = Vec3.multiply(front, MyAvatar.scale * grabDelta.z * THRUST_GRAB_SCALING * deltaTime);
var thrustFront = Vec3.multiply(front, MyAvatar.scale * -grabDelta.z * THRUST_GRAB_SCALING * deltaTime);
MyAvatar.addThrust(thrustFront);
var thrustRight = Vec3.multiply(right, MyAvatar.scale * grabDelta.x * THRUST_GRAB_SCALING * deltaTime);
MyAvatar.addThrust(thrustRight);
var thrustUp = Vec3.multiply(up, MyAvatar.scale * grabDelta.y * THRUST_GRAB_SCALING * deltaTime);
MyAvatar.addThrust(thrustUp);
// add some rotation...
var deltaRotation = getGrabRotation();
var PITCH_SCALING = 2.0;

View file

@ -236,7 +236,7 @@ function checkControllerSide(whichSide) {
debugPrint("modelRadius=" +modelRadius);
newModel = Models.addModel(properties);
//newModel = Models.addModel(properties);
print("just added model... newModel=" + newModel.creatorTokenID);
print("properties.animationURL=" + properties.animationURL);

View file

@ -1476,10 +1476,10 @@ void Application::importVoxels() {
}
if (!_voxelImporter->exec()) {
qDebug() << "[DEBUG] Import succeeded." << endl;
qDebug() << "Import succeeded." << endl;
_importSucceded = true;
} else {
qDebug() << "[DEBUG] Import failed." << endl;
qDebug() << "Import failed." << endl;
if (_sharedVoxelSystem.getTree() == _voxelImporter->getVoxelTree()) {
_sharedVoxelSystem.killLocalVoxels();
_sharedVoxelSystem.changeTree(&_clipboard);

View file

@ -682,7 +682,6 @@ void Model::computeBoundingShape(const FBXGeometry& geometry) {
shapeIsSet.fill(false, numJoints);
int numShapesSet = 0;
int lastNumShapesSet = -1;
glm::vec3 rootOffset(0.0f);
while (numShapesSet < numJoints && numShapesSet != lastNumShapesSet) {
lastNumShapesSet = numShapesSet;
for (int i = 0; i < numJoints; i++) {
@ -692,9 +691,11 @@ void Model::computeBoundingShape(const FBXGeometry& geometry) {
if (parentIndex == -1) {
glm::mat4 baseTransform = glm::scale(_scale) * glm::translate(_offset);
glm::quat combinedRotation = joint.preRotation * joint.rotation * joint.postRotation;
transforms[i] = baseTransform * geometry.offset * glm::translate(joint.translation)
glm::mat4 rootTransform = baseTransform * geometry.offset * glm::translate(joint.translation)
* joint.preTransform * glm::mat4_cast(combinedRotation) * joint.postTransform;
rootOffset = extractTranslation(transforms[i]);
// remove the tranlsation part before we save the root transform
transforms[i] = glm::translate(- extractTranslation(rootTransform)) * rootTransform;
finalRotations[i] = combinedRotation;
++numShapesSet;
shapeIsSet[i] = true;
@ -715,7 +716,7 @@ void Model::computeBoundingShape(const FBXGeometry& geometry) {
for (int i = 0; i < _jointShapes.size(); i++) {
const FBXJoint& joint = geometry.joints[i];
glm::vec3 jointToShapeOffset = uniformScale * (finalRotations[i] * joint.shapePosition);
glm::vec3 localPosition = extractTranslation(transforms[i]) + jointToShapeOffset- rootOffset;
glm::vec3 localPosition = extractTranslation(transforms[i]) + jointToShapeOffset;
Shape* shape = _jointShapes[i];
shape->setPosition(localPosition);
shape->setRotation(finalRotations[i] * joint.shapeRotation);
@ -1078,12 +1079,10 @@ void Model::updateJointState(int index) {
if (joint.parentIndex == -1) {
glm::mat4 baseTransform = glm::mat4_cast(_rotation) * glm::scale(_scale) * glm::translate(_offset);
glm::quat combinedRotation = joint.preRotation * state.rotation * joint.postRotation;
state.transform = baseTransform * geometry.offset * glm::translate(state.translation) * joint.preTransform *
glm::mat4_cast(combinedRotation) * joint.postTransform;
state.combinedRotation = _rotation * combinedRotation;
} else {
const JointState& parentState = _jointStates.at(joint.parentIndex);
if (index == geometry.leanJointIndex) {

View file

@ -40,18 +40,17 @@ void LocalVoxelsList::addPersistantTree(QString treeName, VoxelTree* tree) {
StrongVoxelTreePointer treePtr(tree, doNothing);
_persistantTrees.push_back(treePtr);
_trees.insert(treeName, treePtr);
qDebug() << "[DEBUG] LocalVoxelsList : added persistant tree (" << treeName << ")";
}
void LocalVoxelsList::insert(QString treeName, StrongVoxelTreePointer& tree) {
// If the key don't already exist or the value is null
if (!_trees.contains(treeName) || !_trees.value(treeName)) {
_trees.insert(treeName, tree);
qDebug() << "[DEBUG] LocalVoxelsList : added local tree (" << treeName << ")";
qDebug() << "LocalVoxelsList : added local tree (" << treeName << ")";
} else {
// if not we replace the tree created by the user with the existing one
tree = _trees.value(treeName);
qDebug() << "[DEBUG] LocalVoxelsList : local tree already exist (" << treeName << ")";
qDebug() << "[WARNING] LocalVoxelsList : local tree already exist (" << treeName << ")";
}
}
@ -59,9 +58,6 @@ void LocalVoxelsList::remove(QString treeName) {
// if the tree is not used anymore (no strong pointer)
if (!_trees.value(treeName)) {
// then remove it from the list
qDebug() << "[DEBUG] LocalVoxelsList : removed unused tree (" << treeName << ")";
_trees.remove(treeName);
} else {
qDebug() << "[DEBUG] LocalVoxelsList : tree still in use (" << treeName << ")";
}
}

View file

@ -186,7 +186,7 @@ int retrieveData(std::string filename, std::stringstream &ss) {
return ret;
}
std::cerr << "[DEBUG] Schematic compression type not recognize : " << type << std::endl;
std::cerr << "[ERROR] Schematic compression type not recognize : " << type << std::endl;
return 1;
}

View file

@ -359,7 +359,7 @@ bool VoxelTree::readFromSchematicFile(const char *fileName) {
for (int x = 0; x < schematics.getWidth(); ++x) {
if (_stopImport) {
qDebug("[DEBUG] Canceled import at %d voxels.", count);
qDebug("Canceled import at %d voxels.", count);
_stopImport = false;
return true;
}

View file

@ -107,7 +107,6 @@ DeleteVoxelCommand::DeleteVoxelCommand(VoxelTree* tree, VoxelDetail& voxel, Voxe
_voxel.blue = element->getColor()[2];
} else {
_voxel.s = 0.0f;
qDebug() << "No element for delete.";
}
_tree->unlock();
}