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 (498)
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  
  Textures on a .obj file?  (Read 5097 times)
0 Members and 1 Guest are viewing this topic.
Offline bert

Junior Member




Miles of road and miles of code


« Posted 2006-05-17 22:40:31 »

I'm SICK of colored models! How can I get some textures in there? I've been using Blender (http://www.blender.com) to create my models, then exporting them along with the appropriate .mtl files and accompanying images. Why, why oh WHY?  Huh

w00t, i'm winning
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #1 - Posted 2006-05-18 04:28:45 »

Yes the .obj format does support texturing.  Google for the spec.  I found a copy a year or two back on some russian site (don't think there now, but I'm sure there's others out there) Originally the .obj format was defined by 'wavefront', which might refine your search.

Note that you can define sets of texture coordinates for each polygon.  These map into the texture specified in the material file.  Thus you can map a texture onto several polygons, which is handy if you want to skin a model, but more work if you're writing your own renderer.  If you are using OpenGL, then this maps fairly well onto OpenGLs texture coordinate system, although some tinkering will be required to get textures the right way round.

If you don't care about texture mapping, you could stick with one texture per polygon with an arbritary orgin.  This works better for wall and floor texturing anyway, as you can set the origin position to achieve seamless texturing for all polygons in the same plane.  You still get discontinuities at corners, but then you can't have everything.

Happy texturing
Alan

/Edit
Example: shamelessly ripped off from somewhere...
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
# A 2 x 2 square mapped with a 1 x 1 square
# texture stretched to fit the square exactly.
mtllib master.mtl
0.000000 2.000000 0.000000
0.000000 0.000000 0.000000
2.000000 0.000000 0.000000
2.000000 2.000000 0.000000
vt 0.000000 1.000000 0.000000
vt 0.000000 0.000000 0.000000
vt 1.000000 0.000000 0.000000
vt 1.000000 1.000000 0.000000
# 4 vertices
usemtl wood
# The first number is the point,
# then the slash,
# and the second is the texture point
f 1/1 2/2 3/3 4/4


The vt commands (vertex texture) define texture coordinates on the texture surface.  They are referenced by the number after the '/' in the f command (face).

/Edit2: Nuts I just realised that this is posted under Java3D.  I haven't tried mapping .obj textures onto java3d.
In a vain attempt to redeem myself here is some stuff scrounged from the web...

The standard FileObject loader does understand texture coords.
http://www.vrupl.evl.uic.edu/oldsite/VRLabAcc/about_vrlab/java3d/lesson08/indexa.html
There is also an obj file loader demo in the java3d jdk, called objLoad.
Documentation for the demo:
http://java3d.j3d.org/utilities/loaders/obj/sun.html

Time flies like a bird. Fruit flies like a banana.
Offline NewbTon

Junior Member




Odejava games rock!


« Reply #2 - Posted 2006-05-18 14:03:10 »

What do you uses to load OBJ files in java3d ?
The standard one is is not to well thought out IMO and I'm still looking for another one.
All you really need is a loader that returns some arrays, like indices, vertices and texturecoords to create your own
geometry in whatever library you want. Suns (i think) returns a scenegraph with a bunch of nodes and the worst part is,
you can't read or write the geometry arrays since they are byRef.



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

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #3 - Posted 2006-05-18 18:18:52 »

There's various loaders listed here http://java3d.j3d.org/utilities/loaders.html

Time flies like a bird. Fruit flies like a banana.
Offline bert

Junior Member




Miles of road and miles of code


« Reply #4 - Posted 2006-05-18 19:35:24 »

The way I load OBJ files is from this tutorial:

http://www.vrupl.evl.uic.edu/oldsite/VRLabAcc/about_vrlab/java3d/

Click on Lesson 8a. No matter what I do I can't seem to get anything more than different colors. If I need to do a sign or something I render the text as polygons.

w00t, i'm winning
Offline beowulf03809

Junior Member




We live for the code, we die for the code


« Reply #5 - Posted 2006-05-19 17:58:26 »

Also, I believe the cokeandcode Asteroids tutorial uses OBJ files with textures.  Very basic implementation and should provide a starting point.
Offline otelo

Junior Member





« Reply #6 - Posted 2006-05-28 10:26:28 »

The way I load OBJ files is from this tutorial:

http://www.vrupl.evl.uic.edu/oldsite/VRLabAcc/about_vrlab/java3d/

Click on Lesson 8a. No matter what I do I can't seem to get anything more than different colors. If I need to do a sign or something I render the text as polygons.

I wrote my custom loader (don't ask fot it, it' very application specific). I recommend you do the same, it's easy and gives you a lot of insight into how things work. you'll find all the specs on .obj tags in the source of the bundled J3D obj loader (as comments). Don't forget that for textures to work, you need to export your model with normals (and then load them). I have no idea whether texture loading works or not with the bundled loader.
Offline bert

Junior Member




Miles of road and miles of code


« Reply #7 - Posted 2006-06-20 22:10:03 »

How come people keep forgetting that this is a Java3D board? I don't want to sound frustrated but Coke and Code showed me exactly what I wanted to do... in OpenGL. I'd really prefer to use Java3D.

w00t, i'm winning
Offline Amos Wenger

Senior Member




Everything's possible, but not everything's fun...


« Reply #8 - Posted 2006-06-21 18:36:25 »

How come people keep forgetting that this is a Java3D board? I don't want to sound frustrated but Coke and Code showed me exactly what I wanted to do... in OpenGL. I'd really prefer to use Java3D.
Hey is that what you call OpenGL ? http://www.cokeandcode.com/node/305

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #9 - Posted 2006-06-21 18:42:47 »

More like the poster refers to this:

http://www.cokeandcode.com/node/324

</blatant plug>

Seriously tho, if you just want to apply a single texture to an OBJ file ... load the OBJ, traverse the branch group it returns and apply the texture you want to each appearance node.

The OBJ format does support textures in the mtl file but you might find it easier to programmatically apply your own.

Kev

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

Junior Member




Miles of road and miles of code


« Reply #10 - Posted 2006-06-21 20:43:13 »

Sorry, it didn't look like any Java3D I recognized but on closer inspection I guess it is.

w00t, i'm winning
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 (18 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (187 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!