Frage

I have just started with Helix 3d.What i want to do is create a sphere and to rotate it on it's axis, on some user interaction, say (on swipe) or using the mouse to rotate it.

The code below works, but i am not able to see any of the colors used. Also can anyone explain why it's happening?

I just copied and pasted the code i found here! here's the output i get Ouput Image

Here's the code,in C# MainWindow.XAML.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Media.Media3D;
    
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using HelixToolkit;
    using HelixToolkit.Wpf;

namespace helixdemo1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        protected RotateManipulator r1Manip { get; set; }
        protected RotateManipulator r2Manip { get; set; }
        protected RotateManipulator r3Manip { get; set; }
        
        
        public MainWindow()
        {
            InitializeComponent();
            Create3DView();
        }

        private void Create3DView()
        {
            var builder = new MeshBuilder(true, true);
            var position = new Point3D(0, 0, 0);
            builder.AddSphere(position, 1,15,15);
           
            var geom = new GeometryModel3D(builder.ToMesh(), Materials.Brown);
            var visual = new ModelVisual3D();
            visual.Content = geom;
            
            r1Manip = new RotateManipulator();
            r1Manip.Color = Colors.Orange;
            r1Manip.Axis = new Vector3D(0, 0, 1);
            r1Manip.Diameter = 1;
            r1Manip.Bind(visual);

            r2Manip = new RotateManipulator();
            r2Manip.Color = Colors.Blue;
            r2Manip.Axis = new Vector3D(0, 1, 0);
            r2Manip.Diameter = 1;
            r2Manip.Bind(visual);

            r3Manip = new RotateManipulator();
            r3Manip.Color = Colors.Green;
            r3Manip.Axis = new Vector3D(1, 0, 0);
            r3Manip.Diameter = 1;
            r3Manip.Bind(visual);

            ModelArea.Children.Add(r1Manip);
            ModelArea.Children.Add(r2Manip);
            ModelArea.Children.Add(r3Manip);

            ModelArea.Children.Add(visual);
        }
        
    }
}

And Here's the XAML code

<Window x:Class="helixdemo1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:HelixToolkit="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf"        
        Title="MainWindow" Height="605" Width="597">

    <Grid>
        <Grid Width="300" Height="300" Margin="0,25,0,0" VerticalAlignment="Top" HorizontalAlignment="Center" >
            <HelixToolkit:HelixViewport3D x:Name="viewport"  ZoomExtentsWhenLoaded="True">
                <ModelVisual3D x:Name="ModelArea"></ModelVisual3D>
            </HelixToolkit:HelixViewport3D>
        </Grid>
    </Grid>
</Window>
War es hilfreich?

Lösung

As far as the colors are concerned you forgot to set the lights for the scene:
No lights->black objects!
Try this:

    <Grid>
        <Grid Width="300" Height="300" Margin="0,25,0,0" VerticalAlignment="Top" HorizontalAlignment="Center" >
        <HelixToolkit:HelixViewport3D x:Name="viewport"  ZoomExtentsWhenLoaded="True">
            <HelixToolkit:DefaultLights/>
            <ModelVisual3D x:Name="ModelArea"></ModelVisual3D>
        </HelixToolkit:HelixViewport3D>
        </Grid>
    </Grid>

or you can add this line inside your .cs file (at the beginning of Create3DView() for example):

viewport.Children.Add(new DefaultLights());
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top