none
前后台 关于 3D代码的区别 RRS feed

  • 问题

  • <Viewport2DVisual3D>
                        <Viewport2DVisual3D.Transform>
                            <RotateTransform3D>
                                <RotateTransform3D.Rotation>
                                    <AxisAngleRotation3D x:Name="axisUI" Axis="1,1,0" Angle="0"/>
                                </RotateTransform3D.Rotation>
                            </RotateTransform3D>
                        </Viewport2DVisual3D.Transform>
                        <Viewport2DVisual3D.Geometry>
                            <MeshGeometry3D Positions="-1,-1,0 -1,1,0 1,1,0 1,-1,0" TriangleIndices="0,1,2 2,3,0" TextureCoordinates="1,1 1,0 0,0 0,1"/>
                        </Viewport2DVisual3D.Geometry> 
                        
                        <Viewport2DVisual3D.Material>
                            <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
                        </Viewport2DVisual3D.Material>

                        <Viewport2DVisual3D.Visual>
                            <Border BorderBrush="Yellow" BorderThickness="2">
                                <Button Content="1fdsfsfs" Click="Button_Click"/>
                            </Border>
                        </Viewport2DVisual3D.Visual>
                    </Viewport2DVisual3D>

     

    这段

    转换成后台代码

     

     Viewport2DVisual3D CreateVisual3D()
            {
                Viewport2DVisual3D viewport2DVisual3D = new Viewport2DVisual3D();
                viewport2DVisual3D.SetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty, true);
                viewport2DVisual3D.Geometry = new MeshGeometry3D()
                {
                    Positions = new Point3DCollection(
                        new Point3D[]
                        {
                             new Point3D(-1,-1,0),
                             new Point3D(-1,1,0),
                             new Point3D(1,1,0),
                             new Point3D(1,-1,0)
                        }),
                    TriangleIndices = new Int32Collection(
                        new int[] { 0, 1, 2, 2,3,0 }),

                    TextureCoordinates = new PointCollection(
                        new Point[]
                                {
                                    new Point(1,1),
                                    new Point(1,0),
                                    new Point(0,0),
                                    new Point(0,1)
                                })

                };
                viewport2DVisual3D.Transform = SetModelTransform();
                viewport2DVisual3D.Visual = new Border()
                {
                    Width = 50,
                    Height = 50,
                    BorderBrush = Brushes.Yellow,
                    Background = Brushes.Red,
                    BorderThickness = new Thickness(2),
                    Child = new Button { Content = "test" }
                };
                return viewport2DVisual3D;

            }
            private AxisAngleRotation3D axisAngleRotation3D = new AxisAngleRotation3D();
            Transform3DGroup SetModelTransform()
            {
                axisAngleRotation3D.Axis = new Vector3D(1, 1, 0);
                axisAngleRotation3D.Angle = 0;
                Transform3DGroup transform3DGroup = new Transform3DGroup();

                TranslateTransform3D translateTransform3D = new TranslateTransform3D(0, 0, 0);
                transform3DGroup.Children.Add(translateTransform3D);
                ScaleTransform3D scaleTransform3D = new ScaleTransform3D(1, 1, 1);
                RotateTransform3D rotateTransform3D = new RotateTransform3D
                {
                    Rotation = axisAngleRotation3D,
                };
                transform3DGroup.Children.Add(rotateTransform3D);


                return transform3DGroup;
            }

    然后添加 Viewport2DVisual3D  到ViewPort3D 怎么不显示呢

    我觉得问题貌似是出现在加粗的地方,但是不知道怎么样去改


    Hero
    2011年10月17日 14:12

答案

  • 已解决

      DiffuseMaterial diffuseMaterial = new DiffuseMaterial();
                diffuseMaterial.SetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty, true);
                viewport2DVisual3D.Material = diffuseMaterial;

    这样就可以了

    Ocean He  教的


    Hero

    2011年10月17日 14:50