Skip to content

Commit fe3841b

Browse files
refactor: final blender stabilization and import normalization (Final)
Signed-off-by: arounamounchili <patouossa.mounchili@gmail.com>
1 parent bb0d882 commit fe3841b

9 files changed

Lines changed: 31 additions & 27 deletions

File tree

platforms/blender/linkforge/blender/logic/asynchronous_builder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
from pathlib import Path
1212

1313
import bpy
14+
from linkforge_core.logging_config import get_logger
15+
from linkforge_core.models import Robot
16+
from linkforge_core.utils.kinematics import sort_joints_topological
1417

15-
from ...linkforge_core.logging_config import get_logger
16-
from ...linkforge_core.models import Robot
17-
from ...linkforge_core.utils.kinematics import sort_joints_topological
1818
from ..adapters.core_to_blender import (
1919
create_joint_object,
2020
create_link_object,

platforms/blender/linkforge/blender/operators/export_ops.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import bpy
1515
from bpy.types import Context, Event, Operator
1616
from bpy_extras.io_utils import ExportHelper
17+
from linkforge_core.logging_config import get_logger
1718

18-
from ...linkforge_core.logging_config import get_logger
1919
from ..utils.decorators import OperatorReturn, safe_execute
2020

2121
if typing.TYPE_CHECKING:
@@ -77,7 +77,8 @@ def invoke(self, context: Context, event: Event) -> typing.Any:
7777
def execute(self, context: Context) -> OperatorReturn:
7878
"""Execute the export."""
7979
# Import here to avoid circular dependencies
80-
from ...linkforge_core import URDFGenerator, XACROGenerator
80+
from linkforge_core import URDFGenerator, XACROGenerator
81+
8182
from ..adapters.blender_to_core import scene_to_robot
8283

8384
if not context.scene or not hasattr(context.scene, "linkforge"):
@@ -103,7 +104,7 @@ def execute(self, context: Context) -> OperatorReturn:
103104
logger.info(f"Exporting robot to: {output_path}")
104105
logger.debug(f"Mesh directory: {meshes_dir}")
105106

106-
from ...linkforge_core import LinkForgeError, RobotGeneratorError
107+
from linkforge_core import LinkForgeError, RobotGeneratorError
107108

108109
# Validate if requested
109110
if robot_props.validate_before_export:
@@ -118,7 +119,7 @@ def execute(self, context: Context) -> OperatorReturn:
118119
logger.exception("Dry run build crashed")
119120
return {"CANCELLED"}
120121

121-
from ...linkforge_core.validation import RobotValidator
122+
from linkforge_core.validation import RobotValidator
122123

123124
validator = RobotValidator()
124125
result = validator.validate(robot_dry_run)
@@ -194,7 +195,8 @@ class LINKFORGE_OT_validate_robot(Operator):
194195
@safe_execute
195196
def execute(self, context: Context) -> OperatorReturn:
196197
"""Execute validation."""
197-
from ...linkforge_core.validation import RobotValidator
198+
from linkforge_core.validation import RobotValidator
199+
198200
from ..adapters.blender_to_core import scene_to_robot
199201

200202
# Clear previous results

platforms/blender/linkforge/blender/operators/import_ops.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
import bpy
1414
from bpy_extras.io_utils import ImportHelper
15+
from linkforge_core.logging_config import get_logger
1516

16-
from ...linkforge_core.logging_config import get_logger
1717
from ..utils.decorators import OperatorReturn, safe_execute
1818
from ..utils.scene_utils import clear_stats_cache
1919

@@ -69,7 +69,7 @@ def execute(self, context: Context) -> OperatorReturn:
6969
Returns:
7070
Set containing the execution state (e.g., {'FINISHED'} or {'CANCELLED'}).
7171
"""
72-
from ...linkforge_core.parsers import URDFParser
72+
from linkforge_core.parsers import URDFParser
7373

7474
# Parse URDF/XACRO file
7575
urdf_path = Path(self.filepath)
@@ -112,7 +112,7 @@ def execute(self, context: Context) -> OperatorReturn:
112112
is_xacro = urdf_path.suffix == ".xacro" or urdf_path.name.endswith(".urdf.xacro")
113113

114114
# Detect Sandbox Root for security (allows sibling folders like meshes/)
115-
from ...linkforge_core.validation.security import find_sandbox_root
115+
from linkforge_core.validation.security import find_sandbox_root
116116

117117
sandbox_root = find_sandbox_root(urdf_path)
118118
logger.info(f"Importing robot from: {urdf_path}")
@@ -121,8 +121,8 @@ def execute(self, context: Context) -> OperatorReturn:
121121
# Smart Import Logic:
122122
# 1. If it looks like URDF, try parsing as URDF.
123123
# 2. If parsing fails because of Xacro tags, catch the error and switch to Xacro mode.
124-
from ...linkforge_core import RobotParserError, XacroDetectedError
125-
from ...linkforge_core.base import FileSystemResolver
124+
from linkforge_core import RobotParserError, XacroDetectedError
125+
from linkforge_core.base import FileSystemResolver
126126

127127
# Read additional package paths from preferences
128128
from ..preferences import get_addon_prefs
@@ -160,7 +160,7 @@ def execute(self, context: Context) -> OperatorReturn:
160160
# XACRO PROCESSING (Triggered by extension OR fallback detection)
161161
if is_xacro:
162162
# Convert XACRO to URDF using native XacroResolver
163-
from ...linkforge_core.parsers import XacroResolver
163+
from linkforge_core.parsers import XacroResolver
164164

165165
self.report({"INFO"}, f"Processing XACRO file: {urdf_path.name}")
166166

@@ -195,7 +195,7 @@ def execute(self, context: Context) -> OperatorReturn:
195195
return {"CANCELLED"}
196196

197197
# Validate robot structure
198-
from ...linkforge_core.validation import RobotValidator
198+
from linkforge_core.validation import RobotValidator
199199

200200
validator = RobotValidator()
201201
result = validator.validate(robot)

platforms/blender/linkforge/blender/operators/link_ops.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import time
77
import typing
88

9-
from ...linkforge_core.logging_config import get_logger
10-
from ...linkforge_core.models.link import InertiaTensor
9+
from linkforge_core.logging_config import get_logger
10+
from linkforge_core.models.link import InertiaTensor
11+
1112
from ..properties.link_props import sanitize_urdf_name
1213
from ..utils.context import context_and_mode_guard
1314
from ..utils.decorators import OperatorReturn, safe_execute
@@ -509,8 +510,9 @@ def calculate_inertia_for_link(link_obj: bpy.types.Object) -> bool:
509510
lf = typing.cast("LinkPropertyGroup", getattr(link_obj, "linkforge"))
510511

511512
# Import here to avoid circular dependency
512-
from ...linkforge_core.models.geometry import Box, Cylinder, Sphere
513-
from ...linkforge_core.physics import calculate_inertia, calculate_mesh_inertia_from_triangles
513+
from linkforge_core.models.geometry import Box, Cylinder, Sphere
514+
from linkforge_core.physics import calculate_inertia, calculate_mesh_inertia_from_triangles
515+
514516
from ..adapters.blender_to_core import extract_mesh_triangles
515517
from ..utils.physics import calculate_mesh_inertia_numpy
516518

@@ -558,7 +560,7 @@ def calculate_inertia_for_link(link_obj: bpy.types.Object) -> bool:
558560
# Primitive calculation expects dimensions
559561
if prim_type == "BOX":
560562
# Convert mathutils.Vector to core Vector3
561-
from ...linkforge_core.models.geometry import Vector3
563+
from linkforge_core.models.geometry import Vector3
562564

563565
size = Vector3(dims.x, dims.y, dims.z)
564566
tensor = calculate_inertia(Box(size=size), mass)

platforms/blender/linkforge/blender/utils/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import typing
66
from collections.abc import Callable
77

8-
from ...linkforge_core.logging_config import get_logger
8+
from linkforge_core.logging_config import get_logger
99

1010
logger = get_logger(__name__)
1111

platforms/blender/linkforge/blender/utils/joint_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from __future__ import annotations
44

55
import bpy
6-
7-
from ...linkforge_core.models import Joint
6+
from linkforge_core.models import Joint
87

98

109
def resolve_mimic_joints(joints: list[Joint], joint_objects: dict[str, bpy.types.Object]) -> None:

platforms/blender/linkforge/blender/utils/physics.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66

77
if TYPE_CHECKING:
88
import numpy as np # type: ignore[import-not-found]
9-
10-
from ...linkforge_core.models.link import InertiaTensor
9+
from linkforge_core.models.link import InertiaTensor
1110
else:
1211
try:
1312
import numpy as np # type: ignore[import-not-found]
1413
except ImportError:
1514
np = None
1615

17-
from ...linkforge_core.logging_config import get_logger
18-
from ...linkforge_core.models.link import InertiaTensor
16+
from linkforge_core.logging_config import get_logger
17+
from linkforge_core.models.link import InertiaTensor
1918

2019
logger = get_logger(__name__)
2120

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../core/src/linkforge_core

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ strict = true
5858
warn_return_any = true
5959
warn_unused_configs = true
6060
mypy_path = ["core/src", "platforms/blender"]
61+
exclude = ["platforms/blender/linkforge/linkforge_core"]
6162

6263
# Blender (bpy) stubs use Python 3.12 syntax.
6364
[[tool.mypy.overrides]]

0 commit comments

Comments
 (0)