-
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
0d1dd2d
commit 269abcf
Showing
15 changed files
with
695 additions
and
51 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,6 @@ | ||
before_install: | ||
- sdk install java 21.0.1-tem | ||
- sdk use java 21.0.1-tem | ||
install: | ||
- ./gradlew publishToMavenLocal | ||
- echo -n > gradle.properties |
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,138 @@ | ||
package gltfrenzy.io; | ||
|
||
import java.io.*; | ||
|
||
/** | ||
* A little-endian {@link DataInputStream}. | ||
* @author GlennFolker | ||
*/ | ||
public class LEDataInputStream extends InputStream implements DataInput{ | ||
private final byte[] buffer = new byte[8]; | ||
private final DataInputStream read; | ||
|
||
public LEDataInputStream(InputStream in){ | ||
read = new DataInputStream(in); | ||
} | ||
|
||
@Override | ||
public int available() throws IOException{ | ||
return read.available(); | ||
} | ||
|
||
@Override | ||
public final short readShort() throws IOException{ | ||
read.readFully(buffer, 0, 2); | ||
return (short)( | ||
(buffer[1] & 0xff) << 8 | | ||
(buffer[0] & 0xff) | ||
); | ||
} | ||
|
||
@Override | ||
public final int readUnsignedShort() throws IOException{ | ||
read.readFully(buffer, 0, 2); | ||
return ( | ||
(buffer[1] & 0xff) << 8 | | ||
(buffer[0] & 0xff) | ||
); | ||
} | ||
|
||
@Override | ||
public final char readChar() throws IOException{ | ||
read.readFully(buffer, 0, 2); | ||
return (char)( | ||
(buffer[1] & 0xff) << 8 | | ||
(buffer[0] & 0xff) | ||
); | ||
} | ||
|
||
@Override | ||
public final int readInt() throws IOException{ | ||
read.readFully(buffer, 0, 4); | ||
return | ||
(buffer[3]) << 24 | | ||
(buffer[2] & 0xff) << 16 | | ||
(buffer[1] & 0xff) << 8 | | ||
(buffer[0] & 0xff); | ||
} | ||
|
||
@Override | ||
public final long readLong() throws IOException{ | ||
read.readFully(buffer, 0, 8); | ||
return | ||
(long)(buffer[7]) << 56 | | ||
(long)(buffer[6] & 0xff) << 48 | | ||
(long)(buffer[5] & 0xff) << 40 | | ||
(long)(buffer[4] & 0xff) << 32 | | ||
(long)(buffer[3] & 0xff) << 24 | | ||
(long)(buffer[2] & 0xff) << 16 | | ||
(long)(buffer[1] & 0xff) << 8 | | ||
(long)(buffer[0] & 0xff); | ||
} | ||
|
||
@Override | ||
public final float readFloat() throws IOException{ | ||
return Float.intBitsToFloat(readInt()); | ||
} | ||
|
||
@Override | ||
public final double readDouble() throws IOException{ | ||
return Double.longBitsToDouble(readLong()); | ||
} | ||
|
||
@Override | ||
public final int read(byte[] b, int off, int len) throws IOException{ | ||
return read.read(b, off, len); | ||
} | ||
|
||
@Override | ||
public final void readFully(byte[] b) throws IOException{ | ||
read.readFully(b, 0, b.length); | ||
} | ||
|
||
@Override | ||
public final void readFully(byte[] b, int off, int len) throws IOException{ | ||
read.readFully(b, off, len); | ||
} | ||
|
||
@Override | ||
public final int skipBytes(int n) throws IOException{ | ||
return read.skipBytes(n); | ||
} | ||
|
||
@Override | ||
public final boolean readBoolean() throws IOException{ | ||
return read.readBoolean(); | ||
} | ||
|
||
@Override | ||
public final byte readByte() throws IOException{ | ||
return read.readByte(); | ||
} | ||
|
||
@Override | ||
public int read() throws IOException{ | ||
return read.read(); | ||
} | ||
|
||
@Override | ||
public final int readUnsignedByte() throws IOException{ | ||
return read.readUnsignedByte(); | ||
} | ||
|
||
@Override | ||
@Deprecated | ||
public final String readLine() throws IOException{ | ||
return read.readLine(); | ||
} | ||
|
||
@Override | ||
public final String readUTF() throws IOException{ | ||
return read.readUTF(); | ||
} | ||
|
||
@Override | ||
public final void close() throws IOException{ | ||
read.close(); | ||
} | ||
} |
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,61 @@ | ||
package gltfrenzy.loader; | ||
|
||
import arc.files.*; | ||
import arc.util.io.*; | ||
import arc.util.serialization.*; | ||
import gltfrenzy.data.*; | ||
import gltfrenzy.io.*; | ||
|
||
import java.io.*; | ||
import java.nio.*; | ||
import java.nio.charset.*; | ||
|
||
/** | ||
* Reader implementation for {@code .glb} monolithic binary file. | ||
* @author GlennFolker | ||
*/ | ||
public class GlbReader implements Scenes3DReader{ | ||
@Override | ||
public Scenes3DData read(Fi file) throws IOException{ | ||
try(var stream = new CounterInputStream(file.read()); | ||
var read = new LEDataInputStream(stream); | ||
){ | ||
int fileLen = readHeader(read); | ||
|
||
var data = new Scenes3DData(); | ||
for(int i = 0; stream.count < fileLen; i++){ | ||
byte[] chunk = new byte[read.readInt()]; | ||
int chunkType = read.readInt(); | ||
|
||
read.readFully(chunk); | ||
switch(chunkType){ | ||
case 0x4e4f534a -> { | ||
if(i != 0) throw new IOException("JSON chunk found at index " + i + "."); | ||
data.spec = Gltf.create(Jval.read(new String(chunk, StandardCharsets.UTF_8))); | ||
data.buffers = new ByteBuffer[data.spec.buffers.length]; | ||
} | ||
case 0x004e4942 -> { | ||
if(i != 1) throw new IOException("BIN chunk found at index " + i); | ||
var buffer = data.buffers[0] = ByteBuffer.wrap(chunk); | ||
buffer.order(ByteOrder.LITTLE_ENDIAN); | ||
} | ||
default -> { | ||
if(i == 0) throw new IOException("Custom chunk found at index 0."); | ||
} | ||
} | ||
} | ||
|
||
return data; | ||
} | ||
} | ||
|
||
protected int readHeader(DataInput read) throws IOException{ | ||
int magic = read.readInt(); | ||
if(magic != 0x46546c67) throw new IOException("Invalid header 0x" + Integer.toHexString(magic) + "."); | ||
|
||
int version = read.readInt(); | ||
if(version != 2) throw new IOException("Unsupported container version " + version + "."); | ||
|
||
return read.readInt(); | ||
} | ||
} |
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,36 @@ | ||
package gltfrenzy.loader; | ||
|
||
import arc.files.*; | ||
import arc.util.serialization.*; | ||
import gltfrenzy.data.*; | ||
|
||
import java.io.*; | ||
import java.nio.*; | ||
|
||
/** | ||
* Reader implementation for {@code .gltf} textual file. | ||
* @author GlennFolker | ||
*/ | ||
public class GltfReader implements Scenes3DReader{ | ||
@Override | ||
public Scenes3DData read(Fi file) throws IOException{ | ||
try(var reader = file.reader("UTF-8")){ | ||
int len = (int)file.length(); | ||
len = len == 0 ? 4096 : len; | ||
|
||
var builder = new StringBuilder(len); | ||
char[] buffer = new char[len]; | ||
while(true){ | ||
int read = reader.read(buffer); | ||
if(read == -1) break; | ||
|
||
builder.append(buffer, 0, read); | ||
} | ||
|
||
var data = new Scenes3DData(); | ||
data.spec = Gltf.create(Jval.read(builder.toString())); | ||
data.buffers = new ByteBuffer[data.spec.buffers.length]; | ||
return data; | ||
} | ||
} | ||
} |
Oops, something went wrong.