This commit is contained in:
howard-stearns 2016-01-25 17:01:29 -08:00
commit 331e4e0fe6
6 changed files with 345 additions and 172 deletions

View file

@ -1556,6 +1556,11 @@ PropertiesTool = function(opts) {
Entities.editEntity(selectionManager.selections[i], properties);
}
} else {
if (data.properties.dynamic === false) {
// this object is leaving dynamic, so we zero its velocities
data.properties["velocity"] = {x: 0, y: 0, z: 0};
data.properties["angularVelocity"] = {x: 0, y: 0, z: 0};
}
if (data.properties.rotation !== undefined) {
var rotation = data.properties.rotation;
data.properties.rotation = Quat.fromPitchYawRollDegrees(rotation.x, rotation.y, rotation.z);
@ -1836,4 +1841,4 @@ propertyMenu.onSelectMenuItem = function(name) {
var showMenuItem = propertyMenu.addMenuItem("Show in Marketplace");
propertiesTool = PropertiesTool();
propertiesTool = PropertiesTool();

View file

@ -115,12 +115,13 @@
this.shootArrowSound = SoundCache.getSound(SHOOT_ARROW_SOUND_URL);
this.arrowHitSound = SoundCache.getSound(ARROW_HIT_SOUND_URL);
this.arrowNotchSound = SoundCache.getSound(NOTCH_ARROW_SOUND_URL);
var userData = Entities.getEntityProperties(this.entityID).userData;
this.userData = JSON.parse(userData);
this.preNotchString = this.userData.bowKey.preNotchString;
},
unload: function() {
this.deleteStrings();
Entities.deleteEntity(this.preNotchString);
Entities.deleteEntity(this.arrow);
},
@ -174,18 +175,6 @@
this.bowProperties = Entities.getEntityProperties(this.entityID);
//create a string across the bow when we pick it up
if (this.preNotchString === null) {
this.createPreNotchString();
}
if (this.preNotchString !== null && this.aiming === false) {
// print('DRAW PRE NOTCH STRING')
this.drawPreNotchStrings();
}
// create the notch detector that arrows will look for
if (this.aiming === true) {
Entities.editEntity(this.preNotchString, {
visible: false
@ -213,11 +202,9 @@
var data = getEntityCustomData('grabbableKey', this.entityID, {});
data.grabbable = true;
setEntityCustomData('grabbableKey', this.entityID, data);
Entities.deleteEntity(this.preNotchString);
Entities.deleteEntity(this.arrow);
this.aiming = false;
this.hasArrowNotched = false;
this.preNotchString = null;
}
},
@ -334,10 +321,6 @@
var bottomStringPosition = Vec3.sum(this.bowProperties.position, downOffset);
this.bottomStringPosition = Vec3.sum(bottomStringPosition, backOffset);
Entities.editEntity(this.preNotchString, {
position: this.topStringPosition
});
Entities.editEntity(this.topString, {
position: this.topStringPosition
});
@ -381,50 +364,6 @@
return [topVector, bottomVector];
},
createPreNotchString: function() {
this.bowProperties = Entities.getEntityProperties(_this.entityID, ["position", "rotation", "userData"]);
var stringProperties = {
type: 'Line',
position: Vec3.sum(this.bowProperties.position, TOP_NOTCH_OFFSET),
dimensions: LINE_DIMENSIONS,
visible: true,
dynamic: false,
collisionless: true,
userData: JSON.stringify({
grabbableKey: {
grabbable: false
}
})
};
this.preNotchString = Entities.addEntity(stringProperties);
},
drawPreNotchStrings: function() {
this.bowProperties = Entities.getEntityProperties(_this.entityID, ["position", "rotation", "userData"]);
this.updateStringPositions();
var downVector = Vec3.multiply(-1, Quat.getUp(this.bowProperties.rotation));
var downOffset = Vec3.multiply(downVector, BOTTOM_NOTCH_OFFSET * 2);
Entities.editEntity(this.preNotchString, {
name: 'Hifi-Pre-Notch-String',
linePoints: [{
x: 0,
y: 0,
z: 0
}, Vec3.sum({
x: 0,
y: 0,
z: 0
}, downOffset)],
lineWidth: 5,
color: this.stringData.currentColor,
});
},
checkStringHand: function() {
//invert the hands because our string will be held with the opposite hand of the first one we pick up the bow with
var triggerLookup;
@ -613,4 +552,4 @@
};
return new Bow();
});
});

View file

@ -10,6 +10,8 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var utilsPath = Script.resolvePath('../../libraries/utils.js');
Script.include(utilsPath);
var SCRIPT_URL = Script.resolvePath('bow.js');
@ -33,39 +35,116 @@ var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
z: 0
}), Vec3.multiply(1, Quat.getFront(Camera.getOrientation())));
var bow = Entities.addEntity({
name: 'Hifi-Bow',
type: "Model",
modelURL: MODEL_URL,
position: center,
dimensions: BOW_DIMENSIONS,
dynamic: true,
gravity: BOW_GRAVITY,
shapeType: 'compound',
compoundShapeURL: COLLISION_HULL_URL,
script: SCRIPT_URL,
userData: JSON.stringify({
grabbableKey: {
invertSolidWhileHeld: true,
spatialKey: {
leftRelativePosition: {
x: -0.02,
y: 0.08,
z: 0.09
},
relativePosition: {
x: 0.02,
y: 0.08,
z: 0.09
},
relativeRotation: Quat.fromPitchYawRollDegrees(0, 90, -90)
var TOP_NOTCH_OFFSET = 0.6;
var BOTTOM_NOTCH_OFFSET = 0.6;
var LINE_DIMENSIONS = {
x: 5,
y: 5,
z: 5
};
var bow;
function makeBow() {
var bowProperties = {
name: 'Hifi-Bow',
type: "Model",
modelURL: MODEL_URL,
position: center,
dimensions: BOW_DIMENSIONS,
dynamic: true,
gravity: BOW_GRAVITY,
shapeType: 'compound',
compoundShapeURL: COLLISION_HULL_URL,
script: SCRIPT_URL,
userData: JSON.stringify({
grabbableKey: {
invertSolidWhileHeld: true,
spatialKey: {
leftRelativePosition: {
x: -0.02,
y: 0.08,
z: 0.09
},
relativePosition: {
x: 0.02,
y: 0.08,
z: 0.09
},
relativeRotation: Quat.fromPitchYawRollDegrees(0, 90, -90)
}
}
}
})
});
})
};
bow = Entities.addEntity(bowProperties);
createPreNotchString();
}
var preNotchString;
function createPreNotchString() {
var bowProperties = Entities.getEntityProperties(bow, ["position", "rotation", "userData"]);
var downVector = Vec3.multiply(-1, Quat.getUp(bowProperties.rotation));
var downOffset = Vec3.multiply(downVector, BOTTOM_NOTCH_OFFSET * 2);
var upVector = Quat.getUp(bowProperties.rotation);
var upOffset = Vec3.multiply(upVector, TOP_NOTCH_OFFSET);
var backOffset = Vec3.multiply(-0.1, Quat.getFront(bowProperties.rotation));
var topStringPosition = Vec3.sum(bowProperties.position, upOffset);
topStringPosition = Vec3.sum(topStringPosition, backOffset);
var stringProperties = {
name: 'Hifi-Bow-Pre-Notch-String',
type: 'Line',
position: topStringPosition,
linePoints: [{
x: 0,
y: 0,
z: 0
}, Vec3.sum({
x: 0,
y: 0,
z: 0
}, downOffset)],
lineWidth: 5,
color: {
red: 255,
green: 255,
blue: 255
},
dimensions: LINE_DIMENSIONS,
visible: true,
dynamic: false,
collisionless: true,
parentID: bow,
userData: JSON.stringify({
grabbableKey: {
grabbable: false
}
})
};
preNotchString = Entities.addEntity(stringProperties);
var data = {
preNotchString: preNotchString
};
setEntityCustomData('bowKey', bow, data);
}
makeBow();
function cleanup() {
Entities.deleteEntity(bow);
Entities.deleteEntity(preNotchString);
}
Script.scriptEnding.connect(cleanup);
Script.scriptEnding.connect(cleanup);

View file

@ -480,12 +480,17 @@ Model* RenderableModelEntityItem::getModel(EntityTreeRenderer* renderer) {
} else { // we already have the model we want...
result = _model;
}
} else { // if our desired URL is empty, we may need to delete our existing model
if (_model) {
_myRenderer->releaseModel(_model);
result = _model = NULL;
_needsInitialSimulation = true;
}
} else if (_model) {
// remove from scene
render::ScenePointer scene = AbstractViewStateInterface::instance()->getMain3DScene();
render::PendingChanges pendingChanges;
_model->removeFromScene(scene, pendingChanges);
scene->enqueuePendingChanges(pendingChanges);
// release interest
_myRenderer->releaseModel(_model);
result = _model = NULL;
_needsInitialSimulation = true;
}
return result;

