From 595d68567208b47016f96b9c6f960f96c5e73f1f Mon Sep 17 00:00:00 2001 From: Joseph Birkner Date: Thu, 19 Oct 2023 16:53:23 +0200 Subject: [PATCH] CesiumPrimitive supports Polygons and Triangles. --- libs/core/src/cesium-interface/primitive.cpp | 87 ++++++++++++++++---- 1 file changed, 70 insertions(+), 17 deletions(-) diff --git a/libs/core/src/cesium-interface/primitive.cpp b/libs/core/src/cesium-interface/primitive.cpp index 4f879980..bdcc5b45 100644 --- a/libs/core/src/cesium-interface/primitive.cpp +++ b/libs/core/src/cesium-interface/primitive.cpp @@ -12,33 +12,86 @@ CesiumPrimitive CesiumPrimitive::withPolylineColorAppearance() return result; } -void CesiumPrimitive::addLine(JsValue const& pointList, FeatureStyleRule const& style, uint32_t id) +CesiumPrimitive CesiumPrimitive::withPerInstanceColorAppearance() { - auto polyline = Cesium().PolylineGeometry.New(*JsValue::newDict({ - {"positions", pointList}, + CesiumPrimitive result; + result.appearance_ = Cesium().PerInstanceColorAppearance.New(); + return result; +} + +void CesiumPrimitive::addPolyLine( + JsValue const& vertices, + FeatureStyleRule const& style, + uint32_t id) +{ + auto polyline = Cesium().PolylineGeometry.New({ + {"positions", vertices}, {"width", JsValue(style.width())}, {"arcType", Cesium().ArcType["NONE"]} - })); + }); + addGeometryInstance(style, id, polyline); +} + +void CesiumPrimitive::addPolygon( + const JsValue& vertices, + const FeatureStyleRule& style, + uint32_t id) +{ + auto polygon = Cesium().PolygonGeometry.New({ + {"polygonHierarchy", Cesium().PolygonHierarchy.New(*vertices)}, + {"arcType", Cesium().ArcType["GEODESIC"]}, + {"perPositionHeight", JsValue(true)} + }); + addGeometryInstance(style, id, polygon); +} + +void CesiumPrimitive::addTriangles( + const JsValue& float64Array, + const FeatureStyleRule& style, + uint32_t id) +{ + auto geometry = Cesium().Geometry.New({ + {"attributes", JsValue::Dict({ + {"position", Cesium().GeometryAttribute.New({ + {"componentDatatype", Cesium().ComponentDatatype["DOUBLE"]}, + {"componentsPerAttribute", JsValue(3)}, + {"values", float64Array} + })} + })} + }); + addGeometryInstance(style, id, geometry); +} + +void CesiumPrimitive::addGeometryInstance( + const FeatureStyleRule& style, + uint32_t id, + const JsValue& geom) +{ auto const& color = style.color(); - auto geometryInstance = Cesium().GeometryInstance.New(*JsValue::newDict({ - {"geometry", polyline}, - {"attributes", JsValue::newDict({ - {"color", Cesium().ColorGeometryInstanceAttribute.New( - color.r, color.g, color.b, color.a)}})}, + auto geometryInstance = Cesium().GeometryInstance.New({ + {"geometry", geom}, + {"attributes", + JsValue::Dict( + {{"color", + Cesium().ColorGeometryInstanceAttribute.New(color.r, color.g, color.b, color.a)}})}, {"id", JsValue(id)} - })); + }); + ++numGeometryInstances_; geometryInstances_.push(geometryInstance); } -NativeJsValue CesiumPrimitive::toJsObject() +NativeJsValue CesiumPrimitive::toJsObject() const { - auto result = Cesium().Primitive.New(*JsValue::newDict( - { - {"geometryInstances", geometryInstances_}, - {"appearance", appearance_}, - {"releaseGeometryInstances", JsValue(true)} - })); + auto result = Cesium().Primitive.New(*JsValue::Dict( + {{"geometryInstances", geometryInstances_}, + {"appearance", appearance_}, + {"releaseGeometryInstances", JsValue(true)}})); return *result; } +bool CesiumPrimitive::empty() const +{ + return numGeometryInstances_ == 0; +} + }