I’ve just finished my EntityTemplate editor. My Entity files are essentially JSON files with a bit of meta data and a list of configured entity components. Now, I want to be abel to add those template files as Nodes in the scene composer. I can check if this is possible (it is only possible if there is a RenderComponent for now) That’s not the problem.
I also found the wiki page on “Adding Node types to SceneExplorer”. What I can’t figure out from this page however is how to link those controls/spatials/tools/etc. to my actual template file. What I would like is something similar to the .j3o file, where you have a roght-mouse menu item to add it directly to the scene.
After that, I could easily get the j3o model from the template and display that in the scene editor. I just can’t seem to figure out how to link the two together.
If anyone can give me any hints regarding this, that would be great.
Just use j3o files, whats the problem? Otherwise, look at the SceneExplorer code examples, adding an action that you can invoke to the list is quite easy.
I’d generally say just having a node that just stores the entity type name should suffice, you can load the corresponding data later and construct the model from there.
I know I can set up the template in the userdata, that’s the easy part. But I would prefer to set things up in such a way that I can take the actual model reference from the template and then render it in the actual scene explorer.
That’s what I’m currently trying to figure out how to do.
I created a Custom Control. I can add this Custom Control (EntityTemplateControl) to a Node in the scene editor. On the Custom Control I then added a field called templateName. Now, in the control properties, I can see said field and add the template file I want to add to the Node.
All this is working as well as to be expected.
Next up though, is figuring out how to render the model, which is defined in the template file. I have managed to load the template file, by supplying the complete folder and loading straight from the file.
I would prefer to do it via the AssetManager though. The only problem there is, I don’t have access to the AssetManager, seeing how I’m not running a game with an underlying SimpleApplication.
Is there any way to get an AssetManager up and running which will let me read stuff that’s on the classpath? I managed to find the code which sets up the AssetManager in Application.java:
Only, for some reason, when I then say:
[java]
ModelKey key = new ModelKey(rc.getJ3o());
assetManager.loadModel(key);
[/java]
I get the AssetNotFoundException. I even went so far as to add the Assets.jar to the project classpath, so it would be availlable. But that’s not helping either.
I get the AssetNotFoundException. I even went so far as to add the Assets.jar to the project classpath, so it would be availlable. But that’s not helping either.
If someone could give me some pointers…
I don’t have a solution but I think the reason is that classloaders in netbeans modules are more like OSGI, they don’t have access to other modules classes/classpath unless that module “exports” the classes. So even if you start an asset manager in your module it will not have the same classloader as the SDK uses.
Maybe the SDK exposes it’s AssetManager (if it uses one - I don’t know) through lookups (NbmIdioms - NetBeans Wiki) and you can get it that way.
Well, this custom control thing lives outside of the actual plugin. I couldn’t get it to work inside of the plugin, so I decided to do it outside first. To take out all those problems.
Now, I’m getting closer to the problem, I’ve been able to find the code which sets up the AssetManager in Application.java. I copied that to my own EntityTemplateControl, which should then create a correct AssetManager.
After this, I should be able to load stuff inside my assets folder throught the assetManager I created. I keep getting an AssetNotFoundException though.
So, I did a bit more test code:
[java]
for (ClassLoader loader : assetManager.getClassLoaders()) {
URL url = loader.getResource(rc.getJ3o());
if (url != null) {
logger.info(“found it!”);
URI uri = url.toURI();
logger.info(uri.toString());
InputStream is = loader.getResourceAsStream(rc.getJ3o());
Spatial model = assetManager.loadModel(rc.getJ3o());
logger.info("modeKey: " + model.getKey().getName());
spatial = model;
}
}
[/java]
In here, I get the “found it!” in my mesages.log. So the URI is able to find the file. ThegetResourceAsStream also works as expected. So I can get an inputstream to the j3o. If I look inside the assets.jar, in the location identified by the URI, the file IS there.
So why do I keep getting this AssetNotFoundException?