Guillaume Randon's WebLog

Un peu d'anglais...

Bonjour,

Le rythme de mes posts c'est un peu ralenti courant Aout, je prépare un article d'introduction au shaders en managed directX qui devrait être posté sous peu sur le site msdn français http://www.microsoft.com/france/msdn/directx/default.mspx

Sinon, on m'a demandé à plusieurs reprise une traduction en langue anglaise de mes deux posts précédents. Pour les personnes intéressées vous la trouverez ci-dessous:

I have been asked several time for a translation to english of my two previous posts. For anyone interested here it is: (for the source code please check the zip files associated with the original posts)

Loading a Collada File in a DirectX application

Last week I did show a small code sample that was loading some information from a Collada file and displaying 3D objects in a WPF application. Here is another small sample which process the same information from the Collada file but which this time generates the DirectX Index, Vertex buffer and Textures to display the same 3D objects easily in a DirectX application. This code sample is meant to be used with C#, .Net 2.0 and MDX1.1.

Again the code included in the zip file only process triangles from the Collada file and doesn’t make any attempt at reading complex material properties. Still I tend to think it can be easily modified to server any purpose you might have in mind.

Here is a small screenshot of the result:  

And here is the code to writte in your own application to use the class called ColladaLoader included in the zip file :

collada = new ColladaLoader(e.Device);

collada.Load("Villada.dae");

Puis utiliser le code suivant pour effectuer le rendu de ce qui a été chargé:

IDictionaryEnumerator enumGeometrie = collada.colladaGeometries.GetEnumerator();

while (enumGeometrie.MoveNext())

{

   ColladaGeometry collGeom = enumGeometrie.Value as ColladaGeometry;

   if (collGeom == null)

      continue;

   foreach (LoadedEntity entity in collGeom.models)

   {

            if (entity.materials.Length == 0)

               continue;

            if (entity.textures.Length == 0)

               continue;

            device.SetTransform(TransformType.World,

                        Matrix.Multiply(Matrix.Scaling(0.1f, 0.1f, 0.1f),  Matrix.Translation(0.0f, 5.0f, 0.0f)));

            device.Indices = entity.iBuff;

            device.SetStreamSource(0, entity.vBuff, 0);

            device.Material = entity.materials[0];

            device.SetTexture(0, entity.textures[0]);

            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0,

                        entity.numVertices, 0,   entity.numPrimitives);

       }

}

Feel free to contact me if you have any remark or question at guillara@microsoft.com .

 

 Loading a Collada file in a WPF application

The attached code sample process the <triangles> information from a Collada file and displays them in a WPF application. The code run on WPF Beta2 it might requires some modification to run correctly on newer version of WPF. The screenshot on the blog displays the result of reading the file MissionDolores.dae that can be easily found on the web. Texture coordinates are not right yet. WPF handle textures in a somewhat different way that DirectX does and I still have to invest some more time on that to get them to display correctly.

The dae file in the attached zip file was generated using the free version of Sketchup. To zoom use the right mouse button, to rotate the objet the left one.

This code sample doesn’t make any attempt at reading material properties from the Collada file. Still it might be useful as a starting point for people who would like to use in a WPF application 3D objects they have created with applications that don’t export to the XAML format yet. By the way as instances of WPF classes can be serialized to XAML and vice versa I was initially thinking I could use this application to save the geometries displayed on screen to XAML without much work. In the current version of WPF it is not so and it would in fact require more work to reach that result. If anyone has done some work in that direction I would be happy to hear about it.

I wish a good week to anyone reading this.

For any comment or question regarding this please feel free to send me an email at guillara@microsoft.com .

Published Tuesday, August 29, 2006 12:59 PM by Guillaume Randon

Comments

 

peud said:

June 29, 2008 3:39 AM
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker