Print at Jan 21, 2026, 8:41:27 AM
Posted by enkonyito at Dec 3, 2019, 3:51:53 AM
Several rendering engines in the same plugin
To date, Sweet Home 3D default rendering engine is SunFlow (written in Java).
The YafaRay rendering plugin offers another rendering engine (written in C++ and accessible in Java Native Interface).

Grouping these 2 rendering engines in one plugin with a selector seems like a good idea.


1st problem
For YafaRay rendering to work when selected, you must apparently respect the order and name of the initial com/eteks/sweethome3d/plugin/yafarayrendering packages.
In this case, the YafarayRenderer.h and YafarayRenderer.cpp files do not appear to be necessary but use the lib folder containing the DLLs (Windows, Mac OS X and Linux).
- Solution #1:
In the plugin project folder, use the com/eteks/sweethome3d/plugin/yafarayrendering packages for all files (photo panel, SunFlow and YafaRay rendering engines).
This is a problem when adding another rendering engine where you will also have to respect the order and the name of the initial packages.

- Solution #2:
In the plugin project folder, keep the package created for the SunFlow rendering engine and the photo panel.
Use com/eteks/sweethome3d/plugin/yafarayrendering packages for the YafarayRenderer.java file by adding an
import com.eteks.sweethome3d.plugin.yafarayrendering.YafarayRenderer
in the PhotoPanel.java file.
In this case, each rendering engine has its own packages and this would facilitate future additions.


2nd problem
When you press the Stop button, the YafaRay rendering is not interrupted when it is selected.

Enko Nyito
----------------------------------------
EnkoNyito

Posted by enkonyito at Dec 7, 2019, 4:11:51 PM
Re: Several rendering engines in the same plugin
2nd problem
When you press the Stop button, the YafaRay rendering is not interrupted when it is selected.

Solution:
Take into account the different management of the Stop button by the YafaRay rendering plugin (YafarayPhotoPanel).
----------------------------------------
EnkoNyito

Posted by Puybaret at Dec 9, 2019, 1:19:04 PM
Re: Several rendering engines in the same plugin
YafarayRenderer.h, YafarayRenderer.cpp and any source files like Java ones are not necessary for a plug-in to work. I just took the habit to include source code in the plug-in to avoid developers to download it from another place (these files are generally not very large).
SunFlow and YafaRay renderers are completely independent from each other, so you can organize the packages where you use them like you want.
The only thing to take care of, is too update in the YafaRay program according to where the DLLs it requires are stored, so the plug-in can find these DLLs to extract and load them.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by enkonyito at Jan 27, 2020, 12:43:09 AM
Re: Several rendering engines in the same plugin
How to reduce the size of the plug-in (12 MB) to speed up uploading?
----------------------------------------
EnkoNyito

Posted by Puybaret at Jan 27, 2020, 11:46:34 AM
Re: Several rendering engines in the same plugin
In the Beta 4 version of YafaRay plug-in where I recompiled YafaRay DLLs, I already removed many options to make its DLLs smaller. Not sure, I can do better. By the way, once added the DLLs for 32 bit systems, the size of the plug-in will be even twice as large.
The only way I can think of to reduce the plug-in size, would be to produce one plug-in per operating system / architecture, but I'm not sure that it will be as easy to maintain, distribute and explain. We could say it's the weight of portability!
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by Puybaret at Jan 27, 2020, 2:28:28 PM
Re: Several rendering engines in the same plugin
Sorry, I forgot about the DLLs found in yafaray-plugins folder. It should be possible to remove the ones which are not used: list the values associated to all the parameters named "types" in the program, and remove the DLLs which doesn't match the found names. But this might be more complicated that this, because libjpgHandler and libpngHandler DLLs must be kept to support JPEG and PNG of texture images. There might be other dependencies that will need a deeper study.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by UbuntuBirdy at Jan 27, 2020, 4:39:07 PM
Re: Several rendering engines in the same plugin
In my opinion, in 2020 12MB is not large enough to even think about reducing size...
----------------------------------------
Pascal

SH3D 6.6 / Ubuntu 22.04 (Mainline-Kernel) / Radeon RX580 / Ryzen 7 5800x

Posted by Puybaret at Jan 27, 2020, 5:56:59 PM
Re: Several rendering engines in the same plugin
Useless bytes are never welcomed so if the plug-in size could be reduced easily, it would be a nice gain.
By the way, larger DLLs means also more time to extract and load them at the launch of the first rendering.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by UbuntuBirdy at Jan 27, 2020, 6:53:12 PM
Re: Several rendering engines in the same plugin
Useless bytes are never welcomed so if the plug-in size could be reduced easily, it would be a nice gain.
By the way, larger DLLs means also more time to extract and load them at the launch of the first rendering.

Correct! But, it's the wrong priority to search for useless bytes while the plug-in is not fully functional yet.
And it's totally the wrong priority if the plug-in is 12MB and not 120MB.
But as written bevore, this is only my opinion...
----------------------------------------
Pascal

SH3D 6.6 / Ubuntu 22.04 (Mainline-Kernel) / Radeon RX580 / Ryzen 7 5800x

Posted by enkonyito at Feb 8, 2020, 2:48:42 AM
Re: Several rendering engines in the same plugin
About the integration of the YafaRay rendering engine.


Photos panel at points of view.
The name of the selected rendering engine is added at the end of the image file name.
No particular problem.


Video panel.
The name of the selected rendering engine is added at the end of the video file name.
The video shows a frozen image with the YafaRay renderer while the sequence is animated with the SunFlow renderer.
The following warnings are returned after the first image rendered:
WARNING: Environment: Sorry, Background "background" already exists!
WARNING: Environment: Sorry, Light "sun" already exists!
WARNING: Environment: Sorry, Camera "camera" already exists!".

