Important information: this site is currently scheduled to go offline indefinitely by end of the year.

[solved] Adding texture to a .obj

Post questions about game models here, or help out others!
majidemo
advanced
Posts: 71
Joined: Sun Aug 21, 2016 12:00 am
Has thanked: 29 times
Been thanked: 36 times

[solved] Adding texture to a .obj

Post by majidemo »

I am trying to apply textures to a .obj file I created manually by extracting data from a custom game format.
The model data and texture are on different files.

This is the texture (256x256):

Image

And this is how it looks inside the game:

Image

As you can see, the texture seems to be mirrored/duplicated because the texture image only contains 1 side.
But how do I attach my texture to the object. I was trying it with a .mtl file but it just won't work.

Image

What did I do wrong?

Here is the .mtl file (I tried):

Code: Select all

newmtl test
  illum 2
  map_Ka test.png
  map_Kd test.png
Last edited by majidemo on Fri Aug 26, 2016 6:55 am, edited 4 times in total.
User avatar
Leeloobastet
ultra-n00b
Posts: 6
Joined: Mon Aug 15, 2016 8:45 pm

Re: Adding texture to a .obj

Post by Leeloobastet »

When I extract an .obj file from a game, it always shows up with the .mtl file + the texture file(s).
I use Misfit Model 3D to re-attach the texture file to the object.
I open the object, then in the Edit Material option, I reattribute the texture files to all meshes.
User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 4291
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 1151 times
Been thanked: 2244 times

Re: Adding texture to a .obj

Post by shakotay2 »

@majidemo
first of all the notation of your faces in the obj file is incomplete.
It writes
f 1 2 3
f 1 3 4
[...]

Should be
f 1/1/1 2/2/2 3/3/3
f 1/1/1 3/3/3 4/4/4
[...]

because the 3D apps I know can't create the uv map from f 1 2 3 etc.
Tuts: a) Bigchillghost, viewtopic.php?f=29&t=17889
b) Extracting simple models: http://forum.xentax.com/viewtopic.php?f=29&t=10894
"Quoting the whole thing. Would u ever stop this nonsense?"
majidemo
advanced
Posts: 71
Joined: Sun Aug 21, 2016 12:00 am
Has thanked: 29 times
Been thanked: 36 times

Re: Adding texture to a .obj

Post by majidemo »

shakotay2 wrote:@majidemo
first of all the notation of your faces in the obj file is incomplete.
It writes
f 1 2 3
f 1 3 4
[...]

Should be
f 1/1/1 2/2/2 3/3/3
f 1/1/1 3/3/3 4/4/4
[...]

because the 3D apps I know can't create the uv map from f 1 2 3 etc.
Sir shakotay2, do I just duplicate the face value? or is "1/x/y" x and y a completely different value I need to get the from custom format?

Or it is simply 1/1/1 (x/x/x)? Thank you.
Leeloobastet wrote:When I extract an .obj file from a game, it always shows up with the .mtl file + the texture file(s).
I use Misfit Model 3D to re-attach the texture file to the object.
I open the object, then in the Edit Material option, I reattribute the texture files to all meshes.
I don't think this is the case on mine, because I didn't use any program to extract the object. I manually decoded the custom format and wrote a python script to generate the .obj file.
majidemo
advanced
Posts: 71
Joined: Sun Aug 21, 2016 12:00 am
Has thanked: 29 times
Been thanked: 36 times

Re: Adding texture to a .obj

Post by majidemo »

Sir shakotay2,

I currently cant test

Code: Select all

f x/y/z
or a different value for each slash, because the values on the custom format are all mapped already and I don't know where to get the slash values BUT...

I tested doing

Code: Select all

f v1/v1/v1 v2/v2/v2 v3/v3/v3
assuming every slash is just a duplicate... and this is what I got. (at least the texture is now showing)

Image

But there seems to be a problem in the mapping? what did I do wrong?
Last edited by majidemo on Fri Aug 26, 2016 6:55 am, edited 1 time in total.
User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 4291
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 1151 times
Been thanked: 2244 times

Re: Adding texture to a .obj

Post by shakotay2 »

The indices for vertices/normals/uv may be different (such as f 1/1/2 2/2/3 3/3/2 for example) as you noticed.
majidemo wrote:But there seems to be a problem in the mapping? what did I do wrong?
Please upload the model file which you decoded.

(I'm off to office now...)
Tuts: a) Bigchillghost, viewtopic.php?f=29&t=17889
b) Extracting simple models: http://forum.xentax.com/viewtopic.php?f=29&t=10894
"Quoting the whole thing. Would u ever stop this nonsense?"
majidemo
advanced
Posts: 71
Joined: Sun Aug 21, 2016 12:00 am
Has thanked: 29 times
Been thanked: 36 times

Re: Adding texture to a .obj

Post by majidemo »

I did notice. Thanks for your time in looking into this.

here's the file: download. It contains a few related files like textures and the obj archive, but the actual file is "def_22.obj". (not a wavefront .obj, but a custom format .obj)

A few more details on the format:

The faces starts at offset 76 (decimal) and ends at offset 1954 (decimal). I also added 1 (+1) to all values of the face.

Starting from offset 1954 (decimal) this structure follows until the end:

Code: Select all

float x
float y
float z
I hope the info helps.
Last edited by majidemo on Fri Aug 26, 2016 6:56 am, edited 1 time in total.
Karpati
ultra-veteran
ultra-veteran
Posts: 467
Joined: Thu Dec 07, 2006 11:25 pm
Has thanked: 9 times
Been thanked: 95 times

Re: Adding texture to a .obj

Post by Karpati »

majidemo,

I recommend to read this page:
https://en.wikipedia.org/wiki/Wavefront_.obj_file
majidemo
advanced
Posts: 71
Joined: Sun Aug 21, 2016 12:00 am
Has thanked: 29 times
Been thanked: 36 times

Re: Adding texture to a .obj

Post by majidemo »

Karpati wrote:majidemo,

I recommend to read this page:
https://en.wikipedia.org/wiki/Wavefront_.obj_file
Thanks but I did use that as reference while writing my script to create the obj file.
Karpati
ultra-veteran
ultra-veteran
Posts: 467
Joined: Thu Dec 07, 2006 11:25 pm
Has thanked: 9 times
Been thanked: 95 times

Re: Adding texture to a .obj

Post by Karpati »

OK, Can you tell me which game from comes the (binary) .obj and .t16 files?
majidemo
advanced
Posts: 71
Joined: Sun Aug 21, 2016 12:00 am
Has thanked: 29 times
Been thanked: 36 times

Re: Adding texture to a .obj

Post by majidemo »

Karpati wrote:OK, Can you tell me which game from comes the (binary) .obj and .t16 files?
It's an old korean mmorpg back from 2001. It's no longer around as the company is long gone. I'm just studying the files. Its called Khan.
User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 4291
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 1151 times
Been thanked: 2244 times

Re: Adding texture to a .obj

Post by shakotay2 »

I've used your params in hex2obj:
def_022.jpg
It's just a matter of building 1-y for the uvs (similar to mirroring at y axis)


These are the faces (similar to yours but normals indices ignored)

g submesh_0
f 1/1 2/2 3/3
f 1/1 3/3 4/4
f 5/5 6/6 7/7
f 5/5 7/7 8/8
f 9/9 10/10 11/11
f 12/12 10/10 9/9
f 13/13 9/9 11/11
[...]
You do not have the required permissions to view the files attached to this post.
Tuts: a) Bigchillghost, viewtopic.php?f=29&t=17889
b) Extracting simple models: http://forum.xentax.com/viewtopic.php?f=29&t=10894
"Quoting the whole thing. Would u ever stop this nonsense?"
majidemo
advanced
Posts: 71
Joined: Sun Aug 21, 2016 12:00 am
Has thanked: 29 times
Been thanked: 36 times

Re: Adding texture to a .obj

Post by majidemo »

shakotay2 wrote:I've used your params in hex2obj:
def_022.jpg
It's just a matter of building 1-y for the uvs (similar to mirroring at y axis)


These are the faces (normals indices ignored)

g submesh_0
f 1/1 2/2 3/3
f 1/1 3/3 4/4
f 5/5 6/6 7/7
f 5/5 7/7 8/8
f 9/9 10/10 11/11
f 12/12 10/10 9/9
f 13/13 9/9 11/11
[...]
Oh, wow. Although I didn't completely understand when you said: "It's just a matter of building 1-y for the uvs". So does that mean that the faces are actually just duplicates?

Thank you so much for your help. I'll try to update my python script to also generate the texture.

---edit---

I can't figure out how to fix the texture. Can you show me your `.obj` and `.mtl` file? Thank you

Code: Select all

mtllib 66_22.mtl
usemtl test
g submesh_0
f 1/1 2/2 3/3
f 1/1 3/3 4/4
f 5/5 6/6 7/7
f 5/5 7/7 8/8
f 9/9 10/10 11/11
[/size]
Last edited by majidemo on Thu Aug 25, 2016 8:23 pm, edited 1 time in total.
User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 4291
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 1151 times
Been thanked: 2244 times

Re: Adding texture to a .obj

Post by shakotay2 »

majidemo wrote:Although I didn't completely understand when you said: "It's just a matter of building 1-y for the uvs".
uv Coords 0.0 0.0 -> 0.0 1.0, 1.0 1.0 ->1.0 0.0
Some people say it's mirroring at the y axis, but it's an additional adding of 1.0 to y,
so in the end y -> 1-y
but I can't figure out how to add the textures there.
it's not implemented.
I use blender for the texture thingie ("mirroring" included).

edit: I don't have a mtl file.
you can get the obj by performing a File/SaveAs mesh in hex2obj.
Last edited by shakotay2 on Thu Aug 25, 2016 8:27 pm, edited 1 time in total.
Tuts: a) Bigchillghost, viewtopic.php?f=29&t=17889
b) Extracting simple models: http://forum.xentax.com/viewtopic.php?f=29&t=10894
"Quoting the whole thing. Would u ever stop this nonsense?"
majidemo
advanced
Posts: 71
Joined: Sun Aug 21, 2016 12:00 am
Has thanked: 29 times
Been thanked: 36 times

Re: Adding texture to a .obj

Post by majidemo »

shakotay2 wrote:
majidemo wrote:Although I didn't completely understand when you said: "It's just a matter of building 1-y for the uvs".
uv Coords 0.0 0.0 -> 0.0 1.0, 1.0 1.0 ->1.0 0.0
Some people say it's mirroring at the y axis, but it's an additional adding of 1.0 to y,
so in the end y -> 1-y
but I can't figure out how to add the textures there.
it's not implemented.
I use blender for the texture thingie.
Oh, if I understand correctly. My current python script:

Code: Select all

"vt %f %f\n" % (x[0], x[1])
Should be changed to:

Code: Select all

"vt %f %f\n" % (x[0], 1-x[1])
??
Post Reply