private static FbxElement readFBXElement(ByteBuffer byteBuffer) throws IOException { long endOffset = getUInt(byteBuffer); if(endOffset == 0) return null; long propCount = getUInt(byteBuffer); getUInt(byteBuffer); // Properties length unused FbxElement element = new FbxElement((int) propCount); element.id = new String(getBytes(byteBuffer, getUByte(byteBuffer))); for(int i = 0; i < propCount; ++i) { char dataType = readDataType(byteBuffer); element.properties.add(readData(byteBuffer, dataType)); element.propertiesTypes[i] = dataType; } if(byteBuffer.position() < endOffset) { while(byteBuffer.position() < (endOffset - BLOCK_SENTINEL_LENGTH)) element.children.add(readFBXElement(byteBuffer)); if(!Arrays.equals(BLOCK_SENTINEL_DATA, getBytes(byteBuffer, BLOCK_SENTINEL_LENGTH))) throw new IOException("Failed to read block sentinel, expected 13 zero bytes"); } if(byteBuffer.position() != endOffset) throw new IOException("Data length not equal to expected"); return element; }
public static FbxFile readFBX(InputStream stream) throws IOException { FbxFile fbxFile = new FbxFile(); // Read file to byte buffer so we can know current position in file ByteBuffer byteBuffer = readToByteBuffer(stream); try { stream.close(); } catch(IOException e) { } // Check majic header byte[] majic = getBytes(byteBuffer, HEAD_MAGIC.length); if(!Arrays.equals(HEAD_MAGIC, majic)) throw new IOException("Either ASCII FBX or corrupt file. " + "Only binary FBX files are supported"); // Read version fbxFile.version = getUInt(byteBuffer); // Read root elements while(true) { FbxElement e = readFBXElement(byteBuffer); if(e == null) break; fbxFile.rootElements.add(e); } return fbxFile; }
private static FbxElement readFBXElement(ByteBuffer byteBuffer) throws IOException { long endOffset = getUInt(byteBuffer); if(endOffset == 0) return null; long propCount = getUInt(byteBuffer); getUInt(byteBuffer); // Properties length unused FbxElement element = new FbxElement((int) propCount); element.id = new String(getBytes(byteBuffer, getUByte(byteBuffer))); for(int i = 0; i < propCount; ++i) { char dataType = readDataType(byteBuffer); element.properties.add(readData(byteBuffer, dataType)); element.propertiesTypes[i] = dataType; } if(byteBuffer.position() < endOffset) { while(byteBuffer.position() < (endOffset - BLOCK_SENTINEL_LENGTH)) element.children.add(readFBXElement(byteBuffer)); if(!Arrays.equals(BLOCK_SENTINEL_DATA, getBytes(byteBuffer, BLOCK_SENTINEL_LENGTH))) throw new IOException("Failed to read block sentinel, expected 13 zero bytes"); } if(byteBuffer.position() != endOffset) throw new IOException("Data length not equal to expected"); return element; }
public static FbxFile readFBX(InputStream stream) throws IOException { FbxFile fbxFile = new FbxFile(); // Read file to byte buffer so we can know current position in file ByteBuffer byteBuffer = readToByteBuffer(stream); try { stream.close(); } catch(IOException e) { } // Check majic header byte[] majic = getBytes(byteBuffer, HEAD_MAGIC.length); if(!Arrays.equals(HEAD_MAGIC, majic)) throw new IOException("Either ASCII FBX or corrupt file. " + "Only binary FBX files are supported"); // Read version fbxFile.version = getUInt(byteBuffer); // Read root elements while(true) { FbxElement e = readFBXElement(byteBuffer); if(e == null) break; fbxFile.rootElements.add(e); } return fbxFile; }