View file

@ -330,10 +330,11 @@
z: 506.46
};
var SCRIPT_URL = Script.resolvePath('bow.js');
var BOW_ROTATION = Quat.fromPitchYawRollDegrees(-103.05, -178.60, -87.27);
var MODEL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/new/bow-deadly.fbx";
var COLLISION_HULL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/new/bow_collision_hull.obj";
var BOW_DIMENSIONS = {
x: 0.04,
y: 1.3,
@ -346,44 +347,114 @@
z: 0
};
var bow = Entities.addEntity({
name: 'Hifi-Bow',
type: "Model",
modelURL: MODEL_URL,
position: startPosition,
rotation: BOW_ROTATION,
dimensions: BOW_DIMENSIONS,
dynamic: true,
gravity: BOW_GRAVITY,
shapeType: 'compound',
compoundShapeURL: COLLISION_HULL_URL,
script: bowScriptURL,
userData: JSON.stringify({
resetMe: {
resetMe: true
},
grabbableKey: {
invertSolidWhileHeld: true,
spatialKey: {
rightRelativePosition: {
x: 0.03,
y: 0.08,
z: 0.11
},
leftRelativePosition: {
x: -0.03,
y: 0.08,
z: 0.11
},
relativeRotation: Quat.fromPitchYawRollDegrees(180, 90, 90)
var TOP_NOTCH_OFFSET = 0.6;
var BOTTOM_NOTCH_OFFSET = 0.6;
var LINE_DIMENSIONS = {
x: 5,
y: 5,
z: 5
};
var bow;
function makeBow() {
var bowProperties = {
name: 'Hifi-Bow',
type: "Model",
modelURL: MODEL_URL,
position: startPosition,
dimensions: BOW_DIMENSIONS,
dynamic: true,
gravity: BOW_GRAVITY,
rotation: BOW_ROTATION,
shapeType: 'compound',
compoundShapeURL: COLLISION_HULL_URL,
script: bowScriptURL,
userData: JSON.stringify({
resetMe: {
resetMe: true
},
grabbableKey: {
invertSolidWhileHeld: true,
spatialKey: {
rightRelativePosition: {
x: 0.03,
y: 0.08,
z: 0.11
},
leftRelativePosition: {
x: -0.03,
y: 0.08,
z: 0.11
},
relativeRotation: Quat.fromPitchYawRollDegrees(180, 90, 90)
}
}
}
})
});
})
}
bow = Entities.addEntity(bowProperties);
createPreNotchString();
}
var preNotchString;
function createPreNotchString() {
var bowProperties = Entities.getEntityProperties(bow, ["position", "rotation", "userData"]);
var downVector = Vec3.multiply(-1, Quat.getUp(bowProperties.rotation));
var downOffset = Vec3.multiply(downVector, BOTTOM_NOTCH_OFFSET * 2);
var upVector = Quat.getUp(bowProperties.rotation);
var upOffset = Vec3.multiply(upVector, TOP_NOTCH_OFFSET);
var backOffset = Vec3.multiply(-0.1, Quat.getFront(bowProperties.rotation));
var topStringPosition = Vec3.sum(bowProperties.position, upOffset);
topStringPosition = Vec3.sum(topStringPosition, backOffset);
var stringProperties = {
name: 'Hifi-Bow-Pre-Notch-String',
type: 'Line',
position: topStringPosition,
rotation: Quat.fromPitchYawRollDegrees(164.6, 164.5, -72),
linePoints: [{
x: 0,
y: 0,
z: 0
}, Vec3.sum({
x: 0,
y: 0,
z: 0
}, downOffset)],
lineWidth: 5,
color: {
red: 255,
green: 255,
blue: 255
},
dimensions: LINE_DIMENSIONS,
visible: true,
dynamic: false,
collisionless: true,
parentID: bow,
userData: JSON.stringify({
grabbableKey: {
grabbable: false
}
})
};
preNotchString = Entities.addEntity(stringProperties);
var data = {
preNotchString: preNotchString
};
setEntityCustomData('bowKey', bow, data);
}
makeBow();
}
function createFire() {

View file

@ -314,10 +314,11 @@ MasterReset = function() {
z: 506.46
};
var SCRIPT_URL = Script.resolvePath('bow.js');
var BOW_ROTATION = Quat.fromPitchYawRollDegrees(-103.05, -178.60, -87.27);
var MODEL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/new/bow-deadly.fbx";
var COLLISION_HULL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/new/bow_collision_hull.obj";
var BOW_DIMENSIONS = {
x: 0.04,
y: 1.3,
@ -330,40 +331,113 @@ MasterReset = function() {
z: 0
};
var bow = Entities.addEntity({
name: 'Hifi-Bow',
type: "Model",
modelURL: MODEL_URL,
position: startPosition,
rotation: BOW_ROTATION,
dimensions: BOW_DIMENSIONS,
dynamic: true,
gravity: BOW_GRAVITY,
shapeType: 'compound',
compoundShapeURL: COLLISION_HULL_URL,
script: bowScriptURL,
userData: JSON.stringify({
resetMe: {
resetMe: true
},
grabbableKey: {
invertSolidWhileHeld: true,
spatialKey: {
rightRelativePosition: {
x: 0.03,
y: 0.08,
z: 0.11
},
leftRelativePosition: {
x: -0.03,
y: 0.08,
z: 0.11
},
relativeRotation: Quat.fromPitchYawRollDegrees(180, 90, 90)
var TOP_NOTCH_OFFSET = 0.6;
var BOTTOM_NOTCH_OFFSET = 0.6;
var LINE_DIMENSIONS = {
x: 5,
y: 5,
z: 5
};
var bow;
function makeBow() {
var bowProperties = {
name: 'Hifi-Bow',
type: "Model",
modelURL: MODEL_URL,
position: startPosition,
dimensions: BOW_DIMENSIONS,
dynamic: true,
gravity: BOW_GRAVITY,
rotation: BOW_ROTATION,
shapeType: 'compound',
compoundShapeURL: COLLISION_HULL_URL,
script: bowScriptURL,
userData: JSON.stringify({
resetMe: {
resetMe: true
},
grabbableKey: {
invertSolidWhileHeld: true,
spatialKey: {
rightRelativePosition: {
x: 0.03,
y: 0.08,
z: 0.11
},
leftRelativePosition: {
x: -0.03,
y: 0.08,
z: 0.11
},
relativeRotation: Quat.fromPitchYawRollDegrees(180, 90, 90)
}
}
}
})
});
})
}
bow = Entities.addEntity(bowProperties);
createPreNotchString();
}
var preNotchString;
function createPreNotchString() {
var bowProperties = Entities.getEntityProperties(bow, ["position", "rotation", "userData"]);
var downVector = Vec3.multiply(-1, Quat.getUp(bowProperties.rotation));
var downOffset = Vec3.multiply(downVector, BOTTOM_NOTCH_OFFSET * 2);
var upVector = Quat.getUp(bowProperties.rotation);
var upOffset = Vec3.multiply(upVector, TOP_NOTCH_OFFSET);
var backOffset = Vec3.multiply(-0.1, Quat.getFront(bowProperties.rotation));
var topStringPosition = Vec3.sum(bowProperties.position, upOffset);
topStringPosition = Vec3.sum(topStringPosition, backOffset);
var stringProperties = {
name: 'Hifi-Bow-Pre-Notch-String',
type: 'Line',
position: topStringPosition,
rotation: Quat.fromPitchYawRollDegrees(164.6, 164.5, -72),
linePoints: [{
x: 0,
y: 0,
z: 0
}, Vec3.sum({
x: 0,
y: 0,
z: 0
}, downOffset)],
lineWidth: 5,
color: {
red: 255,
green: 255,
blue: 255
},
dimensions: LINE_DIMENSIONS,
visible: true,
dynamic: false,
collisionless: true,
parentID: bow,
userData: JSON.stringify({
grabbableKey: {
grabbable: false
}
})
};
preNotchString = Entities.addEntity(stringProperties);
var data = {
preNotchString: preNotchString
};
setEntityCustomData('bowKey', bow, data);
}
makeBow();
}
function createFire() {