Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions render-scene-fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

camera = bpy.context.active_object

print(f'Creating camera of {cameraType}')

# creation de la caméra en fonction du type
if cameraType == 'perspective':
aspectRatio = cameraValues[1]
Expand All @@ -59,7 +61,48 @@
camera.data.angle = float(fov)
camera.data.clip_start = float(znear)
camera.data.clip_end = float(zfar)

bpy.context.scene.camera = camera
elif cameraType == 'panoramic':
# Supprime toutes les caméras existantes
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_by_type(type='CAMERA')
bpy.ops.object.delete()

scene = bpy.context.scene
WIDTH, HEIGHT = 8192, 4096
SAMPLES = 128

scene.render.image_settings.file_format = 'WEBP'
scene.render.image_settings.color_mode = 'RGB'
scene.render.image_settings.color_depth = '8'

if hasattr(scene.render.image_settings, "webp"):
ws = scene.render.image_settings.webp
ws.quality = 85
ws.lossless = False
if hasattr(ws, "alpha_quality"):
ws.alpha_quality = 100
elif hasattr(scene.render.image_settings, "quality"):
scene.render.image_settings.quality = 85

scene.render.engine = 'CYCLES'
scene.cycles.samples = SAMPLES

# Ajoute la caméra et configure-la
bpy.ops.object.camera_add(location=(positionX, positionY, positionZ),
rotation=(orientationX, orientationY, orientationZ))
camera = bpy.context.active_object
scene.camera = camera
camera.data.type = 'PANO'
try:
camera.data.cycles.panorama_type = 'EQUIRECTANGULAR'
except AttributeError:
if hasattr(camera.data, "panorama_type"):
camera.data.panorama_type = 'EQUIRECTANGULAR'

scene.render.resolution_x = WIDTH
scene.render.resolution_y = HEIGHT
scene.render.resolution_percentage = 100
else:
znear = cameraValues[1]
zfar = cameraValues[2]
Expand All @@ -70,8 +113,7 @@
camera.data.ortho_scale = float(xmag)
camera.data.clip_start = float(znear)
camera.data.clip_end = float(zfar)

bpy.context.scene.camera = camera
bpy.context.scene.camera = camera

# on change la position du soleil
sun = bpy.data.objects["__render_sun"]
Expand All @@ -81,4 +123,4 @@
hdrMapSunRotation = 0.86924

bpy.data.worlds["World"].node_tree.nodes["Mapping"].inputs[2].default_value[2] = hdrMapSunRotation - sceneSunRotation
print(f'--- render-scene-fast-import.py execution time: {time.time() - startTime} seconds ---')
print(f'--- render-scene-fast-import.py execution time: {time.time() - startTime} seconds ---')
44 changes: 41 additions & 3 deletions render-scene-import.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ def applyCustomColorToMaterial(material, colorToApply):

camera = bpy.context.active_object

print(f'Creating camera of {cameraType}')

# creation de la caméra en fonction du type
if cameraType == 'perspective':
aspectRatio = cameraValues[1]
Expand All @@ -576,7 +578,44 @@ def applyCustomColorToMaterial(material, colorToApply):
camera.data.angle = float(fov)
camera.data.clip_start = float(znear)
camera.data.clip_end = float(zfar)
bpy.context.scene.camera = camera
elif cameraType == 'panoramic':
# Supprime toutes les caméras existantes
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_by_type(type='CAMERA')
bpy.ops.object.delete()

scene = bpy.context.scene
WIDTH, HEIGHT = 8192, 4096
SAMPLES=128

scene.render.image_settings.file_format = 'WEBP'
scene.render.image_settings.color_mode = 'RGB'

if hasattr(scene.render.image_settings, "webp"):
ws = scene.render.image_settings.webp
ws.quality = 85
ws.lossless = False
elif hasattr(scene.render.image_settings, "quality"):
scene.render.image_settings.quality = 85

scene.render.engine = 'CYCLES'
scene.cycles.samples = SAMPLES
bpy.ops.object.camera_add(location=(positionX, positionY, positionZ),
rotation=(orientationX, orientationY, orientationZ))
camera = bpy.context.active_object
scene.camera = camera
camera.data.type = 'PANO'

try:
camera.data.cycles.panorama_type = 'EQUIRECTANGULAR'
except AttributeError:
if hasattr(camera.data, "panorama_type"):
camera.data.panorama_type = 'EQUIRECTANGULAR'

scene.render.resolution_x = WIDTH
scene.render.resolution_y = HEIGHT
scene.render.resolution_percentage = 100
else:
znear = cameraValues[1]
zfar = cameraValues[2]
Expand All @@ -585,13 +624,12 @@ def applyCustomColorToMaterial(material, colorToApply):

camera.data.type = 'ORTHO'
camera.data.ortho_scale = float(xmag)

bpy.context.scene.camera = camera
bpy.context.scene.camera = camera

bpy.ops.wm.save_as_mainfile(filepath=f"./cache/scene-{sceneEnvironment}-{session}.blend")


print(f'--- render-scene-import.py execution time: {time.time() - startTime} seconds ---')
print(f'importedObjectsCount: {importedObjectsCount}')
print(f'importedMaterialsCount: {importedMaterialsCount}')
print(f'importedColorsCount: {importedColorsCount}')
print(f'importedColorsCount: {importedColorsCount}')