For bugs and new features, use the issue tracker located at GitHub.
Also try the chat room!
Refreshing Viewport
murray_b wrote at 2012-04-23 05:33:
Hi Objo
I am having issues with drawing of a line on the viewport.
I am drawing by mousedown and mousemove. With the mousemove reseting the second point in the line LineVisual3D.
What I am not getting is the line being drawn on the viewport. Even once I stop the drawing (using MouseUp) it is not until I rotate the viewport that the line is drawn on the viewport.
I am sure I am missing something simple here but I can't work out what it is. Any ideas what I might be doing wrong to not have the viewport automatically refreshing. Is there a method I can call to force the redraw?
thanks
Murray
private void HViewPortMouseDown(object sender, MouseButtonEventArgs e) { // first see if they have selected an item only allow selection of drillholes var helix = (HelixViewport3D) sender; Point position = e.GetPosition(helix); Visual3D obj = helix.FindNearestVisual(position); if (obj != null) { // First create a new line _measureline = new LinesVisual3D {Color = Colors.White}; _measureline.DepthOffset = 0.001; _measureLinePoint2 = new Point3D(); Point3D? findNearestPoint = helix.FindNearestPoint(position); if (findNearestPoint != null) { _measureline.Points.Add((Point3D) findNearestPoint); _measureLinePoint2 = (Point3D) findNearestPoint; _measureline.Points.Add(_measureLinePoint2); Children.Add(_measureline); RaisePropertyChanged("_measureline"); _measuring = true; MouseMove += HViewPortMouseMove; } } } private void HViewPortMouseMove(object sender, MouseEventArgs e) { if (_measuring) { var helix = (HelixViewport3D) sender; Point position = e.GetPosition(helix); Point3D? obj = helix.FindNearestPoint(position); _measureline.Points.Remove(_measureLinePoint2); if (obj != null) _measureLinePoint2 = (Point3D) obj; _measureline.Points.Add(_measureLinePoint2); RaisePropertyChanged("_measureline"); RaisePropertyChanged("Objects"); } } private void HViewPortMouseUp(object sender, MouseButtonEventArgs e) { if (_measuring) { // Objects.Remove(_measureline); _measuring = false; } }
murray_b wrote at 2012-04-23 05:55:
Ok
So I have discovered this is a bug with LinesVisual3d.
Because If I change the code to use a PipeVisual3d it works fine.
Regards
Murray
objo wrote at 2012-04-25 07:05:
Notice that the LinesVisual3D.Points property is an IList (not implementing INotifyCollectionChanged). This means the visual will not be redrawn until you change the property (replace the points collection) or change the camera (since this is a visual in screen space).
PipeVisual3D is updated every time you change the Point1 or Point2 properties.
xpix wrote at 2014-02-14 12:28:
i guess i have the same Problem. I want to use the LinesVisual3d and not the pipes. At this time, i have a one Question. How can i reset the camera without move to start position? As i right understand, to redraw the LinesVisual3d i have to move the camera a little bit. Or can i use a special event or methode to redraw the screen and the camera pos is still?
Here my short code:
public void refreshCamera(){
camera.UpDirection = new Vector3D(camera.UpDirection.X, camera.UpDirection.Y, camera.UpDirection.Z);
camera.Position = new Point3D(camera.Position.X, camera.Position.Y, camera.Position.Z);
camera.LookDirection = new Vector3D(camera.LookDirection.X - 0.001, camera.LookDirection.Y, camera.LookDirection.Z);
camera.LookAt(new Point3D(0, 0, 0), 1);
viewport.ResetCamera();
}
Please help :)objo wrote at 2014-02-19 21:03:
ItemSource in HelixViewport3D using MVVM
Polymania wrote at 2012-04-25 08:05:
Hello,
I have a problem in using the HelixViewport3D in a MVVM context. My ItemSource is an ObservableCollection of Visual3D-Elements and it works well when I change the Collection after the Viewport is created and the Binding to the Collection is done. But in my case the Collection is not empty when I create the Viewport and then the initial Elements are not drawn in the Viewport. I think the Viewport should refresh the Viewport-Elements when the ItemSource-Property changes. Would it be possible to implement this in the HelixViewport3D class?
Andreas
Polymania wrote at 2012-06-26 09:27:
Hello,
to solve this problem I added the following code in HelexViewport3D:
protected override void OnItemsSourceChanged(System.Collections.IEnumerable oldValue, System.Collections.IEnumerable newValue) { base.OnItemsSourceChanged(oldValue, newValue); if (oldValue != null) { foreach (var element in oldValue) { var visual = element as Visual3D; if (visual != null) { this.Children.Remove(visual); } } } if (newValue != null) { foreach (var element in newValue) { var visual = element as Visual3D; if (visual != null) { this.Children.Add(visual); } } } }
Would it be possible to add this to the current Version of Helix?
Thanks
Andreas
objo wrote at 2012-06-26 10:02:
Thanks for the solution! Checked in the code!
ggalan87 wrote at 2012-08-24 10:02:
I 'm posting here since it's related issue. Not sure if it would be helix-specific or WPF-specific though :)
I want to have for boxes with text (tags) on them and arrows that show their rotation (direction) in 3D space. I also want to hide/show the arrows and the text.
As in MVVMDemo of the toolkit I use a Collection for the Boxes, and also other collections to seperate the text and the arrows. In the XAML I use MultiBinding and a Converter which merges the collections so they can be aggregated to the ItemSource of the Viewport. I also have a seperate collection for the lights. I already use relay commands to check boxes to how or hide the text or the arrows.
I' m doing the job this way, but I 'm thinking of altering this approach because as it is I have to put so much code in the ViewModel to create each box and bind the arrow and the text position to it. I 'm thinking of creating a datatemplate somehow holding a ContainerUIElement3D as root element and holds a BoxVisual3D, a TextVisual3D and an ArrowVisual3D. This is not possible as I 've tested and read, so I probably have to place it in a ResourceDictionary. The other option is to place text and arrow as children of the BoxVisual3D.
Since I don't have much experience using MVVM, I would like to ask how can I have a "DataTemplate" of that ResourceDictionary similar to what I can perform id 2D:
<DataTemplate DataType="{x:Type local:ObjectViewModel}"><local:ObjectView /> </DataTemplate>
and having my SceneViewModel (it's View has the Viewport) to have a Collection of ObjectViewModels, so that it can draw my ObjectViewModel. The ViewModel would have a constructor that takes the Model.
Is there any other solution that applies to my problem?
MrSparkle wrote at 2012-11-09 10:15:
Yes, I miss Databinding in 3d, too. There seems to be no way to bind a collection of objects to the viewport's or to a Visual3D's Children property just as you would do in 2d. Is there anything we can do using the Helix Viewport?
objo wrote at 2012-11-12 21:15:
I think it should be possible to implement a new "DataTemplate3D" class similar to DataTemplate. DataTemplate cannot be used since it only allows FrameworkElement content. Then it should be possible to implement an "ItemsVisual3D" class that creates Visual3D instances from the DataTemplate3D. But I think it is a challenge to set up the bindings, since Visual3D/Model3D objects does not have data contexts...
http://stackoverflow.com/questions/7725313/how-can-i-use-databinding-for-3d-elements-like-visual3d-or-uielement3d
objo wrote at 2012-11-12 22:08:
I added an experimental example to ExampleBrowser/Examples/DataTemplate. The template factory method needs more work to be useful...
MrSparkle wrote at 2012-11-13 09:16:
objo wrote:
I think it should be possible to implement a new "DataTemplate3D" class similar to DataTemplate...
I really like this idea! And I would really appreciate if there is a solution for this problem some day. I'm currently working on an application where content is displayed in a 3d viewport and the user can directly interact with the 3d objects. At first I thought, I simply could bind my ViewModel against the viewport's content the way I built all my WPF applications. But then I realized it wouldn't work because something like the "DataTemplate3D" is missing.
It would be great to define Templates, Styles and Triggers to change the appearance of the 3d objects and make everything work like in "normal" WPF. I looked into your sample and I definitely like the idea of the DataTemplate3D and the ItemsVisual3D!
Christian
cedrelo wrote at 2013-05-14 14:57:
var prop = type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);
foreach (var p in prop)
{
if (p.CanWrite && !boundProperties.Contains(p.Name))
{
var value = p.GetValue(this.Content, null);
p.SetValue(visual, value, null);
}
}
objo wrote at 2013-06-07 11:47:
DataTemplate
, but I think the solution should be somewhere in PresentationFramework.dll :-)Same 3D-Model act like different one?
I load STL files to helixviewport3d and store them in dictionary as key and file name as value.
But then I load same STL file and check if it is already in dictionary. But then It is not found and adding same model into viewport. where do i go wrong?
How to tell TextVisual3D dimensions
MeshBuilder Revolve WPF Lines
mcrxb wrote at 2012-01-18 18:43:
Hello,
Is it possible to use MeshBuilder to create a revolved mesh from WPF lines and arcs?
Thank you!
objo wrote at 2012-01-18 18:50:
see the AddRevolvedGeometry method:
public void AddRevolvedGeometry(IList<Point> points, Point3D origin, Vector3D direction, int thetaDiv)
mcrxb wrote at 2012-01-23 13:24:
Thanks for the quick reply. I was wondering, though, if I could take a WPF object like Path and revolve that. If not, do you have a small sample app that utilizes MeshBuilder for creating revolves? I couldn't find any uses in the sample applications.
Thank you.
objo wrote at 2012-01-26 20:07:
Most of the Visual3D classes in the toolkit is using the MeshBuilder to generate the geometry. See the ArrowVisual3D.Tesselate() method (using an AddArrow method that again uses AddRevolvedGeometry).
No, the revolve method is not accepting Path objects (this would be more work to support all the different path segment types), it just takes a simple list of points.
Camera view of rectangles
I am new to 3d manipulation esp with helix toolkit.
Am trying to have a camera fixed to a side of rectangle. When the rectangle is rotated or moved, the camera should relatively change it's view. Is there any property that ties the camera to an object or a specific vector of an object? Also, there will be 2 rectangles used as planes intersecting making an 'X' shape from the top view. So there has to be 2 views of one side of each plane and a top view.
I am looking forward to understand a way to make this work.Thanks!
Display the 3D mesh
kirru wrote at 2013-11-16 10:06:
I loaded the .obj file into WPF visual c# application, now the issue is how to display the mesh generated by that .obj file using Helix tiilkit. Any help is appreciated.
objo wrote at 2013-11-19 22:27:
See Source\Examples\SimpleDemo and Source\Examples\ModelViewer and http://www.nudoq.org/#!/Packages/HelixToolkit/HelixToolkit.Wpf/ObjReader
Two questions on Manipulator
damianoslebo wrote at 2013-02-12 01:36:
CubeVisual3D box = new CubeVisual3D();
box.Center = new Point3D(x, y, z);
CombinedManipulator boxManipulator = new CombinedManipulator();
boxManipulator.Position = box.Center;
boxManipulator.Pivot = box.Center;
boxManipulator.CanRotateX = false;//true;
boxManipulator.CanRotateY = false;// true;
boxManipulator.CanRotateZ = false;// true;
boxManipulator.CanTranslateX = false;// true;
boxManipulator.CanTranslateY = false;// true;
boxManipulator.CanTranslateZ = true;
boxManipulator.Bind(box);
vp.Children.Add(boxManipulator);
vp.Children.Add(box);
globalManipulatorList.Add(boxManipulator);
I can get the manipulator to work in the x and y and all rotation directions, however the Z translate direction does not show up on the viewport. I don't know why the other directions work but Z does not work.The second question is what event can invoke when using a transparent bounding volume to detect a mouse left button down on the manipulator? I have been using the VisualTreeHelper.HitTest method to ignore transparent geometry before now but I don't know what method can be invoked once a manipulator is found by the VisualTreeHelper.HitTest method.
Thanks for the help,
Damian
objo wrote at 2013-03-12 11:41:
1: Thanks for the notice - I see some change had broken the TranslateManipulator. I removed the default value of the Direction property, now it seems to work again.
2: Sorry, I don't quite understand the problem here. Please make an example that we can debug!
Manipulators to stretch and move box
christianw42 wrote at 2013-06-17 14:03:
i have a little problem with adding manipulators to an visual via code, in my case a BoxVisual3D.
I define a box an two manipulators, one for moving, one for resizing:
var volumeBox = new BoxVisual3D();
volumeBox.Center = new Point3D(0, 0, 0);
volumeBox.Length = 0.3;
volumeBox.Width = 0.3;
volumeBox.Height = 0.3;
volumeBox.Material = MaterialHelper.CreateMaterial(Colors.SkyBlue, 0.3);
var xManipulator = new TranslateManipulator();
xManipulator.Color = Colors.Red;
xManipulator.Length = 0.4;
xManipulator.Diameter = 0.02;
xManipulator.Position = new Point3D(0, 0, 0);
xManipulator.Direction = new Vector3D(-1, 0, 0);
xManipulator.Offset = new Vector3D(-1, 0, 0);
xManipulator.Bind(volumeBox);
var xStretchManipulator = new TranslateManipulator();
xStretchManipulator.Color = Colors.SpringGreen;
xStretchManipulator.Length = 0.3;
xStretchManipulator.Diameter = 0.02;
xStretchManipulator.Position = new Point3D(0, 0, 0);
xStretchManipulator.Direction = new Vector3D(-1, 0, 0);
xStretchManipulator.Offset = new Vector3D(0, 0, 0);
//xStretchManipulator.Bind(volumeBox);
var binding = BindingOperations.SetBinding(
xStretchManipulator, TranslateManipulator.ValueProperty, new Binding("Length") { Source = volumeBox, Converter = new LinearConverter { M = 0.5 }});
binding.UpdateTarget();
//var targetBinding = BindingOperations.SetBinding(
// xStretchManipulator, TranslateManipulator.TransformProperty, new Binding("Transform") { Source = volumeBox });
//targetBinding.UpdateTarget();
//var targetTransformBinding = BindingOperations.SetBinding(
// xStretchManipulator, TranslateManipulator.TargetTransformProperty, new Binding("Transform") { Source = volumeBox });
//targetTransformBinding.UpdateTarget();
The code above works fine for resizing and moving the box, but the manipulator for resizing (xStretchManipulator) does not move with the box. When I add the transform-bindings to the xStretchManipulator, it moves with the box, but position is always in the
center of the box and when you stretch to much, manipulator is inside the box. Does anyone have an idea how to define and bind the manipulators, so that it works correctly?
Thanks a lot for any help or ideas!
christian
Customer support service by UserEcho