Examples of BitPack


Examples of com.ngt.jopenmetaverse.shared.protocol.BitPack

              header.PatchSize = 16;
              header.Type = type;

              // Should be enough to fit even the most poorly packed data
              byte[] data = new byte[patches.length * 16 * 16 * 2];
              BitPack bitpack = new BitPack(data, 0);
              bitpack.PackBits(header.Stride, 16);
              bitpack.PackBits(header.PatchSize, 8);
              bitpack.PackBits((int)header.Type.getIndex(), 8);

              for (int i = 0; i < patches.length; i++)
                  CreatePatch(bitpack, patches[i].Data, patches[i].X, patches[i].Y);

              bitpack.PackBits(END_OF_PATCHES, 8);

              layer.LayerData.Data = new byte[bitpack.getBytePos() + 1];
//              Buffer.BlockCopy(bitpack.Data, 0, layer.LayerData.Data, 0, bitpack.getBytePos() + 1);
              Utils.arraycopy(bitpack.Data, 0, layer.LayerData.Data, 0, bitpack.getBytePos() + 1);

              return layer;
          }
View Full Code Here

Examples of com.ngt.jopenmetaverse.shared.protocol.BitPack

              header.Stride = STRIDE;
              header.PatchSize = 16;
              header.Type = TerrainPatch.LayerType.Land;

              byte[] data = new byte[1536];
              BitPack bitpack = new BitPack(data, 0);
              bitpack.PackBits(header.Stride, 16);
              bitpack.PackBits(header.PatchSize, 8);
              bitpack.PackBits((int)header.Type.getIndex(), 8);

              for (int i = 0; i < patches.length; i++)
                  CreatePatchFromHeightmap(bitpack, heightmap, patches[i] % 16, (patches[i] - (patches[i] % 16)) / 16);

              bitpack.PackBits(END_OF_PATCHES, 8);

              layer.LayerData.Data = new byte[bitpack.getBytePos() + 1];
              Utils.arraycopy(bitpack.Data, 0, layer.LayerData.Data, 0, bitpack.getBytePos() + 1);

              return layer;
          }
View Full Code Here

Examples of com.ngt.jopenmetaverse.shared.protocol.BitPack

              header.Stride = STRIDE;
              header.PatchSize = 16;
              header.Type = TerrainPatch.LayerType.Land;

              byte[] data = new byte[1536];
              BitPack bitpack = new BitPack(data, 0);
              bitpack.PackBits(header.Stride, 16);
              bitpack.PackBits(header.PatchSize, 8);
              bitpack.PackBits((int)header.Type.getIndex(), 8);

              CreatePatch(bitpack, patchData, x, y);

              bitpack.PackBits(END_OF_PATCHES, 8);

              layer.LayerData.Data = new byte[bitpack.getBytePos() + 1];
              Utils.arraycopy(bitpack.Data, 0, layer.LayerData.Data, 0, bitpack.getBytePos() + 1);

              return layer;
          }
View Full Code Here

Examples of com.ngt.jopenmetaverse.shared.protocol.BitPack

              header.Stride = STRIDE;
              header.PatchSize = 16;
              header.Type = TerrainPatch.LayerType.Land;

              byte[] data = new byte[1536];
              BitPack bitpack = new BitPack(data, 0);
              bitpack.PackBits(header.Stride, 16);
              bitpack.PackBits(header.PatchSize, 8);
              bitpack.PackBits((int)header.Type.getIndex(), 8);

              CreatePatch(bitpack, patchData, x, y);

              bitpack.PackBits(END_OF_PATCHES, 8);

              layer.LayerData.Data = new byte[bitpack.getBytePos() + 1];
              Utils.arraycopy(bitpack.Data, 0, layer.LayerData.Data, 0, bitpack.getBytePos() + 1);

              return layer;
          }
View Full Code Here

