diff --git a/obj-parse/ObjParse.gd b/obj-parse/ObjParse.gd index aad9e83..b5a605a 100644 --- a/obj-parse/ObjParse.gd +++ b/obj-parse/ObjParse.gd @@ -1,6 +1,7 @@ -extends Node class_name ObjParse +const debug:=false + # Obj parser made by Ezcha, updated by Deakcor # Created on 7/11/2018 # https://ezcha.net @@ -22,11 +23,11 @@ static func load_obj(obj_path:String, mtl_path:String="")->Mesh: mats=_create_mtl(get_data(mtl_path),get_mtl_tex(mtl_path)) return _create_obj(obj,mats) if obj and mats else null -#Create mesh from obj, mtl and textures data. Texture should be {"path":data} +#Create mesh from obj, materials. Materials should be {"matname":data} static func load_obj_from_buffer(obj_data:String,materials:Dictionary)->Mesh: return _create_obj(obj_data,materials) -#Create material +#Create materials static func load_mtl_from_buffer(mtl_data:String,textures:Dictionary)->Dictionary: return _create_mtl(mtl_data,textures) @@ -91,7 +92,8 @@ static func _create_mtl(obj:String,textures:Dictionary)->Dictionary: pass "newmtl": # Create a new material - #print("Adding new material " + parts[1]) + if debug: + print("Adding new material " + parts[1]) currentMat = SpatialMaterial.new() mats[parts[1]] = currentMat "Ka": @@ -101,7 +103,8 @@ static func _create_mtl(obj:String,textures:Dictionary)->Dictionary: "Kd": # Diffuse color currentMat.albedo_color = Color(float(parts[1]), float(parts[2]), float(parts[3])) - #print("Setting material color " + str(currentMat.albedo_color)) + if debug: + print("Setting material color " + str(currentMat.albedo_color)) pass _: if parts[0] in ["map_Kd","map_Ks","map_Ka"]: @@ -114,12 +117,14 @@ static func _parse_mtl_file(path): return _create_mtl(get_data(path),get_mtl_tex(path)) static func _get_image(mtl_filepath:String, tex_filename:String)->Image: - #print(" Debug: Mapping texture file " + tex_filename) + if debug: + print(" Debug: Mapping texture file " + tex_filename) var texfilepath := tex_filename if tex_filename.is_rel_path(): texfilepath = mtl_filepath.get_base_dir().plus_file(tex_filename) var filetype := texfilepath.get_extension() - #print(" Debug: texture file path: " + texfilepath + " of type " + filetype) + if debug: + print(" Debug: texture file path: " + texfilepath + " of type " + filetype) var img:Image = Image.new() img.load(texfilepath) @@ -135,7 +140,8 @@ static func _create_texture(data:PoolByteArray): static func _get_texture(mtl_filepath, tex_filename): var tex = ImageTexture.new() tex.create_from_image(_get_image(mtl_filepath, tex_filename)) - #print(" Debug: texture is " + str(tex)) + if debug: + print(" Debug: texture is " + str(tex)) return tex @@ -236,7 +242,8 @@ static func _create_obj(obj:String,mats:Dictionary)->Mesh: # Make tri for matgroup in faces.keys(): - #print("Creating surface for matgroup " + matgroup + " with " + str(faces[matgroup].size()) + " faces") + if debug: + print("Creating surface for matgroup " + matgroup + " with " + str(faces[matgroup].size()) + " faces") # Mesh Assembler var st = SurfaceTool.new()