For bugs and new features, use the issue tracker located at GitHub.
Also try the chat room!
Zoom out
Cygor6 wrote at 2012-11-23 22:40:
I'm beginners and would need your help! I made a console application
to save down a rendered image. BUT the camera is too close and
I can not somehow zoom out.
How do I solve this?
using System.IO; using System.Threading; using System.Windows; using System.Windows.Media; using System.Windows.Media.Media3D; using System.Windows.Shapes; using HelixToolkit.Wpf; namespace ConsoleApplication1 { internal class Program { public static IHelixViewport3D HelixView { get; set; } public static Model3D MyModel { get; set; } private static void Main(string[] args) { var thread = new Thread(Test); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); } private static void Test() { var c = new FileStream("Ferarri40.3ds", FileMode.Open, FileAccess.Read, FileShare.Read); var reader = new StudioReader {TexturePath = "."}; MyModel = reader.Read(c); var m = new ModelVisual3D {Content = MyModel}; const string Path = @"H:\test.png"; const int Height = 480; const int Width = 640; var vp = new HelixViewport3D {Width = Width, Height = Height}; vp.Viewport.Children.Add(m); vp.Children.Add(new DefaultLights()); var zoom = new ScaleTransform3D(1.5, 1.5, 1.5); var t = new Transform3DGroup(); t.Children.Add(zoom); vp.Camera.Transform = t; vp.Camera = CameraHelper.CreateDefaultCamera(); vp.Camera.Position = new Point3D(5.300, -12.300, 3.300); vp.Camera.LookDirection = new Vector3D(-6.300, 11.000, -6.600); vp.Camera.UpDirection = new Vector3D(0.000, 0.000, 1.000); vp.Camera.NearPlaneDistance = 0.123; var r = new Rectangle {Width = vp.ActualWidth, Height = vp.ActualHeight}; var cb = new BitmapCacheBrush(vp) {BitmapCache = new BitmapCache(0)}; r.Fill = cb; r.Arrange(new Rect(0, 0, r.Width, r.Height)); r.UpdateLayout(); vp.Export(Path); } } }
Position of imported model
afra89 wrote at 2011-12-21 10:04:
I have successfully imported an model and i can easily rotate it via the Transform property. But how can i set the position of the model? There is no .Center property like the Sphere and Cube..
objo wrote at 2011-12-21 12:47:
Use a
http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.translatetransform3d.aspx
and
http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.transform3dgroup.aspx
to combine it with your rotation transform.
Solved - render a scene with screen space geometry to bitmap
ezolotko wrote at 2013-08-20 06:21:
This is my dirty as hell solution to this - call this function before your render-to-bitmap code:
void InvokeRenderingEvent()
{
// For those about to hack
var mediaContextType = typeof(MatrixTransform).Assembly.GetType("System.Windows.Media.MediaContext");
var fromMethod = mediaContextType.GetMethod("From", BindingFlags.Static | BindingFlags.NonPublic);
var renderingField = mediaContextType.GetField("Rendering", BindingFlags.Instance | BindingFlags.NonPublic);
var mediaContext = fromMethod.Invoke(null, new object[] { Dispatcher.CurrentDispatcher });
var eventDelegate = (MulticastDelegate)renderingField.GetValue(mediaContext);
if (eventDelegate != null)
{
foreach (var handler in eventDelegate.GetInvocationList())
{
handler.Method.Invoke(handler.Target, new object[] { null, EventArgs.Empty });
}
}
}
Hope this will help someone, Yevgeni.
Is there any thing for moving objects?
behnam263 wrote at 2014-04-13 09:10:
I'm looking for a method or a way to move or scale or rotate objects like sphere or cube in 3d view
(not moving or rotating camera or viewport movement). Could you help me to do that?
tnx.
behnam263 wrote at 2014-04-16 23:39:
Embedded Resources
qu1ckdry wrote at 2014-03-03 17:25:
I've been enjoying the usefulness of this toolkit so far during this project! Now I'm thinking about releasing something and I'd like to embed the model I created. Is it possible to reference an embedded resource? I'd rather not release the .obj file along with my .exe.
I've read this article which uses a file stream to access a resource and I've been able to use it to open an embedded .3ds model, using:
MyModel = reader.Read(Assembly.GetExecutingAssembly().GetManifestResourceStream("HelixCs.e100.3DS"));
However I'm unable to open the texture file in the same way, nor was I able to get it working with .obj.
Any ideas how I can open an embedded model?
Thanks for any help!
Viewport2DVisual3D
DuaneTNM wrote at 2011-08-25 03:21:
Are there any examples showing Viewport2DVisual3D with HelixView3D. Can this type of 2D on 3D be achieved with the HelixToolKit.
Thanks
objo wrote at 2011-08-25 07:44:
Hi DuaneTNM, sorry there is no example using Viewport2DVisual3D. But I don't think there should be any problem to use it with the controls in HelixToolkit!
mipa87 wrote at 2011-08-30 17:42:
First, thank you for this project.
How can I use common WPF controls (buttons, sliders) with this toolkit (with supporting button click, slider value changed and etc.)? I'm using Viewport2DVisual3D for this, render is ok, but events are not triggered. What I'm doing wrong?
Thanks
Here is my code:
<helix:HelixView3D
IsHeadLightEnabled="True"
ZoomToFitWhenLoaded="True"
ShowFrameRate="True"
ShowFieldOfView="True"
ShowCoordinateSystem="True"
MouseDown="HelixView3D_MouseDown"
Name="helixView3D"
IsHitTestVisible="true">
<helix:HelixView3D.Camera>
<PerspectiveCamera
Position="0, 0, 4"/>
</helix:HelixView3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup
x:Name="group">
<DirectionalLight
Color="White"
Direction="-1, -1, -3"
/>
</Model3DGroup>
</ModelVisual3D.Content>
<Viewport2DVisual3D>
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D
Positions="-1,1,0 -1,-1,0 1,-1,0 1,1,0"
TextureCoordinates="0,0 0,1 1,1 1,0"
TriangleIndices="0 1 2 0 2 3"/>
</Viewport2DVisual3D.Geometry>
<Viewport2DVisual3D.Material>
<DiffuseMaterial
Viewport2DVisual3D.IsVisualHostMaterial="True"
Brush="White"/>
</Viewport2DVisual3D.Material>
<Viewport2DVisual3D.Visual>
<StackPanel
Orientation="Vertical">
<Button
Click="Button_Click">Button</Button>
<Slider
Value="100"
ValueChanged="Slider_ValueChanged"
/>
</StackPanel>
</Viewport2DVisual3D.Visual>
</Viewport2DVisual3D>
</ModelVisual3D>
</helix:HelixView3D>
objo wrote at 2011-08-31 20:36:
I think this is related to issue 8172, and it is not solved yet...
mipa87 wrote at 2011-09-01 00:06:
Thanks for the reply, I solved it with IsViewportHitTestVisible="True"
Here is good article about it: http://msdn.microsoft.com/en-us/library/ms752097.aspx
I have one another question, what's the difference between HelixView3D and ViewPort3DConrtroller?
And here is my working code:
<helix:HelixView3D IsViewportHitTestVisible="True"> <helix:HelixView3D.Camera> <PerspectiveCamera LookDirection="-10,-10,-10" Position="10,10,10" UpDirection="0,0,1"/> </helix:HelixView3D.Camera> <helix:DefaultLightsVisual3D/> <ModelVisual3D> <Viewport2DVisual3D > <Viewport2DVisual3D.Transform> <RotateTransform3D> <RotateTransform3D.Rotation> <AxisAngleRotation3D x:Name="uiRotate" Angle="40" Axis="0, 1, 0" /> </RotateTransform3D.Rotation> </RotateTransform3D> </Viewport2DVisual3D.Transform> <Viewport2DVisual3D.Geometry> <MeshGeometry3D Positions="-1,1,0 -1,-1,0 1,-1,0 1,1,0" TextureCoordinates="0,0 0,1 1,1 1,0" TriangleIndices="0 1 2 0 2 3"/> </Viewport2DVisual3D.Geometry> <Viewport2DVisual3D.Material> <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" Brush="White"/> </Viewport2DVisual3D.Material> <Viewport2DVisual3D.Visual> <StackPanel Orientation="Vertical"> <Button Background="Yellow" Click="Button_Click">Button1</Button> <Slider Value="100" ValueChanged="Slider_ValueChanged" /> </StackPanel> </Viewport2DVisual3D.Visual> </Viewport2DVisual3D> </ModelVisual3D> </helix:HelixView3D>
objo wrote at 2011-09-14 09:24:
try the newest version of the library, hopefully the fix on UIElements works.
Note that HelixView3D is renamed to HelixViewport3D and the IsViewportHitTestVisible property is removed.
mipa87 wrote at 2011-09-27 19:33:
Thanks, it works now correctly!
Help required in opennig a 3D model (.ply) using FileModelVisual3D in WPF
pyrrhicpk wrote at 2012-09-24 03:38:
Hi,
I have just started using HelixToolkit and trying to load a 3D model (.ply) in my WPF application using FileModelVisual3D with the following code:
FileModelVisual3D scan = new FileModelVisual3D();
scan.Source = "C:\\box.3ds";
myview.Children.Add(scan); //myview is my HelixViewport3D
this.Content = myview;
Running the above code does not show the model. Any suggestions?
Thanks
MVVM with background work
g_todeschini wrote at 2013-08-13 17:41:
In my view (UserControl class derived) I've placed the HelixViewport3D control and I've assigned an instance of my ViewModel to the DataContext property
<h:HelixViewport3D RotateGesture="Alt+RightClick" PanGesture="RightClick">
<h:HelixViewport3D.Camera>
<OrthographicCamera Position="80.22,0,0" LookDirection="-80.22,0,0" UpDirection="0,0,1" Width="56"/>
</h:HelixViewport3D.Camera>
<h:SunLight />
<ModelVisual3D Content="{Binding Model3D}" />
</h:HelixViewport3D>
The ModelVisual3D content property is binded with the Model3D propery of my ViewModel.
All works fine but I would like to create the model in a function that works in background. I've tried to do this using both the BackgroundWorker class that the Task.Factory.StartNew but I've always get the message that the object is property of another thread.
One of my attempt is the following
public class MyViewModel : BaseViewModel
{
private MyData _model; // the data on which to generate my 3d model
private Model3DGroup _model3d;
private CancellationTokenSource _source;
public Model3DGroup Model3D
{
get { return _model3d; }
set
{
if (_model3d != value)
{
_model3d = value;
RaisePropertyChanged(() => Model3D);
}
}
}
private void CreateModel3D(object dispatcherObject)
{
Dispatcher dispatcher = (Dispatcher)dispatcherObject;
Material nodesMaterial = MaterialHelper.CreateMaterial(Colors.Green);
double size = Math.Max(_model.Limits.Width, _model.Limits.Height);
double dn = size / 100;
double db = size / 120;
int thetaDiv = 10;
foreach (Strauss.Node node in _model.Nodes)
{
MeshBuilder meshBuilder = new MeshBuilder(false, false);
meshBuilder.AddSphere(new Point3D(node.X, node.Y, node.Z), dn, thetaDiv, thetaDiv / 2);
MeshGeometry3D mesh = meshBuilder.ToMesh(true);
dispatcher.Invoke((Action)(() => _model3d.Children.Add(new GeometryModel3D { Geometry = mesh, Material = nodesMaterial, BackMaterial = nodesMaterial })));
}
}
private void ModelLoaded(object sender, EventArgs args)
{
System.Windows.Window win = App.Current.Windows[0];
DocManagerViewModel docManager = win.DataContext as DocManagerViewModel;
_source = new CancellationTokenSource();
Task task = Task.Factory.StartNew(CreateModel3D, _model3d.Dispatcher, _source.Token);
}
}The process starts from the ModelLoaded event handler.
Can anyone please help me?
Thanks in advance.
RobPerkins wrote at 2013-08-14 18:02:
2 -- All WPF objects, including GeometryModel3D and MeshGeometry3D, have to be "Frozen" to be passed between threads. See "Freezable" in the MSDN documentation.
Change the code in CreateModel3D from what you have to something like:
var gm3d = new GeometryModel3D { Geometry = mesh, Material = nodesMaterial, BackMaterial = nodesMaterial };
dispatcher.Invoke((Action)(() => _model3d.Children.Add(gm3d.GetAsFrozen())));
HelixViewport3d::SphereVisual3D - How to add children via XAML (and a back end binding)?
BogusException wrote at 2014-07-18 19:15:
I have the back end down. Right now, the XAML is the pain.
Given the following working XAML, how should I implement the backend collection of "Conns" (Connections, or Flights) in the Current Flight Demo code (which this came from)?
Below in the abbreviated XAML, this section toward the bottom is the one in question:
<ItemsControl ItemsSource="{Binding Conns}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Viewport3D /> <--- ??? or...?
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
I'm 100% on the backend. I just can't figure out how to make the XAML under Helix3D ready to bind to/show the collection...
Any help at all REALLY appreciated!!!
pat
:)
<Window x:Class="TheEarthWindow"
x:Name="TheGlobe"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:t="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf"
Title="TheEarthWindow" Height="800" Width="800">
<Grid>
<Grid.Resources>
[...]
</Grid.Resources>
<Grid.Triggers>
[...]
</Grid.Triggers>
<t:HelixViewport3D x:Name="view1"
Background="Black"
CameraRotationMode="Turnball"
ClipToBounds="False"
Grid.Column="0"
IsHeadLightEnabled="True"
IsHitTestVisible="True"
IsPanEnabled="False"
IsZoomEnabled="True"
MouseDown="OnMouseDown"
MouseMove="OnMouseMove"
ShowCameraInfo="False"
ShowCameraTarget="False"
ShowCoordinateSystem="False"
ShowFieldOfView="False"
ShowFrameRate="True"
ShowTriangleCountInfo="False"
ShowViewCube="True"
SubTitle="vASA Global Monitor"
SubTitleSize="40"
Title="vASA"
ZoomExtentsWhenLoaded="True" >
<t:HelixViewport3D.Camera>
<PerspectiveCamera Position="600,27400,0"
LookDirection="0,1,0"
UpDirection="0,0,1"
NearPlaneDistance="0.01"
FarPlaneDistance="Infinity"
FieldOfView="40">
<PerspectiveCamera.Transform>
<Transform3DGroup>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="0,0,1" Angle="0" x:Name="camRotation" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Transform3DGroup>
</PerspectiveCamera.Transform>
</PerspectiveCamera>
</t:HelixViewport3D.Camera>
<t:SunLight />
<t:SphereVisual3D x:Name="TheEarthSphere"
Material="{StaticResource EarthJPG}"
Radius="1"
ThetaDiv="25"
PhiDiv="25" >
<!-- WHAT GOES HERE FOR TUBES? -->
<ItemsControl ItemsSource="{Binding Conns}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Viewport3D /> <--- ??? or...?
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<!-- IS THE ABOVE EVEN IN THE RIGHT PART OF THE TREE? -->
</t:SphereVisual3D>
</t:HelixViewport3D>
</Grid>
</Window>
Event that fires when the camera stops moving
everytimer wrote at 2014-07-31 21:24:
I'm doing it now by subscribing to every MouseEvent that allows interaction with the camera (specifically ButtonUp). The problem is that when the user has zoomed I don't have a way to know when he has stopped zooming. Other issue of capturing mouse events is that when the camera change has been generated programatically (set some saved view, etc) and there is some animation I can't do it either.
I would like to know if there is some event that I can subscribe to know when the Camera is "done", when it has stopped moving.
If such event doesn't exist I would like to know if it is possible to create one without modifying the source code of HelixToolKit and how it could be done.
Thank you very much.
Customer support service by UserEcho