Showing the changes to libraries/script-engine/src/ScriptValueUtils.cpp (1 of 76 files). Show all
Unified · Split
| @@ -35,6 +35,7 @@ · 34 unmodified lines | ||
| 35 | 35 | #include "ScriptEngineLogging.h" |
| 36 | 36 | #include "v8/FastScriptValueUtils.h" |
| 37 | 37 | #include "AddressManager.h" |
| 38 | +#include "Sampler.h" | |
| 38 | 39 | |
| 39 | 40 | bool isListOfStrings(const ScriptValue& arg) { |
| 40 | 41 | if (!arg.isArray()) { |
| @@ -405,6 +406,35 @@ ScriptValue vec4toScriptValue(ScriptEngine* engine, const glm::vec4& vec4) { · 364 unmodified lines | ||
| 405 | 406 | return obj; |
| 406 | 407 | } |
| 407 | 408 | |
| 409 | +ScriptValue vec4ColorToScriptValue(ScriptEngine* engine, const glm::vec4& vec4) { | |
| 410 | + auto prototype = engine->globalObject().property("__hifi_vec4_color__"); | |
| 411 | + if (!prototype.property("defined").toBool()) { | |
| 412 | + prototype = engine->evaluate( | |
| 413 | + "globalThis.__hifi_vec4_color__ = Object.defineProperties({}, { " | |
| 414 | + "defined: { value: true }," | |
| 415 | + "0: { set: function(nv) { return this.red = nv; }, get: function() { return this.red; } }," | |
| 416 | + "1: { set: function(nv) { return this.green = nv; }, get: function() { return this.green; } }," | |
| 417 | + "2: { set: function(nv) { return this.blue = nv; }, get: function() { return this.blue; } }," | |
| 418 | + "3: { set: function(nv) { return this.alpha = nv; }, get: function() { return this.alpha; } }," | |
| 419 | + "r: { set: function(nv) { return this.red = nv; }, get: function() { return this.red; } }," | |
| 420 | + "g: { set: function(nv) { return this.green = nv; }, get: function() { return this.green; } }," | |
| 421 | + "b: { set: function(nv) { return this.blue = nv; }, get: function() { return this.blue; } }," | |
| 422 | + "a: { set: function(nv) { return this.alpha = nv; }, get: function() { return this.alpha; } }," | |
| 423 | + "x: { set: function(nv) { return this.red = nv; }, get: function() { return this.red; } }," | |
| 424 | + "y: { set: function(nv) { return this.green = nv; }, get: function() { return this.green; } }," | |
| 425 | + "z: { set: function(nv) { return this.blue = nv; }, get: function() { return this.blue; } }," | |
| 426 | + "a: { set: function(nv) { return this.alpha = nv; }, get: function() { return this.alpha; } }" | |
| 427 | + "})"); | |
| 428 | + } | |
| 429 | + ScriptValue value = engine->newObject(); | |
| 430 | + value.setProperty("red", vec4.x); | |
| 431 | + value.setProperty("green", vec4.y); | |
| 432 | + value.setProperty("blue", vec4.z); | |
| 433 | + value.setProperty("alpha", vec4.w); | |
| 434 | + value.setPrototype(prototype); | |
| 435 | + return value; | |
| 436 | +} | |
| 437 | + | |
| 408 | 438 | bool vec4FromScriptValue(const ScriptValue& object, glm::vec4& vec4) { |
| 409 | 439 | vec4.x = object.property("x").toVariant().toFloat(); |
| 410 | 440 | vec4.y = object.property("y").toVariant().toFloat(); |
| @@ -1059,4 +1089,69 @@ QVector<QString> qVectorQStringFromScriptValue(const ScriptValue& array) { · 648 unmodified lines | ||
| 1059 | 1089 | newVector << string; |
| 1060 | 1090 | } |
| 1061 | 1091 | return newVector; |
| 1062 | −} | |
| 1092 | +} | |
| 1093 | + | |
| 1094 | +ScriptValue samplerToScriptValue(ScriptEngine* engine, const Sampler& sampler) { | |
| 1095 | + ScriptValue obj = engine->newObject(); | |
| 1096 | + obj.setProperty("borderColor", vec4ColorToScriptValue(engine, sampler.getBorderColor())); | |
| 1097 | + Sampler::Filter filter = sampler.getFilter(); | |
| 1098 | + switch (filter) { | |
| 1099 | + case Sampler::Filter::FILTER_MIN_MAG_POINT: | |
| 1100 | + obj.setProperty("minFilter", qStringToScriptValue(engine, "point")); | |
| 1101 | + obj.setProperty("magFilter", qStringToScriptValue(engine, "point")); | |
| 1102 | + break; | |
| 1103 | + case Sampler::Filter::FILTER_MIN_LINEAR_MAG_POINT: | |
| 1104 | + obj.setProperty("minFilter", qStringToScriptValue(engine, "linear")); | |
| 1105 | + obj.setProperty("magFilter", qStringToScriptValue(engine, "point")); | |
| 1106 | + break; | |
| 1107 | + case Sampler::Filter::FILTER_MIN_MAG_MIP_POINT: | |
| 1108 | + obj.setProperty("minFilter", qStringToScriptValue(engine, "mipmapPoint")); | |
| 1109 | + obj.setProperty("magFilter", qStringToScriptValue(engine, "point")); | |
| 1110 | + break; | |
| 1111 | + case Sampler::Filter::FILTER_MIN_MAG_POINT_MIP_LINEAR: | |
| 1112 | + obj.setProperty("minFilter", qStringToScriptValue(engine, "mipmapLinear")); | |
| 1113 | + obj.setProperty("magFilter", qStringToScriptValue(engine, "point")); | |
| 1114 | + break; | |
| 1115 | + case Sampler::Filter::FILTER_MIN_LINEAR_MAG_MIP_POINT: | |
| 1116 | + obj.setProperty("minFilter", qStringToScriptValue(engine, "linearMipmapPoint")); | |
| 1117 | + obj.setProperty("magFilter", qStringToScriptValue(engine, "point")); | |
| 1118 | + break; | |
| 1119 | + case Sampler::Filter::FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR: | |
| 1120 | + obj.setProperty("minFilter", qStringToScriptValue(engine, "linearMipmapLinear")); | |
| 1121 | + obj.setProperty("magFilter", qStringToScriptValue(engine, "point")); | |
| 1122 | + break; | |
| 1123 | + case Sampler::Filter::FILTER_MIN_POINT_MAG_LINEAR: | |
| 1124 | + obj.setProperty("minFilter", qStringToScriptValue(engine, "point")); | |
| 1125 | + obj.setProperty("magFilter", qStringToScriptValue(engine, "linear")); | |
| 1126 | + break; | |
| 1127 | + case Sampler::Filter::FILTER_MIN_MAG_LINEAR: | |
| 1128 | + obj.setProperty("minFilter", qStringToScriptValue(engine, "linear")); | |
| 1129 | + obj.setProperty("magFilter", qStringToScriptValue(engine, "linear")); | |
| 1130 | + break; | |
| 1131 | + case Sampler::Filter::FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT: | |
| 1132 | + obj.setProperty("minFilter", qStringToScriptValue(engine, "mipmapPoint")); | |
| 1133 | + obj.setProperty("magFilter", qStringToScriptValue(engine, "linear")); | |
| 1134 | + break; | |
| 1135 | + case Sampler::Filter::FILTER_MIN_POINT_MAG_MIP_LINEAR: | |
| 1136 | + obj.setProperty("minFilter", qStringToScriptValue(engine, "mipmapLinear")); | |
| 1137 | + obj.setProperty("magFilter", qStringToScriptValue(engine, "linear")); | |
| 1138 | + break; | |
| 1139 | + case Sampler::Filter::FILTER_MIN_MAG_LINEAR_MIP_POINT: | |
| 1140 | + obj.setProperty("minFilter", qStringToScriptValue(engine, "linearMipmapPoint")); | |
| 1141 | + obj.setProperty("magFilter", qStringToScriptValue(engine, "linear")); | |
| 1142 | + break; | |
| 1143 | + case Sampler::Filter::FILTER_MIN_MAG_MIP_LINEAR: | |
| 1144 | + obj.setProperty("minFilter", qStringToScriptValue(engine, "linearMipmapLinear")); | |
| 1145 | + obj.setProperty("magFilter", qStringToScriptValue(engine, "linear")); | |
| 1146 | + break; | |
| 1147 | + } | |
| 1148 | + obj.setProperty("wrapModeU", qStringToScriptValue(engine, wrapModeToString(sampler.getWrapModeU()))); | |
| 1149 | + obj.setProperty("wrapModeV", qStringToScriptValue(engine, wrapModeToString(sampler.getWrapModeV()))); | |
| 1150 | + obj.setProperty("wrapModeW", qStringToScriptValue(engine, wrapModeToString(sampler.getWrapModeW()))); | |
| 1151 | + return obj; | |
| 1152 | +} | |
| 1153 | + | |
| 1154 | +bool samplerFromScriptValue(const ScriptValue& object, Sampler& sampler) { | |
| 1155 | + sampler = Sampler::parseSampler(QJsonObject::fromVariantMap(object.toVariant().toMap())); | |
| 1156 | + return true; | |
| 1157 | +} | |