mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-19 13:44:20 +02:00
Avatar Scripts
This commit is contained in:
parent
2cae294ab4
commit
165c3214a7
6 changed files with 67 additions and 1 deletions
|
@ -4724,6 +4724,35 @@ void Application::init() {
|
|||
avatar->setCollisionSound(sound);
|
||||
}
|
||||
}, Qt::QueuedConnection);
|
||||
|
||||
connect(getMyAvatar().get(), &MyAvatar::avatarScriptsNeedToLoad, this, [this]() {
|
||||
if (auto avatar = getMyAvatar()) {
|
||||
auto scripts = avatar->getSkeletonModel()->getFBXGeometry().scripts;
|
||||
if (scripts.size() > 0) {
|
||||
auto scriptEngines = DependencyManager::get<ScriptEngines>();
|
||||
auto runningScripts = scriptEngines->getRunningScripts();
|
||||
for (auto script : scripts) {
|
||||
int index = runningScripts.indexOf(script.toString());
|
||||
if (index < 0) {
|
||||
auto loaded = scriptEngines->loadScript(script);
|
||||
avatar->addScriptToUnload(script);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, Qt::QueuedConnection);
|
||||
|
||||
connect(getMyAvatar().get(), &MyAvatar::avatarScriptsNeedToUnload, this, [this]() {
|
||||
if (auto avatar = getMyAvatar()) {
|
||||
auto scripts = avatar->getScriptsToUnload();
|
||||
if (scripts.size() > 0) {
|
||||
auto scriptEngines = DependencyManager::get<ScriptEngines>();
|
||||
for (auto script : scripts) {
|
||||
scriptEngines->stopScript(script.toString(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void Application::updateLOD(float deltaTime) const {
|
||||
|
|
|
@ -121,6 +121,7 @@ MyAvatar::MyAvatar(QThread* thread) :
|
|||
|
||||
_skeletonModel = std::make_shared<MySkeletonModel>(this, nullptr);
|
||||
connect(_skeletonModel.get(), &Model::setURLFinished, this, &Avatar::setModelURLFinished);
|
||||
connect(_skeletonModel.get(), &Model::setURLFinished, this, &MyAvatar::setModelURLLoaded);
|
||||
connect(_skeletonModel.get(), &Model::rigReady, this, &Avatar::rigReady);
|
||||
connect(_skeletonModel.get(), &Model::rigReset, this, &Avatar::rigReset);
|
||||
|
||||
|
@ -1463,6 +1464,9 @@ void MyAvatar::clearJointsData() {
|
|||
}
|
||||
|
||||
void MyAvatar::setSkeletonModelURL(const QUrl& skeletonModelURL) {
|
||||
if (_scriptsToUnload.size() > 0) {
|
||||
emit avatarScriptsNeedToUnload();
|
||||
}
|
||||
_skeletonModelChangeCount++;
|
||||
int skeletonModelChangeCount = _skeletonModelChangeCount;
|
||||
Avatar::setSkeletonModelURL(skeletonModelURL);
|
||||
|
@ -2384,6 +2388,11 @@ void MyAvatar::restrictScaleFromDomainSettings(const QJsonObject& domainSettings
|
|||
settings.endGroup();
|
||||
}
|
||||
|
||||
void MyAvatar::setModelURLLoaded() {
|
||||
_scriptsToUnload.clear();
|
||||
emit avatarScriptsNeedToLoad();
|
||||
}
|
||||
|
||||
void MyAvatar::leaveDomain() {
|
||||
clearScaleRestriction();
|
||||
saveAvatarScale();
|
||||
|
@ -2831,6 +2840,10 @@ float MyAvatar::getWalkSpeed() const {
|
|||
return _walkSpeed.get() * _walkSpeedScalar;
|
||||
}
|
||||
|
||||
void MyAvatar::addScriptToUnload(QUrl& scriptUrl) {
|
||||
_scriptsToUnload.push_back(scriptUrl);
|
||||
}
|
||||
|
||||
void MyAvatar::setSprintMode(bool sprint) {
|
||||
_walkSpeedScalar = sprint ? AVATAR_SPRINT_SPEED_SCALAR : AVATAR_WALK_SPEED_SCALAR;
|
||||
}
|
||||
|
|
|
@ -594,6 +594,9 @@ public:
|
|||
void setWalkSpeed(float value);
|
||||
float getWalkSpeed() const;
|
||||
|
||||
void addScriptToUnload(QUrl& scriptUrl);
|
||||
const QVector<QUrl>& getScriptsToUnload() const { return _scriptsToUnload; };
|
||||
|
||||
public slots:
|
||||
void increaseSize();
|
||||
void decreaseSize();
|
||||
|
@ -659,10 +662,12 @@ signals:
|
|||
void sensorToWorldScaleChanged(float sensorToWorldScale);
|
||||
void attachmentsChanged();
|
||||
void scaleChanged();
|
||||
void avatarScriptsNeedToLoad();
|
||||
void avatarScriptsNeedToUnload();
|
||||
|
||||
private slots:
|
||||
void leaveDomain();
|
||||
|
||||
void setModelURLLoaded();
|
||||
|
||||
protected:
|
||||
virtual void beParentOfChild(SpatiallyNestablePointer newChild) const override;
|
||||
|
@ -905,6 +910,8 @@ private:
|
|||
// max unscaled forward movement speed
|
||||
ThreadSafeValueCache<float> _walkSpeed { DEFAULT_AVATAR_MAX_WALKING_SPEED };
|
||||
float _walkSpeedScalar { AVATAR_WALK_SPEED_SCALAR };
|
||||
|
||||
QVector<QUrl> _scriptsToUnload;
|
||||
};
|
||||
|
||||
QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode);
|
||||
|
|
|
@ -298,6 +298,7 @@ public:
|
|||
bool hasSkeletonJoints;
|
||||
|
||||
QVector<FBXMesh> meshes;
|
||||
QVector<QUrl> scripts;
|
||||
|
||||
QHash<QString, FBXMaterial> materials;
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ static const QString TRANSLATION_Z_FIELD = "tz";
|
|||
static const QString JOINT_FIELD = "joint";
|
||||
static const QString FREE_JOINT_FIELD = "freeJoint";
|
||||
static const QString BLENDSHAPE_FIELD = "bs";
|
||||
static const QString SCRIPT_FIELD = "script";
|
||||
|
||||
class FSTReader {
|
||||
public:
|
||||
|
|
|
@ -66,6 +66,7 @@ void GeometryMappingResource::downloadFinished(const QByteArray& data) {
|
|||
auto mapping = FSTReader::readMapping(data);
|
||||
|
||||
QString filename = mapping.value("filename").toString();
|
||||
|
||||
if (filename.isNull()) {
|
||||
qCDebug(modelnetworking) << "Mapping file" << _url << "has no \"filename\" field";
|
||||
finishedLoading(false);
|
||||
|
@ -209,6 +210,20 @@ void GeometryReader::run() {
|
|||
throw QString("unsupported format");
|
||||
}
|
||||
|
||||
if (_mapping.value("type").toString() == "body+head") {
|
||||
auto scripts = _mapping.value("script");
|
||||
if (!scripts.isNull()) {
|
||||
auto scriptsMap = scripts.toMap();
|
||||
auto count = scriptsMap.size();
|
||||
if (count > 0) {
|
||||
for (auto &key : scriptsMap.keys()) {
|
||||
auto scriptUrl = scriptsMap[key].toString();
|
||||
fbxGeometry->scripts.push_back(QUrl(scriptUrl));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the resource has not been deleted
|
||||
auto resource = _resource.toStrongRef();
|
||||
if (!resource) {
|
||||
|
|
Loading…
Reference in a new issue