I am a beginner in JAVA, and I’m going to use JME to develop a 3D minesweeping game. Now I got a question.
When I generate minefields, since the size and distribution of minefields are not fixed while each grid will be operated in the process of the game, I want to make the grid state to be a class. Then, at the beginning of the game, we load the existing models (obj.&mtl.) according to the state of each grid, then put them together to form a complete minefield. But in all the tutorial I could find, only a single model can be loaded, and I can’t do that as mentioned above. So, I would like to ask for a solution to this problem.
Very appreciated! ( It’s better to offer a sample program as reference.)
Hi @BAO , welcome to jme community, I don’t know from where should I begin, but at least you can navigate the jme3 wiki & search for :
Importing Assets
BaseAppStates
AbstractControls
There are multiple ways to do that, one way is using a BaseAppState & a synchronized time frames within the update which kinda sleeps some frames from a model to other , so
you build a list of models, called Tiles[].
synchronize them inside the update method with time frames.
you can do this too with only time frames w/o a synchronized block anyway.
Example :
Tips : you can do display a SplashScreen or LoadingScreen whenever you are doing a heavy task to hide the ugliness of low fps…
I’m now try to use a Spatial list called temp[][] to load my models. However, I can’t solve the error when load my model.
This is the report:
Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.ClassCastException: class com.jme3.material.MaterialList cannot be cast to class com.jme3.asset.CloneableSmartAsset (com.jme3.material.MaterialList and com.jme3.asset.CloneableSmartAsset are in unnamed module of loader ‘app’)
at com.jme3.asset.cache.WeakRefCloneAssetCache.addToCache(WeakRefCloneAssetCache.java:127)
at com.jme3.asset.DesktopAssetManager.loadLocatedAsset(DesktopAssetManager.java:294)
at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:388)
at com.jme3.asset.DesktopAssetManager.loadMaterial(DesktopAssetManager.java:412)
at Main.simpleInitApp(Main.java:41)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:240)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:139)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:221)
at java.base/java.lang.Thread.run(Thread.java:832)
Could you tell me what is the problem? Very Appreciated!
Yeah, in JME MaterialList doesn’t implement those clonable things. I guess it is never meant to be used like that. I didn’t check the usage, but maybe it is just specific to that loader MTL. I would imagine it is not a big thing to modify MaterialList to implement the interfaces if it serves the purpose.
Typically in production one should use JME’s own formats for superior performance and compatibility.
Could tell me where I can learn about the AppStates & subSpatials? I can only find SimpleApplication in the tutorial (Maybe because of the language barrier)
Really hard to say what you are trying and how your assets work. But probably you can circumvent this problem by converting the assets to J3O. The material might be already attached on the J3O but this is something that you will see then.
But I cannot load models in my BaseAppState. Or shall I write some small app(to load models) with SimpleApplication then manage them in AppState? Could you plz make it more clear to me?
And my plan now is firstly to take every grid to be a class with properties like coordinates & status etc, then I could write a method to load the model of every grid by its property. And I could also write a listener there.