mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
more work, cleanup names, remove translation use snap to center
This commit is contained in:
parent
293963c546
commit
f7da070d77
7 changed files with 37 additions and 98 deletions
|
@ -82,6 +82,15 @@ void Model::setScaleInternal(const glm::vec3& scale) {
|
|||
}
|
||||
}
|
||||
|
||||
void Model::setOffset(const glm::vec3& offset) {
|
||||
_offset = offset;
|
||||
|
||||
// if someone manually sets our offset, then we are no longer snapped to center
|
||||
_snapModelToCenter = false;
|
||||
_snappedToCenter = false;
|
||||
}
|
||||
|
||||
|
||||
void Model::initSkinProgram(ProgramObject& program, Model::SkinLocations& locations) {
|
||||
program.bind();
|
||||
locations.clusterMatrices = program.uniformLocation("clusterMatrices");
|
||||
|
@ -836,7 +845,7 @@ void Model::snapToCenter() {
|
|||
}
|
||||
|
||||
void Model::simulate(float deltaTime, bool fullUpdate) {
|
||||
fullUpdate = updateGeometry() || fullUpdate || (_scaleToFit && !_scaledToFit);
|
||||
fullUpdate = updateGeometry() || fullUpdate || (_scaleToFit && !_scaledToFit) || (_snapModelToCenter && !_snappedToCenter);
|
||||
if (isActive() && fullUpdate) {
|
||||
// check for scale to fit
|
||||
if (_scaleToFit && !_scaledToFit) {
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
void setScale(const glm::vec3& scale);
|
||||
const glm::vec3& getScale() const { return _scale; }
|
||||
|
||||
void setOffset(const glm::vec3& offset) { _offset = offset; _snapModelToCenter = false; _snappedToCenter = false; }
|
||||
void setOffset(const glm::vec3& offset);
|
||||
const glm::vec3& getOffset() const { return _offset; }
|
||||
|
||||
void setPupilDilation(float dilation) { _pupilDilation = dilation; }
|
||||
|
@ -224,7 +224,7 @@ protected:
|
|||
bool _scaledToFit; /// have we scaled to fit
|
||||
|
||||
bool _snapModelToCenter; /// is the model's offset automatically adjusted to center around 0,0,0 in model space
|
||||
bool _snappedToCenter;
|
||||
bool _snappedToCenter; /// are we currently snapped to center
|
||||
|
||||
class JointState {
|
||||
public:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// ModelEditPacketSender.cpp
|
||||
// libraries/particles/src
|
||||
// libraries/models/src
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 8/12/13.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// ModelEditPacketSender.h
|
||||
// libraries/particles/src
|
||||
// libraries/models/src
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 8/12/13.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
|
@ -20,7 +20,7 @@
|
|||
class ModelEditPacketSender : public OctreeEditPacketSender {
|
||||
Q_OBJECT
|
||||
public:
|
||||
/// Send particle add message immediately
|
||||
/// Send model add message immediately
|
||||
/// NOTE: ModelItemProperties assumes that all distances are in meter units
|
||||
void sendEditModelMessage(PacketType type, ModelItemID modelID, const ModelItemProperties& properties);
|
||||
|
||||
|
@ -30,7 +30,7 @@ public:
|
|||
/// NOTE: ModelItemProperties assumes that all distances are in meter units
|
||||
void queueModelEditMessage(PacketType type, ModelItemID modelID, const ModelItemProperties& properties);
|
||||
|
||||
// My server type is the particle server
|
||||
// My server type is the model server
|
||||
virtual unsigned char getMyNodeType() const { return NodeType::ModelServer; }
|
||||
virtual void adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssize_t length, int clockSkew);
|
||||
};
|
||||
|
|
|
@ -84,7 +84,6 @@ ModelItem::ModelItem(const ModelItemID& modelItemID, const ModelItemProperties&
|
|||
memcpy(_color, noColor, sizeof(_color));
|
||||
_shouldDie = false;
|
||||
_modelURL = MODEL_DEFAULT_MODEL_URL;
|
||||
_modelTranslation = MODEL_DEFAULT_MODEL_TRANSLATION;
|
||||
_modelRotation = MODEL_DEFAULT_MODEL_ROTATION;
|
||||
|
||||
setProperties(properties);
|
||||
|
@ -110,7 +109,6 @@ void ModelItem::init(glm::vec3 position, float radius, rgbColor color, uint32_t
|
|||
memcpy(_color, color, sizeof(_color));
|
||||
_shouldDie = false;
|
||||
_modelURL = MODEL_DEFAULT_MODEL_URL;
|
||||
_modelTranslation = MODEL_DEFAULT_MODEL_TRANSLATION;
|
||||
_modelRotation = MODEL_DEFAULT_MODEL_ROTATION;
|
||||
}
|
||||
|
||||
|
@ -148,10 +146,6 @@ bool ModelItem::appendModelData(OctreePacketData* packetData) const {
|
|||
}
|
||||
}
|
||||
|
||||
// modelTranslation
|
||||
if (success) {
|
||||
success = packetData->appendValue(getModelTranslation());
|
||||
}
|
||||
// modelRotation
|
||||
if (success) {
|
||||
success = packetData->appendValue(getModelRotation());
|
||||
|
@ -225,11 +219,6 @@ int ModelItem::readModelDataFromBuffer(const unsigned char* data, int bytesLeftT
|
|||
dataAt += modelURLLength;
|
||||
bytesRead += modelURLLength;
|
||||
|
||||
// modelTranslation
|
||||
memcpy(&_modelTranslation, dataAt, sizeof(_modelTranslation));
|
||||
dataAt += sizeof(_modelTranslation);
|
||||
bytesRead += sizeof(_modelTranslation);
|
||||
|
||||
// modelRotation
|
||||
int bytes = unpackOrientationQuatFromBytes(dataAt, _modelRotation);
|
||||
dataAt += bytes;
|
||||
|
@ -350,13 +339,6 @@ ModelItem ModelItem::fromEditPacket(const unsigned char* data, int length, int&
|
|||
processedBytes += modelURLLength;
|
||||
}
|
||||
|
||||
// modelTranslation
|
||||
if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_MODEL_TRANSLATION) == MODEL_PACKET_CONTAINS_MODEL_TRANSLATION)) {
|
||||
memcpy(&newModelItem._modelTranslation, dataAt, sizeof(newModelItem._modelTranslation));
|
||||
dataAt += sizeof(newModelItem._modelTranslation);
|
||||
processedBytes += sizeof(newModelItem._modelTranslation);
|
||||
}
|
||||
|
||||
// modelRotation
|
||||
if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_MODEL_ROTATION) == MODEL_PACKET_CONTAINS_MODEL_ROTATION)) {
|
||||
int bytes = unpackOrientationQuatFromBytes(dataAt, newModelItem._modelRotation);
|
||||
|
@ -487,14 +469,6 @@ bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id
|
|||
sizeOut += urlLength;
|
||||
}
|
||||
|
||||
// modelTranslation
|
||||
if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_MODEL_TRANSLATION) == MODEL_PACKET_CONTAINS_MODEL_TRANSLATION)) {
|
||||
glm::vec3 modelTranslation = properties.getModelTranslation(); // should this be relative to TREE_SCALE??
|
||||
memcpy(copyAt, &modelTranslation, sizeof(modelTranslation));
|
||||
copyAt += sizeof(modelTranslation);
|
||||
sizeOut += sizeof(modelTranslation);
|
||||
}
|
||||
|
||||
// modelRotation
|
||||
if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_MODEL_ROTATION) == MODEL_PACKET_CONTAINS_MODEL_ROTATION)) {
|
||||
int bytes = packOrientationQuatToBytes(copyAt, properties.getModelRotation());
|
||||
|
@ -572,7 +546,6 @@ ModelItemProperties::ModelItemProperties() :
|
|||
_radius(MODEL_DEFAULT_RADIUS),
|
||||
_shouldDie(false),
|
||||
_modelURL(""),
|
||||
_modelTranslation(MODEL_DEFAULT_MODEL_TRANSLATION),
|
||||
_modelRotation(MODEL_DEFAULT_MODEL_ROTATION),
|
||||
|
||||
_id(UNKNOWN_MODEL_ID),
|
||||
|
@ -584,7 +557,6 @@ ModelItemProperties::ModelItemProperties() :
|
|||
_radiusChanged(false),
|
||||
_shouldDieChanged(false),
|
||||
_modelURLChanged(false),
|
||||
_modelTranslationChanged(false),
|
||||
_modelRotationChanged(false),
|
||||
_defaultSettings(true)
|
||||
{
|
||||
|
@ -613,10 +585,6 @@ uint16_t ModelItemProperties::getChangedBits() const {
|
|||
changedBits += MODEL_PACKET_CONTAINS_MODEL_URL;
|
||||
}
|
||||
|
||||
if (_modelTranslationChanged) {
|
||||
changedBits += MODEL_PACKET_CONTAINS_MODEL_TRANSLATION;
|
||||
}
|
||||
|
||||
if (_modelRotationChanged) {
|
||||
changedBits += MODEL_PACKET_CONTAINS_MODEL_ROTATION;
|
||||
}
|
||||
|
@ -640,9 +608,6 @@ QScriptValue ModelItemProperties::copyToScriptValue(QScriptEngine* engine) const
|
|||
|
||||
properties.setProperty("modelURL", _modelURL);
|
||||
|
||||
QScriptValue modelTranslation = vec3toScriptValue(engine, _modelTranslation);
|
||||
properties.setProperty("modelTranslation", modelTranslation);
|
||||
|
||||
QScriptValue modelRotation = quatToScriptValue(engine, _modelRotation);
|
||||
properties.setProperty("modelRotation", modelRotation);
|
||||
|
||||
|
@ -723,24 +688,6 @@ void ModelItemProperties::copyFromScriptValue(const QScriptValue &object) {
|
|||
}
|
||||
}
|
||||
|
||||
QScriptValue modelTranslation = object.property("modelTranslation");
|
||||
if (modelTranslation.isValid()) {
|
||||
QScriptValue x = modelTranslation.property("x");
|
||||
QScriptValue y = modelTranslation.property("y");
|
||||
QScriptValue z = modelTranslation.property("z");
|
||||
if (x.isValid() && y.isValid() && z.isValid()) {
|
||||
glm::vec3 newModelTranslation;
|
||||
newModelTranslation.x = x.toVariant().toFloat();
|
||||
newModelTranslation.y = y.toVariant().toFloat();
|
||||
newModelTranslation.z = z.toVariant().toFloat();
|
||||
if (_defaultSettings || newModelTranslation != _modelTranslation) {
|
||||
_modelTranslation = newModelTranslation;
|
||||
_modelTranslationChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QScriptValue modelRotation = object.property("modelRotation");
|
||||
if (modelRotation.isValid()) {
|
||||
QScriptValue x = modelRotation.property("x");
|
||||
|
@ -790,11 +737,6 @@ void ModelItemProperties::copyToModelItem(ModelItem& modelItem) const {
|
|||
somethingChanged = true;
|
||||
}
|
||||
|
||||
if (_modelTranslationChanged) {
|
||||
modelItem.setModelTranslation(_modelTranslation);
|
||||
somethingChanged = true;
|
||||
}
|
||||
|
||||
if (_modelRotationChanged) {
|
||||
modelItem.setModelRotation(_modelRotation);
|
||||
somethingChanged = true;
|
||||
|
@ -818,7 +760,6 @@ void ModelItemProperties::copyFromModelItem(const ModelItem& modelItem) {
|
|||
_radius = modelItem.getRadius() * (float) TREE_SCALE;
|
||||
_shouldDie = modelItem.getShouldDie();
|
||||
_modelURL = modelItem.getModelURL();
|
||||
_modelTranslation = modelItem.getModelTranslation();
|
||||
_modelRotation = modelItem.getModelRotation();
|
||||
|
||||
_id = modelItem.getID();
|
||||
|
@ -830,7 +771,6 @@ void ModelItemProperties::copyFromModelItem(const ModelItem& modelItem) {
|
|||
|
||||
_shouldDieChanged = false;
|
||||
_modelURLChanged = false;
|
||||
_modelTranslationChanged = false;
|
||||
_modelRotationChanged = false;
|
||||
_defaultSettings = false;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// ModelItem.h
|
||||
// libraries/particles/src
|
||||
// libraries/models/src
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 12/4/13.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
|
@ -41,18 +41,16 @@ const uint16_t MODEL_PACKET_CONTAINS_POSITION = 2;
|
|||
const uint16_t MODEL_PACKET_CONTAINS_COLOR = 4;
|
||||
const uint16_t MODEL_PACKET_CONTAINS_SHOULDDIE = 512;
|
||||
const uint16_t MODEL_PACKET_CONTAINS_MODEL_URL = 1024;
|
||||
const uint16_t MODEL_PACKET_CONTAINS_MODEL_TRANSLATION = 1024;
|
||||
const uint16_t MODEL_PACKET_CONTAINS_MODEL_ROTATION = 2048;
|
||||
|
||||
const float MODEL_DEFAULT_RADIUS = 0.1f / TREE_SCALE;
|
||||
const float MODEL_MINIMUM_PARTICLE_ELEMENT_SIZE = (1.0f / 100000.0f) / TREE_SCALE; // smallest size container
|
||||
const float MINIMUM_MODEL_ELEMENT_SIZE = (1.0f / 100000.0f) / TREE_SCALE; // smallest size container
|
||||
const QString MODEL_DEFAULT_MODEL_URL("");
|
||||
const glm::vec3 MODEL_DEFAULT_MODEL_TRANSLATION(0, 0, 0);
|
||||
const glm::quat MODEL_DEFAULT_MODEL_ROTATION(0, 0, 0, 0);
|
||||
|
||||
/// A collection of properties of a particle used in the scripting API. Translates between the actual properties of a particle
|
||||
/// A collection of properties of a model item used in the scripting API. Translates between the actual properties of a model
|
||||
/// and a JavaScript style hash/QScriptValue storing a set of properties. Used in scripting to set/get the complete set of
|
||||
/// particle properties via JavaScript hashes/QScriptValues
|
||||
/// model item properties via JavaScript hashes/QScriptValues
|
||||
/// all units for position, radius, etc are in meter units
|
||||
class ModelItemProperties {
|
||||
public:
|
||||
|
@ -61,8 +59,8 @@ public:
|
|||
QScriptValue copyToScriptValue(QScriptEngine* engine) const;
|
||||
void copyFromScriptValue(const QScriptValue& object);
|
||||
|
||||
void copyToModelItem(ModelItem& particle) const;
|
||||
void copyFromModelItem(const ModelItem& particle);
|
||||
void copyToModelItem(ModelItem& modelItem) const;
|
||||
void copyFromModelItem(const ModelItem& modelItem);
|
||||
|
||||
const glm::vec3& getPosition() const { return _position; }
|
||||
xColor getColor() const { return _color; }
|
||||
|
@ -70,7 +68,6 @@ public:
|
|||
bool getShouldDie() const { return _shouldDie; }
|
||||
|
||||
const QString& getModelURL() const { return _modelURL; }
|
||||
const glm::vec3& getModelTranslation() const { return _modelTranslation; }
|
||||
const glm::quat& getModelRotation() const { return _modelRotation; }
|
||||
|
||||
quint64 getLastEdited() const { return _lastEdited; }
|
||||
|
@ -84,11 +81,9 @@ public:
|
|||
|
||||
// model related properties
|
||||
void setModelURL(const QString& url) { _modelURL = url; _modelURLChanged = true; }
|
||||
void setModelTranslation(const glm::vec3& translation) { _modelTranslation = translation;
|
||||
_modelTranslationChanged = true; }
|
||||
void setModelRotation(const glm::quat& rotation) { _modelRotation = rotation; _modelRotationChanged = true; }
|
||||
|
||||
/// used by ModelScriptingInterface to return ModelItemProperties for unknown particles
|
||||
/// used by ModelScriptingInterface to return ModelItemProperties for unknown models
|
||||
void setIsUnknownID() { _id = UNKNOWN_MODEL_ID; _idSet = true; }
|
||||
|
||||
private:
|
||||
|
@ -98,7 +93,6 @@ private:
|
|||
bool _shouldDie; /// to delete it
|
||||
|
||||
QString _modelURL;
|
||||
glm::vec3 _modelTranslation;
|
||||
glm::quat _modelRotation;
|
||||
|
||||
uint32_t _id;
|
||||
|
@ -111,7 +105,6 @@ private:
|
|||
bool _shouldDieChanged;
|
||||
|
||||
bool _modelURLChanged;
|
||||
bool _modelTranslationChanged;
|
||||
bool _modelRotationChanged;
|
||||
bool _defaultSettings;
|
||||
};
|
||||
|
@ -120,9 +113,9 @@ QScriptValue ModelItemPropertiesToScriptValue(QScriptEngine* engine, const Model
|
|||
void ModelItemPropertiesFromScriptValue(const QScriptValue &object, ModelItemProperties& properties);
|
||||
|
||||
|
||||
/// Abstract ID for editing particles. Used in ModelItem JS API - When particles are created in the JS api, they are given a
|
||||
/// local creatorTokenID, the actual id for the particle is not known until the server responds to the creator with the
|
||||
/// correct mapping. This class works with the scripting API an allows the developer to edit particles they created.
|
||||
/// Abstract ID for editing model items. Used in ModelItem JS API - When models are created in the JS api, they are given a
|
||||
/// local creatorTokenID, the actual id for the model is not known until the server responds to the creator with the
|
||||
/// correct mapping. This class works with the scripting API an allows the developer to edit models they created.
|
||||
class ModelItemID {
|
||||
public:
|
||||
ModelItemID() :
|
||||
|
@ -146,15 +139,15 @@ void ModelItemIDfromScriptValue(const QScriptValue &object, ModelItemID& propert
|
|||
|
||||
|
||||
|
||||
/// ModelItem class - this is the actual particle class.
|
||||
/// ModelItem class - this is the actual model item class.
|
||||
class ModelItem {
|
||||
|
||||
public:
|
||||
ModelItem();
|
||||
|
||||
ModelItem(const ModelItemID& particleID, const ModelItemProperties& properties);
|
||||
ModelItem(const ModelItemID& modelItemID, const ModelItemProperties& properties);
|
||||
|
||||
/// creates an NEW particle from an PACKET_TYPE_PARTICLE_ADD_OR_EDIT edit data buffer
|
||||
/// creates an NEW model from an model add or edit message data buffer
|
||||
static ModelItem fromEditPacket(const unsigned char* data, int length, int& processedBytes, ModelTree* tree, bool& valid);
|
||||
|
||||
virtual ~ModelItem();
|
||||
|
@ -172,20 +165,19 @@ public:
|
|||
// model related properties
|
||||
bool hasModel() const { return !_modelURL.isEmpty(); }
|
||||
const QString& getModelURL() const { return _modelURL; }
|
||||
const glm::vec3& getModelTranslation() const { return _modelTranslation; }
|
||||
const glm::quat& getModelRotation() const { return _modelRotation; }
|
||||
|
||||
ModelItemID getModelItemID() const { return ModelItemID(getID(), getCreatorTokenID(), getID() != UNKNOWN_MODEL_ID); }
|
||||
ModelItemProperties getProperties() const;
|
||||
|
||||
/// The last updated/simulated time of this particle from the time perspective of the authoritative server/source
|
||||
/// The last updated/simulated time of this model from the time perspective of the authoritative server/source
|
||||
quint64 getLastUpdated() const { return _lastUpdated; }
|
||||
|
||||
/// The last edited time of this particle from the time perspective of the authoritative server/source
|
||||
/// The last edited time of this model from the time perspective of the authoritative server/source
|
||||
quint64 getLastEdited() const { return _lastEdited; }
|
||||
void setLastEdited(quint64 lastEdited) { _lastEdited = lastEdited; }
|
||||
|
||||
/// lifetime of the particle in seconds
|
||||
/// how long ago was this model edited in seconds
|
||||
float getEditedAgo() const { return static_cast<float>(usecTimestampNow() - _lastEdited) / static_cast<float>(USECS_PER_SECOND); }
|
||||
uint32_t getID() const { return _id; }
|
||||
void setID(uint32_t id) { _id = id; }
|
||||
|
@ -210,7 +202,6 @@ public:
|
|||
|
||||
// model related properties
|
||||
void setModelURL(const QString& url) { _modelURL = url; }
|
||||
void setModelTranslation(const glm::vec3& translation) { _modelTranslation = translation; }
|
||||
void setModelRotation(const glm::quat& rotation) { _modelRotation = rotation; }
|
||||
|
||||
void setProperties(const ModelItemProperties& properties);
|
||||
|
@ -231,7 +222,7 @@ public:
|
|||
// similar to assignment/copy, but it handles keeping lifetime accurate
|
||||
void copyChangedProperties(const ModelItem& other);
|
||||
|
||||
// these methods allow you to create particles, and later edit them.
|
||||
// these methods allow you to create models, and later edit them.
|
||||
static uint32_t getIDfromCreatorTokenID(uint32_t creatorTokenID);
|
||||
static uint32_t getNextCreatorTokenID();
|
||||
static void handleAddModelResponse(const QByteArray& packet);
|
||||
|
@ -246,7 +237,6 @@ protected:
|
|||
|
||||
// model related items
|
||||
QString _modelURL;
|
||||
glm::vec3 _modelTranslation;
|
||||
glm::quat _modelRotation;
|
||||
|
||||
uint32_t _creatorTokenID;
|
||||
|
|
|
@ -100,7 +100,7 @@ void ModelTree::storeModel(const ModelItem& model, const SharedNodePointer& send
|
|||
// if we didn't find it in the tree, then store it...
|
||||
if (!args.found) {
|
||||
glm::vec3 position = model.getPosition();
|
||||
float size = std::max(MODEL_MINIMUM_PARTICLE_ELEMENT_SIZE, model.getRadius());
|
||||
float size = std::max(MINIMUM_MODEL_ELEMENT_SIZE, model.getRadius());
|
||||
|
||||
ModelTreeElement* element = (ModelTreeElement*)getOrCreateChildElementAt(position.x, position.y, position.z, size);
|
||||
element->storeModel(model);
|
||||
|
@ -150,7 +150,7 @@ void ModelTree::addModel(const ModelItemID& modelID, const ModelItemProperties&
|
|||
}
|
||||
ModelItem model(modelID, properties);
|
||||
glm::vec3 position = model.getPosition();
|
||||
float size = std::max(MODEL_MINIMUM_PARTICLE_ELEMENT_SIZE, model.getRadius());
|
||||
float size = std::max(MINIMUM_MODEL_ELEMENT_SIZE, model.getRadius());
|
||||
|
||||
ModelTreeElement* element = (ModelTreeElement*)getOrCreateChildElementAt(position.x, position.y, position.z, size);
|
||||
element->storeModel(model);
|
||||
|
@ -403,8 +403,8 @@ int ModelTree::processEditPacketData(PacketType packetType, const unsigned char*
|
|||
}
|
||||
} break;
|
||||
|
||||
// TODO: wire in support here for server to get PACKET_TYPE_PARTICLE_ERASE messages
|
||||
// instead of using PACKET_TYPE_PARTICLE_ADD_OR_EDIT messages to delete models
|
||||
// TODO: wire in support here for server to get PacketTypeModelErase messages
|
||||
// instead of using PacketTypeModelAddOrEdit messages to delete models
|
||||
case PacketTypeModelErase:
|
||||
processedBytes = 0;
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue