I try to load a 3D model exported by 3dsmax using JME3. This model contains a .obj and a .mtl file.
I found that i only can load the .obj file. I didn’t find the API to load a .mtl file.
Can JME3 load a .mtl file? If not, how to handle this problem?
This code also load mtl file automaticity.
[java]
assetManager.loadModel(“path/to/model.obj”);
[/java]
You check these links !
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_asset
http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core-plugins/com/jme3/scene/plugins/OBJLoader.java#320
soh said:
This code also load mtl file automaticity.
[java]
assetManager.loadModel("path/to/model.obj");
[/java]
You check these links !
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_asset
http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core-plugins/com/jme3/scene/plugins/OBJLoader.java#320
It can not load the .mtl file automatically.
If i don't set a material(such as "ShowNormals") to the model, it can't be appeared.
But i only want to use my .mtl as material of this model.
How to do?
Maybe you need to add a light?
Momoko_Fan said:
Maybe you need to add a light?
I try that but the problem also exist.
[java]
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
rootNode.addLight(sun);
[/java]
Here are all my code.
[java]
Spatial shafa = assetManager.loadModel(“Models/shafa/shafa.obj”);
shafa.setLocalScale(0.1f);
Material mat_default = new Material(assetManager,
“Common/MatDefs/Misc/ShowNormals.j3md”);
shafa.setMaterial(mat_default);
rootNode.attachChild(shafa);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
rootNode.addLight(sun);
[/java]
If i comment out the code:
[java]
Material mat_default = new Material(assetManager,
“Common/MatDefs/Misc/ShowNormals.j3md”);
shafa.setMaterial(mat_default);
[/java]
It can not be appeared. Uncomment them, it’s ok. But the material is “ShowNormals”, not my expected.
And here are all the logs when comment out the “ShowNormals” material setting:
2011-6-20 13:17:06 com.jme3.system.JmeSystem initialize
信息: Running on jMonkey Engine 3 Alpha 0.6
2011-6-20 13:17:06 com.jme3.system.Natives extractNativeLibs
信息: Extraction Directory #1: file:/D:/document/study/3D/jME/jME3_2011-05-19/
2011-6-20 13:17:06 com.jme3.system.Natives extractNativeLibs
信息: Extraction Directory #2: D:workspaceISDKjME
2011-6-20 13:17:06 com.jme3.system.Natives extractNativeLibs
信息: Extraction Directory #3: D:workspaceISDKjME
2011-6-20 13:17:06 com.jme3.system.Natives extractNativeLib
警告: Cannot locate native library: windows/bulletjme.dll
2011-6-20 13:17:07 com.jme3.system.lwjgl.LwjglAbstractDisplay run
信息: Using LWJGL 2.7.1
2011-6-20 13:17:07 com.jme3.system.lwjgl.LwjglDisplay createContext
信息: Selected display mode: 640 x 480 x 0 @0Hz
2011-6-20 13:17:07 com.jme3.system.lwjgl.LwjglContext printContextInitInfo
信息: Adapter: smsmdd
2011-6-20 13:17:07 com.jme3.system.lwjgl.LwjglContext printContextInitInfo
信息: Driver Version: 4.0.6163.1000
2011-6-20 13:17:07 com.jme3.system.lwjgl.LwjglContext printContextInitInfo
信息: Vendor: NVIDIA Corporation
2011-6-20 13:17:07 com.jme3.system.lwjgl.LwjglContext printContextInitInfo
信息: OpenGL Version: 3.1 NVIDIA 189.21
2011-6-20 13:17:07 com.jme3.system.lwjgl.LwjglContext printContextInitInfo
信息: Renderer: Quadro NVS 160M/PCI/SSE2
2011-6-20 13:17:07 com.jme3.system.lwjgl.LwjglContext printContextInitInfo
信息: GLSL Ver: 1.30 NVIDIA via Cg compiler
2011-6-20 13:17:07 com.jme3.system.lwjgl.LwjglTimer
信息: Timer resolution: 1,000 ticks per second
2011-6-20 13:17:07 com.jme3.renderer.lwjgl.LwjglRenderer initialize
信息: Caps: [FrameBuffer, FrameBufferMRT, FrameBufferMultisample, OpenGL20, OpenGL21, OpenGL30, OpenGL31, ARBprogram, GLSL100, GLSL110, GLSL120, GLSL130, VertexTextureFetch, TextureArray, TextureBuffer, FloatTexture, FloatColorBuffer, FloatDepthBuffer, PackedFloatTexture, SharedExponentTexture, PackedFloatColorBuffer, TextureCompressionLATC, NonPowerOfTwoTextures, MeshInstancing, VertexBufferArray]
2011-6-20 13:17:07 com.jme3.asset.DesktopAssetManager
信息: DesktopAssetManager created.
2011-6-20 13:17:07 com.jme3.renderer.Camera
信息: Camera created (W: 640, H: 480)
2011-6-20 13:17:07 com.jme3.renderer.Camera
信息: Camera created (W: 640, H: 480)
2011-6-20 13:17:07 com.jme3.input.lwjgl.LwjglMouseInput initialize
信息: Mouse created.
2011-6-20 13:17:07 com.jme3.input.lwjgl.LwjglKeyInput initialize
信息: Keyboard created.
2011-6-20 13:17:07 com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
信息: AudioRenderer supports 64 channels
2011-6-20 13:17:07 com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
信息: Audio effect extension version: 1.0
2011-6-20 13:17:07 com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
信息: Audio max auxilary sends: 1
2011-6-20 13:17:07 com.jme3.material.MaterialDef
信息: Loaded material definition: Unshaded
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (null)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (null) attached to this node (Gui Node)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (null)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (null) attached to this node (Statistics View)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (null)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (null) attached to this node (Statistics View)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (null)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (null) attached to this node (Statistics View)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (null)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (null) attached to this node (Statistics View)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (null)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (null) attached to this node (Statistics View)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (null)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (null) attached to this node (Statistics View)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (null)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (null) attached to this node (Statistics View)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (null)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (null) attached to this node (Statistics View)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (null)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (null) attached to this node (Statistics View)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (null)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (null) attached to this node (Statistics View)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (null)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (null) attached to this node (Statistics View)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (null)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (null) attached to this node (Statistics View)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (BitmapFont) attached to this node (null)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (null) attached to this node (Statistics View)
2011-6-20 13:17:07 com.jme3.scene.Node attachChild
信息: Child (Statistics View) attached to this node (Gui Node)
2011-6-20 13:17:07 com.jme3.material.MaterialDef
信息: Loaded material definition: Phong Lighting
2011-6-20 13:17:08 com.jme3.scene.Node attachChild
信息: Child (shafa-geom-0) attached to this node (shafa-objnode)
2011-6-20 13:17:08 com.jme3.scene.Node attachChild
信息: Child (shafa-geom-1) attached to this node (shafa-objnode)
2011-6-20 13:17:08 com.jme3.scene.Node attachChild
信息: Child (shafa-geom-2) attached to this node (shafa-objnode)
2011-6-20 13:17:08 com.jme3.scene.Node attachChild
信息: Child (shafa-geom-3) attached to this node (shafa-objnode)
2011-6-20 13:17:08 com.jme3.scene.Node attachChild
信息: Child (shafa-geom-4) attached to this node (shafa-objnode)
2011-6-20 13:17:08 com.jme3.scene.Node attachChild
信息: Child (shafa-geom-5) attached to this node (shafa-objnode)
2011-6-20 13:17:08 com.jme3.scene.Node attachChild
信息: Child (shafa-objnode) attached to this node (Root Node)
2011-6-20 13:17:08 com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation
信息: Uniform m_VertexColor is not declared in shader.
2011-6-20 13:17:11 com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation
信息: Uniform g_CameraPosition is not declared in shader.
2011-6-20 13:17:11 com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation
信息: Uniform g_WorldMatrix is not declared in shader.
2011-6-20 13:17:11 com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation
信息: Uniform m_UseMaterialColors is not declared in shader.
2011-6-20 13:17:21 com.jme3.input.lwjgl.LwjglMouseInput destroy
信息: Mouse destroyed.
2011-6-20 13:17:21 com.jme3.input.lwjgl.LwjglKeyInput destroy
信息: Keyboard destroyed.
2011-6-20 13:17:21 com.jme3.system.lwjgl.LwjglAbstractDisplay deinitInThread
信息: Display destroyed.
Could anybody help me?
If you’ve used a texture image, it needs to be included as well. Right click the model convert to j3o, then click view model/in scenegraph with the newly generated j3o. Click the light icon, and you should see if your model looks right.
I have fixed this problem.
soh is right. We only need to load obj file. The mtl file will be loaded automatically.
The cause of my problem is that i used jme3 jar files are old.
I updated the latest jar files, all things work well now!