From 1b24b84c466baeac703011c7f2293cc9e6698942 Mon Sep 17 00:00:00 2001 From: gents83 Date: Thu, 15 Feb 2024 18:55:00 +0100 Subject: [PATCH] Fixing clippy --- crates/blender/src/engine.rs | 4 ++-- crates/blender/src/exporter.rs | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/crates/blender/src/engine.rs b/crates/blender/src/engine.rs index aa06911e4..46ffd9886 100644 --- a/crates/blender/src/engine.rs +++ b/crates/blender/src/engine.rs @@ -1,7 +1,7 @@ use crate::exporter::Exporter; use inox_resources::Singleton; use inox_serialize::inox_serializable::SerializableRegistryRc; -use pyo3::{pyclass, pymethods, PyResult, Python}; +use pyo3::{prelude::PyAnyMethods, pyclass, pymethods, PyResult, Python}; use inox_binarizer::Binarizer; use inox_core::App; @@ -196,7 +196,7 @@ fn add_node_in_blender( let description = node.description(); let serialized_class = node.serialize_node(serializable_registry); - py.import("INOX") + py.import_bound("INOX") .unwrap() .getattr("node_tree") .unwrap() diff --git a/crates/blender/src/exporter.rs b/crates/blender/src/exporter.rs index 71fd6dc42..1354f2d4b 100644 --- a/crates/blender/src/exporter.rs +++ b/crates/blender/src/exporter.rs @@ -5,6 +5,7 @@ use std::{ }; use pyo3::{ + prelude::PyAnyMethods, types::{PyDict, PyList}, PyObject, PyResult, Python, ToPyObject, }; @@ -40,11 +41,14 @@ impl Exporter { if create_dir_all(self.export_dir.as_path()).is_ok() { // Blender data import - let export_scene = py.import("bpy")?.getattr("ops")?.getattr("export_scene")?; + let export_scene = py + .import_bound("bpy")? + .getattr("ops")? + .getattr("export_scene")?; let scene_path = self.export_dir.join(format!("{}.{}", scene_name, "gltf")); let scene_path = scene_path.to_str().unwrap_or_default().to_string(); - let kwargs = PyDict::new(py); + let kwargs = PyDict::new_bound(py); kwargs.set_item("filepath", scene_path.clone())?; kwargs.set_item("check_existing", true)?; kwargs.set_item("export_format", "GLTF_SEPARATE")?; @@ -55,7 +59,7 @@ impl Exporter { kwargs.set_item("export_lights", true)?; kwargs.set_item("export_extras", true)?; kwargs.set_item("export_texture_dir", "./textures/")?; - export_scene.call_method("gltf", (), Some(kwargs))?; + export_scene.call_method("gltf", (), Some(&kwargs))?; self.export_custom_data(py, self.export_dir.as_path())?; @@ -68,15 +72,15 @@ impl Exporter { } fn export_custom_data(&self, py: Python, export_dir: &Path) -> PyResult { - let data = py.import("bpy")?.getattr("data")?; + let data = py.import_bound("bpy")?.getattr("data")?; // For every Blender scene let scenes = data.getattr("scenes")?.call_method("values", (), None)?; let scenes = scenes.downcast::()?; - for scene in scenes.iter() { + if let Ok(scene) = scenes.iter() { let objects = scene.getattr("objects")?.call_method("values", (), None)?; let objects = objects.downcast::()?; - for object in objects.iter() { + if let Ok(object) = objects.iter() { self.process_object_properties(py, &object.to_object(py), export_dir)?; } } @@ -100,7 +104,9 @@ impl Exporter { fn export_logic(&self, py: Python, logic: &PyObject, path: &Path) -> PyResult { let export_dir = path.join(LogicData::extension()); if !logic.is_none(py) && create_dir_all(export_dir.as_path()).is_ok() { - let mut data: String = logic.call_method_bound(py, "serialize", (), None)?.extract(py)?; + let mut data: String = logic + .call_method_bound(py, "serialize", (), None)? + .extract(py)?; data = data.replace(": ", ":"); data = data.replace(", ", ","); let name: String = logic.getattr(py, "name")?.extract(py)?;