gpt4 book ai didi

wpf - 从代码添加 Viewport2DVisual3D 时出现问题

转载 作者:行者123 更新时间:2023-12-05 08:02:56 26 4
gpt4 key购买 nike

我试图在代码中将 Viewport2DVisual3D 添加到 Viewport3D,但视觉对象未显示。任何帮助理解为什么不将不胜感激。以下是主窗口的代码。

是否仅将 Viewport2DVisual3D 添加到 Viewport3D 的子级以使其被渲染就足够了?

public partial class Window1 : System.Windows.Window
{

public Window1()
{
InitializeComponent();

this.Loaded += new RoutedEventHandler(temp);
}


public void temp(object sender, RoutedEventArgs e)
{
Viewport2DVisual3D test = new Viewport2DVisual3D();
MeshGeometry3D testGeometry = new MeshGeometry3D();

Vector3D CameraLookDirection = Main_Target_CameraOR20.LookDirection;

// Calculate the Positions based on the Camera
Point3DCollection myPoint3DCollection = new Point3DCollection();
myPoint3DCollection.Add(new Point3D(-1, 1, 0));
myPoint3DCollection.Add(new Point3D(-1, -1, 0));
myPoint3DCollection.Add(new Point3D(1, -1, 0));
myPoint3DCollection.Add(new Point3D(1, 1, 0));
testGeometry.Positions = myPoint3DCollection;

PointCollection myPointCollection = new PointCollection();
myPointCollection.Add(new Point(0, 0));
myPointCollection.Add(new Point(0, 1));
myPointCollection.Add(new Point(1, 1));
myPointCollection.Add(new Point(1, 0));
testGeometry.TextureCoordinates = myPointCollection;

Int32Collection triangleIndicesCollection = new Int32Collection();
triangleIndicesCollection.Add(0);
triangleIndicesCollection.Add(1);
triangleIndicesCollection.Add(2);
triangleIndicesCollection.Add(2);
triangleIndicesCollection.Add(3);
triangleIndicesCollection.Add(0);
testGeometry.TriangleIndices = triangleIndicesCollection;


DiffuseMaterial myDiffuseMaterial = new DiffuseMaterial(Brushes.White);
Viewport2DVisual3D.SetIsVisualHostMaterial(myDiffuseMaterial, true);

Transform3DGroup myTransform3DGroup = new Transform3DGroup();
ScaleTransform3D myScaleTransform3D = new ScaleTransform3D();
myScaleTransform3D.ScaleX = 2;
myScaleTransform3D.ScaleY = 2;
myScaleTransform3D.ScaleZ = 2;

TranslateTransform3D myTranslateTransform3D = new TranslateTransform3D();

myTranslateTransform3D.OffsetX = -27;
myTranslateTransform3D.OffsetY = 13;
myTranslateTransform3D.OffsetZ = 6;


RotateTransform3D rotateTransform = new RotateTransform3D()
{
Rotation = new AxisAngleRotation3D
{
Angle = -50,
Axis = new Vector3D(0, 1, 0)
}
};

myTransform3DGroup.Children.Add(myTranslateTransform3D);
myTransform3DGroup.Children.Add(myScaleTransform3D);
myTransform3DGroup.Children.Add(rotateTransform);
test.Transform = myTransform3DGroup;

Button myButton = new Button();
myButton.Content = "Test Button";

test.Material = myDiffuseMaterial;
test.Geometry = testGeometry;
test.Visual = myButton;

ZAM3DViewport3D.Children.Add(test);
}
}

最佳答案

原来是Offset值的问题。因此,将子项添加到 Viewport3D 以使其呈现就足够了。干杯

关于wpf - 从代码添加 Viewport2DVisual3D 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2390941/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com