mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 17:03:58 +02:00
Work on network streaming of referentials
This commit is contained in:
parent
1138a3a275
commit
490dad6bbd
4 changed files with 104 additions and 6 deletions
|
@ -137,11 +137,20 @@ QByteArray AvatarData::toByteArray() {
|
|||
// hand state
|
||||
setSemiNibbleAt(bitItems,HAND_STATE_START_BIT,_handState);
|
||||
// faceshift state
|
||||
if (_headData->_isFaceshiftConnected) { setAtBit(bitItems, IS_FACESHIFT_CONNECTED); }
|
||||
if (_headData->_isFaceshiftConnected) {
|
||||
setAtBit(bitItems, IS_FACESHIFT_CONNECTED);
|
||||
}
|
||||
if (_isChatCirclingEnabled) {
|
||||
setAtBit(bitItems, IS_CHAT_CIRCLING_ENABLED);
|
||||
}
|
||||
if (_referential != NULL && _referential->isValid()) {
|
||||
setAtBit(bitItems, HAS_REFERENTIAL);
|
||||
}
|
||||
*destinationBuffer++ = bitItems;
|
||||
|
||||
if (_referential != NULL && _referential->isValid()) {
|
||||
destinationBuffer += _referential->packReferential(destinationBuffer);
|
||||
}
|
||||
|
||||
// If it is connected, pack up the data
|
||||
if (_headData->_isFaceshiftConnected) {
|
||||
|
@ -384,6 +393,12 @@ int AvatarData::parseDataAtOffset(const QByteArray& packet, int offset) {
|
|||
_headData->_isFaceshiftConnected = oneAtBit(bitItems, IS_FACESHIFT_CONNECTED);
|
||||
_isChatCirclingEnabled = oneAtBit(bitItems, IS_CHAT_CIRCLING_ENABLED);
|
||||
|
||||
bool hasReferential = oneAtBit(bitItems, HAS_REFERENTIAL);
|
||||
if (hasReferential) {
|
||||
_referential = new Referential(sourceBuffer);
|
||||
}
|
||||
|
||||
|
||||
if (_headData->_isFaceshiftConnected) {
|
||||
float leftEyeBlink, rightEyeBlink, averageLoudness, browAudioLift;
|
||||
minPossibleSize += sizeof(leftEyeBlink) + sizeof(rightEyeBlink) + sizeof(averageLoudness) + sizeof(browAudioLift);
|
||||
|
|
|
@ -81,7 +81,8 @@ const quint32 AVATAR_MOTION_SCRIPTABLE_BITS =
|
|||
const int KEY_STATE_START_BIT = 0; // 1st and 2nd bits
|
||||
const int HAND_STATE_START_BIT = 2; // 3rd and 4th bits
|
||||
const int IS_FACESHIFT_CONNECTED = 4; // 5th bit
|
||||
const int IS_CHAT_CIRCLING_ENABLED = 5;
|
||||
const int IS_CHAT_CIRCLING_ENABLED = 5; // 6th bit
|
||||
const int HAS_REFERENTIAL = 6;
|
||||
|
||||
static const float MAX_AVATAR_SCALE = 1000.f;
|
||||
static const float MIN_AVATAR_SCALE = .005f;
|
||||
|
|
|
@ -9,9 +9,13 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "Referential.h"
|
||||
|
||||
Referential::Referential(AvatarData* avatar) :
|
||||
Referential::Referential(Type type, AvatarData* avatar) :
|
||||
_type(type),
|
||||
_createdAt(usecTimestampNow()),
|
||||
_isValid(true),
|
||||
_avatar(avatar)
|
||||
{
|
||||
|
@ -20,3 +24,61 @@ Referential::Referential(AvatarData* avatar) :
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Referential::Referential(const unsigned char*& sourceBuffer) :
|
||||
_isValid(false),
|
||||
_avatar(NULL)
|
||||
{
|
||||
sourceBuffer += unpack(sourceBuffer);
|
||||
}
|
||||
|
||||
Referential::~Referential() {
|
||||
}
|
||||
|
||||
int Referential::packReferential(unsigned char* destinationBuffer) {
|
||||
const unsigned char* startPosition = destinationBuffer;
|
||||
destinationBuffer += pack(destinationBuffer);
|
||||
destinationBuffer += packExtraData(destinationBuffer);
|
||||
return destinationBuffer - startPosition;
|
||||
}
|
||||
|
||||
int Referential::unpackReferential(const unsigned char* sourceBuffer) {
|
||||
const unsigned char* startPosition = sourceBuffer;
|
||||
sourceBuffer += unpack(sourceBuffer);
|
||||
sourceBuffer += unpackExtraData(sourceBuffer);
|
||||
return sourceBuffer - startPosition;
|
||||
}
|
||||
|
||||
int Referential::unpackExtraData(const unsigned char* sourceBuffer) {
|
||||
const unsigned char* startPosition = sourceBuffer;
|
||||
int size = *sourceBuffer++;
|
||||
_extraDataBuffer.clear();
|
||||
_extraDataBuffer.setRawData(reinterpret_cast<const char*>(sourceBuffer), size);
|
||||
sourceBuffer += size;
|
||||
return sourceBuffer - startPosition;
|
||||
}
|
||||
|
||||
int Referential::pack(unsigned char* destinationBuffer) {
|
||||
unsigned char* startPosition = destinationBuffer;
|
||||
*destinationBuffer++ = (unsigned char)_type;
|
||||
memcpy(destinationBuffer, &_createdAt, sizeof(_createdAt));
|
||||
|
||||
destinationBuffer += packFloatVec3ToSignedTwoByteFixed(destinationBuffer, _translation, 0);
|
||||
destinationBuffer += packOrientationQuatToBytes(destinationBuffer, _rotation);
|
||||
destinationBuffer += packFloatScalarToSignedTwoByteFixed(destinationBuffer, _scale, 0);
|
||||
return destinationBuffer - startPosition;
|
||||
}
|
||||
|
||||
int Referential::unpack(const unsigned char* sourceBuffer) {
|
||||
const unsigned char* startPosition = sourceBuffer;
|
||||
_type = (Type)*sourceBuffer++;
|
||||
memcpy(&_createdAt, sourceBuffer, sizeof(_createdAt));
|
||||
sourceBuffer += sizeof(_createdAt);
|
||||
|
||||
sourceBuffer += unpackFloatVec3FromSignedTwoByteFixed(sourceBuffer, _translation, 0);
|
||||
sourceBuffer += unpackOrientationQuatFromBytes(sourceBuffer, _rotation);
|
||||
sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*)sourceBuffer, &_scale, 0);
|
||||
return sourceBuffer - startPosition;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,16 +19,36 @@ class AvatarData;
|
|||
|
||||
class Referential {
|
||||
public:
|
||||
enum Type {
|
||||
MODEL,
|
||||
JOINT,
|
||||
AVATAR
|
||||
};
|
||||
|
||||
Referential(const unsigned char*& sourceBuffer);
|
||||
virtual ~Referential();
|
||||
|
||||
virtual bool isValid() { return _isValid; }
|
||||
virtual void update() = 0;
|
||||
Type type() { return _type; }
|
||||
quint64 createdAt() { return _createdAt; }
|
||||
bool isValid() { return _isValid; }
|
||||
|
||||
virtual void update() {}
|
||||
int packReferential(unsigned char* destinationBuffer);
|
||||
int unpackReferential(const unsigned char* sourceBuffer);
|
||||
|
||||
protected:
|
||||
Referential(AvatarData* avatar);
|
||||
Referential(Type type, AvatarData* avatar);
|
||||
|
||||
int pack(unsigned char* destinationBuffer);
|
||||
int unpack(const unsigned char* sourceBuffer);
|
||||
int packExtraData(unsigned char* destinationBuffer) { return 0; }
|
||||
int unpackExtraData(const unsigned char* sourceBuffer);
|
||||
|
||||
Type _type;
|
||||
quint64 _createdAt;
|
||||
bool _isValid;
|
||||
AvatarData* _avatar;
|
||||
QByteArray _extraDataBuffer;
|
||||
|
||||
glm::vec3 _refPosition;
|
||||
glm::quat _refRotation;
|
||||
|
|
Loading…
Reference in a new issue