66 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

// 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');
Fixes for issues found with last Pull Request 1) Does not give the message regarding not having permissions except for when first rezing the tool. ▶ Fixed - Added in a check for every time there is a collision between the parent-ator and another entity 2) Sound almost unhearable due to distortion ▶ Fixed - Changed audio to 16 bit mono 3) The Parent-ator model rezzes pointing at the user's face. Would probably be better to add 180 to START_POSITION.y then normalize. ▶ Fixed - Added 180 to START_ROTATION (instead fo START_POSITION) and normalized 4) The Parent-ator model floats away. Would suggest increasing linear damping from the default. Maybe go to 0.9 or more. ▶ Fixed - Added damping of 0.9 5) The face normals are inverted on the three rings surrounding the barrel of the Parent-ator model. ▶ Fixed - Normals flipped 6) Also if the user taps an object then releases and re-equips with the Parent-ator it continues to display "tap the child" but will set the object tapped first as the child of the first other object tapped after re-equipping. So the messages change from Tap the child to the "Yay" success message. ▶ Fixed - Re-equiping now resets the parent-ator. 7) Parenting can be broken with this. On occasions the Parentator seems to get out of sequence. With a group of objects eventually one or more can get orphaned. In effect (occasionally ) a single first tap can produce the success message. ▶ Believed to be fixed - I was unable to really reproduce the problem but the fix for the previous item should fix this too, I believe. 8) There is an error in the description on line 7 of parentator.js ▶ Fixed - Changed reference to pingpong gun to parent-ator 9) Equipping can fail with a smaller than normal avatar as the offsets are hard coded rather than scaled relative to the user's scale. ▶ Fixed - I realized I was adding the entity with larger dimensions than the model normally had. I've scaled it down to where it should be and I think this has solved the issue.
2017-07-26 12:14:59 -06:00
// 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));
Fixes for issues found with last Pull Request 1) Does not give the message regarding not having permissions except for when first rezing the tool. ▶ Fixed - Added in a check for every time there is a collision between the parent-ator and another entity 2) Sound almost unhearable due to distortion ▶ Fixed - Changed audio to 16 bit mono 3) The Parent-ator model rezzes pointing at the user's face. Would probably be better to add 180 to START_POSITION.y then normalize. ▶ Fixed - Added 180 to START_ROTATION (instead fo START_POSITION) and normalized 4) The Parent-ator model floats away. Would suggest increasing linear damping from the default. Maybe go to 0.9 or more. ▶ Fixed - Added damping of 0.9 5) The face normals are inverted on the three rings surrounding the barrel of the Parent-ator model. ▶ Fixed - Normals flipped 6) Also if the user taps an object then releases and re-equips with the Parent-ator it continues to display "tap the child" but will set the object tapped first as the child of the first other object tapped after re-equipping. So the messages change from Tap the child to the "Yay" success message. ▶ Fixed - Re-equiping now resets the parent-ator. 7) Parenting can be broken with this. On occasions the Parentator seems to get out of sequence. With a group of objects eventually one or more can get orphaned. In effect (occasionally ) a single first tap can produce the success message. ▶ Believed to be fixed - I was unable to really reproduce the problem but the fix for the previous item should fix this too, I believe. 8) There is an error in the description on line 7 of parentator.js ▶ Fixed - Changed reference to pingpong gun to parent-ator 9) Equipping can fail with a smaller than normal avatar as the offsets are hard coded rather than scaled relative to the user's scale. ▶ Fixed - I realized I was adding the entity with larger dimensions than the model normally had. I've scaled it down to where it should be and I think this has solved the issue.
2017-07-26 12:14:59 -06:00
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,
Fixes for issues found with last Pull Request 1) Does not give the message regarding not having permissions except for when first rezing the tool. ▶ Fixed - Added in a check for every time there is a collision between the parent-ator and another entity 2) Sound almost unhearable due to distortion ▶ Fixed - Changed audio to 16 bit mono 3) The Parent-ator model rezzes pointing at the user's face. Would probably be better to add 180 to START_POSITION.y then normalize. ▶ Fixed - Added 180 to START_ROTATION (instead fo START_POSITION) and normalized 4) The Parent-ator model floats away. Would suggest increasing linear damping from the default. Maybe go to 0.9 or more. ▶ Fixed - Added damping of 0.9 5) The face normals are inverted on the three rings surrounding the barrel of the Parent-ator model. ▶ Fixed - Normals flipped 6) Also if the user taps an object then releases and re-equips with the Parent-ator it continues to display "tap the child" but will set the object tapped first as the child of the first other object tapped after re-equipping. So the messages change from Tap the child to the "Yay" success message. ▶ Fixed - Re-equiping now resets the parent-ator. 7) Parenting can be broken with this. On occasions the Parentator seems to get out of sequence. With a group of objects eventually one or more can get orphaned. In effect (occasionally ) a single first tap can produce the success message. ▶ Believed to be fixed - I was unable to really reproduce the problem but the fix for the previous item should fix this too, I believe. 8) There is an error in the description on line 7 of parentator.js ▶ Fixed - Changed reference to pingpong gun to parent-ator 9) Equipping can fail with a smaller than normal avatar as the offsets are hard coded rather than scaled relative to the user's scale. ▶ Fixed - I realized I was adding the entity with larger dimensions than the model normally had. I've scaled it down to where it should be and I think this has solved the issue.
2017-07-26 12:14:59 -06:00
damping: 0.9,
script: scriptURL,
dimensions: {
Fixes for issues found with last Pull Request 1) Does not give the message regarding not having permissions except for when first rezing the tool. ▶ Fixed - Added in a check for every time there is a collision between the parent-ator and another entity 2) Sound almost unhearable due to distortion ▶ Fixed - Changed audio to 16 bit mono 3) The Parent-ator model rezzes pointing at the user's face. Would probably be better to add 180 to START_POSITION.y then normalize. ▶ Fixed - Added 180 to START_ROTATION (instead fo START_POSITION) and normalized 4) The Parent-ator model floats away. Would suggest increasing linear damping from the default. Maybe go to 0.9 or more. ▶ Fixed - Added damping of 0.9 5) The face normals are inverted on the three rings surrounding the barrel of the Parent-ator model. ▶ Fixed - Normals flipped 6) Also if the user taps an object then releases and re-equips with the Parent-ator it continues to display "tap the child" but will set the object tapped first as the child of the first other object tapped after re-equipping. So the messages change from Tap the child to the "Yay" success message. ▶ Fixed - Re-equiping now resets the parent-ator. 7) Parenting can be broken with this. On occasions the Parentator seems to get out of sequence. With a group of objects eventually one or more can get orphaned. In effect (occasionally ) a single first tap can produce the success message. ▶ Believed to be fixed - I was unable to really reproduce the problem but the fix for the previous item should fix this too, I believe. 8) There is an error in the description on line 7 of parentator.js ▶ Fixed - Changed reference to pingpong gun to parent-ator 9) Equipping can fail with a smaller than normal avatar as the offsets are hard coded rather than scaled relative to the user's scale. ▶ Fixed - I realized I was adding the entity with larger dimensions than the model normally had. I've scaled it down to where it should be and I think this has solved the issue.
2017-07-26 12:14:59 -06:00
x: 0.1270,
y: 0.2715,
z: 0.4672
},
position: START_POSITION,
rotation: START_ROTATION,
userData: JSON.stringify({
"grabbableKey": {"grabbable": true},
"equipHotspots": [
{
Fixes for issues found with last Pull Request 1) Does not give the message regarding not having permissions except for when first rezing the tool. ▶ Fixed - Added in a check for every time there is a collision between the parent-ator and another entity 2) Sound almost unhearable due to distortion ▶ Fixed - Changed audio to 16 bit mono 3) The Parent-ator model rezzes pointing at the user's face. Would probably be better to add 180 to START_POSITION.y then normalize. ▶ Fixed - Added 180 to START_ROTATION (instead fo START_POSITION) and normalized 4) The Parent-ator model floats away. Would suggest increasing linear damping from the default. Maybe go to 0.9 or more. ▶ Fixed - Added damping of 0.9 5) The face normals are inverted on the three rings surrounding the barrel of the Parent-ator model. ▶ Fixed - Normals flipped 6) Also if the user taps an object then releases and re-equips with the Parent-ator it continues to display "tap the child" but will set the object tapped first as the child of the first other object tapped after re-equipping. So the messages change from Tap the child to the "Yay" success message. ▶ Fixed - Re-equiping now resets the parent-ator. 7) Parenting can be broken with this. On occasions the Parentator seems to get out of sequence. With a group of objects eventually one or more can get orphaned. In effect (occasionally ) a single first tap can produce the success message. ▶ Believed to be fixed - I was unable to really reproduce the problem but the fix for the previous item should fix this too, I believe. 8) There is an error in the description on line 7 of parentator.js ▶ Fixed - Changed reference to pingpong gun to parent-ator 9) Equipping can fail with a smaller than normal avatar as the offsets are hard coded rather than scaled relative to the user's scale. ▶ Fixed - I realized I was adding the entity with larger dimensions than the model normally had. I've scaled it down to where it should be and I think this has solved the issue.
2017-07-26 12:14:59 -06:00
"position": {"x": 0.0, "y": 0.0, "z": -0.170 },
"radius": 0.15,
"joints":{
"RightHand":[
Fixes for issues found with last Pull Request 1) Does not give the message regarding not having permissions except for when first rezing the tool. ▶ Fixed - Added in a check for every time there is a collision between the parent-ator and another entity 2) Sound almost unhearable due to distortion ▶ Fixed - Changed audio to 16 bit mono 3) The Parent-ator model rezzes pointing at the user's face. Would probably be better to add 180 to START_POSITION.y then normalize. ▶ Fixed - Added 180 to START_ROTATION (instead fo START_POSITION) and normalized 4) The Parent-ator model floats away. Would suggest increasing linear damping from the default. Maybe go to 0.9 or more. ▶ Fixed - Added damping of 0.9 5) The face normals are inverted on the three rings surrounding the barrel of the Parent-ator model. ▶ Fixed - Normals flipped 6) Also if the user taps an object then releases and re-equips with the Parent-ator it continues to display "tap the child" but will set the object tapped first as the child of the first other object tapped after re-equipping. So the messages change from Tap the child to the "Yay" success message. ▶ Fixed - Re-equiping now resets the parent-ator. 7) Parenting can be broken with this. On occasions the Parentator seems to get out of sequence. With a group of objects eventually one or more can get orphaned. In effect (occasionally ) a single first tap can produce the success message. ▶ Believed to be fixed - I was unable to really reproduce the problem but the fix for the previous item should fix this too, I believe. 8) There is an error in the description on line 7 of parentator.js ▶ Fixed - Changed reference to pingpong gun to parent-ator 9) Equipping can fail with a smaller than normal avatar as the offsets are hard coded rather than scaled relative to the user's scale. ▶ Fixed - I realized I was adding the entity with larger dimensions than the model normally had. I've scaled it down to where it should be and I think this has solved the issue.
2017-07-26 12:14:59 -06:00
{"x":0.05, "y":0.25, "z":0.03},
{"x":-0.5, "y":-0.5, "z":-0.5, "w":0.5}
],
"LeftHand":[
Fixes for issues found with last Pull Request 1) Does not give the message regarding not having permissions except for when first rezing the tool. ▶ Fixed - Added in a check for every time there is a collision between the parent-ator and another entity 2) Sound almost unhearable due to distortion ▶ Fixed - Changed audio to 16 bit mono 3) The Parent-ator model rezzes pointing at the user's face. Would probably be better to add 180 to START_POSITION.y then normalize. ▶ Fixed - Added 180 to START_ROTATION (instead fo START_POSITION) and normalized 4) The Parent-ator model floats away. Would suggest increasing linear damping from the default. Maybe go to 0.9 or more. ▶ Fixed - Added damping of 0.9 5) The face normals are inverted on the three rings surrounding the barrel of the Parent-ator model. ▶ Fixed - Normals flipped 6) Also if the user taps an object then releases and re-equips with the Parent-ator it continues to display "tap the child" but will set the object tapped first as the child of the first other object tapped after re-equipping. So the messages change from Tap the child to the "Yay" success message. ▶ Fixed - Re-equiping now resets the parent-ator. 7) Parenting can be broken with this. On occasions the Parentator seems to get out of sequence. With a group of objects eventually one or more can get orphaned. In effect (occasionally ) a single first tap can produce the success message. ▶ Believed to be fixed - I was unable to really reproduce the problem but the fix for the previous item should fix this too, I believe. 8) There is an error in the description on line 7 of parentator.js ▶ Fixed - Changed reference to pingpong gun to parent-ator 9) Equipping can fail with a smaller than normal avatar as the offsets are hard coded rather than scaled relative to the user's scale. ▶ Fixed - I realized I was adding the entity with larger dimensions than the model normally had. I've scaled it down to where it should be and I think this has solved the issue.
2017-07-26 12:14:59 -06:00
{"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);
}
Fixes for issues found with last Pull Request 1) Does not give the message regarding not having permissions except for when first rezing the tool. ▶ Fixed - Added in a check for every time there is a collision between the parent-ator and another entity 2) Sound almost unhearable due to distortion ▶ Fixed - Changed audio to 16 bit mono 3) The Parent-ator model rezzes pointing at the user's face. Would probably be better to add 180 to START_POSITION.y then normalize. ▶ Fixed - Added 180 to START_ROTATION (instead fo START_POSITION) and normalized 4) The Parent-ator model floats away. Would suggest increasing linear damping from the default. Maybe go to 0.9 or more. ▶ Fixed - Added damping of 0.9 5) The face normals are inverted on the three rings surrounding the barrel of the Parent-ator model. ▶ Fixed - Normals flipped 6) Also if the user taps an object then releases and re-equips with the Parent-ator it continues to display "tap the child" but will set the object tapped first as the child of the first other object tapped after re-equipping. So the messages change from Tap the child to the "Yay" success message. ▶ Fixed - Re-equiping now resets the parent-ator. 7) Parenting can be broken with this. On occasions the Parentator seems to get out of sequence. With a group of objects eventually one or more can get orphaned. In effect (occasionally ) a single first tap can produce the success message. ▶ Believed to be fixed - I was unable to really reproduce the problem but the fix for the previous item should fix this too, I believe. 8) There is an error in the description on line 7 of parentator.js ▶ Fixed - Changed reference to pingpong gun to parent-ator 9) Equipping can fail with a smaller than normal avatar as the offsets are hard coded rather than scaled relative to the user's scale. ▶ Fixed - I realized I was adding the entity with larger dimensions than the model normally had. I've scaled it down to where it should be and I think this has solved the issue.
2017-07-26 12:14:59 -06:00
Script.scriptEnding.connect(cleanUp);