[SOLVED] importing textured models from Blender

Hi guys. I need your help. I have a trouble whith my model. Whenever I try to texturing it I get a model with only one color unlike another models, which looks good with same material
My model

...
stair = assetManager.loadModel("Models/stair.j3o");
stair_geo = (Geometry) ( (Node)  ( (Node) ( (Node) stair.getChild(0)).getChild(0)). getChild(0));
Material stair_mat = new Material(assertManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture stairColorTexture = assetManager.loadTexture("Texture/meat/meat1.png");
stair_mat.setTexture("ColorMap", stairColorTexture);
stair_geo.setMaterial(stair_mat);
rootNode.attachChild(stair_geo);
...

I tried to set different textures, tried to use Lighting.j3md
What should I do?

1 Like

(1) Does the mesh of the stair.j3o model include texture coordinates for its vertices?
(2) If it does, are the texture coordinates all identical?

1 Like

I created and exported model from blender whithout texture and uv mapping. I expected that texture lay on mesh like on every other simple shape.
I don`t understand what does it mean “Does the mesh of the stair.j3o model include texture coordinates for its vertices?” .

1 Like

I order for a texture to be visible, the model it’s applied to needs to have texture coordinates. Texture coordinates are stored in buffers referenced by the model’s meshes, with one set of coordinates per mesh vertex. Simple meshes like Quad and Box include texture coordinates.

Since you created the model in Blender, you should add the texture coordinates in Blender and then re-export it.

https://docs.blender.org/manual/en/dev/render/blender_render/textures/properties/mapping.html

You probably want “UV mapped” texture coordinates.

1 Like

If you go to the 20 minute mark in this video, you can also see an example of how to work with and alter a model’s texture coordinates in blender. I at least found this video very helpful a while ago when I didn’t quite understand how a model gets it’s texture coordinates.

2 Likes

I add uv mapping unfortunately it did not work. Blender view

1 Like

thanks, but I use android studio

1 Like

What did not work? Did you get the model to look the way you wanted in Blender? We you able to export it from blender and import into JME? Were you able to load the model in your JME application? Or did you accomplish all these tasks and it didn’t look the way you wanted in your application?

1 Like

I get normal model looks like in blender but when I try to texture model I get only one colored model(for wood texture it colored in broun). It looks as if all vereties of uv mapping locate in one point of texture.
Blender model
j3o model

code:

import com.jme3.app.SimpleApplication;
import com.jme3.asset.plugins.FileLocator;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.input.ChaseCamera;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.material.RenderState;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.LightControl;
import com.jme3.scene.plugins.blender.BlenderLoader;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;
import com.jme3.texture.Texture;
import java.io.File;

public class BallExpertDesktop extends SimpleApplication {

    public static void main(String args[]) {
        BallExpertDesktopView app = new BallExpertDesktopView();
        app.start();
    }


    private BulletAppState bulletAppState;

    Material stone_mat;
    Material stair_mat;
    Geometry ball_geo;
    Geometry stairs_geo;
    Spatial stairs;

    @Override
    public void simpleInitApp() {

        assetManager.registerLocator("/home/denis/AndroidStudioProjects/BollExpert/assets", FileLocator.class);

        
	/*assetManager.registerLoader(BlenderLoader.class, "blend");
        ModelConverter converter = new ModelConverter(assetManager);
        converter.convert(new File("/home/denis/AndroidStudioProjects/BollExpert/assets/Model/hotel_first_flor/stair.blend"),
                new File("/home/denis/AndroidStudioProjects/BollExpert/assets/Model/stairs2.j3o"), true);*/ 

	initMaterials();

        bulletAppState = new BulletAppState();
        stateManager.attach(bulletAppState);
        

        stairs = assetManager.loadModel("Model/stairs2.j3o");

        Material testMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
	Texture stairDiffuseTexture = assetManager.loadTexture("Texture/meat/meat1.png");
        testMat.setTexture("ColorMap", stairDiffuseTexture);
        stairs.setMaterial(testMat);
        
        stairs.setLocalTranslation(0, -12, 0);
        rootNode.attachChild(stairs);

        RigidBodyControl stairsControl = new RigidBodyControl(0.0f);
        stairs.addControl(stairsControl);
        bulletAppState.getPhysicsSpace().add(stairsControl);



        ball_geo = new Geometry("ball", sphere);
        ball_geo.setMaterial(stone_mat);
        rootNode.attachChild(ball_geo);
        ball_geo.setLocalTranslation(0, 0, 0);
        ball_geo.setShadowMode(RenderQueue.ShadowMode.Receive);
        ball_phy = new RigidBodyControl(1f);
        ball_geo.addControl(ball_phy);
        bulletAppState.getPhysicsSpace().add(ball_phy);

        flyCam.setEnabled(false);
        ChaseCamera chaseCam = new ChaseCamera(cam, ball_geo, inputManager);
        chaseCam.setSmoothMotion(true);
        chaseCam.setToggleRotationTrigger(new MouseAxisTrigger(1, false));
        chaseCam.setRotationSpeed(0.5f);
        chaseCam.setMaxDistance(14);
        chaseCam.setMinDistance(8);

        initKey();
        initLight();
    }


    private void initLight() {
        DirectionalLight light = new DirectionalLight(new Vector3f(-1, -3, -1), ColorRGBA.White);
        rootNode.addLight(light);
    }


    private void initKey() {
        ...
    }


    private AnalogListener analogListener = new AnalogListener() {

        @Override
        public void onAnalog(String name, float value, float tpf) {
            ...
        }
    };

    private ActionListener actionListener = new ActionListener() {
        ...
    };

    public void initMaterials() {
        stone_mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        Texture diffuseTexture = assetManager.loadTexture("Texture/ball/ball.jpg");
        Texture normalTexture = assetManager.loadTexture("Texture/ball/ball_normal.jpg");
        diffuseTexture.setWrap(Texture.WrapMode.Repeat);
        normalTexture.setWrap(Texture.WrapMode.Repeat);
        stone_mat.setTexture("DiffuseMap", diffuseTexture);
        stone_mat.setTexture("NormalMap", normalTexture);
        stone_mat.setFloat("Shininess", 32);
        stone_mat.setBoolean("UseMaterialColors", true);
        stone_mat.setColor("Specular", ColorRGBA.Yellow);
        stone_mat.setColor("Diffuse", ColorRGBA.Yellow);


        stair_mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        Texture stairDiffuseTexture = assetManager.loadTexture("Texture/stairs/wood1.jpg");
        Texture stairNormalTexture = assetManager.loadTexture("Texture/stairs/wood1_NRM.jpg");
        Texture stairSpecularTexture = assetManager.loadTexture("Texture/stairs/wood1_SPEC.jpg");
        stairDiffuseTexture.setWrap(Texture.WrapMode.Repeat);
        stairNormalTexture.setWrap(Texture.WrapMode.Repeat);
        stairSpecularTexture.setWrap(Texture.WrapMode.Repeat);
        stair_mat.setTexture("DiffuseMap", stairDiffuseTexture);
        stair_mat.setTexture("NormalMap", stairNormalTexture);
        stair_mat.setTexture("SpecularMap", stairSpecularTexture);
    }

}
2 Likes

I suspect you are converting from a saved .blend to .j3o in a single step (using the IDE, for instance). If so, you might instead try using an intermediate file format. For instance, try exporting from Blender into Ogre XML format, then converting the exported .mesh.xml to a .j3o .

There are at least 2 other intermediate formats you might try (xbuf and glTF), but I believe the Ogre XML importer is the most mature of JME’s model importers.

2 Likes

Thank you very much. it’s solved my proplem. Texture lay on ogreXML model as it should. But I don’t understand what was wrong whith blender model

2 Likes

I suspect there is/was a bug (or at least room for improvement) in JME’s Blender loader, which is what the IDE uses for conversion.

1 Like