mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 14:03:55 +02:00
move modelScale before translation and rotation since that seems to fix the corruption
This commit is contained in:
parent
305e34e834
commit
a35e5eeb92
2 changed files with 59 additions and 58 deletions
|
@ -190,6 +190,12 @@ bool Particle::appendParticleData(OctreePacketData* packetData) const {
|
|||
success = packetData->appendRawData((const unsigned char*)qPrintable(_modelURL), modelURLLength);
|
||||
}
|
||||
}
|
||||
|
||||
// modelScale
|
||||
if (success) {
|
||||
success = packetData->appendValue(getModelScale());
|
||||
}
|
||||
|
||||
// modelTranslation
|
||||
if (success) {
|
||||
success = packetData->appendValue(getModelTranslation());
|
||||
|
@ -198,11 +204,6 @@ bool Particle::appendParticleData(OctreePacketData* packetData) const {
|
|||
if (success) {
|
||||
success = packetData->appendValue(getModelRotation());
|
||||
}
|
||||
// modelScale
|
||||
if (success) {
|
||||
success = packetData->appendValue(getModelScale());
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -319,6 +320,11 @@ int Particle::readParticleDataFromBuffer(const unsigned char* data, int bytesLef
|
|||
dataAt += modelURLLength;
|
||||
bytesRead += modelURLLength;
|
||||
|
||||
// modelScale
|
||||
memcpy(&_modelScale, dataAt, sizeof(_modelScale));
|
||||
dataAt += sizeof(_modelScale);
|
||||
bytesRead += sizeof(_modelScale);
|
||||
|
||||
// modelTranslation
|
||||
memcpy(&_modelTranslation, dataAt, sizeof(_modelTranslation));
|
||||
dataAt += sizeof(_modelTranslation);
|
||||
|
@ -329,11 +335,6 @@ int Particle::readParticleDataFromBuffer(const unsigned char* data, int bytesLef
|
|||
dataAt += bytes;
|
||||
bytesRead += bytes;
|
||||
|
||||
// modelScale
|
||||
memcpy(&_modelScale, dataAt, sizeof(_modelScale));
|
||||
dataAt += sizeof(_modelScale);
|
||||
bytesRead += sizeof(_modelScale);
|
||||
|
||||
//printf("Particle::readParticleDataFromBuffer()... "); debugDump();
|
||||
}
|
||||
return bytesRead;
|
||||
|
@ -498,6 +499,13 @@ Particle Particle::fromEditPacket(const unsigned char* data, int length, int& pr
|
|||
processedBytes += modelURLLength;
|
||||
}
|
||||
|
||||
// modelScale
|
||||
if (isNewParticle || ((packetContainsBits & CONTAINS_MODEL_SCALE) == CONTAINS_MODEL_SCALE)) {
|
||||
memcpy(&newParticle._modelScale, dataAt, sizeof(newParticle._modelScale));
|
||||
dataAt += sizeof(newParticle._modelScale);
|
||||
processedBytes += sizeof(newParticle._modelScale);
|
||||
}
|
||||
|
||||
// modelTranslation
|
||||
if (isNewParticle || ((packetContainsBits & CONTAINS_MODEL_TRANSLATION) == CONTAINS_MODEL_TRANSLATION)) {
|
||||
memcpy(&newParticle._modelTranslation, dataAt, sizeof(newParticle._modelTranslation));
|
||||
|
@ -512,13 +520,6 @@ Particle Particle::fromEditPacket(const unsigned char* data, int length, int& pr
|
|||
processedBytes += bytes;
|
||||
}
|
||||
|
||||
// modelScale
|
||||
if (isNewParticle || ((packetContainsBits & CONTAINS_MODEL_SCALE) == CONTAINS_MODEL_SCALE)) {
|
||||
memcpy(&newParticle._modelScale, dataAt, sizeof(newParticle._modelScale));
|
||||
dataAt += sizeof(newParticle._modelScale);
|
||||
processedBytes += sizeof(newParticle._modelScale);
|
||||
}
|
||||
|
||||
const bool wantDebugging = false;
|
||||
if (wantDebugging) {
|
||||
qDebug("Particle::fromEditPacket()...");
|
||||
|
@ -696,6 +697,14 @@ bool Particle::encodeParticleEditMessageDetails(PacketType command, ParticleID i
|
|||
sizeOut += urlLength;
|
||||
}
|
||||
|
||||
// modelScale
|
||||
if (isNewParticle || ((packetContainsBits & CONTAINS_MODEL_SCALE) == CONTAINS_MODEL_SCALE)) {
|
||||
float modelScale = properties.getModelScale();
|
||||
memcpy(copyAt, &modelScale, sizeof(modelScale));
|
||||
copyAt += sizeof(modelScale);
|
||||
sizeOut += sizeof(modelScale);
|
||||
}
|
||||
|
||||
// modelTranslation
|
||||
if (isNewParticle || ((packetContainsBits & CONTAINS_MODEL_TRANSLATION) == CONTAINS_MODEL_TRANSLATION)) {
|
||||
glm::vec3 modelTranslation = properties.getModelTranslation(); // should this be relative to TREE_SCALE??
|
||||
|
@ -711,14 +720,6 @@ bool Particle::encodeParticleEditMessageDetails(PacketType command, ParticleID i
|
|||
sizeOut += bytes;
|
||||
}
|
||||
|
||||
// modelScale
|
||||
if (isNewParticle || ((packetContainsBits & CONTAINS_MODEL_SCALE) == CONTAINS_MODEL_SCALE)) {
|
||||
float modelScale = properties.getModelScale();
|
||||
memcpy(copyAt, &modelScale, sizeof(modelScale));
|
||||
copyAt += sizeof(modelScale);
|
||||
sizeOut += sizeof(modelScale);
|
||||
}
|
||||
|
||||
bool wantDebugging = false;
|
||||
if (wantDebugging) {
|
||||
printf("encodeParticleEditMessageDetails()....\n");
|
||||
|
@ -931,9 +932,9 @@ ParticleProperties::ParticleProperties() :
|
|||
_inHand(false),
|
||||
_shouldDie(false),
|
||||
_modelURL(""),
|
||||
_modelScale(DEFAULT_MODEL_SCALE),
|
||||
_modelTranslation(DEFAULT_MODEL_TRANSLATION),
|
||||
_modelRotation(DEFAULT_MODEL_ROTATION),
|
||||
_modelScale(DEFAULT_MODEL_SCALE),
|
||||
|
||||
_id(UNKNOWN_PARTICLE_ID),
|
||||
_idSet(false),
|
||||
|
@ -950,9 +951,9 @@ ParticleProperties::ParticleProperties() :
|
|||
_inHandChanged(false),
|
||||
_shouldDieChanged(false),
|
||||
_modelURLChanged(false),
|
||||
_modelScaleChanged(false),
|
||||
_modelTranslationChanged(false),
|
||||
_modelRotationChanged(false),
|
||||
_modelScaleChanged(false),
|
||||
_defaultSettings(true)
|
||||
{
|
||||
}
|
||||
|
@ -1004,6 +1005,10 @@ uint16_t ParticleProperties::getChangedBits() const {
|
|||
changedBits += CONTAINS_MODEL_URL;
|
||||
}
|
||||
|
||||
if (_modelScaleChanged) {
|
||||
changedBits += CONTAINS_MODEL_SCALE;
|
||||
}
|
||||
|
||||
if (_modelTranslationChanged) {
|
||||
changedBits += CONTAINS_MODEL_TRANSLATION;
|
||||
}
|
||||
|
@ -1012,10 +1017,6 @@ uint16_t ParticleProperties::getChangedBits() const {
|
|||
changedBits += CONTAINS_MODEL_ROTATION;
|
||||
}
|
||||
|
||||
if (_modelScaleChanged) {
|
||||
changedBits += CONTAINS_MODEL_SCALE;
|
||||
}
|
||||
|
||||
return changedBits;
|
||||
}
|
||||
|
||||
|
@ -1045,14 +1046,14 @@ QScriptValue ParticleProperties::copyToScriptValue(QScriptEngine* engine) const
|
|||
|
||||
properties.setProperty("modelURL", _modelURL);
|
||||
|
||||
properties.setProperty("modelScale", _modelScale);
|
||||
|
||||
QScriptValue modelTranslation = vec3toScriptValue(engine, _modelTranslation);
|
||||
properties.setProperty("modelTranslation", modelTranslation);
|
||||
|
||||
QScriptValue modelRotation = quatToScriptValue(engine, _modelRotation);
|
||||
properties.setProperty("modelRotation", modelRotation);
|
||||
|
||||
properties.setProperty("modelScale", _modelScale);
|
||||
|
||||
|
||||
if (_idSet) {
|
||||
properties.setProperty("id", _id);
|
||||
|
@ -1203,7 +1204,17 @@ void ParticleProperties::copyFromScriptValue(const QScriptValue &object) {
|
|||
_modelURLChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QScriptValue modelScale = object.property("modelScale");
|
||||
if (modelScale.isValid()) {
|
||||
float newModelScale;
|
||||
newModelScale = modelScale.toVariant().toFloat();
|
||||
if (_defaultSettings || newModelScale != _modelScale) {
|
||||
_modelScale = newModelScale;
|
||||
_modelScaleChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue modelTranslation = object.property("modelTranslation");
|
||||
if (modelTranslation.isValid()) {
|
||||
QScriptValue x = modelTranslation.property("x");
|
||||
|
@ -1241,16 +1252,6 @@ void ParticleProperties::copyFromScriptValue(const QScriptValue &object) {
|
|||
}
|
||||
}
|
||||
|
||||
QScriptValue modelScale = object.property("modelScale");
|
||||
if (modelScale.isValid()) {
|
||||
float newModelScale;
|
||||
newModelScale = modelScale.toVariant().toFloat();
|
||||
if (_defaultSettings || newModelScale != _modelScale) {
|
||||
_modelScale = newModelScale;
|
||||
_modelScaleChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
_lastEdited = usecTimestampNow();
|
||||
}
|
||||
|
||||
|
@ -1310,6 +1311,11 @@ void ParticleProperties::copyToParticle(Particle& particle) const {
|
|||
particle.setModelURL(_modelURL);
|
||||
somethingChanged = true;
|
||||
}
|
||||
|
||||
if (_modelScaleChanged) {
|
||||
particle.setModelScale(_modelScale);
|
||||
somethingChanged = true;
|
||||
}
|
||||
|
||||
if (_modelTranslationChanged) {
|
||||
particle.setModelTranslation(_modelTranslation);
|
||||
|
@ -1321,11 +1327,6 @@ void ParticleProperties::copyToParticle(Particle& particle) const {
|
|||
somethingChanged = true;
|
||||
}
|
||||
|
||||
if (_modelScaleChanged) {
|
||||
particle.setModelScale(_modelScale);
|
||||
somethingChanged = true;
|
||||
}
|
||||
|
||||
if (somethingChanged) {
|
||||
bool wantDebug = false;
|
||||
if (wantDebug) {
|
||||
|
@ -1350,9 +1351,9 @@ void ParticleProperties::copyFromParticle(const Particle& particle) {
|
|||
_inHand = particle.getInHand();
|
||||
_shouldDie = particle.getShouldDie();
|
||||
_modelURL = particle.getModelURL();
|
||||
_modelScale = particle.getModelScale();
|
||||
_modelTranslation = particle.getModelTranslation();
|
||||
_modelRotation = particle.getModelRotation();
|
||||
_modelScale = particle.getModelScale();
|
||||
|
||||
_id = particle.getID();
|
||||
_idSet = true;
|
||||
|
@ -1368,9 +1369,9 @@ void ParticleProperties::copyFromParticle(const Particle& particle) {
|
|||
_inHandChanged = false;
|
||||
_shouldDieChanged = false;
|
||||
_modelURLChanged = false;
|
||||
_modelScaleChanged = false;
|
||||
_modelTranslationChanged = false;
|
||||
_modelRotationChanged = false;
|
||||
_modelScaleChanged = false;
|
||||
_defaultSettings = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,9 +88,9 @@ public:
|
|||
bool getInHand() const { return _inHand; }
|
||||
bool getShouldDie() const { return _shouldDie; }
|
||||
const QString& getModelURL() const { return _modelURL; }
|
||||
float getModelScale() const { return _modelScale; }
|
||||
const glm::vec3& getModelTranslation() const { return _modelTranslation; }
|
||||
const glm::quat& getModelRotation() const { return _modelRotation; }
|
||||
float getModelScale() const { return _modelScale; }
|
||||
|
||||
quint64 getLastEdited() const { return _lastEdited; }
|
||||
uint16_t getChangedBits() const;
|
||||
|
@ -113,10 +113,10 @@ public:
|
|||
|
||||
// model related properties
|
||||
void setModelURL(const QString& url) { _modelURL = url; _modelURLChanged = true; }
|
||||
void setModelScale(float scale) { _modelScale = scale; _modelScaleChanged = true; }
|
||||
void setModelTranslation(const glm::vec3& translation) { _modelTranslation = translation;
|
||||
_modelTranslationChanged = true; }
|
||||
void setModelRotation(const glm::quat& rotation) { _modelRotation = rotation; _modelRotationChanged = true; }
|
||||
void setModelScale(float scale) { _modelScale = scale; _modelScaleChanged = true; }
|
||||
|
||||
/// used by ParticleScriptingInterface to return ParticleProperties for unknown particles
|
||||
void setIsUnknownID() { _id = UNKNOWN_PARTICLE_ID; _idSet = true; }
|
||||
|
@ -133,9 +133,9 @@ private:
|
|||
bool _inHand;
|
||||
bool _shouldDie;
|
||||
QString _modelURL;
|
||||
float _modelScale;
|
||||
glm::vec3 _modelTranslation;
|
||||
glm::quat _modelRotation;
|
||||
float _modelScale;
|
||||
|
||||
uint32_t _id;
|
||||
bool _idSet;
|
||||
|
@ -152,9 +152,9 @@ private:
|
|||
bool _inHandChanged;
|
||||
bool _shouldDieChanged;
|
||||
bool _modelURLChanged;
|
||||
bool _modelScaleChanged;
|
||||
bool _modelTranslationChanged;
|
||||
bool _modelRotationChanged;
|
||||
bool _modelScaleChanged;
|
||||
bool _defaultSettings;
|
||||
};
|
||||
Q_DECLARE_METATYPE(ParticleProperties);
|
||||
|
@ -227,9 +227,9 @@ public:
|
|||
// model related properties
|
||||
bool hasModel() const { return !_modelURL.isEmpty(); }
|
||||
const QString& getModelURL() const { return _modelURL; }
|
||||
float getModelScale() const { return _modelScale; }
|
||||
const glm::vec3& getModelTranslation() const { return _modelTranslation; }
|
||||
const glm::quat& getModelRotation() const { return _modelRotation; }
|
||||
float getModelScale() const { return _modelScale; }
|
||||
|
||||
ParticleID getParticleID() const { return ParticleID(getID(), getCreatorTokenID(), getID() != UNKNOWN_PARTICLE_ID); }
|
||||
ParticleProperties getProperties() const;
|
||||
|
@ -277,9 +277,9 @@ public:
|
|||
|
||||
// model related properties
|
||||
void setModelURL(const QString& url) { _modelURL = url; }
|
||||
void setModelScale(float scale) { _modelScale = scale; }
|
||||
void setModelTranslation(const glm::vec3& translation) { _modelTranslation = translation; }
|
||||
void setModelRotation(const glm::quat& rotation) { _modelRotation = rotation; }
|
||||
void setModelScale(float scale) { _modelScale = scale; }
|
||||
|
||||
void setProperties(const ParticleProperties& properties);
|
||||
|
||||
|
@ -344,9 +344,9 @@ protected:
|
|||
|
||||
// model related items
|
||||
QString _modelURL;
|
||||
float _modelScale;
|
||||
glm::vec3 _modelTranslation;
|
||||
glm::quat _modelRotation;
|
||||
float _modelScale;
|
||||
|
||||
uint32_t _creatorTokenID;
|
||||
bool _newlyCreated;
|
||||
|
|
Loading…
Reference in a new issue