Obj file not loading correctly

I am trying to load in a traffic cone which was made on blender and was exported and an obj file. The traffic cone was loaded into the game, however the material used on the traffic cone was not loaded properly. It looks like this (for some reason):

Screen Shot 2021-05-27 at 12.05.41 PM

The traffic cone is supposed to be orange and white, however, not a rainbow color. Did I do something wrong?

TrafficCone class:

package ds.main;

import com.jme3.asset.AssetManager;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

public class TrafficCone implements Obstacle {
    private Spatial mesh;
    private RigidBodyControl r;
    
    private final Material mat;
    private final Node rootNode;

    private final String file = "Models/Obstacles/TrafficCone.obj";
    private final float MASS = 0.01f;
    private final Vector3f GRAVITY = new Vector3f(0, -250f, 0);
    
    public TrafficCone(AssetManager assetManager, Node rootNode){
        this.rootNode = rootNode;
        mesh = assetManager.loadModel(file);
        mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
        mesh.setMaterial(mat);
        
        CollisionShape c = CollisionShapeFactory.createDynamicMeshShape(mesh);
        r = new RigidBodyControl(c, MASS);
        r.setGravity(GRAVITY);
        mesh.addControl(r);
        
        rootNode.attachChild(mesh);
    } 

    @Override
    public void addToSpace(BulletAppState state){
        state.getPhysicsSpace().add(r);
    }

    @Override
    public void setPosition(Vector3f position) {
        r.setPhysicsLocation(position);
    }

    @Override
    public Vector3f getPosition() {
        return r.getPhysicsLocation();
    }
        
    @Override
    public void destroy(BulletAppState state){
        rootNode.detachChild(mesh);
        state.getPhysicsSpace().remove(r);
        mesh = null;
        r = null;
    }
}

This might be the problem. I’ve had trouble with obj before in regard to texturing. It is probably best to switch to j3o or another supported type.

1 Like

“ShowNormals” is specifically for debugging. For realistic rendering, you probably want a shaded material instead.

2 Likes