History

Fixed default render states for laser pointers

ksuprynowicz committed 3 years ago

Commit b0e030a1 parent 4062d801 file · +36 −31Browse files

Showing the changes to interface/src/raypick/PointerScriptingInterface.cpp (1 of 1 file). Show all

Unified · Split

interface/src/raypick/PointerScriptingInterface.cpp+36−31
@@ -569,42 +569,47 @@ bool rayPointerPropertiesFromScriptValue(const ScriptValue& value, RayPointerPro · 568 unmodified lines
569569 // This copies properties from script value, but also converts entity properties of entities used in render states
570570 // from JS objects into EntityItemProperties
571571 out.properties = value.engine()->fromScriptValue<QVariantMap>(value);
572− if (out.properties["renderStates"].canConvert<QVariantList>()) {
573− QVariantList renderStates = out.properties["renderStates"].value<QVariantList>();
574− for( int i = 0; i < renderStates.length(); i++) {
575− if (renderStates[i].canConvert<QVariantMap>()) {
576− QVariantMap stateMap = renderStates[i].value<QVariantMap>();
577− if (stateMap["name"].canConvert<QString>()) {
578− stateMap["name"].value<QString>();
579− }
580− if (stateMap["start"].isValid()) {
581− ScriptValue start = value.property("renderStates").property(i).property("start");
582− EntityItemProperties startProperties;
583− startProperties.copyFromScriptValue(start, false);
584− stateMap.insert("startPropertyIndex", QVariant(out.entityProperties.length()));
585− out.entityProperties.append(startProperties);
586− }
572+ QList<QString> renderStatesNames;
573+ renderStatesNames.append("renderStates");
574+ renderStatesNames.append("defaultRenderStates");
575+ for (auto renderStatesName = renderStatesNames.cbegin(); renderStatesName!=renderStatesNames.cend(); renderStatesName++) {
576+ if (out.properties[*renderStatesName].canConvert<QVariantList>()) {
577+ QVariantList renderStates = out.properties[*renderStatesName].value<QVariantList>();
578+ for (int i = 0; i < renderStates.length(); i++) {
579+ if (renderStates[i].canConvert<QVariantMap>()) {
580+ QVariantMap stateMap = renderStates[i].value<QVariantMap>();
581+ if (stateMap["name"].canConvert<QString>()) {
582+ stateMap["name"].value<QString>();
583+ }
584+ if (stateMap["start"].isValid()) {
585+ ScriptValue start = value.property(*renderStatesName).property(i).property("start");
586+ EntityItemProperties startProperties;
587+ startProperties.copyFromScriptValue(start, false);
588+ stateMap.insert("startPropertyIndex", QVariant(out.entityProperties.length()));
589+ out.entityProperties.append(startProperties);
590+ }
587591
588− if (stateMap["path"].isValid()) {
589− ScriptValue path = value.property("renderStates").property(i).property("path");
590− EntityItemProperties pathProperties;
591− pathProperties.copyFromScriptValue(path, false);
592− stateMap.insert("pathPropertyIndex", QVariant(out.entityProperties.length()));
593− out.entityProperties.append(pathProperties);
594− }
592+ if (stateMap["path"].isValid()) {
593+ ScriptValue path = value.property(*renderStatesName).property(i).property("path");
594+ EntityItemProperties pathProperties;
595+ pathProperties.copyFromScriptValue(path, false);
596+ stateMap.insert("pathPropertyIndex", QVariant(out.entityProperties.length()));
597+ out.entityProperties.append(pathProperties);
598+ }
595599
596− if (stateMap["end"].isValid()) {
597− ScriptValue end = value.property("renderStates").property(i).property("end");
598− EntityItemProperties endProperties;
599− endProperties.copyFromScriptValue(end, false);
600− stateMap.insert("endPropertyIndex", QVariant(out.entityProperties.length()));
601− out.entityProperties.append(endProperties);
600+ if (stateMap["end"].isValid()) {
601+ ScriptValue end = value.property(*renderStatesName).property(i).property("end");
602+ EntityItemProperties endProperties;
603+ endProperties.copyFromScriptValue(end, false);
604+ stateMap.insert("endPropertyIndex", QVariant(out.entityProperties.length()));
605+ out.entityProperties.append(endProperties);
606+ }
607+ // V8TODO: Check if path is a polyline and if values are valid
608+ renderStates[i].setValue(stateMap);
602609 }
603− // V8TODO: Check if path is a polyline and if values are valid
604− renderStates[i].setValue(stateMap);
605610 }
611+ out.properties[*renderStatesName].setValue(renderStates);
606612 }
607− out.properties["renderStates"].setValue(renderStates);
608613 }
609614 qDebug() << "rayPointerPropertiesFromScriptValue" << out.properties;
610615 return true;