Package info.ata4.io

Examples of info.ata4.io.DataInputReader


        ByteBuffer vertexBuffer = mesh.vertexData.dataSize;
        vertexBuffer.order(ByteOrder.LITTLE_ENDIAN);
       
        L.log(Level.FINE, "Vertex buffer size: {0}", vertexBuffer.capacity());

        DataInputReader in = DataInputReader.newReader(vertexBuffer);

        List<StreamInfo> streams = mesh.vertexData.streams;
        List<ChannelInfo> channels = mesh.vertexData.channels;
       
        for (StreamInfo stream : streams) {
            // skip empty channels
            if (stream.channelMask.longValue() == 0) {
                continue;
            }

            vertexBuffer.position(stream.offset.intValue());

            // read vertex data from each vertex and channel
            for (int i = 0; i < mesh.vertexData.vertexCount; i++) {
                for (int j = 0; j < CHANNEL_COUNT; j++) {
                    // skip unselected channels
                    if ((stream.channelMask.longValue() & 1 << j) == 0) {
                        continue;
                    }
                   
                    boolean half = false;
                    ChannelInfo channel = null;

                    // channels may not be available in older versions
                    if (!channels.isEmpty()) {
                        channel = channels.get(j);
                        half = channel.format == 1;
                    }

                    switch (j) {
                        case CHANNEL_VERTS:
                            Vector3f v = new Vector3f();
                            v.setHalf(half);
                            v.read(in);
                            vertices.add(v);
                            break;

                        case CHANNEL_NORMALS:
                            Vector3f vn = new Vector3f();
                            vn.setHalf(half);
                            vn.read(in);
                            normals.add(vn);
                            if (half && channel != null && channel.dimension == 4) {
                                in.skipBytes(2); // padding?
                            }
                            break;

                        case CHANNEL_COLORS:
                            Color32 c = new Color32();
                            c.read(in);
                            colors.add(c);
                            break;

                        case CHANNEL_UV1:
                        case CHANNEL_UV2:
                            Vector2f vt = new Vector2f();
                            vt.setHalf(half);
                            vt.read(in);
                            if (j == CHANNEL_UV1) {
                                uv1.add(vt);
                            } else {
                                uv2.add(vt);
                            }
                            break;

                        case CHANNEL_TANGENTS:
                            Vector4f t = new Vector4f();
                            t.setHalf(half);
                            t.read(in);
                            tangents.add(t);
                            break;
                    }
                }
               
                in.align(stream.stride.intValue());
            }
        }
    }
View Full Code Here


        }
    }

    private void readIndexBuffer() throws IOException {
        mesh.indexBuffer.order(ByteOrder.LITTLE_ENDIAN);
        DataInputReader in = DataInputReader.newReader(mesh.indexBuffer);

        for (SubMesh subMesh : mesh.subMeshes) {
            List<Integer> subMeshIndices = new ArrayList<>();
            List<Integer> subMeshTriangles = new ArrayList<>();
           
            in.position(subMesh.firstByte.longValue());
            for (long j = 0; j < subMesh.indexCount.longValue(); j++) {
                subMeshIndices.add(in.readUnsignedShort());
            }
           
            // read triangle strips if topology/isTriStrip is not zero
            if (subMesh.topology.longValue() == 0) {
                // use indices as is
View Full Code Here

            L.log(Level.SEVERE, "Can't open struct database", ex);
            return;
        }

        try (BufferedInputStream bis = new BufferedInputStream(is)) {
            DataInputReader in = DataInputReader.newReader(bis);

            // read header
            int dbVersion = in.readInt();

            if (dbVersion != VERSION) {
                throw new RuntimeException("Wrong database version");
            }

            // read field node table
            int fieldNodeSize = in.readInt();
            List<TypeField> fieldNodes = new ArrayList<>(fieldNodeSize);

            for (int i = 0; i < fieldNodeSize; i++) {
                TypeField fieldNode = new TypeField();
                fieldNode.read(in);
                fieldNodes.add(fieldNode);
            }

            // read version string table
            int versionSize = in.readInt();
            List<UnityVersion> versions = new ArrayList<>(versionSize);

            for (int i = 0; i < versionSize; i++) {
                versions.add(new UnityVersion(in.readStringNull()));
            }

            // read mapping data
            int fieldNodeKeySize = in.readInt();

            for (int i = 0; i < fieldNodeKeySize; i++) {
                int index = in.readInt();
                int classID = in.readInt();
                int revisionIndex = in.readInt();
               
                UnityVersion version = versions.get(revisionIndex);
                TypeField fieldNode = fieldNodes.get(index);

                ftm.add(classID, version, fieldNode);
View Full Code Here

        load(bb);
    }
   
    @Override
    public void load(ByteBuffer bb) throws IOException {
        DataInputReader in = DataInputReader.newReader(bb);
        in.readStruct(header);
        in.setSwap(true);
       
        typeTree = new TypeTree();
        objTable = new ObjectPathTable();
        refTable = new AssetRefTable();
       
        typeTree.setFormat(header.getFormat());
       
        switch (header.getFormat()) {
            case 5:
            case 6:
            case 7:
            case 8:
                // first data, then struct
                int treeOffset = header.getFileSize() - header.getTreeSize() + 1;
                bbData = ByteBufferUtils.getSlice(bb, 0, treeOffset);
                bb.position(treeOffset);

                in.readStruct(typeTree);
                in.readStruct(objTable);
                in.readStruct(refTable);
                break;
               
            case 9:
                // first struct, then data
                in.readStruct(typeTree);
                in.readStruct(objTable);
                in.readStruct(refTable);
               
                bbData = ByteBufferUtils.getSlice(bb, header.getDataOffset());
                break;
               
            default:
View Full Code Here

                bb = codec.decode(bb);
                codecsSave.add(codec);
            }
        }
       
        DataInputReader in = DataInputReader.newReader(bb);
        in.readStruct(header);
       
        // check signature
        if (!header.hasValidSignature()) {
            throw new AssetBundleException("Invalid signature");
        }
       
        // check compression flag in the signature
        compressed = header.isCompressed();
       
        // get buffer slice for bundle data
        ByteBuffer bbData = ByteBufferUtils.getSlice(bb, header.getDataOffset());
       
        // uncompress bundle data if required
        if (isCompressed()) {
            L.log(Level.INFO, "Uncompressing asset bundle, this may take a while");
            bbData = LzmaBufferUtils.decode(bbData);
        }

        // read bundle entries
        in = DataInputReader.newReader(bbData);
        int files = in.readInt();
        for (int i = 0; i < files; i++) {
            String name = in.readStringNull();
            int offset = in.readInt();
            int length = in.readInt();
            ByteBuffer bbEntry = ByteBufferUtils.getSlice(bbData, offset, length);
            entries.put(name, bbEntry);
        }
    }
View Full Code Here

                if (tgaSaveMipMaps || j == 0) {
                    ByteBuffer bbTga = ByteBuffer.allocateDirect(TGAHeader.SIZE + imageSize);
                    bbTga.order(ByteOrder.LITTLE_ENDIAN);

                    // write TGA header
                    DataOutputWriter out = DataOutputWriter.newWriter(bbTga);
                    header.write(out);

                    // write image data
                    bb.limit(bb.position() + imageSize);
                    bbTga.put(bb);
View Full Code Here

        if (pbv.numItems == 0 || pbv.bitSize == 0) {
            return new int[]{};
        }
       
        // the values are packed with a variable bit length
        BitInputStream bis = new BitInputStream(new ByteBufferInputStream(pbv.data));
        bis.setBitLength(pbv.bitSize);
       
        int numItems = pbv.numItems.intValue();
        int[] items = new int[numItems];
        for (int i = 0; i < items.length; i++) {
View Full Code Here

        if (pbv.numItems == 0 || pbv.bitSize == 0) {
            return new int[]{};
        }
       
        // the values are packed with a variable bit length
        BitInputStream bis = new BitInputStream(new ByteBufferInputStream(pbv.data));
        bis.setBitLength(pbv.bitSize);
       
        int numItems = pbv.numItems.intValue();
        int[] items = new int[numItems];
        for (int i = 0; i < items.length; i++) {
            items[i] = bis.read();
        }
       
        return items;
    }
View Full Code Here

                continue;
            }

            String className = ClassID.getNameForID(path.getClassID(), true);
           
            AssetFile subAsset = new AssetFile();
            subAsset.getHeader().setFormat(asset.getHeader().getFormat());
           
            ObjectPath subFieldPath = new ObjectPath();
            subFieldPath.setClassID1(path.getClassID1());
            subFieldPath.setClassID2(path.getClassID2());
            subFieldPath.setLength(path.getLength());
            subFieldPath.setOffset(0);
            subFieldPath.setPathID(1);
            subAsset.getPaths().add(subFieldPath);
           
            TypeTree subTypeTree = subAsset.getTypeTree();
            subTypeTree.setEngineVersion(typeTree.getEngineVersion());
            subTypeTree.setVersion(-2);
            subTypeTree.setFormat(typeTree.getFormat());
            subTypeTree.getFields().put(path.getClassID(), typeTree.getFields().get(path.getClassID()));

            subAsset.setDataBuffer(asset.getPathBuffer(path));
           
            Path subAssetDir = outputDir.resolve(className);
            if (Files.notExists(subAssetDir)) {
                Files.createDirectories(subAssetDir);
            }
           
            // probe asset name
            String subAssetName = getObjectName(asset, path);
            if (subAssetName != null) {
                // remove any chars that could cause troubles on various file systems
                subAssetName = FilenameSanitizer.sanitizeName(subAssetName);
            } else {
                // use numeric names
                subAssetName = String.format("%06d", path.getPathID());
            }
            subAssetName += ".asset";
           
            Path subAssetFile = subAssetDir.resolve(subAssetName);
            if (Files.notExists(subAssetFile)) {
                L.log(Level.INFO, "Writing {0}", subAssetFile);
                subAsset.save(subAssetFile);
            }
        }
    }
View Full Code Here

            }
        }
    }
   
    protected void processAssetFile(Path file) throws IOException {
        AssetFile asset = new AssetFile();
        asset.open(file);

        setOutputDir(PathUtils.removeExtension(file));
        processAsset(asset);
    }
View Full Code Here

TOP

Related Classes of info.ata4.io.DataInputReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.