Author Topic: Corona Physical to Autodesk Physical Material Converter  (Read 14694 times)

2023-07-15, 09:06:15

James Vella

  • Active Users
  • **
  • Posts: 640
    • View Profile
By user request I am releasing this script for free. Script attached to this post.

Notes:
- You can copy/paste, change, learn from it or do whatever to suit your own workflow if you know maxscript.
- Works on scene materials (any object with a Corona Physical Material applied). Not on selected objects so be aware this will convert everything in that scene.
- Currently works with Standard Bitmap, not CoronaBitmap. For example will keep the bitmap as CoronaBitmap instead of converting it to Standard, will update in next verison.
- Be aware this is version 01 so there is probably issues to iron out, your feedback is required to make this better. FYI I don't plan on developing this long term, maybe or maybe not, no promises but for the time being happy to work on it in my spare time.


Install:
- Drag the script into your 3dsmax viewport.
- Customize > Customize User Interface > Toolbars > Category: Vella > Automate CoronaToPhysical

Version 1.0 Features:
- Base Color
- Roughness or Glossiness
- Anisotropy Amount / Rotation
- IOR
- Metal
- Refraction (could be incorrect, still trying to work out how this works in Autodesk Physical)
- Thin Shell
- Opacity
- Emission / Self-Illumination
- Normal / Bump (numeric values kept default 0.3, let me know if this is an issue)
- Displacement
- Clearcoat Amount / Roughness / Bump
- Numerical values such as Base Color Amount, Roughness Amount, IOR value etc.
- Color swatches such as Base Color, Self-Illumination etc.

Exporting to FBX:
- FYI, export does not support the use of the 'Additional Bump' parameter. I have kept it for now since it will work directly in 3dsmax but could create an issue for exporting to FBX. Your feedback is required as I don't know the real-world implications.
- Currently all nodes are kept during the conversion so this also poses a problem for exporting to FBX. For example if you have your Base Color in a Falloff node then the Falloff is kept on conversion. Again real-world examples can help. I might even put a pop up if you prefer such as "Are you exporting to FBX Yes/No?". This way you can either keep all the nodes or just keep the bitmaps.

Corona Physical Material:
corona" border="0

Autodesk Physical Material:
phys" border="0
« Last Edit: 2023-07-15, 10:02:59 by James Vella »

2023-07-15, 10:57:45
Reply #1

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 9066
  • Let's move this topic, shall we?
    • View Profile
    • My Models
Hi James, thank you for the effort! I would love to try your script, since converting from Corona to Autodesk physical material is what i do quite often, but the problem is, that i almost completely adopted Corona bitmap by now and it looks that your script is not supporting it. If at any point you will bring support for Corona bitmap, i will be first in line to test the script and provide you with the feedback. And again, thank you for doing what, honestly speaking, should have been done by Corona team long time ago.
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2023-07-15, 12:18:38
Reply #2

James Vella

  • Active Users
  • **
  • Posts: 640
    • View Profile

2023-07-15, 13:30:04
Reply #3

James Vella

  • Active Users
  • **
  • Posts: 640
    • View Profile
Script attached to this post.

Hmm it works but not in the way I wanted it to. I wanted it to be recursive, ill work it out later but for now you can use the updated version which will do the job (Corona Bitmap to Bitmap).

Notes:
- Just a test for now since it should copy all the bitmap settings as well like coordinate offsets, real-world, blur etc. That will be the next small update.

Version 1.1 Features:
- Corona Bitmap to Standard Bitmap conversion

Corona Physical Material:
cb-corona" border="0

Autodesk Physical Material:
cb-phys" border="0
« Last Edit: 2023-07-15, 13:51:48 by James Vella »

2023-07-15, 14:45:27
Reply #4

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 9066
  • Let's move this topic, shall we?
    • View Profile
    • My Models
Nice!! I will let you know how it worked, once i have time to test it. Thank you very much! :]
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2023-07-16, 19:53:05
Reply #5

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 9066
  • Let's move this topic, shall we?
    • View Profile
    • My Models
Tried both scripts briefly and i love them! I found few small issues with CP->AP script.

1 - anisotropy mapping is completely wrong. Judging from the visual preview the tool sets anisotropy to some off the charts value that's not even possible to set with the spinner. And that happens even if Corona material has zero anisotropy.
2 - bump strength gets ignored, it always converted to Autodesk's stupid default 0,3 which is really annoying. On the other hand i love when that happens with your other script, because in that case script inadvertently fixes stupid incoming bump to Corona's proper default, which is not good when you're working with old fashioned bump maps and arbitrary strength values, but great when you're dealing with normal maps.
3 - cosmetic issue - when Corona physical is populated with Corona bitmaps, the script replaces them with standard bitmaps and strips paths from the Corona bitmaps, which leaves empty CB husks. Maybe it would be possible to handle this somehow more elegant if not too much work for you?

Overall i really like those two little tools a lot - saves quite some manual work!
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2023-07-16, 22:03:48
Reply #6

