Export j3m Material file

beside other things I am currently working on an automated asset importer which automatically converts my blender models (creates tangents, automatically adds particle effects, user properties a.s.o ), textures, … to jme file format.

I also want to create the external material definitions and for obvious reasons I would prefer to have them in the j3m format instead of the binary format using BinaryExporter.

But so far I couldn’t find any implementation for this (store material to j3m file format) apart from the “EditableMaterialFile” implementation within the SDK.

Is there anything in the core that I am missing? I only found the J3MLoader but no corresponding “writer”.

Should I use the implementation in the SDK? Or write my own and contribute it? Or are there any other plans - especially within the context that the SDK is no part of the “core” anymore?


The SDK never was part of the “core”, so you never had it inside your application as a dependency.
However there is no reason not to use this code (as in: copy it into your project).

Other than that I guess there is no Writer since that’s no common use scenario to export Materials.

The only reason against copying it into my project is, that then I would also need to migrate any new features also in “my” j3m writer. Which I try to avoid and which is exactly the reason why i am asking;) Don’t get my wrong - i don’t think that maintaining it myself would be a big problem, but just not my preferred solution…

I thought the common use case would be to also provide a command-line pipeline to import external models (like blender) into the jme project. Because personally I don’t like to do the same manual steps over and over again, whenever importing a new model/scene. But maybe thats only me and not common;) Or I am simply wrong;)

Anyway, thanks for your reply and willingness to help!

What you could do is make your own exporter.
WE have 2 examples of exporter : BinaryExporter and XMLExporter. They are both in com.jme3.plugin.
The binary one is the most commonly used as it’s responsible of saving the scenegraph to j3o.
You could make one that exports Material to J3m.

Yes - this is basically what I meant with “write my own and contribute it”. And using the JmeExporter interface might be the nicest way to do it. But I haven’t verified yet, if this is possible or if there is anything missing.

Ok, so I will do this and post the source afterwards - then anybody can grab it.

1 Like

Tbh I may need this in the future, as I plan to extract the material editor from the SDK. So if you contribute it, it may be integrated to the material editor code.

EDIT : And I will update it along with any material modification

1 Like

Perfect! Sounds like a good deal;) I need to do some payed work first, but I think I will have it ready until Monday…

1 Like

Great Work. I wish I had enough knowledge to contribute in . :grinning:
Thanks @nehon , @tsr

