Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
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  
  ASE Loading textures  (Read 1039 times)
0 Members and 1 Guest are viewing this topic.
Offline rmdire

Junior Member





« Posted 2005-12-06 16:39:29 »

Hi

I'm  back with more ASE loader Q's.

I understand from other posts that ASE loader does not support Materials (light reflection etc)
I have accounted for this in my code.

I note however the ASE file format also has a "*BITMAP" tag - which points to my models textures
 
I was wondering does the ASE Loader support the loading and  application of  these Textures - or
do the textures have to be applied separately -
'cos when I load up my Model - there are no textures showing.

If these textures have to be applied manually - does anybody have some example code  to extract the Shape3D
for each body part and apply the texture2D

Cheers

Rmdire 
Offline rmdire

Junior Member





« Reply #1 - Posted 2005-12-06 18:06:00 »

Still can't find answers on this - as far as I can make out - the xith source code appears to load textures

in the mean time i've built this from other stuff I found on the forum - if anybody is interested - it just dumps a texture on the
object - maybe someone would have a better function?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
   public void addTextureToBodyPart(Group group,String nodeName,URL texturePath)
   {
      //set up texture and appearance
      Texture2D thisTexture = null;
       thisTexture = loadtexture(texturePath);
       Appearance thisAppearance = new Appearance();
       thisAppearance.setTexture(thisTexture);
      
          // list of all the chillllders
         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;
             
                 //is this the name of poor child we want to texture
                //texturing children should be made illegal
             if((group.getName()).equalsIgnoreCase(nodeName))
                  {sh.setAppearance(thisAppearance);}
             }
             else if (obj instanceof Group)
             {
            addTextureToBodyPart( (Group) obj,nodeName,texturePath);
             }
           }  
   }



Rmdire
Offline rmdire

Junior Member





« Reply #2 - Posted 2005-12-07 11:13:32 »


this function is way too slow - don't use it

does anybody else have any functions that they use to texture .ASE models - or am I the only one who is using this file format?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline arne

Senior Member




money is the worst drug- we should not let it rule


« Reply #3 - Posted 2005-12-07 18:40:45 »

moment...:
Texture and Appearance is not the same!!!
The ASE-Loader creates Nodes with Appearances, that contain the Texture. It only uses the default setting for the Material, which handles Lightning and stuff.

so you'll probably only have to do this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
    /** sets the Material of the given Shape */
    private void setMaterial(Shape3D s) {
        Material m = new Material(true);
        m.setAmbientColor(0.2f,0.2f,0.2f);
        m.setDiffuseColor(1,1,1);
        m.setSpecularColor(0.4f,0.4f,0.4f);
        if(s.getAppearance().getTextureUnitCount() == 0) m.setColorTarget(m.AMBIENT_AND_DIFFUSE);
        else  m.setColorTarget(m.NONE);
       s.getAppearance().setMaterial(m);
    }
    /** This Method performs a DFS through all the Nodes contained in g */
    private void setMaterial(Group g) {
       for(int i = 0; i < g.numChildren(); i++) {
          Node n = g.getChild(i);
          if(n instanceof Group) {
             setMaterial((Group) n);
          }
          else if(n instanceof Shape3D) {
             setMaterial((Shape3D) n);
          }
       }
    }


:: JOODE :: Xith3d :: OdeJava ::
Offline rmdire

Junior Member





« Reply #4 - Posted 2005-12-08 10:46:35 »

Thanks arne,

Yep, I have been using these functions already - I got it from one of your previous posts.

But the model just shows up as white without any reflective feature,

This is why I was wondering if the ASE loading of textures is actually implemented.

actually what I've just done is move the textures out of the folder they should be in and tried to load the model in.
and its loaded without any "cannot find resource errors" - so theres my answer - textures are not working for the ASE loader.

is this correct?
Offline arne

Senior Member




money is the worst drug- we should not let it rule


« Reply #5 - Posted 2005-12-08 19:30:00 »

Ahh that problem Cheesy I had it also Wink
The ASE-Loader uses the TextureLoader to load textures, but it doesn't register a path to the directory, where the textures are located. So it simply doesn't find the texture. You'll simply have to register the Path in TextureLoader before loading. I believe this should help.

Important: I believe the ASE-loader still uses TextureLoader and NOT TextureLoader2, so don't register the path at the wrong loader Wink

:: JOODE :: Xith3d :: OdeJava ::
Offline rmdire

Junior Member





« Reply #6 - Posted 2005-12-09 11:53:49 »


HI Arne -
Forgive my total ignorance - but I cant see how to access the ASELoader's TextureLoader in order to set the path.

this is how I load in my ASE file:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
                                          AseFile af = new AseFile();
      BufferedReader br = null;
     
      try {
         // Attempts to read the file normally
        br = new BufferedReader(new FileReader(path));
     
      } catch (IOException e) {
         // Attemts to read file from JAR
        URL url = this.getClass().getClassLoader().getResource(path);
         try {
            br = new BufferedReader(new InputStreamReader(url.openStream()));
         } catch (IOException e1) {
            // TODO Auto-generated catch block
           e1.printStackTrace();
         }
      }
     
      AseReader r = new AseReader(br, af);
   
      af.parse(r);
           
     
      namedNodes = new HashMap ();
      TransformGroup rootTG = af.getTransformGroupTree(namedNodes);


How should I access the ASELoader's TextureLoader in order to set the path.

Cheers

Rmdire
Offline arne

Senior Member




money is the worst drug- we should not let it rule


« Reply #7 - Posted 2005-12-09 16:41:25 »

When you call TextureLoader.getInstance() * it returns you a TextureLoader that's saved as a static variable in TextureLoader. So it returns exactly the same TextureLoader for you as for the ASE loader (I'm talking here about identity). So when you change the TextureLoader you get by TextureLoader.getInstance() you'll change the static variable, so you change the TextureLoader the ASE-Loader uses.

*I don't if the method is called exactly TextureLoader.getInstance() or something different (with the same meaning ofcourse).

:: JOODE :: Xith3d :: OdeJava ::
Offline rmdire

Junior Member





« Reply #8 - Posted 2005-12-10 21:45:18 »

Thanks arne

this hasn't worked either - must be summit up with the ASE exporter.

your help on the secrets of XITH is much appreciated though

Cheers

Rmdire
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.

xsi3rr4x (12 views)
2014-04-15 18:08:23

BurntPizza (10 views)
2014-04-15 03:46:01

UprightPath (24 views)
2014-04-14 17:39:50

UprightPath (10 views)
2014-04-14 17:35:47

Porlus (27 views)
2014-04-14 15:48:38

tom_mai78101 (49 views)
2014-04-10 04:04:31

BurntPizza (107 views)
2014-04-08 23:06:04

tom_mai78101 (207 views)
2014-04-05 13:34:39

trollwarrior1 (176 views)
2014-04-04 12:06:45

CJLetsGame (182 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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!