Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Petition to add VRayMtl support to 3D Max exporter #893

Closed
rogercodina opened this issue Dec 12, 2011 · 9 comments
Closed

Petition to add VRayMtl support to 3D Max exporter #893

rogercodina opened this issue Dec 12, 2011 · 9 comments
Labels

Comments

@rogercodina
Copy link

After some checkings, I found out that my export problems described here in issue 823 (#823) are finally related to VRay library usage on my models.

So I would like to ask Three.js developers if they have planned to add support for VRay materials?

In the other hand, does anyone know if I can modify models in 3DS Max to use normal materials instead of VRay one's?

I guess that this would change the function ExportMaterials in ThreeJSExporter.ms like this:

if classof mat != VRayMtl then
(
    DumpColor mat.diffuse  "colorDiffuse"
    DumpColor mat.ambient  "colorAmbient"
    DumpColor mat.specular "colorSpecular"

        //etc
) 
else
(
    DumpColor mat.diffuse  "colorDiffuse"
        //ambient and specular are not in mat object on VRayMtl

       //etc
)

VRayMtl properties: http://www.cgplusplus.com/online-reference/vray-properties/source/vraymtl-properties.html
Another interisting link: http://www.jamesshaw.co.nz/blog/?p=137

Thx!

@alteredq
Copy link
Contributor

I don't have anymore access to 3ds max. If anybody else wants to step in and maintain the exporter, feel free to do so.

If you don't need vertex colors, anyways it's better to export OBJ from max and then use OBJ converter.

@rogercodina
Copy link
Author

I don't have anymore access to 3ds max. If anybody else wants to step in and maintain the exporter, feel free to do so.

I think I dont have enough knowledge to do this task. I'm just doing my first 3D project but maybe I can ask someone to help me. I guess you first developed the ThreeJSExporter.ms So could you please suggest me some web pages to get started in max script programming? (and/or other pages that helped you)

If you don't need vertex colors, anyways it's better to export OBJ from max and then use OBJ converter

Well, for my project, I have some texturized models in 3DS Max that use V-Ray. When I export to OBJ I lose the textures and materials once I open the file with Blender. But thanks to this link...

http://forums.sketchucation.com/viewtopic.php?f=18&t=31702

...I tryed passing models from Max to Blender with 3ds format and seems to mantain materials but not the textures. Afortunately, the problem here is just the texture names limitation to 8 chars (I have to ask my friend to do this cause I'm so noob in 3DS Max and blender) However, I don't like this method due to 3ds format limitations.

In theory, when you load an obj file in blender it loads automatically the mtl file, doesn't it?

By the way, with "OBJ converter" you mean "OBJ importer" in Blender?

Thank you so much!

@alteredq
Copy link
Contributor

So could you please suggest me some web pages to get started in max script programming? (and/or other pages that helped you)

I just learned enough max script to create exporter, I didn't use it before or after.

I found official help files better than anything on the web (you know these CHM files on Windows that have whole hypertext document embedded into single file, 3ds max has some where they describe max script).

By the way, with "OBJ converter" you mean "OBJ importer" in Blender?

Nope. I meant first use 3ds max built-in OBJ exporter (which is pretty good) and then use Python script convert_obj_three.py which is included with three.js

https://github.com/mrdoob/three.js/blob/master/utils/exporters/convert_obj_three.py

BTW if you have troubles with textures, you may need to hack MTL files manually, sometimes paths get mangled up somewhere in the pipeline (best is to keep it simple, texture files without any path in the same folder as model).

@rogercodina
Copy link
Author

I have tried script convert_obj_three.py as you recommended but I have problems because in mtl file exported from Max textures are missing. And after some googling I found out that this is due to V-Ray or non standart materials usage. So maybe I will have to forget about this V-Ray plugin and use normal materials instead.

By the way, somewhere has to be mentioned that to run this script (and maybe all other Three.js Python scripts) you need Python 2.X branch because Python 3.X branch gives error for this script.

Thank you so much!

@rogercodina
Copy link
Author

Well, I have just discovered that there was another source for my export problems (apart from V-Ray plugin usage): textures were not UV mapped ( I don't know how my friend applied them)

To demonstrate this I have used a simple UV maped cube that I did in Blender by viewing a YouTube tutorial. So I...

  1. Opened my blend file
  2. Exported it to OBJ.
  3. Edited the mtl file and I found the jpg file reference there
  4. Imported the OBJ from 3D Max
  5. Exported again to OBJ from 3D Max
  6. Edited the mtl file and I found the jpg file reference again
  7. Then I used convert_obj_three.py script to export to Three.js
  8. Render successfully on Three.js engine

Of course, my initial blender model was exported to Three.js with Blender exporter a lot of days ago. And I also rendered it successfully.

Hope this helps somebody else!

@rogercodina
Copy link
Author

Today I have discovered that if you have face material texturing in 3DS Max like me and then you export to OBJ, the generated MTL files misses the texture file. But If you manually edit the MTL to add the texture line it will work:

Before

newmtl wire_096160231
    Ns 32
    d 1
    Tr 0
    Tf 1 1 1
    illum 2
    Ka 0.0000 0.0000 0.0000
    Kd 0.3765 0.6275 0.4059
    Ks 0.3500 0.3500 0.3500

After

newmtl wire_096160231
    Ns 32
    d 1
    Tr 0
    Tf 1 1 1
    illum 2
    Ka 0.0000 0.0000 0.0000
    Kd 0.3765 0.6275 0.4059
    Ks 0.3500 0.3500 0.3500
    map_Kd YOUR_TEXTURE.jpg

Don't forget to use convert_obj_three.py script ;)

@nym
Copy link

nym commented Dec 28, 2012

@Romanopoly
Copy link

Hello,

I've tried it with convert_obj_three.py, but in the end my CubeTest.js just looks like this:

{

    "metadata" :
    {
        "formatVersion" : 3.1,
        "sourceFile"    : "CubeTest.obj",
        "generatedBy"   : "OBJConverter",
        "vertices"      : 8,
        "faces"         : 6,
        "normals"       : 15,
        "colors"        : 0,
        "uvs"           : 4,
        "materials"     : 1
    },

    "scale" : 1000.000000,

    "materials": [  {
    "DbgColor" : 15658734,
    "DbgIndex" : 0,
    "DbgName" : "wire_229166215",
    "colorAmbient" : [0.898039, 0.65098, 0.843137],
    "colorDiffuse" : [0.898039, 0.65098, 0.843137],
    "colorSpecular" : [0.35, 0.35, 0.35],
    "illumination" : 2,
    "specularCoef" : 32.0,
    "transparency" : 0.0
    }],

    "vertices": [-1865,-2815,0,-1865,3004,0,2985,3004,0,2985,-2815,0,-502,-8036,2306,2985,-2815,4594,2985,3004,4594,-1865,3004,4594],

    "morphTargets": [],

    "morphColors": [],

    "normals": [0,0,-1,-0.24516,-0.12184,0.9618,-0.54844,0,0.83619,-0.12537,-0.16317,0.9786,0,-0.2029,0.9792,0.52986,-0.63735,-0.5595,0,-1,0,0.47567,-0.72212,-0.50228,0.68086,-0.13984,-0.71894,1,0,0,0,1,0,-0.99135,-0.10632,0.076915,-0.8609,0,0.50878,-0.97784,-0.080329,0.19334,-0.99247,-0.12252,0],

    "colors": [],

    "uvs": [[1,0,1,1,0,1,0,0]],

    "faces": [43,0,1,2,3,0,0,1,2,3,0,0,0,0,43,4,5,6,7,0,3,0,1,2,1,2,3,4,43,0,3,5,4,0,3,0,1,2,5,6,7,8,43,3,2,6,5,0,3,0,1,2,9,9,9,9,43,2,1,7,6,0,3,0,1,2,10,10,10,10,43,1,0,4,7,0,3,0,1,2,11,12,13,14]

}

But this doesn't work. I used Python 2.7. What is wrong here?

Best Regards

Roman

@elyas-bhy
Copy link

For future reference:
Thanks to the OP's example and links, I managed to make the script work with VRayMtl and successfully export my textures as follows:

function ExportMaterials zmaterials zcolors =
    (
            // ...
            if classof mat != BooleanClass then
            (

                useVertexColors = zcolors[i]

                Format "\"DbgName\"  : \"%\",\n" mat.name to:ostream

                if classof mat != VRayMtl then
                (
                    DumpColor mat.diffuse  "colorDiffuse"
                    DumpColor mat.ambient  "colorAmbient"
                    DumpColor mat.specular "colorSpecular"

                    // etc...
                )
                else
                (
                    DumpColor mat.diffuse "colorDiffuse"

                    // this is needed to get texture mapping
                    DumpMap mat.texmap_diffuse "mapDiffuse"
                )
         // ...
    )

Tested and works for me.
PS: if you are going to copy/paste this code, remember that comments in MaxScript are like so: -- comment, so get rid of the double-slashes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants