Models.addModel now returns a more accurate modelID

This commit is contained in:
Atlante45 2014-06-05 15:47:25 -07:00
parent 0bdd20abc9
commit 150477eea4
3 changed files with 11 additions and 24 deletions

View file

@ -47,6 +47,12 @@ uint32_t ModelItem::getNextCreatorTokenID() {
return creatorTokenID; return creatorTokenID;
} }
uint32_t ModelItem::getNextModelItemID() {
uint32_t modelID = _nextID;
_nextID++;
return modelID;
}
void ModelItem::handleAddModelResponse(const QByteArray& packet) { void ModelItem::handleAddModelResponse(const QByteArray& packet) {
const unsigned char* dataAt = reinterpret_cast<const unsigned char*>(packet.data()); const unsigned char* dataAt = reinterpret_cast<const unsigned char*>(packet.data());
int numBytesPacketHeader = numBytesForPacketHeader(packet); int numBytesPacketHeader = numBytesForPacketHeader(packet);
@ -70,31 +76,10 @@ ModelItem::ModelItem() {
} }
ModelItem::ModelItem(const ModelItemID& modelItemID, const ModelItemProperties& properties) { ModelItem::ModelItem(const ModelItemID& modelItemID, const ModelItemProperties& properties) {
_id = modelItemID.id;
_creatorTokenID = modelItemID.creatorTokenID; _creatorTokenID = modelItemID.creatorTokenID;
// init values with defaults before calling setProperties
uint64_t now = usecTimestampNow();
_lastEdited = now;
_lastUpdated = now;
_position = glm::vec3(0,0,0);
_radius = 0;
rgbColor noColor = { 0, 0, 0 };
memcpy(_color, noColor, sizeof(_color));
_shouldDie = false;
_modelURL = MODEL_DEFAULT_MODEL_URL;
_modelRotation = MODEL_DEFAULT_MODEL_ROTATION;
// animation related rgbColor defaultColor = { 0, 0, 0 };
_animationURL = MODEL_DEFAULT_ANIMATION_URL; init(glm::vec3(), 0.0f, defaultColor, modelItemID.id);
_animationIsPlaying = false;
_animationFrameIndex = 0.0f;
_animationFPS = MODEL_DEFAULT_ANIMATION_FPS;
_glowLevel = 0.0f;
_jointMappingCompleted = false;
_lastAnimated = now;
setProperties(properties); setProperties(properties);
} }

View file

@ -276,6 +276,7 @@ public:
// these methods allow you to create models, 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 getIDfromCreatorTokenID(uint32_t creatorTokenID);
static uint32_t getNextCreatorTokenID(); static uint32_t getNextCreatorTokenID();
static uint32_t getNextModelItemID();
static void handleAddModelResponse(const QByteArray& packet); static void handleAddModelResponse(const QByteArray& packet);
void mapJoints(const QStringList& modelJointNames); void mapJoints(const QStringList& modelJointNames);

View file

@ -28,8 +28,9 @@ ModelItemID ModelsScriptingInterface::addModel(const ModelItemProperties& proper
// The application will keep track of creatorTokenID // The application will keep track of creatorTokenID
uint32_t creatorTokenID = ModelItem::getNextCreatorTokenID(); uint32_t creatorTokenID = ModelItem::getNextCreatorTokenID();
uint32_t modelID = ModelItem::getNextModelItemID();
ModelItemID id(NEW_MODEL, creatorTokenID, false ); ModelItemID id(modelID, creatorTokenID, false );
// queue the packet // queue the packet
queueModelMessage(PacketTypeModelAddOrEdit, id, properties); queueModelMessage(PacketTypeModelAddOrEdit, id, properties);