Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Setting Appearance Attributes of Models  (Read 1420 times)
0 Members and 1 Guest are viewing this topic.
Offline shochu

Junior Member




Java games rock!


« Posted 2003-12-11 23:21:05 »

Is it possible to set appearance attributes for loaded models.  In particular I wanted to be able to do this for models loaded using Kev's 3ds loader.  Right now the models I have all seem to be flat shaded and I want them to be smooth shaded.  Is this something that is part of the model or can I change this in xith like you can with a Shape3D?  Thanks!

~Shochu
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #1 - Posted 2003-12-12 02:08:32 »

Yes this is possible - I do this with the Ase loader, in my case it is applying a material so that the object is affected by lighting.

See this post: http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=xith3d;action=display;num=1070726483#7

Look at the methods of Shape3D in particular getAppearence and setAppearence (I use the getMaterial method of the got Appearence) in the javadoc/source code.

Specifically on the question on smooth shading - I don't know the answer to that Smiley

Cheers,

Will.

Offline kevglass

JGO Kernel


Medals: 164
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #2 - Posted 2003-12-12 05:53:43 »

Normally when I've written loaders in the past of added a NodeFactory interface which the user can implement.

As the loader processes the geometry it calls back onto the NodeFactory to produce the actual Xith/Java 3D nodes. This the user direct control over the node creation. I haven't implemented this for 3DS or OBJ loaders.. but I can if it'd be useful.

Kev

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #3 - Posted 2003-12-12 06:59:53 »

Basically loaders produce normal Xith3D scenegraps, so you can always traverse scenegraph produced by any loader and change any attributes of nodes.

On the shading model, you can change shading model using appropriate methods from ColoringAttributes (accessible via Appearance object of Shape3D).

Yuri

Yuri Vl. Gushchin
JProof Group
Offline shochu

Junior Member




Java games rock!


« Reply #4 - Posted 2003-12-12 12:45:26 »

Am I able to access the Shape3D that is the model in the 3ds loader?  Since the TDSModel extends branchgroup it doesn't have a setAppearance option.
Offline kevglass

JGO Kernel


Medals: 164
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2003-12-12 13:14:00 »

What the above posts are suggesting is that you traverse the scenegraph for yourself and find the Shape nodes.. I've always disliked the user having to do this, hence the NodeFactory idea.

Kev

Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #6 - Posted 2003-12-12 15:09:45 »

Quote
I've always disliked the user having to do this, hence the NodeFactory idea.


Kev, I agree with you in this specific case. But for more generic solution the traverser should [OK, may] be also good. In this case there is no need to rely on the source of the model, etc.

This is more conceptual than implementation question. I think both approaches may/should easily co-exist in the same system. We can try to make it easier to traverse scene graph by providing unified traverser and implementing a Visitor design pattern, so it will be easy or even trivial to implement such functionality in the apps.

I agree that NodeFactory idea gives much more control over the scene loading process, but it does not void the later scene traversals that may be used, say, for subtree-level scenegraph changes.

Quote
Am I able to access the Shape3D that is the model in the 3ds loader?  Since the TDSModel extends branchgroup it doesn't have a setAppearance option.


You still should be able to get list of child nodes with getChildren() and then test instanceof Shape3D. Again, if specified child instanceof Group you call traversing recursively, so finally you will get access to all children for root BranchGroup.

Yuri

Yuri Vl. Gushchin
JProof Group
Offline kevglass

JGO Kernel


Medals: 164
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #7 - Posted 2003-12-12 16:11:13 »

Oops, sorry, must have sounded a bit more absolute than I meant it, maybe I should use more smileys  Smiley  Smiley Smiley Smiley Smiley

Traversing the scenegraph is _always_ going to be a valid method. In the case of model loaders its just a nice extra since the chances are every user will want to modify the models (lighting/shadows/caching appearances)

Kev

Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #8 - Posted 2003-12-12 17:05:00 »

Quote
Oops, sorry, must have sounded a bit more absolute than I meant it


Have ABSOLUTELY no problems with this - you are welcome!

Yuri

Yuri Vl. Gushchin
JProof Group
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #9 - Posted 2003-12-12 20:08:22 »

Both are good suggestions Smiley

Here's an example of what Yuri is talking about (actually this code is taken from the linked topic in my first post, but here it is incase you don't like following links Wink)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
 +  /**
+   * Recursivly adds the given material to all Shape3D objects
+   * in the passed group and all of its subgroups.
+   */

+  public static void addMaterial(Group group, Material mat) {
+
+     java.util.List nodes = group.getChildren();
+
+     for (int i = 0; i < nodes.size(); i++) {
+        SceneGraphObject obj = (SceneGraphObject) nodes.get(i);
+
+        if (obj instanceof Shape3D) {
+      Shape3D sh = (Shape3D) obj;
+      sh.getAppearance().setMaterial(mat);
+
+        } else if (obj instanceof Group) {
+      addMaterial( (Group) obj, mat);
+        }
+     }
+  }


That specific example is for setting the same material across all Shape3D's which may not be what you want but it still shows how you can traverse all Shape3D's in a given Group.

fairly straight forward really, but if you want an example of this in action - run this: http://xith.org/jws/jws-com.xith3d.test.Xith3DAseGroupTest.jnlp and look at the source of the Xith3DAseGroupTest which is where that above code snippet is taken from.

Cheers,

Will.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (28 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (74 views)
2014-09-10 06:39:09

Tekkerue (38 views)
2014-09-09 02:24:56

mitcheeb (57 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (28 views)
2014-09-07 01:12:14

Longarmx (34 views)
2014-09-07 01:11:22

Longarmx (34 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!