This is the discussion forum for Helix Toolkit.
For bugs and new features, use the issue tracker located at GitHub.
Also try the chat room!
0

Loading large mesh or many model3d

Anonymous 5 years ago 0
This discussion was imported from CodePlex

behnam263 wrote at 2014-06-29 06:08:

HI
is there any thing like field of view for camera?
i mean loading meshes if camera look into them like "unity4"
and other meshes do not render when they are not in front of
camera? it is a big issue for controlling ram and cpu usage.

objo wrote at 2014-07-02 13:13:

Yes, see http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.perspectivecamera.fieldofview(v=vs.110).aspx
Sorry, occlusion culling is not implemented in this library. I am not sure if this will work with the WPF 3D model, changing the visual model may be expensive!
0

Import a file with background worker

Anonymous 5 years ago 0
This discussion was imported from CodePlex

thiagoaguirre wrote at 2014-02-25 13:47:

Hi Objo!
Your library is amazing!

I couldn't import a model, with the ModelImporter, using a thread or task. It's cause a exception in Viewport3D.
While the thread is reading and the file size is too big, the main window not respond.
I think it is because the Model3DGroup is frozen.

I don't know as do that.
You can help me?

Thank you very much.
Thiago Aguirre Lorscheiter
0

Just a big "Thank You"

Anonymous 5 years ago 0
This discussion was imported from CodePlex

Jac312 wrote at 2010-06-06 18:57:

You have done a wonderful and useful job. I'm using your library in a 3D Xbap application that will help design precasted concrete products once finished. The toolkit works like a charm. So: a big "Thank You" and keep going. Jacques PS: ZoomToFit() works perfectly

objo wrote at 2010-06-07 07:44:

thanks for the feedback! good to hear that the zoomtofit function works for you!

0

Progress - keep it going please

Anonymous 5 years ago 0
This discussion was imported from CodePlex

stfx wrote at 2010-02-02 18:50:

Hey I just registered here to tell you how awesome that toolkit is. I use a modified version of it and it works perfectly. Do you have any progress on the code so far like object transformation (position, rotation, size) or maybe fit screen to object and fit to show all objects?

Please dont give up on it I really appreciate it.

Oh yeah you should consider to rename it to Helix Engine - sounds so much cooler :D

PS: I can send you the modifications if you are interested.


objo wrote at 2010-02-21 18:13:

Thanks for your feedback!! Sure, this project just started - I hope to get more work done on it soon. I have added you as a developer, you are welcome to submit improvements! There is a simple manipulator class for object transformation (translation only) in the toolkit now, but I am sure this needs more work. Do you have solutions to this? And the "fit screen to object" feature? That's a feature I would really like to have included!

Engine or toolkit - I like "toolkit" since this is mostly a collection of tools and helper classes - not replacing or encapsulating the wpf 3d engine. 

0

Drawing Polygon with CuttingEars algorithm

Anonymous 5 years ago 0
This discussion was imported from CodePlex

Darkounet789 wrote at 2014-02-05 11:00:

Hi there !

I'm very new to Helix3D (even WPF...) and I've a newby question about a way to draw polygons from scratch. I just can't figure out how the function AddPolygonByCuttingEars should be used ^^" Here is my current code :
var visualMesh = new MeshVisual3D();
var geometry = new GeometryModel3D();
var meshbuilder = new MeshBuilder(false,false);
var polygon = new[]
{
        new Point(1, 1),
        new Point(1, 2),
        new Point(4, 3),
        new Point(2, 1),
        new Point(1.5, 1.5)
};
var polygon3D = new[]
{
        new Point3D(1, 1,0),
        new Point3D(1, 2,0),
        new Point3D(4, 3,0),
        new Point3D(2, 1,0),
        new Point3D(1.5, 1.5,0)
};

var result = CuttingEarsTriangulator.Triangulate(polygon);
/* 1 */
//meshbuilder.AddPolygon(polygon3D);
/* 2 */
//meshbuilder.AddPolygon(result);
/* 3 */
meshbuilder.AddPolygonByCuttingEars(result);
geometry.Geometry = meshbuilder.ToMesh();
geometry.Material = MaterialHelper.CreateMaterial(Colors.OrangeRed);
visualMesh.Content = geometry;
this.Viewport3D.Children.Add(visualMesh);
The polygons are /convex/ -edited- -> concave !.
  1. The flatten Polygon3D only appear with false, false as attributes of the MeshBuilder constructor, otherwise I get a 'System.InvalidOperationException' in HelixToolkit.Wpf.dll. However some faces are upside down and the shape is finally not /convex/ -edited- -> concave ! =s
  2. meshbuilder.AddPolygon(result) line works, but no shapes appears... even with true, true in the MeshBuilder constructor.
  3. With meshbuilder.AddPolygonByCuttingEars(result); I get a 'System.ArgumentOutOfRangeException' in mscorlib.dll, and I don't really know why...
