Skip to content

Commit

Permalink
Fixing clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
gents83 committed Feb 15, 2024
1 parent 4761b4f commit 1b24b84
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions crates/blender/src/engine.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()
Expand Down
20 changes: 13 additions & 7 deletions crates/blender/src/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
};

use pyo3::{
prelude::PyAnyMethods,
types::{PyDict, PyList},
PyObject, PyResult, Python, ToPyObject,
};
Expand Down Expand Up @@ -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")?;
Expand All @@ -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())?;

Expand All @@ -68,15 +72,15 @@ impl Exporter {
}

fn export_custom_data(&self, py: Python, export_dir: &Path) -> PyResult<bool> {
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::<PyList>()?;
for scene in scenes.iter() {
if let Ok(scene) = scenes.iter() {
let objects = scene.getattr("objects")?.call_method("values", (), None)?;
let objects = objects.downcast::<PyList>()?;
for object in objects.iter() {
if let Ok(object) = objects.iter() {
self.process_object_properties(py, &object.to_object(py), export_dir)?;
}
}
Expand All @@ -100,7 +104,9 @@ impl Exporter {
fn export_logic(&self, py: Python, logic: &PyObject, path: &Path) -> PyResult<bool> {
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)?;
Expand Down

0 comments on commit 1b24b84

Please sign in to comment.