у меня есть код import java.io.; import java.util.; class Vector3f { float x, y, z;…
- User
у меня есть код import java.io.; import java.util.;
class Vector3f { float x, y, z;
Vector3f(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }}
class Polygon { List vertexIndices;
Polygon(List<Integer> vertexIndices) { this.vertexIndices = vertexIndices; }}
class Model { List vertices = new ArrayList<>(); List polygons = new ArrayList<>();
void loadFromObjFile(String filename) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(filename)); String line; while ((line = reader.readLine()) != null) { String[] parts = line.split("\\s+"); switch (parts[0]) { case "v": vertices.add(new Vector3f(Float.parseFloat(parts[1]), Float.parseFloat(parts[2]), Float.parseFloat(parts[3]))); break; case "f": List<Integer> vertexIndices = new ArrayList<>(); for (int i = 1; i < parts.length; i++) { vertexIndices.add(Integer.parseInt(parts[i]) - 1); // OBJ indices start from 1 } polygons.add(new Polygon(vertexIndices)); break; } } reader.close(); } void removeVertices(Set<Integer> indicesToRemove) { // Удаляем полигоны, содержащие удаляемые вершины polygons.removeIf(polygon -> polygon.vertexIndices.stream().anyMatch(indicesToRemove::contains)); // Удаляем вершины vertices.removeIf(vertex -> indicesToRemove.contains(vertices.indexOf(vertex))); } void saveToObjFile(String filename) throws IOException { BufferedWriter writer = new BufferedWriter(new FileWriter(filename)); for (Vector3f vertex : vertices) { writer.write(String.format("v %.6f %.6f %.6f%n", vertex.x, vertex.y, vertex.z)); } for (Polygon polygon : polygons) { String indices = polygon.vertexIndices.stream() .map(index -> String.valueOf(index + 1)) // Возвращаем к 1-индексации .reduce((a, b) -> a + " " + b).orElse(""); writer.write("f " + indices + "\n"); } writer.close(); }}
public class ObjEditor { public static void main(String[] args) { try { Model model = new Model(); model.loadFromObjFile("input.obj");
// Пример: удаляем вершины с индексами 0 и 2 Set<Integer> indicesToRemove = new HashSet<>(Arrays.asList(0, 2)); model.removeVertices(indicesToRemove); model.saveToObjFile("output.obj"); } catch (IOException e) { e.printStackTrace(); } }}
- Assistant
- User
есть такая ошибка
- Assistant
- User
java.io.FileNotFoundException: input.obj (Не удается найти указанный файл)
- Assistant
Ошибка
java.io.FileNotFoundException: input.obj (Не удается найти указанный файл)указывает на то, что программа не может найти файл с именемinput.objв текущей директории. Чтобы исправить эту проблему, выполните следующие шаги:Шаги по устранению ошибки
-
Проверьте местоположение файла:
- Убедитесь, что файл
input.objдействительно существует в директории, откуда вы запускаете программу. - Если вы используете IDE, такую как IntelliJ IDEA или Eclipse, убедитесь, что файл находится в корневой директории вашего проекта или укажите полный путь к файлу.
- Убедитесь, что файл
-