Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Amrsatrio committed Aug 24, 2021
1 parent af99221 commit b1d5c76
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
16 changes: 15 additions & 1 deletion src/main/java/com/tb24/blenderumap/AssetUtils.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tb24.blenderumap

import me.fungames.jfortniteparse.ue4.assets.exports.UObject
import me.fungames.jfortniteparse.ue4.assets.objects.FPropertyTag
import me.fungames.jfortniteparse.ue4.assets.objects.IPropertyHolder
import java.lang.reflect.ParameterizedType
Expand Down Expand Up @@ -35,4 +36,17 @@ fun <T> IPropertyHolder.getProps(name: String, clazz: Class<T>): Array<T?> {
return out
}

inline fun <reified T> IPropertyHolder.getProps(name: String) = getProps(name, T::class.java)
inline fun <reified T> IPropertyHolder.getProps(name: String) = getProps(name, T::class.java)

inline fun <reified T> UObject.getOrNullTraversing(name: String): T? {
var current = this
while (true) {
val value = current.getOrNull<T>(name)
if (value != null) {
//if (current != this) LOGGER.debug("{}.getOrNullTraversing(\"{}\") found value in {}", this.name, name, current.getPathName())
return value
}
current = current.template?.value ?: break
}
return null
}
25 changes: 8 additions & 17 deletions src/main/java/com/tb24/blenderumap/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.google.gson.reflect.TypeToken
import com.tb24.blenderumap.JWPSerializer.GSON
import me.fungames.jfortniteparse.fort.exports.BuildingTextureData
import me.fungames.jfortniteparse.ue4.assets.Package
import me.fungames.jfortniteparse.ue4.assets.exports.UBlueprintGeneratedClass
import me.fungames.jfortniteparse.ue4.assets.exports.UObject
import me.fungames.jfortniteparse.ue4.assets.exports.UStaticMesh
import me.fungames.jfortniteparse.ue4.assets.exports.UWorld
Expand Down Expand Up @@ -40,16 +39,16 @@ import java.util.*
import javax.imageio.ImageIO
import kotlin.system.exitProcess

private val LOGGER = LoggerFactory.getLogger("BlenderUmap")
@JvmField val LOGGER = LoggerFactory.getLogger("BlenderUmap")
private lateinit var config: Config
private lateinit var provider: MyFileProvider
private val start = System.currentTimeMillis()

fun main() {
fun main(args: Array<String>) {
try {
val configFile = File("config.json")
val configFile = File(args.getOrNull(0) ?: "config.json")
if (!configFile.exists()) {
LOGGER.error("config.json not found")
LOGGER.error(configFile.name + " not found")
return
}
LOGGER.info("Reading config file " + configFile.absolutePath)
Expand Down Expand Up @@ -121,16 +120,7 @@ private fun exportAndProduceProcessed(path: String): Package? {
comp.add(guid?.toString()?.lowercase() ?: UUID.randomUUID().toString().replace("-", ""))
comp.add(actor.name)

// region mesh
var staticMeshLazy = staticMeshComponent.getOrNull<Lazy<UStaticMesh>>("StaticMesh") // /Script/Engine.StaticMeshComponent:StaticMesh
if (staticMeshLazy == null) { // read the actor class to find the mesh
val actorBlueprint = actor.clazz
if (actorBlueprint is UBlueprintGeneratedClass) {
staticMeshLazy = actorBlueprint.owner!!.exports.firstNotNullOfOrNull { it.getOrNull<Lazy<UStaticMesh>>("StaticMesh") }
}
}
// endregion

val staticMeshLazy = staticMeshComponent.getOrNullTraversing<Lazy<UStaticMesh>>("StaticMesh") // /Script/Engine.StaticMeshComponent:StaticMesh
val matsObj = JsonObject()
val textureDataArr = JsonArray()
val materials = mutableListOf<Mat>()
Expand Down Expand Up @@ -293,8 +283,9 @@ private class Mat(var material: Lazy<UMaterialInterface>?) {
val material = lazy.value as? UMaterialInstance ?: return
material.TextureParameterValues?.forEach {
val name = it.ParameterInfo.Name ?: FName.NAME_None
if (name.text !in textureMap) {
textureMap[name.text] = it.ParameterValue
val value = it.ParameterValue
if (value != null && name.text !in textureMap) {
textureMap[name.text] = value
}
}
material.Parent?.let(::populateTextures)
Expand Down

0 comments on commit b1d5c76

Please sign in to comment.