refactor: generalize layer set class and method names#7709
Draft
theoryshaw wants to merge 4 commits intov0.8.0from
Draft
refactor: generalize layer set class and method names#7709theoryshaw wants to merge 4 commits intov0.8.0from
theoryshaw wants to merge 4 commits intov0.8.0from
Conversation
…er ordering Three related bugs fixed in the slab material layer set workflow: 1. EditAssignedMaterial (operator.py): Applying a custom offset to one slab instance incorrectly regenerated geometry for ALL slabs sharing the same IfcMaterialLayerSet. Replaced regenerate_from_layer_set (sweeps all users) with per-element regenerate_from_occurence for AXIS3 slabs and targeted recalculate_walls for AXIS2 walls. Each element's IfcMaterialLayerSetUsage attributes are now updated individually before regeneration. 2. slice_layerset_mesh (loader.py): Loader.unit_scale is a class variable only set during full file import, so it was stale (= 1) during live geometry updates on foot-based IFC files. Layer bisect planes were being computed in IFC feet while the mesh was in Blender metres, placing all cuts completely outside the mesh. Fixed by computing unit_scale fresh from the IFC file on each call via ifcopenshell.util.unit.calculate_unit_scale. 3. OffsetFromReferenceLine stale / layer order reversed (slab.py, loader.py): A guard (and custom_offset is None) in change_thickness prevented writing the correct OffsetFromReferenceLine (position.z) to the usage when a custom offset was active. This left the value at 0.0 instead of the actual slab bottom (e.g. -1.0 IFC units for a TOP-reference slab), so the bisect starting point co was at the reference plane rather than the slab bottom, reversing layer assignments or missing layers entirely. Removed the guard — safe because each element has its own IfcMaterialLayerSetUsage instance. Reverted the AXIS3 bisect normal back to (0,0,1) (upward from co at slab bottom) which is correct once OffsetFromReferenceLine is properly set.
Three bugs fixed: 1. EditAssignedMaterial was sweeping all slabs that share a layer set when changing material properties, instead of updating only the selected element's assigned material. 2. slice_layerset_mesh (loader.py): layer bisect positions were scaled incorrectly due to a stale unit_scale and a reversed/missing DirectionSense guard. Now always recalculates unit_scale fresh and correctly applies sense_factor. 3. change_thickness (slab.py): extrusion depth was computed as `thickness / cos(obj.rotation_euler.x)`, which incorrectly scaled ObjectPlacement-rotated slabs (where the extrusion direction is local Z and no scaling is needed). The correct formula is `thickness / extrusion_vec.z`, which handles both ObjectPlacement rotation (extrusion_vec.z ≈ 1.0 → no scale) and ExtrudedDirection tilts (extrusion_vec.z < 1.0 → scale up) uniformly. The resulting slab was 1.414× too thick for 45°-rotated slabs, making both material layers appear fatter than specified. slice_layerset_mesh retains a depth_scale safety factor (extrusion_vec.z × ifc_depth / total_layer_thickness) as a robustness guard for IFC files from other authoring tools where extrusion depth may not match the sum of LayerThicknesses.
In slice_layerset_mesh (loader.py), detect when an AXIS3 slab's stored extrusion.Depth is inconsistent with the sum of its LayerThicknesses (i.e. depth_scale != 1.0). This was caused by old Bonsai code in change_thickness that incorrectly scaled extrusion.Depth by 1/cos(obj.rotation_euler.x) for ObjectPlacement-rotated slabs, making the mesh 1.414× too tall for 45°-rotated slabs. Two-part fix applied on first import of affected files: 1. Scale mesh vertices in Z (from the mesh bottom) by 1/depth_scale so the local Z span equals total_perp_thickness × unit_scale, giving the correct physical slab geometry immediately. 2. Write the corrected extrusion.Depth = total_perp_thickness / extrusion_vec.z back to the IFC data so future imports load the correct geometry without requiring this correction. Files saved after this fix will open correctly with depth_scale = 1.0 and no vertex adjustment needed.
Rename wall/slab-specific identifiers to layer-direction-neutral equivalents: - DumbWallPlaner → Layer2Planer - DumbSlabPlaner → Layer3Planer - recalculate_walls() → recalculate_layer2_elements() - regenerate_slab() → regenerate_layer3_element() - wall_objs → axis2_objs (material/operator.py)
Member
Author
|
Converting this to 'draft'. As I don't want this in BonsaiPR, unless architecturally approved. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
refactor: generalize layer set class and method names
Rename wall/slab-specific identifiers to layer-direction-neutral equivalents: