Yet another blog about WPF, Surface, SL, MVVM, NUI....

2011

2010

2009

2008

 

Tips: increase performances when using D3DImage in WPF

17 September 2009

Hello,

Often when you read articles explaining how to use a D3DImage in your WPF application you use code which directly handle the CompositorTarget.Rendering event by updating the 3D world... This can lead to performance problems.

For example in my application, WPF refresh the display with a FPS of 160 : the handler which recreate the 3D image is then call 160 times a second. No need to refresh this often.


The solution I used is to create a Timer which will do it at the FPS I want. Let's say 30FPS for example :

public void createTheRenderingWithCorrectFPS(int whichFPS){
   DispatcherTimer _timer = new DispatcherTimer();
   _timer.Interval = new TimeSpan(1000 /whichFPS);
   _timer.Start();
   _timer.Tick += new EventHandler(_timer_Tick);
}
void _timer_Tick(object sender, EventArgs e)
{
   //Refresh the 3D scene
}



This enables your application to be really more reactive especially that you need to be on the main thread to update the 3D scene...



Do you know a better way ?



kick it on DotNetKicks.com Shout it



 

Ambient, diffuse, emissive and specular colors : some examples

24 July 2009

Introduction

When you defines a material in Ogre or in 3D engines in general, you can play with at least four differents parameters : Ambient color, diffuse color, emissive color and specular color.

In this post I will give you the definitions and show you some example for those who - like me - requires some visual example to understand better...

Definitions

Here are the definitions (found on the web...) :

Ambient color : Ambient color is the color of an object where it is in shadow. This color is what the object reflects when illuminated by ambient light rather than direct light.

Diffuse color :Diffuse color is the most instinctive meaning of the color of an object. It is that essential color that the object reveals under pure white light. It is perceived as the color of the object itself rather than a reflection of the light.

Emissive color : This is the self-illumination color an object has.

Specular color :Specular color is the color of the light of a specular reflection (specular reflection is the type of reflection that is characteristic of light reflected from a shiny surface).



All object material can so define these 4 parameters. The color will then depend on them but also of the light they receive.

Examples

All the example are done with a point light, placed at the position (350, 400, 800);
With this type of light you define two colors, the ambient one and the diffuse one.

First example

The light parameters are :

  • Ambient color : White
  • Difusse color : White



First example

Second example

The light parameters are :

  • Ambient color : Red
  • Difusse color : White



Second example

Third example

The light parameters are :

  • Ambient color : Red
  • Difusse color : Red



Third example

Conclusion


As a conclusion : nothing is better than experimentation !

kick it on DotNetKicks.com
 

GUI to NUI : representations and manipulation of OLAP data in 3D

21 July 2009

Hello,

Here is a little post to show you a little video presenting the project I have worked on during my 6 months of training. I am very proud of it :) :



The subject was to find the new way of representations and manipulations of OLAP Data without using a keyboard or a mouse.
This is done in 3D on the Microsoft Surface plateform.

The technologies involved are :

  1. Microsoft Surface for the NUI (Natural User Interface),
  2. (M)Ogre to create the 3D World,
  3. OLAP for the acquisition of datas.




Here are some links for those interested :

  1. What is OLAP ? (wikipedia)
  2. What are the NUI ? (wikipedia)
  3. What is Ogre the 3D engine ?
  4. What is Microsoft Surface ?
  5. What is the company in which I have done my training ?



People who worked on it :

  1. Development: Jonathan ANTOINE
  2. Supervision of the project : Elise DUPONT
  3. 3D Expert : Laurent TRUDU



Enjoy !


kick it on DotNetKicks.com


Shout it
 

Use a screenshot of a WPF visual as a texture in Mogre.

25 March 2009

Hello, Here is my first post about WPF and Mogre, maybe it will helps some people... The subject of today is "How to use a screenshot of a WPF elements and put it as an texture on your Mogre object"...

Why ? Because WPF enable you to create very rich interface and so great image to place on you differents elements...



By the way, I let you follow the link at the end of the post to learn how to blend Mogre in WPF and how to take a screenShot of a WPF visual.

The steps to follow are these :

  1. Create a screenshot of the WPF visual (any visual can be used),
  2. Put the bitmap in a stream and then to a buffer,
  3. Use some unsafe code to create a Mogre MemoryStream and a mogre image,
  4. Use this image to create a texture,
  5. Use this texture in a material,
  6. Put it on the mesh of your choice



Create a screenshot of the WPF visual

The original code is from thomas lebrun and can be found in any good WPF book :

Visual theVisual = this ; //Put the aimed visual here.
double width = Convert.ToDouble(theVisual.GetValue(FrameworkElement.WidthProperty));
double height = Convert.ToDouble(theVisual.GetValue(FrameworkElement.HeightProperty));
if (double.IsNaN(width) || double.IsNaN(height))
{
throw new FormatException("You need to indicate the Width and Height values of the UIElement.");
}
RenderTargetBitmap render = new RenderTargetBitmap(
      Convert.ToInt32(width),
      Convert.ToInt32(this.GetValue(FrameworkElement.HeightProperty)),
      96,
      96,
      PixelFormats.Pbgra32);
// Indicate which control to render in the image
render.Render(this);
Stream oStream = new MemoryStream();
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(render));
encoder.Save(oStream);
oStream.Flush();

Put the bitmap in a stream and then to a buffer

//Back to the start of the stream
 oStream.Position = 0;
 
//read all the stream
BinaryReader oBinaryReader = new BinaryReader(oStream);
byte[] pBuffer = oBinaryReader.ReadBytes((int)oBinaryReader.BaseStream.Length);
oStream.Close(); //No more needed
TextureManager.Singleton.Remove(sName); //Remove eventually texture with the same name

Create the texture

unsafe
         {
            GCHandle handle = GCHandle.Alloc(pBuffer, GCHandleType.Pinned);
            byte* pUnsafeByte = (byte*)handle.AddrOfPinnedObject();
            void* pUnsafeBuffer = (void*)handle.AddrOfPinnedObject();
 
            MemoryDataStream oMemoryStream = new MemoryDataStream(pUnsafeBuffer, (uint)pBuffer.Length);
            DataStreamPtr oPtrDataStream = new DataStreamPtr(oMemoryStream);
            oMogreImage = oMogreImage.Load(oPtrDataStream, "png");
 
            TextureManager.Singleton.LoadImageW(sName, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, oMogreImage);
 
            //handle.Free();
         }

Use this texture in a material

Here is the code of how you can create a material with this texture:

_dynamicMaterial = MaterialManager.Singleton.Create(SCREENSHOT_MATERIAL_NAME, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
Pass pass = _dynamicMaterial.GetTechnique(0).GetPass(0);
 
TextureUnitState tus = pass.CreateTextureUnitState(SCREENSHOT_TEXTURE_NAME);
_dynamicMaterial.GetTechnique(0).GetPass(0).AddTextureUnitState(tus);

Then you just have to use it as a normal texture...

An example:

Here is a little screenshot of the results. I display a cube with the face using as a texture a screenshot of the window in which it is.... WPF screenshot as a texture in Mogre



Link: how to blend Mogre in WPF