Skip to content

Commit

Permalink
update docs/organize code
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciuszendron committed Dec 3, 2020
1 parent 9593e7c commit 1463b8a
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 68 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export(fixObjectsXML)
export(getXmlGuid)
export(isValidXML)
export(objectsXmlGuids)
export(removeBinGltfByLods)
export(removeLodNodesFromXML)
export(removeLods)
export(removeModelLibTexturesByLods)
export(updateSceneryFiles)
33 changes: 2 additions & 31 deletions R/BinGltf.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
#' Check .bin and .gltf Files
#'
#' @param xmlPath
#' @param nlods
#' @param nlods Numeric. Number of lods of the project.
#'
#' @return
#' @export
#'
#' @examples
checkFilesBinGltf <- function(xmlPath, nlods) {

# Tests
#xmlPath = xmlsDir[[1]]
#nlods = 3
#

id <- stringr::str_sub(basename(xmlPath), end = -5)
lods <- paste0("_LOD0", 0:(nlods-1))
gltfDir <- file.path(dirname(xmlPath), paste0(id, lods, ".gltf"))
Expand Down Expand Up @@ -46,7 +41,7 @@ checkFilesBinGltf <- function(xmlPath, nlods) {
#' Check multiple .bin and .gltf files
#'
#' @param modelLibDir
#' @param nlods
#' @param nlods Numeric. Number of lods of the project.
#'
#' @return
#' @export
Expand Down Expand Up @@ -117,27 +112,3 @@ fixBinGltf <- function(PackageSourcesDir, invalids, deleteTextures = TRUE) {

}

removeBinGltfByLods <- function(modelLibDir, lodsToRemove) {
# modelLibDir <- "D:/FSProjects/florianopolis-megapack/florianopolis-mega - Copia/PackageSources/modelLib"
lodsToRemoveF <- paste0("_LOD", lodsToRemove)
pattern <- paste0(
c(
paste0(lodsToRemoveF, ".bin"),
paste0(lodsToRemoveF, ".gltf")
),
collapse = "|"
)
filesToRemove <- list.files(modelLibDir, pattern = pattern, full.names = TRUE)
status <- file.remove(filesToRemove)
message(sum(status), " arquivos BIN/GLTF removidos (LODS ", paste(lodsToRemove, collapse = ", "), ")")
message("----------------------------")
}

removeModelLibTexturesByLods <- function(textureDir, lodsToRemove) {
# textureDir <- "D:/FSProjects/florianopolis-megapack/florianopolis-mega - Copia/PackageSources/modelLib/texture"
lodsToRemoveF <- paste0("_LOD", lodsToRemove, collapse = "|")
filesToRemove <- list.files(textureDir, pattern = lodsToRemoveF, full.names = TRUE)
status <- file.remove(filesToRemove)
message(sum(status), " texturas removidas (LODS ", paste(lodsToRemove, collapse = ", "), ")")
message("----------------------------")
}
10 changes: 0 additions & 10 deletions R/fixCorruptedFiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
#' @example
fixCorruptedFiles <- function(PackageSourcesDir, nlods, deleteTextures = TRUE) {

# Testes
# PackageSourcesDir <- "D:/FSProjects/florianopolis-megapack/florianopolis-mega/PackageSources"
# PackageSourcesDir <- "D:/FSProjects/rio-megateste/PackageSources"
# PackageSourcesDir <- "D:/FSProjects/florianopolis-megapack/florianopolis-part6/PackageSources"
#

modelLibDir <- file.path(PackageSourcesDir, "modelLib")

files <- dir(modelLibDir)
Expand Down Expand Up @@ -72,10 +66,6 @@ fixCorruptedFiles <- function(PackageSourcesDir, nlods, deleteTextures = TRUE) {
#' @export
isValidXML <- function(xmlPath, nlods) {

# Testes
#xmlPath = "D:/FSProjects/florianopolis-megapack/florianopolis-mega/PackageSources/modelLib/036173415260400522.xml"
#

lods <- checkLods(xmlPath)
files <- checkFilesBinGltf(xmlPath, nlods)

Expand Down
56 changes: 49 additions & 7 deletions R/lods.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,15 @@ fixLods <- function(PackageSourcesDir, invalids, deleteTextures = TRUE) {

#' Remove lods from project
#'
#' @param PackageSourcesDir
#' @param PackageSourcesDir Path to PackageSources directory.
#' @param lodsToRemove
#' A (character) vector with lods to remove.
#' Example: if you wan't to remove LOD01 and LOD02, provide a vector c("01", "02").
#' @param removeBinGltf Logical. Whether to remove correspondent .bin and .gltf files.
#' @param removeTextures Logical. Whether to remove correspondent texture files.
#'
#' @export
removeLods <- function(PackageSourcesDir, lodsToRemove, removeBinGltf = TRUE, removeTextures = TRUE) {
# PackageSourcesDir <- "D:/FSProjects/florianopolis-megapack/florianopolis-mega - Copia/PackageSources"
modelLibDir <- file.path(PackageSourcesDir, "modelLib")
xmlFiles <- list.files(modelLibDir, pattern = ".xml$", full.names = TRUE)

Expand All @@ -132,15 +135,13 @@ removeLods <- function(PackageSourcesDir, lodsToRemove, removeBinGltf = TRUE, re

#' Remove lod nodes from XML
#'
#' @param xmlPath
#' @param xmlPath Path of the xml file of the object.
#' @param lodsToRemove
#' @param removeBinGltf
#' @param removeTextures
#' A (character) vector with lods to remove.
#' Example: if you wan't to remove LOD01 and LOD02, provide a vector c("01", "02").
#'
#' @export
removeLodNodesFromXML <- function(xmlPath, lodsToRemove) {
# xmlPath <- "D:/FSProjects/florianopolis-megapack/florianopolis-mega - Copia/PackageSources/modelLib/03617341435360627.xml"
# lodsToRemove <- c("01", "02")
obj <- xml2::read_xml(xmlPath)
LibObjNodes <- xml2::xml_find_all(obj, "//LODS/LOD")
pattern <- paste0(paste0("_LOD", lodsToRemove, ".gltf\""), collapse = "|")
Expand All @@ -150,3 +151,44 @@ removeLodNodesFromXML <- function(xmlPath, lodsToRemove) {
file.remove(xmlPath)
xml2::write_xml(obj, xmlPath)
}

#' Remove .bin and .gltf by lods
#'
#' @param modelLibDir Path to modelLib directory.
#' @param lodsToRemove
#' A (character) vector with lods to remove.
#' Example: if you wan't to remove LOD01 and LOD02, provide a vector c("01", "02").
#'
#' @return
#' @export
removeBinGltfByLods <- function(modelLibDir, lodsToRemove) {
lodsToRemoveF <- paste0("_LOD", lodsToRemove)
pattern <- paste0(
c(
paste0(lodsToRemoveF, ".bin"),
paste0(lodsToRemoveF, ".gltf")
),
collapse = "|"
)
filesToRemove <- list.files(modelLibDir, pattern = pattern, full.names = TRUE)
status <- file.remove(filesToRemove)
message(sum(status), " arquivos BIN/GLTF removidos (LODS ", paste(lodsToRemove, collapse = ", "), ")")
message("----------------------------")
}

#' Remove textures by lods
#'
#' @param textureDir Path to modelLib/texture directory.
#' @param lodsToRemove
#' A (character) vector with lods to remove.
#' Example: if you wan't to remove LOD01 and LOD02, provide a vector c("01", "02").
#'
#' @return
#' @export
removeModelLibTexturesByLods <- function(textureDir, lodsToRemove) {
lodsToRemoveF <- paste0("_LOD", lodsToRemove, collapse = "|")
filesToRemove <- list.files(textureDir, pattern = lodsToRemoveF, full.names = TRUE)
status <- file.remove(filesToRemove)
message(sum(status), " texturas removidas (LODS ", paste(lodsToRemove, collapse = ", "), ")")
message("----------------------------")
}
12 changes: 0 additions & 12 deletions R/objectsXml.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
#' @export
fixObjectsXML <- function(xmlPath, invalidGuids, createBackup = FALSE) {

# Testes
# xmlPath <- "D:/FSProjects/florianopolis-megapack/florianopolis-mega/PackageSources/scene/objects.xml"
# xmlPath <- "D:/FSProjects/florianopolis-megapack/florianopolis-mega - Copia/PackageSources/scene/objects.xml"
#

obj <- xml2::read_xml(xmlPath)

if (isTRUE(createBackup)) {
Expand All @@ -21,13 +16,10 @@ fixObjectsXML <- function(xmlPath, invalidGuids, createBackup = FALSE) {
LibObjNodes <- xml2::xml_find_all(obj, "//SceneryObject/LibraryObject")
message(basename(xmlPath), " inicializado com ", length(LibObjNodes), " entradas")

#guidsIndex <- stringr::str_replace_all() xml2::xml_attr(LibObjNodes, attr = "name")
guidsIndex <- xml2::xml_attr(LibObjNodes, attr = "name")

nodesToRemove <- which(guidsIndex %in% paste0("{", invalidGuids, "}"))
# nodesToKeep <- which(!guidsIndex %in% paste0("{", invalidGuids, "}"))

# newObj <- xml2::xml_children(obj)[nodesToKeep]
message("Removendo ", length(nodesToRemove), " entradas inválidas")
xml2::xml_remove(xml2::xml_children(obj)[nodesToRemove])
message(length(nodesToRemove), " entradas inválidas removidas")
Expand Down Expand Up @@ -55,10 +47,6 @@ fixObjectsXML <- function(xmlPath, invalidGuids, createBackup = FALSE) {
#' }
objectsXmlGuids <- function(xmlPath){

# Tests
# xmlPath <- "D:/FSProjects/maceio/PackageSources/scene/objects.xml"
#

obj <- xml2::read_xml(xmlPath)

LibObjNodes <- xml2::xml_find_all(obj, "//SceneryObject/LibraryObject")
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ New function `removeLods` remove specific LODS from a project. It removes LOD en

##### New Functions

- `removeLods`:
- `removeLodNodesFromXML`:
- `removeBinGltfByLods`:
- `removeModelLibTexturesByLods`:
- `removeLods`: Remove lods from project.
- `removeLodNodesFromXML`: Remove lod nodes from XML.
- `removeBinGltfByLods`: Remove .bin and .gltf by lods.
- `removeModelLibTexturesByLods`: Remove textures by lods.


### Version 0.2.0
Expand Down
2 changes: 1 addition & 1 deletion man/checkAllFilesBinGltf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/checkFilesBinGltf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions man/removeBinGltfByLods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/removeLodNodesFromXML.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion man/removeLods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions man/removeModelLibTexturesByLods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1463b8a

Please sign in to comment.