Archive

Archive for the ‘Silverlight’ Category

Silverlight 5 RTW 3D

December 13, 2011 Leave a comment

As many of you will know Microsoft released Silverlgiht 5 RTW over the weekend.

Read about the release over at Pete Brown’s blog http://10rem.net/blog/2011/12/09/announcing-the-release-of-silverlight-5

Get the ‘Bits’ from http://www.silverlight.net/downloads

I have updated the 3D Campus map test application I developed with the SL5 Beta and RC tools (https://drmcg.wordpress.com/2011/09/05/imap-3d-campus-map-in-3d-thanks-to-silverlight-5/) to RTW which did not require any changes to the code….

Until I tried to run it.

I then stuck the issue with graphics locked down for “Security”

luckily I was able to find som information about this in the documentation and http://www.sharpgis.net/post/2011/12/10/Why-Silverlight-5%E2%80%99s-3D-is-(almost)-useless.aspx and http://blogs.msdn.com/b/eternalcoding/archive/2011/12/10/silverlight-5-is-out.aspx

I have now added a block of code to check if 3D can be run (this could easily be refactored into something smaller)

 System.Windows.Controls.ChildWindow cw = new System.Windows.Controls.ChildWindow();

        bool messageShown;

        void TestRenderMode()
        {
            if (GraphicsDeviceManager.Current.RenderMode != RenderMode.Hardware)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                TextBlock tb = new TextBlock();
                switch (GraphicsDeviceManager.Current.RenderModeReason)
                {
                    case RenderModeReason.GPUAccelerationDisabled:

                    case RenderModeReason.SecurityBlocked:
                        sb.AppendLine("1. Right click on your Silverlight plug-in.");
                        sb.AppendLine("2. Click the 'Silverlight' option.");
                        sb.AppendLine("3. Go to the permissions tab.");
                        sb.AppendLine("4. Find the domain '" + Application.Current.Host.Source.AbsoluteUri.Substring(0, Application.Current.Host.Source.AbsoluteUri.IndexOf(Application.Current.Host.Source.LocalPath)) + "'");
                        sb.AppendLine("5. When you find the entry, select the item below it '3D Graphics: use blocked display drivers'.");
                        sb.AppendLine("6. Click 'Allow'");
                        sb.AppendLine("7. Click 'Ok'");
                        sb.AppendLine("8. Refresh Page");

                        tb.TextWrapping = TextWrapping.Wrap;
                        tb.Text = sb.ToString();

                        cw.Width = 500;
                        cw.HasCloseButton = false;

                        cw.Content = tb;
                        cw.Title = "Cannot Load 3D. Please Follow instructions below";

                        if (!messageShown)
                        {
                            messageShown = true;
                            cw.Show();
                        }

                        return;
                    case RenderModeReason.Not3DCapable:
                        sb.AppendLine("Your Graphics card does not support 3D");

                        tb.TextWrapping = TextWrapping.Wrap;
                        tb.Text = sb.ToString();

                        cw.Width = 500;
                        cw.HasCloseButton = false;

                        cw.Content = tb;
                        cw.Title = "Cannot Load 3D.";

                        if (!messageShown)
                        {
                            messageShown = true;
                            cw.Show();
                        }

                        return;
                    case RenderModeReason.TemporarilyUnavailable:
                        sb.AppendLine("1. Right click on your Silverlight plug-in.");
                        sb.AppendLine("2. Click the 'Silverlight' option.");
                        sb.AppendLine("3. Go to the permissions tab.");
                        sb.AppendLine("4. Find the domain '" + Application.Current.Host.Source.AbsoluteUri.Substring(0, Application.Current.Host.Source.AbsoluteUri.IndexOf(Application.Current.Host.Source.LocalPath)) + "'");
                        sb.AppendLine("5. When you find the entry, select the item below it '3D Graphics: use blocked display drivers'.");
                        sb.AppendLine("6. Click 'Allow'");
                        sb.AppendLine("7. Click 'Ok'");

                        tb.TextWrapping = TextWrapping.Wrap;
                        tb.Text = sb.ToString();

                        cw.Width = 500;
                        cw.HasCloseButton = false;

                        cw.Content = tb;
                        cw.Title = "Cannot Load 3D. Please Follow instructions below";

                        if (!messageShown)
                        {
                            messageShown = true;
                            cw.Show();
                        }

                        return;
                }
            }

            cw.Close();

            LoadScene();
        }
        

As Morten on SharpGIS above says, it would be great if the allow/deny model was the same as is implmented for allowing access to the Microphone/Webcam or allowing the application to remain full screen when it looses focus.

Hopefully there with be a GDR update that will add this dialog but in the mean time we will have to add the step-by-step instructions to direct the user to allow 3D to be run, or request the user to run your application with Elevated Privilages.

[Update: Removed link as website is no longer live]

Please let me know in the comments if you think the wording needs improvement, or any comments about the app. Please also note that this is not a final application just an initial test.

You can move round the map by clicking & dragging, or using the keys W S A D, you can also change the altitude of the camera by rolling the mouse wheel. You can click on a builidng or hold down CTRL and click multiple buildings. You can also adjust the Pitch of the camera with the Pitch slider at the top left, or move to ground level to “Walk Around” by clicking “Walk Around Toggle”.

You get great performance with the new XNA based 3D in Silverlight 5, and I look foward to seeing what people can do with it.

iMap 3D Campus Map in 3D thanks to Silverlight 5

September 5, 2011 1 comment

With the impending release of Silverlgiht 5 and the release of the Beta and RC we have been able to produce with our existing triangulated dataset a 3D campus scene using the power of XNA in Sliverlight 5.

We are able to build up the scene and move the camera through it. This is something I have always looked at that would be quite exciting, and give users a new perspecive of the University and how to navigate it.

The following are small set of screenshots from the trial application which we have developed to test 3D in Silverlgiht 5

Solid shaded 3D campus scene

Wireframe of the above 3D campus scene

We also have the ability to walk through the 3D scene and see our buildings from a whole new perspective.

Categories: 3D, iMap, Silverlight, Silverlight 5

Extend MapPolygon to allow binding to Fill Parameter

The Silverlight Bing Maps Control library has a MapPolygon control to allow you to overlay geo-located polygons over your Bing Map.

The MapPolygon control has a property Fill that is used to set the fill Brush for the polygon, but there is no DependencyProperty for the Fill property and it cannot be set using a Binding statement in XAML.
One Solution for this is to extend the MapPolygon control to add a DependencyProperty for Fill.
Here is how you may implement this:
Public Class MapPolygonExtended
   Inherits Microsoft.Maps.MapControl.MapPolygon

   Public Shared ReadOnly FillProperty As DependencyProperty =
         DependencyProperty.Register("Fill", GetType(Brush),
             GetType(MapPolygonExtended),
             New PropertyMetadata(New PropertyChangedCallback(AddressOf FillChangedCallback)))

   Public Overloads Property Fill() As Brush
      Get
         Return MyBase.Fill
      End Get
      Set(ByVal value As Brush)
         MyBase.Fill = value
      End Set
   End Property

   Private Shared Sub FillChangedCallback(ByVal d As DependencyObject,
             ByVal e As DependencyPropertyChangedEventArgs)
      Dim dlb As MapPolygonExtended = CType(d, MapPolygonExtended)
      dlb.Fill = CType(e.NewValue, Brush)
   End Sub

End Class
This then allows you to bind to the Fill property of your new extended control:
<local:MapPolygonExtended Fill=”{Binding Path=FillColour}” >
    <!-- Set other polygon properties like Locations with binding -->
</local:MapPolygonExtended>
If the bound property is already of type Brush then it should just work as long as you have set the locations for the points of the polygon.

If it is another type such as a Color or String then you will need to use a binding converter.

I hope this can help people setup bound MapPolygon.

Happy Coding and Mapping
Categories: 3D, Bing Maps, Silverlight, Tutorial

iMap on Windows Phone 7 (with screenshots)

August 11, 2010 2 comments

I have now been able to setup the iMap map control to run on the Windows Phone 7 emulator.

I have had to revert the code back to Silverlgiht 3 as I was getting errors due to the different versions of mscorlib between Silverlight 4 and Silverlight for Windows Phone 7.

At this point in time iMap is kind of slow on WP7 but I am able to show 3D buildings and change the pitch of the map.

The Bing/Local tile layers seem to stall in loading which is why the screenshots look a bit odd.

I assume this is because although the building models are not in the visual tree, they are still using memory.

Here is a side by side comparison of the Silverlight 4 Web aplication and the WP7 application

I have also been able to load the building floor plans on the WP7.


The floor plan is fully rotatable, pitch and angle, just like the web version as it is essentially the same code.

I think this is pretty cool, just need to make a few optimisations to impove perfomance but i seems that WP7 would be a viable platform for iMap handheld.

Now I just need to get my hands on some actual hardware and we will see how it runs.

Please if you have any thoughts or comments please leve them below.

New Performance Improvements

Welcome to another installment about the development of 3D onto Bing Maps Silverlight control (University of Otago – Interactive Campus Map, iMap)

Recently the performance of iMap has become rather slow, which an increase in displayed elements.

I have started to improve performance of loading/usability by removing objects (buildings) from the visual tree if they do not fit in the current viewable area, then adding them back in when they are within the viewable area.

One performance downside of this is that the adding and removing of a large number of UIElements form the visual tree such as when going from viewing the whole of the Dunedin campus to viewing the Invercargill campus is slow and the application freezes and the view does not transition to the new location it just jumps.
There may be some background way to remove these items without the performance loss, which is something I will look into.

Thank you for the positive comments we have received for the application and please if you have any please use the “iMap Feedback” button at the bottom left of the application to send us any feedback.

Duncan

Bing Maps with 3D Buildings: Some Detail

January 19, 2010 Leave a comment

Hello to all whom are interested.

I was asked if I could expalin how I setup the binding of psudo 3D (3D transofrmed to 2D) buildings to the Bing Maps Silverlight control.

Here is a basic overview, I will do into more detail later.

On the map I have a Canvas bound to a LocationRect which is at the Longitude/Latitude bounds of each building.

To handle scaling I have setup handling of the LayoutUpdated event on the Canvas, passing in the Canvas as a paramater, using an EventHandler Delegate, since the LayoutUpdated event does not pass in a sender object.

In this handler I get the Transform from the canvas to the Map control so I can transform the position of the Canavs to the position on the screen, this is where I set the Canvas.Left and Canvas.Top onf the Model Canvas to the same screen position.
Then I also get the ActualWidth and ActualHeight of the Canvas on the Map control and use a ScaleTransform to scale up the Models Canvas.

Then Model Canvas is added to a Canvas that sits over the Map control (in the same clip region as the map so the models disapear is their base is not visible on the Map.

The model canvas contains the psudo 3D object to display on it.

In the next post I will provide more detail on how to convert 3D into 2D space, and also how to speed up transofrmation calcullations by only rendering updating visible objects.

Bing Maps Silverlight with 3D Buildings

January 18, 2010 2 comments

I have been working on how to get 3D Buildings only the Bing Maps Silverlight control.

Many people believe this to be impossible (or at least not possible for many years)

I have now worked out how this can be achieved. Have a look at the image below.

This is from the University of Otago iMap Campus map http://www.propserv.otago.ac.nz/iMap/

To access this view leave the “Bing Maps View” radio button selected and ckick on “Dunedin” in the menu

There is also a pitch control up the top right

When you mouse over the centre you will get up and down arrows

Click these to adjust the pitch.

Please let me know what you think

Categories: 3D, Bing Maps, iMap, Silverlight

Silverlight in General & Silverlight 4 Beta

November 23, 2009 Leave a comment

I was both surprised and impressed to see Silverlight 4 Beta released at PDC09.

I have been highly impressed with the development speed and features of Silverlight.
As you will see from my other posts I have been developing with Silverlight since Silverlight 1 where we just have JavaScript as a client programming language.

We currently run all of our web facing applications with Silverlight 3.
As we are serving external users we are still maintaining a “static” (as in not evolving) ASP.NET version of some of our applications such as the Web Cameras so that users don’t miss out because they don’t want to, or, due to IT policies, they cannot install Silverlight.

I am impressed with users visiting from countries other than New Zealand, and major corporations, as they, in most cases, have Silverlight already installed and can enjoy the latest fully functional version of our web applications.

There are many people whom refuse to install Silverlight purely because it is a Microsoft product, we have to respect this decision, just like people still wanting to use IE 6 🙂

Looking at the capabilities of Silverlight 4 Beta I look forward to upgrading our applications to take advantage of the new capabilities.

Congrats Microsoft Silverlight Team

iMap going Live

January 22, 2009 Leave a comment

The 3D campus map Silverlight website I have been working on is going live tomorrow with a story in the staff buletin.

The website has been named “iMap” meaning interactive map.

I have moved to writing my own 3D engine as it allowed access to all the objects I require and I can quickly and easily change the colour of models as compared to Kit 3D which can take a while to change.

If you have the appropriate access rights the building floor plans can be viewed in full 3D you can rotate it and view the building as a full stacked building.

If you would like to view the iMap then goto http://www.propserv.otago.ac.nz/iMap

Let me know what you think by using the iMap feedback link at the bottom left of the website.

Categories: 3D, iMap, Silverlight

Silverlight 3D using Kit3D

I have been continuing my work on our campus plans website (Silverlight application)

For the display of the campus I have decides to move from the pseudo 3D version to an actual 3D plan.
I have chosen Kit3D by Mark Dawson http://www.markdawson.org/Kit3D

Here is the current result:

I have keys setup to navigate the 3D model, e.g. left arrow to rotate left

One issue this I am facing with Kit3D is that when I move the camera in closer to the “ground” some triangles/faces appear in front of the camera so you cannot see the models that should be in front of you.

An advantage of having the campus in 3d is the future ability to send the camera through the campus, between the buildings, to perhaps show how to get from one building to another, or just to show a virtual tour of the campus.

There are plenty of possibilities which is very exciting, and I’m really enjoying the task.

Categories: 3D, iMap, Silverlight