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

Helix/SharpDX/WPF few questions

Anonymous 11 years ago 0
This discussion was imported from CodePlex

andyag wrote at 2014-07-27 00:47:

Hi everyone!

I'm looking for a 3D visualization library for WPF that provides a high-level API (at least higher-level than Vertex Buffers and shaders). I'm considering HelixToolkit.Wpf.SharpDX at the moment and absolutely impressed with what it does and how flawlessly it integrates with WPF/MVVM. I have 2 questions to clarify:
  1. As of today, is it possible to somehow disable antialiasing completely? I've checked the code and it looks like there's no way to configure it: there's logic that dynamically decides whether or not to enable it.
  2. I also see that there's a render loop - even if there are no changes to the scene, everything gets redrawn. Is it possible to somehow disable this behavior and instead trigger updates manually?

przem321 wrote at 2014-08-05 17:28:

andyag,

Regarding 1:
In the current sharpdx version you can disable anti-aliasing by removing the conditional compilation symbol MSAA prior to compiling the code. This applies to the forward renderer, if you want to disable anti-aliasing for the deferred renderer remove the symbol DEFERRED_MSAA. You will find the symbols by right-click on the HelixToolkit.Wpf.SharpDX project->properies->build->general.

Regarding 2: this is a direct3d renderer, there is a render loop, which cannot be removed.

andyag wrote at 2014-08-05 20:06:

p.1 - Yes, I've checked the code. Unfortunately, maintaining a custom set of binaries is not an option for me.
p.2 - Direct3D doesn't require a render loop. Even though it's a common approach in games (where things happen quite often), there's a bunch of scenarios when you only need to update the picture on demand.

przem321 wrote at 2014-08-07 15:28:

Well, I guess, I didn't made my point clear enough: this is a real-time rendering framework which is meant to work like a game as you said. There is no option to call the update manually, and such an option is not planned. However, basically you are right, one might trigger the update in D3D on demand. The framework uses D3DImage class to display the content, where the update frequency is bound to the CompositionTarget.Rendering event. You are free to modify it in order to fit your needs.

objo wrote at 2014-08-08 12:39:

I think the original idea was to create a solution that mimcs the WPF 3D scene graph as much as possible (supporting data binding and animations), but also making it possible to use shaders by SharpDX. Isn't the rendering loop just a shortcut we made to avoid keeping track of all changes and invalidating the model? I think it would be great if we could handle the invalidation and update only when the model has changed. Maybe a first step could be to add a flag to enable/disable the render loop and provide an Invalidate method? In that case the client application should be responsible for the invalidation.

Regarding the conditional compilation - can we get rid of this? Could it be possible to change the anti-aliasing at runtime?

andyag wrote at 2014-08-08 20:09:

Render loop is indeed just a shortcut. The 2 options I can think of are:
  1. As objo said, just make it possible to disable automatic updates and provide a method to trigger updates manually.
  2. Keep render loop, but add extra logic to only have it running as long as there are view model updates. The easiest would be just to enable the loop when view model is updated and then keep it running for next N (=1) seconds. If there are more updates while loop is enabled, keep it running for N more seconds. Then, after first N seconds without view model updates, stop the loop.
I can barely imagine someone trying to build a game with Helix 3D. It's just not what Helix 3D is good at. Instead, it's AMAZING for things like lightweight WPF-based CAD. In my case, I have an app with about 30 pages where on each page I show a single static geometry. The 2 cases when I need to render the scene are when user wants to switch to another page (happens about once per minute) and when user moves the camera (like few 5-second manipulations per minute when I actually need a decent frame rate).
0

How to change default world coordinates

Michael Powell 11 years ago updated 11 years ago 1
There's probably a simple way to do this, but how do I change the world coordinates? That is, when a default HelixViewport3D appears, and I include the gridlines, I want to extend this plane from its defaults.
0

How to read facets one by one from already loaded STL file?

Ardahan 9 years ago 0

I am loading STL file into viewport and then I want to read each facet in that model. In helixtoolkit STLReader class it is done from reading stream, but this methods is private so I can't call it in my program. Is there any public method for reading facets or should I override this existing methods?

0

Newbie. Getting started.

Anonymous 11 years ago 0
This discussion was imported from CodePlex

tfarnham wrote at 2014-04-27 04:56:

Hello,

I am having difficulty getting started with the Helix 3D Toolkit. I have cloned the repo and using Visual Studio Express 2013, I attempt to open the HelixToolkit.WPF.sln solution. Upon load, I receive the "Unsuported" notice which indicates that there is some sort of issue loading the HelixToolkit.csproj file. I'm not sure what I might be missing or the reasons for this file not being able to load. Please Help.

Thanks.

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

I don't think "Portable class libraries" (PCL) are supported by VS Express. This means you need to download a prebuilt HelixToolkit.dll core library and change the references in the projects.
0

Adding models/content to the HelixViewport3D in Helix 3D Toolkit

Anonymous 11 years ago 0
This discussion was imported from CodePlex

Rogad wrote at 2013-12-04 21:38:

I thought I would drop this in here for others too if I get a solution. I asked over on Stackoverflow, hopefully someone will be able to help with what is probably a simple problem.

I figured some of us are not so advanced and may well encounter the same, or I am just an idiot !

http://stackoverflow.com/questions/20386519/adding-models-content-to-the-helixviewport3d-in-helix-3d-toolkit

Rogad wrote at 2013-12-05 14:22:

After some experimenting I found a solution, I left the answer over on Stackoverflow.
0

Load fbx file in helix 3D

Anonymous 11 years ago 0
This discussion was imported from CodePlex

charismatubagus wrote at 2013-01-18 11:32:

Hi All,

I am newbie in helix toolkit. I would like to load fbx file programmatically by using helix toolkit. How can I do that? So far this is my xaml file look like:


<Window x:Class="WPFHelixToolkit.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" xmlns:h="http://helixtoolkit.codeplex.com">
    <Grid>
        <h:HelixViewport3D Height="311" HorizontalAlignment="Left" Name="helixViewport3D1" VerticalAlignment="Top" Width="503" >
            <h:FileModelVisual3D x:Name="model3D" >
            </h:FileModelVisual3D>
        </h:HelixViewport3D>
    </Grid>
</Window>

Please help me. Thank you. 


objo wrote at 2013-01-18 13:05:

Sorry, this library does not read fbx files. Try Autodesk's SDK at http://usa.autodesk.com/fbx/

0

is there a way to lock camera in 1 axis?

Anonymous 11 years ago 0
This discussion was imported from CodePlex

behnam263 wrote at 2014-05-11 05:41:

Hi
I want to know that if there is a way to lock camera in one axis like (Z)?
i mean have a view like you work in 2D view with zoom and rotate over z only.
tnx.
0

Finding intersection point between a PipeVisual3D and ModelVisual3D

Nit29 10 years ago updated 10 years ago 1
Is there a way to find the intersection point of a pipevisual3d and a modelvisual3d element?
0
Under review

3D Surface with Pointcloud

Misunderstood 10 years ago updated 10 years ago 2
Hey,

thanks for that great toolkit! Really like to work with it. Actually i am searching for a way to calculate a 3D surface out of a pointcloud. How am i able to do that? I allready got the points in a list (
The result should be a rectangle with drillholes.

I appreciate any kind of help.
0

BoundingSphere ,RayIntersection implementation ...

Anonymous 11 years ago 0
This discussion was imported from CodePlex

RuiTheAlmeida wrote at 2012-11-29 11:48:

Hi Objo and everybody,

First of all I want to congratulate you for this great Helix 3D tookit


I had to use one of the methods of class BoundingSphere and as it was not implemented so I did it. Feel free to test and include the code I'm sending  here.

Best  Regards,

Rui

 

        public bool RayIntersection(Ray3D ray, out Point3D[] result)
        {
            result = null;
            bool inter = false;
            double h = this.center.X ;
            double j = this.center.Y;
            double k = this.center.Z;
            double ra = this.radius;
            double x1 = ray.Origin.X ;
            double y1 = ray.Origin.Y;
            double z1 = ray.Origin.Z;
            double a = x1 - ray.Origin.X * ray.Direction.X;
            double b = y1 - ray.Origin.Y * ray.Direction.Y;
            double c = z1 - ray.Origin.Z * ray.Direction.Z;
            //Quadratic solving
            double aQ = a * a + b * b + c * c;
            double bQ = 2 * a * (x1 - h) + 2 * b * (y1 - j) + 2 * c * (z1 - k);
            double cQ = x1 * x1 + y1 * y1 + z1 * z1 + h * h + k * k + j * j - 2 * (j * y1 + k * z1 + h * x1) - ra * ra;
            //Dscriminant
            double Q = bQ * bQ - 4 * aQ * cQ;
            if (Q >= 0)
            {
                double rx1 = (-bQ + Math.Sqrt(bQ * bQ - 4 * aQ * cQ)) / (2 * aQ); //First Root
                double rx2 = (-bQ - Math.Sqrt(bQ * bQ - 4 * aQ * cQ)) / (2 * aQ); //Second Root
                //first Intersection
                Point3D I1 = new Point3D(x1 + a * rx1,y1 + b * rx1 , z1 + c * rx1);
                //Second Intersection
                Point3D I2 = new Point3D(x1 + a * rx2, y1 + b * rx2, z1 + c * rx2);
                //ray inside sphere
                if ((ray.Origin - this.center).Length <= this.radius)
                {
                    result = new Point3D[1];
                    //Check if the vectors have the same direction
                    if (Vector3D.DotProduct(ray.Direction, I1 - ray.Origin) >= 0)
                    {
                        result[0] = I1;
                    }
                    else
                    {
                        result[0] = I2;
                    }
                }
                else
                {
                    result = new Point3D[2];
                    result[0] = I1;
                    result[1] = I2;
                }
                inter = true;
            }
            else
            {
                inter = false;
            }
            return inter;
        }


objo wrote at 2012-12-04 19:45:

thanks for the code! Did you make this yourself, or do you have a reference?

I created some unit tests for this code, but could not get my last case (no intersection) to work:

        [Test, Ignore]
        public void RayInterSection_NoIntersections()
        {
            var ray = new Ray3D(new Point3D(0.2, 0.3, 1), new Vector3D(1, 0.1, 0.1));
            var sphere = new BoundingSphere(new Point3D(0.2, 0.3, 0), 1.0);
            Point3D[] result;
            Assert.IsFalse(sphere.RayIntersection(ray, out result));
            Assert.AreEqual(sphere.Radius, sphere.Center.DistanceTo(result[0]), 1e-6, "Point is not on sphere.");
            Assert.AreEqual(0, ray.GetNearest(result[0]).DistanceTo(result[0]), 1e-6, "Point is not on ray.");
        }


RuiTheAlmeida wrote at 2012-12-07 05:12:

Hi objo,

I did the all code myself, and yes I have some references from Wikipedia and other common links that I will give.

I'm also finishing a detailed presentation with the all theoretical stuff, and I will post it all here.

 

Regards,

 

Rui



RuiTheAlmeida wrote at 2012-12-09 19:11:

Hi Objo,

I've made some improvements, and you can find the new code below. I'm also posting some test cases. (I've changed your "no intersections" case )

You can also find my detailed explanation and references here

thanks,

Rui

 

 public bool RayIntersection(Ray3D ray, out Point3D[] result)
        {
            result = new Point3D[2];
            result[0] = new Point3D(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity);
            result[1] = new Point3D(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity);
            bool inter = false;
            double h = this.center.X;
            double j = this.center.Y;
            double k = this.center.Z;
            double ra = this.radius;
            double x1 = ray.Origin.X;
            double y1 = ray.Origin.Y;
            double z1 = ray.Origin.Z;
            //[a,b,c] = Ray.direction
            double a = ray.Direction.X;
            double b = ray.Direction.Y;
            double c = ray.Direction.Z;
            //Quadratic solving
            double aQ = a * a + b * b + c * c;
            double bQ = 2 * a * (x1 - h) + 2 * b * (y1 - j) + 2 * c * (z1 - k);
            double cQ = x1 * x1 + y1 * y1 + z1 * z1 + h * h + k * k + j * j - 2 * (j * y1 + k * z1 + h * x1) - ra * ra;
            //Dscriminant 
            double Q = bQ * bQ - 4 * aQ * cQ;
            if (Q >= 0) //We have at least one possible Intersection
            {
                double rx1 = (-bQ + Math.Sqrt(bQ * bQ - 4 * aQ * cQ)) / (2 * aQ); //First Root
                double rx2 = (-bQ - Math.Sqrt(bQ * bQ - 4 * aQ * cQ)) / (2 * aQ); //Second Root
                //first Possible Intersection
                Point3D I1 = new Point3D(x1 + a * rx1, y1 + b * rx1, z1 + c * rx1);
                //Second Possible Intersection
                Point3D I2 = new Point3D(x1 + a * rx2, y1 + b * rx2, z1 + c * rx2);
                //Check if I1 is intersection by laying in the ray
                if (Vector3D.DotProduct(ray.Direction, I1 - ray.Origin) >= 0)
                {
                    result[0] = I1;
                    inter = true;
                }
                //Check if I2 is intersection by laying in the ray
                if (Vector3D.DotProduct(ray.Direction, I2 - ray.Origin) >= 0)
                {
                    result[1] = I2;
                    inter = true;
                }
            }
            return inter;
        }

 

TESTS:

        [Test]
        public void RayInterSection_HasIntersections()
        {
            var ray = new Ray3D(new Point3D(0.2, 0.3, 0), new Vector3D(1, 0, 0));
            var sphere = new BoundingSphere(new Point3D(0.2, 0.3, 0), 1.0);
            Point3D[] result;
            Assert.IsTrue(sphere.RayIntersection(ray, out result));
            Assert.AreEqual(sphere.Radius, sphere.Center.DistanceTo(result[0]), 1e-6, "Point is not on sphere.");
            Assert.AreEqual(0, ray.GetNearest(result[0]).DistanceTo(result[0]), 1e-6, "Point "+ result[0] +" is not on ray.");
        }

        [Test]
        public void RayInterSection_NoIntersections()
        {
            var ray = new Ray3D(new Point3D(0.2, 0.3, 1), new Vector3D(1, 0.1, 0.1));
            var sphere = new BoundingSphere(new Point3D(0.2, 0.3, 0), 1.0);
            Point3D[] result;
            Assert.IsFalse(sphere.RayIntersection(ray, out result));
            Assert.IsTrue( double.IsInfinity(sphere.Center.DistanceTo(result[0])), "There is a finite solution 1.");
            Assert.AreNotEqual(0, ray.GetNearest(result[0]).DistanceTo(result[0]), "Point 1 is on ray.");
            Assert.IsTrue(double.IsInfinity(sphere.Center.DistanceTo(result[1])), "There is a finite solution 2.");
            Assert.AreNotEqual(0, ray.GetNearest(result[0]).DistanceTo(result[1]), "Point 2 is on ray.");
        }

        [Test]
        public void RayInterSection_TwoIntersections()
        {
            var sphere = new BoundingSphere(new Point3D(0.2, 0.3, 0), 1.0);
            var ray = new Ray3D(new Point3D(12, 23, 32), sphere.Center - new Point3D(12, 23, 32)); // vector away and pointing to the center of sphere
            
            Point3D[] result;
            Assert.IsTrue(sphere.RayIntersection(ray, out result));
            Assert.AreEqual(sphere.Radius, sphere.Center.DistanceTo(result[0]), 1e-6, "Point 1 is not on sphere.");
            Assert.AreEqual(0, ray.GetNearest(result[0]).DistanceTo(result[0]), 1e-6, "Point 1" + result[0] + " is not on ray.");
            Assert.AreEqual(sphere.Radius, sphere.Center.DistanceTo(result[1]), 1e-6, "Point 2 is not on sphere.");
            Assert.AreEqual(0, ray.GetNearest(result[1]).DistanceTo(result[1]), 1e-6, "Point 2 " + result[0] + " is not on ray.");
        }
        [Test]
        public void RayInterSection_OnlyOneIntersection()
        {
            var sphere = new BoundingSphere(new Point3D(0.2, 0.3, 0), 1.0);
            var ray = new Ray3D(sphere.Center, new Vector3D(1, 0.1, 0.1)); // vector origin in the center of sphere pointing away
            Point3D[] result;
            Assert.IsTrue(sphere.RayIntersection(ray, out result), "No intersection");
            Assert.IsTrue(sphere.Center.DistanceTo(ray.Origin ) <= sphere.Radius,"Ray origin outside sphere");
            Assert.IsFalse( double.IsInfinity(sphere.Center.DistanceTo(result[0]))  && double.IsInfinity(sphere.Center.DistanceTo(result[1])), "No Intersections");
            Assert.IsFalse(!double.IsInfinity(sphere.Center.DistanceTo(result[0])) && !double.IsInfinity(sphere.Center.DistanceTo(result[1])), "Two Intersections");   
        }

        [Test]
        public void RayInterSection_TwoTangentIntersections()
        {
            var sphere = new BoundingSphere(new Point3D(0.2, 0.3, 0), 1.0);
            var ray = new Ray3D(new Point3D(sphere.Center.X + sphere.Radius, sphere.Center.Y + sphere.Radius, sphere.Center.Z + 50), new Point3D(sphere.Center.X + sphere.Radius, sphere.Center.Y, sphere.Center.Z) - new Point3D(sphere.Center.X + sphere.Radius, sphere.Center.Y + sphere.Radius, sphere.Center.Z + 50)); // ray tangent to sphere
            Point3D[] result;
            Assert.IsTrue(sphere.RayIntersection(ray, out result), "No intersection");
            Assert.IsTrue(!double.IsInfinity(sphere.Center.DistanceTo(result[0])) && !double.IsInfinity(sphere.Center.DistanceTo(result[1])), "Less then two Intersections");
            Assert.IsTrue(result[0]==result[1], "Solutions are not equal");
        }


objo wrote at 2012-12-13 23:08:

thanks for the unit tests. I have done some modifications and submitted the changes!