Setting Image for Spot Projector
Forum rules
Please upload a testscene that allows developers to reproduce the problem, and attach some images.
Please upload a testscene that allows developers to reproduce the problem, and attach some images.
Setting Image for Spot Projector
Hi,
I'm trying to set the Image of Spot Projector from the Python Console of Blender, with the following line of code:
bpy.data.lamps['Spot'].luxcore.image = bpy.data.images['AAA.png']
As a result, I get an error:
Traceback (most recent call last):
File "C:\Users\igall\AppData\Roaming\Blender Foundation\Blender\2.79\scripts\addons\BlendLuxCore\properties\light.py", line 60, in update_image
if context.lamp:
AttributeError: 'Context' object has no attribute 'lamp'
Despite the error, the field is being updated:
>>> bpy.data.lamps['Spot'].luxcore.image
bpy.data.images['AAA.png']
But the render results are unstable: sometimes the rendered image comes out with the pattern, and sometimes without.
What could be the reason for the problem?
Is there a better way to set the Image of Spot Projector from the Python Console of Blender?
Many thanks!
Igal
I'm trying to set the Image of Spot Projector from the Python Console of Blender, with the following line of code:
bpy.data.lamps['Spot'].luxcore.image = bpy.data.images['AAA.png']
As a result, I get an error:
Traceback (most recent call last):
File "C:\Users\igall\AppData\Roaming\Blender Foundation\Blender\2.79\scripts\addons\BlendLuxCore\properties\light.py", line 60, in update_image
if context.lamp:
AttributeError: 'Context' object has no attribute 'lamp'
Despite the error, the field is being updated:
>>> bpy.data.lamps['Spot'].luxcore.image
bpy.data.images['AAA.png']
But the render results are unstable: sometimes the rendered image comes out with the pattern, and sometimes without.
What could be the reason for the problem?
Is there a better way to set the Image of Spot Projector from the Python Console of Blender?
Many thanks!
Igal
Re: Setting Image for Spot Projector
I fixed the exception being thrown and another issue.
However as you noted, it was only a "cosmetic" problem, since the image is still updated.
Maybe it is related to this issue: https://github.com/LuxCoreRender/BlendL ... issues/152
Is your image a generated image? If yes, try to save it to disk.
By the way, you can find all properties here: https://github.com/LuxCoreRender/BlendL ... properties
Here is the faulty "update_image()" method: https://github.com/LuxCoreRender/BlendL ... ght.py#L72
And this is the fix: https://github.com/LuxCoreRender/BlendL ... 313625f46e
However as you noted, it was only a "cosmetic" problem, since the image is still updated.
Sounds strange and I doubt it has anything to do with the rest (doesn't matter if the image was changed from UI or from Python).
Maybe it is related to this issue: https://github.com/LuxCoreRender/BlendL ... issues/152
Is your image a generated image? If yes, try to save it to disk.
By the way, you can find all properties here: https://github.com/LuxCoreRender/BlendL ... properties
Here is the faulty "update_image()" method: https://github.com/LuxCoreRender/BlendL ... ght.py#L72
And this is the fix: https://github.com/LuxCoreRender/BlendL ... 313625f46e
Re: Setting Image for Spot Projector
Thanks B.Y.O.B!
image_name = os.path.basename(pattern_path)
bpy.ops.image.open(filepath=image_name, directory=os.path.dirname(pattern_path),
files=[{"name": image_name}], relative_path=False, show_multiview=True)
Still, the pattern existence in the render results is unstable.
That's how my results look like. It is a scene with two cameras. Each camera yields randomly a result with or without the pattern.
What else could be possible to solve this please?
I took your fix and updated to the latest version.
I'm loading my image from the disk with the following lines of code:
image_name = os.path.basename(pattern_path)
bpy.ops.image.open(filepath=image_name, directory=os.path.dirname(pattern_path),
files=[{"name": image_name}], relative_path=False, show_multiview=True)
Still, the pattern existence in the render results is unstable.
That's how my results look like. It is a scene with two cameras. Each camera yields randomly a result with or without the pattern.
What else could be possible to solve this please?
Last edited by igall2 on Wed May 09, 2018 8:33 am, edited 1 time in total.
Re: Setting Image for Spot Projector
Can you upload an example scene showing the problem?
Re: Setting Image for Spot Projector
Done.
Here is the link:
https://drive.google.com/file/d/1COTFuz ... sp=sharing
Important note:
The problem appeared on a Win10 x64 PC with GTX 1070 GPU and i7-8700K CPU
The problem didn't appear on a Win7 x64 PC with AMD Radeon R7 M360 GPU and i7-6600U CPU
To replicate the problem:
- Download and unzip
- In command line, go to the unzipped folder
- Run the following command:
blender.exe --background "LuxRenderTest.blend" --python "render_scene.py"
I also placed in the folder a Jupyter notebook script that opens and shows the multilayer EXRs, open_multilayer_exrs.ipynb
Igal
Re: Setting Image for Spot Projector
I'm not sure if this is a problem in BlendLuxCore or in your script.
I would recommend to change your set_module_coord_frames() function in the following way:
replace this:
with this:
Running operators might require to force a scene update in some cases.
image_utils avoids this: https://docs.blender.org/api/2.79/bpy_e ... utils.html
Your script also makes some other wonky assumptions, e.g. that one of the cameras is selected. I would change this.
By the way, to do correct stereo you should use camera shift in X direction to make the camera frustums overlap exactly (currently you have some overshoot left and right if I'm not mistaken).
This is my result:
I would recommend to change your set_module_coord_frames() function in the following way:
replace this:
Code: Select all
bpy.ops.image.open(filepath=image_name, directory=os.path.dirname(pattern_path),
files=[{"name": image_name}], relative_path=True, show_multiview=True)
bpy.data.lamps['Spot'].luxcore.image = bpy.data.images[image_name]
Code: Select all
from bpy_extras import image_utils
img = image_utils.load_image(image_name, os.path.dirname(pattern_path))
bpy.data.lamps['Spot'].luxcore.image = img
image_utils avoids this: https://docs.blender.org/api/2.79/bpy_e ... utils.html
Your script also makes some other wonky assumptions, e.g. that one of the cameras is selected. I would change this.
By the way, to do correct stereo you should use camera shift in X direction to make the camera frustums overlap exactly (currently you have some overshoot left and right if I'm not mistaken).
This is my result:
Re: Setting Image for Spot Projector
Thanks B.Y.O.B,
I have replaced the code as you suggested, but still sometimes on a faster computer one of the cameras is rendered without the pattern.
Given multiple cameras in the scene, is it possible to render them simultaneously, by a single Blender API call?
Or, should one organize a loop by cameras? In this case, should one use viewport?
It could be that because of this misunderstanding the rendering in the uploaded script sometimes goes wrong.
I believe that once it becomes clear I can write a correct script.
I have replaced the code as you suggested, but still sometimes on a faster computer one of the cameras is rendered without the pattern.
It seems that this is an important point to understand.
Given multiple cameras in the scene, is it possible to render them simultaneously, by a single Blender API call?
Or, should one organize a loop by cameras? In this case, should one use viewport?
It could be that because of this misunderstanding the rendering in the uploaded script sometimes goes wrong.
I believe that once it becomes clear I can write a correct script.
Re: Setting Image for Spot Projector
No you can't render simultaneously, and it is not necessary.
What I meant is that your script assumes that the camera is selected when the .blend file is opened. In my tests, I once saved the file with the spotlight selected, and the script failed.
You should access them by name, e.g. bpy.data.objects["CamLeft"], instead of bpy.context.object and assuming that it is the camera.
Then please do further tests.
If you can show that the problem is a bug in BlendLuxCore, I can help you again.
Re: Setting Image for Spot Projector
Thanks B.Y.O.B,
I did the corrections that you have suggested.
One or both of the cameras are now rendered without the pattern in about 50% of the runs.
I have uploaded here the new script + Blender model:
https://drive.google.com/open?id=16f1Ow ... EgsS7SrmJL
You can download and run it in the similar way like the previous one.
Best Regards,
Igal
I did the corrections that you have suggested.
I have done more tests. Now I have the same behavior on both computers.
One or both of the cameras are now rendered without the pattern in about 50% of the runs.
I have uploaded here the new script + Blender model:
https://drive.google.com/open?id=16f1Ow ... EgsS7SrmJL
You can download and run it in the similar way like the previous one.
Best Regards,
Igal
Re: Setting Image for Spot Projector
Please test your script with Cycles as render engine.
If it works ok there but not in BlendLuxCore, I will investigate.
If it works ok there but not in BlendLuxCore, I will investigate.