I'me sure I'm doing it wrong, if someone could explain how it should work or lead me to a working example of the cutting ears function usages, it would be great !

Thank you in advance for your answers !

/ Edit /
I said convex, of course, they are concave ^^" sorry !

Darkounet789 wrote at 2014-02-06 11:21:

Hi !

I think I got it ! I just drawn each triangle by using the indexes given by the cuttingears algorithm. I don't know if it's the right way to do it, but it works ^^.
var visualMesh = new MeshVisual3D();
var geometry = new GeometryModel3D();
var meshbuilder = new MeshBuilder(true, true);
var polygon = new PointCollection()
{
      new Point(1, 1),
      new Point(1, 2),
      new Point(2, 3),
      new Point(3, 2),
      new Point(4, 4),
      new Point(4, 2),
      new Point(3, 1)
};

var result = CuttingEarsTriangulator.Triangulate(polygon);

List<int> tri = new List<int>();
for (int i = 0; i < result.Count; i++)
{
      tri.Add(result[i]);
      if (tri.Count == 3)
      {
            Console.WriteLine("Triangle " + (i / 3).ToString() + " : " + tri[0].ToString() + ", " + tri[1].ToString() + ", " + tri[2].ToString());
            meshbuilder.AddTriangle(new Point3D(polygon[tri[0]].X, polygon[tri[0]].Y, 0),
                new Point3D(polygon[tri[1]].X, polygon[tri[1]].Y, 0),
                new Point3D(polygon[tri[2]].X, polygon[tri[2]].Y, 0));
            tri.Clear();
      }
}

geometry.Geometry = meshbuilder.ToMesh();
geometry.Material = MaterialHelper.CreateMaterial(Colors.OrangeRed);
visualMesh.Content = geometry;
                    
this.Viewport3D.Children.Add(visualMesh);
However, I encounter and new issue... the triangles I'm drawing are one-sided. Only the upper side of the face is rendered. Is there a way to make the triangles double-sided ?

/ FIXED / : I didn't know I had to set a backmaterial. I discovered that in an another topic ^^

Darkounet789 wrote at 2014-02-13 16:03:

Hey everybody !

You shouldn't use the code I wrote in my previous posts. Instead of this, I now use this couple of functions to fill a polygon with triangles.
//Support for 2D polygons

        public static MeshGeometry3D FillPolygon(Polygon p)
        {
            List<Point3D> pts3D = new List<Point3D>();
            foreach (var point in p.Points)
            {
                pts3D.Add(new Point3D(point.X, point.Y, 0));
            }
            Polygon3D p3 = new Polygon3D(pts3D);
            return FillPolygon(p3);
        }

//For 3D polygons

        public static MeshGeometry3D FillPolygon(Polygon3D p3)
        {
            var meshBuilder = new MeshBuilder(false, false);

            Polygon polygon = p3.Flatten();
            var triangleIndexes = CuttingEarsTriangulator.Triangulate(polygon.Points);

            meshBuilder.Append(p3.Points, triangleIndexes);
            return meshBuilder.ToMesh();
        }
The Append method of the MeshBuilder made my day...

Feel free to reuse !
0

TextBillboardVisual3D with Mouse-Events?

Anonymous 5 years ago 0
This discussion was imported from CodePlex

31337 wrote at 2012-11-27 12:28:

Hallo, is it possible to add the TextBillboardVisual3D as ModelUIElement3D?


31337 wrote at 2012-11-30 12:22:

Figured it out myself.

"ContainerUIElement3D" is the answer.


bennasi wrote at 2012-12-03 10:47:

Could you please elaborate on this a bit more? A code example would be nice. Thanks

0

CAD formats

Anonymous 5 years ago 0
This discussion was imported from CodePlex

vindex wrote at 2011-12-17 11:55:

Hi, 

First of all, great job, and thank you again. I'm a grateful user of Oxyplot, and here i find you again!

 

And now my question... have you any plans to give support to some CAD formats like .step, .sat,  or .iges?


objo wrote at 2011-12-19 09:24:

