1

我是 helixtoolkit 和 Graphics 3D 领域的真正新手。

我做什么:

我有作业编写一个程序,它可以让你用不同类型的装饰来装饰圣诞树。

一种装饰是蜡烛。问题。与树相比,蜡烛太小了。

我的问题:

如何使用后面的代码在 view_tree 内调整 FileModelVisual3D 的大小?

private void view_tree_MouseDown(object sender, MouseButtonEventArgs e)
    {   
        if (typeOfdecoration == 1)
        {
            Decoration1Visual3D decoration;
            decoration = new Decoration1Visual3D();
            decoration.Fill = Brushes.Red;
            Point3D? pt = view_tree.FindNearestPoint(e.GetPosition(view_tree));
            if (pt.HasValue)
            {
                Point3D p = pt.Value;
                decoration.Transform = new TranslateTransform3D(p.X, p.Y, p.Z);
                view_tree.Children.Add(decoration);
                MessageBox.Show(decoration.ToString());
                decoration = null;
            }
        }
        else if (typeOfdecoration == 2)
        {
            FileModelVisual3D fmv3D = new FileModelVisual3D();
            fmv3D.Source = "C:/Users/flori/Documents/Schulisches/WFSST/christmastree_burtscherflorian/christmastree_burtscherflorian/2245176fd65db964db79f88f870f8154/candle.3DS";

            Point3D? pt = view_tree.FindNearestPoint(e.GetPosition(view_tree));
            if (pt.HasValue)
            {
                Point3D p = pt.Value;

                fmv3D.Transform = new TranslateTransform3D(p.X, p.Y, p.Z);

                view_tree.Children.Add(fmv3D);

                MessageBox.Show(fmv3D.ToString());
                fmv3D = null;
            }
        }

    }

XAML 代码

    <helix:HelixViewport3D x:Name="view_tree" Camera="{helix:PerspectiveCamera 5.3,-12.3,900,-6.3,11,-6.6}" CameraChanged="view_tree_CameraChanged" MouseDown="view_tree_MouseDown" Grid.Row="0" Grid.Column="0">
        <helix:SunLight/>
        <helix:FileModelVisual3D x:Name="model_tree" Source="c:/Users/flori/Documents/Schulisches/WFSST/christmastree_burtscherflorian/christmastree_burtscherflorian/Conifers tree 1 N100616.3DS"/>
    </helix:HelixViewport3D>
    <StackPanel Grid.Row="0" Grid.Column="1">
        <RadioButton Name="rb_candle" Margin="10,10,10,0" IsChecked="True" Checked="rb_candle_Checked">Kerze</RadioButton>
        <RadioButton Name="rb_ball" Margin="10,10,10,10" Checked="rb_candle_Checked">Kugel</RadioButton>
    </StackPanel>

希望任何人都可以提供帮助!我知道对其他人来说这很容易,但我没有 3D 编码方面的经验。

谢谢

4

1 回答 1

2

除了你的TranslateTransform3D,应用一个ScaleTransform3D. 将它们都放入 aTransform3DGroup并将其用作Transform您的FileModelVisual3D

double factor = 2.0;
var transformGroup = new Transform3DGroup();
transformGroup.Children.Add(new TranslateTransform3D(p.X, p.Y, p.Z));
transformGroup.Children.Add(new ScaleTransform3D(factor, factor, factor));
fmv3D.Transform = transformGroup;

当然,您可能需要调整因子。

于 2017-01-26T20:10:25.373 回答