helix-toolkit: texture is not displayed when using PhongMaterial

I am trying to create a material for custom toon shading. In the first step, I referred to some code in the demo and used PhongMaterial to render a model, but I don’t know why the texture won’t display. May I ask if there are some important configurations missing?

I compared the code in the demo, but I don’t have experience in XAML and Windows Forms development. I apologize for not being able to identify the issue by myself, and I hope to get your help~

ViewPanel.xaml

    <hx:Viewport3DX
            x:Name="view2"
            EnableD2DRendering="False"
            ShowCoordinateSystem="True"
            ShowFrameRate="True"
            ShowCameraInfo="True"
            ShowFrameDetails="True"
            ShowViewCube="True"
            EffectsManager="{Binding SREffectsManager}"
            UseDefaultGestures="True">
            
            <hx:GroupModel3D 
                x:Name="PreviewModel2"
                ItemsSource="{Binding ModelGeometry}"
                >
            </hx:GroupModel3D>
            
            <hx:AmbientLight3D 
                Color="{Binding AmbientLightColor}"/>
            <hx:DirectionalLight3D 
                Color="{Binding DirectionalLightColor}" 
                Direction = "{Binding DirectionalLightDirection}"/>
        </hx:Viewport3DX>

MainViewModel.cs

        public Element3DCollection ModelGeometry { get; private set; }
        public DefaultEffectsManager SREffectsManager { get; set; }
        // ...

            SREffectsManager = new DefaultEffectsManager();
            
            AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f);
            DirectionalLightColor = Color.White;
            DirectionalLightDirection = new Vector3(-2, -5, -2);

                var mesh = new MeshGeometry3D
                {
                    Positions = new Vector3Collection(format_.vertex_list.vertex.Select(x => rotationMatrix.Transform(x.pos).ToVector3())),
                    Indices = new IntCollection(indices),
                    TextureCoordinates = new Vector2Collection(format_.vertex_list.vertex.Select(x => x.uv.ToVector2()))
                };

                PhongMaterial material;
                var textureIndex = format_.material_list.material[i].usually_texture_index;
                  var textureModel = TextureModel.Create(Path.Combine(format_.meta_header.folder, format_.texture_list.texture_file[textureIndex]));
                  material = new PhongMaterial
                  {
                      AmbientColor = Colors.Gray.ToColor4(),
                      DiffuseColor = new Color4(1f, 1f, 1f, 1.0f),
                      SpecularColor = Colors.White.ToColor4(),
                      SpecularShininess = 1f,
                      DiffuseMap = textureModel
                  };
                    
                var model = new MeshGeometryModel3D { Geometry = mesh, Material = material};
                if (ModelGeometry == null)
                {
                    ModelGeometry = new Element3DCollection();
                }

                ModelGeometry.Add(model);

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 20 (10 by maintainers)

Most upvoted comments

Helix toolkit.wpf.sharpdx requires using Media.Color and Vector3D for Model3D bindings. Your view model uses sharpdx.color4 and sharpdx.Vector3, which is the reason your directional light is not working.