From 7bc7c2ed3a6321728f9a8e8e10dbb9befc52f8ff Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Thu, 30 Mar 2023 00:13:39 +0200 Subject: [PATCH] Fixed default render states for laser pointers --- .../src/raypick/PointerScriptingInterface.cpp | 67 ++++++++++--------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/interface/src/raypick/PointerScriptingInterface.cpp b/interface/src/raypick/PointerScriptingInterface.cpp index 192bf494f0..2ad27274c8 100644 --- a/interface/src/raypick/PointerScriptingInterface.cpp +++ b/interface/src/raypick/PointerScriptingInterface.cpp @@ -569,42 +569,47 @@ bool rayPointerPropertiesFromScriptValue(const ScriptValue& value, RayPointerPro // This copies properties from script value, but also converts entity properties of entities used in render states // from JS objects into EntityItemProperties out.properties = value.engine()->fromScriptValue(value); - if (out.properties["renderStates"].canConvert()) { - QVariantList renderStates = out.properties["renderStates"].value(); - for( int i = 0; i < renderStates.length(); i++) { - if (renderStates[i].canConvert()) { - QVariantMap stateMap = renderStates[i].value(); - if (stateMap["name"].canConvert()) { - stateMap["name"].value(); - } - if (stateMap["start"].isValid()) { - ScriptValue start = value.property("renderStates").property(i).property("start"); - EntityItemProperties startProperties; - startProperties.copyFromScriptValue(start, false); - stateMap.insert("startPropertyIndex", QVariant(out.entityProperties.length())); - out.entityProperties.append(startProperties); - } + QList renderStatesNames; + renderStatesNames.append("renderStates"); + renderStatesNames.append("defaultRenderStates"); + for (auto renderStatesName = renderStatesNames.cbegin(); renderStatesName!=renderStatesNames.cend(); renderStatesName++) { + if (out.properties[*renderStatesName].canConvert()) { + QVariantList renderStates = out.properties[*renderStatesName].value(); + for (int i = 0; i < renderStates.length(); i++) { + if (renderStates[i].canConvert()) { + QVariantMap stateMap = renderStates[i].value(); + if (stateMap["name"].canConvert()) { + stateMap["name"].value(); + } + if (stateMap["start"].isValid()) { + ScriptValue start = value.property(*renderStatesName).property(i).property("start"); + EntityItemProperties startProperties; + startProperties.copyFromScriptValue(start, false); + stateMap.insert("startPropertyIndex", QVariant(out.entityProperties.length())); + out.entityProperties.append(startProperties); + } - if (stateMap["path"].isValid()) { - ScriptValue path = value.property("renderStates").property(i).property("path"); - EntityItemProperties pathProperties; - pathProperties.copyFromScriptValue(path, false); - stateMap.insert("pathPropertyIndex", QVariant(out.entityProperties.length())); - out.entityProperties.append(pathProperties); - } + if (stateMap["path"].isValid()) { + ScriptValue path = value.property(*renderStatesName).property(i).property("path"); + EntityItemProperties pathProperties; + pathProperties.copyFromScriptValue(path, false); + stateMap.insert("pathPropertyIndex", QVariant(out.entityProperties.length())); + out.entityProperties.append(pathProperties); + } - if (stateMap["end"].isValid()) { - ScriptValue end = value.property("renderStates").property(i).property("end"); - EntityItemProperties endProperties; - endProperties.copyFromScriptValue(end, false); - stateMap.insert("endPropertyIndex", QVariant(out.entityProperties.length())); - out.entityProperties.append(endProperties); + if (stateMap["end"].isValid()) { + ScriptValue end = value.property(*renderStatesName).property(i).property("end"); + EntityItemProperties endProperties; + endProperties.copyFromScriptValue(end, false); + stateMap.insert("endPropertyIndex", QVariant(out.entityProperties.length())); + out.entityProperties.append(endProperties); + } + // V8TODO: Check if path is a polyline and if values are valid + renderStates[i].setValue(stateMap); } - // V8TODO: Check if path is a polyline and if values are valid - renderStates[i].setValue(stateMap); } + out.properties[*renderStatesName].setValue(renderStates); } - out.properties["renderStates"].setValue(renderStates); } qDebug() << "rayPointerPropertiesFromScriptValue" << out.properties; return true;