agi_CustomPatternSensor not visible

I’ve written code to generate a Custom Sensor Pattern and a polyline volume pattern, using czml-writer. the polyline looks great, but the Custom Sensor Pattern is not showing on either CesiumJs or with the ION SDK. Is there something I’m missing?

CustomSphericalSensor.czml (1.8 KB)

 /// <summary>
/// Generates a complete CZML string containing a Custom Sensor Pattern.
/// </summary>
public static string GenerateCustomSensorPattern(
    string id,
    string name,
    Cartesian position,
    List<Spherical> directions,
    double radius,
    int r, int g, int b, int a = 255)
{
    using (StringWriter stringWriter = new StringWriter())
    {
        CesiumOutputStream output = new CesiumOutputStream(stringWriter);
        CesiumStreamWriter writer = new CesiumStreamWriter();

        output.WriteStartSequence();

        // 1. Write the initial document packet
        WriteDocumentPacket(writer, output);

        // 2. Write the Custom Sensor packet
        using (var packet = writer.OpenPacket(output))
        {
            packet.WriteId(id);
            packet.WriteName(name);

            // Set the origin position
            using (var posWriter = packet.OpenPositionProperty())
            {
                posWriter.WriteCartesian(position);
            }

            // Define the custom pattern sensor
            using (var sensor = packet.OpenCustomPatternSensorProperty())
            {
                 using (var interval = sensor.OpenInterval())
                {
                    // Ensure the sensor is visible
                    interval.WriteShowProperty(true);

                    // Set the radius (length of the sensor beam)
                    interval.WriteRadiusProperty(radius);

                    // Open and write the directions (the pattern/shape of the beam)
                    using (var dirWriter = interval.OpenDirectionsProperty())
                    {
                        dirWriter.WriteSpherical(directions);
                    }

                    // Set the lateral surface material (color of the sensor volume)
                    using (var material = interval.OpenLateralSurfaceMaterialProperty())
                    {
                        using (var solidColor = material.OpenSolidColorProperty())
                        {
                            using (var colorWriter = solidColor.OpenColorProperty())
                            {
                                colorWriter.WriteRgba(r, g, b, a);
                            }
                        }
                    }
                }
            }
        }

        output.WriteEndSequence();
        return stringWriter.ToString();
    }
}

Hi Ted,

Sensors require the entity to have both position and orientation defined in order to be rendered.

1 Like

Thanks Scott - I’ll add that and give it a try.

Adding an orientation got me further, but I’m seeing another error now.

This is the input:

double angle = Math.PI / 4.0;
double sinAngle2 = Math.Sin(angle / 2.0);
double cosAngle2 = Math.Cos(angle / 2.0);

UnitQuaternion sensorRotation = new UnitQuaternion(cosAngle2, 0.0, sinAngle2, 0.0);

And the property:

using (var orWriter = packet.OpenOrientationProperty())
{
orWriter.WriteUnitQuaternion(sensorRotation);
}

CustomSphericalSensor.czml (1.9 KB)

Putting the stack trace into Gemini Canvas produced the result that adding the magnitude (using Spherical instead of UnitSpherical) to define the directions was the issue. That fixed it.