Add another 3D model to an existing 3D model?

This topic has been viewed 30466 times and has 14 replies
Thread status: Active
Questions about extending features and developing plug-ins [img]http://www.sweethome3d.com/images/flags/en_small.gif[/img]
enkonyito
Posts: 607
Joined: Thu May 28, 2015 4:52 pm

Add another 3D model to an existing 3D model?

Post by enkonyito »

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
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Add another 3D model to an existing 3D model?

Post by Puybaret »

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
enkonyito
Posts: 607
Joined: Thu May 28, 2015 4:52 pm

Re: Add another 3D model to an existing 3D model?

Post by enkonyito »

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 [font=courier new]WriteNode[/font] method of the [font=courier new]OBJWriter[/font] class?

Code: Select all

...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");
...
EnkoNyito
enkonyito
Posts: 607
Joined: Thu May 28, 2015 4:52 pm

Re: Add another 3D model to an existing 3D model?

Post by enkonyito »

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 ([font=courier new]com/eteks/sweethome3d/io/resources/lightSource.obj[/font]), 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
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Add another 3D model to an existing 3D model?

Post by Puybaret »

Look in DefaultFurnitureCatalog how the subclass [font=courier new]ResourceURLContent[/font] is used.
But as [font=courier new]lightSource.obj[/font] may be in different places (in a file during development, then in [font=courier new]Furniture.jar[/font] or [font=courier new]SweetHome3D-x.y.jar[/font] 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
enkonyito
Posts: 607
Joined: Thu May 28, 2015 4:52 pm

Re: Add another 3D model to an existing 3D model?

Post by enkonyito »

For the first version of the plugin, I used this location for the [font=courier new]lightSource.obj[/font] file.

Code: Select all

final Content sourceContent = new ResourceURLContent (DefaultFurnitureCatalog.class, "resources/lightSource.obj");
Taking inspiration from your ShapeGenerator plug-in, I get these results.
ViewLightSources_firstOpening.jpg
ViewLightSources_secondOpening.jpg

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
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Add another 3D model to an existing 3D model?

Post by Puybaret »

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 [font=courier new]lightSource.obj[/font] in your plug-in.
You could even use your own shape naming it in the OBJ file with a prefix equal to [font=courier new]ModelManager.LIGHT_SHAPE_PREFIX[/font] to ensure it has the same behavior as [font=courier new]lightSource.obj[/font].
Emmanuel Puybaret, Sweet Home 3D creator
enkonyito
Posts: 607
Joined: Thu May 28, 2015 4:52 pm

Re: Add another 3D model to an existing 3D model?

Post by enkonyito »

The ViewLightSources plug-in is available.
EnkoNyito
User avatar
YGYL
Posts: 157
Joined: Tue Feb 05, 2013 4:00 pm

Re: Add another 3D model to an existing 3D model?

Post by YGYL »

Tested and available
It would be perfect if the coordinates of the light source of the object can be adjusted in real time
enkonyito
Posts: 607
Joined: Thu May 28, 2015 4:52 pm

Re: Add another 3D model to an existing 3D model?

Post by enkonyito »

ViewLightSources-1.1.sh3p
- transparency of the previewed light
EnkoNyito
Post Reply New Topic

Who is online

Users browsing this forum: No registered users and 1 guest