mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 18:23:22 +02:00
add support for changing the model URL of a model
This commit is contained in:
parent
a51d2deec6
commit
26075d9d26
4 changed files with 83 additions and 11 deletions
|
@ -706,8 +706,8 @@ function rayPlaneIntersection(pickRay, point, normal) {
|
|||
function Tooltip() {
|
||||
this.x = 285;
|
||||
this.y = 115;
|
||||
this.width = 110;
|
||||
this.height = 115 ;
|
||||
this.width = 500;
|
||||
this.height = 145 ;
|
||||
this.margin = 5;
|
||||
this.decimals = 3;
|
||||
|
||||
|
@ -735,6 +735,9 @@ function Tooltip() {
|
|||
text += "yaw: " + angles.y.toFixed(this.decimals) + "\n"
|
||||
text += "roll: " + angles.z.toFixed(this.decimals) + "\n"
|
||||
text += "Scale: " + 2 * properties.radius.toFixed(this.decimals) + "\n"
|
||||
text += "ID: " + properties.id + "\n"
|
||||
text += "model url: " + properties.modelURL + "\n"
|
||||
text += "animation url: " + properties.animationURL + "\n"
|
||||
|
||||
Overlays.editOverlay(this.textOverlay, { text: text });
|
||||
}
|
||||
|
@ -1004,9 +1007,11 @@ var modelMenuAddedDelete = false;
|
|||
function setupModelMenus() {
|
||||
print("setupModelMenus()");
|
||||
// add our menuitems
|
||||
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Models", isSeparator: true, beforeItem: "Physics" });
|
||||
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Edit Properties...",
|
||||
shortcutKeyEvent: { text: "`" }, afterItem: "Models" });
|
||||
if (!Menu.menuItemExists("Edit","Delete")) {
|
||||
print("no delete... adding ours");
|
||||
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Models", isSeparator: true, beforeItem: "Physics" });
|
||||
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Delete",
|
||||
shortcutKeyEvent: { text: "backspace" }, afterItem: "Models" });
|
||||
modelMenuAddedDelete = true;
|
||||
|
@ -1016,9 +1021,10 @@ function setupModelMenus() {
|
|||
}
|
||||
|
||||
function cleanupModelMenus() {
|
||||
Menu.removeSeparator("Edit", "Models");
|
||||
Menu.removeMenuItem("Edit", "Edit Properties...");
|
||||
if (modelMenuAddedDelete) {
|
||||
// delete our menuitems
|
||||
Menu.removeSeparator("Edit", "Models");
|
||||
Menu.removeMenuItem("Edit", "Delete");
|
||||
}
|
||||
}
|
||||
|
@ -1039,7 +1045,8 @@ Controller.mouseMoveEvent.connect(mouseMoveEvent);
|
|||
Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
|
||||
|
||||
setupModelMenus();
|
||||
Menu.menuItemEvent.connect(function(menuItem){
|
||||
|
||||
function handeMenuEvent(menuItem){
|
||||
print("menuItemEvent() in JS... menuItem=" + menuItem);
|
||||
if (menuItem == "Delete") {
|
||||
if (leftController.grabbing) {
|
||||
|
@ -1057,8 +1064,36 @@ Menu.menuItemEvent.connect(function(menuItem){
|
|||
} else {
|
||||
print(" Delete Model.... not holding...");
|
||||
}
|
||||
} else if (menuItem == "Edit Properties...") {
|
||||
var editModelID = -1;
|
||||
if (leftController.grabbing) {
|
||||
print(" Edit Properties.... leftController.modelID="+ leftController.modelID);
|
||||
editModelID = leftController.modelID;
|
||||
} else if (rightController.grabbing) {
|
||||
print(" Edit Properties.... rightController.modelID="+ rightController.modelID);
|
||||
editModelID = rightController.modelID;
|
||||
} else if (modelSelected) {
|
||||
print(" Edit Properties.... selectedModelID="+ selectedModelID);
|
||||
editModelID = selectedModelID;
|
||||
} else {
|
||||
print(" Edit Properties.... not holding...");
|
||||
}
|
||||
if (editModelID != -1) {
|
||||
print(" Edit Properties.... about to edit properties...");
|
||||
var propertyName = Window.prompt("Which property would you like to change?", "modelURL");
|
||||
var properties = Models.getModelProperties(editModelID);
|
||||
var oldValue = properties[propertyName];
|
||||
var newValue = Window.prompt("New value for: " + propertyName, oldValue);
|
||||
if (newValue != NULL) {
|
||||
properties[propertyName] = newValue;
|
||||
Models.editModel(editModelID, properties);
|
||||
}
|
||||
}
|
||||
tooltip.show(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
Menu.menuItemEvent.connect(handeMenuEvent);
|
||||
|
||||
|
||||
|
||||
// handling of inspect.js concurrence
|
||||
|
@ -1092,4 +1127,11 @@ Controller.keyReleaseEvent.connect(function(event) {
|
|||
xIsPressed = false;
|
||||
somethingChanged = true;
|
||||
}
|
||||
// since sometimes our menu shortcut keys don't work, trap our menu items here also and fire the appropriate menu items
|
||||
if (event.text == "`") {
|
||||
handeMenuEvent("Edit Properties...");
|
||||
}
|
||||
if (event.text == "BACKSPACE") {
|
||||
handeMenuEvent("Delete");
|
||||
}
|
||||
});
|
|
@ -22,6 +22,17 @@ ModelTreeRenderer::ModelTreeRenderer() :
|
|||
}
|
||||
|
||||
ModelTreeRenderer::~ModelTreeRenderer() {
|
||||
clearModelsCache();
|
||||
}
|
||||
|
||||
void ModelTreeRenderer::clear() {
|
||||
OctreeRenderer::clear();
|
||||
clearModelsCache();
|
||||
}
|
||||
|
||||
void ModelTreeRenderer::clearModelsCache() {
|
||||
qDebug() << "ModelTreeRenderer::clearModelsCache()...";
|
||||
|
||||
// delete the models in _knownModelsItemModels
|
||||
foreach(Model* model, _knownModelsItemModels) {
|
||||
delete model;
|
||||
|
@ -71,24 +82,39 @@ Model* ModelTreeRenderer::getModel(const ModelItem& modelItem) {
|
|||
if (modelItem.isKnownID()) {
|
||||
if (_knownModelsItemModels.find(modelItem.getID()) != _knownModelsItemModels.end()) {
|
||||
model = _knownModelsItemModels[modelItem.getID()];
|
||||
} else {
|
||||
|
||||
if (QUrl(modelItem.getModelURL()) != model->getURL()) {
|
||||
delete model; // delete the old model...
|
||||
model = NULL;
|
||||
_knownModelsItemModels.remove(modelItem.getID());
|
||||
}
|
||||
}
|
||||
|
||||
// if we don't have a model...
|
||||
if (!model) {
|
||||
// Make sure we only create new models on the thread that owns the ModelTreeRenderer
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "getModel", Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(Model*, model), Q_ARG(const ModelItem&, modelItem));
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
model = new Model();
|
||||
model->init();
|
||||
model->setURL(QUrl(modelItem.getModelURL()));
|
||||
_knownModelsItemModels[modelItem.getID()] = model;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (_unknownModelsItemModels.find(modelItem.getCreatorTokenID()) != _unknownModelsItemModels.end()) {
|
||||
model = _unknownModelsItemModels[modelItem.getCreatorTokenID()];
|
||||
} else {
|
||||
if (QUrl(modelItem.getModelURL()) != model->getURL()) {
|
||||
delete model; // delete the old model...
|
||||
model = NULL;
|
||||
_unknownModelsItemModels.remove(modelItem.getID());
|
||||
}
|
||||
}
|
||||
|
||||
if (!model) {
|
||||
// Make sure we only create new models on the thread that owns the ModelTreeRenderer
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "getModel", Qt::BlockingQueuedConnection,
|
||||
|
|
|
@ -51,7 +51,11 @@ public:
|
|||
|
||||
virtual const FBXGeometry* getGeometryForModel(const ModelItem& modelItem);
|
||||
|
||||
/// clears the tree
|
||||
virtual void clear();
|
||||
|
||||
protected:
|
||||
void clearModelsCache();
|
||||
Model* getModel(const ModelItem& modelItem);
|
||||
QMap<uint32_t, Model*> _knownModelsItemModels;
|
||||
QMap<uint32_t, Model*> _unknownModelsItemModels;
|
||||
|
|
|
@ -62,7 +62,7 @@ public:
|
|||
static bool renderOperation(OctreeElement* element, void* extraData);
|
||||
|
||||
/// clears the tree
|
||||
void clear();
|
||||
virtual void clear();
|
||||
protected:
|
||||
Octree* _tree;
|
||||
bool _managedTree;
|
||||
|
|
Loading…
Reference in a new issue