----------------------------------------
EnkoNyito

Posted by Puybaret at Feb 8, 2020, 5:25:07 PM
Re: Several rendering engines in the same plugin
In render method, you could create a camera with a different name for each rendered frame using a name equal to UUID.randomUUID().toString(). For the background and the sun, I don't see any way in YafaRay to replace a light by another one, remove a light from the rendered scene or disable a light.
You could ensure that they are created only once but this would forbid to simulate sun moves during the day. You could also compare sunDirection to its value during the previous call to render, and if it changed, delete the scene and environment with a call to finalize() and create again the environment and the scene like in YafarayRenderer constructor (this will slow down video creation process compared to SunFlow renderer, but changing time during a video is probably not a common use of the video creation tool).

Good luck!
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by enkonyito at Feb 11, 2020, 9:44:12 PM
Re: Several rendering engines in the same plugin
I used a unique identifier for the background, the sun and the camera.
String backgroundName = "background";
String cameraName = "camera";
...
createBackground(backgroundName = UUID.randomUUID().toString(), params);
...
createLight(UUID.randomUUID().toString(), params);
...
createCamera(cameraName = UUID.randomUUID().toString(), params);
...
params.put("camera_name", cameraName);
params.put("background_name", backgroundName);


To be sure they are not created several times in order not to slow down the video rendering, I put the call to the YafarayRenderer constructor in the renderImageAt method of the PhotoImageGenerator class.
I did the same for the call to the SunflowRenderer constructor and I adapted the management of the variable light sources.

These modifications allow to animate the camera and simulate the movements of the sun during the day regardless of the selected rendering engine.
----------------------------------------
EnkoNyito

Posted by Puybaret at Feb 12, 2020, 12:55:29 AM
Re: Several rendering engines in the same plugin
If by "calling the YafarayRenderer constructor", you mean programming new YafarayRenderer(...) for each frame of the video, I don’t understand how it couldn’t not slow down the creation of the video. This constructor creates many objects and calls many methods of the rendering engine to create the scene! Or maybe, you meant something else...
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by enkonyito at Feb 12, 2020, 3:30:00 PM
Re: Several rendering engines in the same plugin
As it is not possible to remove a light created during the first video frame in YafaRay, a single call to new YafarayRenderer has the consequence of adding new lights to the scene with each new frame which slows down the video rendering.
Using finalize(), Sweet Home 3D crashes by generating a .log file in the plug-in project folder.

With several calls to new YafarayRenderer as for photos at points of view, a new scene is created with each video frame and the problem of removing lights does not arise.
The surprise is that the video rendering is no longer slowed down and is even faster than SunFlow.
----------------------------------------
EnkoNyito

Posted by Puybaret at Feb 13, 2020, 12:24:36 AM
Re: Several rendering engines in the same plugin
Keep it that way if you want, at least it works. I'll study another way in the next version.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by enkonyito at May 13, 2020, 4:51:08 AM
Re: Several rendering engines in the same plugin
Changes made to version 1.1 of the YafaRay plug-in
if (this.sunDirection == null || !Arrays.equals(this.sunDirection, sunDirection)) {
if (this.sunDirection != null) {
try {
// Reinitialize renderer because Yafaray doesn't allow to modify or delete lights
dispose();
finalize();
init();
} catch (IOException ex) {
// Shouldn't happen since first initRenderer call worked
}
}
if (sunDirection [1] > -0.075f) {
...
}

this.sunDirection = sunDirection;
}

have an impact on variable light sources (daylight or automatic).

Their power is linked to sunDirection [1] which is initialized before the call to the exportLightSource method.
this.sunDirection = getSunDirection(this.compass, Camera.convertTimeToTimeZone(this.home.getCamera().getTime(), this.compass.getTimeZone()));


If I keep this initialization, the sky or the sun is no longer visible.

Automatic light off.


Automatic light on.


Do you have any advice to resolve this situation?
----------------------------------------
EnkoNyito

Posted by Puybaret at May 18, 2020, 7:58:00 PM
Re: Several rendering engines in the same plugin
Sorry Enkonyito, I should have better tested the changes I made for video generation in the version 1.1 of the YafaRay plug-in. The issues should be fixed in version 1.2 that I tested by rendering images more than once with a camera time and place change between frames.
You'll see that I also added to YafaRay some methods able to remove lights, backgrounds, integrators and cameras, to prevent the need to restart YafaRay engine between two frames.
Hope you can integrate these changes more easily in your plug-in.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by enkonyito at May 19, 2020, 1:45:03 AM
Re: Several rendering engines in the same plugin
This will be a great help to advance in compatibility with the YafaRay plug-in!
----------------------------------------
EnkoNyito

Posted by Forestsun at Aug 17, 2020, 2:38:29 AM
Re: Several rendering engines in the same plugin
How to reduce the size of the plug-in (12 MB) to speed up uploading?

Posted by Puybaret at Aug 17, 2020, 4:50:03 PM
Re: Several rendering engines in the same plugin
How to reduce the size of the plug-in (12 MB) to speed up uploading?
Remove some DLLs of the system you don’t want to support.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by Forestsun at Sep 4, 2020, 11:40:34 AM
Re: Several rendering engines in the same plugin
like Java ones are not necessary for a plug-in to work.

Posted by Puybaret at Sep 4, 2020, 1:15:26 PM
Re: Several rendering engines in the same plugin
No I spoke about the DLLs in the plug-in.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator