tags:

views:

50

answers:

2

Hi,

I'm wondering if i can use a bitmap to set alpha channel of a cone in wpf 3d :

Black = > alpha = 0 %

white => alpha = 100 % (more probably 80 % to see inside alpha difference ...)

alt text

A: 

WPF doesn't have any built-in mechanism for this. I think the easiest way is to:

  1. Convert the Bitmap to a Geometry using a tracing library such as the potrace mentioned by Lie Ryan.
  2. Simplify the Geometry to a polyline using GetFlattenedPathGeometry()
  3. Convert each line segment in the resulting geometry into a 3D triangle from (x,y,0) to (0,0,z) where "z" is the height of the cone.
  4. Build the Positions and TriangleIndices of a MeshGeometry3D and set its Material to a SolidColorBrush with the desired opacity.

Steps 2-4 are all extremely easy. Step 1 may be difficult from the standpoint of selecting an appropriate third-party bitmap tracing library and figuring out any P/Invoke or COM Interop required to call it from C#. Use BitmapSource.CopyPixels to get the bits to pass to the libraray and construct the Geometry from the result by drawing on an open StreamGeometry (StreamGeometry.Open).

Ray Burns
Is it possible to had a geometry object with space between shape ?Like on the schema
Bgnt44
What schema? What do you mean by "space between shape"? If you're asking whether you can generate a geometry for the white areas instead of black, the answer is yes. Many tracing libraries have an option to do this. If not, Geometry.Combine can be used with GeometryCombineMode.Exclude to "invert" the area represented by the geometry. Does that answer the question?
Ray Burns
yeah 100% ! by schema i was meaning drawing in the previous post ...
Bgnt44
A: 

Hi,

I've found a way to do what i want ...

I take each pixel of a bitmap and make a solidbrushcolored polygon with it (only if the pixel is not black to see color or white better ) !

But because of performance issue i've choose to rezize it to 32 x 32 !

To give a light effect i've use a emmitive material.

But it looks a bit pixellized .. and i'm afraid of using so much polygon to just one bitmap ... any idea ???

alt text

Bgnt44