Use custom dialog for asset server add to world

This commit is contained in:
Zander Otavka 2016-07-22 15:15:11 -07:00
parent 530e17a7e5
commit c25b87c33f
3 changed files with 76 additions and 8 deletions

View file

@ -141,18 +141,81 @@ ScrollingWindow {
} }
function addToWorld() { function addToWorld() {
var url = assetProxyModel.data(treeView.selection.currentIndex, 0x103); var defaultURL = assetProxyModel.data(treeView.selection.currentIndex, 0x103);
if (!url || !canAddToWorld(url)) { if (!defaultURL || !canAddToWorld(defaultURL)) {
return; return;
} }
var name = assetProxyModel.data(treeView.selection.currentIndex); var SHAPE_TYPE_NONE = 0;
var SHAPE_TYPE_SIMPLE_HULL = 1;
var SHAPE_TYPE_SIMPLE_COMPOUND = 2;
var SHAPE_TYPE_STATIC_MESH = 3;
console.log("Asset browser - adding asset " + url + " (" + name + ") to world."); var SHAPE_TYPES = [];
SHAPE_TYPES[SHAPE_TYPE_NONE] = "No Collision";
SHAPE_TYPES[SHAPE_TYPE_SIMPLE_HULL] = "Basic - Whole model";
SHAPE_TYPES[SHAPE_TYPE_SIMPLE_COMPOUND] = "Good - Sub-meshes";
SHAPE_TYPES[SHAPE_TYPE_STATIC_MESH] = "Exact - All polygons";
var addPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(MyAvatar.orientation))); var SHAPE_TYPE_DEFAULT = SHAPE_TYPE_STATIC_MESH;
Entities.addModelEntity(name, url, addPosition); var DYNAMIC_DEFAULT = false;
var prompt = desktop.customInputDialog({
textInput: {
label: "Model URL",
text: defaultURL
},
comboBox: {
label: "Automatic Collisions",
index: SHAPE_TYPE_DEFAULT,
items: SHAPE_TYPES
},
checkBox: {
label: "Dynamic",
checked: DYNAMIC_DEFAULT,
disableForItems: [
SHAPE_TYPE_STATIC_MESH
],
checkStateOnDisable: false,
warningOnDisable: "Models with automatic collisions set to 'Exact' cannot be dynamic"
}
});
prompt.selected.connect(function (jsonResult) {
if (jsonResult) {
var result = JSON.parse(jsonResult);
var url = result.textInput;
var shapeType;
switch (result.comboBox) {
case SHAPE_TYPE_SIMPLE_HULL:
shapeType = "simple-hull";
break;
case SHAPE_TYPE_SIMPLE_COMPOUND:
shapeType = "simple-compound";
break;
case SHAPE_TYPE_STATIC_MESH:
shapeType = "static-mesh";
break;
default:
shapeType = "none";
}
var dynamic = result.checkBox !== null ? result.checkBox : DYNAMIC_DEFAULT;
if (shapeType === "static-mesh" && dynamic) {
// The prompt should prevent this case
print("Error: model cannot be both static mesh and dynamic. This should never happen.");
} else if (url) {
var name = assetProxyModel.data(treeView.selection.currentIndex);
var addPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(MyAvatar.orientation)));
var gravity = dynamic ? { x: 0, y: -10, z: 0 } : { x: 0, y: 0, z: 0 };
print("Asset browser - adding asset " + url + " (" + name + ") to world.");
// Entities.addEntity doesn't work from QML, so we use this.
Entities.addModelEntity(name, url, shapeType, dynamic, addPosition, gravity);
}
}
});
} }
function copyURLToClipboard(index) { function copyURLToClipboard(index) {

View file

@ -198,12 +198,16 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
} }
} }
QUuid EntityScriptingInterface::addModelEntity(const QString& name, const QString& modelUrl, const glm::vec3& position) { QUuid EntityScriptingInterface::addModelEntity(const QString& name, const QString& modelUrl, const QString& shapeType,
bool dynamic, const glm::vec3& position, const glm::vec3& gravity) {
EntityItemProperties properties; EntityItemProperties properties;
properties.setType(EntityTypes::Model); properties.setType(EntityTypes::Model);
properties.setName(name); properties.setName(name);
properties.setModelURL(modelUrl); properties.setModelURL(modelUrl);
properties.setShapeTypeFromString(shapeType);
properties.setDynamic(dynamic);
properties.setPosition(position); properties.setPosition(position);
properties.setGravity(gravity);
return addEntity(properties); return addEntity(properties);
} }

View file

@ -86,7 +86,8 @@ public slots:
Q_INVOKABLE QUuid addEntity(const EntityItemProperties& properties, bool clientOnly = false); Q_INVOKABLE QUuid addEntity(const EntityItemProperties& properties, bool clientOnly = false);
/// temporary method until addEntity can be used from QJSEngine /// temporary method until addEntity can be used from QJSEngine
Q_INVOKABLE QUuid addModelEntity(const QString& name, const QString& modelUrl, const glm::vec3& position); Q_INVOKABLE QUuid addModelEntity(const QString& name, const QString& modelUrl, const QString& shapeType, bool dynamic,
const glm::vec3& position, const glm::vec3& gravity);
/// gets the current model properties for a specific model /// gets the current model properties for a specific model
/// this function will not find return results in script engine contexts which don't have access to models /// this function will not find return results in script engine contexts which don't have access to models