mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 22:22:54 +02:00
add doppleganger features
This commit is contained in:
parent
3bbecf5c8b
commit
0587981a20
2 changed files with 31 additions and 64 deletions
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
//For procedural walk animation
|
//For procedural walk animation
|
||||||
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
||||||
Script.include(HIFI_PUBLIC_BUCKET + "scripts/proceduralAnimationAPI.js");
|
Script.include(HIFI_PUBLIC_BUCKET + "scripts/acScripts/proceduralAnimationAPI.js");
|
||||||
|
|
||||||
var procAnimAPI = new ProcAnimAPI();
|
var procAnimAPI = new ProcAnimAPI();
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,12 @@
|
||||||
// To-Do: mirror joints, rotate avatar fully, automatically get avatar fbx, make sure dimensions for avatar are right when u bring it in
|
// To-Do: mirror joints, rotate avatar fully, automatically get avatar fbx, make sure dimensions for avatar are right when u bring it in
|
||||||
|
|
||||||
var TEST_MODEL_URL = 'https://s3.amazonaws.com/hifi-public/ozan/avatars/albert/albert/albert.fbx';
|
var TEST_MODEL_URL = 'https://s3.amazonaws.com/hifi-public/ozan/avatars/albert/albert/albert.fbx';
|
||||||
|
|
||||||
|
var MIRROR_JOINT_DATA = true;
|
||||||
var MIRRORED_ENTITY_SCRIPT_URL = Script.resolvePath('mirroredEntity.js');
|
var MIRRORED_ENTITY_SCRIPT_URL = Script.resolvePath('mirroredEntity.js');
|
||||||
var FREEZE_TOGGLER_SCRIPT_URL = Script.resolvePath('freezeToggler.js?' + Math.random(0, 1000))
|
var FREEZE_TOGGLER_SCRIPT_URL = Script.resolvePath('freezeToggler.js?' + Math.random(0, 1000))
|
||||||
var THROTTLE = true;
|
var THROTTLE = false;
|
||||||
var THROTTLE_RATE = 100;
|
var THROTTLE_RATE = 100;
|
||||||
var MIRROR_JOINT_DATA = true;
|
|
||||||
|
|
||||||
var doppelgangers = [];
|
var doppelgangers = [];
|
||||||
|
|
||||||
function Doppelganger(avatar) {
|
function Doppelganger(avatar) {
|
||||||
|
@ -28,8 +28,8 @@ function Doppelganger(avatar) {
|
||||||
// dimensions: getAvatarDimensions(avatar),
|
// dimensions: getAvatarDimensions(avatar),
|
||||||
position: putDoppelgangerAcrossFromAvatar(this, avatar),
|
position: putDoppelgangerAcrossFromAvatar(this, avatar),
|
||||||
rotation: rotateDoppelgangerTowardAvatar(this, avatar),
|
rotation: rotateDoppelgangerTowardAvatar(this, avatar),
|
||||||
dynamic: false,
|
collisionsWillMove: false,
|
||||||
collisionless: false,
|
ignoreForCollisions: false,
|
||||||
script: FREEZE_TOGGLER_SCRIPT_URL,
|
script: FREEZE_TOGGLER_SCRIPT_URL,
|
||||||
userData: JSON.stringify({
|
userData: JSON.stringify({
|
||||||
grabbableKey: {
|
grabbableKey: {
|
||||||
|
@ -43,7 +43,6 @@ function Doppelganger(avatar) {
|
||||||
this.avatar = avatar;
|
this.avatar = avatar;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getJointData(avatar) {
|
function getJointData(avatar) {
|
||||||
var allJointData = [];
|
var allJointData = [];
|
||||||
var jointNames = MyAvatar.jointNames;
|
var jointNames = MyAvatar.jointNames;
|
||||||
|
@ -363,7 +362,12 @@ function getAvatarFootOffset() {
|
||||||
return offset
|
return offset
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
|
function getAvatarDimensions(avatar) {
|
||||||
|
return dimensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
function rotateDoppelgangerTowardAvatar(doppelganger, avatar) {
|
||||||
var avatarRot = Quat.fromPitchYawRollDegrees(0, avatar.bodyYaw, 0.0);
|
var avatarRot = Quat.fromPitchYawRollDegrees(0, avatar.bodyYaw, 0.0);
|
||||||
|
|
||||||
var ids = Entities.findEntities(MyAvatar.position, 20);
|
var ids = Entities.findEntities(MyAvatar.position, 20);
|
||||||
|
@ -385,30 +389,23 @@ function getAvatarFootOffset() {
|
||||||
|
|
||||||
var isConnected = false;
|
var isConnected = false;
|
||||||
|
|
||||||
function getAvatarDimensions(avatar) {
|
|
||||||
return dimensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
function rotateDoppelgangerTowardAvatar(doppelganger, avatar) {
|
|
||||||
var avatarRot = Quat.fromPitchYawRollDegrees(0, avatar.bodyYaw, 0.0);
|
|
||||||
avatarRot = Vec3.multiply(-1, avatarRot);
|
|
||||||
return avatarRot;
|
|
||||||
}
|
|
||||||
|
|
||||||
function connectDoppelgangerUpdates() {
|
function connectDoppelgangerUpdates() {
|
||||||
Script.update.connect(updateDoppelganger);
|
Script.update.connect(updateDoppelganger);
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function disconnectDoppelgangerUpdates() {
|
function disconnectDoppelgangerUpdates() {
|
||||||
Script.update.disconnect(updateDoppelganger);
|
print('SHOULD DISCONNECT')
|
||||||
|
if (isConnected === true) {
|
||||||
|
Script.update.disconnect(updateDoppelganger);
|
||||||
|
}
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var sinceLastUpdate = 0;
|
var sinceLastUpdate = 0;
|
||||||
|
|
||||||
function updateDoppelganger() {
|
function updateDoppelganger(deltaTime) {
|
||||||
if (THROTTLE === true) {
|
if (THROTTLE === true) {
|
||||||
sinceLastUpdate = sinceLastUpdate + deltaTime * 100;
|
sinceLastUpdate = sinceLastUpdate + deltaTime * 100;
|
||||||
if (sinceLastUpdate > THROTTLE_RATE) {
|
if (sinceLastUpdate > THROTTLE_RATE) {
|
||||||
sinceLastUpdate = 0;
|
sinceLastUpdate = 0;
|
||||||
|
@ -417,6 +414,7 @@ function updateDoppelganger() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var absoluteXforms = buildAbsoluteXformsFromMyAvatar();
|
var absoluteXforms = buildAbsoluteXformsFromMyAvatar();
|
||||||
if (MIRROR_JOINT_DATA) {
|
if (MIRROR_JOINT_DATA) {
|
||||||
var mirroredAbsoluteXforms = [];
|
var mirroredAbsoluteXforms = [];
|
||||||
|
@ -436,17 +434,17 @@ function updateDoppelganger() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makeDoppelgangerForMyAvatar() {
|
||||||
|
var doppelganger = createDoppelganger(MyAvatar);
|
||||||
|
doppelgangers.push(doppelganger);
|
||||||
|
connectDoppelgangerUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
function subscribeToWearableMessages() {
|
function subscribeToWearableMessages() {
|
||||||
Messages.subscribe('Hifi-Doppelganger-Wearable');
|
Messages.subscribe('Hifi-Doppelganger-Wearable');
|
||||||
Messages.messageReceived.connect(handleWearableMessages);
|
Messages.messageReceived.connect(handleWearableMessages);
|
||||||
}
|
}
|
||||||
|
|
||||||
function subscribeToWearableMessagesForAvatar() {
|
|
||||||
Messages.subscribe('Hifi-Doppelganger-Wearable-Avatar');
|
|
||||||
Messages.messageReceived.connect(handleWearableMessages);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function subscribeToFreezeMessages() {
|
function subscribeToFreezeMessages() {
|
||||||
Messages.subscribe('Hifi-Doppelganger-Freeze');
|
Messages.subscribe('Hifi-Doppelganger-Freeze');
|
||||||
Messages.messageReceived.connect(handleFreezeMessages);
|
Messages.messageReceived.connect(handleFreezeMessages);
|
||||||
|
@ -487,7 +485,6 @@ function handleWearableMessages(channel, message, sender) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (sender !== MyAvatar.sessionUUID) {
|
if (sender !== MyAvatar.sessionUUID) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -510,33 +507,6 @@ function handleWearableMessages(channel, message, sender) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function mirrorEntitiesForAvatar(avatar, parsedMessage) {
|
|
||||||
var action = parsedMessage.action;
|
|
||||||
print('IN MIRROR ENTITIES CALL' + action)
|
|
||||||
|
|
||||||
var baseEntity = parsedMessage.baseEntity;
|
|
||||||
|
|
||||||
var wearableProps = Entities.getEntityProperties(baseEntity);
|
|
||||||
print('WEARABLE PROPS::')
|
|
||||||
delete wearableProps.id;
|
|
||||||
delete wearableProps.created;
|
|
||||||
delete wearableProps.age;
|
|
||||||
delete wearableProps.ageAsText;
|
|
||||||
|
|
||||||
var joint = wearableProps.parentJointIndex;
|
|
||||||
if (action === 'add') {
|
|
||||||
print('IN AVATAR ADD')
|
|
||||||
}
|
|
||||||
if (action === 'remove') {
|
|
||||||
print('IN AVATAR REMOVE')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action === 'update') {
|
|
||||||
print('IN AVATAR UPDATE')
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function mirrorEntitiesForDoppelganger(doppelganger, parsedMessage) {
|
function mirrorEntitiesForDoppelganger(doppelganger, parsedMessage) {
|
||||||
var doppelgangerProps = Entities.getEntityProperties(doppelganger.id);
|
var doppelgangerProps = Entities.getEntityProperties(doppelganger.id);
|
||||||
|
|
||||||
|
@ -641,13 +611,10 @@ function getBaseEntityForMirrorEntity(mirrorEntity) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeDoppelgangerForMyAvatar() {
|
|
||||||
var doppelganger = createDoppelganger(MyAvatar);
|
|
||||||
doppelgangers.push(doppelganger);
|
|
||||||
connectDoppelgangerUpdates();
|
|
||||||
}
|
|
||||||
|
|
||||||
makeDoppelgangerForMyAvatar();
|
makeDoppelgangerForMyAvatar();
|
||||||
|
subscribeToWearableMessages();
|
||||||
|
subscribeToWearableMessagesForAvatar();
|
||||||
|
subscribeToFreezeMessages();
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
if (isConnected === true) {
|
if (isConnected === true) {
|
||||||
|
@ -655,8 +622,8 @@ function cleanup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
doppelgangers.forEach(function(doppelganger) {
|
doppelgangers.forEach(function(doppelganger) {
|
||||||
|
print('DOPPELGANGER' + doppelganger.id)
|
||||||
Entities.deleteEntity(doppelganger.id);
|
Entities.deleteEntity(doppelganger.id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.scriptEnding.connect(cleanup);
|
Script.scriptEnding.connect(cleanup);
|
Loading…
Reference in a new issue