Worklist Implement a Parenting Tool

This commit is contained in:
VRCat\VRKitten 2017-07-05 15:45:49 -06:00
parent 15a5464bab
commit 0f44e67c88
13 changed files with 17516 additions and 0 deletions

View file

@ -0,0 +1,70 @@
// createParentator.js
//
// Script Type: Entity Spawner
// Created by Jeff Moyes on 6/30/2017
// Copyright 2017 High Fidelity, Inc.
//
// This script creates a gun-looking item that, when tapped on an entity, and then a second entity, sets the second entity as the paernt of the first
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var scriptURL = Script.resolvePath('parentator.js');
var MODEL_URL = Script.resolvePath('resources/Parent-Tool-Production.fbx');
var COLLISION_HULL_URL = Script.resolvePath('resources/Parent-Tool-CollisionHull.obj');
//var COLLISION_SOUND_URL = 'http://hifi-production.s3.amazonaws.com/DomainContent/Toybox/ping_pong_gun/plastic_impact.L.wav';
var START_POSITION = Vec3.sum(Vec3.sum(MyAvatar.position, {
x: 0,
y: 0.5,
z: 0
}), Vec3.multiply(0.7, Quat.getForward(Camera.getOrientation())));
var START_ROTATION = Vec3.sum(MyAvatar.position, Vec3.multiply(1.5, Quat.getFront(Camera.getOrientation())));
var parentator = Entities.addEntity({
name: "Parent-ator",
type: "Model",
modelURL: MODEL_URL,
shapeType: 'compound',
compoundShapeURL: COLLISION_HULL_URL,
dynamic: true,
script: scriptURL,
dimensions: {
x: 0.125,
y: 0.2875,
z: 0.5931
},
position: START_POSITION,
rotation: START_ROTATION,
userData: JSON.stringify({
"grabbableKey": {"grabbable": true},
"equipHotspots": [
{
"position": {"x": 0.0, "y": 0.0, "z": 0.0},
"radius": 0.3,
"joints":{
"RightHand":[
{"x":0.05, "y":0.3, "z":0.03},
{"x":-0.5, "y":-0.5, "z":-0.5, "w":0.5}
],
"LeftHand":[
{"x":-0.05, "y":0.3, "z":0.03},
{"x":-0.5, "y":0.5, "z":0.5, "w":0.5}
]
}
}
]
})
});
function cleanUp() {
Entities.deleteEntity(parentator);
}
Script.scriptEnding.connect(cleanUp);

View file

@ -0,0 +1,115 @@
// parentator.js
//
// Script Type: Entity
// Created by Jeff Moyes on 6/30/2017
// Copyright 2017 High Fidelity, Inc.
//
// This script shoots a ping pong ball.
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function() {
var MESSAGE_1_TEXTURE_URL = Script.resolvePath('resources/message-1-start.png');
var MESSAGE_2_TEXTURE_URL = Script.resolvePath('resources/message-2-noperms.png');
var MESSAGE_3_TEXTURE_URL = Script.resolvePath('resources/message-3-tryagain.png');
var MESSAGE_4_TEXTURE_URL = Script.resolvePath('resources/message-4-setparent.png');
var MESSAGE_5_TEXTURE_URL = Script.resolvePath('resources/message-5-success.png');
var SOUND_1_URL = Script.resolvePath('resources/parent-tool-sound1.wav');
var SOUND_2_URL = Script.resolvePath('resources/parent-tool-sound2.wav');
var SOUND_ERROR_URL = Script.resolvePath('resources/parent-tool-sound-error.wav');
var SOUND_SUCCESS_URL = Script.resolvePath('resources/parent-tool-sound-success.wav');
var SOUND_1, SOUND_2, SOUND_ERROR, SOUND_SUCCESS;
var childEntityID = 0;
var parentEntityID = 0;
function Parentator() {
return;
}
Parentator.prototype.preload = function(entityID) {
this.entityID = entityID;
SOUND_1 = SoundCache.getSound(SOUND_1_URL);
SOUND_2 = SoundCache.getSound(SOUND_2_URL);
SOUND_ERROR = SoundCache.getSound(SOUND_ERROR_URL);
SOUND_SUCCESS = SoundCache.getSound(SOUND_SUCCESS_URL);
};
Parentator.prototype.startEquip = function(entityID, args) {
if (Entities.canRez()) {
Entities.editEntity( this.entityID, { textures: JSON.stringify({ "message-1-start.png.001": MESSAGE_1_TEXTURE_URL }) });
this.playSoundAtCurrentPosition(SOUND_1);
} else {
Entities.editEntity( this.entityID, { textures: JSON.stringify({ "message-1-start.png.001": MESSAGE_2_TEXTURE_URL }) });
this.playSoundAtCurrentPosition(SOUND_ERROR);
}
};
Parentator.prototype.collisionWithEntity = function(parentatorID, collidedID, collisionInfo) {
// We don't want to be able to select Lights, Zone, and Particles but they are not collidable anyway so we don't have to worry about them
var collidedEntityProperties = Entities.getEntityProperties(collidedID);
// User has just reclicked the first entity (or it's 'bounced')
if ( childEntityID == collidedID ) {
return;
}
if (collidedEntityProperties.locked) {
Entities.editEntity( this.entityID, { textures: JSON.stringify({ "message-1-start.png.001": MESSAGE_3_TEXTURE_URL }) });
this.playSoundAtCurrentPosition(SOUND_ERROR);
return;
}
// If no entity has been chosen
if ( childEntityID == 0 ) {
childEntityID = collidedID;
// if there is a parentID, remove it
if (collidedEntityProperties.parentID != "{00000000-0000-0000-0000-000000000000}") {
Entities.editEntity( collidedID, { parentID: "{00000000-0000-0000-0000-000000000000}" });
}
if (collidedEntityProperties.dynamic) {
Entities.editEntity( collidedID, { dynamic: false });
}
Entities.editEntity( this.entityID, { textures: JSON.stringify({ "message-1-start.png.001": MESSAGE_4_TEXTURE_URL }) });
this.playSoundAtCurrentPosition(SOUND_2);
} else {
parentEntityID = collidedID;
this.setParent();
}
};
Parentator.prototype.setParent = function() {
Entities.editEntity(childEntityID, { parentID: parentEntityID });
Entities.editEntity( this.entityID, { textures: JSON.stringify({ "message-1-start.png.001": MESSAGE_5_TEXTURE_URL }) });
Script.setTimeout(function() {
childEntityID = 0;
parentEntityID = 0;
Entities.editEntity( this.entityID, { textures: JSON.stringify({ "message-1-start.png.001": MESSAGE_1_TEXTURE_URL }) });
this.playSoundAtCurrentPosition(SOUND_SUCCESS);
}.bind(this), 5000);
};
Parentator.prototype.playSoundAtCurrentPosition = function(sound) {
var audioProperties = {
volume: 0.3,
position: Entities.getEntityProperties(this.entityID).position
}
Audio.playSound(sound, audioProperties);
};
Parentator.prototype.unload = function () {
Entities.deleteEntity(this.entityID);
};
// entity scripts always need to return a newly constructed object of our type
return new Parentator();
});

File diff suppressed because it is too large Load diff

Binary file not shown.

After

(image error) Size: 40 KiB

Binary file not shown.

After

(image error) Size: 80 KiB

Binary file not shown.

After

(image error) Size: 44 KiB

Binary file not shown.

After

(image error) Size: 50 KiB

Binary file not shown.

After

(image error) Size: 51 KiB