Converting LDraw parts to WPF


Converting LDraw parts to WPF
#1
Hi All,

I'm trying to convert Ldraw parts to use in a Windows Presentation Foundation program, written with visual basic.
Drawing a 4-4disc.dat file for a stud.dat the triangles are CCW that's correct.
stud3.dat uses the same disc, so still CCW and so not visible from the bottom.
The disc has shift down de y axis. I imagen that when it flips so x,y become -x, -y it would be correct.
I use the buildin 4x4 Matrix3d and fill it like the LDraw explanation mentioned. 
What am I missing?

Regards, Hans
.jpg   top.jpg (Size: 9.75 KB / Downloads: 88)
.jpg   bottom.jpg (Size: 13.68 KB / Downloads: 88)
Reply
RE: Converting LDraw parts to WPF
#2
(2019-08-11, 13:17)Hans de Lang Wrote: Hi All,

I'm trying to convert Ldraw parts to use in a Windows Presentation Foundation program, written with visual basic.
Drawing a 4-4disc.dat file for a stud.dat the triangles are CCW that's correct.
stud3.dat uses the same disc, so still CCW and so not visible from the bottom.
The disc has shift down de y axis. I imagen that when it flips so x,y become -x, -y it would be correct.
I use the buildin 4x4 Matrix3d and fill it like the LDraw explanation mentioned. 
What am I missing?

Regards, Hans
Did you remember to invert the drawing order for rotations with negative determinants?

(ie. Reverse the CCW drawing order if determinant(rotation) < 0)

If this is the issue, then I recommend adding this tip to the Culling/clipping page as everyone (including myself twice) have fallen into this.
Reply
RE: Converting LDraw parts to WPF
#3
(2019-08-11, 14:06)Lasse Deleuran Wrote: Did you remember to invert the drawing order for rotations with negative determinants?

(ie. Reverse the CCW drawing order if determinant(rotation) < 0)

If this is the issue, then I recommend adding this tip to the Culling/clipping page as everyone (including myself twice) have fallen into this.

Excellent! That's the trick, now I can see both discs at the top and at the bottom.

Thanks!
Reply
RE: Converting LDraw parts to WPF
#4
(2019-08-11, 21:54)Hans de Lang Wrote: Excellent! That's the trick, now I can see both discs at the top and at the bottom.

Just so you know, full BFC (back face culling) support requires a lot more than just detecting when a matrix mirrors things. The BFC spec isn't super complicated to understand, but it isn't exactly trivial to implement. Also, some polygons in some parts are intended to be drawn on both sides. So to properly draw all LDraw parts, you have to support that also. (One easy way to do that if you can't have the rendering software draw both sides of polygons is to draw the polygons both ways.)
Reply
RE: Converting LDraw parts to WPF
#6
Tongue 
(2019-08-12, 3:43)Travis Cobbs Wrote: Just so you know, full BFC (back face culling) support requires a lot more than just detecting when a matrix mirrors things. The BFC spec isn't super complicated to understand, but it isn't exactly trivial to implement. Also, some polygons in some parts are intended to be drawn on both sides. So to properly draw all LDraw parts, you have to support that also. (One easy way to do that if you can't have the rendering software draw both sides of polygons is to draw the polygons both ways.)
Thanks  for the link on BFC, very helpful, and written in basic! Without all these {{ == << | and so on Smile
Drawing both sides was my work around up to no and I also can convert to .obj and that's always visible 
Doing it as defined is faster and less memory consuming and i'm learning now how to do that!
Reply
RE: Converting LDraw parts to WPF
#5
(2019-08-11, 13:17)Hans de Lang Wrote: Hi All,

I'm trying to convert Ldraw parts to use in a Windows Presentation Foundation program, written with visual basic.
Drawing a 4-4disc.dat file for a stud.dat the triangles are CCW that's correct.
stud3.dat uses the same disc, so still CCW and so not visible from the bottom.
The disc has shift down de y axis. I imagen that when it flips so x,y become -x, -y it would be correct.
I use the buildin 4x4 Matrix3d and fill it like the LDraw explanation mentioned. 
What am I missing?

Regards, Hans
Van you make a tutorial how you make them?
Reply
RE: Converting LDraw parts to WPF
#7
(2019-08-12, 13:09)Victor Di Rienzo Wrote: Van you make a tutorial how you make them?
pretty long story i'm afraidSmile
What you can do is placing an elementhost on a standard form, connect a grid to that and you can use wpf
so
form
  Elementhost
    Grid
      Viewport3D
         Camera
   
     ModelVisual3D
            Model3DGroup
                Model3D
                   TransFormGroup
                   MaterialGroup
                   MeshData
                       Positions
                       Normals (not given by LDraw but you can leave them out
                       Texturecoordinates ( very useful for stickers )
                       Triangles ( and that's the CCW and CW choice)

Parsing the .dat files is easy. Then calculating the points with the matrixes and put them into the Mesh.positions
Thing is WPF works with Y axis up and LDraw with Y-axis down but if you make Y = -Y and Z = - Z then its normal again
You can't draw edges in WPF, but I scale my bricks to the real measures of 7.8 x 7.8 mm
That give's a small gap between the bricks and shows not as a solid wall
Succes!
Reply
RE: Converting LDraw parts to WPF
#8
(2019-08-13, 22:27)Hans de Lang Wrote: pretty long story i'm afraidSmile
What you can do is placing an elementhost on a standard form, connect a grid to that and you can use wpf
so
form
  Elementhost
    Grid
      Viewport3D
         Camera
   
     ModelVisual3D
            Model3DGroup
                Model3D
                   TransFormGroup
                   MaterialGroup
                   MeshData
                       Positions
                       Normals (not given by LDraw but you can leave them out
                       Texturecoordinates ( very useful for stickers )
                       Triangles ( and that's the CCW and CW choice)

Parsing the .dat files is easy. Then calculating the points with the matrixes and put them into the Mesh.positions
Thing is WPF works with Y axis up and LDraw with Y-axis down but if you make Y = -Y and Z = - Z then its normal again
You can't draw edges in WPF, but I scale my bricks to the real measures of 7.8 x 7.8 mm
That give's a small gap between the bricks and shows not as a solid wall
Succes!
Do you think you can make a dll out of this that can be used in my visual basic applications as the renderer for ldraw files, so I can show the result in a picture frame and/or window? Currently I use ldview.dll, but that is 32bit and not 64bit.
Reply
« Next Oldest | Next Newest »



Forum Jump:


Users browsing this thread: 1 Guest(s)