Several rendering engines in the same plugin

This topic has been viewed 50623 times and has 21 replies
Thread status: Active
Questions about extending features and developing plug-ins [img]http://www.sweethome3d.com/images/flags/en_small.gif[/img]
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Several rendering engines in the same plugin

Post by Puybaret »

In [font=courier new]render[/font] method, you could create a camera with a different name for each rendered frame using a name equal to [font=courier new]UUID.randomUUID().toString()[/font]. 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 [font=courier new]sunDirection[/font] to its value during the previous call to [font=courier new]render[/font], and if it changed, delete the scene and environment with a call to [font=courier new]finalize()[/font] and create again the environment and the scene like in [font=courier new]YafarayRenderer[/font] 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
enkonyito
Posts: 607
Joined: Thu May 28, 2015 4:52 pm

Re: Several rendering engines in the same plugin

Post by enkonyito »

I used a unique identifier for the background, the sun and the camera.

Code: Select all

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 [font=courier new]YafarayRenderer[/font] constructor in the [font=courier new]renderImageAt[/font] method of the [font=courier new]PhotoImageGenerator[/font] class.
I did the same for the call to the [font=courier new]SunflowRenderer[/font] 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
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Several rendering engines in the same plugin

Post by Puybaret »

If by "calling the [font=courier new]YafarayRenderer[/font] constructor", you mean programming [font=courier new]new YafarayRenderer(...)[/font] 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
enkonyito
Posts: 607
Joined: Thu May 28, 2015 4:52 pm

Re: Several rendering engines in the same plugin

Post by enkonyito »

As it is not possible to remove a light created during the first video frame in YafaRay, a single call to [font=courier new]new YafarayRenderer[/font] has the consequence of adding new lights to the scene with each new frame which slows down the video rendering.
Using [font=courier new]finalize()[/font], Sweet Home 3D crashes by generating a .log file in the plug-in project folder.

With several calls to [font=courier new]new YafarayRenderer[/font] 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
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Several rendering engines in the same plugin

Post by Puybaret »

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

Re: Several rendering engines in the same plugin

Post by enkonyito »

Changes made to version 1.1 of the YafaRay plug-in

Code: Select all

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 [font=courier new]sunDirection [1][/font] which is initialized before the call to the [font=courier new]exportLightSource[/font] method.

Code: Select all

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.
Image Image

Automatic light on.
Image Image

Do you have any advice to resolve this situation?
EnkoNyito
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Several rendering engines in the same plugin

Post by Puybaret »

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

Re: Several rendering engines in the same plugin

Post by enkonyito »

This will be a great help to advance in compatibility with the YafaRay plug-in!
EnkoNyito
User avatar
Forestsun
Posts: 5
Joined: Tue Apr 28, 2020 6:45 pm

Re: Several rendering engines in the same plugin

Post by Forestsun »

How to reduce the size of the plug-in (12 MB) to speed up uploading?
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Several rendering engines in the same plugin

Post by Puybaret »

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
Post Reply New Topic

Who is online

Users browsing this forum: No registered users and 1 guest