Skip to content

Commit

Permalink
MultiScaleTreeGraph should be >=0.8
Browse files Browse the repository at this point in the history
And fix issue coming from MultiScaleTreeGraph.ordered_children that does not exist anymore
  • Loading branch information
VEZY committed Mar 20, 2023
1 parent 81925c9 commit 5f9c8b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ EzXML = "1"
Makie = "0.15, 0.16, 0.17, 0.18, 0.19"
MeshViz = "0.4, 0.5, 0.6, 0.7"
Meshes = "0.26, 0.27, 0.28"
MultiScaleTreeGraph = "0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9"
MultiScaleTreeGraph = "0.8, 0.9"
Observables = "0.5"
RecipesBase = "1"
StaticArrays = "1"
Expand Down
34 changes: 17 additions & 17 deletions src/opf/write_opf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,25 @@ function write_opf(file, mtg)
error("No reference meshes found in the MTG.")
end

for (key, mesh) in enumerate(mtg[:ref_meshes].meshes)
for (key, mesh_) in enumerate(mtg[:ref_meshes].meshes)
# key = 1; mesh_ = mtg[:ref_meshes].meshes[key]
mesh_elm = addelement!(meshBDD, "mesh")
mesh_elm["name"] = mesh.name
mesh_elm["name"] = mesh_.name
mesh_elm["shape"] = ""
mesh_elm["Id"] = key - 1 # opf uses 0-based indexing
mesh_elm["enableScale"] = mesh.taper
mesh_elm["enableScale"] = mesh_.taper

addelement!(
mesh_elm,
"points",
string("\n", join([vcat([p.coords for p in mesh.mesh.vertices]...)...], "\t"), "\n")
string("\n", join(vcat([p.coords for p in mesh_.mesh.vertices]...), "\t"), "\n")
)

if length(mesh.normals) == Meshes.nelements(mesh) && length(mesh.normals) != Meshes.nvertices(mesh)
if length(mesh_.normals) == Meshes.nelements(mesh_) && length(mesh_.normals) != Meshes.nvertices(mesh_)
# If the normals are per triangle, re-compute them per vertex:
vertex_normals = normals_vertex(mesh)
vertex_normals = normals_vertex(mesh_)
else
vertex_normals = mesh.normals
vertex_normals = mesh_.normals
end

norm_elm = addelement!(
Expand All @@ -63,38 +64,37 @@ function write_opf(file, mtg)
)


if mesh.texture_coords !== nothing && length(mesh.texture_coords) > 0
if mesh_.texture_coords !== nothing && length(mesh_.texture_coords) > 0
# texture_coords are optional
norm_elm = addelement!(
mesh_elm,
"textureCoords",
string("\n", join(vcat([[p.coords...] for p in mesh.texture_coords]...), "\t"), "\n")
string("\n", join(vcat([[p.coords...] for p in mesh_.texture_coords]...), "\t"), "\n")
)
end

faces_elm = addelement!(mesh_elm, "faces")

face_id = [0]
for i = 1:Meshes.nelements(Meshes.topology(mesh.mesh))
for i = 1:Meshes.nelements(Meshes.topology(mesh_.mesh))
face_elm = addelement!(
faces_elm,
"face",
string("\n", join(Meshes.topology(mesh.mesh).connec[i].indices .- 1, "\t"), "\n")
string("\n", join(Meshes.topology(mesh_.mesh).connec[i].indices .- 1, "\t"), "\n")
)
#? NB: we remove one because face index are 0-based in the opf
face_elm["Id"] = face_id[1]
face_id[1] = face_id[1] + 1
end

end

# Parsing the materialBDD section.
materialBDD = addelement!(opf_elm, "materialBDD")
for (key, mesh) in enumerate(mtg[:ref_meshes].meshes)
for (key, mesh_) in enumerate(mtg[:ref_meshes].meshes[2:end])
mat_elm = addelement!(materialBDD, "material")
mat_elm["Id"] = key - 1 # opf uses 0-based indexing

mat = material_to_opf_string(mesh.material)
mat = material_to_opf_string(mesh_.material)
addelement!(
mat_elm,
"emission",
Expand Down Expand Up @@ -128,14 +128,14 @@ function write_opf(file, mtg)

# Parsing the shapeBDD section.
shapeBDD = addelement!(opf_elm, "shapeBDD")
for (key, mesh) in enumerate(mtg[:ref_meshes].meshes)
for (key, mesh_) in enumerate(mtg[:ref_meshes].meshes)
shape_elm = addelement!(shapeBDD, "shape")
shape_elm["Id"] = key - 1 # opf uses 0-based indexing

addelement!(
shape_elm,
"name",
mesh.name
mesh_.name
)

addelement!(
Expand Down Expand Up @@ -207,7 +207,7 @@ function mtg_topology_to_xml!(node, xml_parent, xml_gtparent=nothing, ref_meshes
end

if !isleaf(node)
for chnode in MultiScaleTreeGraph.ordered_children(node)
for chnode in children(node)
xml_node = attributes_to_xml(chnode, xml_parent, xml_gtparent, ref_meshes)
mtg_topology_to_xml!(chnode, xml_node, xml_parent, ref_meshes)
end
Expand Down

0 comments on commit 5f9c8b1

Please sign in to comment.