Windows.Media.Media3D 툴킷을 사용하여 DirectX 응용 프로그램을 WPF로 포팅합니다. 가능한 모든 데이터를 가져 왔지만 모델이 완료되지 않은 것을 제외하고는 모두 잘 작동합니다.MeshGeometry3D (WPF)에서 Vertices 스무딩
DirectX가 최적화되어 어떻게 든 매끄럽게하거나 꼭지점과 표시에 따라 추가 콘텐츠를 렌더링하는 데 도움이 될 것으로 생각됩니다.
그래서 WPF에서 3D 모델을 렌더링하는 방법을 변경할 수있는 옵션이 있는지 궁금합니다. 내가 의미하는 바를 정확하게 표현하는 것은 약간 어렵지만 어떻게 든 이해할 수 있기를 바랍니다.
private void DrawModel()
{
SwordModel swordModel;
string filename = "PG_S8_02";
using(FileStream stream = File.OpenRead(string.Format("Media/Models/{0}.gb", filename)))
using(BinaryReader reader = new BinaryReader(stream))
{
swordModel = new SwordModel(reader);
}
var group = new Model3DGroup();
foreach(var modelMesh in swordModel.Meshes)
{
var mesh3D = new MeshGeometry3D();
// Indices
foreach(var index in modelMesh.Indices)
{
mesh3D.TriangleIndices.Add(index);
}
// Vertices
foreach(var vertex in modelMesh.Vertices)
{
mesh3D.Positions.Add(vertex);
}
// Normals
foreach(var normal in modelMesh.Normals)
{
mesh3D.Normals.Add(normal);
}
// Texture Coordinates
foreach(var vertex in modelMesh.Vertices)
{
mesh3D.TextureCoordinates.Add(new Point(vertex.X, vertex.Y));
}
// Material
var material = new DiffuseMaterial();
var texture = new BitmapImage(new Uri(
string.Format("Media/Textures/{0}.png", filename),
UriKind.RelativeOrAbsolute
));
material.Brush = new ImageBrush(texture);
// Add to View
group.Children.Add(
new GeometryModel3D(mesh3D, material)
);
}
mainViewport.Children.Add(
new ModelVisual3D() { Content = group }
);
}
그리고 XAML :
<Viewport3D Name="mainViewport" ClipToBounds="True">
<Viewport3D.Camera>
<PerspectiveCamera
FarPlaneDistance="100"
LookDirection="-11,-10,-9"
UpDirection="0,1,0"
NearPlaneDistance="1"
Position="11,10,9"
FieldOfView="70" />
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight Color="White" Direction="-2,-3,-1" />
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
얼굴의 "편"이 문제인 것처럼 보입니다 (Ian Hopkinson의 답변 참조). 그래도 DirectX (나는 생각합니다.) 때문에 왜 변환이 잘못 될지 즉시 생각할 수 없습니다. – ChrisF