-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6676510
commit eb5455b
Showing
8 changed files
with
152 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package gltfrenzy.loader; | ||
|
||
import arc.assets.*; | ||
import arc.assets.loaders.*; | ||
import arc.files.*; | ||
import arc.struct.*; | ||
import gltfrenzy.loader.NodeLoader.*; | ||
import gltfrenzy.loader.Scenes3DLoader.*; | ||
import gltfrenzy.model.*; | ||
|
||
/** | ||
* Convenience loader to automatically fetch a mesh by-name from a {@link Scenes3D}. | ||
* @author GlennFolker | ||
*/ | ||
public class NodeLoader extends SynchronousAssetLoader<Node, NodeParameter>{ | ||
public NodeLoader(FileHandleResolver resolver){ | ||
super(resolver); | ||
} | ||
|
||
@Override | ||
public Node load(AssetManager manager, String fileName, Fi file, NodeParameter parameter){ | ||
int hash = fileName.indexOf('#'); | ||
if(hash == -1) throw new IllegalArgumentException("Invalid file name '" + fileName + "', expected 'path/to/model#node-name'"); | ||
|
||
var sceneName = fileName.substring(0, hash); | ||
var scenes = manager.get(sceneName, Scenes3D.class); | ||
var target = fileName.substring(hash + 1); | ||
|
||
return scenes.nodeNames.getThrow(target, () -> new IllegalArgumentException("Node '" + target + "' not found in '" + sceneName + "'.")); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("rawtypes") | ||
public Seq<AssetDescriptor> getDependencies(String fileName, Fi file, NodeParameter parameter){ | ||
int hash = fileName.indexOf('#'); | ||
if(hash == -1) throw new IllegalArgumentException("Invalid file name '" + fileName + "', expected 'path/to/model#node-name'"); | ||
|
||
return Seq.with(new AssetDescriptor<>(resolve(fileName.substring(0, hash)), Scenes3D.class, parameter == null ? null : parameter.sceneParameter)); | ||
} | ||
|
||
public static class NodeParameter extends AssetLoaderParameters<Node>{ | ||
public Scenes3DParameter sceneParameter; | ||
|
||
public NodeParameter(){ | ||
this(null); | ||
} | ||
|
||
public NodeParameter(Scenes3DParameter sceneParameter){ | ||
this.sceneParameter = sceneParameter; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package gltfrenzy.model; | ||
|
||
import arc.math.geom.*; | ||
import arc.struct.*; | ||
import arc.util.*; | ||
|
||
/** | ||
* Defines an object node in the hierarchy tree. Children of this node inherits its transform. | ||
* @author GlennFolker | ||
*/ | ||
public class Node{ | ||
private static final Mat3D mat = new Mat3D(); | ||
|
||
public String name = ""; | ||
public final Seq<Node> children = new Seq<>(); | ||
public @Nullable Node parent; | ||
|
||
public final Transform localTrns = new Transform(); | ||
public final Mat3D globalTrns = new Mat3D(); | ||
|
||
public MeshSet mesh; | ||
|
||
public void update(){ | ||
if(parent != null){ | ||
globalTrns.set(parent.globalTrns).mul(localTrns.matrix(mat)); | ||
}else{ | ||
localTrns.matrix(globalTrns); | ||
} | ||
|
||
children.each(Node::update); | ||
} | ||
|
||
public static class Transform{ | ||
public final Vec3 translation = new Vec3(); | ||
public final Quat rotation = new Quat(); | ||
public final Vec3 scale = new Vec3(1f, 1f, 1f); | ||
|
||
public Transform set(Transform from){ | ||
translation.set(from.translation); | ||
rotation.set(from.rotation); | ||
scale.set(from.scale); | ||
return this; | ||
} | ||
|
||
public Mat3D matrix(Mat3D out){ | ||
return out.set(translation, rotation, scale); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters