Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - data binding in viewport3d

 
 
Old 02-08-2006   #1 (permalink)
Robin Senior


 
 

data binding in viewport3d

Is it possible to bind data in a Viewport3d so that 3d visuals can be
generated from data?

Something along the lines of ItemsControls and DataTemplates for
enumerating a list of data points and assigning coordinates etc to a
visual representation. This is simple to do in XAML for 2D controls,
but I'd like to do it for 3D elements.

I'm looking to dynamically populate the 3D scene, not just vary
properties of a scene element after it has been created.

Something along the lines of this:
http://www.beacosta.com/Archive/2005...a_archive.html

....only in a Viewport3d, not just by using Windows controls. I have yet
to find an elegant solution to this; the example at
http://therhogue.com/WinFX/ is great, but it's strange that binding is
so easy with 2D controls, but 3D requires hundreds of lines of code.

Cheers,
-robin


My System SpecsSystem Spec
Old 02-09-2006   #2 (permalink)
Erno


 
 

Re: data binding in viewport3d

Yes, you can. I did. Take a look at
http://blogs.infosupport.com/ernow/articles/3603.aspx
(look at the screenshots)

I created a class called RenderModel which contains the data and provided
some properties on that class to bind to.

Some code snippets (still work in progress...)

Model:

public class RenderData : INotifyPropertyChanged
{
private Point3DCollection _positions = new Point3DCollection();

public Point3DCollection Positions
{
get { return _positions; }
set { _positions = value; }
}

private Vector3DCollection _normals = new Vector3DCollection();

public Vector3DCollection Normals
{
get { return _normals; }
set { _normals = value; }
}

private PointCollection _textureCoordinates = new PointCollection();

public PointCollection TextureCoordinates
{
get { return _textureCoordinates; }
set { _textureCoordinates = value; }
}

private Int32Collection _triangleIndices = new Int32Collection();

public Int32Collection TriangleIndices
{
get { return _triangleIndices; }
set { _triangleIndices = value; }
}


private string _diffuseMaterialImagePath;

public string DiffuseMaterialImagePath
{
get { return _diffuseMaterialImagePath; }
set
{
_diffuseMaterialImagePath = value;
DiffuseMaterialImage = new BitmapImage(new
Uri(_diffuseMaterialImagePath, UriKind.Relative));
}
}

[XmlIgnore()]
private BitmapImage _diffuseMaterialImage;

[XmlIgnore()]
public BitmapImage DiffuseMaterialImage
{
get { return _diffuseMaterialImage; }
set { _diffuseMaterialImage = value;
OnNotifyPropertyChanged("DiffuseMaterialImage"); }
}




#region INotifyPropertyChanged Members

public event PropertyChangedEventHandler PropertyChanged;

protected void OnNotifyPropertyChanged(string propertyName)
{
PropertyChangedEventHandler p = PropertyChanged;
if (p != null)
{
p(this, new PropertyChangedEventArgs(propertyName));
}
}

#endregion
}
}


XAML:

<Viewport3D Name="ViewPort" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" ClipToBounds="True">
<Viewport3D.Camera>
<OrthographicCamera FarPlaneDistance="1000"
NearPlaneDistance="1" Position="0,0,100" LookDirection="0,0,-1"
UpDirection="0,1,0" Width="4"/>
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup x:Name="WireframeModel"/>
<Model3DGroup x:Name="RenderModel">
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D x:Name="TriangleData"/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<ImageBrush x:Name="DiffuseMaterialImage"/>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
</GeometryModel3D>
<AmbientLight Color="White"/>
</Model3DGroup>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>


Binding code:

private void BindModelData()
{
Binding bind;

bind = new Binding();
bind.Mode = BindingMode.OneWay;
bind.Source = _viewerData.Model.WireframeData;
bind.Path = new PropertyPath("Lines");
BindingOperations.SetBinding(WireframeModel,
Model3DGroup.ChildrenProperty, bind);

bind = new Binding();
bind.Mode = BindingMode.OneWay;
bind.Source = _viewerData.Model.RenderData;
bind.Path = new PropertyPath("DiffuseMaterialImage");
BindingOperations.SetBinding(DiffuseMaterialImage,
ImageBrush.ImageSourceProperty, bind);

bind = new Binding();
bind.Mode = BindingMode.OneWay;
bind.Source = _viewerData.Model.RenderData;
bind.Path = new PropertyPath("Positions");
BindingOperations.SetBinding(TriangleData,
MeshGeometry3D.PositionsProperty, bind);

bind = new Binding();
bind.Mode = BindingMode.OneWay;
bind.Source = _viewerData.Model.RenderData;
bind.Path = new PropertyPath("Normals");
BindingOperations.SetBinding(TriangleData,
MeshGeometry3D.NormalsProperty, bind);

bind = new Binding();
bind.Mode = BindingMode.OneWay;
bind.Source = _viewerData.Model.RenderData;
bind.Path = new PropertyPath("TextureCoordinates");
BindingOperations.SetBinding(TriangleData,
MeshGeometry3D.TextureCoordinatesProperty, bind);

bind = new Binding();
bind.Mode = BindingMode.OneWay;
bind.Source = _viewerData.Model.RenderData;
bind.Path = new PropertyPath("TriangleIndices");
BindingOperations.SetBinding(TriangleData,
MeshGeometry3D.TriangleIndicesProperty, bind);
}

Cheers,

--
Erno
----
WPF tutorials: http://blogs.infosupport.com/ernow/articles/1878.aspx



"Robin Senior" <senior@gmail.com> wrote in message
news:1139414167.763594.176620@z14g2000cwz.googlegroups.com...
> Is it possible to bind data in a Viewport3d so that 3d visuals can be
> generated from data?
>
> Something along the lines of ItemsControls and DataTemplates for
> enumerating a list of data points and assigning coordinates etc to a
> visual representation. This is simple to do in XAML for 2D controls,
> but I'd like to do it for 3D elements.
>
> I'm looking to dynamically populate the 3D scene, not just vary
> properties of a scene element after it has been created.
>
> Something along the lines of this:
> http://www.beacosta.com/Archive/2005...a_archive.html
>
> ...only in a Viewport3d, not just by using Windows controls. I have yet
> to find an elegant solution to this; the example at
> http://therhogue.com/WinFX/ is great, but it's strange that binding is
> so easy with 2D controls, but 3D requires hundreds of lines of code.
>
> Cheers,
> -robin
>



My System SpecsSystem Spec
Old 02-09-2006   #3 (permalink)
Robin Senior


 
 

Re: data binding in viewport3d

Thanks! I'll have a look at it today -- I may have some questions for
you along the way.

You're the only person I've found so far who's found an elegant data
binding solution for 3D Avalon apps.

Cheers,
-robin

My System SpecsSystem Spec
Old 02-09-2006   #4 (permalink)
Erno


 
 

Re: data binding in viewport3d

You're welcome.

Feel free to use my blog or this newsgroups ask questions.

Cheers,

Erno
----
WPF tutorials: http://blogs.infosupport.com/ernow/articles/1878.aspx



"Robin Senior" <senior@gmail.com> wrote in message
news:1139499248.419471.102360@f14g2000cwb.googlegroups.com...
> Thanks! I'll have a look at it today -- I may have some questions for
> you along the way.
>
> You're the only person I've found so far who's found an elegant data
> binding solution for 3D Avalon apps.
>
> Cheers,
> -robin
>



My System SpecsSystem Spec
Old 02-11-2006   #5 (permalink)
Robin Senior


 
 

Re: data binding in viewport3d

Hi Erno,
Your previous post was a great example of how to bind to an individual
Model3D; would it be possible to see an example of how you implemented
the Model3DGroup.ChildrenProperty bindings for the WireframeModel?

I'm interested in generating sets of visuals (ie. cubes for a
scatterplot) from a list of data elements... I'm not sure how to use
these elements to generate multiple Model3Ds.

Cheers,
-robin

My System SpecsSystem Spec
Old 02-11-2006   #6 (permalink)
Erno


 
 

Re: data binding in viewport3d

Robin,

I'm not really sure of what you need but here are some things I ran into:
For the wireframe views I use an Orthographic camera because they're the
views that allow the user to edit the model and editting in Prespectieve is
bad... (e.g. you can't use a grid)
This Cameratype is important because some things you want to display like
selection boxes of vertices should NOT scale to the camera but do an inverse
scale. (Am I making sense here? Imagine zooming into a vertex: the
selectionbox around the vertex shouldn't get bigger but the triangle (of
which the vertex forms a corner) should.)

Here's what I do:

Wireframe:
Every time the model is changed (depending on the change) I recalculate (a
part of) the wireframe.
All I do is loop through the by the affected triangles and for each triangle
I add a ScreenSpaceLine3D of four points.

Selectionboxes (and other things that should do an inverse scale):
Because it is an Orthographic camera the camera has a Width property.
The ViewPort3D has an ActualWidth property so by calculating
ratio=ActualWidth/Width I know how big a selectionbox in Camera space should
be to make it 1 pixel on my display.

Adding multiple objects can be done in different ways:
1. ScreenSpaceLine3Ds do not need to been connected so you can have all you
boxes in a single Model3DGroup.
2. Nesting several (one for each box) Model3DGroups allows you to quickely
manipulate (visiblity, transforms) a single box.


Is this what you are looking for?
I could provide some code.

Cheers,

Erno
----
WPF tutorials: http://blogs.infosupport.com/ernow/articles/1878.aspx




"Robin Senior" <senior@gmail.com> wrote in message
news:1139607393.066543.281280@g47g2000cwa.googlegroups.com...
> Hi Erno,
> Your previous post was a great example of how to bind to an individual
> Model3D; would it be possible to see an example of how you implemented
> the Model3DGroup.ChildrenProperty bindings for the WireframeModel?
>
> I'm interested in generating sets of visuals (ie. cubes for a
> scatterplot) from a list of data elements... I'm not sure how to use
> these elements to generate multiple Model3Ds.
>
> Cheers,
> -robin
>



