예제 #1
0
        public void AttachModelList(List <Object3D> objs)
        {
            for (int i = 0; i < objs.Count; ++i)
            {
                var ob        = objs[i];
                var vertColor = new Color4((float)i / objs.Count, 0, 1 - (float)i / objs.Count, 1);
                ob.Geometry.Colors = new HelixToolkit.Wpf.SharpDX.Core.Color4Collection(Enumerable.Repeat(vertColor, ob.Geometry.Positions.Count));
                ob.Geometry.UpdateOctree();
                ob.Geometry.UpdateBounds();

                context.Post((o) =>
                {
                    var scaleTransform = new Media3D.ScaleTransform3D(15, 15, 15);
                    var s = new MeshGeometryModel3D
                    {
                        Geometry         = ob.Geometry,
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        IsThrowingShadow = true,
                        Transform        = scaleTransform
                    };

                    var diffuseMaterial     = new DiffuseMaterial();
                    PBRMaterial pbrMaterial = null;
                    if (ob.Material is PhongMaterialCore p)
                    {
                        var phong = p.ConvertToPhongMaterial();
                        phong.RenderEnvironmentMap   = true;
                        phong.RenderShadowMap        = true;
                        phong.RenderSpecularColorMap = false;
                        s.Material = phong;
                        diffuseMaterial.DiffuseColor = p.DiffuseColor;
                        diffuseMaterial.DiffuseMap   = p.DiffuseMap;
                        pbrMaterial = new PBRMaterial()
                        {
                            AlbedoColor          = p.DiffuseColor,
                            AlbedoMap            = p.DiffuseMap,
                            NormalMap            = p.NormalMap,
                            RMAMap               = p.SpecularColorMap,
                            RenderShadowMap      = true,
                            RenderEnvironmentMap = true,
                        };
                    }
                    //if (ob.Transform != null && ob.Transform.Count > 0)
                    //{
                    //    s.Instances = ob.Transform;
                    //}
                    this.Model1.Add(s);

                    Model2.Add(new MeshGeometryModel3D()
                    {
                        Geometry         = ob.Geometry,
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        IsThrowingShadow = true,
                        Material         = NormalMaterial,
                        Transform        = scaleTransform
                    });

                    ModelNormalVector.Add(new MeshGeometryModel3D()
                    {
                        Geometry         = ob.Geometry,
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        IsThrowingShadow = true,
                        Material         = NormalVectorMaterial,
                        Transform        = scaleTransform
                    });
                    Model3.Add(new MeshGeometryModel3D()
                    {
                        Geometry         = ob.Geometry,
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        IsThrowingShadow = true,
                        Material         = diffuseMaterial,
                        Transform        = scaleTransform
                    });

                    Model4.Add(new MeshGeometryModel3D()
                    {
                        Geometry         = ob.Geometry,
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        IsThrowingShadow = true,
                        Material         = PositionMaterial,
                        Transform        = scaleTransform
                    });

                    Model5.Add(new MeshGeometryModel3D()
                    {
                        Geometry         = ob.Geometry,
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        IsThrowingShadow = true,
                        Material         = VertMaterial,
                        Transform        = scaleTransform
                    });

                    Model6.Add(new MeshGeometryModel3D()
                    {
                        Geometry         = ob.Geometry,
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        IsThrowingShadow = true,
                        Material         = ColorStripeMaterial,
                        Transform        = scaleTransform
                    });

                    Model7.Add(new MeshGeometryModel3D
                    {
                        Geometry         = ob.Geometry,
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        IsThrowingShadow = true,
                        Transform        = scaleTransform,
                        Material         = pbrMaterial
                    });
                }, null);
            }
        }