Closed LTU-Eimantas closed 3 years ago
Hi @LTU-Eimantas!
Could you verify that your version of nvisii is fully up to date? This is a known bug that should have been fixed in the latest nvisii release.
I am using NVISII 1.1.72 version with nVidia 460 drivers
My way around this problem (in the earlier version) was to manually set the colors on the entities returned by the function.
This is an example in loading an obj file from mecabrick.com
def load_lego_object(path):
"""
This loads a single entity from a lego model taken from
mecabrick.com.
path: path to the head folder for the lego scene
return: a list of visii entity names
"""
models = glob.glob(path+"/*.obj")
if len(models) == 0:
raise('no models')
obj_to_load = models[0]
name_model = models[0].replace(path,'').replace('.obj','').replace(' ',"_")
print("loading:",name_model)
name = path.split('/')[-2]
# load the materials
with open(obj_to_load.replace('obj','mtl')) as f:
lines = f.readlines()
colours = {}
name_material = None
for line in lines:
# print(line)
color = None
texture = None
transparency = 1
if 'newmtl' in line:
# print(line)
name_material = line.split(' ')[-1].replace('\n','')
# print(name_material)
colours[name_material] = {
"texture_path":None
}
if 'Kd' in line and not 'png' in line:
kd = eval(",".join(line.split(' ')[1:]))
# print(name_material,kd)
# colours[name_material] = [kd[0],kd[1],kd[2]]
colours[name_material]['rgb'] = [kd[0],kd[1],kd[2]]
if 'map_Kd' in line:
texture_name = line.split(' ')[-1].replace('\n','')
# print(name_material,kd)
# colours[name_material] = texture_name
colours[name_material]['texture_path'] = texture_name
if 'd' == line.split(' ')[0]:
value_transparency = line.split(' ')[-1]
if not value_transparency == '1':
colours[name_material+'_transparency'] = float(value_transparency)
colours[name_material]['alpha'] = float(value_transparency)
# print(line)
toys = visii.import_scene(obj_to_load,
visii.vec3(0,0,0),
visii.vec3(0.01,0.01,0.01), # the scale
visii.angleAxis(1.57, visii.vec3(1,0,0))
)
for material in toys.materials:
if 'DefaultMaterial' == material.get_name():
continue
rgb = colours[material.get_name()]['rgb']
material.set_base_color(visii.vec3(float(rgb[0]),float(rgb[1]),float(rgb[2])))
if colours[material.get_name()]['alpha']<1:
material.set_alpha(colours[material.get_name()]['alpha'])
material.set_roughness(0)
material.set_metallic(0)
material.set_transmission(0)
material.set_specular(0.33)
# find the entity names
with open(obj_to_load) as f:
lines = f.readlines()
entity_names = []
for line in lines:
if line[0] == 'o':
name = line.split(' ')[-1].replace("\n","")
entity_names.append(f"{name}_{name}")
# print(entity_names)
for entity_name in entity_names:
# print(entity_name)
if entity_name == 'camera':
continue
# print('get')
entity = visii.entity.get(entity_name)
# print('get_mat')
mat_name = entity.get_material().get_name()
if colours[mat_name]['alpha']<1:
entity.set_visibility(shadow = False)
mat = entity.get_material()
mat.set_transmission(1)
mat.set_ior(0.98)
# print(entity.get_name())
# entity.set_visibility(False)
return entity_names
@TontonTremblay can you reproduce this issue with the motion blurred car locally on your system?
Sorry, guys it was fault from my end. I haven't seen that the docer file which I compile use 1.0 version and not 1.1 of NVISII (RUN pip3 install nvisii==1.0.70). I am quite new with when it comes to Docer so I though it use the same version as system. Maybe you should mentioned that you have to do change NVISII version in the docer file.
Thank you for pointing that out. I removed it from the docker file. Happy to answer further questioning you might have.
Sorry if this might sound childish but how should I import colors on object? When I trying to do 15th example (15.camera_motion_car_blur.py) I am getting everything (shines, blur, etc), but no colors. But if I open online 3D Viewer or MS 3D viewer I can clearly see all of them. My pc spec: Ubuntu 18.04 LTS Intel® Core™ i7-10750H CPU @ 2.60GHz × 12 GeForce GTX 1050 3GB 16GB RAM