|
Andre Pohlmann
|
 |
« on: 16. May 2007, 11:54:08 am » |
|
Hi@all, glad to see Xith on again  I got few questions and I want to start with this one ^^: I have an obj-file with named objects in it. Simple said a map with a wall. When the model is loaded I need to get the 'children' by name -> model.getNamedOjects("wall"), but I got only null. So it seems that the OBJLoader sets no names for shape, geometry etc. Any solution ??
|
|
|
|
|
Logged
|
|
|
|
|
'n ddrylliog
|
 |
« Reply #1 on: 16. May 2007, 12:24:15 pm » |
|
Hi@all, glad to see Xith on again  I got few questions and I want to start with this one ^^: I have an obj-file with named objects in it. Simple said a map with a wall. When the model is loaded I need to get the 'children' by name -> model.getNamedOjects("wall"), but I got only null. So it seems that the OBJLoader sets no names for shape, geometry etc. Any solution ?? Hi Andre ! Please post the OBJ file (if you can) with a code snippet and I'll fix that.
|
|
|
|
|
Logged
|
|
|
|
|
Andre Pohlmann
|
 |
« Reply #2 on: 16. May 2007, 12:47:46 pm » |
|
Hi Amos, I hoped to hear that  # Exported from Wings 3D 0.98.35 mtllib simpleRoom0.4.mtl o plane #4 vertices, 4 faces v 20.00000000 -1.0000000e-6 -19.99999800 v 20.00000000 1.0000000e-6 20.00000000 v -20.00000200 1.0000000e-6 19.99999600 v -19.99999200 -1.0000000e-6 -20.00000800 g plane_planeMat usemtl planeMat f 1// 3// 2// f 1// 3// 4// f 2// 3// 1// f 4// 3// 1// o wall #32 vertices, 48 faces v 20.00000000 -1.0000000e-6 -20.00000000 v 20.00000000 1.0000000e-6 20.00000000 v 19.00000000 1.0000000e-6 20.00000000 v 19.00000000 -1.0000000e-6 -20.00000000 v 20.00000000 1.99999900 -20.00000000 v 20.00000000 2.00000100 20.00000000 As far as I can see, at least all end in OBJGroup.build() (?!) thats called from graph.addChild( topGroup.build( verts, texs, normals, graph, getFlags() ) ); So at the point Group group = groups.get(i).build(verts, texs, normals, graph, flags); with groups.get(i).getName() it seems to work... but the names went lost after adding them to the group. 
|
|
|
|
|
Logged
|
|
|
|
|
Andre Pohlmann
|
 |
« Reply #3 on: 16. May 2007, 03:15:10 pm » |
|
hope it will help... Parts of the code:
... try { model = loader.loadModel(x.toString()); System.out.println("After loading. Name of first children from our model: " + model.getChild(0).getName()); scene = loader.loadScene(x.toString()); } catch(IOException e) { ...
System.out.println("ShapeNodes attached to model: " + model.getShapeNodes()); System.out.println("Name of first shape: " + model.getShapeNodes().get(0).getName()); System.out.println("Appearance of 1. shape: " + model.getShapeNodes().get(0).getAppearance()); System.out.println("Name of material: " + model.getShapeNodes().get(0).getAppearance().getMaterial().getName()); System.out.println("Geometry of 1. shape: " + model.getShapeNodes().get(0).getGeometry()); System.out.println("Name of geometry of 1. Shapes: " + model.getShapeNodes().get(0).getGeometry().getName()); System.out.println("Vertexcount of Geometry of 1, Shapes: " + model.getShapeNodes().get(0).getGeometry().getVertexCount()); System.out.println("Is shapenode pickable: " + model.getShapeNodes().get(0).isPickable());
System.out.println("ShapeNodes attached to model: " + model.getShapeNodes()); System.out.println("Name of 2nd shape: " + model.getShapeNodes().get(1).getName()); System.out.println("Appearance of 2nd shape: " + model.getShapeNodes().get(1).getAppearance()); System.out.println("Name of material: " + model.getShapeNodes().get(1).getAppearance().getMaterial().getName()); System.out.println("Geometry of 2nd shape: " + model.getShapeNodes().get(1).getGeometry()); System.out.println("Name of geometry of 2nd Shapes: " + model.getShapeNodes().get(1).getGeometry().getName()); System.out.println("Vertexcount of Geometry of 2nd Shapes: " + model.getShapeNodes().get(1).getGeometry().getVertexCount()); System.out.println("Is shapenode pickable: " + model.getShapeNodes().get(1).isPickable());
And whats written in the console:
After loading. Name of first children from our model: ShapeNodes attached to model: [org.xith3d.scenegraph.Shape3D@1dee400, org.xith3d.scenegraph.Shape3D@4ac216] Name of first shape: Appearance of 1. shape: org.xith3d.scenegraph.Appearance@c5e9c Name of material: Geometry of 1. shape: org.xith3d.scenegraph.TriangleArray@1777b1 Name of geometry of 1. Shapes: Vertexcount of Geometry of 1, Shapes: 12 Is shapenode pickable: true ShapeNodes attached to model: [org.xith3d.scenegraph.Shape3D@1dee400, org.xith3d.scenegraph.Shape3D@4ac216] Name of 2nd shape: Appearance of 2nd shape: org.xith3d.scenegraph.Appearance@b3319f Name of material: Geometry of 2nd shape: org.xith3d.scenegraph.TriangleArray@7ecd78 Name of geometry of 2nd Shapes: Vertexcount of Geometry of 2nd Shapes: 144 Is shapenode pickable: true
|
|
|
|
|
Logged
|
|
|
|
|
Andre Pohlmann
|
 |
« Reply #4 on: 16. May 2007, 03:31:56 pm » |
|
in OBJLoader line 307 to 312 is this fragment of code:
else if (line.startsWith( "o" )) { OBJGroup g = new OBJGroup( factory, line.substring( 2 ) ); topGroup.addGroup( g ); currentGroup = g; }
If I am not wrong, the line in the obj-file is read in there (?!) I tryed to check the name of the group but there is no getName(). So I added in OBJGroup (I am realy sorry for this unprofessional work...) this:
public String getName() { return name; }
than I added in OBJLoader in line 311 System.out.println("Name of g: " + g.getName()); and got this:
Name of g: plane Name of g: wall
Exactly the names from the obj-file.
As written bevor the graph.addChild( topGroup.build( verts, texs, normals, graph, getFlags() ) ); seems to call the build in OBJGroup. So I added in the called methode an System.out.println("Name of group in OBJGroup: " + group.getName()); in line 73 an got this:
Name of group in OBJGroup: top Name of group in OBJGroup: top Name of group in OBJGroup: top Name of group in OBJGroup: top
If in line 68 groups.get(i) is copied to group, why is the name set to top ?? Is there any reason for it?
|
|
|
|
|
Logged
|
|
|
|
|
Andre Pohlmann
|
 |
« Reply #5 on: 16. May 2007, 04:03:49 pm » |
|
The question is: why adding 4 groups to the returned group with the same name?? And what are these other 2 groups? So I added at line 69 System.out.println("Name of group after copying: " + groups.get(i)); And got this: Name of group after copying: plane Name of group after copying: Name of group after copying: wall Name of group after copying: In OBJLOader line 303 is OBJGroup g = new OBJGroup( factory, "" ); ... it is for the material-name ?! If I add there line.substring( 2 ) instead "" it looks like this: Name of group after copying: plane Name of group after copying: plane_planeMat Name of group after copying: wall Name of group after copying: wall_wallMat So my next question is why there is an "" instead of line.substring( 2 ) ??!! So the returned group got 4 attached groups with the names top... until I changed in OBJGroup line 73 group.setName(name); to group.setName(groups.get(i).getName()); So from my point of view I got: model -> returned graph(without name) -> attached bg(without name) (returned one from OBJGroup) with 4 groups named plane, plane_planeMat, wall and wall_wallMat What is happaning to them if I use eg model.getShapeNodes().get(0).getName() ?? I don't want to bother someone... I just try to understand 
|
|
|
|
|
Logged
|
|
|
|
|
'n ddrylliog
|
 |
« Reply #6 on: 19. May 2007, 01:51:31 pm » |
|
Currently investigating that.
Marvin, why is "Scene" a BranchGroup, and not a Group ?
|
|
|
|
|
Logged
|
|
|
|
|
'n ddrylliog
|
 |
« Reply #7 on: 19. May 2007, 01:54:46 pm » |
|
Andre, your 2 additional/garbage groups are caused by these lines of your obj file : g plane_planeMat g wall_wallMat
(and by the way I would have preferred if you had posted the file as attachments (you can do so by expanding the "Additional Options..." panel which is just at the left-bottom of the textfield you type your posts in). Now the only problem is that the groups which are named correctly (e.g. for the test files I've created, "Cube" and "Tube", or for you "plane" and "wall") should be added in the "named nodes" map. And that's all. For all the group hierarchy, maybe we can remove one or two but it's not a priority right now.
|
|
|
|
« Last Edit: 19. May 2007, 01:59:23 pm by Amos Wenger »
|
Logged
|
|
|
|
|
'n ddrylliog
|
 |
« Reply #8 on: 19. May 2007, 03:39:56 pm » |
|
It works. import org.openmali.vecmath.Vector3f; import org.xith3d.base.Xith3DEnvironment; import org.xith3d.loaders.models.impl.obj.OBJLoader; import org.xith3d.loaders.models.impl.obj.OBJScene; import org.xith3d.loop.RenderLoop; import org.xith3d.render.Canvas3D; import org.xith3d.render.Canvas3DFactory; import org.xith3d.render.config.OpenGLLayer; import org.xith3d.scenegraph.Group; import org.xith3d.scenegraph.PointLight; import org.xith3d.scenegraph.Transform; import org.xith3d.utility.general.Xith3DLogo;
public class NamedObjects_OBJ_Blender extends RenderLoop { public static void main(String[] args) throws Throwable {new NamedObjects_OBJ_Blender();}
public NamedObjects_OBJ_Blender() throws Throwable { Xith3DEnvironment env = new Xith3DEnvironment(this); Canvas3D canvas = Canvas3DFactory.create(OpenGLLayer.JOGL_AWT, 800, 600, 32, false, "OBJ+Blender (Named Objects)"); env.addCanvas(canvas); Group g = env.addPerspectiveBranch().getBranchGroup(); OBJScene scene = new OBJLoader().loadScene("data/2objects.obj"); System.out.println("Objects : "+scene.getNamedObjects()); g.addChild(new Transform(scene.getNamedObject("Tube").sharedCopy()).setTranslationX(2f)); g.addChild(new Transform(scene.getNamedObject("Cube").sharedCopy()).setTranslationX(-2f)); env.getView().lookAt(new Vector3f(0f, 3f, -5f), new Vector3f(0f, 0f, 0f), new Vector3f(0f, 1f, 0f)); g.addChild(new PointLight(1f, 1f, 1f, 0f, 18f, 30f, .0005f)); this.begin(); } }
In Blender the "Tube" and "Cube" objects have the same position, and in this app they are separated. Attached, the objects used (exported from Blender, Wings should work also).
|
|
|
|
|
Logged
|
|
|
|
Marvin Fröhlich
Xith Lord
Administrator
Guru
   
Offline
Posts: 4381
May the 4th, be with you...
|
 |
« Reply #9 on: 20. May 2007, 08:25:01 pm » |
|
Marvin, why is "Scene" a BranchGroup, and not a Group ?
Well, scene is a whole scene, but not a group in the graph. So I decided to make it a BranchGroup. Any objections? (and by the way I would have preferred if you had posted the file as attachments (you can do so by expanding the "Additional Options..." panel which is just at the left-bottom of the textfield you type your posts in).
Can we maybe configure SMF to automatically expand the additional options? I see no reason why not. And it will certainly confure more people in the future. Marvin
|
|
|
|
|
Logged
|
|
|
|
|
'n ddrylliog
|
 |
« Reply #10 on: 21. May 2007, 04:44:15 am » |
|
Marvin, why is "Scene" a BranchGroup, and not a Group ?
Well, scene is a whole scene, but not a group in the graph. So I decided to make it a BranchGroup. Any objections? Well, I thimk that anyway a Scene loaded from eg. an OBJ file isn't complete anyway (ie the users will have to add nodes for themselves) so a Group looked more loigcal to me.. You _could_ not always want this group to be the root.. (and by the way I would have preferred if you had posted the file as attachments (you can do so by expanding the "Additional Options..." panel which is just at the left-bottom of the textfield you type your posts in).
Can we maybe configure SMF to automatically expand the additional options? I see no reason why not. And it will certainly confure more people in the future. I agree, but it's beyond my knowledge  I'll search in the admin panel.
|
|
|
|
|
Logged
|
|
|
|
|
Andre Pohlmann
|
 |
« Reply #11 on: 21. May 2007, 10:03:09 am » |
|
Andre, your 2 additional/garbage groups are caused by these lines of your obj file : g plane_planeMat g wall_wallMat
Hi,yes, I already found out  In OBJLOader line 303 is OBJGroup g = new OBJGroup( factory, "" ); ... it is for the material-name ?! If I add there line.substring( 2 ) instead "" it looks like this:
Name of group after copying: plane Name of group after copying: plane_planeMat Name of group after copying: wall Name of group after copying: wall_wallMat
(and by the way I would have preferred if you had posted the file as attachments (you can do so by expanding the "Additional Options..." panel which is just at the left-bottom of the textfield you type your posts in).
... sorry  I know that there are additional options, but I don't thought about using it for code... only for pictures  And the problem was just adding it to the "named nodes" map  ... and I wasn't able to solve it .... *D'oh* Thx ^^
|
|
|
|
|
Logged
|
|
|
|
|
Andre Pohlmann
|
 |
« Reply #12 on: 22. May 2007, 08:29:56 am » |
|
Hi Amos, I got an new problem and need help to understand what I am doing wrong. The following code was called after loading the obj file. public void setMap(Model x) { if(mapTG == null) { // Transformgruppen fuer die geladenen Dateien // Transformgroups for the loaded files mapTG = new TransformGroup(); mapTG.setName("mapTG"); mapTG.addChild(x); mapTG.setShowBounds(actBounds); rootTG.addChild(mapTG); } ...
That worked, except that fact that I need to get the objects by name... Now I should be able to get the objects by name, so I changed the code to: public void setMap(OBJScene x) { if(mapTG == null) { System.out.println("Object: " + x.getNamedObject("plane")); rootTG.addChild(new Transform(x.getNamedObject("plane").sharedCopy())); }
The Sys.out prints indeed the needed object, but the object is not displayed! I got just a black screen. I thought about lightning and diabled it, but it didn't work. If I add the whole scene x, the object is displayed. So I changed the code again to be sure that the plane is added to the rootTg. public void setMap(OBJScene x) { if(mapTG == null) { System.out.println("Object: " + x.getNamedObject("plane")); rootTG.addChild(x.getNamedObject("plane").sharedCopy()); System.out.println(rootTG.numChildren()); System.out.println(rootTG.getChild(0).getName()); }
NumChildren returned 1, as expected, but getName() returned nothing... Maybe sharedCopy() forgets to copy the name  ... but what is about my object? Any ideas? Thx so far for fixing...
|
|
|
|
|
Logged
|
|
|
|
Marvin Fröhlich
Xith Lord
Administrator
Guru
   
Offline
Posts: 4381
May the 4th, be with you...
|
 |
« Reply #13 on: 22. May 2007, 09:24:38 am » |
|
The name-property simply was not copies in sharedCopy(). I have fixed this now.
Marvin
|
|
|
|
|
Logged
|
|
|
|
|
Andre Pohlmann
|
 |
« Reply #14 on: 22. May 2007, 09:52:37 am » |
|
 wow, damn fast thanks. But it won't fix my display problem... ?? I'll try again and post the outcoming 
|
|
|
|
|
Logged
|
|
|
|
|