trying to fix conversion

This commit is contained in:
SamGondelman 2018-07-16 09:22:50 -07:00
parent f9cdfbad7c
commit 3b5a0d278d
5 changed files with 153 additions and 141 deletions

View file

@ -939,7 +939,9 @@ bool Octree::toJSONDocument(QJsonDocument* doc, const OctreeElementPointer& elem
return false;
}
qDebug() << "boop3" << entityDescription;
*doc = QJsonDocument::fromVariant(entityDescription);
qDebug() << "boop4" << *doc;
return true;
}

View file

@ -25,7 +25,6 @@
#include <QtScript/QScriptValue>
#include <QtScript/QScriptValueIterator>
int glmVec2MetaTypeId = qRegisterMetaType<glm::vec2>();
int vec2FloatMetaTypeId = qRegisterMetaType<ScriptVec2Float>();
int glmVec3MetaTypeId = qRegisterMetaType<glm::vec3>();
@ -71,38 +70,46 @@ void registerMetaTypes(QScriptEngine* engine) {
}
QScriptValue vec2FloatToScriptValue(QScriptEngine* engine, const ScriptVec2Float& vec2) {
return engine->newQObject(new ScriptVec2Float(vec2), QScriptEngine::ScriptOwnership);
auto prototype = engine->globalObject().property("__hifi_vec2_float__");
if (!prototype.property("defined").toBool()) {
prototype = engine->evaluate(
"__hifi_vec2_float__ = Object.defineProperties({}, { "
"defined: { value: true },"
"0: { set: function(nv) { return this.x = nv; }, get: function() { return this.x; } },"
"1: { set: function(nv) { return this.y = nv; }, get: function() { return this.y; } },"
"u: { set: function(nv) { return this.x = nv; }, get: function() { return this.x; } },"
"v: { set: function(nv) { return this.y = nv; }, get: function() { return this.y; } },"
"width: { set: function(nv) { return this.x = nv; }, get: function() { return this.x; } },"
"height: { set: function(nv) { return this.y = nv; }, get: function() { return this.y; } }"
"})"
);
}
QScriptValue value = engine->newObject();
value.setProperty("x", vec2.x);
value.setProperty("y", vec2.y);
value.setPrototype(prototype);
return value;
}
void vec2FloatFromScriptValue(const QScriptValue& object, ScriptVec2Float& vec2) {
if (object.isQObject()) {
auto qObject = object.toQObject();
if (qObject) {
vec2 = *qobject_cast<ScriptVec2Float*>(qObject);
return;
}
} else {
QScriptValue x = object.property("x");
if (!x.isValid()) {
x = object.property("u");
}
if (!x.isValid()) {
x = object.property("width");
}
QScriptValue y = object.property("y");
if (!y.isValid()) {
y = object.property("v");
}
if (!y.isValid()) {
y = object.property("height");
}
vec2.x = x.toVariant().toFloat();
vec2.y = y.toVariant().toFloat();
return;
QScriptValue x = object.property("x");
if (!x.isValid()) {
x = object.property("u");
}
vec2 = ScriptVec2Float();
if (!x.isValid()) {
x = object.property("width");
}
QScriptValue y = object.property("y");
if (!y.isValid()) {
y = object.property("v");
}
if (!y.isValid()) {
y = object.property("height");
}
vec2.x = x.toVariant().toFloat();
vec2.y = y.toVariant().toFloat();
}
QScriptValue vec2ToScriptValue(QScriptEngine* engine, const glm::vec2& vec2) {
@ -152,10 +159,12 @@ glm::vec2 vec2FromVariant(const QVariant &object, bool& isValid) {
glm::vec2 result;
if (object.canConvert<float>()) {
result = glm::vec2(object.toFloat());
isValid = true;
} else if (object.canConvert<QVector2D>()) {
auto qvec2 = qvariant_cast<QVector2D>(object);
result.x = qvec2.x();
result.y = qvec2.y();
isValid = true;
} else {
auto map = object.toMap();
auto x = map["x"];
@ -188,70 +197,104 @@ glm::vec2 vec2FromVariant(const QVariant &object) {
}
QScriptValue vec3FloatToScriptValue(QScriptEngine* engine, const ScriptVec3Float& vec3) {
return engine->newQObject(new ScriptVec3Float(vec3), QScriptEngine::ScriptOwnership);
auto prototype = engine->globalObject().property("__hifi_vec3_float__");
if (!prototype.property("defined").toBool()) {
prototype = engine->evaluate(
"__hifi_vec3_float__ = Object.defineProperties({}, { "
"defined: { value: true },"
"0: { set: function(nv) { return this.x = nv; }, get: function() { return this.x; } },"
"1: { set: function(nv) { return this.y = nv; }, get: function() { return this.y; } },"
"2: { set: function(nv) { return this.z = nv; }, get: function() { return this.z; } },"
"r: { set: function(nv) { return this.x = nv; }, get: function() { return this.x; } },"
"g: { set: function(nv) { return this.y = nv; }, get: function() { return this.y; } },"
"b: { set: function(nv) { return this.z = nv; }, get: function() { return this.z; } },"
"red: { set: function(nv) { return this.x = nv; }, get: function() { return this.x; } },"
"green: { set: function(nv) { return this.y = nv; }, get: function() { return this.y; } },"
"blue: { set: function(nv) { return this.z = nv; }, get: function() { return this.z; } },"
"width: { set: function(nv) { return this.x = nv; }, get: function() { return this.x; } },"
"height: { set: function(nv) { return this.y = nv; }, get: function() { return this.y; } },"
"depth: { set: function(nv) { return this.z = nv; }, get: function() { return this.z; } }"
"})"
);
}
QScriptValue value = engine->newObject();
value.setProperty("x", vec3.x);
value.setProperty("y", vec3.y);
value.setProperty("z", vec3.z);
value.setPrototype(prototype);
return value;
}
void vec3FloatFromScriptValue(const QScriptValue& object, ScriptVec3Float& vec3) {
if (object.isQObject()) {
auto qObject = object.toQObject();
if (qObject) {
vec3 = *qobject_cast<ScriptVec3Float*>(qObject);
return;
}
} else {
QScriptValue x = object.property("x");
if (!x.isValid()) {
x = object.property("r");
}
if (!x.isValid()) {
x = object.property("red");
}
if (!x.isValid()) {
x = object.property("width");
}
QScriptValue y = object.property("y");
if (!y.isValid()) {
y = object.property("g");
}
if (!y.isValid()) {
y = object.property("green");
}
if (!y.isValid()) {
y = object.property("height");
}
QScriptValue z = object.property("z");
if (!z.isValid()) {
z = object.property("b");
}
if (!z.isValid()) {
z = object.property("blue");
}
if (!z.isValid()) {
z = object.property("depth");
}
vec3.x = x.toVariant().toFloat();
vec3.y = y.toVariant().toFloat();
vec3.z = z.toVariant().toFloat();
return;
QScriptValue x = object.property("x");
if (!x.isValid()) {
x = object.property("r");
}
vec3 = ScriptVec3Float();
if (!x.isValid()) {
x = object.property("red");
}
if (!x.isValid()) {
x = object.property("width");
}
QScriptValue y = object.property("y");
if (!y.isValid()) {
y = object.property("g");
}
if (!y.isValid()) {
y = object.property("green");
}
if (!y.isValid()) {
y = object.property("height");
}
QScriptValue z = object.property("z");
if (!z.isValid()) {
z = object.property("b");
}
if (!z.isValid()) {
z = object.property("blue");
}
if (!z.isValid()) {
z = object.property("depth");
}
vec3.x = x.toVariant().toFloat();
vec3.y = y.toVariant().toFloat();
vec3.z = z.toVariant().toFloat();
}
QScriptValue vec3UCharToScriptValue(QScriptEngine* engine, const ScriptVec3UChar& vec3) {
return engine->newQObject(new ScriptVec3UChar(vec3), QScriptEngine::ScriptOwnership);
auto prototype = engine->globalObject().property("__hifi_vec3_uchar__");
if (!prototype.property("defined").toBool()) {
prototype = engine->evaluate(
"__hifi_vec3_uchar__ = Object.defineProperties({}, { "
"defined: { value: true },"
"0: { set: function(nv) { return this.x = nv; }, get: function() { return this.x; } },"
"1: { set: function(nv) { return this.y = nv; }, get: function() { return this.y; } },"
"2: { set: function(nv) { return this.z = nv; }, get: function() { return this.z; } },"
"r: { set: function(nv) { return this.x = nv; }, get: function() { return this.x; } },"
"g: { set: function(nv) { return this.y = nv; }, get: function() { return this.y; } },"
"b: { set: function(nv) { return this.z = nv; }, get: function() { return this.z; } },"
"red: { set: function(nv) { return this.x = nv; }, get: function() { return this.x; } },"
"green: { set: function(nv) { return this.y = nv; }, get: function() { return this.y; } },"
"blue: { set: function(nv) { return this.z = nv; }, get: function() { return this.z; } },"
"width: { set: function(nv) { return this.x = nv; }, get: function() { return this.x; } },"
"height: { set: function(nv) { return this.y = nv; }, get: function() { return this.y; } },"
"depth: { set: function(nv) { return this.z = nv; }, get: function() { return this.z; } }"
"})"
);
}
QScriptValue value = engine->newObject();
value.setProperty("x", vec3.x);
value.setProperty("y", vec3.y);
value.setProperty("z", vec3.z);
value.setPrototype(prototype);
return value;
}
void vec3UCharFromScriptValue(const QScriptValue& object, ScriptVec3UChar& vec3) {
if (object.isQObject()) {
auto qObject = object.toQObject();
if (qObject) {
vec3 = *qobject_cast<ScriptVec3UChar*>(qObject);
return;
}
} else if (object.isString()) {
if (object.isString()) {
QColor qColor(object.toString());
if (qColor.isValid()) {
vec3.x = (uint8_t)qColor.red();

View file

@ -53,17 +53,11 @@ void mat4FromScriptValue(const QScriptValue& object, glm::mat4& mat4);
*/
class ScriptVec2Float : public QObject {
Q_OBJECT
Q_PROPERTY(float x MEMBER x)
Q_PROPERTY(float y MEMBER y)
Q_PROPERTY(float u MEMBER x)
Q_PROPERTY(float v MEMBER y)
Q_PROPERTY(float width MEMBER x)
Q_PROPERTY(float height MEMBER y)
public:
ScriptVec2Float() {}
ScriptVec2Float(float xy) : x(xy), y(xy) {}
ScriptVec2Float(float x, float y) : x(x), y(y) {}
ScriptVec2Float(const ScriptVec2Float& other) : QObject(), x(other.x), y(other.y) {}
ScriptVec2Float(const ScriptVec2Float& other) : x(other.x), y(other.y) {}
ScriptVec2Float(const glm::vec2& other) : x(other.x), y(other.y) {}
void operator=(const ScriptVec2Float& other) { x = other.x; y = other.y; }
inline bool operator==(const ScriptVec2Float& other) const { return (x == other.x && y == other.y); }
@ -72,7 +66,7 @@ public:
inline bool operator!=(const glm::vec2& other) const { return !(*this == other); }
glm::vec2 toGlm() const { return glm::vec2(x, y); }
Q_INVOKABLE QVariantMap toJSON() { return toJsonValue(*this, { "x", "y" }).toObject().toVariantMap(); }
Q_INVOKABLE QVariant toJSON() const { return toJsonValue(*this, { "x", "y" }).toVariant(); }
float x { 0.0f };
float y { 0.0f };
@ -82,7 +76,7 @@ private:
friend bool operator!=(glm::vec2 glmVec2, const ScriptVec2Float& vec2);
};
inline QDebug operator<<(QDebug debug, const ScriptVec2Float& vec2) {
debug << "(" << vec2.x << "," << vec2.y << ")";
debug << "{" << vec2.x << "," << vec2.y << "}";
return debug;
}
inline bool operator==(glm::vec2 glmVec2, const ScriptVec2Float& vec2) { return (glmVec2.x == vec2.x && glmVec2.y == vec2.y); }
@ -109,23 +103,11 @@ glm::vec2 vec2FromVariant(const QVariant& object);
*/
class ScriptVec3Float : public QObject {
Q_OBJECT
Q_PROPERTY(float x MEMBER x)
Q_PROPERTY(float y MEMBER y)
Q_PROPERTY(float z MEMBER z)
Q_PROPERTY(float r MEMBER x)
Q_PROPERTY(float g MEMBER y)
Q_PROPERTY(float b MEMBER z)
Q_PROPERTY(float red MEMBER x)
Q_PROPERTY(float green MEMBER y)
Q_PROPERTY(float blue MEMBER z)
Q_PROPERTY(float width MEMBER x)
Q_PROPERTY(float height MEMBER y)
Q_PROPERTY(float depth MEMBER z)
public:
ScriptVec3Float() {}
ScriptVec3Float(float xyz) : x(xyz), y(xyz), z(xyz) {}
ScriptVec3Float(float x, float y, float z) : x(x), y(y), z(z) {}
ScriptVec3Float(const ScriptVec3Float& other) : QObject(), x(other.x), y(other.y), z(other.z) {}
ScriptVec3Float(const ScriptVec3Float& other) : x(other.x), y(other.y), z(other.z) {}
ScriptVec3Float(const glm::vec3& other) : x(other.x), y(other.y), z(other.z) {}
void operator=(const ScriptVec3Float& other) { x = other.x; y = other.y; z = other.z; }
inline bool operator==(const ScriptVec3Float& other) const { return (x == other.x && y == other.y && z == other.z); }
@ -134,7 +116,7 @@ public:
inline bool operator!=(const glm::vec3& other) const { return !(*this == other); }
glm::vec3 toGlm() const { return glm::vec3(x, y, z); }
Q_INVOKABLE QVariantMap toJSON() { return toJsonValue(*this, { "x", "y", "z" }).toObject().toVariantMap(); }
Q_INVOKABLE QVariant toJSON() const { return toJsonValue(*this, { "x", "y", "z" }).toVariant(); }
float x { 0.0f };
float y { 0.0f };
@ -145,7 +127,7 @@ private:
friend bool operator!=(glm::vec3 glmVec3, const ScriptVec3Float& vec3);
};
inline QDebug operator<<(QDebug debug, const ScriptVec3Float& vec3) {
debug << "(" << vec3.x << "," << vec3.y << "," << vec3.z << ")";
debug << "{" << vec3.x << "," << vec3.y << "," << vec3.z << "}";
return debug;
}
inline bool operator==(glm::vec3 glmVec3, const ScriptVec3Float& vec3) { return (glmVec3.x == vec3.x && glmVec3.y == vec3.y && glmVec3.z == vec3.z); }
@ -164,30 +146,18 @@ void vec3FloatFromScriptValue(const QScriptValue& object, ScriptVec3Float& vec3)
*/
class ScriptVec3UChar : public QObject {
Q_OBJECT
Q_PROPERTY(unsigned int x MEMBER x)
Q_PROPERTY(unsigned int y MEMBER y)
Q_PROPERTY(unsigned int z MEMBER z)
Q_PROPERTY(unsigned int r MEMBER x)
Q_PROPERTY(unsigned int g MEMBER y)
Q_PROPERTY(unsigned int b MEMBER z)
Q_PROPERTY(unsigned int red MEMBER x)
Q_PROPERTY(unsigned int green MEMBER y)
Q_PROPERTY(unsigned int blue MEMBER z)
Q_PROPERTY(unsigned int width MEMBER x)
Q_PROPERTY(unsigned int height MEMBER y)
Q_PROPERTY(unsigned int depth MEMBER z)
public:
ScriptVec3UChar() {}
ScriptVec3UChar(unsigned int xyz) : x(xyz), y(xyz), z(xyz) {}
ScriptVec3UChar(unsigned int x, unsigned int y, unsigned int z) : x(x), y(y), z(z) {}
ScriptVec3UChar(const ScriptVec3UChar& other) : QObject(), x(other.x), y(other.y), z(other.z) {}
ScriptVec3UChar(const ScriptVec3UChar& other) : x(other.x), y(other.y), z(other.z) {}
ScriptVec3UChar(const glm::vec3& other) : x(other.x), y(other.y), z(other.z) {}
void operator=(const ScriptVec3UChar& other) { x = other.x; y = other.y; z = other.z; }
inline bool operator==(const ScriptVec3UChar& other) const { return (x == other.x && y == other.y && z == other.z); }
inline bool operator!=(const ScriptVec3UChar& other) const { return !(*this == other); }
glm::vec3 toGlm() const { return glm::vec3(x, y, z); }
Q_INVOKABLE QVariantMap toJSON() { return toJsonValue(*this, { "x", "y", "z" }).toObject().toVariantMap(); }
Q_INVOKABLE QVariant toJSON() const { return toJsonValue(*this, { "x", "y", "z" }).toVariant(); }
unsigned char x { 0 };
unsigned char y { 0 };
@ -198,7 +168,7 @@ private:
friend bool operator!=(glm::vec3 glmVec3, const ScriptVec3UChar& vec3);
};
inline QDebug operator<<(QDebug debug, const ScriptVec3UChar& vec3) {
debug << "(" << vec3.x << "," << vec3.y << "," << vec3.z << ")";
debug << "{" << vec3.x << "," << vec3.y << "," << vec3.z << "}";
return debug;
}
inline bool operator==(glm::vec3 glmVec3, const ScriptVec3UChar& vec3) { return (glmVec3.x == vec3.x && glmVec3.y == vec3.y && glmVec3.z == vec3.z); }

View file

@ -132,9 +132,9 @@ HifiEntityUI.prototype = {
var red = document.getElementById(key + "-red");
var blue = document.getElementById(key + "-blue");
var green = document.getElementById(key + "-green");
vector.red = red.value;
vector.blue = blue.value;
vector.green = green.value;
vector.x = red.value;
vector.y = blue.value;
vector.z = green.value;
} else if (el.className.indexOf("pyr") !== -1) {
var p = document.getElementById(key + "-Pitch");
var y = document.getElementById(key + "-Yaw");
@ -209,15 +209,12 @@ HifiEntityUI.prototype = {
} else if (field.className.indexOf("vector-section") !== -1) {
if (field.className.indexOf("rgb") !== -1) {
var red = document.getElementById(value + "-red");
var blue = document.getElementById(value + "-blue");
var green = document.getElementById(value + "-green");
red.value = parseInt(property.red);
blue.value = parseInt(property.blue);
green.value = parseInt(property.green);
var blue = document.getElementById(value + "-blue");
red.oninput({
target: red
});
red.value = parseInt(property.x);
green.value = parseInt(property.y);
blue.value = parseInt(property.z);
} else if (field.className.indexOf("xyz") !== -1) {
var x = document.getElementById(value + "-x");
var y = document.getElementById(value + "-y");
@ -468,9 +465,9 @@ HifiEntityUI.prototype = {
domArray[1].value = rgb.g;
domArray[2].value = rgb.b;
self.webBridgeSync(group.id, {
red: rgb.r,
green: rgb.g,
blue: rgb.b
x: rgb.r,
y: rgb.g,
z: rgb.b
});
},
onSubmit: function (hsb, hex, rgb, el) {
@ -482,9 +479,9 @@ HifiEntityUI.prototype = {
domArray[1].value = rgb.g;
domArray[2].value = rgb.b;
self.webBridgeSync(group.id, {
red: rgb.r,
green: rgb.g,
blue: rgb.b
x: rgb.r,
y: rgb.g,
z: rgb.b
});
}
});

View file

@ -69,10 +69,10 @@ ParticleExplorerTool = function(createToolsWindow) {
if (isNaN(properties.radiusFinish)) {
properties.radiusFinish = properties.particleRadius;
}
if (isNaN(properties.colorStart.red)) {
if (isNaN(properties.colorStart.x)) {
properties.colorStart = properties.color;
}
if (isNaN(properties.colorFinish.red)) {
if (isNaN(properties.colorFinish.x)) {
properties.colorFinish = properties.color;
}
sendParticleProperties(properties);
@ -113,7 +113,7 @@ ParticleExplorerTool = function(createToolsWindow) {
var fallbackValue = updatedSettings[fallbackProp];
if (fallbackValue) {
var optionalProp = optionalProps[i];
if ((fallbackProp !== "color" && isNaN(entityProps[optionalProp])) || (fallbackProp === "color" && isNaN(entityProps[optionalProp].red))) {
if ((fallbackProp !== "color" && isNaN(entityProps[optionalProp])) || (fallbackProp === "color" && isNaN(entityProps[optionalProp].x))) {
that.updatedActiveParticleProperties[optionalProp] = fallbackValue;
needsUpdate = true;
}