@nehon Could you please have a look at this material file - for me it looks ok and it also shows in the SDK without errors, but I want to be sure before posting the code to you

    Material female_casualsuit02 : Common/MatDefs/Light/Lighting.j3md {

    Transparent Off

    MaterialParameters {
      Diffuse : 1.0 1.0 1.0 1.0
      UseMaterialColors : true
      ParallaxHeight : 0.05
      Ambient : 1.0 1.0 1.0 1.0
      DiffuseMap : Flip Repeat /textures/female_diffuse.png
      Specular : 0.01375 0.01375 0.01375 1.0
      Shininess : 50.0

    AdditionalRenderState {
      PointSprite false
      FaceCull Back
      AlphaTestFalloff 0.0
      DepthWrite true
      ColorWrite true
      PolyOffset 0.0 0.0
      DepthTest true
      Blend Off
      Wireframe false
      AlphaFunc Greater
      DepthFunc LessOrEqual

Btw - I’ve used the JmeExporter interface but this results in a lot of unsupported/not required methods, because the interface is more for a generic exporter and the j3m format is quite specific to materials… Anyway, it works;)

That was Fast !!!
Looks good to me.
Though I have no clue what Transparent Off does…
@Momoko_Fan what do you think ?

EDIT : btw I think there has been some enhancements to the way Flip and Repeat worked. @DannyJo did the change, maybe if we have a serializer it should output the new way .

Yeah indeed. See the source file for supported texture options: jmonkeyengine/J3MLoader.java at master · jMonkeyEngine/jmonkeyengine · GitHub

I should probably take some time to write these out on a wiki page some where. All in all Flip is still supported as is but Repeat should ideally use the prefix Wrap.

Some example valid combinations are:

DiffuseMap : Flip Repeat "/textures/female_diffuse.png"

DiffuseMap : Flip WrapRepeat "/textures/female_diffuse.png"

DiffuseMap : Flip MinBilinearNoMipMaps MagBilinear WrapRepeat "/textures/female_diffuse.png"

The texture wrap mode also supports applying a specific axis.

DiffuseMap : WrapRepeat_S "/textures/female_diffuse.png"

DiffuseMap : WrapRepeat_T "/textures/female_diffuse.png"

DiffuseMap : WrapRepeat_R "/textures/female_diffuse.png"

Also take note that we now support using quotes for paths, ideally these should be used, especially if the path contains spaces.

1 Like

A few things. First you don’t need to write entries which are already the default, like Blend Off.
Second, there’s no true or false in J3M, instead, On and Off should be used.

First of all, thanks for all these useful replies!

Here my comments/questions:

  • Definition for Transparent can be found at the bottom of the wiki

  • About the texture wrap mode: This is not formatted by my implementation, I just use MatParam getValueAsString() and this method formats it that way. See: jmonkeyengine/MatParam.java at master · jMonkeyEngine/jmonkeyengine · GitHub
    I mean, I could change it - but shouldn’t this be done in the MatParam class?

  • The same applies to using quotes for a path - its also in the MatParam class

  • For the “AdditionalRenderState” it now suppresses values that are equal to the default value

  • For the MaterialParameters thats not really possible, because the write implementation from the Material class uses “writeStringSavableMap” and supplies no default values (NULL is used for the default Map). See: jmonkeyengine/Material.java at master · jMonkeyEngine/jmonkeyengine · GitHub

  • According to the wiki, J3M supports true/false. See the “Data Types” section
    Boolean (basic Java type) true or false
    Anyway, I’ve changed true/false to On/Off in the AdditionalRenderState section. Should I also do it in the MaterialParameters? I am asking because all the examples in the wiki use “UseMaterialColors : true” instead of “UseMaterialColors : On”

Edit: Btw - the “true” from “UserMaterialColors” also comes from the MatParam class

Now my example J3M looks like this:

Material female_casualsuit02 : Common/MatDefs/Light/Lighting.j3md {

        MaterialParameters {
          Diffuse : 1.0 1.0 1.0 1.0
          UseMaterialColors : true
          ParallaxHeight : 0.05
          Ambient : 1.0 1.0 1.0 1.0
          DiffuseMap : Flip Repeat /textures/female_casualsuit02_diffuse.png
          Specular : 0.01375 0.01375 0.01375 1.0
          Shininess : 50.0
        AdditionalRenderState {

Its a lot smaller because of all the suppressed default values.

1 Like

Looks like getValueAsString() needs to be fixed to take into account the changes to texture modes / quotes. The On / Off thing I meant only for RenderState, material parameters which are boolean use true and false like you mentioned.

Ok, the On/Off stuff is already like you described - so I am kind of finished for now;)

@nehon: You can find the source @ JMEUtils/AssetsImport/src/main/java/at/illumine/srb/utils at master · rainmantsr/JMEUtils · GitHub

Btw - this project is a simple little command line asset importer

Thanks it will come in handy.

I updated the MatParam getAsString method so that the texture param are formated with the new format.
@tsr could you test?

I guess you “only” changed it in the repo? I am using the binaries from jcenter. So I would need to download the latest engine source, build it and change the dependencies in my project, i guess… Is there any other way, like nightly binaries from jcenter or something like this?

oh ok I thought you were running against master. Nevermind.

The more I think about it , the more I think this getAsString code should be in the exporter. IMO it’s the responsibility of the exporter to properly format data to to the proper output format.
It’s a bit as if we had a getAsXml or a getAsJson to export to xml and json…

Ok, then I will check your MatParam implementation and make the corresponding “mapping” implementation directly in the Exporter. I will let you know when its finished (probably tomorrow).