Package com.ngt.jopenmetaverse.shared.sim.rendering.mesh

Examples of com.ngt.jopenmetaverse.shared.sim.rendering.mesh.BitPack


        protected Face[] _faces;

        public void LoadMesh(String filename) throws IOException
        {
            byte[] buffer = FileUtils.readBytes(new File(filename));
            BitPack input = new BitPack(buffer, 0);

            _header = Utils.TrimAt0(input.UnpackString(24));
            if (!_header.equalsIgnoreCase(MESH_HEADER))
                throw new IOException("Unrecognized mesh format");

            // Populate base mesh variables
            _hasWeights = (input.UnpackByte() != 0);
            _hasDetailTexCoords = (input.UnpackByte() != 0);
            _position = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
            _rotationAngles = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
            _rotationOrder = input.UnpackByte();
            _scale = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
            _numFaces = input.UnpackUShort();

            _faces = new Face[_numFaces];

            for (int i = 0; i < _numFaces; i++)
                _faces[i].Indices = new short[] { input.UnpackShort(), input.UnpackShort(), input.UnpackShort() };
        }
View Full Code Here


    }

    public void LoadMesh(String filename) throws IOException
    {
        byte[] buffer = FileUtils.readBytes(new File(filename));
        BitPack input = new BitPack(buffer, 0);

        _header = Utils.TrimAt0(input.UnpackString(24));
        if (!_header.equalsIgnoreCase(MESH_HEADER))
            throw new IOException("Unrecognized mesh format");

        // Populate base mesh variables
        _hasWeights = (input.UnpackByte() != 0);
        _hasDetailTexCoords = (input.UnpackByte() != 0);
        _position = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
        _rotationAngles = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
        _rotationOrder = input.UnpackByte();
        _scale = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
        _numVertices = input.UnpackUShort();

        // Populate the vertex array
        _vertices = new Vertex[_numVertices];

        for (int i = 0; i < _numVertices; i++)
            _vertices[i].Coord = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());

        for (int i = 0; i < _numVertices; i++)
            _vertices[i].Normal = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());

        for (int i = 0; i < _numVertices; i++)
            _vertices[i].BiNormal = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());

        for (int i = 0; i < _numVertices; i++)
            _vertices[i].TexCoord = new Vector2(input.UnpackFloat(), input.UnpackFloat());

        if (_hasDetailTexCoords)
        {
            for (int i = 0; i < _numVertices; i++)
                _vertices[i].DetailTexCoord = new Vector2(input.UnpackFloat(), input.UnpackFloat());
        }

        if (_hasWeights)
        {
            for (int i = 0; i < _numVertices; i++)
                _vertices[i].Weight = input.UnpackFloat();
        }

        _numFaces = input.UnpackUShort();

        _faces = new Face[_numFaces];

        for (int i = 0; i < _numFaces; i++)
            _faces[i].Indices = new short[] { input.UnpackShort(), input.UnpackShort(), input.UnpackShort() };

        if (_hasWeights)
        {
            _numSkinJoints = input.UnpackUShort();
            _skinJoints = new String[_numSkinJoints];

            for (int i = 0; i < _numSkinJoints; i++)
            {
                _skinJoints[i] = Utils.TrimAt0(input.UnpackString(64));
            }
        }
        else
        {
            _numSkinJoints = 0;
            _skinJoints = new String[0];
        }

        // Grab morphs
        List<Morph> morphs = new ArrayList<Morph>();
        String morphName = Utils.TrimAt0(input.UnpackString(64));

        while (!morphName.equalsIgnoreCase(MORPH_FOOTER))
        {
            if (input.getBytePos() + 48 >= input.Data.length) throw new IOException("Encountered end of file while parsing morphs");

            Morph morph = new Morph();
            morph.Name = morphName;
            morph.NumVertices = input.UnpackInt();
            morph.Vertices = new MorphVertex[morph.NumVertices];

            for (int i = 0; i < morph.NumVertices; i++)
            {
                morph.Vertices[i].VertexIndex = input.UnpackUInt();
                morph.Vertices[i].Coord = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
                morph.Vertices[i].Normal = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
                morph.Vertices[i].BiNormal = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
                morph.Vertices[i].TexCoord = new Vector2(input.UnpackFloat(), input.UnpackFloat());
            }

            morphs.add(morph);

            // Grab the next name
            morphName = Utils.TrimAt0(input.UnpackString(64));
        }

        _morphs = morphs.toArray(new Morph[0]);

        // Check if there are remaps or if we're at the end of the file
        if (input.getBytePos() < input.Data.length - 1)
        {
            _numRemaps = input.UnpackInt();
            _vertexRemaps = new VertexRemap[_numRemaps];

            for (int i = 0; i < _numRemaps; i++)
            {
                _vertexRemaps[i].RemapSource = input.UnpackInt();
                _vertexRemaps[i].RemapDestination = input.UnpackInt();
            }
        }
        else
        {
            _numRemaps = 0;
View Full Code Here

TOP

Related Classes of com.ngt.jopenmetaverse.shared.sim.rendering.mesh.BitPack

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.