Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  LibGDX import .obj and .g3db not showing textures  (Read 955 times)
0 Members and 1 Guest are viewing this topic.
Offline DrewLols

Senior Devvie


Medals: 3
Projects: 1


Noob going through metamorphosis...


« Posted 2014-04-26 02:22:34 »

I have been spending hours trying to figure this out, but no tutorials that I've found have explained why this might be happening.  I just started 3D modeling in Blender, and I'm finally starting to understand how to created models.  I even managed to map a texture to my model in the program.  The problem is importing the model into LibGDX.  Whenever I do, the texture just doesn't load.  Here's a picture of what happens when I try to load my models:



Of course, a face texture should show up when there is a big rectangular blob.  This is what the model looks like in Blender:


Here is a copy of my blender file, and a couple of exported versions if anyone is interested in sifting through my files:

http://download1481.mediafire.com/obe8ke5zc1ag/17y9s20c8nl2onv/Models.zip

Last, but not least, here is a copy of my rendering code:
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  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
package display;
import java.util.ArrayList;
import java.util.List;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
import com.badlogic.gdx.math.Matrix4;

import util.ResourceManager;

/**
 * Main screen used by project
 * @author William Andrew Cahill
 *
 */

public class DisplayScreen implements Screen
{
   // 3D environment variables
   private DisplayGame game;               // Reference to game
   private Environment environment;         // Environment of models
   private ModelBatch mBatch;               // Batch used for rendering models
   private PerspectiveCamera cam;            // Camera used
   private CameraInputController controller;   // Camera controller
   private AssetManager manager;            // Asset manager
   
   // Etc
   private List<Model> models;               // List of models loaded
   private List<ModelInstance>   instances;      // List of model instances loaded

   // Loading flag
   private boolean loading;
   
   /**
    * Constructs a DisplayScreen
    * @param game Game creating this Screen
    */

   public DisplayScreen(DisplayGame game)
   {
      // Keeps reference of game
      this.game = game;
     
      // Constructs fields
        mBatch = new ModelBatch();
      environment = new Environment();
      environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, .5f));
        environment.add(new DirectionalLight().set(0.4f, 0.4f, 0.4f, -1f, -0.8f, -0.2f));
       
        cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        cam.position.set(0f, 5f, 10f);
        //cam.lookAt(0,0,0);
        cam.near = 1f;
        cam.far = 300f;
        cam.update();
       
        controller = new CameraInputController(cam);
        Gdx.input.setInputProcessor(controller);
       
        // Loads main model
        manager = new AssetManager();
        manager.load("models/wigglesModel.g3db", Model.class);
        loading = true;
       
        // Constructs empty lists of models and their instances
        models = new ArrayList<Model>();
        instances = new ArrayList<ModelInstance>();
   }
   
   
   /**
    * Finishes loading
    */

   private void doneLoading()
   {
        // Loads models
        models.add(manager.get("models/wigglesModel.g3db", Model.class));
       
        // Particular instance
        ModelInstance instance;
       
        // Adds instances
        instance = new ModelInstance(models.get(0));
        instances.add(instance);
        instance = new ModelInstance(models.get(0));
        instance.transform.translate(5, 0, 0);
        instances.add(instance);
        loading = false;
   }
   
   @Override
   public void render(float delta)
   {
      // Brings in data to render whenever ready
      if(loading && manager.update())
         doneLoading();
      // Updates controller
      controller.update();
     
      // Camera clear data
      Gdx.gl.glViewport(0,  0,  Gdx.graphics.getWidth(),  Gdx.graphics.getHeight());
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
     
      // Begins rendering
      mBatch.begin(cam);
      mBatch.render(instances, environment);
      for(int i=0; i<instances.size(); i++)
         instances.get(i).transform.rotate(0, 1, 0, 1);
      mBatch.end();
   }

   
   @Override
   public void resize(int width, int height)
   {
     
   }

   
   @Override
   public void show()
   {
     
   }

   
   @Override
   public void hide()
   {
     
   }

   
   @Override
   public void pause()
   {
     
   }

   
   @Override
   public void resume()
   {
     
   }

   
   @Override
   public void dispose()
   {
      mBatch.dispose();
        instances.clear();
        manager.dispose();
   }
}


Halp?

Did you know that 90% of statistics are wrong?
Offline DrewLols

Senior Devvie


Medals: 3
Projects: 1


Noob going through metamorphosis...


« Reply #1 - Posted 2014-04-30 20:40:10 »

I finally got it to work!  It may have been because my UV mapping went outside the borders of the texture I was using.  I still have one problem, though.  The texture is applied upside down!  How can I fix this?

Did you know that 90% of statistics are wrong?
Offline saucymeatman
« Reply #2 - Posted 2014-04-30 21:54:10 »

Try multiplying all your UV normalized coordinates by -1
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DrewLols

Senior Devvie


Medals: 3
Projects: 1


Noob going through metamorphosis...


« Reply #3 - Posted 2014-05-01 00:22:10 »

Try multiplying all your UV normalized coordinates by -1

Ah, ok, so it's something to do with how it's created in Blender.  Please excuse my ignorance, for I am new to Blender and LibGDX, but where can I find that in the UV editor?  Scratch that, what does multiplying the UV nomalized coordinates mean, exactly?  Will it flip the image in Blender?  I want what I see in Blender to be what I see when I import it into LibGDX, or at least, roughly the same.

Edit: I want to specify that the model looks fine in Blender, but is flipped in the LibGDX rendering.

Did you know that 90% of statistics are wrong?
Offline matheus23

JGO Kernel


Medals: 114
Projects: 3


You think about my Avatar right now!


« Reply #4 - Posted 2014-05-01 12:21:15 »

Try multiplying all your UV normalized coordinates by -1

I haven't worked with LibGDX Model's yet, so I can't give a definite answer, but inverting the y-component of the UV coords flips the texture on the y-axis.
This is, however, done by modifying y with
y = 1 - y
, not by multiplying with -1 Smiley

It could also be, because libgdx loads the texture upside down, maybe there is an option when loading textures Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline DrewLols

Senior Devvie


Medals: 3
Projects: 1


Noob going through metamorphosis...


« Reply #5 - Posted 2014-05-02 03:41:48 »

I figured it out.  After exporting from blender, I have to convert the .fbx file to a .g3db file using fbx-con.  I forgot to include the command line argument -f when converting.  I SHOULD have typed...

fbx-conv -f wigglesModel.fbx

instead of...

fbx-conv wigglesModel.fbx

Did you know that 90% of statistics are wrong?
Offline Cero
« Reply #6 - Posted 2014-05-02 05:36:40 »

good to know actually :D

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.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (49 views)
2014-12-09 22:41:13

BurntPizza (83 views)
2014-12-08 04:46:31

JscottyBieshaar (44 views)
2014-12-05 12:39:02

SHC (58 views)
2014-12-03 16:27:13

CopyableCougar4 (56 views)
2014-11-29 21:32:03

toopeicgaming1999 (122 views)
2014-11-26 15:22:04

toopeicgaming1999 (112 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!