Joined: May 28, 2015
Post Count: 607
Status:
Offline
Add another 3D model to an existing 3D model?
Since Sweet Home 3D 6.5, there is a method to modify the 3D model of a piece of furniture.
Is it possible to modify this model by adding another one? This modified 3D model (possibly a clone) would only be visible in a 3D preview.
----------------------------------------
EnkoNyito
France
Joined: Nov 7, 2005
Post Count: 9420
Status:
Offline
Re: Add another 3D model to an existing 3D model?
The setModel method requires a parameter of Content type, like URLContent class. The supported content are the ones cited in the furniture import wizard, i.e. OBJ, 3DS, DAE or a ZIP file containing a file at this format. I don’t see how you could add a second model with these restrictions, unless you generate a model file containing both models.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator
Joined: May 28, 2015
Post Count: 607
Status:
Offline
Re: Add another 3D model to an existing 3D model?
When I select a light and added sources manually, only the light is taken into account when exporting the selection in OBJ format. If I only select the sources added manually, the .obj and .mtl files are empty when exporting the selection in OBJ format.
How to bypass the restriction in the WriteNode method of the OBJWriter class?
...else if (node instanceof Shape3D) { Shape3D shape = (Shape3D)node; Appearance appearance = shape.getAppearance(); RenderingAttributes renderingAttributes = appearance != null ? appearance.getRenderingAttributes() : null; if (shape.numGeometries() >= 1 && (renderingAttributes == null || renderingAttributes.getVisible())) { ... // Start a new object at OBJ format this.out.write("g " + objectName + "\n"); ...
Joined: May 28, 2015
Post Count: 607
Status:
Offline
Re: Add another 3D model to an existing 3D model?
The setModel method requires a parameter of Content type, like URLContent class. The supported content are the ones cited in the furniture import wizard, i.e. OBJ, 3DS, DAE or a ZIP file containing a file at this format. I don’t see how you could add a second model with these restrictions, unless you generate a model file containing both models.
Since it is possible to import an object into SH3D from a resource (com/eteks/sweethome3d/io/resources/lightSource.obj), how to use the URLContent class ?
The goal would be to preload a scene with the model of a light and those of these sources before displaying them in the 3D preview.
----------------------------------------
EnkoNyito
France
Joined: Nov 7, 2005
Post Count: 9420
Status:
Offline
Re: Add another 3D model to an existing 3D model?
Look in DefaultFurnitureCatalog how the subclass ResourceURLContent is used. But as lightSource.obj may be in different places (in a file during development, then in Furniture.jar or SweetHome3D-x.y.jar during deployment and finally in a SH3D file when saved), I would suggest to use a copy of that file in your plug-in.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator
We see that when using the plug-in for the first time, a white box serves as a 3D model of the sources while for other uses the correct model is displayed in the 3D preview.
I can publish this version so that you can suggest some improvements.
----------------------------------------
EnkoNyito
France
Joined: Nov 7, 2005
Post Count: 9420
Status:
Offline
Re: Add another 3D model to an existing 3D model?
As said before, I would suggest not to rely on such a resource in Sweet Home 3D (they can change like icons recently), and would copy lightSource.obj in your plug-in. You could even use your own shape naming it in the OBJ file with a prefix equal to ModelManager.LIGHT_SHAPE_PREFIX to ensure it has the same behavior as lightSource.obj.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator