How do you apply materials in Godot?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mydoghasworms
:warning: Old Version Published before Godot 3 was released.

I am trying to apply a material with a texture to a simple 3D object in Godot. The mesh is just a cube imported from a .obj file exported from Blender.

When I run the scene, it does not seem to apply the material.

Here is a link to my project file: https://drive.google.com/open?id=0B7BEZKRdO750akhuTHJpR19rcTQ

It contains a scene with a cube and a material with a texture image that I simply created inside Godot.

This is what I get when I run the scene:

enter image description here

Did you generate an UV map on your cube before exporting it from Blender? (your link doesn’t contain the original obj file).

Zylann | 2016-12-12 14:03

I did not. Is that a prerequisite? I thought I could just apply materials in Godot. The .obj contains the default scene cube along with a default material (stored in cube.obj and cube.mtl respectively).

–cube.obj:

# Blender v2.78 (sub 0) OBJ File: ''
# www.blender.org
mtllib cube.mtl
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
vn 0.0000 -1.0000 0.0000
vn 0.0000 1.0000 0.0000
vn 1.0000 0.0000 0.0000
vn -0.0000 -0.0000 1.0000
vn -1.0000 -0.0000 -0.0000
vn 0.0000 0.0000 -1.0000
usemtl Material
s off
f 1//1 2//1 3//1 4//1
f 5//2 8//2 7//2 6//2
f 1//3 5//3 6//3 2//3
f 2//4 6//4 7//4 3//4
f 3//5 7//5 8//5 4//5
f 5//6 1//6 4//6 8//6

– cube.mtl

# Blender MTL File: 'None'
# Material Count: 1

newmtl Material
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2

mydoghasworms | 2016-12-13 04:21

:bust_in_silhouette: Reply From: Zylann

Texture coordinates are missing from your cube, so Godot doesn’t know how to apply textures to it. You can do that simply in Blender with one of the unwrap functions.

Thanks. Will the texture co-ordinates be present in an exported .obj file? How will I know they are there?
In fact, how do you know in Blender if the UV unwrap function was successful? I seem to remember having done it but not seeing any difference in the object properties.

mydoghasworms | 2016-12-13 11:42

In Blender you can press U to open the unwrap menu in edit mode with all vertices selected and choose one that suits your model. I don’t remember the exact steps to see the result but you should apply the texture in Blender first to see if it displays correctly here in the first place.

You can tell a .obj has texture coordinates by checking it has vt lines, like this:

vt 0.0000 0.0000
vt 1.0000 0.0000
vt 1.0000 1.0000
vt 0.0000 1.0000
...

Zylann | 2016-12-13 12:38