AnalyticalGraphicsInc / czml-writer

A library for writing CZML content for use with Cesium.
Other
388 stars 142 forks source link

Add three more materials to polylines. #100

Closed emackey closed 8 years ago

emackey commented 9 years ago

Polylines are able to use non-polyline materials, such as stripe, grid, and image. Stripe makes dashed lines (be sure to set vertical stripes). Grid can be used to make lines with "tic marks" on them (this was easy and looks great). Image offers complete control over the static appearance of a line. Typically the image would be longer horizontally than vertically, as the horizontal direction is the one that stretches over the length of the line (regardless of the line's orientation in the world), and vertical stretches over its width.

Here's some sample code that can be added to the end of the ExampleCesiumLanguageServer near the end of the CZML writer (insert these lines near line 87, then un-comment one of the three line materials to test it).

                using (var line1 = cesiumWriter.OpenPacket(output))
                {
                    line1.WriteId("Example line 1");

                    using (var polyline = line1.OpenPolylineProperty())
                    {
                        using (var pos = polyline.OpenPositionsProperty())
                        {
                            pos.WriteReferences(new List<Reference> {
                                new Reference("point -10 10", "position"),
                                new Reference("point 10 -10", "position")
                            });
                        }

                        polyline.WriteWidthProperty(15.0);

                        using (var material = polyline.OpenMaterialProperty())
                        {
                            // Un-comment one of the three materials to test it.

                            /*
                            using (var stripe = material.OpenStripeProperty())
                            {
                                stripe.WriteRepeatProperty(20.0);
                                stripe.WriteOrientationProperty(CesiumStripeOrientation.Vertical);
                            }
                            */

                            /*
                            using (var grid = material.OpenGridProperty())
                            {
                                grid.WriteColorProperty(Color.Lime);
                                grid.WriteLineCountProperty(20.0, 1.0);
                                grid.WriteLineOffsetProperty(0.0, 0.5);
                                grid.WriteCellAlphaProperty(0.0);
                            }
                            */

                            /*
                            using (var img = material.OpenImageProperty())
                            {
                                img.WriteImageProperty(new CesiumResource(new Uri("foo.jpg", UriKind.Relative), CesiumResourceBehavior.LinkTo));
                            }
                            */
                        }
                    }
                }
mramato commented 9 years ago

If here is actually no difference between Polyline and non-polyline materials, we should eliminate the concept from the writer entirely, which would further simplify the code.

mramato commented 9 years ago

I'll add the caveat that it's been a while since I touched czml-writer code, so I'm not sure what's involved in doing so.

emackey commented 9 years ago

There's a PolylineOutlineMaterial that can't be a generic material. But any generic material can act as a polyline material.

emackey commented 9 years ago

So it looks like there's nothing fancy about generating polyline material code, it's just that the schema files treat it as completely separate from non-polyline materials. In particular, in Polyline.jsonschema, we have this:

        "material": {
            "$ref": "PolylineMaterial.jsonschema",
            "description": "The material to use to draw the polyline."
        },

Is there any way to modify this such that it accepts both PolylineMaterial.jsonschema and Material.jsonschema as the value?

emackey commented 8 years ago

For what it's worth, I'm still advocating that we merge this as-is.