Skip to content

Commit

Permalink
update PPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
Deficuet authored and Deficuet committed Jan 8, 2024
1 parent 78b4085 commit 76631dc
Show file tree
Hide file tree
Showing 39 changed files with 80 additions and 66 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ All the C++ code used to decode texture compression come from [AssetStudio/Textu
- UnityAssetManager
- The entry point of loading object. It contains all objects read from all files that are loaded through it, except `AssetBundle` objects.
- Use `UnityAssetManager.new(...)` with two parameters `assetRootFolder` and `readerConfig` to get an instance.
- `assetRootFolder` is optional and it can be a `java.io.File`, `java.nio.file.Path` or just a `String`. When present, it will be used by `PPtr` to look for object according to the `mDependencies` property in the `AssetBundle` object of the file.
- `assetRootFolder` is optional and it can be a `java.io.File`, `java.nio.file.Path` or just a `String`. When present, it will be used by `PPtr` to look for object according to the `mDependencies` in the `AssetBundle` object of the file.
- `readerConfig` is the loading configuration and is also optional.
- Loading Configurations
- When loading file(s)/folder/ByteArray, an optional `ReaderConfig` can also be passed to override the configuration given to the manager, or the configuration given to the manager will be used by default.
Expand All @@ -43,7 +43,7 @@ All the C++ code used to decode texture compression come from [AssetStudio/Textu
- e.g. Its `assetFile` which is a `SerializedFile`, `mPathID`, `unityVersion`, etc. Those are the fields enclosed in the metadata region. See [UnityObject class](https://github.com/Deficuet/UnityKt/blob/main/src/main/kotlin/io/github/deficuet/unitykt/classes/UnityObject.kt).
- Shortcuts
- See [utils.kt](https://github.com/Deficuet/UnityKt/blob/main/src/main/kotlin/io/github/deficuet/unitykt/utils.kt) and [PPtr.kt](https://github.com/Deficuet/UnityKt/blob/main/src/main/kotlin/io/github/deficuet/unitykt/classes/PPtr.kt)
- Should always use `PPtr<O>.safeGetObj()` or `PPtr<O>.getObj()` to get the object, or use `PPtr<*>.safeGetObjAs<T: UnityObject>()` to get and cast.
- Should always use `PPtr<T>.safeGetObj()` or `PPtr<T>.getObj()` to get the object, or use `PPtr<*>.safeGetObjAs<T: UnityObject>()` to get and cast.

## Export
So far the objects that can export data includes:
Expand Down Expand Up @@ -159,7 +159,7 @@ fun main() {
// Then it will look for the file under the directory "C:/path/to/asset/system/root/folder" which was
// given to the manager. The file name comes from the mDependecies property of the AssetBundle object
// in the same file as this Material object being in. The target file will be loaded using the same
// reader config passed to the manager. Finally, PPtr will try to find the object in the new loaded file.
// reader config passed to the manager. Finally, PPtr will try to find the object in the new loaded files.
?.safeCast<Texture2D>()?.getImage()?.let { image ->
ImageIO.write(image, "png", File("C:/whatever/you/want/name.png"))
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'io.github.deficuet'
version '0.1.0_alpha.7'
version '0.1.0_alpha.8'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.deficuet.unitykt.internal.impl;

import io.github.deficuet.unitykt.classes.AnimationClip;
import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.pptr.PPtr;
import org.jetbrains.annotations.NotNull;

abstract class AnimationFields extends BehaviourImpl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import io.github.deficuet.unitykt.classes.AnimationClip;
import io.github.deficuet.unitykt.classes.ControllerConstant;
import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.pptr.PPtr;
import kotlin.UInt;
import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.deficuet.unitykt.internal.impl;

import io.github.deficuet.unitykt.classes.Avatar;
import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.classes.RuntimeAnimatorController;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.pptr.PPtr;
import org.jetbrains.annotations.NotNull;

abstract class AnimatorFields extends BehaviourImpl {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.deficuet.unitykt.internal.impl;

import io.github.deficuet.unitykt.classes.AnimationClipOverride;
import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.classes.RuntimeAnimatorController;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.pptr.PPtr;
import org.jetbrains.annotations.NotNull;

abstract class AnimatorOverrideControllerFields extends RuntimeAnimatorControllerImpl {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.deficuet.unitykt.internal.impl;

import io.github.deficuet.unitykt.classes.AssetInfo;
import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.classes.UnityObject;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.pptr.PPtr;
import kotlin.UInt;
import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.deficuet.unitykt.internal.impl;

import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.classes.UnityObject;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.pptr.PPtr;
import org.jetbrains.annotations.NotNull;

abstract class CanvasFields extends BehaviourImpl {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.deficuet.unitykt.internal.impl;

import io.github.deficuet.unitykt.classes.GameObject;
import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.pptr.PPtr;
import org.jetbrains.annotations.NotNull;

abstract class ComponentFields extends EditorExtensionImpl {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.deficuet.unitykt.internal.impl;

import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.classes.Shader;
import io.github.deficuet.unitykt.classes.UnityPropertySheet;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.pptr.PPtr;
import org.jetbrains.annotations.NotNull;

abstract class MaterialFields extends NamedObjectImpl {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.deficuet.unitykt.internal.impl;

import io.github.deficuet.unitykt.classes.Mesh;
import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.pptr.PPtr;
import org.jetbrains.annotations.NotNull;

abstract class MeshFilterFields extends ComponentImpl{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.deficuet.unitykt.internal.impl;

import io.github.deficuet.unitykt.classes.MonoScript;
import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.pptr.PPtr;
import org.jetbrains.annotations.NotNull;

abstract class MonoBehaviourFields extends BehaviourImpl {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.deficuet.unitykt.internal.impl;

import io.github.deficuet.unitykt.classes.AudioClip;
import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.pptr.PPtr;
import org.jetbrains.annotations.NotNull;

abstract class MovieTextureFields extends TextureImpl {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.deficuet.unitykt.internal.impl;

import io.github.deficuet.unitykt.classes.Material;
import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.classes.StaticBatchInfo;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.pptr.PPtr;
import kotlin.UInt;
import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.deficuet.unitykt.internal.impl;

import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.classes.UnityObject;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.pptr.PPtr;
import org.jetbrains.annotations.NotNull;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.deficuet.unitykt.internal.impl;

import io.github.deficuet.unitykt.classes.Mesh;
import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.classes.Transform;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.pptr.PPtr;
import org.jetbrains.annotations.NotNull;

abstract class SkinnedMeshRendererFields extends RendererImpl {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.deficuet.unitykt.internal.impl;

import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.classes.SpriteAtlas;
import io.github.deficuet.unitykt.classes.SpriteRenderData;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.math.Rectangle;
import io.github.deficuet.unitykt.math.Vector2;
import io.github.deficuet.unitykt.math.Vector4;
import io.github.deficuet.unitykt.pptr.PPtr;
import kotlin.Pair;
import kotlin.UInt;
import org.jetbrains.annotations.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.deficuet.unitykt.internal.impl;

import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.classes.Transform;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.math.Quaternion;
import io.github.deficuet.unitykt.math.Vector3;
import io.github.deficuet.unitykt.pptr.PPtr;
import org.jetbrains.annotations.NotNull;

abstract class TransformFields extends ComponentImpl {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.deficuet.unitykt.internal.impl;

import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.classes.Shader;
import io.github.deficuet.unitykt.classes.StreamedResource;
import io.github.deficuet.unitykt.internal.file.ObjectInfo;
import io.github.deficuet.unitykt.internal.file.SerializedFile;
import io.github.deficuet.unitykt.pptr.PPtr;
import io.github.deficuet.unitykt.util.ResourceReader;
import kotlin.UInt;
import kotlin.ULong;
Expand Down
15 changes: 8 additions & 7 deletions src/main/kotlin/io/github/deficuet/unitykt/UnityAssetManager.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package io.github.deficuet.unitykt

import io.github.deficuet.unitykt.classes.AssetBundle
import io.github.deficuet.unitykt.pptr.PPtr
import io.github.deficuet.unitykt.classes.UnityObject
import io.github.deficuet.unitykt.internal.UnityAssetManagerImpl
import io.github.deficuet.unitykt.pptr.PPtr
import java.io.Closeable
import java.io.File
import java.nio.file.Path
import kotlin.io.path.isDirectory

interface UnityAssetManager: Closeable {
val assetRootFolder: File?
val assetRootFolder: Path?
val defaultReaderConfig: ReaderConfig

/**
Expand Down Expand Up @@ -116,15 +117,15 @@ interface UnityAssetManager: Closeable {
/**
* @see new
*/
fun new(assetRootFolder: Path, readerConfig: ReaderConfig = ReaderConfig.default): UnityAssetManager {
return new(assetRootFolder.toFile(), readerConfig)
fun new(assetRootFolder: File, readerConfig: ReaderConfig = ReaderConfig.default): UnityAssetManager {
return new(assetRootFolder.toPath(), readerConfig)
}
/**
* @see new
*/
fun new(assetRootFolder: File, readerConfig: ReaderConfig = ReaderConfig.default): UnityAssetManager {
if (!assetRootFolder.isDirectory) {
throw IllegalArgumentException("${assetRootFolder.path} is not a valid folder")
fun new(assetRootFolder: Path, readerConfig: ReaderConfig = ReaderConfig.default): UnityAssetManager {
if (!assetRootFolder.isDirectory()) {
throw IllegalArgumentException("$assetRootFolder is not a valid folder")
}
return UnityAssetManagerImpl(assetRootFolder, readerConfig)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import kotlin.io.path.isDirectory
import kotlin.io.path.isRegularFile

internal class UnityAssetManagerImpl(
override val assetRootFolder: File?,
override val assetRootFolder: Path?,
override val defaultReaderConfig: ReaderConfig
): UnityAssetManager {
init { UnityAssetManager.managers.add(this) }
Expand Down Expand Up @@ -64,8 +64,7 @@ internal class UnityAssetManagerImpl(
override fun loadFolder(folder: Path, config: ReaderConfig): Array<ImportContext> {
if (!folder.isDirectory()) throw IllegalArgumentException("parameter \"folder\" must be a directory")
val files = Files.newDirectoryStream(folder).use { stream ->
stream.filter { it.isRegularFile() }
.toTypedArray()
stream.filter { it.isRegularFile() }.toTypedArray()
}
return loadFiles(*files, config = config)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package io.github.deficuet.unitykt.internal.impl

import io.github.deficuet.unitykt.classes.Animation
import io.github.deficuet.unitykt.classes.AnimationClip
import io.github.deficuet.unitykt.pptr.PPtr
import io.github.deficuet.unitykt.internal.file.ObjectInfo
import io.github.deficuet.unitykt.internal.file.SerializedFile
import io.github.deficuet.unitykt.pptr.PPtr
import io.github.deficuet.unitykt.util.readArrayOf

internal class AnimationImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package io.github.deficuet.unitykt.internal.impl

import io.github.deficuet.unitykt.classes.Animator
import io.github.deficuet.unitykt.classes.Avatar
import io.github.deficuet.unitykt.pptr.PPtr
import io.github.deficuet.unitykt.classes.RuntimeAnimatorController
import io.github.deficuet.unitykt.internal.file.ObjectInfo
import io.github.deficuet.unitykt.internal.file.SerializedFile
import io.github.deficuet.unitykt.pptr.PPtr
import io.github.deficuet.unitykt.util.compareTo

internal class AnimatorImpl(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.github.deficuet.unitykt.internal.impl

import io.github.deficuet.unitykt.classes.*
import io.github.deficuet.unitykt.classes.AnimationClip
import io.github.deficuet.unitykt.classes.AnimationClipOverride
import io.github.deficuet.unitykt.classes.AnimatorOverrideController
import io.github.deficuet.unitykt.classes.RuntimeAnimatorController
import io.github.deficuet.unitykt.internal.file.ObjectInfo
import io.github.deficuet.unitykt.internal.file.SerializedFile
import io.github.deficuet.unitykt.pptr.PPtr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package io.github.deficuet.unitykt.internal.impl

import io.github.deficuet.unitykt.classes.AssetBundle
import io.github.deficuet.unitykt.classes.AssetInfo
import io.github.deficuet.unitykt.pptr.PPtr
import io.github.deficuet.unitykt.classes.UnityObject
import io.github.deficuet.unitykt.internal.file.ObjectInfo
import io.github.deficuet.unitykt.internal.file.SerializedFile
import io.github.deficuet.unitykt.pptr.PPtr
import io.github.deficuet.unitykt.util.ObjectReader
import io.github.deficuet.unitykt.util.compareTo
import io.github.deficuet.unitykt.util.readArrayOf
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.deficuet.unitykt.internal.impl

import io.github.deficuet.unitykt.classes.Canvas
import io.github.deficuet.unitykt.pptr.PPtr
import io.github.deficuet.unitykt.classes.UnityObject
import io.github.deficuet.unitykt.internal.file.ObjectInfo
import io.github.deficuet.unitykt.internal.file.SerializedFile
import io.github.deficuet.unitykt.pptr.PPtr

internal class CanvasImpl(
assetFile: SerializedFile, info: ObjectInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package io.github.deficuet.unitykt.internal.impl

import io.github.deficuet.unitykt.classes.Component
import io.github.deficuet.unitykt.classes.GameObject
import io.github.deficuet.unitykt.pptr.PPtr
import io.github.deficuet.unitykt.internal.file.ObjectInfo
import io.github.deficuet.unitykt.internal.file.SerializedFile
import io.github.deficuet.unitykt.pptr.PPtr

internal abstract class ComponentImpl(
assetFile: SerializedFile, info: ObjectInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package io.github.deficuet.unitykt.internal.impl

import io.github.deficuet.unitykt.classes.Mesh
import io.github.deficuet.unitykt.classes.MeshFilter
import io.github.deficuet.unitykt.pptr.PPtr
import io.github.deficuet.unitykt.internal.file.ObjectInfo
import io.github.deficuet.unitykt.internal.file.SerializedFile
import io.github.deficuet.unitykt.pptr.PPtr

internal class MeshFilterImpl(
assetFile: SerializedFile, info: ObjectInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package io.github.deficuet.unitykt.internal.impl

import io.github.deficuet.unitykt.classes.MonoBehaviour
import io.github.deficuet.unitykt.classes.MonoScript
import io.github.deficuet.unitykt.pptr.PPtr
import io.github.deficuet.unitykt.internal.file.ObjectInfo
import io.github.deficuet.unitykt.internal.file.SerializedFile
import io.github.deficuet.unitykt.pptr.PPtr

internal class MonoBehaviourImpl(
assetFile: SerializedFile, info: ObjectInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package io.github.deficuet.unitykt.internal.impl

import io.github.deficuet.unitykt.classes.AudioClip
import io.github.deficuet.unitykt.classes.MovieTexture
import io.github.deficuet.unitykt.pptr.PPtr
import io.github.deficuet.unitykt.internal.file.ObjectInfo
import io.github.deficuet.unitykt.internal.file.SerializedFile
import io.github.deficuet.unitykt.pptr.PPtr

internal class MovieTextureImpl(
assetFile: SerializedFile, info: ObjectInfo
Expand Down
Loading

0 comments on commit 76631dc

Please sign in to comment.