can add image directly from asset server

This commit is contained in:
Elisa Lupin-Jimenez 2018-01-26 14:39:04 -08:00
parent 62437dcc22
commit 9f8e2017ce
4 changed files with 183 additions and 158 deletions

View file

@ -182,92 +182,103 @@ Windows.ScrollingWindow {
return; return;
} }
var SHAPE_TYPE_NONE = 0; if (defaultURL.endsWith(".jpg") || defaultURL.endsWith(".png")) {
var SHAPE_TYPE_SIMPLE_HULL = 1; var name = assetProxyModel.data(treeView.selection.currentIndex);
var SHAPE_TYPE_SIMPLE_COMPOUND = 2; var modelURL = "https://hifi-content.s3.amazonaws.com/elisalj/image_entity/snapshot.fbx";
var SHAPE_TYPE_STATIC_MESH = 3; var textures = JSON.stringify({ "tex.picture": defaultURL});
var SHAPE_TYPE_BOX = 4; var shapeType = "box";
var SHAPE_TYPE_SPHERE = 5; var dynamic = false;
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getForward(MyAvatar.orientation)));
var gravity = Vec3.multiply(Vec3.fromPolar(Math.PI / 2, 0), 0);
Entities.addModelEntity(name, modelURL, textures, shapeType, dynamic, position, gravity);
} else {
var SHAPE_TYPE_NONE = 0;
var SHAPE_TYPE_SIMPLE_HULL = 1;
var SHAPE_TYPE_SIMPLE_COMPOUND = 2;
var SHAPE_TYPE_STATIC_MESH = 3;
var SHAPE_TYPE_BOX = 4;
var SHAPE_TYPE_SPHERE = 5;
var SHAPE_TYPES = []; var SHAPE_TYPES = [];
SHAPE_TYPES[SHAPE_TYPE_NONE] = "No Collision"; SHAPE_TYPES[SHAPE_TYPE_NONE] = "No Collision";
SHAPE_TYPES[SHAPE_TYPE_SIMPLE_HULL] = "Basic - Whole model"; SHAPE_TYPES[SHAPE_TYPE_SIMPLE_HULL] = "Basic - Whole model";
SHAPE_TYPES[SHAPE_TYPE_SIMPLE_COMPOUND] = "Good - Sub-meshes"; SHAPE_TYPES[SHAPE_TYPE_SIMPLE_COMPOUND] = "Good - Sub-meshes";
SHAPE_TYPES[SHAPE_TYPE_STATIC_MESH] = "Exact - All polygons"; SHAPE_TYPES[SHAPE_TYPE_STATIC_MESH] = "Exact - All polygons";
SHAPE_TYPES[SHAPE_TYPE_BOX] = "Box"; SHAPE_TYPES[SHAPE_TYPE_BOX] = "Box";
SHAPE_TYPES[SHAPE_TYPE_SPHERE] = "Sphere"; SHAPE_TYPES[SHAPE_TYPE_SPHERE] = "Sphere";
var SHAPE_TYPE_DEFAULT = SHAPE_TYPE_STATIC_MESH; var SHAPE_TYPE_DEFAULT = SHAPE_TYPE_STATIC_MESH;
var DYNAMIC_DEFAULT = false; var DYNAMIC_DEFAULT = false;
var prompt = desktop.customInputDialog({ var prompt = desktop.customInputDialog({
textInput: { textInput: {
label: "Model URL", label: "Model URL",
text: defaultURL text: defaultURL
}, },
comboBox: { comboBox: {
label: "Automatic Collisions", label: "Automatic Collisions",
index: SHAPE_TYPE_DEFAULT, index: SHAPE_TYPE_DEFAULT,
items: SHAPE_TYPES items: SHAPE_TYPES
}, },
checkBox: { checkBox: {
label: "Dynamic", label: "Dynamic",
checked: DYNAMIC_DEFAULT, checked: DYNAMIC_DEFAULT,
disableForItems: [ disableForItems: [
SHAPE_TYPE_STATIC_MESH SHAPE_TYPE_STATIC_MESH
], ],
checkStateOnDisable: false, checkStateOnDisable: false,
warningOnDisable: "Models with 'Exact' automatic collisions cannot be dynamic, and should not be used as floors" warningOnDisable: "Models with 'Exact' automatic collisions cannot be dynamic, and should not be used as floors"
}
});
prompt.selected.connect(function (jsonResult) {
if (jsonResult) {
var result = JSON.parse(jsonResult);
var url = result.textInput.trim();
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;
case SHAPE_TYPE_BOX:
shapeType = "box";
break;
case SHAPE_TYPE_SPHERE:
shapeType = "sphere";
break;
default:
shapeType = "none";
} }
});
var dynamic = result.checkBox !== null ? result.checkBox : DYNAMIC_DEFAULT; prompt.selected.connect(function (jsonResult) {
if (shapeType === "static-mesh" && dynamic) { if (jsonResult) {
// The prompt should prevent this case var result = JSON.parse(jsonResult);
print("Error: model cannot be both static mesh and dynamic. This should never happen."); var url = result.textInput.trim();
} else if (url) { var shapeType;
var name = assetProxyModel.data(treeView.selection.currentIndex); switch (result.comboBox) {
var addPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getForward(MyAvatar.orientation))); case SHAPE_TYPE_SIMPLE_HULL:
var gravity; shapeType = "simple-hull";
if (dynamic) { break;
// Create a vector <0, -10, 0>. { x: 0, y: -10, z: 0 } won't work because Qt is dumb and this is a case SHAPE_TYPE_SIMPLE_COMPOUND:
// different scripting engine from QTScript. shapeType = "simple-compound";
gravity = Vec3.multiply(Vec3.fromPolar(Math.PI / 2, 0), 10); break;
} else { case SHAPE_TYPE_STATIC_MESH:
gravity = Vec3.multiply(Vec3.fromPolar(Math.PI / 2, 0), 0); shapeType = "static-mesh";
break;
case SHAPE_TYPE_BOX:
shapeType = "box";
break;
case SHAPE_TYPE_SPHERE:
shapeType = "sphere";
break;
default:
shapeType = "none";
} }
print("Asset browser - adding asset " + url + " (" + name + ") to world."); 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.getForward(MyAvatar.orientation)));
var gravity;
if (dynamic) {
// Create a vector <0, -10, 0>. { x: 0, y: -10, z: 0 } won't work because Qt is dumb and this is a
// different scripting engine from QTScript.
gravity = Vec3.multiply(Vec3.fromPolar(Math.PI / 2, 0), 10);
} else {
gravity = Vec3.multiply(Vec3.fromPolar(Math.PI / 2, 0), 0);
}
// Entities.addEntity doesn't work from QML, so we use this. print("Asset browser - adding asset " + url + " (" + name + ") to world.");
Entities.addModelEntity(name, url, shapeType, dynamic, addPosition, gravity);
// 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

@ -182,92 +182,103 @@ Rectangle {
return; return;
} }
var SHAPE_TYPE_NONE = 0; if (defaultURL.endsWith(".jpg") || defaultURL.endsWith(".png")) {
var SHAPE_TYPE_SIMPLE_HULL = 1; var name = assetProxyModel.data(treeView.selection.currentIndex);
var SHAPE_TYPE_SIMPLE_COMPOUND = 2; var modelURL = "https://hifi-content.s3.amazonaws.com/elisalj/image_entity/snapshot.fbx";
var SHAPE_TYPE_STATIC_MESH = 3; var textures = JSON.stringify({ "tex.picture": defaultURL});
var SHAPE_TYPE_BOX = 4; var shapeType = "box";
var SHAPE_TYPE_SPHERE = 5; var dynamic = false;
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getForward(MyAvatar.orientation)));
var gravity = Vec3.multiply(Vec3.fromPolar(Math.PI / 2, 0), 0);
Entities.addModelEntity(name, modelURL, textures, shapeType, dynamic, position, gravity);
} else {
var SHAPE_TYPE_NONE = 0;
var SHAPE_TYPE_SIMPLE_HULL = 1;
var SHAPE_TYPE_SIMPLE_COMPOUND = 2;
var SHAPE_TYPE_STATIC_MESH = 3;
var SHAPE_TYPE_BOX = 4;
var SHAPE_TYPE_SPHERE = 5;
var SHAPE_TYPES = []; var SHAPE_TYPES = [];
SHAPE_TYPES[SHAPE_TYPE_NONE] = "No Collision"; SHAPE_TYPES[SHAPE_TYPE_NONE] = "No Collision";
SHAPE_TYPES[SHAPE_TYPE_SIMPLE_HULL] = "Basic - Whole model"; SHAPE_TYPES[SHAPE_TYPE_SIMPLE_HULL] = "Basic - Whole model";
SHAPE_TYPES[SHAPE_TYPE_SIMPLE_COMPOUND] = "Good - Sub-meshes"; SHAPE_TYPES[SHAPE_TYPE_SIMPLE_COMPOUND] = "Good - Sub-meshes";
SHAPE_TYPES[SHAPE_TYPE_STATIC_MESH] = "Exact - All polygons"; SHAPE_TYPES[SHAPE_TYPE_STATIC_MESH] = "Exact - All polygons";
SHAPE_TYPES[SHAPE_TYPE_BOX] = "Box"; SHAPE_TYPES[SHAPE_TYPE_BOX] = "Box";
SHAPE_TYPES[SHAPE_TYPE_SPHERE] = "Sphere"; SHAPE_TYPES[SHAPE_TYPE_SPHERE] = "Sphere";
var SHAPE_TYPE_DEFAULT = SHAPE_TYPE_STATIC_MESH; var SHAPE_TYPE_DEFAULT = SHAPE_TYPE_STATIC_MESH;
var DYNAMIC_DEFAULT = false; var DYNAMIC_DEFAULT = false;
var prompt = tabletRoot.customInputDialog({ var prompt = tabletRoot.customInputDialog({
textInput: { textInput: {
label: "Model URL", label: "Model URL",
text: defaultURL text: defaultURL
}, },
comboBox: { comboBox: {
label: "Automatic Collisions", label: "Automatic Collisions",
index: SHAPE_TYPE_DEFAULT, index: SHAPE_TYPE_DEFAULT,
items: SHAPE_TYPES items: SHAPE_TYPES
}, },
checkBox: { checkBox: {
label: "Dynamic", label: "Dynamic",
checked: DYNAMIC_DEFAULT, checked: DYNAMIC_DEFAULT,
disableForItems: [ disableForItems: [
SHAPE_TYPE_STATIC_MESH SHAPE_TYPE_STATIC_MESH
], ],
checkStateOnDisable: false, checkStateOnDisable: false,
warningOnDisable: "Models with 'Exact' automatic collisions cannot be dynamic, and should not be used as floors" warningOnDisable: "Models with 'Exact' automatic collisions cannot be dynamic, and should not be used as floors"
}
});
prompt.selected.connect(function (jsonResult) {
if (jsonResult) {
var result = JSON.parse(jsonResult);
var url = result.textInput.trim();
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;
case SHAPE_TYPE_BOX:
shapeType = "box";
break;
case SHAPE_TYPE_SPHERE:
shapeType = "sphere";
break;
default:
shapeType = "none";
} }
});
var dynamic = result.checkBox !== null ? result.checkBox : DYNAMIC_DEFAULT; prompt.selected.connect(function (jsonResult) {
if (shapeType === "static-mesh" && dynamic) { if (jsonResult) {
// The prompt should prevent this case var result = JSON.parse(jsonResult);
print("Error: model cannot be both static mesh and dynamic. This should never happen."); var url = result.textInput.trim();
} else if (url) { var shapeType;
var name = assetProxyModel.data(treeView.selection.currentIndex); switch (result.comboBox) {
var addPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getForward(MyAvatar.orientation))); case SHAPE_TYPE_SIMPLE_HULL:
var gravity; shapeType = "simple-hull";
if (dynamic) { break;
// Create a vector <0, -10, 0>. { x: 0, y: -10, z: 0 } won't work because Qt is dumb and this is a case SHAPE_TYPE_SIMPLE_COMPOUND:
// different scripting engine from QTScript. shapeType = "simple-compound";
gravity = Vec3.multiply(Vec3.fromPolar(Math.PI / 2, 0), 10); break;
} else { case SHAPE_TYPE_STATIC_MESH:
gravity = Vec3.multiply(Vec3.fromPolar(Math.PI / 2, 0), 0); shapeType = "static-mesh";
break;
case SHAPE_TYPE_BOX:
shapeType = "box";
break;
case SHAPE_TYPE_SPHERE:
shapeType = "sphere";
break;
default:
shapeType = "none";
} }
print("Asset browser - adding asset " + url + " (" + name + ") to world."); 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.getForward(MyAvatar.orientation)));
var gravity;
if (dynamic) {
// Create a vector <0, -10, 0>. { x: 0, y: -10, z: 0 } won't work because Qt is dumb and this is a
// different scripting engine from QTScript.
gravity = Vec3.multiply(Vec3.fromPolar(Math.PI / 2, 0), 10);
} else {
gravity = Vec3.multiply(Vec3.fromPolar(Math.PI / 2, 0), 0);
}
// Entities.addEntity doesn't work from QML, so we use this. print("Asset browser - adding asset " + url + " (" + name + ") to world.");
Entities.addModelEntity(name, url, shapeType, dynamic, addPosition, gravity);
// 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

@ -299,7 +299,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
} }
} }
QUuid EntityScriptingInterface::addModelEntity(const QString& name, const QString& modelUrl, const QString& shapeType, QUuid EntityScriptingInterface::addModelEntity(const QString& name, const QString& modelUrl, const QString& textures, const QString& shapeType,
bool dynamic, const glm::vec3& position, const glm::vec3& gravity) { bool dynamic, const glm::vec3& position, const glm::vec3& gravity) {
_activityTracking.addedEntityCount++; _activityTracking.addedEntityCount++;
@ -311,6 +311,9 @@ QUuid EntityScriptingInterface::addModelEntity(const QString& name, const QStrin
properties.setDynamic(dynamic); properties.setDynamic(dynamic);
properties.setPosition(position); properties.setPosition(position);
properties.setGravity(gravity); properties.setGravity(gravity);
if (!textures.isEmpty()) {
properties.setTextures(textures);
}
return addEntity(properties); return addEntity(properties);
} }

View file

@ -158,7 +158,7 @@ public slots:
/// temporary method until addEntity can be used from QJSEngine /// temporary method until addEntity can be used from QJSEngine
/// Deliberately not adding jsdoc, only used internally. /// Deliberately not adding jsdoc, only used internally.
Q_INVOKABLE QUuid addModelEntity(const QString& name, const QString& modelUrl, const QString& shapeType, bool dynamic, Q_INVOKABLE QUuid addModelEntity(const QString& name, const QString& modelUrl, const QString& textures, const QString& shapeType, bool dynamic,
const glm::vec3& position, const glm::vec3& gravity); const glm::vec3& position, const glm::vec3& gravity);
/**jsdoc /**jsdoc