Is it possible to instanciate a visual ?

Topics: Developer Forum
Mar 7, 2007 at 4:19 PM
Hi !
i am working with 3DTools for weeks, and i really enjoy it !

I have an idea, but i do not find the way to program it :

i want to make a 3D environment containing meshes ( planes ) mapped with visuals. Ok this is the way is programmed Channel9Demo. The software start with only one plane, mapped with a visual (MENU_A for example).
Users can add planes ( by pressing a key for example ). Those new planes are mapped with MENUA. But i do not want that they are all mapped with the same visual ( aka if you interact with MENUA on mesh1, you interract on all the meshes ).

The best way should be to have a collection of visuals that i can instantiate an affect those instance ( hum maybe instance is not the good english word ? excuse my poor level of english ).

Thanks a lot for your hard work on 3DTools ! It is really great !
Coordinator
Mar 13, 2007 at 4:06 PM
Let me make sure I know what you're looking to do. Essentially when the user presses a key, they can add another plane with the same Visual as another plane. And interacting with one of them interacts with them all?

If this is what you're looking to do, it's possible to do with 3DTools but will require some code changes. I'll hold off on explaining those though until I know what it is you want to do.
Mar 13, 2007 at 7:13 PM
oh, i think i was not enough precise :

what i want to do is :
- a collection of visuals
- instantiate an unknown number of objects.
- those objects are defined as follow :

  • a plane
  • mapped with a visual
  • FULLY independent

for example if i want to make a 'media player' visual.
My user should be able to create any media player he want, on my application. In fact, my planes will have the same apparency ( is that the good word ? ;-) ) , but each of those media players will be independent, so each of the visual should be different. But regarding a dynamic and object programming approach, i need to have a base object in order to instantiate many of this visuals.
So my question is here : can i program a kind of visual template, or a pool of template, or any thing else ;-) in order to dynamically create objects like in my example ?

Because, regarding the different code samples, as i understood, visual a really a static thing ?

Thanks a lot for the time you spend helping us !!
Mar 15, 2007 at 3:21 PM
Why don't you try creating a UserControl where you define the layout of your control (including the 3D model) as the Template? Then you can have a Property for that UserControl which takes the filename for the MediaElement and assign it as the Source for the MediaElement.
Coordinator
Mar 20, 2007 at 7:14 PM
Another option is to just make a class for each of these visual objects you want, and then to just insantiate them as needed. I do this in the PhotoBrowser sample, which you can get from the Releases page.

For example, each of the photos has the same look, and all are instances of the same class. You just need to put a x:Class="PhotoBrowser.PictureVisual" on the top most XAML tag, and then have any code behind derive from the same item (i.e. public partial class PictureVisual : System.Windows.Controls.Grid). Then you can just do Visual v = new PictureVisual(); and you have a new instance of it. I think this type of strategy will give you what you want. Check out the source for a bunch of other examples.
Mar 21, 2007 at 9:55 AM
ok kurtb !
this is exactly what i need ... this new sample helped me a lot.
I will post here me software when ready.

Thanks