Merge pull request #10902 from jmo7/21391

Worklist #21391 Implement a Parenting Tool
This commit is contained in:
Andrew Meadows 2017-08-08 14:56:24 -07:00 committed by GitHub
commit 23c3715e8f
14 changed files with 256 additions and 0 deletions

View file

@ -0,0 +1,66 @@
// 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');
// the fbx model needs to be rotated from where it would naturally face when it first initializes
var ROT_Y_180 = {x: 0, y: 1, z: 0, w: 0};
var START_ROTATION = Quat.normalize(Quat.multiply(Camera.getOrientation(), ROT_Y_180));
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 parentator = Entities.addEntity({
name: "Parent-ator",
type: "Model",
modelURL: MODEL_URL,
shapeType: 'compound',
compoundShapeURL: COLLISION_HULL_URL,
dynamic: true,
damping: 0.9,
script: scriptURL,
dimensions: {
x: 0.1270,
y: 0.2715,
z: 0.4672
},
position: START_POSITION,
rotation: START_ROTATION,
userData: JSON.stringify({
"grabbableKey": {"grabbable": true},
"equipHotspots": [
{
"position": {"x": 0.0, "y": 0.0, "z": -0.170 },
"radius": 0.15,
"joints":{
"RightHand":[
{"x":0.05, "y":0.25, "z":0.03},
{"x":-0.5, "y":-0.5, "z":-0.5, "w":0.5}
],
"LeftHand":[
{"x":-0.05, "y":0.25, "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,152 @@
// parentator.js
//
// Script Type: Entity
// Created by Jeff Moyes on 6/30/2017
// Copyright 2017 High Fidelity, Inc.
//
// This script allows users to parent one object to another via the "parent-ator" entity
// (which looks like a purple gun-like object). The user:
// 1) equips their avatar with this parent-ator,
// 2) taps the end of the parent-ator on an entity (which becomes the child entity), and
// 3) taps the end of the parent-ator on a second entity (which becomes the parent entity)
//
// 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_0_TEXTURE_URL = Script.resolvePath( 'resources/message-0-off.png' );
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, parentEntityID;
var active = false;
function Parentator() {
return;
}
Parentator.prototype.turnOff = function() {
childEntityID = 0;
parentEntityID = 0;
this.active = false;
Entities.editEntity( this.entityID, { textures: JSON.stringify({ "texture-message": MESSAGE_0_TEXTURE_URL }) });
}
Parentator.prototype.turnOn = function() {
childEntityID = 0;
parentEntityID = 0;
this.active = true;
if (Entities.canRez()) {
Entities.editEntity( this.entityID, { textures: JSON.stringify({ "texture-message": MESSAGE_1_TEXTURE_URL }) });
this.playSoundAtCurrentPosition( SOUND_1 );
} else {
Entities.editEntity( this.entityID, { textures: JSON.stringify({ "texture-message": MESSAGE_2_TEXTURE_URL }) });
this.playSoundAtCurrentPosition( SOUND_ERROR );
}
}
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 );
// Makue sure it's off
this.turnOff();
}
Parentator.prototype.startEquip = function( args ) {
this.hand = args[0];
this.turnOn();
}
Parentator.prototype.releaseEquip = function( args ) {
this.hand = undefined;
this.turnOff();
}
Parentator.prototype.collisionWithEntity = function( parentatorID, collidedID, collisionInfo ) {
if ( this.active ) {
// 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 );
if ( !Entities.canRez() ) {
Entities.editEntity( this.entityID, { textures: JSON.stringify({ "texture-message": MESSAGE_2_TEXTURE_URL }) });
this.playSoundAtCurrentPosition( SOUND_ERROR );
}
// 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({ "texture-message": 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({ "texture-message": MESSAGE_4_TEXTURE_URL }) });
this.playSoundAtCurrentPosition( SOUND_2 );
} else {
parentEntityID = collidedID;
this.setParent();
}
}
}
Parentator.prototype.setParent = function() {
var _this = this;
Entities.editEntity( childEntityID, { parentID: parentEntityID });
Entities.editEntity( this.entityID, { textures: JSON.stringify({ "texture-message": MESSAGE_5_TEXTURE_URL }) });
this.playSoundAtCurrentPosition( SOUND_SUCCESS );
Script.setTimeout( function() {
_this.turnOn(); // reset
}, 5000 );
}
Parentator.prototype.playSoundAtCurrentPosition = function( sound ) {
var audioProperties = {
volume: 0.3,
position: Entities.getEntityProperties( this.entityID ).position,
localOnly: true
}
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();
});

View file

@ -0,0 +1,38 @@
# Blender v2.78 (sub 5) OBJ File: 'untitled.blend'
# www.blender.org
mtllib Parent-Tool-CollisionHull.mtl
o Cube.001
v -0.153045 -0.072355 0.173769
v -0.153045 0.040882 0.173769
v -0.067387 0.040882 0.029156
v -0.067387 -0.072355 0.029156
v 0.062301 0.040882 0.029156
v 0.062301 -0.072355 0.029156
v 0.147960 -0.072355 0.173769
v 0.147960 0.040882 0.173769
v 0.147960 0.026770 0.337324
v 0.147960 -0.047896 0.337324
v -0.153045 0.026770 0.337324
v -0.153045 -0.047896 0.337324
vn -0.8604 0.0000 -0.5096
vn 0.0000 0.0000 -1.0000
vn 1.0000 0.0000 0.0000
vn 0.0000 0.0000 1.0000
vn 0.0000 -0.9890 0.1479
vn 0.0000 0.9963 0.0860
vn 0.0000 1.0000 0.0000
vn 0.0000 -1.0000 -0.0000
vn 0.8604 0.0000 -0.5096
vn -1.0000 -0.0000 0.0000
usemtl None
s 1
f 1//1 2//1 3//1 4//1
f 4//2 3//2 5//2 6//2
f 7//3 8//3 9//3 10//3
f 10//4 9//4 11//4 12//4
f 1//5 7//5 10//5 12//5
f 8//6 2//6 11//6 9//6
f 5//7 3//7 2//7 8//7
f 4//8 6//8 7//8 1//8
f 6//9 5//9 8//9 7//9
f 12//10 11//10 2//10 1//10

Binary file not shown.

After

Width:  |  Height:  |  Size: 5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB