locked
Converting images to 3D from C#-code (tomha) - 4/11/2006 6:44 AM PST RRS feed

  • Question

  • By: tomha

    Hey,
    I am working on an application with two images where the user can change 
    which image is displayed. It's a photo album where the user adds pictures. So 
    far so good. The problem is that I want to do some 3D animations of the 
    selected images. This means that I have to convert the images to 3D object 
    from C# as the application is running. Is this possible? Does anyone know how?
    
    Another option is to have stable 3D objects but changing their source, is 
    this maybe a better way to go?
    
    greets,
    Tomas Hansson
    
    P.S. Why does the picture change shape when you turn them into 3D objects? 
    D.S.
    Monday, February 18, 2008 11:42 PM

Answers

  • By: Unni Ravindranathan (MS)
    Hi Thomas,

    Yes, you can change the source of the image from code. I can give you a code
    sample if you are interested. Please keep in mind that the sample will be
    heavily tied to the way you define your 3d model, so you will have to
    improvise. For example, if you add an extra material, things might break.

    However, I do recommend the databinding approach since it insulates the
    implementation from changes a bit. I think in your case, you have two lists:
    a) a List of Images that you want the user to select from, b) A List of
    images that you want. Once you implement the transfer logic, you can then
    think of the 3d animation also as an animation of the selected item in the
    second list. Then when the user switches to a different page, simply change
    the selected index property of the ListBox (or whatever control you are
    using for your Album) and this will result in the source of the 3d animation
    updating correctly. You can then re-run the animation.

    Thanks,
    -Unni
    --
    This posting is provided "AS IS" with no warranties, and confers no rights.

    "Tomas Hansson" <tomha128@gmail.com> wrote in message
    news:eg29534YGHA.4760@TK2MSFTNGP03.phx.gbl...

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 5:15 PM

