"The specified MatParam cannot be represented in J3M"

Just got the subject message while experimenting with shaders taken from various places. I had to go into the SDK sources to really understand what it means, but I stil can’t find what triggers it. The params section in my material file is:

Vector3 Resolution
Float Time		
Vector4 Mouse
Texture2D Channel0
Texture2D Channel1
Texture2D Channel2
Texture2D Channel3
FloatArray ChannelTime
Vector3Array ChannelResolution
Vector4 Date

And by looking at the source, I found that probably the FloatArray and Vector3Array could be the cause and I removed them. This did not help.

What else could that be?

PS: Please make the error message more specific, or, better, reject such a material on the parsing phase?

UPDATE Looked closer at it, and it seems that it gives this error for a texture that could be programmatically generated and has no TextureKey within it (which is exactly my case). Neither the message, nor the reason are valid in this case… Does this look like a bug?

mhhh could you wrap up a test case?

Well if I get you right the message IS valid in that case. If a texture has no AssetPath (i.e. no TextureKey) then it can not be represented in a j3m.

This is btw bad for all parts of the asset system. Without a path there can be no caching, no sharing, no nothing.

Oh, @normen, I got you. This is to do with the serialization of an asset into a file. Yes, you are right.

However, I want to add that at that point, when we have the actual Texture, with data and all, the key is secondary and could probably be generated while the Texture (the image) being serialized according to its pixel data, most likely being saved in a file with an auto-generated name. This probably won’t be in JME because it’s kinda not a very game-oriented feature and requires an additional asset management facility.

Okay… but I got the original error message on Material.getParams() so that I can’t iterate over the params, which is not really okay even under the circumstances! So, here’s the test case I’ve just factored:

package jme.testcases.matparam;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.nio.ByteBuffer;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.texture.Image;
import com.jme3.texture.Texture2D;
import com.jme3.util.BufferUtils;

import jme3tools.converters.ImageToAwt;

/**
 * This is a testcase for
 * https://hub.jmonkeyengine.org/t/the-specified-matparam-cannot-be-represented-in-j3m
 * @author noncom
 *
 */

public class MatParamTestCase extends SimpleApplication {

	int imgWidth = 256;
	int imgHeihgt = 256;
	
    public static void main(String[] args){
    	MatParamTestCase app = new MatParamTestCase();
        app.start(); // start the game
    }

    public Texture2D createTextureWithGeneratedImage() {
    	// -- programmatically create an image and draw something
    	BufferedImage bi = new BufferedImage(imgWidth, imgHeihgt, BufferedImage.TYPE_INT_ARGB);
    	Graphics g = bi.getGraphics();
    	g.setColor(Color.GREEN);
    	g.fillRect(100, 100, 56, 56);
    	g.drawString("PLEASE ADD FLIP-Y AND FLIP-X", 20, 20);
    	g.drawString("TO THE CONVERT METHOD", 20, 40);
    	int nColorComponents = 4;
    	ByteBuffer bb = BufferUtils.createByteBuffer(imgWidth * imgHeihgt * nColorComponents);
    	ImageToAwt.convert(bi, Image.Format.RGBA8, bb);
    	
    	// -- create JME Image and Texture
    	Image programmaticallyGeneratedImage = new Image(Image.Format.RGBA8, imgWidth, imgHeihgt, bb);
    	//programmaticallyGeneratedImage.setData(bb);
        Texture2D tex = new Texture2D(programmaticallyGeneratedImage);
        tex.setImage(programmaticallyGeneratedImage);
        return tex;
    }
    
    @Override
    public void simpleInitApp() {
        Box b = new Box(1, 1, 1);
        Geometry geom = new Geometry("Box", b);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setTexture("ColorMap", createTextureWithGeneratedImage());
        geom.setMaterial(mat);
        System.out.println("This crashes the program: " + mat.getParams());
        rootNode.attachChild(geom);
    }
}
1 Like

Guys, any opinion on this one? Still bugging me…

Crashes as in “blue screens the operating system” or crashes as in “program just exits”… or crashes as in “there was an exception that I didn’t provide”?

If you want, you can look in the SimArboreal Editor to see how I write a j3o with generated imposters included:

1 Like

mat.getParams()

This uses assetKeys for images. When you create an Image (instead of loading one) you get no texture key for the image.

Under this line (in the test case)

Texture2D tex = new Texture2D(programmaticallyGeneratedImage);

Adding

TextureKey key = new TextureKey("jesteristhebest");
tex.setKey(key);

Stops the error, and you will get ColorMap: jesteristhebest as the parameter, which is the recommended parameter and could increase performance

edit: Oh I just saw you already got the keys bit, I just jumped into the testcase without reading anything :slight_smile:

1 Like