export obj with material metallic will from 0 to 1 #60150

Closed
opened 2019-01-04 12:35:18 +01:00 by Robert Zhang · 14 comments
Member

System Information
Operating system:windows 10 lastest
Graphics card:gtx980ti

Blender Version
blender 2.80.39

export a object with material when metallic set 0, re-import this obj object, metallic will change to 1. but if set 0.01 or something number just not 0 when export and that not going to happened.

**System Information** Operating system:windows 10 lastest Graphics card:gtx980ti **Blender Version** blender 2.80.39 export a object with material when metallic set 0, re-import this obj object, metallic will change to 1. but if set 0.01 or something number just not 0 when export and that not going to happened.
Author
Member

Added subscriber: @zhanghua

Added subscriber: @zhanghua
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Philipp Oeser self-assigned this 2019-01-04 12:39:55 +01:00
Member

Confirmed, checking...

Confirmed, checking...

Added subscriber: @dfelinto

Added subscriber: @dfelinto

Please attach a sample file, and please specify the hash of the Blender you used for testing (e.g., 4d8ed937f2)

Please attach a sample file, and please specify the hash of the Blender you used for testing (e.g., 4d8ed937f226f4cdfa6f62fde5306b14c217e9c5)
Author
Member

output-obj.obj

output-obj.mtl

export-this-cube-to-obj.blend

Hash is today. by the way this bug always have when 2.80 have export obj feature.

[output-obj.obj](https://archive.blender.org/developer/F6171478/output-obj.obj) [output-obj.mtl](https://archive.blender.org/developer/F6171477/output-obj.mtl) [export-this-cube-to-obj.blend](https://archive.blender.org/developer/F6171485/export-this-cube-to-obj.blend) Hash is today. by the way this bug always have when 2.80 have export obj feature.
Member

Added subscribers: @mont29, @brecht

Added subscribers: @mont29, @brecht
Member

blender/blender-addons@f9c31589f6 made some changes here.
Since obj materials are "old school" and dont really support PBR we are abusing the ambient term for metallic

on export:

use_mirror = mat_wrap.metallic != 0.0                
if use_mirror:
    fw('Ka %.6f %.6f %.6f\n' % (mat_wrap.metallic, mat_wrap.metallic, mat_wrap.metallic))
else:
    fw('Ka %.6f %.6f %.6f\n' % (1.0, 1.0, 1.0))

on import:

if line_id == b'ka':
    refl = (float_func(line_split[1]) + float_func(line_split[2]) + float_func(line_split[3])) / 3.0
    context_mat_wrap.metallic = refl
    context_material_vars.add("metallic")

It kind of makes sense to have "old school" ambient when metallic is zero, on the other hand this causes described behavior on import.
Without digging real deep I see two solutions:

  • always dump metallic into ka (but we dont get ambient then when metallic is zero)
  • keep export as is, but check illum < 3 [indicates no Reflection] on import and set metallic to zero then [<< this one has my vote...]

P881: #60150 snippet



diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py
index 3185e5c2..adad3d98 100644
--- a/io_scene_obj/import_obj.py
+++ b/io_scene_obj/import_obj.py
@@ -324,6 +324,8 @@ def create_materials(filepath, relpath,
                         illum = get_int(line_split[1])
 
                         # inline comments are from the spec, v4.2
+                        if illum < 3:
+                            context_mat_wrap.metallic = 0.0
                         if illum == 0:
                             # Color on and Ambient off
                             print("WARNING, Principled BSDF shader does not support illumination 0 mode "

@mont29, @brecht: what do you think?

blender/blender-addons@f9c31589f6 made some changes here. Since obj materials are "old school" and dont really support PBR we are abusing the `ambient` term for metallic on export: ``` use_mirror = mat_wrap.metallic != 0.0 if use_mirror: fw('Ka %.6f %.6f %.6f\n' % (mat_wrap.metallic, mat_wrap.metallic, mat_wrap.metallic)) else: fw('Ka %.6f %.6f %.6f\n' % (1.0, 1.0, 1.0)) ``` on import: ``` if line_id == b'ka': refl = (float_func(line_split[1]) + float_func(line_split[2]) + float_func(line_split[3])) / 3.0 context_mat_wrap.metallic = refl context_material_vars.add("metallic") ``` It kind of makes sense to have "old school" ambient when metallic is zero, on the other hand this causes described behavior on import. Without digging real deep I see two solutions: - **always** dump metallic into ka (but we dont get ambient then when metallic is zero) - keep export as is, but check `illum` < 3 [indicates no Reflection] on import and set metallic to zero then [<< this one has my vote...] [P881: #60150 snippet](https://archive.blender.org/developer/P881.txt) ``` diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py index 3185e5c2..adad3d98 100644 --- a/io_scene_obj/import_obj.py +++ b/io_scene_obj/import_obj.py @@ -324,6 +324,8 @@ def create_materials(filepath, relpath, illum = get_int(line_split[1]) # inline comments are from the spec, v4.2 + if illum < 3: + context_mat_wrap.metallic = 0.0 if illum == 0: # Color on and Ambient off print("WARNING, Principled BSDF shader does not support illumination 0 mode " ``` @mont29, @brecht: what do you think?

@lichtwerk Also think solution #2 is better, please add a comment to that line about meaning of illum < 3 though. ;)

And not sure this is the right place/way to do that, would rather add an else to if do_reflection: condition (line 259 currently)?

@lichtwerk Also think solution #2 is better, please add a comment to that line about meaning of `illum < 3` though. ;) And not sure this is the right place/way to do that, would rather add an `else` to `if do_reflection:` condition (line 259 currently)?
Member

@mont29: generally agree, but putting it in the 259 area will fail if you only have one material, see

Finalize previous mat, if any.

(that is a bit worrying actually, I guess some other stuff will fail as well if you only have one material...)

Regarding this report: would prefer to put it like in P881, move on and have a look at the "finalize-mat-not-doing-its-thing-with-only-one-material" later... OK?

@mont29: generally agree, but putting it in the 259 area will fail if you only have **one material**, see > # Finalize previous mat, if any. (that is a bit worrying actually, I guess some other stuff will fail as well if you only have one material...) Regarding this report: would prefer to put it like in [P881](https://archive.blender.org/developer/P881.txt), move on and have a look at the "finalize-mat-not-doing-its-thing-with-only-one-material" later... OK?

@lichtwerk arg! you are right, finalize is not called for last material (not relevant how many mats there are)!!! That I will fix first, then we can put your fix in (new) finalize func, as it should be :)

@lichtwerk arg! you are right, finalize is not called for last material (not relevant how many mats there are)!!! That I will fix first, then we can put your fix in (new) finalize func, as it should be :)
Done in blender/blender-addons@edc3489136.

This issue was referenced by blender/blender-addons@40340832e3

This issue was referenced by blender/blender-addons@40340832e3992f46034b470aef1af6f7a3a4410f
Member

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#60150
No description provided.