My System SpecsSystem Spec
Old 02-11-2006   #7 (permalink)
TheRHogue


 
 

Re: data binding in viewport3d

It appears what you want is the 3D version of a canvas\grid\stackpanel.

For example, a listbox can be styled with a stackpanel which lays the items
out. Note: ModelVisual3D's can't be used as style items...only Viewport3D's
can - it's a V1 limitation.

If you had a 3D stackpanel, and your itemstyle was a modelvisual3D. There
would be a default layout for the models - perhaps going into Z space or
something.

If you had 3D Canvas, the modelvisual3D itemstyle would have bindings to
your X,Y,Z locations, and you could scatter plot cubes based on xml\clr data
just like 2D does.

Does this sound like what you are looking for? If yes, these features are
not in V1 of WPF, and that is why I created ListBox3D and ListItem3D in the
stock graph sample on my web site http://www.therhogue.com/WinFX . I hope in
V2 of WPF this issue will be addressed, but in V1, it's up to the community
to work around the limitation. I've tried to provide the start of a possible
solution others can leverage.

Not sure if this is what you were looking for...


"Robin Senior" wrote:

> Hi Erno,
> Your previous post was a great example of how to bind to an individual
> Model3D; would it be possible to see an example of how you implemented
> the Model3DGroup.ChildrenProperty bindings for the WireframeModel?
>
> I'm interested in generating sets of visuals (ie. cubes for a
> scatterplot) from a list of data elements... I'm not sure how to use
> these elements to generate multiple Model3Ds.
>
> Cheers,
> -robin
>
>

My System SpecsSystem Spec
Old 02-12-2006   #8 (permalink)
TheRHogue


 
 

Re: data binding in viewport3d

The viewports shouldn't slow things down. For performance, we need to wait
for some follow up CTP's to judge performance. Also, lighting is being done
in software right now and adding more models doesn't scale well at the
moment...not sure which CTP will have lighting in hardware...maybe April or
May...I don't know.


"Erno" wrote:

> Isn't it very expensive having all these ViewPorts3D on screen?
>
> I noticed that as soon as all four ViewPorts in my app needed an update
> things slowed down a lot.
>
> As always: many times 3D can be replaced by 2D (or 2.5D) without the user
> noticing it...
>
> Cheers,
>
> Erno
> ----
> WPF tutorials: http://blogs.infosupport.com/ernow/articles/1878.aspx
>
>
>
>
> "TheRHogue" <TheRHogue@discussions.microsoft.com> wrote in message
> news:1C78D0AD-7901-42B0-90AA-345B705F5DBD@microsoft.com...
> > It appears what you want is the 3D version of a canvas\grid\stackpanel.
> >
> > For example, a listbox can be styled with a stackpanel which lays the
> > items
> > out. Note: ModelVisual3D's can't be used as style items...only
> > Viewport3D's
> > can - it's a V1 limitation.
> >
> > If you had a 3D stackpanel, and your itemstyle was a modelvisual3D. There
> > would be a default layout for the models - perhaps going into Z space or
> > something.
> >
> > If you had 3D Canvas, the modelvisual3D itemstyle would have bindings to
> > your X,Y,Z locations, and you could scatter plot cubes based on xml\clr
> > data
> > just like 2D does.
> >
> > Does this sound like what you are looking for? If yes, these features are
> > not in V1 of WPF, and that is why I created ListBox3D and ListItem3D in
> > the
> > stock graph sample on my web site http://www.therhogue.com/WinFX . I hope
> > in
> > V2 of WPF this issue will be addressed, but in V1, it's up to the
> > community
> > to work around the limitation. I've tried to provide the start of a
> > possible
> > solution others can leverage.
> >
> > Not sure if this is what you were looking for...
> >
> >
> > "Robin Senior" wrote:
> >
> >> Hi Erno,
> >> Your previous post was a great example of how to bind to an individual
> >> Model3D; would it be possible to see an example of how you implemented
> >> the Model3DGroup.ChildrenProperty bindings for the WireframeModel?
> >>
> >> I'm interested in generating sets of visuals (ie. cubes for a
> >> scatterplot) from a list of data elements... I'm not sure how to use
> >> these elements to generate multiple Model3Ds.
> >>
> >> Cheers,
> >> -robin
> >>
> >>

>
>
>

My System SpecsSystem Spec
Old 02-13-2006   #9 (permalink)
Robin Senior


 
 

Re: data binding in viewport3d

Yes, that's exactly what I'm looking for. I saw your example earlier,
but since it wouldn't run with the Jan CTP, I passed it over and looked
for an easier method :^)

You'd think that programmatically populating a scene would be easier,
since it's such a common task.

I'll have another look at your code, thanks!

Cheers,
-robin

My System SpecsSystem Spec
Old 02-14-2006   #10 (permalink)
Robin Senior


 
 

Re: data binding in viewport3d

Sorry, my last post was in response to TheRHogue's ListBox3D comments;
the threading in google groups is a bit off.

-robin

My System SpecsSystem Spec
 

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46