0

Model showing Blue color

saqib 2 years ago in Question • updated by New1User 3 weeks ago 15

HI i have getting problem in model when i load my 3d model it shows blue color whereas my model has multiple color


here is my code


ModelVisual3D device3D;

private Model3D Display3d(string model)
{
Model3D device = null;
try
{
//Adding a gesture here
viewPort3d.RotateGesture = new MouseGesture(MouseAction.LeftClick);



//// Material material = new DiffuseMaterial(new SolidColorBrush(Colors.MediumOrchid));
// System.Windows.Media.Media3D.Material mat = MaterialHelper.CreateMaterial(
//new SolidColorBrush(Color.FromRgb(255, 255, 255)));
//Import 3D model file



////////////Material m = new DiffuseMaterial(new SolidColorBrush(Color.FromRgb(255,255,255)));




//ModelImporter import = new ModelImporter();
var importer = new HelixToolkit.Wpf.ModelImporter();
var point = importer.Load(model);
//Load the 3D model file
//// import.DefaultMaterial = material;
//////////////////////////////import.DefaultMaterial = m;
GeometryModel3D mode = point.Children[0] as GeometryModel3D;
Material m = new DiffuseMaterial(new SolidColorBrush(Color.FromRgb(255, 255, 255)));
//import.DefaultMaterial = mat;
//mat = import.DefaultMaterial;



//mode.Material = m;



// device = import.Load(model);
importer.DefaultMaterial = m;
device = point;







}
catch (Exception e)
{
// Handle exception in case can not file 3D model
MessageBox.Show("Exception Error : " + e.StackTrace);
}
return device;
}


and xaml code is here


xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:fyp2"
mc:Ignorable="d"
d:DesignHeight="350" d:DesignWidth="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="12*"/>
<RowDefinition Height="163*"/>
</Grid.RowDefinitions>



<h:HelixViewport3D x:Name="viewPort3d" ZoomExtentsWhenLoaded="True" Margin="149,10,10,10" Grid.RowSpan="2" >
<!-- Remember to add light to the scene -->



<h:DefaultLights/>
</h:HelixViewport3D>
<ListView x:Name="imageList" HorizontalAlignment="Left" Height="330" Margin="10,10,0,0" VerticalAlignment="Top" Width="134" SelectionChanged="imageList_SelectionChanged" Grid.RowSpan="2"/>



</Grid>

In my case, this happened after I created a MeshVisual3D in code. The solution was to toggle one of the visual's properties (I used SharedVertices) after the creation. This triggered the visual to reapply the materials. The blue and grey pair are the default materials for front and back faces.

can you tell me how you shared vertices and what changes I should do to fet colorfull model in my application

I just set it to true in the MeshVisual3D constructor, then to false on the next line.

Dim res = New MeshVisual3D With {
    .Mesh = New Mesh3D(trPts, Enumerable.Range(0, trPts.Count)),
    .SharedVertices = True,
    .FaceMaterial = mat,
    .FaceBackMaterial = mat,
    .EdgeDiameter = 0,
    .VertexRadius = 0
}

' Force mesh update to propagate materials
res.SharedVertices = False

Return res

Iam getting problem with trPts.count it gives me an error

can you please update my code by inserting your code so that i can get my original 3d model instead of blue color model.......Thanks

I'm not sure what type

ModelImporter.Load()
returns, and I don't have the time now to investigate.

Have you tried assigning the material before loading?


Btw, the blue is the default BackMaterial, maybe you could set the default for it when importing?

private Model3D Display3d(string model)
{
Model3D device = null;
try
{

viewPort3d.RotateGesture = new MouseGesture(MouseAction.LeftClick);



ModelImporter import = new ModelImporter();



//Load the 3D model file
device = import.Load(model);
Material mat = new DiffuseMaterial(new SolidColorBrush(Color.FromRgb(255, 255, 255)));



dynamic res = new MeshVisual3D
{
Mesh = new Mesh3D(trPts, Enumerable.Range(0, trPts.Count)),
SharedVertices = true,
FaceMaterial = mat,
FaceBackMaterial = mat,
EdgeDiameter = 0,
VertexRadius = 0
};



// Force mesh update to propagate materials
res.SharedVertices = false;



return res;



}
catch (Exception e)
{
// Handle exception in case can not file 3D model
MessageBox.Show("Exception Error : " + e.StackTrace);
}
return device;
}


i have simplified my code it is still showing me error on trPts.Count

kindly resolve my issue

"trPts" is just a collection of points I'm generating for Mesh3D (check its constructor declaration). In your case, they should probably be coming from the result of "import.Load".

if you have any sample project or link for this then kindly share with me so that i can get out of this problem... Thanks

I don't have a little sample project, this is a part of a pretty large project. I'm afraid it won't help you much. But this is roughly what I did.

Public Function BuildSubdivisionMeshModel(
        Dim trPts As New List(Of Point3D)()
        For Each tr In (something that returns a 3-tuple of my points)
            trPts.Add(MakePoint(tr.Item1))
            trPts.Add(MakePoint(tr.Item2))
            trPts.Add(MakePoint(tr.Item3))
        Next
        Dim mat As New DiffuseMaterial(
            New SolidColorBrush(faceColor) With {.Opacity = SubdivisionAlpha})
        Dim res = New MeshVisual3D With {
            .Mesh = New Mesh3D(trPts, Enumerable.Range(0, trPts.Count)),
            .SharedVertices = True,
            .FaceMaterial = mat,
            .FaceBackMaterial = mat,
            .EdgeDiameter = 0,
            .VertexRadius = 0
        }
        ' Force mesh update to propagate materials
        res.SharedVertices = False
        Return res
End Function
Public Function MakePoint(c As IPositionAbsolute) As Point3D
    Return New Point3D(c.X, c.Y, c.Z)
End Function

Instead of loading the model I'm building it from scratch, that's the main difference between our tasks. When building, I collect triangles, and for each triangle I add three points to the mesh. I do not reuse the points, for in my case I'd like to see the edges. And note, that the order of the points (clockwise or counter-clockwise), irrelevant in my case, matters - it determines, which side of the triangle shows the face material, and which one is back.

Thanks for helping Mike ...........Can you also tell me that how to crop wig from this 3d model

What wig? Your model is bold...

i just want crop the hair from this model

I thought the model was of a bold man... Anyway, if you want to do it programmatically, I frankly see no easy way of doing it. You'll have to modify your original model to mark the hair somehow - with another material or with some tags (if possible), - or make the hair into another model, which you can add to the rest of the body - or not add.

Hi,I am stuck with the same issue like this @saqibs my code is also the same as it.Is there any real solution for this?