Skip to content

Commit

Permalink
Updated OBJ file loading code
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Nov 12, 2023
1 parent fa191f9 commit 7bf06c9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 3 additions & 1 deletion material_maker/panels/preview_3d/preview_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ func do_load_custom_mesh(file_path) -> void:
mm_globals.config.set_value("path", "mesh", file_path.get_base_dir())
var id = objects.get_child_count()-1
#var mesh = $ObjLoader.load_obj_file(file_path)
var mesh = load(file_path)
var mesh : Mesh = null
var obj_loader = load("res://material_maker/tools/obj_loader/obj_loader.gd")
mesh = obj_loader.load_obj_file(file_path)
if mesh != null:
var object : MeshInstance3D = objects.get_child(id)
object.mesh = mesh
Expand Down
11 changes: 4 additions & 7 deletions material_maker/tools/obj_loader/obj_loader.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
extends Node
extends Object

func _ready():
pass # Replace with function body.

func load_obj_file(path : String) -> ArrayMesh:
static func load_obj_file(path : String) -> ArrayMesh:
if path == null:
return null
var ext := path.get_extension()
Expand Down Expand Up @@ -53,7 +50,7 @@ func load_obj_file(path : String) -> ArrayMesh:

return mdl

func _obj_rel_indice(indice : Vector3, cur_vArr_size : int) -> Vector3:
static func _obj_rel_indice(indice : Vector3, cur_vArr_size : int) -> Vector3:
var output := Vector3.ZERO
var indSign := indice.sign()
output.x = indice.x - 1 if (indSign.x >= 0) else cur_vArr_size + indice.x
Expand All @@ -62,7 +59,7 @@ func _obj_rel_indice(indice : Vector3, cur_vArr_size : int) -> Vector3:

return output

func _import_obj(mdlFile : FileAccess) -> TriMesh:
static func _import_obj(mdlFile : FileAccess) -> TriMesh:
var newMsh := TriMesh.new()

while !mdlFile.eof_reached():
Expand Down

0 comments on commit 7bf06c9

Please sign in to comment.