Adding a Model to SceneViewer?

May I ask what Is the proper way to load a model to the SceneViewer through a modual? I can’t seem to locate the proper code in the trunk and the local help section on JMP Plugin Development does not seem to address it accordingly?

If you want to use the SceneViewer you have to use a SceneRequest as described in the manual. If you mean to add a model through the SceneComposer (which is a different plugin using the SceneViewr, like the Terrain Editor), you can find that code in the add model action or just invoke it yourself.

1 Like

ahh okay thank you so i can either get the reference to com.jme3.gde.scenecomposer.SceneComposerTopComponent and use the method addModel using WindowManager or I can use the code in com.jme3.gde.core.assets.actions.OpenModel or I can get code from SceneEditorControl to load the spatial in sceneViewer now i suppose since I don’t have direct access to an assetManager [that i know of] that it would be best to use SpatialAssetData I understand FileObject my question is what exactly goes into the MultiFileLoader should i just pass a new instance? i’m not too familiar with it. Also when i tried BinaryModelFileLoader and navigated to the .j3o file i receive some odd error pertaining to DataObject and its preferred constructor of creation

All loadable Spatials are already prepared, the DataObjects and nodes have ProjectAssetManagers and AssetData objects in their lookup so you can access them, you dont have to add anything. This is all described in the wiki. The connection you make between SceneViewer and SceneComposer does not exist, the SceneViewer is just the OpenGL window that is used by a plugin to display stuff, without an active plugin its just an OpenGL window and you have to request it to be able to use it.

1 Like

hmm i still seem to be slightly confused i moved the j3os i require to the platform application root folder i have which is to load the spatial in the scene I can’t simply click on it since i need a couple of things to happen in the background and its also part of the module. Also i can’t seem to locate in the jMP Plugin section you are referring to in the offline Help… I was thinking of changing the platform app to a list of plugins to be used ontop of the jmp platform and just tell everyone to get a copy and update but it still doesn’t solve the problem that even if i have access to the project directly instead of in a jar i still can’t properly load the specific test spatial through code, I didn’t seem to get your previous statement i guess is what i mean =p

Please read all information linked on this page so we are on the same:

Yes I read all of the information in the linked pages on the local help documents prior to asking the question and looking at the link it seems as though its the same exact information. I followed the beginning instructions when my project called for it adding the said plugins and its dependencies. The only difference is that I created a platform application and not a module suit though i can change easily. I’ve also viewed some of the source in the repo. I am pretty sure from the instructions once loaded into the scene I can easily manipulate the spatial based on the very small netbeans development knowledge I have. The only way i know how to load it though is through a jme project selecting it in a folder within assets. However this doesn’t help at all as I wish to load it directly instead of by user.



EDIT: After wiping my platform cache i was reminded of the Welcome Screen. I looked at the code and it seems easy enough

:? the welcome screen does nothing thats not described in the wiki page. Why do you lie to me?? t.t

lol after i tried loading the character i still ended up with the same DesktopAssetManager created in the output. I did read the wiki before but everything i have tried either haven’t worked or resulted in a black screen with “DesktopAssetManager created” printed in the output. The Welcome Screen did allow me to become aware of the SceneApplication.getApplication().getAssetManager() which actually didn’t result in another error however i can’t seem to get it working. I even tried enqueuing the second half even though i dnt believe it called for it



public void test() {



final Node rootNode = new Node(“Root Node”);

request = new SceneRequest(this, NodeUtility.createNode(rootNode), new ProjectAssetManager(null));

request.setWindowTitle(“Test Model Loading”);

final DirectionalLight dirLight = new DirectionalLight();

dirLight.setDirection(new Vector3f(.1f, 1, .1f).normalizeLocal());

dirLight.setColor(ColorRGBA.Gray);

SceneApplication.getApplication().addSceneListener(new SceneListener() {

@Override

public void sceneRequested(SceneRequest request) {

if (request.getRequester() == SceneDirector.this) {

SceneApplication.getApplication().enqueue(new Callable() {

@Override

public Object call() throws Exception {

SceneApplication.getApplication().getViewPort().getScenes().get(0).addLight(dirLight);

//SceneApplication.getApplication().getCamera().setLocation(new Vector3f(0, 0, 0));

Spatial model = null;

try {

model = SceneApplication.getApplication().getAssetManager().loadModel("/Models/Alex.j3o");

if (model == null) {

model = SceneApplication.getApplication().getAssetManager().loadModel(“Models/Alex.j3o”);

}

if (model == null) {

model = SceneApplication.getApplication().getAssetManager().loadModel(“nbres:/Models/Alex.j3o”);

}

} catch (Exception ex) {

Exceptions.printStackTrace(ex);

}

// attach the nifty display to the gui view port as a processor

rootNode.attachChild(model);

return null;

}

});

}

Man… dataObject.getLookup().lookup(ProjectAssetManager.class)!!!

i figured it was something with the assetManager but i also thought “SceneApplication.getApplication().getAssetManager()” would have worked since i saw it being used in such a fashion in the WelcomeScreen example XD I was never able to attain the lookup from a jMESpatial because none was loaded and looking at dataObject i still do not think i am initializing it properly even though i changed it into SpatialDataObject or BinaryModelDataObject file wrappers and use the BinaryMultiFileLoader :?



FileObject f = FileUtil.toFileObject(new File(“Models/Alex.j3o”));

MultiFileLoader mc = new BinaryModelFileLoader();

final BinaryModelDataObject context = new BinaryModelDataObject (f,mc);

final ProjectAssetManager m = context.getLookup().lookup(ProjectAssetManager.class);

Spatial model = null;

try {

model = context.loadAsset();

if(model==null)model = m.loadModel("/Models/Alex.j3o");

if (model == null) model = m.loadModel(“nbres:/Models/Alex.j3o”);

if (model == null) model = m.loadModel(“Models/Alex.j3o”);

if (model == null) model = m.loadModel(“nbres:Models/Alex.j3o”);

} catch (Exception ex) {

Exceptions.printStackTrace(ex);

}

// attach the nifty display to the gui view port as a processor

rootNode.attachChild(model);

return null;

}



-__-

also i found for some reason even though i followed welcome screen and added Alex.j3o in a base directory called Models only 6 ever gets called lol now i’m starting to get confused 8O



if(new File("/Models/Alex.j3o").isFile())JOptionPane.showMessageDialog(null, “2”);

if(new File(“Models/Alex.j3o”).isFile())JOptionPane.showMessageDialog(null, “3”);

if(new File(“nbres:/Models/Alex.j3o”).isFile())JOptionPane.showMessageDialog(null, “4”);

if(new File(“nbres:Models/Alex.j3o”).isFile())JOptionPane.showMessageDialog(null, “5”);

JOptionPane.showMessageDialog(null, “6”);

You are doing it all wrong, what are you instancing all that stuff for? Why do I write all that stuff in the wiki??

To get a DataObject from a file and then get the AssetManager do this:

[java]

ProjectAssetManager manager = DataObject.find(FileUtil.toFileObject(myFile)).getLookup().lookup(ProjectAssetManager.class);

[/java]

I’ve tried that call and the result is the same i even tried changing the first section and adding it to the scenerequest parameter instead of new ProjectAssetManager(null)

also i found for some odd reason i have to normalize the path and normalize the file as well as append “src/” to the beginning of it before i stop getting normalization errors which is odd because its not needed in the other modules i made or have seen so i’m definitely confused. I no longer get an error however the model does not show up in the scene. Even Displaying the stats results do not show any thing because i was unsure i tried attaching first the model node and then the rootnode to the viewport directly to no avail.

I’ve also realized that i cannot open a j3o file from the module though i suppose it it because it is not a jme project

also i’m able to request a scene object properly given that its loaded and other things but i took another look at the wiki and reread the online version properly which is identical to the local help version in the platform besides the code formatting but i don’t see exactly where you get some of these references though i suppose the last part was just working knowledge but



public void test() {

final Node rootNode = new Node(“Root Node”);

request = new SceneRequest(this, NodeUtility.createNode(rootNode), new ProjectAssetManager(null));

request.setWindowTitle(“Test Model Loading”);

final DirectionalLight dirLight = new DirectionalLight();

dirLight.setDirection(new Vector3f(.1f, 1, .1f).normalizeLocal());

dirLight.setColor(ColorRGBA.Gray);

SceneApplication.getApplication().addSceneListener(new SceneListener() {

@Override

public void sceneRequested(SceneRequest request) {

if (request.getRequester() == SceneDirector.this) {

SceneApplication.getApplication().enqueue(new Callable() {

@Override

public Object call() throws Exception {

SceneApplication.getApplication().getViewPort().getScenes().get(0).addLight(dirLight);

File f = new File(FileUtil.normalizePath(“src/Models/Alex.j3o”));

FileObject fileObject = FileUtil.toFileObject(FileUtil.normalizeFile(f));

//fileObject.isValid();

final ProjectAssetManager manager = DataObject.find(fileObject).getLookup().lookup(ProjectAssetManager.class);

if (manager == null) {

throw new IllegalStateException(“Cannot find project AssetManager!”);

}

//SceneApplication.getApplication().getCamera().setLocation(new Vector3f(0, 0, 0));

Spatial model = manager.loadModel(“src/Models/Alex.j3o”);

if (model == null) {

model = manager.loadModel(“Models/Alex.j3o”);

}

if (model == null) {

model = manager.loadModel(“Alex.j3o”);

}

} catch (Exception ex) {

Exceptions.printStackTrace(ex);

}

// attach the nifty display to the gui view port as a processor

rootNode.attachChild(model);

return null;

}

});

}

}

@Override

public boolean sceneClose(SceneRequest sr) {

throw new UnsupportedOperationException(“Not supported yet.”);

}

@Override

public void previewRequested(PreviewRequest pr) {

// throw new UnsupportedOperationException(“Not supported yet.”);

}

});

}



I have also spread it out to see if their was a problem somewhere but nothing is caught and it goes through still resulting in a blackscreen[nothing happens] where it was the first time i tried it though this time i centered the camera and the model and added a light source instead of selecting the bulb from the viewer

SceneApplication.getApplication().getViewPort().getScenes().get(0).addLight(dirLight);

File f = new File(FileUtil.normalizePath(“src/Models/”));

FileObject fileObject = FileUtil.toFileObject(FileUtil.normalizeFile(f));

//fileObject.isValid();

final ProjectAssetManager manager = DataObject.find(fileObject).getLookup().lookup(ProjectAssetManager.class);

if (manager == null) {

throw new IllegalStateException(“Cannot Locate ProjectAssetManager!”);

}

SceneApplication.getApplication().getCamera().setLocation(new Vector3f(0, 0, 0));

DataObject modelTarget = DataObject.find(fileObject);

if (modelTarget instanceof SpatialAssetDataObject) {

//TODO: wtf? why do i have to add the assetmanager?

((SpatialAssetDataObject) modelTarget).getLookupContents().add(manager);

Spatial model = ((SpatialAssetDataObject) modelTarget).loadAsset();

if (model == null) {

throw new IllegalStateException(“Cannot load model”);

} else {

//Spatial model = manager.loadModel(“Alex.j3o”);

model.setLocalTranslation(0, 0, 0);

// attach the nifty display to the gui view port as a processor

rootNode.attachChild(model);

}

}

return null;

Put the data in the asset folder, not in the source folder…

asset folder? do you mean create a separate directory called assets in the modules base folder or wrap a asset pack to the module? Or is their suppose to be an assets folder utility in all modules or maybe a separate netbeans platform/module suite project pertaining to the sdk?

In the project where you want to load the model. Also, as in OSGi, you are in a managed class loader environment so you cannot access data in other plugins.

hmm so the class-loader in this case is not configurable. I placed the folder in the same position as WelcomeScreen…“src/”

OSGI uses a type of sandbox class loader so it can only see packages which have been explicitly configured to be visible. The Model was in the base of the module not of the modules parent project but even so if i move the Models folder to the same folder as the base directory where the file search is being called would that help?

You can open classes in OSGi using that but not binary files. Same here.

oh so theirs no way to load a model from the module folder lmao thats what i have been trying to do the whole time. Hmm off chance would wrapping the model in a jar work then since I keep builds of the main project ? Actually i think an assets jar is generated each build maybe i can wrap that into a library module project. meh thanks for the responses anyway

Yes there is, if a class from that module loads the data thats possible.