222
Joined: Feb 27, 2011
Post Count: 10
Status:
Offline
Add furniture progamatically !!!
Hi All,
How can I create furniture programatically on my home? I created walls and rooms but I am unable get the furniture. What classes are involved? Do I need to read from the io resources?
Argentina
Joined: Sep 8, 2009
Post Count: 40
Status:
Offline
Re: Add furniture progamatically !!!
typing from memory: Home myHome = new Home(); HomePieceofFurniture hpf = new HomePieceofFurniture(somePieceOfFurniture); myHome.addFurniture(hpf);
The point is, you need a instance of a class implementing PieceOfFurniture e.g. CatalogPieceOFFurniture, which you can get from a FurnitureCatalog. Then, add it to your Home object. easy if you see it.
Good luck. As I said, I'm typing from memory, so actual names of functions may differ.
Joined: Nov 11, 2011
Post Count: 5
Status:
Offline
Re: Add furniture progamatically !!!
Hi,
sorry for piggybacking on this thread - I've tried using the steps outlined by alied, but still cannot add new furniture to my room :-(
Here's how I'm doing it right now:
Home home = new HomeFileRecorder().readHome(roomFile.getPath());
Content model = new URLContent(modelUrl); PieceOfFurniture piece = new CatalogPieceOfFurniture("MyName", null, model, 100, 100, 100, ...);
HomePieceOfFurniture hpof = new HomePieceOfFurniture(piece); hpof.setX(200); hpof.setY(300); hpof.setElevation(0);
home.addFurniture(hpof);
What happens with this code if I construct a HomeComponent3D around the home and display it in a JFrame is that I see the room and a white cube (1m edge length) at coordinates (200,300,0) -- BUT ONLY FOR ABOUT ONE SECOND!
Then it magically disappears from the scene again.
Very strange. If I query home.getFurniture() I can see that my new object is still in there, but as I said, it is only shown for one second and then it is suddenly gone.
France
Joined: Nov 7, 2005
Post Count: 9426
Status:
Offline
Re: Add furniture progamatically !!!
In which view does it disappear? Plan view? 3D view? Both? Any stack traces?
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator
Joined: Nov 11, 2011
Post Count: 5
Status:
Offline
Re: Add furniture progamatically !!!
Hi Emmanuel,
Thanks for the quick reply! As I pointed out, I'm viewing the room through a HomeComponent3D component. Note that we are talking about a stand-alone application built on top of the SweetHome3D libraries, not a plugin that interacts with the SweetHome3D application itself.
I'd be happy to post the source code of a minimal example - basically it's not much more than the above code inside a main-method, plus the creation of a HomeComponent3D and a JFrame.
There are no stack traces because the program runs without complaints, i.e., no Exceptions are being thrown. It's just that the HomePieceOfFurniture object I add programmatically never gets displayed. Instead, I can see a 1^3m white cube for about one second where the HomePieceOfFurniture is supposed to be which then disappears.
A first guess was that perhaps the model data of the HomePieceOfFurniture was not found correctly, but I made sure that this is not the case, or else the URLContent constructor would complain anyway.
France
Joined: Nov 7, 2005
Post Count: 9426
Status:
Offline
Re: Add furniture progamatically !!!
I guess you see only the box displayed during the loading of the 3D model. Once the 3D model is loaded, the box is replaced by the loaded model, but maybe it's an empty model. Which 3D model file do you try to use?
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator