How to load 3d model with texture from blender? (gdscript)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ravend

.obj loads but no texture

func _ready():
	meshInstance = MeshInstance.new()
	var mesh = load("res://assets/model.obj")
	meshInstance.set_mesh(mesh)
	add_child(meshInstance)

in the tutorial .dae and .gltf are loaded through an editor (not a gdscript)

what format to use in gdscript?

:bust_in_silhouette: Reply From: stormreaver

I used to use .obj for my static model, but I dropped it sometime in 2021. I use GLTF now for all my models, both static and animated. It’s much better (and better supported) than all the others. I highly recommend it above all the other model formats. It is lacking in only one area I’ve found (it doesn’t handle Blender’s face maps), but it is otherwise far and away the best format supported by Godot.

With that pitch out of the way, the .obj texture file and the texture itself must be in the same directory as the .obj file itself. It can be a real pain to manage .obj files, so you’ll be doing yourself a favor by dropping it in favor of GLTF, as its textures can be embedded into the file itself.

is it possible to load .GLTF from a gdscript?
advise an example

ravend | 2022-11-23 19:01

I always create a separate scene for each mesh, then I load that scene:

For 3.x:

var m = load(“scene.tscn”).instance()
add_child(m)

For 4:

var m = load(“scene.tscn”).instantiate()
add_child(m)

stormreaver | 2022-11-23 23:18