Israel
Joined: Dec 24, 2023
Post Count: 14
Status:
Offline
Programmatically Changing Openings
Hey,
As a part of a plugin development, I want to close a door/window in the floor plan. I tried following the code that does this from the UI and my understanding is that modifying the piece of furniture's transformations (hinges and whatnot) also alters its overall dimensions and so, after transforming it, i.e., removing the existing transformations, I need to recalculate the size and position and update the piece of furniture accordingly. I tried to, basically, copy-paste the code from the ModelPreviewComponent class but I guess I'm missing something since, while the door does close, it stays at, more-or-less, the same original dimensions and becomes distorted.
In my code, I find the relevant furniture by traversing home.getFurniture() and, when needed, call a new shutTheDoor() function I created:
Italy
Joined: Nov 17, 2021
Post Count: 474
Status:
Offline
Re: Programmatically Changing Openings
I have interest on this subject, so far I've been able to open doors in the 3D view, but I wasn't able to find a way to consolidate the changes in the plan. If this is enough for your use case, you can have a look at the source code of the Pan3dView plugin. There is also a video on my YouTube channel which shows the feature in action.
Israel
Joined: Dec 24, 2023
Post Count: 14
Status:
Offline
Re: Programmatically Changing Openings
I wasn't able to find a way to consolidate the changes in the plan
What do you mean by this? That the openings are only changed in the 3D view but nothing is changed in the plan?
In my case, it changes both the plan and the 3D view but the door/windows become distorted because their proportions don't match anymore.
If this is enough for your use case, you can have a look at the source code of the Pan3dView plugin
I need this change to be applied when rendering an image. I think that a new scene is built for the renderers and not using the same objects in the 3D view but I might be off here. If I am, then it might be enough to only modify the 3D view and leave the plan intact.
Netherlands
Joined: Apr 8, 2022
Post Count: 1438
Status:
Offline
Re: Programmatically Changing Openings
In my case, it changes both the plan and the 3D view but the door/windows become distorted because their proportions don't match anymore.
Your problem might be related to a bug I reported with wrong deformations in the 3Dview with the Pan3DView plugin: http://www.sweethome3d.com/support/forum/view...ead,5072_offset,100#61531 One thing I figured out that might help you with finding the cause is to place an object horizontal and one diagonal and see the difference in how the deformations show. You will also have to check chained deformations (deformation on a deformed part).
---------------------------------------- Dodecagon.nl 1300+ 3D models, manuals, and projects
Australia
Joined: Sep 1, 2024
Post Count: 7
Status:
Offline
Re: Programmatically Changing Openings
My observations have found that a door opened with the Pan3DView plugin will not render open. A cupboard with 2 doors, the left opened in the Modify Deformations Dialog and the right door opened with the Pan3DView plugin will render with the right door closed.
Australia
Joined: Sep 1, 2024
Post Count: 7
Status:
Offline
Re: Programmatically Changing Openings
In all fairness to Daniels118 his plugin does state that the Edit openings is beta and the option to have access to this feature in its infancy is greatly appreciated.
Netherlands
Joined: Apr 8, 2022
Post Count: 1438
Status:
Offline
Re: Programmatically Changing Openings
In all fairness to Daniels118 his plugin does state that the Edit openings is beta and the option to have access to this feature in its infancy is greatly appreciated.
Correct. That's why I stated in a follow-up post that's it's no problem, no hurry to fix. I mainly use the 3Dview deformations to test that deformations work. That they are distorted with wrong deformations is no problem as long as I can see that they work in the order they are supposed to.
---------------------------------------- Dodecagon.nl 1300+ 3D models, manuals, and projects
Israel
Joined: Dec 24, 2023
Post Count: 14
Status:
Offline
Re: Programmatically Changing Openings
My observations have found that a door opened with the Pan3DView plugin will not render open. A cupboard with 2 doors, the left opened in the Modify Deformations Dialog and the right door opened with the Pan3DView plugin will render with the right door closed.
Thanks for that, then I need to make it work in the plan...
Israel
Joined: Dec 24, 2023
Post Count: 14
Status:
Offline
Re: Programmatically Changing Openings
The feature request for my SH3D plugin requiring this functionality was recently brought up again and I, needing some kind of win, decided to try and tackle it again.
I'm not sure everything below is required but I tried to only include things that made sense to me. I did have the basic idea of what needs to be done correct, just not the way to do it :)
The gist of it is to:
Build a 3D scene with the piece of furniture and its existing dimensions from the floor plan
Modify the 3D model's transformations (in my case, remove them to close the door)
Calculate the bounding box of the 3D model before and after the transformation changes to get the new size and center point
Update the floor plan piece with the new location and size according to the changes calculated from the step above
Here's the functional, though not that pretty, code to do that:
/* Build 3D scene with floor plan piece */ ModelManager modelManager = ModelManager.getInstance(); BranchGroup sceneTree = new BranchGroup(); TransformGroup modelTransformGroup = new TransformGroup(); BranchGroup modelRoot;
/* Remove transformations from 3D model and update modelPiece's size and location */ BoundingBox oldBounds = modelManager.getBounds(piece3D); Point3d oldLower = new Point3d(); oldBounds.getLower(oldLower); Point3d oldUpper = new Point3d(); oldBounds.getUpper(oldUpper);