Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agent assignment client doesn't send avatar data if it doesn't fit in 1 MTU #1270

Open
ksuprynowicz opened this issue Dec 11, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ksuprynowicz
Copy link
Member

Same code works reasonably well in Interface, so maybe Assignment Client is doing something wrong?
Only position will be sent in such case and user is not warned at all:

    int maximumByteArraySize = NLPacket::maxPayloadSize(PacketType::AvatarData) - sizeof(AvatarDataSequenceNumber);

    if (avatarByteArray.size() > maximumByteArraySize) {
        avatarByteArray = toByteArrayStateful(dataDetail, true);

        if (avatarByteArray.size() > maximumByteArraySize) {
            avatarByteArray = toByteArrayStateful(MinimumData, true);

            if (avatarByteArray.size() > maximumByteArraySize) {
                qCWarning(avatars) << "toByteArrayStateful() MinimumData resulted in very large buffer:" << avatarByteArray.size() << "... FAIL!!";
                return 0;
            }
        }
    }

Maybe instead data could be split over several packets?
Surprising part is that Interface deals pretty well with same avatars that don't work on Agent.
Example of broken Agent script:

//
//  simpleBot.js
//  examples
//
//  Created by Brad Hefta-Gaub on 12/23/16.
//  Copyright 2016 High Fidelity, Inc.
//
//  Distributed under the Apache License, Version 2.0.
//  See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//


//var OVERTE_PUBLIC_CDN = networkingConstants.PUBLIC_BUCKET_CDN_URL;

function getRandomFloat(min, max) {
    return Math.random() * (max - min) + min;
}

function getRandomInt (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function printVector(string, vector) {
    print(string + " " + vector.x + ", " + vector.y + ", " + vector.z);
}

var timePassed = 0.0;
var updateSpeed = 3.0;

var X_MIN = 5.0;
var X_MAX = 15.0;
var Z_MIN = 5.0;
var Z_MAX = 15.0;
var Y_PELVIS = 1.0;

Agent.setIsAvatar(true);

// change the avatar's position to the random one
Avatar.position = {x:-8.6826,y:-14.1982,z:129.0581}; // { x: getRandomFloat(X_MIN, X_MAX), y: Y_PELVIS, z: getRandomFloat(Z_MIN, Z_MAX) };;
Avatar.orientation = Quat.fromPitchYawRollDegrees(0, 0, 0);
Avatar.scale = 1.0;

printVector("New bot, position = ", Avatar.position);

//Avatar.setSkeletonModelURL("https://oaktown.pl/bz_proto_1/proto_anim_test_2.fst");
var animationData = {url: "https://oaktown.pl/bz_proto_1/proto_anim_test_2.fbx", firstFrame: 1, lastFrame: 120, fps: 30};
//Avatar.startAnimation(animationData.url, animationData.fps, 1, true, false, 1, animationData.lastFrame);

var millisecondsToWaitBeforeStarting = 8 * 1000;
Script.setTimeout(function () {
    Avatar.setSkeletonModelURL("https://oaktown.pl/bz_proto_1/proto_anim_test_2.fst");
    print("Starting at", JSON.stringify(Avatar.position));
    Avatar.startAnimation(animationData.url, animationData.fps, 1, true, false, 1, animationData.lastFrame);
    var animationDetails = Avatar.getAnimationDetails();
print("Animation details: " + JSON.stringify(animationDetails));
}, millisecondsToWaitBeforeStarting);

Script.setTimeout(function () {
    print("Starting at", JSON.stringify(Avatar.position));
    Avatar.startAnimation(animationData.url, animationData.fps, 1, true, false, 1, animationData.lastFrame);
var animationDetails = Avatar.getAnimationDetails();
print("Animation details: " + JSON.stringify(animationDetails));
}, millisecondsToWaitBeforeStarting*2);

Script.setTimeout(function () {
var animationDetails = Avatar.getAnimationDetails();
print("Animation details: " + JSON.stringify(animationDetails));
}, millisecondsToWaitBeforeStarting*4);

function update(deltaTime) {
    timePassed += deltaTime;
    if (timePassed > updateSpeed) {
        timePassed = 0;
        var newPosition = Vec3.sum(Avatar.position, { x: getRandomFloat(-0.1, 0.1), y: 0, z: getRandomFloat(-0.1, 0.1) });
        Avatar.position = newPosition;
        Vec3.print("new:", newPosition);
    }
}

Script.update.connect(update);

Script that works correctly:

//
//  simpleBot.js
//  examples
//
//  Created by Brad Hefta-Gaub on 12/23/16.
//  Copyright 2016 High Fidelity, Inc.
//
//  Distributed under the Apache License, Version 2.0.
//  See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//


//var OVERTE_PUBLIC_CDN = networkingConstants.PUBLIC_BUCKET_CDN_URL;

function getRandomFloat(min, max) {
    return Math.random() * (max - min) + min;
}

function getRandomInt (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function printVector(string, vector) {
    print(string + " " + vector.x + ", " + vector.y + ", " + vector.z);
}

var timePassed = 0.0;
var updateSpeed = 3.0;

var X_MIN = 5.0;
var X_MAX = 15.0;
var Z_MIN = 5.0;
var Z_MAX = 15.0;
var Y_PELVIS = 1.0;

Agent.setIsAvatar(true);

// change the avatar's position to the random one
Avatar.position = {x:-8.6826,y:-14.1982,z:129.0581}; // { x: getRandomFloat(X_MIN, X_MAX), y: Y_PELVIS, z: getRandomFloat(Z_MIN, Z_MAX) };;
Avatar.orientation = Quat.fromPitchYawRollDegrees(0, 0, 0);
Avatar.scale = 1.0;

printVector("New bot, position = ", Avatar.position);

Avatar.setSkeletonModelURL("https://oaktown.pl/scripts/ac/ac_anim_test_1.fst");
var animationData = {url: "https://oaktown.pl/scripts/ac/ac_anim_test_1.fbx", firstFrame: 1, lastFrame: 120, fps: 30};

var millisecondsToWaitBeforeStarting = 8 * 1000;
Script.setTimeout(function () {
    //Avatar.setSkeletonModelURL("https://oaktown.pl/scripts/ac/ac_anim_test_1.fst");
    print("Starting at", JSON.stringify(Avatar.position));
    Avatar.startAnimation(animationData.url, animationData.fps, 1, true, false, 1, animationData.lastFrame);
}, millisecondsToWaitBeforeStarting);

function update(deltaTime) {
    timePassed += deltaTime;
    if (timePassed > updateSpeed) {
        timePassed = 0;
        var newPosition = Vec3.sum(Avatar.position, { x: getRandomFloat(-0.1, 0.1), y: 0, z: getRandomFloat(-0.1, 0.1) });
        Avatar.position = newPosition;
        Vec3.print("new:", newPosition);
    }
}

Script.update.connect(update);
@ksuprynowicz ksuprynowicz added the bug Something isn't working label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant