C# 3D wpf black meshes
C# 3D wpf visual studio 2010
I have a scene consisting of a circle built up by a number triangles which I have added meshes to both backside and front.
The triangle shows up in my view but it sides are black, both inside and the outside. I add the material in this way
Material material = new DiffuseMaterial(new SolidColorBrush(Colors.Blue));
but if I change the material to
Material material = new EmissiveMaterial(new SolidColorBrush(Colors.Red));
The sides starts to shine in this colour.
I have three lightsources
< AmbientLight Color="White" / >
< DirectionalLight x:Name="myDirectLight1" Color="White"/ >
< PointLight x:Name="myPointLight1" Color="White" Position="0,0,0"/>
Where I also do
myCamera.LookDirection = -(Vector3D)myCamera.Position; //always look to (0,0,0)
myDirectLight1.Direction = myCamera.LookDirection; //light comes from the camera
But the sides are still black (unless I change the material to EmissiveMaterial) ???
Do the lights have some sort of default range not set to infinity ?
The circle is large, around 2000 units in diameter,
Regards
Added
private Model3DGroup CreateTriangleModel(Point3D p0, Point3D p1, Point3D p2, Material material, Material material2)
{
MeshGeometry3D mesh = null;
GeometryModel3D model = null;
Model3DGroup group = new Model3DGroup();
//
// Front side of jagged part
//
mesh = new MeshGeometry3D();
mesh.Positions.Add(p0);
mesh.Positions.Add(p1);
mesh.Positions.Add(p2);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(2);
Vector3D normal = CalculateNormal(p0, p1, p2);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
//
// Front side of the surface below the jagged edge
//
Point3D p3 = new Point3D(p1.X, p1.Y, bh);
Point3D p4 = new Point3D(p2.X, p2.Y, bh);
mesh.Positions.Add(p3);
mesh.Positions.Add(p4);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(3);
mesh.TriangleIndices.Add(4);
normal = CalculateNormal(p1, p3, p4);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(4);
mesh.TriangleIndices.Add(2);
normal = CalculateNormal(p1, p4, p2);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
model = new GeometryModel3D(mesh, material);
group.Children.Add(model);
//
// 开发者_运维问答Back side of jagged part
//
mesh = new MeshGeometry3D();
mesh.Positions.Add(p0);
mesh.Positions.Add(p1);
mesh.Positions.Add(p2);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(2);
mesh.TriangleIndices.Add(1);
normal = CalculateNormal(p0, p1, p2);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
//
// Back side of the surface below the jagged edge
//
p3 = new Point3D(p1.X, p1.Y, bh);
p4 = new Point3D(p2.X, p2.Y, bh);
mesh.Positions.Add(p3);
mesh.Positions.Add(p4);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(4);
mesh.TriangleIndices.Add(3);
normal = CalculateNormal(p1, p4, p3);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(2);
mesh.TriangleIndices.Add(4);
normal = CalculateNormal(p1, p2, p4);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
model = new GeometryModel3D(mesh, material2);
group.Children.Add(model);
return group;
}
private Vector3D CalculateNormal(Point3D p0, Point3D p1, Point3D p2)
{
Vector3D v0 = new Vector3D(
p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
Vector3D v1 = new Vector3D(
p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z);
return Vector3D.CrossProduct(v0, v1);
}
The Error was that my light sources was defined in the XAML code but I accediently removed them in the source code wich resulted in the strange result where the objects was "visible" but all in black, regardless of the material
精彩评论