James Vella

  • Active Users
  • **
  • Posts: 640
    • View Profile
Tried both scripts briefly and i love them! I found few small issues with CP->AP script.

1 - anisotropy mapping is completely wrong. Judging from the visual preview the tool sets anisotropy to some off the charts value that's not even possible to set with the spinner. And that happens even if Corona material has zero anisotropy.
2 - bump strength gets ignored, it always converted to Autodesk's stupid default 0,3 which is really annoying. On the other hand i love when that happens with your other script, because in that case script inadvertently fixes stupid incoming bump to Corona's proper default, which is not good when you're working with old fashioned bump maps and arbitrary strength values, but great when you're dealing with normal maps.
3 - cosmetic issue - when Corona physical is populated with Corona bitmaps, the script replaces them with standard bitmaps and strips paths from the Corona bitmaps, which leaves empty CB husks. Maybe it would be possible to handle this somehow more elegant if not too much work for you?

Overall i really like those two little tools a lot - saves quite some manual work!

Sure thing.

1. Yeah the anisotropy is very different between the 2 engines. I had a feeling there was more work to do on this. Actually I made a typo so actually broken so ill update this soon and try it out and let me know your findings. This is with the typo fixed, weirdly the values show the same but the material ball looks correct, take a look at the bottom of this post. Its almost like the material editor doesnt update the values correctly but should be working... I might be missing something.

2. Can you show me what you prefer to happen with the bump map with some screenshots?

3. What do you mean empty CB husks? Can you show some screenshots?

Anisotropy:
anis-0" border="0

anis-1" border="0

anis-2" border="0

anis-3" border="0


Maybe also put your feedback for the Corona Physical to Autodesk Physical in that thread to keep it separate from this script for less confusion. - Conversation moved back to this thread, ignore this comment.
« Last Edit: 2023-07-17, 10:55:11 by James Vella »

2023-07-17, 07:57:48
Reply #7

James Vella

  • Active Users
  • **
  • Posts: 640
    • View Profile
Ok give it a try, let me know your findings. Script attached to this post.

Version 1.2 Features:
- Bump & Normal map numeric values copied from Corona.
- Bitmap gamma from Corona and Corona Bitmap.
- All bitmap settings copied from Corona Bitmap (excluding the Output Curves).
- Anisotropy fix (hopefully, might need further testing as I have my doubts).
« Last Edit: 2023-07-17, 08:05:33 by James Vella »

2023-07-17, 11:05:52
Reply #8

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 9066
  • Let's move this topic, shall we?
    • View Profile
    • My Models
I tried 1.2 and i see some issues has been fixed. Thank you!

#1 anisotropy [partially fixed] - zero anisotropy is now converting to 0 in Autodesk physical as well, all other settings are still wrong. I think that might be because i'm using Max 2024 and it seems you're still on the older version. It seems that Autodesk has changed something in the Physical material code, because i see in your screenshots that anisotropy has 0 to 100 (or -100 to 100) range, but in Max 2024 it has -1 to 1 range. Either way, i'm quite happy with this result so far, because i rarely use anisotropy, especially in materials that i need to "downgrade" to ADSK physical.

#2 - bump strength is now handled correctly, but the script no longer converts Corona normal node to Max normal node - i think it did so in previous version. Could you look into that please?

#3 - it looks that the issue with the stripped Corona bitmap paths is gone. Script works correctly here.

One additional issue - i noticed that if Corona bitmap is not plugged directly to material, but through some other Max node, like mix, composite, etc., then script does not convert those Corona bitmaps to regular bitmaps and leaves them like they are. It would be great if this can be fixed.
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2023-07-17, 11:18:11
Reply #9

James Vella

  • Active Users
  • **
  • Posts: 640
    • View Profile
I tried 1.2 and i see some issues has been fixed. Thank you!

#1 anisotropy [partially fixed] - zero anisotropy is now converting to 0 in Autodesk physical as well, all other settings are still wrong. I think that might be because i'm using Max 2024 and it seems you're still on the older version. It seems that Autodesk has changed something in the Physical material code, because i see in your screenshots that anisotropy has 0 to 100 (or -100 to 100) range, but in Max 2024 it has -1 to 1 range. Either way, i'm quite happy with this result so far, because i rarely use anisotropy, especially in materials that i need to "downgrade" to ADSK physical.

Ah yes that would be much better actually with a -1 to 1 range. Unfortunately Im not using 3dsmax 2024 yet but might look into it soon. Dont hold your breath on this one.

#2 - bump strength is now handled correctly, but the script no longer converts Corona normal node to Max normal node - i think it did so in previous version. Could you look into that please?

Ah crap I broke it, thanks ill address this in the next update.

#3 - it looks that the issue with the stripped Corona bitmap paths is gone. Script works correctly here.

Great!

One additional issue - i noticed that if Corona bitmap is not plugged directly to material, but through some other Max node, like mix, composite, etc., then script does not convert those Corona bitmaps to regular bitmaps and leaves them like they are. It would be great if this can be fixed.

Ah yes you are correct, I can take a look at this for the next update. It wasn't working previously (it does work with standard bitmaps, not corona bitmaps). Thanks for spotting this. Also on this you want to keep those mix / composite nodes right? Hmm composite node should be fun lol.

2023-07-17, 12:18:56
Reply #10

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 9066
  • Let's move this topic, shall we?
    • View Profile
    • My Models
One additional issue - i noticed that if Corona bitmap is not plugged directly to material, but through some other Max node, like mix, composite, etc., then script does not convert those Corona bitmaps to regular bitmaps and leaves them like they are. It would be great if this can be fixed.

Ah yes you are correct, I can take a look at this for the next update. It wasn't working previously (it does work with standard bitmaps, not corona bitmaps). Thanks for spotting this. Also on this you want to keep those mix / composite nodes right? Hmm composite node should be fun lol.

I think something like 95% of my converted materials are very simple, consisting of single bitmap node plugged into material slot, so personally for me it's not very relevant. I just accidentally noticed this issue and decided to report in case it's not too complicated to fix. If it's too much hassle to keep existing node structure, i would be content if the script would simply convert Corona bitmaps to bitmaps and plug those bitmaps directly to material (first bitmap in line would be fine, i guess), just please do not delete old composite, mix, or whatever nodes, so user could have reference how to rebuild the old node structure. That's my point of view on this. Other users might have other opinions, but since nobody else seems to care to give you the feedback... ;]
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2023-07-17, 14:34:42
Reply #11

James Vella

  • Active Users
  • **
  • Posts: 640
    • View Profile
Hah yeah I also just use simple setups, but it would be nice for it to keep those nodes. Hopefully when I get my head around it ill post an update on that but... there is a workaround for now since its far more complicated than I expected.

Before you use the script use the Corona Converter to convert CoronaBitmap to Bitmap. This will keep all nodes in-tact mix/falloff etc and also makes sure all Bitmaps work correctly. This also means all your Output Curves and specific Bitmap settings all carry over correctly too:
cbitmap" border="0

Script attached to this post.

Version 1.3 Features:
- Fixed Normal node for Physical material with Normal/Bump textures

Edit:
Also if any devs would like to chime in as to why its so hard to recursively look for CoronaBitmaps that would be very useful insight. For example when recurvisely looking for standard bitmaps it works fine, when I try the same method with CoronaBitmaps I keep hitting walls.
All good, think I worked it out. Think it has to do with classinstances, probably easier to use that than what Im currently doing.
« Last Edit: 2023-07-17, 16:02:54 by James Vella »

2023-07-17, 16:02:32
Reply #12

James Vella

  • Active Users
  • **
  • Posts: 640
    • View Profile
Ok fixed the CoronaBitmap conversion issue scene wide, turns out I was just overcomplicating it - noob mistake.Script attached to this post.

Version 1.4 Features:
- Converts CoronaBitmap to Standard Bitmap scene wide
- Keeps all nodes in the hierarchy eg. Diffuse > Falloff > Basecolor.png or Composite nodes etc. Doesnt really matter how deep the hierarchy goes it just searches for the Bitmaps/CoronaBitmaps.

Notes:
The official Corona converter which converts CoronaBitmap to Bitmap is far more fleshed out than this. It also handles Curves in the Output which mine doesn't. Ill get to this one day if its a user request. For now more interested in finding bugs in the current code or implementing other features that are necessary (user feedback).
« Last Edit: 2023-07-17, 16:45:10 by James Vella »

2023-07-17, 16:45:01
Reply #13

Frood

  • Active Users
  • **
  • Posts: 1972
    • View Profile
    • Rakete GmbH
Hi,

Thanks for your work, just a note because I quickly looked at the script. As you have discovered, using the getClassInstances way is the best to go. I'd not just walk through the materials and convert if CoronaPhysicalMtl or Multisub classes are found ("for i in sceneMaterials do"), but just like this instead:

Code: [Select]
for i in getClassInstances CoronaPhysicalMtl do
(
p = convertToPhysicalMtl i
replaceInstances i p
)

This way you get all CoronaPhysicalMtls, even those plugged into a Blend material for example. And you do not have to care about supporting all classes able to handle multiple material inputs. Same of course when it comes to CoronaBitmap conversion. For the latter, you may examine Martin Geupels original Corona converter script. Search for function "convertCoronaBitmapToBitmap" and "convertFrom_CoronaBitmap". Not sure when looking at the license info in the header if you would be allowed to just copy convertFrom_CoronaBitmap().

And: please check "animate off" context :) You could wrap the entire script into one to make it easy :)


Good Luck



Never underestimate the power of a well placed level one spell.

2023-07-17, 16:47:41
Reply #14

James Vella

  • Active Users
  • **
  • Posts: 640
    • View Profile
Thanks Frood! Ill take a look at this when I'm fresh tomorrow.

Very good point about Blend materials, I didnt even consider that!

Yes I did see some script references with animate off, I was wondering if it makes much of a difference. Is that for the user in case they have it switched on?