none
wpf 添加 ModelUIElement3D 不显示 RRS feed

  • 问题

  • 先说问题,我自己用Cs代码 生成 了ModelUIElement3D,然后用Children.Add的方法把它加入到ContainerUIElement3D中,但是,它却不显示 ,我用这样的方法加入的光源是可以显示的。

    请大侠帮我看一下错误,或者给我一个如何用cs生成并添加到xaml中已有的ContainerUIElement3D中的例子,万谢。

    XAML:

    <Viewport3D Grid.Row="0" x:Name="MyViewPort" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <Viewport3D.Camera> <PerspectiveCamera Position="0,800,1200" LookDirection="0,-2,-2" /> </Viewport3D.Camera> <ContainerUIElement3D x:Name="MyCUIE3D"> <ModelUIElement3D> <ModelUIElement3D.Model> <Model3DGroup> <GeometryModel3D> <GeometryModel3D.Geometry> <MeshGeometry3D TriangleIndices = "0 1 2 2 3 0 2 7 3 3 7 4 2 1 6 6 7 2 5 4 7 7 6 5 3 4 5 5 0 3 5 6 0 0 6 1" Positions= "0,0,0 100,0,0 100,0,100 0,0,100 0,0,100 0,100,0 100,100,0 100,100,100" /> </GeometryModel3D.Geometry> <GeometryModel3D.Material> <DiffuseMaterial Brush="Orange"></DiffuseMaterial> </GeometryModel3D.Material> </GeometryModel3D> </Model3DGroup> </ModelUIElement3D.Model> </ModelUIElement3D> </ContainerUIElement3D>

    .CS

     public void MyInit()
            {
                ModelUIElement3D me = _3DFactory.Juxing3D(new Point3D(0, 0,200), 1000, 1000, 1000);
                ModelUIElement3D light = new ModelUIElement3D();
                DirectionalLight dlight = new DirectionalLight();
                dlight.Color = Color.FromRgb(0xff, 0xff, 0xff);
                light.Model = dlight;
                MyCUIE3D.Children.Add(me);
                MyViewPort.Children.Add(light);
            }

    ModelUIElement3D的生成代码:

            public static ModelUIElement3D Juxing3D(Point3D p,int width,int length,int height)
            {
                ModelUIElement3D mui = new ModelUIElement3D();
                Model3DGroup mdgroup = new Model3DGroup();
                GeometryModel3D gm3d = new GeometryModel3D();
                MeshGeometry3D msh = new MeshGeometry3D();
                DiffuseMaterial dmater = new DiffuseMaterial();
                Point3DCollection pc = new Point3DCollection();
                #region 计算每个顶点
                pc.Add(new Point3D(p.X, p.Y, p.Z));
                pc.Add(new Point3D(p.X+length,p.Y,p.Z));
                pc.Add(new Point3D(p.X+length,p.Y,p.Z+width));
                pc.Add(new Point3D(p.X,p.Y,p.Z+width));
                pc.Add(new Point3D(p.X,p.Y,p.Z+width));
                pc.Add(new Point3D(p.X,p.Y+height,p.Z));
                pc.Add(new Point3D(p.X+length,p.Y+height,p.Z));
                pc.Add(new Point3D(p.X+length,p.Y+height,p.Z+width));
                #endregion
                Int32Collection ic = new Int32Collection() { 0,1,2 , 2,3,0 , 2,7,3 , 3,7,4 , 2,1,6 , 6,7,2 , 5,4,7 , 7,6,5 , 3,4,5 , 5,0,3 , 5,6,0 , 0,6,1};
                msh.Positions = pc;//顶点坐标置入
                msh.TriangleIndices = ic;//三角形网格定义
                dmater.Color = Color.FromRgb(0, 191, 224);
                gm3d.Geometry = msh;//网格
                gm3d.Material = dmater;//纹理
                mdgroup.Children.Add(gm3d);//合成组
                mui.Model = mdgroup;//合成模型
                return mui;
            }


    2014年8月1日 1:31

答案

  • 你好,

    我在本地没有能够还原这个问题。如果有任何错误信息,建议你在帖子中回复。经过一些搜索后,我发现这个教程不错。推荐一下。

    http://www.codeproject.com/Articles/24727/WPF-D-Part-of-n

    希望我的回复能够帮到你!

    谢谢!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年8月4日 3:19
    版主