more model naming cleanup and fixing example scripts

This commit is contained in:
ZappoMan 2014-09-03 18:32:44 -07:00
parent 5b8be780a7
commit 3e1401014d
4 changed files with 39 additions and 38 deletions

View file

@ -21,6 +21,7 @@ var roll = 0.0;
var rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll) var rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll)
var originalProperties = { var originalProperties = {
type: "Model",
position: { x: MyAvatar.position.x, position: { x: MyAvatar.position.x,
y: MyAvatar.position.y, y: MyAvatar.position.y,
z: MyAvatar.position.z }, z: MyAvatar.position.z },
@ -37,8 +38,8 @@ var originalProperties = {
animationIsPlaying: true, animationIsPlaying: true,
}; };
var modelID = Models.addModel(originalProperties); var modelID = Entities.addEntity(originalProperties);
print("Models.addModel()... modelID.creatorTokenID = " + modelID.creatorTokenID); print("Entities.addEntity()... modelID.creatorTokenID = " + modelID.creatorTokenID);
var isPlaying = true; var isPlaying = true;
var playPauseEveryWhile = 360; var playPauseEveryWhile = 360;
@ -48,6 +49,7 @@ var resetFrameEveryWhile = 600;
function moveModel(deltaTime) { function moveModel(deltaTime) {
var somethingChanged = false; var somethingChanged = false;
print("count= " + count);
if (count % playPauseEveryWhile == 0) { if (count % playPauseEveryWhile == 0) {
isPlaying = !isPlaying; isPlaying = !isPlaying;
print("isPlaying=" + isPlaying); print("isPlaying=" + isPlaying);
@ -56,11 +58,11 @@ function moveModel(deltaTime) {
if (count % adjustFPSEveryWhile == 0) { if (count % adjustFPSEveryWhile == 0) {
if (animationFPS == 30) { if (animationFPS == 30) {
animationFPS = 30;
} else if (animationFPS == 10) {
animationFPS = 10; animationFPS = 10;
} else if (animationFPS == 60) { } else if (animationFPS == 10) {
animationFPS = 60; animationFPS = 60;
} else if (animationFPS == 60) {
animationFPS = 30;
} }
print("animationFPS=" + animationFPS); print("animationFPS=" + animationFPS);
isPlaying = true; isPlaying = true;
@ -78,7 +80,7 @@ function moveModel(deltaTime) {
// delete it... // delete it...
if (count == moveUntil) { if (count == moveUntil) {
print("calling Models.deleteModel()"); print("calling Models.deleteModel()");
Models.deleteModel(modelID); Entities.deleteEntity(modelID);
} }
// stop it... // stop it...
@ -107,7 +109,7 @@ function moveModel(deltaTime) {
resetFrame = false; resetFrame = false;
} }
Models.editModel(modelID, newProperties); Entities.editEntity(modelID, newProperties);
} }
} }

View file

@ -205,7 +205,7 @@ function mousePressEvent(event) {
// Compute trajectories related values // Compute trajectories related values
var pickRay = Camera.computePickRay(mouseLastX, mouseLastY); var pickRay = Camera.computePickRay(mouseLastX, mouseLastY);
var voxelIntersection = Voxels.findRayIntersection(pickRay); var voxelIntersection = Voxels.findRayIntersection(pickRay);
var modelIntersection = Models.findRayIntersection(pickRay); var modelIntersection = Entities.findRayIntersection(pickRay);
position = Camera.getPosition(); position = Camera.getPosition();
@ -218,7 +218,7 @@ function mousePressEvent(event) {
if (modelIntersection.intersects && modelIntersection.accurate) { if (modelIntersection.intersects && modelIntersection.accurate) {
distance = modelIntersection.distance; distance = modelIntersection.distance;
center = modelIntersection.modelProperties.position; center = modelIntersection.properties.position;
string = "Inspecting model"; string = "Inspecting model";
} }

View file

@ -42,16 +42,16 @@ function mouseMoveEvent(event) {
print("voxelAt.red/green/blue=" + voxelAt.red + ", " + voxelAt.green + ", " + voxelAt.blue); print("voxelAt.red/green/blue=" + voxelAt.red + ", " + voxelAt.green + ", " + voxelAt.blue);
} }
intersection = Models.findRayIntersection(pickRay); intersection = Entities.findRayIntersection(pickRay);
if (!intersection.accurate) { if (!intersection.accurate) {
print(">>> NOTE: intersection not accurate. will try calling Models.findRayIntersectionBlocking()"); print(">>> NOTE: intersection not accurate. will try calling Entities.findRayIntersectionBlocking()");
intersection = Models.findRayIntersectionBlocking(pickRay); intersection = Entities.findRayIntersectionBlocking(pickRay);
print(">>> AFTER BLOCKING CALL intersection.accurate=" + intersection.accurate); print(">>> AFTER BLOCKING CALL intersection.accurate=" + intersection.accurate);
} }
if (intersection.intersects) { if (intersection.intersects) {
print("intersection modelID.id=" + intersection.modelID.id); print("intersection entityID.id=" + intersection.entityID.id);
print("intersection modelProperties.modelURL=" + intersection.modelProperties.modelURL); print("intersection properties.modelURL=" + intersection.properties.modelURL);
print("intersection face=" + intersection.face); print("intersection face=" + intersection.face);
print("intersection distance=" + intersection.distance); print("intersection distance=" + intersection.distance);
print("intersection intersection.x/y/z=" + intersection.intersection.x + ", " print("intersection intersection.x/y/z=" + intersection.intersection.x + ", "

View file

@ -1,6 +1,6 @@
// //
// EntityScriptingInterface.cpp // EntityScriptingInterface.cpp
// libraries/models/src // libraries/entities/src
// //
// Created by Brad Hefta-Gaub on 12/6/13. // Created by Brad Hefta-Gaub on 12/6/13.
// Copyright 2013 High Fidelity, Inc. // Copyright 2013 High Fidelity, Inc.
@ -19,7 +19,6 @@ EntityScriptingInterface::EntityScriptingInterface() :
{ {
} }
void EntityScriptingInterface::queueEntityMessage(PacketType packetType, void EntityScriptingInterface::queueEntityMessage(PacketType packetType,
EntityItemID entityID, const EntityItemProperties& properties) { EntityItemID entityID, const EntityItemProperties& properties) {
getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties); getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties);
@ -35,7 +34,7 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro
// queue the packet // queue the packet
queueEntityMessage(PacketTypeEntityAddOrEdit, id, properties); queueEntityMessage(PacketTypeEntityAddOrEdit, id, properties);
// If we have a local model tree set, then also update it. // If we have a local entity tree set, then also update it.
if (_entityTree) { if (_entityTree) {
_entityTree->lockForWrite(); _entityTree->lockForWrite();
_entityTree->addEntity(id, properties); _entityTree->addEntity(id, properties);
@ -93,20 +92,20 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID
EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const EntityItemProperties& properties) { EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const EntityItemProperties& properties) {
EntityItemID actualID = entityID; EntityItemID actualID = entityID;
// if the model is unknown, attempt to look it up // if the entity is unknown, attempt to look it up
if (!entityID.isKnownID) { if (!entityID.isKnownID) {
actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID); actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID);
} }
// if at this point, we know the id, send the update to the model server // if at this point, we know the id, send the update to the entity server
if (actualID.id != UNKNOWN_ENTITY_ID) { if (actualID.id != UNKNOWN_ENTITY_ID) {
entityID.id = actualID.id; entityID.id = actualID.id;
entityID.isKnownID = true; entityID.isKnownID = true;
queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties);
} }
// If we have a local model tree set, then also update it. We can do this even if we don't know // If we have a local entity tree set, then also update it. We can do this even if we don't know
// the actual id, because we can edit out local models just with creatorTokenID // the actual id, because we can edit out local entities just with creatorTokenID
if (_entityTree) { if (_entityTree) {
_entityTree->lockForWrite(); _entityTree->lockForWrite();
_entityTree->updateEntity(entityID, properties); _entityTree->updateEntity(entityID, properties);
@ -119,19 +118,19 @@ void EntityScriptingInterface::deleteEntity(EntityItemID entityID) {
EntityItemID actualID = entityID; EntityItemID actualID = entityID;
// if the model is unknown, attempt to look it up // if the entity is unknown, attempt to look it up
if (!entityID.isKnownID) { if (!entityID.isKnownID) {
actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID); actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID);
} }
// if at this point, we know the id, send the update to the model server // if at this point, we know the id, send the update to the entity server
if (actualID.id != UNKNOWN_ENTITY_ID) { if (actualID.id != UNKNOWN_ENTITY_ID) {
entityID.id = actualID.id; entityID.id = actualID.id;
entityID.isKnownID = true; entityID.isKnownID = true;
getEntityPacketSender()->queueEraseEntityMessage(entityID); getEntityPacketSender()->queueEraseEntityMessage(entityID);
} }
// If we have a local model tree set, then also update it. // If we have a local entity tree set, then also update it.
if (_entityTree) { if (_entityTree) {
_entityTree->lockForWrite(); _entityTree->lockForWrite();
_entityTree->deleteEntity(entityID); _entityTree->deleteEntity(entityID);
@ -167,12 +166,12 @@ QVector<EntityItemID> EntityScriptingInterface::findEntities(const glm::vec3& ce
QVector<EntityItemID> result; QVector<EntityItemID> result;
if (_entityTree) { if (_entityTree) {
_entityTree->lockForRead(); _entityTree->lockForRead();
QVector<const EntityItem*> models; QVector<const EntityItem*> entities;
_entityTree->findEntities(center/(float)TREE_SCALE, radius/(float)TREE_SCALE, models); _entityTree->findEntities(center/(float)TREE_SCALE, radius/(float)TREE_SCALE, entities);
_entityTree->unlock(); _entityTree->unlock();
foreach (const EntityItem* model, models) { foreach (const EntityItem* entity, entities) {
EntityItemID thisEntityItemID(model->getID(), UNKNOWN_ENTITY_TOKEN, true); EntityItemID thisEntityItemID(entity->getID(), UNKNOWN_ENTITY_TOKEN, true);
result << thisEntityItemID; result << thisEntityItemID;
} }
} }
@ -219,11 +218,11 @@ QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, c
QScriptValue obj = engine->newObject(); QScriptValue obj = engine->newObject();
obj.setProperty("intersects", value.intersects); obj.setProperty("intersects", value.intersects);
obj.setProperty("accurate", value.accurate); obj.setProperty("accurate", value.accurate);
QScriptValue modelItemValue = EntityItemIDtoScriptValue(engine, value.entityID); QScriptValue entityItemValue = EntityItemIDtoScriptValue(engine, value.entityID);
obj.setProperty("entityID", modelItemValue); obj.setProperty("entityID", entityItemValue);
QScriptValue modelPropertiesValue = EntityItemPropertiesToScriptValue(engine, value.properties); QScriptValue propertiesValue = EntityItemPropertiesToScriptValue(engine, value.properties);
obj.setProperty("properties", modelPropertiesValue); obj.setProperty("properties", propertiesValue);
obj.setProperty("distance", value.distance); obj.setProperty("distance", value.distance);
@ -262,13 +261,13 @@ QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, c
void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, RayToEntityIntersectionResult& value) { void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, RayToEntityIntersectionResult& value) {
value.intersects = object.property("intersects").toVariant().toBool(); value.intersects = object.property("intersects").toVariant().toBool();
value.accurate = object.property("accurate").toVariant().toBool(); value.accurate = object.property("accurate").toVariant().toBool();
QScriptValue modelIDValue = object.property("entityID"); QScriptValue entityIDValue = object.property("entityID");
if (modelIDValue.isValid()) { if (entityIDValue.isValid()) {
EntityItemIDfromScriptValue(modelIDValue, value.entityID); EntityItemIDfromScriptValue(entityIDValue, value.entityID);
} }
QScriptValue modelPropertiesValue = object.property("properties"); QScriptValue entityPropertiesValue = object.property("properties");
if (modelPropertiesValue.isValid()) { if (entityPropertiesValue.isValid()) {
EntityItemPropertiesFromScriptValue(modelPropertiesValue, value.properties); EntityItemPropertiesFromScriptValue(entityPropertiesValue, value.properties);
} }
value.distance = object.property("distance").toVariant().toFloat(); value.distance = object.property("distance").toVariant().toFloat();