Examples of com.ngt.jopenmetaverse.shared.protocol.BitPack

      }

      private void LayerDataHandler(Object sender, PacketReceivedEventArgs e)
      {
          LayerDataPacket layer = (LayerDataPacket)e.getPacket();
          BitPack bitpack = new BitPack(layer.LayerData.Data, 0);
          TerrainPatch.GroupHeader header = new TerrainPatch.GroupHeader();
          TerrainPatch.LayerType type = TerrainPatch.LayerType.get(layer.LayerID.Type);

          // Stride
          header.Stride = bitpack.UnpackBits(16);
          // Patch size
          header.PatchSize = bitpack.UnpackBits(8);
          // Layer type
          header.Type = TerrainPatch.LayerType.get((byte)bitpack.UnpackBits(8));

          switch (type)
          {
              case Land:
                  if (onLandPatchReceived != null || Client.settings.STORE_LAND_PATCHES)
View Full Code Here

Examples of com.ngt.jopenmetaverse.shared.protocol.BitPack

            {
                // TODO: Not sure exactly how many bytes we need here, so partial
                // (truncated) data will cause an exception to be thrown
                if (data.length > 0)
                {
                    BitPack pack = new BitPack(data, pos);

                    CRC = pack.UnpackLBits(32);
                    PartFlags = pack.UnpackLBits(32);
                    Pattern = SourcePattern.get(pack.UnpackByte());
                    MaxAge = pack.UnpackFixed(false, 8, 8);
                    StartAge = pack.UnpackFixed(false, 8, 8);
                    InnerAngle = pack.UnpackFixed(false, 3, 5);
                    OuterAngle = pack.UnpackFixed(false, 3, 5);
                    BurstRate = pack.UnpackFixed(false, 8, 8);
                    BurstRadius = pack.UnpackFixed(false, 8, 8);
                    BurstSpeedMin = pack.UnpackFixed(false, 8, 8);
                    BurstSpeedMax = pack.UnpackFixed(false, 8, 8);
                    BurstPartCount = pack.UnpackByte();
                    float x = pack.UnpackFixed(true, 8, 7);
                    float y = pack.UnpackFixed(true, 8, 7);
                    float z = pack.UnpackFixed(true, 8, 7);
                    AngularVelocity = new Vector3(x, y, z);
                    x = pack.UnpackFixed(true, 8, 7);
                    y = pack.UnpackFixed(true, 8, 7);
                    z = pack.UnpackFixed(true, 8, 7);
                    PartAcceleration = new Vector3(x, y, z);
                    Texture = pack.UnpackUUID();
                    Target = pack.UnpackUUID();

                    PartDataFlags = ParticleDataFlags.get(pack.UnpackLBits(32));
                    PartMaxAge = pack.UnpackFixed(false, 8, 8);
                    byte r = pack.UnpackByte();
                    byte g = pack.UnpackByte();
                    byte b = pack.UnpackByte();
                    byte a = pack.UnpackByte();
                    PartStartColor = new Color4(r, g, b, a);
                    r = pack.UnpackByte();
                    g = pack.UnpackByte();
                    b = pack.UnpackByte();
                    a = pack.UnpackByte();
                    PartEndColor = new Color4(r, g, b, a);
                    PartStartScaleX = pack.UnpackFixed(false, 3, 5);
                    PartStartScaleY = pack.UnpackFixed(false, 3, 5);
                    PartEndScaleX = pack.UnpackFixed(false, 3, 5);
                    PartEndScaleY = pack.UnpackFixed(false, 3, 5);
                }
                else
                {
                    CRC = PartFlags = 0;
                    Pattern = SourcePattern.None;
View Full Code Here

Examples of com.ngt.jopenmetaverse.shared.protocol.BitPack

            /// </summary>
            /// <returns>Byte array</returns>
            public byte[] GetBytes() throws Exception
            {
                byte[] bytes = new byte[86];
                BitPack pack = new BitPack(bytes, 0);

                pack.PackBits(CRC, 32);
                pack.PackBits(PartFlags & 0xffffffff, 32);
                pack.PackBits(Pattern.getIndex() & 0xff, 8);
                pack.PackFixed(MaxAge, false, 8, 8);
                pack.PackFixed(StartAge, false, 8, 8);
                pack.PackFixed(InnerAngle, false, 3, 5);
                pack.PackFixed(OuterAngle, false, 3, 5);
                pack.PackFixed(BurstRate, false, 8, 8);
                pack.PackFixed(BurstRadius, false, 8, 8);
                pack.PackFixed(BurstSpeedMin, false, 8, 8);
                pack.PackFixed(BurstSpeedMax, false, 8, 8);
                pack.PackBits(BurstPartCount, 8);
                pack.PackFixed(AngularVelocity.X, true, 8, 7);
                pack.PackFixed(AngularVelocity.Y, true, 8, 7);
                pack.PackFixed(AngularVelocity.Z, true, 8, 7);
                pack.PackFixed(PartAcceleration.X, true, 8, 7);
                pack.PackFixed(PartAcceleration.Y, true, 8, 7);
                pack.PackFixed(PartAcceleration.Z, true, 8, 7);
                pack.PackUUID(Texture);
                pack.PackUUID(Target);

                pack.PackBits(ParticleDataFlags.getIndex(PartDataFlags), 32);
                pack.PackFixed(PartMaxAge, false, 8, 8);
                pack.PackColor(PartStartColor);
                pack.PackColor(PartEndColor);
                pack.PackFixed(PartStartScaleX, false, 3, 5);
                pack.PackFixed(PartStartScaleY, false, 3, 5);
                pack.PackFixed(PartEndScaleX, false, 3, 5);
                pack.PackFixed(PartEndScaleY, false, 3, 5);

                return bytes;
            }
View Full Code Here

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

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

    }

    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
Copyright © 2018 www.massapi.com. 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.