Skip to content

Commit

Permalink
Merge branch 'ff/materials2' of https://github.com/JuliaIO/MeshIO.jl
Browse files Browse the repository at this point in the history
…into ff/materials2
  • Loading branch information
ffreyer committed Oct 3, 2024
2 parents 9a834c4 + 64d624d commit 0b10677
Showing 1 changed file with 1 addition and 54 deletions.
55 changes: 1 addition & 54 deletions src/io/obj.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,59 +214,6 @@ function save(f::Stream{format"OBJ"}, mesh::AbstractMesh)
end


# Experimental stuff for loading .mtl files and working with multiple materials

"""
MehsIO.split_mesh(mesh)
Experimental function for splitting a mesh based material indices.
Also remaps vertices to avoid passing all vertices with a submesh.
"""
function split_mesh(mesh)
ps = coordinates(mesh)
ns = normals(mesh)
uvs = texturecoordinates(mesh)
ids = mesh.material
fs = faces(mesh)

meshes = Dict{Int, Any}()
target_ids = unique(ids)
IndexType = eltype(eltype(fs))

for target_id in target_ids
_fs = eltype(fs)[]
indexmap = Dict{UInt32, UInt32}()
counter = MeshIO._typemin(IndexType)

for f in fs
if any(ids[f] .== target_id)
f = map(f) do _i
i = GeometryBasics.value(_i)
if haskey(indexmap, i)
return indexmap[i]
else
indexmap[i] = counter
counter += 1
return counter-1
end
end
push!(_fs, f)
end
end

indices = Vector{UInt32}(undef, counter-1)
for (old, new) in indexmap
indices[new] = old
end

meshes[target_id] = GeometryBasics.Mesh(
meta(ps[indices], normals = ns[indices], uv = uvs[indices]), _fs
)
end

return meshes
end

function _load_mtl!(materials::Dict{String, Dict{String, Any}}, filename::String)
endswith(filename, ".mtl") || error("Material Template Library $filename must be a .mtl file.")

Expand Down Expand Up @@ -449,4 +396,4 @@ function parse_texture_info(parent_path::String, lines::Vector{SubString{String}
end

return output
end
end

0 comments on commit 0b10677

Please sign in to comment.