Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my wpf project, I have done most of my work using C# and have hardly touched xaml. I have written a function that creates a small 3D object during run-time. I have called that function a few times with different parameter values and it works fine. I can see a bunch of 3D objects in different locations of my screen.

I would like to store all these individual 3Dobjects (preferably in a form of array), and would like to access them individually. I would also like to animate them using translatetransform3D. I would like to do the transformations and animations using C# and during run time. PS: I do not have any <geometrymodel3d> tag in my xaml.

Please help.

Thanks
Posted

You're asking multiple of questions none of them are easy enough to explain in a Q&A, you'll have to do your own research into the subjects and ask about the bits and pieces that troubles you.

About storing your 3D objects in an array, I'm guessing you know how to take an object and put into an array, so I believe you mean to ask how you can access your 3D objects, but that's hard to say without knowing how they are create and where they are placed. If they are defined in your XAML you can either set the Name property so you can use them in your code behind or iterate over the children of the panel containing your 3D objects.

To get you started with your research into transformation and animation here are two CP articles
WPF Tutorial - Part 1 : Transformations[^]
WPF Tutorial - Styles, Triggers & Animation[^] - The animation part explains the basics of storyboards(animation) quite well and to the point.
 
Share this answer
 
Comments
Espen Harlinn 30-Aug-11 16:45pm    
Good reply, my 5
Simon Bang Terkildsen 30-Aug-11 16:48pm    
Thank you
steersteer 30-Aug-11 17:21pm    
Thanks for your reply. I have created the objects using Model3DGroup.Children.Add(meshgeometry); Something like this one WPF 3D Primer

I have called the "buildobject method" (the one i have used to create 3Dmodels)five times with in the constructor of the mainwindow and have created five 3Dobjects of same shape and size but located in different positions.

As I've mentioned, I would like to apply translatetransform3D to each of the objects added. I know how to do apply transformation to every object when the code is written in xaml. I usually use their names to refer to them, but I don't know how to access them individually and apply transformations when the objects are created only using C# as code-behind.

My main objective right now is to access every object. could you please tell me how to iterate over the children of the panel containing my 3Dobjects ? or Could you please let me know the syntax or an example to set the name property(in C#) to 3D objects created by calling a method in the code behind ?


Thanks
steersteer 30-Aug-11 18:13pm    
okay. I am not sure whether it is right or not, but I am referring to the objects by "model3Dgroup.Children[0]" Does it refer to the first of the five 3D objects I have on the screen ? If so, can you please tell me a way to check it ?
Thanks
Simon Bang Terkildsen 30-Aug-11 18:29pm    
model3Dgroup.Children[0] is the first model added to the group wether it's a Light or a mesh (GeometryModel3DModel3DGroup), so yes if you haven't added anything in the xaml like Dario has done in the sample code for that article.
However I would suggest you do not use it like that, if you suddently decide to add a light or a mesh in your XAML then your code doesn't work anymore.
I suggest you keep your own list of the meshes you've added and use that list.

I'm not sure what you mean by "check it"?

In general you want to limit the impact a chance in your XAML has on your code. When you've become more proficient with WPF and especially the MMVM pattern then your collegues can do whatever they want in the XAML but your code will never break, well not because of the changes to the XAML anyhow :D
If you really want to understand whats going on in wpf Snoop[^] is a valuable tool. As the source code is available you could just borrow pieces of it and implement a xaml serializer.

Or take a look at the example at the bottom of the DataContractAttribute[^] documentation page. A bit easier than my first suggestion :) Snoop is still a very nice tool ...

Best regards
Espen Harlinn
 
Share this answer
 
Comments
steersteer 30-Aug-11 17:47pm    
Thank you. will give it a try.
Espen Harlinn 30-Aug-11 17:51pm    
Good :)
Simon Bang Terkildsen 30-Aug-11 18:30pm    
+5 for Snoop - amazing tool.
Espen Harlinn 30-Aug-11 18:47pm    
Thanks Simon :)
Sergey Alexandrovich Kryukov 31-Aug-11 0:32am    
What an interesting tool! I never new it before. Thanks for pointing it out. My 5 of course.
It looks like you take a special interest in this kind of tools; just looking at your most recent article.

By the way, I tried it; it's very nice but I have some notes, suggestions and questions. I'll get back to it soon.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900