Skip to content

Commit

Permalink
Added some lighting Properties.
Browse files Browse the repository at this point in the history
Also organized materials a little.
  • Loading branch information
m-agour committed Dec 16, 2023
1 parent 5a11c11 commit 7d246e7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 41 deletions.
52 changes: 29 additions & 23 deletions docs/examples/viz_gltf_pbr.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
from fury import window, material, utils
"""
==========================================
Visualizing a glTF file with PBR materials
==========================================
In this tutorial, we will show how to display a glTF file that uses PBR materials.
"""

from fury import window
from fury.data import fetch_gltf, read_viz_gltf
from fury.gltf import glTF
from fury.io import load_cubemap_texture, load_image
from fury.data import fetch_gltf, read_viz_gltf, read_viz_cubemap
from fury.lib import Texture, ImageFlip

# rgb_array = load_image(
# '/home/shivam/Downloads/skybox.jpg')

# grid = utils.rgb_to_vtk(rgb_array)
# cubemap = Texture()
# flip = ImageFlip()
# flip.SetInputDataObject(grid)
# flip.SetFilteredAxis(1)
# cubemap.InterpolateOn()
# cubemap.MipmapOn()
# cubemap.SetInputConnection(0, flip.GetOutputPort(0))
# cubemap.UseSRGBColorSpaceOn()

scene = window.Scene(skybox=None)
# scene.SetBackground(0.5, 0.3, 0.3)

##############################################################################
# Create a scene.

scene = window.Scene()
scene.SetBackground(0.19, 0.21, 0.26)

##############################################################################
# Fetch and read the glTF file 'DamagedHelmet'.
fetch_gltf('DamagedHelmet')
filename = read_viz_gltf('DamagedHelmet')

##############################################################################
# Create a glTF object from the file and apply normals to the geometry.
gltf_obj = glTF(filename, apply_normals=True)

##############################################################################
# Extract actors representing the geometry from the glTF object.
actors = gltf_obj.actors()

##############################################################################
# Add all the actors representing the geometry to the scene.
scene.add(*actors)
scene.UseImageBasedLightingOn()

##############################################################################
# Applying camera from the glTF object to the scene.

cameras = gltf_obj.cameras
if cameras:
scene.SetActiveCamera(cameras[0])

interactive = True
interactive = 6

if interactive:
window.show(scene, size=(1280, 720))

window.record(scene, out_path='viz_gltf.png', size=(1280, 720))
window.record(scene, out_path='viz_gltf_PBR.png', size=(1280, 720))
46 changes: 28 additions & 18 deletions fury/gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,19 @@ def actors(self):
actor.GetProperty().SetORMTexture(metal_rough_tex)

emissive = self.materials[i]['emissive']
if emissive is not None:
actor.GetProperty().SetEmissiveTexture(emissive)
actor.GetProperty().SetEmissiveFactor(
self.materials[i]['emissive_factor']
)
if emissive['texture'] is not None:
actor.GetProperty().SetEmissiveTexture(emissive['texture'])
if emissive['factor'] is not None:
actor.GetProperty().SetEmissiveFactor(emissive['factor'])

normal = self.materials[i]['normal']
if normal is not None:
print('applying normal map')
actor.GetProperty().SetNormalTexture(normal)
actor.GetProperty().SetNormalScale(1.0)
if normal["texture"] is not None:
actor.GetProperty().SetNormalTexture(normal["texture"])
actor.GetProperty().SetNormalScale(normal["scale"])

# occlusion = self.materials[i]['occlusion']
# if occlusion["texture"] is not None:
# actor.GetProperty().SetOcclusionStrength(occlusion["strength"])

self._actors.append(actor)

Expand Down Expand Up @@ -447,20 +450,27 @@ def get_materials(self, mat_id):
'metallicValue': metalvalue,
'roughnessValue': roughvalue}
normal = material.normalTexture
normal_tex = self.get_texture(normal.index) if normal else None
normal_tex = {
"texture": self.get_texture(normal.index) if normal else None,
"scale": normal.scale if normal else 1.0
}
occlusion = material.occlusionTexture
occ_tex = self.get_texture(occlusion.index) if occlusion else None
occ_tex = {
"texture": self.get_texture(occlusion.index) if occlusion else None,
"strength": occlusion.strength if occlusion else 1.0
}
# must update pbr_dict with ORM texture
emissive = material.emissiveTexture
emi_tex = self.get_texture(emissive.index, True) if emissive else None
emi_tex = {
"texture": self.get_texture(emissive.index, True) if emissive else None,
"factor": material.emissiveFactor if emissive else [0, 0, 0]
}


return {
'pbr' : pbr_dict,
'normal' : normal_tex,
'occlusion' : occ_tex,
'emissive' : emi_tex,
'emissive_factor' : material.emissiveFactor
'pbr': pbr_dict,
'normal': normal_tex,
'occlusion': occ_tex,
'emissive': emi_tex
}

def get_texture(self, tex_id, srgb_colorspace=False, rgb=False):
Expand Down

0 comments on commit 7d246e7

Please sign in to comment.