Do tematu podchodzę już 3 raz Tym razem Jet już prawie idealnie! w końcu renderowany obiekt posiada wszystkie tekstury na swoich miejscach i na wszystkich geometriach w poszczegulnych modelach ale...
i tu pojawia sie problem którego już nie potrafie zrozumieć małe obiekty mają teksturę doskonale ułożoną natomiast im większy obiekt tym bardziej rozmazuje się.
Jeśli ktoś ma jakikolwiek pomysł co zrobiłem źle byłbym szczęśliwy
private void VOBBILDERRENDER()
{
string filePathModel1 = "";
string applicationPath = AppDomain.CurrentDomain.BaseDirectory;
if (!string.IsNullOrEmpty(comboBox121.Text))
{
filePathModel1 = Path.Combine(applicationPath, "_Work\\Data\\NPC\\MODEL\\VOB", comboBox121.Text + ".3ds");
// Utwórz obiekt kontekstu Assimp
AssimpContext importer = new AssimpContext();
// Wczytaj model 3D
Scene scene = importer.ImportFile(filePathModel1, PostProcessSteps.Triangulate | PostProcessSteps.FlipUVs);
if (scene != null && scene.HasMeshes)
{
foreach (var mesh in scene.Meshes)
{
var material = scene.Materials[mesh.MaterialIndex];
string message = $"Nazwa materiału: {material.Name}\n";
// Sprawdź, czy materiał ma teksturę diffuse
if (material.GetMaterialTexture(TextureType.Diffuse, 0, out var diffuseTextureSlot))
{
if (!string.IsNullOrEmpty(diffuseTextureSlot.FilePath))
{
message += $"Ścieżka tekstury: {diffuseTextureSlot.FilePath}\n";
}
else
{
message += "Brak tekstury lub nieobsługiwany typ tekstury.\n";
}
}
else
{
message += "Brak tekstury lub nieobsługiwany typ tekstury.\n";
}
// Sprawdź, czy mesh ma geometrię
if (mesh.HasVertices)
{
message += "Geometria: ";
// Pobierz nazwę geometrii
string geometryName = mesh.Name;
message += string.IsNullOrEmpty(geometryName) ? "Brak nazwy geometrii" : geometryName;
}
else
{
message += "Brak geometrii w meshu.";
}
// MessageBox.Show(message, "Informacje o materiale i geometrii", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
// MessageBox.Show("Bieda: Nie udało się wczytać modelu lub brak meshów.", "Komunikat", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
string textureDirectoryOLD = @"Work\Data\NPC\TEXTURES\OTHER";
string[] textureDirectories = new string[]
{
@"_Work\Data\NPC\TEXTURES\ARMOR",
@"_Work\Data\NPC\TEXTURES\BODY",
@"_Work\Data\NPC\TEXTURES\HEAD",
@"_Work\Data\NPC\TEXTURES\MONSTER",
@"_Work\Data\NPC\TEXTURES\OTHER",
};
var viewport = new HelixViewport3D();
foreach (var mesh in scene.Meshes)
{
var material = scene.Materials[mesh.MaterialIndex];
if (material.GetMaterialTexture(TextureType.Diffuse, 0, out var diffuseTextureSlot))
{
string textureFileName = diffuseTextureSlot.FilePath;
string textureFilePath = Path.Combine(textureDirectoryOLD, textureFileName);
var meshBuilder = new MeshBuilder();
// Dodaj pozycje
foreach (var vertex in mesh.Vertices)
{
meshBuilder.Positions.Add(new Point3D(vertex.X, vertex.Y, vertex.Z));
}
// Dodaj indeksy trójkątów
foreach (var face in mesh.Faces)
{
meshBuilder.TriangleIndices.Add(face.Indices[0]);
meshBuilder.TriangleIndices.Add(face.Indices[1]);
meshBuilder.TriangleIndices.Add(face.Indices[2]);
}
// Dodaj wektory normalne
foreach (var normal in mesh.Normals)
{
meshBuilder.Normals.Add(new System.Windows.Media.Media3D.Vector3D(normal.X, normal.Y, normal.Z));
}
// Dodaj współrzędne tekstury
foreach (var textureCoordinate in mesh.TextureCoordinateChannels[0])
{
meshBuilder.TextureCoordinates.Add(new System.Windows.Point(textureCoordinate.X, textureCoordinate.Y));
}
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(textureFileName);
string detectfilePng = "";
string detectfileJpg = "";
// Sprawdź dostępność plików w różnych folderach
string wpfMaterialPath = null;
foreach (string textureDirectory in textureDirectories)
{
// MessageBox.Show(textureDirectory, fileNameWithoutExtension, MessageBoxButtons.OK, MessageBoxIcon.Information);
detectfilePng = Path.Combine(PROGRAM, textureDirectory, fileNameWithoutExtension + ".png");
detectfileJpg = Path.Combine(PROGRAM, textureDirectory, fileNameWithoutExtension + ".jpg");
if (File.Exists(detectfilePng))
{
wpfMaterialPath = detectfilePng;
break;
}
else if (File.Exists(detectfileJpg))
{
wpfMaterialPath = detectfileJpg;
break;
}
}
var wpfMaterial = wpfMaterialPath != null
? MaterialHelper.CreateImageMaterial(wpfMaterialPath, 1.0)
: MaterialHelper.CreateImageMaterial(Path.Combine(PROGRAM, "_Work", "Data", "NPC", "TEXTURES", "DEFAULT.jpg"), 1.0);
// Utwórz geometrię modelu
var geometryModel = new GeometryModel3D
{
Geometry = meshBuilder.ToMesh(),
Material = wpfMaterial,
};
// Dodaj model do sceny
viewport.Children.Add(new ModelVisual3D { Content = geometryModel });
}
}
// Dodaj oświetlenie - AmbientLight (oświetlenie ambientalne)
int cyfra1; // Twoja cyfra, którą chcesz przypisać
int cyfra2; // Twoja cyfra, którą chcesz przypisać
int cyfra3; // Twoja cyfra, którą chcesz przypisać
cyfra1 = int.Parse(label607.Text);
cyfra2 = int.Parse(label608.Text);
cyfra3 = int.Parse(label609.Text);
viewport.Camera.Position = new Point3D(cyfra1, cyfra2, cyfra3); // Pozycja kamery ( , , Wysokosc)
if (comboBox123.SelectedIndex <= 0)
{
comboBox123.SelectedIndex = 0;
viewport.Camera.LookDirection = new System.Windows.Media.Media3D.Vector3D(0, 1, 0); // Kierunek patrzenia kamery (patrzy na przód)
viewport.Camera.UpDirection = new System.Windows.Media.Media3D.Vector3D(0, 0, 1); // Kierunek góry kamery
}
else if (comboBox123.SelectedIndex <= 1)
{
viewport.Camera.LookDirection = new System.Windows.Media.Media3D.Vector3D(1, 0, 0); // Kierunek patrzenia kamery (patrzy na przód)
viewport.Camera.UpDirection = new System.Windows.Media.Media3D.Vector3D(0, 0, 1); // Kierunek góry kamery
}
else if (comboBox123.SelectedIndex <= 2)
{
viewport.Camera.LookDirection = new System.Windows.Media.Media3D.Vector3D(0, 0, -1); // Kierunek patrzenia kamery (patrzy na przód)
viewport.Camera.UpDirection = new System.Windows.Media.Media3D.Vector3D(1, 0, 0); // Kierunek góry kamery
}
else if (comboBox123.SelectedIndex <= 3)
{
viewport.Camera.LookDirection = new System.Windows.Media.Media3D.Vector3D(0, -1, 0); // Kierunek patrzenia kamery (patrzy na przód)
viewport.Camera.UpDirection = new System.Windows.Media.Media3D.Vector3D(0, 0, 1); // Kierunek góry kamery
}
else if (comboBox123.SelectedIndex <= 4)
{
viewport.Camera.LookDirection = new System.Windows.Media.Media3D.Vector3D(-1, 0, 0); // Kierunek patrzenia kamery (patrzy na przód)
viewport.Camera.UpDirection = new System.Windows.Media.Media3D.Vector3D(0, 0, 1); // Kierunek góry kamery
}
else if (comboBox123.SelectedIndex <= 5)
{
viewport.Camera.LookDirection = new System.Windows.Media.Media3D.Vector3D(0, 0, 1); // Kierunek patrzenia kamery (patrzy na przód)
viewport.Camera.UpDirection = new System.Windows.Media.Media3D.Vector3D(1, 0, 0); // Kierunek góry kamery
}
var ambientLight = new AmbientLight
{
Color = Colors.White,
};
// Dodaj oświetlenie - DirectionalLight (światło kierunkowe)
var directionalLight = new DirectionalLight
{
Color = Colors.White,
Direction = new System.Windows.Media.Media3D.Vector3D(-1, -1, -1),
};
// Dodaj oświetlenie do sceny
viewport.Children.Add(new ModelVisual3D { Content = ambientLight });
viewport.Children.Add(new ModelVisual3D { Content = directionalLight });
elementHost4.Child = viewport;
}
}