How to convert a obj file to an espadon object of class mesh ?

How to convert a *.obj file to an espadon object of class mesh ?

The following function converts a *.obj file into an espadon object of mesh class:

library (Rvcg)


load.mesh.from.obj <- function (obj.filename) {
  if (!file.exists(obj.filename)) {
    stop(paste (obj.filename, "does'nt exist"))
  }
  mesh_ <- list ()
  mesh_$patient <- ""
  mesh_$patient.bd <- ""
  mesh_$patient.sex <- ""
  mesh_$file.basename <- ""
  mesh_$file.dirname <- ""
  mesh_$object.name <- gsub("[.]obj","",basename(obj.filename))
  mesh_$object.name <- gsub( '[[:blank:]]','_',paste(gsub('[[:punct:]]+', '', 
                                                          unlist(strsplit(mesh_$object.name,"_"))),collapse="_"))

  mesh_$object.alias <-mesh_$object.name
  
  mesh_$frame.of.reference <- paste0(mesh_$object.name,"ref")
  mesh_$ref.pseudo <- mesh_$frame.of.reference 
  mesh_$modality <- "mesh"
  mesh_$description <- paste (mesh_$object.alias, "mesh")
  mesh_$creation.date <- format(Sys.Date(), "%Y%m%d")
  mesh_$nb.faces  <- 0
  mesh_$mesh <- vcgImport (obj.filename)
  mesh_$nb.faces <- dim(mesh_$mesh$it)[2]
  class (mesh_) <- "mesh"
  return (mesh_)
} 

You can then use in the following way:

library (rgl)
library (espadon)
obj.filename <- file.choose ()
m <- load.mesh.from.obj(obj.filename)
display.3D.mesh (m, color = "burlywood2", specular = "#404040")