Sorry, no plans to implement readers for step, sat or iges. Only simple formats using triangular/quadrilateral meshes.

I might add import for a subset of the DXF format (polylines/curves and simple surfaces).

openNURBS is also interesting, would like to add a demo using the .net library:

http://download.rhino3d.com/openNURBS.NET/5.0/release/download/

0

Loaded objects flip upside down when zooming

Anonymous 5 years ago 0
This discussion was imported from CodePlex

Elementu wrote at 2012-02-22 15:53:

Hello.

 

I have several helix controls in my application. Some of them are froze to give the feeling of a 2D display than cannot be rotated.

The one that is not froze uses a perspective camera and the other 2D use Orthographic Camera.

The problem that I'm facing is that when I zoom into the 2D controls my objects flip upside down. this can be seen also on the view cube the view changes, however even if I bring the view(guiding myself after the view cube) as it was before the objects are still upside down.

However if I reset the camera the objects will be in the correct position.

Is there a way to prevent this behavior and stop it from happening?

 

Thank you in advance.


elementu wrote at 2012-02-23 11:07:

Hello,

What I discovered in my investigation is that in the CameraContoller.cs(HelixToolkit.Wpf.CameraController) in the OnTimeStep method at the point were the this.ZoomHandler.Zoom method is called, when the "this.zoomSpeed * time" parameter has a large value this bug will occur. In fact this bug occurred especially if I ran my application a slower machine. If I ran it on my main machine the bug only occurred if I added a thread.sleep of 500 or 1000 before calling the Zoom method.

So from the Zoom method the delta parameter is passed further in the ChangeCameraWidth method because my camera is an OrthographicCamera one.

Finally in the ChangeCameraWidth method to prevent the delta parameter from having a value that is too large  if the absolute value of the parameter is larger that 1 ( Math.Abs(delta) >= 1 ) then delta will take the value "delta = delta % 1" .

Having done this even if I add the delay or run the application on a slower machine the bug is not reproduced anymore.

I noticed that in the ChangeCameraPosition method that is called from the Zoom method in case my camera is a PerspectiveCamera not an OrthographicCamera there is a section of code with similar functionality to limit the value of the delta parameter.

if (delta < -0.5)
{
      delta = -0.5;
}

On a first look the behavior seems the same as before and everything looks all right with the change, except the bug that does not occur anymore.

What I want to ask you is what could be the implications of the change(the limitation of the delta value) I made, what is the case or were could it have a negative effect on the behavior or performance of the HelixToolkit ?

 

Thank you.


objo wrote at 2012-03-10 15:41:

thanks for debugging this! I added the clamping on the delta value as you suggested (change set c213bd42d8f7), and this seems to correct the problem. It limits the maximum zoom-out speed, but 50% zoom out per zoom event should be sufficient, I think.


stfx wrote at 2012-05-21 00:05:

Nice fix - btw this also occured on a perspective camera but yea fixed after that commit.

Another problem related to zooming is that if you zoom in too far (as far as you can) the camera will start to wobble at the end).

Fixed it by modifying the CameraHelfer.LookAt function like this:

 

        public static void LookAt(
            PerspectiveCamera camera, Point3D target, Vector3D newLookDirection, double animationTime)
        {
            Point3D newPosition = target - newLookDirection;

            // prevent zooming in until camera gets wobbly due to precision loss
            if (Math.Abs(newPosition.Z) > 0.01)
            {
                AnimateTo(camera, newPosition, newLookDirection, camera.UpDirection, animationTime);
            }
        }
EDIT: This fix is definately not correct
0

Problem with material when adding new child to the group

Anonymous 5 years ago 0
This discussion was imported from CodePlex

Tapir wrote at 2012-11-08 08:13:

I have a problem with adding new child to group. Regardless of which material i use, all figures are filled with color of the last added one. Any idea how to solve this problem?

        static private Model3DGroup DrawLayers(int noOfLayers)
        {
            Material materialFiber = new DiffuseMaterial(new SolidColorBrush(Colors.Lime));
            Material materialCopper = new DiffuseMaterial(new SolidColorBrush(Colors.Orange));
          
            HelixToolkit.Wpf.MeshBuilder builder = new HelixToolkit.Wpf.MeshBuilder();
            Model3DGroup group = new Model3DGroup();

            for (int i = 0; i < noOfLayers; i++)
            {
                if (i == 0)
                {
                    builder.AddBox(new Point3D(0, 0, 0), 15, 15, 1);
                }
                else
                {
                    builder.AddBox(new Point3D(0, 0, 2*i), 15, 15, 1);
                }

                MeshGeometry3D layer = builder.ToMesh();

                if (i % 2 == 0)
                {
                    GeometryModel3D model = new GeometryModel3D() { Geometry = layer, Material = materialFiber, BackMaterial = materialFiber };
                    group.Children.Add(model);
                }
                else
                {
                    GeometryModel3D model = new GeometryModel3D() { Geometry = layer, Material = materialCopper, BackMaterial = materialCopper };
                    group.Children.Add(model);
                }
            }
            return group;
        }


objo wrote at 2012-11-08 08:25:

move

var builder = new HelixToolkit.Wpf.MeshBuilder();

inside your loop?

otherwise you are appending more and more boxes to your geometry...


Tapir wrote at 2012-11-08 08:31:

Works perfectly. Thanks a lot!

0

SharpDX - Transparency from image

Anonymous 5 years ago 0
This discussion was imported from CodePlex

geoarsal wrote at 2014-03-07 10:05:

Hi,

how can i enable transparency from image for textures ??

In WPF3D, all i need to do is to create the diffuse material with image brush and use it. In SharpDX fork, I had created PhongMaterial and set its DiffuseMap to the same image i used in WPF3D, but here the transparent region are rendered as Black.

Thanks

Rogad wrote at 2014-03-08 16:05:

I used PNG textures. Also read this about how you need to order transparent parts :

http://www.ericsink.com/wpf3d/2_Transparency.html


I still have problems with layered transparency though, when one part of the model overlaps the other it does not look right.

geoarsal wrote at 2014-03-08 17:48:

Thank you Rogad for your reply.

I would like to know have you used PNG textures to attained transparency in "SharpDX fork of Helix Toolkit" ?? because the link you have provided is about transparency in WPF3D but I need transparency in SharpDX.

P.S. I already got the transparency using image texture in WPF3D but I require same functionality in SharpDX fork using that same image.

Rogad wrote at 2014-03-08 17:56:

Sorry I did not realise you were asking about SharpDX. I have not tried it, because I couldn't see how to get support, so gave up on it.

geoarsal wrote at 2014-03-12 19:04:

After debugging the code, I had resolved this issue. Following are the changes I needed to make in Helix SharpDx.


In the pixel shader "PShaderPhong" method, alpha value is taken explicitly from the diffuse material.

Current Code "Default.fx"
/// set diffuse alpha
I.a = vMaterialDiffuse.a;
Fix "Default.fx"
I.a = vMaterialDiffuse.a * vMaterialTexture[3];
Also the conversion of texture map is done through BMP encoder, however apparantly it looks like BMP encoder doesn't support alpha in texture map. Changing bmp encoder to png encoder will resolve this issue.

Current Code "RenderUtil.cs"
public static byte[] ToByteArray(this System.Windows.Media.Imaging.BitmapSource bitmapSource)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                var encoder = new System.Windows.Media.Imaging.BmpBitmapEncoder();
                encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bitmapSource));
                encoder.Save(ms);
                return ms.ToArray();
            }
        }
Fix "RenderUtil.cs"
public static byte[] ToByteArray(this System.Windows.Media.Imaging.BitmapSource bitmapSource)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                var encoder = new System.Windows.Media.Imaging.PngBitmapEncoder();
                encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bitmapSource));
                encoder.Save(ms);
                return ms.ToArray();
            }
        }

objo wrote at 2014-04-29 10:57:

I have forwarded this to the guys working on the sharpdx fork.

Rogad wrote at 2014-05-24 18:16:

Is there a similar fix for Helix ?

For my project this is the main area where Helix does not seem to work right.

Despite following various tutorials/guides on transparency, such as putting the transparent textures last I still end up with this :

Image

Some of the transparency is working, but as you can see not all.

Would really like to fix this :)

Rogad wrote at 2014-05-30 16:46:

Anyone ? Objo ? Are you still with us ? :)

objo wrote at 2014-05-30 22:56:

hi Rogad, yes I am following the discussion, but don´t know how to solve this. How are you rendering the hair? Are you using SharpDX or WPF? Can you create a demo application we can include with the library?

Rogad wrote at 2014-05-30 23:08:

Hi :)

I'm using WPF and Helix. I have not used SharpDX for anything yet, I was trying to find some documentation for it or support, but haven't found much yet.

Unfortunately I cannot turn this into something distributable. The models I had to buy from Daz3D and I cannot redistribute them like that.