All replies

  • By: Lingesh Palaniappan (MS)
    Hi,
    regarding making an image to a 3D object in run time you will need to write
    code. But you can change the image being displayed at run time using EID.
    you should use data binding for this. Put an image element from library into
    the scene. Set its height and width to what ever you like. Now data bind its
    source property.(I am assuming you know how to data bind. the following
    tutorial might be helpful:
    http://blogs.msdn.com/expression/articles/516566.aspx) So the source of the
    image element changes with respect to the element you bound to.

    Now tools->make image 3D. Build and run the application. You will get the
    desired effect.
    regards,
    Lingesh
    "tomha" <tomha@discussions.microsoft.com> wrote in message
    news:F9199AFC-4608-4593-B7F3-0648D86305AE@microsoft.com...

    Click to show or hide original message or reply text.


    Tuesday, February 19, 2008 5:09 PM
  • By: tomha
    Hi Lingesh,
    I know how to do databind, but I'm not sure about how to use it this time. I
    have a list of pictures which are loaded into a ListBox with databind. The
    user then uses drag and drop to place pictures in the two pages of the album.
    I change the image source from the code, depending on what object the user is
    dropping on the image area.

    Now I need to do the same thing but for 3D objects instead of images, so I
    need to edit the source of the 3D object from the code. How do I do this?

    For Images I use:
    Image1.Source = ...
    but this does not work for 3D objects.

    Hope you can give some advice...
    Regards,
    /Tomas

    "Lingesh Palaniappan (MS)" wrote:

    Click to show or hide original message or reply text.


    Tuesday, February 19, 2008 5:09 PM
  • By: Lingesh Palaniappan (MS)
    Hi,
    I was very busy today! I will reply in detail with a sample tomorrow
    morning.
    regards,
    Lingesh
    "tomha" <tomha@discussions.microsoft.com> wrote in message
    news:242B6A0B-6A19-475B-BCBC-012CAFF7102C@microsoft.com...

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 5:10 PM
  • By: Lingesh Palaniappan (MS)
    Hi,
    I have attached a project here. It has a list box which displays a bunch of
    images from your pictures folder(In case you dont have some specific images
    on your computer it will show a blank there). There is a 3D control nearby
    which is animating. When you select one of the images in the list box the 3D
    control would animate that image. I think this resembles what you want to
    do. Let us know if not. This was completely done in EID. I will put up a
    blog entry later tomorrow how this was done in EID and post it here.
    regards,
    Lingesh

    "Lingesh Palaniappan (MS)" <lipalani@microsoft.com> wrote in message
    news:eri1xBqXGHA.3448@TK2MSFTNGP04.phx.gbl...

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 5:11 PM
  • By: tomha
    Hi,
    That sounds very interesting, seems to be a thing similar to what I want to
    do. I can't find the attachment though, and on your blog
    (
    http://spaces.msn.com/lingesh/) I can't find it either. Can you give me a
    clearer instruction on where I can find the attachment?

    Thanks,
    Tomas

    "Lingesh Palaniappan (MS)" wrote:

    Click to show or hide original message or reply text.


    Tuesday, February 19, 2008 5:11 PM
  • By: Unni Ravindranathan (MS)
    Please use a newsgroup reader like Outlook Express to download attachments.

    Thanks!
    -Unni
    --
    This posting is provided "AS IS" with no warranties, and confers no rights.

    "tomha" <tomha@discussions.microsoft.com> wrote in message
    news:921812B8-B75F-401F-8071-A0EF279950FE@microsoft.com...

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 5:12 PM
  • By: Tomas Hansson
    Ah, thanks Unni. Now I finally had a chance to test the attached
    application. It does not, however, solve my problem. I can't use a standard
    databind for my problem, I will try to explain why.

    I am creating a photo album editor, where the user can select images from a
    list and add them to the album. The album has several pages, and the user
    can flip through them. I save the information about the images in an array
    (C#-code), so that when the user changes page in the album the program knows
    what images to present.

    The image I want to animate is the currently open page in the album, not
    just the selected item in a list. I need to get information from code about
    the source of the image I want to animate. Is this possible?

    The way I see it there are two solutions, either converting the images to 3D
    object from C# as the application is running or to have stable 3D objects
    but change their source (from code) during runtime. Is either of those
    possible?

    Best regards,

    Tomas Hansson

    "Unni Ravindranathan (MS)" <unnir@online.microsoft.com> schrieb im
    Newsbeitrag news:%230GWo6wYGHA.4580@TK2MSFTNGP03.phx.gbl...

    Click to show or hide original message or reply text.


    Tuesday, February 19, 2008 5:13 PM
  • By: Unni Ravindranathan (MS)
    Hi Thomas,

    Yes, you can change the source of the image from code. I can give you a code
    sample if you are interested. Please keep in mind that the sample will be
    heavily tied to the way you define your 3d model, so you will have to
    improvise. For example, if you add an extra material, things might break.

    However, I do recommend the databinding approach since it insulates the
    implementation from changes a bit. I think in your case, you have two lists:
    a) a List of Images that you want the user to select from, b) A List of
    images that you want. Once you implement the transfer logic, you can then
    think of the 3d animation also as an animation of the selected item in the
    second list. Then when the user switches to a different page, simply change
    the selected index property of the ListBox (or whatever control you are
    using for your Album) and this will result in the source of the 3d animation
    updating correctly. You can then re-run the animation.

    Thanks,
    -Unni
    --
    This posting is provided "AS IS" with no warranties, and confers no rights.

    "Tomas Hansson" <tomha128@gmail.com> wrote in message
    news:eg29534YGHA.4760@TK2MSFTNGP03.phx.gbl...

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 5:15 PM
  • By: tomha
    Thanks for the idea, will require some rebuilding of the application but I
    will try it.

    I would still appreciate it if you could give me a code exaple of how to
    change the source of a 3D object from code, then I can try this solution as
    well.

    Thanks,
    Tomas

    "Unni Ravindranathan (MS)" wrote:

    Click to show or hide original message or reply text.


    Tuesday, February 19, 2008 5:15 PM
  • By: Unni Ravindranathan (MS)
    Hi Tomas,

    Sure, here you go:

    GeometryModel3D geo = (GeometryModel3D)this.Sunset_jpgModel;
    DiffuseMaterial material = (DiffuseMaterial)geo.Material;
    ImageBrush brush = (ImageBrush)material.Brush;
    brush.ImageSource = new BitmapImage(new
    Uri("pack://application:,,,/Winter.jpg"));

    To work with example, create a new project. Add Sunset.jpg and Winter.jpg to
    the project. Insert Sunset.jpg into the scene and Tools -> Make Image 3D.
    Add a new button and update the event handler with the code above.

    Hope this helps!
    -Unni
    --
    This posting is provided "AS IS" with no warranties, and confers no rights.

    "tomha" <tomha@discussions.microsoft.com> wrote in message
    news:5E3F041D-84E0-4D15-8F69-D1220C4108F7@microsoft.com...

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 5:16 PM
  • By: tomha
    Hah, so easy when you don't have to figure out the code yourself :)

    The example work, now I just have to implement it in my photo album. Great!

    Thanks again,
    Tomas

    "Unni Ravindranathan (MS)" wrote:

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 5:18 PM
  • By: Lingesh Palaniappan (MS)
    Hi,
    if you use outlook express to read the newsgroup you should be able to find
    the attachment. Regarding the blog I am really sorry about that. We are
    extremely busy working on the next set of features in EID. But the blog will
    be updated as soon as this deadline is over. Possibly with in a week. Stay
    tuned. If you still cannot access the project let me know and I will upload
    it to some web site.
    regards,
    Lingesh
    "tomha" <tomha@discussions.microsoft.com> wrote in message
    news:921812B8-B75F-401F-8071-A0EF279950FE@microsoft.com...

    Click to show or hide original message or reply text.


    Tuesday, February 19, 2008 5:18 PM
  • By: MyWebTV
    Lingesh,

    I know you can turn 2d image into 3d model. Is a way to turn a group of
    control into 3d. ( I have control panel (Grid control ) with buttons,
    textbox, images on it. Can I turn the whole panel into 3D ?

    Thanks

    "Lingesh Palaniappan (MS)" wrote:

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 5:19 PM
  • By: Unni Ravindranathan (MS)
    Yes, you can create a Visual Brush out of this Panel (Select the Panel,
    Tools menu -> Make Tile Brush -> Make Visual Brush). You can then use this
    Visual Brush as a texture (similar to how you are using ImageBrushes in the
    other case of making an image 3d). However, please be aware that in WPF 1.0
    these controls will not be live (that is clicking on Button will not raise
    event etc.) - you will have to do your own hit-testing to provide
    interactivity when you do such texture mapping (using Visual Brushes).

    Thanks,
    -Unni
    --
    This posting is provided "AS IS" with no warranties, and confers no rights.

    "MyWebTV" <MyWebTV@discussions.microsoft.com> wrote in message
    news:13AD1EDC-CB82-4DF7-92EE-561E9982C61E@microsoft.com...

    Click to show or hide original message or reply text.

    Tuesday, February 19, 2008 5:20 PM